mail[Wesnoth-commits] r28410 - in /trunk: data/gui/default/window/ src/editor2/ src/gui/dialogs/


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by kailoran on August 09, 2008 - 19:41:
Author: ilor
Date: Sat Aug  9 18:32:45 2008
New Revision: 28410

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28410&view=rev
Log:
editor2: allow resizing the map in any direction, the dialog needs some more 
work (use icons instead of text in the descriptions). Also use the map sizes 
sans the border in dialogs.

Modified:
    trunk/data/gui/default/window/editor_resize_map.cfg
    trunk/src/editor2/action.cpp
    trunk/src/editor2/action.hpp
    trunk/src/editor2/editor_controller.cpp
    trunk/src/editor2/editor_map.cpp
    trunk/src/gui/dialogs/editor_resize_map.cpp
    trunk/src/gui/dialogs/editor_resize_map.hpp

Modified: trunk/data/gui/default/window/editor_resize_map.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/window/editor_resize_map.cfg?rev=28410&r1=28409&r2=28410&view=diff
==============================================================================
--- trunk/data/gui/default/window/editor_resize_map.cfg (original)
+++ trunk/data/gui/default/window/editor_resize_map.cfg Sat Aug  9 18:32:45 
2008
@@ -135,6 +135,115 @@
                                [/column]
                        [/row]
                        [row]
+                               [column]
+                                       [label]
+                                               definition = "default"
+                                               label = _ "Expand / shrink 
direction"
+                                       [/label]
+                               [/column]
+                       [/row]
+                       [row]
+                               [column]
+                                       [grid]
+                                               [row]
+                                                       grow_factor = 1
+                                                       [column]
+                                                               grow_factor = 0
+                                                               
[toggle_button]
+                                                                       id = 
"expand0"
+                                                                       
definition = "default"
+                                                                       label 
= "Bottom / right"
+                                                               
[/toggle_button]
+                                                       [/column]
+                                                       [column]
+                                                               grow_factor = 0
+                                                               
[toggle_button]
+                                                                       id = 
"expand1"
+                                                                       
definition = "default"
+                                                                       label 
= "Bottom / center"
+                                                               
[/toggle_button]
+                                                       [/column]
+                                                       [column]
+                                                               grow_factor = 0
+                                                               
[toggle_button]
+                                                                       id = 
"expand2"
+                                                                       
definition = "default"
+                                                                       label 
= "Bottom / left"
+                                                               
[/toggle_button]
+                                                       [/column]
+                                               [/row]
+                                               [row]
+                                                       grow_factor = 1
+                                                       [column]
+                                                               grow_factor = 0
+                                                               
[toggle_button]
+                                                                       id = 
"expand3"
+                                                                       
definition = "default"
+                                                                       label 
= "Center / right"
+                                                               
[/toggle_button]
+                                                       [/column]
+                                                       [column]
+                                                               grow_factor = 0
+                                                               
[toggle_button]
+                                                                       id = 
"expand4"
+                                                                       
definition = "default"
+                                                                       label 
= "Center"
+                                                               
[/toggle_button]
+                                                       [/column]
+                                                       [column]
+                                                               grow_factor = 0
+                                                               
[toggle_button]
+                                                                       id = 
"expand5"
+                                                                       
definition = "default"
+                                                                       label 
= "Center / left"
+                                                               
[/toggle_button]
+                                                       [/column]
+                                               [/row]
+                                               [row]
+                                                       grow_factor = 1
+                                                       [column]
+                                                               grow_factor = 0
+                                                               
[toggle_button]
+                                                                       id = 
"expand6"
+                                                                       
definition = "default"
+                                                                       label 
= "Top / right"
+                                                               
[/toggle_button]
+                                                       [/column]
+                                                       [column]
+                                                               grow_factor = 0
+                                                               
[toggle_button]
+                                                                       id = 
"expand7"
+                                                                       
definition = "default"
+                                                                       label 
= "Top / center"
+                                                               
[/toggle_button]
+                                                       [/column]
+                                                       [column]
+                                                               grow_factor = 0
+                                                               
[toggle_button]
+                                                                       id = 
"expand8"
+                                                                       
definition = "default"
+                                                                       label 
= "Top / left"
+                                                               
[/toggle_button]
+                                                       [/column]
+                                               [/row]
+                                       [/grid]
+                               [/column]
+                       [/row]                  
+                       [row]
+                               [column]
+                                       grow_factor = 1
+                                       horizontal_grow = "true"
+                                       border = "all"
+                                       border_size = 5
+                                       horizontal_alignment = "right"
+                                       [toggle_button]
+                                               id = "copy_edge_terrain"
+                                               definition = "default"
+                                               label = _ "Copy edge terrain"
+                                       [/toggle_button]
+                               [/column]
+                       [/row]
+                       [row]
                                grow_factor = 0
                                [column]
                                        grow_factor = 1

