ManaPlus
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends

#include <charselectdialog.h>

Inheritance diagram for CharSelectDialog:
Window ActionListener KeyListener BasicContainer2 MouseListener WidgetListener BasicContainer Widget WidgetDeathListener Widget2

Public Types

enum  SelectAction { Focus = 0 , Choose }
 

Public Member Functions

 CharSelectDialog (LoginData &data)
 
 ~CharSelectDialog ()
 
void action (const ActionEvent &event)
 
void keyPressed (KeyEvent &event)
 
bool selectByName (const std::string &name, const SelectAction action)
 
void askPasswordForDeletion (const int index)
 
void close ()
 
void widgetResized (const Event &event)
 
void updateState ()
 
void postInit ()
 
void setName (const BeingId id, const std::string &newName)
 
- Public Member Functions inherited from Window
 Window (const std::string &caption, const Modal modal, Window *const parent, std::string skin)
 
 ~Window ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void setContentSize (int width, int height)
 
void setLocationRelativeTo (const Widget *const widget)
 
void setLocationHorisontallyRelativeTo (const Widget *const widget)
 
void setLocationRelativeTo (const ImagePosition::Type &position, int offsetX, int offsetY)
 
void setResizable (const bool resize)
 
void redraw ()
 
void widgetMoved (const Event &event)
 
void widgetHidden (const Event &event)
 
void setCloseButton (const bool flag)
 
bool getCloseButton () const
 
void setAllowClose (const bool b)
 
bool getAlowClose () const
 
bool isResizable () const
 
void setMinWidth (const int width)
 
int getMinWidth () const
 
void setMinHeight (const int height)
 
int getMinHeight () const
 
void setMaxWidth (const int width)
 
int getMaxWidth () const
 
void setMaxHeight (const int height)
 
int getMaxHeight () const
 
void setShowTitle (bool flag)
 
void setStickyButton (const bool flag)
 
void setSticky (const bool sticky)
 
bool isSticky () const
 
void setStickyButtonLock (const bool sticky)
 
bool isStickyButtonLock () const
 
virtual void setVisible (Visible visible)
 
void setVisible (const Visible visible, const bool forceSticky)
 
bool isDefaultVisible () const
 
void setDefaultVisible (const bool save)
 
bool willSaveVisible () const
 
void setSaveVisible (const bool save)
 
WindowgetParentWindow () const
 
virtual void scheduleDelete ()
 
void mousePressed (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void mouseEntered (MouseEvent &event)
 
void updateResizeHandler (MouseEvent &event)
 
void setWindowName (const std::string &name)
 
const std::string & getWindowName () const
 
void loadWindowState ()
 
void saveWindowState ()
 
void setDefaultSize (const int defaultX, const int defaultY, int defaultWidth, int defaultHeight)
 
void setDefaultSize ()
 
void setDefaultSize (const int defaultWidth, const int defaultHeight, const ImagePosition::Type &position, const int offsetx, const int offsetY)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w, int h)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w, const int h)
 
ContainerPlacer getPlacer (const int x, const int y)
 
void center ()
 
void centerHorisontally ()
 
void setModal (const Modal modal)
 
Rect getWindowArea () const
 
bool isResizeAllowed (const MouseEvent &event) const
 
void setCaptionFont (Font *font)
 
void enableVisibleSound (bool b)
 
bool isWindowVisible () const
 
void setPadding (int padding)
 
int getPadding () const
 
void setTitleBarHeight (unsigned int height)
 
unsigned int getTitleBarHeight () const
 
void setCaption (const std::string &caption)
 
const std::string & getCaption () const
 
void setAlignment (Graphics::Alignment alignment)
 
Graphics::Alignment getAlignment () const
 
void setMovable (Move movable)
 
bool isMovable () const
 
Rect getChildrenArea ()
 
virtual void resizeToContent ()
 
- Public Member Functions inherited from BasicContainer2
 BasicContainer2 (const Widget2 *const widget)
 
 ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
void focusNext ()
 
void focusPrevious ()
 
void logic ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget * > &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetShown (const Event &event)
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from KeyListener
virtual ~KeyListener ()
 
virtual void keyReleased (KeyEvent &event)
 

Private Member Functions

void attemptCharacterDelete (const int index, const std::string &email)
 
void attemptCharacterSelect (const int index)
 
void setCharacters (const Net::Characters &characters)
 
void setCharacter (Net::Character *const character)
 
void use (const int selected)
 
void lock ()
 
void unlock ()
 
void setLocked (const bool locked)
 

Private Attributes

LoginDatamLoginData
 
ButtonmSwitchLoginButton
 
ButtonmChangePasswordButton
 
ButtonmPlayButton
 
ButtonmInfoButton
 
ButtonmDeleteButton
 
ButtonmRenameButton
 
ButtonmChangePinButton
 
CharacterViewBasemCharacterView
 
std::vector< CharacterDisplay * > mCharacterEntries
 
Net::CharServerHandlermCharServerHandler
 
TextDialogmDeleteDialog
 
int mDeleteIndex
 
bool mLocked
 
bool mSmallScreen
 

Friends

class CharDeleteConfirm
 
class Net::CharServerHandler
 

Additional Inherited Members

- Static Public Member Functions inherited from Window
static void setWindowContainer (WindowContainer *const windowContainer)
 
- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Member Functions inherited from Window
bool canMove () const
 
int getOption (const std::string &name, const int def) const
 
bool getOptionBool (const std::string &name, const bool def) const
 
void setTitlePadding (const int p)
 
int getTitlePadding () const
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Member Functions inherited from KeyListener
 KeyListener ()
 
- Protected Attributes inherited from Window
std::string mCaption
 
Graphics::Alignment mAlignment
 
int mPadding
 
unsigned int mTitleBarHeight
 
Move mMovable
 
int mDragOffsetX
 
int mDragOffsetY
 
bool mMoved
 
SkinmSkin
 
int mDefaultX
 
int mDefaultY
 
int mDefaultWidth
 
int mDefaultHeight
 
int mCaptionOffsetX
 
int mCaptionOffsetY
 
bool mShowTitle
 
bool mLastRedraw
 
- Protected Attributes inherited from BasicContainer2
Opaque mOpaque
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

Character selection dialog.

Definition at line 52 of file charselectdialog.h.

Member Enumeration Documentation

◆ SelectAction

Enumerator
Focus 
Choose 

Definition at line 73 of file charselectdialog.h.

74  {
75  Focus = 0,
76  Choose
77  };

Constructor & Destructor Documentation

◆ CharSelectDialog()

CharSelectDialog::CharSelectDialog ( LoginData data)
explicit

Constructor.

Definition at line 63 of file charselectdialog.cpp.

