Reconciliated Screen and ModalDialog by extracting their common funcitonality into a common base class

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5746 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2010-08-16 00:39:53 +00:00
parent ce0f923623
commit 021dea1829
18 changed files with 303 additions and 383 deletions

View File

@@ -957,9 +957,7 @@ namespace GUIEngine
// if a modal dialog is shown, search within it too
if (ModalDialog::isADialogActive())
{
Widget* widgetWithinDialog =
Screen::getWidget(name,
&(ModalDialog::getCurrent()->m_children));
Widget* widgetWithinDialog = ModalDialog::getCurrent()->getWidget(name);
if (widgetWithinDialog != NULL) return widgetWithinDialog;
}
@@ -976,9 +974,7 @@ namespace GUIEngine
// if a modal dialog is shown, search within it too
if (ModalDialog::isADialogActive())
{
Widget* widgetWithinDialog =
Screen::getWidget(id,
&(ModalDialog::getCurrent()->m_children));
Widget* widgetWithinDialog = ModalDialog::getCurrent()->getWidget(id);
if (widgetWithinDialog != NULL) return widgetWithinDialog;
}

View File

@@ -262,7 +262,7 @@ void EventHandler::navigateUp(const int playerID, Input::InputType type, const b
}
// don't allow navigating to any widget when a dialog is shown; only navigate to widgets in the dialog
if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyChild(el))
if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyIrrChild(el))
{
el = NULL;
}
@@ -381,7 +381,7 @@ void EventHandler::navigateDown(const int playerID, Input::InputType type, const
}
// don't allow navigating to any widget when a dialog is shown; only navigate to widgets in the dialog
if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyChild(el))
if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyIrrChild(el))
{
el = NULL;
}

View File

@@ -34,6 +34,198 @@ using namespace video;
using namespace io;
using namespace gui;
void ITopLevelWidgetContainer::addWidgetsRecursively(ptr_vector<Widget>& widgets, Widget* parent)
{
const unsigned short widgets_amount = widgets.size();
// ------- add widgets
for (int n=0; n<widgets_amount; n++)
{
if (widgets[n].getType() == WTYPE_DIV)
{
widgets[n].add(); // Will do nothing, but will maybe reserve an ID
addWidgetsRecursively(widgets[n].m_children, &widgets[n]);
}
else
{
// warn if widget has no dimensions (except for ribbons and icons, where it is normal since it
// adjusts to its contents)
if ((widgets[n].m_w < 1 || widgets[n].m_h < 1) &&
widgets[n].getType() != WTYPE_RIBBON &&
widgets[n].getType() != WTYPE_ICON_BUTTON)
{
std::cerr << "/!\\ Warning /!\\ : widget " << widgets[n].m_properties[PROP_ID].c_str() << " has no dimensions" << std::endl;
}
if (widgets[n].m_x == -1 || widgets[n].m_y == -1)
{
std::cerr << "/!\\ Warning /!\\ : widget " << widgets[n].m_properties[PROP_ID].c_str() << " has no position" << std::endl;
}
widgets[n].add();
}
} // next widget
} // addWidgetsRecursively
// ----------------------------------------------------------------------------
bool isMyChildHelperFunc(const ptr_vector<Widget>* within, const Widget* widget)
{
if (within->size() == 0) return false;
if (within->contains(widget))
{
return true;
}
const int count = within->size();
for (int n=0; n<count; n++)
{
if (isMyChildHelperFunc(&within->getConst(n)->getChildren(), widget))
{
return true;
}
}
return false;
}
bool ITopLevelWidgetContainer::isMyChild(Widget* widget) const
{
return isMyChildHelperFunc(&m_widgets, widget);
}
Widget* ITopLevelWidgetContainer::getWidget(const char* name)
{
return getWidget(name, &m_widgets);
} // getWidget
// -----------------------------------------------------------------------------
Widget* ITopLevelWidgetContainer::getWidget(const int id)
{
return getWidget(id, &m_widgets);
} // getWidget
// -----------------------------------------------------------------------------
Widget* ITopLevelWidgetContainer::getWidget(const char* name, ptr_vector<Widget>* within_vector)
{
const unsigned short widgets_amount = within_vector->size();
for(int n=0; n<widgets_amount; n++)
{
Widget& widget = (*within_vector)[n];
if (widget.m_properties[PROP_ID] == name) return &widget;
if (widget.searchInsideMe() && widget.m_children.size() > 0)
{
Widget* el = getWidget(name, &(widget.m_children));
if(el != NULL) return el;
}
} // next
return NULL;
} // getWidget
// -----------------------------------------------------------------------------
Widget* ITopLevelWidgetContainer::getWidget(const int id, ptr_vector<Widget>* within_vector)
{
const unsigned short widgets_amount = within_vector->size();
for (int n=0; n<widgets_amount; n++)
{
Widget& widget = (*within_vector)[n];
if (widget.m_element != NULL && widget.getIrrlichtElement()->getID() == id) return &widget;
if (widget.searchInsideMe() && widget.getChildren().size() > 0)
{
// std::cout << "widget = <" << widget.m_properties[PROP_ID].c_str()
// << "> widget.m_children.size()=" << widget.m_children.size() << std::endl;
Widget* el = getWidget(id, &(widget.m_children));
if(el != NULL) return el;
}
} // next
return NULL;
} // getWidget
// -----------------------------------------------------------------------------
Widget* ITopLevelWidgetContainer::getFirstWidget(ptr_vector<Widget>* within_vector)
{
if (m_first_widget != NULL) return m_first_widget;
if (within_vector == NULL) within_vector = &m_widgets;
for (int i = 0; i < within_vector->size(); i++)
{
if (!within_vector->get(i)->m_focusable) continue;
// if container, also checks children (FIXME: don't hardcode which types to avoid descending into)
if (within_vector->get(i)->m_children.size() > 0 &&
within_vector->get(i)->getType() != WTYPE_RIBBON &&
within_vector->get(i)->getType() != WTYPE_SPINNER)
{
Widget* w = getFirstWidget(&within_vector->get(i)->m_children);
if (w != NULL) return w;
}
Widget* item = within_vector->get(i);
if (item->getIrrlichtElement() == NULL ||
item->getIrrlichtElement()->getTabOrder() == -1 ||
item->getIrrlichtElement()->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */ ||
!item->m_focusable)
{
continue;
}
return item;
}
return NULL;
} // getFirstWidget
// -----------------------------------------------------------------------------
Widget* ITopLevelWidgetContainer::getLastWidget(ptr_vector<Widget>* within_vector)
{
if (m_last_widget != NULL) return m_last_widget;
if (within_vector == NULL) within_vector = &m_widgets;
for (int i = within_vector->size()-1; i >= 0; i--)
{
if (!within_vector->get(i)->m_focusable) continue;
// if container, also checks children
if (within_vector->get(i)->getChildren().size() > 0 &&
within_vector->get(i)->getType() != WTYPE_RIBBON &&
within_vector->get(i)->getType() != WTYPE_SPINNER)
{
Widget* w = getLastWidget(&within_vector->get(i)->m_children);
if (w != NULL) return w;
}
Widget* item = within_vector->get(i);
if (item->getIrrlichtElement() == NULL ||
item->getIrrlichtElement()->getTabOrder() == -1 ||
item->getIrrlichtElement()->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */ ||
!item->m_focusable)
{
continue;
}
return item;
}
return NULL;
} // getLastWidget
// ----------------------------------------------------------------------------

