xoreos  0.0.5
feedback.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/util.h"
26 #include "src/common/configman.h"
27 
28 #include "src/aurora/talkman.h"
29 
34 
36 
37 const int kStringSec = 2367;
38 
39 namespace Engines {
40 
41 namespace NWN {
42 
43 OptionsFeedbackMenu::OptionsFeedbackMenu(bool isMain, ::Engines::Console *console) : GUI(console) {
44  load("options_feedback");
45 
46  if (isMain) {
47  WidgetPanel *backdrop = new WidgetPanel(*this, "PNL_MAINMENU", "pnl_mainmenu");
48  backdrop->setPosition(0.0f, 0.0f, 100.0f);
49  addWidget(backdrop);
50  }
51 
52  std::list<Widget *> bubbleMode;
53  bubbleMode.push_back(getWidget("BubblesTextOnly"));
54  bubbleMode.push_back(getWidget("BubblesFull"));
55  bubbleMode.push_back(getWidget("BubblesOff"));
56  declareGroup(bubbleMode);
57 
58  std::list<Widget *> targetingFeedback;
59  targetingFeedback.push_back(getWidget("FeedbackNever"));
60  targetingFeedback.push_back(getWidget("FeedbackPause"));
61  targetingFeedback.push_back(getWidget("FeedbackAlways"));
62  declareGroup(targetingFeedback);
63 
64  // TODO: Targeting feedback
65  getWidget("FeedbackNever", true)->setDisabled(true);
66  getWidget("FeedbackPause", true)->setDisabled(true);
67  getWidget("FeedbackAlways", true)->setDisabled(true);
68 
69  // TODO: Floaty text feedback
70  getWidget("FloatyText", true)->setDisabled(true);
71 }
72 
74 }
75 
77  uint32 tooltipDelay = (CLIP(ConfigMan.getInt("tooltipdelay", 100), 100, 2700) / 100) - 1;
78 
79  getSlider("TooltipSlider", true)->setState(tooltipDelay);
80  updateTooltipDelay(tooltipDelay);
81 
82  getCheckBox("MouseoverBox", true)->setState(ConfigMan.getBool("mouseoverfeedback"));
83 
84  uint32 feedbackMode = CLIP(ConfigMan.getInt("feedbackmode", 2), 0, 2);
85  if (feedbackMode == 0)
86  getCheckBox("BubblesOff", true)->setState(true);
87  else if (feedbackMode == 1)
88  getCheckBox("BubblesTextOnly", true)->setState(true);
89  else if (feedbackMode == 2)
90  getCheckBox("BubblesFull", true)->setState(true);
91 
92  GUI::show();
93 }
94 
96  if (widget.getTag() == "TooltipSlider") {
97  dynamic_cast<WidgetSlider &>(widget).setSteps(26);
98  return;
99  }
100 }
101 
103  if ((widget.getTag() == "CancelButton") ||
104  (widget.getTag() == "XButton")) {
105 
106  revertChanges();
107  _returnCode = 1;
108  return;
109  }
110 
111  if (widget.getTag() == "OkButton") {
112 
113  adoptChanges();
114  _returnCode = 2;
115  return;
116  }
117 
118  if (widget.getTag() == "TooltipSlider") {
119  updateTooltipDelay(dynamic_cast<WidgetSlider &>(widget).getState());
120  return;
121  }
122 }
123 
125  WidgetLabel &ttDelayLabel = *getLabel ("ToolTipValue" , true);
126  WidgetSlider &ttDelaySlider = *getSlider("TooltipSlider", true);
127 
128  const float ttDelay = ((float) (ttDelaySlider.getState() + 1)) / 10.0f;
129 
130  const Common::UString secString = TalkMan.getString(kStringSec);
131  const Common::UString ttDelayText =
132  Common::UString::format("%3.1f %s", ttDelay, secString.c_str());
133 
134  ttDelayLabel.setText(ttDelayText);
135 }
136 
138  uint32 tooltipDelay = (getSlider("TooltipSlider", true)->getState() + 1) * 100;
139  ConfigMan.setInt("tooltipdelay", tooltipDelay, true);
140 
141  bool mouseoverFeedback = getCheckBox("MouseoverBox", true)->getState();
142  ConfigMan.setBool("mouseoverfeedback", mouseoverFeedback, true);
143 
144  uint32 feedbackMode = 2;
145  if (getCheckBox("BubblesOff", true)->getState())
146  feedbackMode = 0;
147  else if (getCheckBox("BubblesTextOnly", true)->getState())
148  feedbackMode = 1;
149  else if (getCheckBox("BubblesFull", true)->getState())
150  feedbackMode = 2;
151 
152  ConfigMan.setInt("feedbackmode", feedbackMode, true);
153 }
154 
156 }
157 
158 } // End of namespace NWN
159 
160 } // End of namespace Engines
A NWN panel widget.
Definition: panel.h:41
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: feedback.cpp:102
Widget * getWidget(const Common::UString &tag, bool vital=false)
Return a widget in the GUI.
Definition: gui.cpp:314
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
uint32 _returnCode
The GUI&#39;s return code.
Definition: gui.h:75
A class holding an UTF-8 string.
Definition: ustring.h:48
A NWN slider widget.
The global config manager.
A NWN slider widget.
Definition: slider.h:41
virtual void setDisabled(bool disabled)
Disable/Enable the widget.
Definition: widget.cpp:154
const int kStringSec
Definition: feedback.cpp:37
WidgetCheckBox * getCheckBox(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:246
OptionsFeedbackMenu(bool isMain=false, ::Engines::Console *console=0)
Definition: feedback.cpp:43
void initWidget(Widget &widget)
Definition: feedback.cpp:95
void declareGroup(const std::list< Widget *> &group)
Put these widgets together into a group.
Definition: gui.cpp:340
A NWN checkbox widget.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
virtual void show()
Show the GUI.
Definition: gui.cpp:62
WidgetLabel * getLabel(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:270
void updateTooltipDelay(uint32 tooltipDelay)
Definition: feedback.cpp:124
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
#define ConfigMan
Shortcut for accessing the config manager.
Definition: configman.h:176
#define UNUSED(x)
Definition: system.h:170
A NWN GUI.
Definition: gui.h:54
Utility templates and functions.
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
WidgetSlider * getSlider(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:282
void load(const Common::UString &resref)
Definition: gui.cpp:77
A NWN label widget.
Definition: label.h:41
The NWN feedback options menu.
A widget in a GUI.
Definition: widget.h:40
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: modelwidget.cpp:71
uint32_t uint32
Definition: types.h:204
The global talk manager for Aurora strings.
void setState(int state)
Definition: slider.cpp:69
void show()
Show the GUI.
Definition: feedback.cpp:76
void setState(bool state)
Definition: checkbox.cpp:101
void addWidget(Widget *widget)
Add a widget.
Definition: gui.cpp:250
T CLIP(T v, T amin, T amax)
Definition: util.h:72
A NWN panel widget.
A NWN label widget.
void setText(const Common::UString &text)
Definition: label.cpp:67