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, const bool select)
 
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)
 
void wearPreviousOutfit (const bool all)
 
void wearAwayOutfit ()
 
void unwearAwayOutfit ()
 
void showCurrentOutfit ()
 
void clearCurrentOutfit ()
 
std::string getOutfitString () const
 
- Public Member Functions inherited from Window
 Window (const std::string &caption, const Modal modal, Window *const parent, std::string skin)
 
 ~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, int offsetY)
 
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, const int offsetY)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w, int h)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w, const int h)
 
ContainerPlacer getPlacer (const int x, const int y)
 
void center ()
 
void centerHorisontally ()
 
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)
 
 ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
void focusNext ()
 
void focusPrevious ()
 
void logic ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget *> &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetShown (const Event &event)
 

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) const
 
bool getOptionBool (const std::string &name, const bool def) const
 
void setTitlePadding (const int p)
 
int getTitlePadding () const
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected 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", BUTTON_SKIN, this)),
65  // TRANSLATORS: outfits window button
66  mNextButton(new Button(this, _(">"), "next", BUTTON_SKIN, this)),
67  // TRANSLATORS: outfits window button
68  mEquipBottom(new Button(this, _("Equip"), "equip", BUTTON_SKIN, 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  nullptr, std::string())),
75  // TRANSLATORS: outfits window checkbox
76  mAwayOutfitCheck(new CheckBox(this, _("Away outfit"),
77  serverConfig.getValue("OutfitAwayIndex", OUTFITS_COUNT - 1) != 0U,
78  nullptr, std::string())),
79  // TRANSLATORS: outfits window label
80  mKeyLabel(new Label(this, strprintf(_("Key: %s"),
81  keyName(0).c_str()))),
83  mCurrentOutfit(0),
84  mBoxWidth(33),
85  mBoxHeight(33),
86  mGridWidth(4),
87  mGridHeight(4),
88  mItems(),
89  mAwayOutfit(0),
90  mItemColors(),
91  mItemClicked(false),
93 {
94  setWindowName("Outfits");
95  setResizable(true);
96  setCloseButton(true);
97  setStickyButtonLock(true);
98 
100 
101  setDefaultSize(250, 400, 150, 290);
102  setMinWidth(145);
103  setMinHeight(220);
104 
105  if (setupWindow != nullptr)
107 
110 
111  mUnequipCheck->setActionEventId("unequip");
113 
116 
117  place(1, 3, mEquipBottom, 2, 1);
118  place(0, 4, mKeyLabel, 4, 1);
119  place(0, 5, mPreviousButton, 1, 1);
120  place(1, 5, mCurrentLabel, 2, 1);
121  place(3, 5, mNextButton, 1, 1);
122  place(0, 6, mUnequipCheck, 4, 1);
123  place(0, 7, mAwayOutfitCheck, 4, 1);
124 
125  Layout &layout = getLayout();
126  layout.setRowHeight(0, LayoutType::SET);
127  layout.setColWidth(4, Layout::CENTER);
128 
129  loadWindowState();
130 
131  enableVisibleSound(true);
132  load();
133 }
void setDefaultSize()
Definition: window.cpp:1197
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1383
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:129
#define _(s)
Definition: gettext.h:34
Button * mPreviousButton
Definition: outfitwindow.h:108
void loadWindowState()
Definition: window.cpp:1086
Label * mCurrentLabel
Definition: outfitwindow.h:111
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
void setMinWidth(const int width)
Definition: window.cpp:590
Definition: button.h:96
void setColWidth(const int n, const int w)
Definition: layoutcell.cpp:122
CheckBox * mUnequipCheck
Definition: outfitwindow.h:112
Button * mEquipBottom
Definition: outfitwindow.h:110
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:127
Color mBackgroundColor
Definition: widget.h:1090
const std::string BUTTON_SKIN
Definition: button.h:88
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
Definition: label.h:87
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:748
void enableVisibleSound(bool b)
Definition: window.h:480
void setMinHeight(const int height)
Definition: window.cpp:603
Layout & getLayout()
Definition: window.cpp:1364
CheckBox * mAwayOutfitCheck
Definition: outfitwindow.h:113
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:109
Label * mKeyLabel
Definition: outfitwindow.h:114
Color mBorderColor
Definition: outfitwindow.h:116
void setResizable(const bool resize)
Definition: window.cpp:626
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:771
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
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:124
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:108
void setWindowName(const std::string &name)
Definition: window.h:354