63  :
64  // TRANSLATORS: char select dialog name
65  Window(strprintf(_("Account %s (last login time %s)"),
66  data.username.c_str(), data.lastLogin.c_str()),
68  nullptr,
69  "char.xml"),
71  KeyListener(),
72  mLoginData(&data),
73  // TRANSLATORS: char select dialog. button.
74  mSwitchLoginButton(new Button(this, _("Switch"), "switch",
75  BUTTON_SKIN, this)),
76  // TRANSLATORS: char select dialog. button.
77  mChangePasswordButton(new Button(this, _("Password"), "change_password",
78  BUTTON_SKIN, this)),
79  // TRANSLATORS: char select dialog. button.
80  mPlayButton(new Button(this, _("Play"), "use", BUTTON_SKIN, this)),
81  // TRANSLATORS: char select dialog. button.
82  mInfoButton(new Button(this, _("Info"), "info", BUTTON_SKIN, this)),
83  // TRANSLATORS: char select dialog. button.
84  mDeleteButton(new Button(this, _("Delete"), "delete", BUTTON_SKIN, this)),
85  // TRANSLATORS: char select dialog. button.
86  mRenameButton(nullptr),
87  mChangePinButton(nullptr),
88  mCharacterView(nullptr),
91  mDeleteDialog(nullptr),
92  mDeleteIndex(-1),
93  mLocked(false),
95  || mainGraphics->getHeight() < 370)
96 {
97  setCloseButton(true);
98  setFocusable(true);
99 
100  ContainerPlacer placer(nullptr, nullptr);
101  placer = getPlacer(0, 0);
102 
103  placer(0, 0, mSwitchLoginButton, 1, 1);
104 
105  int n = 1;
106  placer(n, 0, mChangePasswordButton, 1, 1);
107  n ++;
108  placer(n, 0, mDeleteButton, 1, 1);
109  n ++;
110 #ifdef TMWA_SUPPORT
112 #endif
113  {
114  mRenameButton = new Button(this,
115  // TRANSLATORS: character rename button
116  _("Rename"),
117  "rename",
118  BUTTON_SKIN,
119  this);
120  placer(n, 0, mRenameButton, 1, 1);
121  n ++;
122  }
123 #ifdef TMWA_SUPPORT
125 #endif
126  {
127  mChangePinButton = new Button(this,
128  // TRANSLATORS: change pincode button
129  _("Change pin"),
130  "changepin",
131  BUTTON_SKIN,
132  this);
133  placer(n, 0, mChangePinButton, 1, 1);
134  n ++;
135  }
136  placer(n, 0, mInfoButton, 1, 1);
137  n ++;
138 
139  for (int i = 0; i < CAST_S32(mLoginData->characterSlots); i++)
140  {
141  CharacterDisplay *const character = new CharacterDisplay(this, this);
142  character->setVisible(Visible_false);
143  mCharacterEntries.push_back(character);
144  }
145 
146  placer(0, 2, mPlayButton, 1, 1);
147 
148  if (!mSmallScreen)
149  {
151  this, &mCharacterEntries, mPadding);
152  placer(0, 1, mCharacterView, 10, 1);
153  int sz = 410 + 2 * mPadding;
154  if (config.getIntValue("fontSize") > 18)
155  sz = 500 + 2 * mPadding;
156  const int width = mCharacterView->getWidth() + 2 * mPadding;
157  if (sz < width)
158  sz = width;
159  if (sz > mainGraphics->getWidth())
160  sz = mainGraphics->getWidth();
161  reflowLayout(sz, 0);
162  }
163  else
164  {
165  // TRANSLATORS: char select dialog name
166  setCaption(strprintf(_("Account %s"), mLoginData->username.c_str()));
168  this, &mCharacterEntries, mPadding);
170  - 2 * getPadding());
171  placer(0, 1, mCharacterView, 10, 1);
172  reflowLayout(0, 0);
173  }
174  addKeyListener(this);
175  center();
176 
178  mCharacterView->show(0);
179  updateState();
180 }
const std::string BUTTON_SKIN
Definition: button.h:89
#define CAST_S32
Definition: cast.h:30
Net::CharServerHandler * charServerHandler
Definition: net.cpp:85
Definition: button.h:102
std::vector< CharacterDisplay * > mCharacterEntries
CharacterViewBase * mCharacterView
Net::CharServerHandler * mCharServerHandler
TextDialog * mDeleteDialog
LoginData * mLoginData
Button * mSwitchLoginButton
Button * mChangePasswordButton
virtual void show(const int i)=0
int getIntValue(const std::string &key) const
int getHeight() const
Definition: graphics.cpp:648
int getWidth() const
Definition: graphics.cpp:643
std::string username
Definition: logindata.h:59
uint16_t characterSlots
Definition: logindata.h:77
virtual void setCharSelectDialog(CharSelectDialog *const window) const =0
virtual bool havePincode() const =0
void setVisible(Visible visible)
Definition: widget.cpp:225
void setFocusable(const bool focusable)
Definition: widget.cpp:192
void setWidth(const int width)
Definition: widget.cpp:133
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:272
int getWidth() const
Definition: widget.h:221
void center()
Definition: window.cpp:1417
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1391
void reflowLayout(int w, int h)
Definition: window.cpp:1396
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:109
void setCaption(const std::string &caption)
Definition: window.h:531
int getPadding() const
Definition: window.h:504
void setCloseButton(const bool flag)
Definition: window.cpp:749
int mPadding
Definition: window.h:618
Configuration config
#define _(s)
Definition: gettext.h:35
Graphics * mainGraphics
Definition: graphics.cpp:109
uint32_t data
const bool Modal_false
Definition: modal.h:30
ServerTypeT getNetworkType()
Definition: net.cpp:189
Net::ServerFeatures * serverFeatures
Definition: net.cpp:101
std::string strprintf(const char *const format,...)
const bool Visible_false
Definition: visible.h:30

References _, Widget::addKeyListener(), BUTTON_SKIN, CAST_S32, Window::center(), LoginData::characterSlots, charServerHandler, config, Configuration::getIntValue(), Net::getNetworkType(), Window::getPadding(), Window::getPlacer(), Widget::getWidth(), Graphics::getWidth(), Net::ServerFeatures::havePincode(), mainGraphics, mChangePasswordButton, mChangePinButton, mCharacterEntries, mCharacterView, mDeleteButton, mInfoButton, mLoginData, Window::mPadding, mPlayButton, mRenameButton, mSmallScreen, mSwitchLoginButton, Window::reflowLayout(), serverFeatures, Window::setCaption(), Net::CharServerHandler::setCharSelectDialog(), Window::setCloseButton(), Widget::setFocusable(), Widget::setVisible(), Widget::setWidth(), CharacterViewBase::show(), strprintf(), ServerType::TMWATHENA, updateState(), LoginData::username, and Visible_false.

◆ ~CharSelectDialog()

CharSelectDialog::~CharSelectDialog ( )

Definition at line 182 of file charselectdialog.cpp.

183 {
184  mDeleteDialog = nullptr;
185 }

References mDeleteDialog.

Member Function Documentation

◆ action()

void CharSelectDialog::action ( const ActionEvent actionEvent)
virtual

Called when an action is recieved from a widget. It is used to be able to recieve a notification that an action has occured.

Parameters
actionEventThe event of the action.

Implements ActionListener.

Definition at line 194 of file charselectdialog.cpp.

