File: CKingdomInterface.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 (361 lines) | stat: -rw-r--r-- 9,736 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*
 * CKingdomInterface.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 "CWindowWithArtifacts.h"

VCMI_LIB_NAMESPACE_BEGIN
class CGObjectInstance;
VCMI_LIB_NAMESPACE_END

class CButton;
class CAnimImage;
class CToggleGroup;
class CResDataBar;
class CSlider;
class CTownInfo;
class CCreaInfo;
class HeroSlots;
class LRClickableAreaOpenTown;
class CComponent;
class CHeroArea;
class MoraleLuckBox;
class CListBox;
class CTabbedInt;
class CGStatusBar;
class CGarrisonInt;

class CKingdHeroList;
class CKingdTownList;
class IInfoBoxData;

/*
 * Several classes to display basically any data.
 * Main part - class InfoBox which controls how data will be formatted\positioned
 * InfoBox have image and 0-2 labels
 * In constructor it should receive object that implements IInfoBoxData interface
 *
 * interface IInfoBoxData defines way to get data for use in InfoBox
 * have several implementations:
 * InfoBoxHeroData - to display one of fields from hero (e.g. absolute value of primary skills)
 * InfoBoxCustomHeroData - to display one of hero fields without hero (e.g. bonuses from objects)
 * InfoBoxTownData - data from town
 * InfoBoxCustom - user-defined data
 */

/// Displays one of object propertries with image and optional labels
class InfoBox : public CIntObject
{
public:
	enum InfoPos
	{
		POS_UP_DOWN, POS_DOWN, POS_RIGHT, POS_INSIDE, POS_CORNER, POS_NONE
	};
	enum InfoSize
	{
		SIZE_TINY, SIZE_SMALL, SIZE_MEDIUM, SIZE_BIG, SIZE_HUGE
	};

private:
	InfoSize size;
	InfoPos infoPos;
	std::shared_ptr<IInfoBoxData> data;

	std::shared_ptr<CLabel> value;
	std::shared_ptr<CLabel> name;
	std::shared_ptr<CAnimImage> image;
	std::shared_ptr<CHoverableArea> hover;

public:
	InfoBox(Point position, InfoPos Pos, InfoSize Size, std::shared_ptr<IInfoBoxData> Data);
	~InfoBox();

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

class IInfoBoxData
{
public:
	enum InfoType
	{
		HERO_PRIMARY_SKILL, HERO_MANA, HERO_EXPERIENCE, HERO_SPECIAL, HERO_SECONDARY_SKILL,
		//TODO: Luck? Morale? Artifact?
		ARMY_SLOT,//TODO
		TOWN_GROWTH, TOWN_AVAILABLE, TOWN_BUILDING,//TODO
		CUSTOM
	};

protected:
	InfoType type;

	IInfoBoxData(InfoType Type);

public:
	//methods that generate values for displaying
	virtual std::string getValueText()=0;
	virtual std::string getNameText()=0;
	virtual AnimationPath getImageName(InfoBox::InfoSize size)=0;
	virtual std::string getHoverText()=0;
	virtual size_t getImageIndex()=0;

	//TODO: replace with something better
	virtual void prepareMessage(std::string & text, std::shared_ptr<CComponent> & comp)=0;

	virtual ~IInfoBoxData(){};
};

class InfoBoxAbstractHeroData : public IInfoBoxData
{
protected:
	virtual int  getSubID()=0;
	virtual si64 getValue()=0;

public:
	InfoBoxAbstractHeroData(InfoType Type);

	std::string getValueText() override;
	std::string getNameText() override;
	AnimationPath getImageName(InfoBox::InfoSize size) override;
	std::string getHoverText() override;
	size_t getImageIndex() override;

	void prepareMessage(std::string & text, std::shared_ptr<CComponent> & comp) override;
};

class InfoBoxHeroData : public InfoBoxAbstractHeroData
{
	const CGHeroInstance * hero;
	int index;//index of data in hero (0-7 for sec. skill, 0-3 for pr. skill)

	int  getSubID() override;
	si64 getValue() override;

public:
	InfoBoxHeroData(InfoType Type, const CGHeroInstance *Hero, int Index=0);

	//To get a bit different texts for hero window
	std::string getHoverText() override;
	std::string getValueText() override;

	void prepareMessage(std::string & text, std::shared_ptr<CComponent> & comp) override;
};

class InfoBoxCustomHeroData : public InfoBoxAbstractHeroData
{
	int subID;//subID of data (0=attack...)
	si64 value;//actual value of data, 64-bit to fit experience and negative values

	int  getSubID() override;
	si64 getValue() override;

public:
	InfoBoxCustomHeroData(InfoType Type, int subID, si64 value);
};

class InfoBoxCustom : public IInfoBoxData
{
public:
	std::string valueText;
	std::string nameText;
	AnimationPath imageName;
	std::string hoverText;
	size_t imageIndex;

	InfoBoxCustom(std::string ValueText, std::string NameText, const AnimationPath & ImageName, size_t ImageIndex, std::string HoverText="");

	std::string getValueText() override;
	std::string getNameText() override;
	AnimationPath getImageName(InfoBox::InfoSize size) override;
	std::string getHoverText() override;
	size_t getImageIndex() override;

	void prepareMessage(std::string & text, std::shared_ptr<CComponent> & comp) override;
};

//TODO!!!
class InfoBoxTownData : public IInfoBoxData
{
	const CGTownInstance * town;
	int index;//index of data in town
	int value;//actual value of data

public:
	InfoBoxTownData(InfoType Type, const CGTownInstance * Town, int Index);
	InfoBoxTownData(InfoType Type, int SubID, int Value);