◆ ~OutfitWindow()

OutfitWindow::~OutfitWindow ( )

Destructor.

Definition at line 135 of file outfitwindow.cpp.

References save().

136 {
137  save();
138 }
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 238 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().

239 {
240  const std::string &eventId = event.getId();
241  if (eventId == "next")
242  {
243  next();
244  }
245  else if (eventId == "previous")
246  {
247  previous();
248  }
249  else if (eventId == "unequip")
250  {
251  if (mCurrentOutfit >= 0 && mCurrentOutfit < CAST_S32(
252  OUTFITS_COUNT))
253  {
255  }
256  }
257  else if (eventId == "equip")
258  {
260  true,
261  false);
262  if (Game::instance() != nullptr)
264  }
265  else if (eventId == "away")
266  {
270  }
271 }
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:129
void setValidSpeed()
Definition: game.cpp:1272
CheckBox * mUnequipCheck
Definition: outfitwindow.h:112
#define CAST_S32
Definition: cast.h:29
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
CheckBox * mAwayOutfitCheck
Definition: outfitwindow.h:113
void wearOutfit(const int outfit, const bool unwearEmpty, const bool select)
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 725 of file outfitwindow.cpp.

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

Referenced by Actions::changeRelation().

726 {
727  if (mCurrentOutfit < 0 || mCurrentOutfit
728  >= static_cast<signed int>(OUTFITS_COUNT))
729  {
730  return;
731  }
732  for (unsigned f = 0; f < OUTFIT_ITEM_COUNT; f++)
733  {
734  mItems[mCurrentOutfit][f] = -1;
736  }
737  save();
738 }
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:127
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
void save() const
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:124

◆ copyFromEquiped() [1/2]

void OutfitWindow::copyFromEquiped ( )

Definition at line 684 of file outfitwindow.cpp.

References mCurrentOutfit.

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

685 {
687 }
void copyFromEquiped()

◆ copyFromEquiped() [2/2]

void OutfitWindow::copyFromEquiped ( const int  dst)

Definition at line 689 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().

690 {
691  const Inventory *const inventory = PlayerInfo::getInventory();
692  if (inventory == nullptr)
693  return;
694 
695  int outfitCell = 0;
696  for (unsigned i = 0, sz = inventory->getSize(); i < sz; i++)
697  {
698  const Item *const item = inventory->getItem(i);
699  if ((item != nullptr) && item->isEquipped() == Equipped_true)
700  {
701  mItems[dst][outfitCell] = item->getId();
702  mItemColors[dst][outfitCell++] = item->getColor();
703  if (outfitCell >= CAST_S32(OUTFIT_ITEM_COUNT))
704  break;
705  }
706  }
707  save();
708 }
Equipped isEquipped() const
Definition: item.h:128
Inventory * getInventory()
Definition: playerinfo.cpp:193
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:127
#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:124
unsigned getSize() const
Definition: inventory.h:75

◆ copyOutfit() [1/2]

void OutfitWindow::copyOutfit ( const int  outfit)

Definition at line 311 of file outfitwindow.cpp.

References mCurrentOutfit.

Referenced by Actions::getAmountFromEvent().

312 {
314 }
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 316 of file outfitwindow.cpp.

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

317 {
318  if (src < 0 || src > CAST_S32(OUTFITS_COUNT)
319  || dst < 0 || dst > CAST_S32(OUTFITS_COUNT))
320  {
321  return;
322  }
323 
324  for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++)
325  mItems[dst][i] = mItems[src][i];
326  save();
327 }
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:124

◆ draw()

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

Draws the window.

Reimplemented from Window.

Definition at line 329 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().

