editor/editor_controller.hpp

Go to the documentation of this file.
00001 /* $Id: editor_controller.hpp 53726 2012-03-31 18:16:27Z fendrin $ */
00002 /*
00003    Copyright (C) 2008 - 2012 by Tomasz Sniatowski <kailoran@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 #ifndef EDITOR_EDITOR_CONTROLLER_HPP_INCLUDED
00017 #define EDITOR_EDITOR_CONTROLLER_HPP_INCLUDED
00018 
00019 #include "editor_display.hpp"
00020 #include "editor_main.hpp"
00021 #include "map/map_context.hpp"
00022 #include "map/map_fragment.hpp"
00023 
00024 #include "editor/toolkit/editor_toolkit.hpp"
00025 
00026 #include "../controller_base.hpp"
00027 #include "../mouse_handler_base.hpp"
00028 #include "../tooltips.hpp"
00029 
00030 #include "editor/map/context_manager.hpp"
00031 
00032 class map_generator;
00033 
00034 namespace tooltips {
00035 struct manager;
00036 }
00037 
00038 namespace font {
00039 struct floating_label_context;
00040 }
00041 
00042 namespace rand_rng {
00043 class rng;
00044 struct set_random_generator;
00045 }
00046 
00047 namespace preferences {
00048     struct display_manager;
00049 } // namespace preferences
00050 
00051 namespace halo {
00052     struct manager;
00053 } // namespace halo
00054 
00055 namespace editor {
00056 
00057 class editor_map;
00058 
00059 std::string get_left_button_function();
00060 
00061 enum menu_type {
00062     MAP,
00063     PALETTE,
00064     AREA,
00065     SIDE
00066 };
00067 
00068 /**
00069  * The editor_controller class contains the mouse and keyboard event handling
00070  * routines for the editor. It also serves as the main editor class with the
00071  * general logic.
00072  */
00073 class editor_controller : public controller_base,
00074     public events::mouse_handler_base,
00075     private boost::noncopyable
00076 {
00077     public:
00078         /**
00079          * The constructor. A initial map context can be specified here, the controller
00080          * will assume ownership and delete the pointer during destruction, but changes
00081          * to the map can be retrieved between the main loop's end and the controller's
00082          * destruction.
00083          */
00084         editor_controller(const config &game_config, CVideo& video);
00085 
00086         ~editor_controller();
00087 
00088         /** Editor main loop */
00089         EXIT_STATUS main_loop();
00090 
00091         /** Takes a screenshot **/
00092         void do_screenshot(const std::string& screenshot_filename = "map_screenshot.bmp");
00093 
00094         /** Process a hotkey quit command */
00095         void hotkey_quit();
00096 
00097         /** Show a quit confirmation dialog and if confirmed quit with the given exit status */
00098         void quit_confirm(EXIT_STATUS status);
00099 
00100         /** Display the settings dialog, used to control e.g. the lighting settings */
00101         void editor_settings_dialog();
00102 
00103         /** Save the map, open dialog if not named yet. */
00104         void save_map() {context_manager_->save_map();};
00105 
00106         /** command_executor override */
00107         bool can_execute_command(hotkey::HOTKEY_COMMAND, int index = -1) const;
00108 
00109         /** command_executor override */
00110         hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command, int index) const;
00111 
00112         /** command_executor override */
00113         bool execute_command(hotkey::HOTKEY_COMMAND command, int index = -1);
00114 
00115         /** controller_base override */
00116         void show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu);
00117 
00118         /** Show the preferences dialog */
00119         void preferences();
00120 
00121         /** Grid toggle */
00122         void toggle_grid();
00123 
00124         /** Copy the selection on the current map to the clipboard */
00125         void copy_selection();
00126 
00127         /** Cut the selection from the current map to the clipboard */
00128         void cut_selection();
00129 
00130         /** Export the WML-compatible list of selected tiles to the system clipboard */
00131         void export_selection_coords();
00132 
00133         void update_mouse_action_highlights();
00134 
00135         /* mouse_handler_base overrides */
00136         void mouse_motion(int x, int y, const bool browse, bool update, map_location new_loc = map_location::null_location);
00137         editor_display& gui() { return *gui_; }
00138         const editor_display& gui() const { return *gui_; }
00139         bool allow_mouse_wheel_scroll(int x, int y);
00140         bool right_click_show_menu(int x, int y, const bool browse);
00141         bool left_click(int x, int y, const bool browse);
00142         void left_drag_end(int x, int y, const bool browse);
00143         void left_mouse_up(int x, int y, const bool browse);
00144         bool right_click(int x, int y, const bool browse);
00145         void right_drag_end(int x, int y, const bool browse);
00146         void right_mouse_up(int x, int y, const bool browse);
00147 
00148 
00149     protected:
00150         /* controller_base overrides */
00151         void process_keyup_event(const SDL_Event& event);
00152         mouse_handler_base& get_mouse_handler_base() { return *this; };
00153         editor_display& get_display() {return *gui_;};
00154 
00155         /** Get the current mouse action */
00156         mouse_action* get_mouse_action();
00157 
00158         /**
00159          * Perform an action, then delete the action object.
00160          * The pointer can be NULL, in which case nothing will happen.
00161          */
00162         void perform_delete(editor_action* action);
00163 
00164         /**
00165          * Peform an action on the current map_context, then refresh the display
00166          * and delete the pointer. The pointer can be NULL, in which case nothing will happen.
00167          */
00168         void perform_refresh_delete(editor_action* action, bool drag_part = false);
00169 
00170 
00171 
00172         /**
00173          * Callback for the editor settings dialog to allow on-the-fly
00174          * updating of the lighting display on the game map behing the dialog
00175          */
00176         void editor_settings_dialog_redraw_callback(int r, int g, int b);
00177 
00178     private:
00179 
00180         /** init the display object and general set-up */
00181         void init_gui();
00182 
00183         /** init the available time-of-day settings */
00184         void init_tods(const config& game_config);
00185 
00186         /** init background music for the editor */
00187         void init_music(const config& game_config);
00188 
00189         /** Load editor-specific tooltips */
00190         void load_tooltips();
00191 
00192         /** Reload images */
00193         void refresh_image_cache();
00194 
00195         /**
00196          * Callback function passed to display to be called on each redraw_everything run.
00197          * Redraws toolbar, brush bar and related items.
00198          */
00199         void display_redraw_callback(display&);
00200 
00201         /**
00202          * Undos an action in the current map context
00203          */
00204         void undo();
00205 
00206         /**
00207          * Redos an action in the current map context
00208          */
00209         void redo();
00210 
00211         editor::menu_type active_menu_;
00212 
00213         boost::scoped_ptr<rand_rng::rng> rng_;
00214 
00215         boost::scoped_ptr<rand_rng::set_random_generator> rng_setter_;
00216 
00217         unit_map units_;
00218 
00219         /** The display object used and owned by the editor. */
00220         boost::scoped_ptr<editor_display> gui_;
00221 
00222         std::vector<team> teams_;
00223 
00224         /** Pre-defined time of day lighting settings for the settings dialog */
00225         std::vector<time_of_day> tods_;
00226 
00227         /* managers */
00228     public:
00229         boost::scoped_ptr<context_manager> context_manager_;
00230     private:
00231         boost::scoped_ptr<editor_toolkit> toolkit_;
00232         boost::scoped_ptr<preferences::display_manager> prefs_disp_manager_;
00233         tooltips::manager tooltip_manager_;
00234         boost::scoped_ptr<font::floating_label_context> floating_label_manager_;
00235 
00236         boost::scoped_ptr<halo::manager> halo_manager_;
00237 
00238         /** Quit main loop flag */
00239         bool do_quit_;
00240         EXIT_STATUS quit_mode_;
00241 
00242 };
00243 
00244 } //end namespace editor
00245 
00246 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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