CAdventureMapWidget.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * CAdventureMapWidget.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../gui/InterfaceObjectConfigurable.h"
  12. class CHeroList;
  13. class CTownList;
  14. class CMinimap;
  15. class MapView;
  16. class CInfoBar;
  17. class IImage;
  18. enum class EGameState
  19. {
  20. NOT_INITIALIZED,
  21. HOTSEAT_WAIT,
  22. MAKING_TURN,
  23. ENEMY_TURN,
  24. CASTING_SPELL,
  25. WORLD_VIEW
  26. };
  27. /// Internal class of AdventureMapInterface that contains actual UI elements
  28. class CAdventureMapWidget : public InterfaceObjectConfigurable
  29. {
  30. EGameState state;
  31. /// temporary stack of sizes of currently building widgets
  32. std::vector<Rect> subwidgetSizes;
  33. /// list of images on which player-colored palette will be applied
  34. std::vector<std::string> playerColorerImages;
  35. /// list of named images shared between widgets
  36. std::map<std::string, std::shared_ptr<IImage>> images;
  37. std::map<std::string, std::shared_ptr<CAnimation>> animations;
  38. Rect readTargetArea(const JsonNode & source);
  39. Rect readSourceArea(const JsonNode & source, const JsonNode & sourceCommon);
  40. Rect readArea(const JsonNode & source, const Rect & boundingBox);
  41. std::shared_ptr<IImage> loadImage(const std::string & name);
  42. std::shared_ptr<CAnimation> loadAnimation(const std::string & name);
  43. std::shared_ptr<CIntObject> buildInfobox(const JsonNode & input);
  44. std::shared_ptr<CIntObject> buildMapImage(const JsonNode & input);
  45. std::shared_ptr<CIntObject> buildMapButton(const JsonNode & input);
  46. std::shared_ptr<CIntObject> buildMapContainer(const JsonNode & input);
  47. std::shared_ptr<CIntObject> buildMapGameArea(const JsonNode & input);
  48. std::shared_ptr<CIntObject> buildMapHeroList(const JsonNode & input);
  49. std::shared_ptr<CIntObject> buildMapIcon(const JsonNode & input);
  50. std::shared_ptr<CIntObject> buildMapTownList(const JsonNode & input);
  51. std::shared_ptr<CIntObject> buildMinimap(const JsonNode & input);
  52. std::shared_ptr<CIntObject> buildResourceDateBar(const JsonNode & input);
  53. std::shared_ptr<CIntObject> buildStatusBar(const JsonNode & input);
  54. void setPlayerChildren(CIntObject * widget, const PlayerColor & player);
  55. public:
  56. CAdventureMapWidget();
  57. std::shared_ptr<CHeroList> getHeroList();
  58. std::shared_ptr<CTownList> getTownList();
  59. std::shared_ptr<CMinimap> getMinimap();
  60. std::shared_ptr<MapView> getMapView();
  61. std::shared_ptr<CInfoBar> getInfoBar();
  62. void setPlayer(const PlayerColor & player);
  63. void setState(EGameState newState);
  64. EGameState getState();
  65. void setOptionHasQuests(bool on);
  66. void setOptionHasUnderground(bool on);
  67. void setOptionUndergroundLevel(bool on);
  68. void setOptionHeroSleeping(bool on);
  69. void setOptionHeroSelected(bool on);
  70. void setOptionHeroCanMove(bool on);
  71. void setOptionHasNextHero(bool on);
  72. };
  73. /// Small helper class that provides ownership for shared_ptr's of child elements
  74. class CAdventureMapContainerWidget : public CIntObject
  75. {
  76. friend class CAdventureMapWidget;
  77. std::vector<std::shared_ptr<CIntObject>> ownedChildren;
  78. };
  79. /// Small helper class that provides player-colorable icon using animation file
  80. class CAdventureMapIcon : public CIntObject
  81. {
  82. std::shared_ptr<CAnimImage> image;
  83. size_t index;
  84. size_t iconsPerPlayer;
  85. public:
  86. CAdventureMapIcon(const Point & position, std::shared_ptr<CAnimation> image, size_t index, size_t iconsPerPlayer);
  87. void setPlayer(const PlayerColor & player);
  88. };