1 //  Copyright (C) 2007, 2008 Ole Laursen
2 //  Copyright (C) 2007, 2008, 2009, 2011, 2012, 2014, 2015, 2016, 2017,
3 //  2020 Ben Asselstine
4 //
5 //  This program is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation; either version 3 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU Library General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 //  02110-1301, USA.
19 
20 #pragma once
21 #ifndef GUI_GAME_WINDOW_H
22 #define GUI_GAME_WINDOW_H
23 
24 #include <memory>
25 #include <vector>
26 #include <sigc++/signal.h>
27 #include <sigc++/trackable.h>
28 #include <sigc++/connection.h>
29 #include <gtkmm.h>
30 
31 #include "army-info-tip.h"
32 #include "city-info-tip.h"
33 #include "stack-info-tip.h"
34 #include "game-parameters.h"
35 #include "sidebar-stats.h"
36 #include "stack.h"
37 #include "fight.h"
38 #include "map-tip-position.h"
39 #include "callback-enums.h"
40 #include "vector.h"
41 #include "army.h"
42 #include "ImageCache.h"
43 #include "GameScenario.h"
44 #include "select-city-map.h"
45 
46 class Game;
47 class GameButtonBox;
48 class Ruin;
49 class Fight;
50 class Hero;
51 class HeroProto;
52 class Player;
53 class Temple;
54 class Quest;
55 class City;
56 class Reward;
57 class Reward_Ruin;
58 class NextTurn;
59 class LocationBox;
60 class StatusBox;
61 class Profile;
62 class Keeper;
63 
64 /** The main window in which all the game action is going on.
65   *
66   * This class takes cares of the widget side of the things around the action
67   * area, delegating the actual drawing to the model classes, but is also
68   * responsible for popping up dialog windows in response to the action.
69   * It has a pane at the bottom with information about the currently selected
70   * stack and a pane to the right with the small map, buttons and statistics.
71   */
72 class GameWindow: public sigc::trackable
73 {
74  public:
75      static double minimum_zoom_scale;
76      static double maximum_zoom_scale;
77     GameWindow();
78     ~GameWindow();
79 
80     void show();
hide()81     void hide() {window->hide();};
82 
83     // initialize the big map widget
84     void init(int width, int height);
85 
86     // setup a new game
87     void new_game(GameScenario *game_scenario, NextTurn *next_turn);
88 
89     // setup a new network game
90     void new_network_game(GameScenario *game_scenario, NextTurn *next_turn);
91 
92     void continue_network_game(NextTurn *next_turn);
93 
94     // load the game
95     void load_game(GameScenario *game_scenario, NextTurn *next_turn);
96 
97     // emitted when the game has ended and it is time to show the splash again
98     sigc::signal<void> game_ended;
99 
100     // emitted when the game has ended and we want to start a new game.
101     sigc::signal<void> game_ended_start_new;
102 
103     sigc::signal<void> show_lobby;
104     sigc::signal<void> show_quick_help;
105 
106     sigc::signal<void> quit_requested;
107 
108     sigc::signal<void,Glib::ustring,int,Profile*,bool,bool> load_hosted_network_game;
109 
get_window()110     Gtk::Window *get_window() const {return window;};
111 
112     void on_player_replaced(Player *p);
113  private:
114     Gtk::Window* window;
115     Gtk::Window* map_tip;	// tooltip appears over the map
116     Gtk::Window* stack_tip;// tooltip appears over the map
117     Gtk::Container *bigmap_container;
118     Gtk::Container *map_container;
119     Gtk::MenuBar *menubar;
120     Gtk::CheckMenuItem *fullscreen_menuitem;
121     Gtk::MenuItem *new_game_menuitem;
122     Gtk::MenuItem *load_game_menuitem;
123     Gtk::MenuItem *save_game_menuitem;
124     Gtk::MenuItem *save_game_as_menuitem;
125     Gtk::MenuItem *show_lobby_menuitem;
126     Gtk::MenuItem *end_turn_menuitem;
127     Gtk::MenuItem *move_all_menuitem;
128     Gtk::MenuItem *search_menuitem;
129     Gtk::MenuItem *use_menuitem;
130     Gtk::MenuItem *disband_menuitem;
131     Gtk::MenuItem *stack_info_menuitem;
132     Gtk::MenuItem *signpost_menuitem;
133     Gtk::MenuItem *diplomacy_report_menuitem;
134     Gtk::MenuItem *item_report_menuitem;
135     Gtk::MenuItem *city_history_menuitem;
136     Gtk::MenuItem *ruin_history_menuitem;
137     Gtk::MenuItem *event_history_menuitem;
138     Gtk::MenuItem *gold_history_menuitem;
139     Gtk::MenuItem *winner_history_menuitem;
140     Gtk::MenuItem *plant_standard_menuitem;
141     Gtk::MenuItem *group_ungroup_menuitem;
142     Gtk::MenuItem *leave_menuitem;
143     Gtk::MenuItem *next_menuitem;
144     Gtk::MenuItem *fight_order_menuitem;
145     Gtk::MenuItem *resign_menuitem;
146     Gtk::MenuItem *production_menuitem;
147     Gtk::MenuItem *cities_menuitem;
148     Gtk::MenuItem *build_menuitem;
149     Gtk::MenuItem *vectoring_menuitem;
150     Gtk::MenuItem *levels_menuitem;
151     Gtk::MenuItem *inspect_menuitem;
152     Gtk::MenuItem *ruin_report_menuitem;
153     Gtk::MenuItem *army_bonus_menuitem;
154     Gtk::MenuItem *item_bonus_menuitem;
155     Gtk::MenuItem *production_report_menuitem;
156     Gtk::MenuItem *triumphs_menuitem;
157     Gtk::MenuItem *help_about_menuitem;
158     Gtk::MenuItem *tutorial_menuitem;
159     Gtk::MenuItem *online_help_menuitem;
160     Gtk::MenuItem *quit_menuitem;
161     Gtk::MenuItem *toggle_grid_menuitem;
162     Gtk::MenuItem *army_report_menuitem;
163     Gtk::MenuItem *city_report_menuitem;
164     Gtk::MenuItem *gold_report_menuitem;
165     Gtk::MenuItem *winning_report_menuitem;
166     Gtk::MenuItem *quests_menuitem;
167     Gtk::MenuItem *preferences_menuitem;
168     Gtk::MenuItem *zoom_in_menuitem;
169     Gtk::MenuItem *zoom_out_menuitem;
170     Gtk::MenuItem *best_fit_menuitem;
171     Gtk::MenuItem *quick_help_menuitem;
172     Gtk::Image *smallmap_image;
173     Gtk::Image *bigmap_image;
174 
175     Gtk::Label *turn_label;
176     Gtk::Box *turn_hbox;
177     Gtk::Image *shield_image[MAX_PLAYERS];
178 
179     // the button control panel
180     Gtk::Viewport *control_panel_viewport;
181 
182     CityInfoTip* city_info_tip;
183     StackInfoTip* stack_info_tip;
184     typedef std::vector<Gtk::ToggleButton *> army_buttons_type;
185     army_buttons_type army_buttons;
186     typedef std::vector<Gtk::RadioButton*> stack_buttons_type;
187     stack_buttons_type stack_buttons;
188     Gtk::EventBox *map_eventbox;
189     Gtk::EventBox *bigmap_eventbox;
190     Gtk::Box *status_box_container;
191     StatusBox *status_box;
192 
193     Glib::ustring current_save_filename;
194 
195     Game* game;
196     GameButtonBox *game_button_box;
197     Gtk::Label *pos_label;
198 
199     GdkEventButton *button_event;
200 
201     bool on_delete_event();
202 
203     bool on_bigmap_mouse_button_event(GdkEventButton *e);
204     bool on_bigmap_mouse_motion_event(GdkEventMotion *e);
205     bool on_bigmap_key_event(GdkEventKey *e);
206 
207     bool on_smallmap_mouse_button_event(GdkEventButton *e);
208     bool on_smallmap_mouse_motion_event(GdkEventMotion *e);
209     bool on_mouse_entered_smallmap();
210 
211     void on_load_game_activated();
212     void on_save_game_activated();
213     void on_save_game_as_activated();
214     void on_show_lobby_activated();
215     void on_quit_activated();
216     void on_new_game_activated();
217     void on_game_stopped();
218     void on_quests_activated();
219     void on_disband_activated();
220     void on_stack_info_activated();
221     void on_resign_activated();
222     void on_resignation_completed();
223     void on_signpost_activated();
224     void on_inspect_activated();
225     void on_plant_standard_activated();
226     void on_item_bonus_activated();
227     void on_army_report_activated();
228     void on_item_report_activated();
229     void on_city_report_activated();
230     void on_gold_report_activated();
231     void on_production_report_activated();
232     void on_winning_report_activated();
233     void on_diplomacy_report_activated();
234     void on_diplomacy_button_clicked();
235 
236     void on_fullscreen_activated();
237     void on_preferences_activated();
238     void on_zoom_in_activated();
239     void on_zoom_out_activated();
240     void on_best_fit_activated();
241     void zoom (double scale);
242     void on_group_ungroup_activated();
243 
244     void on_fight_order_activated();
245     void on_levels_activated();
246     void on_production_activated();
247     void on_vectoring_activated();
248     void on_grid_toggled();
249     void on_ruin_report_activated();
250     void on_army_bonus_activated();
251     void on_city_history_activated();
252     void on_ruin_history_activated();
253     void on_event_history_activated();
254     void on_gold_history_activated();
255     void on_winner_history_activated();
256     void on_triumphs_activated();
257     void on_help_about_activated();
258     void on_tutorial_activated();
259     void on_online_help_activated();
260     void on_quick_help_activated();
261 
262     void on_message_requested(Glib::ustring msg);
263 
264     // shield set on the top
265     void show_shield_turn();
266 
267     // game callbacks
268     void on_sidebar_stats_changed(SidebarStats s);
269     void on_progress_status_changed(Glib::ustring status);
270     void on_progress_changed();
271     void on_smallmap_changed(Cairo::RefPtr<Cairo::Surface> map);
272     void on_smallmap_slid();
273     void on_bigmap_cursor_changed(ImageCache::CursorType cursor);
274     void on_bigmap_changed(Cairo::RefPtr<Cairo::Surface> map);
275     void on_stack_info_changed(Stack *s);
276     void on_bigmap_tip_changed(Glib::ustring tip, MapTipPosition pos, bool timeout);
277     void on_stack_tip_changed(StackTile *stile, MapTipPosition pos);
278     void on_city_tip_changed(City *city, MapTipPosition pos);
279     void on_ruin_searched(Ruin *ruin, Stack *s, Reward *reward);
280     Reward* on_sage_visited(Ruin *ruin, Sage *sage, Stack *s);
281     void on_ruin_rewarded(Reward_Ruin *reward);
282     void on_fight_started(LocationBox box, Fight &fight);
283     void on_abbreviated_fight_started(LocationBox box);
284     void on_ruinfight_started(Stack *attackers, Keeper *keeper);
285     void on_ruinfight_finished(Fight::Result result);
286     bool on_hero_offers_service(Player *player, HeroProto *hero, City *city, int gold);
287     bool on_enemy_offers_surrender(int numEnemies);
288     void on_surrender_answered (bool accepted);
289     bool on_stack_considers_treachery (Player *them);
290     bool on_temple_searched(Hero *hero, Temple *temple, int blessCount);
291     void on_quest_assigned(Hero *hero, Quest *quest);
292     CityDefeatedAction on_city_defeated(City *city, int gold);
293     void on_city_pillaged(City *city, int gold, int pillaged_army_type);
294     void on_city_sacked(City *city, int gold, std::list<guint32> sacked_types);
295     void on_city_razed(City *city);
296     void on_city_visited(City *city);
297     void on_ruin_visited(Ruin *ruin);
298     void on_temple_visited(Temple *temple);
299     void on_next_player_turn(Player *player, unsigned int turn_number);
300     void on_remote_next_player_turn();
301     void on_hero_brings_allies(int alliesCount);
302     void on_medal_awarded_to_army(Army *army, int medaltype);
303     Army::Stat on_hero_gains_level(Hero *hero);
304     void on_game_loaded(Player *player);
305     void on_game_over(Player *winner);
306     void on_player_died(Player *player);
307     void on_advice_asked(float percent);
308     void on_gold_stolen(Player *victim, guint32 gold_pieces);
309     void on_ships_sunk(guint32 num_armies);
310     void on_bags_picked_up(Hero *hero, guint32 num_bags);
311     void on_worms_killed(Hero *hero, Glib::ustring army_type_name, guint32 num_worms_killed);
312     void on_city_diseased(Glib::ustring city_name, guint32 num_armies_killed);
313     void on_city_defended(Glib::ustring city_name, Glib::ustring army_name, guint32 num_armies);
314     void on_city_persuaded(Glib::ustring city_name, guint32 num_armies);
315     void on_stack_teleported(Hero *hero, Glib::ustring city_name);
316     void on_bridge_burned(Hero *hero);
317     void on_keeper_captured(Hero *hero, Ruin*, Glib::ustring monster_name);
318     void on_monster_summoned(Hero *hero, Glib::ustring monster_name);
319     void on_mp_added_to_hero_stack(Hero *hero, guint32 mp);
320     void on_stack_moves(Stack *stack, Vector<int> pos);
321     void on_commentator_comments(Glib::ustring comment);
322     Item* on_select_item(std::list<Item*> items);
323     Player *on_select_item_victim_player();
324     City *on_select_city_to_use_item_on(SelectCityMap::Type type);
325     bool on_bigmap_scrolled(GdkEventScroll* event);
326     void on_popup_stack_menu (Stack *stack);
327     void on_pointing_at_new_tile(Vector<int> tile);
328 
329     // quest manager callbacks
330     void on_quest_completed(Quest *quest, Reward *reward);
331     void on_quest_expired(Quest *quest);
332 
333     // helpers
334     void get_default_magnifying_glass_hotspot (int *x, int *y);
335     void show_map_tip(Glib::ustring msg, MapTipPosition pos, bool timeout = false);
336     void on_city_looted(City *city, int gold);
337     bool hide_map_tip();
338     void show_city_production_report (bool destitute);
339 
340     bool setup_game(GameScenario *game_scenario, NextTurn *nextTurn);
341     void setup_signals(GameScenario *game_scenario);
342     void stop_game(Glib::ustring action);
343     std::list<sigc::connection> connections;
344 
345     void setup_menuitem(Gtk::MenuItem*, sigc::slot<void> , sigc::signal<void, bool> &);
346     void on_bigmap_surface_changed(Gtk::Allocation box);
347     void on_group_stack_toggled(bool lock);
348 
349     Player *game_winner;
350     void give_some_cheese(Player *game_winner);
351 
352     bool on_window_state_event (GdkEventWindowState *e);
353     bool on_configure_event (GdkEventConfigure *e);
354     void set_default_bigmap_zoom ();
355 public:
356     bool d_quick_fights; //do we speed up fights for this player's turn?
357     Glib::ustring stop_action; //hackhackhack
358     Glib::ustring d_scenario;
359     int d_gold;
360     std::list<Hero*> d_heroes;
361     Glib::ustring d_player_name;
362     Glib::ustring d_load_filename;
363     Gtk::Allocation last_box;
364     Gtk::Allocation unmaximized_box;
365     sigc::connection map_tip_timer;
366 };
367 
368 #endif
369