]> git.localhorst.tv Git - blank.git/blob - src/ui/Interface.hpp
state management and control
[blank.git] / src / ui / Interface.hpp
1 #ifndef BLANK_UI_INTERFACE_HPP_
2 #define BLANK_UI_INTERFACE_HPP_
3
4 #include "HUD.hpp"
5 #include "../app/FPSController.hpp"
6 #include "../app/IntervalTimer.hpp"
7 #include "../audio/Sound.hpp"
8 #include "../graphics/FixedText.hpp"
9 #include "../graphics/Font.hpp"
10 #include "../graphics/MessageBox.hpp"
11 #include "../model/geometry.hpp"
12 #include "../model/OutlineModel.hpp"
13 #include "../world/Block.hpp"
14
15 #include <string>
16 #include <glm/glm.hpp>
17
18
19 namespace blank {
20
21 class Chunk;
22 class Environment;
23 class Viewport;
24 class World;
25
26 class Interface {
27
28 public:
29         struct Config {
30                 float move_velocity = 0.005f;
31                 float pitch_sensitivity = -0.0025f;
32                 float yaw_sensitivity = -0.001f;
33
34                 bool keyboard_disabled = false;
35                 bool mouse_disabled = false;
36                 bool audio_disabled = false;
37                 bool visual_disabled = false;
38         };
39
40         Interface(const Config &, Environment &, World &);
41
42         void HandlePress(const SDL_KeyboardEvent &);
43         void HandleRelease(const SDL_KeyboardEvent &);
44         void Handle(const SDL_MouseMotionEvent &);
45         void HandlePress(const SDL_MouseButtonEvent &);
46         void HandleRelease(const SDL_MouseButtonEvent &);
47         void Handle(const SDL_MouseWheelEvent &);
48
49         void FaceBlock();
50         void TurnBlock();
51
52         void ToggleCollision();
53
54         void PickBlock();
55         void PlaceBlock();
56         void RemoveBlock() noexcept;
57
58         void PrintBlockInfo();
59         void PrintChunkInfo();
60         void PrintLightInfo();
61         void PrintSelectionInfo();
62         void Print(const Block &);
63
64         void SelectNext();
65         void SelectPrevious();
66
67         void ToggleAudio();
68         void ToggleVisual();
69
70         void ToggleDebug();
71         void UpdateCounter();
72         void UpdatePosition();
73
74         void PostMessage(const char *);
75         void PostMessage(const std::string &msg) {
76                 PostMessage(msg.c_str());
77         }
78
79         void Update(int dt);
80
81         void Render(Viewport &) noexcept;
82
83 private:
84         void CheckAim();
85
86 private:
87         Environment &env;
88         World &world;
89         FPSController ctrl;
90         Font font;
91         HUD hud;
92
93         Ray aim;
94         Chunk *aim_chunk;
95         int aim_block;
96         glm::vec3 aim_normal;
97
98         OutlineModel outline;
99         glm::mat4 outline_transform;
100
101         FixedText counter_text;
102         FixedText position_text;
103         MessageBox messages;
104         IntervalTimer msg_timer;
105
106         Config config;
107
108         IntervalTimer place_timer;
109         IntervalTimer remove_timer;
110
111         Block remove;
112         Block selection;
113
114         Sound place_sound;
115         Sound remove_sound;
116
117         glm::tvec3<int> fwd, rev;
118
119 };
120
121 }
122
123 #endif