UiEngine.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #pragma once
  2. #include "glm/vec4.hpp"
  3. #include "glm/vec2.hpp"
  4. #include <glui/glui.h>
  5. #include <gameplay/effects.h>
  6. #include <optional>
  7. struct PlayerInventory;
  8. struct BlocksLoader;
  9. struct Item;
  10. struct CraftingTableInventory;
  11. struct Life;
  12. struct ProgramData;
  13. struct LocalPlayer;
  14. struct BaseBlock;
  15. struct ChunkSystem;
  16. struct UndoQueue;
  17. struct LightSystem;
  18. struct ClientEntityManager;
  19. struct ChestBlock;
  20. const int INVENTORY_TAB_DEFAULT = 0;
  21. const int INVENTORY_TAB_CRAFTING = 1;
  22. const int INVENTORY_TAB_CHEST = 2;
  23. const int INVENTORY_TAB_BLOCKS = 3;
  24. const int INVENTORY_TAB_ITEMS = 4;
  25. struct UiENgine
  26. {
  27. gl2d::Renderer2D renderer2d;
  28. glui::RendererUi menuRenderer;
  29. void init();
  30. void loadTextures(std::string path);
  31. void clearOnlyTextures();
  32. gl2d::TextureAtlas uiAtlas{6, 1};
  33. gl2d::Font font;
  34. gl2d::Texture uiTexture;
  35. gl2d::Texture buttonTexture;
  36. gl2d::Texture coinIconTexture;
  37. gl2d::Texture arrowIconTexture;
  38. gl2d::Texture bootsIconTexture;
  39. gl2d::Texture chestPlateIconTexture;
  40. gl2d::Texture helmetIconTexture;
  41. gl2d::Texture potionIconTexture;
  42. gl2d::Texture itemsBar;
  43. gl2d::Texture itemsHighlighter;
  44. gl2d::Texture itemsBarInventory;
  45. gl2d::Texture oneInventorySlot;
  46. gl2d::Texture arrowUI;
  47. gl2d::Texture playerCell;
  48. glm::vec2 itemsBarSize;
  49. glm::vec2 itemsHighlighterSize;
  50. glm::vec2 itemsBarInventorySize;
  51. glm::vec2 oneInventorySlotSize;
  52. glm::vec2 playerCellSize;
  53. gl2d::Texture background;
  54. gl2d::Texture vignete;
  55. gl2d::Texture effectsTexture[Effects::EffectsNames::Effects_Count] = {};
  56. enum BattleTextures
  57. {
  58. circle,
  59. leftButton,
  60. rightButton,
  61. leftButtonFrontAttack,
  62. rightButtonSwipeAttack,
  63. circleSmall,
  64. battleTexturesCount
  65. };
  66. gl2d::Texture battleTextures[battleTexturesCount];
  67. //todo simplify
  68. //cursorItemIndex returns -1 if outside the menu to throw items, and -2 if it is nowhere
  69. //if inside crafting, supply craftingTableInventory
  70. void renderGameUI(float deltaTime,
  71. int w, int h, int itemSelected, PlayerInventory &inventory,
  72. BlocksLoader &blocksLoader, bool insideInventory, int &cursorItemIndex,
  73. int &currentInventoryTab, bool isCreative,
  74. unsigned short &selectedItem, Life &playerHealth, ProgramData &programData,
  75. LocalPlayer &player, int &craftingSlider, int &outCraftingRecepieGlobalIndex,
  76. bool showUI, std::uint16_t interactingBlock, ChestBlock *chestBlock
  77. );
  78. bool renderBaseBlockUI(float deltaTime,
  79. int w, int h, ProgramData &programData,
  80. BaseBlock &baseBlock, glm::ivec3 blockPos, ChunkSystem &chunkSystem,
  81. UndoQueue &undoQueue, LightSystem &lightSystem, ClientEntityManager &clientEntityManager
  82. );
  83. };
  84. struct Oscilator
  85. {
  86. Oscilator() {};
  87. Oscilator(float t, int fazes = 2): maxFazeTime(t), maxFazes(fazes) {};
  88. float maxFazeTime = 0;
  89. int maxFazes = 0;
  90. float currentTimer = 0;
  91. int currentFaze = 0;
  92. void update(float deltaTime);
  93. void reset();
  94. };