195 {
196  // Check if a button of a character was pressed
197  const Widget *const sourceParent = event.getSource()->getParent();
198  int selected = -1;
199  for (unsigned int i = 0, fsz = CAST_U32(
200  mCharacterEntries.size());
201  i < fsz;
202  ++i)
203  {
204  if (mCharacterEntries[i] == sourceParent)
205  {
206  selected = i;
207  mCharacterView->show(i);
208  updateState();
209  break;
210  }
211  }
212  if (selected == -1)
213  selected = mCharacterView->getSelected();
214 
215  const std::string &eventId = event.getId();
216  const bool blocked = pincodeManager.isBlocked();
217 
218  if (selected >= 0)
219  {
220  if (blocked)
221  return;
222  if (eventId == "use")
223  {
224  use(selected);
225  return;
226  }
227  else if (eventId == "delete"
228  && (mCharacterEntries[selected]->getCharacter() != nullptr))
229  {
230  CREATEWIDGET(CharDeleteConfirm, this, selected);
231  return;
232  }
233  else if (eventId == "rename"
234  && (mCharacterEntries[selected]->getCharacter() != nullptr))
235  {
236  const LocalPlayer *const player = mCharacterEntries[
237  selected]->getCharacter()->dummy;
238  EditDialog *const dialog = CREATEWIDGETR(EditDialog,
239  // TRANSLATORS: character rename dialog header.
240  _("Please enter new name"),
241  player->getName(),
242  "OK",
243  300,
244  nullptr,
245  Modal_true);
246  charRenameListener.setId(player->getId());
249  }
250  else if (eventId == "info")
251  {
252  Net::Character *const character = mCharacterEntries[
253  selected]->getCharacter();
254  if (character == nullptr)
255  return;
256 
257  const LocalPlayer *const data = character->dummy;
258  if (data == nullptr)
259  return;
260 
261  const std::string strExp = toString(CAST_U64(
263  const std::string msg = strprintf(
264  // TRANSLATORS: char select dialog. player info message.
265  _("Hp: %u/%u\nMp: %u/%u\nLevel: %u\n"
266  "Experience: %s\nMoney: %s"),
267  CAST_U32(
269  CAST_U32(
271  CAST_U32(
273  CAST_U32(
275  CAST_U32(
277  strExp.c_str(),
279  character->data.mAttributes[Attributes::MONEY])).c_str());
280  CREATEWIDGET(OkDialog, data->getName(), msg,
281  // TRANSLATORS: ok dialog button
282  _("OK"),
284  Modal_true,
286  nullptr,
287  260);
288  }
289  }
290  if (eventId == "switch")
291  {
293  close();
294  }
295  else if (eventId == "change_password")
296  {
297  if (blocked)
298  return;
300  }
301  else if (eventId == "change_email")
302  {
303  if (blocked)
304  return;
306  }
307  else if (eventId == "try delete character")
308  {
309  if (blocked)
310  return;
311  if ((mDeleteDialog != nullptr) && mDeleteIndex != -1)
312  {
314  {
316  mDeleteDialog = nullptr;
317  }
319  {
321  mDeleteDialog = nullptr;
322  }
323  else
324  {
326  // TRANSLATORS: error header
327  _("Error"),
328  // TRANSLATORS: error message
329  _("Incorrect password"),
330  // TRANSLATORS: ok dialog button
331  _("OK"),
333  Modal_true,
335  nullptr,
336  260);
337  }
338  }
339  mDeleteIndex = -1;
340  }
341  else if (eventId == "changepin")
342  {
343  if (blocked)
344  return;
347  }
348 }
#define CAST_U32
Definition: cast.h:31
#define CAST_U64
Definition: cast.h:33
CharRenameListener charRenameListener
BeingId getId() const
Definition: actorsprite.h:64
const std::string & getName() const
Definition: being.h:232
void setDialog(EditDialog *const dialog)
void setId(const BeingId id)
void attemptCharacterDelete(const int index, const std::string &email)
void use(const int selected)
int getSelected() const
void setState(const StateT state)
Definition: client.h:66
static std::string savedPassword
Definition: logindialog.h:80
virtual void clear() const =0
virtual bool haveEmailOnDelete() const =0
void setState(const PincodeStateT state)
const std::string & getText() const
Definition: textdialog.cpp:124
Definition: widget.h:99
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
Widget * getParent() const
Definition: widget.h:202
#define CREATEWIDGET(type,...)
Definition: createwidget.h:29
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
Client * client
Definition: client.cpp:118
const bool Modal_true
Definition: modal.h:30
bool msg(InputEvent &event)
Definition: chat.cpp:39
@ PLAYER_MAX_MP
Definition: attributes.h:35
@ PLAYER_BASE_LEVEL
Definition: attributes.h:31
@ PLAYER_MAX_HP
Definition: attributes.h:33
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
@ CHANGEPASSWORD
Definition: state.h:56
@ CHANGEEMAIL
Definition: state.h:59
std::string formatCurrency(const int value)
Definition: unitsdb.cpp:324
PincodeManager pincodeManager
const bool ShowCenter_true
Definition: showcenter.h:30
LocalPlayer * dummy
Definition: character.h:56
PlayerInfoBackend data
Definition: character.h:57
AtrIntMap mAttributes
Definition: playerinfo.h:73

References _, Widget::addActionListener(), attemptCharacterDelete(), CAST_S32, CAST_U32, CAST_U64, PincodeState::Change, State::CHANGEEMAIL, State::CHANGEPASSWORD, charRenameListener, charServerHandler, Net::CharServerHandler::clear(), client, close(), CREATEWIDGET, CREATEWIDGETR, Net::Character::data, data, Net::Character::dummy, DialogType::ERROR, UnitsDb::formatCurrency(), ActorSprite::getId(), Being::getName(), Widget::getParent(), CharacterViewBase::getSelected(), TextDialog::getText(), Net::ServerFeatures::haveEmailOnDelete(), PincodeManager::isBlocked(), PlayerInfoBackend::mAttributes, mCharacterEntries, mCharacterView, mDeleteDialog, mDeleteIndex, Modal_true, Attributes::MONEY, Actions::msg(), pincodeManager, Attributes::PLAYER_BASE_LEVEL, Attributes::PLAYER_EXP, Attributes::PLAYER_HP, Attributes::PLAYER_MAX_HP, Attributes::PLAYER_MAX_MP, Attributes::PLAYER_MP, LoginDialog::savedPassword, serverFeatures, CharRenameListener::setDialog(), CharRenameListener::setId(), PincodeManager::setState(), Client::setState(), CharacterViewBase::show(), ShowCenter_true, DialogType::SILENCE, strprintf(), Catch::toString(), updateState(), PincodeManager::updateState(), and use().

Referenced by keyPressed().

◆ askPasswordForDeletion()

void CharSelectDialog::askPasswordForDeletion ( const int  index)

Definition at line 485 of file charselectdialog.cpp.

486 {
487  mDeleteIndex = index;
489  {
491  // TRANSLATORS: char deletion question.
492  _("Enter your email for deleting character"),
493  // TRANSLATORS: email label.
494  _("Enter email:"),
495  this,
496  false);
497  }
498  else
499  {
501  // TRANSLATORS: char deletion question.
502  _("Enter password for deleting character"),
503  // TRANSLATORS: email label.
504  _("Enter password:"),
505  this,
506  true);
507  }
508  mDeleteDialog->setActionEventId("try delete character");
510 }
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:596
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:25

References _, Widget::addActionListener(), CREATEWIDGETV, Net::ServerFeatures::haveEmailOnDelete(), mDeleteDialog, mDeleteIndex, serverFeatures, and Widget::setActionEventId().

Referenced by CharDeleteConfirm::action().

◆ attemptCharacterDelete()

void CharSelectDialog::attemptCharacterDelete ( const int  index,
const std::string &  email 
)
private

Communicate character deletion to the server.

Definition at line 470 of file charselectdialog.cpp.

472 {
473  if (mLocked)
474  return;
475 
476  if (mCharacterEntries[index] != nullptr)
477  {
479  mCharacterEntries[index]->getCharacter(),
480  email);
481  }
482  lock();
483 }
virtual void deleteCharacter(Net::Character *const character, const std::string &email) const =0

References Net::CharServerHandler::deleteCharacter(), lock(), mCharacterEntries, mCharServerHandler, and mLocked.

Referenced by action().

◆ attemptCharacterSelect()

void CharSelectDialog::attemptCharacterSelect ( const int  index)
private

Communicate character selection to the server.

Definition at line 515 of file charselectdialog.cpp.

516 {
517  if (mLocked || (mCharacterEntries[index] == nullptr))
518  return;
519 
521  if (mCharServerHandler != nullptr)
522  {
524  mCharacterEntries[index]->getCharacter());
525  }
526  lock();
527 }
virtual void chooseCharacter(Net::Character *const character) const =0
virtual void setVisible(Visible visible)
Definition: window.cpp:778

