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
|
/*
* Gui Skinning
* Copyright (C) 2008 The Legend of Mazzeroth Development Team
* Copyright (C) 2009 Aethyra Development Team
* Copyright (C) 2009 The Mana World Development Team
* Copyright (C) 2009-2012 The Mana Developers
*
* This file is part of The Mana Client.
*
* This program 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
* any later version.
*
* This program 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/>.
*/
#pragma once
#include "graphics.h"
#include "eventlistener.h"
#include "gui/palette.h"
#include "resources/image.h"
#include "utils/xml.h"
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <variant>
namespace gcn {
class Widget;
}
class DyePalette;
class Image;
class ImageSet;
class ProgressBar;
class ThemeInfo
{
public:
ThemeInfo() = default;
explicit ThemeInfo(const std::string &path);
bool isValid() const { return !name.empty(); }
const std::string &getName() const { return name; }
const std::string &getPath() const { return path; }
std::string getFullPath() const;
const XML::Document &getDocument() const { return *doc; }
private:
std::string name;
std::string path;
std::unique_ptr<XML::Document> doc;
};
enum class SkinType
{
Window,
ToolWindow,
Popup,
SpeechBubble,
Button,
ButtonUp,
ButtonDown,
ButtonLeft,
ButtonRight,
ButtonClose,
ButtonSticky,
CheckBox,
RadioButton,
TextField,
Tab,
ScrollArea,
ScrollAreaHBar,
ScrollAreaHMarker,
ScrollAreaVBar,
ScrollAreaVMarker,
DropDownFrame,
DropDownButton,
ProgressBar,
Slider,
SliderHandle,
ResizeGrip,
ShortcutBox,
EquipmentBox,
ItemSlot,
EmoteSlot,
};
enum StateFlags : uint8_t
{
STATE_HOVERED = 0x01,
STATE_SELECTED = 0x02,
STATE_DISABLED = 0x04,
STATE_FOCUSED = 0x08,
};
struct ColoredRectangle
{
gcn::Color color;
bool filled = true;
};
struct SkinPart
{
int offsetX = 0;
int offsetY = 0;
std::variant<ImageRect, Image *, ColoredRectangle> data;
};
struct TextFormat
{
bool bold = false;
gcn::Color color;
std::optional<gcn::Color> outlineColor;
std::optional<gcn::Color> shadowColor;
};
struct SkinState
{
uint8_t stateFlags = 0;
uint8_t setFlags = 0;
TextFormat textFormat;
std::vector<SkinPart> parts;
};
struct WidgetState
{
WidgetState() = default;
explicit WidgetState(const gcn::Widget *widget);
explicit WidgetState(const gcn::Rectangle &dim, uint8_t flags = 0);
int x = 0;
int y = 0;
int width = 0;
int height = 0;
uint8_t flags = 0;
};
class Skin
{
public:
Skin() = default;
~Skin();
void addState(SkinState state);
void draw(Graphics *graphics, const WidgetState &state) const;
const SkinState *getState(uint8_t flags) const;
/**
* Returns the minimum width which can be used with this skin.
*/
int getMinWidth() const;
/**
* Returns the minimum height which can be used with this skin.
*/
int getMinHeight() const;
/**
* Updates the alpha value of the skin
*/
void updateAlpha(float alpha);
int width = 0;
int height = 0;
int frameSize = 0;
int padding = 0;
int spacing = 0;
int titleBarHeight = 0;
int titleOffsetX = 0;
int titleOffsetY = 0;
int palette = 0;
bool showButtons = true;
private:
std::vector<SkinState> mStates;
};
class Theme : public EventListener
{
public:
static std::string prepareThemePath();
static std::vector<ThemeInfo> getAvailableThemes();
Theme(const ThemeInfo &themeInfo);
~Theme() override;
const std::string &getThemePath() const { return mThemePath; }
/**
* Returns the patch to the given GUI resource relative to the theme
* or, if it isn't in the theme, relative to 'graphics/gui'.
*/
std::string resolvePath(const std::string &path) const;
static ResourceRef<Image> getImageFromTheme(const std::string &path);
enum ThemePalette {
TEXT,
BLACK, // Color 0
RED, // Color 1
GREEN, // Color 2
BLUE, // Color 3
ORANGE, // Color 4
YELLOW, // Color 5
PINK, // Color 6
PURPLE, // Color 7
GRAY, // Color 8
BROWN, // Color 9
CARET,
SHADOW,
OUTLINE,
PARTY_TAB,
WHISPER_TAB,
BACKGROUND,
HIGHLIGHT,
TAB_FLASH,
SHOP_WARNING,
ITEM_EQUIPPED,
CHAT,
OLDCHAT,
AWAYCHAT,
BUBBLE_TEXT,
GM,
GLOBAL,
PLAYER,
WHISPER,
IS,
PARTY,
GUILD,
SERVER,
LOGGER,
HYPERLINK,
UNKNOWN_ITEM,
GENERIC,
HEAD,
USABLE,
TORSO,
ONEHAND,
LEGS,
FEET,
TWOHAND,
SHIELD,
RING,
NECKLACE,
ARMS,
AMMO,
SERVER_VERSION_NOT_SUPPORTED,
THEME_COLORS_END
};
enum ProgressPalette {
PROG_DEFAULT,
PROG_HP,
PROG_MP,
PROG_NO_MP,
PROG_EXP,
PROG_INVY_SLOTS,
PROG_WEIGHT,
PROG_JOB,
THEME_PROG_END
};
/**
* Gets the color associated with the type in the default palette (0).
*
* @param type the color type requested
* @return the requested color
*/
static const gcn::Color &getThemeColor(int type);
static gcn::Color getProgressColor(int type, float progress);
const Palette &getPalette(size_t index) const;
/**
* Returns a color from the default palette (0).
*/
const gcn::Color &getColor(int type) const;
/**
* Returns the color ID associated with a character, if it exists.
* Returns no value if the character is not found.
*
* @param c character requested
* @return the requested color or none
*/
static std::optional<int> getColorIdForChar(char c);
void drawSkin(Graphics *graphics, SkinType type, const WidgetState &state) const;
void drawProgressBar(Graphics *graphics,
const gcn::Rectangle &area,
const gcn::Color &color,
float progress,
const std::string &text = std::string()) const;
const Skin &getSkin(SkinType skinType) const;
const Image *getIcon(const std::string &name) const;
/**
* Get the current GUI alpha value.
*/
int getGuiAlpha() const { return static_cast<int>(mAlpha * 255.0f); }
/**
* Get the minimum opacity allowed to skins.
*/
float getMinimumOpacity() const { return mMinimumOpacity; }
/**
* Set the minimum opacity allowed to skins.
* Set a negative value to free the minimum allowed.
*/
void setMinimumOpacity(float minimumOpacity);
void event(Event::Channel channel, const Event &event) override;
private:
/**
* Updates the alpha values of all of the skins and images.
*/
void updateAlpha();
ResourceRef<Image> getImage(const std::string &path) const;
bool readTheme(const ThemeInfo &themeInfo);
void readSkinNode(XML::Node node);
void readSkinStateNode(XML::Node node, Skin &skin) const;
void readSkinStateImgNode(XML::Node node, SkinState &state) const;
void readIconNode(XML::Node node);
void readPaletteNode(XML::Node node);
void readProgressBarNode(XML::Node node);
std::string mThemePath;
std::map<SkinType, Skin> mSkins;
std::map<std::string, Image *> mIcons;
/**
* Tells if the current skins opacity
* should not get less than the given value
*/
float mMinimumOpacity = 0.0f;
float mAlpha = 1.0;
std::vector<Palette> mPalettes;
std::vector<std::unique_ptr<DyePalette>> mProgressColors;
};
|