File: MiscWidgets.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 (265 lines) | stat: -rw-r--r-- 7,556 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
 * MiscWidgets.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 "../gui/CIntObject.h"
#include "../../lib/networkPacks/Component.h"

VCMI_LIB_NAMESPACE_BEGIN

class CGGarrison;
class CGCreature;
struct InfoAboutArmy;
struct InfoAboutHero;
struct InfoAboutTown;
class CArmedInstance;
class CGTownInstance;
class CGHeroInstance;
class AFactionMember;

VCMI_LIB_NAMESPACE_END

class CLabel;
class CTextBox;
class CGarrisonInt;
class CCreatureAnim;
class CComponent;
class CAnimImage;
class LRClickableArea;
class TransparentFilledRectangle;

/// Shows a text by moving the mouse cursor over the object
class CHoverableArea: public virtual CIntObject
{
public:
	std::string hoverText;

	void hover (bool on) override;

	CHoverableArea();
	virtual ~CHoverableArea();
};

/// Can interact on left and right mouse clicks, plus it shows a text when by hovering over it
class LRClickableAreaWText: public CHoverableArea
{
public:
	std::string text;

	LRClickableAreaWText();
	LRClickableAreaWText(const Rect & Pos, const std::string & HoverText = "", const std::string & ClickText = "");
	virtual ~LRClickableAreaWText();
	void init();

	void clickPressed(const Point & cursorPosition) override;
	void showPopupWindow(const Point & cursorPosition) override;
};

/// base class for hero/town/garrison tooltips
class CArmyTooltip : public CIntObject
{
	std::shared_ptr<CLabel> title;
	std::vector<std::shared_ptr<CAnimImage>> icons;
	std::vector<std::shared_ptr<CLabel>> subtitles;
	void init(const InfoAboutArmy & army);
public:
	CArmyTooltip(Point pos, const InfoAboutArmy & army);
	CArmyTooltip(Point pos, const CArmedInstance * army);
};

/// Class for hero tooltip. Does not have any background!
/// background for infoBox: ADSTATHR
/// background for tooltip: HEROQVBK
class CHeroTooltip : public CArmyTooltip
{
	std::shared_ptr<CAnimImage> portrait;
	std::vector<std::shared_ptr<CLabel>> labels;
	std::shared_ptr<CAnimImage> morale;
	std::shared_ptr<CAnimImage> luck;

	void init(const InfoAboutHero & hero);
public:
	CHeroTooltip(Point pos, const InfoAboutHero & hero);
	CHeroTooltip(Point pos, const CGHeroInstance * hero);
};

/// Class for HD mod-like interactable infobox tooltip. Does not have any background!
class CInteractableHeroTooltip : public CIntObject
{
	std::shared_ptr<CLabel> title;
	std::shared_ptr<CAnimImage> portrait;
	std::vector<std::shared_ptr<CLabel>> labels;
	std::shared_ptr<CAnimImage> morale;
	std::shared_ptr<CAnimImage> luck;
	std::shared_ptr<CGarrisonInt> garrison;

	void init(const InfoAboutHero & hero);
public:
	CInteractableHeroTooltip(Point pos, const CGHeroInstance * hero);
};

/// Class for town tooltip. Does not have any background!
/// background for infoBox: ADSTATCS
/// background for tooltip: TOWNQVBK
class CTownTooltip : public CArmyTooltip
{
	std::shared_ptr<CAnimImage> fort;
	std::shared_ptr<CAnimImage> hall;
	std::shared_ptr<CAnimImage> build;
	std::shared_ptr<CLabel> income;
	std::shared_ptr<CPicture> garrisonedHero;
	std::shared_ptr<CAnimImage> res1;
	std::shared_ptr<CAnimImage> res2;

	void init(const InfoAboutTown & town);
public:
	CTownTooltip(Point pos, const InfoAboutTown & town);
	CTownTooltip(Point pos, const CGTownInstance * town);
};

/// Class for HD mod-like interactable infobox tooltip. Does not have any background!
class CInteractableTownTooltip : public CIntObject
{
	std::shared_ptr<CLabel> title;
	std::shared_ptr<CAnimImage> fort;
	std::shared_ptr<CAnimImage> hall;
	std::shared_ptr<CAnimImage> build;
	std::shared_ptr<CLabel> income;
	std::shared_ptr<CPicture> garrisonedHero;
	std::shared_ptr<CAnimImage> res1;
	std::shared_ptr<CAnimImage> res2;
	std::shared_ptr<CGarrisonInt> garrison;
	