View File

@@ -21,17 +21,66 @@
#include <cstring> // for NULL
#include "utils/ptr_vector.hpp"
#include "guiengine/widget.hpp"
namespace GUIEngine
{
class Widget;
class ITopLevelWidgetContainer
{
protected:
/** the widgets in this screen */
ptr_vector<Widget, HOLD> m_widgets;
/**
* Screen is generally able to determine its first widget just fine, but in highly complex screens
* (e.g. multiplayer kart selection) you can help it by providing the first widget manually.
*/
Widget* m_first_widget;
/**
* Screen is generally able to determine its last widget just fine, but in highly complex screens
* (e.g. multiplayer kart selection) you can help it by providing the first widget manually.
*/
Widget* m_last_widget;
void addWidgetsRecursively(ptr_vector<Widget>& widgets, Widget* parent=NULL);
public:
virtual ~ITopLevelWidgetContainer() {}
virtual int getWidth() = 0;
virtual int getHeight() = 0;
/** \return an object by name, or NULL if not found */
Widget* getWidget(const char* name);
/** \return an object by irrlicht ID, or NULL if not found */
Widget* getWidget(const int id);
/** \return an object by name, casted to specified type, or NULL if not found/wrong type */
template <typename T> T* getWidget(const char* name)
{
Widget* out = getWidget(name);
T* outCasted = dynamic_cast<T*>( out );
if (out != NULL && outCasted == NULL)
{
fprintf(stderr, "Screen::getWidget : Widget '%s' of type '%s' cannot be casted to "
"requested type '%s'!\n", name, typeid(*out).name(), typeid(T).name());
abort();
}
return outCasted;
}
static Widget* getWidget(const char* name, ptr_vector<Widget>* within_vector);
static Widget* getWidget(const int id, ptr_vector<Widget>* within_vector);
Widget* getFirstWidget(ptr_vector<Widget>* within_vector=NULL);
Widget* getLastWidget(ptr_vector<Widget>* within_vector=NULL);
bool isMyChild(Widget* widget) const;
};
class LayoutManager
@@ -46,7 +95,7 @@ namespace GUIEngine
* Returns false if couldn't convert to either
*/
static bool convertToCoord(std::string& x, int* absolute /* out */, int* percentage /* out */);
public:
/**
* \brief Find a widget's x, y, w and h coords from what is specified in the XML properties.

View File

@@ -62,14 +62,14 @@ void ModalDialog::loadFromFile(const char* xmlFile)
return;
}
Screen::parseScreenFileDiv(xml, m_children, m_irrlicht_window);
Screen::parseScreenFileDiv(xml, m_widgets, m_irrlicht_window);
delete xml;
loadedFromFile();
LayoutManager::calculateLayout( m_children, this );
LayoutManager::calculateLayout( m_widgets, this );
addWidgetsRecursively(m_children);
addWidgetsRecursively(m_widgets);
}
// ----------------------------------------------------------------------------
@@ -136,12 +136,13 @@ ModalDialog::~ModalDialog()
void ModalDialog::clearWindow()
{
const int children_amount = m_children.size();
// TODO: extract this code and its eqauivalent from Screen into the common base class?
const int children_amount = m_widgets.size();
for(int i=0; i<children_amount; i++)
{
m_irrlicht_window->removeChild( m_children[i].getIrrlichtElement() );
m_irrlicht_window->removeChild( m_widgets[i].getIrrlichtElement() );
}
m_children.clearAndDeleteAll();
m_widgets.clearAndDeleteAll();
m_irrlicht_window->remove();
m_irrlicht_window = GUIEngine::getGUIEnv()->addWindow ( m_area, true /* modal */ );
@@ -190,113 +191,7 @@ ModalDialog* ModalDialog::getCurrent()
void ModalDialog::onEnterPressedInternal()
{
}
// ----------------------------------------------------------------------------
Widget* ModalDialog::getLastWidget()
{
// FIXME: don't duplicate this code from 'Screen.cpp'
const int childrenCount = m_children.size();
for (int i=childrenCount-1; i>=0; i--)
{
if (m_children[i].getIrrlichtElement() == NULL ||
m_children[i].getIrrlichtElement()->getTabOrder() == -1 ||
m_children[i].getIrrlichtElement()->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */ ||
!m_children[i].m_focusable)
{
continue;
}
return m_children.get(i);
}
return NULL;
}
// ----------------------------------------------------------------------------
Widget* ModalDialog::getFirstWidget()
{
// FIXME: don't duplicate this code from 'Screen.cpp'
const int childrenCount = m_children.size();
for (int i=0; i<childrenCount; i++)
{
if (m_children[i].getIrrlichtElement() == NULL ||
m_children[i].getIrrlichtElement()->getTabOrder() == -1 ||
m_children[i].getIrrlichtElement()->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */ ||
!m_children[i].m_focusable)
{
continue;
}
return m_children.get(i);
}
return NULL;
}
// ----------------------------------------------------------------------------
// FIXME: this code was duplicated from Screen, find a way to share instead of duplicating
void ModalDialog::addWidgetsRecursively(ptr_vector<Widget>& widgets, Widget* parent)
{
const unsigned short widgets_amount = widgets.size();
// ------- add widgets
for (int n=0; n<widgets_amount; n++)
{
if (widgets[n].getType() == WTYPE_DIV)
{
widgets[n].add(); // Will do nothing, but will maybe reserve an ID
addWidgetsRecursively(widgets[n].m_children, &widgets[n]);
}
else
{
// warn if widget has no dimensions (except for ribbons and icons, where it is normal since it
// adjusts to its contents)
if ((widgets[n].m_w < 1 || widgets[n].m_h < 1) &&
widgets[n].getType() != WTYPE_RIBBON &&
widgets[n].getType() != WTYPE_ICON_BUTTON)
{
std::cerr << "/!\\ Warning /!\\ : widget " << widgets[n].m_properties[PROP_ID].c_str() << " has no dimensions" << std::endl;
}
if (widgets[n].m_x == -1 || widgets[n].m_y == -1)
{
std::cerr << "/!\\ Warning /!\\ : widget " << widgets[n].m_properties[PROP_ID].c_str() << " has no position" << std::endl;
}
widgets[n].add();
}
} // next widget
} // addWidgetsRecursively
// ----------------------------------------------------------------------------
bool isMyChildHelperFunc(const ptr_vector<Widget>* within, const Widget* widget)
{
if (within->size() == 0) return false;
if (within->contains(widget))
{
return true;
}
const int count = within->size();
for (int n=0; n<count; n++)
{
if (isMyChildHelperFunc(&within->getConst(n)->getChildren(), widget))
{
return true;
}
}
return false;
}
bool ModalDialog::isMyChild(Widget* widget) const
{
return isMyChildHelperFunc(&m_children, widget);
}

