Move repeated code to a function

This commit is contained in:
Alayan-stk-2
2018-09-13 15:14:56 +02:00
committed by GitHub
parent b413d9ef24
commit 3d14ae5bf1
2 changed files with 23 additions and 30 deletions

View File

@@ -111,35 +111,10 @@ SelectChallengeDialog::SelectChallengeDialog(const float percentWidth,
const ChallengeStatus* c = PlayerManager::getCurrentPlayer()
->getChallengeStatus(challenge_id);
if (c->isSolved(RaceManager::DIFFICULTY_EASY))
{
IconButtonWidget* btn = getWidget<IconButtonWidget>("novice");
btn->setImage(file_manager->getAsset(FileManager::GUI, "cup_bronze.png"),
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
}
if (c->isSolved(RaceManager::DIFFICULTY_MEDIUM))
{
IconButtonWidget* btn = getWidget<IconButtonWidget>("intermediate");
btn->setImage(file_manager->getAsset(FileManager::GUI,"cup_silver.png"),
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
}
if (c->isSolved(RaceManager::DIFFICULTY_HARD))
{
IconButtonWidget* btn = getWidget<IconButtonWidget>("expert");
btn->setImage(file_manager->getAsset(FileManager::GUI,"cup_gold.png"),
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
}
if (c->isSolved(RaceManager::DIFFICULTY_BEST)
&& !PlayerManager::getCurrentPlayer()->isLocked("difficulty_best"))
{
IconButtonWidget* btn = getWidget<IconButtonWidget>("supertux");
btn->setImage(file_manager->getAsset(FileManager::GUI,"cup_platinum.png"),
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
}
updateSolvedIcon(c, RaceManager::DIFFICULTY_EASY, "novice", "cup_bronze.png");
updateSolvedIcon(c, RaceManager::DIFFICULTY_MEDIUM, "intermediate", "cup_silver.png");
updateSolvedIcon(c, RaceManager::DIFFICULTY_HARD, "expert", "cup_gold.png");
updateSolvedIcon(c, RaceManager::DIFFICULTY_BEST, "supertux", "cup_platinum.png");
LabelWidget* novice_label = getWidget<LabelWidget>("novice_label");
LabelWidget* medium_label = getWidget<LabelWidget>("intermediate_label");
@@ -188,6 +163,19 @@ SelectChallengeDialog::~SelectChallengeDialog()
// ----------------------------------------------------------------------------
void SelectChallengeDialog::updateSolvedIcon(const ChallengeStatus* c, RaceManager::Difficulty diff,
const char* widget_name, const char* path)
{
if (c->isSolved(diff))
{
IconButtonWidget* btn = getWidget<IconButtonWidget>(widget_name);
btn->setImage(file_manager->getAsset(FileManager::GUI, path),
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
}
} //updateSolvedIcon
// ----------------------------------------------------------------------------
GUIEngine::EventPropagation SelectChallengeDialog::processEvent(const std::string& eventSourceParam)
{
std::string eventSource = eventSourceParam;
@@ -237,7 +225,7 @@ GUIEngine::EventPropagation SelectChallengeDialog::processEvent(const std::strin
// Initialise global data - necessary even in local games to avoid
// many if tests in other places (e.g. if network_game call
// network_manager else call race_manager).
// network_manager->initCharacterDataStructures();
// network_manager->initCharacterDataStructures();
// Launch challenge
if (eventSource == "novice")

View File

@@ -18,8 +18,10 @@
#ifndef SELECT_CHALLENGE_HPP
#define SELECT_CHALLENGE_HPP
#include "challenges/challenge_status.hpp"
#include "guiengine/event_handler.hpp"
#include "guiengine/modaldialog.hpp"
#include "race/race_manager.hpp"
/**
* \brief Dialog shown when starting a challenge
@@ -27,7 +29,10 @@
*/
class SelectChallengeDialog : public GUIEngine::ModalDialog
{
private:
std::string m_challenge_id;
void updateSolvedIcon(const ChallengeStatus* c, RaceManager::Difficulty diff,
const char* widget_name, const char* path);
public:
SelectChallengeDialog(const float percentWidth, const float percentHeight,