hud.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
  4. Copyright (C) 2017 red-001 <red-001@outlook.ie>
  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. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #ifndef CLIENT_HUD_HEADER
  18. #define CLIENT_HUD_HEADER
  19. #include <vector>
  20. #include <IGUIFont.h>
  21. #include "irr_aabb3d.h"
  22. #include "../hud.h"
  23. class Client;
  24. class ITextureSource;
  25. class Inventory;
  26. class InventoryList;
  27. class LocalPlayer;
  28. struct ItemStack;
  29. class Hud
  30. {
  31. public:
  32. video::IVideoDriver *driver;
  33. scene::ISceneManager *smgr;
  34. gui::IGUIEnvironment *guienv;
  35. Client *client;
  36. LocalPlayer *player;
  37. Inventory *inventory;
  38. ITextureSource *tsrc;
  39. video::SColor crosshair_argb;
  40. video::SColor selectionbox_argb;
  41. bool use_crosshair_image = false;
  42. std::string hotbar_image = "";
  43. bool use_hotbar_image = false;
  44. std::string hotbar_selected_image = "";
  45. bool use_hotbar_selected_image = false;
  46. Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
  47. Inventory *inventory);
  48. ~Hud();
  49. void drawHotbar(u16 playeritem);
  50. void resizeHotbar();
  51. void drawCrosshair();
  52. void drawSelectionMesh();
  53. void updateSelectionMesh(const v3s16 &camera_offset);
  54. std::vector<aabb3f> *getSelectionBoxes() { return &m_selection_boxes; }
  55. void setSelectionPos(const v3f &pos, const v3s16 &camera_offset);
  56. v3f getSelectionPos() const { return m_selection_pos; }
  57. void setSelectionMeshColor(const video::SColor &color)
  58. {
  59. m_selection_mesh_color = color;
  60. }
  61. void setSelectedFaceNormal(const v3f &face_normal)
  62. {
  63. m_selected_face_normal = face_normal;
  64. }
  65. void drawLuaElements(const v3s16 &camera_offset);
  66. private:
  67. void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, const std::string &texture,
  68. s32 count, v2s32 offset, v2s32 size = v2s32());
  69. void drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
  70. s32 inv_offset, InventoryList *mainlist, u16 selectitem,
  71. u16 direction);
  72. void drawItem(const ItemStack &item, const core::rect<s32> &rect, bool selected);
  73. float m_hud_scaling; // cached minetest setting
  74. v3s16 m_camera_offset;
  75. v2u32 m_screensize;
  76. v2s32 m_displaycenter;
  77. s32 m_hotbar_imagesize; // Takes hud_scaling into account, updated by resizeHotbar()
  78. s32 m_padding; // Takes hud_scaling into account, updated by resizeHotbar()
  79. video::SColor hbar_colors[4];
  80. std::vector<aabb3f> m_selection_boxes;
  81. std::vector<aabb3f> m_halo_boxes;
  82. v3f m_selection_pos;
  83. v3f m_selection_pos_with_offset;
  84. scene::IMesh *m_selection_mesh = nullptr;
  85. video::SColor m_selection_mesh_color;
  86. v3f m_selected_face_normal;
  87. video::SMaterial m_selection_material;
  88. enum
  89. {
  90. HIGHLIGHT_BOX,
  91. HIGHLIGHT_HALO,
  92. HIGHLIGHT_NONE
  93. } m_mode;
  94. };
  95. enum ItemRotationKind
  96. {
  97. IT_ROT_SELECTED,
  98. IT_ROT_HOVERED,
  99. IT_ROT_DRAGGED,
  100. IT_ROT_OTHER,
  101. IT_ROT_NONE, // Must be last, also serves as number
  102. };
  103. void drawItemStack(video::IVideoDriver *driver,
  104. gui::IGUIFont *font,
  105. const ItemStack &item,
  106. const core::rect<s32> &rect,
  107. const core::rect<s32> *clip,
  108. Client *client,
  109. ItemRotationKind rotation_kind);
  110. void drawItemStack(
  111. video::IVideoDriver *driver,
  112. gui::IGUIFont *font,
  113. const ItemStack &item,
  114. const core::rect<s32> &rect,
  115. const core::rect<s32> *clip,
  116. Client *client,
  117. ItemRotationKind rotation_kind,
  118. const v3s16 &angle,
  119. const v3s16 &rotation_speed);
  120. #endif