Mana
Loading...
Searching...
No Matches
setup_interface.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "gui/setup_interface.h"
23
24#include "configuration.h"
25
26#include "gui/okdialog.h"
29#include "gui/widgets/label.h"
30#include "gui/widgets/layout.h"
31#include "gui/widgets/slider.h"
32#include "gui/widgets/spacer.h"
33
34#include "resources/theme.h"
35
36#include "utils/gettext.h"
37
38#include <guichan/key.hpp>
39#include <guichan/listmodel.hpp>
40
41#include <SDL.h>
42
43#include <algorithm>
44#include <string>
45
46class ThemesListModel : public gcn::ListModel
47{
48public:
49 int getNumberOfElements() override
50 {
51 return gui->getAvailableThemes().size();
52 }
53
54 std::string getElementAt(int i) override
55 {
56 return gui->getAvailableThemes().at(i).getName();
57 }
58
59 static int getThemeIndex(const std::string &path)
60 {
61 auto &themes = gui->getAvailableThemes();
62 auto themeIt = std::find_if(themes.begin(),
63 themes.end(),
64 [&](const ThemeInfo &theme) {
65 return theme.getPath() == path;
66 });
67 return themeIt != themes.end() ? std::distance(themes.begin(), themeIt) : 0;
68 }
69};
70
71
72const char *SIZE_NAME[4] =
73{
74 N_("Tiny"),
75 N_("Small"),
76 N_("Medium"),
77 N_("Large"),
78};
79
80class FontSizeChoiceListModel : public gcn::ListModel
81{
82public:
83 int getNumberOfElements() override
84 {
85 return 4;
86 }
87
88 std::string getElementAt(int i) override
89 {
90 if (i >= getNumberOfElements())
91 return _("???");
92
93 return SIZE_NAME[i];
94 }
95};
96
97static const char *speechModeToString(Being::Speech mode)
98{
99 switch (mode)
100 {
101 case Being::NO_SPEECH: return _("No text");
102 case Being::TEXT_OVERHEAD: return _("Text");
103 case Being::NO_NAME_IN_BUBBLE: return _("Bubbles, no names");
104 case Being::NAME_IN_BUBBLE: return _("Bubbles with names");
105 }
106 return "";
107}
108
110 mShowMonsterDamageEnabled(config.showMonstersTakedDamage),
111 mVisibleNamesEnabled(config.visibleNames),
112 mNameEnabled(config.showOwnName),
113 mNPCLogEnabled(config.logNpcInGui),
114 mPickupChatEnabled(config.showPickupChat),
115 mPickupParticleEnabled(config.showPickupParticle),
116 mOpacity(config.guiAlpha),
117 mSpeechMode(config.speech),
118 mVisibleNamesCheckBox(new CheckBox(_("Visible names"),
119 mVisibleNamesEnabled)),
120 mNameCheckBox(new CheckBox(_("Show own name"), mNameEnabled)),
121 mNPCLogCheckBox(new CheckBox(_("Log NPC dialogue"), mNPCLogEnabled)),
122 mPickupNotifyLabel(new Label(_("Show pickup notification:"))),
123 // TRANSLATORS: Refers to "Show pickup notification"
124 mPickupChatCheckBox(new CheckBox(_("in chat"), mPickupChatEnabled)),
125 // TRANSLATORS: Refers to "Show pickup notification"
126 mPickupParticleCheckBox(new CheckBox(_("as particle"),
127 mPickupParticleEnabled)),
128 mSpeechSlider(new Slider(0, 3)),
129 mSpeechLabel(new Label(std::string())),
130 mAlphaSlider(new Slider(0.2, 1.0))
131{
132 setName(_("Interface"));
133
134 // Create widgets
135 auto *space = new Spacer(0,10);
136
137 mShowMonsterDamageCheckBox = new CheckBox(_("Show damage"),
139
140 gcn::Label *speechLabel = new Label(_("Overhead text:"));
141 gcn::Label *alphaLabel = new Label(_("GUI opacity"));
142 gcn::Label *themeLabel = new Label(_("Theme:"));
143 gcn::Label *fontSizeLabel = new Label(_("Font size:"));
144
145 mThemesListModel = std::make_unique<ThemesListModel>();
147
148 mFontSizeListModel = std::make_unique<FontSizeChoiceListModel>();
150
151 mAlphaSlider->setValue(mOpacity);
152 mAlphaSlider->setWidth(90);
154
155 // Set actions
156 mShowMonsterDamageCheckBox->setActionEventId("monsterdamage");
157 mVisibleNamesCheckBox->setActionEventId("visiblenames");
158 mPickupChatCheckBox->setActionEventId("pickupchat");
159 mPickupParticleCheckBox->setActionEventId("pickupparticle");
160 mNameCheckBox->setActionEventId("showownname");
161 mNPCLogCheckBox->setActionEventId("lognpc");
162 mThemeDropDown->setActionEventId("theme");
163 mAlphaSlider->setActionEventId("guialpha");
164 mSpeechSlider->setActionEventId("speech");
165
166 // Set Listeners
167 mShowMonsterDamageCheckBox->addActionListener(this);
168 mVisibleNamesCheckBox->addActionListener(this);
169 mPickupChatCheckBox->addActionListener(this);
170 mPickupParticleCheckBox->addActionListener(this);
171 mNameCheckBox->addActionListener(this);
172 mNPCLogCheckBox->addActionListener(this);
173 mThemeDropDown->addActionListener(this);
174 mAlphaSlider->addActionListener(this);
175 mSpeechSlider->addActionListener(this);
176
177 mSpeechLabel->setCaption(speechModeToString(mSpeechMode));
178 mSpeechSlider->setValue(mSpeechMode);
179
181
182 mFontSizeDropDown->setSelected(config.fontSize - 10);
183 mFontSizeDropDown->adjustHeight();
184
185 // Do the layout
187 place(3, 0, mNameCheckBox, 3);
188
190 place(3, 1, mNPCLogCheckBox, 3);
191
192 place(0, 2, space, 1, 1);
193
194 place(0, 3, mPickupNotifyLabel, 6);
195
196 place(0, 4, mPickupChatCheckBox, 3);
198
199 place(0, 5, space, 1, 1);
200
201 place(0, 6, themeLabel, 2);
202 place(2, 6, mThemeDropDown, 2).setPadding(2);
203
204 place(0, 7, fontSizeLabel, 2);
206
207 place(0, 8, space, 1, 1);
208
209 place(0, 9, mAlphaSlider, 2);
210 place(2, 9, alphaLabel, 2);
211
212 place(0, 10, mSpeechSlider, 2);
213 place(2, 10, speechLabel, 2);
214 place(4, 10, mSpeechLabel, 2).setPadding(2);
215}
216
218
220{
221 auto &theme = gui->getAvailableThemes().at(mThemeDropDown->getSelected());
222 auto fontSize = mFontSizeDropDown->getSelected() + 10;
223 if (config.theme != theme.getPath() || config.fontSize != fontSize)
224 {
225 new OkDialog(_("Changing Theme or Font Size"),
226 _("Theme and font size changes will apply after restart."));
227 }
228 config.theme = theme.getPath();
229 config.fontSize = fontSize;
230
239}
240
262
263void Setup_Interface::action(const gcn::ActionEvent &event)
264{
265 const std::string &id = event.getId();
266
267 if (id == "guialpha")
268 {
269 setConfigValue<float>(&Config::guiAlpha, mAlphaSlider->getValue());
270 }
271 else if (id == "monsterdamage")
272 {
274 }
275 else if (id == "visiblenames")
276 {
278 }
279 else if (id == "pickupchat")
280 {
282 }
283 else if (id == "pickupparticle")
284 {
286 }
287 else if (id == "speech")
288 {
289 auto val = (Being::Speech)mSpeechSlider->getValue();
290 mSpeechLabel->setCaption(speechModeToString(val));
291 mSpeechSlider->setValue(val);
292 config.speech = val;
293 }
294 else if (id == "showownname")
295 {
297 }
298 else if (id == "lognpc")
299 {
300 config.logNpcInGui = mNPCLogCheckBox->isSelected();
301 }
302}
Speech
Definition being.h:83
@ NAME_IN_BUBBLE
Definition being.h:87
@ NO_NAME_IN_BUBBLE
Definition being.h:86
@ TEXT_OVERHEAD
Definition being.h:85
@ NO_SPEECH
Definition being.h:84
Check box widget.
Definition checkbox.h:32
LayoutCell & place(int x, int y, gcn::Widget *wg, int w=1, int h=1)
Adds a widget to the container and sets it at given cell.
Definition container.cpp:46
A drop down box from which you can select different values.
Definition dropdown.h:34
std::string getElementAt(int i) override
int getNumberOfElements() override
const std::vector< ThemeInfo > & getAvailableThemes() const
Definition gui.h:127
Label widget.
Definition label.h:34
LayoutCell & setPadding(int p)
Sets the padding around the cell content.
Definition layout.h:179
An 'Ok' button dialog.
Definition okdialog.h:34
void setName(const std::string &name)
Sets the name displayed on the tab.
Definition setuptab.h:54
gcn::DropDown * mThemeDropDown
gcn::CheckBox * mVisibleNamesCheckBox
gcn::Slider * mAlphaSlider
gcn::CheckBox * mNameCheckBox
std::unique_ptr< gcn::ListModel > mThemesListModel
gcn::Label * mSpeechLabel
~Setup_Interface() override
void cancel() override
Called when the Cancel button is pressed in the setup window.
void apply() override
Called when the Apply button is pressed in the setup window.
std::unique_ptr< gcn::ListModel > mFontSizeListModel
gcn::DropDown * mFontSizeDropDown
gcn::CheckBox * mNPCLogCheckBox
gcn::CheckBox * mPickupChatCheckBox
Being::Speech mSpeechMode
gcn::Label * mPickupNotifyLabel
gcn::CheckBox * mPickupParticleCheckBox
void action(const gcn::ActionEvent &event) override
gcn::CheckBox * mShowMonsterDamageCheckBox
gcn::Slider * mSpeechSlider
Slider widget.
Definition slider.h:32
A space.
Definition spacer.h:33
int getNumberOfElements() override
std::string getElementAt(int i) override
static int getThemeIndex(const std::string &path)
Config config
Global settings (config.xml)
Definition client.cpp:97
void setConfigValue(T Config::*member, const T &value)
Sets the given Config member and sends a change event.
#define N_(s)
Definition gettext.h:39
#define _(s)
Definition gettext.h:38
Gui * gui
The GUI system.
Definition gui.cpp:50
const char * SIZE_NAME[4]
float guiAlpha
bool showPickupChat
bool visibleNames
Being::Speech speech
bool logNpcInGui
bool showOwnName
bool disableTransparency
bool showPickupParticle
std::string theme
bool showMonstersTakedDamage