330 {
331  BLOCK_START("OutfitWindow::draw")
332  Window::draw(graphics);
333 
335  >= static_cast<signed int>(OUTFITS_COUNT))
336  {
337  return;
338  }
339 
340  for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++)
341  {
342  const int itemX = mPadding + ((i % mGridWidth) * mBoxWidth);
343  const int itemY = mPadding + mTitleBarHeight
344  + ((i / CAST_U32(mGridWidth)) * mBoxHeight);
345 
346  graphics->setColor(mBorderColor);
347  graphics->drawRectangle(Rect(itemX, itemY, 32, 32));
348  graphics->setColor(mBackgroundColor);
349  graphics->fillRectangle(Rect(itemX, itemY, 32, 32));
350 
351  if (mItems[mCurrentOutfit][i] < 0)
352  continue;
353 
354  bool foundItem = false;
355  const Inventory *const inv = PlayerInfo::getInventory();
356  if (inv != nullptr)
357  {
358  const Item *const item = inv->findItem(mItems[mCurrentOutfit][i],
360  if (item != nullptr)
361  {
362  // Draw item icon.
363  const Image *const image = item->getImage();
364  if (image != nullptr)
365  {
366  graphics->drawImage(image, itemX, itemY);
367  foundItem = true;
368  }
369  }
370  }
371  if (!foundItem)
372  {
373  Image *const image = Item::getImage(mItems[mCurrentOutfit][i],
375  if (image != nullptr)
376  {
377  graphics->drawImage(image, itemX, itemY);
378  image->decRef();
379  }
380  }
381  }
382  BLOCK_END("OutfitWindow::draw")
383 }
#define CAST_U32
Definition: cast.h:30
int mPadding
Definition: window.h:617
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
Definition: rect.h:72
Inventory * getInventory()
Definition: playerinfo.cpp:193
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:127
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:116
unsigned int mTitleBarHeight
Definition: window.h:622
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:124
void decRef()
Definition: image.cpp:522
void draw(Graphics *const graphics)

◆ getIndexFromGrid()

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

Definition at line 555 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().

556 {
557  const Rect tRect = Rect(mPadding, mTitleBarHeight,
559  if (!tRect.isPointInRect(pointX, pointY))
560  return -1;
561  const int index = (((pointY - mTitleBarHeight) / mBoxHeight) * mGridWidth)
562  + (pointX - mPadding) / mBoxWidth;
563  if (index >= CAST_S32(OUTFIT_ITEM_COUNT) || index < 0)
564  return -1;
565  return index;
566 }
int mPadding
Definition: window.h:617
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:622

◆ getOutfitString()

std::string OutfitWindow::getOutfitString ( ) const

Definition at line 740 of file outfitwindow.cpp.

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

Referenced by Actions::changeRelation().

741 {
742  std::string str;
743  for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++)
744  {
745  const int id = mItems[mCurrentOutfit][i];
746  if (id < 0)
747  continue;
748 
749  const ItemColor color = mItemColors[mCurrentOutfit][i];
750  STD_VECTOR<int> ids;
751  ids.push_back(id);
752  ids.push_back(CAST_S32(color));
753 
754  const std::string name = ItemDB::getNamesStr(ids);
755  if (name.empty())
756  continue;
757  str.append("[");
758  str.append(name);
759  str.append("] ");
760  }
761  return str;
762 }
std::string getNamesStr(const std::vector< int > &parts)
Definition: itemdb.cpp:1180
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:127
#define CAST_S32
Definition: cast.h:29
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:124

◆ keyName()

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

Definition at line 597 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().

598 {
599  if (number < 0 || number >= SHORTCUT_EMOTES)
600  return "";
602 }
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 140 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().

141 {
142  const Configuration *cfg = &serverConfig;
143 
144  memset(mItems, -1, sizeof(mItems));
145  memset(mItemColors, 1, sizeof(mItemColors));
146 
147  for (unsigned o = 0; o < OUTFITS_COUNT; o++)
148  {
149  std::string outfit = cfg->getValue("Outfit" + toString(o), "-1");
150  std::string buf;
151  std::stringstream ss(outfit);
152 
153  STD_VECTOR<int> tokens;
154 
155  while (ss >> buf)
156  tokens.push_back(atoi(buf.c_str()));
157 
158  for (size_t i = 0, sz = tokens.size();
159  i < sz && i < OUTFIT_ITEM_COUNT; i++)
160  {
161  mItems[o][i] = tokens[i];
162  }
163 
164  outfit = cfg->getValue("OutfitColor" + toString(o), "1");
165  std::stringstream ss2(outfit);
166 
167  tokens.clear();
168 
169  STD_VECTOR<unsigned char> tokens2;
170  while (ss2 >> buf)
171  tokens2.push_back(CAST_U8(atoi(buf.c_str())));
172 
173  for (size_t i = 0, sz = tokens2.size();
174  i < sz && i < OUTFIT_ITEM_COUNT; i++)
175  {
176  mItemColors[o][i] = fromInt(tokens2[i], ItemColor);
177  }
178 
179  mItemsUnequip[o] = cfg->getValueBool("OutfitUnequip" + toString(o),
180  true);
181  }
182  mAwayOutfit = cfg->getValue("OutfitAwayIndex", OUTFITS_COUNT - 1);
183  if (mAwayOutfit >= CAST_S32(OUTFITS_COUNT))
184  mAwayOutfit = CAST_S32(OUTFITS_COUNT) - 1;
185 
186  if (mAwayOutfitCheck != nullptr)
188 }
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:129
#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:127
#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:113
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:124

◆ 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 441 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.

442 {
443  if (event.getButton() == MouseButton::LEFT)
444  {
445  if (dragDrop.isEmpty() && mItemClicked)
446  {
447  if (mCurrentOutfit < 0 || mCurrentOutfit
448  >= static_cast<signed int>(OUTFITS_COUNT))
449  {
450  Window::mouseDragged(event);
451  return;
452  }
453 
454  const int index = getIndexFromGrid(event.getX(), event.getY());
455  if (index == -1)
456  {
457  Window::mouseDragged(event);
458  return;
459  }
460  const int itemId = mItems[mCurrentOutfit][index];
461  const ItemColor itemColor = mItemColors[mCurrentOutfit][index];
462  if (itemId < 0)
463  {
464  Window::mouseDragged(event);
465  return;
466  }
467  mMoved = false;
468  event.consume();
469  const Inventory *const inv = PlayerInfo::getInventory();
470  if (inv != nullptr)
471  {
472  Item *const item = inv->findItem(itemId, itemColor);
473  if (item != nullptr)
475  else
476  dragDrop.clear();
477  mItems[mCurrentOutfit][index] = -1;
478  }
479  }
480  }
481  Window::mouseDragged(event);
482 }
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:115
Inventory * getInventory()
Definition: playerinfo.cpp:193
DragDrop dragDrop
uint16_t ItemColor
Definition: itemcolor.h:29
bool mMoved
Definition: window.h:646
bool isEmpty() const
Definition: dragdrop.h:195
void dragItem(const Item *const item, const DragDropSourceT source, const int tag)
Definition: dragdrop.h:86
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:127
Definition: item.h:48
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
void mouseDragged(MouseEvent &event)
Definition: window.cpp:981
int getX() const
Definition: mouseevent.h:126
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:124
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 484 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.

485 {
486  const int index = getIndexFromGrid(event.getX(), event.getY());
487  if (event.getButton() == MouseButton::RIGHT && (popupMenu != nullptr))
488  {
490  viewport->mMouseY);
491  event.consume();
492  return;
493  }
494  else if (index == -1)
495  {
496  Window::mousePressed(event);
497  return;
498  }
499  mMoved = false;
500  event.consume();
501 
502  if (mItems[mCurrentOutfit][index] > 0)
503  {
504  mItemClicked = true;
505  }
506  else
507  {
508  if (dragDrop.isSelected())
509  {
512  dragDrop.deselect();
513  save();
514  }
515  }
516 
517  Window::mousePressed(event);
518 }
bool isSelected() const
Definition: dragdrop.h:224
MouseButtonT getButton() const
Definition: mouseevent.h:115
DragDrop dragDrop
bool mMoved
Definition: window.h:646
int mMouseX
Definition: viewport.h:153
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:127
int getSelected() const
Definition: dragdrop.h:218
PopupMenu * popupMenu
Definition: popupmenu.cpp:102
void showOutfitsWindowPopup(const int x, const int y)
Definition: popupmenu.cpp:852
void deselect()
Definition: dragdrop.h:212
void save() const
int mMouseY
Definition: viewport.h:154
void mousePressed(MouseEvent &event)
Definition: window.cpp:835
int getX() const
Definition: mouseevent.h:126
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:124
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 520 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().

