]> git.lizzy.rs Git - minetest.git/blob - src/hud.h
c7289f7c4f79244b963f17cd6ef00266c3c960f0
[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
25 #define HUD_DIR_LEFT_RIGHT 0
26 #define HUD_DIR_RIGHT_LEFT 1
27 #define HUD_DIR_TOP_BOTTOM 2
28 #define HUD_DIR_BOTTOM_TOP 3
29
30 #define HUD_CORNER_UPPER  0
31 #define HUD_CORNER_LOWER  1
32 #define HUD_CORNER_CENTER 2
33
34 #define HUD_FLAG_HOTBAR_VISIBLE    (1 << 0)
35 #define HUD_FLAG_HEALTHBAR_VISIBLE (1 << 1)
36 #define HUD_FLAG_CROSSHAIR_VISIBLE (1 << 2)
37 #define HUD_FLAG_WIELDITEM_VISIBLE (1 << 3)
38 #define HUD_FLAG_BREATHBAR_VISIBLE (1 << 4)
39
40 #define HUD_PARAM_HOTBAR_ITEMCOUNT 1
41
42 #define HUD_HOTBAR_ITEMCOUNT_DEFAULT 8
43 #define HUD_HOTBAR_ITEMCOUNT_MAX     23
44
45 class Player;
46
47 enum HudElementType {
48         HUD_ELEM_IMAGE     = 0,
49         HUD_ELEM_TEXT      = 1,
50         HUD_ELEM_STATBAR   = 2,
51         HUD_ELEM_INVENTORY = 3
52 };
53
54 enum HudElementStat {
55         HUD_STAT_POS = 0,
56         HUD_STAT_NAME,
57         HUD_STAT_SCALE,
58         HUD_STAT_TEXT,
59         HUD_STAT_NUMBER,
60         HUD_STAT_ITEM,
61         HUD_STAT_DIR,
62         HUD_STAT_ALIGN,
63         HUD_STAT_OFFSET
64 };
65
66 struct HudElement {
67         HudElementType type;
68         v2f pos;
69         std::string name;
70         v2f scale;
71         std::string text;
72         u32 number;
73         u32 item;
74         u32 dir;
75         v2f align;
76         v2f offset;
77 };
78
79
80 inline u32 hud_get_free_id(Player *player) {
81         size_t size = player->hud.size();
82         for (size_t i = 0; i != size; i++) {
83                 if (!player->hud[i])
84                         return i;
85         }
86         return size;
87 }
88
89 #ifndef SERVER
90
91 #include <IGUIFont.h>
92
93 #include "gamedef.h"
94 #include "inventory.h"
95 #include "localplayer.h"
96
97 class Hud {
98 public:
99         video::IVideoDriver *driver;
100         gui::IGUIEnvironment *guienv;
101         gui::IGUIFont *font;
102         u32 text_height;
103         IGameDef *gamedef;
104         LocalPlayer *player;
105         Inventory *inventory;
106         ITextureSource *tsrc;
107
108         v2u32 screensize;
109         v2s32 displaycenter;
110         s32 hotbar_imagesize;
111         
112         video::SColor crosshair_argb;
113         video::SColor selectionbox_argb;
114         bool use_crosshair_image;
115         
116         Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv,
117                 gui::IGUIFont *font, u32 text_height, IGameDef *gamedef,
118                 LocalPlayer *player, Inventory *inventory);
119         
120         void drawItem(v2s32 upperleftpos, s32 imgsize, s32 itemcount,
121                 InventoryList *mainlist, u16 selectitem, u16 direction);
122         void drawLuaElements();
123         void drawStatbar(v2s32 pos, u16 corner, u16 drawdir,
124                                          std::string texture, s32 count, v2s32 offset);
125         
126         void drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem, s32 breath);
127         void resizeHotbar();
128         
129         void drawCrosshair();
130         void drawSelectionBoxes(std::vector<aabb3f> &hilightboxes);
131 };
132
133 #endif
134
135 #endif