Author: shadowmaster
Date: Fri Oct 28 04:12:15 2011
New Revision: 51691

URL: http://svn.gna.org/viewcvs/wesnoth?rev=51691&view=rev
Log:
gui2/teditor_set_starting_position: Converted old GUI1 starting positions tool 
menu to GUI2

* Added a column displaying existing starting locations' coordinates to
  the player numbers list
* May have made the player number entries easier to translate
* Removed overly long infodump about hotkeys that's already part of the
  tooltip on the editor palette anyway.
* Ran into a lot of frustration involving adding or substracting one
  from various things like map coordinates and team numbers because the
  zero-based C arrays assumption doesn't seem to work here.

Added:
    trunk/data/gui/default/window/editor_set_starting_position.cfg
    trunk/src/gui/dialogs/editor_set_starting_position.cpp
    trunk/src/gui/dialogs/editor_set_starting_position.hpp
Modified:
    trunk/changelog
    trunk/src/CMakeLists.txt
    trunk/src/SConscript
    trunk/src/editor/mouse_action.cpp

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=51691&r1=51690&r2=51691&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Fri Oct 28 04:12:15 2011
@@ -15,6 +15,8 @@
  * Editor:
    * Made sure lighting setting changes are applied immediately when closing 
the
      settings window when automatic map view updates are disabled
+   * Starting position tool menu now displays coordinates of existing 
positions,
+     and initially highlights the current player number assigned to the 
selected hex
  * Graphics:
    * New Animations:
      * Goblin spearman run se

Added: trunk/data/gui/default/window/editor_set_starting_position.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/window/editor_set_starting_position.cfg?rev=51691&view=auto
==============================================================================
--- trunk/data/gui/default/window/editor_set_starting_position.cfg (added)
+++ trunk/data/gui/default/window/editor_set_starting_position.cfg Fri Oct 28 
04:12:15 2011
@@ -1,0 +1,193 @@
+#textdomain wesnoth-lib
+
+[window]
+       id = "editor_set_starting_position"
+       description = "Map editor dialog for setting player starting positions."
+
+       [resolution]
+               definition = "default"
+
+               automatic_placement = "true"
+               vertical_placement = "center"
+               horizontal_placement = "center"
+
+               maximum_width = 500
+               maximum_height = 600
+
+               [linked_group]
+                       id = "players"
+                       fixed_width = "true"
+               [/linked_group]
+               
+               [linked_group]
+                       id = "locations"
+                       fixed_width = "true"
+               [/linked_group]
+
+               [tooltip]
+                       id = "tooltip_large"
+               [/tooltip]
+
+               [helptip]
+                       id = "tooltip_large"
+               [/helptip]
+
+               [grid]
+
+                       [row]
+                               grow_factor = 0
+
+                               [column]
+                                       grow_factor = 1
+
+                                       border = "all"
+                                       border_size = 5
+                                       horizontal_alignment = "left"
+
+                                       [label]
+                                               id =  "title"
+                                               definition = "title"
+                                               label = _ "Choose Player"
+                                       [/label]
+
+                               [/column]
+
+                       [/row]
+
+                       [row]
+                               grow_factor = 0
+
+                               [column]
+                                       grow_factor = 0
+
+                                       border = "all"
+                                       border_size = 5
+                                       horizontal_alignment = "left"
+
+                                       [label]
+                                               id = "message"
+                                               definition = "default"
+                                               label = _ "Which player should 
start here?"
+                                               wrap = "true"
+                                       [/label]
+
+                               [/column]
+
+                       [/row]
+
+                       [row]
+                               grow_factor = 1
+
+                               [column]
+                                       grow_factor = 1
+
+                                       horizontal_grow = "true"
+                                       vertical_grow = "true"
+
+                                       border = "all"
+                                       border_size = 5
+
+                                       [listbox]
+                                               id = "listbox"
+                                               definition = "default"
+
+                                               [list_definition]
+
+                                                       [row]
+
+                                                               [column]
+                                                                       
vertical_grow = "true"
+                                                                       
horizontal_grow = "true"
+                                                                       
[toggle_panel]
+                                                                               
definition = "default"
+                                                                               
return_value_id = "ok"
+                                                                               
[grid]
+                                                                               
        [row]
