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