From 6f9ae6e51034bd236ed2b6fe230f86e88b3f3ad5 Mon Sep 17 00:00:00 2001 From: konstin Date: Mon, 12 May 2014 14:59:09 +0200 Subject: [PATCH 001/121] get back into working state --- src/states_screens/dialogs/gp_info_dialog.cpp | 14 ++------------ src/states_screens/dialogs/gp_info_dialog.hpp | 13 +++++++------ src/states_screens/tracks_screen.cpp | 4 ++-- src/tracks/track.cpp | 8 ++++---- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index 9f8ff35ff..840110c57 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -83,17 +83,8 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa const int from_y = y1 + height_of_one_line*(t+1); Track* track = track_manager->getTrack(tracks[t]); - stringw lineText; - if (track == NULL) - { - lineText = L"MISSING : "; - lineText.append( stringw(tracks[t].c_str()) ); - gp_ok = false; - } - else - { - lineText = track->getName(); - } + assert(track != NULL); + stringw lineText = track->getName(); LabelWidget* widget = new LabelWidget(); widget->setText(translations->fribidize(lineText), false); @@ -195,7 +186,6 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa okBtn->getIrrlichtElement()->setTabGroup(false); okBtn->setFocusForPlayer( PLAYER_ID_GAME_MASTER ); - } // ------------------------------------------------------------------------------------------------------ diff --git a/src/states_screens/dialogs/gp_info_dialog.hpp b/src/states_screens/dialogs/gp_info_dialog.hpp index b8959bf2d..a6218644c 100644 --- a/src/states_screens/dialogs/gp_info_dialog.hpp +++ b/src/states_screens/dialogs/gp_info_dialog.hpp @@ -32,23 +32,24 @@ namespace GUIEngine */ class GPInfoDialog : public GUIEngine::ModalDialog { +private: std::string m_gp_ident; GUIEngine::IconButtonWidget* m_screenshot_widget; - float m_curr_time; - + public: /** * Creates a modal dialog with given percentage of screen width and height + * atm only used in track_screen.cpp */ - GPInfoDialog(const std::string& gpIdent, const float percentWidth, const float percentHeight); + GPInfoDialog(const std::string& gpIdent, const float percentWidth, + const float percentHeight); virtual ~GPInfoDialog(); - + void onEnterPressedInternal(); GUIEngine::EventPropagation processEvent(const std::string& eventSource); - - virtual void onUpdate(float dt); + virtual void onUpdate(float dt); }; #endif diff --git a/src/states_screens/tracks_screen.cpp b/src/states_screens/tracks_screen.cpp index a2ecc22ce..10dae69c3 100644 --- a/src/states_screens/tracks_screen.cpp +++ b/src/states_screens/tracks_screen.cpp @@ -206,12 +206,12 @@ void TracksScreen::init() } } - /*// Random GP - not finished yet + // Random GP - not finished yet std::vector screenshots; screenshots.push_back("gui/main_help.png"); gps_widget->addAnimatedItem(translations->fribidize("Random"), "Random", screenshots, 1.5f, 0, - IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);*/ + IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE); gps_widget->updateItemDisplay(); diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 2010adb30..d66f9530b 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -454,10 +454,10 @@ void Track::loadTrackInfo() delete root; std::string dir = StringUtils::getPath(m_filename); - std::string easter_name = dir+"/easter_eggs.xml"; + std::string easter_name = dir + "/easter_eggs.xml"; XMLNode *easter = file_manager->createXMLTree(easter_name); - + if(easter) { for(unsigned int i=0; igetNumNodes(); i++) @@ -858,7 +858,7 @@ bool Track::loadMainTrack(const XMLNode &root) { mesh = irr_driver->getMesh(full_path); } - + if(!mesh) { Log::fatal("track", @@ -1886,7 +1886,7 @@ void Track::loadObjects(const XMLNode* root, const std::string& path, ModelDefin libroot = library_nodes[name]; create_lod_definitions = false; // LOD definitions are already created, don't create them again } - + scene::ISceneNode* parent = irr_driver->getSceneManager()->addEmptySceneNode(); parent->setPosition(xyz); parent->setRotation(hpr); From d997780cd7dceee307806b2bc733d0102914e422 Mon Sep 17 00:00:00 2001 From: konstin Date: Wed, 14 May 2014 19:57:13 +0200 Subject: [PATCH 002/121] moving the definition of the size of a GPInfoDialog to it's header --- src/race/grand_prix_data.cpp | 2 +- src/states_screens/dialogs/gp_info_dialog.cpp | 23 ++++++++++--------- src/states_screens/dialogs/gp_info_dialog.hpp | 5 ++-- src/states_screens/tracks_screen.cpp | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/race/grand_prix_data.cpp b/src/race/grand_prix_data.cpp index 35e22a2f7..e1c293a8d 100644 --- a/src/race/grand_prix_data.cpp +++ b/src/race/grand_prix_data.cpp @@ -365,7 +365,7 @@ void GrandPrixData::addTrack(Track* track, unsigned int laps, bool reverse, int n = getNumberOfTracks(true); assert (track != NULL); assert (laps > 0); - assert (-1 < position && position < n); + assert (-1 <= position && position < n); if (position < 0 || position == (n - 1) || m_tracks.empty()) { diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index 840110c57..5472953a1 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -44,9 +44,10 @@ using namespace irr::video; using namespace irr::core; using namespace GUIEngine; -// ------------------------------------------------------------------------------------------------------ +// ---------------------------------------------------------------------------- -GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const float h) : ModalDialog(w, h) +GPInfoDialog::GPInfoDialog(const std::string& gp_ident) : + ModalDialog(PERCENT_WIDTH, PERCENT_HEIGHT) { doInit(); m_curr_time = 0.0f; @@ -54,9 +55,9 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa const int y1 = m_area.getHeight()/7; const int y2 = m_area.getHeight()*6/7; - m_gp_ident = gpIdent; + m_gp_ident = gp_ident; - const GrandPrixData* gp = grand_prix_manager->getGrandPrix(gpIdent); + const GrandPrixData* gp = grand_prix_manager->getGrandPrix(gp_ident); assert (gp != NULL); // ---- GP Name @@ -117,7 +118,7 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa Track* track = (tracks.size() == 0 ? NULL : track_manager->getTrack(tracks[0])); - m_screenshot_widget->m_properties[PROP_ICON] = (track != NULL ? + m_screenshot_widget->m_properties[PROP_ICON] = (track != NULL ? track->getScreenshotFile().c_str() : file_manager->getAsset(FileManager::GUI,"main_help.png")); m_screenshot_widget->setParent(m_irrlicht_window); @@ -132,7 +133,7 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa SavedGrandPrix* saved_gp = SavedGrandPrix::getSavedGP( StateManager::get() ->getActivePlayerProfile(0) ->getUniqueID(), - gpIdent, + gp_ident, race_manager->getDifficulty(), race_manager->getNumberOfKarts(), race_manager->getNumLocalPlayers()); @@ -188,7 +189,7 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa okBtn->setFocusForPlayer( PLAYER_ID_GAME_MASTER ); } -// ------------------------------------------------------------------------------------------------------ +// ---------------------------------------------------------------------------- GPInfoDialog::~GPInfoDialog() { @@ -202,7 +203,7 @@ GPInfoDialog::~GPInfoDialog() } -// ------------------------------------------------------------------------------------------------------ +// ---------------------------------------------------------------------------- void GPInfoDialog::onEnterPressedInternal() { @@ -214,7 +215,7 @@ void GPInfoDialog::onEnterPressedInternal() race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id), false, false); } -// ------------------------------------------------------------------------------------------------------ +// ---------------------------------------------------------------------------- GUIEngine::EventPropagation GPInfoDialog::processEvent(const std::string& eventSource) { @@ -242,7 +243,7 @@ GUIEngine::EventPropagation GPInfoDialog::processEvent(const std::string& eventS return GUIEngine::EVENT_LET; } -// ------------------------------------------------------------------------------------------------------ +// ---------------------------------------------------------------------------- void GPInfoDialog::onUpdate(float dt) { @@ -268,4 +269,4 @@ void GPInfoDialog::onUpdate(float dt) m_screenshot_widget->setImage(fn.c_str(), IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE); } -// ------------------------------------------------------------------------------------------------------ +// ---------------------------------------------------------------------------- diff --git a/src/states_screens/dialogs/gp_info_dialog.hpp b/src/states_screens/dialogs/gp_info_dialog.hpp index a6218644c..cc308a742 100644 --- a/src/states_screens/dialogs/gp_info_dialog.hpp +++ b/src/states_screens/dialogs/gp_info_dialog.hpp @@ -38,12 +38,13 @@ private: float m_curr_time; public: + static const float PERCENT_WIDTH = 0.8f; + static const float PERCENT_HEIGHT = 0.7f; /** * Creates a modal dialog with given percentage of screen width and height * atm only used in track_screen.cpp */ - GPInfoDialog(const std::string& gpIdent, const float percentWidth, - const float percentHeight); + GPInfoDialog(const std::string& gpIdent); virtual ~GPInfoDialog(); void onEnterPressedInternal(); diff --git a/src/states_screens/tracks_screen.cpp b/src/states_screens/tracks_screen.cpp index 10dae69c3..a335ab71e 100644 --- a/src/states_screens/tracks_screen.cpp +++ b/src/states_screens/tracks_screen.cpp @@ -115,7 +115,7 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name, if (selection == "locked") unlock_manager->playLockSound(); else - new GPInfoDialog(selection, 0.8f, 0.7f); + new GPInfoDialog(selection); } else if (name == "trackgroups") { From 42f39db17009a7aa15e3f1aebf839f1e2285e362 Mon Sep 17 00:00:00 2001 From: konstin Date: Wed, 14 May 2014 20:01:12 +0200 Subject: [PATCH 003/121] removing old comment and moving the picture 10px to the left --- src/states_screens/dialogs/gp_info_dialog.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index 5472953a1..607943482 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -97,10 +97,6 @@ GPInfoDialog::GPInfoDialog(const std::string& gp_ident) : m_widgets.push_back(widget); widget->add(); - - // IGUIStaticText* line = GUIEngine::getGUIEnv()->addStaticText( lineText.c_str(), - // entry_area, false , true , // border, word wrap - // m_irrlicht_window); } // ---- Track screenshot @@ -113,7 +109,7 @@ GPInfoDialog::GPInfoDialog(const std::string& gp_ident) : m_screenshot_widget->m_x = m_area.getWidth()/2; m_screenshot_widget->m_y = y1; - m_screenshot_widget->m_w = m_area.getWidth()/2; + m_screenshot_widget->m_w = m_area.getWidth()/2-20; m_screenshot_widget->m_h = y2 - y1 - 10; Track* track = (tracks.size() == 0 ? NULL : track_manager->getTrack(tracks[0])); From 84d1d8e511cc50a5031b537e6987247d885e998b Mon Sep 17 00:00:00 2001 From: konstin Date: Wed, 14 May 2014 20:03:13 +0200 Subject: [PATCH 004/121] moving picture 20px to the left --- src/states_screens/dialogs/gp_info_dialog.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index 5472953a1..3e9a600dc 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -97,10 +97,6 @@ GPInfoDialog::GPInfoDialog(const std::string& gp_ident) : m_widgets.push_back(widget); widget->add(); - - // IGUIStaticText* line = GUIEngine::getGUIEnv()->addStaticText( lineText.c_str(), - // entry_area, false , true , // border, word wrap - // m_irrlicht_window); } // ---- Track screenshot @@ -111,7 +107,7 @@ GPInfoDialog::GPInfoDialog(const std::string& gp_ident) : // images are saved squared, but must be stretched to 4:3 m_screenshot_widget->setCustomAspectRatio(4.0f / 3.0f); - m_screenshot_widget->m_x = m_area.getWidth()/2; + m_screenshot_widget->m_x = m_area.getWidth()/2-20; m_screenshot_widget->m_y = y1; m_screenshot_widget->m_w = m_area.getWidth()/2; m_screenshot_widget->m_h = y2 - y1 - 10; From 9d2a0752895e1316145748771453f396a9362aa9 Mon Sep 17 00:00:00 2001 From: konstin Date: Wed, 14 May 2014 20:05:29 +0200 Subject: [PATCH 005/121] reverting malicious change --- src/states_screens/dialogs/gp_info_dialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index 2c28fa182..3e9a600dc 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -109,7 +109,7 @@ GPInfoDialog::GPInfoDialog(const std::string& gp_ident) : m_screenshot_widget->m_x = m_area.getWidth()/2-20; m_screenshot_widget->m_y = y1; - m_screenshot_widget->m_w = m_area.getWidth()/2-20; + m_screenshot_widget->m_w = m_area.getWidth()/2; m_screenshot_widget->m_h = y2 - y1 - 10; Track* track = (tracks.size() == 0 ? NULL : track_manager->getTrack(tracks[0])); From e981489f067dca121eacbcff55fc9c47204d4184 Mon Sep 17 00:00:00 2001 From: konstin Date: Wed, 14 May 2014 20:44:15 +0200 Subject: [PATCH 006/121] moving part of the constructor to a method for a new derived class --- src/states_screens/dialogs/gp_info_dialog.cpp | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index 3e9a600dc..98d957d3e 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -67,8 +67,28 @@ GPInfoDialog::GPInfoDialog(const std::string& gp_ident) : m_irrlicht_window); title->setTabStop(false); title->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); +} +// ---------------------------------------------------------------------------- +GPInfoDialog::~GPInfoDialog() +{ + // Place focus back on selected GP, in case the dialog was cancelled and we're back to + // the track selection screen after + Screen* curr_screen = GUIEngine::getCurrentScreen(); + if (curr_screen->getName() == "tracks.stkgui") + { + ((TracksScreen*)curr_screen)->setFocusOnGP(m_gp_ident); + } + +} + +// ---------------------------------------------------------------------------- + +void GPInfoDialog::InitAfterDrawingTheHeader(GrandPrixData gp, const float y1, + const float y2, + const std::string& gp_ident) +{ // ---- Track listings const std::vector tracks = gp->getTrackNames(); const int trackAmount = tracks.size(); @@ -185,22 +205,6 @@ GPInfoDialog::GPInfoDialog(const std::string& gp_ident) : okBtn->setFocusForPlayer( PLAYER_ID_GAME_MASTER ); } -// ---------------------------------------------------------------------------- - -GPInfoDialog::~GPInfoDialog() -{ - // Place focus back on selected GP, in case the dialog was cancelled and we're back to - // the track selection screen after - Screen* curr_screen = GUIEngine::getCurrentScreen(); - if (curr_screen->getName() == "tracks.stkgui") - { - ((TracksScreen*)curr_screen)->setFocusOnGP(m_gp_ident); - } - -} - -// ---------------------------------------------------------------------------- - void GPInfoDialog::onEnterPressedInternal() { // Save the gp identifier, since dismiss will delete this object. From 556e537ce575d3e927b2cb3ac41922805741c89a Mon Sep 17 00:00:00 2001 From: konstin Date: Wed, 14 May 2014 21:05:48 +0200 Subject: [PATCH 007/121] Adding RandomGPInfoDialog-class with few content --- .../dialogs/random_gp_dialog.cpp | 18 ++++++++++ .../dialogs/random_gp_dialog.hpp | 35 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/states_screens/dialogs/random_gp_dialog.cpp create mode 100644 src/states_screens/dialogs/random_gp_dialog.hpp diff --git a/src/states_screens/dialogs/random_gp_dialog.cpp b/src/states_screens/dialogs/random_gp_dialog.cpp new file mode 100644 index 000000000..5632f9781 --- /dev/null +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -0,0 +1,18 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2014 konstin +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "states_screens/dialogs/random_gp_dialog.hpp" diff --git a/src/states_screens/dialogs/random_gp_dialog.hpp b/src/states_screens/dialogs/random_gp_dialog.hpp new file mode 100644 index 000000000..18e5e9390 --- /dev/null +++ b/src/states_screens/dialogs/random_gp_dialog.hpp @@ -0,0 +1,35 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2014 konstin +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef HEADER_RANDOM_GP_INFO_DIALOG_HPP +#define HEADER_RANDOM_GP_INFO_DIALOG_HPP + +#include "states_screens/dialogs/gp_info_dialog.hpp" + +#include + +class randomGPInfoDialog : public GPInfoDialog +{ +private: + int m_number_of_laps; + std::string m_track_group; + bool m_use_reverse; +public: + randomGPInfoDialog(const std::string& gp_ident) : GPInfoDialog(gp_ident) {} +}; + +#endif From 3f5c2138c3706c674374edc55587e261f2fffff9 Mon Sep 17 00:00:00 2001 From: konstin Date: Wed, 14 May 2014 21:13:08 +0200 Subject: [PATCH 008/121] Start Using InitAfterDrawingTheHeader --- src/states_screens/dialogs/gp_info_dialog.cpp | 8 ++++++-- src/states_screens/dialogs/gp_info_dialog.hpp | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index 98d957d3e..79ec24927 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -28,6 +28,7 @@ #include "guiengine/widgets/label_widget.hpp" #include "io/file_manager.hpp" #include "race/grand_prix_manager.hpp" +#include "race/grand_prix_data.hpp" #include "race/race_manager.hpp" #include "states_screens/state_manager.hpp" #include "states_screens/tracks_screen.hpp" @@ -67,6 +68,8 @@ GPInfoDialog::GPInfoDialog(const std::string& gp_ident) : m_irrlicht_window); title->setTabStop(false); title->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); + + InitAfterDrawingTheHeader(gp, y1, y2, gp_ident); } // ---------------------------------------------------------------------------- @@ -85,8 +88,9 @@ GPInfoDialog::~GPInfoDialog() // ---------------------------------------------------------------------------- -void GPInfoDialog::InitAfterDrawingTheHeader(GrandPrixData gp, const float y1, - const float y2, +void GPInfoDialog::InitAfterDrawingTheHeader(const GrandPrixData* gp, + const int y1, + const int y2, const std::string& gp_ident) { // ---- Track listings diff --git a/src/states_screens/dialogs/gp_info_dialog.hpp b/src/states_screens/dialogs/gp_info_dialog.hpp index cc308a742..ecb576375 100644 --- a/src/states_screens/dialogs/gp_info_dialog.hpp +++ b/src/states_screens/dialogs/gp_info_dialog.hpp @@ -20,6 +20,7 @@ #define HEADER_GP_INFO_DIALOG_HPP #include "guiengine/modaldialog.hpp" +#include "race/grand_prix_data.hpp" namespace GUIEngine { @@ -47,6 +48,9 @@ public: GPInfoDialog(const std::string& gpIdent); virtual ~GPInfoDialog(); + void InitAfterDrawingTheHeader(const GrandPrixData* gp, const int y1, + const int y2, const std::string& gp_ident); + void onEnterPressedInternal(); GUIEngine::EventPropagation processEvent(const std::string& eventSource); From 53a432ea70991ca75e6070601f557c7ca0d04bd4 Mon Sep 17 00:00:00 2001 From: konstin Date: Wed, 14 May 2014 21:41:12 +0200 Subject: [PATCH 009/121] 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") { From 0fdfe16a93ff0a25a62b29262e1e6225b9b7efd4 Mon Sep 17 00:00:00 2001 From: konstin Date: Sun, 18 May 2014 15:27:57 +0200 Subject: [PATCH 010/121] first try for a Random GP generator --- src/challenges/challenge_data.cpp | 3 +- src/main.cpp | 8 ++--- src/race/grand_prix_data.cpp | 30 ++++++++++++++++++- src/race/grand_prix_data.hpp | 5 +++- src/race/race_manager.cpp | 19 ++++++------ src/race/race_manager.hpp | 12 ++++---- src/states_screens/dialogs/gp_info_dialog.cpp | 6 ++-- src/states_screens/dialogs/gp_info_dialog.hpp | 4 +-- .../dialogs/random_gp_dialog.cpp | 10 +++---- .../dialogs/random_gp_dialog.hpp | 4 ++- src/states_screens/tracks_screen.cpp | 1 - 11 files changed, 65 insertions(+), 37 deletions(-) diff --git a/src/challenges/challenge_data.cpp b/src/challenges/challenge_data.cpp index 901f0ff6d..c22a7cfc9 100644 --- a/src/challenges/challenge_data.cpp +++ b/src/challenges/challenge_data.cpp @@ -376,8 +376,7 @@ void ChallengeData::setRace(RaceManager::Difficulty d) const else if(m_mode==CM_GRAND_PRIX) { race_manager->setMinorMode(m_minor); - const GrandPrixData *gp = grand_prix_manager->getGrandPrix(m_gp_id); - race_manager->setGrandPrix(*gp); + race_manager->setGrandPrix(grand_prix_manager->getGrandPrix(m_gp_id)); race_manager->setDifficulty(d); race_manager->setNumKarts(m_num_karts[d]); race_manager->setNumLocalPlayers(1); diff --git a/src/main.cpp b/src/main.cpp index 09eaf0e34..93b0f48ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -359,7 +359,7 @@ void gamepadVisualisation() } // gamepadVisualisation // ============================================================================ -/** Sets the hat mesh name depending on the current christmas mode +/** Sets the hat mesh name depending on the current christmas mode * m_xmas_mode (0: use current date, 1: always on, 2: always off). */ void handleXmasMode() @@ -808,14 +808,14 @@ int handleCmdLine() if(CommandLine::has("--gp", &s)) { race_manager->setMajorMode(RaceManager::MAJOR_MODE_GRAND_PRIX); - const GrandPrixData *gp = grand_prix_manager->getGrandPrix(s); + GrandPrixData *gp = grand_prix_manager->getGrandPrix(s); if (!gp) { Log::warn("main", "There is no GP named '%s'.", s.c_str()); return 0; } - race_manager->setGrandPrix(*gp); + race_manager->setGrandPrix(gp); } // --gp if(CommandLine::has("--numkarts", &n) ||CommandLine::has("-k", &n)) @@ -1266,7 +1266,7 @@ int main(int argc, char *argv[] ) // displayed (if necessary), so we have to make sure there is // a current player PlayerManager::get()->enforceCurrentPlayer(); - + InputDevice *device; // Use keyboard 0 by default in --no-start-screen diff --git a/src/race/grand_prix_data.cpp b/src/race/grand_prix_data.cpp index e1c293a8d..c6e46ec94 100644 --- a/src/race/grand_prix_data.cpp +++ b/src/race/grand_prix_data.cpp @@ -28,9 +28,10 @@ #include "tracks/track.hpp" #include "utils/string_utils.hpp" +#include +#include #include #include -#include #include @@ -44,6 +45,33 @@ GrandPrixData::GrandPrixData(const std::string& filename) reload(); } +// ---------------------------------------------------------------------------- +GrandPrixData::GrandPrixData(const unsigned int number_of_tracks, + const std::string& track_group, + const bool use_reverse) +{ + m_filename = "Random GP - Not loaded from a file!"; + m_id = "random"; + m_name = L"Random"; + m_editable = false; + + const std::vector track_indices = track_manager->getTracksInGroup(track_group); + const size_t available_tracks = track_indices.size(); + assert(number_of_tracks <= available_tracks); + + m_tracks.reserve(number_of_tracks); + m_laps.reserve(number_of_tracks); + m_reversed.reserve(number_of_tracks); + + for (unsigned int i = 0; i < number_of_tracks; i++) + { + int index = track_indices[int(rand() % available_tracks)]; + m_tracks.push_back(std::string(track_manager->getTrack(index)->getIdent())); + m_laps.push_back(3); + m_reversed.push_back(rand() % 2); + } +} + // ---------------------------------------------------------------------------- void GrandPrixData::setId(const std::string& id) { diff --git a/src/race/grand_prix_data.hpp b/src/race/grand_prix_data.hpp index c2013d75c..c9c38f118 100644 --- a/src/race/grand_prix_data.hpp +++ b/src/race/grand_prix_data.hpp @@ -76,6 +76,10 @@ public: GrandPrixData(const std::string& filename); /** Needed for simple creation of an instance of GrandPrixData */ GrandPrixData() {}; + /** TODO */ + GrandPrixData(const unsigned int number_of_tracks, + const std::string& m_track_group, + const bool use_reverse); // Methods for the GP editor void setId(const std::string& id); @@ -117,7 +121,6 @@ public: // ------------------------------------------------------------------------ /** Returns the filename of the grand prix xml file. */ const std::string& getFilename() const { return m_filename; } - }; // GrandPrixData #endif diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp index a646d51e8..27a800cca 100644 --- a/src/race/race_manager.cpp +++ b/src/race/race_manager.cpp @@ -283,9 +283,9 @@ void RaceManager::startNew(bool from_overworld) if(m_major_mode==MAJOR_MODE_GRAND_PRIX) { // GP: get tracks, laps and reverse info from grand prix - m_tracks = m_grand_prix.getTrackNames(); - m_num_laps = m_grand_prix.getLaps(); - m_reverse_track = m_grand_prix.getReverse(); + m_tracks = m_grand_prix->getTrackNames(); + m_num_laps = m_grand_prix->getLaps(); + m_reverse_track = m_grand_prix->getReverse(); } //assert(m_player_karts.size() > 0); @@ -348,7 +348,7 @@ void RaceManager::startNew(bool from_overworld) SavedGrandPrix* gp = SavedGrandPrix::getSavedGP( StateManager::get() ->getActivePlayerProfile(0) ->getUniqueID(), - m_grand_prix.getId(), + m_grand_prix->getId(), m_difficulty, m_num_karts, m_player_karts.size()); @@ -499,7 +499,7 @@ void RaceManager::next() SavedGrandPrix::getSavedGP(StateManager::get() ->getActivePlayerProfile(0) ->getUniqueID(), - m_grand_prix.getId(), + m_grand_prix->getId(), m_difficulty, m_num_karts, m_player_karts.size()); @@ -516,7 +516,7 @@ void RaceManager::next() new SavedGrandPrix( StateManager::get()->getActivePlayerProfile(0) ->getUniqueID(), - m_grand_prix.getId(), + m_grand_prix->getId(), m_difficulty, m_player_karts.size(), m_track_number, @@ -642,7 +642,7 @@ void RaceManager::exitRace(bool delete_world) SavedGrandPrix::getSavedGP(StateManager::get() ->getActivePlayerProfile(0) ->getUniqueID(), - m_grand_prix.getId(), + m_grand_prix->getId(), m_difficulty, m_num_karts, m_player_karts.size()); @@ -774,13 +774,14 @@ void RaceManager::rerunRace() //----------------------------------------------------------------------------- -void RaceManager::startGP(const GrandPrixData* gp, bool from_overworld, +void RaceManager::startGP(GrandPrixData* gp, bool from_overworld, bool continue_saved_gp) { assert(gp != NULL); + //std::cout << gp->getId(); StateManager::get()->enterGameState(); - setGrandPrix(*gp); + setGrandPrix(gp); setCoinTarget( 0 ); // Might still be set from a previous challenge race_manager->setupPlayerKartInfo(); m_continue_saved_gp = continue_saved_gp; diff --git a/src/race/race_manager.hpp b/src/race/race_manager.hpp index 12834fac8..c457514ca 100644 --- a/src/race/race_manager.hpp +++ b/src/race/race_manager.hpp @@ -324,14 +324,14 @@ private: * same list of AIs is used for all tracks of a GP. */ std::vector m_ai_kart_list; int m_track_number; - GrandPrixData m_grand_prix; + GrandPrixData* m_grand_prix; int m_num_karts; unsigned int m_num_finished_karts; unsigned int m_num_finished_players; int m_coin_target; bool m_has_time_target; float m_time_target; - int m_goal_target; + int m_goal_target; void startNextRace(); // start a next race @@ -344,7 +344,7 @@ private: bool m_have_kart_last_position_on_overworld; Vec3 m_kart_last_position_on_overworld; - + /** Determines if saved GP should be continued or not*/ bool m_continue_saved_gp; @@ -410,7 +410,7 @@ public: void setDifficulty(Difficulty diff); // ------------------------------------------------------------------------ - void setGrandPrix(const GrandPrixData &gp) + void setGrandPrix(GrandPrixData* gp) { m_grand_prix = gp; m_coin_target = 0; @@ -525,7 +525,7 @@ public: // ------------------------------------------------------------------------ const std::string& getTrackName() const { return m_tracks[m_track_number];} // ------------------------------------------------------------------------ - const GrandPrixData *getGrandPrix() const { return &m_grand_prix; } + GrandPrixData* getGrandPrix() const { return m_grand_prix; } // ------------------------------------------------------------------------ unsigned int getFinishedKarts() const { return m_num_finished_karts; } // ------------------------------------------------------------------------ @@ -682,7 +682,7 @@ public: * \brief Higher-level method to start a GP without having to care about * the exact startup sequence */ - void startGP(const GrandPrixData* gp, bool from_overworld, + void startGP(GrandPrixData* gp, bool from_overworld, bool continue_saved_gp); /** diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index f4c08ded7..d252e33dd 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -123,7 +123,6 @@ void GPInfoDialog::InitAfterDrawingTheHeader(const int y1, } // ---- Track screenshot - m_screenshot_widget = new IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_CUSTOM_ASPECT_RATIO, false /* tab stop */, false /* focusable */, IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE /* Track gives us absolute paths */); @@ -215,7 +214,7 @@ void GPInfoDialog::onEnterPressedInternal() ModalDialog::dismiss(); // Disable accidentally unlocking of a challenge PlayerManager::getCurrentPlayer()->setCurrentChallenge(""); - race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id), false, false); + race_manager->startGP(m_gp, false, false); } // ---------------------------------------------------------------------------- @@ -225,9 +224,8 @@ GUIEngine::EventPropagation GPInfoDialog::processEvent(const std::string& eventS if (eventSource == "start") { // Save GP identifier, since dismiss will delete this object. - std::string gp_id = m_gp_ident; ModalDialog::dismiss(); - race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id), false, false); + race_manager->startGP(m_gp, false, false); return GUIEngine::EVENT_BLOCK; } if (eventSource == "continue") diff --git a/src/states_screens/dialogs/gp_info_dialog.hpp b/src/states_screens/dialogs/gp_info_dialog.hpp index 369be0041..37c63b7f8 100644 --- a/src/states_screens/dialogs/gp_info_dialog.hpp +++ b/src/states_screens/dialogs/gp_info_dialog.hpp @@ -33,7 +33,7 @@ namespace GUIEngine */ class GPInfoDialog : public GUIEngine::ModalDialog { -protected: // Needed for randomGPInfoDialog +protected: // Necessary for randomGPInfoDialog std::string m_gp_ident; GUIEngine::IconButtonWidget* m_screenshot_widget; float m_curr_time; @@ -46,7 +46,7 @@ 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() : ModalDialog(PERCENT_WIDTH, PERCENT_HEIGHT) {} GPInfoDialog(const std::string& gpIdent); virtual ~GPInfoDialog(); diff --git a/src/states_screens/dialogs/random_gp_dialog.cpp b/src/states_screens/dialogs/random_gp_dialog.cpp index c3e54ebda..ff17f1a54 100644 --- a/src/states_screens/dialogs/random_gp_dialog.cpp +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -30,9 +30,9 @@ 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; + m_number_of_tracks = 2; + m_track_group = "nextgen"; + m_use_reverse = true; doInit(); m_curr_time = 0.0f; @@ -41,9 +41,7 @@ randomGPInfoDialog::randomGPInfoDialog() 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"); + m_gp = new GrandPrixData(m_number_of_tracks, m_track_group, m_use_reverse); // ---- GP Name core::rect< s32 > area_top(0, 0, m_area.getWidth(), y1); diff --git a/src/states_screens/dialogs/random_gp_dialog.hpp b/src/states_screens/dialogs/random_gp_dialog.hpp index 1055537e0..939168c2a 100644 --- a/src/states_screens/dialogs/random_gp_dialog.hpp +++ b/src/states_screens/dialogs/random_gp_dialog.hpp @@ -25,11 +25,13 @@ class randomGPInfoDialog : public GPInfoDialog { private: - int m_number_of_laps; + unsigned int m_number_of_tracks; std::string m_track_group; bool m_use_reverse; + public: randomGPInfoDialog(); + ~randomGPInfoDialog() { delete m_gp; } }; #endif diff --git a/src/states_screens/tracks_screen.cpp b/src/states_screens/tracks_screen.cpp index d6e7550d9..2791cfdca 100644 --- a/src/states_screens/tracks_screen.cpp +++ b/src/states_screens/tracks_screen.cpp @@ -119,7 +119,6 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name, } else { - std::cout << selection << std::endl; if (selection != "Random") new GPInfoDialog(selection); else From 520fce618587f95758430266cf28177d144631be Mon Sep 17 00:00:00 2001 From: konstin Date: Mon, 19 May 2014 16:33:29 +0200 Subject: [PATCH 011/121] change the scaling of the objects in GPInfoDialog to be able to free space for randomGPInfoDialog --- src/states_screens/dialogs/gp_info_dialog.cpp | 47 ++++++++++--------- .../dialogs/random_gp_dialog.cpp | 5 +- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index d252e33dd..e02adbeea 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -52,24 +52,20 @@ GPInfoDialog::GPInfoDialog(const std::string& gp_ident) : { doInit(); m_curr_time = 0.0f; - - const int y1 = m_area.getHeight()/7; - const int y2 = m_area.getHeight()*6/7; - m_gp_ident = gp_ident; 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); + core::rect< s32 > area_top(0, 0, m_area.getWidth(), m_area.getHeight()/7); 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(y1, y2, gp_ident); + InitAfterDrawingTheHeader(m_area.getHeight()/7, m_area.getHeight()*6/7, gp_ident); } // ---------------------------------------------------------------------------- @@ -88,24 +84,23 @@ GPInfoDialog::~GPInfoDialog() // ---------------------------------------------------------------------------- -void GPInfoDialog::InitAfterDrawingTheHeader(const int y1, - const int y2, +void GPInfoDialog::InitAfterDrawingTheHeader(const int upper_bound, + const int lower_bound, const std::string& gp_ident) { // ---- Track listings const std::vector tracks = m_gp->getTrackNames(); const int trackAmount = tracks.size(); - int height_of_one_line = (y2 - y1)/(trackAmount+1); + int height_of_one_line = (lower_bound - upper_bound)/(trackAmount+1); const int textHeight = GUIEngine::getFontHeight(); - if (height_of_one_line > (int)(textHeight*1.5f)) height_of_one_line = (int)(textHeight*1.5f); + if (height_of_one_line > (int)(textHeight*1.5f)) + height_of_one_line = (int)(textHeight*1.5f); bool gp_ok = true; for (int t=0; tgetTrack(tracks[t]); assert(track != NULL); stringw lineText = track->getName(); @@ -113,7 +108,7 @@ void GPInfoDialog::InitAfterDrawingTheHeader(const int y1, LabelWidget* widget = new LabelWidget(); widget->setText(translations->fribidize(lineText), false); widget->m_x = 20; - widget->m_y = from_y; + widget->m_y = upper_bound + height_of_one_line*(t+1); widget->m_w = m_area.getWidth()/2 - 20; widget->m_h = height_of_one_line; widget->setParent(m_irrlicht_window); @@ -130,9 +125,18 @@ void GPInfoDialog::InitAfterDrawingTheHeader(const int y1, m_screenshot_widget->setCustomAspectRatio(4.0f / 3.0f); m_screenshot_widget->m_x = m_area.getWidth()/2-20; - m_screenshot_widget->m_y = y1; - m_screenshot_widget->m_w = m_area.getWidth()/2; - m_screenshot_widget->m_h = y2 - y1 - 10; + m_screenshot_widget->m_y = upper_bound + 10; + // Scale the picture to the biggest possible size without an overflow + if (lower_bound - upper_bound - 20 < m_area.getWidth()/2*3/4) + { + m_screenshot_widget->m_w = (lower_bound - upper_bound - 30)*4/3; + m_screenshot_widget->m_h = lower_bound - upper_bound - 30; + } + else + { + m_screenshot_widget->m_w = m_area.getWidth()/2; + m_screenshot_widget->m_h = m_area.getWidth()*3/8; // *(3/4)*(1/2) + } Track* track = (tracks.size() == 0 ? NULL : track_manager->getTrack(tracks[0])); @@ -179,9 +183,9 @@ void GPInfoDialog::InitAfterDrawingTheHeader(const int y1, if (saved_gp && gp_ok) { continueBtn->m_x = m_area.getWidth()/2 + 110; - continueBtn->m_y = y2; + continueBtn->m_y = lower_bound; continueBtn->m_w = 200; - continueBtn->m_h = m_area.getHeight() - y2 - 15; + continueBtn->m_h = m_area.getHeight() - lower_bound - 15; continueBtn->setParent(m_irrlicht_window); m_widgets.push_back(continueBtn); continueBtn->add(); @@ -195,9 +199,9 @@ void GPInfoDialog::InitAfterDrawingTheHeader(const int y1, okBtn->m_x = m_area.getWidth()/2 - 200; } - okBtn->m_y = y2; + okBtn->m_y = lower_bound; okBtn->m_w = 400; - okBtn->m_h = m_area.getHeight() - y2 - 15; + okBtn->m_h = m_area.getHeight() - lower_bound - 15; okBtn->setParent(m_irrlicht_window); m_widgets.push_back(okBtn); okBtn->add(); @@ -209,8 +213,6 @@ void GPInfoDialog::InitAfterDrawingTheHeader(const int y1, void GPInfoDialog::onEnterPressedInternal() { - // Save the gp identifier, since dismiss will delete this object. - std::string gp_id = m_gp_ident; ModalDialog::dismiss(); // Disable accidentally unlocking of a challenge PlayerManager::getCurrentPlayer()->setCurrentChallenge(""); @@ -223,7 +225,6 @@ GUIEngine::EventPropagation GPInfoDialog::processEvent(const std::string& eventS { if (eventSource == "start") { - // Save GP identifier, since dismiss will delete this object. ModalDialog::dismiss(); race_manager->startGP(m_gp, false, false); return GUIEngine::EVENT_BLOCK; diff --git a/src/states_screens/dialogs/random_gp_dialog.cpp b/src/states_screens/dialogs/random_gp_dialog.cpp index ff17f1a54..5c70f65b4 100644 --- a/src/states_screens/dialogs/random_gp_dialog.cpp +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -37,8 +37,7 @@ randomGPInfoDialog::randomGPInfoDialog() doInit(); m_curr_time = 0.0f; - const int y1 = m_area.getHeight()/7; - const int y2 = m_area.getHeight()*6/7; + int y1 = m_area.getHeight()/7; m_gp_ident = "random"; m_gp = new GrandPrixData(m_number_of_tracks, m_track_group, m_use_reverse); @@ -51,5 +50,5 @@ randomGPInfoDialog::randomGPInfoDialog() title->setTabStop(false); title->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); - InitAfterDrawingTheHeader(y1, y2, "random"); + InitAfterDrawingTheHeader(m_area.getHeight()/7 + 50, m_area.getHeight()*6/7, "random"); } From aab6a1fcb6106785420a183caca57a29d7393cac Mon Sep 17 00:00:00 2001 From: konstin Date: Fri, 23 May 2014 22:55:25 +0200 Subject: [PATCH 012/121] adding sliders to dialogue --- src/race/grand_prix_data.cpp | 22 ++++-- .../dialogs/random_gp_dialog.cpp | 71 ++++++++++++++++++- .../dialogs/random_gp_dialog.hpp | 6 +- 3 files changed, 91 insertions(+), 8 deletions(-) diff --git a/src/race/grand_prix_data.cpp b/src/race/grand_prix_data.cpp index c6e46ec94..bad8d9e63 100644 --- a/src/race/grand_prix_data.cpp +++ b/src/race/grand_prix_data.cpp @@ -55,8 +55,19 @@ GrandPrixData::GrandPrixData(const unsigned int number_of_tracks, m_name = L"Random"; m_editable = false; - const std::vector track_indices = track_manager->getTracksInGroup(track_group); - const size_t available_tracks = track_indices.size(); + // The problem with the track groups is that "all" isn't a track group + // TODO: Add "all" to the track groups and rewrite this more elegant + std::vector track_indices; + size_t available_tracks; + if (track_group == "all") + { + available_tracks = track_manager->getNumberOfTracks(); + } + else + { + track_indices = track_manager->getTracksInGroup(track_group); + available_tracks = track_indices.size(); + } assert(number_of_tracks <= available_tracks); m_tracks.reserve(number_of_tracks); @@ -65,8 +76,11 @@ GrandPrixData::GrandPrixData(const unsigned int number_of_tracks, for (unsigned int i = 0; i < number_of_tracks; i++) { - int index = track_indices[int(rand() % available_tracks)]; - m_tracks.push_back(std::string(track_manager->getTrack(index)->getIdent())); + int index = (track_group == "all") ? + rand() % available_tracks : + track_indices[rand() % available_tracks]; + + m_tracks.push_back(track_manager->getTrack(index)->getIdent()); m_laps.push_back(3); m_reversed.push_back(rand() % 2); } diff --git a/src/states_screens/dialogs/random_gp_dialog.cpp b/src/states_screens/dialogs/random_gp_dialog.cpp index 5c70f65b4..7191fa46a 100644 --- a/src/states_screens/dialogs/random_gp_dialog.cpp +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -16,8 +16,10 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "guiengine/engine.hpp" +#include "guiengine/widgets/spinner_widget.hpp" #include "race/grand_prix_manager.hpp" #include "states_screens/dialogs/random_gp_dialog.hpp" +#include "tracks/track_manager.hpp" #include #include @@ -31,7 +33,7 @@ randomGPInfoDialog::randomGPInfoDialog() { // Defaults - loading selection from last time frrom a file would be better m_number_of_tracks = 2; - m_track_group = "nextgen"; + m_trackgroup = "all"; m_use_reverse = true; doInit(); @@ -40,7 +42,7 @@ randomGPInfoDialog::randomGPInfoDialog() int y1 = m_area.getHeight()/7; m_gp_ident = "random"; - m_gp = new GrandPrixData(m_number_of_tracks, m_track_group, m_use_reverse); + m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse); // ---- GP Name core::rect< s32 > area_top(0, 0, m_area.getWidth(), y1); @@ -50,5 +52,68 @@ randomGPInfoDialog::randomGPInfoDialog() title->setTabStop(false); title->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); - InitAfterDrawingTheHeader(m_area.getHeight()/7 + 50, m_area.getHeight()*6/7, "random"); + // ---- Spinners + // Number of laps chooser + GUIEngine::SpinnerWidget* spinner = new GUIEngine::SpinnerWidget(false); + spinner->setValue(m_number_of_tracks); + spinner->setMin(1); + spinner->setMax(track_manager->getTracksInGroup(m_trackgroup).size()); + spinner->setParent(m_irrlicht_window); + spinner->m_properties[PROP_ID] = "Number of tracks"; + m_widgets.push_back(spinner); + spinner->add(); + spinner->move(10, m_area.getHeight()/7, 300, 40); + + // Trackgroup chooser + spinner = new GUIEngine::SpinnerWidget(false); + spinner->m_properties[PROP_ID] = "Trackgroup"; + spinner->setParent(m_irrlicht_window); + m_widgets.push_back(spinner); + spinner->add(); + spinner->move(310, m_area.getHeight()/7, 300, 40); + // Fill it with with all the track group names + spinner->addLabel("all"); + const std::vector& groups = track_manager->getAllTrackGroups(); + for (unsigned int i = 1; i < groups.size() + 1; i++) + spinner->addLabel(stringw(groups[i].c_str())); + + InitAfterDrawingTheHeader(m_area.getHeight()/7 + 50, + m_area.getHeight()*6/7, + "random"); } + +GUIEngine::EventPropagation randomGPInfoDialog::processEvent( + const std::string& eventSource) +{ + if (eventSource == "Number of laps") + { + m_number_of_tracks = getWidget("Number of tracks")->getValue(); + updateGP(); + } + else if (eventSource == "Trackgroup") + { + GUIEngine::SpinnerWidget* t = getWidget("Trackgroup"); + GUIEngine::SpinnerWidget* s = getWidget("Number of tracks"); + m_trackgroup = stringc(t->getStringValue()).c_str(); + unsigned int max = (m_trackgroup == "all") ? + track_manager->getNumberOfTracks() : + track_manager->getTracksInGroup(m_trackgroup).size(); + m_number_of_tracks = std::min(max, m_number_of_tracks); + s->setMax(max); + if (s->getValue() > (signed)max) + s->setValue(max); + + updateGP(); + } + + return GPInfoDialog::processEvent(eventSource); +} + +void randomGPInfoDialog::updateGP() +{ + if (m_gp != NULL) + delete m_gp; + + m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse); +} + diff --git a/src/states_screens/dialogs/random_gp_dialog.hpp b/src/states_screens/dialogs/random_gp_dialog.hpp index 939168c2a..945bbdc8c 100644 --- a/src/states_screens/dialogs/random_gp_dialog.hpp +++ b/src/states_screens/dialogs/random_gp_dialog.hpp @@ -18,6 +18,7 @@ #ifndef HEADER_RANDOM_GP_INFO_DIALOG_HPP #define HEADER_RANDOM_GP_INFO_DIALOG_HPP +#include "guiengine/widgets/spinner_widget.hpp" #include "states_screens/dialogs/gp_info_dialog.hpp" #include @@ -26,12 +27,15 @@ class randomGPInfoDialog : public GPInfoDialog { private: unsigned int m_number_of_tracks; - std::string m_track_group; + std::string m_trackgroup; bool m_use_reverse; public: randomGPInfoDialog(); ~randomGPInfoDialog() { delete m_gp; } + + GUIEngine::EventPropagation processEvent(const std::string& eventSource); + void updateGP(); }; #endif From 0d959a72aa56e96dab756317cebb022415850c29 Mon Sep 17 00:00:00 2001 From: konstin Date: Sun, 25 May 2014 21:16:42 +0200 Subject: [PATCH 013/121] implement dynamic track listing (thanks to unitraxx for the help with the updating) --- src/states_screens/dialogs/gp_info_dialog.cpp | 111 ++++++++++++------ src/states_screens/dialogs/gp_info_dialog.hpp | 7 ++ .../dialogs/random_gp_dialog.cpp | 37 +++--- 3 files changed, 105 insertions(+), 50 deletions(-) diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index e02adbeea..e5ec330aa 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -36,7 +36,6 @@ #include "tracks/track_manager.hpp" #include "utils/translation.hpp" -#include #include #include @@ -65,6 +64,7 @@ GPInfoDialog::GPInfoDialog(const std::string& gp_ident) : title->setTabStop(false); title->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); + displayTracks(m_area.getHeight()/7, m_area.getHeight()*6/7); InitAfterDrawingTheHeader(m_area.getHeight()/7, m_area.getHeight()*6/7, gp_ident); } @@ -82,40 +82,85 @@ GPInfoDialog::~GPInfoDialog() } +// ---------------------------------------------------------------------------- +void GPInfoDialog::displayTracks(const int upper_bound, + const int lower_bound) +{ + const std::vector tracks = m_gp->getTrackNames(); + const unsigned int track_amount = tracks.size(); + + int height_of_one_line = std::min((lower_bound - upper_bound)/(track_amount+1), + (unsigned int)(GUIEngine::getFontHeight()*1.5f)); + + // Count the number of label already existing labels representing a track + unsigned int existing = 0; + for (unsigned int i = 0; i < m_widgets.size(); i++) + { + if (m_widgets.get(i)->m_properties[PROP_ID] == "Track label") + existing++; + } + + unsigned int reuse = std::min(existing, track_amount); + // m_widgets has the type PtrVector + unsigned int widgets_iter = 0; + for (unsigned int i = 0; i < reuse; i++) + { + Track* track = track_manager->getTrack(tracks[i]); + + // Find the next widget that is a track label + while (m_widgets.get(widgets_iter)->m_properties[PROP_ID] != "Track label") + widgets_iter++; + + LabelWidget* widget = dynamic_cast(m_widgets.get(widgets_iter)); + widget->setText(translations->fribidize(track->getName()), false); + widget->move(20, upper_bound + height_of_one_line*(i+1), + m_area.getWidth()/2 - 20, height_of_one_line); + + widgets_iter++; + } + + if (existing < track_amount) + { + // There are not enough labels for all the track names, so we have to + // add some more + for (unsigned int i = reuse; i < track_amount; i++) + { + Track* track = track_manager->getTrack(tracks[i]); + assert(track != NULL); + + LabelWidget* widget = new LabelWidget(); + widget->m_properties[PROP_ID] = "Track label"; + widget->setText(translations->fribidize(track->getName()), false); + widget->setParent(m_irrlicht_window); + m_widgets.push_back(widget); + widget->add(); + + widget->move(20, upper_bound + height_of_one_line*(i+1), + m_area.getWidth()/2 - 20, height_of_one_line); + } + } + else if (existing > track_amount) + { + // There are label which are not necessary anymore so they're deleted + for (unsigned int i = widgets_iter; i < m_widgets.size(); i++) + { + if (m_widgets.get(i)->m_properties[PROP_ID] == "Track label") + { + m_irrlicht_window->removeChild(m_widgets.get(i)->getIrrlichtElement()); + m_widgets.remove(i); + i--; + } + } + } +} + // ---------------------------------------------------------------------------- void GPInfoDialog::InitAfterDrawingTheHeader(const int upper_bound, const int lower_bound, const std::string& gp_ident) { - // ---- Track listings const std::vector tracks = m_gp->getTrackNames(); - const int trackAmount = tracks.size(); - - int height_of_one_line = (lower_bound - upper_bound)/(trackAmount+1); - const int textHeight = GUIEngine::getFontHeight(); - if (height_of_one_line > (int)(textHeight*1.5f)) - height_of_one_line = (int)(textHeight*1.5f); - - bool gp_ok = true; - - for (int t=0; tgetTrack(tracks[t]); - assert(track != NULL); - stringw lineText = track->getName(); - - LabelWidget* widget = new LabelWidget(); - widget->setText(translations->fribidize(lineText), false); - widget->m_x = 20; - widget->m_y = upper_bound + height_of_one_line*(t+1); - widget->m_w = m_area.getWidth()/2 - 20; - widget->m_h = height_of_one_line; - widget->setParent(m_irrlicht_window); - - m_widgets.push_back(widget); - widget->add(); - } // ---- Track screenshot m_screenshot_widget = new IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_CUSTOM_ASPECT_RATIO, @@ -165,7 +210,7 @@ void GPInfoDialog::InitAfterDrawingTheHeader(const int upper_bound, okBtn->m_properties[PROP_ID] = "cannot_start"; okBtn->setText(_("Sorry, no tracks available")); } - else if (gp_ok) + else { okBtn->m_properties[PROP_ID] = "start"; okBtn->setText(_("Start Grand Prix")); @@ -173,14 +218,8 @@ void GPInfoDialog::InitAfterDrawingTheHeader(const int upper_bound, continueBtn->m_properties[PROP_ID] = "continue"; continueBtn->setText(_("Continue")); } - else - { - okBtn->m_properties[PROP_ID] = "cannot_start"; - okBtn->setText(_("This Grand Prix is broken!")); - okBtn->setBadge(BAD_BADGE); - } - if (saved_gp && gp_ok) + if (saved_gp) { continueBtn->m_x = m_area.getWidth()/2 + 110; continueBtn->m_y = lower_bound; diff --git a/src/states_screens/dialogs/gp_info_dialog.hpp b/src/states_screens/dialogs/gp_info_dialog.hpp index 37c63b7f8..d0baa771b 100644 --- a/src/states_screens/dialogs/gp_info_dialog.hpp +++ b/src/states_screens/dialogs/gp_info_dialog.hpp @@ -53,6 +53,13 @@ public: void InitAfterDrawingTheHeader(const int y1, const int y2, const std::string& gp_ident); + /** \brief display all the tracks according to the current gp + * For a normal gp info dialog, it just creates a label with the name for + * every track. But in a random gp info dialog, it tries to reuse as many + * labels as possible by just changing their labels. If there are less than + * need, some are added, if there are to many, some become deleted. */ + void displayTracks(const int y1, const int y2); + 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 7191fa46a..3a3016648 100644 --- a/src/states_screens/dialogs/random_gp_dialog.cpp +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -17,6 +17,7 @@ #include "guiengine/engine.hpp" #include "guiengine/widgets/spinner_widget.hpp" +#include "guiengine/widget.hpp" #include "race/grand_prix_manager.hpp" #include "states_screens/dialogs/random_gp_dialog.hpp" #include "tracks/track_manager.hpp" @@ -53,30 +54,31 @@ randomGPInfoDialog::randomGPInfoDialog() title->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); // ---- Spinners - // Number of laps chooser - GUIEngine::SpinnerWidget* spinner = new GUIEngine::SpinnerWidget(false); - spinner->setValue(m_number_of_tracks); - spinner->setMin(1); - spinner->setMax(track_manager->getTracksInGroup(m_trackgroup).size()); - spinner->setParent(m_irrlicht_window); - spinner->m_properties[PROP_ID] = "Number of tracks"; - m_widgets.push_back(spinner); - spinner->add(); - spinner->move(10, m_area.getHeight()/7, 300, 40); - // Trackgroup chooser - spinner = new GUIEngine::SpinnerWidget(false); + GUIEngine::SpinnerWidget* spinner = new GUIEngine::SpinnerWidget(false); spinner->m_properties[PROP_ID] = "Trackgroup"; spinner->setParent(m_irrlicht_window); m_widgets.push_back(spinner); spinner->add(); - spinner->move(310, m_area.getHeight()/7, 300, 40); + spinner->move(10, m_area.getHeight()/7, 300, 40); // Fill it with with all the track group names spinner->addLabel("all"); const std::vector& groups = track_manager->getAllTrackGroups(); for (unsigned int i = 1; i < groups.size() + 1; i++) spinner->addLabel(stringw(groups[i].c_str())); + // Number of laps chooser + spinner = new GUIEngine::SpinnerWidget(false); + spinner->setValue(m_number_of_tracks); + spinner->setMin(1); + spinner->setMax(track_manager->getNumberOfTracks()); // default is "all" + spinner->setParent(m_irrlicht_window); + spinner->m_properties[PROP_ID] = "Number of tracks"; + m_widgets.push_back(spinner); + spinner->add(); + spinner->move(310, m_area.getHeight()/7, 200, 40); + + displayTracks(m_area.getHeight()/7 + 50, m_area.getHeight()*6/7); InitAfterDrawingTheHeader(m_area.getHeight()/7 + 50, m_area.getHeight()*6/7, "random"); @@ -85,7 +87,7 @@ randomGPInfoDialog::randomGPInfoDialog() GUIEngine::EventPropagation randomGPInfoDialog::processEvent( const std::string& eventSource) { - if (eventSource == "Number of laps") + if (eventSource == "Number of tracks") { m_number_of_tracks = getWidget("Number of tracks")->getValue(); updateGP(); @@ -94,7 +96,13 @@ GUIEngine::EventPropagation randomGPInfoDialog::processEvent( { GUIEngine::SpinnerWidget* t = getWidget("Trackgroup"); GUIEngine::SpinnerWidget* s = getWidget("Number of tracks"); + m_trackgroup = stringc(t->getStringValue()).c_str(); + + // Update the maximum for the number of tracks since it's depending on + // the current track. The current value in the Number-of-tracks-spinner + // has to be updated, since otherwise the displayed (and used) value + // can be bigger than the maximum. (Might be a TODO to fix this) unsigned int max = (m_trackgroup == "all") ? track_manager->getNumberOfTracks() : track_manager->getTracksInGroup(m_trackgroup).size(); @@ -115,5 +123,6 @@ void randomGPInfoDialog::updateGP() delete m_gp; m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse); + displayTracks(m_area.getHeight()/7, m_area.getHeight()*6/7); } From feeab733e4172b5e4a0950508b389c88705fce62 Mon Sep 17 00:00:00 2001 From: konstin Date: Tue, 27 May 2014 20:49:02 +0200 Subject: [PATCH 014/121] more intellegent track adding and removing --- src/race/grand_prix_data.cpp | 46 ++++++++++++++----- src/race/grand_prix_data.hpp | 3 ++ src/states_screens/dialogs/gp_info_dialog.hpp | 8 ++-- .../dialogs/random_gp_dialog.cpp | 3 +- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/race/grand_prix_data.cpp b/src/race/grand_prix_data.cpp index bad8d9e63..eed2da4e8 100644 --- a/src/race/grand_prix_data.cpp +++ b/src/race/grand_prix_data.cpp @@ -55,6 +55,18 @@ GrandPrixData::GrandPrixData(const unsigned int number_of_tracks, m_name = L"Random"; m_editable = false; + m_tracks.reserve(number_of_tracks); + m_laps.reserve(number_of_tracks); + m_reversed.reserve(number_of_tracks); + + changeTrackNumber(number_of_tracks, track_group, use_reverse); +} + +// ---------------------------------------------------------------------------- +void GrandPrixData::changeTrackNumber(const unsigned int number_of_tracks, + const std::string& track_group, + const bool use_reverse) +{ // The problem with the track groups is that "all" isn't a track group // TODO: Add "all" to the track groups and rewrite this more elegant std::vector track_indices; @@ -70,20 +82,32 @@ GrandPrixData::GrandPrixData(const unsigned int number_of_tracks, } assert(number_of_tracks <= available_tracks); - m_tracks.reserve(number_of_tracks); - m_laps.reserve(number_of_tracks); - m_reversed.reserve(number_of_tracks); - - for (unsigned int i = 0; i < number_of_tracks; i++) + // add or remove the right number of tracks + if (m_tracks.size() < number_of_tracks) { - int index = (track_group == "all") ? - rand() % available_tracks : - track_indices[rand() % available_tracks]; + while (m_tracks.size() < number_of_tracks) + { + int index = (track_group == "all") ? + rand() % available_tracks : + track_indices[rand() % available_tracks]; - m_tracks.push_back(track_manager->getTrack(index)->getIdent()); - m_laps.push_back(3); - m_reversed.push_back(rand() % 2); + m_tracks.push_back(track_manager->getTrack(index)->getIdent()); + m_laps.push_back(3); // TODO: Take the default number from the track + m_reversed.push_back(rand() % 2); + } } + else if (m_tracks.size() > number_of_tracks) + { + while (m_tracks.size() > number_of_tracks) + { + m_tracks.pop_back(); + m_laps.pop_back(); + m_reversed.pop_back(); + } + } + + assert(m_tracks.size() == m_laps.size() ); + assert(m_laps.size() == m_reversed.size()); } // ---------------------------------------------------------------------------- diff --git a/src/race/grand_prix_data.hpp b/src/race/grand_prix_data.hpp index c9c38f118..d92e2ff5f 100644 --- a/src/race/grand_prix_data.hpp +++ b/src/race/grand_prix_data.hpp @@ -80,6 +80,9 @@ public: GrandPrixData(const unsigned int number_of_tracks, const std::string& m_track_group, const bool use_reverse); + void changeTrackNumber(const unsigned int number_of_tracks, + const std::string& track_group, + const bool use_reverse); // Methods for the GP editor void setId(const std::string& id); diff --git a/src/states_screens/dialogs/gp_info_dialog.hpp b/src/states_screens/dialogs/gp_info_dialog.hpp index d0baa771b..61ded1118 100644 --- a/src/states_screens/dialogs/gp_info_dialog.hpp +++ b/src/states_screens/dialogs/gp_info_dialog.hpp @@ -54,10 +54,10 @@ public: const std::string& gp_ident); /** \brief display all the tracks according to the current gp - * For a normal gp info dialog, it just creates a label with the name for - * every track. But in a random gp info dialog, it tries to reuse as many - * labels as possible by just changing their labels. If there are less than - * need, some are added, if there are to many, some become deleted. */ + * For a normal gp info dialog, it just creates a label for every track. + * With its name. But in a random gp info dialog, it tries to reuse as many + * labels as possible by just changing their text. If there are less than + * need, some are added, if there are to many, some are deleted. */ void displayTracks(const int y1, const int y2); void onEnterPressedInternal(); diff --git a/src/states_screens/dialogs/random_gp_dialog.cpp b/src/states_screens/dialogs/random_gp_dialog.cpp index 3a3016648..4700209d5 100644 --- a/src/states_screens/dialogs/random_gp_dialog.cpp +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -90,7 +90,8 @@ GUIEngine::EventPropagation randomGPInfoDialog::processEvent( if (eventSource == "Number of tracks") { m_number_of_tracks = getWidget("Number of tracks")->getValue(); - updateGP(); + m_gp->changeTrackNumber(m_number_of_tracks, m_trackgroup, m_use_reverse); + displayTracks(m_area.getHeight()/7, m_area.getHeight()*6/7); } else if (eventSource == "Trackgroup") { From 02677b38c24a2c93bd879820fce180ea38cad68d Mon Sep 17 00:00:00 2001 From: konstin Date: Fri, 30 May 2014 20:26:44 +0200 Subject: [PATCH 015/121] Refactoring, renaming and cleaning-up --- src/race/grand_prix_data.cpp | 2 +- src/states_screens/dialogs/gp_info_dialog.cpp | 164 ++++++++---------- src/states_screens/dialogs/gp_info_dialog.hpp | 42 +++-- .../dialogs/random_gp_dialog.cpp | 84 +++++---- .../dialogs/random_gp_dialog.hpp | 14 +- src/states_screens/tracks_screen.cpp | 11 +- 6 files changed, 164 insertions(+), 153 deletions(-) diff --git a/src/race/grand_prix_data.cpp b/src/race/grand_prix_data.cpp index eed2da4e8..a49e44964 100644 --- a/src/race/grand_prix_data.cpp +++ b/src/race/grand_prix_data.cpp @@ -52,7 +52,7 @@ GrandPrixData::GrandPrixData(const unsigned int number_of_tracks, { m_filename = "Random GP - Not loaded from a file!"; m_id = "random"; - m_name = L"Random"; + m_name = L"Random Grand Prix"; m_editable = false; m_tracks.reserve(number_of_tracks); diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index e5ec330aa..b9cd91aae 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -39,57 +39,60 @@ #include #include -using namespace irr::gui; -using namespace irr::video; -using namespace irr::core; -using namespace GUIEngine; +using irr::gui::IGUIStaticText; +using GUIEngine::PROP_ID; -// ---------------------------------------------------------------------------- +typedef GUIEngine::LabelWidget Label; GPInfoDialog::GPInfoDialog(const std::string& gp_ident) : ModalDialog(PERCENT_WIDTH, PERCENT_HEIGHT) { doInit(); m_curr_time = 0.0f; - m_gp_ident = gp_ident; m_gp = grand_prix_manager->getGrandPrix(gp_ident); - assert (m_gp != NULL); + m_gp->checkConsistency(); - // ---- GP Name - core::rect< s32 > area_top(0, 0, m_area.getWidth(), m_area.getHeight()/7); - 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); + m_under_title = m_area.getHeight()/7; + m_over_body = m_area.getHeight()/7; + m_lower_bound = m_area.getHeight()*6/7; - displayTracks(m_area.getHeight()/7, m_area.getHeight()*6/7); - InitAfterDrawingTheHeader(m_area.getHeight()/7, m_area.getHeight()*6/7, gp_ident); + addTitle(); + addTracks(); + addScreenshot(); + addButtons(); } // ---------------------------------------------------------------------------- GPInfoDialog::~GPInfoDialog() { - // Place focus back on selected GP, in case the dialog was cancelled and we're back to - // the track selection screen after - Screen* curr_screen = GUIEngine::getCurrentScreen(); + GUIEngine::Screen* curr_screen = GUIEngine::getCurrentScreen(); if (curr_screen->getName() == "tracks.stkgui") - { - ((TracksScreen*)curr_screen)->setFocusOnGP(m_gp_ident); - } - + static_cast(curr_screen)->setFocusOnGP(m_gp->getId()); } // ---------------------------------------------------------------------------- -void GPInfoDialog::displayTracks(const int upper_bound, - const int lower_bound) + +void GPInfoDialog::addTitle() +{ + core::rect< s32 > area_top(0, 0, m_area.getWidth(), m_under_title); + 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(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER); +} + +// ---------------------------------------------------------------------------- + +void GPInfoDialog::addTracks() { const std::vector tracks = m_gp->getTrackNames(); const unsigned int track_amount = tracks.size(); - int height_of_one_line = std::min((lower_bound - upper_bound)/(track_amount+1), + int height_of_one_line = std::min((m_lower_bound - m_over_body)/(track_amount+1), (unsigned int)(GUIEngine::getFontHeight()*1.5f)); // Count the number of label already existing labels representing a track @@ -111,9 +114,9 @@ void GPInfoDialog::displayTracks(const int upper_bound, while (m_widgets.get(widgets_iter)->m_properties[PROP_ID] != "Track label") widgets_iter++; - LabelWidget* widget = dynamic_cast(m_widgets.get(widgets_iter)); + Label* widget = dynamic_cast(m_widgets.get(widgets_iter)); widget->setText(translations->fribidize(track->getName()), false); - widget->move(20, upper_bound + height_of_one_line*(i+1), + widget->move(20, m_over_body + height_of_one_line*(i+1), m_area.getWidth()/2 - 20, height_of_one_line); widgets_iter++; @@ -128,14 +131,14 @@ void GPInfoDialog::displayTracks(const int upper_bound, Track* track = track_manager->getTrack(tracks[i]); assert(track != NULL); - LabelWidget* widget = new LabelWidget(); + Label* widget = new Label(); widget->m_properties[PROP_ID] = "Track label"; widget->setText(translations->fribidize(track->getName()), false); widget->setParent(m_irrlicht_window); m_widgets.push_back(widget); widget->add(); - widget->move(20, upper_bound + height_of_one_line*(i+1), + widget->move(20, m_over_body + height_of_one_line*(i+1), m_area.getWidth()/2 - 20, height_of_one_line); } } @@ -156,26 +159,22 @@ void GPInfoDialog::displayTracks(const int upper_bound, // ---------------------------------------------------------------------------- -void GPInfoDialog::InitAfterDrawingTheHeader(const int upper_bound, - const int lower_bound, - const std::string& gp_ident) +void GPInfoDialog::addScreenshot() { - const std::vector tracks = m_gp->getTrackNames(); - - // ---- Track screenshot - m_screenshot_widget = new IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_CUSTOM_ASPECT_RATIO, - false /* tab stop */, false /* focusable */, - IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE /* Track gives us absolute paths */); + m_screenshot_widget = new GUIEngine::IconButtonWidget( + GUIEngine::IconButtonWidget::SCALE_MODE_KEEP_CUSTOM_ASPECT_RATIO, + false, false, GUIEngine::IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE); // images are saved squared, but must be stretched to 4:3 m_screenshot_widget->setCustomAspectRatio(4.0f / 3.0f); m_screenshot_widget->m_x = m_area.getWidth()/2-20; - m_screenshot_widget->m_y = upper_bound + 10; + m_screenshot_widget->m_y = m_over_body + 10; + // Scale the picture to the biggest possible size without an overflow - if (lower_bound - upper_bound - 20 < m_area.getWidth()/2*3/4) + if (m_lower_bound - m_over_body - 20 < m_area.getWidth()/2*3/4) { - m_screenshot_widget->m_w = (lower_bound - upper_bound - 30)*4/3; - m_screenshot_widget->m_h = lower_bound - upper_bound - 30; + m_screenshot_widget->m_w = (m_lower_bound - m_over_body - 30)*4/3; + m_screenshot_widget->m_h = m_lower_bound - m_over_body - 30; } else { @@ -183,48 +182,41 @@ void GPInfoDialog::InitAfterDrawingTheHeader(const int upper_bound, m_screenshot_widget->m_h = m_area.getWidth()*3/8; // *(3/4)*(1/2) } - Track* track = (tracks.size() == 0 ? NULL : track_manager->getTrack(tracks[0])); - - m_screenshot_widget->m_properties[PROP_ICON] = (track != NULL ? - track->getScreenshotFile().c_str() : - file_manager->getAsset(FileManager::GUI,"main_help.png")); + Track* track = track_manager->getTrack(m_gp->getTrackNames()[0]); + m_screenshot_widget->m_properties[GUIEngine::PROP_ICON] = (track->getScreenshotFile().c_str()); m_screenshot_widget->setParent(m_irrlicht_window); m_screenshot_widget->add(); m_widgets.push_back(m_screenshot_widget); +} +// ---------------------------------------------------------------------------- +void GPInfoDialog::addButtons() +{ // ---- Start button - ButtonWidget* okBtn = new ButtonWidget(); - ButtonWidget* continueBtn = new ButtonWidget(); + GUIEngine::ButtonWidget* okBtn = new GUIEngine::ButtonWidget(); + GUIEngine::ButtonWidget* continueBtn = new GUIEngine::ButtonWidget(); SavedGrandPrix* saved_gp = SavedGrandPrix::getSavedGP( StateManager::get() ->getActivePlayerProfile(0) ->getUniqueID(), - gp_ident, + m_gp->getId(), race_manager->getDifficulty(), race_manager->getNumberOfKarts(), race_manager->getNumLocalPlayers()); - if (tracks.size() == 0) - { - okBtn->m_properties[PROP_ID] = "cannot_start"; - okBtn->setText(_("Sorry, no tracks available")); - } - else - { - okBtn->m_properties[PROP_ID] = "start"; - okBtn->setText(_("Start Grand Prix")); + okBtn->m_properties[PROP_ID] = "start"; + okBtn->setText(_("Start Grand Prix")); - continueBtn->m_properties[PROP_ID] = "continue"; - continueBtn->setText(_("Continue")); - } + continueBtn->m_properties[PROP_ID] = "continue"; + continueBtn->setText(_("Continue")); if (saved_gp) { continueBtn->m_x = m_area.getWidth()/2 + 110; - continueBtn->m_y = lower_bound; + continueBtn->m_y = m_lower_bound; continueBtn->m_w = 200; - continueBtn->m_h = m_area.getHeight() - lower_bound - 15; + continueBtn->m_h = m_area.getHeight() - m_lower_bound - 15; continueBtn->setParent(m_irrlicht_window); m_widgets.push_back(continueBtn); continueBtn->add(); @@ -238,9 +230,9 @@ void GPInfoDialog::InitAfterDrawingTheHeader(const int upper_bound, okBtn->m_x = m_area.getWidth()/2 - 200; } - okBtn->m_y = lower_bound; + okBtn->m_y = m_lower_bound; okBtn->m_w = 400; - okBtn->m_h = m_area.getHeight() - lower_bound - 15; + okBtn->m_h = m_area.getHeight() - m_lower_bound - 15; okBtn->setParent(m_irrlicht_window); m_widgets.push_back(okBtn); okBtn->add(); @@ -250,36 +242,30 @@ void GPInfoDialog::InitAfterDrawingTheHeader(const int upper_bound, okBtn->setFocusForPlayer( PLAYER_ID_GAME_MASTER ); } +// ---------------------------------------------------------------------------- + void GPInfoDialog::onEnterPressedInternal() { + std::string gp_id = m_gp->getId(); ModalDialog::dismiss(); // Disable accidentally unlocking of a challenge PlayerManager::getCurrentPlayer()->setCurrentChallenge(""); - race_manager->startGP(m_gp, false, false); + race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id), false, false); } // ---------------------------------------------------------------------------- GUIEngine::EventPropagation GPInfoDialog::processEvent(const std::string& eventSource) { - if (eventSource == "start") - { - ModalDialog::dismiss(); - race_manager->startGP(m_gp, false, false); - return GUIEngine::EVENT_BLOCK; - } - if (eventSource == "continue") + if (eventSource == "start" || eventSource == "continue") { // Save GP identifier, since dismiss will delete this object. - std::string gp_id = m_gp_ident; + std::string gp_id = m_gp->getId(); ModalDialog::dismiss(); - race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id), false, true); + race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id), false, + (eventSource == "continue")); return GUIEngine::EVENT_BLOCK; } - else if (eventSource == "cannot_start") - { - sfx_manager->quickSound( "anvil" ); - } return GUIEngine::EVENT_LET; } @@ -288,12 +274,12 @@ GUIEngine::EventPropagation GPInfoDialog::processEvent(const std::string& eventS void GPInfoDialog::onUpdate(float dt) { - const int frameBefore = (int)(m_curr_time / 1.5f); + if (dt == 0) + return; // if nothing changed, return right now + m_curr_time += dt; int frameAfter = (int)(m_curr_time / 1.5f); - if (frameAfter == frameBefore) return; // if nothing changed, return right now - const std::vector tracks = m_gp->getTrackNames(); if (frameAfter >= (int)tracks.size()) { @@ -301,11 +287,9 @@ void GPInfoDialog::onUpdate(float dt) m_curr_time = 0; } - Track* track = (tracks.size() == 0 ? NULL : - track_manager->getTrack(tracks[frameAfter])); - std::string fn = track ? track->getScreenshotFile() - : file_manager->getAsset(FileManager::GUI, "main_help.png"); - m_screenshot_widget->setImage(fn.c_str(), IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE); + Track* track = track_manager->getTrack(tracks[frameAfter]); + std::string file = track->getScreenshotFile(); + typedef GUIEngine::IconButtonWidget Icon; + m_screenshot_widget->setImage(file.c_str(), Icon::ICON_PATH_TYPE_ABSOLUTE); } -// ---------------------------------------------------------------------------- diff --git a/src/states_screens/dialogs/gp_info_dialog.hpp b/src/states_screens/dialogs/gp_info_dialog.hpp index 61ded1118..bb455ce71 100644 --- a/src/states_screens/dialogs/gp_info_dialog.hpp +++ b/src/states_screens/dialogs/gp_info_dialog.hpp @@ -33,33 +33,41 @@ namespace GUIEngine */ class GPInfoDialog : public GUIEngine::ModalDialog { -protected: // Necessary for randomGPInfoDialog - std::string m_gp_ident; +protected: // Necessary for RandomGPInfoDialog GUIEngine::IconButtonWidget* m_screenshot_widget; float m_curr_time; GrandPrixData* m_gp; + /** height of the separator over the body */ + int m_over_body; + /** height of the separator under the titlebar, which is equal to + * m_over_body in a normal GPInfoDialo and lower in RandomGPInfoDialog. */ + int m_under_title; + /** height of the seperator over the buttons */ + int m_lower_bound; + + void addTitle(); + /** \brief display all the tracks according to the current gp + * For a normal gp info dialog, it just creates a label for every track. + * But with a random gp info dialog, it tries to reuse as many + * labels as possible by just changing their text. */ + void addTracks(); + void addScreenshot(); + /** display a ok-button and eventually a continue-button */ + void addButtons(); + + /** only used for track_screen.cpp */ + GPInfoDialog() : ModalDialog(PERCENT_WIDTH, PERCENT_HEIGHT) {} + public: static const float PERCENT_WIDTH = 0.8f; static const float PERCENT_HEIGHT = 0.7f; - /** - * 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) {} + GPInfoDialog(const std::string& gpIdent); + /** Places the focus back on the selected GP, in the case that the dialog + * was cancelled and we're returning to the track selection screen */ virtual ~GPInfoDialog(); - void InitAfterDrawingTheHeader(const int y1, const int y2, - const std::string& gp_ident); - - /** \brief display all the tracks according to the current gp - * For a normal gp info dialog, it just creates a label for every track. - * With its name. But in a random gp info dialog, it tries to reuse as many - * labels as possible by just changing their text. If there are less than - * need, some are added, if there are to many, some are deleted. */ - void displayTracks(const int y1, const int y2); - 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 4700209d5..afa4aebc4 100644 --- a/src/states_screens/dialogs/random_gp_dialog.cpp +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -17,20 +17,21 @@ #include "guiengine/engine.hpp" #include "guiengine/widgets/spinner_widget.hpp" -#include "guiengine/widget.hpp" #include "race/grand_prix_manager.hpp" +#include "race/race_manager.hpp" #include "states_screens/dialogs/random_gp_dialog.hpp" #include "tracks/track_manager.hpp" #include #include -using namespace irr::gui; -using namespace irr::video; -using namespace irr::core; -using namespace GUIEngine; +using irr::core::stringc; +using irr::core::stringw; +using irr::gui::IGUIStaticText; -randomGPInfoDialog::randomGPInfoDialog() +typedef GUIEngine::SpinnerWidget Spinner; + +RandomGPInfoDialog::RandomGPInfoDialog() { // Defaults - loading selection from last time frrom a file would be better m_number_of_tracks = 2; @@ -40,27 +41,30 @@ randomGPInfoDialog::randomGPInfoDialog() doInit(); m_curr_time = 0.0f; - int y1 = m_area.getHeight()/7; + m_under_title = m_area.getHeight()/7; + m_over_body = m_area.getHeight()/7 + SPINNER_HEIGHT + 10; // 10px space + m_lower_bound = m_area.getHeight()*6/7; - m_gp_ident = "random"; m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse); - // ---- 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); + addTitle(); + addSpinners(); + addTracks(); + addScreenshot(); + addButtons(); +} - // ---- Spinners +// ---------------------------------------------------------------------------- + +void RandomGPInfoDialog::addSpinners() +{ // Trackgroup chooser - GUIEngine::SpinnerWidget* spinner = new GUIEngine::SpinnerWidget(false); - spinner->m_properties[PROP_ID] = "Trackgroup"; + Spinner* spinner = new Spinner(false); + spinner->m_properties[GUIEngine::PROP_ID] = "Trackgroup"; spinner->setParent(m_irrlicht_window); m_widgets.push_back(spinner); spinner->add(); - spinner->move(10, m_area.getHeight()/7, 300, 40); + spinner->move(10, m_under_title, 300, SPINNER_HEIGHT); // Fill it with with all the track group names spinner->addLabel("all"); const std::vector& groups = track_manager->getAllTrackGroups(); @@ -68,35 +72,41 @@ randomGPInfoDialog::randomGPInfoDialog() spinner->addLabel(stringw(groups[i].c_str())); // Number of laps chooser - spinner = new GUIEngine::SpinnerWidget(false); + spinner = new Spinner(false); spinner->setValue(m_number_of_tracks); spinner->setMin(1); spinner->setMax(track_manager->getNumberOfTracks()); // default is "all" spinner->setParent(m_irrlicht_window); - spinner->m_properties[PROP_ID] = "Number of tracks"; + spinner->m_properties[GUIEngine::PROP_ID] = "Number of tracks"; m_widgets.push_back(spinner); spinner->add(); - spinner->move(310, m_area.getHeight()/7, 200, 40); - - displayTracks(m_area.getHeight()/7 + 50, m_area.getHeight()*6/7); - InitAfterDrawingTheHeader(m_area.getHeight()/7 + 50, - m_area.getHeight()*6/7, - "random"); + spinner->move(310, m_under_title, 200, SPINNER_HEIGHT); } -GUIEngine::EventPropagation randomGPInfoDialog::processEvent( +// ---------------------------------------------------------------------------- + +GUIEngine::EventPropagation RandomGPInfoDialog::processEvent( const std::string& eventSource) { - if (eventSource == "Number of tracks") + if (eventSource == "start") { - m_number_of_tracks = getWidget("Number of tracks")->getValue(); + // Save the gp since dismiss deletes it otherwise + GrandPrixData buff = *m_gp; + ModalDialog::dismiss(); + race_manager->startGP(&buff, false, false); + return GUIEngine::EVENT_BLOCK; + } + else if (eventSource == "Number of tracks") + { + // The old gp can be reused because there's only track deletion/adding + m_number_of_tracks = getWidget("Number of tracks")->getValue(); m_gp->changeTrackNumber(m_number_of_tracks, m_trackgroup, m_use_reverse); - displayTracks(m_area.getHeight()/7, m_area.getHeight()*6/7); + addTracks(); } else if (eventSource == "Trackgroup") { - GUIEngine::SpinnerWidget* t = getWidget("Trackgroup"); - GUIEngine::SpinnerWidget* s = getWidget("Number of tracks"); + Spinner* t = getWidget("Trackgroup"); + Spinner* s = getWidget("Number of tracks"); m_trackgroup = stringc(t->getStringValue()).c_str(); @@ -115,15 +125,17 @@ GUIEngine::EventPropagation randomGPInfoDialog::processEvent( updateGP(); } - return GPInfoDialog::processEvent(eventSource); + return GUIEngine::EVENT_LET; } -void randomGPInfoDialog::updateGP() +// ---------------------------------------------------------------------------- + +void RandomGPInfoDialog::updateGP() { if (m_gp != NULL) delete m_gp; m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse); - displayTracks(m_area.getHeight()/7, m_area.getHeight()*6/7); + addTracks(); } diff --git a/src/states_screens/dialogs/random_gp_dialog.hpp b/src/states_screens/dialogs/random_gp_dialog.hpp index 945bbdc8c..ee66a8f30 100644 --- a/src/states_screens/dialogs/random_gp_dialog.hpp +++ b/src/states_screens/dialogs/random_gp_dialog.hpp @@ -18,12 +18,11 @@ #ifndef HEADER_RANDOM_GP_INFO_DIALOG_HPP #define HEADER_RANDOM_GP_INFO_DIALOG_HPP -#include "guiengine/widgets/spinner_widget.hpp" #include "states_screens/dialogs/gp_info_dialog.hpp" #include -class randomGPInfoDialog : public GPInfoDialog +class RandomGPInfoDialog : public GPInfoDialog { private: unsigned int m_number_of_tracks; @@ -31,10 +30,17 @@ private: bool m_use_reverse; public: - randomGPInfoDialog(); - ~randomGPInfoDialog() { delete m_gp; } + static const int SPINNER_HEIGHT = 40; + + RandomGPInfoDialog(); + ~RandomGPInfoDialog() { delete m_gp; } + + /** Adds a SpinnerWidgets to choose the track groups and one to choose the + * number of tracks */ + void addSpinners(); GUIEngine::EventPropagation processEvent(const std::string& eventSource); + /** Constructs a new gp from the members */ void updateGP(); }; diff --git a/src/states_screens/tracks_screen.cpp b/src/states_screens/tracks_screen.cpp index 2791cfdca..831608aa8 100644 --- a/src/states_screens/tracks_screen.cpp +++ b/src/states_screens/tracks_screen.cpp @@ -119,10 +119,10 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name, } else { - if (selection != "Random") - new GPInfoDialog(selection); + if (selection == "Random Grand Prix") + new RandomGPInfoDialog(); else - new randomGPInfoDialog(); + new GPInfoDialog(selection); } } else if (name == "trackgroups") @@ -214,10 +214,11 @@ void TracksScreen::init() } } - // Random GP - not finished yet + // Random GP std::vector screenshots; screenshots.push_back("gui/main_help.png"); - gps_widget->addAnimatedItem(translations->fribidize("Random"), "Random", + gps_widget->addAnimatedItem(translations->fribidize("Random Grand Prix"), + "Random Grand Prix", screenshots, 1.5f, 0, IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE); From 6bf1a33ddc94e4ccc7ea9fe4eb69911ed85188b2 Mon Sep 17 00:00:00 2001 From: konstin Date: Sat, 31 May 2014 16:50:01 +0200 Subject: [PATCH 016/121] fix compilation failure due to merging --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 118e2885a..ff95b19ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -361,7 +361,7 @@ void gamepadVisualisation() } // gamepadVisualisation // ============================================================================ -/** Sets the hat mesh name depending on the current christmas mode +/** Sets the hat mesh name depending on the current christmas mode * m_xmas_mode (0: use current date, 1: always on, 2: always off). */ void handleXmasMode() @@ -847,14 +847,14 @@ int handleCmdLine() if(CommandLine::has("--gp", &s)) { race_manager->setMajorMode(RaceManager::MAJOR_MODE_GRAND_PRIX); - const GrandPrixData *gp = grand_prix_manager->getGrandPrix(s); + GrandPrixData *gp = grand_prix_manager->getGrandPrix(s); if (!gp) { Log::warn("main", "There is no GP named '%s'.", s.c_str()); return 0; } - race_manager->setGrandPrix(*gp); + race_manager->setGrandPrix(gp); } // --gp if(CommandLine::has("--numkarts", &n) ||CommandLine::has("-k", &n)) From 6521e3d496afd2638fb0ad7087ec0e0bd5d91e70 Mon Sep 17 00:00:00 2001 From: konstin Date: Sat, 31 May 2014 17:28:20 +0200 Subject: [PATCH 017/121] fix crash due to a dangling pointer --- src/race/grand_prix_manager.cpp | 39 ++++++++++++------- src/race/grand_prix_manager.hpp | 4 ++ .../dialogs/random_gp_dialog.cpp | 14 +++++-- .../dialogs/random_gp_dialog.hpp | 1 - 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/race/grand_prix_manager.cpp b/src/race/grand_prix_manager.cpp index 48b02046e..d0eb5dfef 100644 --- a/src/race/grand_prix_manager.cpp +++ b/src/race/grand_prix_manager.cpp @@ -27,10 +27,30 @@ #include #include +#include // remove later + GrandPrixManager *grand_prix_manager = NULL; const char* GrandPrixManager::SUFFIX = ".grandprix"; +// ---------------------------------------------------------------------------- +GrandPrixManager::GrandPrixManager() +{ + m_random_gp = NULL; // better do it explicitly and avoid weird stuff + loadFiles(); +} + +// ---------------------------------------------------------------------------- +GrandPrixManager::~GrandPrixManager() +{ + for(unsigned int i=0; igetId() == s) diff --git a/src/race/grand_prix_manager.hpp b/src/race/grand_prix_manager.hpp index c8510bf3a..314ddcc59 100644 --- a/src/race/grand_prix_manager.hpp +++ b/src/race/grand_prix_manager.hpp @@ -47,6 +47,10 @@ private: bool existsName(const irr::core::stringw& name) const; public: + /** saved here by a random GP dialog to avoid dangling pinters or + * memory leaks */ + GrandPrixData* m_random_gp; + GrandPrixManager(); ~GrandPrixManager(); void reload(); diff --git a/src/states_screens/dialogs/random_gp_dialog.cpp b/src/states_screens/dialogs/random_gp_dialog.cpp index afa4aebc4..412d850cf 100644 --- a/src/states_screens/dialogs/random_gp_dialog.cpp +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -45,7 +45,14 @@ RandomGPInfoDialog::RandomGPInfoDialog() m_over_body = m_area.getHeight()/7 + SPINNER_HEIGHT + 10; // 10px space m_lower_bound = m_area.getHeight()*6/7; + // The GP manager is be used to make the GP live longer than this dialog + if (grand_prix_manager->m_random_gp) + { + delete grand_prix_manager->m_random_gp; + grand_prix_manager->m_random_gp = NULL; + } m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse); + grand_prix_manager->m_random_gp = m_gp; addTitle(); addSpinners(); @@ -91,9 +98,8 @@ GUIEngine::EventPropagation RandomGPInfoDialog::processEvent( if (eventSource == "start") { // Save the gp since dismiss deletes it otherwise - GrandPrixData buff = *m_gp; ModalDialog::dismiss(); - race_manager->startGP(&buff, false, false); + race_manager->startGP(m_gp, false, false); return GUIEngine::EVENT_BLOCK; } else if (eventSource == "Number of tracks") @@ -132,10 +138,10 @@ GUIEngine::EventPropagation RandomGPInfoDialog::processEvent( void RandomGPInfoDialog::updateGP() { - if (m_gp != NULL) - delete m_gp; + delete m_gp; m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse); + grand_prix_manager->m_random_gp = m_gp; addTracks(); } diff --git a/src/states_screens/dialogs/random_gp_dialog.hpp b/src/states_screens/dialogs/random_gp_dialog.hpp index ee66a8f30..587bd06cf 100644 --- a/src/states_screens/dialogs/random_gp_dialog.hpp +++ b/src/states_screens/dialogs/random_gp_dialog.hpp @@ -33,7 +33,6 @@ public: static const int SPINNER_HEIGHT = 40; RandomGPInfoDialog(); - ~RandomGPInfoDialog() { delete m_gp; } /** Adds a SpinnerWidgets to choose the track groups and one to choose the * number of tracks */ From ae2e6f77ad2858a1cf82f49f7c01d908ebcd94d1 Mon Sep 17 00:00:00 2001 From: konstin Date: Sat, 31 May 2014 22:12:01 +0200 Subject: [PATCH 018/121] Avoid duplicate name in GP editor --- src/states_screens/dialogs/enter_gp_name_dialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/states_screens/dialogs/enter_gp_name_dialog.cpp b/src/states_screens/dialogs/enter_gp_name_dialog.cpp index 6434a747d..e75c64abc 100644 --- a/src/states_screens/dialogs/enter_gp_name_dialog.cpp +++ b/src/states_screens/dialogs/enter_gp_name_dialog.cpp @@ -81,7 +81,7 @@ void EnterGPNameDialog::onEnterPressedInternal() TextBoxWidget* textCtrl = getWidget("textfield"); assert(textCtrl != NULL); stringw name = textCtrl->getText().trim(); - if (name.size() > 0) + if (name.size() > 0 && name != "Random Grand Prix") { // check for duplicate names for (unsigned int i = 0; i < grand_prix_manager->getNumberOfGrandPrix(); i++) From 03768db82abfc5fd0519402982a3e18da0c236af Mon Sep 17 00:00:00 2001 From: konstin Date: Sat, 31 May 2014 22:32:55 +0200 Subject: [PATCH 019/121] avoid duplicate tracks --- src/race/grand_prix_data.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/race/grand_prix_data.cpp b/src/race/grand_prix_data.cpp index a49e44964..686a053cf 100644 --- a/src/race/grand_prix_data.cpp +++ b/src/race/grand_prix_data.cpp @@ -30,7 +30,6 @@ #include #include -#include #include #include @@ -91,7 +90,12 @@ void GrandPrixData::changeTrackNumber(const unsigned int number_of_tracks, rand() % available_tracks : track_indices[rand() % available_tracks]; - m_tracks.push_back(track_manager->getTrack(index)->getIdent()); + std::string id = track_manager->getTrack(index)->getIdent(); + // Avoid duplicate tracks + if (std::find(m_tracks.begin(), m_tracks.end(), id) != m_tracks.end()) + continue; + + m_tracks.push_back(id); m_laps.push_back(3); // TODO: Take the default number from the track m_reversed.push_back(rand() % 2); } From ce661a4dd47755daa11467462fc650fe5058e099 Mon Sep 17 00:00:00 2001 From: konstin Date: Mon, 2 Jun 2014 16:56:59 +0200 Subject: [PATCH 020/121] add a reverse spinner --- src/network/race_config.cpp | 2 + src/race/grand_prix_data.cpp | 34 +++++++++++--- src/race/grand_prix_data.hpp | 15 +++--- src/race/grand_prix_manager.cpp | 3 -- src/states_screens/dialogs/gp_info_dialog.hpp | 5 +- .../dialogs/random_gp_dialog.cpp | 46 ++++++++++++------- .../dialogs/random_gp_dialog.hpp | 18 ++++++-- 7 files changed, 84 insertions(+), 39 deletions(-) diff --git a/src/network/race_config.cpp b/src/network/race_config.cpp index bb4ac65ae..a60af9015 100644 --- a/src/network/race_config.cpp +++ b/src/network/race_config.cpp @@ -3,6 +3,8 @@ #include "race/race_manager.hpp" #include "utils/log.hpp" +#include + /** \brief Gets the element with the highest count in a std::map. * \param histogram : A pointer to the histogram. * \return The key of type S that has the highest second value. diff --git a/src/race/grand_prix_data.cpp b/src/race/grand_prix_data.cpp index 686a053cf..318db46d6 100644 --- a/src/race/grand_prix_data.cpp +++ b/src/race/grand_prix_data.cpp @@ -24,11 +24,13 @@ #include "config/player_manager.hpp" #include "io/file_manager.hpp" #include "io/utf_writer.hpp" +#include "states_screens/dialogs/random_gp_dialog.hpp" #include "tracks/track_manager.hpp" #include "tracks/track.hpp" #include "utils/string_utils.hpp" #include +#include #include #include #include @@ -46,25 +48,25 @@ GrandPrixData::GrandPrixData(const std::string& filename) // ---------------------------------------------------------------------------- GrandPrixData::GrandPrixData(const unsigned int number_of_tracks, - const std::string& track_group, - const bool use_reverse) + const std::string& track_group, + const RandomGPInfoDialog::REVERSED use_reverse) { m_filename = "Random GP - Not loaded from a file!"; m_id = "random"; - m_name = L"Random Grand Prix"; + m_name = "Random Grand Prix"; m_editable = false; m_tracks.reserve(number_of_tracks); m_laps.reserve(number_of_tracks); m_reversed.reserve(number_of_tracks); - changeTrackNumber(number_of_tracks, track_group, use_reverse); + changeTrackNumber(number_of_tracks, track_group); + changeReverse(use_reverse); } // ---------------------------------------------------------------------------- void GrandPrixData::changeTrackNumber(const unsigned int number_of_tracks, - const std::string& track_group, - const bool use_reverse) + const std::string& track_group) { // The problem with the track groups is that "all" isn't a track group // TODO: Add "all" to the track groups and rewrite this more elegant @@ -97,7 +99,7 @@ void GrandPrixData::changeTrackNumber(const unsigned int number_of_tracks, m_tracks.push_back(id); m_laps.push_back(3); // TODO: Take the default number from the track - m_reversed.push_back(rand() % 2); + m_reversed.push_back(false); // This will be changed later } } else if (m_tracks.size() > number_of_tracks) @@ -114,6 +116,24 @@ void GrandPrixData::changeTrackNumber(const unsigned int number_of_tracks, assert(m_laps.size() == m_reversed.size()); } +// ---------------------------------------------------------------------------- + +void GrandPrixData::changeReverse(const RandomGPInfoDialog::REVERSED use_reverse) +{ + for (unsigned int i = 0; i < m_tracks.size(); i++) + { + if (use_reverse == RandomGPInfoDialog::NO_REVERSE) + m_reversed[i] = false; + else if (use_reverse == RandomGPInfoDialog::MIXED) + if (track_manager->getTrack(m_tracks[i])->reverseAvailable()) + m_reversed[i] = rand() % 2; + else + m_reversed[i] = false; + else // all reversed + m_reversed[i] = true; + } +} + // ---------------------------------------------------------------------------- void GrandPrixData::setId(const std::string& id) { diff --git a/src/race/grand_prix_data.hpp b/src/race/grand_prix_data.hpp index d92e2ff5f..fee47e729 100644 --- a/src/race/grand_prix_data.hpp +++ b/src/race/grand_prix_data.hpp @@ -20,14 +20,15 @@ #ifndef HEADER_GRAND_PRIX_DATA_HPP #define HEADER_GRAND_PRIX_DATA_HPP +#include #include #include -#include -#include -#include +#include "states_screens/dialogs/random_gp_dialog.hpp" #include "utils/translation.hpp" +using irr::core::stringw; + class Track; /** Simple class that hold the data relevant to a 'grand_prix', aka. a number @@ -78,11 +79,11 @@ public: GrandPrixData() {}; /** TODO */ GrandPrixData(const unsigned int number_of_tracks, - const std::string& m_track_group, - const bool use_reverse); + const std::string& track_group, + const RandomGPInfoDialog::REVERSED use_reverse); void changeTrackNumber(const unsigned int number_of_tracks, - const std::string& track_group, - const bool use_reverse); + const std::string& track_group); + void changeReverse(const RandomGPInfoDialog::REVERSED use_reverse); // Methods for the GP editor void setId(const std::string& id); diff --git a/src/race/grand_prix_manager.cpp b/src/race/grand_prix_manager.cpp index d0eb5dfef..887a7888b 100644 --- a/src/race/grand_prix_manager.cpp +++ b/src/race/grand_prix_manager.cpp @@ -27,8 +27,6 @@ #include #include -#include // remove later - GrandPrixManager *grand_prix_manager = NULL; const char* GrandPrixManager::SUFFIX = ".grandprix"; @@ -159,7 +157,6 @@ GrandPrixData* GrandPrixManager::getGrandPrix(const std::string& s) const // ---------------------------------------------------------------------------- GrandPrixData* GrandPrixManager::editGrandPrix(const std::string& s) const { - std::cout << s << std::endl; if (s == "random") return m_random_gp; diff --git a/src/states_screens/dialogs/gp_info_dialog.hpp b/src/states_screens/dialogs/gp_info_dialog.hpp index bb455ce71..f29d3ad2e 100644 --- a/src/states_screens/dialogs/gp_info_dialog.hpp +++ b/src/states_screens/dialogs/gp_info_dialog.hpp @@ -20,7 +20,10 @@ #define HEADER_GP_INFO_DIALOG_HPP #include "guiengine/modaldialog.hpp" -#include "race/grand_prix_data.hpp" +// Don't include grand_prix_data.hpp here or the compilation will fail + + +class GrandPrixData; namespace GUIEngine { diff --git a/src/states_screens/dialogs/random_gp_dialog.cpp b/src/states_screens/dialogs/random_gp_dialog.cpp index 412d850cf..a43a351da 100644 --- a/src/states_screens/dialogs/random_gp_dialog.cpp +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -36,7 +36,7 @@ RandomGPInfoDialog::RandomGPInfoDialog() // Defaults - loading selection from last time frrom a file would be better m_number_of_tracks = 2; m_trackgroup = "all"; - m_use_reverse = true; + m_use_reverse = NO_REVERSE; doInit(); m_curr_time = 0.0f; @@ -65,13 +65,16 @@ RandomGPInfoDialog::RandomGPInfoDialog() void RandomGPInfoDialog::addSpinners() { + const int left = (m_area.getWidth() - 250 - 150 - 250)/2; + // Trackgroup chooser Spinner* spinner = new Spinner(false); spinner->m_properties[GUIEngine::PROP_ID] = "Trackgroup"; + spinner->m_properties[GUIEngine::PROP_WRAP_AROUND] = "true"; spinner->setParent(m_irrlicht_window); m_widgets.push_back(spinner); spinner->add(); - spinner->move(10, m_under_title, 300, SPINNER_HEIGHT); + spinner->move(left + 0, m_under_title, 250, SPINNER_HEIGHT); // Fill it with with all the track group names spinner->addLabel("all"); const std::vector& groups = track_manager->getAllTrackGroups(); @@ -85,9 +88,22 @@ void RandomGPInfoDialog::addSpinners() spinner->setMax(track_manager->getNumberOfTracks()); // default is "all" spinner->setParent(m_irrlicht_window); spinner->m_properties[GUIEngine::PROP_ID] = "Number of tracks"; + spinner->m_properties[GUIEngine::PROP_WRAP_AROUND] = "true"; m_widgets.push_back(spinner); spinner->add(); - spinner->move(310, m_under_title, 200, SPINNER_HEIGHT); + spinner->move(left + 260, m_under_title, 150, SPINNER_HEIGHT); + + // reverse choose + spinner = new Spinner(false); + spinner->setParent(m_irrlicht_window); + spinner->m_properties[GUIEngine::PROP_ID] = "reverse"; + spinner->m_properties[GUIEngine::PROP_WRAP_AROUND] = "true"; + m_widgets.push_back(spinner); + spinner->add(); + spinner->move(left + 410, m_under_title, 250, SPINNER_HEIGHT); + spinner->addLabel("no reverse"); + spinner->addLabel("all reverse"); + spinner->addLabel("mixed"); } // ---------------------------------------------------------------------------- @@ -106,7 +122,7 @@ GUIEngine::EventPropagation RandomGPInfoDialog::processEvent( { // The old gp can be reused because there's only track deletion/adding m_number_of_tracks = getWidget("Number of tracks")->getValue(); - m_gp->changeTrackNumber(m_number_of_tracks, m_trackgroup, m_use_reverse); + m_gp->changeTrackNumber(m_number_of_tracks, m_trackgroup); addTracks(); } else if (eventSource == "Trackgroup") @@ -128,20 +144,18 @@ GUIEngine::EventPropagation RandomGPInfoDialog::processEvent( if (s->getValue() > (signed)max) s->setValue(max); - updateGP(); + delete m_gp; + m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse); + grand_prix_manager->m_random_gp = m_gp; + addTracks(); + } + else if (eventSource == "reverse") + { + Spinner* r = getWidget("reverse"); + m_use_reverse = static_cast(r->getValue()); + m_gp->changeReverse(m_use_reverse); } return GUIEngine::EVENT_LET; } -// ---------------------------------------------------------------------------- - -void RandomGPInfoDialog::updateGP() -{ - delete m_gp; - - m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse); - grand_prix_manager->m_random_gp = m_gp; - addTracks(); -} - diff --git a/src/states_screens/dialogs/random_gp_dialog.hpp b/src/states_screens/dialogs/random_gp_dialog.hpp index 587bd06cf..126e23128 100644 --- a/src/states_screens/dialogs/random_gp_dialog.hpp +++ b/src/states_screens/dialogs/random_gp_dialog.hpp @@ -24,23 +24,31 @@ class RandomGPInfoDialog : public GPInfoDialog { +public: + // the enum has to be declared here because you can't forward declare it + // without c++11 + enum REVERSED + { + NO_REVERSE = 0, + ALL_REVERSE = 1, + MIXED = 2 + }; private: unsigned int m_number_of_tracks; std::string m_trackgroup; - bool m_use_reverse; + REVERSED m_use_reverse; public: static const int SPINNER_HEIGHT = 40; RandomGPInfoDialog(); - /** Adds a SpinnerWidgets to choose the track groups and one to choose the - * number of tracks */ + /** Adds a SpinnerWidgets to choose the track groups, one to choose the + * number of tracks and one to choose if the tracks should be raced in + * reverse. The Spinners are centered. */ void addSpinners(); GUIEngine::EventPropagation processEvent(const std::string& eventSource); - /** Constructs a new gp from the members */ - void updateGP(); }; #endif From 173725a9d49f4a3fe648aed21782b8588003f0cd Mon Sep 17 00:00:00 2001 From: konstin Date: Thu, 5 Jun 2014 18:26:11 +0200 Subject: [PATCH 021/121] add a restart button + better looking on 600x800 --- .../dialogs/random_gp_dialog.cpp | 48 +++++++++++++++---- .../dialogs/random_gp_dialog.hpp | 3 +- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/states_screens/dialogs/random_gp_dialog.cpp b/src/states_screens/dialogs/random_gp_dialog.cpp index a43a351da..1e66debd3 100644 --- a/src/states_screens/dialogs/random_gp_dialog.cpp +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -16,6 +16,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "guiengine/engine.hpp" +#include "guiengine/widgets/icon_button_widget.hpp" #include "guiengine/widgets/spinner_widget.hpp" #include "race/grand_prix_manager.hpp" #include "race/race_manager.hpp" @@ -34,8 +35,8 @@ typedef GUIEngine::SpinnerWidget Spinner; RandomGPInfoDialog::RandomGPInfoDialog() { // Defaults - loading selection from last time frrom a file would be better - m_number_of_tracks = 2; - m_trackgroup = "all"; + m_number_of_tracks = 2; // We can assume that there are at least 2 standart tracks + m_trackgroup = "standard"; m_use_reverse = NO_REVERSE; doInit(); @@ -59,13 +60,15 @@ RandomGPInfoDialog::RandomGPInfoDialog() addTracks(); addScreenshot(); addButtons(); + addRestartButton(); } // ---------------------------------------------------------------------------- void RandomGPInfoDialog::addSpinners() { - const int left = (m_area.getWidth() - 250 - 150 - 250)/2; + const int trackgroup_width = 200, laps_with = 150, reverse_width = 200; + const int left = (m_area.getWidth() - trackgroup_width - 150 - 250)/2; // Trackgroup chooser Spinner* spinner = new Spinner(false); @@ -74,24 +77,33 @@ void RandomGPInfoDialog::addSpinners() spinner->setParent(m_irrlicht_window); m_widgets.push_back(spinner); spinner->add(); - spinner->move(left + 0, m_under_title, 250, SPINNER_HEIGHT); + spinner->move(left, m_under_title, trackgroup_width, SPINNER_HEIGHT); // Fill it with with all the track group names spinner->addLabel("all"); const std::vector& groups = track_manager->getAllTrackGroups(); for (unsigned int i = 1; i < groups.size() + 1; i++) - spinner->addLabel(stringw(groups[i].c_str())); + { + // FIXME: The NULL check is necessary until #1348 on github is fixed + if (groups[i].c_str() != NULL) + { + spinner->addLabel(stringw(groups[i].c_str())); + if(groups[i] == "standard") + spinner->setValue(i); + } + } + spinner->setValue(1); // Let's just hope it's right ... // Number of laps chooser spinner = new Spinner(false); spinner->setValue(m_number_of_tracks); spinner->setMin(1); - spinner->setMax(track_manager->getNumberOfTracks()); // default is "all" + spinner->setMax(track_manager->getTracksInGroup("standard").size()); spinner->setParent(m_irrlicht_window); spinner->m_properties[GUIEngine::PROP_ID] = "Number of tracks"; spinner->m_properties[GUIEngine::PROP_WRAP_AROUND] = "true"; m_widgets.push_back(spinner); spinner->add(); - spinner->move(left + 260, m_under_title, 150, SPINNER_HEIGHT); + spinner->move(left + trackgroup_width + 10, m_under_title, laps_with, SPINNER_HEIGHT); // reverse choose spinner = new Spinner(false); @@ -100,7 +112,7 @@ void RandomGPInfoDialog::addSpinners() spinner->m_properties[GUIEngine::PROP_WRAP_AROUND] = "true"; m_widgets.push_back(spinner); spinner->add(); - spinner->move(left + 410, m_under_title, 250, SPINNER_HEIGHT); + spinner->move(left + trackgroup_width + laps_with + 10, m_under_title, reverse_width, SPINNER_HEIGHT); spinner->addLabel("no reverse"); spinner->addLabel("all reverse"); spinner->addLabel("mixed"); @@ -108,6 +120,19 @@ void RandomGPInfoDialog::addSpinners() // ---------------------------------------------------------------------------- +void RandomGPInfoDialog::addRestartButton() +{ + GUIEngine::IconButtonWidget* button = new GUIEngine::IconButtonWidget(); + button->setImage("gui/restart.png"); + button->setParent(m_irrlicht_window); + button->m_properties[GUIEngine::PROP_ID] = "reload"; + m_widgets.push_back(button); + button->add(); + button->move(m_area.getWidth() - 20 - 32, 20, 32, 32); +} + +// ---------------------------------------------------------------------------- + GUIEngine::EventPropagation RandomGPInfoDialog::processEvent( const std::string& eventSource) { @@ -155,6 +180,13 @@ GUIEngine::EventPropagation RandomGPInfoDialog::processEvent( m_use_reverse = static_cast(r->getValue()); m_gp->changeReverse(m_use_reverse); } + else if (eventSource == "reload") + { + delete m_gp; + m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse); + grand_prix_manager->m_random_gp = m_gp; + addTracks(); + } return GUIEngine::EVENT_LET; } diff --git a/src/states_screens/dialogs/random_gp_dialog.hpp b/src/states_screens/dialogs/random_gp_dialog.hpp index 126e23128..698217eec 100644 --- a/src/states_screens/dialogs/random_gp_dialog.hpp +++ b/src/states_screens/dialogs/random_gp_dialog.hpp @@ -25,8 +25,6 @@ class RandomGPInfoDialog : public GPInfoDialog { public: - // the enum has to be declared here because you can't forward declare it - // without c++11 enum REVERSED { NO_REVERSE = 0, @@ -47,6 +45,7 @@ public: * number of tracks and one to choose if the tracks should be raced in * reverse. The Spinners are centered. */ void addSpinners(); + void addRestartButton(); GUIEngine::EventPropagation processEvent(const std::string& eventSource); }; From 3679bf46174f23d70538ef336badf9ee459197fb Mon Sep 17 00:00:00 2001 From: konstin Date: Thu, 5 Jun 2014 18:59:16 +0200 Subject: [PATCH 022/121] adding a comment; fix #930 --- src/race/grand_prix_data.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/race/grand_prix_data.hpp b/src/race/grand_prix_data.hpp index fee47e729..742ec15f7 100644 --- a/src/race/grand_prix_data.hpp +++ b/src/race/grand_prix_data.hpp @@ -77,7 +77,7 @@ public: GrandPrixData(const std::string& filename); /** Needed for simple creation of an instance of GrandPrixData */ GrandPrixData() {}; - /** TODO */ + /** Creates a new random GP */ GrandPrixData(const unsigned int number_of_tracks, const std::string& track_group, const RandomGPInfoDialog::REVERSED use_reverse); From cd9c2653b696dd5aa2065276045e4f4984b7ebfe Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Tue, 17 Jun 2014 19:26:12 -0400 Subject: [PATCH 023/121] Initial work on porting minimap to new RTT --- src/graphics/glwrap.hpp | 2 +- src/graphics/irr_driver.cpp | 5 +- src/graphics/irr_driver.hpp | 5 +- src/graphics/post_processing.cpp | 10 ++-- src/graphics/post_processing.hpp | 2 +- src/graphics/render.cpp | 2 +- src/graphics/rtts.cpp | 22 +++++++++ src/graphics/rtts.hpp | 3 ++ src/guiengine/widgets/model_view_widget.cpp | 19 +------- src/states_screens/race_gui.cpp | 22 ++++++--- src/states_screens/race_gui_overworld.cpp | 20 +++++--- src/tracks/quad_graph.cpp | 52 +++++++++++++++++---- src/tracks/quad_graph.hpp | 10 ++-- src/tracks/track.cpp | 43 +++++++++++------ src/tracks/track.hpp | 6 ++- 15 files changed, 153 insertions(+), 70 deletions(-) diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index bb5a5cbf9..9a735b3ec 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -199,7 +199,7 @@ public: FrameBuffer(const std::vector &RTTs, GLuint DS, size_t w, size_t h, bool layered = false); ~FrameBuffer(); void Bind(); - std::vector &getRTT() { return RenderTargets; } + const std::vector &getRTT() const { return RenderTargets; } GLuint &getDepthTexture() { assert(DepthTexture); return DepthTexture; } size_t getWidth() const { return width; } size_t getHeight() const { return height; } diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 2f4291056..b38f3cb8d 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -2052,7 +2052,10 @@ bool IrrDriver::supportsSplatting() #endif // ---------------------------------------------------------------------------- -/** Begins a rendering to a texture. +/** + * THIS IS THE OLD OPENGL 1 RTT PROVIDER, USE THE SHADER-BASED + * RTT FOR NEW DEVELOPMENT + * Begins a rendering to a texture. * \param dimension The size of the texture. * \param name Name of the texture. * \param persistent_texture Whether the created RTT texture should persist in diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index bfffa6c3c..4b969956b 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -714,8 +714,11 @@ public: unsigned UpdateLightsInfo(scene::ICameraSceneNode * const camnode, float dt); void computeCameraMatrix(scene::ICameraSceneNode * const camnode, size_t width, size_t height); - // --------------------- RTT -------------------- + // --------------------- OLD RTT -------------------- /** + * THIS IS THE OLD OPENGL 1 RTT PROVIDER, USE THE SHADER-BASED + * RTT FOR NEW DEVELOPMENT + * * Class that provides RTT (currently, only when no other 3D rendering * in the main scene is required) * Provides an optional 'setupRTTScene' method to make it quick and easy diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index fd4fc0eed..d0003c733 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -698,7 +698,7 @@ void PostProcessing::applyMLAA() // ---------------------------------------------------------------------------- /** Render the post-processed scene */ -FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode) +FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode, bool isRace) { IVideoDriver * const drv = irr_driver->getVideoDriver(); @@ -716,7 +716,7 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode) glDisable(GL_DEPTH_TEST); glDisable(GL_BLEND); - if (UserConfigParams::m_dof) + if (isRace && UserConfigParams::m_dof) { PROFILER_PUSH_CPU_MARKER("- DoF", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_DOF)); @@ -732,7 +732,7 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode) if (World::getWorld() != NULL) hasgodrays = World::getWorld()->getTrack()->hasGodRays(); - if (UserConfigParams::m_light_shaft && m_sunpixels > 30 && hasgodrays) + if (isRace && UserConfigParams::m_light_shaft && m_sunpixels > 30 && hasgodrays) { glEnable(GL_DEPTH_TEST); // Grab the sky @@ -798,7 +798,7 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode) { PROFILER_PUSH_CPU_MARKER("- Bloom", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_BLOOM)); - if (UserConfigParams::m_bloom) + if (isRace && UserConfigParams::m_bloom) { glClear(GL_STENCIL_BUFFER_BIT); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); @@ -850,7 +850,7 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode) { PROFILER_PUSH_CPU_MARKER("- Motion blur", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_MOTIONBLUR)); - if (UserConfigParams::m_motionblur && m_any_boost && World::getWorld() != NULL) // motion blur + if (isRace && UserConfigParams::m_motionblur && m_any_boost && World::getWorld() != NULL) // motion blur { renderMotionBlur(0, *in_fbo, *out_fbo); std::swap(in_fbo, out_fbo); diff --git a/src/graphics/post_processing.hpp b/src/graphics/post_processing.hpp index edf314700..c046eb00a 100644 --- a/src/graphics/post_processing.hpp +++ b/src/graphics/post_processing.hpp @@ -96,7 +96,7 @@ public: void renderGlow(unsigned tex); /** Render the post-processed scene */ - FrameBuffer *render(scene::ICameraSceneNode * const camnode); + FrameBuffer *render(scene::ICameraSceneNode * const camnode, bool isRace); /** Use motion blur for a short time */ void giveBoost(unsigned int cam_index); diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index b7647a38c..ad865aa26 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -185,7 +185,7 @@ void IrrDriver::renderGLSL(float dt) // Render the post-processed scene if (UserConfigParams::m_dynamic_lights) { - FrameBuffer *fbo = m_post_processing->render(camnode); + FrameBuffer *fbo = m_post_processing->render(camnode, true); if (irr_driver->getNormals()) irr_driver->getFBO(FBO_NORMAL_AND_DEPTHS).BlitToDefault(viewport.UpperLeftCorner.X, viewport.UpperLeftCorner.Y, viewport.LowerRightCorner.X, viewport.LowerRightCorner.Y); diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 345841d6e..860725564 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -20,7 +20,9 @@ #include "config/user_config.hpp" #include "graphics/glwrap.hpp" #include "graphics/irr_driver.hpp" +#include "graphics/post_processing.hpp" #include "utils/log.hpp" +#include static GLuint generateRTT3D(GLenum target, size_t w, size_t h, size_t d, GLint internalFormat, GLint format, GLint type) { @@ -290,3 +292,23 @@ RTT::~RTT() delete m_RSM; } } + +FrameBuffer* RTT::render(scene::ICameraSceneNode* camera, float dt) +{ + irr_driver->setRTT(this); + + irr_driver->getSceneManager()->setActiveCamera(camera); + + std::vector glows; + irr_driver->computeCameraMatrix(camera, 512, 512); + unsigned plc = irr_driver->UpdateLightsInfo(camera, dt); + irr_driver->renderScene(camera, plc, glows, dt, false, true); + FrameBuffer* frame_buffer = irr_driver->getPostProcessing()->render(camera, false); + glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height); + + irr_driver->setRTT(NULL); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + + irr_driver->getSceneManager()->setActiveCamera(NULL); + return frame_buffer; +} \ No newline at end of file diff --git a/src/graphics/rtts.hpp b/src/graphics/rtts.hpp index 2c080eeec..802001eca 100644 --- a/src/graphics/rtts.hpp +++ b/src/graphics/rtts.hpp @@ -45,6 +45,9 @@ public: unsigned getDepthStencilTexture() const { return DepthStencilTexture; } unsigned getRenderTarget(enum TypeRTT target) const { return RenderTargetTextures[target]; } FrameBuffer& getFBO(enum TypeFBO fbo) { return FrameBuffers[fbo]; } + + FrameBuffer* render(scene::ICameraSceneNode* camera, float dt); + private: unsigned RenderTargetTextures[RTT_COUNT]; PtrVector FrameBuffers; diff --git a/src/guiengine/widgets/model_view_widget.cpp b/src/guiengine/widgets/model_view_widget.cpp index a89ad3b5c..745500998 100644 --- a/src/guiengine/widgets/model_view_widget.cpp +++ b/src/guiengine/widgets/model_view_widget.cpp @@ -173,21 +173,9 @@ void ModelViewWidget::update(float delta) m_rtt_main_node->setRotation(core::vector3df(0.0f, angle, 0.0f)); m_rtt_main_node->setVisible(true); - irr_driver->setRTT(m_rtt_provider); - irr_driver->getSceneManager()->setActiveCamera(m_camera); + m_frame_buffer = m_rtt_provider->render(m_camera, GUIEngine::getLatestDt()); - std::vector glows; - irr_driver->computeCameraMatrix(m_camera, 512, 512); - unsigned plc = irr_driver->UpdateLightsInfo(m_camera, GUIEngine::getLatestDt()); - irr_driver->renderScene(m_camera, plc, glows, GUIEngine::getLatestDt(), false, true); - m_frame_buffer = irr_driver->getPostProcessing()->render(m_camera); - glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height); - - irr_driver->setRTT(NULL); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - - irr_driver->getSceneManager()->setActiveCamera(NULL); m_rtt_main_node->setVisible(false); } @@ -284,10 +272,7 @@ void ModelViewWidget::setupRTTScene(PtrVector& mesh, m_camera->setAspectRatio(1.0f); m_camera->setPosition(core::vector3df(0.0, 20.0f, 70.0f)); - if (irr_driver->isGLSL()) - m_camera->setUpVector(core::vector3df(0.0, 1.0, 0.0)); - else - m_camera->setUpVector(core::vector3df(0.0, 1.0, 0.0)); + m_camera->setUpVector(core::vector3df(0.0, 1.0, 0.0)); m_camera->setTarget(core::vector3df(0, 10, 0.0f)); m_camera->setFOV(DEGREE_TO_RAD*50.0f); m_camera->updateAbsolutePosition(); diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index ae03ffe7e..700f955fa 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -342,19 +342,27 @@ void RaceGUI::drawGlobalMiniMap() // arenas currently don't have a map. if(world->getTrack()->isArena() || world->getTrack()->isSoccer()) return; - const video::ITexture *mini_map = world->getTrack()->getMiniMap(); + const video::ITexture *old_rtt_mini_map = world->getTrack()->getOldRttMiniMap(); + const FrameBuffer* new_rtt_mini_map = world->getTrack()->getNewRttMiniMap(); int upper_y = UserConfigParams::m_height - m_map_bottom - m_map_height; int lower_y = UserConfigParams::m_height - m_map_bottom; - if (mini_map != NULL) + core::rect dest(m_map_left, upper_y, + m_map_left + m_map_width, lower_y); + + if (old_rtt_mini_map != NULL) { - core::rect dest(m_map_left, upper_y, - m_map_left + m_map_width, lower_y); core::rect source(core::position2di(0, 0), - mini_map->getOriginalSize()); - draw2DImage(mini_map, dest, source, - NULL, NULL, true); + old_rtt_mini_map->getOriginalSize()); + draw2DImage(old_rtt_mini_map, dest, source, + NULL, NULL, true); + } + else if (new_rtt_mini_map != NULL) + { + core::rect source(0, 0, new_rtt_mini_map->getWidth(), new_rtt_mini_map->getHeight()); + draw2DImageFromRTT(new_rtt_mini_map->getRTT()[0], 512, 512, + dest, source, NULL, true); } for(unsigned int i=0; igetNumKarts(); i++) diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index 48b85fe91..208bd2360 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -321,17 +321,25 @@ void RaceGUIOverworld::drawGlobalMiniMap() } - const video::ITexture *mini_map = world->getTrack()->getMiniMap(); + const video::ITexture *old_rtt_mini_map = world->getTrack()->getOldRttMiniMap(); + const FrameBuffer* new_rtt_mini_map = world->getTrack()->getNewRttMiniMap(); int upper_y = m_map_bottom - m_map_height; int lower_y = m_map_bottom; - if (mini_map != NULL) + core::rect dest(m_map_left, upper_y, + m_map_left + m_map_width, lower_y); + + if (old_rtt_mini_map != NULL) { - core::rect dest(m_map_left, upper_y, - m_map_left + m_map_width, lower_y); - core::rect source(core::position2di(0, 0), mini_map->getOriginalSize()); - draw2DImage(mini_map, dest, source, 0, 0, true); + core::rect source(core::position2di(0, 0), old_rtt_mini_map->getOriginalSize()); + draw2DImage(old_rtt_mini_map, dest, source, 0, 0, true); + } + else if (new_rtt_mini_map != NULL) + { + core::rect source(0, 0, new_rtt_mini_map->getWidth(), new_rtt_mini_map->getHeight()); + draw2DImageFromRTT(new_rtt_mini_map->getRTT()[0], 512, 512, + dest, source, NULL, true); } Vec3 kart_xyz; diff --git a/src/tracks/quad_graph.cpp b/src/tracks/quad_graph.cpp index 528519058..70ffe9e9d 100644 --- a/src/tracks/quad_graph.cpp +++ b/src/tracks/quad_graph.cpp @@ -970,20 +970,35 @@ int QuadGraph::findOutOfRoadSector(const Vec3& xyz, //----------------------------------------------------------------------------- /** Takes a snapshot of the driveline quads so they can be used as minimap. */ -video::ITexture *QuadGraph::makeMiniMap(const core::dimension2du &origdimension, - const std::string &name, - const video::SColor &fill_color) +void QuadGraph::makeMiniMap(const core::dimension2du &origdimension, + const std::string &name, + const video::SColor &fill_color, + video::ITexture** oldRttMinimap, + FrameBuffer** newRttMinimap) { + *oldRttMinimap = NULL; + *newRttMinimap = NULL; + const core::dimension2du dimension = origdimension * 2; - IrrDriver::RTTProvider rttProvider(dimension, name, true); + RTT* newRttProvider = NULL; + IrrDriver::RTTProvider* oldRttProvider = NULL; + if (irr_driver->isGLSL()) + { + newRttProvider = new RTT(512, 512); + } + else + { + oldRttProvider = new IrrDriver::RTTProvider(dimension, name, true); + } + video::SColor red(128, 255, 0, 0); createMesh(/*show_invisible part of the track*/ false, /*enable_transparency*/ false, /*track_color*/ &fill_color, /*lap line color*/ &red ); - m_node = irr_driver->getSceneManager()->addMeshSceneNode(m_mesh); // add Debug Mesh + m_node = irr_driver->addMesh(m_mesh); #ifdef DEBUG m_node->setName("minimap-mesh"); #endif @@ -1035,28 +1050,47 @@ video::ITexture *QuadGraph::makeMiniMap(const core::dimension2du &origdimension, range, -1, bb_max.getY()-bb_min.getY()+1); camera->setProjectionMatrix(projection, true); + + irr_driver->suppressSkyBox(); + irr_driver->clearLights(); + // Adjust Y position by +1 for max, -1 for min - this helps in case that // the maximum Y coordinate is negative (otherwise the minimap is mirrored) // and avoids problems for tracks which have a flat (max Y = min Y) minimap. camera->setPosition(core::vector3df(center.getX(), bb_max.getY()+1, center.getZ())); camera->setUpVector(core::vector3df(0, 0, 1)); camera->setTarget(core::vector3df(center.getX(),bb_min.getY()-1,center.getZ())); + camera->setAspectRatio(1.0f); + camera->updateAbsolutePosition(); - video::ITexture *texture = rttProvider.renderToTexture(); + video::ITexture* texture = NULL; + FrameBuffer* frame_buffer = NULL; + if (irr_driver->isGLSL()) + { + frame_buffer = newRttProvider->render(camera, GUIEngine::getLatestDt()); + + // TODO: leak + //delete newRttProvider; + } + else + { + texture = oldRttProvider->renderToTexture(); + delete oldRttProvider; + } cleanupDebugMesh(); irr_driver->removeCameraSceneNode(camera); m_min_coord = bb_min; - if (texture == NULL) + if (texture == NULL && frame_buffer == NULL) { Log::error("Quad Graph", "[makeMiniMap] WARNING: RTT does not appear to work," "mini-map will not be available."); - return NULL; } - return texture; + *oldRttMinimap = texture; + *newRttMinimap = frame_buffer; } // makeMiniMap //----------------------------------------------------------------------------- diff --git a/src/tracks/quad_graph.hpp b/src/tracks/quad_graph.hpp index e4e58b260..23b71a6af 100644 --- a/src/tracks/quad_graph.hpp +++ b/src/tracks/quad_graph.hpp @@ -37,6 +37,7 @@ namespace irr using namespace irr; class CheckLine; +class FrameBuffer; /** * \brief This class stores a graph of quads. It uses a 'simplified singleton' @@ -118,10 +119,11 @@ public: float forwards_distance=1.5f, float sidewards_distance=1.5f, float upwards_distance=0.0f) const; - video::ITexture *makeMiniMap(const core::dimension2du &where, - const std::string &name, - const video::SColor &fill_color - =video::SColor(127, 255, 255, 255) ); + void makeMiniMap(const core::dimension2du &where, + const std::string &name, + const video::SColor &fill_color, + video::ITexture** oldRttMinimap, + FrameBuffer** newRttMinimap); void mapPoint2MiniMap(const Vec3 &xyz, Vec3 *out) const; void updateDistancesForAllSuccessors(unsigned int indx, float delta, diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 02ecf8588..e44c6181a 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -115,7 +115,8 @@ Track::Track(const std::string &filename) m_is_soccer = false; m_is_cutscene = false; m_camera_far = 1000.0f; - m_mini_map = NULL; + m_old_rtt_mini_map = NULL; + m_new_rtt_mini_map = NULL; m_bloom = true; m_bloom_threshold = 0.75f; m_color_inlevel = core::vector3df(0.0,1.0, 255.0); @@ -273,13 +274,13 @@ void Track::cleanup() // Clear reminder of the link between textures and file names. irr_driver->clearTexturesFileName(); - for(unsigned int i=0; iremoveNode(m_all_nodes[i]); } @@ -310,37 +311,42 @@ void Track::cleanup() // than once are in m_all_cached_mesh more than once (which is easier // than storing the mesh only once, but then having to test for each // mesh if it is already contained in the list or not). - for(unsigned int i=0; idropAllTextures(m_all_cached_meshes[i]); // If a mesh is not in Irrlicht's texture cache, its refcount is // 1 (since its scene node was removed, so the only other reference // is in m_all_cached_meshes). In this case we only drop it once // and don't try to remove it from the cache. - if(m_all_cached_meshes[i]->getReferenceCount()==1) + if (m_all_cached_meshes[i]->getReferenceCount() == 1) { m_all_cached_meshes[i]->drop(); continue; } m_all_cached_meshes[i]->drop(); - if(m_all_cached_meshes[i]->getReferenceCount()==1) + if (m_all_cached_meshes[i]->getReferenceCount() == 1) irr_driver->removeMeshFromCache(m_all_cached_meshes[i]); } m_all_cached_meshes.clear(); // Now free meshes that are not associated to any scene node. - for (unsigned int i=0; idropAllTextures(m_detached_cached_meshes[i]); irr_driver->removeMeshFromCache(m_detached_cached_meshes[i]); } m_detached_cached_meshes.clear(); - if(m_mini_map) + if (m_old_rtt_mini_map) { - assert(m_mini_map->getReferenceCount()==1); - irr_driver->removeTexture(m_mini_map); - m_mini_map = NULL; + assert(m_old_rtt_mini_map->getReferenceCount() == 1); + irr_driver->removeTexture(m_old_rtt_mini_map); + m_old_rtt_mini_map = NULL; + } + if (m_new_rtt_mini_map) + { + delete m_new_rtt_mini_map; + m_new_rtt_mini_map = NULL; } for(unsigned int i=0; igetRaceGUI()->getMiniMapSize(); core::dimension2du size = m_mini_map_size .getOptimalSize(!nonpower,!nonsquare); - m_mini_map = QuadGraph::get()->makeMiniMap(size, "minimap::"+m_ident); - if (m_mini_map) + + QuadGraph::get()->makeMiniMap(size, "minimap::" + m_ident, video::SColor(127, 255, 255, 255), + &m_old_rtt_mini_map, &m_new_rtt_mini_map); + if (m_old_rtt_mini_map) { - m_minimap_x_scale = float(m_mini_map_size.Width) / float(m_mini_map->getSize().Width); - m_minimap_y_scale = float(m_mini_map_size.Height) / float(m_mini_map->getSize().Height); + m_minimap_x_scale = float(m_mini_map_size.Width) / float(m_old_rtt_mini_map->getSize().Width); + m_minimap_y_scale = float(m_mini_map_size.Height) / float(m_old_rtt_mini_map->getSize().Height); + } + else if (m_new_rtt_mini_map) + { + m_minimap_x_scale = float(m_mini_map_size.Width) / float(m_new_rtt_mini_map->getWidth()); + m_minimap_y_scale = float(m_mini_map_size.Height) / float(m_new_rtt_mini_map->getHeight()); } else { diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index 3c2b8acaa..1d7073569 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -371,7 +371,8 @@ private: video::SColor m_fog_color; /** The texture for the mini map, which is displayed in the race gui. */ - video::ITexture *m_mini_map; + video::ITexture *m_old_rtt_mini_map; + FrameBuffer *m_new_rtt_mini_map; core::dimension2du m_mini_map_size; float m_minimap_x_scale; float m_minimap_y_scale; @@ -448,7 +449,8 @@ public: std::vector< std::vector > buildHeightMap(); // ------------------------------------------------------------------------ /** Returns the texture with the mini map for this track. */ - const video::ITexture* getMiniMap () const { return m_mini_map; } + const video::ITexture* getOldRttMiniMap() const { return m_old_rtt_mini_map; } + const FrameBuffer* getNewRttMiniMap() const { return m_new_rtt_mini_map; } // ------------------------------------------------------------------------ const core::dimension2du& getMiniMapSize() const { return m_mini_map_size; } // ------------------------------------------------------------------------ From 79727500c0b321f39315f2c00ba924709b73aaba Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Sat, 17 May 2014 16:54:43 +0200 Subject: [PATCH 024/121] Script to run batch profile tests --- test.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 test.sh diff --git a/test.sh b/test.sh new file mode 100755 index 000000000..4ad0b8333 --- /dev/null +++ b/test.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +#TODO test multiple tracks +#TODO fix escape characters + +mkdir -p ../batch + +for run in {1..50}; do + for num in {1..4}; do + for laps in {2..7}; do + ./cmake_build/bin/supertuxkart.app/Contents/MacOS/supertuxkart -R --mode=3 --numkarts=$num --with-profile --profile-laps=$laps --no-graphics | grep "profile" > ../batch/$run.$num.$laps.txt + done + done +done \ No newline at end of file From b94fe0fcde49405b208bab19cea9163c6e3200d7 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Sun, 18 May 2014 14:49:40 +0200 Subject: [PATCH 025/121] Profile data now saved without escape characters --- test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 4ad0b8333..83982e99d 100755 --- a/test.sh +++ b/test.sh @@ -8,7 +8,8 @@ mkdir -p ../batch for run in {1..50}; do for num in {1..4}; do for laps in {2..7}; do - ./cmake_build/bin/supertuxkart.app/Contents/MacOS/supertuxkart -R --mode=3 --numkarts=$num --with-profile --profile-laps=$laps --no-graphics | grep "profile" > ../batch/$run.$num.$laps.txt + ./cmake_build/bin/supertuxkart.app/Contents/MacOS/supertuxkart -R --mode=3 --numkarts=$num --with-profile --profile-laps=$laps --no-graphics > /dev/null + grep "profile" ~/Library/Application\ Support/SuperTuxKart/stdout.log > ../batch/$run.$num.$laps.txt done done done \ No newline at end of file From 26967a41dbc9e57591d0867b94855f9522fbf4af Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Wed, 21 May 2014 10:07:25 +0200 Subject: [PATCH 026/121] changes to progress bar to make the percentage label optional --- src/guiengine/widgets/progress_bar_widget.cpp | 8 ++++++-- src/guiengine/widgets/progress_bar_widget.hpp | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/guiengine/widgets/progress_bar_widget.cpp b/src/guiengine/widgets/progress_bar_widget.cpp index fc79403c5..10c493b2b 100644 --- a/src/guiengine/widgets/progress_bar_widget.cpp +++ b/src/guiengine/widgets/progress_bar_widget.cpp @@ -30,9 +30,10 @@ using namespace irr; // ----------------------------------------------------------------------------- -ProgressBarWidget::ProgressBarWidget() : Widget(WTYPE_PROGRESS) +ProgressBarWidget::ProgressBarWidget(bool show_label) : Widget(WTYPE_PROGRESS) { m_value = 0; + m_show_label = show_label; } // ----------------------------------------------------------------------------- @@ -52,7 +53,10 @@ void ProgressBarWidget::add() void ProgressBarWidget::setValue(int value) { m_value = value; - setLabel(std::string(StringUtils::toString(value) + "%").c_str()); + if (m_show_label) + { + setLabel(std::string(StringUtils::toString(value) + "%").c_str()); + } } // ----------------------------------------------------------------------------- diff --git a/src/guiengine/widgets/progress_bar_widget.hpp b/src/guiengine/widgets/progress_bar_widget.hpp index 06cfaadcb..7ec8c8b91 100644 --- a/src/guiengine/widgets/progress_bar_widget.hpp +++ b/src/guiengine/widgets/progress_bar_widget.hpp @@ -45,12 +45,12 @@ namespace GUIEngine /** Change the label on the widget */ void setLabel(const irr::core::stringw label); int m_value; + bool m_show_label; public: LEAK_CHECK() - - ProgressBarWidget(); + ProgressBarWidget(bool show_label = true); virtual ~ProgressBarWidget() {} /** Change the value of the widget, it must be a percent. */ From a3c751728b8d43e7862dc6070765553d73383b5b Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Wed, 21 May 2014 10:08:02 +0200 Subject: [PATCH 027/121] addition of python script to parse test output --- batch.py | 6 ++++++ test.sh | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 batch.py diff --git a/batch.py b/batch.py new file mode 100644 index 000000000..b37118bfc --- /dev/null +++ b/batch.py @@ -0,0 +1,6 @@ +from os import listdir +for file in listdir('../batch'): + f = open('../batch/'+file,'r') + for c in f.readlines(): + print(c) + diff --git a/test.sh b/test.sh index 83982e99d..e8dc1bc1a 100755 --- a/test.sh +++ b/test.sh @@ -9,7 +9,8 @@ for run in {1..50}; do for num in {1..4}; do for laps in {2..7}; do ./cmake_build/bin/supertuxkart.app/Contents/MacOS/supertuxkart -R --mode=3 --numkarts=$num --with-profile --profile-laps=$laps --no-graphics > /dev/null - grep "profile" ~/Library/Application\ Support/SuperTuxKart/stdout.log > ../batch/$run.$num.$laps.txt + grep "profile" ~/Library/Application\ Support/SuperTuxKart/stdout.log > ../batch/$run.$num.$laps.txt + python batch.py done done done \ No newline at end of file From 95bb6835aeb272460ccbc9876cc8961c02647aeb Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Fri, 23 May 2014 01:25:20 +0200 Subject: [PATCH 028/121] first work at adding kart properties widget to the kart selection screen --- src/states_screens/kart_selection.cpp | 16 ++++++++++++++-- src/states_screens/kart_selection.hpp | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index d704836a4..b44352ddc 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -232,6 +232,16 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, m_player_ident_spinner->m_w = player_name_w; m_player_ident_spinner->m_h = player_name_h; + // ---- Progressbar widget + m_kart_stat_mass = NULL; + + m_kart_stat_mass = new GUIEngine::ProgressBarWidget(false); + m_kart_stat_mass->setValue(25); + m_kart_stat_mass->m_x = player_name_x; + m_kart_stat_mass->m_y = player_name_y; + m_kart_stat_mass->m_w = player_name_w+100; + m_kart_stat_mass->m_h = player_name_h+100; + if (parent->m_multiplayer && associated_player) { if (associated_player->getDevice()->getType() == DT_KEYBOARD) @@ -272,7 +282,9 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, //m_player_ident_spinner->m_event_handler = this; m_children.push_back(m_player_ident_spinner); - + m_kart_stat_mass->m_properties[PROP_ID] = + StringUtils::insertValues("@p%i_mass", m_player_id); + m_children.push_back(m_kart_stat_mass); // ----- Kart model view @@ -473,7 +485,7 @@ void PlayerKartWidget::add() m_player_ident_spinner->add(); m_player_ident_spinner->getIrrlichtElement()->setTabStop(false); m_player_ident_spinner->setListener(this); - + m_kart_stat_mass->add(); m_model_view->add(); m_kart_name->add(); diff --git a/src/states_screens/kart_selection.hpp b/src/states_screens/kart_selection.hpp index 7e3e8fa26..586d79c16 100644 --- a/src/states_screens/kart_selection.hpp +++ b/src/states_screens/kart_selection.hpp @@ -24,6 +24,7 @@ #include "guiengine/widgets/label_widget.hpp" #include "guiengine/widgets/model_view_widget.hpp" #include "guiengine/widgets/spinner_widget.hpp" +#include "guiengine/widgets/progress_bar_widget.hpp" #include "states_screens/state_manager.hpp" #include @@ -267,6 +268,7 @@ public: /** Sub-widgets created by this widget */ PlayerNameSpinner* m_player_ident_spinner; + GUIEngine::ProgressBarWidget* m_kart_stat_mass; GUIEngine::ModelViewWidget* m_model_view; GUIEngine::LabelWidget* m_kart_name; From e47f85a32c0c3a9652c5fa7512a21865fc082170 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Sat, 24 May 2014 16:01:02 +0200 Subject: [PATCH 029/121] bit of testing with the scripts for optimal settings --- batch.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- test.sh | 24 ++++++++++++++---------- 2 files changed, 60 insertions(+), 14 deletions(-) diff --git a/batch.py b/batch.py index b37118bfc..4d58f6377 100644 --- a/batch.py +++ b/batch.py @@ -1,6 +1,48 @@ from os import listdir -for file in listdir('../batch'): - f = open('../batch/'+file,'r') - for c in f.readlines(): - print(c) + +def is_numeric(x): + try: + float(x) + except ValueError: + return False + return True +avg_lap_time = [0]*50 +avg_position = [0]*50 +avg_speed = [0]*50 +avg_top = [0]*50 +total_rescued = [0]*50 + +#for entry in ['sara','tux','elephpant','pidgin']: + +tests = len(listdir('../batch'))-1 +for file in listdir('../batch'): + if (file == '.DS_Store'): + continue + f = open('../batch/'+file,'r') + """ + name_index = file.find('.') + name = str(file[:name_index]) + first = file.find('.',name_index+1) + numkarts = int(file[name_index+1:first]) + second = file.find('.',first+1) + laps = int(file[first+1:second]) + third = file.find('.',second+1) + run = int(file[second+1:third]) + """ + mass = int(file[:file.find('.')]) + contents = f.readlines() + contents = contents[2:contents.index("[debug ] profile: \n")-1] + content = [s for s in contents if "sara" in s] + data = [float(x) for x in content[0].split() if is_numeric(x)] + avg_lap_time[(mass-50)/10] += (data[2]/2)/5 + avg_position[(mass-50)/10] += data[1]/5 + avg_speed[(mass-50)/10] += data[3]/5 + avg_top[(mass-50)/10] += data[4]/5 + total_rescued[((mass-50)/10)] += data[7] +print("total rescue") +for i in range(len(avg_lap_time)): + print(i*10+50, total_rescued[i]) + + + """avg_lap_time[i], avg_position[i], avg_speed[i], avg_top[i],""" diff --git a/test.sh b/test.sh index e8dc1bc1a..e39cd5935 100755 --- a/test.sh +++ b/test.sh @@ -1,16 +1,20 @@ #!/bin/bash -#TODO test multiple tracks -#TODO fix escape characters - mkdir -p ../batch +count=1 -for run in {1..50}; do - for num in {1..4}; do - for laps in {2..7}; do - ./cmake_build/bin/supertuxkart.app/Contents/MacOS/supertuxkart -R --mode=3 --numkarts=$num --with-profile --profile-laps=$laps --no-graphics > /dev/null - grep "profile" ~/Library/Application\ Support/SuperTuxKart/stdout.log > ../batch/$run.$num.$laps.txt - python batch.py - done +#for numkarts in 4; do +# for laps in 4 10; do +for ((mass = 50; mass <= 500; mass=$mass+10)) do + sed -i -e "s/mass\ value\ =\ \"[0-9]*/mass\ value\ =\ \"$mass/g" ../stk-assets/karts/sara/kart.xml + for run in {1..10}; do + echo $count/450 + ./cmake_build/bin/supertuxkart.app/Contents/MacOS/supertuxkart -R --mode=3 --numkarts=1 --with-profile --profile-laps=3 --kart=sara --ai=beastie,beastie,beastie --no-graphics > /dev/null + grep "profile" ~/Library/Application\ Support/SuperTuxKart/stdout.log > ../batch/$mass.$run.txt + let "count = $count + 1" done +done + +for track in "cave" "city" "scotland" "jungle" "lighthouse" "hacienda" "fortmagma"; do + ./cmake_build/bin/supertuxkart.app/Contents/MacOS/supertuxkart -R --mode=3 --track=$track --with-profile --profile-laps=1 > /dev/null done \ No newline at end of file From 7ac7955808c53d1d87a5db644aa94a2504ea5438 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Sat, 24 May 2014 16:04:23 +0200 Subject: [PATCH 030/121] First work on GUI support for different properties --- src/guiengine/widgets/kart_stats_widget.cpp | 223 ++++++++++++++++++++ src/guiengine/widgets/kart_stats_widget.hpp | 102 +++++++++ src/guiengine/widgets/model_view_widget.cpp | 104 ++++----- src/states_screens/kart_selection.cpp | 40 ++-- src/states_screens/kart_selection.hpp | 3 + 5 files changed, 408 insertions(+), 64 deletions(-) create mode 100644 src/guiengine/widgets/kart_stats_widget.cpp create mode 100644 src/guiengine/widgets/kart_stats_widget.hpp diff --git a/src/guiengine/widgets/kart_stats_widget.cpp b/src/guiengine/widgets/kart_stats_widget.cpp new file mode 100644 index 000000000..53cc9ff6a --- /dev/null +++ b/src/guiengine/widgets/kart_stats_widget.cpp @@ -0,0 +1,223 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2009-2013 Marianne Gagnon +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// 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 "guiengine/widgets/kart_stats_widget.hpp" +#include "utils/string_utils.hpp" +#include +#include "karts/kart_properties.hpp" +#include "karts/kart_properties_manager.hpp" + +#include "utils/log.hpp" +#include "utils/string_utils.hpp" + +#include "config/user_config.hpp" + +#include +#include +#include + +using namespace GUIEngine; +using namespace irr::core; +using namespace irr; + +// ----------------------------------------------------------------------------- + +KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, + std::string kart_group) : Widget(WTYPE_DIV) +{ + m_player_id = player_id; + + setSize(area.UpperLeftCorner.X, area.UpperLeftCorner.Y, + area.getWidth(), area.getHeight() ); + + // ---- Mass skill level widget + m_mass_bar = NULL; + + m_mass_bar = new ProgressBarWidget(false); + m_mass_bar->m_x = m_mass_bar_x; + m_mass_bar->m_y = m_mass_bar_y; + m_mass_bar->m_w = m_mass_bar_w; + m_mass_bar->m_h = m_mass_bar_h; + m_mass_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); + + const std::string default_kart = UserConfigParams::m_default_kart; + const KartProperties* props = + kart_properties_manager->getKart(default_kart); + m_mass_bar->setValue((int)props->getMass()/10); + Log::verbose("Value", StringUtils::toString(m_mass_bar->getValue()).c_str()); + m_children.push_back(m_mass_bar); + if(!props) + { + // If the default kart can't be found (e.g. previously a addon + // kart was used, but the addon package was removed), use the + // first kart as a default. This way we don't have to hardcode + // any kart names. + int id = kart_properties_manager->getKartByGroup(kart_group, 0); + if (id == -1) + { + props = kart_properties_manager->getKartById(0); + } + else + { + props = kart_properties_manager->getKartById(id); + } + + if(!props) + { + fprintf(stderr, + "[KartSelectionScreen] WARNING: Can't find default " + "kart '%s' nor any other kart.\n", + default_kart.c_str()); + exit(-1); + } + } +} // KartStatsWidget + +// ----------------------------------------------------------------------------- + +void KartStatsWidget::add() +{ + Log::verbose("Widget", "ADD"); + //TODO add others, and add them properly + m_mass_bar->add(); +} + +// ----------------------------------------------------------------------------- + +/** Updates the animation (moving/shrinking/etc.) */ +void KartStatsWidget::onUpdate(float delta) +{ + assert(m_magic_number == 0x33445566); + if (target_x == m_x && target_y == m_y && + target_w == m_w && target_h == m_h) return; + + int move_step = (int)(delta*1000.0f); + + // move x towards target + if (m_x < target_x) + { + m_x += (int)(move_step*x_speed); + // don't move to the other side of the target + if (m_x > target_x) m_x = target_x; + } + else if (m_x > target_x) + { + m_x -= (int)(move_step*x_speed); + // don't move to the other side of the target + if (m_x < target_x) m_x = target_x; + } + + // move y towards target + if (m_y < target_y) + { + m_y += (int)(move_step*y_speed); + // don't move to the other side of the target + if (m_y > target_y) m_y = target_y; + } + else if (m_y > target_y) + { + m_y -= (int)(move_step*y_speed); + // don't move to the other side of the target + if (m_y < target_y) m_y = target_y; + } + + // move w towards target + if (m_w < target_w) + { + m_w += (int)(move_step*w_speed); + // don't move to the other side of the target + if (m_w > target_w) m_w = target_w; + } + else if (m_w > target_w) + { + m_w -= (int)(move_step*w_speed); + // don't move to the other side of the target + if (m_w < target_w) m_w = target_w; + } + // move h towards target + if (m_h < target_h) + { + m_h += (int)(move_step*h_speed); + // don't move to the other side of the target + if (m_h > target_h) m_h = target_h; + } + else if (m_h > target_h) + { + m_h -= (int)(move_step*h_speed); + // don't move to the other side of the target + if (m_h < target_h) m_h = target_h; + } + + setSize(m_x, m_y, m_w, m_h); + + if (m_mass_bar != NULL) + { + m_mass_bar->move(m_mass_bar_x, + m_mass_bar_y, + m_mass_bar_w, + m_mass_bar_h ); + } +} // onUpdate + +// ------------------------------------------------------------------------- + +void KartStatsWidget::setSize(const int x, const int y, const int w, const int h) +{ + assert(m_magic_number == 0x33445566); + m_x = x; + m_y = y; + m_w = w; + m_h = h; + + // -- sizes + m_mass_bar_w = 2*w/3; + m_mass_bar_h = 100; + + // for shrinking effect + if (h < 175) + { + const float factor = h / 175.0f; + m_mass_bar_h = (int)(m_mass_bar_h*factor); + } + + m_mass_bar_x = x + w/2 - m_mass_bar_w; + m_mass_bar_y = y + h/2 - m_mass_bar_h; +} // setSize + +// ----------------------------------------------------------------------------- + +void KartStatsWidget::setMass(int value) +{ + m_mass_value = value; +} + +// ----------------------------------------------------------------------------- + +void KartStatsWidget::setAcceleration(int value) +{ + m_accel_value = value; +} + +// ----------------------------------------------------------------------------- + +void KartStatsWidget::setSpeed(int value) +{ + m_speed_value = value; +} +// ----------------------------------------------------------------------------- + diff --git a/src/guiengine/widgets/kart_stats_widget.hpp b/src/guiengine/widgets/kart_stats_widget.hpp new file mode 100644 index 000000000..9ce5941c5 --- /dev/null +++ b/src/guiengine/widgets/kart_stats_widget.hpp @@ -0,0 +1,102 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2009-2013 Marianne Gagnon +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + + +#ifndef HEADER_KART_STATS_HPP +#define HEADER_KART_STATS_HPP + +#include + +#include "guiengine/widget.hpp" +#include "utils/leak_check.hpp" +#include "utils/ptr_vector.hpp" + +#include "guiengine/widgets/label_widget.hpp" +#include "guiengine/widgets/progress_bar_widget.hpp" + + +namespace GUIEngine +{ + /** + * \brief A progress bar widget. + * \ingroup widgetsgroup + */ + +class KartStatsWidget : public Widget + { + /** When inferring widget size from its label length, this method will be called to + * if/how much space must be added to the raw label's size for the widget to be large enough */ + virtual int getWidthNeededAroundLabel() const { return 35; } + + /** When inferring widget size from its label length, this method will be called to + * if/how much space must be added to the raw label's size for the widget to be large enough */ + virtual int getHeightNeededAroundLabel() const { return 4; } + + /** widget coordinates */ + int m_mass_bar_x, m_mass_bar_y, m_mass_bar_h, m_mass_bar_w; + + /** For animation purposes (see method 'move') */ + int target_x, target_y, target_w, target_h; + float x_speed, y_speed, w_speed, h_speed; + + int m_mass_value; + int m_accel_value; + int m_speed_value; + + int m_player_id; + + public: + + LEAK_CHECK() + + LabelWidget* m_mass_label; + ProgressBarWidget* m_mass_bar; + + KartStatsWidget(core::recti area, const int player_id, + std::string kart_group); + virtual ~KartStatsWidget() {}; + + // ------------------------------------------------------------------------ + /** Add the widgets to the current screen */ + virtual void add(); + + // ------------------------------------------------------------------------- + /** Updates the animation (moving/shrinking/etc.) */ + void onUpdate(float delta); + + // ------------------------------------------------------------------------- + /** Event callback */ + + // ------------------------------------------------------------------------- + /** Sets the size of the widget as a whole, and placed children widgets + * inside itself */ + void setSize(const int x, const int y, const int w, const int h); + + /** Change the value of the widget, it must be a percent. */ + void setMass(int value); + void setAcceleration(int value); + void setSpeed(int value); + + /** Get the current values of the widget. */ + int getMass() {return m_mass_value; }; + int getAcceleration() {return m_accel_value; }; + int getSpeed() {return m_speed_value; }; + }; +} + +#endif diff --git a/src/guiengine/widgets/model_view_widget.cpp b/src/guiengine/widgets/model_view_widget.cpp index a89ad3b5c..60349965c 100644 --- a/src/guiengine/widgets/model_view_widget.cpp +++ b/src/guiengine/widgets/model_view_widget.cpp @@ -33,7 +33,7 @@ using namespace irr::core; using namespace irr::gui; ModelViewWidget::ModelViewWidget() : - IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, false, false) +IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, false, false) { m_frame_buffer = NULL; m_rtt_main_node = NULL; @@ -42,17 +42,17 @@ ModelViewWidget::ModelViewWidget() : m_type = WTYPE_MODEL_VIEW; m_rtt_provider = NULL; m_rotation_mode = ROTATE_OFF; - + // so that the base class doesn't complain there is no icon defined m_properties[PROP_ICON]="gui/main_help.png"; - + m_rtt_unsupported = false; } // ----------------------------------------------------------------------------- ModelViewWidget::~ModelViewWidget() { GUIEngine::needsUpdate.remove(this); - + delete m_rtt_provider; m_rtt_provider = NULL; } @@ -61,18 +61,18 @@ void ModelViewWidget::add() { // so that the base class doesn't complain there is no icon defined m_properties[PROP_ICON]="gui/main_help.png"; - + IconButtonWidget::add(); - + /* FIXME: remove this unclean thing, I think irrlicht provides this feature: - virtual void IGUIElement::OnPostRender (u32 timeMs) - \brief animate the element and its children. + virtual void IGUIElement::OnPostRender (u32 timeMs) + \brief animate the element and its children. */ GUIEngine::needsUpdate.push_back(this); - + angle = 0; - + } // add // ----------------------------------------------------------------------------- @@ -82,11 +82,11 @@ void ModelViewWidget::clearModels() m_model_location.clear(); m_model_scale.clear(); m_model_frames.clear(); - + if (m_rtt_main_node != NULL) m_rtt_main_node->remove(); if (m_light != NULL) m_light->remove(); if (m_camera != NULL) m_camera->remove(); - + m_rtt_main_node = NULL; m_camera = NULL; m_light = NULL; @@ -98,7 +98,7 @@ void ModelViewWidget::addModel(irr::scene::IMesh* mesh, const Vec3& location, const Vec3& scale, const int frame) { if(!mesh) return; - + m_models.push_back(mesh); m_model_location.push_back(location); m_model_scale.push_back(scale); @@ -109,7 +109,7 @@ void ModelViewWidget::addModel(irr::scene::IMesh* mesh, const Vec3& location, void ModelViewWidget::update(float delta) { if (m_rtt_unsupported) return; - + if (m_rotation_mode == ROTATE_CONTINUOUSLY) { angle += delta*m_rotation_speed; @@ -121,10 +121,10 @@ void ModelViewWidget::update(float delta) // (taking wrap-arounds into account) const int angle_distance_from_end = (int)(360 - angle); const int target_distance_from_end = (int)(360 - angle); - + int distance_with_positive_rotation; int distance_with_negative_rotation; - + if (angle < m_rotation_target) { distance_with_positive_rotation = (int)(m_rotation_target - angle); @@ -135,10 +135,10 @@ void ModelViewWidget::update(float delta) distance_with_positive_rotation = (int)(angle_distance_from_end + m_rotation_target); distance_with_negative_rotation = (int)(angle - m_rotation_target); } - + //std::cout << "distance_with_positive_rotation=" << distance_with_positive_rotation << //" distance_with_negative_rotation=" << distance_with_negative_rotation << " angle="<< angle < 360) angle -= 360; if (angle < 0) angle += 360; - + // stop rotating when target reached if (fabsf(angle - m_rotation_target) < 2.0f) m_rotation_mode = ROTATE_OFF; } - + if (!irr_driver->isGLSL()) return; - + if (m_rtt_provider == NULL) { std::string name = "model view "; name += m_properties[PROP_ID].c_str(); - + m_rtt_provider = new RTT(512, 512); } - + if (m_rtt_main_node == NULL) { setupRTTScene(m_models, m_model_location, m_model_scale, m_model_frames); } - + m_rtt_main_node->setRotation(core::vector3df(0.0f, angle, 0.0f)); m_rtt_main_node->setVisible(true); irr_driver->setRTT(m_rtt_provider); - + irr_driver->getSceneManager()->setActiveCamera(m_camera); - + std::vector glows; irr_driver->computeCameraMatrix(m_camera, 512, 512); unsigned plc = irr_driver->UpdateLightsInfo(m_camera, GUIEngine::getLatestDt()); irr_driver->renderScene(m_camera, plc, glows, GUIEngine::getLatestDt(), false, true); m_frame_buffer = irr_driver->getPostProcessing()->render(m_camera); glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height); - + irr_driver->setRTT(NULL); glBindFramebuffer(GL_FRAMEBUFFER, 0); - + irr_driver->getSceneManager()->setActiveCamera(NULL); m_rtt_main_node->setVisible(false); } void ModelViewWidget::setupRTTScene(PtrVector& mesh, - AlignedArray& mesh_location, - AlignedArray& mesh_scale, - const std::vector& model_frames) + AlignedArray& mesh_location, + AlignedArray& mesh_scale, + const std::vector& model_frames) { irr_driver->suppressSkyBox(); - + if (m_rtt_main_node != NULL) m_rtt_main_node->remove(); if (m_light != NULL) m_light->remove(); if (m_camera != NULL) m_camera->remove(); - + m_rtt_main_node = NULL; m_camera = NULL; m_light = NULL; - + irr_driver->clearLights(); - + if (model_frames[0] == -1) { scene::ISceneNode* node = irr_driver->addMesh(mesh.get(0), NULL); @@ -219,27 +219,27 @@ void ModelViewWidget::setupRTTScene(PtrVector& mesh, else { scene::IAnimatedMeshSceneNode* node = - irr_driver->addAnimatedMesh((scene::IAnimatedMesh*)mesh.get(0), NULL); + irr_driver->addAnimatedMesh((scene::IAnimatedMesh*)mesh.get(0), NULL); node->setPosition(mesh_location[0].toIrrVector()); node->setFrameLoop(model_frames[0], model_frames[0]); node->setAnimationSpeed(0); node->setScale(mesh_scale[0].toIrrVector()); node->setMaterialFlag(video::EMF_FOG_ENABLE, false); - + m_rtt_main_node = node; } - + assert(m_rtt_main_node != NULL); assert(mesh.size() == mesh_location.size()); assert(mesh.size() == model_frames.size()); - + const int mesh_amount = mesh.size(); for (int n = 1; naddMesh(mesh.get(n), m_rtt_main_node); + irr_driver->addMesh(mesh.get(n), m_rtt_main_node); node->setPosition(mesh_location[n].toIrrVector()); node->updateAbsolutePosition(); node->setScale(mesh_scale[n].toIrrVector()); @@ -247,8 +247,8 @@ void ModelViewWidget::setupRTTScene(PtrVector& mesh, else { scene::IAnimatedMeshSceneNode* node = - irr_driver->addAnimatedMesh((scene::IAnimatedMesh*)mesh.get(n), - m_rtt_main_node); + irr_driver->addAnimatedMesh((scene::IAnimatedMesh*)mesh.get(n), + m_rtt_main_node); node->setPosition(mesh_location[n].toIrrVector()); node->setFrameLoop(model_frames[n], model_frames[n]); node->setAnimationSpeed(0); @@ -257,32 +257,32 @@ void ModelViewWidget::setupRTTScene(PtrVector& mesh, //std::cout << "(((( set frame " << model_frames[n] << " ))))\n"; } } - + irr_driver->getSceneManager()->setAmbientLight(video::SColor(255, 35, 35, 35)); - + const core::vector3df &spot_pos = core::vector3df(0, 30, 40); m_light = irr_driver->addLight(spot_pos, 0.3f /* energy */, 10 /* distance */, 1.0f /* r */, 1.0f /* g */, 1.0f /* g*/, true, NULL); - + m_rtt_main_node->setMaterialFlag(video::EMF_GOURAUD_SHADING, true); m_rtt_main_node->setMaterialFlag(video::EMF_LIGHTING, true); - + const int materials = m_rtt_main_node->getMaterialCount(); for (int n = 0; ngetMaterial(n).setFlag(video::EMF_LIGHTING, true); - + // set size of specular highlights m_rtt_main_node->getMaterial(n).Shininess = 100.0f; m_rtt_main_node->getMaterial(n).SpecularColor.set(255, 50, 50, 50); m_rtt_main_node->getMaterial(n).DiffuseColor.set(255, 150, 150, 150); - + m_rtt_main_node->getMaterial(n).setFlag(video::EMF_GOURAUD_SHADING, - true); + true); } - + m_camera = irr_driver->getSceneManager()->addCameraSceneNode(); m_camera->setAspectRatio(1.0f); - + m_camera->setPosition(core::vector3df(0.0, 20.0f, 70.0f)); if (irr_driver->isGLSL()) m_camera->setUpVector(core::vector3df(0.0, 1.0, 0.0)); @@ -325,4 +325,4 @@ void ModelViewWidget::clearRttProvider() { delete m_rtt_provider; m_rtt_provider = NULL; -} +} \ No newline at end of file diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index b44352ddc..fadf8b628 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -232,15 +232,18 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, m_player_ident_spinner->m_w = player_name_w; m_player_ident_spinner->m_h = player_name_h; - // ---- Progressbar widget - m_kart_stat_mass = NULL; + // ---- KartStatsWidget + m_kart_stats = NULL; + + // area for the stats widget + core::recti statsArea(m_kart_stats_x, + m_kart_stats_y, + m_kart_stats_w, + m_kart_stats_h); + + //m_kart_stats = new ProgressBarWidget(false); + m_kart_stats = new GUIEngine::KartStatsWidget(statsArea, player_id, kart_group); - m_kart_stat_mass = new GUIEngine::ProgressBarWidget(false); - m_kart_stat_mass->setValue(25); - m_kart_stat_mass->m_x = player_name_x; - m_kart_stat_mass->m_y = player_name_y; - m_kart_stat_mass->m_w = player_name_w+100; - m_kart_stat_mass->m_h = player_name_h+100; if (parent->m_multiplayer && associated_player) { @@ -282,9 +285,9 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, //m_player_ident_spinner->m_event_handler = this; m_children.push_back(m_player_ident_spinner); - m_kart_stat_mass->m_properties[PROP_ID] = + m_kart_stats->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); - m_children.push_back(m_kart_stat_mass); + m_children.push_back(m_kart_stats); // ----- Kart model view @@ -485,7 +488,7 @@ void PlayerKartWidget::add() m_player_ident_spinner->add(); m_player_ident_spinner->getIrrlichtElement()->setTabStop(false); m_player_ident_spinner->setListener(this); - m_kart_stat_mass->add(); + m_kart_stats->add(); m_model_view->add(); m_kart_name->add(); @@ -673,11 +676,18 @@ void PlayerKartWidget::onUpdate(float delta) core::recti(core::position2di(player_name_x, player_name_y), core::dimension2di(player_name_w, player_name_h)) ); } + m_kart_stats->move(m_kart_stats_x, + m_kart_stats_y, + m_kart_stats_w, + m_kart_stats_h); + m_kart_stats->onUpdate(delta); + m_model_view->move(model_x, model_y, model_w, model_h); + m_kart_name->move(kart_name_x, kart_name_y, kart_name_w, @@ -754,6 +764,9 @@ void PlayerKartWidget::setSize(const int x, const int y, const int w, const int kart_name_w = w; kart_name_h = 25; + m_kart_stats_w = 300; + m_kart_stats_h = GUIEngine::getFontHeight(); + // for shrinking effect if (h < 175) { @@ -761,6 +774,7 @@ void PlayerKartWidget::setSize(const int x, const int y, const int w, const int kart_name_h = (int)(kart_name_h*factor); player_name_h = (int)(player_name_h*factor); player_id_h = (int)(player_id_h*factor); + m_kart_stats_h = (int)(m_kart_stats_h*factor); } // --- layout @@ -775,13 +789,15 @@ void PlayerKartWidget::setSize(const int x, const int y, const int w, const int const int modelMaxWidth = w; const int bestSize = std::min(modelMaxWidth, modelMaxHeight); const int modelY = y + player_name_h + player_id_h; - model_x = x + w/2 - (int)(bestSize/2); + model_x = x + w/4 - (int)(bestSize/2); model_y = modelY + modelMaxHeight/2 - bestSize/2; model_w = (int)(bestSize); model_h = bestSize; kart_name_x = x; kart_name_y = y + h - kart_name_h; + m_kart_stats_x = x + 3*w/4 - m_kart_stats_w/2; + m_kart_stats_y = y + h/2 - m_kart_stats_h/2; } // setSize // ------------------------------------------------------------------------- diff --git a/src/states_screens/kart_selection.hpp b/src/states_screens/kart_selection.hpp index 586d79c16..3019dc64f 100644 --- a/src/states_screens/kart_selection.hpp +++ b/src/states_screens/kart_selection.hpp @@ -26,6 +26,7 @@ #include "guiengine/widgets/spinner_widget.hpp" #include "guiengine/widgets/progress_bar_widget.hpp" #include "states_screens/state_manager.hpp" +#include "guiengine/widgets/kart_stats_widget.hpp" #include @@ -237,6 +238,7 @@ class PlayerKartWidget : public GUIEngine::Widget, int player_name_x, player_name_y, player_name_w, player_name_h; int model_x, model_y, model_w, model_h; int kart_name_x, kart_name_y, kart_name_w, kart_name_h; + int m_kart_stats_x, m_kart_stats_y, m_kart_stats_w, m_kart_stats_h; /** A reserved ID for this widget if any, -1 otherwise. (If no ID is * reserved, widget will not be in the regular tabbing order */ @@ -269,6 +271,7 @@ public: /** Sub-widgets created by this widget */ PlayerNameSpinner* m_player_ident_spinner; GUIEngine::ProgressBarWidget* m_kart_stat_mass; + GUIEngine::KartStatsWidget* m_kart_stats; GUIEngine::ModelViewWidget* m_model_view; GUIEngine::LabelWidget* m_kart_name; From d5d2ef991a9982878ada6477174a4f6cd232d652 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Wed, 28 May 2014 17:21:33 +0200 Subject: [PATCH 031/121] Fix for sometimes disappearing skill bar --- src/guiengine/widgets/kart_stats_widget.cpp | 13 +++++++++++-- src/states_screens/kart_selection.cpp | 18 +++++++++++++++--- src/states_screens/kart_selection.hpp | 5 +++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/guiengine/widgets/kart_stats_widget.cpp b/src/guiengine/widgets/kart_stats_widget.cpp index 53cc9ff6a..709fb38bb 100644 --- a/src/guiengine/widgets/kart_stats_widget.cpp +++ b/src/guiengine/widgets/kart_stats_widget.cpp @@ -40,10 +40,20 @@ using namespace irr; KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, std::string kart_group) : Widget(WTYPE_DIV) { + + x_speed = 1.0f; + y_speed = 1.0f; + w_speed = 1.0f; + h_speed = 1.0f; + m_player_id = player_id; setSize(area.UpperLeftCorner.X, area.UpperLeftCorner.Y, area.getWidth(), area.getHeight() ); + target_x = m_x; + target_y = m_y; + target_w = m_w; + target_h = m_h; // ---- Mass skill level widget m_mass_bar = NULL; @@ -102,7 +112,7 @@ void KartStatsWidget::add() /** Updates the animation (moving/shrinking/etc.) */ void KartStatsWidget::onUpdate(float delta) { - assert(m_magic_number == 0x33445566); + m_mass_bar->setValue(m_mass_value); if (target_x == m_x && target_y == m_y && target_w == m_w && target_h == m_h) return; @@ -178,7 +188,6 @@ void KartStatsWidget::onUpdate(float delta) void KartStatsWidget::setSize(const int x, const int y, const int w, const int h) { - assert(m_magic_number == 0x33445566); m_x = x; m_y = y; m_w = w; diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index fadf8b628..f28543200 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -238,8 +238,8 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, // area for the stats widget core::recti statsArea(m_kart_stats_x, m_kart_stats_y, - m_kart_stats_w, - m_kart_stats_h); + m_kart_stats_x+m_kart_stats_w, + m_kart_stats_y+m_kart_stats_h); //m_kart_stats = new ProgressBarWidget(false); m_kart_stats = new GUIEngine::KartStatsWidget(statsArea, player_id, kart_group); @@ -802,6 +802,18 @@ void PlayerKartWidget::setSize(const int x, const int y, const int w, const int // ------------------------------------------------------------------------- +void PlayerKartWidget::setKartStats(const std::string& selection) +{ + assert(m_magic_number == 0x33445566); + const KartProperties *kp = + kart_properties_manager->getKart(selection); + if (kp != NULL) + { + m_kart_stats->setMass((int)kp->getMass()/10); + //TODO add other stats + } +} + /** Sets which kart was selected for this player */ void PlayerKartWidget::setKartInternalName(const std::string& whichKart) { @@ -879,7 +891,7 @@ void KartHoverListener::onSelectionChanged(DynamicRibbonWidget* theWidget, } m_parent->updateKartWidgetModel(playerID, selectionID, selectionText); - + m_parent->m_kart_widgets[playerID].setKartStats(selectionID); m_parent->m_kart_widgets[playerID].setKartInternalName(selectionID); m_parent->validateKartChoices(); } // onSelectionChanged diff --git a/src/states_screens/kart_selection.hpp b/src/states_screens/kart_selection.hpp index 3019dc64f..4017cf789 100644 --- a/src/states_screens/kart_selection.hpp +++ b/src/states_screens/kart_selection.hpp @@ -342,6 +342,11 @@ public: // ------------------------------------------------------------------------- + /** Set the kart stats for this player */ + void setKartStats(const std::string& selection); + + // ------------------------------------------------------------------------- + /** Sets which kart was selected for this player */ void setKartInternalName(const std::string& whichKart); From e7852648fac232b5cee06f11095ee5bd57d1f333 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Thu, 29 May 2014 13:27:56 +0200 Subject: [PATCH 032/121] Changes to the Skill Level Widget, only bar refuses to show --- src/guiengine/widgets/kart_stats_widget.cpp | 119 +++------------ src/guiengine/widgets/kart_stats_widget.hpp | 11 +- src/guiengine/widgets/skill_level_widget.cpp | 148 +++++++++++++++++++ src/guiengine/widgets/skill_level_widget.hpp | 92 ++++++++++++ src/states_screens/kart_selection.cpp | 21 +-- 5 files changed, 275 insertions(+), 116 deletions(-) create mode 100644 src/guiengine/widgets/skill_level_widget.cpp create mode 100644 src/guiengine/widgets/skill_level_widget.hpp diff --git a/src/guiengine/widgets/kart_stats_widget.cpp b/src/guiengine/widgets/kart_stats_widget.cpp index 709fb38bb..f3d3d82cd 100644 --- a/src/guiengine/widgets/kart_stats_widget.cpp +++ b/src/guiengine/widgets/kart_stats_widget.cpp @@ -40,37 +40,14 @@ using namespace irr; KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, std::string kart_group) : Widget(WTYPE_DIV) { - - x_speed = 1.0f; - y_speed = 1.0f; - w_speed = 1.0f; - h_speed = 1.0f; - m_player_id = player_id; setSize(area.UpperLeftCorner.X, area.UpperLeftCorner.Y, area.getWidth(), area.getHeight() ); - target_x = m_x; - target_y = m_y; - target_w = m_w; - target_h = m_h; - - // ---- Mass skill level widget - m_mass_bar = NULL; - - m_mass_bar = new ProgressBarWidget(false); - m_mass_bar->m_x = m_mass_bar_x; - m_mass_bar->m_y = m_mass_bar_y; - m_mass_bar->m_w = m_mass_bar_w; - m_mass_bar->m_h = m_mass_bar_h; - m_mass_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); const std::string default_kart = UserConfigParams::m_default_kart; const KartProperties* props = kart_properties_manager->getKart(default_kart); - m_mass_bar->setValue((int)props->getMass()/10); - Log::verbose("Value", StringUtils::toString(m_mass_bar->getValue()).c_str()); - m_children.push_back(m_mass_bar); if(!props) { // If the default kart can't be found (e.g. previously a addon @@ -96,83 +73,30 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, exit(-1); } } + + irr::core::recti massArea(m_mass_bar_x, m_mass_bar_y, + m_mass_bar_x + m_mass_bar_w, + m_mass_bar_y + m_mass_bar_h); + + // ---- Mass skill level widget + m_mass_bar = NULL; + + m_mass_bar = new SkillLevelWidget(massArea, m_player_id, (int) props->getMass()/10, "Weight"); + m_mass_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); + + } // KartStatsWidget // ----------------------------------------------------------------------------- void KartStatsWidget::add() { - Log::verbose("Widget", "ADD"); - //TODO add others, and add them properly m_mass_bar->add(); } -// ----------------------------------------------------------------------------- - -/** Updates the animation (moving/shrinking/etc.) */ -void KartStatsWidget::onUpdate(float delta) +void KartStatsWidget::move(int x, int y, int w, int h) { - m_mass_bar->setValue(m_mass_value); - if (target_x == m_x && target_y == m_y && - target_w == m_w && target_h == m_h) return; - - int move_step = (int)(delta*1000.0f); - - // move x towards target - if (m_x < target_x) - { - m_x += (int)(move_step*x_speed); - // don't move to the other side of the target - if (m_x > target_x) m_x = target_x; - } - else if (m_x > target_x) - { - m_x -= (int)(move_step*x_speed); - // don't move to the other side of the target - if (m_x < target_x) m_x = target_x; - } - - // move y towards target - if (m_y < target_y) - { - m_y += (int)(move_step*y_speed); - // don't move to the other side of the target - if (m_y > target_y) m_y = target_y; - } - else if (m_y > target_y) - { - m_y -= (int)(move_step*y_speed); - // don't move to the other side of the target - if (m_y < target_y) m_y = target_y; - } - - // move w towards target - if (m_w < target_w) - { - m_w += (int)(move_step*w_speed); - // don't move to the other side of the target - if (m_w > target_w) m_w = target_w; - } - else if (m_w > target_w) - { - m_w -= (int)(move_step*w_speed); - // don't move to the other side of the target - if (m_w < target_w) m_w = target_w; - } - // move h towards target - if (m_h < target_h) - { - m_h += (int)(move_step*h_speed); - // don't move to the other side of the target - if (m_h > target_h) m_h = target_h; - } - else if (m_h > target_h) - { - m_h -= (int)(move_step*h_speed); - // don't move to the other side of the target - if (m_h < target_h) m_h = target_h; - } - + Widget::move(x,y,w,h); setSize(m_x, m_y, m_w, m_h); if (m_mass_bar != NULL) @@ -180,11 +104,12 @@ void KartStatsWidget::onUpdate(float delta) m_mass_bar->move(m_mass_bar_x, m_mass_bar_y, m_mass_bar_w, - m_mass_bar_h ); + m_mass_bar_h); } -} // onUpdate -// ------------------------------------------------------------------------- +} + +// ----------------------------------------------------------------------------- void KartStatsWidget::setSize(const int x, const int y, const int w, const int h) { @@ -194,7 +119,7 @@ void KartStatsWidget::setSize(const int x, const int y, const int w, const int h m_h = h; // -- sizes - m_mass_bar_w = 2*w/3; + m_mass_bar_w = w; m_mass_bar_h = 100; // for shrinking effect @@ -204,15 +129,15 @@ void KartStatsWidget::setSize(const int x, const int y, const int w, const int h m_mass_bar_h = (int)(m_mass_bar_h*factor); } - m_mass_bar_x = x + w/2 - m_mass_bar_w; - m_mass_bar_y = y + h/2 - m_mass_bar_h; + m_mass_bar_x = x; + m_mass_bar_y = y + h/2 - m_mass_bar_h/2; } // setSize // ----------------------------------------------------------------------------- void KartStatsWidget::setMass(int value) { - m_mass_value = value; + m_mass_bar->setValue(value); } // ----------------------------------------------------------------------------- diff --git a/src/guiengine/widgets/kart_stats_widget.hpp b/src/guiengine/widgets/kart_stats_widget.hpp index 9ce5941c5..e7a0f0cfe 100644 --- a/src/guiengine/widgets/kart_stats_widget.hpp +++ b/src/guiengine/widgets/kart_stats_widget.hpp @@ -28,6 +28,7 @@ #include "guiengine/widgets/label_widget.hpp" #include "guiengine/widgets/progress_bar_widget.hpp" +#include "guiengine/widgets/skill_level_widget.hpp" namespace GUIEngine @@ -50,10 +51,6 @@ class KartStatsWidget : public Widget /** widget coordinates */ int m_mass_bar_x, m_mass_bar_y, m_mass_bar_h, m_mass_bar_w; - /** For animation purposes (see method 'move') */ - int target_x, target_y, target_w, target_h; - float x_speed, y_speed, w_speed, h_speed; - int m_mass_value; int m_accel_value; int m_speed_value; @@ -64,8 +61,7 @@ class KartStatsWidget : public Widget LEAK_CHECK() - LabelWidget* m_mass_label; - ProgressBarWidget* m_mass_bar; + SkillLevelWidget* m_mass_bar; KartStatsWidget(core::recti area, const int player_id, std::string kart_group); @@ -75,6 +71,9 @@ class KartStatsWidget : public Widget /** Add the widgets to the current screen */ virtual void add(); + /** Move the widget and its children */ + virtual void move(int x, int y, int w, int h); + // ------------------------------------------------------------------------- /** Updates the animation (moving/shrinking/etc.) */ void onUpdate(float delta); diff --git a/src/guiengine/widgets/skill_level_widget.cpp b/src/guiengine/widgets/skill_level_widget.cpp new file mode 100644 index 000000000..edb0ccbe3 --- /dev/null +++ b/src/guiengine/widgets/skill_level_widget.cpp @@ -0,0 +1,148 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2009-2013 Marianne Gagnon +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// 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 "guiengine/widgets/skill_level_widget.hpp" +#include "utils/string_utils.hpp" +#include +#include "karts/kart_properties.hpp" +#include "karts/kart_properties_manager.hpp" + +#include "utils/log.hpp" +#include "utils/string_utils.hpp" + +#include "config/user_config.hpp" + +#include +#include +#include + +using namespace GUIEngine; +using namespace irr::core; +using namespace irr; + +// ----------------------------------------------------------------------------- + +SkillLevelWidget::SkillLevelWidget(core::recti area, const int player_id, + const int value, const stringw& label) : Widget(WTYPE_DIV) +{ + m_show_bounding_box = true; + m_bar_value = value; + m_player_id = player_id; + + setSize(area.UpperLeftCorner.X, area.UpperLeftCorner.Y, + area.getWidth(), area.getHeight() ); + + // ---- Mass skill level widget + m_bar = NULL; + + m_bar = new ProgressBarWidget(false); + m_bar->setValue(value); + + m_bar->m_x = m_bar_x; + m_bar->m_y = m_bar_y; + m_bar->m_w = m_bar_w; + m_bar->m_h = m_bar_h; + m_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_skill_bar", m_player_id); + + m_label = NULL; + + m_label = new LabelWidget(true, true); + m_label->setText(label,false); + + m_label->m_x = m_label_x; + m_label->m_y = m_label_y; + m_label->m_w = m_label_w; + m_label->m_h = m_label_h; + m_label->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_skill_label", m_player_id); + + m_children.push_back(m_bar); + m_children.push_back(m_label); +} // KartStatsWidget + +// ----------------------------------------------------------------------------- + +void SkillLevelWidget::add() +{ + m_bar->add(); + m_label->add(); +} + +// ----------------------------------------------------------------------------- + + +void SkillLevelWidget::move(int x, int y, int w, int h) +{ + Widget::move(x,y,w,h); + setSize(m_x, m_y, m_w, m_h); + + if (m_bar != NULL) + { + m_bar->move(m_bar_x, + m_bar_y, + m_bar_w, + m_bar_h ); + m_bar->setValue(m_bar_value); + } + if (m_label != NULL) + { + m_label->move(m_label_x, + m_label_y, + m_label_w, + m_label_h); + } +} + +// ------------------------------------------------------------------------- + +void SkillLevelWidget::setSize(const int x, const int y, const int w, const int h) +{ + m_x = x; + m_y = y; + m_w = w; + m_h = h; + + // -- sizes + m_bar_w = w/2; + m_bar_h = h; + m_label_w = w/2; + m_label_h = h; + + // for shrinking effect + if (h < 175) + { + const float factor = h / 175.0f; + m_bar_h = (int)(m_bar_h*factor); + m_label_h = (int)(m_label_h*factor); + } + + m_bar_x = x + w/2; + m_bar_y = y; + + m_label_x = x; + m_label_y = y; +} // setSize + +// ----------------------------------------------------------------------------- + +void SkillLevelWidget::setValue(int value) +{ + m_bar_value = value; +} + +// ----------------------------------------------------------------------------- + diff --git a/src/guiengine/widgets/skill_level_widget.hpp b/src/guiengine/widgets/skill_level_widget.hpp new file mode 100644 index 000000000..84a1fd547 --- /dev/null +++ b/src/guiengine/widgets/skill_level_widget.hpp @@ -0,0 +1,92 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2009-2013 Marianne Gagnon +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + + +#ifndef HEADER_SKILL_LEVEL_HPP +#define HEADER_SKILL_LEVEL_HPP + +#include + +#include "guiengine/widget.hpp" +#include "utils/leak_check.hpp" +#include "utils/ptr_vector.hpp" + +#include "guiengine/widgets/label_widget.hpp" +#include "guiengine/widgets/progress_bar_widget.hpp" + + +namespace GUIEngine +{ + /** + * \brief A skill level widget. + * \ingroup widgetsgroup + */ + +class SkillLevelWidget : public Widget + { + /** When inferring widget size from its label length, this method will be called to + * if/how much space must be added to the raw label's size for the widget to be large enough */ + virtual int getWidthNeededAroundLabel() const { return 35; } + + /** When inferring widget size from its label length, this method will be called to + * if/how much space must be added to the raw label's size for the widget to be large enough */ + virtual int getHeightNeededAroundLabel() const { return 4; } + + /** widget coordinates */ + int m_bar_x, m_bar_y, m_bar_h, m_bar_w; + int m_label_x, m_label_y, m_label_h, m_label_w; + + int m_bar_value; + std::string m_label_name; + + int m_player_id; + + public: + + LEAK_CHECK() + + LabelWidget* m_label; + ProgressBarWidget* m_bar; + + SkillLevelWidget(core::recti area, const int player_id, + const int value, const irr::core::stringw& label); + virtual ~SkillLevelWidget() {}; + + // ------------------------------------------------------------------------ + /** Add the widgets to the current screen */ + virtual void add(); + + // ------------------------------------------------------------------------- + + virtual void move(int x, int y, int w, int h); + + // ------------------------------------------------------------------------- + + /** Sets the size of the widget as a whole, and placed children widgets + * inside itself */ + void setSize(const int x, const int y, const int w, const int h); + + /** Change the value of the widget, it must be a percent. */ + void setValue(int value); + + /** Get the current values of the widget. */ + int getValue() {return m_bar_value; }; + }; +} + +#endif diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index f28543200..a0430a0f3 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -238,10 +238,9 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, // area for the stats widget core::recti statsArea(m_kart_stats_x, m_kart_stats_y, - m_kart_stats_x+m_kart_stats_w, - m_kart_stats_y+m_kart_stats_h); + m_kart_stats_x + m_kart_stats_w, + m_kart_stats_y + m_kart_stats_h); - //m_kart_stats = new ProgressBarWidget(false); m_kart_stats = new GUIEngine::KartStatsWidget(statsArea, player_id, kart_group); @@ -286,7 +285,7 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, //m_player_ident_spinner->m_event_handler = this; m_children.push_back(m_player_ident_spinner); m_kart_stats->m_properties[PROP_ID] = - StringUtils::insertValues("@p%i_mass", m_player_id); + StringUtils::insertValues("@p%i_stats", m_player_id); m_children.push_back(m_kart_stats); @@ -362,8 +361,7 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, m_model_view->setRotateContinuously( 35.0f ); // ---- Kart name label - m_kart_name = new LabelWidget(); - m_kart_name->add(); // add the widget + m_kart_name = new LabelWidget(true, true); m_kart_name->setText(props->getName(), false); m_kart_name->m_properties[PROP_TEXT_ALIGN] = "center"; m_kart_name->m_properties[PROP_ID] = @@ -680,8 +678,6 @@ void PlayerKartWidget::onUpdate(float delta) m_kart_stats_y, m_kart_stats_w, m_kart_stats_h); - m_kart_stats->onUpdate(delta); - m_model_view->move(model_x, model_y, @@ -764,8 +760,8 @@ void PlayerKartWidget::setSize(const int x, const int y, const int w, const int kart_name_w = w; kart_name_h = 25; - m_kart_stats_w = 300; - m_kart_stats_h = GUIEngine::getFontHeight(); + m_kart_stats_w = w/2; + m_kart_stats_h = h; // for shrinking effect if (h < 175) @@ -796,8 +792,8 @@ void PlayerKartWidget::setSize(const int x, const int y, const int w, const int kart_name_x = x; kart_name_y = y + h - kart_name_h; - m_kart_stats_x = x + 3*w/4 - m_kart_stats_w/2; - m_kart_stats_y = y + h/2 - m_kart_stats_h/2; + m_kart_stats_x = x + w/2; + m_kart_stats_y = y; } // setSize // ------------------------------------------------------------------------- @@ -891,7 +887,6 @@ void KartHoverListener::onSelectionChanged(DynamicRibbonWidget* theWidget, } m_parent->updateKartWidgetModel(playerID, selectionID, selectionText); - m_parent->m_kart_widgets[playerID].setKartStats(selectionID); m_parent->m_kart_widgets[playerID].setKartInternalName(selectionID); m_parent->validateKartChoices(); } // onSelectionChanged From e2abf6648f69f1c908a2574bb568085c145790d2 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Thu, 29 May 2014 23:57:55 +0200 Subject: [PATCH 033/121] ProgressBar shows, made 3 SkillLevelWidgets, only updating the widgets when hovering over new kart isn't working yet --- src/guiengine/widgets/kart_stats_widget.cpp | 74 ++++++++++++++++---- src/guiengine/widgets/kart_stats_widget.hpp | 18 +++-- src/guiengine/widgets/skill_level_widget.cpp | 5 +- src/states_screens/kart_selection.cpp | 24 ++++++- src/states_screens/kart_selection.hpp | 4 ++ 5 files changed, 95 insertions(+), 30 deletions(-) diff --git a/src/guiengine/widgets/kart_stats_widget.cpp b/src/guiengine/widgets/kart_stats_widget.cpp index f3d3d82cd..796e0de3a 100644 --- a/src/guiengine/widgets/kart_stats_widget.cpp +++ b/src/guiengine/widgets/kart_stats_widget.cpp @@ -74,16 +74,43 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, } } - irr::core::recti massArea(m_mass_bar_x, m_mass_bar_y, - m_mass_bar_x + m_mass_bar_w, - m_mass_bar_y + m_mass_bar_h); + // ---- Mass skill level widget + irr::core::recti massArea(m_skill_bar_x, m_skill_bar_y, + m_skill_bar_x + m_skill_bar_w, + m_skill_bar_y + m_skill_bar_h); m_mass_bar = NULL; - m_mass_bar = new SkillLevelWidget(massArea, m_player_id, (int) props->getMass()/10, "Weight"); + m_mass_bar = new SkillLevelWidget(massArea, m_player_id, + (int) props->getMass()/10, "Weight"); m_mass_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); + // ---- Speed skill level widget + irr::core::recti speedArea(m_skill_bar_x, m_skill_bar_y - m_skill_bar_h - 10, + m_skill_bar_x + m_skill_bar_w, + m_skill_bar_y + 10); + + m_speed_bar = NULL; + + m_speed_bar = new SkillLevelWidget(speedArea, m_player_id, + (int) props->getMaxSpeed()/10, "Speed"); + m_speed_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_speed", m_player_id); + + // ---- Acceleration skill level widget + irr::core::recti accelArea(m_skill_bar_x, m_skill_bar_y + m_skill_bar_h + 10, + m_skill_bar_x + m_skill_bar_w, + m_skill_bar_y + 2*m_skill_bar_y + 10); + + m_accel_bar = NULL; + + m_accel_bar = new SkillLevelWidget(accelArea, m_player_id, + (int) props->getTrackConnectionAccel()/10, "Accel"); + m_accel_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_accel", m_player_id); + + m_children.push_back(m_mass_bar); + m_children.push_back(m_speed_bar); + m_children.push_back(m_accel_bar); } // KartStatsWidget @@ -92,6 +119,8 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, void KartStatsWidget::add() { m_mass_bar->add(); + m_speed_bar->add(); + m_accel_bar->add(); } void KartStatsWidget::move(int x, int y, int w, int h) @@ -101,10 +130,25 @@ void KartStatsWidget::move(int x, int y, int w, int h) if (m_mass_bar != NULL) { - m_mass_bar->move(m_mass_bar_x, - m_mass_bar_y, - m_mass_bar_w, - m_mass_bar_h); + m_mass_bar->move(m_skill_bar_x, + m_skill_bar_y, + m_skill_bar_w, + m_skill_bar_h); + } + + if (m_speed_bar != NULL) + { + m_speed_bar->move(m_skill_bar_x, + m_skill_bar_y - m_skill_bar_h - 10, + m_skill_bar_w, + m_skill_bar_h); + } + if (m_accel_bar != NULL) + { + m_accel_bar->move(m_skill_bar_x, + m_skill_bar_y + m_skill_bar_h + 10, + m_skill_bar_w, + m_skill_bar_h); } } @@ -119,18 +163,18 @@ void KartStatsWidget::setSize(const int x, const int y, const int w, const int h m_h = h; // -- sizes - m_mass_bar_w = w; - m_mass_bar_h = 100; + m_skill_bar_w = w; + m_skill_bar_h = 100; // for shrinking effect if (h < 175) { const float factor = h / 175.0f; - m_mass_bar_h = (int)(m_mass_bar_h*factor); + m_skill_bar_h = (int)(m_skill_bar_h*factor); } - m_mass_bar_x = x; - m_mass_bar_y = y + h/2 - m_mass_bar_h/2; + m_skill_bar_x = x; + m_skill_bar_y = y + h/2 - m_skill_bar_h/2; } // setSize // ----------------------------------------------------------------------------- @@ -144,14 +188,14 @@ void KartStatsWidget::setMass(int value) void KartStatsWidget::setAcceleration(int value) { - m_accel_value = value; + m_accel_bar->setValue(value); } // ----------------------------------------------------------------------------- void KartStatsWidget::setSpeed(int value) { - m_speed_value = value; + m_speed_bar->setValue(value); } // ----------------------------------------------------------------------------- diff --git a/src/guiengine/widgets/kart_stats_widget.hpp b/src/guiengine/widgets/kart_stats_widget.hpp index e7a0f0cfe..52b69b9b0 100644 --- a/src/guiengine/widgets/kart_stats_widget.hpp +++ b/src/guiengine/widgets/kart_stats_widget.hpp @@ -49,20 +49,18 @@ class KartStatsWidget : public Widget virtual int getHeightNeededAroundLabel() const { return 4; } /** widget coordinates */ - int m_mass_bar_x, m_mass_bar_y, m_mass_bar_h, m_mass_bar_w; - - int m_mass_value; - int m_accel_value; - int m_speed_value; + int m_skill_bar_x, m_skill_bar_y, m_skill_bar_h, m_skill_bar_w; int m_player_id; + SkillLevelWidget* m_mass_bar; + SkillLevelWidget* m_speed_bar; + SkillLevelWidget* m_accel_bar; + public: LEAK_CHECK() - SkillLevelWidget* m_mass_bar; - KartStatsWidget(core::recti area, const int player_id, std::string kart_group); virtual ~KartStatsWidget() {}; @@ -92,9 +90,9 @@ class KartStatsWidget : public Widget void setSpeed(int value); /** Get the current values of the widget. */ - int getMass() {return m_mass_value; }; - int getAcceleration() {return m_accel_value; }; - int getSpeed() {return m_speed_value; }; + int getMass() {return m_mass_bar->getValue(); }; + int getAcceleration() {return m_accel_bar->getValue(); }; + int getSpeed() {return m_speed_bar->getValue(); }; }; } diff --git a/src/guiengine/widgets/skill_level_widget.cpp b/src/guiengine/widgets/skill_level_widget.cpp index edb0ccbe3..edd19fd42 100644 --- a/src/guiengine/widgets/skill_level_widget.cpp +++ b/src/guiengine/widgets/skill_level_widget.cpp @@ -40,7 +40,6 @@ using namespace irr; SkillLevelWidget::SkillLevelWidget(core::recti area, const int player_id, const int value, const stringw& label) : Widget(WTYPE_DIV) { - m_show_bounding_box = true; m_bar_value = value; m_player_id = player_id; @@ -118,9 +117,9 @@ void SkillLevelWidget::setSize(const int x, const int y, const int w, const int // -- sizes m_bar_w = w/2; - m_bar_h = h; + m_bar_h = GUIEngine::getFontHeight(); m_label_w = w/2; - m_label_h = h; + m_label_h = GUIEngine::getFontHeight(); // for shrinking effect if (h < 175) diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index a0430a0f3..d579ab414 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -370,7 +370,6 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, m_kart_name->m_y = kart_name_y; m_kart_name->m_w = kart_name_w; m_kart_name->m_h = kart_name_h; - //m_kart_name->setParent(this); m_children.push_back(m_kart_name); } // PlayerKartWidget // ------------------------------------------------------------------------ @@ -806,7 +805,9 @@ void PlayerKartWidget::setKartStats(const std::string& selection) if (kp != NULL) { m_kart_stats->setMass((int)kp->getMass()/10); - //TODO add other stats + m_kart_stats->setSpeed((int)kp->getMaxSpeed()/10); + m_kart_stats->setAcceleration((int)kp->getTrackConnectionAccel()/10); + m_kart_stats->update(0); } } @@ -888,6 +889,7 @@ void KartHoverListener::onSelectionChanged(DynamicRibbonWidget* theWidget, m_parent->updateKartWidgetModel(playerID, selectionID, selectionText); m_parent->m_kart_widgets[playerID].setKartInternalName(selectionID); + m_parent->updateKartStats(playerID, selectionID); m_parent->validateKartChoices(); } // onSelectionChanged @@ -1490,6 +1492,24 @@ void KartSelectionScreen::playerConfirm(const int playerID) // ---------------------------------------------------------------------------- +void KartSelectionScreen::updateKartStats(uint8_t widget_id, + const std::string& selection) +{ + KartStatsWidget* w = m_kart_widgets[widget_id].m_kart_stats; + assert(w != NULL); + + const KartProperties *kp = + kart_properties_manager->getKart(selection); + if (kp != NULL) + { + Log::verbose("updateKartStats", StringUtils::toString((int)kp->getMass()/10).c_str()); + w->setMass((int)kp->getMass()/10); + w->setSpeed((int)kp->getMaxSpeed()/10); + w->setAcceleration((int)kp->getTrackConnectionAccel()/10); + w->update(0); + } +} + void KartSelectionScreen::updateKartWidgetModel(uint8_t widget_id, const std::string& selection, const irr::core::stringw& selectionText) diff --git a/src/states_screens/kart_selection.hpp b/src/states_screens/kart_selection.hpp index 4017cf789..85c6986e5 100644 --- a/src/states_screens/kart_selection.hpp +++ b/src/states_screens/kart_selection.hpp @@ -111,6 +111,10 @@ protected: void setKartsFromCurrentGroup(); virtual void playerConfirm(const int playerID); + + void updateKartStats(uint8_t widget_id, + const std::string& selection); + /** updates model of a kart widget, to have the good selection when the user validates */ void updateKartWidgetModel(uint8_t widget_id, const std::string& selection, From 9b898683201d9bbd231a8eb0e6584d17d7f01f54 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Fri, 30 May 2014 00:13:18 +0200 Subject: [PATCH 034/121] reflect changes in network kart selection --- src/states_screens/network_kart_selection.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/states_screens/network_kart_selection.cpp b/src/states_screens/network_kart_selection.cpp index 66575978e..10dd6a750 100644 --- a/src/states_screens/network_kart_selection.cpp +++ b/src/states_screens/network_kart_selection.cpp @@ -146,6 +146,7 @@ void NetworkKartSelectionScreen::playerSelected(uint8_t race_id, std::string kar assert(widget_id>=0 && widget_id < m_kart_widgets.size()); KartSelectionScreen::updateKartWidgetModel(widget_id, kart_name, irr::core::stringw(kart_name.c_str())); + KartSelectionScreen::updateKartStats(widget_id, kart_name); m_kart_widgets[widget_id].setKartInternalName(kart_name); m_kart_widgets[widget_id].markAsReady(); // mark player ready } From 43971c1e7934712f6ded380fba0552f71142100f Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Fri, 30 May 2014 00:55:58 +0200 Subject: [PATCH 035/121] Fix for the changing ProgressBar.. The only thing now needed for properties GUI is making it fancy, and change the way it's placed with multiple players --- src/guiengine/widgets/skill_level_widget.cpp | 5 ++--- src/guiengine/widgets/skill_level_widget.hpp | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/guiengine/widgets/skill_level_widget.cpp b/src/guiengine/widgets/skill_level_widget.cpp index edd19fd42..3f0ca300c 100644 --- a/src/guiengine/widgets/skill_level_widget.cpp +++ b/src/guiengine/widgets/skill_level_widget.cpp @@ -40,7 +40,6 @@ using namespace irr; SkillLevelWidget::SkillLevelWidget(core::recti area, const int player_id, const int value, const stringw& label) : Widget(WTYPE_DIV) { - m_bar_value = value; m_player_id = player_id; setSize(area.UpperLeftCorner.X, area.UpperLeftCorner.Y, @@ -95,7 +94,6 @@ void SkillLevelWidget::move(int x, int y, int w, int h) m_bar_y, m_bar_w, m_bar_h ); - m_bar->setValue(m_bar_value); } if (m_label != NULL) { @@ -140,7 +138,8 @@ void SkillLevelWidget::setSize(const int x, const int y, const int w, const int void SkillLevelWidget::setValue(int value) { - m_bar_value = value; + m_bar->setValue(value); + } // ----------------------------------------------------------------------------- diff --git a/src/guiengine/widgets/skill_level_widget.hpp b/src/guiengine/widgets/skill_level_widget.hpp index 84a1fd547..bdd1e4b3f 100644 --- a/src/guiengine/widgets/skill_level_widget.hpp +++ b/src/guiengine/widgets/skill_level_widget.hpp @@ -51,7 +51,6 @@ class SkillLevelWidget : public Widget int m_bar_x, m_bar_y, m_bar_h, m_bar_w; int m_label_x, m_label_y, m_label_h, m_label_w; - int m_bar_value; std::string m_label_name; int m_player_id; @@ -85,7 +84,7 @@ class SkillLevelWidget : public Widget void setValue(int value); /** Get the current values of the widget. */ - int getValue() {return m_bar_value; }; + int getValue() {return m_bar->getValue(); }; }; } From 45ac7d5e035263dd6884053cc68860f1e388dfff Mon Sep 17 00:00:00 2001 From: hiker Date: Fri, 30 May 2014 10:07:13 +1000 Subject: [PATCH 036/121] Fixed compiler warnings. --- src/guiengine/widgets/kart_stats_widget.hpp | 2 +- src/guiengine/widgets/skill_level_widget.cpp | 2 +- src/guiengine/widgets/skill_level_widget.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/guiengine/widgets/kart_stats_widget.hpp b/src/guiengine/widgets/kart_stats_widget.hpp index 52b69b9b0..3d4962140 100644 --- a/src/guiengine/widgets/kart_stats_widget.hpp +++ b/src/guiengine/widgets/kart_stats_widget.hpp @@ -70,7 +70,7 @@ class KartStatsWidget : public Widget virtual void add(); /** Move the widget and its children */ - virtual void move(int x, int y, int w, int h); + virtual void move(const int x, const int y, const int w, const int h); // ------------------------------------------------------------------------- /** Updates the animation (moving/shrinking/etc.) */ diff --git a/src/guiengine/widgets/skill_level_widget.cpp b/src/guiengine/widgets/skill_level_widget.cpp index 3f0ca300c..ec09f55c4 100644 --- a/src/guiengine/widgets/skill_level_widget.cpp +++ b/src/guiengine/widgets/skill_level_widget.cpp @@ -83,7 +83,7 @@ void SkillLevelWidget::add() // ----------------------------------------------------------------------------- -void SkillLevelWidget::move(int x, int y, int w, int h) +void SkillLevelWidget::move(const int x, const int y, const int w, const int h) { Widget::move(x,y,w,h); setSize(m_x, m_y, m_w, m_h); diff --git a/src/guiengine/widgets/skill_level_widget.hpp b/src/guiengine/widgets/skill_level_widget.hpp index bdd1e4b3f..05e7db123 100644 --- a/src/guiengine/widgets/skill_level_widget.hpp +++ b/src/guiengine/widgets/skill_level_widget.hpp @@ -72,7 +72,7 @@ class SkillLevelWidget : public Widget // ------------------------------------------------------------------------- - virtual void move(int x, int y, int w, int h); + virtual void move(const int x, const int y, const int w, const int h); // ------------------------------------------------------------------------- From 084a4a46f34d2573eae5e2179c075e6eae0ce061 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Sat, 31 May 2014 20:21:15 +0200 Subject: [PATCH 037/121] GUI Property now more modifiable (with SkillLevelWidget in vector and types in an enum) --- src/guiengine/widgets/kart_stats_widget.cpp | 97 ++++++++------------ src/guiengine/widgets/kart_stats_widget.hpp | 22 +++-- src/guiengine/widgets/skill_level_widget.cpp | 4 +- src/states_screens/kart_selection.cpp | 20 +--- src/states_screens/kart_selection.hpp | 5 - 5 files changed, 58 insertions(+), 90 deletions(-) diff --git a/src/guiengine/widgets/kart_stats_widget.cpp b/src/guiengine/widgets/kart_stats_widget.cpp index 796e0de3a..179f92b58 100644 --- a/src/guiengine/widgets/kart_stats_widget.cpp +++ b/src/guiengine/widgets/kart_stats_widget.cpp @@ -80,37 +80,42 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, irr::core::recti massArea(m_skill_bar_x, m_skill_bar_y, m_skill_bar_x + m_skill_bar_w, m_skill_bar_y + m_skill_bar_h); - m_mass_bar = NULL; + SkillLevelWidget* skill_bar = NULL; - m_mass_bar = new SkillLevelWidget(massArea, m_player_id, + skill_bar = new SkillLevelWidget(massArea, m_player_id, (int) props->getMass()/10, "Weight"); - m_mass_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); + skill_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); + + m_skills.push_back(skill_bar); + m_children.push_back(skill_bar); // ---- Speed skill level widget irr::core::recti speedArea(m_skill_bar_x, m_skill_bar_y - m_skill_bar_h - 10, m_skill_bar_x + m_skill_bar_w, m_skill_bar_y + 10); - m_speed_bar = NULL; + skill_bar = NULL; - m_speed_bar = new SkillLevelWidget(speedArea, m_player_id, + skill_bar = new SkillLevelWidget(speedArea, m_player_id, (int) props->getMaxSpeed()/10, "Speed"); - m_speed_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_speed", m_player_id); + skill_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_speed", m_player_id); + + m_skills.push_back(skill_bar); + m_children.push_back(skill_bar); // ---- Acceleration skill level widget irr::core::recti accelArea(m_skill_bar_x, m_skill_bar_y + m_skill_bar_h + 10, m_skill_bar_x + m_skill_bar_w, m_skill_bar_y + 2*m_skill_bar_y + 10); - m_accel_bar = NULL; + skill_bar = NULL; - m_accel_bar = new SkillLevelWidget(accelArea, m_player_id, + skill_bar = new SkillLevelWidget(accelArea, m_player_id, (int) props->getTrackConnectionAccel()/10, "Accel"); - m_accel_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_accel", m_player_id); + skill_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_accel", m_player_id); - m_children.push_back(m_mass_bar); - m_children.push_back(m_speed_bar); - m_children.push_back(m_accel_bar); + m_skills.push_back(skill_bar); + m_children.push_back(skill_bar); } // KartStatsWidget @@ -118,43 +123,42 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, void KartStatsWidget::add() { - m_mass_bar->add(); - m_speed_bar->add(); - m_accel_bar->add(); + for (int i = 0; i < SKILL_COUNT; ++i) { + m_skills[i]->add(); + } } void KartStatsWidget::move(int x, int y, int w, int h) { Widget::move(x,y,w,h); setSize(m_x, m_y, m_w, m_h); - - if (m_mass_bar != NULL) + int offset = (m_h - (SKILL_COUNT*m_skill_bar_h)) / 2; + for (int i = 0; i < SKILL_COUNT; ++i) { - m_mass_bar->move(m_skill_bar_x, - m_skill_bar_y, - m_skill_bar_w, - m_skill_bar_h); - } - - if (m_speed_bar != NULL) - { - m_speed_bar->move(m_skill_bar_x, - m_skill_bar_y - m_skill_bar_h - 10, + m_skills[i]->move(m_skill_bar_x, + m_y + offset + m_skill_bar_h*i, m_skill_bar_w, m_skill_bar_h); } - if (m_accel_bar != NULL) - { - m_accel_bar->move(m_skill_bar_x, - m_skill_bar_y + m_skill_bar_h + 10, - m_skill_bar_w, - m_skill_bar_h); - } - -} +} //move // ----------------------------------------------------------------------------- +// ---- set value for given type +void KartStatsWidget::setValue(Stats type, int value) +{ + m_skills[type]->setValue(value); +} //setValue + +// ----------------------------------------------------------------------------- + +// ---- get value for given type +int KartStatsWidget::getValue(Stats type) +{ + return m_skills[type]->getValue(); +} // getVAlue + +// ---- set size for widgets inside KartStatsWidget void KartStatsWidget::setSize(const int x, const int y, const int w, const int h) { m_x = x; @@ -178,24 +182,3 @@ void KartStatsWidget::setSize(const int x, const int y, const int w, const int h } // setSize // ----------------------------------------------------------------------------- - -void KartStatsWidget::setMass(int value) -{ - m_mass_bar->setValue(value); -} - -// ----------------------------------------------------------------------------- - -void KartStatsWidget::setAcceleration(int value) -{ - m_accel_bar->setValue(value); -} - -// ----------------------------------------------------------------------------- - -void KartStatsWidget::setSpeed(int value) -{ - m_speed_bar->setValue(value); -} -// ----------------------------------------------------------------------------- - diff --git a/src/guiengine/widgets/kart_stats_widget.hpp b/src/guiengine/widgets/kart_stats_widget.hpp index 3d4962140..8fca22ea9 100644 --- a/src/guiengine/widgets/kart_stats_widget.hpp +++ b/src/guiengine/widgets/kart_stats_widget.hpp @@ -38,6 +38,7 @@ namespace GUIEngine * \ingroup widgetsgroup */ + class KartStatsWidget : public Widget { /** When inferring widget size from its label length, this method will be called to @@ -52,13 +53,20 @@ class KartStatsWidget : public Widget int m_skill_bar_x, m_skill_bar_y, m_skill_bar_h, m_skill_bar_w; int m_player_id; - SkillLevelWidget* m_mass_bar; - SkillLevelWidget* m_speed_bar; - SkillLevelWidget* m_accel_bar; + + std::vector m_skills; public: + enum Stats + { + SKILL_MASS, + SKILL_SPEED, + SKILL_ACCEL, + SKILL_COUNT + }; + LEAK_CHECK() KartStatsWidget(core::recti area, const int player_id, @@ -85,14 +93,10 @@ class KartStatsWidget : public Widget void setSize(const int x, const int y, const int w, const int h); /** Change the value of the widget, it must be a percent. */ - void setMass(int value); - void setAcceleration(int value); - void setSpeed(int value); + void setValue(Stats type, int value); /** Get the current values of the widget. */ - int getMass() {return m_mass_bar->getValue(); }; - int getAcceleration() {return m_accel_bar->getValue(); }; - int getSpeed() {return m_speed_bar->getValue(); }; + int getValue(Stats type); }; } diff --git a/src/guiengine/widgets/skill_level_widget.cpp b/src/guiengine/widgets/skill_level_widget.cpp index ec09f55c4..f8b3c3cfa 100644 --- a/src/guiengine/widgets/skill_level_widget.cpp +++ b/src/guiengine/widgets/skill_level_widget.cpp @@ -128,10 +128,10 @@ void SkillLevelWidget::setSize(const int x, const int y, const int w, const int } m_bar_x = x + w/2; - m_bar_y = y; + m_bar_y = y + m_h/2 - m_bar_h/2; m_label_x = x; - m_label_y = y; + m_label_y = y + m_h/2 - m_label_h/2; } // setSize // ----------------------------------------------------------------------------- diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index d579ab414..de955a6b5 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -797,20 +797,6 @@ void PlayerKartWidget::setSize(const int x, const int y, const int w, const int // ------------------------------------------------------------------------- -void PlayerKartWidget::setKartStats(const std::string& selection) -{ - assert(m_magic_number == 0x33445566); - const KartProperties *kp = - kart_properties_manager->getKart(selection); - if (kp != NULL) - { - m_kart_stats->setMass((int)kp->getMass()/10); - m_kart_stats->setSpeed((int)kp->getMaxSpeed()/10); - m_kart_stats->setAcceleration((int)kp->getTrackConnectionAccel()/10); - m_kart_stats->update(0); - } -} - /** Sets which kart was selected for this player */ void PlayerKartWidget::setKartInternalName(const std::string& whichKart) { @@ -1503,9 +1489,9 @@ void KartSelectionScreen::updateKartStats(uint8_t widget_id, if (kp != NULL) { Log::verbose("updateKartStats", StringUtils::toString((int)kp->getMass()/10).c_str()); - w->setMass((int)kp->getMass()/10); - w->setSpeed((int)kp->getMaxSpeed()/10); - w->setAcceleration((int)kp->getTrackConnectionAccel()/10); + w->setValue(KartStatsWidget::SKILL_MASS, (int)kp->getMass()/10); + w->setValue(KartStatsWidget::SKILL_SPEED, (int)kp->getMaxSpeed()/10); + w->setValue(KartStatsWidget::SKILL_ACCEL, (int)kp->getTrackConnectionAccel()/10); w->update(0); } } diff --git a/src/states_screens/kart_selection.hpp b/src/states_screens/kart_selection.hpp index 85c6986e5..e42abbf93 100644 --- a/src/states_screens/kart_selection.hpp +++ b/src/states_screens/kart_selection.hpp @@ -346,11 +346,6 @@ public: // ------------------------------------------------------------------------- - /** Set the kart stats for this player */ - void setKartStats(const std::string& selection); - - // ------------------------------------------------------------------------- - /** Sets which kart was selected for this player */ void setKartInternalName(const std::string& whichKart); From cdb0e88895a85ef9d4bd5bdf22e642f7c028bbf3 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Sun, 1 Jun 2014 14:12:50 +0200 Subject: [PATCH 038/121] Make creation of new skills more generic --- src/guiengine/widgets/kart_stats_widget.cpp | 55 +++++++------------- src/guiengine/widgets/skill_level_widget.cpp | 7 ++- src/guiengine/widgets/skill_level_widget.hpp | 8 ++- 3 files changed, 32 insertions(+), 38 deletions(-) diff --git a/src/guiengine/widgets/kart_stats_widget.cpp b/src/guiengine/widgets/kart_stats_widget.cpp index 179f92b58..b69fa7d37 100644 --- a/src/guiengine/widgets/kart_stats_widget.cpp +++ b/src/guiengine/widgets/kart_stats_widget.cpp @@ -75,47 +75,32 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, } + const int offset = (m_h - (SKILL_COUNT*m_skill_bar_h)) / 2;; + for (int i = 0; i < SKILL_COUNT; ++i) + { + irr::core::recti skillArea(m_skill_bar_x, m_skill_bar_y + offset*i, + m_skill_bar_x + m_skill_bar_w, + m_skill_bar_y + offset*i + m_skill_bar_h); - // ---- Mass skill level widget - irr::core::recti massArea(m_skill_bar_x, m_skill_bar_y, - m_skill_bar_x + m_skill_bar_w, - m_skill_bar_y + m_skill_bar_h); - SkillLevelWidget* skill_bar = NULL; + SkillLevelWidget* skill_bar = NULL; - skill_bar = new SkillLevelWidget(massArea, m_player_id, - (int) props->getMass()/10, "Weight"); - skill_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); + skill_bar = new SkillLevelWidget(skillArea, m_player_id); - m_skills.push_back(skill_bar); - m_children.push_back(skill_bar); + m_skills.push_back(skill_bar); + m_children.push_back(skill_bar); + } - // ---- Speed skill level widget - irr::core::recti speedArea(m_skill_bar_x, m_skill_bar_y - m_skill_bar_h - 10, - m_skill_bar_x + m_skill_bar_w, - m_skill_bar_y + 10); + m_skills[SKILL_MASS]->setValue(props->getMass()/10); + m_skills[SKILL_MASS]->setLabel("Weight"); + m_skills[SKILL_MASS]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); - skill_bar = NULL; + m_skills[SKILL_ACCEL]->setValue(props->getTrackConnectionAccel()/10); + m_skills[SKILL_ACCEL]->setLabel("Accel"); + m_skills[SKILL_ACCEL]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_accel", m_player_id); - skill_bar = new SkillLevelWidget(speedArea, m_player_id, - (int) props->getMaxSpeed()/10, "Speed"); - skill_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_speed", m_player_id); - - m_skills.push_back(skill_bar); - m_children.push_back(skill_bar); - - // ---- Acceleration skill level widget - irr::core::recti accelArea(m_skill_bar_x, m_skill_bar_y + m_skill_bar_h + 10, - m_skill_bar_x + m_skill_bar_w, - m_skill_bar_y + 2*m_skill_bar_y + 10); - - skill_bar = NULL; - - skill_bar = new SkillLevelWidget(accelArea, m_player_id, - (int) props->getTrackConnectionAccel()/10, "Accel"); - skill_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_accel", m_player_id); - - m_skills.push_back(skill_bar); - m_children.push_back(skill_bar); + m_skills[SKILL_SPEED]->setValue(props->getMaxSpeed()/10); + m_skills[SKILL_SPEED]->setLabel("Speed"); + m_skills[SKILL_SPEED]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_speed", m_player_id); } // KartStatsWidget diff --git a/src/guiengine/widgets/skill_level_widget.cpp b/src/guiengine/widgets/skill_level_widget.cpp index f8b3c3cfa..08084b0b5 100644 --- a/src/guiengine/widgets/skill_level_widget.cpp +++ b/src/guiengine/widgets/skill_level_widget.cpp @@ -136,7 +136,7 @@ void SkillLevelWidget::setSize(const int x, const int y, const int w, const int // ----------------------------------------------------------------------------- -void SkillLevelWidget::setValue(int value) +void SkillLevelWidget::setValue(const int value) { m_bar->setValue(value); @@ -144,3 +144,8 @@ void SkillLevelWidget::setValue(int value) // ----------------------------------------------------------------------------- +void SkillLevelWidget::setLabel(const irr::core::stringw& label) +{ + m_label->setText(label, false); +} + diff --git a/src/guiengine/widgets/skill_level_widget.hpp b/src/guiengine/widgets/skill_level_widget.hpp index 05e7db123..5f5fa05be 100644 --- a/src/guiengine/widgets/skill_level_widget.hpp +++ b/src/guiengine/widgets/skill_level_widget.hpp @@ -63,7 +63,7 @@ class SkillLevelWidget : public Widget ProgressBarWidget* m_bar; SkillLevelWidget(core::recti area, const int player_id, - const int value, const irr::core::stringw& label); + const int value = 0, const irr::core::stringw& label = "default"); virtual ~SkillLevelWidget() {}; // ------------------------------------------------------------------------ @@ -81,10 +81,14 @@ class SkillLevelWidget : public Widget void setSize(const int x, const int y, const int w, const int h); /** Change the value of the widget, it must be a percent. */ - void setValue(int value); + void setValue(const int value); /** Get the current values of the widget. */ int getValue() {return m_bar->getValue(); }; + + /** Change the label of the widget */ + void setLabel(const irr::core::stringw& label); + }; } From 07b6579529a7ecd85220e0423eebddcf59d8138a Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Sun, 1 Jun 2014 18:29:11 +0200 Subject: [PATCH 039/121] Fixed the GUI properties for multiplayer view, though the screen is way too full right now. Some changes (to GUI or screen) have to be done! --- src/guiengine/widgets/kart_stats_widget.cpp | 17 ++-- src/guiengine/widgets/kart_stats_widget.hpp | 3 +- src/guiengine/widgets/skill_level_widget.cpp | 9 +- src/guiengine/widgets/skill_level_widget.hpp | 9 +- src/states_screens/kart_selection.cpp | 95 ++++++++++++++------ src/states_screens/kart_selection.hpp | 1 - 6 files changed, 90 insertions(+), 44 deletions(-) diff --git a/src/guiengine/widgets/kart_stats_widget.cpp b/src/guiengine/widgets/kart_stats_widget.cpp index b69fa7d37..2db661fe5 100644 --- a/src/guiengine/widgets/kart_stats_widget.cpp +++ b/src/guiengine/widgets/kart_stats_widget.cpp @@ -38,7 +38,8 @@ using namespace irr; // ----------------------------------------------------------------------------- KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, - std::string kart_group) : Widget(WTYPE_DIV) + std::string kart_group, + bool multiplayer) : Widget(WTYPE_DIV) { m_player_id = player_id; @@ -75,31 +76,31 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, } - const int offset = (m_h - (SKILL_COUNT*m_skill_bar_h)) / 2;; + const int offset = (m_h - (SKILL_COUNT*m_skill_bar_h)) / 2; for (int i = 0; i < SKILL_COUNT; ++i) { irr::core::recti skillArea(m_skill_bar_x, m_skill_bar_y + offset*i, m_skill_bar_x + m_skill_bar_w, - m_skill_bar_y + offset*i + m_skill_bar_h); + m_skill_bar_y + m_skill_bar_h + offset*i); SkillLevelWidget* skill_bar = NULL; - skill_bar = new SkillLevelWidget(skillArea, m_player_id); + skill_bar = new SkillLevelWidget(skillArea, m_player_id, multiplayer); m_skills.push_back(skill_bar); m_children.push_back(skill_bar); } m_skills[SKILL_MASS]->setValue(props->getMass()/10); - m_skills[SKILL_MASS]->setLabel("Weight"); + m_skills[SKILL_MASS]->setLabel("WEIGHT"); m_skills[SKILL_MASS]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); m_skills[SKILL_ACCEL]->setValue(props->getTrackConnectionAccel()/10); - m_skills[SKILL_ACCEL]->setLabel("Accel"); + m_skills[SKILL_ACCEL]->setLabel("ACCEL"); m_skills[SKILL_ACCEL]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_accel", m_player_id); m_skills[SKILL_SPEED]->setValue(props->getMaxSpeed()/10); - m_skills[SKILL_SPEED]->setLabel("Speed"); + m_skills[SKILL_SPEED]->setLabel("SPEED"); m_skills[SKILL_SPEED]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_speed", m_player_id); } // KartStatsWidget @@ -153,7 +154,7 @@ void KartStatsWidget::setSize(const int x, const int y, const int w, const int h // -- sizes m_skill_bar_w = w; - m_skill_bar_h = 100; + m_skill_bar_h = GUIEngine::getTitleFontHeight(); // for shrinking effect if (h < 175) diff --git a/src/guiengine/widgets/kart_stats_widget.hpp b/src/guiengine/widgets/kart_stats_widget.hpp index 8fca22ea9..cf3b3033a 100644 --- a/src/guiengine/widgets/kart_stats_widget.hpp +++ b/src/guiengine/widgets/kart_stats_widget.hpp @@ -70,7 +70,8 @@ class KartStatsWidget : public Widget LEAK_CHECK() KartStatsWidget(core::recti area, const int player_id, - std::string kart_group); + std::string kart_group, + bool multiplayer); virtual ~KartStatsWidget() {}; // ------------------------------------------------------------------------ diff --git a/src/guiengine/widgets/skill_level_widget.cpp b/src/guiengine/widgets/skill_level_widget.cpp index 08084b0b5..85c0c1228 100644 --- a/src/guiengine/widgets/skill_level_widget.cpp +++ b/src/guiengine/widgets/skill_level_widget.cpp @@ -38,7 +38,8 @@ using namespace irr; // ----------------------------------------------------------------------------- SkillLevelWidget::SkillLevelWidget(core::recti area, const int player_id, - const int value, const stringw& label) : Widget(WTYPE_DIV) + bool multiplayer, const int value, + const stringw& label) : Widget(WTYPE_DIV) { m_player_id = player_id; @@ -59,7 +60,7 @@ SkillLevelWidget::SkillLevelWidget(core::recti area, const int player_id, m_label = NULL; - m_label = new LabelWidget(true, true); + m_label = new LabelWidget(!multiplayer, true); m_label->setText(label,false); m_label->m_x = m_label_x; @@ -115,9 +116,9 @@ void SkillLevelWidget::setSize(const int x, const int y, const int w, const int // -- sizes m_bar_w = w/2; - m_bar_h = GUIEngine::getFontHeight(); + m_bar_h = h; m_label_w = w/2; - m_label_h = GUIEngine::getFontHeight(); + m_label_h = h; // for shrinking effect if (h < 175) diff --git a/src/guiengine/widgets/skill_level_widget.hpp b/src/guiengine/widgets/skill_level_widget.hpp index 5f5fa05be..a621e6786 100644 --- a/src/guiengine/widgets/skill_level_widget.hpp +++ b/src/guiengine/widgets/skill_level_widget.hpp @@ -62,8 +62,9 @@ class SkillLevelWidget : public Widget LabelWidget* m_label; ProgressBarWidget* m_bar; - SkillLevelWidget(core::recti area, const int player_id, + SkillLevelWidget(core::recti area, const int player_id, bool multiplayer, const int value = 0, const irr::core::stringw& label = "default"); + virtual ~SkillLevelWidget() {}; // ------------------------------------------------------------------------ @@ -89,6 +90,12 @@ class SkillLevelWidget : public Widget /** Change the label of the widget */ void setLabel(const irr::core::stringw& label); + /** Get the current label of the widget. */ + const irr::core::stringw& getLabel() + { + return m_label->getText(); + } + }; } diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index de955a6b5..baa8e1dbe 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -236,13 +236,26 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, m_kart_stats = NULL; // area for the stats widget - core::recti statsArea(m_kart_stats_x, - m_kart_stats_y, - m_kart_stats_x + m_kart_stats_w, - m_kart_stats_y + m_kart_stats_h); + core::recti statsArea; + if (!parent->m_multiplayer) + { + statsArea = core::recti(m_kart_stats_x, + m_kart_stats_y, + m_kart_stats_x + m_kart_stats_w, + m_kart_stats_y + m_kart_stats_h); + } + else + { + statsArea = core::recti(m_x , m_y + m_h/2, + m_x + m_w, m_y + m_h); + } - m_kart_stats = new GUIEngine::KartStatsWidget(statsArea, player_id, kart_group); + m_kart_stats = new GUIEngine::KartStatsWidget(statsArea, player_id, kart_group, + m_parent_screen->m_multiplayer); + m_kart_stats->m_properties[PROP_ID] = + StringUtils::insertValues("@p%i_stats", m_player_id); + m_children.push_back(m_kart_stats); if (parent->m_multiplayer && associated_player) { @@ -284,10 +297,6 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, //m_player_ident_spinner->m_event_handler = this; m_children.push_back(m_player_ident_spinner); - m_kart_stats->m_properties[PROP_ID] = - StringUtils::insertValues("@p%i_stats", m_player_id); - m_children.push_back(m_kart_stats); - // ----- Kart model view m_model_view = new ModelViewWidget(); @@ -673,10 +682,19 @@ void PlayerKartWidget::onUpdate(float delta) core::recti(core::position2di(player_name_x, player_name_y), core::dimension2di(player_name_w, player_name_h)) ); } - m_kart_stats->move(m_kart_stats_x, - m_kart_stats_y, - m_kart_stats_w, - m_kart_stats_h); + if (!m_parent_screen->m_multiplayer) + { + m_kart_stats->move(m_kart_stats_x, + m_kart_stats_y, + m_kart_stats_w, + m_kart_stats_h); + } + else + { + m_kart_stats->move(m_x, m_y + m_h/2, + m_w, m_h/2); + } + m_model_view->move(model_x, model_y, @@ -759,9 +777,6 @@ void PlayerKartWidget::setSize(const int x, const int y, const int w, const int kart_name_w = w; kart_name_h = 25; - m_kart_stats_w = w/2; - m_kart_stats_h = h; - // for shrinking effect if (h < 175) { @@ -769,7 +784,6 @@ void PlayerKartWidget::setSize(const int x, const int y, const int w, const int kart_name_h = (int)(kart_name_h*factor); player_name_h = (int)(player_name_h*factor); player_id_h = (int)(player_id_h*factor); - m_kart_stats_h = (int)(m_kart_stats_h*factor); } // --- layout @@ -779,20 +793,44 @@ void PlayerKartWidget::setSize(const int x, const int y, const int w, const int player_name_x = x + w/2 - player_name_w/2; player_name_y = y + player_id_h; - const int modelMaxHeight = h - kart_name_h - player_name_h - - player_id_h; - const int modelMaxWidth = w; - const int bestSize = std::min(modelMaxWidth, modelMaxHeight); - const int modelY = y + player_name_h + player_id_h; - model_x = x + w/4 - (int)(bestSize/2); - model_y = modelY + modelMaxHeight/2 - bestSize/2; - model_w = (int)(bestSize); - model_h = bestSize; + if (m_parent_screen->m_multiplayer) + { + const int modelMaxHeight = (h - kart_name_h - player_name_h + - player_id_h)/2; + const int modelMaxWidth = w; + const int bestSize = std::min(modelMaxWidth, modelMaxHeight); + model_x = x + w/2 - (int)(bestSize/2); + model_y = y + player_name_h + player_id_h; + model_w = (int)(bestSize); + model_h = bestSize; + + m_kart_stats_w = model_w; + m_kart_stats_h = model_h; + m_kart_stats_x = x + w/2 - (int)(bestSize/2); + m_kart_stats_y = model_y + model_h; + + + } + else + { + const int modelMaxHeight = h - kart_name_h - player_name_h + - player_id_h; + const int modelMaxWidth = w; + const int bestSize = std::min(modelMaxWidth, modelMaxHeight); + const int modelY = y + player_name_h + player_id_h; + model_x = x + w/4 - (int)(bestSize/2); + model_y = modelY + modelMaxHeight/2 - bestSize/2; + model_w = (int)(bestSize); + model_h = bestSize; + + m_kart_stats_w = w/2; + m_kart_stats_h = h; + m_kart_stats_x = x + w/2; + m_kart_stats_y = y; + } kart_name_x = x; kart_name_y = y + h - kart_name_h; - m_kart_stats_x = x + w/2; - m_kart_stats_y = y; } // setSize // ------------------------------------------------------------------------- @@ -1488,7 +1526,6 @@ void KartSelectionScreen::updateKartStats(uint8_t widget_id, kart_properties_manager->getKart(selection); if (kp != NULL) { - Log::verbose("updateKartStats", StringUtils::toString((int)kp->getMass()/10).c_str()); w->setValue(KartStatsWidget::SKILL_MASS, (int)kp->getMass()/10); w->setValue(KartStatsWidget::SKILL_SPEED, (int)kp->getMaxSpeed()/10); w->setValue(KartStatsWidget::SKILL_ACCEL, (int)kp->getTrackConnectionAccel()/10); diff --git a/src/states_screens/kart_selection.hpp b/src/states_screens/kart_selection.hpp index e42abbf93..0c0ddf0f0 100644 --- a/src/states_screens/kart_selection.hpp +++ b/src/states_screens/kart_selection.hpp @@ -274,7 +274,6 @@ public: /** Sub-widgets created by this widget */ PlayerNameSpinner* m_player_ident_spinner; - GUIEngine::ProgressBarWidget* m_kart_stat_mass; GUIEngine::KartStatsWidget* m_kart_stats; GUIEngine::ModelViewWidget* m_model_view; GUIEngine::LabelWidget* m_kart_name; From a9de2018744cbefa2d75dd015fd9955cddd26b1e Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Thu, 19 Jun 2014 14:34:34 +0200 Subject: [PATCH 040/121] apply new patches to before the dubious applied/reverted merge --- src/guiengine/widgets/skill_level_widget.cpp | 2 +- test.sh | 53 +++++++++++++++----- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/guiengine/widgets/skill_level_widget.cpp b/src/guiengine/widgets/skill_level_widget.cpp index 85c0c1228..97786bf1e 100644 --- a/src/guiengine/widgets/skill_level_widget.cpp +++ b/src/guiengine/widgets/skill_level_widget.cpp @@ -115,7 +115,7 @@ void SkillLevelWidget::setSize(const int x, const int y, const int w, const int m_h = h; // -- sizes - m_bar_w = w/2; + m_bar_w = 3*(w/2)/4; m_bar_h = h; m_label_w = w/2; m_label_h = h; diff --git a/test.sh b/test.sh index e39cd5935..9950973bb 100755 --- a/test.sh +++ b/test.sh @@ -1,20 +1,47 @@ #!/bin/bash mkdir -p ../batch -count=1 -#for numkarts in 4; do -# for laps in 4 10; do -for ((mass = 50; mass <= 500; mass=$mass+10)) do - sed -i -e "s/mass\ value\ =\ \"[0-9]*/mass\ value\ =\ \"$mass/g" ../stk-assets/karts/sara/kart.xml - for run in {1..10}; do - echo $count/450 - ./cmake_build/bin/supertuxkart.app/Contents/MacOS/supertuxkart -R --mode=3 --numkarts=1 --with-profile --profile-laps=3 --kart=sara --ai=beastie,beastie,beastie --no-graphics > /dev/null - grep "profile" ~/Library/Application\ Support/SuperTuxKart/stdout.log > ../batch/$mass.$run.txt - let "count = $count + 1" +tracks='snowmountain city lighthouse olivermath hacienda startrack farm zengarden' +karts='beastie sara elephpant tuxley' +laps=1 + +for track in $tracks; do + #beastie is the current kart + #sara is the light kart + #tuxley is the medium kart + #elephpant is the heavy kart + for kart in $karts; do + for run in {1..50}; do + for lap in $laps; do + ./cmake_build/bin/supertuxkart.app/Contents/MacOS/supertuxkart -R --mode=3 --numkarts=1 --track=$track --with-profile --profile-laps=$lap --kart=$kart --ai=beastie,beastie,beastie --no-graphics > /dev/null + grep "profile" ~/Library/Application\ Support/SuperTuxKart/stdout.log > ../batch/$track.$kart.$run.txt + done + done done done + + -for track in "cave" "city" "scotland" "jungle" "lighthouse" "hacienda" "fortmagma"; do - ./cmake_build/bin/supertuxkart.app/Contents/MacOS/supertuxkart -R --mode=3 --track=$track --with-profile --profile-laps=1 > /dev/null -done \ No newline at end of file + + + +#for track in ../stk-assets/tracks/*/track.xml; do +# grep "internal" "$track" +# if grep -q "internal" "$track" ; then +# continue; +# else +# if grep -q "arena" "$track" ; then +# continue; +# else +# if grep -q "soccer" "$track" ; then +# continue; +# else +# a=${track%%/track.xml}; +# trackname=${a##../stk-assets/tracks/}; +# fi +# fi +# fi +# if [ $trackname = "minel" ] || [ $trackname = "mines" ]; then +# continue; +# fi \ No newline at end of file From 7e9361bc8bf8f8c3e4bf5a45abce72f636e9d12a Mon Sep 17 00:00:00 2001 From: konstin Date: Sat, 21 Jun 2014 16:19:37 +0200 Subject: [PATCH 041/121] avoid reading deallocated memory --- src/states_screens/dialogs/gp_info_dialog.cpp | 1 + src/states_screens/dialogs/random_gp_dialog.cpp | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index b9cd91aae..2f683c874 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -246,6 +246,7 @@ void GPInfoDialog::addButtons() void GPInfoDialog::onEnterPressedInternal() { + // Save the GP id because dismiss() will destroy this instance std::string gp_id = m_gp->getId(); ModalDialog::dismiss(); // Disable accidentally unlocking of a challenge diff --git a/src/states_screens/dialogs/random_gp_dialog.cpp b/src/states_screens/dialogs/random_gp_dialog.cpp index 1e66debd3..32763e357 100644 --- a/src/states_screens/dialogs/random_gp_dialog.cpp +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -138,9 +138,8 @@ GUIEngine::EventPropagation RandomGPInfoDialog::processEvent( { if (eventSource == "start") { - // Save the gp since dismiss deletes it otherwise ModalDialog::dismiss(); - race_manager->startGP(m_gp, false, false); + race_manager->startGP(grand_prix_manager->m_random_gp, false, false); return GUIEngine::EVENT_BLOCK; } else if (eventSource == "Number of tracks") From 59a14df340b5b68207957e1fdfff275f47f039c7 Mon Sep 17 00:00:00 2001 From: konstin Date: Sat, 21 Jun 2014 17:16:23 +0200 Subject: [PATCH 042/121] fix track group spinner --- src/guiengine/widgets/spinner_widget.cpp | 6 +++--- src/states_screens/dialogs/random_gp_dialog.cpp | 13 ++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/guiengine/widgets/spinner_widget.cpp b/src/guiengine/widgets/spinner_widget.cpp index 31a8ad3d2..d6a53e6f8 100644 --- a/src/guiengine/widgets/spinner_widget.cpp +++ b/src/guiengine/widgets/spinner_widget.cpp @@ -160,7 +160,7 @@ void SpinnerWidget::add() { label->setText(m_labels[m_value].c_str() ); } - + } @@ -174,7 +174,7 @@ void SpinnerWidget::add() m_children[2].m_id = m_children[2].m_element->getID(); // refresh display - + setValue(m_value); } @@ -333,7 +333,7 @@ void SpinnerWidget::setValue(const int new_value) assert(new_value >= 0); assert(new_value < (int)m_labels.size()); - m_children[1].m_element->setText(m_labels[new_value].c_str() ); + m_children[1].m_element->setText(m_labels[new_value].c_str()); } else if (m_text.size() > 0 && m_children.size() > 0) { diff --git a/src/states_screens/dialogs/random_gp_dialog.cpp b/src/states_screens/dialogs/random_gp_dialog.cpp index 32763e357..41ab3facb 100644 --- a/src/states_screens/dialogs/random_gp_dialog.cpp +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -35,7 +35,7 @@ typedef GUIEngine::SpinnerWidget Spinner; RandomGPInfoDialog::RandomGPInfoDialog() { // Defaults - loading selection from last time frrom a file would be better - m_number_of_tracks = 2; // We can assume that there are at least 2 standart tracks + m_number_of_tracks = 2; // We can assume that there are at least 2 standard tracks m_trackgroup = "standard"; m_use_reverse = NO_REVERSE; @@ -78,20 +78,23 @@ void RandomGPInfoDialog::addSpinners() m_widgets.push_back(spinner); spinner->add(); spinner->move(left, m_under_title, trackgroup_width, SPINNER_HEIGHT); - // Fill it with with all the track group names + // Fill it with all the track group names spinner->addLabel("all"); + int index_standard; const std::vector& groups = track_manager->getAllTrackGroups(); - for (unsigned int i = 1; i < groups.size() + 1; i++) + for (unsigned int i = 0; i < groups.size() + 1; i++) { // FIXME: The NULL check is necessary until #1348 on github is fixed if (groups[i].c_str() != NULL) { spinner->addLabel(stringw(groups[i].c_str())); if(groups[i] == "standard") - spinner->setValue(i); + index_standard = i+1; } } - spinner->setValue(1); // Let's just hope it's right ... + // The value can only be set here because SpinnerWidget resets the value + // every time a label is added + spinner->setValue(index_standard); // Number of laps chooser spinner = new Spinner(false); From 98f8ddb4e96b7806d6a265699fb499e4e766b600 Mon Sep 17 00:00:00 2001 From: konstin Date: Sat, 21 Jun 2014 17:18:01 +0200 Subject: [PATCH 043/121] fix path to icon --- src/states_screens/tracks_screen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/states_screens/tracks_screen.cpp b/src/states_screens/tracks_screen.cpp index 95597ffb4..94f715553 100644 --- a/src/states_screens/tracks_screen.cpp +++ b/src/states_screens/tracks_screen.cpp @@ -224,7 +224,7 @@ void TracksScreen::init() // Random GP std::vector screenshots; - screenshots.push_back("gui/main_help.png"); + screenshots.push_back(file_manager->getAsset(FileManager::GUI, "main_help.png")); gps_widget->addAnimatedItem(translations->fribidize("Random Grand Prix"), "Random Grand Prix", screenshots, 1.5f, 0, From ca2ee5d226b2af7e5732ce9fb79161b85f4e1b9a Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Sun, 22 Jun 2014 20:06:58 -0400 Subject: [PATCH 044/121] New minimap rtt branch : now something is visible --- src/tracks/quad_graph.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tracks/quad_graph.cpp b/src/tracks/quad_graph.cpp index 70ffe9e9d..78e7011f9 100644 --- a/src/tracks/quad_graph.cpp +++ b/src/tracks/quad_graph.cpp @@ -1046,8 +1046,8 @@ void QuadGraph::makeMiniMap(const core::dimension2du &origdimension, float range = (dx>dz) ? dx : dz; core::matrix4 projection; - projection.buildProjectionMatrixOrthoLH(range, - range, + projection.buildProjectionMatrixOrthoLH(range /* width */, + range /* height */, -1, bb_max.getY()-bb_min.getY()+1); camera->setProjectionMatrix(projection, true); @@ -1057,7 +1057,8 @@ void QuadGraph::makeMiniMap(const core::dimension2du &origdimension, // Adjust Y position by +1 for max, -1 for min - this helps in case that // the maximum Y coordinate is negative (otherwise the minimap is mirrored) // and avoids problems for tracks which have a flat (max Y = min Y) minimap. - camera->setPosition(core::vector3df(center.getX(), bb_max.getY()+1, center.getZ())); + camera->setPosition(core::vector3df(center.getX(), bb_min.getY() - 300.0f, center.getZ())); + //camera->setPosition(core::vector3df(center.getX() - 5.0f, bb_min.getY() - 1 - 5.0f, center.getZ() - 15.0f)); camera->setUpVector(core::vector3df(0, 0, 1)); camera->setTarget(core::vector3df(center.getX(),bb_min.getY()-1,center.getZ())); camera->setAspectRatio(1.0f); From d5e1bb6631e1a22eaa8dd0ca8ba1db511971af97 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Sun, 22 Jun 2014 21:28:25 -0400 Subject: [PATCH 045/121] Make progress on new minimap RTT : it was actually 2 issues. First the new code calls camera->setAspectRatio which resets the matrix; second, we rendered the minimap from the back, and backface culling is now active --- src/tracks/quad_graph.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/tracks/quad_graph.cpp b/src/tracks/quad_graph.cpp index 78e7011f9..6156eadd1 100644 --- a/src/tracks/quad_graph.cpp +++ b/src/tracks/quad_graph.cpp @@ -452,12 +452,12 @@ void QuadGraph::createMesh(bool show_invisible, // Set up the indices for the triangles // (note, afaik with opengl we could use quads directly, but the code // would not be portable to directx anymore). - ind[6*i ] = 4*i; // First triangle: vertex 0, 1, 2 + ind[6*i ] = 4*i+2; // First triangle: vertex 0, 1, 2 ind[6*i+1] = 4*i+1; - ind[6*i+2] = 4*i+2; - ind[6*i+3] = 4*i; // second triangle: vertex 0, 1, 3 + ind[6*i+2] = 4*i; + ind[6*i+3] = 4*i+3; // second triangle: vertex 0, 1, 3 ind[6*i+4] = 4*i+2; - ind[6*i+5] = 4*i+3; + ind[6*i+5] = 4*i; i++; } // for i=1; iisGLSL()) @@ -1057,15 +1055,16 @@ void QuadGraph::makeMiniMap(const core::dimension2du &origdimension, // Adjust Y position by +1 for max, -1 for min - this helps in case that // the maximum Y coordinate is negative (otherwise the minimap is mirrored) // and avoids problems for tracks which have a flat (max Y = min Y) minimap. - camera->setPosition(core::vector3df(center.getX(), bb_min.getY() - 300.0f, center.getZ())); + camera->setPosition(core::vector3df(center.getX(), bb_min.getY() + 1.0f, center.getZ())); //camera->setPosition(core::vector3df(center.getX() - 5.0f, bb_min.getY() - 1 - 5.0f, center.getZ() - 15.0f)); camera->setUpVector(core::vector3df(0, 0, 1)); camera->setTarget(core::vector3df(center.getX(),bb_min.getY()-1,center.getZ())); - camera->setAspectRatio(1.0f); + //camera->setAspectRatio(1.0f); camera->updateAbsolutePosition(); video::ITexture* texture = NULL; FrameBuffer* frame_buffer = NULL; + if (irr_driver->isGLSL()) { frame_buffer = newRttProvider->render(camera, GUIEngine::getLatestDt()); From 1a8b35c79642cb7eaae0c82d0b191bb49c2465f5 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 23 Jun 2014 14:46:02 +0200 Subject: [PATCH 046/121] Set blendfunc when calling draw2DImageFromRTT. --- src/graphics/glwrap.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 516be8203..37f6cefe1 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -781,7 +781,11 @@ void draw2DImageFromRTT(GLuint texture, size_t texture_w, size_t texture_h, const core::rect& sourceRect, const core::rect* clipRect, bool useAlphaChannelOfTexture) { - glEnable(GL_BLEND); + if (useAlphaChannelOfTexture) + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } float width, height, center_pos_x, center_pos_y, tex_width, tex_height, From 4d6aa9d9427f3177fb41d9d36d7e7fa900a926a3 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 23 Jun 2014 14:54:16 +0200 Subject: [PATCH 047/121] Override clear color inside makeMiniMap Track clear color was used, resulting in wrong alpha channel value. --- src/tracks/quad_graph.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tracks/quad_graph.cpp b/src/tracks/quad_graph.cpp index 6156eadd1..b0edf1274 100644 --- a/src/tracks/quad_graph.cpp +++ b/src/tracks/quad_graph.cpp @@ -976,6 +976,8 @@ void QuadGraph::makeMiniMap(const core::dimension2du &dimension, video::ITexture** oldRttMinimap, FrameBuffer** newRttMinimap) { + const SColor oldClearColor = World::getWorld()->getClearColor(); + World::getWorld()->setClearbackBufferColor(SColor(0, 255, 255, 255)); *oldRttMinimap = NULL; *newRttMinimap = NULL; @@ -1091,6 +1093,7 @@ void QuadGraph::makeMiniMap(const core::dimension2du &dimension, *oldRttMinimap = texture; *newRttMinimap = frame_buffer; + World::getWorld()->setClearbackBufferColor(oldClearColor); } // makeMiniMap //----------------------------------------------------------------------------- From 01623da5e9646bd930018d6d1e78760512ca0aab Mon Sep 17 00:00:00 2001 From: konstin Date: Mon, 23 Jun 2014 16:13:54 +0200 Subject: [PATCH 048/121] remove +1 --- src/states_screens/dialogs/random_gp_dialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/states_screens/dialogs/random_gp_dialog.cpp b/src/states_screens/dialogs/random_gp_dialog.cpp index 41ab3facb..5a7406e5e 100644 --- a/src/states_screens/dialogs/random_gp_dialog.cpp +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -82,7 +82,7 @@ void RandomGPInfoDialog::addSpinners() spinner->addLabel("all"); int index_standard; const std::vector& groups = track_manager->getAllTrackGroups(); - for (unsigned int i = 0; i < groups.size() + 1; i++) + for (unsigned int i = 0; i < groups.size(); i++) { // FIXME: The NULL check is necessary until #1348 on github is fixed if (groups[i].c_str() != NULL) From e9acaa8e4da13aca131530bb4087039d61d6c932 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Mon, 23 Jun 2014 19:34:29 -0400 Subject: [PATCH 049/121] Do not hardcode minimap size --- src/states_screens/race_gui.cpp | 3 ++- src/states_screens/race_gui_overworld.cpp | 3 ++- src/tracks/quad_graph.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index 700f955fa..8bc797412 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -361,7 +361,8 @@ void RaceGUI::drawGlobalMiniMap() else if (new_rtt_mini_map != NULL) { core::rect source(0, 0, new_rtt_mini_map->getWidth(), new_rtt_mini_map->getHeight()); - draw2DImageFromRTT(new_rtt_mini_map->getRTT()[0], 512, 512, + draw2DImageFromRTT(new_rtt_mini_map->getRTT()[0], + new_rtt_mini_map->getWidth(), new_rtt_mini_map->getHeight(), dest, source, NULL, true); } diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index 208bd2360..b5312fbe5 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -338,7 +338,8 @@ void RaceGUIOverworld::drawGlobalMiniMap() else if (new_rtt_mini_map != NULL) { core::rect source(0, 0, new_rtt_mini_map->getWidth(), new_rtt_mini_map->getHeight()); - draw2DImageFromRTT(new_rtt_mini_map->getRTT()[0], 512, 512, + draw2DImageFromRTT(new_rtt_mini_map->getRTT()[0], + new_rtt_mini_map->getWidth(), new_rtt_mini_map->getHeight(), dest, source, NULL, true); } diff --git a/src/tracks/quad_graph.cpp b/src/tracks/quad_graph.cpp index b0edf1274..c35953f1b 100644 --- a/src/tracks/quad_graph.cpp +++ b/src/tracks/quad_graph.cpp @@ -985,7 +985,7 @@ void QuadGraph::makeMiniMap(const core::dimension2du &dimension, IrrDriver::RTTProvider* oldRttProvider = NULL; if (irr_driver->isGLSL()) { - newRttProvider = new RTT(512, 512); + newRttProvider = new RTT(dimension.Width, dimension.Height); } else { From 4c3cce42ee1ab481518f5471786c0d66d1ca75cf Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Mon, 23 Jun 2014 19:45:48 -0400 Subject: [PATCH 050/121] new minimap RTT fixes, getting there! --- src/graphics/rtts.cpp | 7 +++++-- src/graphics/rtts.hpp | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index ff15cc586..924d43385 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -74,6 +74,8 @@ static GLuint generateFBO(GLuint ColorAttachement, GLuint DepthAttachement) RTT::RTT(size_t width, size_t height) { + m_width = width; + m_height = height; m_shadow_FBO = NULL; m_RH_FBO = NULL; m_RSM = NULL; @@ -292,12 +294,13 @@ FrameBuffer* RTT::render(scene::ICameraSceneNode* camera, float dt) irr_driver->getSceneManager()->setActiveCamera(camera); std::vector glows; - irr_driver->computeCameraMatrix(camera, 512, 512); + irr_driver->computeCameraMatrix(camera, m_width, m_height); unsigned plc = irr_driver->UpdateLightsInfo(camera, dt); irr_driver->renderScene(camera, plc, glows, dt, false, true); FrameBuffer* frame_buffer = irr_driver->getPostProcessing()->render(camera, false); - glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height); + // reset + glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height); irr_driver->setRTT(NULL); glBindFramebuffer(GL_FRAMEBUFFER, 0); diff --git a/src/graphics/rtts.hpp b/src/graphics/rtts.hpp index 802001eca..e93f1edf1 100644 --- a/src/graphics/rtts.hpp +++ b/src/graphics/rtts.hpp @@ -53,6 +53,9 @@ private: PtrVector FrameBuffers; unsigned DepthStencilTexture; + int m_width; + int m_height; + unsigned shadowColorTex, shadowNormalTex, shadowDepthTex; unsigned RSM_Color, RSM_Normal, RSM_Depth; unsigned RH_Red, RH_Green, RH_Blue; From 9ed57bdd461174b50976ecb1e7818d586e868619 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Mon, 23 Jun 2014 20:09:54 -0400 Subject: [PATCH 051/121] Set ambient light when rendering minimap --- src/tracks/quad_graph.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tracks/quad_graph.cpp b/src/tracks/quad_graph.cpp index c35953f1b..b657d5464 100644 --- a/src/tracks/quad_graph.cpp +++ b/src/tracks/quad_graph.cpp @@ -992,6 +992,8 @@ void QuadGraph::makeMiniMap(const core::dimension2du &dimension, oldRttProvider = new IrrDriver::RTTProvider(dimension, name, true); } + irr_driver->getSceneManager()->setAmbientLight(video::SColor(255, 255, 255, 255)); + video::SColor red(128, 255, 0, 0); createMesh(/*show_invisible part of the track*/ false, /*enable_transparency*/ false, From 79838bffe3d198bf3e04e821378c21df1fe996e5 Mon Sep 17 00:00:00 2001 From: vlj Date: Thu, 26 Jun 2014 00:46:55 +0200 Subject: [PATCH 052/121] Add 50% transparency to minimap. --- data/shaders/uniformcolortexturedquad.frag | 2 +- src/graphics/glwrap.cpp | 13 ++++++++++--- src/graphics/glwrap.hpp | 2 +- src/guiengine/skin.cpp | 2 +- src/states_screens/race_gui.cpp | 2 +- src/states_screens/race_gui_overworld.cpp | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/data/shaders/uniformcolortexturedquad.frag b/data/shaders/uniformcolortexturedquad.frag index a4208f639..608da17ec 100644 --- a/data/shaders/uniformcolortexturedquad.frag +++ b/data/shaders/uniformcolortexturedquad.frag @@ -12,5 +12,5 @@ varying vec2 uv; void main() { vec4 res = texture(tex, uv); - FragColor = vec4(res.xyz * color.xyz / 255., res.a); + FragColor = res * color / 255.; } diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 37f6cefe1..75e311bc0 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -779,7 +779,7 @@ void draw2DImage(const video::ITexture* texture, const core::rect& destRect void draw2DImageFromRTT(GLuint texture, size_t texture_w, size_t texture_h, const core::rect& destRect, const core::rect& sourceRect, const core::rect* clipRect, - bool useAlphaChannelOfTexture) + const video::SColor &colors, bool useAlphaChannelOfTexture) { if (useAlphaChannelOfTexture) { @@ -794,9 +794,16 @@ void draw2DImageFromRTT(GLuint texture, size_t texture_w, size_t texture_h, getSize(texture_w, texture_h, true, destRect, sourceRect, width, height, center_pos_x, center_pos_y, tex_width, tex_height, tex_center_pos_x, tex_center_pos_y); - drawTexQuad(texture, width, height, center_pos_x, center_pos_y, - tex_center_pos_x, tex_center_pos_y, tex_width, tex_height); + glUseProgram(UIShader::UniformColoredTextureRectShader::Program); + glBindVertexArray(UIShader::UniformColoredTextureRectShader::vao); + + setTexture(0, texture, GL_LINEAR, GL_LINEAR); + UIShader::UniformColoredTextureRectShader::setUniforms(center_pos_x, center_pos_y, width, height, tex_center_pos_x, tex_center_pos_y, tex_width, tex_height, colors, 0); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); } void draw2DImage(const video::ITexture* texture, const core::rect& destRect, diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index 9a735b3ec..1457a1e4e 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -224,7 +224,7 @@ void draw3DLine(const core::vector3df& start, void draw2DImageFromRTT(GLuint texture, size_t texture_w, size_t texture_h, const core::rect& destRect, const core::rect& sourceRect, const core::rect* clipRect, - bool useAlphaChannelOfTexture); + const video::SColor &colors, bool useAlphaChannelOfTexture); void draw2DImage(const irr::video::ITexture* texture, const irr::core::rect& destRect, const irr::core::rect& sourceRect, const irr::core::rect* clipRect, diff --git a/src/guiengine/skin.cpp b/src/guiengine/skin.cpp index 1f4048017..af78b6315 100644 --- a/src/guiengine/skin.cpp +++ b/src/guiengine/skin.cpp @@ -1922,7 +1922,7 @@ void Skin::process3DPane(IGUIElement *element, const core::recti &rect, if (fb != NULL && fb->getRTT().size() > 0) { draw2DImageFromRTT(fb->getRTT()[0], 512, 512, - rect, core::rect(0, 0, 512, 512), NULL, true); + rect, core::rect(0, 0, 512, 512), NULL, SColor(255, 255, 255, 255), true); } } else if (type == WTYPE_ICON_BUTTON || type == WTYPE_MODEL_VIEW) diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index 8bc797412..38b43a193 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -363,7 +363,7 @@ void RaceGUI::drawGlobalMiniMap() core::rect source(0, 0, new_rtt_mini_map->getWidth(), new_rtt_mini_map->getHeight()); draw2DImageFromRTT(new_rtt_mini_map->getRTT()[0], new_rtt_mini_map->getWidth(), new_rtt_mini_map->getHeight(), - dest, source, NULL, true); + dest, source, NULL, video::SColor(127, 255, 255, 255), true); } for(unsigned int i=0; igetNumKarts(); i++) diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index b5312fbe5..a2a7299f8 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -340,7 +340,7 @@ void RaceGUIOverworld::drawGlobalMiniMap() core::rect source(0, 0, new_rtt_mini_map->getWidth(), new_rtt_mini_map->getHeight()); draw2DImageFromRTT(new_rtt_mini_map->getRTT()[0], new_rtt_mini_map->getWidth(), new_rtt_mini_map->getHeight(), - dest, source, NULL, true); + dest, source, NULL, video::SColor(127, 255, 255, 255), true); } Vec3 kart_xyz; From 0fa746c805365fe4ea07f5e34a203515701dc382 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Thu, 26 Jun 2014 12:09:22 +0200 Subject: [PATCH 053/121] Changes to stk_config to make 3 groups of karts, which will default to the medium, and can be set in the kart.xml --- data/stk_config.xml | 193 ++++++++++++++++---- src/karts/kart_properties.cpp | 321 +++++++++++++++++++--------------- src/karts/kart_properties.hpp | 4 + 3 files changed, 338 insertions(+), 180 deletions(-) diff --git a/data/stk_config.xml b/data/stk_config.xml index a2e4e4d2d..2b6056c07 100644 --- a/data/stk_config.xml +++ b/data/stk_config.xml @@ -145,6 +145,7 @@ + - - - - - - - - - + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index 203704ea9..e6694a803 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -172,7 +172,9 @@ void KartProperties::load(const std::string &filename, const std::string &node) { // Get the default values from STKConfig. This will also allocate any // pointers used in KartProperties + copyFrom(&stk_config->getDefaultKartProperties()); + // m_kart_model must be initialised after assigning the default // values from stk_config (otherwise all kart_properties will // share the same KartModel @@ -286,7 +288,7 @@ void KartProperties::load(const std::string &filename, const std::string &node) */ void KartProperties::getAllData(const XMLNode * root) { - root->get("version", &m_version); + root->get("version", &m_version); root->get("name", &m_name ); @@ -307,50 +309,32 @@ void KartProperties::getAllData(const XMLNode * root) root->get("shadow-x-offset", &m_shadow_x_offset ); root->get("shadow-y-offset", &m_shadow_y_offset ); + if(const XMLNode *props_group = root->getNode("properties")) { + props_group->get("group", &m_kart_type ); + } + else + { + root->get("kart-type", &m_kart_type ); + } + + if(const XMLNode *kart_type = root->getNode("kart-type")) + { + getProperties(kart_type->getNode(m_kart_type)); + } + else + { + //When we load in kart.xml values, we first set the correct type + //After we have done that, we can still enter kart-specific values + const XMLNode* config_root = new XMLNode(file_manager->getAsset("stk_config.xml")); + getProperties(config_root->getNode("general-kart-defaults")->getNode("kart-type")->getNode(m_kart_type)); + getProperties(root); + } + + + if(const XMLNode *dimensions_node = root->getNode("center")) dimensions_node->get("gravity-shift", &m_gravity_center_shift); - if(const XMLNode *nitro_node = root->getNode("nitro")) - { - nitro_node->get("consumption", &m_nitro_consumption ); - nitro_node->get("small-container", &m_nitro_small_container ); - nitro_node->get("big-container", &m_nitro_big_container ); - nitro_node->get("max-speed-increase", &m_nitro_max_speed_increase); - nitro_node->get("engine-force", &m_nitro_engine_force ); - nitro_node->get("duration", &m_nitro_duration ); - nitro_node->get("fade-out-time", &m_nitro_fade_out_time ); - nitro_node->get("max", &m_nitro_max ); - nitro_node->get("min-consumption-time", &m_nitro_min_consumption ); - } - - if(const XMLNode *bubble_node = root->getNode("bubblegum")) - { - bubble_node->get("time", &m_bubblegum_time ); - bubble_node->get("speed-fraction", &m_bubblegum_speed_fraction); - bubble_node->get("fade-in-time", &m_bubblegum_fade_in_time ); - bubble_node->get("torque", &m_bubblegum_torque ); - } - - if(const XMLNode *rescue_node = root->getNode("rescue")) - { - rescue_node->get("vert-offset", &m_rescue_vert_offset); - rescue_node->get("time", &m_rescue_time ); - rescue_node->get("height", &m_rescue_height ); - } - - if(const XMLNode *explosion_node = root->getNode("explosion")) - { - explosion_node->get("time", &m_explosion_time ); - explosion_node->get("radius", &m_explosion_radius); - explosion_node->get("invulnerability-time", - &m_explosion_invulnerability_time); - } - - if(const XMLNode *skid_node = root->getNode("skid")) - { - m_skidding_properties->load(skid_node); - } - if(const XMLNode *ai_node = root->getNode("ai")) { const XMLNode *easy = ai_node->getNode("easy"); @@ -363,59 +347,6 @@ void KartProperties::getAllData(const XMLNode * root) m_ai_properties[RaceManager::DIFFICULTY_BEST]->load(best); } - if(const XMLNode *slipstream_node = root->getNode("slipstream")) - { - slipstream_node->get("length", &m_slipstream_length ); - slipstream_node->get("width", &m_slipstream_width ); - slipstream_node->get("collect-time", &m_slipstream_collect_time ); - slipstream_node->get("use-time", &m_slipstream_use_time ); - slipstream_node->get("add-power", &m_slipstream_add_power ); - slipstream_node->get("min-speed", &m_slipstream_min_speed ); - slipstream_node->get("max-speed-increase", - &m_slipstream_max_speed_increase); - slipstream_node->get("duration", &m_slipstream_duration ); - slipstream_node->get("fade-out-time",&m_slipstream_fade_out_time ); - } - - if(const XMLNode *turn_node = root->getNode("turn")) - { - turn_node->get("time-full-steer", &m_time_full_steer ); - turn_node->get("time-reset-steer", &m_time_reset_steer ); - turn_node->get("turn-radius", &m_turn_angle_at_speed ); - // For now store the turn radius in turn angle, the correct - // value can only be determined later in ::load - } - - if(const XMLNode *engine_node = root->getNode("engine")) - { - engine_node->get("brake-factor", &m_brake_factor); - engine_node->get("max-speed-reverse-ratio", &m_max_speed_reverse_ratio); - engine_node->get("power", &m_engine_power); - if(m_engine_power.size()!=RaceManager::DIFFICULTY_COUNT) - { - Log::fatal("[KartProperties]", - "Incorrect engine-power specifications for kart '%s'", - getIdent().c_str()); - } - engine_node->get("max-speed", &m_max_speed); - if(m_max_speed.size()!=RaceManager::DIFFICULTY_COUNT) - { - Log::fatal("[KartProperties]", - "Incorrect max-speed specifications for kart '%s'", - getIdent().c_str()); - } - } // if getNode("engine") - - if(const XMLNode *gear_node = root->getNode("gear")) - { - gear_node->get("switch-ratio", &m_gear_switch_ratio ); - gear_node->get("power-increase", &m_gear_power_increase); - } - - if(const XMLNode *mass_node = root->getNode("mass")) - mass_node->get("value", &m_mass); - - if(const XMLNode *suspension_node = root->getNode("suspension")) { suspension_node->get("stiffness", &m_suspension_stiffness); @@ -488,50 +419,6 @@ void KartProperties::getAllData(const XMLNode * root) //TODO: listed as an attribute in the xml file after wheel-radius //TODO: same goes for their rear equivalents - if(const XMLNode *plunger_node= root->getNode("plunger")) - { - plunger_node->get("band-max-length", &m_rubber_band_max_length ); - plunger_node->get("band-force", &m_rubber_band_force ); - plunger_node->get("band-duration", &m_rubber_band_duration ); - plunger_node->get("band-speed-increase",&m_rubber_band_speed_increase); - plunger_node->get("band-fade-out-time", &m_rubber_band_fade_out_time ); - plunger_node->get("in-face-time", &m_plunger_in_face_duration); - if(m_plunger_in_face_duration.size()!=RaceManager::DIFFICULTY_COUNT) - { - Log::fatal("KartProperties", - "Invalid plunger in-face-time specification."); - } - } - - if(const XMLNode *zipper_node= root->getNode("zipper")) - { - zipper_node->get("time", &m_zipper_time ); - zipper_node->get("fade-out-time", &m_zipper_fade_out_time ); - zipper_node->get("force", &m_zipper_force ); - zipper_node->get("speed-gain", &m_zipper_speed_gain ); - zipper_node->get("max-speed-increase", &m_zipper_max_speed_increase); - } - - if(const XMLNode *swatter_node= root->getNode("swatter")) - { - swatter_node->get("duration", &m_swatter_duration ); - swatter_node->get("squash-duration", &m_squash_duration ); - swatter_node->get("squash-slowdown", &m_squash_slowdown ); - if(swatter_node->get("distance", &m_swatter_distance2) ) - { - // Avoid squaring if distance is not defined, so that - // distance2 remains UNDEFINED (which is a negative value) - m_swatter_distance2 *= m_swatter_distance2; - } - } - - if(const XMLNode *lean_node= root->getNode("lean")) - { - lean_node->get("max", &m_max_lean ); - lean_node->get("speed", &m_lean_speed); - m_max_lean *= DEGREE_TO_RAD; - m_lean_speed *= DEGREE_TO_RAD; - } if(const XMLNode *jump_node= root->getNode("jump")) { @@ -547,12 +434,6 @@ void KartProperties::getAllData(const XMLNode * root) m_camera_backward_up_angle *= DEGREE_TO_RAD; } - if(const XMLNode *startup_node= root->getNode("startup")) - { - startup_node->get("time", &m_startup_times); - startup_node->get("boost", &m_startup_boost); - } - if(const XMLNode *sounds_node= root->getNode("sounds")) { std::string s; @@ -755,6 +636,156 @@ bool KartProperties::isInGroup(const std::string &group) const return std::find(m_groups.begin(), m_groups.end(), group) != m_groups.end(); } // isInGroups +void KartProperties::getProperties(const XMLNode* root) +{ + + if(const XMLNode *nitro_node = root->getNode("nitro")) + { + nitro_node->get("consumption", &m_nitro_consumption ); + nitro_node->get("small-container", &m_nitro_small_container ); + nitro_node->get("big-container", &m_nitro_big_container ); + nitro_node->get("max-speed-increase", &m_nitro_max_speed_increase); + nitro_node->get("engine-force", &m_nitro_engine_force ); + nitro_node->get("duration", &m_nitro_duration ); + nitro_node->get("fade-out-time", &m_nitro_fade_out_time ); + nitro_node->get("max", &m_nitro_max ); + nitro_node->get("min-consumption-time", &m_nitro_min_consumption ); + } + + if(const XMLNode *bubble_node = root->getNode("bubblegum")) + { + bubble_node->get("time", &m_bubblegum_time ); + bubble_node->get("speed-fraction", &m_bubblegum_speed_fraction); + bubble_node->get("fade-in-time", &m_bubblegum_fade_in_time ); + bubble_node->get("torque", &m_bubblegum_torque ); + } + + if(const XMLNode *rescue_node = root->getNode("rescue")) + { + rescue_node->get("vert-offset", &m_rescue_vert_offset); + rescue_node->get("time", &m_rescue_time ); + rescue_node->get("height", &m_rescue_height ); + } + + if(const XMLNode *explosion_node = root->getNode("explosion")) + { + explosion_node->get("time", &m_explosion_time ); + explosion_node->get("radius", &m_explosion_radius); + explosion_node->get("invulnerability-time", + &m_explosion_invulnerability_time); + } + + if(const XMLNode *skid_node = root->getNode("skid")) + { + m_skidding_properties->load(skid_node); + } + + + if(const XMLNode *slipstream_node = root->getNode("slipstream")) + { + slipstream_node->get("length", &m_slipstream_length ); + slipstream_node->get("width", &m_slipstream_width ); + slipstream_node->get("collect-time", &m_slipstream_collect_time ); + slipstream_node->get("use-time", &m_slipstream_use_time ); + slipstream_node->get("add-power", &m_slipstream_add_power ); + slipstream_node->get("min-speed", &m_slipstream_min_speed ); + slipstream_node->get("max-speed-increase", + &m_slipstream_max_speed_increase); + slipstream_node->get("duration", &m_slipstream_duration ); + slipstream_node->get("fade-out-time",&m_slipstream_fade_out_time ); + } + + if(const XMLNode *turn_node = root->getNode("turn")) + { + turn_node->get("time-full-steer", &m_time_full_steer ); + turn_node->get("time-reset-steer", &m_time_reset_steer ); + turn_node->get("turn-radius", &m_turn_angle_at_speed ); + // For now store the turn radius in turn angle, the correct + // value can only be determined later in ::load + } + + if(const XMLNode *engine_node = root->getNode("engine")) + { + engine_node->get("brake-factor", &m_brake_factor); + engine_node->get("max-speed-reverse-ratio", &m_max_speed_reverse_ratio); + engine_node->get("power", &m_engine_power); + if(m_engine_power.size()!=RaceManager::DIFFICULTY_COUNT) + { + Log::fatal("[KartProperties]", + "Incorrect engine-power specifications for kart '%s'", + getIdent().c_str()); + } + engine_node->get("max-speed", &m_max_speed); + if(m_max_speed.size()!=RaceManager::DIFFICULTY_COUNT) + { + Log::fatal("[KartProperties]", + "Incorrect max-speed specifications for kart '%s'", + getIdent().c_str()); + } + } // if getNode("engine") + + if(const XMLNode *gear_node = root->getNode("gear")) + { + gear_node->get("switch-ratio", &m_gear_switch_ratio ); + gear_node->get("power-increase", &m_gear_power_increase); + } + + if(const XMLNode *mass_node = root->getNode("mass")) + mass_node->get("value", &m_mass); + + if(const XMLNode *plunger_node= root->getNode("plunger")) + { + plunger_node->get("band-max-length", &m_rubber_band_max_length ); + plunger_node->get("band-force", &m_rubber_band_force ); + plunger_node->get("band-duration", &m_rubber_band_duration ); + plunger_node->get("band-speed-increase",&m_rubber_band_speed_increase); + plunger_node->get("band-fade-out-time", &m_rubber_band_fade_out_time ); + plunger_node->get("in-face-time", &m_plunger_in_face_duration); + if(m_plunger_in_face_duration.size()!=RaceManager::DIFFICULTY_COUNT) + { + Log::fatal("KartProperties", + "Invalid plunger in-face-time specification."); + } + } + + if(const XMLNode *zipper_node= root->getNode("zipper")) + { + zipper_node->get("time", &m_zipper_time ); + zipper_node->get("fade-out-time", &m_zipper_fade_out_time ); + zipper_node->get("force", &m_zipper_force ); + zipper_node->get("speed-gain", &m_zipper_speed_gain ); + zipper_node->get("max-speed-increase", &m_zipper_max_speed_increase); + } + + if(const XMLNode *swatter_node= root->getNode("swatter")) + { + swatter_node->get("duration", &m_swatter_duration ); + swatter_node->get("squash-duration", &m_squash_duration ); + swatter_node->get("squash-slowdown", &m_squash_slowdown ); + if(swatter_node->get("distance", &m_swatter_distance2) ) + { + // Avoid squaring if distance is not defined, so that + // distance2 remains UNDEFINED (which is a negative value) + m_swatter_distance2 *= m_swatter_distance2; + } + } + + if(const XMLNode *lean_node= root->getNode("lean")) + { + lean_node->get("max", &m_max_lean ); + lean_node->get("speed", &m_lean_speed); + m_max_lean *= DEGREE_TO_RAD; + m_lean_speed *= DEGREE_TO_RAD; + } + + if(const XMLNode *startup_node= root->getNode("startup")) + { + startup_node->get("time", &m_startup_times); + startup_node->get("boost", &m_startup_boost); + } +} + + // ---------------------------------------------------------------------------- /** Called the first time a kart accelerates after 'ready-set-go'. It searches * through m_startup_times to find the appropriate slot, and returns the diff --git a/src/karts/kart_properties.hpp b/src/karts/kart_properties.hpp index 621b14cec..f9f90cf76 100644 --- a/src/karts/kart_properties.hpp +++ b/src/karts/kart_properties.hpp @@ -181,6 +181,9 @@ private: */ float m_nitro_min_consumption; + /** Type of the kart (for the properties) */ + std::string m_kart_type; + /** Filename of the wheel models. */ std::string m_wheel_filename[4]; /** Radius of the graphical wheels. */ @@ -389,6 +392,7 @@ public: float getStartupBoost () const; bool isInGroup (const std::string &group) const; bool operator<(const KartProperties &other) const; + void getProperties (const XMLNode * root); // ------------------------------------------------------------------------ /** Returns the (maximum) speed for a given turn radius. From c3e862f40c4d5e9cccc36ded21aff36fb6d5ea6f Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Thu, 26 Jun 2014 12:53:17 +0200 Subject: [PATCH 054/121] fix for different kart properties, now based on kart type set in kart.xml --- data/stk_config.xml | 403 +++++++++++++++++----------------- src/karts/kart_properties.cpp | 2 +- 2 files changed, 202 insertions(+), 203 deletions(-) diff --git a/data/stk_config.xml b/data/stk_config.xml index 2b6056c07..eb329f6ce 100644 --- a/data/stk_config.xml +++ b/data/stk_config.xml @@ -163,49 +163,6 @@ shown. --> - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - + - + - + + fade-out-time="1.0" /> + visual="1.25" visual-time="0.7" revert-visual-time="0.7" + min-speed="10" time-till-bonus="1.0 3.0" + bonus-speed="4.5 6.5" bonus-time="3.0 4.0" + bonus-force="250 350" + physical-jump-time="0" graphical-jump-time="0.4" + post-skid-rotate-factor="1" + reduce-turn-min="0.2" reduce-turn-max="0.8"/> - + + squash-slowdown="0.5"/> - + - + - + - + + band-speed-increase="7" band-fade-out-time="3" + in-face-time="3 4 4.5 4.5"/> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index e6694a803..237863485 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -314,7 +314,7 @@ void KartProperties::getAllData(const XMLNode * root) } else { - root->get("kart-type", &m_kart_type ); + root->get("type", &m_kart_type ); } if(const XMLNode *kart_type = root->getNode("kart-type")) From 000fa2cf73d432000045727c1e08a205bfa6511b Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Thu, 26 Jun 2014 13:43:53 +0200 Subject: [PATCH 055/121] Fixed skill bars to return correct values. Also minor fix in kart properties --- data/stk_config.xml | 6 +++--- src/guiengine/widgets/kart_stats_widget.cpp | 8 ++++---- src/states_screens/kart_selection.cpp | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/data/stk_config.xml b/data/stk_config.xml index eb329f6ce..48ae0c06e 100644 --- a/data/stk_config.xml +++ b/data/stk_config.xml @@ -574,8 +574,8 @@ - - @@ -677,7 +677,7 @@ time-full-steer ="0:0.23 0.5:0.23 0.5:0.41 1.0:0.41" time-reset-steer="0.1"/> - diff --git a/src/guiengine/widgets/kart_stats_widget.cpp b/src/guiengine/widgets/kart_stats_widget.cpp index 2db661fe5..a6e25985a 100644 --- a/src/guiengine/widgets/kart_stats_widget.cpp +++ b/src/guiengine/widgets/kart_stats_widget.cpp @@ -91,16 +91,16 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, m_children.push_back(skill_bar); } - m_skills[SKILL_MASS]->setValue(props->getMass()/10); + m_skills[SKILL_MASS]->setValue((int)(props->getMass()/5)); m_skills[SKILL_MASS]->setLabel("WEIGHT"); m_skills[SKILL_MASS]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); - m_skills[SKILL_ACCEL]->setValue(props->getTrackConnectionAccel()/10); + m_skills[SKILL_ACCEL]->setValue((int)((props->getMaxSpeed()-20)*20)); m_skills[SKILL_ACCEL]->setLabel("ACCEL"); m_skills[SKILL_ACCEL]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_accel", m_player_id); - m_skills[SKILL_SPEED]->setValue(props->getMaxSpeed()/10); - m_skills[SKILL_SPEED]->setLabel("SPEED"); + m_skills[SKILL_SPEED]->setValue((int)(props->getMaxPower()/10)); + m_skills[SKILL_SPEED]->setLabel("POWER"); m_skills[SKILL_SPEED]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_speed", m_player_id); } // KartStatsWidget diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index baa8e1dbe..1cdd91364 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -1526,9 +1526,9 @@ void KartSelectionScreen::updateKartStats(uint8_t widget_id, kart_properties_manager->getKart(selection); if (kp != NULL) { - w->setValue(KartStatsWidget::SKILL_MASS, (int)kp->getMass()/10); - w->setValue(KartStatsWidget::SKILL_SPEED, (int)kp->getMaxSpeed()/10); - w->setValue(KartStatsWidget::SKILL_ACCEL, (int)kp->getTrackConnectionAccel()/10); + w->setValue(KartStatsWidget::SKILL_MASS, (int)(kp->getMass()/5)); + w->setValue(KartStatsWidget::SKILL_SPEED, (int)(kp->getMaxPower()/10)); + w->setValue(KartStatsWidget::SKILL_ACCEL, (int)((kp->getMaxSpeed()-20)*20)); w->update(0); } } From 21cb22f13a4447f83298f3f9b7fb6c6b0fbe14c5 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Thu, 26 Jun 2014 21:43:47 -0400 Subject: [PATCH 056/121] Workaround crash. Vlj, please look at this, this is probably not an idea fix! --- src/graphics/render.cpp | 18 +++++++++++------- src/utils/vec3.hpp | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index b1cce9a83..12a294598 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -837,13 +837,17 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz { core::aabbox3df trackbox(vmin->toIrrVector(), vmax->toIrrVector() - core::vector3df(0, 30, 0)); - SunCamViewMatrix.transformBoxEx(trackbox); - core::matrix4 tmp_matrix; - tmp_matrix.buildProjectionMatrixOrthoLH(trackbox.MinEdge.X, trackbox.MaxEdge.X, - trackbox.MaxEdge.Y, trackbox.MinEdge.Y, - 30, trackbox.MaxEdge.Z); - m_suncam->setProjectionMatrix(tmp_matrix, true); - m_suncam->render(); + if (trackbox.MinEdge.X != trackbox.MaxEdge.X && + trackbox.MinEdge.Y != trackbox.MaxEdge.Y) + { + SunCamViewMatrix.transformBoxEx(trackbox); + core::matrix4 tmp_matrix; + tmp_matrix.buildProjectionMatrixOrthoLH(trackbox.MinEdge.X, trackbox.MaxEdge.X, + trackbox.MaxEdge.Y, trackbox.MinEdge.Y, + 30, trackbox.MaxEdge.Z); + m_suncam->setProjectionMatrix(tmp_matrix, true); + m_suncam->render(); + } rsm_matrix = getVideoDriver()->getTransform(video::ETS_PROJECTION) * getVideoDriver()->getTransform(video::ETS_VIEW); } rh_extend = core::vector3df(128, 64, 128); diff --git a/src/utils/vec3.hpp b/src/utils/vec3.hpp index c52e6d7e8..0d3905869 100644 --- a/src/utils/vec3.hpp +++ b/src/utils/vec3.hpp @@ -51,7 +51,7 @@ public: inline Vec3(const btVector3& a) : btVector3(a) {} // ------------------------------------------------------------------------ /** Empty constructor. */ - inline Vec3() : btVector3() {} + inline Vec3() : btVector3(0, 0, 0) {} // ------------------------------------------------------------------------ /** Creates a 3d vector from three scalars. */ inline Vec3(float x, float y, float z) : btVector3(x,y,z) {} From 109f783fa4ebe0ac8f98c89f08438249c8e62756 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Fri, 27 Jun 2014 23:26:02 +0200 Subject: [PATCH 057/121] Finally implemented the correct way to parse the data --- data/stk_config.xml | 60 ++++++++++++++++++++++++++++++++++- src/config/stk_config.cpp | 10 ++++++ src/config/stk_config.hpp | 5 +++ src/karts/kart_properties.cpp | 25 ++++----------- 4 files changed, 81 insertions(+), 19 deletions(-) diff --git a/data/stk_config.xml b/data/stk_config.xml index 48ae0c06e..835aee371 100644 --- a/data/stk_config.xml +++ b/data/stk_config.xml @@ -145,7 +145,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -591,6 +645,8 @@ + + @@ -642,6 +698,8 @@ + + diff --git a/src/config/stk_config.cpp b/src/config/stk_config.cpp index c904349de..936e6eb27 100644 --- a/src/config/stk_config.cpp +++ b/src/config/stk_config.cpp @@ -380,6 +380,16 @@ void STKConfig::getAllData(const XMLNode * root) throw std::runtime_error(msg.str()); } m_default_kart_properties->getAllData(node); + const XMLNode *types = node->getNode("kart-type"); + m_default_kart_properties->getProperties(types->getNode("default")); + + for (int i = 0; i < types->getNumNodes(); ++i) + { + const XMLNode* type = types->getNode(i); + m_kart_properties[type->getName()] = new KartProperties(); + m_kart_properties[type->getName()]->copyFrom(m_default_kart_properties); + m_kart_properties[type->getName()]->getProperties(type); + } } // getAllData diff --git a/src/config/stk_config.hpp b/src/config/stk_config.hpp index 3ccbc82f5..0a94d3db8 100644 --- a/src/config/stk_config.hpp +++ b/src/config/stk_config.hpp @@ -30,6 +30,7 @@ #include #include +#include class KartProperties; class MusicInformation; @@ -47,6 +48,7 @@ class STKConfig : public NoCopy protected: /** Default kart properties. */ KartProperties *m_default_kart_properties; + std::map m_kart_properties; public: /** What to do if a kart already has a powerup when it hits a bonus box: @@ -170,6 +172,9 @@ public: /** Returns the default kart properties for each kart. */ const KartProperties & getDefaultKartProperties() const {return *m_default_kart_properties; } + + const KartProperties & + getKartProperties(std::string type) { return *m_kart_properties[type]; } } ; // STKConfig diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index 237863485..7d53e0bc6 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -173,14 +173,18 @@ void KartProperties::load(const std::string &filename, const std::string &node) // Get the default values from STKConfig. This will also allocate any // pointers used in KartProperties - copyFrom(&stk_config->getDefaultKartProperties()); + const XMLNode* root = new XMLNode(filename); + std::string kart_type; + if (root->get("type", &kart_type)) + copyFrom(&stk_config->getKartProperties(kart_type)); + else + copyFrom(&stk_config->getDefaultKartProperties()); // m_kart_model must be initialised after assigning the default // values from stk_config (otherwise all kart_properties will // share the same KartModel m_kart_model = new KartModel(/*is_master*/true); - const XMLNode * root = 0; m_root = StringUtils::getPath(filename)+"/"; m_ident = StringUtils::getBasename(StringUtils::getPath(filename)); // If this is an addon kart, add "addon_" to the identifier - just in @@ -190,7 +194,6 @@ void KartProperties::load(const std::string &filename, const std::string &node) m_ident = Addon::createAddonId(m_ident); try { - root = new XMLNode(filename); if(!root || root->getName()!="kart") { std::ostringstream msg; @@ -201,6 +204,7 @@ void KartProperties::load(const std::string &filename, const std::string &node) throw std::runtime_error(msg.str()); } getAllData(root); + getProperties(root); } catch(std::exception& err) { @@ -317,21 +321,6 @@ void KartProperties::getAllData(const XMLNode * root) root->get("type", &m_kart_type ); } - if(const XMLNode *kart_type = root->getNode("kart-type")) - { - getProperties(kart_type->getNode(m_kart_type)); - } - else - { - //When we load in kart.xml values, we first set the correct type - //After we have done that, we can still enter kart-specific values - const XMLNode* config_root = new XMLNode(file_manager->getAsset("stk_config.xml")); - getProperties(config_root->getNode("general-kart-defaults")->getNode("kart-type")->getNode(m_kart_type)); - getProperties(root); - } - - - if(const XMLNode *dimensions_node = root->getNode("center")) dimensions_node->get("gravity-shift", &m_gravity_center_shift); From 8f59d8cac09a651ff8f96778b7a7f7eff570a0a6 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 28 Jun 2014 00:20:44 +0200 Subject: [PATCH 058/121] Add a weight for vignette. --- data/shaders/tonemap.frag | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/shaders/tonemap.frag b/data/shaders/tonemap.frag index c0a183da8..7982e66cb 100644 --- a/data/shaders/tonemap.frag +++ b/data/shaders/tonemap.frag @@ -4,6 +4,7 @@ uniform sampler2D tex; uniform sampler2D logluminancetex; uniform float exposure = .09; uniform float Lwhite = 1.; +uniform float vignette_weight = 0.; layout (std140) uniform MatrixesData { @@ -43,12 +44,11 @@ void main() // Uncharted2 tonemap with Auria's custom coefficients vec4 perChannel = (col * (6.9 * col + .5)) / (col * (5.2 * col + 1.7) + 0.06); perChannel = pow(perChannel, vec4(2.2)); - + vec2 inside = uv - 0.5; - float vignette = 1 - dot(inside, inside); + float vignette = 1. - dot(inside, inside) * vignette_weight; vignette = clamp(pow(vignette, 0.8), 0., 1.); //vignette = clamp(vignette + vignette - 0.5, 0., 1.15); - FragColor = vec4(perChannel.xyz * vignette, col.a); } From 14cfa57f2ac323c8e38e7fef5b758bde322afa35 Mon Sep 17 00:00:00 2001 From: vlj Date: Sat, 28 Jun 2014 16:05:21 +0200 Subject: [PATCH 059/121] Change "faceness" of lap line. --- src/tracks/quad_graph.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tracks/quad_graph.cpp b/src/tracks/quad_graph.cpp index b657d5464..6152546e3 100644 --- a/src/tracks/quad_graph.cpp +++ b/src/tracks/quad_graph.cpp @@ -491,12 +491,12 @@ void QuadGraph::createMesh(bool show_invisible, lap_v[2].Pos = lap_v[1].Pos+core::vector3df(0, 0, 1); else lap_v[2].Pos = lap_v[1].Pos+dr*length/sqrt(lr2); - lap_ind[0] = 0; + lap_ind[0] = 2; lap_ind[1] = 1; - lap_ind[2] = 2; - lap_ind[3] = 0; + lap_ind[2] = 0; + lap_ind[3] = 3; lap_ind[4] = 2; - lap_ind[5] = 3; + lap_ind[5] = 0; // Set it a bit higher to avoid issued with z fighting, // i.e. part of the lap line might not be visible. for(unsigned int i=0; i<4; i++) From 621539849ab8ba12f61149054a483786c4728185 Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 30 Jun 2014 16:45:00 +1000 Subject: [PATCH 060/121] Removed unused code. --- src/physics/btKart.cpp | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/src/physics/btKart.cpp b/src/physics/btKart.cpp index 61e389909..c195e4535 100644 --- a/src/physics/btKart.cpp +++ b/src/physics/btKart.cpp @@ -323,35 +323,24 @@ btScalar btKart::rayCast(unsigned int index) #else if(index==2 || index==3) { - if(m_visual_rotation==0.123123123) + btTransform chassisTrans = getChassisWorldTransform(); + if (getRigidBody()->getMotionState()) { - m_visual_contact_point[index ] = rayResults.m_hitPointInWorld; - m_visual_contact_point[index-2] = source; - m_visual_wheels_touch_ground &= (object!=NULL); + getRigidBody()->getMotionState()->getWorldTransform(chassisTrans); } - else - { - btTransform chassisTrans = getChassisWorldTransform(); - if (getRigidBody()->getMotionState()) - { - getRigidBody()->getMotionState()->getWorldTransform(chassisTrans); - } - btQuaternion q(m_visual_rotation, 0, 0); - btQuaternion rot_new = chassisTrans.getRotation() * q; - chassisTrans.setRotation(rot_new); - btVector3 pos = m_kart->getKartModel()->getWheelGraphicsPosition(index); - pos.setZ(pos.getZ()*0.9f); - //pos.setX(pos.getX()*0.1f); - //btVector3 pos = wheel.m_chassisConnectionPointCS; - btVector3 source = chassisTrans( pos ); - btVector3 target = source + rayvector; - btVehicleRaycaster::btVehicleRaycasterResult rayResults; + btQuaternion q(m_visual_rotation, 0, 0); + btQuaternion rot_new = chassisTrans.getRotation() * q; + chassisTrans.setRotation(rot_new); + btVector3 pos = m_kart->getKartModel()->getWheelGraphicsPosition(index); + pos.setZ(pos.getZ()*0.9f); + btVector3 source = chassisTrans( pos ); + btVector3 target = source + rayvector; + btVehicleRaycaster::btVehicleRaycasterResult rayResults; - void* object = m_vehicleRaycaster->castRay(source,target,rayResults); - m_visual_contact_point[index] = rayResults.m_hitPointInWorld; - m_visual_contact_point[index-2] = source; - m_visual_wheels_touch_ground &= (object!=NULL); - } + void* object = m_vehicleRaycaster->castRay(source,target,rayResults); + m_visual_contact_point[index] = rayResults.m_hitPointInWorld; + m_visual_contact_point[index-2] = source; + m_visual_wheels_touch_ground &= (object!=NULL); } #endif From ff6af6b072afc70498b46d8cb5e93c7c6fe5b592 Mon Sep 17 00:00:00 2001 From: Deve Date: Mon, 30 Jun 2014 18:18:41 +0200 Subject: [PATCH 061/121] Change power of bouncy edges in soccer field as temporary solution for #1367. Ideally power of bounce should depend on soccer ball weight. --- src/physics/physical_object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/physics/physical_object.cpp b/src/physics/physical_object.cpp index 45eaeb564..f6a612336 100644 --- a/src/physics/physical_object.cpp +++ b/src/physics/physical_object.cpp @@ -580,7 +580,7 @@ void PhysicalObject::hit(const Material *m, const Vec3 &normal) if(isSoccerBall() && m != NULL && m->getCollisionReaction() == Material::PUSH_SOCCER_BALL) { - m_body->applyCentralImpulse(normal * 1000.0f); + m_body->applyCentralImpulse(normal * 100.0f); } } // hit From a73462759bdd250895812d5e330919ce85d62821 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Tue, 1 Jul 2014 10:37:00 +0200 Subject: [PATCH 062/121] Moved the default kart-type to to better catch missing values in the kart-type nodes. Also moved the documentation again to properly fit the fields. --- data/stk_config.xml | 341 ++++++++++++++++++-------------------- src/config/stk_config.cpp | 9 +- 2 files changed, 172 insertions(+), 178 deletions(-) diff --git a/data/stk_config.xml b/data/stk_config.xml index 835aee371..b2a086e5d 100644 --- a/data/stk_config.xml +++ b/data/stk_config.xml @@ -417,180 +417,173 @@ impulse="3000" impulse-time="0.1" terrain-impulse="8000" restitution="1.0" bevel-factor="0.5 0.0 0.5" /> - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -623,8 +616,6 @@ - - @@ -675,9 +666,7 @@ - - - + @@ -728,9 +717,7 @@ - - - + diff --git a/src/config/stk_config.cpp b/src/config/stk_config.cpp index 936e6eb27..fe7fdd599 100644 --- a/src/config/stk_config.cpp +++ b/src/config/stk_config.cpp @@ -50,6 +50,13 @@ STKConfig::~STKConfig() if(m_default_kart_properties) delete m_default_kart_properties; + + for(std::map::iterator it = m_kart_properties.begin(); + it != m_kart_properties.end(); ++it) + { + if (it->second) + delete it->second; + } } // ~STKConfig //----------------------------------------------------------------------------- @@ -380,8 +387,8 @@ void STKConfig::getAllData(const XMLNode * root) throw std::runtime_error(msg.str()); } m_default_kart_properties->getAllData(node); + m_default_kart_properties->getProperties(node); const XMLNode *types = node->getNode("kart-type"); - m_default_kart_properties->getProperties(types->getNode("default")); for (int i = 0; i < types->getNumNodes(); ++i) { From 1bbd29475060f6b00a98e8a5ee07bd3c2e49e338 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Tue, 1 Jul 2014 10:43:00 +0200 Subject: [PATCH 063/121] Forgot to add documentation to a single node --- data/stk_config.xml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/data/stk_config.xml b/data/stk_config.xml index b2a086e5d..1a85d5908 100644 --- a/data/stk_config.xml +++ b/data/stk_config.xml @@ -475,6 +475,38 @@ + Date: Tue, 1 Jul 2014 10:59:42 +0200 Subject: [PATCH 064/121] Final fix for properties, every missing field / overwrite should now be handled --- src/config/stk_config.cpp | 3 +- src/karts/kart_properties.cpp | 295 +++++++++++++++++----------------- src/karts/kart_properties.hpp | 1 - 3 files changed, 146 insertions(+), 153 deletions(-) diff --git a/src/config/stk_config.cpp b/src/config/stk_config.cpp index fe7fdd599..2607f08ab 100644 --- a/src/config/stk_config.cpp +++ b/src/config/stk_config.cpp @@ -387,7 +387,6 @@ void STKConfig::getAllData(const XMLNode * root) throw std::runtime_error(msg.str()); } m_default_kart_properties->getAllData(node); - m_default_kart_properties->getProperties(node); const XMLNode *types = node->getNode("kart-type"); for (int i = 0; i < types->getNumNodes(); ++i) @@ -395,7 +394,7 @@ void STKConfig::getAllData(const XMLNode * root) const XMLNode* type = types->getNode(i); m_kart_properties[type->getName()] = new KartProperties(); m_kart_properties[type->getName()]->copyFrom(m_default_kart_properties); - m_kart_properties[type->getName()]->getProperties(type); + m_kart_properties[type->getName()]->getAllData(type); } } // getAllData diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index 7d53e0bc6..d4cbdf273 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -204,7 +204,6 @@ void KartProperties::load(const std::string &filename, const std::string &node) throw std::runtime_error(msg.str()); } getAllData(root); - getProperties(root); } catch(std::exception& err) { @@ -468,6 +467,151 @@ void KartProperties::getAllData(const XMLNode * root) #endif } // if sounds-node exist + if(const XMLNode *nitro_node = root->getNode("nitro")) + { + nitro_node->get("consumption", &m_nitro_consumption ); + nitro_node->get("small-container", &m_nitro_small_container ); + nitro_node->get("big-container", &m_nitro_big_container ); + nitro_node->get("max-speed-increase", &m_nitro_max_speed_increase); + nitro_node->get("engine-force", &m_nitro_engine_force ); + nitro_node->get("duration", &m_nitro_duration ); + nitro_node->get("fade-out-time", &m_nitro_fade_out_time ); + nitro_node->get("max", &m_nitro_max ); + nitro_node->get("min-consumption-time", &m_nitro_min_consumption ); + } + + if(const XMLNode *bubble_node = root->getNode("bubblegum")) + { + bubble_node->get("time", &m_bubblegum_time ); + bubble_node->get("speed-fraction", &m_bubblegum_speed_fraction); + bubble_node->get("fade-in-time", &m_bubblegum_fade_in_time ); + bubble_node->get("torque", &m_bubblegum_torque ); + } + + if(const XMLNode *rescue_node = root->getNode("rescue")) + { + rescue_node->get("vert-offset", &m_rescue_vert_offset); + rescue_node->get("time", &m_rescue_time ); + rescue_node->get("height", &m_rescue_height ); + } + + if(const XMLNode *explosion_node = root->getNode("explosion")) + { + explosion_node->get("time", &m_explosion_time ); + explosion_node->get("radius", &m_explosion_radius); + explosion_node->get("invulnerability-time", + &m_explosion_invulnerability_time); + } + + if(const XMLNode *skid_node = root->getNode("skid")) + { + m_skidding_properties->load(skid_node); + } + + + if(const XMLNode *slipstream_node = root->getNode("slipstream")) + { + slipstream_node->get("length", &m_slipstream_length ); + slipstream_node->get("width", &m_slipstream_width ); + slipstream_node->get("collect-time", &m_slipstream_collect_time ); + slipstream_node->get("use-time", &m_slipstream_use_time ); + slipstream_node->get("add-power", &m_slipstream_add_power ); + slipstream_node->get("min-speed", &m_slipstream_min_speed ); + slipstream_node->get("max-speed-increase", + &m_slipstream_max_speed_increase); + slipstream_node->get("duration", &m_slipstream_duration ); + slipstream_node->get("fade-out-time",&m_slipstream_fade_out_time ); + } + + if(const XMLNode *turn_node = root->getNode("turn")) + { + turn_node->get("time-full-steer", &m_time_full_steer ); + turn_node->get("time-reset-steer", &m_time_reset_steer ); + turn_node->get("turn-radius", &m_turn_angle_at_speed ); + // For now store the turn radius in turn angle, the correct + // value can only be determined later in ::load + } + + if(const XMLNode *engine_node = root->getNode("engine")) + { + engine_node->get("brake-factor", &m_brake_factor); + engine_node->get("max-speed-reverse-ratio", &m_max_speed_reverse_ratio); + engine_node->get("power", &m_engine_power); + if(m_engine_power.size()!=RaceManager::DIFFICULTY_COUNT) + { + Log::fatal("[KartProperties]", + "Incorrect engine-power specifications for kart '%s'", + getIdent().c_str()); + } + engine_node->get("max-speed", &m_max_speed); + if(m_max_speed.size()!=RaceManager::DIFFICULTY_COUNT) + { + Log::fatal("[KartProperties]", + "Incorrect max-speed specifications for kart '%s'", + getIdent().c_str()); + } + } // if getNode("engine") + + if(const XMLNode *gear_node = root->getNode("gear")) + { + gear_node->get("switch-ratio", &m_gear_switch_ratio ); + gear_node->get("power-increase", &m_gear_power_increase); + } + + if(const XMLNode *mass_node = root->getNode("mass")) + mass_node->get("value", &m_mass); + + if(const XMLNode *plunger_node= root->getNode("plunger")) + { + plunger_node->get("band-max-length", &m_rubber_band_max_length ); + plunger_node->get("band-force", &m_rubber_band_force ); + plunger_node->get("band-duration", &m_rubber_band_duration ); + plunger_node->get("band-speed-increase",&m_rubber_band_speed_increase); + plunger_node->get("band-fade-out-time", &m_rubber_band_fade_out_time ); + plunger_node->get("in-face-time", &m_plunger_in_face_duration); + if(m_plunger_in_face_duration.size()!=RaceManager::DIFFICULTY_COUNT) + { + Log::fatal("KartProperties", + "Invalid plunger in-face-time specification."); + } + } + + if(const XMLNode *zipper_node= root->getNode("zipper")) + { + zipper_node->get("time", &m_zipper_time ); + zipper_node->get("fade-out-time", &m_zipper_fade_out_time ); + zipper_node->get("force", &m_zipper_force ); + zipper_node->get("speed-gain", &m_zipper_speed_gain ); + zipper_node->get("max-speed-increase", &m_zipper_max_speed_increase); + } + + if(const XMLNode *swatter_node= root->getNode("swatter")) + { + swatter_node->get("duration", &m_swatter_duration ); + swatter_node->get("squash-duration", &m_squash_duration ); + swatter_node->get("squash-slowdown", &m_squash_slowdown ); + if(swatter_node->get("distance", &m_swatter_distance2) ) + { + // Avoid squaring if distance is not defined, so that + // distance2 remains UNDEFINED (which is a negative value) + m_swatter_distance2 *= m_swatter_distance2; + } + } + + if(const XMLNode *lean_node= root->getNode("lean")) + { + lean_node->get("max", &m_max_lean ); + lean_node->get("speed", &m_lean_speed); + m_max_lean *= DEGREE_TO_RAD; + m_lean_speed *= DEGREE_TO_RAD; + } + + if(const XMLNode *startup_node= root->getNode("startup")) + { + startup_node->get("time", &m_startup_times); + startup_node->get("boost", &m_startup_boost); + } + if(m_kart_model) m_kart_model->loadInfo(*root); } // getAllData @@ -625,155 +769,6 @@ bool KartProperties::isInGroup(const std::string &group) const return std::find(m_groups.begin(), m_groups.end(), group) != m_groups.end(); } // isInGroups -void KartProperties::getProperties(const XMLNode* root) -{ - - if(const XMLNode *nitro_node = root->getNode("nitro")) - { - nitro_node->get("consumption", &m_nitro_consumption ); - nitro_node->get("small-container", &m_nitro_small_container ); - nitro_node->get("big-container", &m_nitro_big_container ); - nitro_node->get("max-speed-increase", &m_nitro_max_speed_increase); - nitro_node->get("engine-force", &m_nitro_engine_force ); - nitro_node->get("duration", &m_nitro_duration ); - nitro_node->get("fade-out-time", &m_nitro_fade_out_time ); - nitro_node->get("max", &m_nitro_max ); - nitro_node->get("min-consumption-time", &m_nitro_min_consumption ); - } - - if(const XMLNode *bubble_node = root->getNode("bubblegum")) - { - bubble_node->get("time", &m_bubblegum_time ); - bubble_node->get("speed-fraction", &m_bubblegum_speed_fraction); - bubble_node->get("fade-in-time", &m_bubblegum_fade_in_time ); - bubble_node->get("torque", &m_bubblegum_torque ); - } - - if(const XMLNode *rescue_node = root->getNode("rescue")) - { - rescue_node->get("vert-offset", &m_rescue_vert_offset); - rescue_node->get("time", &m_rescue_time ); - rescue_node->get("height", &m_rescue_height ); - } - - if(const XMLNode *explosion_node = root->getNode("explosion")) - { - explosion_node->get("time", &m_explosion_time ); - explosion_node->get("radius", &m_explosion_radius); - explosion_node->get("invulnerability-time", - &m_explosion_invulnerability_time); - } - - if(const XMLNode *skid_node = root->getNode("skid")) - { - m_skidding_properties->load(skid_node); - } - - - if(const XMLNode *slipstream_node = root->getNode("slipstream")) - { - slipstream_node->get("length", &m_slipstream_length ); - slipstream_node->get("width", &m_slipstream_width ); - slipstream_node->get("collect-time", &m_slipstream_collect_time ); - slipstream_node->get("use-time", &m_slipstream_use_time ); - slipstream_node->get("add-power", &m_slipstream_add_power ); - slipstream_node->get("min-speed", &m_slipstream_min_speed ); - slipstream_node->get("max-speed-increase", - &m_slipstream_max_speed_increase); - slipstream_node->get("duration", &m_slipstream_duration ); - slipstream_node->get("fade-out-time",&m_slipstream_fade_out_time ); - } - - if(const XMLNode *turn_node = root->getNode("turn")) - { - turn_node->get("time-full-steer", &m_time_full_steer ); - turn_node->get("time-reset-steer", &m_time_reset_steer ); - turn_node->get("turn-radius", &m_turn_angle_at_speed ); - // For now store the turn radius in turn angle, the correct - // value can only be determined later in ::load - } - - if(const XMLNode *engine_node = root->getNode("engine")) - { - engine_node->get("brake-factor", &m_brake_factor); - engine_node->get("max-speed-reverse-ratio", &m_max_speed_reverse_ratio); - engine_node->get("power", &m_engine_power); - if(m_engine_power.size()!=RaceManager::DIFFICULTY_COUNT) - { - Log::fatal("[KartProperties]", - "Incorrect engine-power specifications for kart '%s'", - getIdent().c_str()); - } - engine_node->get("max-speed", &m_max_speed); - if(m_max_speed.size()!=RaceManager::DIFFICULTY_COUNT) - { - Log::fatal("[KartProperties]", - "Incorrect max-speed specifications for kart '%s'", - getIdent().c_str()); - } - } // if getNode("engine") - - if(const XMLNode *gear_node = root->getNode("gear")) - { - gear_node->get("switch-ratio", &m_gear_switch_ratio ); - gear_node->get("power-increase", &m_gear_power_increase); - } - - if(const XMLNode *mass_node = root->getNode("mass")) - mass_node->get("value", &m_mass); - - if(const XMLNode *plunger_node= root->getNode("plunger")) - { - plunger_node->get("band-max-length", &m_rubber_band_max_length ); - plunger_node->get("band-force", &m_rubber_band_force ); - plunger_node->get("band-duration", &m_rubber_band_duration ); - plunger_node->get("band-speed-increase",&m_rubber_band_speed_increase); - plunger_node->get("band-fade-out-time", &m_rubber_band_fade_out_time ); - plunger_node->get("in-face-time", &m_plunger_in_face_duration); - if(m_plunger_in_face_duration.size()!=RaceManager::DIFFICULTY_COUNT) - { - Log::fatal("KartProperties", - "Invalid plunger in-face-time specification."); - } - } - - if(const XMLNode *zipper_node= root->getNode("zipper")) - { - zipper_node->get("time", &m_zipper_time ); - zipper_node->get("fade-out-time", &m_zipper_fade_out_time ); - zipper_node->get("force", &m_zipper_force ); - zipper_node->get("speed-gain", &m_zipper_speed_gain ); - zipper_node->get("max-speed-increase", &m_zipper_max_speed_increase); - } - - if(const XMLNode *swatter_node= root->getNode("swatter")) - { - swatter_node->get("duration", &m_swatter_duration ); - swatter_node->get("squash-duration", &m_squash_duration ); - swatter_node->get("squash-slowdown", &m_squash_slowdown ); - if(swatter_node->get("distance", &m_swatter_distance2) ) - { - // Avoid squaring if distance is not defined, so that - // distance2 remains UNDEFINED (which is a negative value) - m_swatter_distance2 *= m_swatter_distance2; - } - } - - if(const XMLNode *lean_node= root->getNode("lean")) - { - lean_node->get("max", &m_max_lean ); - lean_node->get("speed", &m_lean_speed); - m_max_lean *= DEGREE_TO_RAD; - m_lean_speed *= DEGREE_TO_RAD; - } - - if(const XMLNode *startup_node= root->getNode("startup")) - { - startup_node->get("time", &m_startup_times); - startup_node->get("boost", &m_startup_boost); - } -} - // ---------------------------------------------------------------------------- /** Called the first time a kart accelerates after 'ready-set-go'. It searches diff --git a/src/karts/kart_properties.hpp b/src/karts/kart_properties.hpp index f9f90cf76..be30c20e5 100644 --- a/src/karts/kart_properties.hpp +++ b/src/karts/kart_properties.hpp @@ -392,7 +392,6 @@ public: float getStartupBoost () const; bool isInGroup (const std::string &group) const; bool operator<(const KartProperties &other) const; - void getProperties (const XMLNode * root); // ------------------------------------------------------------------------ /** Returns the (maximum) speed for a given turn radius. From 0fa6df587f729dfe6d7766beef9c7c0f0547ec8c Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Tue, 1 Jul 2014 12:25:02 +0200 Subject: [PATCH 065/121] Removed redundant kart configuration --- data/stk_config.xml | 66 --------------------------------------------- 1 file changed, 66 deletions(-) diff --git a/data/stk_config.xml b/data/stk_config.xml index 1a85d5908..e53cca6ba 100644 --- a/data/stk_config.xml +++ b/data/stk_config.xml @@ -621,32 +621,13 @@ - - - - - - - - - - - - @@ -672,32 +649,13 @@ - - - - - - - - - - - - @@ -723,25 +677,9 @@ - - - - - - - - - - From 41a5b5275bf15a9cae881ac55227d2efe668de44 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Tue, 1 Jul 2014 13:32:26 +0200 Subject: [PATCH 066/121] properties group node is not really necessary --- data/stk_config.xml | 21 ++++----------------- src/karts/kart_properties.cpp | 8 +------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/data/stk_config.xml b/data/stk_config.xml index e53cca6ba..84d3c09c0 100644 --- a/data/stk_config.xml +++ b/data/stk_config.xml @@ -145,8 +145,7 @@ - - + - - -