GUI Property now more modifiable (with SkillLevelWidget in vector and types in an enum)
This commit is contained in:
parent
45ac7d5e03
commit
084a4a46f3
@ -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_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_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);
|
||||
}
|
||||
|
||||
}
|
||||
} //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);
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
@ -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<SkillLevelWidget*> 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);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user