3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
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.
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.
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.
23 #include "irrlichttypes_extrabloated.h"
26 #define HUD_DIR_LEFT_RIGHT 0
27 #define HUD_DIR_RIGHT_LEFT 1
28 #define HUD_DIR_TOP_BOTTOM 2
29 #define HUD_DIR_BOTTOM_TOP 3
31 #define HUD_CORNER_UPPER 0
32 #define HUD_CORNER_LOWER 1
33 #define HUD_CORNER_CENTER 2
35 // Note that these visibility flags do not determine if the hud items are
36 // actually drawn, but rather, whether to draw the item should the rest
37 // of the game state permit it.
38 #define HUD_FLAG_HOTBAR_VISIBLE (1 << 0)
39 #define HUD_FLAG_HEALTHBAR_VISIBLE (1 << 1)
40 #define HUD_FLAG_CROSSHAIR_VISIBLE (1 << 2)
41 #define HUD_FLAG_WIELDITEM_VISIBLE (1 << 3)
42 #define HUD_FLAG_BREATHBAR_VISIBLE (1 << 4)
43 #define HUD_FLAG_MINIMAP_VISIBLE (1 << 5)
45 #define HUD_PARAM_HOTBAR_ITEMCOUNT 1
46 #define HUD_PARAM_HOTBAR_IMAGE 2
47 #define HUD_PARAM_HOTBAR_SELECTED_IMAGE 3
49 #define HUD_HOTBAR_ITEMCOUNT_DEFAULT 8
50 #define HUD_HOTBAR_ITEMCOUNT_MAX 23
53 #define HOTBAR_IMAGE_SIZE 48
59 HUD_ELEM_INVENTORY = 3,
60 HUD_ELEM_WAYPOINT = 4,
96 #include "irr_aabb3d.h"
107 video::IVideoDriver *driver;
108 scene::ISceneManager* smgr;
109 gui::IGUIEnvironment *guienv;
112 Inventory *inventory;
113 ITextureSource *tsrc;
115 video::SColor crosshair_argb;
116 video::SColor selectionbox_argb;
117 bool use_crosshair_image;
118 std::string hotbar_image;
119 bool use_hotbar_image;
120 std::string hotbar_selected_image;
121 bool use_hotbar_selected_image;
123 Hud(video::IVideoDriver *driver,scene::ISceneManager* smgr,
124 gui::IGUIEnvironment* guienv, Client *client, LocalPlayer *player,
125 Inventory *inventory);
128 void drawHotbar(u16 playeritem);
130 void drawCrosshair();
131 void drawSelectionMesh();
132 void updateSelectionMesh(const v3s16 &camera_offset);
134 std::vector<aabb3f> *getSelectionBoxes()
135 { return &m_selection_boxes; }
137 void setSelectionPos(const v3f &pos, const v3s16 &camera_offset);
139 v3f getSelectionPos() const
140 { return m_selection_pos; }
142 void setSelectionMeshColor(const video::SColor &color)
143 { m_selection_mesh_color = color; }
145 void setSelectedFaceNormal(const v3f &face_normal)
146 { m_selected_face_normal = face_normal; }
148 void drawLuaElements(const v3s16 &camera_offset);
151 void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
152 s32 count, v2s32 offset, v2s32 size=v2s32());
154 void drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
155 s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction);
157 void drawItem(const ItemStack &item, const core::rect<s32>& rect,
160 float m_hud_scaling; // cached minetest setting
161 v3s16 m_camera_offset;
163 v2s32 m_displaycenter;
164 s32 m_hotbar_imagesize; // Takes hud_scaling into account, updated by resizeHotbar()
165 s32 m_padding; // Takes hud_scaling into account, updated by resizeHotbar()
166 video::SColor hbar_colors[4];
168 std::vector<aabb3f> m_selection_boxes;
169 std::vector<aabb3f> m_halo_boxes;
171 v3f m_selection_pos_with_offset;
173 scene::IMesh* m_selection_mesh;
174 video::SColor m_selection_mesh_color;
175 v3f m_selected_face_normal;
177 video::SMaterial m_selection_material;
178 bool m_use_selection_mesh;
181 enum ItemRotationKind {
185 IT_ROT_NONE, // Must be last, also serves as number
188 void drawItemStack(video::IVideoDriver *driver,
190 const ItemStack &item,
191 const core::rect<s32> &rect,
192 const core::rect<s32> *clip,
194 ItemRotationKind rotation_kind);