	std::shared_ptr<LRClickableArea> fastTavern;
	std::shared_ptr<LRClickableArea> fastMarket;
	std::shared_ptr<LRClickableArea> fastTownHall;
	std::shared_ptr<LRClickableArea> fastArmyPurchase;

	void init(const CGTownInstance * town);
public:
	CInteractableTownTooltip(Point pos, const CGTownInstance * town);
};

/// draws picture with creature on background, use Animated=true to get animation
class CCreaturePic : public CIntObject
{
private:
	std::shared_ptr<CPicture> bg;
	std::shared_ptr<CCreatureAnim> anim; //displayed animation
	std::shared_ptr<CLabel> amount;

	void show(Canvas & to) override;
public:
	CCreaturePic(int x, int y, const CCreature * cre, bool Big=true, bool Animated=true);
	void setAmount(int newAmount);
};

class CreatureTooltip : public CIntObject
{
	std::shared_ptr<CAnimImage> creatureImage;
	std::shared_ptr<CTextBox> tooltipTextbox;

public:
	CreatureTooltip(Point pos, const CGCreature * creature);
};

/// Resource bar like that at the bottom of the adventure map screen
class CMinorResDataBar : public CIntObject
{
	std::shared_ptr<CPicture> background;

	std::string buildDateString();
public:
	void show(Canvas & to) override;
	void showAll(Canvas & to) override;
	CMinorResDataBar();
	~CMinorResDataBar();
};

/// Performs an action by left-clicking on it. Opens hero window by default
class CHeroArea: public CIntObject
{
public:
	using ClickFunctor = std::function<void()>;

	CHeroArea(int x, int y, const CGHeroInstance * hero);
	void addClickCallback(ClickFunctor callback);
	void addRClickCallback(ClickFunctor callback);
	void clickPressed(const Point & cursorPosition) override;
	void showPopupWindow(const Point & cursorPosition) override;
	void hover(bool on) override;
private:
	const CGHeroInstance * hero;
	std::shared_ptr<CAnimImage> portrait;
	ClickFunctor clickFunctor;
	ClickFunctor clickRFunctor;
	ClickFunctor showPopupHandler;
};

/// Can interact on left and right mouse clicks
class LRClickableAreaWTextComp: public LRClickableAreaWText
{
public:
	Component component;

	void clickPressed(const Point & cursorPosition) override;
	void showPopupWindow(const Point & cursorPosition) override;

	LRClickableAreaWTextComp(const Rect &Pos = Rect(0,0,0,0), ComponentType baseType = ComponentType::NONE);
	std::shared_ptr<CComponent> createComponent() const;
};

/// Opens town screen by left-clicking on it
class LRClickableAreaOpenTown: public LRClickableAreaWTextComp
{
public:
	const CGTownInstance * town;
	void clickPressed(const Point & cursorPosition) override;
	LRClickableAreaOpenTown(const Rect & Pos, const CGTownInstance * Town);
};

/// Can do action on click
class LRClickableArea: public CIntObject
{
	std::function<void()> onClick;
	std::function<void()> onPopup;
public:
	void clickPressed(const Point & cursorPosition) override;
	void showPopupWindow(const Point & cursorPosition) override;
	LRClickableArea(const Rect & Pos, std::function<void()> onClick = nullptr, std::function<void()> onPopup = nullptr);
};

class MoraleLuckBox : public LRClickableAreaWTextComp
{
	std::shared_ptr<CAnimImage> image;
	std::shared_ptr<CLabel> label;
public:
	bool morale; //true if morale, false if luck
	bool small;

	void set(const AFactionMember *node);

	MoraleLuckBox(bool Morale, const Rect &r, bool Small=false);
};

class SelectableSlot : public LRClickableAreaWTextComp
{
	std::shared_ptr<TransparentFilledRectangle> selection;
	bool selected;

public:
	SelectableSlot(Rect area, Point oversize, const int width);
	SelectableSlot(Rect area, Point oversize);
	SelectableSlot(Rect area, const int width = 1);
	void selectSlot(bool on);
	bool isSelected() const;
	void setSelectionWidth(int width);
	void moveSelectionForeground();
};