2
0

AdventureMapWidget.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. void updateMapLayerButtonsHelp();
  54. public:
  55. explicit AdventureMapWidget( std::shared_ptr<AdventureMapShortcuts> shortcuts );
  56. std::shared_ptr<CHeroList> getHeroList();
  57. std::shared_ptr<CTownList> getTownList();
  58. std::shared_ptr<CMinimap> getMinimap();
  59. std::shared_ptr<MapView> getMapView();
  60. std::shared_ptr<CInfoBar> getInfoBar();
  61. void setPlayerColor(const PlayerColor & player);
  62. void onMapViewMoved(const Rect & visibleArea, int mapLevel);
  63. void updateActiveState();
  64. };
  65. /// Small helper class that provides ownership for shared_ptr's of child elements
  66. class CAdventureMapContainerWidget : public CIntObject
  67. {
  68. friend class AdventureMapWidget;
  69. std::vector<std::shared_ptr<CIntObject>> ownedChildren;
  70. std::string disableCondition;
  71. };
  72. class CAdventureMapOverlayWidget : public CAdventureMapContainerWidget
  73. {
  74. public:
  75. void show(Canvas & to) override;
  76. };
  77. /// Small helper class that provides player-colorable icon using animation file
  78. class CAdventureMapIcon : public CIntObject
  79. {
  80. std::shared_ptr<CAnimImage> image;
  81. size_t index;
  82. size_t iconsPerPlayer;
  83. public:
  84. CAdventureMapIcon(const Point & position, const AnimationPath & image, size_t index, size_t iconsPerPlayer);
  85. void setPlayerColor(const PlayerColor & player);
  86. };