Combined GPInfoScreen and RandomGPInfoScreen into one class, requiring

only one stkgui file.
This commit is contained in:
hiker
2014-09-04 16:49:15 +10:00
parent 7c3164a9c1
commit 8ffe09de29
5 changed files with 39 additions and 141 deletions

View File

@@ -2,13 +2,13 @@
<stkgui>
<icon-button id="back" x="0" y="0" height="8%" icon="gui/back.png"/>
<div x="1%" y="1%" width="98%" height="98%" layout="vertical-row">
<div x="1%" y="1%" width="96%" height="98%" layout="vertical-row">
<header id="name" width="100%" text_align="center"/>
<header id="name" width="80%" align="center" text_align="center"/>
<spacer width="1" height="5%"/>
<box width="95%" height="50%" padding="10" layout="horizontal-row">
<box width="95%" height="40%" padding="10" layout="horizontal-row">
<spacer width="10" height="100%"/>
<!-- Left pane -->
<div width="45%" height="95%" align="center" layout="vertical-row">
@@ -25,37 +25,35 @@
</box>
<spacer width="1" height="3%"/>
<box width="95%" height="17%" padding="10" layout="horizontal-row">
<box width="95%" height="30%" padding="10" layout="horizontal-row">
<spacer width="1" height="5%"/>
<div width="50%" height="100%" layout="vertical-row">
<div width="100%" height="fit" layout="horizontal-row" >
<label id="ai-text" height="100%" width="40%" I18N="Number of AI karts" text="AI karts"/>
<spinner id="ai-spinner" width="40%" min_value="1" max_value="20" align="center"
<label id="ai-text" height="100%" width="50%" I18N="Number of AI karts" text="AI karts"/>
<spinner id="ai-spinner" width="50%" min_value="1" max_value="20" align="center"
wrap_around="true" />
<spacer proportion="1" height="2" />
</div>
<spacer height="5%" />
<div width="100%" height="fit" layout="horizontal-row" >
<label id="reverse-text" height="100%" width="40%" I18N="Drive the track reverse" text="Reverse"/>
<label id="reverse-text" width="50%" height="100%" I18N="Drive the track reverse" text="Reverse"/>
<spinner id="reverse-spinner" width="50%" align="center" wrap_around="true" />
<spacer proportion="1" height="2" />
</div>
</div>
<div width="50%" height="100%" layout="vertical-row">
<div width="100%" height="fit" layout="horizontal-row" >
<label id="track-text" height="100%" width="50%" text="Tracks"
<spacer height="5%" />
<div width="100%" height="fit" layout="horizontal-row">
<label id="track-text" width="50%" height="100%" text="Tracks"
I18N="Number of tracks to pick in a random Grand Prix."/>
<spinner id="track-spinner" width="50%" min_value="1" max_value="20" align="center"
wrap_around="true" />
<spacer proportion="1" height="2" />
<spacer height="1%" />
</div>
<spacer height="5%" />
<div width="100%" height="fit" layout="horizontal-row" >
<label id="group-text" height="100%" width="50%" I18N="Number of AI karts" text="Track group"/>
<label id="group-text" width="50%" height="100%" I18N="Number of AI karts" text="Track group"/>
<spinner id="group-spinner" width="50%" align="center" wrap_around="true" />
<spacer proportion="1" height="2" />
</div>
</div>
<spacer width="1" height="2%"/>
</box>
<spacer width="1" height="2%"/>
<buttonbar id="buttons" height="15%" width="100%" align="center">
@@ -64,7 +62,7 @@
I18N="Start race" text="Start Race"/>
<icon-button id="continue" width="64" height="64" icon="gui/green_check.png"
I18N="Continue race" text="Continue Race"/>
I18N="Continue saved GP" text="Continue saved GP"/>
</buttonbar>
</div>

View File

