/* $Id: wopgui.hpp,v 1.33.2.2 2006/01/24 10:08:10 chfreund Exp $ */ #ifndef _WOPGUI_HPP_ #define _WOPGUI_HPP_ #include #include #include "string.hpp" #include "serverlistwindow.hpp" #include "weaponindicator.hpp" #include "weaponwindow.hpp" #include "wopwindow.hpp" #include "scoretable.hpp" #include "splashscreen.hpp" #include "messagewidget.hpp" #include "optionswindow.hpp" #include "keyconfigwindow.hpp" #include "creditswindow.hpp" #include "gameinfowindow.hpp" #include "textfield.h" #include "backgroundwidget.h" #include "action.h" #include "rootcontainer.h" using namespace SDLwidgets; class Client; struct ServerEntry; struct InfoMessage; class Player; class Bot; class WopGUI : public ActionListener { private: //! Mutex for enabling synchronous access to the GUI SDL_mutex* m_mutex; //! The client controlled by the GUI Client* m_client; //! Root container for the widgets RootContainer* m_root; //! Splash screen SplashScreen* m_splashScreen; //! Text label for showing version information TextLabel* m_versionLabel; //! Text label for showing version information TextLabel* m_fpsLabel; //! A window for showing general information struct { TextLabel* text; WopWindow* window; Uint32 duration; Uint32 startTicks; } m_infoBox; //! The indicator displaying the sprite loading progress struct { WeaponIndicator* progressBar; TextLabel* title; WopWindow* window; } m_initializationWindow; //! The indicator displaying the progress of a joining client struct { WeaponIndicator* progressBar; TextLabel* title; WopWindow* window; } m_progressWindow; //! The main menu struct { TextButton* startButton; TextButton* joinButton; TextButton* join2Button; TextButton* optionsButton; TextButton* creditButton; TextButton* exitButton; WopWindow* window; } m_mainMenu; //! The options window OptionsWindow* m_optionsWindow; //! The key configuration window KeyConfigWindow* m_keyConfigWindow; //! The credits window CreditsWindow* m_creditsWindow; //! The window for displaying all found servers ServerListWindow* m_serverListWindow; Uint32 m_lastServerUpdate; //! The window for entering a server address struct { TextField* addressField; TextButton* connectButton; TextButton* backButton; WopWindow* window; } m_serverEnterWindow; //! The window for displaying game information GameInfoWindow* m_gameInfoWindow; //! Store surface dimensions for later use int m_surfaceWidth, m_surfaceHeight; //! The input widget for chat messages struct { bool visible; TextField* input; WopWindow* window; } m_chatInputWindow; //! The widget displaying all game messages struct { MessageWidget* messageArea; BackgroundWidget* window; int blinkState; } m_messageWindow; //! The widget showing the status of all weapons struct { WeaponWindow* indicators; BackgroundWidget* window; } m_weaponWindow; //! The widget showing the avatar's health struct { WeaponIndicator* indicator; WidgetComposite* container; } m_healthWidget; //! The widget showing the rope status struct { WeaponIndicator* indicator; WidgetComposite* container; } m_ropeWidget; //! The widget showing the status of the active weapon struct { WeaponIndicator* indicator; WidgetComposite* container; } m_activeWeaponWidget; //! The widget showing the avatar's fuel struct { WeaponIndicator* indicator; WidgetComposite* container; } m_fuelWidget; //! The score table struct { ScoreTable* scoreTable; WopWindow* window; } m_scoreTableWindow; public: WopGUI( Client* m_client, SDL_Surface* surface ); virtual ~WopGUI(); void lock() { SDL_mutexP( m_mutex ); } void unlock() { SDL_mutexV( m_mutex ); } virtual void actionPerformed( Uint32 cmd, void* source ); bool handleEvent( SDL_Event* event ); void showChatWindow() { SDL_mutexP( m_mutex ); m_root->add( m_chatInputWindow.window ); m_root->requestFocus( m_chatInputWindow.input ); SDL_mutexV( m_mutex ); } void showMessage( String message, const SDL_Color& color ); void blinkMessageWindow( void ) { m_messageWindow.blinkState = 255; } void showServerListWindow( std::vector& servers ); void hideServerListWindow() { SDL_mutexP( m_mutex ); m_root->remove( m_serverListWindow ); SDL_mutexV( m_mutex ); }; void showGameWidgets() { SDL_mutexP( m_mutex ); m_root->add( m_messageWindow.window ); m_root->add( m_weaponWindow.window ); m_root->add( m_healthWidget.container ); m_root->add( m_ropeWidget.container ); m_root->add( m_activeWeaponWidget.container ); m_root->add( m_fuelWidget.container ); SDL_mutexV( m_mutex ); } void hideGameWidgets() { SDL_mutexP( m_mutex ); m_root->remove( m_messageWindow.window ); m_root->remove( m_weaponWindow.window ); m_root->remove( m_healthWidget.container ); m_root->remove( m_ropeWidget.container ); m_root->remove( m_activeWeaponWidget.container ); m_root->remove( m_fuelWidget.container ); SDL_mutexV( m_mutex ); } void setWeaponColor( int index, SDL_Color& color ) { m_weaponWindow.indicators->getIndicator( index )->setColor( color ); } void setWeaponValue( int index, Uint32 value ) { m_weaponWindow.indicators->getIndicator( index )->setValue( value ); } void setHealthValue( Uint32 value ) { m_healthWidget.indicator->setValue( value ); } void setRopeValue( Uint32 value ) { m_ropeWidget.indicator->setValue( value ); } void setActiveWeaponColor( SDL_Color& color ) { m_activeWeaponWidget.indicator->setColor( color ); } void setActiveWeaponValue( Uint32 value ) { m_activeWeaponWidget.indicator->setValue( value ); } void setFuelValue( Uint32 value ) { m_fuelWidget.indicator->setValue( value ); } void updateScores( World* world ) { SDL_mutexP( m_mutex ); m_scoreTableWindow.scoreTable->updateScores( world ); SDL_mutexV( m_mutex ); } void showScoreTable() { SDL_mutexP( m_mutex ); m_root->add( m_scoreTableWindow.window ); SDL_mutexV( m_mutex ); } void hideScoreTable() { SDL_mutexP( m_mutex ); m_root->remove( m_scoreTableWindow.window ); SDL_mutexV( m_mutex ); } void showInitializationWindow() { SDL_mutexP( m_mutex ); m_root->add( m_initializationWindow.window ); SDL_mutexV( m_mutex ); } void hideInitializationWindow() { SDL_mutexP( m_mutex ); m_root->remove( m_initializationWindow.window ); SDL_mutexV( m_mutex ); } void setInitializationValue( Uint32 value ) { m_initializationWindow.progressBar->setValue( value ); } void setInitializationTitle( std::string title ) { m_initializationWindow.title->setText( title ); } void showProgressWindow() { SDL_mutexP( m_mutex ); m_root->add( m_progressWindow.window ); SDL_mutexV( m_mutex ); } void hideProgressWindow() { SDL_mutexP( m_mutex ); m_root->remove( m_progressWindow.window ); SDL_mutexV( m_mutex ); } void setProgressTitle( std::string title ) { SDL_mutexP( m_mutex ); m_progressWindow.window->setTitle( title ); SDL_mutexV( m_mutex ); } void setProgressComment( std::string comment ) { SDL_mutexP( m_mutex ); m_progressWindow.title->setText( comment ); SDL_mutexV( m_mutex ); } void setProgressValue( Uint32 value ) { m_progressWindow.progressBar->setValue( value ); } void showSplashScreen() { LOG( 1 ) ASSERT( ! m_splashScreen, "WopGUI::showSplashScreen: m_splashScreen != 0\n" ); SDL_mutexP( m_mutex ); m_splashScreen = new SplashScreen(); m_splashScreen->setPosition( ( m_surfaceWidth - m_splashScreen->getWidth () ) / 2, ( m_surfaceHeight - m_splashScreen->getHeight() ) / 2 ); m_root->add( m_splashScreen ); m_splashScreen->startAnimation(); SDL_mutexV( m_mutex ); } void hideSplashScreen() { SDL_mutexP( m_mutex ); m_root->remove( m_splashScreen ); delete m_splashScreen; m_splashScreen = 0; SDL_mutexV( m_mutex ); } void showVersionLabel() { SDL_mutexP( m_mutex ); m_root->add( m_versionLabel ); SDL_mutexV( m_mutex ); } void hideVersionLabel() { SDL_mutexP( m_mutex ); m_root->remove( m_versionLabel ); SDL_mutexV( m_mutex ); } void showFpsLabel() { SDL_mutexP( m_mutex ); m_root->add( m_fpsLabel ); SDL_mutexV( m_mutex ); } void hideFpsLabel() { SDL_mutexP( m_mutex ); m_root->remove( m_fpsLabel ); SDL_mutexV( m_mutex ); } void setFps( double fps ) { SDL_mutexP( m_mutex ); char fpsString[10]; sprintf( fpsString, "%4.1f fps", fps ); m_fpsLabel->setText( fpsString ); SDL_mutexV( m_mutex ); } void toggleFps(); void setLimitFps( bool limitFps ) { SDL_Color white = { 255, 255, 255, 0 }; SDL_Color red = { 255, 0, 0, 0 }; if ( limitFps ) m_fpsLabel->setColor( white ); else m_fpsLabel->setColor( red ); } void showCreditsWindow() { SDL_mutexP( m_mutex ); m_root->add( m_creditsWindow ); SDL_mutexV( m_mutex ); } void hideCreditsWindow() { SDL_mutexP( m_mutex ); m_root->remove( m_creditsWindow ); SDL_mutexV( m_mutex ); } void showMainMenu() { SDL_mutexP( m_mutex ); m_root->add( m_mainMenu.window ); SDL_mutexV( m_mutex ); } void hideMainMenu() { SDL_mutexP( m_mutex ); m_root->remove( m_mainMenu.window ); SDL_mutexV( m_mutex ); } void showOptionsWindow() { SDL_mutexP( m_mutex ); m_root->add( m_optionsWindow ); SDL_mutexV( m_mutex ); } void hideOptionsWindow() { SDL_mutexP( m_mutex ); m_root->remove( m_optionsWindow ); SDL_mutexV( m_mutex ); } void showKeyConfigWindow() { SDL_mutexP( m_mutex ); m_root->add( m_keyConfigWindow ); SDL_mutexV( m_mutex ); } void hideKeyConfigWindow() { SDL_mutexP( m_mutex ); m_root->remove( m_keyConfigWindow ); SDL_mutexV( m_mutex ); } void showGameInfoWindow( ServerEntry* entry, InfoMessage* info, Player* player, std::vector bots, Video* video ) { m_gameInfoWindow->setInfo( entry, info, player, bots, video ); m_gameInfoWindow->setPosition ( ( m_root->getWidth() - m_gameInfoWindow->getWidth() ) / 2, ( m_root->getHeight() - m_gameInfoWindow->getHeight() ) / 2 ); SDL_mutexP( m_mutex ); m_root->add( m_gameInfoWindow ); SDL_mutexV( m_mutex ); } void hideGameInfoWindow() { SDL_mutexP( m_mutex ); m_root->remove( m_gameInfoWindow ); SDL_mutexV( m_mutex ); } void showInfoBox( std::string text, Uint32 duration ); void draw(); private: void createMainMenu(); }; #endif // _WOPGUI_HPP_