+                                                                               
                [column]
+                                                                               
                        grow_factor = 1
+                                                                               
                        horizontal_grow = "true"
+                                                                               
                        border = "all"
+                                                                               
                        border_size = 5
+                                                                               
                        [label]
+                                                                               
                                id = "player"
+                                                                               
                                definition = "default"
+                                                                               
                                linked_group = "players"
+                                                                               
                        [/label]
+                                                                               
                [/column]
+                                                                               
                [column]
+                                                                               
                        grow_factor = 1
+                                                                               
                        horizontal_grow = "true"
+                                                                               
                        border = "all"
+                                                                               
                        border_size = 5
+                                                                               
                        [label]
+                                                                               
                                id = "location"
+                                                                               
                                definition = "default"
+                                                                               
                                linked_group = "locations"
+                                                                               
                        [/label]
+                                                                               
                [/column]
+                                                                               
        [/row]
+                                                                               
[/grid]
+                                                                       
[/toggle_panel]
+                                                               [/column]
+
+                                                       [/row]
+
+                                               [/list_definition]
+
+                                       [/listbox]
+
+                               [/column]
+
+                       [/row]
+
+                       [row]
+                               grow_factor = 0
+
+                               [column]
+                                       grow_factor = 1
+                                       horizontal_grow = "true"
+
+                                       [grid]
+
+                                               [row]
+                                                       grow_factor = 0
+
+                                                       [column]
+                                                               border = "all"
+                                                               border_size = 5
+                                                               
horizontal_alignment = "right"
+
+                                                               [button]
+                                                                       id = 
"ok"
+                                                                       
definition = "default"
+                                                                       label = 
_ "OK"
+                                                               [/button]
+
+                                                       [/column]
+
+                                                       [column]
+                                                               border = "all"
+                                                               border_size = 5
+                                                               
horizontal_alignment = "right"
+
+                                                               [button]
+                                                                       id = 
"cancel"
+                                                                       
definition = "default"
+                                                                       label = 
_ "Cancel"
+                                                               [/button]
+
+                                                       [/column]
+
+                                               [/row]
+
+                                       [/grid]
+
+                               [/column]
+
+                       [/row]
+
+               [/grid]
+
+       [/resolution]
+
+[/window]

Modified: trunk/src/CMakeLists.txt
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/CMakeLists.txt?rev=51691&r1=51690&r2=51691&view=diff
==============================================================================
--- trunk/src/CMakeLists.txt (original)
+++ trunk/src/CMakeLists.txt Fri Oct 28 04:12:15 2011
@@ -463,6 +463,7 @@
        gui/dialogs/editor_generate_map.cpp
        gui/dialogs/editor_new_map.cpp
        gui/dialogs/editor_resize_map.cpp
+       gui/dialogs/editor_set_starting_position.cpp
        gui/dialogs/editor_settings.cpp
        gui/dialogs/folder_create.cpp
        gui/dialogs/formula_debugger.cpp

Modified: trunk/src/SConscript
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/SConscript?rev=51691&r1=51690&r2=51691&view=diff
==============================================================================
--- trunk/src/SConscript (original)
+++ trunk/src/SConscript Fri Oct 28 04:12:15 2011
@@ -307,6 +307,7 @@
     gui/dialogs/editor_generate_map.cpp
     gui/dialogs/editor_new_map.cpp
     gui/dialogs/editor_resize_map.cpp
+    gui/dialogs/editor_set_starting_position.cpp
     gui/dialogs/editor_settings.cpp
     gui/dialogs/folder_create.cpp
     gui/dialogs/formula_debugger.cpp

Modified: trunk/src/editor/mouse_action.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor/mouse_action.cpp?rev=51691&r1=51690&r2=51691&view=diff
==============================================================================
--- trunk/src/editor/mouse_action.cpp (original)
+++ trunk/src/editor/mouse_action.cpp Fri Oct 28 04:12:15 2011
@@ -21,7 +21,7 @@
 
 #include "../construct_dialog.hpp"
 #include "../gettext.hpp"
