From 79727500c0b321f39315f2c00ba924709b73aaba Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Sat, 17 May 2014 16:54:43 +0200 Subject: [PATCH 01/38] 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 02/38] 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 03/38] 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 04/38] 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 05/38] 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 06/38] 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 07/38] 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 08/38] 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 09/38] 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 10/38] 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 11/38] 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 12/38] 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 13/38] 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 14/38] 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 15/38] 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 16/38] 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 17/38] 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 0fa746c805365fe4ea07f5e34a203515701dc382 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Thu, 26 Jun 2014 12:09:22 +0200 Subject: [PATCH 18/38] 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 19/38] 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 20/38] 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 109f783fa4ebe0ac8f98c89f08438249c8e62756 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Fri, 27 Jun 2014 23:26:02 +0200 Subject: [PATCH 21/38] 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 a73462759bdd250895812d5e330919ce85d62821 Mon Sep 17 00:00:00 2001 From: Bart Cools Date: Tue, 1 Jul 2014 10:37:00 +0200 Subject: [PATCH 22/38] 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 23/38] 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 24/38] 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 25/38] 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 26/38] 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 @@ - - + -