Implemented a callback listener for the login dialog. Added a vote dialog for addons.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13395 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-07-31 20:47:06 +00:00
parent ea2b52a663
commit 9a4c93f2de
15 changed files with 269 additions and 9509 deletions

View File

@ -3,12 +3,12 @@
<div x="5%" y="5%" width="90%" height="90%" layout="vertical-row">
<div x="5%" y="0%" width="90%" proportion="6" layout="horizontal-row" >
<div x="5%" y="0%" width="90%" proportion="5" layout="horizontal-row" >
<div width="40%" height="100%" layout="vertical-row" >
<icon id="icon" align="center" proportion="8" width="100%" icon="gui/loading.png"/>
<spacer proportion="1" />
<spacer proportion="1" width="1"/>
</div>
<spacer proportion="1" />
<spacer proportion="1" width="1" />
<div width="60%" height="50%" layout="vertical-row" >
<label id="name" width="100%" text_align="left"/>
<div width="100%" height="100%" layout="horizontal-row" >
@ -20,22 +20,25 @@
<ratingbar id="rating" height="64" width="100%"/>
</div>
</div>
<spacer height="10"/>
<spacer height="10" width="1"/>
<label id="flags" width="100%" text="" word_wrap="true"/>
</div>
</div>
<bubble word_wrap="true" id="description" height="100%" width="90%" proportion="5" align="center" />
<bubble word_wrap="true" id="description" height="100%" width="90%" proportion="6" align="center" />
<div width="80%" proportion="5" align="center">
<div width="80%" proportion="3" align="center">
<buttonbar id="actions" x="0" y="0" height="100%" width="100%" align="center">
<icon-button id="install" width="128" height="128"
<icon-button id="install" width="64" height="64"
icon="gui/package-update.png"
I18N="Add-on screen action" text="Install"/>
<icon-button id="uninstall" width="128" height="128"
<icon-button id="uninstall" width="64" height="64"
icon="gui/package-uninstall.png"
I18N="Add-on screen action" text="Uninstall"/>
<icon-button id="back" width="128" height="128"
<icon-button id="vote" width="64" height="64"
icon="gui/banana.png"
I18N="Add-ons screen action" text="Vote"/>
<icon-button id="back" width="64" height="64"
icon="gui/back.png"
I18N="Add-ons screen action" text="Back"/>
</buttonbar>

View File

@ -0,0 +1,25 @@
<stkgui>
<div x="2%" y="5%" width="96%" height="90%" layout="vertical-row" >
<header id="title" width="96%" height="fit" text_align="center" word_wrap="true"
I18N="In the vote dialog' dialog" text="Vote"/>
<spacer proportion="1" width="50">
<div width="80%" height="fit" layout="vertical-row" >
<ratingbar id="rating" height="64" width="100%"/>
</div>
<spacer proportion="1" width="50">
<buttonbar id="options" width="25%" height="15%" align="center">
<icon-button id="submit" width="64" height="64" icon="gui/green_check.png"
I18N="Vote dialog" text="Submit" label_location="none"/>
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
I18N="Vote dialog" text="Cancel" label_location="none"/>
</buttonbar>
</div>
</stkgui>

9473
diff.patch

File diff suppressed because it is too large Load Diff

View File

@ -215,6 +215,7 @@ src/states_screens/dialogs/select_challenge.cpp
src/states_screens/dialogs/server_info_dialog.cpp
src/states_screens/dialogs/track_info_dialog.cpp
src/states_screens/dialogs/tutorial_message_dialog.cpp
src/states_screens/dialogs/vote_dialog.cpp
src/states_screens/feature_unlocked.cpp
src/states_screens/grand_prix_lose.cpp
src/states_screens/grand_prix_win.cpp
@ -510,6 +511,7 @@ src/states_screens/dialogs/select_challenge.hpp
src/states_screens/dialogs/server_info_dialog.hpp
src/states_screens/dialogs/track_info_dialog.hpp
src/states_screens/dialogs/tutorial_message_dialog.hpp
src/states_screens/dialogs/vote_dialog.hpp
src/states_screens/feature_unlocked.hpp
src/states_screens/grand_prix_lose.hpp
src/states_screens/grand_prix_win.hpp

View File

