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_EDITOR_UI_MENUS_PLAYER_MENU_H
21 #define WL_EDITOR_UI_MENUS_PLAYER_MENU_H
22 
23 #include <memory>
24 
25 #include "editor/ui_menus/tool_options_menu.h"
26 #include "ui_basic/box.h"
27 #include "ui_basic/button.h"
28 #include "ui_basic/dropdown.h"
29 #include "ui_basic/editbox.h"
30 #include "ui_basic/unique_window.h"
31 
32 class EditorInteractive;
33 
34 class EditorPlayerMenu : public EditorToolOptionsMenu {
35 public:
36 	EditorPlayerMenu(EditorInteractive&,
37 	                 EditorSetStartingPosTool& tool,
38 	                 UI::UniqueWindow::Registry&);
39 
40 private:
41 	// Container with UI elements to set a player slot's properties
42 	struct PlayerEditRow {
PlayerEditRowPlayerEditRow43 		explicit PlayerEditRow(UI::Box* init_box,
44 		                       UI::EditBox* init_name,
45 		                       UI::Button* init_position,
46 		                       UI::Dropdown<std::string>* init_tribe)
47 		   : box(init_box), name(init_name), position(init_position), tribe(init_tribe) {
48 		}
49 		UI::Box* box;
50 		UI::EditBox* name;
51 		UI::Button* position;
52 		UI::Dropdown<std::string>* tribe;
53 	};
54 
55 	EditorInteractive& eia();
56 
57 	/// Update player name on map for the given row's player
58 	void name_changed(size_t row);
59 	/// Update number of player slots available on the map
60 	void no_of_players_clicked();
61 	/// Select tribe for the given row's player
62 	void player_tribe_clicked(size_t row);
63 	/// Select starting position for the given row's player
64 	void set_starting_pos_clicked(size_t row);
65 
66 	/// Resize window according to number of rows
67 	void layout() override;
68 
69 	UI::Box box_;
70 	UI::Dropdown<uintptr_t> no_of_players_;
71 	std::vector<std::unique_ptr<PlayerEditRow>> rows_;
72 };
73 
74 #endif  // end of include guard: WL_EDITOR_UI_MENUS_PLAYER_MENU_H
75