AdventureMapWidget.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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<std::string> playerColorerImages;
  28. /// list of named images shared between widgets
  29. std::map<std::string, std::shared_ptr<IImage>> images;
  30. std::map<std::string, std::shared_ptr<CAnimation>> animations;
  31. /// Widgets that require access from adventure map
  32. std::shared_ptr<CHeroList> heroList;
  33. std::shared_ptr<CTownList> townList;
  34. std::shared_ptr<CMinimap> minimap;
  35. std::shared_ptr<MapView> mapView;
  36. std::shared_ptr<CInfoBar> infoBar;
  37. std::shared_ptr<AdventureMapShortcuts> shortcuts;
  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. std::shared_ptr<CIntObject> buildTexturePlayerColored(const JsonNode &);
  55. void setPlayerChildren(CIntObject * widget, const PlayerColor & player);
  56. void updateActiveStateChildden(CIntObject * widget);
  57. public:
  58. explicit AdventureMapWidget( std::shared_ptr<AdventureMapShortcuts> shortcuts );
  59. std::shared_ptr<CHeroList> getHeroList();
  60. std::shared_ptr<CTownList> getTownList();
  61. std::shared_ptr<CMinimap> getMinimap();
  62. std::shared_ptr<MapView> getMapView();
  63. std::shared_ptr<CInfoBar> getInfoBar();
  64. void setPlayer(const PlayerColor & player);
  65. void onMapViewMoved(const Rect & visibleArea, int mapLevel);
  66. void updateActiveState();
  67. };
  68. /// Small helper class that provides ownership for shared_ptr's of child elements
  69. class CAdventureMapContainerWidget : public CIntObject
  70. {
  71. friend class AdventureMapWidget;
  72. std::vector<std::shared_ptr<CIntObject>> ownedChildren;
  73. std::string disableCondition;
  74. };
  75. class CAdventureMapOverlayWidget : public CAdventureMapContainerWidget
  76. {
  77. public:
  78. void show(SDL_Surface * to) override;
  79. };
  80. /// Small helper class that provides player-colorable icon using animation file
  81. class CAdventureMapIcon : public CIntObject
  82. {
  83. std::shared_ptr<CAnimImage> image;
  84. size_t index;
  85. size_t iconsPerPlayer;
  86. public:
  87. CAdventureMapIcon(const Point & position, std::shared_ptr<CAnimation> image, size_t index, size_t iconsPerPlayer);
  88. void setPlayer(const PlayerColor & player);
  89. };