View File

@@ -64,28 +64,18 @@ namespace GUIEngine
virtual void onEnterPressedInternal();
void clearWindow();
void addWidgetsRecursively(ptr_vector<Widget>& widgets, Widget* parent=NULL);
/** \brief Callback invoked when the dialog was loaded from the XML file (if the constructor
* that takes a XML file as argument is used)
*/
virtual void loadedFromFile() {}
public:
ptr_vector<Widget> m_children;
public:
virtual ~ModalDialog();
/** Returns whether to block event propagation (usually, you will want to block events you processed) */
virtual EventPropagation processEvent(const std::string& eventSource){ return EVENT_LET; }
bool isMyChild(Widget* widget) const;
bool isMyChild(irr::gui::IGUIElement* widget) const { return m_irrlicht_window->isMyChild(widget); }
Widget* getFirstWidget();
Widget* getLastWidget();
irr::gui::IGUIWindow* getIrrlichtElement()
{
return m_irrlicht_window;
@@ -111,6 +101,8 @@ namespace GUIEngine
* \brief Implementing callback from ITopLevelWidgetContainer
*/
virtual int getHeight() { return m_area.getHeight(); }
bool isMyIrrChild(irr::gui::IGUIElement* widget) const { return m_irrlicht_window->isMyChild(widget); }
};
}

