Changes to the Skill Level Widget, only bar refuses to show

This commit is contained in:
Bart Cools 2014-05-29 13:27:56 +02:00
parent d5d2ef991a
commit e7852648fa
5 changed files with 275 additions and 116 deletions

View File

@ -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);
}
// -----------------------------------------------------------------------------

View File

@ -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);

View File

@ -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 <string.h>
#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 <IGUIEnvironment.h>
#include <IGUIElement.h>
#include <IGUIButton.h>
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;
}
// -----------------------------------------------------------------------------

View File

@ -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 <irrString.h>
#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

View File

@ -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