making the dialog work with a predefined GP

This commit is contained in:
konstin 2014-05-14 21:41:12 +02:00
parent 3f5c2138c3
commit 53a432ea70
5 changed files with 62 additions and 15 deletions

View File

@ -58,18 +58,18 @@ GPInfoDialog::GPInfoDialog(const std::string& gp_ident) :
m_gp_ident = gp_ident;
const GrandPrixData* gp = grand_prix_manager->getGrandPrix(gp_ident);
assert (gp != NULL);
m_gp = grand_prix_manager->getGrandPrix(gp_ident);
assert (m_gp != NULL);
// ---- GP Name
core::rect< s32 > area_top(0, 0, m_area.getWidth(), y1);
IGUIStaticText* title = GUIEngine::getGUIEnv()->addStaticText( translations->fribidize(gp->getName()),
IGUIStaticText* title = GUIEngine::getGUIEnv()->addStaticText( translations->fribidize(m_gp->getName()),
area_top, false, true, // border, word wrap
m_irrlicht_window);
title->setTabStop(false);
title->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
InitAfterDrawingTheHeader(gp, y1, y2, gp_ident);
InitAfterDrawingTheHeader(y1, y2, gp_ident);
}
// ----------------------------------------------------------------------------
@ -88,13 +88,12 @@ GPInfoDialog::~GPInfoDialog()
// ----------------------------------------------------------------------------
void GPInfoDialog::InitAfterDrawingTheHeader(const GrandPrixData* gp,
const int y1,
void GPInfoDialog::InitAfterDrawingTheHeader(const int y1,
const int y2,
const std::string& gp_ident)
{
// ---- Track listings
const std::vector<std::string> tracks = gp->getTrackNames();
const std::vector<std::string> tracks = m_gp->getTrackNames();
const int trackAmount = tracks.size();
int height_of_one_line = (y2 - y1)/(trackAmount+1);
@ -257,9 +256,7 @@ void GPInfoDialog::onUpdate(float dt)
if (frameAfter == frameBefore) return; // if nothing changed, return right now
const GrandPrixData* gp = grand_prix_manager->getGrandPrix(m_gp_ident);
assert(gp != NULL);
const std::vector<std::string> tracks = gp->getTrackNames();
const std::vector<std::string> tracks = m_gp->getTrackNames();
if (frameAfter >= (int)tracks.size())
{
frameAfter = 0;

View File

@ -33,10 +33,11 @@ namespace GUIEngine
*/
class GPInfoDialog : public GUIEngine::ModalDialog
{
private:
protected: // Needed for randomGPInfoDialog
std::string m_gp_ident;
GUIEngine::IconButtonWidget* m_screenshot_widget;
float m_curr_time;
GrandPrixData* m_gp;
public:
static const float PERCENT_WIDTH = 0.8f;
@ -45,11 +46,12 @@ public:
* Creates a modal dialog with given percentage of screen width and height
* atm only used in track_screen.cpp
*/
GPInfoDialog() : ModalDialog(PERCENT_WIDTH, PERCENT_HEIGHT) {} // FIXME: This line's only here for compiling
GPInfoDialog(const std::string& gpIdent);
virtual ~GPInfoDialog();
void InitAfterDrawingTheHeader(const GrandPrixData* gp, const int y1,
const int y2, const std::string& gp_ident);
void InitAfterDrawingTheHeader(const int y1, const int y2,
const std::string& gp_ident);
void onEnterPressedInternal();
GUIEngine::EventPropagation processEvent(const std::string& eventSource);

View File

@ -15,4 +15,43 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "guiengine/engine.hpp"
#include "race/grand_prix_manager.hpp"
#include "states_screens/dialogs/random_gp_dialog.hpp"
#include <IGUIEnvironment.h>
#include <IGUIStaticText.h>
using namespace irr::gui;
using namespace irr::video;
using namespace irr::core;
using namespace GUIEngine;
randomGPInfoDialog::randomGPInfoDialog()
{
// Defaults - loading selection from last time frrom a file would be better
int m_number_of_tracks = 4;
std::string m_track_group = "standart";
bool m_use_reverse = true;
doInit();
m_curr_time = 0.0f;
const int y1 = m_area.getHeight()/7;
const int y2 = m_area.getHeight()*6/7;
m_gp_ident = "random";
//const GrandPrixData* gp = grand_prix_manager->newRandomGP(m_number_of_tracks, m_track_group, m_use_reverse);
m_gp = grand_prix_manager->getGrandPrix("1_penguinplayground");
// ---- GP Name
core::rect< s32 > area_top(0, 0, m_area.getWidth(), y1);
IGUIStaticText* title = GUIEngine::getGUIEnv()->addStaticText(translations->fribidize("Random Grand Prix"),
area_top, false, true, // border, word wrap
m_irrlicht_window);
title->setTabStop(false);
title->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
InitAfterDrawingTheHeader(y1, y2, "random");
}

View File

@ -29,7 +29,7 @@ private:
std::string m_track_group;
bool m_use_reverse;
public:
randomGPInfoDialog(const std::string& gp_ident) : GPInfoDialog(gp_ident) {}
randomGPInfoDialog();
};
#endif

View File

@ -29,6 +29,7 @@
#include "race/grand_prix_manager.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/dialogs/gp_info_dialog.hpp"
#include "states_screens/dialogs/random_gp_dialog.hpp"
#include "states_screens/dialogs/track_info_dialog.hpp"
#include "tracks/track.hpp"
#include "tracks/track_manager.hpp"
@ -113,9 +114,17 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name,
std::string selection = gps_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if (selection == "locked")
{
unlock_manager->playLockSound();
}
else
new GPInfoDialog(selection);
{
std::cout << selection << std::endl;
if (selection != "Random")
new GPInfoDialog(selection);
else
new randomGPInfoDialog();
}
}
else if (name == "trackgroups")
{