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
|
/*
* The ManaPlus Client
* Copyright (C) 2013-2015 The ManaPlus Developers
*
* This file is part of The ManaPlus 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/>.
*/
#include "gui/windows/emotewindow.h"
#include "gui/models/colormodel.h"
#include "gui/models/namesmodel.h"
#include "gui/windows/setupwindow.h"
#include "gui/widgets/colorpage.h"
#include "gui/widgets/emotepage.h"
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/tabbedarea.h"
#include "utils/delete2.h"
#include "utils/gettext.h"
#include "resources/image.h"
#include "resources/imageset.h"
#include "debug.h"
EmoteWindow *emoteWindow = nullptr;
static const int fontSizeListSize = 2;
static const char *const fontSizeList[] =
{
// TRANSLATORS: font size
N_("Normal font"),
// TRANSLATORS: font size
N_("Bold font"),
};
EmoteWindow::EmoteWindow() :
// TRANSLATORS: emotes window name
Window(_("Emotes"), false, nullptr, "emotes.xml"),
mTabs(new TabbedArea(this)),
mEmotePage(new EmotePage(this)),
mColorModel(ColorModel::createDefault(this)),
mColorPage(new ColorPage(this, mColorModel, "colorpage.xml")),
mScrollColorPage(new ScrollArea(this, mColorPage, false, "emotepage.xml")),
mFontModel(new NamesModel),
mFontPage(new ListBox(this, mFontModel, "")),
mScrollFontPage(new ScrollArea(this, mFontPage, false, "fontpage.xml")),
mImageSet(Theme::getImageSetFromThemeXml("emotetabs.xml", "", 17, 16))
{
mTabs->postInit();
mColorPage->postInit();
mFontPage->postInit();
setShowTitle(false);
setResizable(true);
if (setupWindow)
setupWindow->registerWindowForReset(this);
addMouseListener(this);
}
void EmoteWindow::postInit()
{
const int pad2 = mPadding * 2;
const int width = 200;
const int height = 150;
setWidth(width + pad2);
setHeight(height + pad2);
add(mTabs);
mTabs->setPosition(mPadding, mPadding);
mTabs->setWidth(width);
mTabs->setHeight(height);
center();
setTitleBarHeight(getPadding() + getTitlePadding());
mScrollColorPage->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
mScrollColorPage->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
mScrollFontPage->setVerticalScrollPolicy(ScrollArea::SHOW_NEVER);
mScrollFontPage->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
mFontModel->fillFromArray(&fontSizeList[0], fontSizeListSize);
mFontPage->setCenter(true);
if (mImageSet && mImageSet->size() >= 3)
{
for (int f = 0; f < 3; f ++)
{
Image *const image = mImageSet->get(f);
if (image)
image->incRef();
}
mTabs->addTab(mImageSet->get(0), mEmotePage);
mTabs->addTab(mImageSet->get(2), mScrollColorPage);
mTabs->addTab(mImageSet->get(1), mScrollFontPage);
}
else
{
// TRANSLATORS: emotes tab name
mTabs->addTab(_("Emotes"), mEmotePage);
// TRANSLATORS: emotes tab name
mTabs->addTab(_("Colors"), mScrollColorPage);
// TRANSLATORS: emotes tab name
mTabs->addTab(_("Fonts"), mScrollFontPage);
}
mEmotePage->setActionEventId("emote");
mColorPage->setActionEventId("color");
mFontPage->setActionEventId("font");
}
EmoteWindow::~EmoteWindow()
{
mTabs->removeAll(false);
mTabs->removeTab(mTabs->getTabByIndex(0));
delete2(mEmotePage);
delete2(mColorPage);
delete2(mColorModel);
delete2(mScrollColorPage);
delete2(mFontPage);
delete2(mFontModel);
delete2(mScrollFontPage);
if (mImageSet)
{
mImageSet->decRef();
mImageSet = nullptr;
}
}
void EmoteWindow::show()
{
setVisible(true);
}
void EmoteWindow::hide()
{
setVisible(false);
}
std::string EmoteWindow::getSelectedEmote() const
{
const int index = mEmotePage->getSelectedIndex();
if (index < 0)
return std::string();
char chr[2];
chr[0] = static_cast<char>('0' + index);
chr[1] = 0;
return std::string("%%").append(&chr[0]);
}
void EmoteWindow::clearEmote()
{
const int index = mEmotePage->getSelectedIndex();
mEmotePage->resetAction();
if (index >= 0)
setVisible(false);
}
std::string EmoteWindow::getSelectedColor() const
{
const int index = mColorPage->getSelected();
if (index < 0)
return std::string();
char chr[2];
chr[0] = static_cast<char>('0' + index);
chr[1] = 0;
return std::string("##").append(&chr[0]);
}
void EmoteWindow::clearColor()
{
mColorPage->resetAction();
setVisible(false);
}
std::string EmoteWindow::getSelectedFont() const
{
const int index = mFontPage->getSelected();
if (index < 0)
return std::string();
if (!index)
return "##b";
else
return "##B";
}
void EmoteWindow::clearFont()
{
mFontPage->setSelected(-1);
setVisible(false);
}
void EmoteWindow::addListeners(ActionListener *const listener)
{
mEmotePage->addActionListener(listener);
mColorPage->addActionListener(listener);
mFontPage->addActionListener(listener);
}
void EmoteWindow::widgetResized(const Event &event)
{
Window::widgetResized(event);
const int pad2 = mPadding * 2;
const int width = mDimension.width;
const int height = mDimension.height;
mTabs->setSize(width - pad2, height - pad2);
mTabs->adjustWidget(mEmotePage);
mTabs->adjustWidget(mScrollColorPage);
mColorPage->setSize(mScrollColorPage->getWidth(),
mScrollColorPage->getHeight());
mEmotePage->widgetResized(event);
}
void EmoteWindow::widgetMoved(const Event &event)
{
Window::widgetMoved(event);
mEmotePage->widgetResized(event);
}
|