finish the save gp button

This commit is contained in:
konstin 2014-07-30 16:06:44 +02:00
parent fb50c9c338
commit 98d3728a4e
4 changed files with 44 additions and 18 deletions

View File

@ -84,17 +84,13 @@ void EnterGPNameDialog::onEnterPressedInternal()
if (name.size() > 0 && name != "Random Grand Prix") if (name.size() > 0 && name != "Random Grand Prix")
{ {
// check for duplicate names // check for duplicate names
for (unsigned int i = 0; i < grand_prix_manager->getNumberOfGrandPrix(); i++) if (grand_prix_manager->existsName(name))
{ {
const GrandPrixData* gp = grand_prix_manager->getGrandPrix(i); LabelWidget* label = getWidget<LabelWidget>("title");
if (gp->getName() == name) assert(label != NULL);
{ label->setText(_("Another grand prix with this name already exists."), false);
LabelWidget* label = getWidget<LabelWidget>("title"); sfx_manager->quickSound("anvil");
assert(label != NULL); return;
label->setText(_("Another grand prix with this name already exists."), false);
sfx_manager->quickSound("anvil");
return;
}
} }
// It's unsafe to delete from inside the event handler so we do it // It's unsafe to delete from inside the event handler so we do it

View File

@ -18,23 +18,47 @@
#include "guiengine/scalable_font.hpp" #include "guiengine/scalable_font.hpp"
#include "guiengine/widgets/button_widget.hpp" #include "guiengine/widgets/button_widget.hpp"
#include "modes/cutscene_world.hpp" #include "modes/cutscene_world.hpp"
#include "race/grand_prix_data.hpp"
#include "race/grand_prix_manager.hpp"
#include "race/race_manager.hpp"
#include "states_screens/grand_prix_cutscene.hpp" #include "states_screens/grand_prix_cutscene.hpp"
#include "tracks/track_manager.hpp"
#include <string>
#include <vector>
typedef GUIEngine::ButtonWidget Button; typedef GUIEngine::ButtonWidget Button;
/** A Button to save the GP if it was a random one */ /** A Button to save the GP if it was a random GP */
void GrandPrixCutscene::saveGPButton() void GrandPrixCutscene::saveGPButton()
{ {
#ifdef IMPLEMENTATION_FINISHED
if (race_manager->getGrandPrix().getId() != "random") if (race_manager->getGrandPrix().getId() != "random")
getWidget<Button>("save")->setVisible(false); getWidget<Button>("save")->setVisible(false);
#else
getWidget<Button>("save")->setVisible(false);
#endif
} // saveGPButton } // saveGPButton
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** \brief Creates a new GP with the same content as the current and saves it
* The GP that the race_manager provides can't be used because we need some
* functions and settings that the GP manager only gives us through
* createNewGP(). */
void GrandPrixCutscene::onNewGPWithName(const irr::core::stringw& name)
{
// Create a new gp with the corre
GrandPrixData* gp = grand_prix_manager->createNewGP(name);
const GrandPrixData current_gp = race_manager->getGrandPrix();
std::vector<std::string> tracks = current_gp.getTrackNames();
std::vector<int> laps = current_gp.getLaps();
std::vector<bool> reverse = current_gp.getReverse();
for (unsigned int i = 0; i < laps.size(); i++)
gp->addTrack(track_manager->getTrack(tracks[i]), laps[i], reverse[i]);
gp->writeToFile();
// Avoid double-save
getWidget<Button>("save")->setVisible(false);
} // onNewGPWithName
// ----------------------------------------------------------------------------
void GrandPrixCutscene::eventCallback(GUIEngine::Widget* widget, void GrandPrixCutscene::eventCallback(GUIEngine::Widget* widget,
const std::string& name, const std::string& name,
@ -44,8 +68,9 @@ void GrandPrixCutscene::eventCallback(GUIEngine::Widget* widget,
{ {
((CutsceneWorld*)World::getWorld())->abortCutscene(); ((CutsceneWorld*)World::getWorld())->abortCutscene();
} }
else if (name == "save_gp") else if (name == "save")
{ {
new EnterGPNameDialog(this, 0.5f, 0.4f);
} }
} // eventCallback } // eventCallback

View File

@ -21,10 +21,12 @@
#include "guiengine/screen.hpp" #include "guiengine/screen.hpp"
#include "guiengine/widgets/button_widget.hpp" #include "guiengine/widgets/button_widget.hpp"
#include "race/race_manager.hpp" #include "race/race_manager.hpp"
#include "states_screens/dialogs/enter_gp_name_dialog.hpp"
#include <string> #include <string>
class GrandPrixCutscene: public GUIEngine::CutsceneScreen class GrandPrixCutscene: public GUIEngine::CutsceneScreen,
public EnterGPNameDialog::INewGPListener
{ {
friend class GUIEngine::ScreenSingleton<GrandPrixCutscene>; friend class GUIEngine::ScreenSingleton<GrandPrixCutscene>;
public: public:
@ -32,6 +34,9 @@ public:
protected: protected:
void saveGPButton(); void saveGPButton();
/** implement callback from INewGPListener */
void onNewGPWithName(const irr::core::stringw& name);
// implement callbacks from parent class GUIEngine::Screen // implement callbacks from parent class GUIEngine::Screen
void eventCallback(GUIEngine::Widget* widget, void eventCallback(GUIEngine::Widget* widget,
const std::string& name, const std::string& name,

View File

@ -18,8 +18,8 @@
#ifndef HEADER_GRAND_PRIX_EDITOR_SCREEN_HPP #ifndef HEADER_GRAND_PRIX_EDITOR_SCREEN_HPP
#define HEADER_GRAND_PRIX_EDITOR_SCREEN_HPP #define HEADER_GRAND_PRIX_EDITOR_SCREEN_HPP
#include "dialogs/enter_gp_name_dialog.hpp"
#include "guiengine/screen.hpp" #include "guiengine/screen.hpp"
#include "states_screens/dialogs/enter_gp_name_dialog.hpp"
#include "states_screens/dialogs/message_dialog.hpp" #include "states_screens/dialogs/message_dialog.hpp"