1 #ifndef SPRINGLOBBY_HEADERGUARD_UI_H 2 #define SPRINGLOBBY_HEADERGUARD_UI_H 3 4 class Server; 5 class TASServer; 6 class ConnectWindow; 7 class Spring; 8 class MainWindow; 9 class Channel; 10 class User; 11 class IBattle; 12 class Battle; 13 class SinglePlayerBattle; 14 class OfflineBattle; 15 class ChatPanel; 16 class ReconnectDialog; 17 18 //this removes the necessity to drag wx/event.h into almost every other file for a single type 19 //if it's too "hackish" for someone's taste, just include that header again and remove this (koshi) 20 #ifndef wxEventType 21 typedef int wxEventType; 22 #endif 23 24 typedef int AlertEventType; 25 26 extern const wxEventType torrentSystemStatusUpdateEvt; 27 28 #include "utils/battleevents.h" 29 #include <wx/string.h> 30 #include <wx/timer.h> 31 #include "utils/mixins.hh" 32 33 //! @brief UI main class 34 class Ui : public wxEvtHandler, public GlobalEvent, public SL::NonCopyable 35 { 36 public: 37 38 Ui(); 39 ~Ui(); 40 41 enum PlaybackEnum { 42 ReplayPlayback, 43 SavegamePlayback 44 }; 45 46 ChatPanel* GetActiveChatPanel(); 47 ChatPanel* GetChannelChatPanel( const wxString& channel ); 48 49 bool ExecuteSayCommand( const wxString& cmd ); 50 void ConsoleHelp( const wxString& topic ); 51 52 void ShowMainWindow(); 53 void ShowConnectWindow(); 54 void Connect(); 55 void Disconnect(); 56 void Reconnect(); 57 void DoConnect( const wxString& servername, const wxString& username, const wxString& password ); 58 void AddServerWindow( const wxString& servername ); 59 void ReopenServerTab(); 60 61 void ConnectionFailurePrompt(); 62 wxString GetNextServer(); 63 64 bool DoRegister( const wxString& servername, const wxString& username, const wxString& password, wxString& reason ); 65 66 bool IsConnecting() const; 67 bool IsConnected() const; 68 void JoinChannel( const wxString& name, const wxString& password ); 69 70 bool IsSpringCompatible(const wxString& engine, const wxString& version); 71 72 bool IsSpringRunning() const; 73 74 void Quit(); 75 76 void Download( const wxString& category, const wxString& name, const wxString& hash ); 77 78 bool Ask( const wxString& heading, const wxString& question ) const; 79 bool AskText( const wxString& heading, const wxString& question, wxString& answer, bool multiline = false); 80 bool AskPassword( const wxString& heading, const wxString& message, wxString& password ); 81 void ShowMessage( const wxString& heading, const wxString& message ) const; 82 83 MainWindow& mw(); 84 const MainWindow& mw() const; 85 86 bool IsMainWindowCreated() const; 87 88 void OnInit(); 89 90 void OnConnected( Server& server, const wxString& server_name, const wxString& server_ver, bool supported ); 91 void OnLoggedIn( ); 92 void OnDisconnected( Server& server, bool wasonline ); 93 94 void OnJoinedChannelSuccessful( Channel& chan ); 95 void OnJoinedChannelSuccessful( Channel& chan, bool focusTab ); 96 void OnUserJoinedChannel( Channel& chan, User& user ); 97 void OnChannelJoin( Channel& chan, User& user ); 98 void OnUserLeftChannel( Channel& chan, User& user, const wxString& reason ); 99 100 void OnChannelTopic( Channel& channel , const wxString& user, const wxString& topic ); 101 void OnChannelSaid( Channel& channel , User& user, const wxString& message ); 102 void OnChannelDidAction( Channel& channel , User& user, const wxString& action ); 103 void OnChannelMessage( const wxString& channel, const wxString& msg ); 104 105 void OnChannelList( const wxString& channel, const int& numusers ); 106 void OnUserOnline( User& user ); 107 void OnUserOffline( User& user ); 108 void OnUserStatusChanged( User& user ); 109 void OnUserSaid( User& user, const wxString& message, bool me = false ); 110 void OnUserSaidEx( User& user, const wxString& action, bool me = false ); 111 112 void OnUnknownCommand( Server& server, const wxString& command, const wxString& params ); 113 void OnMotd( Server& server, const wxString& message ); 114 void OnServerBroadcast( Server& server, const wxString& message ); 115 void OnServerMessage( Server& server, const wxString& message ); 116 117 void OnBattleOpened( IBattle& battle ); 118 void OnBattleClosed( IBattle& battle ); 119 void OnUserJoinedBattle( IBattle& battle, User& user ); 120 void OnUserLeftBattle( IBattle& battle, User& user, bool isbot ); 121 void OnBattleInfoUpdated( BattleEvents::BattleEventData data ); 122 void OnBattleStarted( Battle& battle ); 123 124 void OnJoinedBattle( Battle& battle ); 125 void OnHostedBattle( Battle& battle ); 126 void OnUserBattleStatus( IBattle& battle, User& user ); 127 void OnRequestBattleStatus( IBattle& battle ); 128 129 void OnSaidBattle( IBattle& battle, const wxString& nick, const wxString& msg ); 130 131 void OnSpringTerminated( wxCommandEvent& data); 132 133 void OnAcceptAgreement( const wxString& agreement ); 134 135 void OnMainWindowDestruct(); 136 137 void OnRing( const wxString& from ); 138 void OnQuit(wxCommandEvent& data); 139 140 //! ask to download missing map, return true if download attempted 141 bool OnPresetRequiringMap( const wxString& mapname ); 142 143 bool IsThisMe(User& other) const; 144 bool IsThisMe(User* other) const; 145 bool IsThisMe(const wxString& other) const; 146 147 int TestHostPort( unsigned int port ) const; 148 149 void ReloadPresetList(); 150 151 void OpenFileInEditor( const wxString& filepath ); 152 153 //! the welcome box, should be called in all code paths directly after MainWindow might be shown for the first time 154 void FirstRunWelcome(); 155 void CheckForUpdates(); 156 157 protected: 158 Server* m_serv; 159 MainWindow* m_main_win; 160 ConnectWindow* m_con_win; 161 wxTimer m_reconnect_delay_timer; 162 ReconnectDialog* m_reconnect_dialog; 163 164 wxString m_last_used_backup_server; 165 166 bool m_first_update_trigger; 167 168 bool m_recconecting_wait; 169 bool m_disable_autoconnect; 170 171 EventReceiverFunc<Ui, BattleEvents::BattleEventData, &Ui::OnBattleInfoUpdated> 172 m_battle_info_updatedSink; 173 }; 174 175 Ui& ui(); 176 177 #endif // SPRINGLOBBY_HEADERGUARD_UI_H 178 179 /** 180 This file is part of SpringLobby, 181 Copyright (C) 2007-2011 182 183 SpringLobby is free software: you can redistribute it and/or modify 184 it under the terms of the GNU General Public License version 2 as published by 185 the Free Software Foundation. 186 187 SpringLobby is distributed in the hope that it will be useful, 188 but WITHOUT ANY WARRANTY; without even the implied warranty of 189 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 190 GNU General Public License for more details. 191 192 You should have received a copy of the GNU General Public License 193 along with SpringLobby. If not, see <http://www.gnu.org/licenses/>. 194 **/ 195 196