]> git.localhorst.tv Git - blank.git/blob - src/ui/Interface.hpp
special treatment for players
[blank.git] / src / ui / Interface.hpp
1 #ifndef BLANK_UI_INTERFACE_HPP_
2 #define BLANK_UI_INTERFACE_HPP_
3
4 #include "FixedText.hpp"
5 #include "HUD.hpp"
6 #include "MessageBox.hpp"
7 #include "../app/FPSController.hpp"
8 #include "../app/IntervalTimer.hpp"
9 #include "../audio/Sound.hpp"
10 #include "../model/geometry.hpp"
11 #include "../model/OutlineModel.hpp"
12 #include "../world/Block.hpp"
13 #include "../world/EntityCollision.hpp"
14 #include "../world/WorldCollision.hpp"
15
16 #include <string>
17 #include <glm/glm.hpp>
18 #include <SDL.h>
19
20
21 namespace blank {
22
23 class Environment;
24 class Viewport;
25 class World;
26
27 class Interface {
28
29 public:
30         struct Config {
31                 std::string player_name = "default";
32
33                 float move_velocity = 0.005f;
34                 float pitch_sensitivity = -0.0025f;
35                 float yaw_sensitivity = -0.001f;
36
37                 bool keyboard_disabled = false;
38                 bool mouse_disabled = false;
39                 bool audio_disabled = false;
40                 bool visual_disabled = false;
41         };
42
43         Interface(const Config &, Environment &, World &);
44
45         Entity &Player() noexcept { return ctrl.Controlled(); }
46         const Entity &Player() const noexcept { return ctrl.Controlled(); }
47
48         void HandlePress(const SDL_KeyboardEvent &);
49         void HandleRelease(const SDL_KeyboardEvent &);
50         void Handle(const SDL_MouseMotionEvent &);
51         void HandlePress(const SDL_MouseButtonEvent &);
52         void HandleRelease(const SDL_MouseButtonEvent &);
53         void Handle(const SDL_MouseWheelEvent &);
54
55         void FaceBlock();
56         void TurnBlock();
57
58         void ToggleCollision();
59
60         void PickBlock();
61         void PlaceBlock();
62         void RemoveBlock() noexcept;
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         void UpdateOrientation();
74         void UpdateBlockInfo();
75         void UpdateEntityInfo();
76
77         void PostMessage(const char *);
78         void PostMessage(const std::string &msg) {
79                 PostMessage(msg.c_str());
80         }
81
82         void Update(int dt);
83
84         void Render(Viewport &) noexcept;
85
86 private:
87         void CheckAim();
88         void UpdateOutline();
89
90 private:
91         Environment &env;
92         World &world;
93         FPSController ctrl;
94         HUD hud;
95
96         Ray aim;
97         WorldCollision aim_world;
98         EntityCollision aim_entity;
99
100         OutlineModel outline;
101         glm::mat4 outline_transform;
102
103         FixedText counter_text;
104         FixedText position_text;
105         FixedText orientation_text;
106         FixedText block_text;
107         FixedText entity_text;
108         Block last_block;
109         Entity *last_entity;
110         MessageBox messages;
111         IntervalTimer msg_timer;
112
113         Config config;
114
115         IntervalTimer place_timer;
116         IntervalTimer remove_timer;
117
118         Block remove;
119         Block selection;
120
121         Sound place_sound;
122         Sound remove_sound;
123
124         glm::ivec3 fwd, rev;
125
126         bool debug;
127
128 };
129
130 }
131
132 #endif