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=Focus)
 
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="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
 
virtual ~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=0, int offsetY=0)
 
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=0, const int offsetY=0)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w=0, int h=0)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w=1, const int h=1)
 
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)
 
virtual ~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)
 
virtual ~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)
 
virtual ~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=255U) 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
 
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=0) const
 
bool getOptionBool (const std::string &name, const bool def=false) 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 51 of file charselectdialog.h.

Member Enumeration Documentation

◆ SelectAction

Enumerator
Focus 
Choose 

Definition at line 72 of file charselectdialog.h.

Constructor & Destructor Documentation

◆ CharSelectDialog()

CharSelectDialog::CharSelectDialog ( LoginData data)
explicit

Constructor.

Definition at line 62 of file charselectdialog.cpp.

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

62  :
63  // TRANSLATORS: char select dialog name
64  Window(strprintf(_("Account %s (last login time %s)"),
65  data.username.c_str(), data.lastLogin.c_str()),
67  nullptr,
68  "char.xml"),
70  KeyListener(),
71  mLoginData(&data),
72  // TRANSLATORS: char select dialog. button.
73  mSwitchLoginButton(new Button(this, _("Switch"), "switch", this)),
74  // TRANSLATORS: char select dialog. button.
75  mChangePasswordButton(new Button(this, _("Password"),
76  "change_password", this)),
77  // TRANSLATORS: char select dialog. button.
78  mPlayButton(new Button(this, _("Play"), "use", this)),
79  // TRANSLATORS: char select dialog. button.
80  mInfoButton(new Button(this, _("Info"), "info", this)),
81  // TRANSLATORS: char select dialog. button.
82  mDeleteButton(new Button(this, _("Delete"), "delete", this)),
83  // TRANSLATORS: char select dialog. button.
84  mRenameButton(nullptr),
85  mCharacterView(nullptr),
88  mDeleteDialog(nullptr),
89  mDeleteIndex(-1),
90  mLocked(false),
92  || mainGraphics->getHeight() < 370)
93 {
94  setCloseButton(true);
95  setFocusable(true);
96 
97  ContainerPlacer placer;
98  placer = getPlacer(0, 0);
99 
100  placer(0, 0, mSwitchLoginButton);
101 
102  int n = 1;
103  placer(n, 0, mChangePasswordButton);
104  n ++;
105  placer(n, 0, mDeleteButton);
106  n ++;
107 #ifdef TMWA_SUPPORT
109 #endif
110  {
111  mRenameButton = new Button(this,
112  // TRANSLATORS: character rename button
113  _("Rename"),
114  "rename",
115  this);
116  placer(n, 0, mRenameButton);
117  n ++;
118  }
119  placer(n, 0, mInfoButton);
120  n ++;
121 
122  for (int i = 0; i < CAST_S32(mLoginData->characterSlots); i++)
123  {
124  CharacterDisplay *const character = new CharacterDisplay(this, this);
125  character->setVisible(Visible_false);
126  mCharacterEntries.push_back(character);
127  }
128 
129  placer(0, 2, mPlayButton);
130 
131  if (!mSmallScreen)
132  {
134  this, &mCharacterEntries, mPadding);
135  placer(0, 1, mCharacterView, 10);
136  int sz = 410 + 2 * mPadding;
137  if (config.getIntValue("fontSize") > 18)
138  sz = 500 + 2 * mPadding;
139  const int width = mCharacterView->getWidth() + 2 * mPadding;
140  if (sz < width)
141  sz = width;
142  if (sz > mainGraphics->getWidth())
143  sz = mainGraphics->getWidth();
144  reflowLayout(sz);
145  }
146  else
147  {
148  // TRANSLATORS: char select dialog name
149  setCaption(strprintf(_("Account %s"), mLoginData->username.c_str()));
151  this, &mCharacterEntries, mPadding);
153  - 2 * getPadding());
154  placer(0, 1, mCharacterView, 10);
155  reflowLayout();
156  }
157  addKeyListener(this);
158  center();
159 
161  mCharacterView->show(0);
162  updateState();
163 }
uint16_t characterSlots
Definition: logindata.h:76
#define _(s)
Definition: gettext.h:34
TextDialog * mDeleteDialog
int getWidth() const
Definition: widget.h:220
Button * mSwitchLoginButton
void setWidth(const int width)
Definition: widget.cpp:132
int mPadding
Definition: window.h:610
void setVisible(Visible visible)
Definition: widget.cpp:224
virtual void show(const int i)=0
Definition: button.h:94
Configuration config
int getIntValue(const std::string &key) const
Button * mChangePasswordButton
int getWidth() const
Definition: graphics.cpp:642
void reflowLayout(int w=0, int h=0)
Definition: window.cpp:1384
virtual void setCharSelectDialog(CharSelectDialog *const window) const =0
#define CAST_S32
Definition: cast.h:29
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
const bool Visible_false
Definition: visible.h:29
int getHeight() const
Definition: graphics.cpp:647
std::string username
Definition: logindata.h:58
Graphics * mainGraphics
Definition: graphics.cpp:108
std::string lastLogin
Definition: logindata.h:63
void setCloseButton(const bool flag)
Definition: window.cpp:737
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:271
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1379
ServerTypeT getNetworkType()
Definition: net.cpp:178
void setFocusable(const bool focusable)
Definition: widget.cpp:191
void center()
Definition: window.cpp:1405
LoginData * mLoginData
std::vector< CharacterDisplay * > mCharacterEntries
CharacterViewBase * mCharacterView
Window(const std::string &caption="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
Definition: window.cpp:108
Net::CharServerHandler * mCharServerHandler
void setCaption(const std::string &caption)
Definition: window.h:523
Net::CharServerHandler * charServerHandler
Definition: net.cpp:79
int getPadding() const
Definition: window.h:496

◆ ~CharSelectDialog()

CharSelectDialog::~CharSelectDialog ( )

Definition at line 165 of file charselectdialog.cpp.

166 {
167 }

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 185 of file charselectdialog.cpp.

References _, Widget::addActionListener(), attemptCharacterDelete(), CAST_S32, CAST_U32, CAST_U64, State::CHANGEEMAIL, State::CHANGEPASSWORD, charRenameListener, charServerHandler, Net::CharServerHandler::clear(), client, close(), CREATEWIDGET, CREATEWIDGETR, data, Net::Character::data, Net::Character::dummy, DialogType::ERROR, UnitsDb::formatCurrency(), ActorSprite::getId(), Being::getName(), Widget::getParent(), CharacterViewBase::getSelected(), TextDialog::getText(), Net::ServerFeatures::haveEmailOnDelete(), PlayerInfoBackend::mAttributes, mCharacterEntries, mCharacterView, mDeleteDialog, mDeleteIndex, Modal_true, Attributes::MONEY, Actions::msg(), 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(), Client::setState(), CharacterViewBase::show(), ShowCenter_true, DialogType::SILENCE, strprintf(), Catch::toString(), updateState(), and use().

Referenced by keyPressed().

186 {
187  // Check if a button of a character was pressed
188  const Widget *const sourceParent = event.getSource()->getParent();
189  int selected = -1;
190  for (unsigned int i = 0, fsz = CAST_U32(
191  mCharacterEntries.size());
192  i < fsz;
193  ++i)
194  {
195  if (mCharacterEntries[i] == sourceParent)
196  {
197  selected = i;
198  mCharacterView->show(i);
199  updateState();
200  break;
201  }
202  }
203  if (selected == -1)
204  selected = mCharacterView->getSelected();
205 
206  const std::string &eventId = event.getId();
207 
208  if (selected >= 0)
209  {
210  if (eventId == "use")
211  {
212  use(selected);
213  return;
214  }
215  else if (eventId == "delete"
216  && (mCharacterEntries[selected]->getCharacter() != nullptr))
217  {
218  CREATEWIDGET(CharDeleteConfirm, this, selected);
219  return;
220  }
221  else if (eventId == "rename"
222  && (mCharacterEntries[selected]->getCharacter() != nullptr))
223  {
224  const LocalPlayer *const player = mCharacterEntries[
225  selected]->getCharacter()->dummy;
226  EditDialog *const dialog = CREATEWIDGETR(EditDialog,
227  // TRANSLATORS: character rename dialog header.
228  _("Please enter new name"),
229  player->getName(),
230  "OK");
231  charRenameListener.setId(player->getId());
234  }
235  else if (eventId == "info")
236  {
237  Net::Character *const character = mCharacterEntries[
238  selected]->getCharacter();
239  if (character == nullptr)
240  return;
241 
242  const LocalPlayer *const data = character->dummy;
243  if (data == nullptr)
244  return;
245 
246  const std::string strExp = toString(CAST_U64(
248  const std::string msg = strprintf(
249  // TRANSLATORS: char select dialog. player info message.
250  _("Hp: %u/%u\nMp: %u/%u\nLevel: %u\n"
251  "Experience: %s\nMoney: %s"),
252  CAST_U32(
254  CAST_U32(
256  CAST_U32(
258  CAST_U32(
260  CAST_U32(
262  strExp.c_str(),
264  character->data.mAttributes[Attributes::MONEY])).c_str());
265  CREATEWIDGET(OkDialog, data->getName(), msg,
266  // TRANSLATORS: ok dialog button
267  _("OK"),
269  Modal_true,
271  nullptr,
272  260);
273  }
274  }
275  if (eventId == "switch")
276  {
278  close();
279  }
280  else if (eventId == "change_password")
281  {
283  }
284  else if (eventId == "change_email")
285  {
287  }
288  else if (eventId == "try delete character")
289  {
290  if ((mDeleteDialog != nullptr) && mDeleteIndex != -1)
291  {
293  {
295  mDeleteDialog = nullptr;
296  }
298  {
300  mDeleteDialog = nullptr;
301  }
302  else
303  {
305  // TRANSLATORS: error header
306  _("Error"),
307  // TRANSLATORS: error message
308  _("Incorrect password"),
309  // TRANSLATORS: ok dialog button
310  _("OK"),
312  Modal_true,
314  nullptr,
315  260);
316  }
317  }
318  mDeleteIndex = -1;
319  }
320 }
#define CAST_U32
Definition: cast.h:30
#define _(s)
Definition: gettext.h:34
TextDialog * mDeleteDialog
void setState(const StateT state)
Definition: client.h:65
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
BeingId getId() const
Definition: actorsprite.h:63
#define CAST_U64
Definition: cast.h:32
virtual void show(const int i)=0
void setId(const BeingId id)
std::string formatCurrency(const int value)
Definition: unitsdb.cpp:323
bool msg(InputEvent &event)
Definition: chat.cpp:38
Client * client
Definition: client.cpp:113
virtual void clear() const =0
void setDialog(EditDialog *const dialog)
Net::ServerFeatures * serverFeatures
Definition: net.cpp:94
const std::string & getText() const
Definition: textdialog.cpp:114
#define CAST_S32
Definition: cast.h:29
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
uint32_t data
CharRenameListener charRenameListener
AtrIntMap mAttributes
Definition: playerinfo.h:72
const bool ShowCenter_true
Definition: showcenter.h:29
static std::string savedPassword
Definition: logindialog.h:79
void use(const int selected)
const std::string & getName() const
Definition: being.h:233
int getSelected() const
void attemptCharacterDelete(const int index, const std::string &email)
Widget * getParent() const
Definition: widget.h:201
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
#define CREATEWIDGET(type,...)
Definition: createwidget.h:28
Definition: widget.h:97
std::vector< CharacterDisplay * > mCharacterEntries
CharacterViewBase * mCharacterView
PlayerInfoBackend data
Definition: character.h:56
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
virtual bool haveEmailOnDelete() const =0
Net::CharServerHandler * charServerHandler
Definition: net.cpp:79
LocalPlayer * dummy
Definition: character.h:55

◆ askPasswordForDeletion()

void CharSelectDialog::askPasswordForDeletion ( const int  index)

Definition at line 452 of file charselectdialog.cpp.

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

Referenced by CharDeleteConfirm::action().

453 {
454  mDeleteIndex = index;
456  {
458  // TRANSLATORS: char deletion question.
459  _("Enter your email for deleting character"),
460  // TRANSLATORS: email label.
461  _("Enter email:"),
462  this, false);
463  }
464  else
465  {
467  // TRANSLATORS: char deletion question.
468  _("Enter password for deleting character"),
469  // TRANSLATORS: email label.
470  _("Enter password:"),
471  this, true);
472  }
473  mDeleteDialog->setActionEventId("try delete character");
475 }
#define _(s)
Definition: gettext.h:34
TextDialog * mDeleteDialog
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:24
Net::ServerFeatures * serverFeatures
Definition: net.cpp:94
virtual bool haveEmailOnDelete() const =0

◆ attemptCharacterDelete()

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

Communicate character deletion to the server.

Definition at line 437 of file charselectdialog.cpp.

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

Referenced by action().

439 {
440  if (mLocked)
441  return;
442 
443  if (mCharacterEntries[index] != nullptr)
444  {
446  mCharacterEntries[index]->getCharacter(),
447  email);
448  }
449  lock();
450 }
virtual void deleteCharacter(Net::Character *const character, const std::string &email) const =0
std::vector< CharacterDisplay * > mCharacterEntries
Net::CharServerHandler * mCharServerHandler

◆ attemptCharacterSelect()

void CharSelectDialog::attemptCharacterSelect ( const int  index)
private

Communicate character selection to the server.

Definition at line 480 of file charselectdialog.cpp.

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

Referenced by selectByName(), and use().

481 {
482  if (mLocked || (mCharacterEntries[index] == nullptr))
483  return;
484 
486  if (mCharServerHandler != nullptr)
487  {
489  mCharacterEntries[index]->getCharacter());
490  }
491  lock();
492 }
const bool Visible_false
Definition: visible.h:29
virtual void setVisible(Visible visible)
Definition: window.cpp:766
std::vector< CharacterDisplay * > mCharacterEntries
virtual void chooseCharacter(Net::Character *const character) const =0
Net::CharServerHandler * mCharServerHandler

◆ 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 584 of file charselectdialog.cpp.

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

Referenced by action().

585 {
587  Window::close();
588 }
void setState(const StateT state)
Definition: client.h:65
Client * client
Definition: client.cpp:113
virtual void close()
Definition: window.cpp:890

◆ 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 337 of file charselectdialog.cpp.

References action(), 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, mCharacterEntries, mCharacterView, mSwitchLoginButton, PRAGMA45(), CharacterViewBase::show(), SLOTS_PER_ROW, updateState(), and use().

338 {
339  const InputActionT actionId = event.getActionId();
340  PRAGMA45(GCC diagnostic push)
341  PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
342  switch (actionId)
343  {
345  event.consume();
348  break;
349 
351  {
352  event.consume();
353  int idx = mCharacterView->getSelected();
354  if (idx >= 0)
355  {
356  idx ++;
357  if (idx == SLOTS_PER_ROW)
358  break;
359  mCharacterView->show(idx);
360  updateState();
361  }
362  break;
363  }
364 
366  {
367  event.consume();
368  int idx = mCharacterView->getSelected();
369  if (idx >= 0)
370  {
371  if ((idx == 0) || idx == SLOTS_PER_ROW)
372  break;
373  idx --;
374  mCharacterView->show(idx);
375  updateState();
376  }
377  break;
378  }
379 
380  case InputAction::GUI_UP:
381  {
382  event.consume();
383  int idx = mCharacterView->getSelected();
384  if (idx >= 0)
385  {
386  if (idx < SLOTS_PER_ROW)
387  break;
388  idx -= SLOTS_PER_ROW;
389  mCharacterView->show(idx);
390  updateState();
391  }
392  break;
393  }
394 
396  {
397  event.consume();
398  int idx = mCharacterView->getSelected();
399  if (idx >= 0)
400  {
401  if (idx >= SLOTS_PER_ROW)
402  break;
403  idx += SLOTS_PER_ROW;
404  mCharacterView->show(idx);
405  updateState();
406  }
407  break;
408  }
409 
411  {
412  event.consume();
413  const int idx = mCharacterView->getSelected();
414  if (idx >= 0 && (mCharacterEntries[idx] != nullptr)
415  && (mCharacterEntries[idx]->getCharacter() != nullptr))
416  {
417  CREATEWIDGET(CharDeleteConfirm, this, idx);
418  }
419  break;
420  }
421 
423  {
424  event.consume();
426  break;
427  }
428  default:
429  break;
430  }
431  PRAGMA45(GCC diagnostic pop)
432 }
Button * mSwitchLoginButton
PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wunused-result") int TestLauncher
virtual void show(const int i)=0
const std::string & getActionEventId() const
Definition: widget.h:604
void action(const ActionEvent &event)
InputAction ::T InputActionT
Definition: inputaction.h:714
void use(const int selected)
int getSelected() const
#define CREATEWIDGET(type,...)
Definition: createwidget.h:28
std::vector< CharacterDisplay * > mCharacterEntries
CharacterViewBase * mCharacterView
static const int SLOTS_PER_ROW

◆ lock()

void CharSelectDialog::lock ( )
private

Definition at line 524 of file charselectdialog.cpp.

References mLocked, and setLocked().

Referenced by attemptCharacterDelete(), and attemptCharacterSelect().

525 {
526  if (!mLocked)
527  setLocked(true);
528 }
void setLocked(const bool locked)

◆ postInit()

void CharSelectDialog::postInit ( )
virtual

Reimplemented from Window.

Definition at line 169 of file charselectdialog.cpp.

References _, Widget::addActionListener(), charServerHandler, CREATEWIDGETR, Net::CharServerHandler::isNeedCreatePin(), pincodeListener, Window::postInit(), Widget::requestFocus(), Window::setVisible(), and Visible_true.

170 {
173  requestFocus();
175  {
176  EditDialog *const dialog = CREATEWIDGETR(EditDialog,
177  // TRANSLATORS: pin code dialog header.
178  _("Please set new pincode"),
179  "",
180  "OK");
182  }
183 }
#define _(s)
Definition: gettext.h:34
const bool Visible_true
Definition: visible.h:29
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
virtual bool isNeedCreatePin() const =0
virtual void requestFocus()
Definition: widget.cpp:203
virtual void setVisible(Visible visible)
Definition: window.cpp:766
PincodeListener pincodeListener
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
Net::CharServerHandler * charServerHandler
Definition: net.cpp:79
void postInit()
Definition: window.cpp:241

◆ selectByName()

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

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 554 of file charselectdialog.cpp.

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

556 {
557  if (mLocked)
558  return false;
559 
560  for (size_t i = 0, sz = mCharacterEntries.size(); i < sz; ++i)
561  {
562  if (mCharacterEntries[i] != nullptr)
563  {
564  const Net::Character *const character
565  = mCharacterEntries[i]->getCharacter();
566  if (character != nullptr)
567  {
568  if (character->dummy != nullptr &&
569  character->dummy->getName() == name)
570  {
572  updateState();
573  if (selAction == Choose)
575  return true;
576  }
577  }
578  }
579  }
580 
581  return false;
582 }
virtual void show(const int i)=0
#define CAST_S32
Definition: cast.h:29
void attemptCharacterSelect(const int index)
const std::string & getName() const
Definition: being.h:233
std::vector< CharacterDisplay * > mCharacterEntries
CharacterViewBase * mCharacterView
LocalPlayer * dummy
Definition: character.h:55

◆ setCharacter()

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

Definition at line 509 of file charselectdialog.cpp.

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

Referenced by setCharacters().

510 {
511  if (character == nullptr)
512  return;
513  const int characterSlot = character->slot;
514  if (characterSlot >= CAST_S32(mCharacterEntries.size()))
515  {
516  logger->log("Warning: slot out of range: %d", character->slot);
517  return;
518  }
519 
520  if (mCharacterEntries[characterSlot] != nullptr)
521  mCharacterEntries[characterSlot]->setCharacter(character);
522 }
Logger * logger
Definition: logger.cpp:95
#define CAST_S32
Definition: cast.h:29
uint16_t slot
Definition: character.h:57
std::vector< CharacterDisplay * > mCharacterEntries
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ setCharacters()

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

Definition at line 494 of file charselectdialog.cpp.

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

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

495 {
496  // Reset previous characters
497  FOR_EACH (STD_VECTOR<CharacterDisplay*>::const_iterator,
498  iter, mCharacterEntries)
499  {
500  if (*iter != nullptr)
501  (*iter)->setCharacter(nullptr);
502  }
503 
504  FOR_EACH (Net::Characters::const_iterator, i, characters)
505  setCharacter(*i);
506  updateState();
507 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
std::vector< CharacterDisplay * > mCharacterEntries
void setCharacter(Net::Character *const character)

◆ setLocked()

void CharSelectDialog::setLocked ( const bool  locked)
private

Definition at line 535 of file charselectdialog.cpp.

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

Referenced by lock(), and unlock().

536 {
537  mLocked = locked;
538 
539  if (mSwitchLoginButton != nullptr)
540  mSwitchLoginButton->setEnabled(!locked);
541  if (mChangePasswordButton != nullptr)
543  mPlayButton->setEnabled(!locked);
544  if (mDeleteButton != nullptr)
545  mDeleteButton->setEnabled(!locked);
546 
547  for (size_t i = 0, sz = mCharacterEntries.size(); i < sz; ++i)
548  {
549  if (mCharacterEntries[i] != nullptr)
550  mCharacterEntries[i]->setActive(!mLocked);
551  }
552 }
Button * mSwitchLoginButton
Button * mChangePasswordButton
void setEnabled(const bool enabled)
Definition: widget.h:351
std::vector< CharacterDisplay * > mCharacterEntries

◆ setName()

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

Definition at line 624 of file charselectdialog.cpp.

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

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

625 {
626  for (unsigned int i = 0, fsz = CAST_U32(
627  mCharacterEntries.size());
628  i < fsz;
629  ++i)
630  {
631  if (mCharacterEntries[i] == nullptr)
632  continue;
633  CharacterDisplay *const character = mCharacterEntries[i];
634  if (character == nullptr)
635  continue;
636  LocalPlayer *const player = character->getCharacter()->dummy;
637  if ((player != nullptr) && player->getId() == id)
638  {
639  player->setName(newName);
640  character->update();
641  return;
642  }
643  }
644 }
#define CAST_U32
Definition: cast.h:30
BeingId getId() const
Definition: actorsprite.h:63
Net::Character * getCharacter() const
void setName(const std::string &name)
Definition: being.cpp:1125
std::vector< CharacterDisplay * > mCharacterEntries
LocalPlayer * dummy
Definition: character.h:55

◆ unlock()

void CharSelectDialog::unlock ( )
private

Definition at line 530 of file charselectdialog.cpp.

References setLocked().

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

531 {
532  setLocked(false);
533 }
void setLocked(const bool locked)

◆ updateState()

void CharSelectDialog::updateState ( )

Definition at line 596 of file charselectdialog.cpp.

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

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

597 {
598  const int idx = mCharacterView->getSelected();
599  if (idx == -1)
600  {
601  mPlayButton->setEnabled(false);
602  return;
603  }
604  mPlayButton->setEnabled(true);
605 
606  if (mCharacterEntries[idx] != nullptr &&
607  mCharacterEntries[idx]->getCharacter() != nullptr)
608  {
609  // TRANSLATORS: char select dialog. button.
610  mPlayButton->setCaption(_("Play"));
611 
612  const LocalPlayer *const player = mCharacterEntries[
613  idx]->getCharacter()->dummy;
614  if ((player != nullptr) && (mRenameButton != nullptr))
615  mRenameButton->setEnabled(player->getRename() ? true : false);
616  }
617  else
618  {
619  // TRANSLATORS: char select dialog. button.
620  mPlayButton->setCaption(_("Create"));
621  }
622 }
#define _(s)
Definition: gettext.h:34
bool getRename() const
Definition: localplayer.h:417
void setCaption(const std::string &caption)
Definition: button.h:214
void setEnabled(const bool enabled)
Definition: widget.h:351
int getSelected() const
std::vector< CharacterDisplay * > mCharacterEntries
CharacterViewBase * mCharacterView

◆ use()

void CharSelectDialog::use ( const int  selected)
private

Definition at line 322 of file charselectdialog.cpp.

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

Referenced by action(), and keyPressed().

323 {
324  if ((mCharacterEntries[selected] != nullptr)
325  && (mCharacterEntries[selected]->getCharacter() != nullptr))
326  {
327  attemptCharacterSelect(selected);
328  }
329  else
330  {
331  CharCreateDialog *const charCreateDialog =
332  CREATEWIDGETR(CharCreateDialog, this, selected);
333  mCharServerHandler->setCharCreateDialog(charCreateDialog);
334  }
335 }
virtual void setCharCreateDialog(CharCreateDialog *const window) const =0
void attemptCharacterSelect(const int index)
std::vector< CharacterDisplay * > mCharacterEntries
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
Net::CharServerHandler * mCharServerHandler

◆ widgetResized()

void CharSelectDialog::widgetResized ( const Event event)
virtual

Called whenever the widget changes size.

Reimplemented from Window.

Definition at line 590 of file charselectdialog.cpp.

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

591 {
592  Window::widgetResized(event);
594 }
virtual void resize()=0
void widgetResized(const Event &event)
Definition: window.cpp:643
CharacterViewBase * mCharacterView

Friends And Related Function Documentation

◆ CharDeleteConfirm

friend class CharDeleteConfirm
friend

Definition at line 56 of file charselectdialog.h.

◆ Net::CharServerHandler

friend class Net::CharServerHandler
friend

Definition at line 57 of file charselectdialog.h.

Field Documentation

◆ mChangePasswordButton

Button* CharSelectDialog::mChangePasswordButton
private

Definition at line 120 of file charselectdialog.h.

Referenced by CharSelectDialog(), and setLocked().

◆ mCharacterEntries

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

◆ mCharacterView

CharacterViewBase* CharSelectDialog::mCharacterView
private

◆ mCharServerHandler

Net::CharServerHandler* CharSelectDialog::mCharServerHandler
private

Definition at line 129 of file charselectdialog.h.

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

◆ mDeleteButton

Button* CharSelectDialog::mDeleteButton
private

Definition at line 123 of file charselectdialog.h.

Referenced by CharSelectDialog(), and setLocked().

◆ mDeleteDialog

TextDialog* CharSelectDialog::mDeleteDialog
private

Definition at line 130 of file charselectdialog.h.

Referenced by action(), and askPasswordForDeletion().

◆ mDeleteIndex

int CharSelectDialog::mDeleteIndex
private

Definition at line 131 of file charselectdialog.h.

Referenced by action(), and askPasswordForDeletion().

◆ mInfoButton

Button* CharSelectDialog::mInfoButton
private

Definition at line 122 of file charselectdialog.h.

Referenced by CharSelectDialog().

◆ mLocked

bool CharSelectDialog::mLocked
private

◆ mLoginData

LoginData* CharSelectDialog::mLoginData
private

Definition at line 117 of file charselectdialog.h.

Referenced by CharSelectDialog().

◆ mPlayButton

Button* CharSelectDialog::mPlayButton
private

Definition at line 121 of file charselectdialog.h.

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

◆ mRenameButton

Button* CharSelectDialog::mRenameButton
private

Definition at line 124 of file charselectdialog.h.

Referenced by CharSelectDialog(), and updateState().

◆ mSmallScreen

bool CharSelectDialog::mSmallScreen
private

Definition at line 133 of file charselectdialog.h.

Referenced by CharSelectDialog().

◆ mSwitchLoginButton

Button* CharSelectDialog::mSwitchLoginButton
private

Definition at line 119 of file charselectdialog.h.

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


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