diff --git a/client/client_application.cpp b/client/client_application.cpp index ebc9f18..267440c 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -37,6 +37,7 @@ #include "lobby_menu.hpp" #include "in_world.hpp" #include "in_combat.hpp" +#include "restart.hpp" //------------------------- //Public access members @@ -127,6 +128,9 @@ void ClientApplication::LoadScene(SceneList sceneIndex) { case SceneList::INCOMBAT: activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap); break; + case SceneList::RESTART: + activeScene = new Restart(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap); + break; default: throw(std::logic_error("Failed to recognize the scene index")); } diff --git a/client/in_combat.cpp b/client/in_combat.cpp index 992643e..6be762f 100644 --- a/client/in_combat.cpp +++ b/client/in_combat.cpp @@ -167,8 +167,7 @@ void InCombat::HandlePacket(SerialPacket packet) { } void InCombat::HandleDisconnect(SerialPacket) { - //TODO: stuff - //TODO: I probably need a separate disconnection scene, for setting the client state back to normal + SetNextScene(SceneList::RESTART); } //TODO: more network handlers diff --git a/client/in_world.cpp b/client/in_world.cpp index b9a5002..8063de6 100644 --- a/client/in_world.cpp +++ b/client/in_world.cpp @@ -273,12 +273,7 @@ void InWorld::HandlePacket(SerialPacket packet) { } void InWorld::HandleDisconnect(SerialPacket packet) { - //TODO: I probably need a separate disconnection scene, for setting the client state back to normal - network.Unbind(Channels::SERVER); - clientIndex = -1; - accountIndex = -1; - characterIndex = -1; - SetNextScene(SceneList::MAINMENU); + SetNextScene(SceneList::RESTART); } void InWorld::HandleRegionContent(SerialPacket packet) { diff --git a/client/restart.cpp b/client/restart.cpp new file mode 100644 index 0000000..91f266e --- /dev/null +++ b/client/restart.cpp @@ -0,0 +1,138 @@ +/* Copyright: (c) Kayne Ruse 2014 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#include "restart.hpp" + +#include "channels.hpp" + +#include + +//------------------------- +//Public access members +//------------------------- + +Restart::Restart( + ConfigUtility* const argConfig, + UDPNetworkUtility* const argNetwork, + int* const argClientIndex, + int* const argAccountIndex, + int* const argCharacterIndex, + std::map* argCombatMap, + std::map* argCharacterMap, + std::map* argEnemyMap + ): + config(*argConfig), + network(*argNetwork), + clientIndex(*argClientIndex), + accountIndex(*argAccountIndex), + characterIndex(*argCharacterIndex), + combatMap(*argCombatMap), + characterMap(*argCharacterMap), + enemyMap(*argEnemyMap) +{ + //setup the utility objects + image.LoadSurface(config["dir.interface"] + "button_menu.bmp"); + image.SetClipH(image.GetClipH()/3); + font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp"); + + //pass the utility objects + backButton.SetImage(&image); + backButton.SetFont(&font); + + //set the button positions + backButton.SetX(50); + backButton.SetY(50 + image.GetClipH() * 0); + + //set the button texts + backButton.SetText("Back"); + + //full reset + network.Unbind(Channels::SERVER); + clientIndex = -1; + accountIndex = -1; + characterIndex = -1; + combatMap.clear(); + characterMap.clear(); + enemyMap.clear(); + + //auto return + startTick = std::chrono::steady_clock::now(); +} + +Restart::~Restart() { + // +} + +//------------------------- +//Frame loop +//------------------------- + +void Restart::Update(double delta) { + if (std::chrono::steady_clock::now() - startTick > std::chrono::duration(10)) { + QuitEvent(); + } +} + +void Restart::RenderFrame() { + SDL_FillRect(GetScreen(), 0, 0); + Render(GetScreen()); + SDL_Flip(GetScreen()); + fps.Calculate(); +} + +void Restart::Render(SDL_Surface* const screen) { + backButton.DrawTo(screen); + font.DrawStringTo("You have been disconnected.", screen, 50, 30); +} + +//------------------------- +//Event handlers +//------------------------- + +void Restart::QuitEvent() { + SetNextScene(SceneList::MAINMENU); +} + +void Restart::MouseMotion(SDL_MouseMotionEvent const& motion) { + backButton.MouseMotion(motion); +} + +void Restart::MouseButtonDown(SDL_MouseButtonEvent const& button) { + backButton.MouseButtonDown(button); +} + +void Restart::MouseButtonUp(SDL_MouseButtonEvent const& button) { + if (backButton.MouseButtonUp(button) == Button::State::HOVER) { + QuitEvent(); + } +} + +void Restart::KeyDown(SDL_KeyboardEvent const& key) { + switch(key.keysym.sym) { + case SDLK_ESCAPE: + QuitEvent(); + break; + } +} + +void Restart::KeyUp(SDL_KeyboardEvent const& key) { + // +} diff --git a/client/restart.hpp b/client/restart.hpp new file mode 100644 index 0000000..4012a80 --- /dev/null +++ b/client/restart.hpp @@ -0,0 +1,98 @@ +/* Copyright: (c) Kayne Ruse 2014 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#ifndef RESTART_HPP_ +#define RESTART_HPP_ + +//network +#include "udp_network_utility.hpp" + +//graphics +#include "image.hpp" +#include "raster_font.hpp" +#include "button.hpp" + +//common +#include "config_utility.hpp" +#include "frame_rate.hpp" + +#include "combat_data.hpp" +#include "character_data.hpp" +#include "enemy_data.hpp" + +//client +#include "base_scene.hpp" + +//std namespace +#include + +class Restart : public BaseScene { +public: + //Public access members + Restart( + ConfigUtility* const argConfig, + UDPNetworkUtility* const argNetwork, + int* const argClientIndex, + int* const argAccountIndex, + int* const argCharacterIndex, + std::map* argCombatMap, + std::map* argCharacterMap, + std::map* argEnemyMap + ); + ~Restart(); + +protected: + //Frame loop + void Update(double delta); + void RenderFrame(); + void Render(SDL_Surface* const); + + //Event handlers + void QuitEvent(); + void MouseMotion(SDL_MouseMotionEvent const&); + void MouseButtonDown(SDL_MouseButtonEvent const&); + void MouseButtonUp(SDL_MouseButtonEvent const&); + void KeyDown(SDL_KeyboardEvent const&); + void KeyUp(SDL_KeyboardEvent const&); + + //shared parameters + ConfigUtility& config; + UDPNetworkUtility& network; + int& clientIndex; + int& accountIndex; + int& characterIndex; + std::map& combatMap; + std::map& characterMap; + std::map& enemyMap; + + //graphics + Image image; + RasterFont font; + + //UI + Button backButton; + FrameRate fps; + + //auto return + std::chrono::steady_clock::time_point startTick; +}; + +#endif diff --git a/client/scene_list.hpp b/client/scene_list.hpp index a124237..79d396c 100644 --- a/client/scene_list.hpp +++ b/client/scene_list.hpp @@ -35,6 +35,7 @@ enum class SceneList { LOBBYMENU, INWORLD, INCOMBAT, + RESTART, }; #endif