hud.h 3.7 KB

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