View File

@@ -182,43 +182,6 @@ void Screen::addWidgets()
// -----------------------------------------------------------------------------
void Screen::addWidgetsRecursively(ptr_vector<Widget>& widgets, Widget* parent)
{
const unsigned short widgets_amount = widgets.size();
// ------- add widgets
for (int n=0; n<widgets_amount; n++)
{
if (widgets[n].m_type == WTYPE_DIV)
{
widgets[n].add(); // Will do nothing, but will maybe reserve an ID
addWidgetsRecursively(widgets[n].m_children, &widgets[n]);
}
else
{
// warn if widget has no dimensions (except for ribbons and icons, where it is normal since it
// adjusts to its contents)
if ((widgets[n].m_w < 1 || widgets[n].m_h < 1) &&
widgets[n].m_type != WTYPE_RIBBON &&
widgets[n].m_type != WTYPE_ICON_BUTTON)
{
std::cerr << "/!\\ Warning /!\\ : widget " << widgets[n].m_properties[PROP_ID].c_str() << " has no dimensions" << std::endl;
}
if (widgets[n].m_x == -1 || widgets[n].m_y == -1)
{
std::cerr << "/!\\ Warning /!\\ : widget " << widgets[n].m_properties[PROP_ID].c_str() << " has no position" << std::endl;
}
widgets[n].add();
}
} // next widget
} // addWidgetsRecursively
// -----------------------------------------------------------------------------
/**
* Called when screen is removed. This means all irrlicht widgets this object has pointers
* to are now gone. Set all references to NULL to avoid problems.
@@ -262,133 +225,9 @@ void Screen::manualRemoveWidget(Widget* w)
#if 0
#pragma mark -
#pragma mark Getting widgets
#pragma mark Getters
#endif
Widget* Screen::getWidget(const char* name)
{
return getWidget(name, &m_widgets);
} // getWidget
// -----------------------------------------------------------------------------
Widget* Screen::getWidget(const int id)
{
return getWidget(id, &m_widgets);
} // getWidget
// -----------------------------------------------------------------------------
Widget* Screen::getWidget(const char* name, ptr_vector<Widget>* within_vector)
{
const unsigned short widgets_amount = within_vector->size();
for(int n=0; n<widgets_amount; n++)
{
Widget& widget = (*within_vector)[n];
if (widget.m_properties[PROP_ID] == name) return &widget;
if (widget.searchInsideMe() && widget.m_children.size() > 0)
{
Widget* el = getWidget(name, &(widget.m_children));
if(el != NULL) return el;
}
} // next
return NULL;
} // getWidget
// -----------------------------------------------------------------------------
Widget* Screen::getWidget(const int id, ptr_vector<Widget>* within_vector)
{
const unsigned short widgets_amount = within_vector->size();
for(int n=0; n<widgets_amount; n++)
{
Widget& widget = (*within_vector)[n];
if (widget.m_element != NULL && widget.m_element->getID() == id) return &widget;
if (widget.searchInsideMe() && widget.m_children.size() > 0)
{
// std::cout << "widget = <" << widget.m_properties[PROP_ID].c_str()
// << "> widget.m_children.size()=" << widget.m_children.size() << std::endl;
Widget* el = getWidget(id, &(widget.m_children));
if(el != NULL) return el;
}
} // next
return NULL;
} // getWidget
// -----------------------------------------------------------------------------
Widget* Screen::getFirstWidget(ptr_vector<Widget>* within_vector)
{
if (m_first_widget != NULL) return m_first_widget;
if (within_vector == NULL) within_vector = &m_widgets;
for (int i = 0; i < within_vector->size(); i++)
{
if (!within_vector->get(i)->m_focusable) continue;
// if container, also checks children (FIXME: don't hardcode which types to avoid descending into)
if (within_vector->get(i)->m_children.size() > 0 &&
within_vector->get(i)->m_type != WTYPE_RIBBON &&
within_vector->get(i)->m_type != WTYPE_SPINNER)
{
Widget* w = getFirstWidget(&within_vector->get(i)->m_children);
if (w != NULL) return w;
}
Widget* item = within_vector->get(i);
if (item->m_element == NULL ||
item->m_element->getTabOrder() == -1 ||
item->m_element->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */ ||
!item->m_focusable)
{
continue;
}
return item;
}
return NULL;
} // getFirstWidget
// -----------------------------------------------------------------------------
Widget* Screen::getLastWidget(ptr_vector<Widget>* within_vector)
{
if (m_last_widget != NULL) return m_last_widget;
if (within_vector == NULL) within_vector = &m_widgets;
for (int i = within_vector->size()-1; i >= 0; i--)
{
if (!within_vector->get(i)->m_focusable) continue;
// if container, also checks children
if (within_vector->get(i)->m_children.size() > 0 &&
within_vector->get(i)->m_type != WTYPE_RIBBON &&
within_vector->get(i)->m_type != WTYPE_SPINNER)
{
Widget* w = getLastWidget(&within_vector->get(i)->m_children);
if (w != NULL) return w;
}
Widget* item = within_vector->get(i);
if (item->m_element == NULL ||
item->m_element->getTabOrder() == -1 ||
item->m_element->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */ ||
!item->m_focusable)
{
continue;
}
return item;
}
return NULL;
} // getLastWidget
// -----------------------------------------------------------------------------
int Screen::getWidth()

