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