Display skill labels only once

This commit is contained in:
Flakebi
2014-07-17 21:33:25 +02:00
parent 3684d22ef8
commit a77778b1cd
6 changed files with 79 additions and 24 deletions

View File

@@ -38,8 +38,8 @@ using namespace irr;
// -----------------------------------------------------------------------------
KartStatsWidget::KartStatsWidget(core::recti area, const int player_id,
std::string kart_group,
bool multiplayer) : Widget(WTYPE_DIV)
std::string kart_group, bool multiplayer,
bool display_text) : Widget(WTYPE_DIV)
{
m_player_id = player_id;
@@ -85,7 +85,7 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id,
SkillLevelWidget* skill_bar = NULL;
skill_bar = new SkillLevelWidget(skillArea, m_player_id, multiplayer);
skill_bar = new SkillLevelWidget(skillArea, m_player_id, multiplayer, display_text);
m_skills.push_back(skill_bar);
m_children.push_back(skill_bar);
@@ -167,4 +167,13 @@ void KartStatsWidget::setSize(const int x, const int y, const int w, const int h
m_skill_bar_y = y + h/2 - m_skill_bar_h/2;
} // setSize
void KartStatsWidget::setDisplayText(bool display_text)
{
for (int i = 0; i < SKILL_COUNT; ++i)
{
m_skills[i]->setDisplayText(display_text);
}
} // setDisplayText
// -----------------------------------------------------------------------------

View File

@@ -37,9 +37,7 @@ namespace GUIEngine
* \brief A progress bar widget.
* \ingroup widgetsgroup
*/
class KartStatsWidget : public Widget
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 */
@@ -70,8 +68,8 @@ class KartStatsWidget : public Widget
LEAK_CHECK()
KartStatsWidget(core::recti area, const int player_id,
std::string kart_group,
bool multiplayer);
std::string kart_group, bool multiplayer,
bool display_text);
virtual ~KartStatsWidget() {};
// ------------------------------------------------------------------------
@@ -98,6 +96,9 @@ class KartStatsWidget : public Widget
/** Get the current values of the widget. */
int getValue(Stats type);
/** If the labels should be displayed. */
void setDisplayText(bool display_text);
};
}

View File

