ManaPlus
dialogsmanager.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2018 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "gui/dialogsmanager.h"
24 
25 #include "configuration.h"
26 #include "settings.h"
27 
28 #include "being/playerinfo.h"
29 
30 #include "const/sound.h"
31 
33 
35 
36 #ifndef DYECMD
37 #include "gui/widgets/selldialog.h"
38 
40 #include "gui/windows/buydialog.h"
42 
44 #endif // DYECMD
45 
47 
48 #include "net/inventoryhandler.h"
49 
50 #include "resources/db/deaddb.h"
51 
52 #include "utils/gettext.h"
53 
54 #include "debug.h"
55 
56 #ifdef WIN32
57 #undef ERROR
58 #endif // WIN32
59 
60 OkDialog *deathNotice = nullptr;
63 time_t weightNoticeTime = 0;
64 
65 #ifndef DYECMD
66 namespace
67 {
70 } // namespace
71 #endif // DYECMD
72 
76 {
77 }
78 
80 {
81 #ifndef DYECMD
87  if (inventoryHandler != nullptr)
89 #endif // DYECMD
90 
91  if (deathNotice != nullptr)
92  {
93  deathNotice->scheduleDelete();
94  deathNotice = nullptr;
95  }
96 }
97 
99 {
100 #ifndef DYECMD
104  false,
106 #endif // DYECMD
107 }
108 
109 Window *DialogsManager::openErrorDialog(const std::string &header,
110  const std::string &message,
111  const Modal modal)
112 {
113  if (settings.supportUrl.empty() || config.getBoolValue("hidesupport"))
114  {
115  OkDialog *const dialog = CREATEWIDGETR(OkDialog,
116  header,
117  message,
118  // TRANSLATORS: ok dialog button
119  _("Close"),
121  modal,
123  nullptr,
124  260);
125  return dialog;
126  }
127  ConfirmDialog *const dialog = CREATEWIDGETR(ConfirmDialog,
128  header,
129  strprintf("%s %s", message.c_str(),
130  // TRANSLATORS: error message question
131  _("Do you want to open support page?")),
132  SOUND_ERROR,
133  false,
134  modal,
135  nullptr);
136  return dialog;
137 }
138 
140 {
141 #ifndef DYECMD
142  if (deathNotice == nullptr)
143  {
144  CREATEWIDGETV(deathNotice, OkDialog,
145  // TRANSLATORS: message header
146  _("Message"),
148  // TRANSLATORS: ok dialog button
149  _("Revive"),
151  Modal_false,
153  nullptr,
154  260);
155  deathNotice->addActionListener(&postDeathListener);
156  }
157 #endif // DYECMD
158 }
159 
160 #ifndef DYECMD
162  const int64_t oldVal,
163  const int64_t newVal)
164 {
165  if (id == Attributes::TOTAL_WEIGHT)
166  {
167  if ((weightNotice == nullptr) && config.getBoolValue("weightMsg"))
168  {
169  int percent = settings.overweightPercent;
170  if (percent < 1)
171  percent = 50;
172  const int max = PlayerInfo::getAttribute(
173  Attributes::MAX_WEIGHT) * percent / 100;
174  const int total = CAST_S32(oldVal);
175  if (newVal >= max && total < max)
176  {
178  CREATEWIDGETV(weightNotice, OkDialog,
179  // TRANSLATORS: message header
180  _("Message"),
181  // TRANSLATORS: weight message
182  _("You are carrying more than "
183  "half your weight. You are "
184  "unable to regain health."),
185  // TRANSLATORS: ok dialog button
186  _("OK"),
188  Modal_false,
190  nullptr,
191  260);
192  weightNotice->addActionListener(
193  &weightListener);
194  }
195  else if (newVal < max && total >= max)
196  {
198  CREATEWIDGETV(weightNotice, OkDialog,
199  // TRANSLATORS: message header
200  _("Message"),
201  // TRANSLATORS: weight message
202  _("You are carrying less than "
203  "half your weight. You "
204  "can regain health."),
205  // TRANSLATORS: ok dialog button
206  _("OK"),
208  Modal_false,
210  nullptr,
211  260);
212  weightNotice->addActionListener(
213  &weightListener);
214  }
215  }
216  }
217 }
218 #else // DYECMD
219 
221  const int64_t oldVal A_UNUSED,
222  const int64_t newVal A_UNUSED)
223 {
224 }
225 #endif // DYECMD
std::string getRandomString()
Definition: deaddb.cpp:102
#define _(s)
Definition: gettext.h:34
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
PlayerPostDeathListener postDeathListener
OkDialog * deathNotice
Definition: window.h:98
Configuration config
std::string supportUrl
Definition: settings.h:118
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:24
static void createUpdaterWindow()
static void closeAll()
Settings settings
Definition: settings.cpp:31
bool getBoolValue(const std::string &key) const
#define CAST_S32
Definition: cast.h:29
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
OkDialog * weightNotice
std::string oldUpdates
Definition: settings.h:106
unsigned int overweightPercent
Definition: settings.h:144
const bool ShowCenter_true
Definition: showcenter.h:29
UpdaterWindow * updaterWindow
static void closeAll()
Definition: npcdialog.cpp:865
static void closeDialogs()
volatile time_t cur_time
Definition: timer.cpp:57
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:85
virtual void scheduleDelete()
Definition: window.cpp:826
static const std::string SOUND_ERROR
Definition: sound.h:27
static void clearDialogs()
Definition: npcdialog.cpp:1216
#define A_UNUSED
Definition: localconsts.h:151
Attributes ::T AttributesT
Definition: attributes.h:117
void attributeChanged(const AttributesT id, const int64_t oldVal, const int64_t newVal)
static void closeAll()
Definition: buydialog.cpp:775
std::string updateHost
Definition: settings.h:104
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
static Window * openErrorDialog(const std::string &header, const std::string &message, const Modal modal)
static void closeAll()
Definition: selldialog.cpp:414
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:100
DialogsManager * dialogsManager
time_t weightNoticeTime
virtual void destroyStorage() const =0