From 53a432ea70991ca75e6070601f557c7ca0d04bd4 Mon Sep 17 00:00:00 2001 From: konstin Date: Wed, 14 May 2014 21:41:12 +0200 Subject: [PATCH] making the dialog work with a predefined GP --- src/states_screens/dialogs/gp_info_dialog.cpp | 17 ++++---- src/states_screens/dialogs/gp_info_dialog.hpp | 8 ++-- .../dialogs/random_gp_dialog.cpp | 39 +++++++++++++++++++ .../dialogs/random_gp_dialog.hpp | 2 +- src/states_screens/tracks_screen.cpp | 11 +++++- 5 files changed, 62 insertions(+), 15 deletions(-) diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index 79ec24927..f4c08ded7 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -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 tracks = gp->getTrackNames(); + const std::vector 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 tracks = gp->getTrackNames(); + const std::vector tracks = m_gp->getTrackNames(); if (frameAfter >= (int)tracks.size()) { frameAfter = 0; diff --git a/src/states_screens/dialogs/gp_info_dialog.hpp b/src/states_screens/dialogs/gp_info_dialog.hpp index ecb576375..369be0041 100644 --- a/src/states_screens/dialogs/gp_info_dialog.hpp +++ b/src/states_screens/dialogs/gp_info_dialog.hpp @@ -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); diff --git a/src/states_screens/dialogs/random_gp_dialog.cpp b/src/states_screens/dialogs/random_gp_dialog.cpp index 5632f9781..c3e54ebda 100644 --- a/src/states_screens/dialogs/random_gp_dialog.cpp +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -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 +#include + +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"); +} diff --git a/src/states_screens/dialogs/random_gp_dialog.hpp b/src/states_screens/dialogs/random_gp_dialog.hpp index 18e5e9390..1055537e0 100644 --- a/src/states_screens/dialogs/random_gp_dialog.hpp +++ b/src/states_screens/dialogs/random_gp_dialog.hpp @@ -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 diff --git a/src/states_screens/tracks_screen.cpp b/src/states_screens/tracks_screen.cpp index a335ab71e..d6e7550d9 100644 --- a/src/states_screens/tracks_screen.cpp +++ b/src/states_screens/tracks_screen.cpp @@ -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") {