1 //  Copyright (C) 2008, 2009, 2014, 2015 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 #pragma once
19 #ifndef GAME_LOBBY_DIALOG_H
20 #define GAME_LOBBY_DIALOG_H
21 
22 #include <gtkmm.h>
23 #include "citymap.h"
24 #include "GameScenario.h"
25 #include "game-station.h"
26 #include "lw-dialog.h"
27 
28 class Player;
29 class NextTurnNetworked;
30 
31 //! dialog for showing the scenario and who's joined
32 class GameLobbyDialog: public LwDialog
33 {
34  public:
35     GameLobbyDialog(Gtk::Window &parent, GameScenario *game_scenario,
36 		    NextTurnNetworked *next_turn,
37 		    GameStation *game_station,
38 		    bool has_ops);
39 
40     ~GameLobbyDialog();
41 
42     void clean_up_players();
hide()43     void hide() {dialog->hide();};
show()44     void show() {dialog->show_all();};
45     bool run();
46 
47   sigc::signal<void, Player*> player_sat_down;
48   sigc::signal<void, Player*> player_stood_up;
49   sigc::signal<void, Glib::ustring> message_sent;
50   sigc::signal<void, Player*, Glib::ustring> player_changed_name;
51   sigc::signal<void, Player*, int> player_changed_type;
52   sigc::signal<void, GameScenario *, NextTurnNetworked*> start_network_game;
53   sigc::signal<void> game_may_begin;
54 
55   void disconnect_signals();
56  private:
57     //! The mini map that shows the scenario map
58     CityMap* citymap;
59     Gtk::Image *map_image;
60     guint32 d_player_id_of_sit_or_stand_request;
61     guint32 d_player_id_of_name_change_request;
62     guint32 d_player_id_of_type_change_request;
63 
64     void initDialog(GameScenario *gamescenario,
65                     NextTurnNetworked *next_turn, GameStation *game_station);
66     void on_map_changed(Cairo::RefPtr< Cairo::Surface> map);
67     GameScenario *d_game_scenario;
68     GameStation *d_game_station;
69     NextTurnNetworked *d_next_turn;
70     bool d_has_ops;
71     bool d_play_message_received;
72     bool d_play_button_clicked;
73     Gtk::Label *turn_label;
74     Gtk::Label *scenario_name_label;
75     Gtk::Label *cities_label;
76     Gtk::Button *play_button;
77     Gtk::Button *cancel_button;
78     Gtk::Button *show_options_button;
79     Gtk::ScrolledWindow *chat_scrolledwindow;
80     Gtk::TextView *chat_textview;
81     Gtk::Entry *chat_entry;
82 
83     void update_scenario_details();
84     void update_player_details();
85     void on_show_options_clicked();
86     void update_city_map();
87 
88     Gtk::TreeView *player_treeview;
89 
90     class PlayerColumns: public Gtk::TreeModelColumnRecord {
91     public:
PlayerColumns()92 	PlayerColumns()
93 	    {add(order); add(sitting); add(person); add(shield); add(name); add(type); add(turn); add(player_id);}
94 
95 	Gtk::TreeModelColumn<guint32> order;
96 	Gtk::TreeModelColumn<bool> sitting;
97 	Gtk::TreeModelColumn<Glib::ustring> person;
98 	Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > shield;
99 	Gtk::TreeModelColumn<Glib::ustring> name, type;
100 	Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > turn;
101 	Gtk::TreeModelColumn<guint32> player_id;
102     };
103     const PlayerColumns player_columns;
104     Glib::RefPtr<Gtk::ListStore> player_list;
105 
106     Gtk::CellRendererText name_renderer;
107     Gtk::TreeViewColumn name_column;
108 
109     class PlayerNameColumns: public Gtk::TreeModelColumnRecord {
110     public:
PlayerNameColumns()111 	PlayerNameColumns()
112 	    { add(name); }
113 
114 	Gtk::TreeModelColumn<Glib::ustring> name;
115     };
116     const PlayerNameColumns player_name_columns;
117     Glib::RefPtr<Gtk::ListStore> player_name_list;
118 
119     void cell_data_name(Gtk::CellRenderer *renderer, const Gtk::TreeIter &i);
120 
121     void on_name_edited(const Glib::ustring &path,
122 				     const Glib::ustring &new_text);
123 
124     Gtk::CellRendererCombo type_renderer;
125     Gtk::TreeViewColumn type_column;
126 
127     class PlayerTypeColumns: public Gtk::TreeModelColumnRecord {
128     public:
PlayerTypeColumns()129 	PlayerTypeColumns()
130 	    { add(type); }
131 
132 	Gtk::TreeModelColumn<Glib::ustring> type;
133     };
134     const PlayerTypeColumns player_type_columns;
135     Glib::RefPtr<Gtk::ListStore> player_type_list;
136 
137     void cell_data_type(Gtk::CellRenderer *renderer, const Gtk::TreeIter &i);
138     void on_type_edited(const Glib::ustring &path,
139 			const Glib::ustring &new_text);
140 
141     Gtk::CellRendererToggle sitting_renderer;
142     Gtk::TreeViewColumn sitting_column;
143     void cell_data_sitting(Gtk::CellRenderer *renderer, const Gtk::TreeIter& i);
144 
145     Gtk::TreeView *people_treeview;
146     std::list<sigc::connection> connections;
147 
148     class PeopleColumns: public Gtk::TreeModelColumnRecord {
149     public:
PeopleColumns()150 	PeopleColumns()
151 	    {add(nickname);}
152 
153 	Gtk::TreeModelColumn<Glib::ustring> nickname;
154     };
155     const PeopleColumns people_columns;
156     Glib::RefPtr<Gtk::ListStore> people_list;
157 
158     void add_player(guint32 order, const Glib::ustring &type,
159                     const Glib::ustring &name, Player *player);
160     void on_player_selected();
161     void update_buttons();
162     void on_remote_player_ends_turn();
163     void on_remote_player_starts_turn();
164 
165     void on_remote_participant_joins(Glib::ustring nickname);
166     void on_remote_participant_departs(Glib::ustring nickname);
167     void on_player_stands(Player *p);
168     void on_player_sits(Player *p, Glib::ustring nickname);
169     void on_player_changes_name(Player *p, Glib::ustring name);
170     void on_player_changes_type(Player *p, int type);
171     void on_remote_player_changes_name(Player *p);
172     void on_player_died(Player *p);
173     void on_play_clicked();
174     void on_cancel_clicked();
175     void on_sitting_toggled (const Glib::ustring &path);
176     void on_name_changed(Gtk::CellEditable *editable, const Glib::ustring &path);
177 
178     void on_chat_key_pressed(GdkEventKey *event);
179     void on_chatted(Glib::ustring message);
180 
181     void on_reorder_playerlist();
182 
183     void on_local_player_ends_turn();
184     void on_local_player_starts_turn();
185     void on_play_message_received();
186 
187     void on_nickname_changed(Glib::ustring old_name, Glib::ustring new_name);
188 
189     void on_player_turned_off(Player *player);
190 
191 
192     void lock_down();
193     Player* get_selected_player(Glib::ustring &nick, bool &sitting);
194 
195     void sort_player_list_by_turn_order();
196 
197     void update_turn_indicator();
198 };
199 
200 #endif
201