View File

@@ -94,9 +94,7 @@ namespace GUIEngine
bool m_loaded;
std::string m_filename;
static void addWidgetsRecursively(ptr_vector<Widget>& widgets, Widget* parent=NULL);
/** Will be called to determine if the 3D scene must be rendered when at this screen. */
bool m_render_3d;
@@ -106,21 +104,6 @@ namespace GUIEngine
protected:
bool m_throttle_FPS;
/**
* Screen is generally able to determine its first widget just fine, but in highly complex screens
* (e.g. multiplayer kart selection) you can help it by providing the first widget manually.
*/
Widget* m_first_widget;
/**
* Screen is generally able to determine its last widget just fine, but in highly complex screens
* (e.g. multiplayer kart selection) you can help it by providing the first widget manually.
*/
Widget* m_last_widget;
/** the widgets in this screen */
ptr_vector<Widget, HOLD> m_widgets;
public:
/**
@@ -152,36 +135,9 @@ namespace GUIEngine
/** \return whether this screen is currently loaded */
bool isLoaded() const { return m_loaded; }
/** returns an object by name, or NULL if not found */
Widget* getWidget(const char* name);
/** returns an object by irrlicht ID, or NULL if not found */
Widget* getWidget(const int id);
bool throttleFPS() const { return m_throttle_FPS; }
/** returns an object by name, casted to specified type, or NULL if not found/wrong type */
template <typename T> T* getWidget(const char* name)
{
Widget* out = getWidget(name);
T* outCasted = dynamic_cast<T*>( out );
if (out != NULL && outCasted == NULL)
{
fprintf(stderr, "Screen::getWidget : Widget '%s' of type '%s' cannot be casted to "
"requested type '%s'!\n", name, typeid(*out).name(), typeid(T).name());
abort();
}
return outCasted;
}
static Widget* getWidget(const char* name, ptr_vector<Widget>* within_vector);
static Widget* getWidget(const int id, ptr_vector<Widget>* within_vector);
Widget* getFirstWidget(ptr_vector<Widget>* within_vector=NULL);
Widget* getLastWidget(ptr_vector<Widget>* within_vector=NULL);
/** \brief adds the irrLicht widgets corresponding to this screen to the IGUIEnvironment */
void addWidgets();

View File

@@ -125,6 +125,7 @@ namespace GUIEngine
friend class DynamicRibbonWidget;
friend class LayoutManager;
friend class ModalDialog;
friend class ITopLevelWidgetContainer;
/** When true, this widget shall use a bigger and more colourful font */
bool m_title_font;

View File