References Net::CharServerHandler::chooseCharacter(), lock(), mCharacterEntries, mCharServerHandler, mLocked, Window::setVisible(), and Visible_false.

Referenced by selectByName(), and use().

◆ close()

void CharSelectDialog::close ( )
virtual

Overrideable functionality for when the window is to close. This allows for class implementations to clean up or do certain actions on window close they couldn't do otherwise.

Reimplemented from Window.

Definition at line 619 of file charselectdialog.cpp.

620 {
622  Window::close();
623 }
virtual void close()
Definition: window.cpp:902
@ SWITCH_LOGIN
Definition: state.h:63

References client, Window::close(), Client::setState(), and State::SWITCH_LOGIN.

Referenced by action().

◆ keyPressed()

void CharSelectDialog::keyPressed ( KeyEvent event)
virtual

Called if a key is pressed when the widget has keyboard focus. If a key is held down the widget will generate multiple key presses.

Parameters
eventDiscribes the event.

Reimplemented from KeyListener.

Definition at line 365 of file charselectdialog.cpp.

366 {
367  const InputActionT actionId = event.getActionId();
368  const bool blocked = pincodeManager.isBlocked();
369  PRAGMA45(GCC diagnostic push)
370  PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
371  switch (actionId)
372  {
374  event.consume();
377  break;
378 
380  {
381  event.consume();
382  int idx = mCharacterView->getSelected();
383  if (idx >= 0)
384  {
385  if ((idx + 1) % SLOTS_PER_ROW == 0)
386  break;
387  idx ++;
388  mCharacterView->show(idx);
389  updateState();
390  }
391  break;
392  }
393 
395  {
396  event.consume();
397  int idx = mCharacterView->getSelected();
398  if (idx >= 0)
399  {
400  if (idx == 0 || idx % SLOTS_PER_ROW == 0)
401  break;
402  idx --;
403  mCharacterView->show(idx);
404  updateState();
405  }
406  break;
407  }
408 
409  case InputAction::GUI_UP:
410  {
411  event.consume();
412  int idx = mCharacterView->getSelected();
413  if (idx >= 0)
414  {
415  if (idx < SLOTS_PER_ROW)
416  break;
417  idx -= SLOTS_PER_ROW;
418  mCharacterView->show(idx);
419  updateState();
420  }
421  break;
422  }
423 
425  {
426  event.consume();
427  int idx = mCharacterView->getSelected();
428  if (idx >= 0)
429  {
431  break;
432  idx += SLOTS_PER_ROW;
433  mCharacterView->show(idx);
434  updateState();
435  }
436  break;
437  }
438 
440  {
441  if (blocked)
442  return;
443  event.consume();
444  const int idx = mCharacterView->getSelected();
445  if (idx >= 0 && (mCharacterEntries[idx] != nullptr)
446  && (mCharacterEntries[idx]->getCharacter() != nullptr))
447  {
448  CREATEWIDGET(CharDeleteConfirm, this, idx);
449  }
450  break;
451  }
452 
454  {
455  if (blocked)
456  return;
457  event.consume();
459  break;
460  }
461  default:
462  break;
463  }
464  PRAGMA45(GCC diagnostic pop)
465 }
static const int SLOTS_PER_ROW
void action(const ActionEvent &event)
const std::string & getActionEventId() const
Definition: widget.h:605
PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wredundant-decls") PRAGMA45(GCC diagnostic pop) class TestMain
InputAction ::T InputActionT
Definition: inputaction.h:717

