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