1 /*
2  * Copyright (C) 2002-2020 by the Widelands Development Team
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  *
18  */
19 
20 #ifndef WL_UI_FSMENU_OPTIONS_H
21 #define WL_UI_FSMENU_OPTIONS_H
22 
23 #include <memory>
24 
25 #include "ui_basic/box.h"
26 #include "ui_basic/button.h"
27 #include "ui_basic/checkbox.h"
28 #include "ui_basic/dropdown.h"
29 #include "ui_basic/multilinetextarea.h"
30 #include "ui_basic/spinbox.h"
31 #include "ui_basic/tabpanel.h"
32 #include "ui_basic/textarea.h"
33 #include "ui_fsmenu/base.h"
34 #include "wui/sound_options.h"
35 
36 class FullscreenMenuOptions;
37 class Section;
38 
39 class OptionsCtrl {
40 public:
41 	struct OptionsStruct {
42 
43 		// Interface options
44 		int32_t xres;
45 		int32_t yres;
46 		bool fullscreen;
47 		bool inputgrab;
48 		uint32_t maxfps;
49 		bool sdl_cursor;
50 
51 		// Windows options
52 		bool snap_win_overlap_only;
53 		bool dock_windows_to_edges;
54 		int32_t panel_snap_distance;
55 		int32_t border_snap_distance;
56 		bool animate_map_panning;
57 
58 		// Saving options
59 		int32_t autosave;          // autosave interval in minutes
60 		int32_t rolling_autosave;  // number of file to use for rolling autosave
61 		bool zip;
62 		bool write_syncstreams;
63 
64 		// Game options
65 		bool auto_roadbuild_mode;
66 		bool transparent_chat;
67 		bool single_watchwin;
68 		bool ctrl_zoom;
69 		bool game_clock;
70 
71 		// Language options
72 		std::string language;
73 
74 		// Last tab for reloading the options menu
75 		uint32_t active_tab;
76 	};
77 
78 	explicit OptionsCtrl(Section&);
79 	void handle_menu();
80 	OptionsCtrl::OptionsStruct options_struct(uint32_t active_tab);
81 	void save_options();
82 
83 private:
84 	Section& opt_section_;
85 	std::unique_ptr<FullscreenMenuOptions> opt_dialog_;
86 };
87 
88 /**
89  * Fullscreen Optionsmenu. A modal optionsmenu
90  */
91 
92 class FullscreenMenuOptions : public FullscreenMenuBase {
93 public:
94 	explicit FullscreenMenuOptions(OptionsCtrl::OptionsStruct opt);
95 	OptionsCtrl::OptionsStruct get_values();
96 
97 private:
98 	void layout() override;
99 
100 	// Fills the language selection list
101 	void add_languages_to_list(const std::string& current_locale);
102 	void update_language_stats(bool include_system_lang);
103 
104 	// Saves the options and reloads the active tab
105 	void clicked_apply();
106 	// Restores old options when canceled
107 	void clicked_cancel();
108 
109 	const uint32_t padding_;
110 	uint32_t butw_;
111 	uint32_t buth_;
112 	uint32_t hmargin_;
113 	uint32_t tab_panel_y_;
114 
115 	UI::Textarea title_;
116 	UI::Box button_box_;
117 	UI::Button cancel_, apply_, ok_;
118 
119 	// UI elements
120 	UI::TabPanel tabs_;
121 	UI::Box box_interface_;
122 	UI::Box box_interface_left_;
123 	UI::Box box_windows_;
124 	UI::Box box_sound_;
125 	UI::Box box_saving_;
126 	UI::Box box_game_;
127 
128 	// Interface options
129 	UI::Dropdown<std::string> language_dropdown_;
130 	UI::Dropdown<uintptr_t> resolution_dropdown_;
131 	UI::Checkbox fullscreen_;
132 	UI::Checkbox inputgrab_;
133 	UI::Checkbox sdl_cursor_;
134 	UI::SpinBox sb_maxfps_;
135 	UI::MultilineTextarea translation_info_;
136 
137 	// Windows options
138 	UI::Checkbox snap_win_overlap_only_;
139 	UI::Checkbox dock_windows_to_edges_;
140 	UI::Checkbox animate_map_panning_;
141 	UI::SpinBox sb_dis_panel_;
142 	UI::SpinBox sb_dis_border_;
143 
144 	// Sound options
145 	SoundOptions sound_options_;
146 
147 	// Saving options
148 	UI::SpinBox sb_autosave_;
149 	UI::SpinBox sb_rolling_autosave_;
150 	UI::Checkbox zip_;
151 	UI::Checkbox write_syncstreams_;
152 
153 	// Game options
154 	UI::Checkbox auto_roadbuild_mode_;
155 	UI::Checkbox transparent_chat_;
156 	UI::Checkbox single_watchwin_;
157 	UI::Checkbox ctrl_zoom_;
158 	UI::Checkbox game_clock_;
159 
160 	OptionsCtrl::OptionsStruct os_;
161 
162 	class ScreenResolution {
163 	public:
164 		int32_t xres;
165 		int32_t yres;
166 		int32_t depth;
167 	};
168 
169 	/// All supported screen resolutions.
170 	std::vector<ScreenResolution> resolutions_;
171 
172 	// Data model for the entries in the language selection list.
173 	struct LanguageEntry {
LanguageEntryLanguageEntry174 		LanguageEntry(const std::string& init_localename, const std::string& init_descname)
175 		   : localename(init_localename), descname(init_descname) {
176 		}
LanguageEntryLanguageEntry177 		LanguageEntry() : LanguageEntry("", "") {
178 		}
179 		std::string localename;  // ISO code for the locale
180 		std::string descname;    // Native language name
181 	};
182 	std::map<std::string, LanguageEntry> language_entries_;
183 };
184 
185 #endif  // end of include guard: WL_UI_FSMENU_OPTIONS_H
186