Author: ilor
Date: Tue Jul 15 18:12:56 2008
New Revision: 28044

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28044&view=rev
Log:
editor map loading 

Modified:
    trunk/src/editor2/editor_controller.cpp
    trunk/src/editor2/editor_controller.hpp

Modified: trunk/src/editor2/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28044&r1=28043&r2=28044&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Tue Jul 15 18:12:56 2008
@@ -15,11 +15,17 @@
 #include "editor_display.hpp"
 #include "editor_map.hpp"
 #include "mouse_action.hpp"
+
 #include "../config_adapter.hpp"
+#include "../construct_dialog.hpp"
 #include "../cursor.hpp"
+#include "../file_chooser.hpp"
+#include "../filesystem.hpp"
 #include "../foreach.hpp"
+#include "../gettext.hpp"
 #include "../hotkeys.hpp"
 #include "../preferences.hpp"
+#include "../wml_exception.hpp"
 
 #include "SDL.h"
 
@@ -44,6 +50,7 @@
        events::raise_draw_event();
        
        brushes_.push_back(brush());
+       brushes_[0].add_relative_location(0, 0);
        const config::child_list& children = game_config.get_children("brush");
        foreach (const config* i, game_config.get_children("brush")) {
                brushes_.push_back(brush(*i));
@@ -83,6 +90,43 @@
        for(;;) {
                play_slice();
        }
+}
+
+void editor_controller::load_map_dialog()
+{
+       std::string filename_;
+       std::string fn = filename_.empty() ? 
get_dir(get_dir(get_user_data_dir() + "/editor") + "/maps") : filename_;
+       int res = dialogs::show_file_chooser_dialog(gui(), fn, _("Choose a Map 
to Load"));
+       if (res == 0) {
+               load_map(fn);
+       }
+}
+
+void editor_controller::load_map(const std::string& filename)
+{
+       std::string map_string = read_file(filename);
+       try {
+               editor_map new_map(game_config_, map_string);
+               set_map(new_map);
+       } catch (gamemap::incorrect_format_exception& e) {
+               std::string message = "There was an error while loading the 
map: \n";
+               message += e.msg_;
+               gui::message_dialog(gui(), "Error loading map", message).show();
+               return;
+       } catch (twml_exception& e) {
+               std::string message = "There was an error while loading the 
map: \n";
+               message += e.user_message;
+               gui::message_dialog(gui(), "Error loading map", message).show();
+               return;
+       }
+}
+
+void editor_controller::set_map(const editor_map& map)
+{
+       map_ = map;
+       clear_stack(undo_stack_);
+       clear_stack(redo_stack_);
+       refresh_all();
 }
 
 bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, 
int /*index*/) const
@@ -162,8 +206,12 @@
                                        next = &brushes_[0];
                                }
                                set_brush(next);
-                               gui().invalidate_all();
+                               refresh_all();
+                               gui().draw();
                        }
+                       return true;
+               case HOTKEY_EDITOR_MAP_LOAD:
+                       load_map_dialog();
                        return true;
                default:
                        return controller_base::execute_command(command, index);
@@ -192,8 +240,6 @@
 {
        return *gui_;
 }
-
-
 
 void editor_controller::perform_action(const editor_action& action)
 {
@@ -218,6 +264,11 @@
 void editor_controller::refresh_after_action(const editor_action& /*action*/)
 {
        //TODO rebuild and ivalidate only what's really needed
+       refresh_all();
+}
+
+void editor_controller::refresh_all()
+{
        gui().rebuild_all();
        gui().invalidate_all();
        gui().recalculate_minimap();

Modified: trunk/src/editor2/editor_controller.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=28044&r1=28043&r2=28044&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Tue Jul 15 18:12:56 2008
@@ -43,6 +43,9 @@
                editor_controller(const config &game_config, CVideo& video);
                ~editor_controller();
                void main_loop();
+               void load_map_dialog();
+               void load_map(const std::string& filename);
+               void set_map(const editor_map& map);
                bool can_execute_command(hotkey::HOTKEY_COMMAND, int index = 
-1) const;
                bool execute_command(hotkey::HOTKEY_COMMAND command, int index 
= -1);
                void preferences();
@@ -76,6 +79,8 @@
                void perform_partial_action(const editor_action& action);
 
                void refresh_after_action(const editor_action& action);
+               
+               void refresh_all();
 
                /**
                 * Checks if an action stack reached its capacity and removes 
the front element if so.


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

Reply via email to