521 {
522  if (event.getButton() == MouseButton::LEFT)
523  {
524  if (mCurrentOutfit < 0 || mCurrentOutfit
525  >= static_cast<signed int>(OUTFITS_COUNT))
526  {
527  return;
528  }
529  const int index = getIndexFromGrid(event.getX(), event.getY());
530  if (index == -1)
531  {
532  dragDrop.clear();
533  Window::mouseReleased(event);
534  return;
535  }
536  mMoved = false;
537  event.consume();
538  if (!dragDrop.isEmpty())
539  {
541  {
544  dragDrop.clear();
545  dragDrop.deselect();
546  save();
547  }
548  }
549  if (mItemClicked)
550  mItemClicked = false;
551  }
552  Window::mouseReleased(event);
553 }
void clear()
Definition: dragdrop.h:182
MouseButtonT getButton() const
Definition: mouseevent.h:115
DragDrop dragDrop
bool mMoved
Definition: window.h:646
bool isEmpty() const
Definition: dragdrop.h:195
ItemColor mItemColors[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:127
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:906
ItemColor getItemColor() const
Definition: dragdrop.h:68
int getX() const
Definition: mouseevent.h:126
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:124
int getIndexFromGrid(const int pointX, const int pointY) const
int getItem() const
Definition: dragdrop.h:65

◆ next()

void OutfitWindow::next ( )

Definition at line 604 of file outfitwindow.cpp.

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

Referenced by action(), and wearNextOutfit().

605 {
607  mCurrentOutfit++;
608  else
609  mCurrentOutfit = 0;
611 }
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 613 of file outfitwindow.cpp.

References mCurrentOutfit, OUTFITS_COUNT, and showCurrentOutfit().

Referenced by action(), and wearPreviousOutfit().

614 {
615  if (mCurrentOutfit > 0)
616  mCurrentOutfit--;
617  else
620 }
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 385 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().

386 {
387  BLOCK_START("OutfitWindow::draw")
388  Window::safeDraw(graphics);
389 
391  >= static_cast<signed int>(OUTFITS_COUNT))
392  {
393  return;
394  }
395 
396  for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++)
397  {
398  const int itemX = mPadding + ((i % mGridWidth) * mBoxWidth);
399  const int itemY = mPadding + mTitleBarHeight
400  + ((i / CAST_U32(mGridWidth)) * mBoxHeight);
401 
402  graphics->setColor(mBorderColor);
403  graphics->drawRectangle(Rect(itemX, itemY, 32, 32));
404  graphics->setColor(mBackgroundColor);
405  graphics->fillRectangle(Rect(itemX, itemY, 32, 32));
406 
407  if (mItems[mCurrentOutfit][i] < 0)
408  continue;
409 
410  bool foundItem = false;
411  const Inventory *const inv = PlayerInfo::getInventory();
412  if (inv != nullptr)
413  {
414  const Item *const item = inv->findItem(mItems[mCurrentOutfit][i],
416  if (item != nullptr)
417  {
418  // Draw item icon.
419  const Image *const image = item->getImage();
420  if (image != nullptr)
421  {
422  graphics->drawImage(image, itemX, itemY);
423  foundItem = true;
424  }
425  }
426  }
427  if (!foundItem)
428  {
429  Image *const image = Item::getImage(mItems[mCurrentOutfit][i],
431  if (image != nullptr)
432  {
433  graphics->drawImage(image, itemX, itemY);
434  image->decRef();
435  }
436  }
437  }
438  BLOCK_END("OutfitWindow::draw")
439 }
#define CAST_U32
Definition: cast.h:30
int mPadding
Definition: window.h:617
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
Definition: rect.h:72
Inventory * getInventory()
Definition: playerinfo.cpp:193
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:127
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:116
unsigned int mTitleBarHeight
Definition: window.h:622
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:124
void decRef()
Definition: image.cpp:522

◆ save()

void OutfitWindow::save ( ) const
private

Definition at line 190 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().

191 {
192  std::string outfitStr;
193  std::string outfitColorsStr;
194  for (unsigned o = 0; o < OUTFITS_COUNT; o++)
195  {
196  bool good = false;
197  for (unsigned i = 0; i < OUTFIT_ITEM_COUNT; i++)
198  {
199  const int val = mItems[o][i];
200  const int res = val != 0 ? val : -1;
201  if (res != -1)
202  good = true;
203  outfitStr.append(toString(res));
204  if (i < OUTFIT_ITEM_COUNT - 1)
205  outfitStr.append(" ");
206  outfitColorsStr.append(toString(CAST_S32(
207  toInt(mItemColors[o][i], int))));
208  if (i < OUTFIT_ITEM_COUNT - 1)
209  outfitColorsStr.append(" ");
210  }
211  if (good)
212  {
213  serverConfig.setValue("Outfit" + toString(o), outfitStr);
214  serverConfig.setValue("OutfitColor" + toString(o),
215  outfitColorsStr);
216  }
217  else
218  {
219  serverConfig.deleteKey("Outfit" + toString(o));
220  serverConfig.deleteKey("OutfitColor" + toString(o));
221  }
222 
223  if (mItemsUnequip[o])
224  {
225  serverConfig.deleteKey("OutfitUnequip" + toString(o));
226  }
227  else
228  {
229  serverConfig.setValue("OutfitUnequip" + toString(o),
230  mItemsUnequip[o]);
231  }
232  outfitStr.clear();
233  outfitColorsStr.clear();
234  }
235  serverConfig.setValue("OutfitAwayIndex", mAwayOutfit);
236 }
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:129
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:127
#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:124
void setValue(const std::string &key, const std::string &value)

◆ showCurrentOutfit()

void OutfitWindow::showCurrentOutfit ( )

Definition at line 622 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().

623 {
624  // TRANSLATORS: outfits window label
625  mCurrentLabel->setCaption(strprintf(_("Outfit: %d"), mCurrentOutfit + 1));
628  else
629  mUnequipCheck->setSelected(false);
630  // TRANSLATORS: outfits window label
631  mKeyLabel->setCaption(strprintf(_("Key: %s"),
632  keyName(mCurrentOutfit).c_str()));
633  mAwayOutfitCheck->setSelected(mAwayOutfit == mCurrentOutfit);
634 }
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:129
#define _(s)
Definition: gettext.h:34
Label * mCurrentLabel
Definition: outfitwindow.h:111
CheckBox * mUnequipCheck
Definition: outfitwindow.h:112
#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:261
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
CheckBox * mAwayOutfitCheck
Definition: outfitwindow.h:113
static std::string keyName(const int number)
Label * mKeyLabel
Definition: outfitwindow.h:114
void setSelected(const bool selected)
Definition: checkbox.h:155

◆ unequipNotInOutfit()

void OutfitWindow::unequipNotInOutfit ( const int  outfit) const

Definition at line 568 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().

569 {
570  // here we think that outfit is correct index
571 
572  const Inventory *const inventory = PlayerInfo::getInventory();
573  if (inventory == nullptr)
574  return;
575 
576  const unsigned int invSize = inventory->getSize();
577  for (unsigned i = 0; i < invSize; i++)
578  {
579  const Item *const item = inventory->getItem(i);
580  if ((item != nullptr) && item->isEquipped() == Equipped_true)
581  {
582  bool found = false;
583  for (unsigned f = 0; f < OUTFIT_ITEM_COUNT; f++)
584  {
585  if (item->getId() == mItems[outfit][f])
586  {
587  found = true;
588  break;
589  }
590  }
591  if (!found)
593  }
594  }
595 }
Equipped isEquipped() const
Definition: item.h:128
Inventory * getInventory()
Definition: playerinfo.cpp:193
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:244
Item * getItem(const int index) const
Definition: inventory.cpp:82
int mItems[OUTFITS_COUNT+1][OUTFIT_ITEM_COUNT]
Definition: outfitwindow.h:124
unsigned getSize() const
Definition: inventory.h:75

◆ unwearAwayOutfit()

void OutfitWindow::unwearAwayOutfit ( )

Definition at line 718 of file outfitwindow.cpp.

References OUTFITS_COUNT, and wearOutfit().

Referenced by AwayListener::action().

719 {
721  true,
722  false);
723 }
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
void wearOutfit(const int outfit, const bool unwearEmpty, const bool select)

