File: MapViewController.h

package info (click to toggle)
vcmi 1.6.5%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 32,060 kB
  • sloc: cpp: 238,971; python: 265; sh: 224; xml: 157; ansic: 78; objc: 61; makefile: 49
file content (112 lines) | stat: -rw-r--r-- 4,432 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * MapViewController.h, part of VCMI engine
 *
 * Authors: listed in file AUTHORS in main folder
 *
 * License: GNU General Public License v2.0 or later
 * Full text of license available in license.txt file, in main folder
 *
 */
#pragma once

#include "IMapRendererObserver.h"
#include "../ConditionalWait.h"
#include "../../lib/Point.h"

VCMI_LIB_NAMESPACE_BEGIN
struct ObjectPosInfo;
class PlayerColor;
VCMI_LIB_NAMESPACE_END

struct MapRendererContextState;

class MapViewCache;
class MapViewModel;
class IMapRendererContext;
class MapRendererAdventureContext;
class MapRendererAdventureFadingContext;
class MapRendererAdventureMovingContext;
class MapRendererAdventureTransitionContext;
class MapRendererWorldViewContext;
class MapRendererSpellViewContext;
class MapRendererPuzzleMapContext;

/// Class responsible for updating view state,
/// such as its position and any animations
class MapViewController : public IMapObjectObserver
{
	ConditionalWait animationWait;

	std::shared_ptr<IMapRendererContext> context;
	std::shared_ptr<MapRendererContextState> state;
	std::shared_ptr<MapViewModel> model;
	std::shared_ptr<MapViewCache> view;

	// all potential contexts for view
	// only some are present at any given moment, rest are nullptr's
	std::shared_ptr<MapRendererAdventureContext> adventureContext;
	std::shared_ptr<MapRendererAdventureMovingContext> movementContext;
	std::shared_ptr<MapRendererAdventureTransitionContext> teleportContext;
	std::shared_ptr<MapRendererAdventureFadingContext> fadingOutContext;
	std::shared_ptr<MapRendererAdventureFadingContext> fadingInContext;
	std::shared_ptr<MapRendererWorldViewContext> worldViewContext;
	std::shared_ptr<MapRendererSpellViewContext> spellViewContext;
	std::shared_ptr<MapRendererPuzzleMapContext> puzzleMapContext;

private:
	const int defaultTileSize = 32;
	const int zoomTileDeadArea = 4;
	Point targetTileSize = Point(32, 32);
	bool wasInDeadZone = true;

	bool isEventInstant(const CGObjectInstance * obj, const PlayerColor & initiator);
	bool isEventVisible(const CGObjectInstance * obj, const PlayerColor & initiator);
	bool isEventVisible(const CGHeroInstance * obj, const int3 & from, const int3 & dest);

	void fadeOutObject(const CGObjectInstance * obj);
	void fadeInObject(const CGObjectInstance * obj);

	void removeObject(const CGObjectInstance * obj);
	void addObject(const CGObjectInstance * obj);

	// IMapObjectObserver impl
	bool hasOngoingAnimations() override;
	void waitForOngoingAnimations() override;
	void endNetwork() override;

	void onObjectFadeIn(const CGObjectInstance * obj, const PlayerColor & initiator) override;
	void onObjectFadeOut(const CGObjectInstance * obj, const PlayerColor & initiator) override;
	void onObjectInstantAdd(const CGObjectInstance * obj, const PlayerColor & initiator) override;
	void onObjectInstantRemove(const CGObjectInstance * obj, const PlayerColor & initiator) override;
	void onAfterHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
	void onBeforeHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
	void onHeroMoved(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
	void onBeforeHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
	void onAfterHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
	void onBeforeHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
	void onAfterHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;

	void resetContext();
	void updateState();

public:
	MapViewController(std::shared_ptr<MapViewModel> model, std::shared_ptr<MapViewCache> view);

	std::shared_ptr<IMapRendererContext> getContext() const;

	void setViewCenter(const int3 & position);
	void setViewCenter(const Point & position, int level);
	void setTileSize(const Point & tileSize);
	void modifyTileSize(int stepsChange, bool useDeadZone);
	void tick(uint32_t timePassed);
	void afterRender();

	void activateAdventureContext(uint32_t animationTime);
	void activateAdventureContext();
	void activateWorldViewContext();
	void activateSpellViewContext();
	void activatePuzzleMapContext(const int3 & grailPosition);

	void setTerrainVisibility(bool showAllTerrain);
	void setOverlayVisibility(const std::vector<ObjectPosInfo> & objectPositions);
};