@ -57,7 +57,7 @@ void RatingBarWidget::add()
int RatingBarWidget::getStepOfStar(int index, int max_step)
{
assert(index >= 0 && index < m_star_number); // Index must be between 0 and m_star_number - 1.
assert(max_step >= 2); // The maximun number of step must be superior or equals to 2.
assert(max_step >= 2); // The maximun number of step must be larger or equal to 2.
if (m_rating < index)
{
@ -83,3 +83,10 @@ int RatingBarWidget::getStepOfStar(int index, int max_step)
// TODO: Assert or throws a exception, what type?
} // getStepOfStar
EventPropagation RatingBarWidget::mouseHovered(Widget* child, const int playerID) {
Log::info("RatingBarWidget::mouseHovered","");
//m_rating++;
return EVENT_BLOCK;
}

View File

@ -38,6 +38,10 @@ namespace GUIEngine
float m_rating;
int m_star_number;
protected:
virtual EventPropagation mouseHovered(Widget* child, const int playerID);
public:
LEAK_CHECK()
@ -45,6 +49,8 @@ namespace GUIEngine
RatingBarWidget();
virtual ~RatingBarWidget() {}
void add();
/** Change the rating value of the widget. */
@ -53,10 +59,10 @@ namespace GUIEngine
/** Get the current value of the widget. */
float getRating() {return m_rating; };
/** Change the number of star of the widget. */
/** Change the number of stars of the widget. */
void setStarNumber(int star_number) { m_star_number = star_number; };
/** Get the current number of star of the widget. */
/** Get the current number of stars of the widget. */
int getStarNumber() {return m_star_number; };
int getStepOfStar(int index, int max_step);

View File

@ -132,6 +132,10 @@ namespace Online{
/** Returns the username if signed in. */
const irr::core::stringw getUserName() const;
const UserState getUserState() const { return m_state.getAtomic(); }
bool isRegisteredUser() const {
MutexLocker(m_state);
return m_state.getData() == US_SIGNED_IN;
}
const std::string getToken() const { return m_token.getAtomic(); }
}; // class CurrentUser

View File

@ -426,7 +426,7 @@ void AddonsScreen::eventCallback(GUIEngine::Widget* widget,
if (!id.empty() && addons_manager->getAddon(id) != NULL)
{
m_selected_index = list->getSelectionID();
new AddonsLoading(0.8f, 0.8f, id);
new AddonsLoading(id);
}
}
if (name == "category")

View File

@ -31,6 +31,8 @@
#include "io/file_manager.hpp"
#include "states_screens/addons_screen.hpp"
#include "states_screens/dialogs/message_dialog.hpp"
#include "states_screens/dialogs/vote_dialog.hpp"
#include "states_screens/dialogs/login_dialog.hpp"
#include "states_screens/state_manager.hpp"
#include "tracks/track_manager.hpp"
#include "utils/string_utils.hpp"
@ -43,10 +45,11 @@ using namespace irr::gui;
/** Creates a modal dialog with given percentage of screen width and height
*/
AddonsLoading::AddonsLoading(const float w, const float h,
const std::string &id)
: ModalDialog(w, h)
AddonsLoading::AddonsLoading(const std::string &id)
: ModalDialog(0.8f, 0.8f)
{
m_vote_clicked = false;
m_addon = *(addons_manager->getAddon(id));
m_icon_shown = false;
m_download_request = NULL;
@ -197,8 +200,7 @@ void AddonsLoading::escapePressed()
// ----------------------------------------------------------------------------
GUIEngine::EventPropagation
AddonsLoading::processEvent(const std::string& event_source)
GUIEngine::EventPropagation AddonsLoading::processEvent(const std::string& event_source)
{
GUIEngine::RibbonWidget* actions_ribbon =
getWidget<GUIEngine::RibbonWidget>("actions");
@ -236,13 +238,34 @@ GUIEngine::EventPropagation
doUninstall();
return GUIEngine::EVENT_BLOCK;
}
else if (selection == "vote")
{
voteClicked();
return GUIEngine::EVENT_BLOCK;
}
}
return GUIEngine::EVENT_LET;
} // processEvent
// ----------------------------------------------------------------------------
void AddonsLoading::voteClicked()
{
ModalDialog::dismiss();
if (Online::CurrentUser::get()->isRegisteredUser())
new VoteDialog(m_addon.getId());
else
new LoginDialog(LoginDialog::Registration_Required, new VoteDialog::LoginListener(m_addon.getId()));
}
// ----------------------------------------------------------------------------
void AddonsLoading::onUpdate(float delta)
{
if(m_vote_clicked)
{
voteClicked();
return;
}
if(m_progress->isVisible())
{
float progress = m_download_request->getProgress();

View File

@ -55,16 +55,15 @@ private:
* to the progress of a download. */
Request *m_download_request;
bool m_vote_clicked;
public:
AddonsLoading(const float percent_width,
const float percent_height,
const std::string &addon_name);
AddonsLoading(const std::string &addon_name);
~AddonsLoading();
virtual GUIEngine::EventPropagation processEvent(const std::string& event_source);
virtual void beforeAddingWidgets();
virtual void init();
/** This function is called by the GUI, all the frame (or somthing like
@ -72,6 +71,7 @@ public:
* and do the necessary.
* */
void onUpdate(float delta);
void voteClicked();
}; // AddonsLoading

View File

@ -37,12 +37,13 @@ using namespace Online;
// -----------------------------------------------------------------------------
LoginDialog::LoginDialog(const Message message_type) :
ModalDialog(0.8f,0.9f)
LoginDialog::LoginDialog(const Message message_type, const LoginDialog::Listener * listener) :
ModalDialog(0.8f,0.9f), m_listener(listener)
{
m_self_destroy = false;
m_open_registration_dialog = false;
m_open_recovery_dialog = false;
m_success = false;
m_sign_in_request = NULL;
loadFromFile("online/login_dialog.stkgui");
@ -181,7 +182,7 @@ void LoginDialog::onUpdate(float dt)
{
if(m_sign_in_request->isSuccess())
{
m_self_destroy = true;
m_success = true;
}
else
{
@ -200,7 +201,7 @@ void LoginDialog::onUpdate(float dt)
}
}
//If we want to open another dialog, we need to close this one first
(m_open_registration_dialog || m_open_recovery_dialog) && (m_self_destroy = true);
(m_open_registration_dialog || m_open_recovery_dialog || m_success) && (m_self_destroy = true);
// It's unsafe to delete from inside the event handler so we do it here
if (m_self_destroy)
@ -210,6 +211,8 @@ void LoginDialog::onUpdate(float dt)
new RegistrationDialog();
else if (m_open_recovery_dialog)
new RecoveryDialog();
else if (m_success && (m_listener != NULL) )
m_listener->onSuccess();
return;
}
}