Modified: trunk/src/editor2/action.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.cpp?rev=28410&r1=28409&r2=28410&view=diff
==============================================================================
--- trunk/src/editor2/action.cpp (original)
+++ trunk/src/editor2/action.cpp Sat Aug  9 18:32:45 2008
@@ -248,7 +248,7 @@
 
 void editor_action_resize_map::perform_without_undo(map_context& mc) const
 {
-       mc.get_map().resize(x_size_, y_size_, x_offset_, y_offset_);
+       mc.get_map().resize(x_size_, y_size_, x_offset_, y_offset_, fill_);
        mc.set_needs_reload();
 }
 

Modified: trunk/src/editor2/action.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.hpp?rev=28410&r1=28409&r2=28410&view=diff
==============================================================================
--- trunk/src/editor2/action.hpp (original)
+++ trunk/src/editor2/action.hpp Sat Aug  9 18:32:45 2008
@@ -233,8 +233,9 @@
 class editor_action_resize_map : public editor_action
 {
        public:
-               editor_action_resize_map(int x_size, int y_size, int 
x_offset, int y_offset)
-               : x_size_(x_size), y_size_(y_size), x_offset_(x_offset), 
y_offset_(y_offset)
+               editor_action_resize_map(int x_size, int y_size, int 
x_offset, int y_offset,
+                       t_translation::t_terrain fill = 
t_translation::NONE_TERRAIN)
+               : x_size_(x_size), y_size_(y_size), x_offset_(x_offset), 
y_offset_(y_offset), fill_(fill)
                {
                }
                void perform_without_undo(map_context& mc) const;
@@ -243,6 +244,7 @@
                int y_size_;
                int x_offset_;
                int y_offset_;
+               t_translation::t_terrain fill_;
 };
 
 //basic rotations. angle is multiplied by 90 degrees so 2 does a 180 turn

Modified: trunk/src/editor2/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28410&r1=28409&r2=28410&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Sat Aug  9 18:32:45 2008
@@ -68,6 +68,7 @@
                WRN_ED << "No brushes defined!";
        }
        brush_ = &brushes_[0];
+       
        
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_PAINT, 
                new mouse_action_paint(foreground_terrain_, &brush_, key_)));
        mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_FILL, 
@@ -79,6 +80,9 @@
        mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_PASTE,
                new mouse_action_paste(clipboard_)));
        hotkey_set_mouse_action(hotkey::HOTKEY_EDITOR_TOOL_PAINT);      
+       
+       background_terrain_ = t_translation::GRASS_LAND;
+       foreground_terrain_ = t_translation::MOUNTAIN;
        get_map_context().set_starting_position_labels(gui());
        cursor::set(cursor::NORMAL);
        gui_->invalidate_game_status();
@@ -162,8 +166,8 @@
 {
        if (!confirm_discard()) return;
        gui2::teditor_new_map dialog;
-       dialog.set_map_width(get_map().total_width());
-       dialog.set_map_height(get_map().total_height());
+       dialog.set_map_width(get_map().w());
+       dialog.set_map_height(get_map().h());
        
        dialog.show(gui().video());
        int res = dialog.get_retval();
@@ -230,20 +234,64 @@
 void editor_controller::resize_map_dialog()
 {
        gui2::teditor_resize_map dialog;
-       dialog.set_map_width(get_map().total_width());
-       dialog.set_map_height(get_map().total_height());
-       dialog.set_old_map_width(get_map().total_width());
-       dialog.set_old_map_height(get_map().total_height());
+       dialog.set_map_width(get_map().w());
+       dialog.set_map_height(get_map().h());
+       dialog.set_old_map_width(get_map().w());
+       dialog.set_old_map_height(get_map().h());
        
        dialog.show(gui().video());
        int res = dialog.get_retval();
        if(res == gui2::twindow::OK) {
                int w = dialog.map_width();
                int h = dialog.map_height();
-               t_translation::t_terrain fill = t_translation::GRASS_LAND;
-               editor_action_resize_map a(w, h, 0, 0);
-               get_map_context().perform_action(a);
-               refresh_after_action();
+               if (w != get_map().w() || h != get_map().h()) {
+                       t_translation::t_terrain fill = background_terrain_;
+                       if (dialog.copy_edge_terrain()) {
+                               fill = t_translation::NONE_TERRAIN;
+                       }
+                       int x_offset = get_map().w() - w;
+                       int y_offset = get_map().h() - h;
+                       switch (dialog.expand_direction()) {
+                               case 
gui2::teditor_resize_map::EXPAND_BOTTOM_RIGHT:
+                               case gui2::teditor_resize_map::EXPAND_BOTTOM:
+                               case 
gui2::teditor_resize_map::EXPAND_BOTTOM_LEFT:
+                                       y_offset = 0;
+                                       break;
+                               case gui2::teditor_resize_map::EXPAND_RIGHT:
+                               case gui2::teditor_resize_map::EXPAND_CENTER:
+                               case gui2::teditor_resize_map::EXPAND_LEFT:
+                                       y_offset /= 2;
+                                       break;
+                               case 
gui2::teditor_resize_map::EXPAND_TOP_RIGHT:
+                               case gui2::teditor_resize_map::EXPAND_TOP:
+                               case 
gui2::teditor_resize_map::EXPAND_TOP_LEFT:
+                                       break;
+                               default:
+                                       y_offset = 0;
+                                       WRN_ED << "Unknown resize expand 
direction\n";
+                       }
+                       switch (dialog.expand_direction()) {
+                               case 
gui2::teditor_resize_map::EXPAND_BOTTOM_RIGHT:
+                               case gui2::teditor_resize_map::EXPAND_RIGHT:
+                               case 
gui2::teditor_resize_map::EXPAND_TOP_RIGHT:
+                                       x_offset = 0;
+                                       break;
+                               case gui2::teditor_resize_map::EXPAND_BOTTOM:
+                               case gui2::teditor_resize_map::EXPAND_CENTER:
+                               case gui2::teditor_resize_map::EXPAND_TOP:
+                                       x_offset /= 2;
+                                       break;
+                               case 
gui2::teditor_resize_map::EXPAND_BOTTOM_LEFT:
+                               case gui2::teditor_resize_map::EXPAND_LEFT:
+                               case 
gui2::teditor_resize_map::EXPAND_TOP_LEFT:
+                                       break;
+                               default:
+                                       x_offset = 0;
+                       }
+                       editor_action_resize_map a(w, h, x_offset, y_offset, 
fill);
+                       get_map_context().perform_action(a);
+                       refresh_after_action();
+               }
        }
 }
 

Modified: trunk/src/editor2/editor_map.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_map.cpp?rev=28410&r1=28409&r2=28410&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.cpp (original)
+++ trunk/src/editor2/editor_map.cpp Sat Aug  9 18:32:45 2008
@@ -35,7 +35,7 @@
 
 editor_map::editor_map(const config& terrain_cfg, size_t width, size_t 
height, t_translation::t_terrain filler)
 : gamemap(terrain_cfg, gamemap::default_map_header + 
t_translation::write_game_map(
-       t_translation::t_map(width, t_translation::t_list(height, filler))))
+       t_translation::t_map(width + 2, t_translation::t_list(height + 2, 
filler))))
 {
        sanity_check();
 }
