1 #include "ChatState.hpp"
2 #include "MessageState.hpp"
3 #include "ProgressState.hpp"
5 #include "../app/Environment.hpp"
6 #include "../io/event.hpp"
13 ChatState::ChatState(Environment &env, State &parent, Responder &responder)
16 , responder(responder)
18 , input(env.assets.small_ui_font) {
19 input.Position(glm::vec3(25.0f, -25.0f, -1.0f), Gravity::SOUTH_WEST, Gravity::SOUTH_WEST);
20 input.Width(env.viewport.Width() - 50.0f);
21 input.Foreground(PrimitiveMesh::Color(255));
22 input.Background(PrimitiveMesh::Color(127));
25 void ChatState::Preset(const std::string &text) {
29 void ChatState::Clear() {
33 void ChatState::OnResume() {
34 OnResize(env.viewport);
36 if (!preset.empty()) {
37 input.Insert(preset.c_str());
39 input.Focus(env.viewport);
42 void ChatState::OnPause() {
46 void ChatState::OnResize(Viewport &viewport) {
47 input.Width(viewport.Width() - 50.0f);
51 void ChatState::Handle(const SDL_Event &e) {
54 switch (e.key.keysym.sym) {
60 responder.OnLineSubmit(input.GetInput());
99 std::cout << e << std::endl;
100 input.Handle(e.edit);
108 void ChatState::Quit() {
109 env.state.PopUntil(this);
112 void ChatState::Update(int dt) {
116 void ChatState::Render(Viewport &viewport) {
117 parent.Render(viewport);
118 input.Render(viewport);
122 MessageState::MessageState(Environment &env)
124 message.Position(glm::vec3(0.0f), Gravity::CENTER);
126 press_key.Position(glm::vec3(0.0f, env.assets.large_ui_font.LineSkip(), 0.0f), Gravity::CENTER);
127 press_key.Set(env.assets.small_ui_font, "press any key to continue");
131 void MessageState::SetMessage(const char *msg) {
132 message.Set(env.assets.large_ui_font, msg);
136 void MessageState::ClearMessage() {
140 void MessageState::Handle(const SDL_Event &e) {
141 if (e.type == SDL_QUIT || e.type == SDL_KEYDOWN) {
146 void MessageState::Update(int) {
150 void MessageState::Render(Viewport &viewport) {
151 if (message.Visible()) {
152 message.Render(viewport);
154 if (press_key.Visible()) {
155 press_key.Render(viewport);
160 ProgressState::ProgressState(Environment &env, const char *tpl)
162 , progress(env.assets.large_ui_font) {
163 progress.Position(glm::vec3(0.0f), Gravity::CENTER);
164 progress.Template(tpl);
167 void ProgressState::SetProgress(int value, int total) {
168 progress.Update(value, total);
171 void ProgressState::Handle(const SDL_Event &e) {
172 if (e.type == SDL_QUIT) {
177 void ProgressState::Render(Viewport &viewport) {
178 progress.Render(viewport);