Icon button for race result (#4071)

* Icons for race result

* Fix bugs && improvements

* Tabs to spaces

* Fix bugs && improvements
This commit is contained in:
Du maosen 2019-09-30 15:33:07 +08:00 committed by Benau
parent 98d8aca91a
commit 71fec6780c
2 changed files with 242 additions and 218 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<stkgui> <stkgui>
<div x="2%" y="5%" width="100%" height="95%" layout="vertical-row" id="div"> <div x="3%" y="2%" width="94%" height="96%" layout="vertical-row" id="div">
<roundedbox width="90%" proportion="1" align="center"> <roundedbox width="100%" height="100%" align="center">
<div id="result-table" width="96%" height="96%" x="2%" y="2%"> <div x="2%" y="2%" width="96%" height="96%" layout="vertical-row">
<div id="result-table" width="100%" height="80%">
<!-- Contents is added programatically --> <!-- Contents is added programatically -->
</div> </div>
</roundedbox> <spacer height="3%" width="100%"/>
<spacer height="1%" width="96%"/>
<!-- The actual button texts will vary depending on what type of race <!-- The actual button texts will vary depending on what type of race
was being run, and if something was unlocked etc. So we don't was being run, and if something was unlocked etc. So we don't
specify a text here, and label the buttons : specify a text here, and label the buttons :
@ -15,11 +15,13 @@
bottom: 'Abort GP', 'Back to the menu' (or invisible) bottom: 'Abort GP', 'Back to the menu' (or invisible)
Setting text=" " is important, otherwise the height of the Setting text=" " is important, otherwise the height of the
widget is incorrect. --> widget is incorrect. -->
<button id="top" align="center" width="60%"/> <buttonbar id="operations" width="65%" height="18%" align="center">
<spacer height="1%" width="96%"/> <icon-button id="left" width="128" height="128" text="Left"/>
<button id="middle" align="center" width="60%"/> <icon-button id="middle" width="128" height="128" text="Middle"/>
<spacer height="1%" width="96%"/> <icon-button id="right" width="128" height="128" text="Right"/>
<button id="bottom" align="center" width="60%"/> </buttonbar>
<spacer height="1%" width="96%"/> </div>
</roundedbox>
<spacer height="3%" width="90%"/>
</div> </div>
</stkgui> </stkgui>

View File

@ -34,6 +34,7 @@
#include "guiengine/widget.hpp" #include "guiengine/widget.hpp"
#include "guiengine/widgets/icon_button_widget.hpp" #include "guiengine/widgets/icon_button_widget.hpp"
#include "guiengine/widgets/label_widget.hpp" #include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "io/file_manager.hpp" #include "io/file_manager.hpp"
#include "karts/abstract_kart.hpp" #include "karts/abstract_kart.hpp"
#include "karts/controller/controller.hpp" #include "karts/controller/controller.hpp"
@ -83,9 +84,9 @@ void RaceResultGUI::init()
m_timer = 0; m_timer = 0;
getWidget("top")->setVisible(false); getWidget("left")->setVisible(false);
getWidget("middle")->setVisible(false); getWidget("middle")->setVisible(false);
getWidget("bottom")->setVisible(false); getWidget("right")->setVisible(false);
music_manager->stopMusic(); music_manager->stopMusic();
@ -159,9 +160,9 @@ void RaceResultGUI::tearDown()
*/ */
void RaceResultGUI::enableAllButtons() void RaceResultGUI::enableAllButtons()
{ {
GUIEngine::Widget *top = getWidget("top"); GUIEngine::IconButtonWidget *left = getWidget<GUIEngine::IconButtonWidget>("left");
GUIEngine::Widget *middle = getWidget("middle"); GUIEngine::IconButtonWidget *middle = getWidget<GUIEngine::IconButtonWidget>("middle");
GUIEngine::Widget *bottom = getWidget("bottom"); GUIEngine::IconButtonWidget *right = getWidget<GUIEngine::IconButtonWidget>("right");
if (race_manager->getMajorMode() == RaceManager::MAJOR_MODE_GRAND_PRIX) if (race_manager->getMajorMode() == RaceManager::MAJOR_MODE_GRAND_PRIX)
{ {
@ -171,12 +172,14 @@ void RaceResultGUI::enableAllButtons()
// If we're in a network world, change the buttons text // If we're in a network world, change the buttons text
if (World::getWorld()->isNetworkWorld()) if (World::getWorld()->isNetworkWorld())
{ {
top->setVisible(false); left->setLabel(_("Continue"));
middle->setText(_("Continue")); left->setImage("gui/icons/green_check.png");
middle->setVisible(true); left->setVisible(true);
middle->setFocusForPlayer(PLAYER_ID_GAME_MASTER); left->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
bottom->setText(_("Quit the server")); middle->setVisible(false);
bottom->setVisible(true); right->setLabel(_("Quit the server"));
right->setImage("gui/icons/main_quit.png");
right->setVisible(true);
return; return;
} }
@ -187,30 +190,40 @@ void RaceResultGUI::enableAllButtons()
(race_manager->getMajorMode() != RaceManager::MAJOR_MODE_GRAND_PRIX || (race_manager->getMajorMode() != RaceManager::MAJOR_MODE_GRAND_PRIX ||
race_manager->getTrackNumber() + 1 == race_manager->getNumOfTracks() ) ) race_manager->getTrackNumber() + 1 == race_manager->getNumOfTracks() ) )
{ {
top->setText(n == 1 ? _("You completed a challenge!") middle->setLabel(n == 1 ? _("You completed a challenge!")
: _("You completed challenges!")); : _("You completed challenges!"));
top->setVisible(true); middle->setImage("gui/icons/cup_gold.png");
top->setFocusForPlayer(PLAYER_ID_GAME_MASTER); middle->setVisible(true);
middle->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
} }
else if (race_manager->getMajorMode() == RaceManager::MAJOR_MODE_GRAND_PRIX) else if (race_manager->getMajorMode() == RaceManager::MAJOR_MODE_GRAND_PRIX)
{ {
// In case of a GP: // In case of a GP:
// ---------------- // ----------------
top->setVisible(false); middle->setLabel(_("Continue"));
top->setFocusable(false); middle->setImage("gui/icons/green_check.png");
middle->setVisible(false);
middle->setFocusable(false);
right->setVisible(false);
right->setFocusable(false);
middle->setText(_("Continue")); // Two continue buttons to make sure the buttons in the bar is balanced
middle->setVisible(true); left->setLabel(_("Continue"));
left->setImage("gui/icons/green_check.png");
left->setVisible(true);
if (race_manager->getTrackNumber() + 1 < race_manager->getNumOfTracks()) if (race_manager->getTrackNumber() + 1 < race_manager->getNumOfTracks())
{ {
bottom->setText(_("Abort Grand Prix")); right->setLabel(_("Abort Grand Prix"));
bottom->setVisible(true); right->setImage("gui/icons/race_giveup.png");
bottom->setFocusable(true); right->setVisible(true);
right->setFocusable(true);
} }
else else
{ {
bottom->setFocusable(false); left->setVisible(false);
left->setFocusable(false);
middle->setVisible(true);
} }
middle->setFocusForPlayer(PLAYER_ID_GAME_MASTER); middle->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
@ -220,24 +233,28 @@ void RaceResultGUI::enableAllButtons()
// Normal race // Normal race
// ----------- // -----------
middle->setText(_("Restart")); left->setLabel(_("Restart"));
middle->setVisible(true); left->setImage("gui/icons/restart.png");
middle->setFocusForPlayer(PLAYER_ID_GAME_MASTER); left->setVisible(true);
left->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
if (race_manager->raceWasStartedFromOverworld()) if (race_manager->raceWasStartedFromOverworld())
{ {
top->setVisible(false); middle->setVisible(false);
bottom->setText(_("Back to challenge selection")); right->setLabel(_("Back to challenge selection"));
right->setImage("gui/icons/back.png");
} }
else else
{ {
middle->setImage("gui/icons/main_race.png");
if (race_manager->isRecordingRace()) if (race_manager->isRecordingRace())
top->setText(_("Race against the new ghost replay")); middle->setLabel(_("Race against the new ghost replay"));
else else
top->setText(_("Setup New Race")); middle->setLabel(_("Setup New Race"));
top->setVisible(true); middle->setVisible(true);
bottom->setText(_("Back to the menu")); right->setLabel(_("Back to the menu"));
right->setImage("gui/icons/back.png");
} }
bottom->setVisible(true); right->setVisible(true);
} }
} // enableAllButtons } // enableAllButtons
@ -260,18 +277,22 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget,
displayScreenShots(); displayScreenShots();
} }
if(name == "operations")
{
const std::string& action =
getWidget<GUIEngine::RibbonWidget>("operations")->getSelectionIDString(PLAYER_ID_GAME_MASTER);
// If we're playing online : // If we're playing online :
if (World::getWorld()->isNetworkWorld()) if (World::getWorld()->isNetworkWorld())
{ {
if (name == "middle") // Continue button (return to server lobby) if (action == "left") // Continue button (return to server lobby)
{ {
// Signal to the server that this client is back in the lobby now. // Signal to the server that this client is back in the lobby now.
auto cl = LobbyProtocol::get<ClientLobby>(); auto cl = LobbyProtocol::get<ClientLobby>();
if (cl) if (cl)
cl->doneWithResults(); cl->doneWithResults();
getWidget("middle")->setText(_("Waiting for others")); getWidget<GUIEngine::IconButtonWidget>("left")->setLabel(_("Waiting for others"));
} }
if (name == "bottom") // Quit server (return to online lan / wan menu) if (action == "right") // Quit server (return to online lan / wan menu)
{ {
race_manager->clearNetworkGrandPrixResult(); race_manager->clearNetworkGrandPrixResult();
if (STKHost::existHost()) if (STKHost::existHost())
@ -297,7 +318,7 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget,
race_manager->getTrackNumber() + 1 == race_manager->getNumOfTracks() ) ) race_manager->getTrackNumber() + 1 == race_manager->getNumOfTracks() ) )
{ {
if (name == "top") if (action == "middle")
{ {
if (race_manager->getMajorMode() == RaceManager::MAJOR_MODE_GRAND_PRIX) if (race_manager->getMajorMode() == RaceManager::MAJOR_MODE_GRAND_PRIX)
{ {
@ -368,34 +389,38 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget,
return; return;
} }
Log::warn("RaceResultGUI", "Incorrect event '%s' when things are unlocked.", Log::warn("RaceResultGUI", "Incorrect event '%s' when things are unlocked.",
name.c_str()); action.c_str());
} }
// Next check for GP // Next check for GP
// ----------------- // -----------------
if (race_manager->getMajorMode() == RaceManager::MAJOR_MODE_GRAND_PRIX) if (race_manager->getMajorMode() == RaceManager::MAJOR_MODE_GRAND_PRIX)
{ {
if (name == "middle") // Next GP if (action == "left" || action == "middle") // Next GP
{ {
cleanupGPProgress(); cleanupGPProgress();
StateManager::get()->popMenu(); StateManager::get()->popMenu();
race_manager->next(); race_manager->next();
} }
else if (name == "bottom") // Abort else if (action == "right") // Abort
{ {
new MessageDialog(_("Do you really want to abort the Grand Prix?"), new MessageDialog(_("Do you really want to abort the Grand Prix?"),
MessageDialog::MESSAGE_DIALOG_CONFIRM, this, false); MessageDialog::MESSAGE_DIALOG_CONFIRM, this, false);
} }
else if (!getWidget(name.c_str())->isVisible()) else if (!getWidget(action.c_str())->isVisible())
{ {
Log::warn("RaceResultGUI", "Incorrect event '%s' when things are unlocked.", Log::warn("RaceResultGUI", "Incorrect event '%s' when things are unlocked.",
name.c_str()); action.c_str());
} }
return; return;
} }
StateManager::get()->popMenu(); StateManager::get()->popMenu();
if (name == "top") // Setup new race if (action == "left") // Restart
{
race_manager->rerunRace();
}
else if (action == "middle") // Setup new race
{ {
// Save current race data for race against new ghost // Save current race data for race against new ghost
std::string track_name = race_manager->getTrackName(); std::string track_name = race_manager->getTrackName();
@ -438,11 +463,7 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget,
StateManager::get()->resetAndSetStack(newStack); StateManager::get()->resetAndSetStack(newStack);
} }
} }
else if (name == "middle") // Restart else if (action == "right") // Back to main
{
race_manager->rerunRace();
}
else if (name == "bottom") // Back to main
{ {
race_manager->exitRace(); race_manager->exitRace();
race_manager->setAIKartOverride(""); race_manager->setAIKartOverride("");
@ -453,6 +474,7 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget,
OverWorld::enterOverWorld(); OverWorld::enterOverWorld();
} }
} }
}
else else
Log::warn("RaceResultGUI", "Incorrect event '%s' for normal race.", Log::warn("RaceResultGUI", "Incorrect event '%s' for normal race.",
name.c_str()); name.c_str());