Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #define GETTEXT_DOMAIN "wesnoth-editor"
00017
00018 #include "gui/dialogs/editor_set_starting_position.hpp"
00019
00020 #include "foreach.hpp"
00021 #include "formatter.hpp"
00022 #include "formula_string_utils.hpp"
00023 #include "gettext.hpp"
00024 #ifdef GUI2_EXPERIMENTAL_LISTBOX
00025 #include "gui/widgets/list.hpp"
00026 #else
00027 #include "gui/widgets/listbox.hpp"
00028 #endif
00029 #include "gui/widgets/settings.hpp"
00030 #include "gui/widgets/window.hpp"
00031 #include "map_location.hpp"
00032
00033 namespace gui2 {
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 REGISTER_DIALOG(editor_set_starting_position)
00065
00066 teditor_set_starting_position::teditor_set_starting_position(unsigned current_player, unsigned maximum_players, const std::vector<map_location>& starting_positions)
00067 : players_(maximum_players)
00068 , selection_(std::min(current_player, maximum_players))
00069 , starting_positions_(starting_positions)
00070 {
00071 if(starting_positions_.size() != maximum_players) {
00072 starting_positions_.resize(maximum_players);
00073 }
00074 }
00075
00076 void teditor_set_starting_position::pre_show(CVideo& , twindow& window)
00077 {
00078 tlistbox& list = find_widget<tlistbox>(&window, "listbox", false);
00079 window.keyboard_capture(&list);
00080
00081 std::map<std::string, string_map> data;
00082 string_map column;
00083
00084 column["label"] = _("player^None");
00085 data.insert(std::make_pair("player", column));
00086 list.add_row(data);
00087
00088 for(unsigned i = 0; i < starting_positions_.size(); ++i) {
00089 const map_location& player_pos = starting_positions_[i];
00090
00091 data.clear();
00092
00093 utils::string_map symbols;
00094 symbols["player_number"] = str_cast(i + 1);
00095
00096 column["label"] = utils::interpolate_variables_into_string(_("Player $player_number"), &symbols);
00097 data.insert(std::make_pair("player", column));
00098
00099 if(player_pos.valid()) {
00100 column["label"] = (formatter() << "(" << player_pos.x + 1 << ", " << player_pos.y + 1 << ")").str();
00101 data.insert(std::make_pair("location", column));
00102 }
00103
00104 list.add_row(data);
00105 }
00106
00107 list.select_row(selection_);
00108 }
00109
00110 void teditor_set_starting_position::post_show(twindow& window)
00111 {
00112 if(get_retval() != twindow::OK) {
00113 return;
00114 }
00115
00116 tlistbox& list = find_widget<tlistbox>(&window, "listbox", false);
00117 selection_ = list.get_selected_row();
00118 }
00119
00120 }