initial commit, lordsawar source, slightly modified
[lordsawar] / src / gui / fight-window.h
1 //  Copyright (C) 2007, 2008, 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 FIGHT_WINDOW_H
20 #define FIGHT_WINDOW_H
21
22 #include <memory>
23 #include <vector>
24 #include <list>
25 #include <sigc++/trackable.h>
26 #include <glibmm/main.h>
27 #include <gtkmm.h>
28
29 #include "game-parameters.h"
30 #include "fight.h"
31
32 class Fight;
33 class Army;
34
35 // window for displaying the course of a fight
36 class FightWindow: public sigc::trackable
37 {
38  public:
39     FightWindow(Fight &fight);
40     ~FightWindow();
41
42     void set_parent_window(Gtk::Window &parent);
43
44     void hide();
45     void run(bool *quick);
46     
47  private:
48     Gtk::Window* window;
49     static const int max_cols = 8;
50
51     struct ArmyItem
52     {
53         Army *army;
54         int hp;
55         Gtk::ProgressBar *bar;
56         Gtk::Image *image;
57         bool exploding;
58     };
59     
60     typedef std::vector<ArmyItem> army_items_type;
61     army_items_type army_items;
62
63     typedef std::list<FightItem> actions_type;
64     actions_type actions;
65
66     typedef std::vector<Army *> armies_type; // for convenience
67
68     Glib::RefPtr<Glib::MainLoop> main_loop;
69     
70     int round;
71     actions_type::iterator action_iterator;
72     
73     // determine the max no. of rows in each column
74     int compute_max_rows(const armies_type &attackers,
75                          const armies_type &defenders);
76     
77     // add an army to the window
78     void add_army(Army *army, int initial_hp,
79                   std::vector<Gtk::HBox *> &hboxes,
80                   Gtk::VBox *vbox,
81                   int current_no, int max_rows, Gtk::AlignmentEnum alignment);
82
83     void on_key_release_event(GdkEventKey* event);
84
85     bool do_round();
86     bool d_quick;
87     int normal_round_speed;
88     int fast_round_speed;
89 };
90
91 #endif