@@ -66,7 +66,7 @@ AddDeviceDialog::AddDeviceDialog() : ModalDialog(0.7f, 0.7f)
widget->m_w = textWidth;
widget->m_h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
m_widgets.push_back(widget);
widget->add();
}
{
@@ -81,7 +81,7 @@ AddDeviceDialog::AddDeviceDialog() : ModalDialog(0.7f, 0.7f)
widget->m_w = textWidth;
widget->m_h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
m_widgets.push_back(widget);
widget->add();
widget->setFocusForPlayer( PLAYER_ID_GAME_MASTER );

View File

@@ -59,7 +59,7 @@ AddonsLoading::AddonsLoading(Addons * id, const float w, const float h) :
m_next->m_properties[PROP_ID] = "next";
m_next->m_h = 40;
m_next->setParent(m_irrlicht_window);
m_children.push_back(m_next);
m_widgets.push_back(m_next);
m_next->add();
m_previous = new IconButtonWidget();
@@ -70,7 +70,7 @@ AddonsLoading::AddonsLoading(Addons * id, const float w, const float h) :
m_previous->m_properties[PROP_ID] = "previous";
m_previous->m_h = 40;
m_previous->setParent(m_irrlicht_window);
m_children.push_back(m_previous);
m_widgets.push_back(m_previous);
m_previous->add();
name = new LabelWidget();
@@ -81,7 +81,7 @@ AddonsLoading::AddonsLoading(Addons * id, const float w, const float h) :
name->m_h = area_left.getHeight()/6;
name->setParent(m_irrlicht_window);
m_children.push_back(name);
m_widgets.push_back(name);
name->add();
description = new LabelWidget();
@@ -93,7 +93,7 @@ AddonsLoading::AddonsLoading(Addons * id, const float w, const float h) :
description->setParent(m_irrlicht_window);
description->m_text = StringUtils::insertValues(_("Description: %i"), this->addons->GetDescription().c_str());
description->add();
m_children.push_back(description);
m_widgets.push_back(description);
version = new LabelWidget();
version->m_x = area_left.UpperLeftCorner.X;
@@ -103,7 +103,7 @@ AddonsLoading::AddonsLoading(Addons * id, const float w, const float h) :
version->m_h = area_left.getHeight()/3;
version->setParent(m_irrlicht_window);
m_children.push_back(version);
m_widgets.push_back(version);
version->add();
this->loadInfo();
@@ -123,7 +123,7 @@ void AddonsLoading::loadInfo()
icon->m_w = m_area.getWidth()/2;
icon->m_h = m_area.getHeight();
icon->setParent(m_irrlicht_window);
m_children.push_back(icon);
m_widgets.push_back(icon);
icon->add();
@@ -141,7 +141,7 @@ void AddonsLoading::loadInfo()
m_back_button->m_x = 20;
m_back_button->m_y = m_area.getHeight()-45;
m_back_button->setParent(m_irrlicht_window);
m_children.push_back(m_back_button);
m_widgets.push_back(m_back_button);
m_back_button->m_w = 150;
m_back_button->m_h = 35;
m_back_button->add();
@@ -156,7 +156,7 @@ void AddonsLoading::loadInfo()
this->install_button->m_x = m_area.getWidth()-170;
this->install_button->m_y = m_area.getHeight()-45;
this->install_button->setParent(m_irrlicht_window);
m_children.push_back(this->install_button);
m_widgets.push_back(this->install_button);
this->install_button->m_w = 150;
this->install_button->m_h = 35;
this->install_button->add();
@@ -191,7 +191,7 @@ GUIEngine::EventPropagation AddonsLoading::processEvent(const std::string& event
m_progress->m_h = 35;
m_progress->setParent(m_irrlicht_window);
m_children.push_back(m_progress);
m_widgets.push_back(m_progress);
m_progress->add();
m_state = new LabelWidget();
@@ -201,7 +201,7 @@ GUIEngine::EventPropagation AddonsLoading::processEvent(const std::string& event
m_state->m_h = 35;
m_state->setParent(m_irrlicht_window);
m_children.push_back(m_state);
m_widgets.push_back(m_state);
m_state->add();
m_back_button->setDeactivated();

View File

@@ -73,7 +73,7 @@ void ConfirmResolutionDialog::updateMessage()
(int)m_remaining_time);
//std::cout << stringc(msg.c_str()).c_str() << std::endl;
LabelWidget* countdown_message = (LabelWidget*)Screen::getWidget("title", &m_children);
LabelWidget* countdown_message = getWidget<LabelWidget>("title");
countdown_message->setText( msg.c_str() );
}

View File

@@ -36,7 +36,7 @@ EnterPlayerNameDialog::EnterPlayerNameDialog(const float w, const float h) :
{
loadFromFile("enter_player_name_dialog.stkgui");
TextBoxWidget* textCtrl = (TextBoxWidget*)Screen::getWidget("textfield", &m_children);
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
assert(textCtrl != NULL);
textCtrl->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
}
@@ -46,7 +46,7 @@ EnterPlayerNameDialog::EnterPlayerNameDialog(const float w, const float h) :
EnterPlayerNameDialog::~EnterPlayerNameDialog()
{
// FIXME: what is this code for?
TextBoxWidget* textCtrl = (TextBoxWidget*)Screen::getWidget("textfield", &m_children);
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
textCtrl->getIrrlichtElement()->remove();
}
@@ -67,8 +67,8 @@ GUIEngine::EventPropagation EnterPlayerNameDialog::processEvent(const std::strin
void EnterPlayerNameDialog::onEnterPressedInternal()
{
// ---- Cancel button pressed
const int playerID = 0; // FIXME: don't hardcode player 0?
ButtonWidget* cancelButton = (ButtonWidget*)Screen::getWidget("cancel", &m_children);
const int playerID = PLAYER_ID_GAME_MASTER;
ButtonWidget* cancelButton = getWidget<ButtonWidget>("cancel");
if (GUIEngine::isFocusedForPlayer(cancelButton, playerID))
{
std::string fakeEvent = "cancel";
@@ -77,14 +77,14 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
}
// ---- Otherwise, accept entered name
TextBoxWidget* textCtrl = (TextBoxWidget*)Screen::getWidget("textfield", &m_children);
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
stringw playerName = textCtrl->getText();
if (playerName.size() > 0)
{
const bool success = OptionsScreenPlayers::getInstance()->gotNewPlayerName( playerName );
if (!success)
{
LabelWidget* label = (LabelWidget*)Screen::getWidget("title", &m_children);
LabelWidget* label = getWidget<LabelWidget>("title");
label->setText(_("Cannot add a player with this name."));
sfx_manager->quickSound( "use_anvil" );
return;

View File

@@ -104,7 +104,7 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa
widget->m_h = height_of_one_line;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
m_widgets.push_back(widget);
widget->add();
// IGUIStaticText* line = GUIEngine::getGUIEnv()->addStaticText( lineText.c_str(),
@@ -132,7 +132,7 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa
file_manager->getDataDir() + "gui/main_help.png");
m_screenshot_widget->setParent(m_irrlicht_window);
m_screenshot_widget->add();
m_children.push_back(m_screenshot_widget);
m_widgets.push_back(m_screenshot_widget);
// ---- Start button
@@ -155,7 +155,7 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa
okBtn->m_w = 400;
okBtn->m_h = m_area.getHeight() - y2 - 15;
okBtn->setParent(m_irrlicht_window);
m_children.push_back(okBtn);
m_widgets.push_back(okBtn);
okBtn->add();
okBtn->getIrrlichtElement()->setTabStop(true);
okBtn->getIrrlichtElement()->setTabGroup(false);

View File

@@ -61,7 +61,7 @@ void PlayerInfoDialog::showRegularDialog()
textCtrl->m_w = m_area.getWidth()-100;
textCtrl->m_h = textHeight + 5;
textCtrl->setParent(m_irrlicht_window);
m_children.push_back(textCtrl);
m_widgets.push_back(textCtrl);
textCtrl->add();
}
@@ -79,7 +79,7 @@ void PlayerInfoDialog::showRegularDialog()
widget->m_w = textWidth;
widget->m_h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
m_widgets.push_back(widget);
widget->add();
}
{
@@ -94,7 +94,7 @@ void PlayerInfoDialog::showRegularDialog()
widget->m_w = textWidth;
widget->m_h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
m_widgets.push_back(widget);
widget->add();
}
@@ -112,7 +112,7 @@ void PlayerInfoDialog::showRegularDialog()
widget->m_w = textWidth;
widget->m_h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
m_widgets.push_back(widget);
widget->add();
}
@@ -158,7 +158,7 @@ void PlayerInfoDialog::showConfirmDialog()
widget->m_w = textWidth;
widget->m_h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
m_widgets.push_back(widget);
widget->add();
}
@@ -176,7 +176,7 @@ void PlayerInfoDialog::showConfirmDialog()
widget->m_w = textWidth;
widget->m_h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
m_widgets.push_back(widget);
widget->add();
widget->setFocusForPlayer( PLAYER_ID_GAME_MASTER );