@@ -38,10 +38,12 @@ using namespace irr;
// -----------------------------------------------------------------------------
SkillLevelWidget::SkillLevelWidget(core::recti area, const int player_id,
bool multiplayer, const int value,
const stringw& label) : Widget(WTYPE_DIV)
bool multiplayer, bool display_text,
const int value, const stringw& label)
: Widget(WTYPE_DIV)
{
m_player_id = player_id;
m_display_text = display_text;
setSize(area.UpperLeftCorner.X, area.UpperLeftCorner.Y,
area.getWidth(), area.getHeight() );
@@ -79,6 +81,7 @@ void SkillLevelWidget::add()
{
m_bar->add();
m_label->add();
m_label->setVisible(m_display_text);
}
// -----------------------------------------------------------------------------
@@ -115,7 +118,10 @@ void SkillLevelWidget::setSize(const int x, const int y, const int w, const int
m_h = h;
// -- sizes
m_bar_w = 3*(w/2)/4;
if (m_display_text)
m_bar_w = (w / 2) * 3 / 4;
else
m_bar_w = w * 2 / 3;
m_bar_h = h;
m_label_w = w/2;
m_label_h = h;
@@ -128,7 +134,10 @@ void SkillLevelWidget::setSize(const int x, const int y, const int w, const int
m_label_h = (int)(m_label_h*factor);
}
m_bar_x = x + w/2;
if (m_display_text)
m_bar_x = x + w / 2;
else
m_bar_x = x + w / 6;
m_bar_y = y + m_h/2 - m_bar_h/2;
m_label_x = x;
@@ -140,7 +149,6 @@ void SkillLevelWidget::setSize(const int x, const int y, const int w, const int
void SkillLevelWidget::setValue(const int value)
{
m_bar->setValue(value);
}
// -----------------------------------------------------------------------------
@@ -150,3 +158,13 @@ void SkillLevelWidget::setLabel(const irr::core::stringw& label)
m_label->setText(label, false);
}
void SkillLevelWidget::setDisplayText(bool display_text)
{
if(m_display_text != display_text)
{
m_display_text = display_text;
m_label->setVisible(display_text);
setSize(m_x, m_y, m_w, m_h);
}
}

View File

@@ -36,8 +36,7 @@ namespace GUIEngine
* \brief A skill level widget.
* \ingroup widgetsgroup
*/
class SkillLevelWidget : public Widget
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 */
@@ -54,6 +53,7 @@ class SkillLevelWidget : public Widget
std::string m_label_name;
int m_player_id;
bool m_display_text;
public:
@@ -62,7 +62,7 @@ class SkillLevelWidget : public Widget
LabelWidget* m_label;
ProgressBarWidget* m_bar;
SkillLevelWidget(core::recti area, const int player_id, bool multiplayer,
SkillLevelWidget(core::recti area, const int player_id, bool multiplayer, bool display_text,
const int value = 0, const irr::core::stringw& label = "default");
virtual ~SkillLevelWidget() {};
@@ -91,11 +91,13 @@ class SkillLevelWidget : public Widget
void setLabel(const irr::core::stringw& label);
/** Get the current label of the widget. */
const irr::core::stringw& getLabel()
const irr::core::stringw getLabel()
{
return m_label->getText();
}
/** If the label should be displayed. */
void setDisplayText(bool display_text);
};
}

View File

@@ -251,9 +251,9 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent,
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_parent_screen->m_multiplayer,
!m_parent_screen->m_multiplayer || parent->m_kart_widgets.size() == 0);
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)
@@ -433,13 +433,14 @@ void PlayerKartWidget::setPlayerID(const int newPlayerID)
assert(false);
}
// Remove current focus, but rembmer it
// Remove current focus, but remember it
Widget* focus = GUIEngine::getFocusForPlayer(m_player_id);
GUIEngine::focusNothingForPlayer(m_player_id);
// Change the player ID
m_player_id = newPlayerID;
m_player_ident_spinner->setID(m_player_id);
m_kart_stats->setDisplayText(m_player_id == 0);
// restore previous focus, but with new player ID
if (focus != NULL) focus->setFocusForPlayer(m_player_id);
@@ -1347,6 +1348,28 @@ bool KartSelectionScreen::playerQuit(StateManager::ActivePlayer* player)
// Tell the StateManager to remove this player
StateManager::get()->removeActivePlayer(playerID);
if (m_kart_widgets.size() == 1)
{
// Add multiplayer message
if (m_multiplayer_message == NULL)
{
Widget* fullarea = getWidget("playerskarts");
const int splitWidth = fullarea->m_w / 2;
m_multiplayer_message = new BubbleWidget();
m_multiplayer_message->m_properties[PROP_TEXT_ALIGN] = "center";
m_multiplayer_message->setText( _("Everyone:\nPress 'Select' now to "
"join the game!") );
m_multiplayer_message->m_x =
(int)(fullarea->m_x + splitWidth + splitWidth*0.2f);
m_multiplayer_message->m_y = (int)(fullarea->m_y + fullarea->m_h*0.3f);
m_multiplayer_message->m_w = (int)(splitWidth*0.6f);
m_multiplayer_message->m_h = (int)(fullarea->m_h*0.6f);
m_multiplayer_message->setFocusable(false);
m_multiplayer_message->add();
manualAddWidget(m_multiplayer_message);
}
}
// Karts count changed, maybe order too, so renumber them.
renumberKarts();
@@ -2060,7 +2083,9 @@ void KartSelectionScreen::renumberKarts()
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts");
assert( w != NULL );
Widget* fullarea = getWidget("playerskarts");
const int splitWidth = fullarea->m_w / m_kart_widgets.size();
int splitWidth = fullarea->m_w / m_kart_widgets.size();
if (m_kart_widgets.size() == 1)
splitWidth /= 2;
for (unsigned int n=0; n < m_kart_widgets.size(); n++)
{

View File

@@ -77,8 +77,6 @@ protected:
bool m_must_delete_on_back; //!< To delete the screen if back is pressed
KartSelectionScreen(const char* filename);
/** Stores whether any player confirmed their choice; then, some things
* are "frozen", for instance the selected kart group tab
*/
@@ -89,6 +87,8 @@ protected:
/** Message shown in multiplayer mode */
GUIEngine::BubbleWidget* m_multiplayer_message;
KartSelectionScreen(const char* filename);
/** Called when all players selected their kart */
void allPlayersDone();