@@ -1,69 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<stkgui>
<icon-button id="back" x="0" y="0" height="8%" icon="gui/back.png"/>
<div x="1%" y="1%" width="96%" height="98%" layout="vertical-row">
<header id="name" width="80%" align="center" text_align="center"/>
<spacer width="1" height="5%"/>
<box width="95%" height="40%" padding="10" layout="horizontal-row">
<spacer width="10" height="100%"/>
<!-- Left pane -->
<div width="45%" height="95%" align="center" layout="vertical-row">
<placeholder proportion="1" width="100%" height="100%" id="screenshot_div">
</placeholder>
</div>
<spacer width="5%" height="100%"/>
<!-- Right pane -->
<div width="45%" height="95%" align="center" layout="vertical-row">
<list id="tracks" width="100%" height="100%"/>
</div>
</box>
<spacer width="1" height="3%"/>
<box width="95%" height="30%" padding="10" layout="horizontal-row">
<spacer width="1" height="5%"/>
<div width="50%" height="100%" layout="vertical-row">
<div width="100%" height="fit" layout="horizontal-row" >
<label id="ai-text" height="100%" width="50%" I18N="Number of AI karts" text="AI karts"/>
<spinner id="ai-spinner" width="50%" min_value="1" max_value="20" align="center"
wrap_around="true" />
</div>
<spacer height="5%" />
<div width="100%" height="fit" layout="horizontal-row" >
<label id="reverse-text" width="50%" height="100%" I18N="Drive the track reverse" text="Reverse"/>
<spinner id="reverse-spinner" width="50%" align="center" wrap_around="true" />
</div>
<spacer height="5%" />
<div width="100%" height="fit" layout="horizontal-row">
<label id="track-text" width="50%" height="100%" text="Tracks"
I18N="Number of tracks to pick in a random Grand Prix."/>
<spinner id="track-spinner" width="50%" min_value="1" max_value="20" align="center"
wrap_around="true" />
<spacer height="1%" />
</div>
<spacer height="5%" />
<div width="100%" height="fit" layout="horizontal-row" >
<label id="group-text" width="50%" height="100%" I18N="Number of AI karts" text="Track group"/>
<spinner id="group-spinner" width="50%" align="center" wrap_around="true" />
<spacer proportion="1" height="2" />
</div>
</div>
</box>
<spacer width="1" height="2%"/>
<buttonbar id="buttons" height="15%" width="100%" align="center">
<icon-button id="start" width="64" height="64" icon="gui/green_check.png"
I18N="Start race" text="Start Race"/>
<icon-button id="continue" width="64" height="64" icon="gui/green_check.png"
I18N="Continue saved GP" text="Continue saved GP"/>
</buttonbar>
</div>
</stkgui>

View File

