forked from miki151/keeperrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui_builder.h
218 lines (195 loc) · 8.09 KB
/
gui_builder.h
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
/* Copyright (C) 2013-2014 Michal Brzozowski ([email protected])
This file is part of KeeperRL.
KeeperRL is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
KeeperRL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.gnu.org/licenses/ . */
#ifndef _GUI_BUILDER_H
#define _GUI_BUILDER_H
#include "util.h"
#include "gui_elem.h"
#include "game_info.h"
#include "user_input.h"
class Clock;
class MinionAction;
class ListElem;
struct HighscoreList;
class Options;
class MapGui;
class GuiBuilder {
public:
enum class GameSpeed;
struct Callbacks {
function<void(UserInput)> input;
function<void(const vector<string>&)> hint;
function<void(sf::Event::KeyEvent)> keyboard;
function<void()> refreshScreen;
};
GuiBuilder(Renderer&, GuiFactory&, Clock*, Options*, Callbacks);
void reset();
void setTilesOk(bool);
int getStandardLineHeight() const;
PGuiElem getSunlightInfoGui(GameSunlightInfo& sunlightInfo);
PGuiElem getTurnInfoGui(int turn);
PGuiElem drawBottomPlayerInfo(GameInfo&);
PGuiElem drawRightPlayerInfo(PlayerInfo&);
PGuiElem drawPlayerHelp(PlayerInfo&);
PGuiElem drawPlayerInventory(PlayerInfo&);
PGuiElem drawBottomBandInfo(GameInfo&);
PGuiElem drawRightBandInfo(CollectiveInfo&, VillageInfo&);
PGuiElem drawBuildings(CollectiveInfo&);
PGuiElem drawTechnology(CollectiveInfo&);
PGuiElem drawVillages(VillageInfo&);
PGuiElem drawDeities(CollectiveInfo&);
PGuiElem drawMinions(CollectiveInfo&);
PGuiElem drawKeeperHelp();
optional<string> getTextInput(const string& title, const string& value, int maxLength, const string& hint);
struct OverlayInfo {
PGuiElem elem;
Vec2 size;
enum { LEFT, TOP_RIGHT, BOTTOM_RIGHT, MESSAGES, GAME_SPEED, INVISIBLE, MINIONS } alignment;
};
void drawPlayerOverlay(vector<OverlayInfo>&, PlayerInfo&);
void drawBandOverlay(vector<OverlayInfo>&, CollectiveInfo&);
void drawMessages(vector<OverlayInfo>&, const vector<PlayerMessage>&, int guiLength);
void drawGameSpeedDialog(vector<OverlayInfo>&);
typedef function<void(Rectangle, optional<int>)> ItemMenuCallback;
vector<PGuiElem> drawItemMenu(const vector<ItemInfo>&, ItemMenuCallback, bool doneBut = false);
typedef function<void(optional<int>)> CreatureMenuCallback;
PGuiElem drawRecruitMenu(SyncQueue<optional<UniqueEntity<Creature>::Id>>&, const string& title,
const string& warning, pair<ViewId, int> budget, const vector<CreatureInfo>&, double* scrollPos);
PGuiElem drawTradeItemMenu(SyncQueue<optional<UniqueEntity<Item>::Id>>&, const string& title,
pair<ViewId, int> budget, const vector<ItemInfo>&, double* scrollPos);
PGuiElem drawCost(pair<ViewId, int>, ColorId = ColorId::WHITE);
PGuiElem drawHighscores(const vector<HighscoreList>&, Semaphore&, int& tabNum, vector<double>& scrollPos,
bool& online);
enum class CollectiveTab {
BUILDINGS,
MINIONS,
TECHNOLOGY,
VILLAGES,
KEY_MAPPING,
};
void setCollectiveTab(CollectiveTab t);
CollectiveTab getCollectiveTab() const;
enum class MinionTab {
INVENTORY,
HELP,
};
void addFpsCounterTick();
void addUpsCounterTick();
void closeOverlayWindows();
int getActiveBuilding() const;
int getActiveLibrary() const;
GameSpeed getGameSpeed() const;
void setGameSpeed(GameSpeed);
bool showMorale() const;
Rectangle getMenuPosition(MenuType);
Rectangle getMinionMenuPosition();
Rectangle getEquipmentMenuPosition(int height);
Rectangle getTextInputPosition();
PGuiElem drawListGui(const string& title, const vector<ListElem>& options,
MenuType, int* height, int* highlight, int* choice);
int getScrollPos(int index, int count);
void setMapGui(MapGui*);
private:
Renderer& renderer;
GuiFactory& gui;
Clock* clock;
Options* options;
Callbacks callbacks;
PGuiElem getHintCallback(const vector<string>&);
PGuiElem getTooltip(const vector<string>&);
vector<PGuiElem> drawPlayerAttributes(const vector<PlayerInfo::AttributeInfo>&);
PGuiElem drawMinionButtons(const vector<PlayerInfo>&, UniqueEntity<Creature>::Id current, optional<TeamId> teamId);
PGuiElem minionButtonsCache;
int minionButtonsHash = 0;
PGuiElem drawMinionPage(const PlayerInfo&);
PGuiElem drawActivityButton(const PlayerInfo&);
vector<PGuiElem> drawAttributesOnPage(vector<PGuiElem>&&);
vector<PGuiElem> drawEquipmentAndConsumables(const PlayerInfo&);
vector<PGuiElem> drawSkillsList(const PlayerInfo&);
vector<PGuiElem> drawSpellsList(const PlayerInfo&, bool active);
PGuiElem getSpellIcon(const PlayerInfo::Spell&, bool active);
vector<PGuiElem> drawEffectsList(const PlayerInfo&);
vector<PGuiElem> drawMinionActions(const PlayerInfo&);
vector<PGuiElem> joinLists(vector<PGuiElem>&&, vector<PGuiElem>&&);
function<void()> getButtonCallback(UserInput);
void drawMiniMenu(GuiFactory::ListBuilder elems, bool& exit, Vec2 menuPos, int width);
void showAttackTriggers(const vector<TriggerInfo>&, Vec2 pos);
PGuiElem getTextContent(const string& title, const string& value, const string& hint);
PGuiElem getVillageActionButton(int villageIndex, VillageAction);
PGuiElem getVillageStateLabel(VillageInfo::Village::State);
vector<PGuiElem> drawRecruitList(const vector<CreatureInfo>&, CreatureMenuCallback, int budget);
PGuiElem drawHighscorePage(const HighscoreList&, double *scrollPos);
PGuiElem drawTeams(CollectiveInfo&);
PGuiElem teamCache;
int teamHash = 0;
int activeBuilding = 0;
bool hideBuildingOverlay = false;
int activeLibrary = -1;
bool showTasks = false;
bool tilesOk;
double inventoryScroll = 0;
double playerStatsScroll = 0;
double buildingsScroll = 0;
double minionsScroll = 0;
double lyingItemsScroll = 0;
double villagesScroll = 0;
int itemIndex = -1;
int numSeenVillains = -1;
bool playerOverlayFocused = false;
optional<int> lastPlayerPositionHash;
int scrollbarsHeld = GuiFactory::getHeldInitValue();
bool disableTooltip = false;
CollectiveTab collectiveTab = CollectiveTab::BUILDINGS;
MinionTab minionTab = MinionTab::INVENTORY;
bool gameSpeedDialogOpen = false;
atomic<GameSpeed> gameSpeed;
string getGameSpeedName(GameSpeed) const;
string getCurrentGameSpeedName() const;
class FpsCounter {
public:
int getSec();
void addTick();
int getFps();
int lastFps = 0;
int curSec = -1;
int curFps = 0;
sf::Clock clock;
} fpsCounter, upsCounter;
vector<PGuiElem> drawButtons(vector<CollectiveInfo::Button> buttons, int& active, CollectiveTab);
PGuiElem getButtonLine(CollectiveInfo::Button, int num, int& active, CollectiveTab);
void drawMinionsOverlay(vector<OverlayInfo>&, CollectiveInfo&);
PGuiElem minionsOverlayCache;
int minionsOverlayHash = 0;
void drawTasksOverlay(vector<OverlayInfo>&, CollectiveInfo&);
void drawRansomOverlay(vector<OverlayInfo>& ret, const CollectiveInfo::Ransom&);
void drawBuildingsOverlay(vector<OverlayInfo>&, CollectiveInfo&);
void renderMessages(const vector<PlayerMessage>&);
int getNumMessageLines() const;
PGuiElem getStandingGui(double standing);
PGuiElem getItemLine(const ItemInfo&, function<void(Rectangle)> onClick,
function<void()> onMultiClick = nullptr);
vector<string> getItemHint(const ItemInfo&);
bool morale = true;
optional<ItemAction> getItemChoice(const ItemInfo& itemInfo, Vec2 menuPos, bool autoDefault);
vector<PGuiElem> getMultiLine(const string& text, Color, MenuType, int maxWidth);
PGuiElem menuElemMargins(PGuiElem);
PGuiElem getHighlight(MenuType, const string& label, int height);
vector<string> breakText(const string& text, int maxWidth);
string getPlayerTitle(PlayerInfo&);
Event::KeyEvent getHotkeyEvent(char);
MapGui* mapGui = nullptr;
};
RICH_ENUM(GuiBuilder::GameSpeed,
SLOW,
NORMAL,
FAST,
VERY_FAST
);
#endif