1 /*
2  *  metaserver_dialogs.h - UI for metaserver client
3 
4 	Copyright (C) 2004 and beyond by Woody Zenfell, III
5 	and the "Aleph One" developers.
6 
7 	This program is free software; you can redistribute it and/or modify
8 	it under the terms of the GNU General Public License as published by
9 	the Free Software Foundation; either version 3 of the License, or
10 	(at your option) any later version.
11 
12 	This program is distributed in the hope that it will be useful,
13 	but WITHOUT ANY WARRANTY; without even the implied warranty of
14 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 	GNU General Public License for more details.
16 
17 	This license is contained in the file "COPYING",
18 	which is included with this source code; it is available online at
19 	http://www.gnu.org/licenses/gpl.html
20 
21  April 29, 2004 (Woody Zenfell):
22 	Created.
23  */
24 
25 #ifndef METASERVER_DIALOGS_H
26 #define METASERVER_DIALOGS_H
27 
28 #include "network_metaserver.h"
29 #include "metaserver_messages.h"
30 #include "shared_widgets.h"
31 
32 
33 const IPaddress run_network_metaserver_ui();
34 
35 // This doesn't go here
36 void setupAndConnectClient(MetaserverClient& client);
37 
38 
39 
40 struct game_info;
41 
42 class GameAvailableMetaserverAnnouncer
43 {
44 public:
45 	GameAvailableMetaserverAnnouncer(const game_info& info);
46 	void Start(int32 time_limit);
47 
48 private:
49 	// using gMetaserverClient instead
50 	// MetaserverClient	m_client;
51 };
52 
53 class GlobalMetaserverChatNotificationAdapter : public MetaserverClient::NotificationAdapter
54 {
55 public:
56 	virtual void playersInRoomChanged(const std::vector<MetaserverPlayerInfo>&);
57 	virtual void gamesInRoomChanged(const std::vector<GameListMessage::GameListEntry>&);
58 	virtual void receivedChatMessage(const std::string& senderName, uint32 senderID, const std::string& message);
59 	virtual void receivedLocalMessage(const std::string& message);
60 	virtual void receivedBroadcastMessage(const std::string& message);
61 	virtual void receivedPrivateMessage(const std::string& senderName, uint32 senderID, const std::string& message);
62 	virtual void roomDisconnected();
63 };
64 
65 // Eventually this may disappear behind the facade of run_network_metaserver_ui()
66 // Or maybe it will disappear instead, leaving this.  Unsure.
67 class MetaserverClientUi : public GlobalMetaserverChatNotificationAdapter
68 {
69 public:
70 	// Abstract factory; concrete type determined at link-time
71 	static std::unique_ptr<MetaserverClientUi> Create();
72 
73 	const IPaddress GetJoinAddressByRunning();
74 
~MetaserverClientUi()75 	virtual ~MetaserverClientUi () {};
76 
77 protected:
MetaserverClientUi()78 	MetaserverClientUi() : m_used (false), m_lastGameSelected(0) {}
79 
80 	void delete_widgets ();
81 
82 	virtual int Run() = 0;
83 	virtual void Stop() = 0;
84 
85 	void GameSelected(GameListMessage::GameListEntry game);
86 	void JoinGame(const GameListMessage::GameListEntry&);
87 	void PlayerSelected(MetaserverPlayerInfo info);
88 	void MuteClicked();
89 	void JoinClicked();
InfoClicked()90 	virtual void InfoClicked() { };
91 	void playersInRoomChanged(const std::vector<MetaserverPlayerInfo> &playerChanges);
92 	void gamesInRoomChanged(const std::vector<GameListMessage::GameListEntry> &gamesChanges);
93 	void sendChat();
94 	void ChatTextEntered (char character);
95 	void handleCancel();
96 	void UpdatePlayerButtons();
97 	void UpdateGameButtons();
98 
99 	PlayerListWidget*				m_playersInRoomWidget;
100 	GameListWidget*					m_gamesInRoomWidget;
101 	EditTextWidget*					m_chatEntryWidget;
102 //	HistoricTextboxWidget*				m_textboxWidget;
103 	ColorfulChatWidget*                             m_chatWidget;
104 	ButtonWidget*					m_cancelWidget;
105 	IPaddress					m_joinAddress;
106 	bool						m_used;
107 	ButtonWidget*                                   m_muteWidget;
108 	ButtonWidget*                                   m_joinWidget;
109 	ButtonWidget*                                   m_gameInfoWidget;
110 
111 	Uint32 m_lastGameSelected;
112 	bool m_stay_selected; // doesn't deselect after PM
113 };
114 
115 #endif // METASERVER_DIALOGS_H
116