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-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "gui/dialogsmanager.h"
25 
26 #include "configuration.h"
27 #include "settings.h"
28 
29 #include "being/playerinfo.h"
30 
31 #include "const/sound.h"
32 
34 
36 
37 #ifndef DYECMD
38 #include "gui/widgets/selldialog.h"
39 
41 #include "gui/windows/buydialog.h"
43 
45 #endif // DYECMD
46 
48 
49 #include "net/inventoryhandler.h"
50 
51 #include "resources/db/deaddb.h"
52 #include "resources/db/groupdb.h"
53 
54 #include "utils/gettext.h"
55 
56 #include "debug.h"
57 
58 #ifdef WIN32
59 #undef ERROR
60 #endif // WIN32
61 
62 Window *deathNotice = nullptr;
65 time_t weightNoticeTime = 0;
66 
67 #ifndef DYECMD
68 namespace
69 {
72 } // namespace
73 #endif // DYECMD
74 
78 {
79 }
80 
82 {
83 #ifndef DYECMD
89  if (inventoryHandler != nullptr)
91 #endif // DYECMD
92 
93  if (deathNotice != nullptr)
94  {
96  deathNotice = nullptr;
97  }
98 }
99 
101 {
102 #ifndef DYECMD
106  false,
108 #endif // DYECMD
109 }
110 
111 Window *DialogsManager::openErrorDialog(const std::string &header,
112  const std::string &message,
113  const Modal modal)
114 {
115  if (settings.supportUrl.empty() || config.getBoolValue("hidesupport"))
116  {
117  OkDialog *const dialog = CREATEWIDGETR(OkDialog,
118  header,
119  message,
120  // TRANSLATORS: ok dialog button
121  _("Close"),
123  modal,
125  nullptr,
126  260);
127  return dialog;
128  }
129  ConfirmDialog *const dialog = CREATEWIDGETR(ConfirmDialog,
130  header,
131  strprintf("%s %s", message.c_str(),
132  // TRANSLATORS: error message question
133  _("Do you want to open support page?")),
134  SOUND_ERROR,
135  false,
136  modal,
137  nullptr);
138  return dialog;
139 }
140 
142 {
143 #ifndef DYECMD
144  if (deathNotice == nullptr)
145  {
146  if (GroupDb::isAllowCommand(ServerCommandType::alive))
147  {
149  std::string(),
151  // TRANSLATORS: ok dialog button
152  _("Revive"),
153  // TRANSLATORS: ok dialog button
154  _("GM revive"),
156  false,
157  Modal_false,
158  nullptr);
159  }
160  else
161  {
163  std::string(),
165  // TRANSLATORS: ok dialog button
166  _("Revive"),
168  Modal_false,
170  nullptr,
171  260);
172  }
174  }
175 #endif // DYECMD
176 }
177 
178 #ifndef DYECMD
180  const int64_t oldVal,
181  const int64_t newVal)
182 {
183  if (id == Attributes::TOTAL_WEIGHT)
184  {
185  if ((weightNotice == nullptr) && config.getBoolValue("weightMsg"))
186  {
187  int percent = settings.overweightPercent;
188  if (percent < 1)
189  percent = 50;
190  const int max = PlayerInfo::getAttribute(
191  Attributes::MAX_WEIGHT) * percent / 100;
192  const int total = CAST_S32(oldVal);
193  if (newVal >= max && total < max)
194  {
197  std::string(),
198  // TRANSLATORS: weight message
199  _("You are carrying more than "
200  "half your weight. You are "
201  "unable to regain health."),
202  // TRANSLATORS: ok dialog button
203  _("OK"),
205  Modal_false,
207  nullptr,
208  260);
210  &weightListener);
211  }
212  else if (newVal < max && total >= max)
213  {
216  std::string(),
217  // TRANSLATORS: weight message
218  _("You are carrying less than "
219  "half your weight. You "
220  "can regain health."),
221  // TRANSLATORS: ok dialog button
222  _("OK"),
224  Modal_false,
226  nullptr,
227  260);
229  &weightListener);
230  }
231  }
232  }
233 }
234 #else // DYECMD
235 
237  const int64_t oldVal A_UNUSED,
238  const int64_t newVal A_UNUSED)
239 {
240 }
241 #endif // DYECMD
Attributes ::T AttributesT
Definition: attributes.h:118
volatile time_t cur_time
Definition: timer.cpp:58
#define CAST_S32
Definition: cast.h:30
static void closeAll()
Definition: buydialog.cpp:784
static void closeAll()
bool getBoolValue(const std::string &key) const
static Window * openErrorDialog(const std::string &header, const std::string &message, const Modal modal)
void attributeChanged(const AttributesT id, const int64_t oldVal, const int64_t newVal)
static void closeDialogs()
static void createUpdaterWindow()
virtual void destroyStorage() const =0
static void clearDialogs()
Definition: npcdialog.cpp:1217
static void closeAll()
Definition: npcdialog.cpp:866
static void closeAll()
Definition: selldialog.cpp:415
unsigned int overweightPercent
Definition: settings.h:147
std::string oldUpdates
Definition: settings.h:109
std::string supportUrl
Definition: settings.h:121
std::string updateHost
Definition: settings.h:107
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
Definition: window.h:102
virtual void scheduleDelete()
Definition: window.cpp:831
Configuration config
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:25
Window * deathNotice
time_t weightNoticeTime
DialogsManager * dialogsManager
OkDialog * weightNotice
#define _(s)
Definition: gettext.h:35
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:89
#define A_UNUSED
Definition: localconsts.h:160
const bool Modal_false
Definition: modal.h:30
bool Modal
Definition: modal.h:30
@ TOTAL_WEIGHT
Definition: attributes.h:39
std::string getRandomString()
Definition: deaddb.cpp:103
bool isAllowCommand(const ServerCommandTypeT command)
Definition: groupdb.cpp:410
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:102
PlayerPostDeathListener postDeathListener
Settings settings
Definition: settings.cpp:32
const bool ShowCenter_true
Definition: showcenter.h:30
static const std::string SOUND_ERROR
Definition: sound.h:28
static const std::string SOUND_REQUEST
Definition: sound.h:29
std::string strprintf(const char *const format,...)
UpdaterWindow * updaterWindow