initial commit, lordsawar source, slightly modified
[lordsawar] / src / editor / main-window.h
1 //  Copyright (C) 2007 Ole Laursen
2 //  Copyright (C) 2007, 2008, 2009 Ben Asselstine
3 //
4 //  This program is free software; you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation; either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU Library General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program; if not, write to the Free Software
16 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
17 //  02110-1301, USA.
18
19 #ifndef GUI_MAIN_WINDOW_H
20 #define GUI_MAIN_WINDOW_H
21
22 #include <memory>
23 #include <vector>
24 #include <sigc++/signal.h>
25 #include <sigc++/trackable.h>
26 #include <gtkmm.h>
27
28 #include "map-tip-position.h"
29 #include "editorbigmap.h"
30 #include "RenamableLocation.h"
31
32 class EditorBigMap;
33 class SmallMap;
34 class GameScenario;
35 class CreateScenarioRandomize;
36
37 #include "UniquelyIdentified.h"
38
39 //! Scenario editor.  Edits a Scenario.
40 class MainWindow: public sigc::trackable
41 {
42  public:
43     MainWindow(std::string load_filename = "");
44     ~MainWindow();
45
46     void show();
47     void hide();
48
49     void init();
50     void show_initial_map();
51     Gtk::Window &get_window() { return *window; }
52
53
54  private:
55     Gtk::Window* window;
56     EditorBigMap* bigmap;
57     SmallMap* smallmap;
58     GameScenario* game_scenario;
59     CreateScenarioRandomize* d_create_scenario_names;
60
61     Gtk::DrawingArea *bigmap_drawingarea;
62     Gtk::EventBox *bigmap_eventbox;
63     Gtk::CheckMenuItem *fullscreen_menuitem;
64     Gtk::MenuItem *new_map_menuitem;
65     Gtk::MenuItem *load_map_menuitem;
66     Gtk::MenuItem *save_map_menuitem;
67     Gtk::MenuItem *save_map_as_menuitem;
68     Gtk::MenuItem *import_map_from_sav_menuitem;
69     Gtk::MenuItem *export_as_bitmap_menuitem;
70     Gtk::MenuItem *export_as_bitmap_no_game_objects_menuitem;
71     Gtk::MenuItem *validate_menuitem;
72     Gtk::MenuItem *quit_menuitem;
73     Gtk::MenuItem *edit_players_menuitem;
74     Gtk::MenuItem *edit_map_info_menuitem;
75     Gtk::MenuItem *toggle_tile_graphics_menuitem;
76     Gtk::MenuItem *toggle_grid_menuitem;
77     Gtk::MenuItem *smooth_map_menuitem;
78     Gtk::MenuItem *smooth_screen_menuitem;
79     Gtk::MenuItem *switch_sets_menuitem;
80     Gtk::MenuItem *edit_items_menuitem ;
81     Gtk::MenuItem *edit_rewards_menuitem;
82     Gtk::MenuItem *random_all_cities_menuitem;
83     Gtk::MenuItem *random_unnamed_cities_menuitem;
84     Gtk::MenuItem *random_all_ruins_menuitem;
85     Gtk::MenuItem *random_unnamed_ruins_menuitem;
86     Gtk::MenuItem *random_all_temples_menuitem;
87     Gtk::MenuItem *random_unnamed_temples_menuitem;
88     Gtk::MenuItem *random_all_signs_menuitem;
89     Gtk::MenuItem *random_unnamed_signs_menuitem;
90     Gtk::MenuItem *help_about_menuitem;
91     Gtk::HBox *terrain_tile_style_hbox;
92     Gtk::DrawingArea *map_drawingarea;
93     std::string current_save_filename;
94     bool needs_saving;
95     Gtk::Table *terrain_type_table;
96     Gtk::Label *mouse_position_label;
97     Gtk::RadioButton *pointer_radiobutton;
98     Gtk::Tooltips tooltips;
99     Gtk::Box *players_hbox;
100
101     
102     GdkEventButton *button_event;
103
104     bool on_delete_event(GdkEventAny *e);
105
106     bool on_bigmap_mouse_button_event(GdkEventButton *e);
107     bool on_bigmap_mouse_motion_event(GdkEventMotion *e);
108     bool on_bigmap_key_event(GdkEventKey *e);
109     bool on_bigmap_leave_event(GdkEventCrossing *e);
110
111     bool on_smallmap_mouse_button_event(GdkEventButton *e);
112     bool on_smallmap_mouse_motion_event(GdkEventMotion *e);
113     
114     void on_new_map_activated();
115     void on_load_map_activated();
116     void on_save_map_activated();
117     void on_import_map_activated();
118     void on_export_as_bitmap_activated();
119     void on_export_as_bitmap_no_game_objects_activated();
120     void on_validate_activated();
121     void on_save_map_as_activated();
122     void on_quit_activated();
123     bool quit();
124     void on_edit_map_info_activated();
125     void on_edit_players_activated();
126     void on_smooth_map_activated();
127     void on_smooth_screen_activated();
128     void on_switch_sets_activated();
129     void on_edit_items_activated();
130     void on_edit_rewards_activated();
131
132     void on_fullscreen_activated();
133     void on_tile_graphics_toggled();
134     void on_grid_toggled();
135
136     void on_random_all_cities_activated();
137     void on_random_unnamed_cities_activated();
138     void on_random_all_ruins_activated();
139     void on_random_unnamed_ruins_activated();
140     void on_random_all_temples_activated();
141     void on_random_unnamed_temples_activated();
142     void on_random_all_signs_activated();
143     void on_random_unnamed_signs_activated();
144
145     void on_help_about_activated();
146     
147     struct PointerItem
148     {
149         Gtk::RadioButton *button;
150         EditorBigMap::Pointer pointer;
151         int size;
152     };
153
154     std::vector<PointerItem> pointer_items;
155     
156     struct TerrainItem
157     {
158         Gtk::RadioButton *button;
159         Tile::Type terrain;
160     };
161
162     struct TileStyleItem
163     {
164         Gtk::RadioButton *button;
165         int tile_style_id;
166     };
167
168     std::vector<TerrainItem> terrain_items;
169     std::vector<TileStyleItem> tile_style_items;
170     
171     void on_pointer_radiobutton_toggled();
172     void on_terrain_radiobutton_toggled();
173     void on_tile_style_radiobutton_toggled();
174     
175
176     void clear_save_file_of_scenario_specific_data();
177     Tile::Type get_terrain();
178     int get_tile_style_id();
179     void setup_pointer_radiobutton(Glib::RefPtr<Gtk::Builder> xml,
180         std::string prefix, std::string image_file,
181         EditorBigMap::Pointer pointer, int size);
182     void setup_terrain_radiobuttons();
183
184     void init_maps();
185     void set_filled_map(int width, int height, int fill_style, 
186                         std::string tileset, std::string shieldset, 
187                         std::string cityset, std::string armyset);
188     void set_random_map(int width, int height,
189                         int grass, int water, int swamp, int forest,
190                         int hills, int mountains,
191                         int cities, int ruins, int temples, int signposts,
192                         std::string tileset, std::string shieldset,
193                         std::string cityset, std::string armyset);
194
195     void clear_map_state();
196     void init_map_state();
197     void remove_tile_style_buttons();
198     void setup_tile_style_buttons(Tile::Type terrain);
199     void randomize_signpost(Signpost *signpost);
200     void randomize_city(City *city);
201     void randomize_ruin(Ruin *ruin);
202
203     // map callbacks
204     void on_smallmap_changed(Glib::RefPtr<Gdk::Pixmap> map, Gdk::Rectangle r);
205     void on_bigmap_changed(Glib::RefPtr<Gdk::Pixmap> map);
206     void on_objects_selected(std::vector<UniquelyIdentified *> objects);
207     void on_mouse_on_tile(Vector<int> tile);
208     
209     void popup_dialog_for_object(UniquelyIdentified *object);
210
211     void auto_select_appropriate_pointer();
212
213     bool on_bigmap_exposed(GdkEventExpose *event);
214     bool on_smallmap_exposed(GdkEventExpose *event);
215     void on_bigmap_surface_changed(Gtk::Allocation box);
216     void redraw();
217     void fill_players();
218
219     struct PlayerItem
220     {
221         Gtk::ToggleButton *button;
222         int player_id;
223     };
224     std::list<PlayerItem> player_buttons;
225     void on_player_toggled(PlayerItem item);
226
227     int d_width;
228     int d_height;
229     std::string d_load_filename;// filename given on the command line.
230     
231 };
232
233 #endif