Wrath of Zeus
Made by Torchlight Games for CSE 125 SP24
Loading...
Searching...
No Matches
gui.hpp
Go to the documentation of this file.
1#pragma once
2
3// Include all gui headers so everyone else just needs to include this file
20
21#include <iostream>
22#include <vector>
23#include <memory>
24#include <map>
25#include <boost/optional/optional.hpp>
26
27// Forward declarration of LobbyPlayer struct
28struct LobbyPlayer;
29
30class Client;
31
32namespace gui {
33
39enum class GUIState {
40 NONE,
44 LOBBY,
50};
51
52#define GUI_PROJECTION_MATRIX() glm::ortho(0.0f, (float)WINDOW_WIDTH, 0.0f, (float)WINDOW_HEIGHT);
53
63class GUI {
64public:
70
80 explicit GUI(Client* client, const GameConfig& config);
86 bool init();
88
95
101 void beginFrame();
108 void layoutFrame(GUIState state);
138 void handleInputs(float mouse_xpos, float mouse_ypos, bool& is_left_mouse_down, bool& is_right_mouse_down);
143 void renderFrame();
145
151
203 template <typename W>
205 for (const auto& [_, widget] : this->widgets) {
206 if (widget->hasHandle(handle)) {
207 return dynamic_cast<W*>(widget->borrow(handle));
208 }
209 }
210
211 std::cerr << "GUI ERROR: attempting to borrowWidget from GUI\n"
212 << "with invalid handle. This should never happen\n"
213 << "and means we are doing something very very bad." << std::endl;
214 std::exit(1);
215 }
217
225
234 bool shouldCaptureKeystrokes() const;
240 void setCaptureKeystrokes(bool should_capture);
258 void captureKeystroke(char c);
263 void captureBackspace();
271 void displayControl();
277 std::string getCapturedKeyboardInput() const;
279
284
288 std::shared_ptr<font::Loader> getFonts();
290
291private:
292 widget::Handle next_handle {0};
293 std::map<widget::Handle, widget::Widget::Ptr> widgets;
294
295 std::shared_ptr<font::Loader> fonts;
296 img::Loader images;
297
298 bool capture_keystrokes;
299 std::string keyboard_input;
300
301 Client* client;
302
303 GameConfig config;
304 bool controlDisplayed;
305
306 std::vector<std::string> recentEvents;
307
308 img::Logo logo;
309
311
319 void _handleClick(float x, float y);
328 void _handleHover(float x, float y);
330
343
346 void _layoutLoadingScreen();
352 void _layoutTitleScreen();
359 void _layoutLobbyBrowser();
360
364 void _layoutFPSCounter();
365
374 void _layoutLobby();
375
386 gui::widget::Flexbox::Ptr _createPlayerStatusRow(boost::optional<LobbyPlayer> lobbyPlayer,
387 glm::vec3 columnWidths, glm::vec2 origin, int playerIndex);
393 void _layoutGameHUD();
394
398 void _sharedGameHUD();
399
407 void _layoutGameEscMenu();
411 void _layoutDeadScreen();
412
417 void _layoutResultsScreen();
418
420};
421
422}
A clsas that represents the client for the game. Contains all local information, including the Shared...
Definition: client.hpp:50
Definition: gui.hpp:63
void renderFrame()
Definition: gui.cpp:67
bool init()
Initializes all of the necessary file loading for all of the GUI elements, and registers all of the s...
Definition: gui.cpp:23
widget::Widget::Ptr removeWidget(widget::Handle handle)
Removes the specified widget from the GUI.
Definition: gui.cpp:100
void handleInputs(float mouse_xpos, float mouse_ypos, bool &is_left_mouse_down, bool &is_right_mouse_down)
Takes the current relevant input information and alters the GUI based on the how the inputs interact ...
Definition: gui.cpp:81
widget::Handle addWidget(widget::Widget::Ptr &&widget)
==============================================================================
Definition: gui.cpp:94
void beginFrame()
================================================================================
Definition: gui.cpp:62
void setCaptureKeystrokes(bool should_capture)
Toggles whether or not the GUI should be capturing keyboard input.
Definition: gui.cpp:130
void captureBackspace()
If the GUI is capturing backspaces, then records a backspace press. This deletes the most recently ca...
Definition: gui.cpp:106
void clearCapturedKeyboardInput()
Wipes all of the captured keyboard input from the internal state.
Definition: gui.cpp:134
W * borrowWidget(widget::Handle handle)
Borrows the specified widget from the GUI. This is especially useful inside of callback functions for...
Definition: gui.hpp:204
void captureKeystroke(char c)
Captures a keystroke as an ASCII char.
Definition: gui.cpp:114
bool shouldCaptureKeystrokes() const
==============================================================================
Definition: gui.cpp:126
void displayControl()
Displays controls for the player.
Definition: gui.cpp:206
std::shared_ptr< font::Loader > getFonts()
==============================================================================
Definition: gui.cpp:140
std::string getCapturedKeyboardInput() const
Returns all of the captured keyboard input without clearing it.
Definition: gui.cpp:122
void layoutFrame(GUIState state)
Adds widgets to the layout depending on the specified GUI state.
Definition: gui.cpp:144
std::unique_ptr< Flexbox > Ptr
Definition: flexbox.hpp:12
std::unique_ptr< Widget > Ptr
Definition: widget.hpp:45
GLint GLenum GLint x
Definition: glad.h:1655
GLint y
Definition: glad.h:1516
std::size_t Handle
Type for a Widget Handle.
Definition: widget.hpp:16
Definition: font.hpp:9
GUIState
Definition: gui.hpp:39
Definition: config.hpp:12
Information about a player that has connected to the current lobby.
Definition: sharedgamestate.hpp:37