]> git.lizzy.rs Git - minetest.git/blob - src/client/hud.h
Fix lighting of upright_sprite entities (#12336)
[minetest.git] / src / client / hud.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4 Copyright (C) 2017 red-001 <red-001@outlook.ie>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #pragma once
22
23 #include <vector>
24 #include <IGUIFont.h>
25 #include "irr_aabb3d.h"
26 #include "../hud.h"
27
28 class Client;
29 class ITextureSource;
30 class Inventory;
31 class InventoryList;
32 class LocalPlayer;
33 struct ItemStack;
34
35 class Hud
36 {
37 public:
38         enum BlockBoundsMode
39         {
40                 BLOCK_BOUNDS_OFF,
41                 BLOCK_BOUNDS_CURRENT,
42                 BLOCK_BOUNDS_NEAR,
43                 BLOCK_BOUNDS_MAX
44         } m_block_bounds_mode = BLOCK_BOUNDS_OFF;
45
46         video::SColor crosshair_argb;
47         video::SColor selectionbox_argb;
48
49         bool use_crosshair_image = false;
50         bool use_object_crosshair_image = false;
51         std::string hotbar_image = "";
52         bool use_hotbar_image = false;
53         std::string hotbar_selected_image = "";
54         bool use_hotbar_selected_image = false;
55
56         bool pointing_at_object = false;
57
58         Hud(Client *client, LocalPlayer *player,
59                         Inventory *inventory);
60         ~Hud();
61
62         enum BlockBoundsMode toggleBlockBounds();
63         void disableBlockBounds();
64         void drawBlockBounds();
65
66         void drawHotbar(u16 playeritem);
67         void resizeHotbar();
68         void drawCrosshair();
69         void drawSelectionMesh();
70         void updateSelectionMesh(const v3s16 &camera_offset);
71
72         std::vector<aabb3f> *getSelectionBoxes() { return &m_selection_boxes; }
73
74         void setSelectionPos(const v3f &pos, const v3s16 &camera_offset);
75
76         v3f getSelectionPos() const { return m_selection_pos; }
77
78         void setSelectionMeshColor(const video::SColor &color)
79         {
80                 m_selection_mesh_color = color;
81         }
82
83         void setSelectedFaceNormal(const v3f &face_normal)
84         {
85                 m_selected_face_normal = face_normal;
86         }
87
88         bool hasElementOfType(HudElementType type);
89
90         void drawLuaElements(const v3s16 &camera_offset);
91
92 private:
93         bool calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos);
94         void drawStatbar(v2s32 pos, u16 corner, u16 drawdir,
95                         const std::string &texture, const std::string& bgtexture,
96                         s32 count, s32 maxcount, v2s32 offset, v2s32 size = v2s32());
97
98         void drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
99                         s32 inv_offset, InventoryList *mainlist, u16 selectitem,
100                         u16 direction);
101
102         void drawItem(const ItemStack &item, const core::rect<s32> &rect, bool selected);
103
104         void drawCompassTranslate(HudElement *e, video::ITexture *texture,
105                         const core::rect<s32> &rect, int way);
106
107         void drawCompassRotate(HudElement *e, video::ITexture *texture,
108                         const core::rect<s32> &rect, int way);
109
110         Client *client = nullptr;
111         video::IVideoDriver *driver = nullptr;
112         LocalPlayer *player = nullptr;
113         Inventory *inventory = nullptr;
114         ITextureSource *tsrc = nullptr;
115
116         float m_hud_scaling; // cached minetest setting
117         float m_scale_factor;
118         v3s16 m_camera_offset;
119         v2u32 m_screensize;
120         v2s32 m_displaycenter;
121         s32 m_hotbar_imagesize; // Takes hud_scaling into account, updated by resizeHotbar()
122         s32 m_padding; // Takes hud_scaling into account, updated by resizeHotbar()
123         video::SColor hbar_colors[4];
124
125         std::vector<aabb3f> m_selection_boxes;
126         std::vector<aabb3f> m_halo_boxes;
127         v3f m_selection_pos;
128         v3f m_selection_pos_with_offset;
129
130         scene::IMesh *m_selection_mesh = nullptr;
131         video::SColor m_selection_mesh_color;
132         v3f m_selected_face_normal;
133
134         video::SMaterial m_selection_material;
135
136         scene::SMeshBuffer m_rotation_mesh_buffer;
137
138         enum
139         {
140                 HIGHLIGHT_BOX,
141                 HIGHLIGHT_HALO,
142                 HIGHLIGHT_NONE
143         } m_mode;
144 };
145
146 enum ItemRotationKind
147 {
148         IT_ROT_SELECTED,
149         IT_ROT_HOVERED,
150         IT_ROT_DRAGGED,
151         IT_ROT_OTHER,
152         IT_ROT_NONE, // Must be last, also serves as number
153 };
154
155 void drawItemStack(video::IVideoDriver *driver,
156                 gui::IGUIFont *font,
157                 const ItemStack &item,
158                 const core::rect<s32> &rect,
159                 const core::rect<s32> *clip,
160                 Client *client,
161                 ItemRotationKind rotation_kind);
162
163 void drawItemStack(
164                 video::IVideoDriver *driver,
165                 gui::IGUIFont *font,
166                 const ItemStack &item,
167                 const core::rect<s32> &rect,
168                 const core::rect<s32> *clip,
169                 Client *client,
170                 ItemRotationKind rotation_kind,
171                 const v3s16 &angle,
172                 const v3s16 &rotation_speed);
173