ManaPlus
Public Member Functions | Static Public Member Functions
DialogsManager Class Reference

#include <dialogsmanager.h>

Inheritance diagram for DialogsManager:
AttributeListener PlayerDeathListener

Public Member Functions

 DialogsManager ()
 
void playerDeath ()
 
void attributeChanged (const AttributesT id, const int64_t oldVal, const int64_t newVal)
 
- Public Member Functions inherited from AttributeListener
 AttributeListener ()
 
virtual ~ AttributeListener ()
 
- Public Member Functions inherited from PlayerDeathListener
 PlayerDeathListener ()
 
virtual ~ PlayerDeathListener ()
 

Static Public Member Functions

static void closeDialogs ()
 
static void createUpdaterWindow ()
 
static WindowopenErrorDialog (const std::string &header, const std::string &message, const Modal modal)
 
- Static Public Member Functions inherited from AttributeListener
static void distributeEvent (const AttributesT id, const int64_t oldVal, const int64_t newVal)
 
static void addListener (AttributeListener *const listener)
 
static void removeListener (const AttributeListener *const listener)
 
- Static Public Member Functions inherited from PlayerDeathListener
static void distributeEvent ()
 
static void addListener (PlayerDeathListener *const listener)
 
static void removeListener (const PlayerDeathListener *const listener)
 

Detailed Description

Definition at line 38 of file dialogsmanager.h.

Constructor & Destructor Documentation

◆ DialogsManager()

DialogsManager::DialogsManager ( )

Definition at line 75 of file dialogsmanager.cpp.

Member Function Documentation

◆ attributeChanged()

void DialogsManager::attributeChanged ( const AttributesT  id,
const int64_t  oldVal,
const int64_t  newVal 
)
virtual

Implements AttributeListener.

Definition at line 179 of file dialogsmanager.cpp.

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 }
volatile time_t cur_time
Definition: timer.cpp:58
#define CAST_S32
Definition: cast.h:30
bool getBoolValue(const std::string &key) const
unsigned int overweightPercent
Definition: settings.h:147
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
Configuration config
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:25
time_t weightNoticeTime
OkDialog * weightNotice
#define _(s)
Definition: gettext.h:35
const bool Modal_false
Definition: modal.h:30
@ TOTAL_WEIGHT
Definition: attributes.h:39
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:102
Settings settings
Definition: settings.cpp:32
const bool ShowCenter_true
Definition: showcenter.h:30

References _, Widget::addActionListener(), CAST_S32, config, CREATEWIDGETV, cur_time, PlayerInfo::getAttribute(), Configuration::getBoolValue(), Attributes::MAX_WEIGHT, Modal_false, DialogType::OK, Settings::overweightPercent, settings, ShowCenter_true, Attributes::TOTAL_WEIGHT, anonymous_namespace{dialogsmanager.cpp}::weightListener, weightNotice, and weightNoticeTime.

◆ closeDialogs()

void DialogsManager::closeDialogs ( )
static

Definition at line 81 of file dialogsmanager.cpp.

82 {
83 #ifndef DYECMD
89  if (inventoryHandler != nullptr)
91 #endif // DYECMD
92 
93  if (deathNotice != nullptr)
94  {
96  deathNotice = nullptr;
97  }
98 }
static void closeAll()
Definition: buydialog.cpp:784
static void closeAll()
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
virtual void scheduleDelete()
Definition: window.cpp:831
Window * deathNotice
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:89

References NpcDialog::clearDialogs(), SellDialog::closeAll(), BuyDialog::closeAll(), BuySellDialog::closeAll(), NpcDialog::closeAll(), deathNotice, Net::InventoryHandler::destroyStorage(), inventoryHandler, and Window::scheduleDelete().

Referenced by QuitDialog::action(), PlayerPostDeathListener::action(), and Game::slowLogic().

◆ createUpdaterWindow()

void DialogsManager::createUpdaterWindow ( )
static

Definition at line 100 of file dialogsmanager.cpp.

101 {
102 #ifndef DYECMD
106  false,
108 #endif // DYECMD
109 }
std::string oldUpdates
Definition: settings.h:109
std::string updateHost
Definition: settings.h:107
UpdaterWindow * updaterWindow

References CREATEWIDGETV, UpdateType::Normal, Settings::oldUpdates, settings, Settings::updateHost, and updaterWindow.

◆ openErrorDialog()

Window * DialogsManager::openErrorDialog ( const std::string &  header,
const std::string &  message,
const Modal  modal 
)
static

Definition at line 111 of file dialogsmanager.cpp.

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 }
std::string supportUrl
Definition: settings.h:121
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
static const std::string SOUND_ERROR
Definition: sound.h:28
std::string strprintf(const char *const format,...)

References _, config, CREATEWIDGETR, DialogType::ERROR, Configuration::getBoolValue(), settings, ShowCenter_true, SOUND_ERROR, strprintf(), and Settings::supportUrl.

Referenced by Game::slowLogic().

◆ playerDeath()

void DialogsManager::playerDeath ( )
virtual

Implements PlayerDeathListener.

Definition at line 141 of file dialogsmanager.cpp.

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 }
std::string getRandomString()
Definition: deaddb.cpp:103
bool isAllowCommand(const ServerCommandTypeT command)
Definition: groupdb.cpp:410
PlayerPostDeathListener postDeathListener
static const std::string SOUND_REQUEST
Definition: sound.h:29

References _, Widget::addActionListener(), CREATEWIDGETV, deathNotice, DeadDB::getRandomString(), GroupDb::isAllowCommand(), Modal_false, DialogType::OK, anonymous_namespace{dialogsmanager.cpp}::postDeathListener, ShowCenter_true, and SOUND_REQUEST.


The documentation for this class was generated from the following files: