use parent to remove copy+paste code

This commit is contained in:
konstin
2014-07-23 16:43:25 +02:00
parent 1d8b4c352d
commit e4f7b6041c
6 changed files with 47 additions and 110 deletions

View File

@@ -16,12 +16,16 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "guiengine/scalable_font.hpp"
#include "guiengine/widgets/button_widget.hpp"
#include "modes/cutscene_world.hpp"
#include "states_screens/grand_prix_cutscene.hpp"
typedef GUIEngine::ButtonWidget Button;
/** A Button to save the GP if it was a random one */
void GrandPrixCutscene::saveGPButton()
{
#ifdef IMPLEMENTATION_FINISHED
if (race_manager->getGrandPrix().getId() == "random")
{
core::stringw text = _("Save Grand Prix");
@@ -36,4 +40,37 @@ void GrandPrixCutscene::saveGPButton()
save_button->add();
manualAddWidget(save_button);
}
}
#endif
} // saveGPButton
// ----------------------------------------------------------------------------
void GrandPrixCutscene::eventCallback(GUIEngine::Widget* widget,
const std::string& name,
const int playerID)
{
if (name == "continue")
{
((CutsceneWorld*)World::getWorld())->abortCutscene();
}
else if (name == "save_gp")
{
}
} // eventCallback
// ----------------------------------------------------------------------------
bool GrandPrixCutscene::onEscapePressed()
{
((CutsceneWorld*)World::getWorld())->abortCutscene();
return false;
} // onEscapePressed
// ----------------------------------------------------------------------------
void GrandPrixCutscene::tearDown()
{
Screen::tearDown();
} // tearDown

View File

@@ -31,6 +31,13 @@ public:
GrandPrixCutscene(const char * filename) : CutsceneScreen(filename) {}
protected:
void saveGPButton();
// implement callbacks from parent class GUIEngine::Screen
void eventCallback(GUIEngine::Widget* widget,
const std::string& name,
const int playerID) OVERRIDE;
bool onEscapePressed() OVERRIDE;
void tearDown() OVERRIDE;
};
#endif

View File

@@ -109,14 +109,6 @@ void GrandPrixLose::onCutsceneEnd()
// -------------------------------------------------------------------------------------
bool GrandPrixLose::onEscapePressed()
{
((CutsceneWorld*)World::getWorld())->abortCutscene();
return false;
}
// -------------------------------------------------------------------------------------
void GrandPrixLose::loadedFromFile()
{
m_kart_node[0] = NULL;
@@ -138,22 +130,7 @@ void GrandPrixLose::init()
World::getWorld()->setPhase(WorldStatus::RACE_PHASE);
if (race_manager->getGrandPrix().getId() == "random")
{
core::stringw text = _("Save Grand Prix");
typedef GUIEngine::ButtonWidget Button;
Button* save_button = new Button();
save_button->m_properties[GUIEngine::PROP_ID] = "save gp";
Button* c = getWidget<Button>("continue");
save_button->m_x = c->m_x + c->m_w + 20;
save_button->m_y = c->m_y;
save_button->m_w = GUIEngine::getFont()->getDimension(text.c_str()).Width + 30;
save_button->m_h = c->m_h;
save_button->setText(text);
save_button->add();
manualAddWidget(save_button);
}
saveGPButton();
m_phase = 1;
m_global_time = 0.0f;
@@ -161,13 +138,6 @@ void GrandPrixLose::init()
// -------------------------------------------------------------------------------------
void GrandPrixLose::tearDown()
{
Screen::tearDown();
} // tearDown
// -------------------------------------------------------------------------------------
void GrandPrixLose::onUpdate(float dt)
{
m_global_time += dt;
@@ -207,21 +177,6 @@ void GrandPrixLose::onUpdate(float dt)
// -------------------------------------------------------------------------------------
void GrandPrixLose::eventCallback(GUIEngine::Widget* widget,
const std::string& name,
const int playerID)
{
if (name == "continue")
{
((CutsceneWorld*)World::getWorld())->abortCutscene();
}
else if (name == "save_gp")
{
}
} // eventCallback
// -------------------------------------------------------------------------------------
void GrandPrixLose::setKarts(std::vector<std::string> ident_arg)
{
TrackObjectManager* tobjman = World::getWorld()->getTrack()->getTrackObjectManager();

View File

@@ -57,8 +57,6 @@ class GrandPrixLose :
public:
virtual void onCutsceneEnd() OVERRIDE;
virtual bool onEscapePressed() OVERRIDE;
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void loadedFromFile() OVERRIDE;
@@ -68,13 +66,6 @@ public:
/** \brief implement callback from parent class GUIEngine::Screen */
void init() OVERRIDE;
/** \brief implement callback from parent class GUIEngine::Screen */
void tearDown() OVERRIDE;
/** \brief implement callback from parent class GUIEngine::Screen */
void eventCallback(GUIEngine::Widget* widget, const std::string& name,
const int playerID) OVERRIDE;
/** \brief set which karts lost this GP */
void setKarts(std::vector<std::string> ident);
};

View File

@@ -182,22 +182,7 @@ void GrandPrixWin::init()
{
m_unlocked_label = NULL;
if (race_manager->getGrandPrix().getId() == "random")
{
core::stringw text = _("Save Grand Prix");
typedef GUIEngine::ButtonWidget Button;
Button* save_button = new Button();
save_button->m_properties[GUIEngine::PROP_ID] = "save gp";
Button* c = getWidget<Button>("continue");
save_button->m_x = c->m_x + c->m_w + 20;
save_button->m_y = c->m_y;
save_button->m_w = GUIEngine::getFont()->getDimension(text.c_str()).Width + 30;
save_button->m_h = c->m_h;
save_button->setText(text);
save_button->add();
manualAddWidget(save_button);
}
saveGPButton();
}
m_global_time = 0.0f;
@@ -208,21 +193,6 @@ void GrandPrixWin::init()
// -------------------------------------------------------------------------------------
bool GrandPrixWin::onEscapePressed()
{
((CutsceneWorld*)World::getWorld())->abortCutscene();
return false;
}
// -------------------------------------------------------------------------------------
void GrandPrixWin::tearDown()
{
Screen::tearDown();
} // tearDown
// -------------------------------------------------------------------------------------
void GrandPrixWin::onUpdate(float dt)
{
m_global_time += dt;
@@ -338,20 +308,6 @@ void GrandPrixWin::onUpdate(float dt)
true/* center h */, true /* center v */ );
} // onUpdate
// -------------------------------------------------------------------------------------
void GrandPrixWin::eventCallback(GUIEngine::Widget* widget,
const std::string& name,
const int playerID)
{
if (name == "continue")
{
((CutsceneWorld*)World::getWorld())->abortCutscene();
}
else if (name == "save_gp")
{
}
} // eventCallback
// -------------------------------------------------------------------------------------

View File

@@ -64,8 +64,6 @@ public:
virtual void onCutsceneEnd() OVERRIDE;
virtual bool onEscapePressed() OVERRIDE;
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void loadedFromFile() OVERRIDE {};
@@ -75,13 +73,6 @@ public:
/** \brief implement callback from parent class GUIEngine::Screen */
void init() OVERRIDE;
/** \brief implement callback from parent class GUIEngine::Screen */
void tearDown() OVERRIDE;
/** \brief implement callback from parent class GUIEngine::Screen */
void eventCallback(GUIEngine::Widget* widget, const std::string& name,
const int playerID) OVERRIDE;
/** \pre must be called after pushing the screen, but before onUpdate had the chance to be invoked */
void setKarts(const std::string idents[3]);
};