isometricGameEditor.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #pragma once
  2. #include <gl2d/gl2d.h>
  3. #include <imgui.h>
  4. #include <baseContainer.h>
  5. #include <shortcutApi/shortcutApi.h>
  6. #include <pikaSizes.h>
  7. #include <fileChanged.h>
  8. #include <engineLibraresSupport/engineGL2DSupport.h>
  9. struct IsometricGameEditor: public Container
  10. {
  11. //todo some decorative piece and a hint
  12. //alimente care ii scresc viata
  13. enum Blocks
  14. {
  15. air = 0,
  16. clay,
  17. stone,
  18. ice,
  19. snowDirt,
  20. dirt,
  21. log,
  22. woddenPlank,
  23. redstone,
  24. trapdor,
  25. lever,
  26. redstoneTorch,
  27. redstoneBlock,
  28. chest,
  29. };
  30. pika::FileChanged fileChanged;
  31. gl2d::Renderer2D renderer;
  32. pika::pikaImgui::FileSelector loadedLevel;
  33. gl2d::Texture tiles;
  34. gl2d::Texture shadow;
  35. gl2d::TextureAtlasPadding tilesAtlas;
  36. glm::ivec3 newMapSize = {};
  37. glm::ivec3 blockSelector = {};
  38. static bool pointInBox(glm::vec2 p, glm::vec4 box);
  39. static bool canPlaceRedstoneOn(int type);
  40. static bool redstoneWire(int type);
  41. static ContainerStaticInfo containerInfo()
  42. {
  43. ContainerStaticInfo info = {};
  44. info.defaultHeapMemorySize = pika::MB(10);
  45. info.extensionsSuported = {".isomap"};
  46. info.requestImguiFbo = true;
  47. //todo option to not allow the user to close the container using the imgui x
  48. return info;
  49. }
  50. bool create(RequestedContainerInfo &requestedInfo, pika::StaticString<256> commandLineArgument);
  51. int currentBlock = 0;
  52. struct Block
  53. {
  54. unsigned char type;
  55. unsigned char secondType;
  56. void set(unsigned char count, unsigned char down)
  57. {
  58. type = count;
  59. secondType = down;
  60. }
  61. glm::ivec2 get()
  62. {
  63. return {type, secondType};
  64. }
  65. };
  66. struct Map
  67. {
  68. std::vector<Block> mapData;
  69. glm::ivec3 size = {};
  70. void init(glm::ivec3 size)
  71. {
  72. mapData.clear();
  73. mapData.resize(size.x * size.y * size.z);
  74. this->size = size;
  75. }
  76. void setSafe(glm::ivec3 pos, unsigned char count, bool down)
  77. {
  78. auto get = getSafe(pos);
  79. if (get) { get->set(count, down); }
  80. }
  81. void setSafe(glm::ivec3 pos, Block b)
  82. {
  83. auto get = getSafe(pos);
  84. if (get) { *get = b; }
  85. }
  86. Block *getSafe(glm::ivec3 pos)
  87. {
  88. if (pos.x >= 0 && pos.y >= 0 && pos.z >= 0
  89. && pos.x < size.x && pos.y < size.y && pos.z < size.z
  90. )
  91. {
  92. return &mapData[pos.x * size.z * size.y + pos.y * size.z + pos.z];
  93. }
  94. else
  95. {
  96. return 0;
  97. }
  98. }
  99. };
  100. Map map;
  101. bool update(pika::Input input, pika::WindowState windowState,
  102. RequestedContainerInfo &requestedInfo) override;
  103. void destruct(RequestedContainerInfo &requestedInfo) override;
  104. };