From: Daniel Karbach Date: Mon, 26 Oct 2015 13:22:49 +0000 (+0100) Subject: moved common stated to shared dir X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=69e4d6c0a86a27f9b3f1297e46c55b36059a24b9;p=blank.git moved common stated to shared dir --- diff --git a/src/app/ChatState.cpp b/src/app/ChatState.cpp deleted file mode 100644 index 1eb35be..0000000 --- a/src/app/ChatState.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include "ChatState.hpp" - -#include "Environment.hpp" -#include "../io/event.hpp" - -#include - - -namespace blank { - -ChatState::ChatState(Environment &env, State &parent, Responder &responder) -: env(env) -, parent(parent) -, responder(responder) -, input(env.assets.small_ui_font) { - input.Position(glm::vec3(25.0f, -25.0f, -1.0f), Gravity::SOUTH_WEST, Gravity::SOUTH_WEST); - input.Width(env.viewport.Width() - 50.0f); - input.Foreground(glm::vec4(1.0f)); - input.Background(glm::vec4(0.5f)); -} - -void ChatState::OnResume() { - OnResize(env.viewport); - input.Clear(); - input.Focus(env.viewport); -} - -void ChatState::OnPause() { - input.Blur(); -} - -void ChatState::OnResize(Viewport &viewport) { - input.Width(viewport.Width() - 50.0f); -} - - -void ChatState::Handle(const SDL_Event &e) { - switch (e.type) { - case SDL_KEYDOWN: - switch (e.key.keysym.sym) { - case SDLK_ESCAPE: - Quit(); - break; - case SDLK_KP_ENTER: - case SDLK_RETURN: - responder.OnLineSubmit(input.GetInput()); - Quit(); - break; - - case SDLK_BACKSPACE: - input.Backspace(); - break; - case SDLK_DELETE: - input.Delete(); - break; - - case SDLK_LEFT: - input.MoveBackward(); - break; - case SDLK_RIGHT: - input.MoveForward(); - break; - - case SDLK_HOME: - input.MoveBegin(); - break; - case SDLK_END: - input.MoveEnd(); - break; - - default: - break; - } - break; - - case SDL_QUIT: - env.state.PopAll(); - break; - - case SDL_TEXTINPUT: - input.Handle(e.text); - break; - - case SDL_TEXTEDITING: - std::cout << e << std::endl; - input.Handle(e.edit); - break; - - default: - break; - } -} - -void ChatState::Quit() { - env.state.PopUntil(this); -} - -void ChatState::Update(int dt) { - parent.Update(dt); -} - -void ChatState::Render(Viewport &viewport) { - parent.Render(viewport); - input.Render(viewport); -} - -} diff --git a/src/app/ChatState.hpp b/src/app/ChatState.hpp deleted file mode 100644 index 56f8538..0000000 --- a/src/app/ChatState.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef BLANK_APP_CHATSTATE_HPP_ -#define BLANK_APP_CHATSTATE_HPP_ - -#include "State.hpp" - -#include "../ui/TextInput.hpp" - -#include - - -namespace blank { - -class Environment; - -class ChatState -: public State { - -public: - struct Responder { - virtual void OnLineSubmit(const std::string &) = 0; - }; - -public: - ChatState(Environment &env, State &parent, Responder &); - - void OnResume() override; - void OnPause() override; - - void OnResize(Viewport &) override; - - void Handle(const SDL_Event &) override; - void Update(int dt) override; - void Render(Viewport &) override; - - void Quit(); - -private: - Environment &env; - State &parent; - Responder &responder; - - TextInput input; - -}; - -} - -#endif diff --git a/src/app/Environment.hpp b/src/app/Environment.hpp index 724db70..7061000 100644 --- a/src/app/Environment.hpp +++ b/src/app/Environment.hpp @@ -3,11 +3,11 @@ #include "Assets.hpp" #include "FrameCounter.hpp" -#include "MessageState.hpp" #include "StateControl.hpp" #include "../audio/Audio.hpp" #include "../graphics/Viewport.hpp" #include "../rand/GaloisLFSR.hpp" +#include "../shared/MessageState.hpp" #include "../ui/Keymap.hpp" #include diff --git a/src/app/MessageState.cpp b/src/app/MessageState.cpp deleted file mode 100644 index 53ed741..0000000 --- a/src/app/MessageState.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "MessageState.hpp" - -#include "Environment.hpp" - - -namespace blank { - -MessageState::MessageState(Environment &env) -: env(env) { - message.Position(glm::vec3(0.0f), Gravity::CENTER); - message.Hide(); - press_key.Position(glm::vec3(0.0f, env.assets.large_ui_font.LineSkip(), 0.0f), Gravity::CENTER); - press_key.Set(env.assets.small_ui_font, "press any key to continue"); - press_key.Show(); -} - -void MessageState::SetMessage(const char *msg) { - message.Set(env.assets.large_ui_font, msg); - message.Show(); -} - -void MessageState::ClearMessage() { - message.Hide(); -} - -void MessageState::Handle(const SDL_Event &e) { - if (e.type == SDL_KEYDOWN) { - env.state.Pop(); - } -} - -void MessageState::Update(int dt) { - -} - -void MessageState::Render(Viewport &viewport) { - if (message.Visible()) { - message.Render(viewport); - } - if (press_key.Visible()) { - press_key.Render(viewport); - } -} - -} diff --git a/src/app/MessageState.hpp b/src/app/MessageState.hpp deleted file mode 100644 index 29c8cb6..0000000 --- a/src/app/MessageState.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef BLANK_APP_MESSAGESTATE_HPP_ -#define BLANK_APP_MESSAGESTATE_HPP_ - -#include "State.hpp" - -#include "../ui/FixedText.hpp" - - -namespace blank { - -class Environment; - -class MessageState -: public State { - -public: - explicit MessageState(Environment &); - - void SetMessage(const char *); - void ClearMessage(); - - void Handle(const SDL_Event &) override; - void Update(int dt) override; - void Render(Viewport &) override; - -private: - Environment &env; - FixedText message; - FixedText press_key; - -}; - -} - -#endif diff --git a/src/app/ProgressState.cpp b/src/app/ProgressState.cpp deleted file mode 100644 index 30a60dc..0000000 --- a/src/app/ProgressState.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "ProgressState.hpp" - -#include "../app/Environment.hpp" - - -namespace blank { - -ProgressState::ProgressState(Environment &env, const char *tpl) -: env(env) -, progress(env.assets.large_ui_font) { - progress.Position(glm::vec3(0.0f), Gravity::CENTER); - progress.Template(tpl); -} - -void ProgressState::SetProgress(int value, int total) { - progress.Update(value, total); -} - -void ProgressState::Handle(const SDL_Event &e) { - if (e.type == SDL_QUIT) { - env.state.PopAll(); - } -} - -void ProgressState::Render(Viewport &viewport) { - progress.Render(viewport); -} - -} diff --git a/src/app/ProgressState.hpp b/src/app/ProgressState.hpp deleted file mode 100644 index b3295c2..0000000 --- a/src/app/ProgressState.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef BLANK_APP_PROGRESSSTATE_HPP_ -#define BLANK_APP_PROGRESSSTATE_HPP_ - -#include "State.hpp" - -#include "../ui/Progress.hpp" - - -namespace blank { - -class Environment; - -class ProgressState -: public State { - -public: - ProgressState(Environment &env, const char *tpl); - - void SetProgress(int value, int total); - - void Handle(const SDL_Event &) override; - void Render(Viewport &) override; - -private: - Environment &env; - Progress progress; - -}; - -} - -#endif diff --git a/src/client/InteractiveState.hpp b/src/client/InteractiveState.hpp index ab65138..d5fd4a1 100644 --- a/src/client/InteractiveState.hpp +++ b/src/client/InteractiveState.hpp @@ -6,12 +6,12 @@ #include "ChunkReceiver.hpp" #include "NetworkedInput.hpp" -#include "../app/ChatState.hpp" #include "../app/IntervalTimer.hpp" #include "../audio/SoundBank.hpp" #include "../graphics/SkyBox.hpp" #include "../io/WorldSave.hpp" #include "../net/Packet.hpp" +#include "../shared/ChatState.hpp" #include "../shared/WorldResources.hpp" #include "../ui/HUD.hpp" #include "../ui/InteractiveManipulator.hpp" diff --git a/src/shared/ChatState.hpp b/src/shared/ChatState.hpp new file mode 100644 index 0000000..7b8a993 --- /dev/null +++ b/src/shared/ChatState.hpp @@ -0,0 +1,48 @@ +#ifndef BLANK_SHARED_CHATSTATE_HPP_ +#define BLANK_SHARED_CHATSTATE_HPP_ + +#include "../app/State.hpp" + +#include "../ui/TextInput.hpp" + +#include + + +namespace blank { + +class Environment; + +class ChatState +: public State { + +public: + struct Responder { + virtual void OnLineSubmit(const std::string &) = 0; + }; + +public: + ChatState(Environment &env, State &parent, Responder &); + + void OnResume() override; + void OnPause() override; + + void OnResize(Viewport &) override; + + void Handle(const SDL_Event &) override; + void Update(int dt) override; + void Render(Viewport &) override; + + void Quit(); + +private: + Environment &env; + State &parent; + Responder &responder; + + TextInput input; + +}; + +} + +#endif diff --git a/src/shared/MessageState.hpp b/src/shared/MessageState.hpp new file mode 100644 index 0000000..8595fe0 --- /dev/null +++ b/src/shared/MessageState.hpp @@ -0,0 +1,35 @@ +#ifndef BLANK_SHARED_MESSAGESTATE_HPP_ +#define BLANK_SHARED_MESSAGESTATE_HPP_ + +#include "../app/State.hpp" + +#include "../ui/FixedText.hpp" + + +namespace blank { + +class Environment; + +class MessageState +: public State { + +public: + explicit MessageState(Environment &); + + void SetMessage(const char *); + void ClearMessage(); + + void Handle(const SDL_Event &) override; + void Update(int dt) override; + void Render(Viewport &) override; + +private: + Environment &env; + FixedText message; + FixedText press_key; + +}; + +} + +#endif diff --git a/src/shared/ProgressState.hpp b/src/shared/ProgressState.hpp new file mode 100644 index 0000000..8bfea0e --- /dev/null +++ b/src/shared/ProgressState.hpp @@ -0,0 +1,32 @@ +#ifndef BLANK_SHARED_PROGRESSSTATE_HPP_ +#define BLANK_SHARED_PROGRESSSTATE_HPP_ + +#include "../app/State.hpp" + +#include "../ui/Progress.hpp" + + +namespace blank { + +class Environment; + +class ProgressState +: public State { + +public: + ProgressState(Environment &env, const char *tpl); + + void SetProgress(int value, int total); + + void Handle(const SDL_Event &) override; + void Render(Viewport &) override; + +private: + Environment &env; + Progress progress; + +}; + +} + +#endif diff --git a/src/shared/states.cpp b/src/shared/states.cpp new file mode 100644 index 0000000..b9a48b0 --- /dev/null +++ b/src/shared/states.cpp @@ -0,0 +1,169 @@ +#include "ChatState.hpp" +#include "MessageState.hpp" +#include "ProgressState.hpp" + +#include "../app/Environment.hpp" +#include "../io/event.hpp" + +#include + + +namespace blank { + +ChatState::ChatState(Environment &env, State &parent, Responder &responder) +: env(env) +, parent(parent) +, responder(responder) +, input(env.assets.small_ui_font) { + input.Position(glm::vec3(25.0f, -25.0f, -1.0f), Gravity::SOUTH_WEST, Gravity::SOUTH_WEST); + input.Width(env.viewport.Width() - 50.0f); + input.Foreground(glm::vec4(1.0f)); + input.Background(glm::vec4(0.5f)); +} + +void ChatState::OnResume() { + OnResize(env.viewport); + input.Clear(); + input.Focus(env.viewport); +} + +void ChatState::OnPause() { + input.Blur(); +} + +void ChatState::OnResize(Viewport &viewport) { + input.Width(viewport.Width() - 50.0f); +} + + +void ChatState::Handle(const SDL_Event &e) { + switch (e.type) { + case SDL_KEYDOWN: + switch (e.key.keysym.sym) { + case SDLK_ESCAPE: + Quit(); + break; + case SDLK_KP_ENTER: + case SDLK_RETURN: + responder.OnLineSubmit(input.GetInput()); + Quit(); + break; + + case SDLK_BACKSPACE: + input.Backspace(); + break; + case SDLK_DELETE: + input.Delete(); + break; + + case SDLK_LEFT: + input.MoveBackward(); + break; + case SDLK_RIGHT: + input.MoveForward(); + break; + + case SDLK_HOME: + input.MoveBegin(); + break; + case SDLK_END: + input.MoveEnd(); + break; + + default: + break; + } + break; + + case SDL_QUIT: + env.state.PopAll(); + break; + + case SDL_TEXTINPUT: + input.Handle(e.text); + break; + + case SDL_TEXTEDITING: + std::cout << e << std::endl; + input.Handle(e.edit); + break; + + default: + break; + } +} + +void ChatState::Quit() { + env.state.PopUntil(this); +} + +void ChatState::Update(int dt) { + parent.Update(dt); +} + +void ChatState::Render(Viewport &viewport) { + parent.Render(viewport); + input.Render(viewport); +} + + +MessageState::MessageState(Environment &env) +: env(env) { + message.Position(glm::vec3(0.0f), Gravity::CENTER); + message.Hide(); + press_key.Position(glm::vec3(0.0f, env.assets.large_ui_font.LineSkip(), 0.0f), Gravity::CENTER); + press_key.Set(env.assets.small_ui_font, "press any key to continue"); + press_key.Show(); +} + +void MessageState::SetMessage(const char *msg) { + message.Set(env.assets.large_ui_font, msg); + message.Show(); +} + +void MessageState::ClearMessage() { + message.Hide(); +} + +void MessageState::Handle(const SDL_Event &e) { + if (e.type == SDL_KEYDOWN) { + env.state.Pop(); + } +} + +void MessageState::Update(int dt) { + +} + +void MessageState::Render(Viewport &viewport) { + if (message.Visible()) { + message.Render(viewport); + } + if (press_key.Visible()) { + press_key.Render(viewport); + } +} + + +ProgressState::ProgressState(Environment &env, const char *tpl) +: env(env) +, progress(env.assets.large_ui_font) { + progress.Position(glm::vec3(0.0f), Gravity::CENTER); + progress.Template(tpl); +} + +void ProgressState::SetProgress(int value, int total) { + progress.Update(value, total); +} + +void ProgressState::Handle(const SDL_Event &e) { + if (e.type == SDL_QUIT) { + env.state.PopAll(); + } +} + +void ProgressState::Render(Viewport &viewport) { + progress.Render(viewport); +} + +} diff --git a/src/standalone/MasterState.hpp b/src/standalone/MasterState.hpp index 942cc13..26fcf26 100644 --- a/src/standalone/MasterState.hpp +++ b/src/standalone/MasterState.hpp @@ -7,9 +7,9 @@ #include "PreloadState.hpp" #include "UnloadState.hpp" #include "../ai/Spawner.hpp" -#include "../app/ChatState.hpp" #include "../audio/SoundBank.hpp" #include "../graphics/SkyBox.hpp" +#include "../shared/ChatState.hpp" #include "../shared/WorldResources.hpp" #include "../ui/DirectInput.hpp" #include "../ui/HUD.hpp" diff --git a/src/standalone/PreloadState.hpp b/src/standalone/PreloadState.hpp index 1e750d9..2012d4b 100644 --- a/src/standalone/PreloadState.hpp +++ b/src/standalone/PreloadState.hpp @@ -1,7 +1,7 @@ #ifndef BLANK_STANDALONE_PRELOADSTATE_HPP_ #define BLANK_STANDALONE_PRELOADSTATE_HPP_ -#include "../app/ProgressState.hpp" +#include "../shared/ProgressState.hpp" #include diff --git a/src/standalone/UnloadState.hpp b/src/standalone/UnloadState.hpp index 959fa94..7782ce2 100644 --- a/src/standalone/UnloadState.hpp +++ b/src/standalone/UnloadState.hpp @@ -1,7 +1,7 @@ #ifndef BLANK_STANDALONE_UNLOADSTATE_HPP_ #define BLANK_STANDALONE_UNLOADSTATE_HPP_ -#include "../app/ProgressState.hpp" +#include "../shared/ProgressState.hpp" #include #include