◆ wearAwayOutfit()

void OutfitWindow::wearAwayOutfit ( )

Definition at line 710 of file outfitwindow.cpp.

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

Referenced by GameModifiers::changeAwayMode().

711 {
714  false,
715  false);
716 }
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
void wearOutfit(const int outfit, const bool unwearEmpty, const bool select)
void copyFromEquiped()

◆ wearNextOutfit()

void OutfitWindow::wearNextOutfit ( const bool  all)

Definition at line 636 of file outfitwindow.cpp.

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

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

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

◆ wearOutfit()

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

Definition at line 273 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().

276 {
277  bool isEmpty = true;
278 
279  if (outfit < 0 || outfit > CAST_S32(OUTFITS_COUNT))
280  return;
281 
282  for (unsigned i = 0; i < OUTFIT_ITEM_COUNT; i++)
283  {
284  const Item *const item = PlayerInfo::getInventory()->findItem(
285  mItems[outfit][i],
286  mItemColors[outfit][i]);
287  if ((item != nullptr)
288  && item->isEquipped() == Equipped_false
289  && (item->getQuantity() != 0))
290  {
291  if (item->isEquipment() == Equipm_true)
292  {
294  isEmpty = false;
295  }
296  }
297  }
298 
299  if ((!isEmpty || unwearEmpty) && outfit < CAST_S32(OUTFITS_COUNT)
300  && mItemsUnequip[outfit])
301  {
302  unequipNotInOutfit(outfit);
303  }
304  if (select)
305  {
308  }
309 }
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:129
void equipItem(const Item *const item, const Sfx sfx)
Definition: playerinfo.cpp:236
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:193
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:127
#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:124

◆ wearPreviousOutfit()

void OutfitWindow::wearPreviousOutfit ( const bool  all)

Definition at line 660 of file outfitwindow.cpp.

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

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

661 {
662  previous();
663  if (!all && mCurrentOutfit >= 0 && mCurrentOutfit
665  {
666  bool fromStart = false;
667  while (!mItemsUnequip[mCurrentOutfit])
668  {
669  previous();
670  if (mCurrentOutfit == 0)
671  {
672  if (!fromStart)
673  fromStart = true;
674  else
675  return;
676  }
677  }
678  }
679  wearOutfit(mCurrentOutfit,
680  true,
681  false);
682 }
bool mItemsUnequip[OUTFITS_COUNT]
Definition: outfitwindow.h:129
#define CAST_S32
Definition: cast.h:29
const unsigned int OUTFITS_COUNT
Definition: outfitwindow.h:32
void wearOutfit(const int outfit, const bool unwearEmpty, const bool select)

Field Documentation

◆ mAwayOutfit

int OutfitWindow::mAwayOutfit
private

Definition at line 125 of file outfitwindow.h.

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

◆ mAwayOutfitCheck

CheckBox* OutfitWindow::mAwayOutfitCheck
private

Definition at line 113 of file outfitwindow.h.

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

◆ mBorderColor

Color OutfitWindow::mBorderColor
private

Definition at line 116 of file outfitwindow.h.

Referenced by draw(), and safeDraw().

◆ mBoxHeight

int OutfitWindow::mBoxHeight
private

Definition at line 120 of file outfitwindow.h.

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

◆ mBoxWidth

int OutfitWindow::mBoxWidth
private

Definition at line 119 of file outfitwindow.h.

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

◆ mCurrentLabel

Label* OutfitWindow::mCurrentLabel
private

Definition at line 111 of file outfitwindow.h.

Referenced by OutfitWindow(), and showCurrentOutfit().

◆ mCurrentOutfit

int OutfitWindow::mCurrentOutfit
private

◆ mEquipBottom

Button* OutfitWindow::mEquipBottom
private

Definition at line 110 of file outfitwindow.h.

Referenced by OutfitWindow().

◆ mGridHeight

int OutfitWindow::mGridHeight
private

Definition at line 122 of file outfitwindow.h.

Referenced by getIndexFromGrid().

◆ mGridWidth

int OutfitWindow::mGridWidth
private

Definition at line 121 of file outfitwindow.h.

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

◆ mItemClicked

bool OutfitWindow::mItemClicked
private

Definition at line 128 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 114 of file outfitwindow.h.

Referenced by OutfitWindow(), and showCurrentOutfit().

◆ mNextButton

Button* OutfitWindow::mNextButton
private

Definition at line 109 of file outfitwindow.h.

Referenced by OutfitWindow().

◆ mPreviousButton

Button* OutfitWindow::mPreviousButton
private

Definition at line 108 of file outfitwindow.h.

Referenced by OutfitWindow().

◆ mUnequipCheck

CheckBox* OutfitWindow::mUnequipCheck
private

Definition at line 112 of file outfitwindow.h.

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


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