[_GSoC Uni_] Extended ribbon_widget to only take in mind active children. Overall improvement of GUI and code organization.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13027 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
f99f27cbf1
commit
dea6a6d721
@ -1,9 +1,13 @@
|
||||
<stkgui>
|
||||
|
||||
<div x="2%" y="5%" width="96%" height="90%" layout="vertical-row" >
|
||||
<div x="2%" y="5%" width="96%" height="85%" layout="vertical-row" >
|
||||
|
||||
<header id="title" width="96%" proportion="1" text_align="center" word_wrap="true"
|
||||
<header id="title" width="96%" height="fit" text_align="center" word_wrap="true"
|
||||
I18N="In the login dialog' dialog" text="Sign in"/>
|
||||
|
||||
<spacer height="20" width="50">
|
||||
|
||||
<label id="info" proportion="2" width="90%" align="center" text_align="left" word_wrap="true" text=""/>
|
||||
|
||||
<spacer height="40" width="50">
|
||||
|
||||
@ -23,17 +27,22 @@
|
||||
|
||||
<spacer height="20" width="50">
|
||||
|
||||
<label id="info" proportion="1" width="90%" align="center" text_align="center" word_wrap="true" dialog" text=""/>
|
||||
<label id="message" proportion="1" width="90%" align="center" text_align="center" word_wrap="true" text=""/>
|
||||
|
||||
<spacer height="20" width="50">
|
||||
|
||||
<div id="options" width="fit" proportion="1" align="center" layout="horizontal-row">
|
||||
<button id="signin" height="fit" align="center" width="fit" I18N="In the login dialog" text="Sign In"/>
|
||||
<spacer height="50" width="50">
|
||||
<button id="signup" height="fit" align="center" width="fit" I18N="In the login dialog" text="Register"/>
|
||||
<spacer height="50" width="50">
|
||||
<button id="cancel" height="fit" align="center" width="fit" I18N="In the login dialog" text="Cancel"/>
|
||||
</div>
|
||||
<buttonbar id="options" width="90%" proportion="1" align="center">
|
||||
<icon-button id="sign_in" width="64" height="64" icon="gui/main_options.png"
|
||||
I18N="Main menu button" text="Sign In" label_location="bottom"/>
|
||||
<icon-button id="forgot_password" width="64" height="64" icon="gui/main_help.png"
|
||||
I18N="Main menu button" text="Recovery" label_location="bottom"/>
|
||||
<icon-button id="sign_up" width="64" height="64" icon="gui/tutorial.png"
|
||||
I18N="Main menu button" text="Register" label_location="bottom"/>
|
||||
<icon-button id="as_guest" width="64" height="64" icon="gui/main_about.png"
|
||||
I18N="Main menu button" text="As guest" label_location="bottom"/>
|
||||
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
|
||||
I18N="Main menu button" text="Cancel" label_location="bottom"/>
|
||||
</buttonbar>
|
||||
|
||||
|
||||
</div>
|
||||
|
@ -5,15 +5,8 @@
|
||||
<spacer height="15" width="10"/>
|
||||
<box proportion="4" width="90%" layout="vertical-row" align="center">
|
||||
<div x="2%" y="2%" width="96%" height="96%" layout="vertical-row" id="outer_box" >
|
||||
<label I18N="In the online multiplayer screen" proportion="4" text="Graphical Effects Level" align="center"/>
|
||||
<spacer width="20" height="20"/>
|
||||
<div id="options" width="fit" proportion="1" align="center" layout="horizontal-row">
|
||||
<button id="signin" height="fit" align="center" width="fit" I18N="In the login dialog" text="Sign In"/>
|
||||
<spacer height="50" width="50">
|
||||
<button id="signup" height="fit" align="center" width="fit" I18N="In the login dialog" text="Register"/>
|
||||
<spacer height="50" width="50">
|
||||
<button id="cancel" height="fit" align="center" width="fit" I18N="In the login dialog" text="Cancel"/>
|
||||
</div>
|
||||
<label I18N="In the online multiplayer screen" proportion="4" word_wrap="true" text=
|
||||
"Here will come some information.. or statistic.. or whatever. Yet to be filled in!" align="center"/>
|
||||
</div>
|
||||
</box>
|
||||
|
||||
@ -32,15 +25,16 @@
|
||||
<spacer width="10" height="7%"/>
|
||||
|
||||
<bottombar x="2%" width="96%" height="10%" layout="horizontal-row">
|
||||
<label text_align="left" align="center" height="100%" id="online_status" proportion="1" I18N="In the online multiplayer screen" text="Loading..."/>
|
||||
<label text_align="left" align="center" height="100%" id="online_status" proportion="1" text=""/>
|
||||
|
||||
<spacer width="10" height="10" />
|
||||
|
||||
<buttonbar id="menu_bottomrow" x="0" y="0" width="20%" height="100%" align="right">
|
||||
<icon-button id="sign_in" width="64" height="64" icon="gui/main_options.png" extend_label="50"
|
||||
<buttonbar id="menu_bottomrow" x="0" y="0" width="20%" height="100%" align="center">
|
||||
<icon-button id="sign_in" width="64" height="64" icon="gui/main_about.png" extend_label="50"
|
||||
I18N="Main menu button" text="Sign In" label_location="hover"/>
|
||||
<icon-button id="sign_out" width="64" height="64" icon="gui/main_quit.png" extend_label="50"
|
||||
I18N="Main menu button" text="Sign Out" label_location="hover"/>
|
||||
<icon-button id="register" width="64" height="64" icon="gui/main_quit.png" extend_label="50"
|
||||
<icon-button id="sign_up" width="64" height="64" icon="gui/tutorial.png" extend_label="50"
|
||||
I18N="Main menu button" text="Register" label_location="hover"/>
|
||||
</buttonbar>
|
||||
|
||||
|
@ -64,6 +64,13 @@ RibbonWidget::RibbonWidget(const RibbonType type) : Widget(WTYPE_RIBBON)
|
||||
updateSelection();
|
||||
} // RibbonWidget
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
RibbonWidget::~RibbonWidget()
|
||||
{
|
||||
m_active_children.clearWithoutDeleting();
|
||||
} // ~RibbonWidget
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void RibbonWidget::add()
|
||||
{
|
||||
@ -84,7 +91,15 @@ void RibbonWidget::add()
|
||||
m_parent, id, L"");
|
||||
m_element = btn;
|
||||
|
||||
const int subbuttons_amount = m_children.size();
|
||||
m_active_children.clearWithoutDeleting(); // Is just a copy of m_children without the deactivated children. m_children takes care of memory.
|
||||
for (int i=0; i<m_children.size(); i++)
|
||||
{
|
||||
if (!m_children[i].m_deactivated)
|
||||
{
|
||||
m_active_children.push_back(m_children.get(i));
|
||||
}
|
||||
}
|
||||
const int subbuttons_amount = m_active_children.size();
|
||||
|
||||
// For some ribbon types, we can have unequal sizes depending on whether
|
||||
// items have labels or not
|
||||
@ -97,11 +112,11 @@ void RibbonWidget::add()
|
||||
for (int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
// FIXME: why do I manually invoke the Layout Manager here?
|
||||
LayoutManager::readCoords(m_children.get(i));
|
||||
LayoutManager::applyCoords(m_children.get(i), NULL, this);
|
||||
LayoutManager::readCoords(m_active_children.get(i));
|
||||
LayoutManager::applyCoords(m_active_children.get(i), NULL, this);
|
||||
|
||||
if (m_children[i].m_type != WTYPE_ICON_BUTTON &&
|
||||
m_children[i].m_type != WTYPE_BUTTON)
|
||||
if (m_active_children[i].m_type != WTYPE_ICON_BUTTON &&
|
||||
m_active_children[i].m_type != WTYPE_BUTTON)
|
||||
{
|
||||
fprintf(stderr, "/!\\ Warning /!\\ : ribbon widgets can only have "
|
||||
"(icon)button widgets as children\n");
|
||||
@ -110,15 +125,15 @@ void RibbonWidget::add()
|
||||
|
||||
// ribbon children must not be keyboard navigatable, the parent
|
||||
// ribbon takes care of that
|
||||
if (m_children[i].m_type == WTYPE_ICON_BUTTON)
|
||||
if (m_active_children[i].m_type == WTYPE_ICON_BUTTON)
|
||||
{
|
||||
IconButtonWidget* icon = ((IconButtonWidget*)m_children.get(i));
|
||||
IconButtonWidget* icon = ((IconButtonWidget*)m_active_children.get(i));
|
||||
icon->m_tab_stop = false;
|
||||
}
|
||||
|
||||
|
||||
bool has_label_underneath = m_children[i].m_text.size() > 0;
|
||||
if (m_children[i].m_properties[PROP_LABELS_LOCATION].size() > 0)
|
||||
bool has_label_underneath = m_active_children[i].m_text.size() > 0;
|
||||
if (m_active_children[i].m_properties[PROP_LABELS_LOCATION].size() > 0)
|
||||
{
|
||||
has_label_underneath = false;
|
||||
}
|
||||
@ -126,7 +141,7 @@ void RibbonWidget::add()
|
||||
if (has_label_underneath) with_label++;
|
||||
else without_label++;
|
||||
|
||||
total_needed_space += m_children[i].m_w;
|
||||
total_needed_space += m_active_children[i].m_w;
|
||||
}
|
||||
|
||||
int free_w_space = m_w - total_needed_space;
|
||||
@ -155,7 +170,7 @@ void RibbonWidget::add()
|
||||
/ (with_label + without_label/2.0f));
|
||||
const int small_tab = large_tab/2;
|
||||
|
||||
stringw& message = m_children[i].m_text;
|
||||
stringw& message = m_active_children[i].m_text;
|
||||
|
||||
|
||||
if (message.size() == 0)
|
||||
@ -179,7 +194,7 @@ void RibbonWidget::add()
|
||||
widget_x + small_tab/2-2, m_h);
|
||||
}
|
||||
|
||||
if (m_children[i].m_type == WTYPE_BUTTON)
|
||||
if (m_active_children[i].m_type == WTYPE_BUTTON)
|
||||
{
|
||||
subbtn = GUIEngine::getGUIEnv()
|
||||
->addButton(subsize, btn, getNewNoFocusID(),
|
||||
@ -197,7 +212,7 @@ void RibbonWidget::add()
|
||||
subbtn->setOverrideFont(GUIEngine::getSmallFont());
|
||||
}
|
||||
}
|
||||
else if (m_children[i].m_type == WTYPE_ICON_BUTTON)
|
||||
else if (m_active_children[i].m_type == WTYPE_ICON_BUTTON)
|
||||
{
|
||||
rect<s32> icon_part = rect<s32>(15,
|
||||
0,
|
||||
@ -232,7 +247,7 @@ void RibbonWidget::add()
|
||||
same_id, L"");
|
||||
icon->setScaleImage(true);
|
||||
std::string filename = file_manager->getDataDir()
|
||||
+ m_children[i].m_properties[PROP_ICON];
|
||||
+ m_active_children[i].m_properties[PROP_ICON];
|
||||
icon->setImage( irr_driver->getTexture(filename.c_str()) );
|
||||
icon->setUseAlphaChannel(true);
|
||||
icon->setDrawBorder(false);
|
||||
@ -267,21 +282,21 @@ void RibbonWidget::add()
|
||||
fprintf(stderr, "Invalid tab bar contents\n");
|
||||
}
|
||||
|
||||
m_children[i].m_element = subbtn;
|
||||
m_active_children[i].m_element = subbtn;
|
||||
|
||||
if (message.size() == 0) widget_x += small_tab/2;
|
||||
else widget_x += large_tab/2;
|
||||
}
|
||||
// ---- icon ribbons
|
||||
else if (m_children[i].m_type == WTYPE_ICON_BUTTON)
|
||||
else if (m_active_children[i].m_type == WTYPE_ICON_BUTTON)
|
||||
{
|
||||
if (widget_x == -1) widget_x = one_button_space/2;
|
||||
|
||||
// find how much space to keep for the label under the button.
|
||||
// consider font size, whether the label is multiline, etc...
|
||||
bool has_label = m_children[i].m_text.size() > 0;
|
||||
bool has_label = m_active_children[i].m_text.size() > 0;
|
||||
|
||||
if (m_children[i].m_properties[PROP_LABELS_LOCATION].size() > 0)
|
||||
if (m_active_children[i].m_properties[PROP_LABELS_LOCATION].size() > 0)
|
||||
{
|
||||
has_label = false;
|
||||
}
|
||||
@ -291,11 +306,11 @@ void RibbonWidget::add()
|
||||
: 10;
|
||||
|
||||
float imageRatio =
|
||||
(float)m_children[i].m_w / (float)m_children[i].m_h;
|
||||
(float)m_active_children[i].m_w / (float)m_active_children[i].m_h;
|
||||
|
||||
// calculate the size of the image
|
||||
std::string filename = file_manager->getDataDir()
|
||||
+ m_children[i].m_properties[PROP_ICON];
|
||||
+ m_active_children[i].m_properties[PROP_ICON];
|
||||
video::ITexture* image =
|
||||
irr_driver->getTexture((filename).c_str());
|
||||
float image_h = (float)image->getSize().Height;
|
||||
@ -320,17 +335,17 @@ void RibbonWidget::add()
|
||||
// ---- add bitmap button part
|
||||
// backup and restore position in case the same object is added
|
||||
// multiple times (FIXME: unclean)
|
||||
int old_x = m_children[i].m_x;
|
||||
int old_y = m_children[i].m_y;
|
||||
int old_w = m_children[i].m_w;
|
||||
int old_h = m_children[i].m_h;
|
||||
int old_x = m_active_children[i].m_x;
|
||||
int old_y = m_active_children[i].m_y;
|
||||
int old_w = m_active_children[i].m_w;
|
||||
int old_h = m_active_children[i].m_h;
|
||||
|
||||
m_children[i].m_x = widget_x - (int)(image_w*zoom/2.0f);
|
||||
m_children[i].m_y = button_y;
|
||||
m_children[i].m_w = (int)(image_w*zoom);
|
||||
m_children[i].m_h = (int)(image_h*zoom);
|
||||
m_active_children[i].m_x = widget_x - (int)(image_w*zoom/2.0f);
|
||||
m_active_children[i].m_y = button_y;
|
||||
m_active_children[i].m_w = (int)(image_w*zoom);
|
||||
m_active_children[i].m_h = (int)(image_h*zoom);
|
||||
|
||||
IconButtonWidget* icon = ((IconButtonWidget*)m_children.get(i));
|
||||
IconButtonWidget* icon = ((IconButtonWidget*)m_active_children.get(i));
|
||||
|
||||
if (icon->m_properties[PROP_EXTEND_LABEL].size() == 0)
|
||||
{
|
||||
@ -338,14 +353,14 @@ void RibbonWidget::add()
|
||||
StringUtils::toString(one_button_space - icon->m_w);
|
||||
}
|
||||
|
||||
m_children.get(i)->m_parent = btn;
|
||||
m_children.get(i)->add();
|
||||
m_active_children.get(i)->m_parent = btn;
|
||||
m_active_children.get(i)->add();
|
||||
|
||||
// restore backuped size and location (see above for more info)
|
||||
m_children[i].m_x = old_x;
|
||||
m_children[i].m_y = old_y;
|
||||
m_children[i].m_w = old_w;
|
||||
m_children[i].m_h = old_h;
|
||||
m_active_children[i].m_x = old_x;
|
||||
m_active_children[i].m_y = old_y;
|
||||
m_active_children[i].m_w = old_w;
|
||||
m_active_children[i].m_h = old_h;
|
||||
|
||||
// the label itself will be added by the icon widget. since it
|
||||
// adds the label outside of the widget area it is assigned to,
|
||||
@ -361,7 +376,7 @@ void RibbonWidget::add()
|
||||
|
||||
|
||||
//m_children[i].id = subbtn->getID();
|
||||
m_children[i].m_event_handler = this;
|
||||
m_active_children[i].m_event_handler = this;
|
||||
}// next sub-button
|
||||
|
||||
id = m_element->getID();
|
||||
@ -434,16 +449,34 @@ void RibbonWidget::removeChildNamed(const char* name)
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void RibbonWidget::hideChildNamed(const char* name)
|
||||
{
|
||||
// This method should only be called BEFORE a widget is added
|
||||
assert(m_element == NULL);
|
||||
|
||||
Widget* child;
|
||||
for_in (child, m_children)
|
||||
{
|
||||
if (child->m_properties[PROP_ID] == name)
|
||||
{
|
||||
m_children.erase(child);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void RibbonWidget::select(std::string item, const int mousePlayerID)
|
||||
{
|
||||
const int subbuttons_amount = m_children.size();
|
||||
const int subbuttons_amount = m_active_children.size();
|
||||
|
||||
for (int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
if (m_children[i].m_properties[PROP_ID] == item)
|
||||
if (m_active_children[i].m_properties[PROP_ID] == item)
|
||||
{
|
||||
m_selection[mousePlayerID] = i;
|
||||
updateSelection();
|
||||
@ -456,17 +489,18 @@ void RibbonWidget::select(std::string item, const int mousePlayerID)
|
||||
// ----------------------------------------------------------------------------
|
||||
EventPropagation RibbonWidget::rightPressed(const int playerID)
|
||||
{
|
||||
Log::info("RibbonWidget", "Right Pressed");
|
||||
if (m_deactivated) return EVENT_LET;
|
||||
// empty ribbon, or only one item (can't move right)
|
||||
if (m_children.size() < 2) return EVENT_LET;
|
||||
if (m_active_children.size() < 2) return EVENT_LET;
|
||||
|
||||
m_selection[playerID]++;
|
||||
|
||||
if (m_selection[playerID] >= m_children.size())
|
||||
if (m_selection[playerID] >= m_active_children.size())
|
||||
{
|
||||
if (m_listener != NULL) m_listener->onRibbonWidgetScroll(1);
|
||||
|
||||
m_selection[playerID] = m_event_handler ? m_children.size()-1 : 0;
|
||||
m_selection[playerID] = m_event_handler ? m_active_children.size()-1 : 0;
|
||||
}
|
||||
updateSelection();
|
||||
|
||||
@ -475,14 +509,14 @@ EventPropagation RibbonWidget::rightPressed(const int playerID)
|
||||
const int mousePlayerID = input_manager->getPlayerKeyboardID();
|
||||
if (playerID == mousePlayerID || playerID == PLAYER_ID_GAME_MASTER)
|
||||
{
|
||||
m_mouse_focus = m_children.get(m_selection[playerID]);
|
||||
m_mouse_focus = m_active_children.get(m_selection[playerID]);
|
||||
}
|
||||
}
|
||||
|
||||
// if we reached a filler item, move again (but don't wrap)
|
||||
if (getSelectionIDString(playerID) == RibbonWidget::NO_ITEM_ID)
|
||||
{
|
||||
if (m_selection[playerID] + 1 < m_children.size())
|
||||
if (m_selection[playerID] + 1 < m_active_children.size())
|
||||
{
|
||||
rightPressed(playerID);
|
||||
}
|
||||
@ -496,7 +530,7 @@ EventPropagation RibbonWidget::leftPressed(const int playerID)
|
||||
{
|
||||
if (m_deactivated) return EVENT_LET;
|
||||
// empty ribbon, or only one item (can't move left)
|
||||
if (m_children.size() < 2) return EVENT_LET;
|
||||
if (m_active_children.size() < 2) return EVENT_LET;
|
||||
|
||||
m_selection[playerID]--;
|
||||
if (m_selection[playerID] < 0)
|
||||
@ -505,7 +539,7 @@ EventPropagation RibbonWidget::leftPressed(const int playerID)
|
||||
|
||||
m_selection[playerID] = m_event_handler
|
||||
? 0
|
||||
: m_children.size()-1;
|
||||
: m_active_children.size()-1;
|
||||
}
|
||||
|
||||
updateSelection();
|
||||
@ -515,7 +549,7 @@ EventPropagation RibbonWidget::leftPressed(const int playerID)
|
||||
const int mousePlayerID = input_manager->getPlayerKeyboardID();
|
||||
if (playerID == mousePlayerID || playerID == PLAYER_ID_GAME_MASTER)
|
||||
{
|
||||
m_mouse_focus = m_children.get(m_selection[playerID]);
|
||||
m_mouse_focus = m_active_children.get(m_selection[playerID]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -542,7 +576,7 @@ EventPropagation RibbonWidget::focused(const int playerID)
|
||||
{
|
||||
Widget::focused(playerID);
|
||||
|
||||
if (m_children.size() < 1) return EVENT_LET; // empty ribbon
|
||||
if (m_active_children.size() < 1) return EVENT_LET; // empty ribbon
|
||||
|
||||
if (m_ribbon_type == RIBBON_COMBO || m_ribbon_type == RIBBON_TABS)
|
||||
{
|
||||
@ -550,7 +584,7 @@ EventPropagation RibbonWidget::focused(const int playerID)
|
||||
if (m_mouse_focus == NULL && m_selection[playerID] != -1 &&
|
||||
(playerID == mousePlayerID || playerID == PLAYER_ID_GAME_MASTER))
|
||||
{
|
||||
m_mouse_focus = m_children.get(m_selection[playerID]);
|
||||
m_mouse_focus = m_active_children.get(m_selection[playerID]);
|
||||
m_mouse_focus->focused(playerID);
|
||||
}
|
||||
}
|
||||
@ -558,7 +592,7 @@ EventPropagation RibbonWidget::focused(const int playerID)
|
||||
{
|
||||
if (m_selection[playerID] != -1)
|
||||
{
|
||||
m_children.get(m_selection[playerID])->focused(playerID);
|
||||
m_active_children.get(m_selection[playerID])->focused(playerID);
|
||||
}
|
||||
}
|
||||
|
||||
@ -572,11 +606,11 @@ EventPropagation RibbonWidget::focused(const int playerID)
|
||||
|
||||
void RibbonWidget::unfocused(const int playerID, Widget* new_focus)
|
||||
{
|
||||
if (new_focus != NULL && new_focus != this && !m_children.contains(new_focus))
|
||||
if (new_focus != NULL && new_focus != this && !m_active_children.contains(new_focus))
|
||||
{
|
||||
if (m_selection[playerID] != -1)
|
||||
{
|
||||
m_children.get(m_selection[playerID])->unfocused(playerID, new_focus);
|
||||
m_active_children.get(m_selection[playerID])->unfocused(playerID, new_focus);
|
||||
}
|
||||
}
|
||||
|
||||
@ -589,7 +623,7 @@ EventPropagation RibbonWidget::mouseHovered(Widget* child,
|
||||
{
|
||||
if (m_deactivated) return EVENT_LET;
|
||||
|
||||
const int subbuttons_amount = m_children.size();
|
||||
const int subbuttons_amount = m_active_children.size();
|
||||
|
||||
if (m_ribbon_type == RIBBON_COMBO || m_ribbon_type == RIBBON_TABS)
|
||||
{
|
||||
@ -602,7 +636,7 @@ EventPropagation RibbonWidget::mouseHovered(Widget* child,
|
||||
{
|
||||
for (int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
if (m_children.get(i) == child)
|
||||
if (m_active_children.get(i) == child)
|
||||
{
|
||||
// Was already selected, don't send another event
|
||||
if (m_selection[mousePlayerID] == i) return EVENT_BLOCK;
|
||||
@ -623,21 +657,21 @@ const std::string& RibbonWidget::getSelectionIDString(const int playerID)
|
||||
{
|
||||
static std::string empty;
|
||||
if (m_selection[playerID] == -1) return empty;
|
||||
if (m_children.size() == 0) return empty;
|
||||
if (m_active_children.size() == 0) return empty;
|
||||
|
||||
// This can happen if an addon is removed, which causes a tab group
|
||||
// to be removed. If this tab group was previously selected, an
|
||||
// invalid array element would be accessed. In this case just pretend
|
||||
// that the first child was selected previously.
|
||||
if(m_selection[playerID]>=m_children.size())
|
||||
return m_children[0].m_properties[PROP_ID];
|
||||
return m_children[m_selection[playerID]].m_properties[PROP_ID];
|
||||
if(m_selection[playerID]>=m_active_children.size())
|
||||
return m_active_children[0].m_properties[PROP_ID];
|
||||
return m_active_children[m_selection[playerID]].m_properties[PROP_ID];
|
||||
} // getSelectionIDString
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void RibbonWidget::updateSelection()
|
||||
{
|
||||
const int subbuttons_amount = m_children.size();
|
||||
const int subbuttons_amount = m_active_children.size();
|
||||
|
||||
// FIXME: m_selection, m_selected, m_mouse_focus... what a mess...
|
||||
|
||||
@ -648,12 +682,12 @@ void RibbonWidget::updateSelection()
|
||||
for (int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
bool new_val = (i == m_selection[p]);
|
||||
if (!new_val && m_children[i].m_selected[p])
|
||||
if (!new_val && m_active_children[i].m_selected[p])
|
||||
{
|
||||
m_children[i].unfocused(PLAYER_ID_GAME_MASTER, NULL);
|
||||
m_active_children[i].unfocused(PLAYER_ID_GAME_MASTER, NULL);
|
||||
}
|
||||
m_children[i].m_selected[p] = new_val;
|
||||
if (new_val) m_children[i].focused(PLAYER_ID_GAME_MASTER);
|
||||
m_active_children[i].m_selected[p] = new_val;
|
||||
if (new_val) m_active_children[i].focused(PLAYER_ID_GAME_MASTER);
|
||||
}
|
||||
}
|
||||
|
||||
@ -670,11 +704,11 @@ EventPropagation RibbonWidget::transmitEvent(Widget* w,
|
||||
|
||||
if (!m_deactivated)
|
||||
{
|
||||
const int subbuttons_amount = m_children.size();
|
||||
const int subbuttons_amount = m_active_children.size();
|
||||
|
||||
for (int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
if (m_children[i].m_properties[PROP_ID] == originator)
|
||||
if (m_active_children[i].m_properties[PROP_ID] == originator)
|
||||
{
|
||||
m_selection[playerID] = i;
|
||||
break;
|
||||
@ -689,10 +723,10 @@ EventPropagation RibbonWidget::transmitEvent(Widget* w,
|
||||
|
||||
if (m_selection[playerID] != -1)
|
||||
{
|
||||
if (m_children[m_selection[playerID]].m_deactivated)
|
||||
if (m_active_children[m_selection[playerID]].m_deactivated)
|
||||
{
|
||||
GUIEngine::getCurrentScreen()->onDisabledItemClicked(
|
||||
m_children[m_selection[playerID]].m_properties[PROP_ID]);
|
||||
m_active_children[m_selection[playerID]].m_properties[PROP_ID]);
|
||||
|
||||
return EVENT_BLOCK;
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ namespace GUIEngine
|
||||
PtrVector<irr::gui::IGUIStaticText, REF> m_labels;
|
||||
|
||||
IRibbonListener* m_listener;
|
||||
|
||||
PtrVector<Widget> m_active_children;
|
||||
|
||||
public:
|
||||
|
||||
@ -106,7 +106,7 @@ namespace GUIEngine
|
||||
Widget* m_mouse_focus;
|
||||
|
||||
RibbonWidget(const RibbonType type=RIBBON_COMBO);
|
||||
virtual ~RibbonWidget() {}
|
||||
virtual ~RibbonWidget();
|
||||
|
||||
void add();
|
||||
|
||||
|
@ -111,7 +111,7 @@ bool CurrentOnlineUser::signIn( const irr::core::stringw &username,
|
||||
}
|
||||
else
|
||||
{
|
||||
info = _("Server error");
|
||||
info = _("Unable to connect to the server. Check your internet connection or try again later.");
|
||||
}
|
||||
|
||||
return m_is_signed_in;
|
||||
@ -146,7 +146,7 @@ irr::core::stringw CurrentOnlineUser::getUserName() const
|
||||
if(m_is_signed_in){
|
||||
return m_name;
|
||||
}else{
|
||||
return _("Not Signed In");
|
||||
return _("Not signed in");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "config/player.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/widgets/button_widget.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
#include "guiengine/widgets/text_box_widget.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
@ -38,11 +37,12 @@ using namespace irr::gui;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
LoginDialog::LoginDialog(const float w, const float h, const core::stringw& msg) :
|
||||
ModalDialog(w,h)
|
||||
LoginDialog::LoginDialog(const Message message_type) :
|
||||
ModalDialog(0.8f,0.8f)
|
||||
{
|
||||
m_self_destroy = false;
|
||||
m_open_registration_dialog = false;
|
||||
m_reshow_current_screen = false;
|
||||
loadFromFile("online/login_dialog.stkgui");
|
||||
|
||||
TextBoxWidget* textBox = getWidget<TextBoxWidget>("password");
|
||||
@ -53,9 +53,22 @@ LoginDialog::LoginDialog(const float w, const float h, const core::stringw& msg)
|
||||
assert(textBox != NULL);
|
||||
textBox->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
LabelWidget * info = getWidget<LabelWidget>("info");
|
||||
assert(info != NULL);
|
||||
info->setText(msg, false);
|
||||
LabelWidget * m_info_widget = getWidget<LabelWidget>("info");
|
||||
assert(m_info_widget != NULL);
|
||||
irr::core::stringw info;
|
||||
if (message_type == Normal)
|
||||
info = _("Fill in your username and password. ");
|
||||
else if (message_type == Signing_In_Required)
|
||||
info = _("You need to sign in to be able to use this feature. ");
|
||||
else if (message_type == Registration_Required)
|
||||
info = _("You need to be a registered user to enjoy this feature! "
|
||||
"If you do not have an account yet, you can sign up using the register icon at the bottom.");
|
||||
else
|
||||
info = "";
|
||||
if (message_type == Normal || message_type == Signing_In_Required)
|
||||
info += _("If you do not have an account yet, you can choose to sign in as a guest "
|
||||
"or press the register icon at the bottom to gain access to all the features!");
|
||||
m_info_widget->setText(info, false);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -64,6 +77,12 @@ LoginDialog::~LoginDialog()
|
||||
{
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void LoginDialog::beforeAddingWidgets()
|
||||
{
|
||||
LabelWidget * m_message_widget = getWidget<LabelWidget>("message");
|
||||
assert(m_message_widget != NULL);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@ -74,26 +93,28 @@ GUIEngine::EventPropagation LoginDialog::processEvent(const std::string& eventSo
|
||||
m_self_destroy = true;
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
else if(eventSource == "signin")
|
||||
else if(eventSource == "sign_in")
|
||||
{
|
||||
// ---- See if we can accept the input
|
||||
const stringw username = getWidget<TextBoxWidget>("username")->getText().trim();
|
||||
const stringw password = getWidget<TextBoxWidget>("password")->getText().trim();
|
||||
stringw info = "";
|
||||
if(CurrentOnlineUser::get()->signIn(username,password,info))
|
||||
{
|
||||
m_reshow_current_screen = true;
|
||||
m_self_destroy = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sfx_manager->quickSound( "anvil" );
|
||||
LabelWidget * infoLabel = getWidget<LabelWidget>("info");
|
||||
infoLabel->setColor(irr::video::SColor(255, 255, 0, 0));
|
||||
infoLabel->setText(info, false);
|
||||
Log::info("Login Dialog", "check1");
|
||||
irr::video::SColor red(255, 255, 0, 0);
|
||||
m_message_widget->setColor(red);
|
||||
m_message_widget->setText(info, false);
|
||||
Log::info("Login Dialog", "check2");
|
||||
}
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
else if(eventSource == "signup")
|
||||
else if(eventSource == "sign_up")
|
||||
{
|
||||
m_open_registration_dialog = true;
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
@ -109,12 +130,12 @@ void LoginDialog::onEnterPressedInternal()
|
||||
const int playerID = PLAYER_ID_GAME_MASTER;
|
||||
ButtonWidget* cancelButton = getWidget<ButtonWidget>("cancel");
|
||||
assert(cancelButton != NULL);
|
||||
ButtonWidget* registerButton = getWidget<ButtonWidget>("signup");
|
||||
ButtonWidget* registerButton = getWidget<ButtonWidget>("sign_up");
|
||||
assert(registerButton != NULL);
|
||||
if (!GUIEngine::isFocusedForPlayer(cancelButton, playerID) &&
|
||||
!GUIEngine::isFocusedForPlayer(registerButton, playerID))
|
||||
{
|
||||
processEvent("signin");
|
||||
processEvent("sign_in");
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,12 +145,17 @@ void LoginDialog::onUpdate(float dt)
|
||||
{
|
||||
//If we want to open the registration dialog, we need to close this one first
|
||||
m_open_registration_dialog && (m_self_destroy = true);
|
||||
|
||||
// It's unsafe to delete from inside the event handler so we do it here
|
||||
if (m_self_destroy)
|
||||
{
|
||||
ModalDialog::dismiss();
|
||||
if (m_reshow_current_screen)
|
||||
GUIEngine::reshowCurrentScreen();
|
||||
if (m_open_registration_dialog)
|
||||
new RegistrationDialog(0.8f, 0.9f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
#include "guiengine/widgets/text_box_widget.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
|
||||
/**
|
||||
* \brief Dialog that allows a user to sign in
|
||||
@ -35,17 +36,28 @@ private:
|
||||
|
||||
bool m_self_destroy;
|
||||
bool m_open_registration_dialog;
|
||||
bool m_reshow_current_screen;
|
||||
GUIEngine::LabelWidget * m_message_widget;
|
||||
GUIEngine::LabelWidget * m_info_widget;
|
||||
|
||||
public:
|
||||
|
||||
enum Message
|
||||
{
|
||||
Normal = 1, // If the user presses the sign in button himself
|
||||
Signing_In_Required = 2, // If the user needs to be signed in
|
||||
Registration_Required = 3 // If the user needs to be registered
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a modal dialog with given percentage of screen width and height
|
||||
*/
|
||||
LoginDialog(const float percentWidth, const float percentHeight, const core::stringw& msg);
|
||||
LoginDialog(const Message);
|
||||
~LoginDialog();
|
||||
|
||||
void onEnterPressedInternal();
|
||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
|
||||
void beforeAddingWidgets();
|
||||
|
||||
virtual void onUpdate(float dt);
|
||||
//virtual void onTextUpdated();
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "challenges/unlock_manager.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "guiengine/scalable_font.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
@ -35,11 +34,13 @@
|
||||
#include "main_loop.hpp"
|
||||
#include "states_screens/online_screen.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/dialogs/login_dialog.hpp"
|
||||
#include "states_screens/dialogs/message_dialog.hpp"
|
||||
#include "modes/demo_world.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
#include "online/current_online_user.hpp"
|
||||
#include "states_screens/dialogs/login_dialog.hpp"
|
||||
|
||||
|
||||
using namespace GUIEngine;
|
||||
|
||||
@ -55,29 +56,20 @@ OnlineScreen::OnlineScreen() : Screen("online/main.stkgui")
|
||||
|
||||
void OnlineScreen::loadedFromFile()
|
||||
{
|
||||
|
||||
Log::info("OnlineScreen", "Loaded from file");
|
||||
} // loadedFromFile
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
void OnlineScreen::init()
|
||||
{
|
||||
Screen::init();
|
||||
RibbonWidget* r = getWidget<RibbonWidget>("menu_toprow");
|
||||
r->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
DemoWorld::resetIdleTime();
|
||||
|
||||
} // init
|
||||
|
||||
|
||||
void OnlineScreen::beforeAddingWidget()
|
||||
{
|
||||
Log::info("OnlineScreen", "Before adding widget");
|
||||
RibbonWidget* topRow = getWidget<RibbonWidget>("menu_toprow");
|
||||
assert(topRow != NULL);
|
||||
RibbonWidget* bottomRow = getWidget<RibbonWidget>("menu_bottomrow");
|
||||
assert(bottomRow != NULL);
|
||||
if(CurrentOnlineUser::get()->isSignedIn())
|
||||
{
|
||||
|
||||
if(CurrentOnlineUser::get()->isGuest())
|
||||
{
|
||||
|
||||
@ -87,12 +79,32 @@ void OnlineScreen::beforeAddingWidget()
|
||||
//Signed in and not guest
|
||||
bottomRow->removeChildNamed("sign_in");
|
||||
}
|
||||
bottomRow->removeChildNamed("sign_up");
|
||||
}
|
||||
else
|
||||
{
|
||||
bottomRow->removeChildNamed("sign_out");
|
||||
|
||||
//bottomRow->removeChildNamed("sign_out");
|
||||
IconButtonWidget* iconbutton = getWidget<IconButtonWidget>("sign_out");
|
||||
iconbutton->setVisible(false);
|
||||
IconButtonWidget* quick_play = getWidget<IconButtonWidget>("quick_play");
|
||||
quick_play->setVisible(false);
|
||||
}
|
||||
}
|
||||
} // beforeAddingWidget
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void OnlineScreen::init()
|
||||
{
|
||||
Screen::init();
|
||||
m_online_status_widget = getWidget<LabelWidget>("online_status");
|
||||
assert(m_online_status_widget != NULL);
|
||||
RibbonWidget* r = getWidget<RibbonWidget>("menu_bottomrow");
|
||||
r->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
DemoWorld::resetIdleTime();
|
||||
m_online_status_widget->setText(irr::core::stringw("Signed in as : ") + CurrentOnlineUser::get()->getUserName(), true);
|
||||
} // init
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
|
||||
@ -115,11 +127,32 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const
|
||||
|
||||
if (selection == "sign_in")
|
||||
{
|
||||
new LoginDialog(0.6f, 0.6f, _("Not yet an account? Press register beneath!"));
|
||||
new LoginDialog(LoginDialog::Normal);
|
||||
}
|
||||
else if (selection == "sign_out")
|
||||
{
|
||||
CurrentOnlineUser::get()->signOut();
|
||||
if (CurrentOnlineUser::get()->signOut())
|
||||
{
|
||||
new MessageDialog( _("Signed out successfully.") );
|
||||
GUIEngine::reshowCurrentScreen();
|
||||
}
|
||||
else
|
||||
{
|
||||
new MessageDialog( _("An error occured while signing out.") );
|
||||
}
|
||||
|
||||
}
|
||||
else if (selection == "find_server")
|
||||
{
|
||||
new LoginDialog(LoginDialog::Registration_Required);
|
||||
}
|
||||
else if (selection == "create_server")
|
||||
{
|
||||
new LoginDialog(LoginDialog::Registration_Required);
|
||||
}
|
||||
else if (selection == "quick_play")
|
||||
{
|
||||
new LoginDialog(LoginDialog::Signing_In_Required);
|
||||
}
|
||||
|
||||
} // eventCallback
|
||||
@ -135,12 +168,3 @@ void OnlineScreen::tearDown()
|
||||
void OnlineScreen::onDisabledItemClicked(const std::string& item)
|
||||
{
|
||||
} // onDisabledItemClicked
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void OnlineScreen::reload()
|
||||
{
|
||||
this->unload();
|
||||
if (!this->isLoaded()) this->loadFromFile();
|
||||
this->init();
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define HEADER_ONLINE_SCREEN_HPP
|
||||
|
||||
#include "guiengine/screen.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
|
||||
namespace GUIEngine { class Widget; class ListWidget; }
|
||||
|
||||
@ -32,11 +33,10 @@ private:
|
||||
friend class GUIEngine::ScreenSingleton<OnlineScreen>;
|
||||
|
||||
OnlineScreen();
|
||||
GUIEngine::LabelWidget* m_online_status_widget;
|
||||
|
||||
public:
|
||||
|
||||
void reload();
|
||||
|
||||
virtual void onUpdate(float delta, irr::video::IVideoDriver* driver) OVERRIDE;
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
|
Loading…
Reference in New Issue
Block a user