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 #include "resources/db/groupdb.h"
52 
53 #include "utils/gettext.h"
54 
55 #include "debug.h"
56 
57 #ifdef WIN32
58 #undef ERROR
59 #endif // WIN32
60 
61 Window *deathNotice = nullptr;
64 time_t weightNoticeTime = 0;
65 
66 #ifndef DYECMD
67 namespace
68 {
71 } // namespace
72 #endif // DYECMD
73 
77 {
78 }
79 
81 {
82 #ifndef DYECMD
88  if (inventoryHandler != nullptr)
90 #endif // DYECMD
91 
92  if (deathNotice != nullptr)
93  {
94  deathNotice->scheduleDelete();
95  deathNotice = nullptr;
96  }
97 }
98 
100 {
101 #ifndef DYECMD
105  false,
107 #endif // DYECMD
108 }
109 
110 Window *DialogsManager::openErrorDialog(const std::string &header,
111  const std::string &message,
112  const Modal modal)
113 {
114  if (settings.supportUrl.empty() || config.getBoolValue("hidesupport"))
115  {
116  OkDialog *const dialog = CREATEWIDGETR(OkDialog,
117  header,
118  message,
119  // TRANSLATORS: ok dialog button
120  _("Close"),
122  modal,
124  nullptr,
125  260);
126  return dialog;
127  }
128  ConfirmDialog *const dialog = CREATEWIDGETR(ConfirmDialog,
129  header,
130  strprintf("%s %s", message.c_str(),
131  // TRANSLATORS: error message question
132  _("Do you want to open support page?")),
133  SOUND_ERROR,
134  false,
135  modal,
136  nullptr);
137  return dialog;
138 }
139 
141 {
142 #ifndef DYECMD
143  if (deathNotice == nullptr)
144  {
146  {
147  CREATEWIDGETV(deathNotice, ConfirmDialog,
148  std::string(),
150  // TRANSLATORS: ok dialog button
151  _("Revive"),
152  // TRANSLATORS: ok dialog button
153  _("GM revive"),
155  false,
156  Modal_false,
157  nullptr);
158  }
159  else
160  {
161  CREATEWIDGETV(deathNotice, OkDialog,
162  std::string(),
164  // TRANSLATORS: ok dialog button
165  _("Revive"),
167  Modal_false,
169  nullptr,
170  260);
171  }
172  deathNotice->addActionListener(&postDeathListener);
173  }
174 #endif // DYECMD
175 }
176 
177 #ifndef DYECMD
179  const int64_t oldVal,
180  const int64_t newVal)
181 {
182  if (id == Attributes::TOTAL_WEIGHT)
183  {
184  if ((weightNotice == nullptr) && config.getBoolValue("weightMsg"))
185  {
186  int percent = settings.overweightPercent;
187  if (percent < 1)
188  percent = 50;
189  const int max = PlayerInfo::getAttribute(
190  Attributes::MAX_WEIGHT) * percent / 100;
191  const int total = CAST_S32(oldVal);
192  if (newVal >= max && total < max)
193  {
195  CREATEWIDGETV(weightNotice, OkDialog,
196  std::string(),
197  // TRANSLATORS: weight message
198  _("You are carrying more than "
199  "half your weight. You are "
200  "unable to regain health."),
201  // TRANSLATORS: ok dialog button
202  _("OK"),
204  Modal_false,
206  nullptr,
207  260);
208  weightNotice->addActionListener(
209  &weightListener);
210  }
211  else if (newVal < max && total >= max)
212  {
214  CREATEWIDGETV(weightNotice, OkDialog,
215  std::string(),
216  // TRANSLATORS: weight message
217  _("You are carrying less than "
218  "half your weight. You "
219  "can regain health."),
220  // TRANSLATORS: ok dialog button
221  _("OK"),
223  Modal_false,
225  nullptr,
226  260);
227  weightNotice->addActionListener(
228  &weightListener);
229  }
230  }
231  }
232 }
233 #else // DYECMD
234 
236  const int64_t oldVal A_UNUSED,
237  const int64_t newVal A_UNUSED)
238 {
239 }
240 #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
bool isAllowCommand(const ServerCommandTypeT command)
Definition: groupdb.cpp:409
Definition: window.h:98
Configuration config
static const std::string SOUND_REQUEST
Definition: sound.h:28
std::string supportUrl
Definition: settings.h:119
#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:107
unsigned int overweightPercent
Definition: settings.h:145
const bool ShowCenter_true
Definition: showcenter.h:29
UpdaterWindow * updaterWindow
static void closeAll()
Definition: npcdialog.cpp:865
static void closeDialogs()
Window * deathNotice
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:105
#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