mail[Wesnoth-commits] r28687 - 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 17, 2008 - 20:32:
Author: ilor
Date: Sun Aug 17 20:24:02 2008
New Revision: 28687

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28687&view=rev
Log:
editor2: random map generation

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

Modified: trunk/data/gui/default/window/editor_generate_map.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/window/editor_generate_map.cfg?rev=28687&r1=28686&r2=28687&view=diff
==============================================================================
--- trunk/data/gui/default/window/editor_generate_map.cfg (original)
+++ trunk/data/gui/default/window/editor_generate_map.cfg Sun Aug 17 20:24:02 
2008
@@ -51,7 +51,7 @@
                                                                border_size = 
5
                                                                
horizontal_alignment = "right"
                                                                [button]
-                                                                       id = 
"generate"
+                                                                       id = 
"ok"
                                                                        
definition = "default"
                                                                        label 
= _ "Generate"
                                                                [/button]

Modified: trunk/src/editor2/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28687&r1=28686&r2=28687&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Sun Aug 17 20:24:02 2008
@@ -37,6 +37,7 @@
 #include "../map_create.hpp"
 #include "../mapgen.hpp"
 #include "../preferences.hpp"
+#include "../random.hpp"
 #include "../wml_exception.hpp"
 
 #include "SDL.h"
@@ -53,13 +54,15 @@
 
 editor_controller::editor_controller(const config &game_config, CVideo& 
video)
 : controller_base(SDL_GetTicks(), game_config, video)
-, mouse_handler_base(get_map())
+, mouse_handler_base(get_map()), rng_(NULL), rng_setter_(NULL)
 , map_context_(editor_map(game_config, 44, 33, t_translation::GRASS_LAND))
 , gui_(NULL), map_generator_(NULL), tooltip_manager_(video), 
floating_label_manager_(NULL)
 , do_quit_(false), quit_mode_(EXIT_ERROR)
 , toolbar_dirty_(true), auto_update_transitions_(true)
 {
        init(video);
+       rng_ = new rand_rng::rng();
+       rng_setter_ = new rand_rng::set_random_generator(rng_);
        floating_label_manager_ = new font::floating_label_context();
        size_specs_ = new size_specs();
        adjust_sizes(gui(), *size_specs_);
@@ -148,6 +151,8 @@
                delete a.second;
        }
        delete prefs_disp_manager_;
+       delete rng_setter_;
+       delete rng_;
 }
 
 EXIT_STATUS editor_controller::main_loop()
@@ -260,11 +265,23 @@
                        map_generator_ = create_map_generator("", cfg);
                }
        }
-       if (!confirm_discard()) return;
        gui2::teditor_generate_map dialog;
+       dialog.set_map_generator(map_generator_);
+       dialog.set_gui(&gui());
        dialog.show(gui().video());
-       if (map_generator_->allow_user_config()) {
-               map_generator_->user_config(gui());
+       
+       int res = dialog.get_retval();
+       if(res == gui2::twindow::OK) {
+               if (!confirm_discard()) return;
+               std::string map_string =
+                       
map_generator_->create_map(std::vector<std::string>());
+               if (map_string.empty()) {
+                       gui::message_dialog(gui(), "",
+                                                        _("Map creation 
failed.")).show();
+               } else {
+                       editor_map new_map(game_config_, map_string);
+                       set_map(new_map);
+               }
        }
 }
 

Modified: trunk/src/editor2/editor_controller.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=28687&r1=28686&r2=28687&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Sun Aug 17 20:24:02 2008
@@ -42,6 +42,11 @@
 
 namespace font {
 class floating_label_context;
+}
+
+namespace rand_rng {
+class rng;
+class set_random_generator;
 }
 
 namespace editor2 {
@@ -266,6 +271,10 @@
                 */
                void redo();
                
+               rand_rng::rng* rng_;
+               
+               rand_rng::set_random_generator* rng_setter_;
+               
                /** The current map object */
                map_context map_context_;
                

Modified: trunk/src/gui/dialogs/editor_generate_map.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/editor_generate_map.cpp?rev=28687&r1=28686&r2=28687&view=diff
==============================================================================
--- trunk/src/gui/dialogs/editor_generate_map.cpp (original)
+++ trunk/src/gui/dialogs/editor_generate_map.cpp Sun Aug 17 20:24:02 2008
@@ -14,6 +14,8 @@
 
 #include "gui/dialogs/editor_generate_map.hpp"
 
+#include "gui/dialogs/helper.hpp"
+
 #include "gui/widgets/button.hpp"
 #include "gui/widgets/widget.hpp"
 #include "gui/widgets/window.hpp"
@@ -21,17 +23,26 @@
 #include "gui/widgets/settings.hpp"
 #include "gui/widgets/text_box.hpp"
 #include "log.hpp"
+#include "mapgen.hpp"
 #include "wml_exception.hpp"
-
 #define DBG_GUI LOG_STREAM_INDENT(debug, gui)
 #define LOG_GUI LOG_STREAM_INDENT(info, gui)
 #define WRN_GUI LOG_STREAM_INDENT(warn, gui)
 #define ERR_GUI LOG_STREAM_INDENT(err, gui)
+#define ERR_ED LOG_STREAM_INDENT(err, editor)
 
 namespace gui2 {
 
 teditor_generate_map::teditor_generate_map()
+: map_generator_(NULL), gui_(NULL)
 {
+}
+
+void teditor_generate_map::do_settings(twindow& window)
+{
+       if (map_generator_->allow_user_config()) {
+               map_generator_->user_config(*gui_);
+       }
 }
 
 twindow teditor_generate_map::build_window(CVideo& video)
@@ -39,8 +50,13 @@
        return build(video, get_id(EDITOR_GENERATE_MAP));
 }
 
-void teditor_generate_map::pre_show(CVideo& /*video*/, twindow& /*window*/)
+void teditor_generate_map::pre_show(CVideo& /*video*/, twindow& window)
 {
+       assert(map_generator_);
+       assert(gui_);
+       tbutton& settings_button = window.get_widget<tbutton>("settings", 
false);
+       settings_button.set_callback_mouse_left_click(
+               dialog_callback<teditor_generate_map, 
&teditor_generate_map::do_settings>);
 }
 
 void teditor_generate_map::post_show(twindow& /*window*/)

Modified: trunk/src/gui/dialogs/editor_generate_map.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/editor_generate_map.hpp?rev=28687&r1=28686&r2=28687&view=diff
==============================================================================
--- trunk/src/gui/dialogs/editor_generate_map.hpp (original)
+++ trunk/src/gui/dialogs/editor_generate_map.hpp Sun Aug 17 20:24:02 2008
@@ -17,12 +17,24 @@
 
 #include "gui/dialogs/dialog.hpp"
 
+class map_generator;
+
+class display;
+
 namespace gui2 {
 
 class teditor_generate_map : public tdialog
 {
 public:
        teditor_generate_map();
+       
+       void do_settings(twindow& window);
+       
+       void set_map_generator(map_generator* mg) { map_generator_ = mg; }
+       map_generator* get_map_generator() { return map_generator_; }
+       
+       void set_gui(display* d) { gui_ = d; }
+       display* get_gui() { return gui_; }
        
 private:
        /** Inherited from tdialog. */
@@ -33,6 +45,10 @@
 
        /** Inherited from tdialog. */
        void post_show(twindow& window);
+       
+       map_generator* map_generator_;
+       
+       display* gui_;
 };
 
 } // namespace gui2




Related Messages


Powered by MHonArc, Updated Sun Aug 17 20:42:06 2008