1 /* 2 hud.h 3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net> 4 */ 5 6 /* 7 This file is part of Freeminer. 8 9 Freeminer is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Freeminer is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Freeminer. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 #ifndef HUD_HEADER 24 #define HUD_HEADER 25 26 #include "irrlichttypes_extrabloated.h" 27 #include <string> 28 29 #define HUD_DIR_LEFT_RIGHT 0 30 #define HUD_DIR_RIGHT_LEFT 1 31 #define HUD_DIR_TOP_BOTTOM 2 32 #define HUD_DIR_BOTTOM_TOP 3 33 34 #define HUD_CORNER_UPPER 0 35 #define HUD_CORNER_LOWER 1 36 #define HUD_CORNER_CENTER 2 37 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 44 #define HUD_PARAM_HOTBAR_ITEMCOUNT 1 45 #define HUD_PARAM_HOTBAR_IMAGE 2 46 #define HUD_PARAM_HOTBAR_SELECTED_IMAGE 3 47 48 #define HUD_HOTBAR_ITEMCOUNT_DEFAULT 8 49 #define HUD_HOTBAR_ITEMCOUNT_MAX 23 50 51 52 #define HOTBAR_IMAGE_SIZE 48 53 54 enum HudElementType { 55 HUD_ELEM_IMAGE = 0, 56 HUD_ELEM_TEXT = 1, 57 HUD_ELEM_STATBAR = 2, 58 HUD_ELEM_INVENTORY = 3, 59 HUD_ELEM_WAYPOINT = 4, 60 }; 61 62 enum HudElementStat { 63 HUD_STAT_POS = 0, 64 HUD_STAT_NAME, 65 HUD_STAT_SCALE, 66 HUD_STAT_TEXT, 67 HUD_STAT_NUMBER, 68 HUD_STAT_ITEM, 69 HUD_STAT_DIR, 70 HUD_STAT_ALIGN, 71 HUD_STAT_OFFSET, 72 HUD_STAT_WORLD_POS, 73 HUD_STAT_SIZE 74 }; 75 76 struct HudElement { 77 HudElementType type; 78 v2f pos; 79 std::string name; 80 v2f scale; 81 std::string text; 82 u32 number; 83 u32 item; 84 u32 dir; 85 v2f align; 86 v2f offset; 87 v3f world_pos; 88 v2s32 size; 89 }; 90 91 #ifndef SERVER 92 93 #include <vector> 94 #include <IGUIFont.h> 95 #include "irr_aabb3d.h" 96 97 class IGameDef; 98 class ITextureSource; 99 class Inventory; 100 class InventoryList; 101 class LocalPlayer; 102 struct ItemStack; 103 104 class Hud { 105 public: 106 video::IVideoDriver *driver; 107 scene::ISceneManager* smgr; 108 gui::IGUIEnvironment *guienv; 109 gui::IGUIFont *font; 110 u32 text_height; 111 IGameDef *gamedef; 112 LocalPlayer *player; 113 Inventory *inventory; 114 ITextureSource *tsrc; 115 116 video::SColor crosshair_argb; 117 video::SColor selectionbox_argb; 118 bool use_crosshair_image; 119 std::string hotbar_image; 120 bool use_hotbar_image; 121 std::string hotbar_selected_image; 122 bool use_hotbar_selected_image; 123 v3s16 camera_offset; 124 125 Hud(video::IVideoDriver *driver,scene::ISceneManager* smgr, 126 gui::IGUIEnvironment* guienv, gui::IGUIFont *font, 127 u32 text_height, IGameDef *gamedef, 128 LocalPlayer *player, Inventory *inventory); 129 130 void drawHotbar(u16 playeritem); 131 void resizeHotbar(); 132 void drawCrosshair(); 133 void drawSelectionBoxes(std::vector<aabb3f> &hilightboxes); 134 void drawLuaElements(v3s16 camera_offset); 135 private: 136 void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, 137 s32 count, v2s32 offset, v2s32 size=v2s32()); 138 139 void drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset, 140 InventoryList *mainlist, u16 selectitem, u16 direction); 141 142 void drawItem(const ItemStack &item, const core::rect<s32>& rect, bool selected); 143 144 v2u32 m_screensize; 145 v2s32 m_displaycenter; 146 s32 m_hotbar_imagesize; 147 s32 m_padding; 148 video::SColor hbar_colors[4]; 149 }; 150 151 void drawItemStack(video::IVideoDriver *driver, 152 gui::IGUIFont *font, 153 const ItemStack &item, 154 const core::rect<s32> &rect, 155 const core::rect<s32> *clip, 156 IGameDef *gamedef); 157 158 159 #endif 160 161 #endif 162