-
+#include "../gui/dialogs/editor_set_starting_position.hpp"
 
 namespace editor {
 
@@ -421,27 +421,35 @@
        if (!disp.map().on_board(hex)) {
                return NULL;
        }
-       int player_starting_at_hex = disp.map().is_starting_position(hex) + 1;
-       std::vector<std::string> players;
-       players.push_back(_("(Player)^None"));
-       for (int i = 1; i <= gamemap::MAX_PLAYERS; i++) {
-               std::stringstream str;
-               str << _("Player") << " " << i;
-               players.push_back(str.str());
-       }
-       gui::dialog pmenu = gui::dialog(disp,
-                                      _("Choose player"),
-                                      _("Which player should start here? You 
can use alt and a number key to set the starting position for a player, and del 
to clear the starting position under the cursor. Pressing a number key by 
itself will scroll to that player’s starting position."),
-                                      gui::OK_CANCEL);
-       pmenu.set_menu(players);
-       int res = pmenu.show();
+
+       const unsigned player_starting_at_hex =
+               static_cast<unsigned>(disp.map().is_starting_position(hex) + 
1); // 1st player = 1
+
+       std::vector<map_location> starting_positions;
+       
+       for(int i = 1; i <= gamemap::MAX_PLAYERS; ++i) {
+               starting_positions.push_back(disp.map().starting_position(i));
+       }
+
+       gui2::teditor_set_starting_position dlg(
+               player_starting_at_hex, gamemap::MAX_PLAYERS, 
starting_positions);
+       dlg.show(disp.video());
+
+       unsigned new_player_at_hex = dlg.result(); // 1st player = 1
        editor_action* a = NULL;
-       if (res == 0 && player_starting_at_hex != -1) {
-               a = new editor_action_starting_position(map_location(), 
player_starting_at_hex);
-       } else if (res > 0 && res != player_starting_at_hex) {
-               a = new editor_action_starting_position(hex, res);
-       }
+
+       if(new_player_at_hex != player_starting_at_hex) {
+               if(!new_player_at_hex) {
+                       // Erase current starting position
+                       a = new editor_action_starting_position(map_location(), 
player_starting_at_hex);
+               } else {
+                       // Set a starting position
+                       a = new editor_action_starting_position(hex, 
new_player_at_hex);
+               }
+       }
+
        update_brush_highlights(disp, hex);
+
        return a;
 }
 

Added: trunk/src/gui/dialogs/editor_set_starting_position.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/editor_set_starting_position.cpp?rev=51691&view=auto
==============================================================================
--- trunk/src/gui/dialogs/editor_set_starting_position.cpp (added)
+++ trunk/src/gui/dialogs/editor_set_starting_position.cpp Fri Oct 28 04:12:15 
2011
@@ -1,0 +1,120 @@
+/* $Id$ */
+/*
+   Copyright (C) 2011 by Ignacio Riquelme Morelle <[email protected]>
+   Part of the Battle for Wesnoth Project http://www.wesnoth.org/
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY.
+
+   See the COPYING file for more details.
+*/
+
+#define GETTEXT_DOMAIN "wesnoth-editor"
+
+#include "gui/dialogs/editor_set_starting_position.hpp"
+
+#include "foreach.hpp"
+#include "formatter.hpp"
+#include "formula_string_utils.hpp"
+#include "gettext.hpp"
+#ifdef GUI2_EXPERIMENTAL_LISTBOX
+       #include "gui/widgets/list.hpp"
+#else
+       #include "gui/widgets/listbox.hpp"
+#endif
+#include "gui/widgets/settings.hpp"
+#include "gui/widgets/window.hpp"
+#include "map_location.hpp"
+
+namespace gui2 {
+
+/*WIKI
+ * @page = GUIWindowDefinitionWML
+ * @order = 2_editor_set_starting_position
+ *
+ * == Editor set starting position ==
+ *
+ * Map editor dialog for setting player starting positions.
+ *
+ * @begin{table}{dialog_widgets}
+ * 
+ * listbox & & listbox & m &
+ *         Listbox displaying player choices. $
+ *
+ * -player & & control & m &
+ *         Widget which shows a player item label. $
+ *
+ * -location & & control & m &
+ *         Widget which shows the coordinates to the current
+ *         starting position for a player if it exists. $
+ *
+ * ok & & button & m &
+ *         OK button. $
+ *
+ * cancel & & button & m &
+ *         Cancel button. $
+ *
+ * @end{table}
+ */
+
+REGISTER_DIALOG(editor_set_starting_position)
+
+teditor_set_starting_position::teditor_set_starting_position(unsigned 
current_player, unsigned maximum_players, const std::vector<map_location>& 
starting_positions)
+       : players_(maximum_players)
+       , selection_(std::min(current_player, maximum_players))
+       , starting_positions_(starting_positions)
+{
+       if(starting_positions_.size() != maximum_players) {
+               starting_positions_.resize(maximum_players);
+       }
+}
+
+void teditor_set_starting_position::pre_show(CVideo& /*video*/, twindow& 
window)
+{
+       tlistbox& list = find_widget<tlistbox>(&window, "listbox", false);
+       window.keyboard_capture(&list);
+
+       std::map<std::string, string_map> data;
+       string_map column;
+
+       column["label"] = _("player^None");
+       data.insert(std::make_pair("player", column));
+       list.add_row(data);
+
+       for(unsigned i = 0; i < starting_positions_.size(); ++i) {
+               const map_location& player_pos = starting_positions_[i];
+
+               data.clear();
+
+               utils::string_map symbols;
+               symbols["player_number"] = str_cast(i + 1);
+
+               column["label"] = 
utils::interpolate_variables_into_string(_("Player $player_number"), &symbols);
+               data.insert(std::make_pair("player", column));
+
+               if(player_pos.valid()) {
+                       column["label"] = (formatter() << "(" << player_pos.x + 
1 << ", " << player_pos.y + 1 << ")").str();
+                       data.insert(std::make_pair("location", column));
+               }
+
+               list.add_row(data);
+       }
+
+       list.select_row(selection_);
+}
+
+void teditor_set_starting_position::post_show(twindow& window)
+{
+       if(get_retval() != twindow::OK) {
+               return;
+       }
+
+       tlistbox& list = find_widget<tlistbox>(&window, "listbox", false);
+       selection_ = list.get_selected_row();
+}
+
+}

Added: trunk/src/gui/dialogs/editor_set_starting_position.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/editor_set_starting_position.hpp?rev=51691&view=auto
==============================================================================
--- trunk/src/gui/dialogs/editor_set_starting_position.hpp (added)
+++ trunk/src/gui/dialogs/editor_set_starting_position.hpp Fri Oct 28 04:12:15 
2011
@@ -1,0 +1,50 @@
+/* $Id$ */
+/*
+   Copyright (C) 2011 by Ignacio Riquelme Morelle <[email protected]>
+   Part of the Battle for Wesnoth Project http://www.wesnoth.org/
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY.
+
+   See the COPYING file for more details.
+*/
+
+#ifndef GUI_DIALOGS_EDITOR_SET_STARTING_POSITION_HPP_INCLUDED
+#define GUI_DIALOGS_EDITOR_SET_STARTING_POSITION_HPP_INCLUDED
+
+#include "gui/dialogs/dialog.hpp"
+
+#include <vector>
+
+struct map_location;
+
+namespace gui2 {
+
+class teditor_set_starting_position : public tdialog
+{
+public:
+       teditor_set_starting_position(unsigned current_player, unsigned 
maximum_players, const std::vector<map_location>& starting_positions);
+
+       unsigned result() const { return selection_; }
+
+private:
+       unsigned players_, selection_;
+       std::vector<map_location> starting_positions_;
+
+       /** Inherited from tdialog, implemented by REGISTER_DIALOG. */
+       virtual const std::string& window_id() const;
+
+       /** Inherited from tdialog. */
+       void pre_show(CVideo& video, twindow& window);
+
+       /** Inherited from tdialog. */
+       void post_show(twindow& window);
+};
+
+}
+
+#endif /* ! GUI_DIALOGS_EDITOR_SET_STARTING_POSITION_HPP_INCLUDED */


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to