Hide minimap if it has been disabled by server
[oweals/minetest.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 #ifndef HUD_HEADER
21 #define HUD_HEADER
22
23 #include "irrlichttypes_extrabloated.h"
24 #include <string>
25
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
30
31 #define HUD_CORNER_UPPER  0
32 #define HUD_CORNER_LOWER  1
33 #define HUD_CORNER_CENTER 2
34
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)
44
45 #define HUD_PARAM_HOTBAR_ITEMCOUNT 1
46 #define HUD_PARAM_HOTBAR_IMAGE 2
47 #define HUD_PARAM_HOTBAR_SELECTED_IMAGE 3
48
49 #define HUD_HOTBAR_ITEMCOUNT_DEFAULT 8
50 #define HUD_HOTBAR_ITEMCOUNT_MAX     23
51
52
53 #define HOTBAR_IMAGE_SIZE 48
54
55 enum HudElementType {
56         HUD_ELEM_IMAGE     = 0,
57         HUD_ELEM_TEXT      = 1,
58         HUD_ELEM_STATBAR   = 2,
59         HUD_ELEM_INVENTORY = 3,
60         HUD_ELEM_WAYPOINT  = 4,
61 };
62
63 enum HudElementStat {
64         HUD_STAT_POS = 0,
65         HUD_STAT_NAME,
66         HUD_STAT_SCALE,
67         HUD_STAT_TEXT,
68         HUD_STAT_NUMBER,
69         HUD_STAT_ITEM,
70         HUD_STAT_DIR,
71         HUD_STAT_ALIGN,
72         HUD_STAT_OFFSET,
73         HUD_STAT_WORLD_POS,
74         HUD_STAT_SIZE
75 };
76
77 struct HudElement {
78         HudElementType type;
79         v2f pos;
80         std::string name;
81         v2f scale;
82         std::string text;
83         u32 number;
84         u32 item;
85         u32 dir;
86         v2f align;
87         v2f offset;
88         v3f world_pos;
89         v2s32 size;
90 };
91
92 #ifndef SERVER
93
94 #include <vector>
95 #include <IGUIFont.h>
96 #include "irr_aabb3d.h"
97
98 class IGameDef;
99 class ITextureSource;
100 class Inventory;
101 class InventoryList;
102 class LocalPlayer;
103 struct ItemStack;
104
105 class Hud {
106 public:
107         video::IVideoDriver *driver;
108         scene::ISceneManager* smgr;
109         gui::IGUIEnvironment *guienv;
110         IGameDef *gamedef;
111         LocalPlayer *player;
112         Inventory *inventory;
113         ITextureSource *tsrc;
114
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;
122         v3s16 camera_offset;
123
124         Hud(video::IVideoDriver *driver,scene::ISceneManager* smgr,
125                 gui::IGUIEnvironment* guienv, IGameDef *gamedef, LocalPlayer *player,
126                 Inventory *inventory);
127
128         void drawHotbar(u16 playeritem);
129         void resizeHotbar();
130         void drawCrosshair();
131         void drawSelectionBoxes(std::vector<aabb3f> &hilightboxes);
132         void drawLuaElements(v3s16 camera_offset);
133 private:
134         void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
135                         s32 count, v2s32 offset, v2s32 size=v2s32());
136
137         void drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
138                 InventoryList *mainlist, u16 selectitem, u16 direction);
139
140         void drawItem(const ItemStack &item, const core::rect<s32>& rect, bool selected);
141
142         v2u32 m_screensize;
143         v2s32 m_displaycenter;
144         s32 m_hotbar_imagesize;
145         s32 m_padding;
146         video::SColor hbar_colors[4];
147 };
148
149 void drawItemStack(video::IVideoDriver *driver,
150                 gui::IGUIFont *font,
151                 const ItemStack &item,
152                 const core::rect<s32> &rect,
153                 const core::rect<s32> *clip,
154                 IGameDef *gamedef);
155
156
157 #endif
158
159 #endif