CAdventureMapWidget.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. class AdventureMapShortcuts;
  19. enum class EGameState
  20. {
  21. NOT_INITIALIZED,
  22. HOTSEAT_WAIT,
  23. MAKING_TURN,
  24. ENEMY_TURN,
  25. CASTING_SPELL,
  26. WORLD_VIEW
  27. };
  28. /// Internal class of AdventureMapInterface that contains actual UI elements
  29. class CAdventureMapWidget : public InterfaceObjectConfigurable
  30. {
  31. EGameState state;
  32. /// temporary stack of sizes of currently building widgets
  33. std::vector<Rect> subwidgetSizes;
  34. /// list of images on which player-colored palette will be applied
  35. std::vector<std::string> playerColorerImages;
  36. /// list of named images shared between widgets
  37. std::map<std::string, std::shared_ptr<IImage>> images;
  38. std::map<std::string, std::shared_ptr<CAnimation>> animations;
  39. /// Widgets that require access from adventure map
  40. std::shared_ptr<CHeroList> heroList;
  41. std::shared_ptr<CTownList> townList;
  42. std::shared_ptr<CMinimap> minimap;
  43. std::shared_ptr<MapView> mapView;
  44. std::shared_ptr<CInfoBar> infoBar;
  45. std::shared_ptr<AdventureMapShortcuts> shortcuts;
  46. Rect readTargetArea(const JsonNode & source);
  47. Rect readSourceArea(const JsonNode & source, const JsonNode & sourceCommon);
  48. Rect readArea(const JsonNode & source, const Rect & boundingBox);
  49. std::shared_ptr<IImage> loadImage(const std::string & name);
  50. std::shared_ptr<CAnimation> loadAnimation(const std::string & name);
  51. std::shared_ptr<CIntObject> buildInfobox(const JsonNode & input);
  52. std::shared_ptr<CIntObject> buildMapImage(const JsonNode & input);
  53. std::shared_ptr<CIntObject> buildMapButton(const JsonNode & input);
  54. std::shared_ptr<CIntObject> buildMapContainer(const JsonNode & input);
  55. std::shared_ptr<CIntObject> buildMapGameArea(const JsonNode & input);
  56. std::shared_ptr<CIntObject> buildMapHeroList(const JsonNode & input);
  57. std::shared_ptr<CIntObject> buildMapIcon(const JsonNode & input);
  58. std::shared_ptr<CIntObject> buildMapTownList(const JsonNode & input);
  59. std::shared_ptr<CIntObject> buildMinimap(const JsonNode & input);
  60. std::shared_ptr<CIntObject> buildResourceDateBar(const JsonNode & input);
  61. std::shared_ptr<CIntObject> buildStatusBar(const JsonNode & input);
  62. void setPlayerChildren(CIntObject * widget, const PlayerColor & player);
  63. void updateActiveStateChildden(CIntObject * widget);
  64. public:
  65. explicit CAdventureMapWidget( std::shared_ptr<AdventureMapShortcuts> shortcuts );
  66. std::shared_ptr<CHeroList> getHeroList();
  67. std::shared_ptr<CTownList> getTownList();
  68. std::shared_ptr<CMinimap> getMinimap();
  69. std::shared_ptr<MapView> getMapView();
  70. std::shared_ptr<CInfoBar> getInfoBar();
  71. void setPlayer(const PlayerColor & player);
  72. void setState(EGameState newState);
  73. EGameState getState();
  74. void updateActiveState();
  75. };
  76. /// Small helper class that provides ownership for shared_ptr's of child elements
  77. class CAdventureMapContainerWidget : public CIntObject
  78. {
  79. friend class CAdventureMapWidget;
  80. std::vector<std::shared_ptr<CIntObject>> ownedChildren;
  81. std::string disableCondition;
  82. };
  83. class CAdventureMapOverlayWidget : public CAdventureMapContainerWidget
  84. {
  85. public:
  86. void show(SDL_Surface * to) override;
  87. };
  88. /// Small helper class that provides player-colorable icon using animation file
  89. class CAdventureMapIcon : public CIntObject
  90. {
  91. std::shared_ptr<CAnimImage> image;
  92. size_t index;
  93. size_t iconsPerPlayer;
  94. public:
  95. CAdventureMapIcon(const Point & position, std::shared_ptr<CAnimation> image, size_t index, size_t iconsPerPlayer);
  96. void setPlayer(const PlayerColor & player);
  97. };