Minetest  5.4.0
hud.h
Go to the documentation of this file.
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  video::IVideoDriver *driver;
39  scene::ISceneManager *smgr;
40  gui::IGUIEnvironment *guienv;
45 
46  video::SColor crosshair_argb;
47  video::SColor selectionbox_argb;
48 
49  bool use_crosshair_image = false;
51  std::string hotbar_image = "";
52  bool use_hotbar_image = false;
53  std::string hotbar_selected_image = "";
55 
56  bool pointing_at_object = false;
57 
58  Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
60  ~Hud();
61 
62  void drawHotbar(u16 playeritem);
63  void resizeHotbar();
64  void drawCrosshair();
65  void drawSelectionMesh();
66  void updateSelectionMesh(const v3s16 &camera_offset);
67 
68  std::vector<aabb3f> *getSelectionBoxes() { return &m_selection_boxes; }
69 
70  void setSelectionPos(const v3f &pos, const v3s16 &camera_offset);
71 
72  v3f getSelectionPos() const { return m_selection_pos; }
73 
74  void setSelectionMeshColor(const video::SColor &color)
75  {
76  m_selection_mesh_color = color;
77  }
78 
79  void setSelectedFaceNormal(const v3f &face_normal)
80  {
81  m_selected_face_normal = face_normal;
82  }
83 
85 
86  void drawLuaElements(const v3s16 &camera_offset);
87 
88 private:
89  bool calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos);
90  void drawStatbar(v2s32 pos, u16 corner, u16 drawdir,
91  const std::string &texture, const std::string& bgtexture,
92  s32 count, s32 maxcount, v2s32 offset, v2s32 size = v2s32());
93 
94  void drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
95  s32 inv_offset, InventoryList *mainlist, u16 selectitem,
96  u16 direction);
97 
98  void drawItem(const ItemStack &item, const core::rect<s32> &rect, bool selected);
99 
100  void drawCompassTranslate(HudElement *e, video::ITexture *texture,
101  const core::rect<s32> &rect, int way);
102 
103  void drawCompassRotate(HudElement *e, video::ITexture *texture,
104  const core::rect<s32> &rect, int way);
105 
106  float m_hud_scaling; // cached minetest setting
111  s32 m_hotbar_imagesize; // Takes hud_scaling into account, updated by resizeHotbar()
112  s32 m_padding; // Takes hud_scaling into account, updated by resizeHotbar()
113  video::SColor hbar_colors[4];
114 
115  std::vector<aabb3f> m_selection_boxes;
116  std::vector<aabb3f> m_halo_boxes;
119 
120  scene::IMesh *m_selection_mesh = nullptr;
121  video::SColor m_selection_mesh_color;
123 
124  video::SMaterial m_selection_material;
125 
126  scene::SMeshBuffer m_rotation_mesh_buffer;
127 
128  enum
129  {
134 };
135 
137 {
142  IT_ROT_NONE, // Must be last, also serves as number
143 };
144 
145 void drawItemStack(video::IVideoDriver *driver,
146  gui::IGUIFont *font,
147  const ItemStack &item,
148  const core::rect<s32> &rect,
149  const core::rect<s32> *clip,
150  Client *client,
151  ItemRotationKind rotation_kind);
152 
153 void drawItemStack(
154  video::IVideoDriver *driver,
155  gui::IGUIFont *font,
156  const ItemStack &item,
157  const core::rect<s32> &rect,
158  const core::rect<s32> *clip,
159  Client *client,
160  ItemRotationKind rotation_kind,
161  const v3s16 &angle,
162  const v3s16 &rotation_speed);
163 
Definition: client.h:109
Definition: hud.h:36
video::SColor m_selection_mesh_color
Definition: hud.h:121
scene::ISceneManager * smgr
Definition: hud.h:39
Client * client
Definition: hud.h:41
bool hasElementOfType(HudElementType type)
Definition: hud.cpp:301
scene::IMesh * m_selection_mesh
Definition: hud.h:120
void drawSelectionMesh()
Definition: hud.cpp:822
ITextureSource * tsrc
Definition: hud.h:44
~Hud()
Definition: hud.cpp:142
scene::SMeshBuffer m_rotation_mesh_buffer
Definition: hud.h:126
bool pointing_at_object
Definition: hud.h:56
v3f m_selected_face_normal
Definition: hud.h:122
video::IVideoDriver * driver
Definition: hud.h:38
void setSelectionMeshColor(const video::SColor &color)
Definition: hud.h:74
std::vector< aabb3f > m_selection_boxes
Definition: hud.h:115
void drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount, s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction)
Definition: hud.cpp:226
v3f m_selection_pos
Definition: hud.h:117
bool calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos)
Definition: hud.cpp:314
void drawItem(const ItemStack &item, const core::rect< s32 > &rect, bool selected)
Definition: hud.cpp:148
v2s32 m_displaycenter
Definition: hud.h:110
bool use_crosshair_image
Definition: hud.h:49
void setSelectionPos(const v3f &pos, const v3s16 &camera_offset)
Definition: hud.cpp:815
Inventory * inventory
Definition: hud.h:43
void drawLuaElements(const v3s16 &camera_offset)
Definition: hud.cpp:333
s32 m_hotbar_imagesize
Definition: hud.h:111
void drawCrosshair()
Definition: hud.cpp:772
bool use_object_crosshair_image
Definition: hud.h:50
video::SColor crosshair_argb
Definition: hud.h:46
float m_scale_factor
Definition: hud.h:107
void resizeHotbar()
Definition: hud.cpp:910
void drawHotbar(u16 playeritem)
Definition: hud.cpp:736
v3s16 m_camera_offset
Definition: hud.h:108
void drawCompassTranslate(HudElement *e, video::ITexture *texture, const core::rect< s32 > &rect, int way)
Definition: hud.cpp:531
v2u32 m_screensize
Definition: hud.h:109
video::SColor selectionbox_argb
Definition: hud.h:47
bool use_hotbar_image
Definition: hud.h:52
void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, const std::string &texture, const std::string &bgtexture, s32 count, s32 maxcount, v2s32 offset, v2s32 size=v2s32())
Definition: hud.cpp:600
void updateSelectionMesh(const v3s16 &camera_offset)
Definition: hud.cpp:865
void setSelectedFaceNormal(const v3f &face_normal)
Definition: hud.h:79
std::string hotbar_selected_image
Definition: hud.h:53
@ HIGHLIGHT_NONE
Definition: hud.h:132
@ HIGHLIGHT_BOX
Definition: hud.h:130
@ HIGHLIGHT_HALO
Definition: hud.h:131
std::vector< aabb3f > * getSelectionBoxes()
Definition: hud.h:68
LocalPlayer * player
Definition: hud.h:42
enum Hud::@16 m_mode
void drawCompassRotate(HudElement *e, video::ITexture *texture, const core::rect< s32 > &rect, int way)
Definition: hud.cpp:571
video::SMaterial m_selection_material
Definition: hud.h:124
gui::IGUIEnvironment * guienv
Definition: hud.h:40
std::string hotbar_image
Definition: hud.h:51
video::SColor hbar_colors[4]
Definition: hud.h:113
float m_hud_scaling
Definition: hud.h:106
Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player, Inventory *inventory)
Definition: hud.cpp:48
s32 m_padding
Definition: hud.h:112
bool use_hotbar_selected_image
Definition: hud.h:54
v3f getSelectionPos() const
Definition: hud.h:72
v3f m_selection_pos_with_offset
Definition: hud.h:118
std::vector< aabb3f > m_halo_boxes
Definition: hud.h:116
Definition: tile.h:86
Definition: inventory.h:190
Definition: inventory.h:282
Definition: localplayer.h:45
void drawItemStack(video::IVideoDriver *driver, gui::IGUIFont *font, const ItemStack &item, const core::rect< s32 > &rect, const core::rect< s32 > *clip, Client *client, ItemRotationKind rotation_kind)
Definition: hud.cpp:1116
ItemRotationKind
Definition: hud.h:137
@ IT_ROT_OTHER
Definition: hud.h:141
@ IT_ROT_NONE
Definition: hud.h:142
@ IT_ROT_HOVERED
Definition: hud.h:139
@ IT_ROT_DRAGGED
Definition: hud.h:140
@ IT_ROT_SELECTED
Definition: hud.h:138
HudElementType
Definition: hud.h:56
core::vector2d< s32 > v2s32
Definition: irr_v2d.h:28
core::vector2d< u32 > v2u32
Definition: irr_v2d.h:29
core::vector3d< s16 > v3s16
Definition: irr_v3d.h:28
core::vector3df v3f
Definition: irr_v3d.h:26
Definition: activeobjectmgr.cpp:25
u8 direction
Definition: voxelalgorithms.cpp:39
Definition: hud.h:90
Definition: inventory.h:34