diff --git a/data/gui/online/lan.stkgui b/data/gui/online/lan.stkgui new file mode 100644 index 000000000..c94e6082a --- /dev/null +++ b/data/gui/online/lan.stkgui @@ -0,0 +1,29 @@ + + + + +
+
+ + +
+
diff --git a/data/gui/online/online.stkgui b/data/gui/online/online.stkgui new file mode 100644 index 000000000..3572916bc --- /dev/null +++ b/data/gui/online/online.stkgui @@ -0,0 +1,29 @@ + + +
+
+ +
+ + +
diff --git a/data/gui/online/profile_achievements_tab.stkgui b/data/gui/online/profile_achievements_tab.stkgui index dbf3256b5..7d519d661 100644 --- a/data/gui/online/profile_achievements_tab.stkgui +++ b/data/gui/online/profile_achievements_tab.stkgui @@ -9,7 +9,6 @@ - diff --git a/data/gui/online/profile_friends.stkgui b/data/gui/online/profile_friends.stkgui index 0e1213c61..e0e49473b 100644 --- a/data/gui/online/profile_friends.stkgui +++ b/data/gui/online/profile_friends.stkgui @@ -9,7 +9,6 @@ - diff --git a/data/gui/online/profile_servers.stkgui b/data/gui/online/profile_servers.stkgui index 25ca99ffa..88de78d8c 100644 --- a/data/gui/online/profile_servers.stkgui +++ b/data/gui/online/profile_servers.stkgui @@ -3,59 +3,25 @@
-
+
- + +
diff --git a/data/gui/online/profile_settings.stkgui b/data/gui/online/profile_settings.stkgui index 126519d9f..d89d52c23 100644 --- a/data/gui/online/profile_settings.stkgui +++ b/data/gui/online/profile_settings.stkgui @@ -8,7 +8,6 @@ - BoundingBox; - f32 AnimationFrames; f32 FramesPerSecond; f32 LastAnimatedFrame; diff --git a/src/graphics/sp_mesh_loader.cpp b/src/graphics/sp_mesh_loader.cpp index fec1a8e2c..57c1cd614 100644 --- a/src/graphics/sp_mesh_loader.cpp +++ b/src/graphics/sp_mesh_loader.cpp @@ -20,6 +20,7 @@ #include "utils/constants.hpp" #include "utils/mini_glm.hpp" +#include "../../lib/irrlicht/source/Irrlicht/CSkinnedMesh.h" const uint8_t VERSION_NOW = 1; #include @@ -47,7 +48,7 @@ scene::IAnimatedMesh* SPMeshLoader::createMesh(io::IReadFile* f) } m_bind_frame = 0; m_joint_count = 0; - //m_frame_count = 0; + m_frame_count = 0; m_mesh = NULL; m_mesh = m_scene_manager->createSkinnedMesh(); io::IFileSystem* fs = m_scene_manager->getFileSystem(); @@ -196,6 +197,9 @@ scene::IAnimatedMesh* SPMeshLoader::createMesh(io::IReadFile* f) f->read(&pre_computed_size, 2); } m_mesh->finalize(); + // Because the last frame in spm is usable + static_cast(m_mesh)->AnimationFrames = + (float)m_frame_count + 1.0f; m_all_armatures.clear(); m_to_bind_pose_matrices.clear(); m_joints.clear(); @@ -366,8 +370,8 @@ void SPMeshLoader::createAnimationData(irr::io::IReadFile* spm) } for (unsigned i = 0; i < armature_size; i++) { - //m_frame_count = std::max(m_frame_count, - // (unsigned)m_all_armatures[i].m_frame_pose_matrices.back().first); + m_frame_count = std::max(m_frame_count, + (unsigned)m_all_armatures[i].m_frame_pose_matrices.back().first); m_joint_count += m_all_armatures[i].m_joint_used; } diff --git a/src/graphics/sp_mesh_loader.hpp b/src/graphics/sp_mesh_loader.hpp index 64e257bf8..55fc031ae 100644 --- a/src/graphics/sp_mesh_loader.hpp +++ b/src/graphics/sp_mesh_loader.hpp @@ -79,7 +79,7 @@ private: unsigned id); }; // ------------------------------------------------------------------------ - unsigned m_bind_frame, m_joint_count;//, m_frame_count; + unsigned m_bind_frame, m_joint_count, m_frame_count; // ------------------------------------------------------------------------ std::vector m_all_armatures; // ------------------------------------------------------------------------ diff --git a/src/scriptengine/script_track.cpp b/src/scriptengine/script_track.cpp index 2ca00ea0c..a221e0ce4 100644 --- a/src/scriptengine/script_track.cpp +++ b/src/scriptengine/script_track.cpp @@ -295,6 +295,33 @@ namespace Scripting return -1; } + /** Remove all animation set for a skeletal animation */ + void removeAllAnimationSet(/** \cond DOXYGEN_IGNORE */void *memory /** \endcond */) + { + if (memory) + { + ((scene::IAnimatedMeshSceneNode*)(memory))->removeAllAnimationSet(); + } + } + + /** Add an animation set for a skeletal animation */ + void addAnimationSet(int start/** \cond DOXYGEN_IGNORE */, int end/** \cond DOXYGEN_IGNORE */, /** \cond DOXYGEN_IGNORE */void *memory /** \endcond */) + { + if (memory) + { + ((scene::IAnimatedMeshSceneNode*)(memory))->addAnimationSet(start, end); + } + } + + /** use an current frame for a skeletal animation */ + void useAnimationSet(int set_num /** \cond DOXYGEN_IGNORE */, void *memory /** \endcond */) + { + if (memory) + { + ((scene::IAnimatedMeshSceneNode*)(memory))->useAnimationSet(set_num); + } + } + /** Sets the current frame for a skeletal animation */ void setCurrentFrame(int frame /** \cond DOXYGEN_IGNORE */, void *memory /** \endcond */) { @@ -465,6 +492,8 @@ namespace Scripting r = engine->RegisterObjectMethod("TrackObject", "void moveTo(const Vec3 &in, bool)", asMETHOD(::TrackObject, moveTo), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("TrackObject", "Vec3 getCenterPosition()", asFUNCTION(TrackObject::getCenterPosition), asCALL_CDECL_OBJLAST); assert(r >= 0); r = engine->RegisterObjectMethod("TrackObject", "Vec3 getOrigin()", asFUNCTION(TrackObject::getOrigin), asCALL_CDECL_OBJLAST); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "TrackObject@ getParentLibrary()", asMETHOD(::TrackObject, getParentLibrary), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "string getName()", asMETHOD(::TrackObject, getName), asCALL_THISCALL); assert(r >= 0); // PhysicalObject r = engine->RegisterObjectMethod("PhysicalObject", "bool isFlattenKartObject()", asMETHOD(PhysicalObject, isFlattenKartObject), asCALL_THISCALL); assert(r >= 0); @@ -476,6 +505,9 @@ namespace Scripting r = engine->RegisterObjectMethod("Mesh", "void setFrameLoopOnce(int start, int end)", asFUNCTION(Mesh::setFrameLoopOnce), asCALL_CDECL_OBJLAST); assert(r >= 0); r = engine->RegisterObjectMethod("Mesh", "int getFrameNr()", asFUNCTION(Mesh::getFrameNr), asCALL_CDECL_OBJLAST); assert(r >= 0); r = engine->RegisterObjectMethod("Mesh", "int getAnimationSet()", asFUNCTION(Mesh::getAnimationSet), asCALL_CDECL_OBJLAST); assert(r >= 0); + r = engine->RegisterObjectMethod("Mesh", "void useAnimationSet(int set_num)", asFUNCTION(Mesh::useAnimationSet), asCALL_CDECL_OBJLAST); assert(r >= 0); + r = engine->RegisterObjectMethod("Mesh", "void addAnimationSet(int start, int end)", asFUNCTION(Mesh::addAnimationSet), asCALL_CDECL_OBJLAST); assert(r >= 0); + r = engine->RegisterObjectMethod("Mesh", "void removeAllAnimationSet()", asFUNCTION(Mesh::removeAllAnimationSet), asCALL_CDECL_OBJLAST); assert(r >= 0); r = engine->RegisterObjectMethod("Mesh", "void setCurrentFrame(int frame)", asFUNCTION(Mesh::setCurrentFrame), asCALL_CDECL_OBJLAST); assert(r >= 0); //r = engine->RegisterObjectMethod("Mesh", "void move(Vec3 &in)", asFUNCTION(movePresentation), asCALL_CDECL_OBJLAST); assert(r >= 0); diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index 35523b85d..17f1d3257 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -46,6 +46,7 @@ #include "states_screens/offline_kart_selection.hpp" #include "states_screens/online_profile_achievements.hpp" #include "states_screens/online_profile_servers.hpp" +#include "states_screens/online_screen.hpp" #include "states_screens/options_screen_video.hpp" #include "states_screens/state_manager.hpp" #include "states_screens/user_screen.hpp" @@ -75,9 +76,6 @@ bool MainMenuScreen::m_enable_online = false; MainMenuScreen::MainMenuScreen() : Screen("main_menu.stkgui") { - m_online_string = _("Online"); - //I18N: Used as a verb, appears on the main menu (login button) - m_login_string = _("Login"); } // MainMenuScreen // ---------------------------------------------------------------------------- @@ -151,10 +149,7 @@ void MainMenuScreen::init() w->setBadge(LOADING_BADGE); } - m_online = getWidget("online"); - - if(!m_enable_online) - m_online->setActive(false); + IconButtonWidget* online = getWidget("online"); LabelWidget* w = getWidget("info_addons"); const core::stringw &news_text = NewsManager::get()->getNextNewsMessage(); @@ -179,32 +174,25 @@ void MainMenuScreen::init() } // init // ---------------------------------------------------------------------------- -void MainMenuScreen::onUpdate(float delta) +void MainMenuScreen::onUpdate(float delta) { PlayerProfile *player = PlayerManager::getCurrentPlayer(); if(PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_GUEST || PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_SIGNED_IN) { m_user_id->setText(player->getLastOnlineName() + "@stk"); - m_online->setActive(true); - m_online->setLabel(m_online_string); } else if (PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_SIGNED_OUT) { - m_online->setActive(true); - m_online->setLabel(m_login_string); m_user_id->setText(player->getName()); } else { // now must be either logging in or logging out - m_online->setActive(false); m_user_id->setText(player->getName()); } - m_online->setLabel(PlayerManager::getCurrentOnlineId() ? m_online_string - : m_login_string); IconButtonWidget* addons_icon = getWidget("addons"); if (addons_icon != NULL) { @@ -472,6 +460,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, } else if (selection == "story") { + NetworkConfig::get()->unsetNetworking(); PlayerProfile *player = PlayerManager::getCurrentPlayer(); if (player->isFirstTime()) { @@ -505,23 +494,30 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, } else if (selection == "online") { - if(UserConfigParams::m_internet_status!=RequestManager::IPERM_ALLOWED) + if (MainMenuScreen::m_enable_online) { - new MessageDialog(_("You can not play online without internet access. " - "If you want to play online, go to options, select " - " tab 'User Interface', and edit " - "\"Connect to the Internet\".")); - return; - } - - if (PlayerManager::getCurrentOnlineId()) - { - ProfileManager::get()->setVisiting(PlayerManager::getCurrentOnlineId()); - OnlineProfileServers::getInstance()->push(); + OnlineScreen::getInstance()->push(); } else { - UserScreen::getInstance()->push(); + if (UserConfigParams::m_internet_status != RequestManager::IPERM_ALLOWED) + { + new MessageDialog(_("You can not play online without internet access. " + "If you want to play online, go to options, select " + " tab 'User Interface', and edit " + "\"Connect to the Internet\".")); + return; + } + + if (PlayerManager::getCurrentOnlineId()) + { + ProfileManager::get()->setVisiting(PlayerManager::getCurrentOnlineId()); + TabOnlineProfileAchievements::getInstance()->push(); + } + else + { + UserScreen::getInstance()->push(); + } } } else if (selection == "addons") diff --git a/src/states_screens/main_menu_screen.hpp b/src/states_screens/main_menu_screen.hpp index 4e79c4532..8da6c94ab 100644 --- a/src/states_screens/main_menu_screen.hpp +++ b/src/states_screens/main_menu_screen.hpp @@ -32,13 +32,6 @@ class MainMenuScreen : public GUIEngine::Screen, public GUIEngine::ScreenSinglet private: friend class GUIEngine::ScreenSingleton; - core::stringw m_online_string; - - core::stringw m_login_string; - - /** Keep the widget to avoid looking it up every frame. */ - GUIEngine::IconButtonWidget* m_online; - /** Keep the widget to to the user name. */ GUIEngine::ButtonWidget *m_user_id; diff --git a/src/states_screens/online_lan.cpp b/src/states_screens/online_lan.cpp new file mode 100644 index 000000000..9e22fa104 --- /dev/null +++ b/src/states_screens/online_lan.cpp @@ -0,0 +1,112 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2010-2015 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/online_profile_servers.hpp" + +#include "audio/sfx_manager.hpp" +#include "config/player_manager.hpp" +#include "guiengine/engine.hpp" +#include "guiengine/scalable_font.hpp" +#include "guiengine/screen.hpp" +#include "guiengine/widget.hpp" +#include "network/network_config.hpp" +#include "network/protocol_manager.hpp" +#include "network/protocols/connect_to_server.hpp" +#include "network/protocols/request_connection.hpp" +#include "network/servers_manager.hpp" +#include "states_screens/state_manager.hpp" +#include "states_screens/create_server_screen.hpp" +#include "states_screens/networking_lobby.hpp" +#include "states_screens/online_lan.hpp" +#include "states_screens/server_selection.hpp" +#include "utils/translation.hpp" + +#include + +#include +#include + +using namespace GUIEngine; +using namespace irr::core; +using namespace irr::gui; +using namespace Online; + +DEFINE_SCREEN_SINGLETON( OnlineLanScreen ); + +// ----------------------------------------------------------------------------- + +OnlineLanScreen::OnlineLanScreen() : GUIEngine::Screen("online/lan.stkgui") +{ +} // OnlineLanScreen + +// ----------------------------------------------------------------------------- + +void OnlineLanScreen::loadedFromFile() +{ +} // loadedFromFile + +// ----------------------------------------------------------------------------- + +void OnlineLanScreen::init() +{ + RibbonWidget* ribbon = getWidget("lan"); + assert(ribbon != NULL); + ribbon->select("find_lan_server", PLAYER_ID_GAME_MASTER); + ribbon->setFocusForPlayer(PLAYER_ID_GAME_MASTER); +} // init + +// ----------------------------------------------------------------------------- + +void OnlineLanScreen::eventCallback(Widget* widget, const std::string& name, const int playerID) +{ + if (name == "back") + { + StateManager::get()->popMenu(); + return; + } + if (name == "lan") + { + RibbonWidget* ribbon = dynamic_cast(widget); + std::string selection = ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER); + if (selection == "create_lan_server") + { + NetworkConfig::get()->setIsLAN(); + NetworkConfig::get()->setIsServer(true); + CreateServerScreen::getInstance()->push(); + // TODO: create lan server + } + else if (selection == "find_lan_server") + { + NetworkConfig::get()->setIsLAN(); + NetworkConfig::get()->setIsServer(false); + ServerSelection::getInstance()->push(); + } + } + +} // eventCallback + +// ---------------------------------------------------------------------------- +/** Also called when pressing the back button. It resets the flags to indicate + * a networked game. + */ +bool OnlineLanScreen::onEscapePressed() +{ + NetworkConfig::get()->unsetNetworking(); + //StateManager::get()->popMenu(); + return true; +} // onEscapePressed + diff --git a/src/states_screens/online_lan.hpp b/src/states_screens/online_lan.hpp new file mode 100644 index 000000000..615cb9e37 --- /dev/null +++ b/src/states_screens/online_lan.hpp @@ -0,0 +1,57 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2013-2015 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_OLAN_HPP__ +#define __HEADER_OLAN_HPP__ + +#include +#include + +#include "guiengine/screen.hpp" +#include "guiengine/widgets.hpp" +#include "states_screens/online_profile_base.hpp" + +namespace GUIEngine { class Widget; } + + +/** + * \brief Online profiel overview screen + * \ingroup states_screens + */ +class OnlineLanScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton +{ +protected: + OnlineLanScreen(); + +public: + friend class GUIEngine::ScreenSingleton; + + /** \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; + + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void init() OVERRIDE; + virtual bool onEscapePressed() OVERRIDE; + +}; // class OnlineProfileServers + +#endif diff --git a/src/states_screens/online_profile_base.cpp b/src/states_screens/online_profile_base.cpp index 208123750..0088cdaf3 100644 --- a/src/states_screens/online_profile_base.cpp +++ b/src/states_screens/online_profile_base.cpp @@ -42,7 +42,6 @@ using namespace Online; OnlineProfileBase::OnlineProfileBase(const std::string &filename) : Screen(filename.c_str()) { - m_servers_tab = NULL; m_friends_tab = NULL; m_achievements_tab = NULL; m_settings_tab = NULL; @@ -63,9 +62,6 @@ void OnlineProfileBase::loadedFromFile() m_friends_tab = (IconButtonWidget *)m_profile_tabs->findWidgetNamed("tab_friends"); assert(m_friends_tab != NULL); - m_servers_tab = (IconButtonWidget *)m_profile_tabs->findWidgetNamed("tab_servers"); - assert(m_servers_tab != NULL); - m_achievements_tab = (IconButtonWidget*)m_profile_tabs->findWidgetNamed("tab_achievements"); assert(m_profile_tabs == NULL || m_achievements_tab != NULL); @@ -107,7 +103,6 @@ void OnlineProfileBase::init() if (m_profile_tabs) { - m_servers_tab->setTooltip(_("Servers")); m_friends_tab->setTooltip(_("Friends")); m_achievements_tab->setTooltip(_("Achievements")); m_settings_tab->setTooltip(_("Account Settings")); @@ -159,8 +154,6 @@ void OnlineProfileBase::eventCallback(Widget* widget, const std::string& name, sm->replaceTopMostScreen(TabOnlineProfileAchievements::getInstance()); else if (selection == m_settings_tab->m_properties[PROP_ID]) sm->replaceTopMostScreen(OnlineProfileSettings::getInstance()); - else if (selection == m_servers_tab->m_properties[PROP_ID]) - sm->replaceTopMostScreen(OnlineProfileServers::getInstance()); } else if (name == "back") { diff --git a/src/states_screens/online_profile_base.hpp b/src/states_screens/online_profile_base.hpp index 95a6906fa..0285edb4b 100644 --- a/src/states_screens/online_profile_base.hpp +++ b/src/states_screens/online_profile_base.hpp @@ -42,7 +42,6 @@ protected: /** Pointer to the various widgets on the screen. */ GUIEngine::LabelWidget * m_header; GUIEngine::RibbonWidget* m_profile_tabs; - GUIEngine::IconButtonWidget * m_servers_tab; GUIEngine::IconButtonWidget * m_friends_tab; GUIEngine::IconButtonWidget * m_achievements_tab; GUIEngine::IconButtonWidget * m_settings_tab; diff --git a/src/states_screens/online_profile_servers.cpp b/src/states_screens/online_profile_servers.cpp index 7d3400b0f..0787d2fef 100644 --- a/src/states_screens/online_profile_servers.cpp +++ b/src/states_screens/online_profile_servers.cpp @@ -48,7 +48,7 @@ DEFINE_SCREEN_SINGLETON( OnlineProfileServers ); // ----------------------------------------------------------------------------- -OnlineProfileServers::OnlineProfileServers() : OnlineProfileBase("online/profile_servers.stkgui") +OnlineProfileServers::OnlineProfileServers() : GUIEngine::Screen("online/profile_servers.stkgui") { } // OnlineProfileServers @@ -56,44 +56,28 @@ OnlineProfileServers::OnlineProfileServers() : OnlineProfileBase("online/profile void OnlineProfileServers::loadedFromFile() { - OnlineProfileBase::loadedFromFile(); } // loadedFromFile // ----------------------------------------------------------------------------- void OnlineProfileServers::init() { - OnlineProfileBase::init(); - m_profile_tabs->select( m_servers_tab->m_properties[PROP_ID], PLAYER_ID_GAME_MASTER ); - m_servers_tab->setFocusForPlayer(PLAYER_ID_GAME_MASTER); - // OnlineScreen::getInstance()->push(); + RibbonWidget* ribbon = getWidget("wan"); + assert(ribbon != NULL); + ribbon->select("find_wan_server", PLAYER_ID_GAME_MASTER); + ribbon->setFocusForPlayer(PLAYER_ID_GAME_MASTER); } // init // ----------------------------------------------------------------------------- void OnlineProfileServers::eventCallback(Widget* widget, const std::string& name, const int playerID) { - OnlineProfileBase::eventCallback( widget, name, playerID); - - if (name == "lan") + if (name == "back") { - RibbonWidget* ribbon = dynamic_cast(widget); - std::string selection = ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER); - if (selection == "create_lan_server") - { - NetworkConfig::get()->setIsLAN(); - NetworkConfig::get()->setIsServer(true); - CreateServerScreen::getInstance()->push(); - // TODO: create lan server - } - else if (selection == "find_lan_server") - { - NetworkConfig::get()->setIsLAN(); - NetworkConfig::get()->setIsServer(false); - ServerSelection::getInstance()->push(); - } + StateManager::get()->popMenu(); + return; } - else if (name == "wan") + if (name == "wan") { RibbonWidget* ribbon = dynamic_cast(widget); std::string selection = ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER); @@ -176,6 +160,6 @@ void OnlineProfileServers::doQuickPlay() bool OnlineProfileServers::onEscapePressed() { NetworkConfig::get()->unsetNetworking(); - return OnlineProfileBase::onEscapePressed(); + return true; } // onEscapePressed diff --git a/src/states_screens/online_profile_servers.hpp b/src/states_screens/online_profile_servers.hpp index b840f103e..0d30b6fe6 100644 --- a/src/states_screens/online_profile_servers.hpp +++ b/src/states_screens/online_profile_servers.hpp @@ -33,7 +33,7 @@ namespace GUIEngine { class Widget; } * \brief Online profiel overview screen * \ingroup states_screens */ -class OnlineProfileServers : public OnlineProfileBase, public GUIEngine::ScreenSingleton +class OnlineProfileServers : public GUIEngine::Screen, public GUIEngine::ScreenSingleton { protected: OnlineProfileServers(); diff --git a/src/states_screens/online_screen.cpp b/src/states_screens/online_screen.cpp new file mode 100644 index 000000000..e0601c56e --- /dev/null +++ b/src/states_screens/online_screen.cpp @@ -0,0 +1,198 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2009-2015 Marianne Gagnon +// +// 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/main_menu_screen.hpp" + +#include "config/player_manager.hpp" +#include "config/user_config.hpp" +#include "graphics/irr_driver.hpp" +#include "guiengine/scalable_font.hpp" +#include "guiengine/widgets/label_widget.hpp" +#include "guiengine/widgets/list_widget.hpp" +#include "guiengine/widgets/ribbon_widget.hpp" +#include "input/device_manager.hpp" +#include "input/input_manager.hpp" +#include "input/keyboard_device.hpp" +#include "io/file_manager.hpp" +#include "main_loop.hpp" +#include "network/network_config.hpp" +#include "online/request_manager.hpp" +#include "states_screens/online_lan.hpp" +#include "states_screens/online_profile_achievements.hpp" +#include "states_screens/online_profile_servers.hpp" +#include "states_screens/online_screen.hpp" +#include "states_screens/state_manager.hpp" +#include "states_screens/user_screen.hpp" +#include "states_screens/dialogs/message_dialog.hpp" +#include "tracks/track_manager.hpp" +#include "utils/string_utils.hpp" + + +#include + + +using namespace GUIEngine; +using namespace Online; + +DEFINE_SCREEN_SINGLETON( OnlineScreen ); + +// ---------------------------------------------------------------------------- + +OnlineScreen::OnlineScreen() : Screen("online/online.stkgui") +{ + m_online_string = _("Your profile"); + //I18N: Used as a verb, appears on the main networking menu (login button) + m_login_string = _("Login"); +} // OnlineScreen + +// ---------------------------------------------------------------------------- + +void OnlineScreen::loadedFromFile() +{ +} // loadedFromFile + +// ---------------------------------------------------------------------------- + +void OnlineScreen::beforeAddingWidget() +{ + bool is_logged_in = false; + PlayerProfile *player = PlayerManager::getCurrentPlayer(); + if (PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_GUEST || + PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_SIGNED_IN) + { + is_logged_in = true; + } + + IconButtonWidget* wan = getWidget("wan"); + wan->setActive(is_logged_in); + wan->setVisible(is_logged_in); +} // beforeAddingWidget + +// ---------------------------------------------------------------------------- +// +void OnlineScreen::init() +{ + Screen::init(); + + m_online = getWidget("online"); + + if (!MainMenuScreen::m_enable_online) + m_online->setActive(false); + + m_user_id = getWidget("user-id"); + assert(m_user_id); + + RibbonWidget* r = getWidget("menu_toprow"); + r->setFocusForPlayer(PLAYER_ID_GAME_MASTER); + +} // init + +// ---------------------------------------------------------------------------- + +void OnlineScreen::onUpdate(float delta) +{ + PlayerProfile *player = PlayerManager::getCurrentPlayer(); + if (PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_GUEST || + PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_SIGNED_IN) + { + m_online->setActive(true); + m_online->setLabel(m_online_string); + m_user_id->setText(player->getLastOnlineName() + "@stk"); + } + else if (PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_SIGNED_OUT) + { + m_online->setActive(true); + m_online->setLabel(m_login_string); + m_user_id->setText(player->getName()); + } + else + { + // now must be either logging in or logging out + m_online->setActive(false); + m_user_id->setText(player->getName()); + } + + m_online->setLabel(PlayerManager::getCurrentOnlineId() ? m_online_string + : m_login_string); +} // onUpdate + +// ---------------------------------------------------------------------------- + +void OnlineScreen::eventCallback(Widget* widget, const std::string& name, + const int playerID) +{ + if (name == "user-id") + { + UserScreen::getInstance()->push(); + return; + } + else if (name == "back") + { + StateManager::get()->popMenu(); + return; + } + + RibbonWidget* ribbon = dynamic_cast(widget); + if (ribbon == NULL) return; // what's that event?? + + // ---- A ribbon icon was clicked + std::string selection = + ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER); + + if (selection == "lan") + { + OnlineLanScreen::getInstance()->push(); + } + else if (selection == "wan") + { + OnlineProfileServers::getInstance()->push(); + } + else if (selection == "online") + { + if (UserConfigParams::m_internet_status != RequestManager::IPERM_ALLOWED) + { + new MessageDialog(_("You can not play online without internet access. " + "If you want to play online, go to options, select " + " tab 'User Interface', and edit " + "\"Connect to the Internet\".")); + return; + } + + if (PlayerManager::getCurrentOnlineId()) + { + ProfileManager::get()->setVisiting(PlayerManager::getCurrentOnlineId()); + TabOnlineProfileAchievements::getInstance()->push(); + } + else + { + UserScreen::getInstance()->push(); + } + } +} // eventCallback + +// ---------------------------------------------------------------------------- + +void OnlineScreen::tearDown() +{ +} // tearDown + +// ---------------------------------------------------------------------------- + +void OnlineScreen::onDisabledItemClicked(const std::string& item) +{ +} // onDisabledItemClicked diff --git a/src/states_screens/online_screen.hpp b/src/states_screens/online_screen.hpp new file mode 100644 index 000000000..69f2b371b --- /dev/null +++ b/src/states_screens/online_screen.hpp @@ -0,0 +1,71 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2009-2015 Marianne Gagnon +// +// 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_ONLINE_SCREEN_HPP +#define HEADER_ONLINE_SCREEN_HPP + +#include "guiengine/screen.hpp" + +namespace GUIEngine { class Widget; class ListWidget; + class ButtonWidget; class IconButtonWidget; } + +/** + * \brief Handles the networking main menu + * \ingroup states_screens + */ +class OnlineScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton +{ +private: + friend class GUIEngine::ScreenSingleton; + + core::stringw m_online_string; + + core::stringw m_login_string; + + /** Keep the widget to to the user name. */ + GUIEngine::ButtonWidget *m_user_id; + + /** Keep the widget to avoid looking it up every frame. */ + GUIEngine::IconButtonWidget* m_online; + + OnlineScreen(); + +public: + + virtual void onUpdate(float delta) OVERRIDE; + + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void loadedFromFile() OVERRIDE; + + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void beforeAddingWidget() OVERRIDE; + + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name, + const int playerID) OVERRIDE; + + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void init() OVERRIDE; + + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void tearDown() OVERRIDE; + + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void onDisabledItemClicked(const std::string& item) OVERRIDE; +}; + +#endif diff --git a/src/states_screens/user_screen.cpp b/src/states_screens/user_screen.cpp index 91071c597..c9ef957ee 100644 --- a/src/states_screens/user_screen.cpp +++ b/src/states_screens/user_screen.cpp @@ -400,7 +400,7 @@ void BaseUserScreen::eventCallback(Widget* widget, */ void BaseUserScreen::closeScreen() { - StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); + StateManager::get()->popMenu(); } // closeScreen // ---------------------------------------------------------------------------- diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index f29266e26..ca3fabb63 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -466,6 +466,7 @@ void Track::cleanup() } #endif + m_meta_library.clear(); Scripting::ScriptEngine::getInstance()->cleanupCache(); m_current_track = NULL; @@ -1757,6 +1758,14 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) loadObjects(root, path, model_def_loader, true, NULL, NULL); + // Correct the parenting of meta library + for (auto& p : m_meta_library) + { + auto* ln = p.first->getPresentation(); + assert(ln); + p.second->setParent(ln->getNode()); + } + model_def_loader.cleanLibraryNodesAfterLoad(); Scripting::ScriptEngine::getInstance()->compileLoadedScripts(); diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index a0d5a5adb..4a4603547 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -374,6 +374,8 @@ private: /** List of all bezier curves in the track - for e.g. camera, ... */ std::vector m_all_curves; + std::vector > m_meta_library; + /** The number of laps the track will be raced in a random GP. * m_actual_number_of_laps is initialised with this value.*/ int m_default_number_of_laps; @@ -672,6 +674,10 @@ public: // ------------------------------------------------------------------------ /** Adds mesh to cleanup list */ void addCachedMesh(scene::IMesh* mesh) { m_all_cached_meshes.push_back(mesh); } + // ------------------------------------------------------------------------ + /** Adds the parent of the meta library for correction later */ + void addMetaLibrary(TrackObject* parent, scene::ISceneNode* meta_library) + { m_meta_library.emplace_back(parent, meta_library); } }; // class Track #endif diff --git a/src/tracks/track_object.cpp b/src/tracks/track_object.cpp index 0d441d123..0e11cd069 100644 --- a/src/tracks/track_object.cpp +++ b/src/tracks/track_object.cpp @@ -31,6 +31,7 @@ #include "physics/physical_object.hpp" #include "race/race_manager.hpp" #include "scriptengine/script_engine.hpp" +#include "tracks/track.hpp" #include "tracks/model_definition_loader.hpp" #include @@ -160,6 +161,11 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent, { xml_node.get("name", &m_name); m_presentation = new TrackObjectPresentationLibraryNode(this, xml_node, model_def_loader); + if (parent_library != NULL) + { + Track::getCurrentTrack()->addMetaLibrary(parent_library, + (dynamic_cast(m_presentation))->getNode()); + } } else if (type == "sfx-emitter") { diff --git a/src/tracks/track_object_presentation.cpp b/src/tracks/track_object_presentation.cpp index 414106b1b..5fe1e839c 100644 --- a/src/tracks/track_object_presentation.cpp +++ b/src/tracks/track_object_presentation.cpp @@ -180,6 +180,7 @@ TrackObjectPresentationLibraryNode::TrackObjectPresentationLibraryNode( { m_parent = NULL; m_start_executed = false; + m_reset_executed = false; std::string name; xml_node.get("name", &name); @@ -289,6 +290,22 @@ void TrackObjectPresentationLibraryNode::update(float dt) m_start_executed = true; std::string fn_name = StringUtils::insertValues("void %s::onStart(const string)", m_name.c_str()); + if (m_parent != NULL) + { + std::string lib_id = m_parent->getID(); + std::string* lib_id_ptr = &lib_id; + + Scripting::ScriptEngine::getInstance()->runFunction(false, fn_name, + [&](asIScriptContext* ctx) { + ctx->SetArgObject(0, lib_id_ptr); + }); + } + } + if (!m_reset_executed) + { + m_reset_executed = true; + std::string fn_name = StringUtils::insertValues("void %s::onReset(const string)", m_name.c_str()); + if (m_parent != NULL) { std::string lib_id = m_parent->getID(); diff --git a/src/tracks/track_object_presentation.hpp b/src/tracks/track_object_presentation.hpp index a2eedf32a..4a990b296 100644 --- a/src/tracks/track_object_presentation.hpp +++ b/src/tracks/track_object_presentation.hpp @@ -187,13 +187,18 @@ class TrackObjectPresentationLibraryNode : public TrackObjectPresentationSceneNo TrackObject* m_parent; using TrackObjectPresentationSceneNode::move; std::string m_name; - bool m_start_executed; + bool m_start_executed, m_reset_executed; public: TrackObjectPresentationLibraryNode(TrackObject* parent, const XMLNode& xml_node, ModelDefinitionLoader& model_def_loader); virtual ~TrackObjectPresentationLibraryNode(); - virtual void update(float dt); + virtual void update(float dt) OVERRIDE; + virtual void reset() OVERRIDE + { + m_reset_executed = false; + TrackObjectPresentationSceneNode::reset(); + } void move(const core::vector3df& xyz, const core::vector3df& hpr, const core::vector3df& scale, bool isAbsoluteCoord, bool moveChildrenPhysicalBodies); }; // TrackObjectPresentationLibraryNode