@@ -25,7 +25,6 @@
#include "graphics/irr_driver.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/screen.hpp"
#include "guiengine/widgets/check_box_widget.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/list_widget.hpp"
@@ -52,23 +51,22 @@ using GUIEngine::PROP_ID;
using namespace GUIEngine;
DEFINE_SCREEN_SINGLETON( GPInfoScreen );
DEFINE_SCREEN_SINGLETON( RandomGPInfoScreen );
BaseGPInfoScreen::BaseGPInfoScreen(const std::string &name) : Screen(name.c_str())
GPInfoScreen::GPInfoScreen() : Screen("gp_info.stkgui")
{
m_curr_time = 0.0f;
// Necessary to test if loadedFroMFile() was executed (in setGP)
m_reverse_spinner = NULL;
} // BaseGPInfoScreen
} // GPInfoScreen
// ----------------------------------------------------------------------------
BaseGPInfoScreen::~BaseGPInfoScreen()
GPInfoScreen::~GPInfoScreen()
{
} // ~BaseGPInfoScreen
} // ~GPInfoScreen
// ----------------------------------------------------------------------------
void BaseGPInfoScreen::loadedFromFile()
void GPInfoScreen::loadedFromFile()
{
// The group spinner is filled in init every time the screen is shown
// (since the groups can change if addons are added/deleted).
@@ -91,7 +89,7 @@ void BaseGPInfoScreen::loadedFromFile()
/** Sets the GP to be displayed. If the identifier is 'random', no gp info
* will be loaded.
*/
void BaseGPInfoScreen::setGP(const std::string &gp_ident)
void GPInfoScreen::setGP(const std::string &gp_ident)
{
if(gp_ident!="random")
m_gp = *grand_prix_manager->getGrandPrix(gp_ident);
@@ -106,7 +104,7 @@ void BaseGPInfoScreen::setGP(const std::string &gp_ident)
} // setGP
// ----------------------------------------------------------------------------
GrandPrixData::GPReverseType BaseGPInfoScreen::getReverse() const
GrandPrixData::GPReverseType GPInfoScreen::getReverse() const
{
switch (m_reverse_spinner->getValue())
{
@@ -120,7 +118,7 @@ GrandPrixData::GPReverseType BaseGPInfoScreen::getReverse() const
} // getReverse
// ----------------------------------------------------------------------------
void BaseGPInfoScreen::init()
void GPInfoScreen::init()
{
Screen::init();
m_curr_time = 0.0f;
@@ -206,7 +204,7 @@ void BaseGPInfoScreen::init()
// ----------------------------------------------------------------------------
/** Updates the list of tracks shown.
*/
void BaseGPInfoScreen::addTracks()
void GPInfoScreen::addTracks()
{
const std::vector<std::string> tracks = m_gp.getTrackNames();
@@ -223,7 +221,7 @@ void BaseGPInfoScreen::addTracks()
// ----------------------------------------------------------------------------
/** Creates a screenshot widget in the placeholder of the GUI.
*/
void BaseGPInfoScreen::addScreenshot()
void GPInfoScreen::addScreenshot()
{
Widget* screenshot_div = getWidget("screenshot_div");
@@ -254,7 +252,7 @@ void BaseGPInfoScreen::addScreenshot()
// ----------------------------------------------------------------------------
void BaseGPInfoScreen::onEnterPressedInternal()
void GPInfoScreen::onEnterPressedInternal()
{
// Save the GP id because dismiss() will destroy this instance
GrandPrixData gp_data = m_gp;
@@ -264,7 +262,7 @@ void BaseGPInfoScreen::onEnterPressedInternal()
}
// ----------------------------------------------------------------------------
void BaseGPInfoScreen::updateRandomGP()
void GPInfoScreen::updateRandomGP()
{
// First get the right track group to use
const std::vector<std::string>& groups = track_manager->getAllTrackGroups();
@@ -287,7 +285,7 @@ void BaseGPInfoScreen::updateRandomGP()
// ----------------------------------------------------------------------------
/** Handle user input.
*/
void BaseGPInfoScreen::eventCallback(GUIEngine::Widget *, const std::string &name,
void GPInfoScreen::eventCallback(GUIEngine::Widget *, const std::string &name,
const int player_id)
{
if(name=="buttons")
@@ -356,7 +354,7 @@ void BaseGPInfoScreen::eventCallback(GUIEngine::Widget *, const std::string &nam
/** Called every update. Used to cycle the screenshots.
* \param dt Time step size.
*/
void BaseGPInfoScreen::onUpdate(float dt)
void GPInfoScreen::onUpdate(float dt)
{
if (dt == 0)
return; // if nothing changed, return right now

View File

@@ -35,7 +35,8 @@ namespace GUIEngine
* \brief Dialog that shows information about a specific grand prix
* \ingroup states_screens
*/
class BaseGPInfoScreen : public GUIEngine::Screen
class GPInfoScreen : public GUIEngine::Screen,
public GUIEngine::ScreenSingleton<GPInfoScreen>
{
private:
/** Spinner for the different track groups. */
@@ -53,7 +54,7 @@ private:
/** The currently selected group name. */
std::string m_group_name;
protected: // Necessary for RandomBaseGPInfoScreen
protected: // Necessary for RandomGPInfoScreen
GUIEngine::IconButtonWidget* m_screenshot_widget;
float m_curr_time;
@@ -70,10 +71,10 @@ protected: // Necessary for RandomBaseGPInfoScreen
GrandPrixData::GPReverseType getReverse() const;
public:
BaseGPInfoScreen(const std::string &name);
GPInfoScreen();
/** Places the focus back on the selected GP, in the case that the dialog
* was cancelled and we're returning to the track selection screen */
virtual ~BaseGPInfoScreen();
virtual ~GPInfoScreen();
void onEnterPressedInternal();
virtual void eventCallback(GUIEngine::Widget *, const std::string &name,
@@ -84,28 +85,6 @@ public:
virtual void onUpdate(float dt);
void setGP(const std::string &gp_ident);
}; // BaseGPInfoScreen
// ============================================================================
class GPInfoScreen: public BaseGPInfoScreen,
public GUIEngine::ScreenSingleton<GPInfoScreen>
{
private:
GPInfoScreen() : BaseGPInfoScreen("gp_info.stkgui")
{};
public:
friend class GUIEngine::ScreenSingleton<GPInfoScreen>;
}; // class GPInfoScreen
// ============================================================================
class RandomGPInfoScreen: public BaseGPInfoScreen,
public GUIEngine::ScreenSingleton<RandomGPInfoScreen>
{
private:
RandomGPInfoScreen() : BaseGPInfoScreen("random_gp_info.stkgui")
{};
public:
friend class GUIEngine::ScreenSingleton<RandomGPInfoScreen>;
}; // class RandomGPInfoScreen
}; // GPInfoScreen
#endif

View File

@@ -114,18 +114,10 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name,
}
else
{
if (selection == "Random Grand Prix")
{
RandomGPInfoScreen *gpis = RandomGPInfoScreen::getInstance();
gpis->setGP("random");
StateManager::get()->pushScreen(gpis);
}
else
{
GPInfoScreen *gpis = GPInfoScreen::getInstance();
gpis->setGP(selection);
StateManager::get()->pushScreen(gpis);
}
GPInfoScreen *gpis = GPInfoScreen::getInstance();
gpis->setGP( selection == "Random Grand Prix" ? "random"
: selection);
StateManager::get()->pushScreen(gpis);
}
}
else if (name == "trackgroups")