	std::string getValueText() override;
	std::string getNameText() override;
	AnimationPath getImageName(InfoBox::InfoSize size) override;
	std::string getHoverText() override;
	size_t getImageIndex() override;
};

/// Class which holds all parts of kingdom overview window
class CKingdomInterface : public IGarrisonHolder, public CWindowWithArtifacts, public ITownHolder
{
private:
	struct OwnedObjectInfo
	{
		int imageID;
		ui32 count;
		std::string hoverText;
		OwnedObjectInfo():
			imageID(0),
			count(0)
		{}
	};
	std::vector<OwnedObjectInfo> objects;

	std::shared_ptr<CListBox> dwellingsList;
	std::shared_ptr<CTabbedInt> tabArea;

	//Main buttons
	std::shared_ptr<CButton> btnTowns;
	std::shared_ptr<CButton> btnHeroes;
	std::shared_ptr<CButton> btnExit;

	//Buttons for scrolling dwellings list
	std::shared_ptr<CButton> dwellUp;
	std::shared_ptr<CButton> dwellDown;
	std::shared_ptr<CButton> dwellTop;
	std::shared_ptr<CButton> dwellBottom;

	std::array<std::shared_ptr<InfoBox>, 7> minesBox;

	std::shared_ptr<CHoverableArea> incomeArea;
	std::shared_ptr<CLabel> incomeAmount;

	std::shared_ptr<CGStatusBar> statusbar;
	std::shared_ptr<CResDataBar> resdatabar;

	void activateTab(size_t which);

	//Internal functions used during construction
	void generateButtons();
	void generateObjectsList(const std::vector<const CGObjectInstance * > &ownedObjects);
	void generateMinesList(const std::vector<const CGObjectInstance * > &ownedObjects);

	std::shared_ptr<CIntObject> createOwnedObject(size_t index);
	std::shared_ptr<CIntObject> createMainTab(size_t index);

public:
	CKingdomInterface();

	void townChanged(const CGTownInstance *town);
	void heroRemoved();
	void updateGarrisons() override;
	bool holdsGarrison(const CArmedInstance * army) override;
	void buildChanged() override;
};

/// List item with town
class CTownItem : public CIntObject, public IGarrisonHolder
{
	std::shared_ptr<CAnimImage> background;
	std::shared_ptr<CAnimImage> picture;
	std::shared_ptr<CLabel> name;
	std::shared_ptr<CLabel> income;
	std::shared_ptr<CGarrisonInt> garr;

	std::shared_ptr<HeroSlots> heroes;
	std::shared_ptr<CTownInfo> hall;
	std::shared_ptr<CTownInfo> fort;

	std::vector<std::shared_ptr<CCreaInfo>> available;
	std::vector<std::shared_ptr<CCreaInfo>> growth;

	std::shared_ptr<LRClickableAreaOpenTown> openTown;

	std::shared_ptr<CButton> fastTownHall;
	std::shared_ptr<CButton> fastArmyPurchase;
	std::shared_ptr<LRClickableArea> fastMarket;
	std::shared_ptr<LRClickableArea> fastTavern;
	std::shared_ptr<LRClickableArea> fastTown;

public:
	const CGTownInstance * town;

	CTownItem(const CGTownInstance * Town);

	void updateGarrisons() override;
	bool holdsGarrison(const CArmedInstance * army) override;
	void update();
};

/// List item with hero
class CHeroItem : public CIntObject, public IGarrisonHolder
{
	const CGHeroInstance * hero;

	std::vector<std::shared_ptr<CIntObject>> artTabs;

	std::shared_ptr<CAnimImage> portrait;
	std::shared_ptr<CLabel> name;
	std::shared_ptr<CHeroArea> heroArea;

	std::shared_ptr<CLabel> artsText;
	std::shared_ptr<CTabbedInt> artsTabs;

	std::shared_ptr<CToggleGroup> artButtons;
	std::vector<std::shared_ptr<InfoBox>> heroInfo;
	std::shared_ptr<MoraleLuckBox> morale;
	std::shared_ptr<MoraleLuckBox> luck;

	std::shared_ptr<CGarrisonInt> garr;

	void onArtChange(int tabIndex);

	std::shared_ptr<CIntObject> onTabSelected(size_t index);

public:
	std::shared_ptr<CArtifactsOfHeroKingdom> heroArts;

	void updateGarrisons() override;
	bool holdsGarrison(const CArmedInstance * army) override;

	CHeroItem(const CGHeroInstance * hero);
};

/// Tab with all hero-specific data
class CKingdHeroList : public CIntObject, public IGarrisonHolder
{
private:
	std::shared_ptr<CListBox> heroes;
	std::shared_ptr<CPicture> title;
	std::shared_ptr<CLabel> heroLabel;
	std::shared_ptr<CLabel> skillsLabel;

public:
	using CreateHeroItemFunctor = std::function<void(const CWindowWithArtifacts::CArtifactsOfHeroPtr)>;

	CKingdHeroList(size_t maxSize, const CreateHeroItemFunctor & onCreateHeroItemCallback);
	void updateGarrisons() override;
	bool holdsGarrison(const CArmedInstance * army) override;
};

/// Tab with all town-specific data
class CKingdTownList : public CIntObject, public IGarrisonHolder
{
private:
	std::shared_ptr<CListBox> towns;
	std::shared_ptr<CPicture> title;
	std::shared_ptr<CLabel> townLabel;
	std::shared_ptr<CLabel> garrHeroLabel;
	std::shared_ptr<CLabel> visitHeroLabel;

	std::shared_ptr<CIntObject> createTownItem(size_t index);
public:
	CKingdTownList(size_t maxSize);

	void townChanged(const CGTownInstance * town);
	void updateGarrisons() override;
	bool holdsGarrison(const CArmedInstance * army) override;
};