View File

@@ -342,7 +342,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
unlocked_label->m_h = button_h;
unlocked_label->m_text = _("You unlocked a new feature!");
unlocked_label->setParent(m_irrlicht_window);
m_children.push_back(unlocked_label);
m_widgets.push_back(unlocked_label);
unlocked_label->add();
ButtonWidget* whats_next_btn = new ButtonWidget();
@@ -355,7 +355,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
whats_next_btn->m_text = _("See unlocked features");
whats_next_btn->m_properties[PROP_ID] = "seeunlocked";
m_children.push_back(whats_next_btn);
m_widgets.push_back(whats_next_btn);
whats_next_btn->add();
whats_next_btn->setFocusForPlayer( PLAYER_ID_GAME_MASTER );
@@ -370,7 +370,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
new_race_btn->m_h = button_h;
new_race_btn->m_text = _("Setup New Race");
new_race_btn->setParent(m_irrlicht_window);
m_children.push_back(new_race_btn);
m_widgets.push_back(new_race_btn);
new_race_btn->add();
ButtonWidget* race_again_btn = new ButtonWidget();
@@ -381,7 +381,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
race_again_btn->m_h = button_h;
race_again_btn->m_text = _("Race in this track again");
race_again_btn->setParent(m_irrlicht_window);
m_children.push_back(race_again_btn);
m_widgets.push_back(race_again_btn);
race_again_btn->add();
ButtonWidget* whats_next_btn = new ButtonWidget();
@@ -394,7 +394,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
whats_next_btn->m_text = _("Back to the main menu");
whats_next_btn->m_properties[PROP_ID] = "backtomenu";
m_children.push_back(whats_next_btn);
m_widgets.push_back(whats_next_btn);
whats_next_btn->add();
whats_next_btn->setFocusForPlayer( PLAYER_ID_GAME_MASTER );
@@ -411,7 +411,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
whats_next_btn->m_text = _("Continue Grand Prix");
whats_next_btn->m_properties[PROP_ID] = "continuegp";
m_children.push_back(whats_next_btn);
m_widgets.push_back(whats_next_btn);
whats_next_btn->add();
whats_next_btn->setFocusForPlayer( PLAYER_ID_GAME_MASTER );
@@ -425,7 +425,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
abort_gp->m_h = button_h;
abort_gp->m_text = _("Abort Grand Prix");
abort_gp->setParent(m_irrlicht_window);
m_children.push_back(abort_gp);
m_widgets.push_back(abort_gp);
abort_gp->add();

