gui/dialogs/editor_set_starting_position.cpp

Go to the documentation of this file.
00001 /* $Id: editor_set_starting_position.cpp 52869 2012-02-03 20:18:33Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2011 - 2012 by Ignacio Riquelme Morelle <shadowm2006@gmail.com>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
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 /*WIKI
00036  * @page = GUIWindowDefinitionWML
00037  * @order = 2_editor_set_starting_position
00038  *
00039  * == Editor set starting position ==
00040  *
00041  * Map editor dialog for setting player starting positions.
00042  *
00043  * @begin{table}{dialog_widgets}
00044  *
00045  * listbox & & listbox & m &
00046  *         Listbox displaying player choices. $
00047  *
00048  * -player & & control & m &
00049  *         Widget which shows a player item label. $
00050  *
00051  * -location & & control & m &
00052  *         Widget which shows the coordinates to the current
00053  *         starting position for a player if it exists. $
00054  *
00055  * ok & & button & m &
00056  *         OK button. $
00057  *
00058  * cancel & & button & m &
00059  *         Cancel button. $
00060  *
00061  * @end{table}
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& /*video*/, 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 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:42 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs