ManaPlus
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
OutfitWindow Class Reference

#include <outfitwindow.h>

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

Public Member Functions

 OutfitWindow ()
 
 ~OutfitWindow ()
 
void action (const ActionEvent &event)
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void mousePressed (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void load ()
 
void wearOutfit (const int outfit, const bool unwearEmpty=true, const bool select=false)
 
void copyOutfit (const int outfit)
 
void copyOutfit (const int src, const int dst)
 
void copyFromEquiped ()
 
void copyFromEquiped (const int dst)
 
void unequipNotInOutfit (const int outfit) const
 
void next ()
 
void previous ()
 
void wearNextOutfit (const bool all=false)
 
void wearPreviousOutfit (const bool all=false)
 
void wearAwayOutfit ()
 
void unwearAwayOutfit ()
 
void showCurrentOutfit ()
 
void clearCurrentOutfit ()
 
std::string getOutfitString () const
 
- 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 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 widgetResized (const Event &event)
 
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)
 
void postInit ()
 
WindowgetParentWindow () const
 
virtual void scheduleDelete ()
 
void mouseMoved (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 ()
 
virtual void close ()
 
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)
 

Static Public Member Functions

static std::string keyName (const int number)
 
- 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)
 

Private Member Functions

int getIndexFromGrid (const int pointX, const int pointY) const
 
void save () const
 
- Private Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
 ActionListener ()
 

Private Attributes

ButtonmPreviousButton
 
ButtonmNextButton
 
ButtonmEquipBottom
 
LabelmCurrentLabel
 
CheckBoxmUnequipCheck
 
CheckBoxmAwayOutfitCheck
 
LabelmKeyLabel
 
Color mBorderColor
 
int mCurrentOutfit
 
int mBoxWidth
 
int mBoxHeight
 
int mGridWidth
 
int mGridHeight
 
int mItems [OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
 
int mAwayOutfit
 
ItemColor mItemColors [OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
 
bool mItemClicked
 
bool mItemsUnequip [OUTFITS_COUNT]
 

Additional Inherited Members

- 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 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

Definition at line 39 of file outfitwindow.h.

Constructor & Destructor Documentation

◆ OutfitWindow()

OutfitWindow::OutfitWindow ( )

Constructor.

Definition at line 59 of file outfitwindow.cpp.

References Widget::addActionListener(), ThemeColorId::BACKGROUND, LayoutCell::CENTER, Graphics::CENTER, Window::enableVisibleSound(), Window::getLayout(), Widget2::getThemeColor(), load(), Window::loadWindowState(), mAwayOutfitCheck, Widget::mBackgroundColor, mCurrentLabel, mEquipBottom, mKeyLabel, mNextButton, mPreviousButton, mUnequipCheck, Window::place(), SetupWindow::registerWindowForReset(), LayoutType::SET, Widget::setActionEventId(), Label::setAlignment(), Window::setCloseButton(), LayoutCell::setColWidth(), Window::setDefaultSize(), Window::setMinHeight(), Window::setMinWidth(), Window::setResizable(), LayoutCell::setRowHeight(), Window::setStickyButtonLock(), setupWindow, and Window::setWindowName().

59  :
60  // TRANSLATORS: outfits window name
61  Window(_("Outfits"), Modal_false, nullptr, "outfits.xml"),
63  // TRANSLATORS: outfits window button
64  mPreviousButton(new Button(this, _("<"), "previous", this)),
65  // TRANSLATORS: outfits window button
66  mNextButton(new Button(this, _(">"), "next", this)),
67  // TRANSLATORS: outfits window button
68  mEquipBottom(new Button(this, _("Equip"), "equip", this)),
69  // TRANSLATORS: outfits window label
70  mCurrentLabel(new Label(this, strprintf(_("Outfit: %d"), 1))),
71  // TRANSLATORS: outfits window checkbox
72  mUnequipCheck(new CheckBox(this, _("Unequip first"),
73  serverConfig.getValueBool("OutfitUnequip0", true))),
74  // TRANSLATORS: outfits window checkbox
75  mAwayOutfitCheck(new CheckBox(this, _("Away outfit"),
76  serverConfig.getValue("OutfitAwayIndex", OUTFITS_COUNT - 1) != 0u)),
77  // TRANSLATORS: outfits window label
78  mKeyLabel(new Label(this, strprintf(_("Key: %s"),
79  keyName(0).c_str()))),
81  mCurrentOutfit(0),
82  mBoxWidth(33),
83  mBoxHeight(33),
84  mGridWidth(4),
85  mGridHeight(4),
86  mItems(),
87  mAwayOutfit(0),
88  mItemColors(),
89  mItemClicked(false),
91 {
92  setWindowName("Outfits");
93  setResizable(true);
94  setCloseButton(true);
95  setStickyButtonLock(true);
96 
98 
99  setDefaultSize(250, 400, 150, 290);
100  setMinWidth(145);
101  setMinHeight(220);
102 
103  if (setupWindow != nullptr)
105 
108 
109  mUnequipCheck->setActionEventId("unequip");
111 
114 
115  place(1, 3, mEquipBottom, 2);
116  place(0, 4, mKeyLabel, 4);
117  place(0, 5, mPreviousButton, 1);
118  place(1, 5, mCurrentLabel, 2);
119  place(3, 5, mNextButton, 1);
120  place(0, 6, mUnequipCheck, 4);
121  place(0, 7, mAwayOutfitCheck, 4);
122 
123  Layout &layout = getLayout();
124  layout.setRowHeight(0, LayoutType::SET);
125  layout.setColWidth(4, Layout::CENTER);
126 
127  loadWindowState();
128 
129  enableVisibleSound(true);
130  load();
131 }
void setDefaultSize()
Definition: window.cpp:1186
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:128
#define _(s)
Definition: gettext.h:34
Button * mPreviousButton
Definition: outfitwindow.h:107
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha=255U) const A_INLINE
Definition: widget2.h:44
void loadWindowState()
Definition: window.cpp:1075
Label * mCurrentLabel
Definition: outfitwindow.h:110
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
void setMinWidth(const int width)
Definition: window.cpp:579
Definition: button.h:94
void setColWidth(const int n, const int w)
Definition: layoutcell.cpp:122
CheckBox * mUnequipCheck
Definition: outfitwindow.h:111
Button * mEquipBottom
Definition: outfitwindow.h:109
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
Configuration serverConfig
void registerWindowForReset(Window *const window)
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:126
Color mBackgroundColor
Definition: widget.h:1090
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
Definition: label.h:87
LayoutCell & place(const int x, const int y, Widget *const wg, const int w=1, const int h=1)
Definition: window.cpp:1372
bool getValueBool(const std::string &key, const bool deflt) const
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
void setCloseButton(const bool flag)
Definition: window.cpp:737
void enableVisibleSound(bool b)
Definition: window.h:473
void setMinHeight(const int height)
Definition: window.cpp:592
Layout & getLayout()
Definition: window.cpp:1353
CheckBox * mAwayOutfitCheck
Definition: outfitwindow.h:112
std::string getValue(const std::string &key, const std::string &deflt) const
static std::string keyName(const int number)
void setAlignment(Graphics::Alignment alignment)
Definition: label.h:152
Button * mNextButton
Definition: outfitwindow.h:108
Label * mKeyLabel
Definition: outfitwindow.h:113
Color mBorderColor
Definition: outfitwindow.h:115
void setResizable(const bool resize)
Definition: window.cpp:615
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:760
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
Window(const std::string &caption="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
Definition: window.cpp:108
Definition: layout.h:43
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:127
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:123
void setWindowName(const std::string &name)
Definition: window.h:353

◆ ~OutfitWindow()

OutfitWindow::~OutfitWindow ( )

Destructor.

Definition at line 133 of file outfitwindow.cpp.

References save().

134 {
135  save();
136 }
void save() const

Member Function Documentation

◆ action()

void OutfitWindow::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 236 of file outfitwindow.cpp.

References CAST_S32, Game::instance(), CheckBox::isSelected(), mAwayOutfit, mAwayOutfitCheck, mCurrentOutfit, mItemsUnequip, mUnequipCheck, next(), OUTFITS_COUNT, previous(), CheckBox::setSelected(), Game::setValidSpeed(), and wearOutfit().

237 {
238  const std::string &eventId = event.getId();
239  if (eventId == "next")
240  {
241  next();
242  }
243  else if (eventId == "previous")
244  {
245  previous();
246  }
247  else if (eventId == "unequip")
248  {
249  if (mCurrentOutfit >= 0 && mCurrentOutfit < CAST_S32(
250  OUTFITS_COUNT))
251  {
253  }
254  }
255  else if (eventId == "equip")
256  {
258  if (Game::instance() != nullptr)
260  }
261  else if (eventId == "away")
262  {
266  }
267 }
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:128
void setValidSpeed()
Definition: game.cpp:1238
CheckBox * mUnequipCheck
Definition: outfitwindow.h:111
#define CAST_S32
Definition: cast.h:29
void wearOutfit(const int outfit, const bool unwearEmpty=true, const bool select=false)
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
CheckBox * mAwayOutfitCheck
Definition: outfitwindow.h:112
static Game * instance()
Definition: game.h:81
void setSelected(const bool selected)
Definition: checkbox.h:155
bool isSelected() const
Definition: checkbox.h:146

◆ clearCurrentOutfit()

void OutfitWindow::clearCurrentOutfit ( )

Definition at line 712 of file outfitwindow.cpp.

References ItemColor_one, mCurrentOutfit, mItemColors, mItems, OUTFIT_ITEM_COUNT, OUTFITS_COUNT, and save().

Referenced by Actions::changeRelation().

713 {
714  if (mCurrentOutfit < 0 || mCurrentOutfit
715  >= static_cast<signed int>(OUTFITS_COUNT))
716  {
717  return;
718  }
719  for (unsigned f = 0; f < OUTFIT_ITEM_COUNT; f++)
720  {
721  mItems[mCurrentOutfit][f] = -1;
723  }
724  save();
725 }
const unsigned int OUTFIT_ITEM_COUNT
Definition: outfitwindow.h:33
const ItemColor ItemColor_one
Definition: itemcolor.h:29
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:126
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
void save() const
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:123

◆ copyFromEquiped() [1/2]

void OutfitWindow::copyFromEquiped ( )

Definition at line 675 of file outfitwindow.cpp.

References mCurrentOutfit.

Referenced by Actions::getAmountFromEvent(), and wearAwayOutfit().

676 {
678 }
void copyFromEquiped()

◆ copyFromEquiped() [2/2]

void OutfitWindow::copyFromEquiped ( const int  dst)

Definition at line 680 of file outfitwindow.cpp.

References CAST_S32, Equipped_true, Item::getColor(), Item::getId(), PlayerInfo::getInventory(), Inventory::getItem(), Inventory::getSize(), Item::isEquipped(), ServerCommandType::item, mItemColors, mItems, OUTFIT_ITEM_COUNT, and save().

681 {
682  const Inventory *const inventory = PlayerInfo::getInventory();
683  if (inventory == nullptr)
684  return;
685 
686  int outfitCell = 0;
687  for (unsigned i = 0, sz = inventory->getSize(); i < sz; i++)
688  {
689  const Item *const item = inventory->getItem(i);
690  if ((item != nullptr) && item->isEquipped() == Equipped_true)
691  {
692  mItems[dst][outfitCell] = item->getId();
693  mItemColors[dst][outfitCell++] = item->getColor();
694  if (outfitCell >= CAST_S32(OUTFIT_ITEM_COUNT))
695  break;
696  }
697  }
698  save();
699 }
Equipped isEquipped() const
Definition: item.h:128
Inventory * getInventory()
Definition: playerinfo.cpp:207
const unsigned int OUTFIT_ITEM_COUNT
Definition: outfitwindow.h:33
const bool Equipped_true
Definition: equipped.h:29
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:126
#define CAST_S32
Definition: cast.h:29
ItemColor getColor() const
Definition: item.h:180
Definition: item.h:48
void save() const
int getId() const
Definition: item.h:80
Item * getItem(const int index) const
Definition: inventory.cpp:82
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:123
unsigned getSize() const
Definition: inventory.h:75

◆ copyOutfit() [1/2]

void OutfitWindow::copyOutfit ( const int  outfit)

Definition at line 306 of file outfitwindow.cpp.

References mCurrentOutfit.

Referenced by Actions::getAmountFromEvent().

307 {
309 }
void copyOutfit(const int outfit)
bool outfit(InputEvent &event)
Definition: actions.cpp:31

◆ copyOutfit() [2/2]

void OutfitWindow::copyOutfit ( const int  src,
const int  dst 
)

Definition at line 311 of file outfitwindow.cpp.

References CAST_S32, mItems, OUTFIT_ITEM_COUNT, OUTFITS_COUNT, and save().

312 {
313  if (src < 0 || src > CAST_S32(OUTFITS_COUNT)
314  || dst < 0 || dst > CAST_S32(OUTFITS_COUNT))
315  {
316  return;
317  }
318 
319  for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++)
320  mItems[dst][i] = mItems[src][i];
321  save();
322 }
const unsigned int OUTFIT_ITEM_COUNT
Definition: outfitwindow.h:33
#define CAST_S32
Definition: cast.h:29
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
void save() const
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:123

◆ draw()

void OutfitWindow::draw ( Graphics *const  graphics)
virtual

Draws the window.

Reimplemented from Window.

Definition at line 324 of file outfitwindow.cpp.

References BLOCK_END, BLOCK_START, CAST_U32, Image::decRef(), Window::draw(), Graphics::drawImage(), Graphics::drawRectangle(), Graphics::fillRectangle(), Inventory::findItem(), Item::getImage(), PlayerInfo::getInventory(), ServerCommandType::item, Widget::mBackgroundColor, mBorderColor, mBoxHeight, mBoxWidth, mCurrentOutfit, mGridWidth, mItemColors, mItems, Window::mPadding, Window::mTitleBarHeight, OUTFIT_ITEM_COUNT, OUTFITS_COUNT, and Graphics::setColor().

325 {
326  BLOCK_START("OutfitWindow::draw")
327  Window::draw(graphics);
328 
330  >= static_cast<signed int>(OUTFITS_COUNT))
331  {
332  return;
333  }
334 
335  for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++)
336  {
337  const int itemX = mPadding + ((i % mGridWidth) * mBoxWidth);
338  const int itemY = mPadding + mTitleBarHeight
339  + ((i / CAST_U32(mGridWidth)) * mBoxHeight);
340 
341  graphics->setColor(mBorderColor);
342  graphics->drawRectangle(Rect(itemX, itemY, 32, 32));
343  graphics->setColor(mBackgroundColor);
344  graphics->fillRectangle(Rect(itemX, itemY, 32, 32));
345 
346  if (mItems[mCurrentOutfit][i] < 0)
347  continue;
348 
349  bool foundItem = false;
350  const Inventory *const inv = PlayerInfo::getInventory();
351  if (inv != nullptr)
352  {
353  const Item *const item = inv->findItem(mItems[mCurrentOutfit][i],
355  if (item != nullptr)
356  {
357  // Draw item icon.
358  const Image *const image = item->getImage();
359  if (image != nullptr)
360  {
361  graphics->drawImage(image, itemX, itemY);
362  foundItem = true;
363  }
364  }
365  }
366  if (!foundItem)
367  {
368  Image *const image = Item::getImage(mItems[mCurrentOutfit][i],
370  if (image != nullptr)
371  {
372  graphics->drawImage(image, itemX, itemY);
373  image->decRef();
374  }
375  }
376  }
377  BLOCK_END("OutfitWindow::draw")
378 }
#define CAST_U32
Definition: cast.h:30
int mPadding
Definition: window.h:610
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
Definition: rect.h:72
Inventory * getInventory()
Definition: playerinfo.cpp:207
Definition: window.h:98
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
const unsigned int OUTFIT_ITEM_COUNT
Definition: outfitwindow.h:33
virtual void drawRectangle(const Rect &rectangle)=0
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:126
Color mBackgroundColor
Definition: widget.h:1090
virtual void setColor(const Color &color)
Definition: graphics.h:319
Definition: item.h:48
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
virtual void fillRectangle(const Rect &rectangle)=0
Image * getImage() const
Definition: item.h:86
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
Definition: image.h:61
Color mBorderColor
Definition: outfitwindow.h:115
unsigned int mTitleBarHeight
Definition: window.h:615
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:123
void decRef()
Definition: image.cpp:521
void draw(Graphics *const graphics)

◆ getIndexFromGrid()

int OutfitWindow::getIndexFromGrid ( const int  pointX,
const int  pointY 
) const
private

Definition at line 550 of file outfitwindow.cpp.

References CAST_S32, Rect::isPointInRect(), mBoxHeight, mBoxWidth, mGridHeight, mGridWidth, Window::mPadding, Window::mTitleBarHeight, and OUTFIT_ITEM_COUNT.

Referenced by mouseDragged(), mousePressed(), and mouseReleased().

551 {
552  const Rect tRect = Rect(mPadding, mTitleBarHeight,
554  if (!tRect.isPointInRect(pointX, pointY))
555  return -1;
556  const int index = (((pointY - mTitleBarHeight) / mBoxHeight) * mGridWidth)
557  + (pointX - mPadding) / mBoxWidth;
558  if (index >= CAST_S32(OUTFIT_ITEM_COUNT) || index < 0)
559  return -1;
560  return index;
561 }
int mPadding
Definition: window.h:610
Definition: rect.h:72
bool isPointInRect(const int x_, const int y_) const
Definition: rect.h:196
const unsigned int OUTFIT_ITEM_COUNT
Definition: outfitwindow.h:33
#define CAST_S32
Definition: cast.h:29
unsigned int mTitleBarHeight
Definition: window.h:615

◆ getOutfitString()

std::string OutfitWindow::getOutfitString ( ) const

Definition at line 727 of file outfitwindow.cpp.

References CAST_S32, ItemDB::getNamesStr(), mCurrentOutfit, mItemColors, mItems, OUTFIT_ITEM_COUNT, and ServerCommandType::str.

Referenced by Actions::changeRelation().

728 {
729  std::string str;
730  for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++)
731  {
732  const int id = mItems[mCurrentOutfit][i];
733  if (id < 0)
734  continue;
735 
736  const ItemColor color = mItemColors[mCurrentOutfit][i];
737  STD_VECTOR<int> ids;
738  ids.push_back(id);
739  ids.push_back(CAST_S32(color));
740 
741  const std::string name = ItemDB::getNamesStr(ids);
742  if (name.empty())
743  continue;
744  str.append("[");
745  str.append(name);
746  str.append("] ");
747  }
748  return str;
749 }
std::string getNamesStr(const std::vector< int > &parts)
Definition: itemdb.cpp:1201
uint16_t ItemColor
Definition: itemcolor.h:29
const unsigned int OUTFIT_ITEM_COUNT
Definition: outfitwindow.h:33
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:126
#define CAST_S32
Definition: cast.h:29
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:123

◆ keyName()

std::string OutfitWindow::keyName ( const int  number)
static

Definition at line 592 of file outfitwindow.cpp.

References InputManager::getKeyStringLong(), inputManager, InputAction::OUTFIT_1, and SHORTCUT_EMOTES.

Referenced by EAthena::BeingRecv::processBeingSpawn(), TmwAthena::BeingRecv::processBeingVisible(), EAthena::BeingRecv::processBeingVisible(), LocalPlayer::setHome(), showCurrentOutfit(), and SocialNavigationTab::updateList().

593 {
594  if (number < 0 || number >= SHORTCUT_EMOTES)
595  return "";
597 }
std::string getKeyStringLong(const InputActionT index) const
static const int SHORTCUT_EMOTES
Definition: emoteshortcut.h:24
InputManager inputManager

◆ load()

void OutfitWindow::load ( )

Definition at line 138 of file outfitwindow.cpp.

References CAST_S32, CAST_U8, fromInt, ConfigurationObject::getValue(), ConfigurationObject::getValueBool(), mAwayOutfit, mAwayOutfitCheck, mCurrentOutfit, mItemColors, mItems, mItemsUnequip, Actions::outfit(), OUTFIT_ITEM_COUNT, OUTFITS_COUNT, serverConfig, CheckBox::setSelected(), and Catch::toString().

Referenced by OutfitWindow().

139 {
140  const Configuration *cfg = &serverConfig;
141 
142  memset(mItems, -1, sizeof(mItems));
143  memset(mItemColors, 1, sizeof(mItemColors));
144 
145  for (unsigned o = 0; o < OUTFITS_COUNT; o++)
146  {
147  std::string outfit = cfg->getValue("Outfit" + toString(o), "-1");
148  std::string buf;
149  std::stringstream ss(outfit);
150 
151  STD_VECTOR<int> tokens;
152 
153  while (ss >> buf)
154  tokens.push_back(atoi(buf.c_str()));
155 
156  for (size_t i = 0, sz = tokens.size();
157  i < sz && i < OUTFIT_ITEM_COUNT; i++)
158  {
159  mItems[o][i] = tokens[i];
160  }
161 
162  outfit = cfg->getValue("OutfitColor" + toString(o), "1");
163  std::stringstream ss2(outfit);
164 
165  tokens.clear();
166 
167  STD_VECTOR<unsigned char> tokens2;
168  while (ss2 >> buf)
169  tokens2.push_back(CAST_U8(atoi(buf.c_str())));
170 
171  for (size_t i = 0, sz = tokens2.size();
172  i < sz && i < OUTFIT_ITEM_COUNT; i++)
173  {
174  mItemColors[o][i] = fromInt(tokens2[i], ItemColor);
175  }
176 
177  mItemsUnequip[o] = cfg->getValueBool("OutfitUnequip" + toString(o),
178  true);
179  }
180  mAwayOutfit = cfg->getValue("OutfitAwayIndex", OUTFITS_COUNT - 1);
181  if (mAwayOutfit >= CAST_S32(OUTFITS_COUNT))
182  mAwayOutfit = CAST_S32(OUTFITS_COUNT) - 1;
183 
184  if (mAwayOutfitCheck != nullptr)
186 }
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:128
#define CAST_U8
Definition: cast.h:26
#define fromInt(val, name)
Definition: intdefines.h:45
uint16_t ItemColor
Definition: itemcolor.h:29
const unsigned int OUTFIT_ITEM_COUNT
Definition: outfitwindow.h:33
Configuration serverConfig
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:126
#define CAST_S32
Definition: cast.h:29
bool getValueBool(const std::string &key, const bool deflt) const
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
bool outfit(InputEvent &event)
Definition: actions.cpp:31
CheckBox * mAwayOutfitCheck
Definition: outfitwindow.h:112
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
std::string getValue(const std::string &key, const std::string &deflt) const
void setSelected(const bool selected)
Definition: checkbox.h:155
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:123

◆ mouseDragged()

void OutfitWindow::mouseDragged ( MouseEvent event)
virtual

Implements window resizing and makes sure the window is not dragged/resized outside of the screen.

Reimplemented from Window.

Definition at line 436 of file outfitwindow.cpp.

References DragDrop::clear(), dragDrop, DragDrop::dragItem(), Inventory::findItem(), MouseEvent::getButton(), getIndexFromGrid(), PlayerInfo::getInventory(), MouseEvent::getX(), DragDrop::isEmpty(), ServerCommandType::item, MouseButton::LEFT, mCurrentOutfit, mItemClicked, mItemColors, mItems, Window::mMoved, Window::mouseDragged(), DragDropSource::Outfit, and OUTFITS_COUNT.

437 {
438  if (event.getButton() == MouseButton::LEFT)
439  {
440  if (dragDrop.isEmpty() && mItemClicked)
441  {
442  if (mCurrentOutfit < 0 || mCurrentOutfit
443  >= static_cast<signed int>(OUTFITS_COUNT))
444  {
445  Window::mouseDragged(event);
446  return;
447  }
448 
449  const int index = getIndexFromGrid(event.getX(), event.getY());
450  if (index == -1)
451  {
452  Window::mouseDragged(event);
453  return;
454  }
455  const int itemId = mItems[mCurrentOutfit][index];
456  const ItemColor itemColor = mItemColors[mCurrentOutfit][index];
457  if (itemId < 0)
458  {
459  Window::mouseDragged(event);
460  return;
461  }
462  mMoved = false;
463  event.consume();
464  const Inventory *const inv = PlayerInfo::getInventory();
465  if (inv != nullptr)
466  {
467  Item *const item = inv->findItem(itemId, itemColor);
468  if (item != nullptr)
470  else
471  dragDrop.clear();
472  mItems[mCurrentOutfit][index] = -1;
473  }
474  }
475  }
476  Window::mouseDragged(event);
477 }
void dragItem(const Item *const item, const DragDropSourceT source, const int tag=0)
Definition: dragdrop.h:86
void clear()
Definition: dragdrop.h:182
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
MouseButtonT getButton() const
Definition: mouseevent.h:113
Inventory * getInventory()
Definition: playerinfo.cpp:207
DragDrop dragDrop
uint16_t ItemColor
Definition: itemcolor.h:29
bool mMoved
Definition: window.h:639
bool isEmpty() const
Definition: dragdrop.h:195
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:126
Definition: item.h:48
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
void mouseDragged(MouseEvent &event)
Definition: window.cpp:970
int getX() const
Definition: mouseevent.h:124
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:123
int getIndexFromGrid(const int pointX, const int pointY) const

◆ mousePressed()

void OutfitWindow::mousePressed ( MouseEvent event)
virtual

Starts window resizing when appropriate.

Reimplemented from Window.

Definition at line 479 of file outfitwindow.cpp.

References DragDrop::deselect(), dragDrop, MouseEvent::getButton(), getIndexFromGrid(), DragDrop::getSelected(), DragDrop::getSelectedColor(), MouseEvent::getX(), DragDrop::isSelected(), mCurrentOutfit, mItemClicked, mItemColors, mItems, Viewport::mMouseX, Viewport::mMouseY, Window::mMoved, Window::mousePressed(), popupMenu, MouseButton::RIGHT, save(), PopupMenu::showOutfitsWindowPopup(), and viewport.

480 {
481  const int index = getIndexFromGrid(event.getX(), event.getY());
482  if (event.getButton() == MouseButton::RIGHT && (popupMenu != nullptr))
483  {
485  viewport->mMouseY);
486  event.consume();
487  return;
488  }
489  else if (index == -1)
490  {
491  Window::mousePressed(event);
492  return;
493  }
494  mMoved = false;
495  event.consume();
496 
497  if (mItems[mCurrentOutfit][index] > 0)
498  {
499  mItemClicked = true;
500  }
501  else
502  {
503  if (dragDrop.isSelected())
504  {
507  dragDrop.deselect();
508  save();
509  }
510  }
511 
512  Window::mousePressed(event);
513 }
bool isSelected() const
Definition: dragdrop.h:224
MouseButtonT getButton() const
Definition: mouseevent.h:113
DragDrop dragDrop
bool mMoved
Definition: window.h:639
int mMouseX
Definition: viewport.h:153
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:126
int getSelected() const
Definition: dragdrop.h:218
PopupMenu * popupMenu
Definition: popupmenu.cpp:102
void showOutfitsWindowPopup(const int x, const int y)
Definition: popupmenu.cpp:844
void deselect()
Definition: dragdrop.h:212
void save() const
int mMouseY
Definition: viewport.h:154
void mousePressed(MouseEvent &event)
Definition: window.cpp:824
int getX() const
Definition: mouseevent.h:124
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:123
ItemColor getSelectedColor() const
Definition: dragdrop.h:221
int getIndexFromGrid(const int pointX, const int pointY) const
Viewport * viewport
Definition: viewport.cpp:35

◆ mouseReleased()

void OutfitWindow::mouseReleased ( MouseEvent event)
virtual

When the mouse button has been let go, this ensures that the mouse custom cursor is restored back to it's standard image.

Reimplemented from Window.

Definition at line 515 of file outfitwindow.cpp.

References DragDrop::clear(), DragDrop::deselect(), dragDrop, MouseEvent::getButton(), getIndexFromGrid(), DragDrop::getItem(), DragDrop::getItemColor(), MouseEvent::getX(), DragDrop::isEmpty(), DragDrop::isSourceItemContainer(), MouseButton::LEFT, mCurrentOutfit, mItemClicked, mItemColors, mItems, Window::mMoved, Window::mouseReleased(), OUTFITS_COUNT, and save().

516 {
517  if (event.getButton() == MouseButton::LEFT)
518  {
519  if (mCurrentOutfit < 0 || mCurrentOutfit
520  >= static_cast<signed int>(OUTFITS_COUNT))
521  {
522  return;
523  }
524  const int index = getIndexFromGrid(event.getX(), event.getY());
525  if (index == -1)
526  {
527  dragDrop.clear();
528  Window::mouseReleased(event);
529  return;
530  }
531  mMoved = false;
532  event.consume();
533  if (!dragDrop.isEmpty())
534  {
536  {
539  dragDrop.clear();
540  dragDrop.deselect();
541  save();
542  }
543  }
544  if (mItemClicked)
545  mItemClicked = false;
546  }
547  Window::mouseReleased(event);
548 }
void clear()
Definition: dragdrop.h:182
MouseButtonT getButton() const
Definition: mouseevent.h:113
DragDrop dragDrop
bool mMoved
Definition: window.h:639
bool isEmpty() const
Definition: dragdrop.h:195
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:126
bool isSourceItemContainer() const
Definition: dragdrop.h:240
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
void deselect()
Definition: dragdrop.h:212
void save() const
void mouseReleased(MouseEvent &event)
Definition: window.cpp:895
ItemColor getItemColor() const
Definition: dragdrop.h:68
int getX() const
Definition: mouseevent.h:124
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:123
int getIndexFromGrid(const int pointX, const int pointY) const
int getItem() const
Definition: dragdrop.h:65

◆ next()

void OutfitWindow::next ( )

Definition at line 599 of file outfitwindow.cpp.

References CAST_S32, mCurrentOutfit, OUTFITS_COUNT, and showCurrentOutfit().

Referenced by action(), and wearNextOutfit().

600 {
602  mCurrentOutfit++;
603  else
604  mCurrentOutfit = 0;
606 }
void showCurrentOutfit()
#define CAST_S32
Definition: cast.h:29
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32

◆ previous()

void OutfitWindow::previous ( )

Definition at line 608 of file outfitwindow.cpp.

References mCurrentOutfit, OUTFITS_COUNT, and showCurrentOutfit().

Referenced by action(), and wearPreviousOutfit().

609 {
610  if (mCurrentOutfit > 0)
611  mCurrentOutfit--;
612  else
615 }
void showCurrentOutfit()
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32

◆ safeDraw()

void OutfitWindow::safeDraw ( Graphics *const  graphics)
virtual

Reimplemented from Window.

Definition at line 380 of file outfitwindow.cpp.

References BLOCK_END, BLOCK_START, CAST_U32, Image::decRef(), Graphics::drawImage(), Graphics::drawRectangle(), Graphics::fillRectangle(), Inventory::findItem(), Item::getImage(), PlayerInfo::getInventory(), ServerCommandType::item, Widget::mBackgroundColor, mBorderColor, mBoxHeight, mBoxWidth, mCurrentOutfit, mGridWidth, mItemColors, mItems, Window::mPadding, Window::mTitleBarHeight, OUTFIT_ITEM_COUNT, OUTFITS_COUNT, Window::safeDraw(), and Graphics::setColor().

381 {
382  BLOCK_START("OutfitWindow::draw")
383  Window::safeDraw(graphics);
384 
386  >= static_cast<signed int>(OUTFITS_COUNT))
387  {
388  return;
389  }
390 
391  for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++)
392  {
393  const int itemX = mPadding + ((i % mGridWidth) * mBoxWidth);
394  const int itemY = mPadding + mTitleBarHeight
395  + ((i / CAST_U32(mGridWidth)) * mBoxHeight);
396 
397  graphics->setColor(mBorderColor);
398  graphics->drawRectangle(Rect(itemX, itemY, 32, 32));
399  graphics->setColor(mBackgroundColor);
400  graphics->fillRectangle(Rect(itemX, itemY, 32, 32));
401 
402  if (mItems[mCurrentOutfit][i] < 0)
403  continue;
404 
405  bool foundItem = false;
406  const Inventory *const inv = PlayerInfo::getInventory();
407  if (inv != nullptr)
408  {
409  const Item *const item = inv->findItem(mItems[mCurrentOutfit][i],
411  if (item != nullptr)
412  {
413  // Draw item icon.
414  const Image *const image = item->getImage();
415  if (image != nullptr)
416  {
417  graphics->drawImage(image, itemX, itemY);
418  foundItem = true;
419  }
420  }
421  }
422  if (!foundItem)
423  {
424  Image *const image = Item::getImage(mItems[mCurrentOutfit][i],
426  if (image != nullptr)
427  {
428  graphics->drawImage(image, itemX, itemY);
429  image->decRef();
430  }
431  }
432  }
433  BLOCK_END("OutfitWindow::draw")
434 }
#define CAST_U32
Definition: cast.h:30
int mPadding
Definition: window.h:610
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
Definition: rect.h:72
Inventory * getInventory()
Definition: playerinfo.cpp:207
Definition: window.h:98
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
const unsigned int OUTFIT_ITEM_COUNT
Definition: outfitwindow.h:33
virtual void drawRectangle(const Rect &rectangle)=0
void safeDraw(Graphics *const graphics)
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:126
Color mBackgroundColor
Definition: widget.h:1090
virtual void setColor(const Color &color)
Definition: graphics.h:319
Definition: item.h:48
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
virtual void fillRectangle(const Rect &rectangle)=0
Image * getImage() const
Definition: item.h:86
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
Definition: image.h:61
Color mBorderColor
Definition: outfitwindow.h:115
unsigned int mTitleBarHeight
Definition: window.h:615
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:123
void decRef()
Definition: image.cpp:521

◆ save()

void OutfitWindow::save ( ) const
private

Definition at line 188 of file outfitwindow.cpp.

References CAST_S32, ConfigurationObject::deleteKey(), mAwayOutfit, mItemColors, mItems, mItemsUnequip, OUTFIT_ITEM_COUNT, OUTFITS_COUNT, serverConfig, Configuration::setValue(), toInt, and Catch::toString().

Referenced by clearCurrentOutfit(), copyFromEquiped(), copyOutfit(), mousePressed(), mouseReleased(), and ~OutfitWindow().

189 {
190  std::string outfitStr;
191  std::string outfitColorsStr;
192  for (unsigned o = 0; o < OUTFITS_COUNT; o++)
193  {
194  bool good = false;
195  for (unsigned i = 0; i < OUTFIT_ITEM_COUNT; i++)
196  {
197  const int val = mItems[o][i];
198  const int res = val != 0 ? val : -1;
199  if (res != -1)
200  good = true;
201  outfitStr.append(toString(res));
202  if (i < OUTFIT_ITEM_COUNT - 1)
203  outfitStr.append(" ");
204  outfitColorsStr.append(toString(CAST_S32(
205  toInt(mItemColors[o][i], int))));
206  if (i < OUTFIT_ITEM_COUNT - 1)
207  outfitColorsStr.append(" ");
208  }
209  if (good)
210  {
211  serverConfig.setValue("Outfit" + toString(o), outfitStr);
212  serverConfig.setValue("OutfitColor" + toString(o),
213  outfitColorsStr);
214  }
215  else
216  {
217  serverConfig.deleteKey("Outfit" + toString(o));
218  serverConfig.deleteKey("OutfitColor" + toString(o));
219  }
220 
221  if (mItemsUnequip[o])
222  {
223  serverConfig.deleteKey("OutfitUnequip" + toString(o));
224  }
225  else
226  {
227  serverConfig.setValue("OutfitUnequip" + toString(o),
228  mItemsUnequip[o]);
229  }
230  outfitStr.clear();
231  outfitColorsStr.clear();
232  }
233  serverConfig.setValue("OutfitAwayIndex", mAwayOutfit);
234 }
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:128
const unsigned int OUTFIT_ITEM_COUNT
Definition: outfitwindow.h:33
Configuration serverConfig
#define toInt(val, name)
Definition: intdefines.h:46
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:126
#define CAST_S32
Definition: cast.h:29
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
void deleteKey(const std::string &key)
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:123
void setValue(const std::string &key, const std::string &value)

◆ showCurrentOutfit()

void OutfitWindow::showCurrentOutfit ( )

Definition at line 617 of file outfitwindow.cpp.

References _, CAST_S32, keyName(), mAwayOutfit, mAwayOutfitCheck, mCurrentLabel, mCurrentOutfit, mItemsUnequip, mKeyLabel, mUnequipCheck, OUTFITS_COUNT, Label::setCaption(), CheckBox::setSelected(), and strprintf().

Referenced by next(), previous(), and wearOutfit().

618 {
619  // TRANSLATORS: outfits window label
620  mCurrentLabel->setCaption(strprintf(_("Outfit: %d"), mCurrentOutfit + 1));
623  else
624  mUnequipCheck->setSelected(false);
625  // TRANSLATORS: outfits window label
626  mKeyLabel->setCaption(strprintf(_("Key: %s"),
627  keyName(mCurrentOutfit).c_str()));
628  mAwayOutfitCheck->setSelected(mAwayOutfit == mCurrentOutfit);
629 }
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:128
#define _(s)
Definition: gettext.h:34
Label * mCurrentLabel
Definition: outfitwindow.h:110
CheckBox * mUnequipCheck
Definition: outfitwindow.h:111
#define CAST_S32
Definition: cast.h:29
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void setCaption(const std::string &caption)
Definition: label.cpp:256
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
CheckBox * mAwayOutfitCheck
Definition: outfitwindow.h:112
static std::string keyName(const int number)
Label * mKeyLabel
Definition: outfitwindow.h:113
void setSelected(const bool selected)
Definition: checkbox.h:155

◆ unequipNotInOutfit()

void OutfitWindow::unequipNotInOutfit ( const int  outfit) const

Definition at line 563 of file outfitwindow.cpp.

References Equipped_true, Item::getId(), PlayerInfo::getInventory(), Inventory::getItem(), Inventory::getSize(), Item::isEquipped(), ServerCommandType::item, mItems, Actions::outfit(), OUTFIT_ITEM_COUNT, Sfx_false, and PlayerInfo::unequipItem().

Referenced by wearOutfit().

564 {
565  // here we think that outfit is correct index
566 
567  const Inventory *const inventory = PlayerInfo::getInventory();
568  if (inventory == nullptr)
569  return;
570 
571  const unsigned int invSize = inventory->getSize();
572  for (unsigned i = 0; i < invSize; i++)
573  {
574  const Item *const item = inventory->getItem(i);
575  if ((item != nullptr) && item->isEquipped() == Equipped_true)
576  {
577  bool found = false;
578  for (unsigned f = 0; f < OUTFIT_ITEM_COUNT; f++)
579  {
580  if (item->getId() == mItems[outfit][f])
581  {
582  found = true;
583  break;
584  }
585  }
586  if (!found)
588  }
589  }
590 }
Equipped isEquipped() const
Definition: item.h:128
Inventory * getInventory()
Definition: playerinfo.cpp:207
const bool Sfx_false
Definition: sfx.h:29
const unsigned int OUTFIT_ITEM_COUNT
Definition: outfitwindow.h:33
const bool Equipped_true
Definition: equipped.h:29
Definition: item.h:48
bool outfit(InputEvent &event)
Definition: actions.cpp:31
int getId() const
Definition: item.h:80
void unequipItem(const Item *const item, const Sfx sfx)
Definition: playerinfo.cpp:258
Item * getItem(const int index) const
Definition: inventory.cpp:82
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:123
unsigned getSize() const
Definition: inventory.h:75

◆ unwearAwayOutfit()

void OutfitWindow::unwearAwayOutfit ( )

Definition at line 707 of file outfitwindow.cpp.

References OUTFITS_COUNT, and wearOutfit().

Referenced by AwayListener::action().

708 {
710 }
void wearOutfit(const int outfit, const bool unwearEmpty=true, const bool select=false)
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32

◆ wearAwayOutfit()

void OutfitWindow::wearAwayOutfit ( )

Definition at line 701 of file outfitwindow.cpp.

References copyFromEquiped(), mAwayOutfit, OUTFITS_COUNT, and wearOutfit().

Referenced by GameModifiers::changeAwayMode().

702 {
704  wearOutfit(mAwayOutfit, false);
705 }
void wearOutfit(const int outfit, const bool unwearEmpty=true, const bool select=false)
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
void copyFromEquiped()

◆ wearNextOutfit()

void OutfitWindow::wearNextOutfit ( const bool  all = false)

Definition at line 631 of file outfitwindow.cpp.

References CAST_S32, mCurrentOutfit, mItemsUnequip, next(), OUTFITS_COUNT, and wearOutfit().

Referenced by Actions::changeRelation(), Actions::closeMoveNpcDialog(), and CrazyMoves::crazyMoveAo().

632 {
633  next();
634  if (!all && mCurrentOutfit >= 0 && mCurrentOutfit
636  {
637  bool fromStart = false;
638  while (!mItemsUnequip[mCurrentOutfit])
639  {
640  next();
641  if (mCurrentOutfit == 0)
642  {
643  if (!fromStart)
644  fromStart = true;
645  else
646  return;
647  }
648  }
649  }
650  wearOutfit(mCurrentOutfit);
651 }
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:128
#define CAST_S32
Definition: cast.h:29
void wearOutfit(const int outfit, const bool unwearEmpty=true, const bool select=false)
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32

◆ wearOutfit()

void OutfitWindow::wearOutfit ( const int  outfit,
const bool  unwearEmpty = true,
const bool  select = false 
)

Definition at line 269 of file outfitwindow.cpp.

References CAST_S32, PlayerInfo::equipItem(), Equipm_true, Equipped_false, Inventory::findItem(), PlayerInfo::getInventory(), Item::getQuantity(), Item::isEquipment(), Item::isEquipped(), ServerCommandType::item, mCurrentOutfit, mItemColors, mItems, mItemsUnequip, Actions::outfit(), OUTFIT_ITEM_COUNT, OUTFITS_COUNT, Sfx_false, showCurrentOutfit(), and unequipNotInOutfit().

Referenced by action(), Actions::changeRelation(), Actions::getAmountFromEvent(), unwearAwayOutfit(), wearAwayOutfit(), wearNextOutfit(), and wearPreviousOutfit().

271 {
272  bool isEmpty = true;
273 
274  if (outfit < 0 || outfit > CAST_S32(OUTFITS_COUNT))
275  return;
276 
277  for (unsigned i = 0; i < OUTFIT_ITEM_COUNT; i++)
278  {
279  const Item *const item = PlayerInfo::getInventory()->findItem(
280  mItems[outfit][i],
281  mItemColors[outfit][i]);
282  if ((item != nullptr)
283  && item->isEquipped() == Equipped_false
284  && (item->getQuantity() != 0))
285  {
286  if (item->isEquipment() == Equipm_true)
287  {
289  isEmpty = false;
290  }
291  }
292  }
293 
294  if ((!isEmpty || unwearEmpty) && outfit < CAST_S32(OUTFITS_COUNT)
295  && mItemsUnequip[outfit])
296  {
297  unequipNotInOutfit(outfit);
298  }
299  if (select)
300  {
303  }
304 }
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:128
void equipItem(const Item *const item, const Sfx sfx)
Definition: playerinfo.cpp:250
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
Equipped isEquipped() const
Definition: item.h:128
void showCurrentOutfit()
Inventory * getInventory()
Definition: playerinfo.cpp:207
const bool Sfx_false
Definition: sfx.h:29
const unsigned int OUTFIT_ITEM_COUNT
Definition: outfitwindow.h:33
const bool Equipped_false
Definition: equipped.h:29
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:126
#define CAST_S32
Definition: cast.h:29
const bool Equipm_true
Definition: equipm.h:29
int getQuantity() const
Definition: item.h:104
void unequipNotInOutfit(const int outfit) const
Definition: item.h:48
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
bool outfit(InputEvent &event)
Definition: actions.cpp:31
Equipm isEquipment() const
Definition: item.h:116
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:123

◆ wearPreviousOutfit()

void OutfitWindow::wearPreviousOutfit ( const bool  all = false)

Definition at line 653 of file outfitwindow.cpp.

References CAST_S32, mCurrentOutfit, mItemsUnequip, OUTFITS_COUNT, previous(), and wearOutfit().

Referenced by Actions::changeRelation(), Actions::closeMoveNpcDialog(), and CrazyMoves::crazyMoveAo().

654 {
655  previous();
656  if (!all && mCurrentOutfit >= 0 && mCurrentOutfit
658  {
659  bool fromStart = false;
660  while (!mItemsUnequip[mCurrentOutfit])
661  {
662  previous();
663  if (mCurrentOutfit == 0)
664  {
665  if (!fromStart)
666  fromStart = true;
667  else
668  return;
669  }
670  }
671  }
672  wearOutfit(mCurrentOutfit);
673 }
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:128
#define CAST_S32
Definition: cast.h:29
void wearOutfit(const int outfit, const bool unwearEmpty=true, const bool select=false)
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32

Field Documentation

◆ mAwayOutfit

int OutfitWindow::mAwayOutfit
private

Definition at line 124 of file outfitwindow.h.

Referenced by action(), load(), save(), showCurrentOutfit(), and wearAwayOutfit().

◆ mAwayOutfitCheck

CheckBox* OutfitWindow::mAwayOutfitCheck
private

Definition at line 112 of file outfitwindow.h.

Referenced by action(), load(), OutfitWindow(), and showCurrentOutfit().

◆ mBorderColor

Color OutfitWindow::mBorderColor
private

Definition at line 115 of file outfitwindow.h.

Referenced by draw(), and safeDraw().

◆ mBoxHeight

int OutfitWindow::mBoxHeight
private

Definition at line 119 of file outfitwindow.h.

Referenced by draw(), getIndexFromGrid(), and safeDraw().

◆ mBoxWidth

int OutfitWindow::mBoxWidth
private

Definition at line 118 of file outfitwindow.h.

Referenced by draw(), getIndexFromGrid(), and safeDraw().

◆ mCurrentLabel

Label* OutfitWindow::mCurrentLabel
private

Definition at line 110 of file outfitwindow.h.

Referenced by OutfitWindow(), and showCurrentOutfit().

◆ mCurrentOutfit

int OutfitWindow::mCurrentOutfit
private

◆ mEquipBottom

Button* OutfitWindow::mEquipBottom
private

Definition at line 109 of file outfitwindow.h.

Referenced by OutfitWindow().

◆ mGridHeight

int OutfitWindow::mGridHeight
private

Definition at line 121 of file outfitwindow.h.

Referenced by getIndexFromGrid().

◆ mGridWidth

int OutfitWindow::mGridWidth
private

Definition at line 120 of file outfitwindow.h.

Referenced by draw(), getIndexFromGrid(), and safeDraw().

◆ mItemClicked

bool OutfitWindow::mItemClicked
private

Definition at line 127 of file outfitwindow.h.

Referenced by mouseDragged(), mousePressed(), and mouseReleased().

◆ mItemColors

ItemColor OutfitWindow::mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
private

◆ mItems

int OutfitWindow::mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
private

◆ mItemsUnequip

bool OutfitWindow::mItemsUnequip[OUTFITS_COUNT]
private

◆ mKeyLabel

Label* OutfitWindow::mKeyLabel
private

Definition at line 113 of file outfitwindow.h.

Referenced by OutfitWindow(), and showCurrentOutfit().

◆ mNextButton

Button* OutfitWindow::mNextButton
private

Definition at line 108 of file outfitwindow.h.

Referenced by OutfitWindow().

◆ mPreviousButton

Button* OutfitWindow::mPreviousButton
private

Definition at line 107 of file outfitwindow.h.

Referenced by OutfitWindow().

◆ mUnequipCheck

CheckBox* OutfitWindow::mUnequipCheck
private

Definition at line 111 of file outfitwindow.h.

Referenced by action(), OutfitWindow(), and showCurrentOutfit().


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