]> git.lizzy.rs Git - dragonfireclient.git/blob - src/hud.h
C++ modernize: Pragma once (#6264)
[dragonfireclient.git] / src / hud.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include "irrlichttypes_extrabloated.h"
23 #include <string>
24
25 #define HUD_DIR_LEFT_RIGHT 0
26 #define HUD_DIR_RIGHT_LEFT 1
27 #define HUD_DIR_TOP_BOTTOM 2
28 #define HUD_DIR_BOTTOM_TOP 3
29
30 #define HUD_CORNER_UPPER  0
31 #define HUD_CORNER_LOWER  1
32 #define HUD_CORNER_CENTER 2
33
34 // Note that these visibility flags do not determine if the hud items are
35 // actually drawn, but rather, whether to draw the item should the rest
36 // of the game state permit it.
37 #define HUD_FLAG_HOTBAR_VISIBLE    (1 << 0)
38 #define HUD_FLAG_HEALTHBAR_VISIBLE (1 << 1)
39 #define HUD_FLAG_CROSSHAIR_VISIBLE (1 << 2)
40 #define HUD_FLAG_WIELDITEM_VISIBLE (1 << 3)
41 #define HUD_FLAG_BREATHBAR_VISIBLE (1 << 4)
42 #define HUD_FLAG_MINIMAP_VISIBLE   (1 << 5)
43
44 #define HUD_PARAM_HOTBAR_ITEMCOUNT 1
45 #define HUD_PARAM_HOTBAR_IMAGE 2
46 #define HUD_PARAM_HOTBAR_SELECTED_IMAGE 3
47
48 #define HUD_HOTBAR_ITEMCOUNT_DEFAULT 8
49 #define HUD_HOTBAR_ITEMCOUNT_MAX     23
50
51
52 #define HOTBAR_IMAGE_SIZE 48
53
54 enum HudElementType {
55         HUD_ELEM_IMAGE     = 0,
56         HUD_ELEM_TEXT      = 1,
57         HUD_ELEM_STATBAR   = 2,
58         HUD_ELEM_INVENTORY = 3,
59         HUD_ELEM_WAYPOINT  = 4,
60 };
61
62 enum HudElementStat {
63         HUD_STAT_POS = 0,
64         HUD_STAT_NAME,
65         HUD_STAT_SCALE,
66         HUD_STAT_TEXT,
67         HUD_STAT_NUMBER,
68         HUD_STAT_ITEM,
69         HUD_STAT_DIR,
70         HUD_STAT_ALIGN,
71         HUD_STAT_OFFSET,
72         HUD_STAT_WORLD_POS,
73         HUD_STAT_SIZE
74 };
75
76 struct HudElement {
77         HudElementType type;
78         v2f pos;
79         std::string name;
80         v2f scale;
81         std::string text;
82         u32 number;
83         u32 item;
84         u32 dir;
85         v2f align;
86         v2f offset;
87         v3f world_pos;
88         v2s32 size;
89 };
90
91 #ifndef SERVER
92
93 #include <vector>
94 #include <IGUIFont.h>
95 #include "irr_aabb3d.h"
96
97 class Client;
98 class ITextureSource;
99 class Inventory;
100 class InventoryList;
101 class LocalPlayer;
102 struct ItemStack;
103
104 class Hud {
105 public:
106         video::IVideoDriver *driver;
107         scene::ISceneManager* smgr;
108         gui::IGUIEnvironment *guienv;
109         Client *client;
110         LocalPlayer *player;
111         Inventory *inventory;
112         ITextureSource *tsrc;
113
114         video::SColor crosshair_argb;
115         video::SColor selectionbox_argb;
116         bool use_crosshair_image = false;
117         std::string hotbar_image = "";
118         bool use_hotbar_image = false;
119         std::string hotbar_selected_image = "";
120         bool use_hotbar_selected_image = false;
121
122         Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
123                 Inventory *inventory);
124         ~Hud();
125
126         void drawHotbar(u16 playeritem);
127         void resizeHotbar();
128         void drawCrosshair();
129         void drawSelectionMesh();
130         void updateSelectionMesh(const v3s16 &camera_offset);
131
132         std::vector<aabb3f> *getSelectionBoxes()
133         { return &m_selection_boxes; }
134
135         void setSelectionPos(const v3f &pos, const v3s16 &camera_offset);
136
137         v3f getSelectionPos() const
138         { return m_selection_pos; }
139
140         void setSelectionMeshColor(const video::SColor &color)
141         { m_selection_mesh_color = color; }
142
143         void setSelectedFaceNormal(const v3f &face_normal)
144         { m_selected_face_normal = face_normal; }
145
146         void drawLuaElements(const v3s16 &camera_offset);
147
148 private:
149         void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
150                         s32 count, v2s32 offset, v2s32 size=v2s32());
151
152         void drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
153                 s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction);
154
155         void drawItem(const ItemStack &item, const core::rect<s32>& rect,
156                 bool selected);
157
158         float m_hud_scaling; // cached minetest setting
159         v3s16 m_camera_offset;
160         v2u32 m_screensize;
161         v2s32 m_displaycenter;
162         s32 m_hotbar_imagesize; // Takes hud_scaling into account, updated by resizeHotbar()
163         s32 m_padding;  // Takes hud_scaling into account, updated by resizeHotbar()
164         video::SColor hbar_colors[4];
165
166         std::vector<aabb3f> m_selection_boxes;
167         std::vector<aabb3f> m_halo_boxes;
168         v3f m_selection_pos;
169         v3f m_selection_pos_with_offset;
170
171         scene::IMesh *m_selection_mesh = nullptr;
172         video::SColor m_selection_mesh_color;
173         v3f m_selected_face_normal;
174
175         video::SMaterial m_selection_material;
176
177         enum {
178                 HIGHLIGHT_BOX,
179                 HIGHLIGHT_HALO,
180                 HIGHLIGHT_NONE } m_mode;
181 };
182
183 enum ItemRotationKind {
184         IT_ROT_SELECTED,
185         IT_ROT_HOVERED,
186         IT_ROT_DRAGGED,
187         IT_ROT_NONE, // Must be last, also serves as number
188 };
189
190 void drawItemStack(video::IVideoDriver *driver,
191                 gui::IGUIFont *font,
192                 const ItemStack &item,
193                 const core::rect<s32> &rect,
194                 const core::rect<s32> *clip,
195                 Client *client,
196                 ItemRotationKind rotation_kind);
197
198 #endif