References action(), LoginData::characterSlots, CREATEWIDGET, Widget::getActionEventId(), CharacterViewBase::getSelected(), InputAction::GUI_CANCEL, InputAction::GUI_DELETE, InputAction::GUI_DOWN, InputAction::GUI_LEFT, InputAction::GUI_RIGHT, InputAction::GUI_SELECT, InputAction::GUI_UP, PincodeManager::isBlocked(), mCharacterEntries, mCharacterView, mLoginData, mSwitchLoginButton, pincodeManager, PRAGMA45(), CharacterViewBase::show(), SLOTS_PER_ROW, updateState(), and use().

◆ lock()

void CharSelectDialog::lock ( )
private

Definition at line 559 of file charselectdialog.cpp.

560 {
561  if (!mLocked)
562  setLocked(true);
563 }
void setLocked(const bool locked)

References mLocked, and setLocked().

Referenced by attemptCharacterDelete(), and attemptCharacterSelect().

◆ postInit()

void CharSelectDialog::postInit ( )
virtual

Reimplemented from Window.

Definition at line 187 of file charselectdialog.cpp.

188 {
191  requestFocus();
192 }
virtual void requestFocus()
Definition: widget.cpp:204
void postInit()
Definition: window.cpp:249
const bool Visible_true
Definition: visible.h:30

References Window::postInit(), Widget::requestFocus(), Window::setVisible(), and Visible_true.

◆ selectByName()

bool CharSelectDialog::selectByName ( const std::string &  name,
const SelectAction  action 
)

Attempt to select the character with the given name. Returns whether a character with the given name was found.

Parameters
actiondetermines what to do when a character with the given name was found (just focus or also try to choose this character).

Definition at line 589 of file charselectdialog.cpp.

591 {
592  if (mLocked)
593  return false;
594 
595  for (size_t i = 0, sz = mCharacterEntries.size(); i < sz; ++i)
596  {
597  if (mCharacterEntries[i] != nullptr)
598  {
599  const Net::Character *const character
600  = mCharacterEntries[i]->getCharacter();
601  if (character != nullptr)
602  {
603  if (character->dummy != nullptr &&
604  character->dummy->getName() == name)
605  {
607  updateState();
608  if (selAction == Choose)
610  return true;
611  }
612  }
613  }
614  }
615 
616  return false;
617 }
void attemptCharacterSelect(const int index)