View File

@ -33,11 +33,21 @@
class LoginDialog : public GUIEngine::ModalDialog
{
public:
class Listener
{
public :
virtual void onSuccess() const = 0;
};
private:
const Listener * m_listener;
bool m_self_destroy;
bool m_open_registration_dialog;
bool m_open_recovery_dialog;
bool m_success;
const Online::CurrentUser::SignInRequest * m_sign_in_request;
GUIEngine::LabelWidget * m_message_widget;
GUIEngine::TextBoxWidget * m_username_widget;
@ -66,7 +76,7 @@ public:
/**
* Creates a modal dialog with given percentage of screen width and height
*/
LoginDialog(const Message);
LoginDialog(const Message, const LoginDialog::Listener * = NULL);
~LoginDialog();
void onEnterPressedInternal();

View File

@ -44,8 +44,6 @@ private:
bool m_from_server_creation;
const Online::CurrentUser::ServerJoinRequest * m_server_join_request;
float m_load_timer;
const uint32_t m_server_id;
uint32_t m_host_id;

View File

@ -0,0 +1,88 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Glenn De Jonghe
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "states_screens/dialogs/vote_dialog.hpp"
#include <IGUIEnvironment.h>
#include "audio/sfx_manager.hpp"
//#include "config/player.hpp"
#include "guiengine/engine.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"
#include "online/current_user.hpp"
#include "online/messages.hpp"
using namespace GUIEngine;
using namespace irr;
using namespace irr::gui;
using namespace Online;
// -----------------------------------------------------------------------------
VoteDialog::VoteDialog(const std::string & addon_id)
: ModalDialog(0.8f,0.8f)
{
m_self_destroy = false;
loadFromFile("online/vote_dialog.stkgui");
m_rating_widget = getWidget<RatingBarWidget>("rating");
assert(m_rating_widget != NULL);
m_rating_widget->setRating(0);
m_rating_widget->setStarNumber(3);
m_options_widget = getWidget<RibbonWidget>("options");
assert(m_options_widget != NULL);
m_submit_widget = getWidget<IconButtonWidget>("submit");
assert(m_submit_widget != NULL);
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
assert(m_cancel_widget != NULL);
m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
}
// -----------------------------------------------------------------------------
VoteDialog::~VoteDialog()
{
//delete m_server_join_request;
}
// -----------------------------------------------------------------------------
GUIEngine::EventPropagation VoteDialog::processEvent(const std::string& eventSource)
{
if (eventSource == m_options_widget->m_properties[PROP_ID])
{
const std::string& selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if (selection == m_rating_widget->m_properties[PROP_ID])
{
m_self_destroy = true;
return GUIEngine::EVENT_BLOCK;
}
}
return GUIEngine::EVENT_LET;
}
// -----------------------------------------------------------------------------
void VoteDialog::onUpdate(float dt)
{
}

View File

@ -0,0 +1,64 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Glenn De Jonghe
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_VOTE_DIALOG_HPP
#define HEADER_VOTE_DIALOG_HPP
#include <irrString.h>
#include "guiengine/modaldialog.hpp"
#include "guiengine/widgets.hpp"
#include "online/current_user.hpp"
#include "utils/types.hpp"
#include "states_screens/dialogs/login_dialog.hpp"
/**
* \brief Dialog that allows a user to sign in
* \ingroup states_screens
*/
class VoteDialog : public GUIEngine::ModalDialog
{
public :
class LoginListener : public LoginDialog::Listener
{
const std::string m_addon_id;
public :
LoginListener(const std::string & addon_id) : m_addon_id(addon_id) {}
virtual void onSuccess() const { new VoteDialog(m_addon_id); }
};
private:
bool m_self_destroy;
//const Online::CurrentUser::AddonVoteRequest * m_addon_vote_request;
GUIEngine::RatingBarWidget * m_rating_widget;
GUIEngine::RibbonWidget * m_options_widget;
GUIEngine::IconButtonWidget * m_submit_widget;
GUIEngine::IconButtonWidget * m_cancel_widget;
public:
VoteDialog(const std::string & addon_id);
~VoteDialog();
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
virtual void onUpdate(float dt);
};
#endif