]> git.localhorst.tv Git - blank.git/blob - src/ui/Interface.hpp
00b76e66b0c2232ea48cfc0eec1f053e03c3aaac
[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 "../graphics/FixedText.hpp"
8 #include "../graphics/Font.hpp"
9 #include "../graphics/MessageBox.hpp"
10 #include "../model/geometry.hpp"
11 #include "../model/OutlineModel.hpp"
12 #include "../world/Block.hpp"
13
14 #include <string>
15 #include <glm/glm.hpp>
16
17
18 namespace blank {
19
20 class Assets;
21 class Chunk;
22 class FrameCounter;
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 visual_disabled = false;
37         };
38
39         Interface(const Config &, const Assets &, const FrameCounter &, World &);
40
41         void HandlePress(const SDL_KeyboardEvent &);
42         void HandleRelease(const SDL_KeyboardEvent &);
43         void Handle(const SDL_MouseMotionEvent &);
44         void HandlePress(const SDL_MouseButtonEvent &);
45         void HandleRelease(const SDL_MouseButtonEvent &);
46         void Handle(const SDL_MouseWheelEvent &);
47
48         void FaceBlock();
49         void TurnBlock();
50
51         void ToggleCollision();
52
53         void PickBlock();
54         void PlaceBlock();
55         void RemoveBlock() noexcept;
56
57         void PrintBlockInfo();
58         void PrintChunkInfo();
59         void PrintLightInfo();
60         void PrintSelectionInfo();
61         void Print(const Block &);
62
63         void SelectNext();
64         void SelectPrevious();
65
66         void ToggleCounter();
67         void UpdateCounter();
68
69         void PostMessage(const char *);
70         void PostMessage(const std::string &msg) {
71                 PostMessage(msg.c_str());
72         }
73
74         void Update(int dt);
75
76         void Render(Viewport &) noexcept;
77
78 private:
79         void CheckAim();
80
81 private:
82         const FrameCounter &counter;
83         World &world;
84         FPSController ctrl;
85         Font font;
86         HUD hud;
87
88         Ray aim;
89         Chunk *aim_chunk;
90         int aim_block;
91         glm::vec3 aim_normal;
92
93         OutlineModel outline;
94         glm::mat4 outline_transform;
95
96         FixedText counter_text;
97         MessageBox messages;
98         IntervalTimer msg_timer;
99
100         Config config;
101
102         IntervalTimer place_timer;
103         IntervalTimer remove_timer;
104
105         Block remove;
106         Block selection;
107
108         glm::tvec3<int> fwd, rev;
109
110 };
111
112 }
113
114 #endif