AdventureMapWidget.h 3.5 KB

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