AdventureMapWidget.h 3.8 KB

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