hud.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef HUD_HEADER
  17. #define HUD_HEADER
  18. #include "irrlichttypes_extrabloated.h"
  19. #include <string>
  20. #define HUD_DIR_LEFT_RIGHT 0
  21. #define HUD_DIR_RIGHT_LEFT 1
  22. #define HUD_DIR_TOP_BOTTOM 2
  23. #define HUD_DIR_BOTTOM_TOP 3
  24. #define HUD_CORNER_UPPER 0
  25. #define HUD_CORNER_LOWER 1
  26. #define HUD_CORNER_CENTER 2
  27. // Note that these visibility flags do not determine if the hud items are
  28. // actually drawn, but rather, whether to draw the item should the rest
  29. // of the game state permit it.
  30. #define HUD_FLAG_HOTBAR_VISIBLE (1 << 0)
  31. #define HUD_FLAG_HEALTHBAR_VISIBLE (1 << 1)
  32. #define HUD_FLAG_CROSSHAIR_VISIBLE (1 << 2)
  33. #define HUD_FLAG_WIELDITEM_VISIBLE (1 << 3)
  34. #define HUD_FLAG_BREATHBAR_VISIBLE (1 << 4)
  35. #define HUD_FLAG_MINIMAP_VISIBLE (1 << 5)
  36. #define HUD_PARAM_HOTBAR_ITEMCOUNT 1
  37. #define HUD_PARAM_HOTBAR_IMAGE 2
  38. #define HUD_PARAM_HOTBAR_SELECTED_IMAGE 3
  39. #define HUD_HOTBAR_ITEMCOUNT_DEFAULT 8
  40. #define HUD_HOTBAR_ITEMCOUNT_MAX 23
  41. #define HOTBAR_IMAGE_SIZE 48
  42. enum HudElementType {
  43. HUD_ELEM_IMAGE = 0,
  44. HUD_ELEM_TEXT = 1,
  45. HUD_ELEM_STATBAR = 2,
  46. HUD_ELEM_INVENTORY = 3,
  47. HUD_ELEM_WAYPOINT = 4,
  48. };
  49. enum HudElementStat {
  50. HUD_STAT_POS = 0,
  51. HUD_STAT_NAME,
  52. HUD_STAT_SCALE,
  53. HUD_STAT_TEXT,
  54. HUD_STAT_NUMBER,
  55. HUD_STAT_ITEM,
  56. HUD_STAT_DIR,
  57. HUD_STAT_ALIGN,
  58. HUD_STAT_OFFSET,
  59. HUD_STAT_WORLD_POS,
  60. HUD_STAT_SIZE
  61. };
  62. struct HudElement {
  63. HudElementType type;
  64. v2f pos;
  65. std::string name;
  66. v2f scale;
  67. std::string text;
  68. u32 number;
  69. u32 item;
  70. u32 dir;
  71. v2f align;
  72. v2f offset;
  73. v3f world_pos;
  74. v2s32 size;
  75. };
  76. #ifndef SERVER
  77. #include <vector>
  78. #include <IGUIFont.h>
  79. #include "irr_aabb3d.h"
  80. class Client;
  81. class ITextureSource;
  82. class Inventory;
  83. class InventoryList;
  84. class LocalPlayer;
  85. struct ItemStack;
  86. class Hud {
  87. public:
  88. video::IVideoDriver *driver;
  89. scene::ISceneManager* smgr;
  90. gui::IGUIEnvironment *guienv;
  91. Client *client;
  92. LocalPlayer *player;
  93. Inventory *inventory;
  94. ITextureSource *tsrc;
  95. video::SColor crosshair_argb;
  96. video::SColor selectionbox_argb;
  97. bool use_crosshair_image = false;
  98. std::string hotbar_image = "";
  99. bool use_hotbar_image = false;
  100. std::string hotbar_selected_image = "";
  101. bool use_hotbar_selected_image;
  102. Hud(video::IVideoDriver *driver,scene::ISceneManager* smgr,
  103. gui::IGUIEnvironment* guienv, Client *client, LocalPlayer *player,
  104. Inventory *inventory);
  105. ~Hud();
  106. void drawHotbar(u16 playeritem);
  107. void resizeHotbar();
  108. void drawCrosshair();
  109. void drawSelectionMesh();
  110. void updateSelectionMesh(const v3s16 &camera_offset);
  111. std::vector<aabb3f> *getSelectionBoxes()
  112. { return &m_selection_boxes; }
  113. void setSelectionPos(const v3f &pos, const v3s16 &camera_offset);
  114. v3f getSelectionPos() const
  115. { return m_selection_pos; }
  116. void setSelectionMeshColor(const video::SColor &color)
  117. { m_selection_mesh_color = color; }
  118. void setSelectedFaceNormal(const v3f &face_normal)
  119. { m_selected_face_normal = face_normal; }
  120. void drawLuaElements(const v3s16 &camera_offset);
  121. private:
  122. void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
  123. s32 count, v2s32 offset, v2s32 size=v2s32());
  124. void drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
  125. s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction);
  126. void drawItem(const ItemStack &item, const core::rect<s32>& rect,
  127. bool selected);
  128. float m_hud_scaling; // cached minetest setting
  129. v3s16 m_camera_offset;
  130. v2u32 m_screensize;
  131. v2s32 m_displaycenter;
  132. s32 m_hotbar_imagesize; // Takes hud_scaling into account, updated by resizeHotbar()
  133. s32 m_padding; // Takes hud_scaling into account, updated by resizeHotbar()
  134. video::SColor hbar_colors[4];
  135. std::vector<aabb3f> m_selection_boxes;
  136. std::vector<aabb3f> m_halo_boxes;
  137. v3f m_selection_pos;
  138. v3f m_selection_pos_with_offset;
  139. scene::IMesh *m_selection_mesh = nullptr;
  140. video::SColor m_selection_mesh_color;
  141. v3f m_selected_face_normal;
  142. video::SMaterial m_selection_material;
  143. enum {
  144. HIGHLIGHT_BOX,
  145. HIGHLIGHT_HALO,
  146. HIGHLIGHT_NONE } m_mode;
  147. };
  148. enum ItemRotationKind {
  149. IT_ROT_SELECTED,
  150. IT_ROT_HOVERED,
  151. IT_ROT_DRAGGED,
  152. IT_ROT_NONE, // Must be last, also serves as number
  153. };
  154. void drawItemStack(video::IVideoDriver *driver,
  155. gui::IGUIFont *font,
  156. const ItemStack &item,
  157. const core::rect<s32> &rect,
  158. const core::rect<s32> *clip,
  159. Client *client,
  160. ItemRotationKind rotation_kind);
  161. #endif
  162. #endif