Added higher-level calls to RibbonWidget so that Screens don't need to manually manipulate the internals of GUIEngine (continuing work started in previous commit)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5270 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2010-04-25 18:54:55 +00:00
parent e9b621c93c
commit e4fcbd4535
4 changed files with 42 additions and 48 deletions

View File

@@ -101,10 +101,8 @@
\note Property PROP_SQUARE can be set to tell the engine if the ribbon's contents are rectangular or not
(this will affect the type of highlighting used)
\note All elements within a ribbon must have an 'ID' property
\note Text-only ribbons (e.g. tabs) can have their elements dynamically added at runtime, too. Just add
\note Ribbons (e.g. tabs) can have their elements dynamically added at runtime, too. Just add
no children to the ribbon in the XML file, and add them at runtime through the method for this.
Dynamic contents creation for other types RibbonWidget is currently NOT implemented because we had
no need for it. It can be added as needed.
\n
\subsection widget2 WTYPE_SPINNER

View File

@@ -260,6 +260,25 @@ void RibbonWidget::addTextChild(const wchar_t* text, const std::string id)
// -----------------------------------------------------------------------------
void RibbonWidget::addIconChild(const wchar_t* text, const std::string id,
const int w, const int h, const std::string icon,
const IconButtonWidget::IconPathType iconPathType)
{
IconButtonWidget* ribbon_item = new IconButtonWidget();
ribbon_item->m_properties[PROP_ID] = id;
ribbon_item->setImage(icon.c_str(), iconPathType);
ribbon_item->m_properties[PROP_WIDTH] = StringUtils::toString(w);
ribbon_item->m_properties[PROP_HEIGHT] = StringUtils::toString(h);
ribbon_item->m_text = text;
m_children.push_back(ribbon_item);
}
// -----------------------------------------------------------------------------
void RibbonWidget::select(std::string item, const int mousePlayerID)
{
const int subbuttons_amount = m_children.size();

View File

@@ -23,6 +23,7 @@
#include <irrlicht.h>
#include "guiengine/widget.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
#include "utils/ptr_vector.hpp"
namespace GUIEngine
@@ -124,6 +125,15 @@ namespace GUIEngine
* \precondition only valid for ribbons that take text-only contents (e.g. tab bars)
*/
void addTextChild(const wchar_t* text, const std::string id);
/** \brief dynamically (at runtime) add an icon item to this ribbon
* \precondition this must be called before RibbonWidget::add, while the widget is not yet displayed
* \precondition only valid for ribbons that take icon contents
*/
void addIconChild(const wchar_t* text, const std::string id,
const int w, const int h, const std::string icon,
const IconButtonWidget::IconPathType iconPathType=IconButtonWidget::ICON_PATH_TYPE_RELATIVE);
};
}

View File

@@ -90,58 +90,25 @@ RacePausedDialog::RacePausedDialog(const float percentWidth, const float percent
if (race_manager->getMajorMode() == RaceManager::MAJOR_MODE_SINGLE)
{
IconButtonWidget* ribbon_item = new IconButtonWidget();
ribbon_item->m_properties[PROP_ID] = "newrace";
ribbon_item->m_properties[PROP_ICON] = "gui/main_race.png";
ribbon_item->m_properties[PROP_WIDTH] = "128";
ribbon_item->m_properties[PROP_HEIGHT] = "128";
//I18N: In the 'paused' screen
ribbon_item->m_text = _("Setup New Race");
m_choice_ribbon->m_children.push_back(ribbon_item);
m_choice_ribbon->addIconChild(_("Setup New Race"), "newrace", 128, 128, "gui/main_race.png");
}
if (race_manager->getMajorMode() == RaceManager::MAJOR_MODE_SINGLE)
{
IconButtonWidget* ribbon_item = new IconButtonWidget();
ribbon_item->m_properties[PROP_ID] = "restart";
ribbon_item->m_properties[PROP_ICON] = "gui/restart.png";
ribbon_item->m_properties[PROP_WIDTH] = "128";
ribbon_item->m_properties[PROP_HEIGHT] = "128";
//I18N: In the 'paused' screen
ribbon_item->m_text = _("Restart Race");
m_choice_ribbon->m_children.push_back(ribbon_item);
m_choice_ribbon->addIconChild(_("Restart Race"), "restart", 128, 128, "gui/restart.png");
}
{
IconButtonWidget* ribbon_item = new IconButtonWidget();
ribbon_item->m_properties[PROP_ID] = "options";
ribbon_item->m_properties[PROP_ICON] = "gui/main_options.png";
ribbon_item->m_properties[PROP_WIDTH] = "128";
ribbon_item->m_properties[PROP_HEIGHT] = "128";
//I18N: In the 'paused' screen
ribbon_item->m_text = _("Options");
m_choice_ribbon->m_children.push_back(ribbon_item);
}
{
IconButtonWidget* ribbon_item = new IconButtonWidget();
ribbon_item->m_properties[PROP_ID] = "help";
ribbon_item->m_properties[PROP_ICON] = "gui/main_help.png";
ribbon_item->m_properties[PROP_WIDTH] = "128";
ribbon_item->m_properties[PROP_HEIGHT] = "128";
//I18N: In the 'paused' screen
ribbon_item->m_text = _("Help");
m_choice_ribbon->m_children.push_back(ribbon_item);
}
{
IconButtonWidget* ribbon_item = new IconButtonWidget();
ribbon_item->m_properties[PROP_ID] = "exit";
ribbon_item->m_properties[PROP_ICON] = "gui/main_quit.png";
ribbon_item->m_properties[PROP_WIDTH] = "128";
ribbon_item->m_properties[PROP_HEIGHT] = "128";
//I18N: In the 'paused' screen
ribbon_item->m_text = _("Exit Race");
m_choice_ribbon->m_children.push_back(ribbon_item);
}
//I18N: In the 'paused' screen
m_choice_ribbon->addIconChild(_("Options"), "options", 128, 128, "gui/main_options.png");
//I18N: In the 'paused' screen
m_choice_ribbon->addIconChild(_("Help"), "help", 128, 128, "gui/main_help.png");
//I18N: In the 'paused' screen
m_choice_ribbon->addIconChild(_("Exit Race"), "exit", 128, 128, "gui/main_quit.png");
m_children.push_back(m_choice_ribbon);
m_choice_ribbon->add();
}