From 626f83087a2012af61c861f358b00ecef6d0a265 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Sun, 11 Jul 2010 23:03:54 +0000 Subject: [PATCH] Added new base class for race gui (in prepration for improved result gui). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5680 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/Makefile.am | 1 + src/graphics/irr_driver.cpp | 2 +- src/ide/vc9/supertuxkart.vcproj | 4 ++ src/items/flyable.cpp | 2 +- src/items/plunger.cpp | 2 +- src/items/powerup.cpp | 2 +- src/items/rubber_band.cpp | 2 +- src/karts/controller/player_controller.cpp | 4 +- src/karts/kart.cpp | 4 +- src/modes/follow_the_leader.cpp | 4 +- src/modes/follow_the_leader.hpp | 4 +- src/modes/linear_world.cpp | 10 +-- src/modes/linear_world.hpp | 4 +- src/modes/three_strikes_battle.cpp | 8 +-- src/modes/three_strikes_battle.hpp | 8 +-- src/modes/world.cpp | 5 +- src/modes/world.hpp | 10 +-- src/states_screens/race_gui.cpp | 2 +- src/states_screens/race_gui.hpp | 47 +++++--------- src/states_screens/race_gui_base.hpp | 72 ++++++++++++++++++++++ src/tracks/track.cpp | 2 +- 21 files changed, 129 insertions(+), 70 deletions(-) create mode 100644 src/states_screens/race_gui_base.hpp diff --git a/src/Makefile.am b/src/Makefile.am index eedf63577..823dd08ab 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -314,6 +314,7 @@ supertuxkart_SOURCES = \ states_screens/addons_screen.hpp \ states_screens/addons_update_screen.cpp \ states_screens/addons_update_screen.hpp \ + states_screens/race_gui_base.hpp \ states_screens/race_gui.cpp \ states_screens/race_gui.hpp \ states_screens/race_setup_screen.cpp \ diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index f3bc8ecda..c8a249f68 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -811,7 +811,7 @@ void IrrDriver::update(float dt) if (inRace) { - RaceGUI *rg = world->getRaceGUI(); + RaceGUIBase *rg = world->getRaceGUI(); for(unsigned int i=0; igetNumKarts(); i++) { Kart *kart=world->getKart(i); diff --git a/src/ide/vc9/supertuxkart.vcproj b/src/ide/vc9/supertuxkart.vcproj index 3abeb6d08..bb788f2c1 100644 --- a/src/ide/vc9/supertuxkart.vcproj +++ b/src/ide/vc9/supertuxkart.vcproj @@ -1844,6 +1844,10 @@ RelativePath="..\..\states_screens\race_gui.hpp" > + + diff --git a/src/items/flyable.cpp b/src/items/flyable.cpp index 003fc67e4..a123e66d2 100644 --- a/src/items/flyable.cpp +++ b/src/items/flyable.cpp @@ -392,7 +392,7 @@ void Flyable::hit(Kart *kart_hit, PhysicalObject* object) if (kart_hit != NULL) { - RaceGUI* gui = World::getWorld()->getRaceGUI(); + RaceGUIBase* gui = World::getWorld()->getRaceGUI(); irr::core::stringw hit_message; switch(m_type) { diff --git a/src/items/plunger.cpp b/src/items/plunger.cpp index 39b43d7af..2d013a175 100644 --- a/src/items/plunger.cpp +++ b/src/items/plunger.cpp @@ -165,7 +165,7 @@ void Plunger::hit(Kart *kart, PhysicalObject *obj) { if(isOwnerImmunity(kart)) return; - RaceGUI* gui = World::getWorld()->getRaceGUI(); + RaceGUIBase* gui = World::getWorld()->getRaceGUI(); irr::core::stringw hit_message; // pulling back makes no sense in battle mode, since this mode is not a race. diff --git a/src/items/powerup.cpp b/src/items/powerup.cpp index 8bfaaec81..bbe8c1b18 100644 --- a/src/items/powerup.cpp +++ b/src/items/powerup.cpp @@ -205,7 +205,7 @@ void Powerup::use() m_number--; World *world = World::getWorld(); - RaceGUI* gui = world->getRaceGUI(); + RaceGUIBase* gui = world->getRaceGUI(); switch (m_type) { case PowerupManager::POWERUP_ZIPPER: m_owner->handleZipper(); diff --git a/src/items/rubber_band.cpp b/src/items/rubber_band.cpp index 70f359e1d..ed1ed6dda 100644 --- a/src/items/rubber_band.cpp +++ b/src/items/rubber_band.cpp @@ -234,7 +234,7 @@ void RubberBand::hit(Kart *kart_hit, const Vec3 *track_xyz) m_hit_kart = kart_hit; m_attached_state = RB_TO_KART; - RaceGUI* gui = World::getWorld()->getRaceGUI(); + RaceGUIBase* gui = World::getWorld()->getRaceGUI(); irr::core::stringw hit_message; hit_message += StringUtils::insertValues(getPlungerString(), kart_hit->getName().c_str(), diff --git a/src/karts/controller/player_controller.cpp b/src/karts/controller/player_controller.cpp index 7ac3dde4f..c3ef280b7 100644 --- a/src/karts/controller/player_controller.cpp +++ b/src/karts/controller/player_controller.cpp @@ -29,7 +29,7 @@ #include "items/item.hpp" #include "modes/world.hpp" #include "race/history.hpp" -#include "states_screens/race_gui.hpp" +#include "states_screens/race_gui_base.hpp" #include "utils/constants.hpp" #include "utils/translation.hpp" @@ -274,7 +274,7 @@ void PlayerController::update(float dt) { if (m_penalty_time == 0.0)//eliminates machine-gun-effect for SOUND_BZZT { - RaceGUI* m=World::getWorld()->getRaceGUI(); + RaceGUIBase* m=World::getWorld()->getRaceGUI(); if(m) { m->addMessage(_("Penalty time!!"), m_kart, 2.0f, 60); diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 3d9e01e39..c59e98e3e 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -492,7 +492,7 @@ void Kart::finishedRace(float time) // Not all karts have a camera if (m_camera) m_camera->setMode(Camera::CM_FINAL); - RaceGUI* m = World::getWorld()->getRaceGUI(); + RaceGUIBase* m = World::getWorld()->getRaceGUI(); if(m) { m->addMessage((getPosition() == 1 ? _("You won the race!") : _("You finished the race!")) , @@ -511,7 +511,7 @@ void Kart::finishedRace(float time) // Not all karts have a camera if (m_camera) m_camera->setMode(Camera::CM_REVERSE); - RaceGUI* m = World::getWorld()->getRaceGUI(); + RaceGUIBase* m = World::getWorld()->getRaceGUI(); if(m) { m->addMessage((getPosition() == 2 ? _("You won the race!") : _("You finished the race!")) , diff --git a/src/modes/follow_the_leader.cpp b/src/modes/follow_the_leader.cpp index 1c7d9e70e..ed610c621 100644 --- a/src/modes/follow_the_leader.cpp +++ b/src/modes/follow_the_leader.cpp @@ -21,7 +21,7 @@ #include "challenges/unlock_manager.hpp" #include "config/user_config.hpp" #include "items/powerup_manager.hpp" -#include "states_screens/race_gui.hpp" +#include "states_screens/race_gui_base.hpp" #include "tracks/track.hpp" #include "utils/translation.hpp" @@ -134,7 +134,7 @@ std::string FollowTheLeaderRace::getIdent() const return FTL_IDENT; } //----------------------------------------------------------------------------- -RaceGUI::KartIconDisplayInfo* FollowTheLeaderRace::getKartsDisplayInfo() +RaceGUIBase::KartIconDisplayInfo* FollowTheLeaderRace::getKartsDisplayInfo() { LinearWorld::getKartsDisplayInfo(); m_kart_display_info[0].special_title = _("Leader"); diff --git a/src/modes/follow_the_leader.hpp b/src/modes/follow_the_leader.hpp index 00019e3ec..9903225c8 100644 --- a/src/modes/follow_the_leader.hpp +++ b/src/modes/follow_the_leader.hpp @@ -19,7 +19,7 @@ #define _follow_the_leader_hpp_ #include "modes/linear_world.hpp" -#include "states_screens/race_gui.hpp" +#include "states_screens/race_gui_base.hpp" /** * \brief An implementation of World, based on LinearWorld, to provide the Follow-the-leader game mode @@ -42,7 +42,7 @@ public: virtual void restartRace(); virtual std::string getIdent() const; virtual bool useFastMusicNearEnd() const { return false; } - virtual RaceGUI::KartIconDisplayInfo* getKartsDisplayInfo(); + virtual RaceGUIBase::KartIconDisplayInfo* getKartsDisplayInfo(); virtual bool isRaceOver(); virtual bool raceHasLaps(){ return false; } diff --git a/src/modes/linear_world.cpp b/src/modes/linear_world.cpp index d9be41a24..73b664793 100644 --- a/src/modes/linear_world.cpp +++ b/src/modes/linear_world.cpp @@ -16,7 +16,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "modes/linear_world.hpp" -#include "states_screens/race_gui.hpp" +#include "states_screens/race_gui_base.hpp" #include @@ -44,7 +44,7 @@ void LinearWorld::init() World::init(); const unsigned int kart_amount = m_karts.size(); - m_kart_display_info = new RaceGUI::KartIconDisplayInfo[kart_amount]; + m_kart_display_info = new RaceGUIBase::KartIconDisplayInfo[kart_amount]; for(unsigned int n=0; n -#include "states_screens/race_gui.hpp" +#include "states_screens/race_gui_base.hpp" #include "audio/music_manager.hpp" #include "tracks/track.hpp" @@ -45,7 +45,7 @@ void ThreeStrikesBattle::init() } const unsigned int kart_amount = m_karts.size(); - m_kart_display_info = new RaceGUI::KartIconDisplayInfo[kart_amount]; + m_kart_display_info = new RaceGUIBase::KartIconDisplayInfo[kart_amount]; for(unsigned int n=0; n #include "modes/world.hpp" -#include "states_screens/race_gui.hpp" +#include "states_screens/race_gui_base.hpp" /** * \brief An implementation of World, to provide the 3 strikes battle game mode @@ -37,7 +37,7 @@ private: int m_lives; }; - RaceGUI::KartIconDisplayInfo* m_kart_display_info; + RaceGUIBase::KartIconDisplayInfo* m_kart_display_info; /** This vector contains an 'BattleInfo' struct for every kart in the race. */ @@ -67,7 +67,7 @@ public: //virtual void getDefaultCollectibles(int& collectible_type, int& amount); virtual bool useFastMusicNearEnd() const { return false; } - virtual RaceGUI::KartIconDisplayInfo* getKartsDisplayInfo(); + virtual RaceGUIBase::KartIconDisplayInfo* getKartsDisplayInfo(); virtual bool raceHasLaps(){ return false; } virtual void moveKartAfterRescue(Kart* kart); @@ -80,7 +80,7 @@ public: virtual void raceResultOrder( int* order ); void updateKartRanks(); -}; +}; // ThreeStrikesBattles #endif diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 223509bbf..e464e925c 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -32,6 +32,7 @@ #include "config/user_config.hpp" #include "graphics/camera.hpp" #include "states_screens/state_manager.hpp" +#include "states_screens/race_gui_base.hpp" #include "states_screens/race_gui.hpp" #include "io/file_manager.hpp" #include "items/projectile_manager.hpp" @@ -154,7 +155,7 @@ void World::init() powerup_manager->updateWeightsForRace(num_karts); // erase messages left over - RaceGUI* m = World::getWorld()->getRaceGUI(); + RaceGUIBase* m = World::getWorld()->getRaceGUI(); if (m) m->clearAllMessages(); } // init @@ -293,7 +294,7 @@ void World::terminateRace() updateHighscores(); unlock_manager->raceFinished(); - RaceGUI* m = World::getWorld()->getRaceGUI(); + RaceGUIBase* m = World::getWorld()->getRaceGUI(); if (m) m->clearAllMessages(); WorldStatus::terminateRace(); diff --git a/src/modes/world.hpp b/src/modes/world.hpp index 86c17de75..17513ee31 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -28,7 +28,7 @@ #include "network/network_kart.hpp" #include "physics/physics.hpp" #include "race/highscores.hpp" -#include "states_screens/race_gui.hpp" +#include "states_screens/race_gui_base.hpp" #include "utils/random_generator.hpp" class btRigidBody; @@ -127,7 +127,7 @@ protected: Track* m_track; /** Pointer to the race GUI. The race GUI is handedl by world. */ - RaceGUI *m_race_gui; + RaceGUIBase *m_race_gui; bool m_clear_back_buffer; @@ -170,10 +170,10 @@ public: /** Put race into limbo phase */ void disableRace(); - /** Returns a pointer to the race gui. */ - RaceGUI *getRaceGUI() const { return m_race_gui; } Kart *getPlayerKart(unsigned int player) const; Kart *getLocalPlayerKart(unsigned int n) const; + /** Returns a pointer to the race gui. */ + RaceGUIBase *getRaceGUI() const { return m_race_gui; } unsigned int getNumKarts() const { return m_karts.size(); } Kart *getKart(int kartId) const { assert(kartId >= 0 && kartId < int(m_karts.size())); @@ -227,7 +227,7 @@ public: /** Called by the code that draws the list of karts on the race GUI * to know what needs to be drawn in the current mode */ - virtual RaceGUI::KartIconDisplayInfo* getKartsDisplayInfo() = 0; + virtual RaceGUIBase::KartIconDisplayInfo* getKartsDisplayInfo() = 0; /** Since each mode will have a different way of deciding where a rescued * kart is dropped, this method will be called and each mode can implement it. diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index 796948631..81faab543 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -244,7 +244,7 @@ void RaceGUI::renderGlobal(float dt) } drawGlobalMiniMap(); - RaceGUI::KartIconDisplayInfo* info = world->getKartsDisplayInfo(); + KartIconDisplayInfo* info = world->getKartsDisplayInfo(); drawGlobalPlayerIcons(info); } // renderGlobal diff --git a/src/states_screens/race_gui.hpp b/src/states_screens/race_gui.hpp index 28ac6ed5c..ef3173b9b 100644 --- a/src/states_screens/race_gui.hpp +++ b/src/states_screens/race_gui.hpp @@ -18,8 +18,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef HEADER_RACEGUI_HPP -#define HEADER_RACEGUI_HPP +#ifndef HEADER_RACE_GUI_HPP +#define HEADER_RACE_GUI_HPP #include #include @@ -27,8 +27,8 @@ #include "irrlicht.h" using namespace irr; - #include "config/player.hpp" +#include "states_screens/race_gui_base.hpp" class InputMap; class Kart; @@ -39,28 +39,8 @@ class RaceSetup; * \brief Handles the in-race GUI (messages, mini-map, rankings, timer, etc...) * \ingroup states_screens */ -class RaceGUI +class RaceGUI : public RaceGUIBase { -public: - /** - * Used to display the list of karts and their times or - * whatever other info is relevant to the current mode. - */ - struct KartIconDisplayInfo - { - /** text to display next to icon, if any */ - irr::core::stringw m_text; - - /** text color, if any text */ - float r, g, b; - - /** if this kart has a special title, e.g. "leader" in follow-the-leader */ - irr::core::stringw special_title; - - /** Current lap of this kart, or -1 if irrelevant */ - int lap; - }; // KartIconDisplayInfo - private: class TimedMessage { @@ -191,19 +171,20 @@ public: RaceGUI(); ~RaceGUI(); - void renderGlobal(float dt); - void renderPlayerView(const Kart *kart); + virtual void renderGlobal(float dt); + virtual void renderPlayerView(const Kart *kart); - void addMessage(const irr::core::stringw &m, const Kart *kart, float time, - int fonst_size, - const video::SColor &color=video::SColor(255, 255, 0, 255), - bool important=true); + virtual void addMessage(const irr::core::stringw &m, const Kart *kart, + float time, int fonst_size, + const video::SColor &color= + video::SColor(255, 255, 0, 255), + bool important=true); - void clearAllMessages() { m_messages.clear(); } + virtual void clearAllMessages() { m_messages.clear(); } /** Returns the size of the texture on which to render the minimap to. */ - const core::dimension2du getMiniMapSize() const + virtual const core::dimension2du getMiniMapSize() const { return core::dimension2du(m_map_width, m_map_height); } -}; +}; // RaceGUI #endif diff --git a/src/states_screens/race_gui_base.hpp b/src/states_screens/race_gui_base.hpp new file mode 100644 index 000000000..a78b46fcb --- /dev/null +++ b/src/states_screens/race_gui_base.hpp @@ -0,0 +1,72 @@ +// $Id: race_gui_base.hpp 5310 2010-04-28 18:26:23Z auria $ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2010 Joerg Henrichs +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef HEADER_RACE_GUI_BASE_HPP +#define HEADER_RACE_GUI_BASE_HPP + +/** + * \brief An abstract base class for the two race guis (race_gui and + * race_result gui) + * \ingroup states_screens + */ +class Kart; + +class RaceGUIBase +{ +public: + /** + * Used to display the list of karts and their times or + * whatever other info is relevant to the current mode. + */ + struct KartIconDisplayInfo + { + /** text to display next to icon, if any */ + irr::core::stringw m_text; + + /** text color, if any text */ + float r, g, b; + + /** if this kart has a special title, e.g. "leader" in follow-the-leader */ + irr::core::stringw special_title; + + /** Current lap of this kart, or -1 if irrelevant */ + int lap; + }; // KartIconDisplayInfo + +public: + + RaceGUIBase() {}; + virtual ~RaceGUIBase() {}; + virtual void renderGlobal(float dt) = 0; + virtual void renderPlayerView(const Kart *kart) = 0; + virtual void addMessage(const irr::core::stringw &m, const Kart *kart, + float time, + int fonst_size, + const video::SColor &color= + video::SColor(255, 255, 0, 255), + bool important=true) = 0; + + virtual void clearAllMessages() = 0; + + /** Returns the size of the texture on which to render the minimap to. */ + virtual const core::dimension2du + getMiniMapSize() const = 0; +}; // RaceGUIBase + +#endif diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index a048339d6..15d4a186f 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -45,7 +45,7 @@ using namespace irr; #include "physics/physical_object.hpp" #include "physics/triangle_mesh.hpp" #include "race/race_manager.hpp" -#include "states_screens/race_gui.hpp" +#include "states_screens/race_gui_base.hpp" #include "tracks/bezier_curve.hpp" #include "tracks/check_manager.hpp" #include "tracks/quad_graph.hpp"