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