@@ -159,8 +159,8 @@
 void editor_map::resize(int width, int height, int x_offset, int y_offset,
        t_translation::t_terrain filler)
 {
-       int old_w = total_width();
-       int old_h = total_height();
+       int old_w = w();
+       int old_h = h();
        if (old_w == width && old_h == height && x_offset == 0 && y_offset == 
0) {
                return;
        }

Modified: trunk/src/gui/dialogs/editor_resize_map.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/editor_resize_map.cpp?rev=28410&r1=28409&r2=28410&view=diff
==============================================================================
--- trunk/src/gui/dialogs/editor_resize_map.cpp (original)
+++ trunk/src/gui/dialogs/editor_resize_map.cpp Sat Aug  9 18:32:45 2008
@@ -21,6 +21,7 @@
 #include "gui/widgets/listbox.hpp"
 #include "gui/widgets/settings.hpp"
 #include "gui/widgets/text_box.hpp"
+#include "gui/widgets/toggle_button.hpp"
 #include "gui/widgets/slider.hpp"
 #include "gui/widgets/window.hpp"
 #include "gui/widgets/window_builder.hpp"
@@ -37,9 +38,20 @@
 
 namespace gui2 {
 
+static void callback_expand_direction_changed(twidget* caller)
+{
+       teditor_resize_map* dialog = 
dynamic_cast<teditor_resize_map*>(caller->dialog());
+       assert(dialog);
+       twindow* window = dynamic_cast<twindow*>(caller->get_window());
+       assert(window);
+       dialog->update_expand_direction(*window);       
+}
+
 teditor_resize_map::teditor_resize_map() :
        map_width_(register_integer("width", false)),
-       map_height_(register_integer("height", false))
+       map_height_(register_integer("height", false)),
+       copy_edge_terrain_(register_bool("copy_edge_terrain", false)),
+       expand_direction_(EXPAND_BOTTOM_RIGHT)
 {
 }
 
@@ -73,6 +85,11 @@
        old_height_ = value;
 }
 
+bool teditor_resize_map::copy_edge_terrain() const
+{
+       return copy_edge_terrain_->get_value();
+}
+
 twindow teditor_resize_map::build_window(CVideo& video)
 {
        return build(video, get_id(EDITOR_RESIZE_MAP));
@@ -86,7 +103,34 @@
        VALIDATE(old_height, missing_widget("old_height"));
        old_width->set_label(lexical_cast<std::string>(old_width_));
        old_height->set_label(lexical_cast<std::string>(old_height_));
+       
+       std::string name_prefix = "expand";
+       for (int i = 0; i < 9; ++i) {
+               std::string name = name_prefix + lexical_cast<std::string>(i);
+               direction_buttons_[i] = 
dynamic_cast<ttoggle_button*>(window.find_widget(name, false));
+               VALIDATE(direction_buttons_[i], missing_widget(name));        
  
+               
direction_buttons_[i]->set_callback_state_change(callback_expand_direction_changed);
+       }
+       
        window.recalculate_size();
 }
 
+void teditor_resize_map::update_expand_direction(twindow& window)
+{
+       std::string name_prefix = "expand";
+       for (int i = 0; i < 9; ++i) {
+               if (direction_buttons_[i]->get_value() && 
static_cast<int>(expand_direction_) != i) {
+                       expand_direction_ = static_cast<EXPAND_DIRECTION>(i);
+                       break;
+               }
+       }
+       for (int i = 0; i < static_cast<int>(expand_direction_); ++i) {
+               direction_buttons_[i]->set_value(false);
+       }
+       direction_buttons_[expand_direction_]->set_value(true);
+       for (int i = expand_direction_ + 1; i < 9; ++i) {
+               direction_buttons_[i]->set_value(false);
+       }
+}
+
 } // namespace gui2

Modified: trunk/src/gui/dialogs/editor_resize_map.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/editor_resize_map.hpp?rev=28410&r1=28409&r2=28410&view=diff
==============================================================================
--- trunk/src/gui/dialogs/editor_resize_map.hpp (original)
+++ trunk/src/gui/dialogs/editor_resize_map.hpp Sat Aug  9 18:32:45 2008
@@ -19,6 +19,8 @@
 
 namespace gui2 {
 
+class ttoggle_button;
+
 class teditor_resize_map : public tdialog
 {
 public:
@@ -29,9 +31,9 @@
        void set_map_height(int value);
        int map_height() const;
        void set_old_map_width(int value);
-       int old_map_width() const;
        void set_old_map_height(int value);
-       int old_map_height() const;
+       bool copy_edge_terrain() const;
+       
        enum EXPAND_DIRECTION {
                EXPAND_BOTTOM_RIGHT,
                EXPAND_BOTTOM,
@@ -43,8 +45,10 @@
                EXPAND_TOP,
                EXPAND_TOP_LEFT
        };
+       EXPAND_DIRECTION expand_direction() { return expand_direction_; }
+       void set_expand_direction(EXPAND_DIRECTION direction) { 
expand_direction_ = direction; }
        
-       EXPAND_DIRECTION expand_direction() { return EXPAND_BOTTOM_RIGHT; }
+       void update_expand_direction(twindow& window);
 
 private:
        /**
@@ -53,14 +57,18 @@
         */
        tfield_integer* map_width_;
        tfield_integer* map_height_;
-       
+       tfield_bool* copy_edge_terrain_;
+       ttoggle_button* direction_buttons_[9];
        int old_width_;
        int old_height_;
+       
+       EXPAND_DIRECTION expand_direction_;
 
        /** Inherited from tdialog. */
        twindow build_window(CVideo& video);
        
        void pre_show(CVideo& video, twindow& window);
+       
 };
 
 } // namespace gui2




Related Messages


Powered by MHonArc, Updated Sat Aug 09 20:23:25 2008