Added 'reload' random GP support, fixed 'back' icon on screen.

This commit is contained in:
hiker 2014-09-04 09:38:25 +10:00
parent 12e403b909
commit 7c3164a9c1
3 changed files with 44 additions and 11 deletions

View File

@ -2,9 +2,9 @@
<stkgui> <stkgui>
<icon-button id="back" x="0" y="0" height="8%" icon="gui/back.png"/> <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%"/> <spacer width="1" height="5%"/>
@ -62,7 +62,7 @@
I18N="Start race" text="Start Race"/> I18N="Start race" text="Start Race"/>
<icon-button id="continue" width="64" height="64" icon="gui/green_check.png" <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> </buttonbar>
</div> </div>

View File

@ -73,7 +73,7 @@ void BaseGPInfoScreen::loadedFromFile()
// The group spinner is filled in init every time the screen is shown // The group spinner is filled in init every time the screen is shown
// (since the groups can change if addons are added/deleted). // (since the groups can change if addons are added/deleted).
m_group_spinner = getWidget<SpinnerWidget>("group-spinner"); m_group_spinner = getWidget<SpinnerWidget>("group-spinner");
m_continue_button = getWidget<IconButtonWidget>("continue");
m_reverse_spinner = getWidget<SpinnerWidget>("reverse-spinner"); m_reverse_spinner = getWidget<SpinnerWidget>("reverse-spinner");
m_reverse_spinner->addLabel(_("No")); m_reverse_spinner->addLabel(_("No"));
m_reverse_spinner->addLabel(_("Yes")); m_reverse_spinner->addLabel(_("Yes"));
@ -136,8 +136,12 @@ void BaseGPInfoScreen::init()
if(random) if(random)
{ {
RibbonWidget *rb = getWidget<RibbonWidget>("buttons");
rb->setLabel(1,_(L"Reload") );
getWidget<LabelWidget>("name")->setText(_("Random Grand Prix"), false); getWidget<LabelWidget>("name")->setText(_("Random Grand Prix"), false);
getWidget<IconButtonWidget>("continue")->setVisible(false); std::string restart = file_manager->getAsset(FileManager::GUI, "restart.png");
m_continue_button->setImage(restart, IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
m_continue_button->setVisible(true);
// We have to recreate the group spinner, but a new group might have // We have to recreate the group spinner, but a new group might have
// been added or deleted since the last time this screen was shown. // been added or deleted since the last time this screen was shown.
@ -190,7 +194,9 @@ void BaseGPInfoScreen::init()
race_manager->getNumberOfKarts(), race_manager->getNumberOfKarts(),
race_manager->getNumLocalPlayers()); race_manager->getNumLocalPlayers());
getWidget<IconButtonWidget>("continue")->setVisible(saved_gp != NULL); //I18N: Continue a previously saved Grand Prix.
m_continue_button->setText(_(L"Continue saved GP"));
m_continue_button->setVisible(saved_gp != NULL);
} }
addTracks(); addTracks();
@ -198,7 +204,8 @@ void BaseGPInfoScreen::init()
} // init } // init
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Updates the list of tracks shown.
*/
void BaseGPInfoScreen::addTracks() void BaseGPInfoScreen::addTracks()
{ {
const std::vector<std::string> tracks = m_gp.getTrackNames(); const std::vector<std::string> tracks = m_gp.getTrackNames();
@ -214,7 +221,8 @@ void BaseGPInfoScreen::addTracks()
} // addTracks } // addTracks
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Creates a screenshot widget in the placeholder of the GUI.
*/
void BaseGPInfoScreen::addScreenshot() void BaseGPInfoScreen::addScreenshot()
{ {
Widget* screenshot_div = getWidget("screenshot_div"); Widget* screenshot_div = getWidget("screenshot_div");
@ -277,7 +285,8 @@ void BaseGPInfoScreen::updateRandomGP()
} // updateRandomGP } // updateRandomGP
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Handle user input.
*/
void BaseGPInfoScreen::eventCallback(GUIEngine::Widget *, const std::string &name, void BaseGPInfoScreen::eventCallback(GUIEngine::Widget *, const std::string &name,
const int player_id) const int player_id)
{ {
@ -286,8 +295,18 @@ void BaseGPInfoScreen::eventCallback(GUIEngine::Widget *, const std::string &nam
const std::string &button = getWidget<GUIEngine::RibbonWidget>("buttons") const std::string &button = getWidget<GUIEngine::RibbonWidget>("buttons")
->getSelectionIDString(PLAYER_ID_GAME_MASTER); ->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if (button == "start" || button=="continue") // The continue button becomes a 'reload' button in random GP:
if(button=="continue" && m_gp.isRandomGP())
{ {
// Create a new GP:
m_gp.createRandomGP(m_num_tracks_spinner->getValue(),
m_group_name, getReverse(),
/*new tracks*/ true );
addTracks();
}
else if (button == "start" || button=="continue")
{
// Normal GP: start/continue a saved GP
int n = getWidget<SpinnerWidget>("ai-spinner")->getValue(); int n = getWidget<SpinnerWidget>("ai-spinner")->getValue();
race_manager->setNumKarts(race_manager->getNumLocalPlayers() + n); race_manager->setNumKarts(race_manager->getNumLocalPlayers() + n);
@ -326,11 +345,17 @@ void BaseGPInfoScreen::eventCallback(GUIEngine::Widget *, const std::string &nam
{ {
m_gp.changeReverse(getReverse()); m_gp.changeReverse(getReverse());
} }
else if(name=="back")
{
StateManager::get()->escapePressed();
}
} // eventCallback } // eventCallback
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Called every update. Used to cycle the screenshots.
* \param dt Time step size.
*/
void BaseGPInfoScreen::onUpdate(float dt) void BaseGPInfoScreen::onUpdate(float dt)
{ {
if (dt == 0) if (dt == 0)

View File

@ -38,10 +38,18 @@ namespace GUIEngine
class BaseGPInfoScreen : public GUIEngine::Screen class BaseGPInfoScreen : public GUIEngine::Screen
{ {
private: private:
/** Spinner for the different track groups. */
GUIEngine::SpinnerWidget *m_group_spinner; GUIEngine::SpinnerWidget *m_group_spinner;
/** Spinner for reverse mode. */
GUIEngine::SpinnerWidget *m_reverse_spinner; GUIEngine::SpinnerWidget *m_reverse_spinner;
/** Spinner for number of tracks (in case of random GP). */
GUIEngine::SpinnerWidget *m_num_tracks_spinner; GUIEngine::SpinnerWidget *m_num_tracks_spinner;
/** The continue/reload (in case of random GP) icon. */
GUIEngine::IconButtonWidget *m_continue_button;
/** The currently selected group name. */ /** The currently selected group name. */
std::string m_group_name; std::string m_group_name;