initial commit, lordsawar source, slightly modified
[lordsawar] / src / gui / game-lobby-dialog.h
1 //  Copyright (C) 2008, 2009 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
16 //  02110-1301, USA.
17
18 #ifndef GAME_LOBBY_DIALOG_H
19 #define GAME_LOBBY_DIALOG_H
20
21 #include <string>
22 #include <memory>
23 #include <vector>
24 #include <gtkmm.h>
25 #include "citymap.h"
26 #include "GameScenario.h"
27 #include "game-station.h"
28
29 #include "decorated.h"
30 class NextTurnNetworked;
31
32 class Player;
33 class NextTurnNetworked;
34
35 //! dialog for showing the scenario and who's joined
36 class GameLobbyDialog: public Decorated
37 {
38  public:
39     GameLobbyDialog(GameScenario *game_scenario, 
40                     NextTurnNetworked *next_turn, 
41                     GameStation *game_station,
42                     bool has_ops);
43
44     ~GameLobbyDialog();
45
46     void set_parent_window(Gtk::Window &parent);
47
48
49     void player_is_unavailable(Player *p);
50
51     void hide();
52     void show();
53     bool run();
54     
55   sigc::signal<void, Player*> player_sat_down;
56   sigc::signal<void, Player*> player_stood_up;
57   sigc::signal<void, std::string> message_sent;
58   sigc::signal<void, GameScenario *, NextTurnNetworked*> start_network_game;
59
60  private:
61     Gtk::Dialog* dialog;
62     //! The mini map that shows the scenario map
63     CityMap* citymap;
64     Gtk::Image *map_image;
65
66     void initDialog(GameScenario *gamescenario, NextTurnNetworked *next_turn,
67                     GameStation *game_station);
68     void on_map_changed(Glib::RefPtr< Gdk::Pixmap> map);
69     GameScenario *d_game_scenario;
70     GameStation *d_game_station;
71     NextTurnNetworked *d_next_turn;
72     Gtk::Label *turn_label;
73     Gtk::Label *scenario_name_label;
74     Gtk::Label *cities_label;
75     Gtk::Button *play_button;
76     Gtk::Button *cancel_button;
77     Gtk::Button *show_options_button;
78     Gtk::ScrolledWindow *chat_scrolledwindow;
79     Gtk::TextView *chat_textview;
80     Gtk::Entry *chat_entry;
81
82     void update_scenario_details();
83     void update_player_details();
84     void on_show_options_clicked();
85     void update_city_map();
86
87     Gtk::TreeView *player_treeview;
88     
89     class PlayerColumns: public Gtk::TreeModelColumnRecord {
90     public:
91         PlayerColumns()
92             {add(shield); add(sitting); add(person); add(name); add(type); add(turn); add(player_id);}
93         
94         Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > shield;
95         Gtk::TreeModelColumn<bool> sitting;
96         Gtk::TreeModelColumn<Glib::ustring> person, name, type;
97         Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > turn;
98         Gtk::TreeModelColumn<guint32> player_id;
99     };
100     const PlayerColumns player_columns;
101     Glib::RefPtr<Gtk::ListStore> player_list;
102     
103     Gtk::CellRendererText name_renderer;
104     Gtk::TreeViewColumn name_column;
105     
106     class PlayerNameColumns: public Gtk::TreeModelColumnRecord {
107     public:
108         PlayerNameColumns()
109             { add(name); }
110         
111         Gtk::TreeModelColumn<Glib::ustring> name;
112     };
113     const PlayerNameColumns player_name_columns;
114     Glib::RefPtr<Gtk::ListStore> player_name_list;
115
116     void cell_data_name(Gtk::CellRenderer *renderer, const Gtk::TreeIter &i);
117
118     void on_name_edited(const Glib::ustring &path,
119                                      const Glib::ustring &new_text);
120
121     Gtk::CellRendererCombo type_renderer;
122     Gtk::TreeViewColumn type_column;
123     
124     class PlayerTypeColumns: public Gtk::TreeModelColumnRecord {
125     public:
126         PlayerTypeColumns()
127             { add(type); }
128         
129         Gtk::TreeModelColumn<Glib::ustring> type;
130     };
131     const PlayerTypeColumns player_type_columns;
132     Glib::RefPtr<Gtk::ListStore> player_type_list;
133
134     void cell_data_type(Gtk::CellRenderer *renderer, const Gtk::TreeIter &i);
135     void on_type_edited(const Glib::ustring &path,
136                         const Glib::ustring &new_text);
137
138     Gtk::CellRendererToggle sitting_renderer;
139     Gtk::TreeViewColumn sitting_column;
140     class PlayerSittingColumns: public Gtk::TreeModelColumnRecord {
141     public:
142         PlayerSittingColumns()
143             { add(sitting); }
144         
145         Gtk::TreeModelColumn<bool> sitting;
146     };
147     const PlayerSittingColumns player_sitting_columns;
148     Glib::RefPtr<Gtk::ListStore> player_sitting_list;
149     void cell_data_sitting(Gtk::CellRenderer *renderer, const Gtk::TreeIter& i);
150     
151     Gtk::TreeView *people_treeview;
152     
153     class PeopleColumns: public Gtk::TreeModelColumnRecord {
154     public:
155         PeopleColumns()
156             {add(nickname);}
157         
158         Gtk::TreeModelColumn<Glib::ustring> nickname;
159     };
160     const PeopleColumns people_columns;
161     Glib::RefPtr<Gtk::ListStore> people_list;
162
163     void add_player(const Glib::ustring &type, const Glib::ustring &name,
164                     Player *player);
165     void on_player_selected();
166     bool d_has_ops;
167     void update_buttons();
168     void on_remote_player_ends_turn(Player *p);
169
170     void on_remote_participant_joins(std::string nickname);
171     void on_remote_participant_departs(std::string nickname);
172     void on_player_stands(Player *p, std::string nickname);
173     void on_player_sits(Player *p, std::string nickname);
174     void on_remote_player_changes_name(Player *p);
175     void on_player_died(Player *p);
176     void on_play_clicked();
177     void on_cancel_clicked();
178     void on_sitting_changed(Gtk::CellEditable *editable, const Glib::ustring &path);
179     void on_name_changed(Gtk::CellEditable *editable, const Glib::ustring &path);
180
181     void on_chat_key_pressed(GdkEventKey *event);
182     void on_chatted(std::string nickname, std::string message);
183
184     void on_reorder_playerlist();
185
186     void on_local_player_ends_turn(Player *p);
187     void on_local_player_starts_turn(Player *p);
188
189
190 };
191
192 #endif