References attemptCharacterSelect(), CAST_S32, Choose, Net::Character::dummy, Being::getName(), mCharacterEntries, mCharacterView, mLocked, CharacterViewBase::show(), and updateState().

◆ setCharacter()

void CharSelectDialog::setCharacter ( Net::Character *const  character)
private

Definition at line 544 of file charselectdialog.cpp.

545 {
546  if (character == nullptr)
547  return;
548  const int characterSlot = character->slot;
549  if (characterSlot >= CAST_S32(mCharacterEntries.size()))
550  {
551  logger->log("Warning: slot out of range: %d", character->slot);
552  return;
553  }
554 
555  if (mCharacterEntries[characterSlot] != nullptr)
556  mCharacterEntries[characterSlot]->setCharacter(character);
557 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
Logger * logger
Definition: logger.cpp:89
uint16_t slot
Definition: character.h:58

References CAST_S32, Logger::log(), logger, mCharacterEntries, and Net::Character::slot.

Referenced by setCharacters().

◆ setCharacters()

void CharSelectDialog::setCharacters ( const Net::Characters characters)
private

Definition at line 529 of file charselectdialog.cpp.

530 {
531  // Reset previous characters
532  FOR_EACH (STD_VECTOR<CharacterDisplay*>::const_iterator,
533  iter, mCharacterEntries)
534  {
535  if (*iter != nullptr)
536  (*iter)->setCharacter(nullptr);
537  }
538 
539  FOR_EACH (Net::Characters::const_iterator, i, characters)
540  setCharacter(*i);
541  updateState();
542 }
void setCharacter(Net::Character *const character)
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25

References FOR_EACH, mCharacterEntries, setCharacter(), and updateState().

Referenced by Net::CharServerHandler::updateCharSelectDialog().

◆ setLocked()

void CharSelectDialog::setLocked ( const bool  locked)
private

Definition at line 570 of file charselectdialog.cpp.

571 {
572  mLocked = locked;
573 
574  if (mSwitchLoginButton != nullptr)
575  mSwitchLoginButton->setEnabled(!locked);
576  if (mChangePasswordButton != nullptr)
578  mPlayButton->setEnabled(!locked);
579  if (mDeleteButton != nullptr)
580  mDeleteButton->setEnabled(!locked);
581 
582  for (size_t i = 0, sz = mCharacterEntries.size(); i < sz; ++i)
583  {
584  if (mCharacterEntries[i] != nullptr)
585  mCharacterEntries[i]->setActive(!mLocked);
586  }
587 }
void setEnabled(const bool enabled)
Definition: widget.h:352

References mChangePasswordButton, mCharacterEntries, mDeleteButton, mLocked, mPlayButton, mSwitchLoginButton, and Widget::setEnabled().

Referenced by lock(), and unlock().

◆ setName()

void CharSelectDialog::setName ( const BeingId  id,
const std::string &  newName 
)

Definition at line 659 of file charselectdialog.cpp.

660 {
661  for (unsigned int i = 0, fsz = CAST_U32(
662  mCharacterEntries.size());
663  i < fsz;
664  ++i)
665  {
666  CharacterDisplay *const character = mCharacterEntries[i];
667  if (character == nullptr)
668  continue;
669  LocalPlayer *const player = character->getCharacter()->dummy;
670  if ((player != nullptr) && player->getId() == id)
671  {
672  player->setName(newName);
673  character->update();
674  return;
675  }
676  }
677 }
void setName(const std::string &name)
Definition: being.cpp:1136
Net::Character * getCharacter() const

References CAST_U32, Net::Character::dummy, CharacterDisplay::getCharacter(), ActorSprite::getId(), mCharacterEntries, Being::setName(), and CharacterDisplay::update().

Referenced by EAthena::CharServerRecv::processCharRename().

◆ unlock()

void CharSelectDialog::unlock ( )
private

Definition at line 565 of file charselectdialog.cpp.

566 {
567  setLocked(false);
568 }

References setLocked().

Referenced by Net::CharServerHandler::unlockCharSelectDialog().

◆ updateState()

void CharSelectDialog::updateState ( )

Definition at line 631 of file charselectdialog.cpp.

632 {
633  const int idx = mCharacterView->getSelected();
634  if (idx == -1)
635  {
636  mPlayButton->setEnabled(false);
637  return;
638  }
639  mPlayButton->setEnabled(true);
640 
641  if (mCharacterEntries[idx] != nullptr &&
642  mCharacterEntries[idx]->getCharacter() != nullptr)
643  {
644  // TRANSLATORS: char select dialog. button.
645  mPlayButton->setCaption(_("Play"));
646 
647  const LocalPlayer *const player = mCharacterEntries[
648  idx]->getCharacter()->dummy;
649  if ((player != nullptr) && (mRenameButton != nullptr))
650  mRenameButton->setEnabled(player->getRename() ? true : false);
651  }
652  else
653  {
654  // TRANSLATORS: char select dialog. button.
655  mPlayButton->setCaption(_("Create"));
656  }
657 }
void setCaption(const std::string &caption)
Definition: button.h:214
bool getRename() const
Definition: localplayer.h:425

References _, LocalPlayer::getRename(), CharacterViewBase::getSelected(), mCharacterEntries, mCharacterView, mPlayButton, mRenameButton, Button::setCaption(), and Widget::setEnabled().

Referenced by CharacterViewSmall::action(), action(), CharSelectDialog(), keyPressed(), selectByName(), and setCharacters().

◆ use()

void CharSelectDialog::use ( const int  selected)
private

Definition at line 350 of file charselectdialog.cpp.

351 {
352  if ((mCharacterEntries[selected] != nullptr)
353  && (mCharacterEntries[selected]->getCharacter() != nullptr))
354  {
355  attemptCharacterSelect(selected);
356  }
357  else
358  {
359  CharCreateDialog *const charCreateDialog =
360  CREATEWIDGETR(CharCreateDialog, this, selected);
361  mCharServerHandler->setCharCreateDialog(charCreateDialog);
362  }
363 }
virtual void setCharCreateDialog(CharCreateDialog *const window) const =0

References attemptCharacterSelect(), CREATEWIDGETR, mCharacterEntries, mCharServerHandler, and Net::CharServerHandler::setCharCreateDialog().

Referenced by action(), and keyPressed().

◆ widgetResized()

void CharSelectDialog::widgetResized ( const Event event)
virtual

Called whenever the widget changes size.

Reimplemented from Window.

Definition at line 625 of file charselectdialog.cpp.

626 {
627  Window::widgetResized(event);
629 }
virtual void resize()=0
void widgetResized(const Event &event)
Definition: window.cpp:655

References mCharacterView, CharacterViewBase::resize(), and Window::widgetResized().

Friends And Related Function Documentation

◆ CharDeleteConfirm

friend class CharDeleteConfirm
friend

Definition at line 57 of file charselectdialog.h.

◆ Net::CharServerHandler

friend class Net::CharServerHandler
friend

Definition at line 58 of file charselectdialog.h.

Field Documentation

◆ mChangePasswordButton

Button* CharSelectDialog::mChangePasswordButton
private

Definition at line 121 of file charselectdialog.h.

Referenced by CharSelectDialog(), and setLocked().

◆ mChangePinButton

Button* CharSelectDialog::mChangePinButton
private

Definition at line 126 of file charselectdialog.h.

Referenced by CharSelectDialog().

◆ mCharacterEntries

std::vector<CharacterDisplay*> CharSelectDialog::mCharacterEntries
private

◆ mCharacterView

CharacterViewBase* CharSelectDialog::mCharacterView
private

◆ mCharServerHandler

Net::CharServerHandler* CharSelectDialog::mCharServerHandler
private

Definition at line 131 of file charselectdialog.h.

Referenced by attemptCharacterDelete(), attemptCharacterSelect(), and use().

◆ mDeleteButton

Button* CharSelectDialog::mDeleteButton
private

Definition at line 124 of file charselectdialog.h.

Referenced by CharSelectDialog(), and setLocked().

◆ mDeleteDialog

TextDialog* CharSelectDialog::mDeleteDialog
private

Definition at line 132 of file charselectdialog.h.

Referenced by action(), askPasswordForDeletion(), and ~CharSelectDialog().

◆ mDeleteIndex

int CharSelectDialog::mDeleteIndex
private

Definition at line 133 of file charselectdialog.h.

Referenced by action(), and askPasswordForDeletion().

◆ mInfoButton

Button* CharSelectDialog::mInfoButton
private

Definition at line 123 of file charselectdialog.h.

Referenced by CharSelectDialog().

◆ mLocked

bool CharSelectDialog::mLocked
private

◆ mLoginData

LoginData* CharSelectDialog::mLoginData
private

Definition at line 118 of file charselectdialog.h.

Referenced by CharSelectDialog(), and keyPressed().

◆ mPlayButton

Button* CharSelectDialog::mPlayButton
private

Definition at line 122 of file charselectdialog.h.

Referenced by CharSelectDialog(), setLocked(), and updateState().

◆ mRenameButton

Button* CharSelectDialog::mRenameButton
private

Definition at line 125 of file charselectdialog.h.

Referenced by CharSelectDialog(), and updateState().

◆ mSmallScreen

bool CharSelectDialog::mSmallScreen
private

Definition at line 135 of file charselectdialog.h.

Referenced by CharSelectDialog().

◆ mSwitchLoginButton

Button* CharSelectDialog::mSwitchLoginButton
private

Definition at line 120 of file charselectdialog.h.

Referenced by CharSelectDialog(), keyPressed(), and setLocked().


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