View File

@@ -48,7 +48,7 @@ RacePausedDialog::RacePausedDialog(const float percentWidth,
World::getWorld()->pause(WorldStatus::IN_GAME_MENU_PHASE);
ButtonWidget* back_btn = (ButtonWidget*)Screen::getWidget("backbtn", &m_children);
IconButtonWidget* back_btn = getWidget<IconButtonWidget>("backbtn");
back_btn->setFocusForPlayer( PLAYER_ID_GAME_MASTER );
} // RacePausedDialog
@@ -68,8 +68,8 @@ void RacePausedDialog::loadedFromFile()
if (race_manager->getMajorMode() != RaceManager::MAJOR_MODE_SINGLE)
{
printf("==== REMOVING restart button ====\n");
GUIEngine::RibbonWidget* choice_ribbon = (GUIEngine::RibbonWidget*)
Screen::getWidget("choiceribbon", &m_children);
GUIEngine::RibbonWidget* choice_ribbon =
getWidget<GUIEngine::RibbonWidget>("choiceribbon");
const bool success = choice_ribbon->deleteChild("restart");
@@ -88,8 +88,8 @@ void RacePausedDialog::onEnterPressedInternal()
GUIEngine::EventPropagation
RacePausedDialog::processEvent(const std::string& eventSource)
{
GUIEngine::RibbonWidget* chocie_ribbon = (GUIEngine::RibbonWidget*)
Screen::getWidget("choiceribbon", &m_children);
GUIEngine::RibbonWidget* chocie_ribbon =
getWidget<GUIEngine::RibbonWidget>("choiceribbon");
if (UserConfigParams::m_verbosity>=5)
{

View File

@@ -100,7 +100,7 @@ TrackInfoDialog::TrackInfoDialog(const std::string& trackIdent, const irr::core:
{
screenshotWidget->setImage(screenshot);
}
m_children.push_back(screenshotWidget);
m_widgets.push_back(screenshotWidget);
a->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
b->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
@@ -122,7 +122,7 @@ TrackInfoDialog::TrackInfoDialog(const std::string& trackIdent, const irr::core:
//I18N: In the track setup screen (number of laps choice, where %i is the number)
m_spinner->m_text = _("%i laps");
m_children.push_back(m_spinner);
m_widgets.push_back(m_spinner);
m_spinner->add();
m_spinner->setValue(3);
m_spinner->getIrrlichtElement()->setTabStop(true);
@@ -142,7 +142,7 @@ TrackInfoDialog::TrackInfoDialog(const std::string& trackIdent, const irr::core:
okBtn->m_w = 400;
okBtn->m_h = m_area.getHeight() - y3 - 15;
okBtn->setParent(m_irrlicht_window);
m_children.push_back(okBtn);
m_widgets.push_back(okBtn);
okBtn->add();
okBtn->getIrrlichtElement()->setTabStop(true);
okBtn->getIrrlichtElement()->setTabGroup(false);