]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/hud.h
Improve waypoints and add image variant (#9480)
[dragonfireclient.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 #ifndef CLIENT_HUD_HEADER
22 #define CLIENT_HUD_HEADER
23
24 #include <vector>
25 #include <IGUIFont.h>
26 #include "irr_aabb3d.h"
27 #include "../hud.h"
28
29 class Client;
30 class ITextureSource;
31 class Inventory;
32 class InventoryList;
33 class LocalPlayer;
34 struct ItemStack;
35
36 class Hud
37 {
38 public:
39         video::IVideoDriver *driver;
40         scene::ISceneManager *smgr;
41         gui::IGUIEnvironment *guienv;
42         Client *client;
43         LocalPlayer *player;
44         Inventory *inventory;
45         ITextureSource *tsrc;
46
47         video::SColor crosshair_argb;
48         video::SColor selectionbox_argb;
49         bool use_crosshair_image = false;
50         std::string hotbar_image = "";
51         bool use_hotbar_image = false;
52         std::string hotbar_selected_image = "";
53         bool use_hotbar_selected_image = false;
54
55         Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
56                         Inventory *inventory);
57         ~Hud();
58
59         void drawHotbar(u16 playeritem);
60         void resizeHotbar();
61         void drawCrosshair();
62         void drawSelectionMesh();
63         void updateSelectionMesh(const v3s16 &camera_offset);
64
65         std::vector<aabb3f> *getSelectionBoxes() { return &m_selection_boxes; }
66
67         void setSelectionPos(const v3f &pos, const v3s16 &camera_offset);
68
69         v3f getSelectionPos() const { return m_selection_pos; }
70
71         void setSelectionMeshColor(const video::SColor &color)
72         {
73                 m_selection_mesh_color = color;
74         }
75
76         void setSelectedFaceNormal(const v3f &face_normal)
77         {
78                 m_selected_face_normal = face_normal;
79         }
80
81         void drawLuaElements(const v3s16 &camera_offset);
82
83 private:
84         bool calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos);
85         void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, const std::string &texture,
86                         s32 count, v2s32 offset, v2s32 size = v2s32());
87
88         void drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
89                         s32 inv_offset, InventoryList *mainlist, u16 selectitem,
90                         u16 direction);
91
92         void drawItem(const ItemStack &item, const core::rect<s32> &rect, bool selected);
93
94         float m_hud_scaling; // cached minetest setting
95         v3s16 m_camera_offset;
96         v2u32 m_screensize;
97         v2s32 m_displaycenter;
98         s32 m_hotbar_imagesize; // Takes hud_scaling into account, updated by resizeHotbar()
99         s32 m_padding; // Takes hud_scaling into account, updated by resizeHotbar()
100         video::SColor hbar_colors[4];
101
102         std::vector<aabb3f> m_selection_boxes;
103         std::vector<aabb3f> m_halo_boxes;
104         v3f m_selection_pos;
105         v3f m_selection_pos_with_offset;
106
107         scene::IMesh *m_selection_mesh = nullptr;
108         video::SColor m_selection_mesh_color;
109         v3f m_selected_face_normal;
110
111         video::SMaterial m_selection_material;
112
113         enum
114         {
115                 HIGHLIGHT_BOX,
116                 HIGHLIGHT_HALO,
117                 HIGHLIGHT_NONE
118         } m_mode;
119 };
120
121 enum ItemRotationKind
122 {
123         IT_ROT_SELECTED,
124         IT_ROT_HOVERED,
125         IT_ROT_DRAGGED,
126         IT_ROT_OTHER,
127         IT_ROT_NONE, // Must be last, also serves as number
128 };
129
130 void drawItemStack(video::IVideoDriver *driver,
131                 gui::IGUIFont *font,
132                 const ItemStack &item,
133                 const core::rect<s32> &rect,
134                 const core::rect<s32> *clip,
135                 Client *client,
136                 ItemRotationKind rotation_kind);
137
138 void drawItemStack(
139                 video::IVideoDriver *driver,
140                 gui::IGUIFont *font,
141                 const ItemStack &item,
142                 const core::rect<s32> &rect,
143                 const core::rect<s32> *clip,
144                 Client *client,
145                 ItemRotationKind rotation_kind,
146                 const v3s16 &angle,
147                 const v3s16 &rotation_speed);
148
149 #endif