diff --git a/data/gui/online/guest_login.stkgui b/data/gui/online/guest_login.stkgui
new file mode 100644
index 000000000..b69941132
--- /dev/null
+++ b/data/gui/online/guest_login.stkgui
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/data/gui/online/login.stkgui b/data/gui/online/login.stkgui
new file mode 100644
index 000000000..2d7159f10
--- /dev/null
+++ b/data/gui/online/login.stkgui
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/data/gui/online/login_dialog.stkgui b/data/gui/online/login_dialog.stkgui
index b60b8599e..d0b74ed7e 100644
--- a/data/gui/online/login_dialog.stkgui
+++ b/data/gui/online/login_dialog.stkgui
@@ -5,11 +5,11 @@
-
+
-
+
@@ -17,14 +17,14 @@
-
+
-
+
@@ -34,11 +34,11 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/data/gui/online/registration_terms.stkgui b/data/gui/online/registration_terms.stkgui
index c2c4d4396..4c94d47e5 100644
--- a/data/gui/online/registration_terms.stkgui
+++ b/data/gui/online/registration_terms.stkgui
@@ -14,7 +14,6 @@
-
@@ -25,12 +24,10 @@
-
-
+
+ I18N="Registration dialog" text="Cancel" label_location="bottom"/>
diff --git a/sources.cmake b/sources.cmake
index d32269956..28aded699 100644
--- a/sources.cmake
+++ b/sources.cmake
@@ -243,11 +243,13 @@ src/states_screens/easter_egg_screen.cpp
src/states_screens/feature_unlocked.cpp
src/states_screens/grand_prix_lose.cpp
src/states_screens/grand_prix_win.cpp
+src/states_screens/guest_login_screen.cpp
src/states_screens/help_screen_1.cpp
src/states_screens/help_screen_2.cpp
src/states_screens/help_screen_3.cpp
src/states_screens/help_screen_4.cpp
src/states_screens/kart_selection.cpp
+src/states_screens/login_screen.cpp
src/states_screens/main_menu_screen.cpp
src/states_screens/network_kart_selection.cpp
src/states_screens/networking_lobby.cpp
@@ -270,6 +272,7 @@ src/states_screens/race_gui_base.cpp
src/states_screens/race_gui_overworld.cpp
src/states_screens/race_result_gui.cpp
src/states_screens/race_setup_screen.cpp
+src/states_screens/register_screen.cpp
src/states_screens/server_selection.cpp
src/states_screens/soccer_setup_screen.cpp
src/states_screens/state_manager.cpp
@@ -572,11 +575,13 @@ src/states_screens/easter_egg_screen.hpp
src/states_screens/feature_unlocked.hpp
src/states_screens/grand_prix_lose.hpp
src/states_screens/grand_prix_win.hpp
+src/states_screens/guest_login_screen.hpp
src/states_screens/help_screen_1.hpp
src/states_screens/help_screen_2.hpp
src/states_screens/help_screen_3.hpp
src/states_screens/help_screen_4.hpp
src/states_screens/kart_selection.hpp
+src/states_screens/login_screen.hpp
src/states_screens/main_menu_screen.hpp
src/states_screens/network_kart_selection.hpp
src/states_screens/networking_lobby.hpp
@@ -599,6 +604,7 @@ src/states_screens/race_gui_base.hpp
src/states_screens/race_gui_overworld.hpp
src/states_screens/race_result_gui.hpp
src/states_screens/race_setup_screen.hpp
+src/states_screens/register_screen.hpp
src/states_screens/server_selection.hpp
src/states_screens/soccer_setup_screen.hpp
src/states_screens/state_manager.hpp
diff --git a/src/online/current_user.cpp b/src/online/current_user.cpp
index bc0ef7b08..e824b3b85 100644
--- a/src/online/current_user.cpp
+++ b/src/online/current_user.cpp
@@ -28,8 +28,9 @@
#include "utils/translation.hpp"
#include "addons/addon.hpp"
#include "guiengine/dialog_queue.hpp"
+#include "guiengine/screen.hpp"
+#include "states_screens/login_screen.hpp"
#include "states_screens/dialogs/change_password_dialog.hpp"
-#include "states_screens/dialogs/login_dialog.hpp"
#include "states_screens/dialogs/user_info_dialog.hpp"
#include "states_screens/dialogs/notification_dialog.hpp"
#include "states_screens/online_profile_friends.hpp"
@@ -88,8 +89,7 @@ namespace Online
const XMLRequest * CurrentUser::requestSignUp(const core::stringw &username,
const core::stringw &password,
const core::stringw &password_confirm,
- const core::stringw &email,
- bool terms)
+ const core::stringw &email)
{
assert(m_state == US_SIGNED_OUT || m_state == US_GUEST);
XMLRequest * request = new XMLRequest();
@@ -139,7 +139,7 @@ namespace Online
{
assert(m_state == US_SIGNED_OUT);
m_save_session = save_session;
- SignInRequest * request = new SignInRequest(request_now);
+ SignInRequest * request = new SignInRequest(false);
request->setServerURL("client-user.php");
request->addParameter("action","connect");
request->addParameter("username",username);
@@ -159,18 +159,15 @@ namespace Online
void CurrentUser::SignInRequest::callback()
{
CurrentUser::get()->signIn(isSuccess(), getXMLData());
- if(GUIEngine::ModalDialog::isADialogActive())
+ GUIEngine::Screen *screen = GUIEngine::getCurrentScreen();
+ LoginScreen *login = dynamic_cast(screen);
+ if(login)
{
- LoginDialog * dialog =
- dynamic_cast(GUIEngine::ModalDialog::getCurrent());
- if(dialog)
- {
- if(isSuccess())
- dialog->success();
- else
- dialog->error(getInfo());
- } // if dialog
- } // isDialogActive
+ if(isSuccess())
+ login->loginSuccessful();
+ else
+ login->loginError(getInfo());
+ } // if dialog
} // SignInRequest::callback
// ------------------------------------------------------------------------
@@ -841,7 +838,8 @@ namespace Online
} // getUserName
// ------------------------------------------------------------------------
- /** \return the online id. */
+ /** \return the online id, or 0 if the user is not signed in.
+ */
uint32_t CurrentUser::getID() const
{
if((m_state == US_SIGNED_IN ))
diff --git a/src/online/current_user.hpp b/src/online/current_user.hpp
index d7d4b106a..f5b00e03c 100644
--- a/src/online/current_user.hpp
+++ b/src/online/current_user.hpp
@@ -180,8 +180,7 @@ namespace Online
const XMLRequest * requestSignUp( const irr::core::stringw &username,
const irr::core::stringw &password,
const irr::core::stringw &password_ver,
- const irr::core::stringw &email,
- bool terms);
+ const irr::core::stringw &email);
const XMLRequest * requestRecovery(const irr::core::stringw &username,
const irr::core::stringw &email);
diff --git a/src/states_screens/dialogs/registration_dialog.cpp b/src/states_screens/dialogs/registration_dialog.cpp
index 8fea4ad53..f1e9626c8 100644
--- a/src/states_screens/dialogs/registration_dialog.cpp
+++ b/src/states_screens/dialogs/registration_dialog.cpp
@@ -23,6 +23,7 @@
#include "config/player.hpp"
#include "guiengine/engine.hpp"
#include "states_screens/state_manager.hpp"
+#include "states_screens/register_screen.hpp"
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"
#include "online/messages.hpp"
@@ -38,86 +39,7 @@ using namespace Online;
RegistrationDialog::RegistrationDialog() :
ModalDialog(0.8f,0.9f)
{
- m_sign_up_request = NULL;
- m_self_destroy = false;
- m_show_registration_input = false;
- m_show_registration_terms = false;
- m_show_registration_info = false;
- m_username = "";
- m_email = "";
- m_email_confirm = "";
- m_password = "";
- m_password_confirm = "";
- m_agreement = false;
- showRegistrationInput();
-}
-
-// -----------------------------------------------------------------------------
-
-RegistrationDialog::~RegistrationDialog()
-{
- delete m_sign_up_request;
-}
-
-// -----------------------------------------------------------------------------
-
-void RegistrationDialog::showRegistrationInput()
-{
- if(isInited())
- clearWindow();
- m_show_registration_input = false;
- m_phase = Input;
- loadFromFile("online/registration_input.stkgui");
-
- //Password should always be reentered if previous has been clicked, or an error occurred.
- m_password = "";
- m_password_confirm = "";
-
- m_username_widget = getWidget("username");
- assert(m_username_widget != NULL);
- m_username_widget->setText(m_username);
- m_username_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
-
- m_password_widget = getWidget("password");
- assert(m_password_widget != NULL);
- m_password_widget->setPasswordBox(true,L'*');
-
- m_password_confirm_widget = getWidget("password_confirm");
- assert(m_password_confirm_widget != NULL);
- m_password_confirm_widget->setPasswordBox(true,L'*');
-
- m_email_widget = getWidget("email");
- assert(m_email_widget != NULL);
- m_email_widget->setText(m_email);
-
- m_email_confirm_widget = getWidget("email_confirm");
- assert(m_email_confirm_widget != NULL);
- m_email_confirm_widget->setText(m_email_confirm);
-
- m_info_widget = getWidget("info");
- assert(m_info_widget != NULL);
- m_info_widget->setErrorColor();
- m_info_widget->setText(m_registration_error, false);
-
- m_options_widget = getWidget("options");
- assert(m_options_widget != NULL);
- m_next_widget = getWidget("next");
- assert(m_next_widget != NULL);
- m_cancel_widget = getWidget("cancel");
- assert(m_cancel_widget != NULL);
-}
-
-// -----------------------------------------------------------------------------
-
-void RegistrationDialog::showRegistrationTerms()
-{
- m_show_registration_terms = false;
- if(isInited())
- clearWindow();
- m_phase = Terms;
loadFromFile("online/registration_terms.stkgui");
-
-
ListWidget * terms_widget = getWidget("terms");
@@ -132,218 +54,35 @@ void RegistrationDialog::showRegistrationTerms()
"one of the members of the development team would gladly assist you."
, -1 , false );
-
- m_accept_terms_widget = getWidget("accepted");
- assert(m_accept_terms_widget != NULL);
- m_accept_terms_widget->setState(false);
- m_accept_terms_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); //FIXME set focus on the terms
-
- m_info_widget = getWidget("info");
- assert(m_info_widget != NULL);
-
- m_options_widget = getWidget("options");
- assert(m_options_widget != NULL);
- m_previous_widget = getWidget("previous");
- assert(m_previous_widget != NULL);
- m_next_widget = getWidget("next");
- assert(m_next_widget != NULL);
- m_cancel_widget = getWidget("cancel");
- assert(m_cancel_widget != NULL);
- m_next_widget->setDeactivated();
+ // showRegistrationTerms();
}
// -----------------------------------------------------------------------------
-void RegistrationDialog::showRegistrationInfo()
+RegistrationDialog::~RegistrationDialog()
{
- m_show_registration_info = false;
- if(isInited())
- clearWindow();
- m_phase = Info;
- loadFromFile("online/registration_info.stkgui");
-
- m_info_widget = getWidget("info");
- assert(m_info_widget != NULL);
-
- m_options_widget = getWidget("options");
- assert(m_options_widget != NULL);
- m_cancel_widget = getWidget("cancel");
- assert(m_cancel_widget != NULL);
}
// -----------------------------------------------------------------------------
-
-void RegistrationDialog::processInput()
+/** Process input events.
+ * \event_source name of the widget that triggered the event.
+ */
+EventPropagation RegistrationDialog::processEvent(const std::string& event_source)
{
- m_username = m_username_widget->getText().trim();
- m_password = m_password_widget->getText().trim();
- m_password_confirm = m_password_confirm_widget->getText().trim();
- m_email = m_email_widget->getText().trim();
- m_email_confirm = m_email_confirm_widget->getText().trim();
- //FIXME More validation of registration information
- m_info_widget->setErrorColor();
- if (m_password != m_password_confirm)
+ if (event_source == "options")
{
- m_info_widget->setText(_("Passwords don't match!"), false);
- }
- else if (m_email != m_email_confirm)
- {
- m_info_widget->setText(_("Emails don't match!"), false);
- }
- else if (m_username.size() < 4 || m_username.size() > 30)
- {
- m_info_widget->setText(_("Username has to be between 4 and 30 characters long!"), false);
- }
- else if (m_password.size() < 8 || m_password.size() > 30)
- {
- m_info_widget->setText(_("Password has to be between 8 and 30 characters long!"), false);
- }
- else if (m_email.size() < 4 || m_email.size() > 50)
- {
- m_info_widget->setText(_("Email has to be between 4 and 50 characters long!"), false);
- }
- else
- {
- m_show_registration_terms = true;
- return;
- }
- sfx_manager->quickSound( "anvil" );
-}
-
-
-// -----------------------------------------------------------------------------
-
-bool RegistrationDialog::processInputEvent(const std::string& eventSource)
-{
- if (m_phase == Input)
- {
- if (eventSource == m_next_widget->m_properties[PROP_ID])
+ RibbonWidget *rib = getWidget("options");
+ std::string s = rib->getSelectionIDString(PLAYER_ID_GAME_MASTER);
+ if(s=="accept")
{
- processInput();
- return true;
+ Screen *s = GUIEngine::getCurrentScreen();
+ RegisterScreen *r = dynamic_cast(s);
+ assert(r);
+ r->acceptTerms();
}
- }
- return false;
-}
-
-// -----------------------------------------------------------------------------
-
-bool RegistrationDialog::processTermsEvent(const std::string& eventSource)
-{
- if (m_phase == Terms)
- {
- if (eventSource == m_next_widget->m_properties[PROP_ID])
- {
- assert(m_accept_terms_widget->getState());
- m_options_widget->setDeactivated();
- m_info_widget->setDefaultColor();
- m_info_widget->setText(Messages::validatingInfo(), false);
- m_sign_up_request = CurrentUser::get()->requestSignUp(m_username, m_password, m_password_confirm, m_email, true);
- return true;
- }
- else if (eventSource == m_accept_terms_widget->m_properties[PROP_ID])
- {
- bool new_state = !m_accept_terms_widget->getState();
- m_accept_terms_widget->setState(new_state);
- if(new_state)
- m_next_widget->setActivated();
- else
- m_next_widget->setDeactivated();
- return true;
- }
- else if (eventSource == m_previous_widget->m_properties[PROP_ID])
- {
- m_show_registration_info = true;
- return true;
- }
- }
- return false;
-}
-
-// -----------------------------------------------------------------------------
-
-bool RegistrationDialog::processInfoEvent(const std::string& eventSource)
-{
- return false;
-}
-
-// -----------------------------------------------------------------------------
-
-bool RegistrationDialog::onEscapePressed()
-{
- return m_cancel_widget->isActivated();
-}
-
-// -----------------------------------------------------------------------------
-
-GUIEngine::EventPropagation RegistrationDialog::processEvent(const std::string& eventSource)
-{
- std::string selection;
- if (eventSource == m_options_widget->m_properties[PROP_ID])
- selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
- else
- selection = eventSource;
- if (selection == m_cancel_widget->m_properties[PROP_ID])
- {
- m_self_destroy = true;
- return GUIEngine::EVENT_BLOCK;
- }
- else if (processInputEvent(selection) || processTermsEvent(selection) || processInfoEvent(selection))
- {
- return GUIEngine::EVENT_BLOCK;
- }
- return GUIEngine::EVENT_LET;
-}
-
-// -----------------------------------------------------------------------------
-
-void RegistrationDialog::onEnterPressedInternal()
-{
-
- if (GUIEngine::isFocusedForPlayer(m_options_widget, PLAYER_ID_GAME_MASTER))
- return;
- if (m_next_widget->isActivated())
- processInput();
-}
-
-// -----------------------------------------------------------------------------
-
-void RegistrationDialog::onUpdate(float dt)
-{
- if (m_phase == Terms)
- {
- if(m_sign_up_request != NULL)
- {
- if(m_sign_up_request->isDone())
- {
- if(m_sign_up_request->isSuccess())
- {
- m_show_registration_info = true;
- }
- else
- {
- sfx_manager->quickSound( "anvil" );
- m_show_registration_input = true;
- m_registration_error = m_sign_up_request->getInfo();
- }
- delete m_sign_up_request;
- m_sign_up_request = NULL;
- //FIXME m_options_widget->setActivated();
- }
- else
- {
- m_info_widget->setDefaultColor();
- m_info_widget->setText(Messages::validatingInfo(), false);
- }
- }
- }
- // It's unsafe to delete from inside the event handler so we do it here
- if (m_self_destroy)
+ // If it's not accept, it's cancel - anyway, close dialog
ModalDialog::dismiss();
- else if (m_show_registration_input)
- showRegistrationInput();
- else if (m_show_registration_terms)
- showRegistrationTerms();
- else if (m_show_registration_info)
- showRegistrationInfo();
-}
+ return EVENT_BLOCK;
+ }
+ return EVENT_LET;
+} // processEvent
diff --git a/src/states_screens/dialogs/registration_dialog.hpp b/src/states_screens/dialogs/registration_dialog.hpp
index 60fc9340d..23d3526af 100644
--- a/src/states_screens/dialogs/registration_dialog.hpp
+++ b/src/states_screens/dialogs/registration_dialog.hpp
@@ -31,62 +31,10 @@
class RegistrationDialog : public GUIEngine::ModalDialog
{
public:
- enum Phase
- {
- Input = 1,
- Terms = 2,
- Info = 4
- };
RegistrationDialog();
~RegistrationDialog();
- void onEnterPressedInternal();
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
-
- virtual void onUpdate(float dt);
- virtual bool onEscapePressed();
-
-private:
- Phase m_phase;
- bool m_self_destroy;
- bool m_show_registration_input;
- bool m_show_registration_terms;
- bool m_show_registration_info;
-
- const Online::XMLRequest * m_sign_up_request;
-
- //Saved user input :
- irr::core::stringw m_username;
- irr::core::stringw m_password;
- irr::core::stringw m_password_confirm;
- irr::core::stringw m_email;
- irr::core::stringw m_email_confirm;
- irr::core::stringw m_registration_error;
- bool m_agreement;
-
- GUIEngine::TextBoxWidget * m_username_widget;
- GUIEngine::TextBoxWidget * m_password_widget;
- GUIEngine::TextBoxWidget * m_password_confirm_widget;
- GUIEngine::TextBoxWidget * m_email_widget;
- GUIEngine::TextBoxWidget * m_email_confirm_widget;
-
- GUIEngine::LabelWidget * m_info_widget;
-
- GUIEngine::RibbonWidget * m_options_widget;
- GUIEngine::IconButtonWidget * m_previous_widget;
- GUIEngine::IconButtonWidget * m_next_widget;
- GUIEngine::IconButtonWidget * m_cancel_widget;
-
- GUIEngine::CheckBoxWidget * m_accept_terms_widget;
-
- void showRegistrationInput();
- void showRegistrationTerms();
- void showRegistrationInfo();
- void processInput();
- bool processInputEvent(const std::string& eventSource);
- bool processTermsEvent(const std::string& eventSource);
- bool processInfoEvent(const std::string& eventSource);
-
-};
+}; // class RegistrationDialog
#endif
diff --git a/src/states_screens/guest_login_screen.cpp b/src/states_screens/guest_login_screen.cpp
new file mode 100644
index 000000000..b1da5b7e8
--- /dev/null
+++ b/src/states_screens/guest_login_screen.cpp
@@ -0,0 +1,66 @@
+// SuperTuxKart - a fun racing game with go-kart
+// Copyright (C) 2014 Joerg Henrichs
+//
+// 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/guest_login_screen.hpp"
+
+#include "guiengine/widgets/ribbon_widget.hpp"
+#include "states_screens/login_screen.hpp"
+#include "states_screens/register_screen.hpp"
+#include "states_screens/state_manager.hpp"
+
+using namespace GUIEngine;
+
+DEFINE_SCREEN_SINGLETON( GuestLoginScreen );
+
+// -----------------------------------------------------------------------------
+
+GuestLoginScreen::GuestLoginScreen() : Screen("online/guest_login.stkgui")
+{
+} // GuestLoginScreen
+
+// -----------------------------------------------------------------------------
+
+void GuestLoginScreen::eventCallback(Widget* widget, const std::string& name,
+ const int playerID)
+{
+ if (name == "category")
+ {
+ const std::string selection =
+ ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
+
+ Log::warn("login", "selection %s", selection.c_str());
+ if (selection == "login")
+ StateManager::get()->replaceTopMostScreen(LoginScreen::getInstance());
+ else if (selection == "register")
+ StateManager::get()->replaceTopMostScreen(RegisterScreen::getInstance());
+ }
+ else if (name=="options")
+ {
+ const std::string button =
+ getWidget("options")
+ ->getSelectionIDString(PLAYER_ID_GAME_MASTER);
+ if(button=="sign_in")
+ {
+ // FIXME TODO: guest login
+ }
+ else if(button=="cancel")
+ StateManager::get()->escapePressed();
+ }
+
+} // eventCallback
+
+// -----------------------------------------------------------------------------
diff --git a/src/states_screens/guest_login_screen.hpp b/src/states_screens/guest_login_screen.hpp
new file mode 100644
index 000000000..3e23cab28
--- /dev/null
+++ b/src/states_screens/guest_login_screen.hpp
@@ -0,0 +1,47 @@
+// SuperTuxKart - a fun racing game with go-kart
+// Copyright (C) 2014 Joerg Henrichs
+//
+// 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_GUEST_LOGIN_SCREEN_HPP
+#define HEADER_GUEST_LOGIN_SCREEN_HPP
+
+#include "guiengine/screen.hpp"
+
+namespace GUIEngine { class Widget; }
+
+/**
+ * \brief Gest-Login screen.
+ * \ingroup states_screens
+ */
+class GuestLoginScreen : public GUIEngine::Screen,
+ public GUIEngine::ScreenSingleton
+{
+ friend class GUIEngine::ScreenSingleton;
+ GuestLoginScreen();
+
+public:
+
+ /** \brief implement callback from parent class GUIEngine::Screen */
+ virtual void loadedFromFile() OVERRIDE {};
+
+ /** \brief implement callback from parent class GUIEngine::Screen */
+ virtual void eventCallback(GUIEngine::Widget* widget,
+ const std::string& name,
+ const int playerID) OVERRIDE;
+
+}; // GuestLoginScreen
+
+#endif
diff --git a/src/states_screens/login_screen.cpp b/src/states_screens/login_screen.cpp
new file mode 100644
index 000000000..d4b7c84b7
--- /dev/null
+++ b/src/states_screens/login_screen.cpp
@@ -0,0 +1,173 @@
+// SuperTuxKart - a fun racing game with go-kart
+// Copyright (C) 2014 Joerg Henrichs
+//
+// 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/login_screen.hpp"
+
+#include "audio/sfx_manager.hpp"
+#include "guiengine/widgets/check_box_widget.hpp"
+#include "guiengine/widgets/label_widget.hpp"
+#include "guiengine/widgets/ribbon_widget.hpp"
+#include "guiengine/widgets/text_box_widget.hpp"
+#include "guiengine/widgets/check_box_widget.hpp"
+#include "online/current_user.hpp"
+#include "online/messages.hpp"
+#include "states_screens/guest_login_screen.hpp"
+#include "states_screens/online_screen.hpp"
+#include "states_screens/register_screen.hpp"
+#include "states_screens/state_manager.hpp"
+#include "utils/log.hpp"
+#include "utils/translation.hpp"
+
+using namespace GUIEngine;
+
+DEFINE_SCREEN_SINGLETON( LoginScreen );
+
+// -----------------------------------------------------------------------------
+
+LoginScreen::LoginScreen() : Screen("online/login.stkgui")
+{
+} // LoginScreen
+
+// -----------------------------------------------------------------------------
+void LoginScreen::init()
+{
+ TextBoxWidget *password_widget = getWidget("password");
+ password_widget->setPasswordBox(true,L'*');
+
+ m_options_widget = getWidget("options");
+ assert(m_options_widget);
+ m_options_widget->setActivated();
+
+ m_info_widget = getWidget("info");
+ assert(m_info_widget != NULL);
+ m_success = false;
+} // loadedFromFile
+
+// -----------------------------------------------------------------------------
+/** Collects the data entered into the gui and submits a login request.
+ * The login request is processes asynchronously b the ReqeustManager.
+ */
+void LoginScreen::login()
+{
+ // Reset any potential error message shown.
+ LabelWidget *info_widget = getWidget("info");
+ info_widget->setDefaultColor();
+ info_widget->setText("", false);
+
+ const stringw username = getWidget("username")
+ ->getText().trim();
+ const stringw password = getWidget("password")
+ ->getText().trim();
+
+ if (username.size() < 4 || username.size() > 30 ||
+ password.size() < 8 || password.size() > 30 )
+ {
+ sfx_manager->quickSound("anvil");
+ info_widget->setErrorColor();
+ info_widget->setText(_("Username and/or password too short or too long."),
+ false);
+ }
+ else
+ {
+ m_options_widget->setDeactivated();
+ info_widget->setDefaultColor();
+ bool remember = getWidget("remember")->getState();
+ Online::CurrentUser::get()->requestSignIn(username,password,
+ remember );
+ }
+} // login
+
+// -----------------------------------------------------------------------------
+/** Called from the login request when it was successfully exected.
+ */
+void LoginScreen::loginSuccessful()
+{
+ // The callback is done from the main thread, so no need to sync
+ // access to m_success
+ m_success = true;
+} // loginSuccessful
+
+// -----------------------------------------------------------------------------
+/** Called from the login request when the login was not successful.
+ * \param error_message The error message from the server (or curl).
+ */
+void LoginScreen::loginError(const irr::core::stringw & error_message)
+{
+ sfx_manager->quickSound("anvil");
+ LabelWidget *info_widget = getWidget("info");
+ info_widget->setErrorColor();
+ info_widget->setText(error_message, false);
+
+ m_options_widget->setActivated();
+} // loginError
+
+// -----------------------------------------------------------------------------
+/** Called in each frame. If a successful login is detected, the online screen
+ * will be displayed.
+ */
+void LoginScreen::onUpdate(float dt, irr::video::IVideoDriver*)
+{
+
+ if(!m_options_widget->isActivated())
+ m_info_widget->setText(Online::Messages::signingIn(), false);
+
+ // Login was successful, so put the online main menu on the screen
+ if(m_success)
+ {
+ StateManager::get()->replaceTopMostScreen(OnlineScreen::getInstance());
+ }
+} // onUpdate
+
+// -----------------------------------------------------------------------------
+/** Called when the user clicks on a widget.
+ * \param widget that was clicked on.
+ * \param name Name of the widget.
+ * \param playerID The id of the player who clicked the item.
+ */
+void LoginScreen::eventCallback(Widget* widget, const std::string& name,
+ const int playerID)
+{
+ if (name == "category")
+ {
+ StateManager *sm = StateManager::get();
+ const std::string selection =
+ ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
+
+ if (selection == "guest_login")
+ sm->replaceTopMostScreen(GuestLoginScreen::getInstance());
+ else if (selection == "register")
+ sm->replaceTopMostScreen(RegisterScreen::getInstance());
+ }
+ else if (name=="options")
+ {
+ const std::string button =
+ getWidget("options")
+ ->getSelectionIDString(PLAYER_ID_GAME_MASTER);
+ if(button=="sign_in")
+ {
+ login();
+ }
+ else if(button=="recovery")
+ {
+ }
+ else if(button=="cancel")
+ StateManager::get()->escapePressed();
+ }
+
+} // eventCallback
+
+// -----------------------------------------------------------------------------
diff --git a/src/states_screens/login_screen.hpp b/src/states_screens/login_screen.hpp
new file mode 100644
index 000000000..19b0cf51a
--- /dev/null
+++ b/src/states_screens/login_screen.hpp
@@ -0,0 +1,63 @@
+// SuperTuxKart - a fun racing game with go-kart
+// Copyright (C) 2014 Joerg Henrichs
+//
+// 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_LOGIN_SCREEN_HPP
+#define HEADER_LOGIN_SCREEN_HPP
+
+#include "guiengine/screen.hpp"
+
+namespace GUIEngine { class LabelWidget;
+ class RibbonWidget;
+ class Widget; }
+
+/**
+ * \brief Login screen.
+ * \ingroup states_screens
+ */
+class LoginScreen : public GUIEngine::Screen,
+ public GUIEngine::ScreenSingleton
+{
+private:
+ friend class GUIEngine::ScreenSingleton;
+ LoginScreen();
+ void login();
+
+ /** Store a pointer to the options buttons. */
+ GUIEngine::RibbonWidget *m_options_widget;
+ GUIEngine::LabelWidget * m_info_widget;
+
+ bool m_success;
+
+
+public:
+
+ /** \brief implement callback from parent class GUIEngine::Screen */
+ virtual void loadedFromFile() OVERRIDE {};
+ virtual void init() OVERRIDE;
+ virtual void onUpdate(float dt, irr::video::IVideoDriver*) OVERRIDE;
+
+
+ /** \brief implement callback from parent class GUIEngine::Screen */
+ virtual void eventCallback(GUIEngine::Widget* widget,
+ const std::string& name,
+ const int playerID) OVERRIDE;
+
+ void loginSuccessful();
+ void loginError(const irr::core::stringw & error_message);
+}; // class LoginScreen
+
+#endif
diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp
index 4c56e1624..36145ea7b 100644
--- a/src/states_screens/main_menu_screen.cpp
+++ b/src/states_screens/main_menu_screen.cpp
@@ -37,12 +37,12 @@
#include "modes/overworld.hpp"
#include "modes/demo_world.hpp"
#include "online/request_manager.hpp"
-#include "states_screens/online_screen.hpp"
#include "states_screens/addons_screen.hpp"
#include "states_screens/credits.hpp"
#include "states_screens/help_screen_1.hpp"
+#include "states_screens/login_screen.hpp"
#include "states_screens/offline_kart_selection.hpp"
-#include "states_screens/network_kart_selection.hpp" // FIXME : remove when not testing
+#include "states_screens/online_screen.hpp"
#include "states_screens/options_screen_video.hpp"
#include "states_screens/state_manager.hpp"
@@ -111,6 +111,11 @@ void MainMenuScreen::init()
w->setBadge(LOADING_BADGE);
}
+ IconButtonWidget* online = getWidget("online");
+ if(CurrentUser::get()->getID())
+ online->setLabel(_("Online"));
+ else
+ online->setLabel(_("Login"));
LabelWidget* w = getWidget("info_addons");
const core::stringw &news_text = NewsManager::get()->getNextNewsMessage();
@@ -380,7 +385,10 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
"\"Allow STK to connect to the Internet\"."));
return;
}
- StateManager::get()->pushScreen(OnlineScreen::getInstance());
+ if(CurrentUser::get()->getID())
+ StateManager::get()->pushScreen(OnlineScreen::getInstance());
+ else
+ StateManager::get()->pushScreen(LoginScreen::getInstance());
}
else if (selection == "addons")
{
diff --git a/src/states_screens/register_screen.cpp b/src/states_screens/register_screen.cpp
new file mode 100644
index 000000000..0dde8884d
--- /dev/null
+++ b/src/states_screens/register_screen.cpp
@@ -0,0 +1,192 @@
+// SuperTuxKart - a fun racing game with go-kart
+// Copyright (C) 2014 Joerg Henrichs
+//
+// 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/register_screen.hpp"
+
+#include "audio/sfx_manager.hpp"
+#include "guiengine/widgets/label_widget.hpp"
+#include "guiengine/widgets/ribbon_widget.hpp"
+#include "guiengine/widgets/text_box_widget.hpp"
+#include "online/current_user.hpp"
+#include "online/messages.hpp"
+#include "states_screens/dialogs/registration_dialog.hpp"
+#include "states_screens/dialogs/message_dialog.hpp"
+#include "states_screens/guest_login_screen.hpp"
+#include "states_screens/login_screen.hpp"
+#include "states_screens/main_menu_screen.hpp"
+#include "states_screens/state_manager.hpp"
+#include "utils/log.hpp"
+#include "utils/translation.hpp"
+
+using namespace GUIEngine;
+using namespace Online;
+
+DEFINE_SCREEN_SINGLETON( RegisterScreen );
+
+// -----------------------------------------------------------------------------
+
+RegisterScreen::RegisterScreen() : Screen("online/register.stkgui")
+{
+} // RegisterScreen
+
+// -----------------------------------------------------------------------------
+void RegisterScreen::init()
+{
+ TextBoxWidget *password_widget = getWidget("password");
+ password_widget->setPasswordBox(true,L'*');
+ password_widget = getWidget("password_confirm");
+ password_widget->setPasswordBox(true,L'*');
+
+ m_info_widget = getWidget("info");
+ assert(m_info_widget);
+ m_options_widget = getWidget("options");
+ assert(m_options_widget);
+
+ m_signup_request = NULL;
+ m_info_message_shown = false;
+} // init
+
+// -----------------------------------------------------------------------------
+void RegisterScreen::doRegister()
+{
+ core::stringw username = getWidget("username")->getText().trim();
+ core::stringw password = getWidget("password")->getText().trim();
+ core::stringw password_confirm = getWidget("password_confirm")
+ ->getText().trim();
+ core::stringw email = getWidget("email")->getText().trim();
+ core::stringw email_confirm = getWidget("email_confirm")
+ ->getText().trim();
+
+ m_info_widget->setErrorColor();
+
+ if (password != password_confirm)
+ {
+ m_info_widget->setText(_("Passwords don't match!"), false);
+ }
+ else if (email != email_confirm)
+ {
+ m_info_widget->setText(_("Emails don't match!"), false);
+ }
+ else if (username.size() < 4 || username.size() > 30)
+ {
+ m_info_widget->setText(_("Username has to be between 4 and 30 characters long!"), false);
+ }
+ else if (password.size() < 8 || password.size() > 30)
+ {
+ m_info_widget->setText(_("Password has to be between 8 and 30 characters long!"), false);
+ }
+ else if (email.size() < 4 || email.size() > 50)
+ {
+ m_info_widget->setText(_("Email has to be between 4 and 50 characters long!"), false);
+ }
+ else
+ {
+ m_info_widget->setDefaultColor();
+ new RegistrationDialog();
+ return;
+ }
+
+ sfx_manager->quickSound( "anvil" );
+
+} // doRegister
+
+// -----------------------------------------------------------------------------
+/** Called from the registration info dialog when 'accept' is clicked.
+ */
+void RegisterScreen::acceptTerms()
+{
+ m_options_widget->setDeactivated();
+
+ core::stringw username = getWidget("username")->getText().trim();
+ core::stringw password = getWidget("password")->getText().trim();
+ core::stringw password_confirm= getWidget("password_confirm")->getText().trim();
+ core::stringw email = getWidget("email")->getText().trim();
+
+ m_signup_request = CurrentUser::get()->requestSignUp(username, password,
+ password_confirm, email);
+} // acceptTerms
+
+// -----------------------------------------------------------------------------
+
+void RegisterScreen::onUpdate(float dt, irr::video::IVideoDriver*)
+{
+ if(m_signup_request)
+ {
+ if(!m_options_widget->isActivated())
+ m_info_widget->setText(Messages::validatingInfo(), false);
+
+ if(m_signup_request->isDone())
+ {
+ if(m_signup_request->isSuccess())
+ {
+ new MessageDialog(
+ _("You will receive an email with further instructions "
+ "regarding account activation. Please be patient and be "
+ "sure to check your spam folder."),
+ MessageDialog::MESSAGE_DIALOG_OK, NULL, false);
+ // Set the flag that the message was shown, which will triger
+ // a pop of this menu and so a return to the main menu
+ m_info_message_shown = true;
+ }
+ else
+ {
+ // Error signing up, display error message
+ m_info_widget->setText(m_signup_request->getInfo(), false);
+ }
+ delete m_signup_request;
+ m_signup_request = NULL;
+ m_options_widget->setActivated();
+ }
+ }
+ else if(m_info_message_shown && !ModalDialog::isADialogActive())
+ {
+ // Once the info message was shown (signup was successful), but the
+ // message has been gone (user clicked on OK), go back to main menu
+ StateManager::get()->popMenu();
+ }
+} // onUpdate
+
+// -----------------------------------------------------------------------------
+
+void RegisterScreen::eventCallback(Widget* widget, const std::string& name,
+ const int playerID)
+{
+ if (name == "category")
+ {
+ const std::string selection =
+ ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
+ StateManager *sm = StateManager::get();
+ if (selection == "login")
+ sm->replaceTopMostScreen(RegisterScreen::getInstance());
+ else if (selection == "guest_login")
+ sm->replaceTopMostScreen(GuestLoginScreen::getInstance());
+ }
+ else if (name=="options")
+ {
+ const std::string button = m_options_widget
+ ->getSelectionIDString(PLAYER_ID_GAME_MASTER);
+ if(button=="next")
+ {
+ doRegister();
+ }
+ else if(button=="cancel")
+ StateManager::get()->escapePressed();
+ }
+
+} // eventCallback
+
+// -----------------------------------------------------------------------------
diff --git a/src/states_screens/register_screen.hpp b/src/states_screens/register_screen.hpp
new file mode 100644
index 000000000..f3d585801
--- /dev/null
+++ b/src/states_screens/register_screen.hpp
@@ -0,0 +1,64 @@
+// SuperTuxKart - a fun racing game with go-kart
+// Copyright (C) 2014 Joerg Henrichs
+//
+// 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_REGISTER_SCREEN_HPP
+#define HEADER_REGISTER_SCREEN_HPP
+
+#include "guiengine/screen.hpp"
+
+namespace GUIEngine { class Widget; class LabelWidget; }
+namespace Online { class XMLRequest; }
+/**
+ * \brief Screen to register an online account.
+ * \ingroup states_screens
+ */
+class RegisterScreen : public GUIEngine::Screen,
+ public GUIEngine::ScreenSingleton
+{
+private:
+ friend class GUIEngine::ScreenSingleton;
+
+ void doRegister();
+ void init();
+ RegisterScreen();
+
+ /** Save the pointer to the info widget, it is widely used. */
+ GUIEngine::LabelWidget *m_info_widget;
+
+ /** Save the pointer to the options widget, it is widely used. */
+ GUIEngine::RibbonWidget *m_options_widget;
+
+ const Online::XMLRequest *m_signup_request;
+
+ /** True if the info message (email was sent...) is shown. */
+ bool m_info_message_shown;
+
+public:
+
+ /** \brief implement callback from parent class GUIEngine::Screen */
+ virtual void loadedFromFile() OVERRIDE {};
+ virtual void onUpdate(float dt, irr::video::IVideoDriver*) OVERRIDE;
+
+ void acceptTerms();
+ /** \brief implement callback from parent class GUIEngine::Screen */
+ virtual void eventCallback(GUIEngine::Widget* widget,
+ const std::string& name,
+ const int playerID) OVERRIDE;
+
+}; // class RegisterScreen
+
+#endif