ManaPlus
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes

#include <equipmentwindow.h>

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

Public Member Functions

 EquipmentWindow (Equipment *const equipment, Being *const being, const bool foring=false)
 
 ~EquipmentWindow ()
 
void postInit ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void action (const ActionEvent &event)
 
void mousePressed (MouseEvent &event)
 
const ItemgetEquipment (const int i) const
 
void setBeing (Being *const being)
 
void updateBeing (Being *const being)
 
void resetBeing (const Being *const being)
 
void mouseExited (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void recalcSize ()
 
- 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)
 
WindowgetParentWindow () const
 
virtual void scheduleDelete ()
 
void mouseDragged (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)
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 

Static Public Member Functions

static void prepareSlotNames ()
 
- 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

const ItemgetItem (const int x, const int y) const
 
void setSelected (const int index)
 
void fillBoxes ()
 
void fillDefault ()
 
void updatePage ()
 
int addPage (const std::string &name)
 
void addDefaultPage ()
 
void addBox (const int idx, int x, int y, const int imageIndex)
 
void loadWindow (const xmlNode *const windowNode)
 
void loadPage (const xmlNodePtr node)
 
void loadPlayerBox (const xmlNodePtr playerBoxNode, const int page)
 
void loadSlot (const xmlNodePtr slotNode, const ImageSet *const imageset, const int page)
 

Static Private Member Functions

static int parseSlotName (const std::string &name)
 

Private Attributes

EquipmentmEquipment
 
PlayerBoxmPlayerBox
 
ButtonmUnequip
 
ImageSetmImageSet
 
BeingmBeing
 
ImagemSlotBackground
 
ImagemSlotHighlightedBackground
 
ImageCollectionmVertexes
 
std::vector< EquipmentPage * > mPages
 
TabStripmTabs
 
Color mHighlightColor
 
Color mBorderColor
 
Color mLabelsColor
 
Color mLabelsColor2
 
int mSelected
 
int mItemPadding
 
int mBoxSize
 
int mButtonPadding
 
int mMinX
 
int mMinY
 
int mMaxX
 
int mMaxY
 
int mYPadding
 
int mSelectedTab
 
bool mForing
 
bool mHaveDefaultPage
 

Static Private Attributes

static StringIntMap mSlotNames
 

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 Member Functions inherited from ActionListener
 ActionListener ()
 
- 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

Equipment dialog.

Definition at line 51 of file equipmentwindow.h.

Constructor & Destructor Documentation

◆ EquipmentWindow()

EquipmentWindow::EquipmentWindow ( Equipment *const  equipment,
Being *const  being,
const bool  foring = false 
)

Constructor.

Definition at line 63 of file equipmentwindow.cpp.

References Widget::addActionListener(), config, fillBoxes(), Widget::getHeight(), Configuration::getIntValue(), Window::getOption(), Window::loadWindowState(), mBoxSize, mPlayerBox, mTabs, mYPadding, recalcSize(), SetupWindow::registerWindowForReset(), Widget::setActionEventId(), Window::setCloseButton(), Widget::setDimension(), PlayerBox::setPlayer(), Window::setSaveVisible(), Widget::setSelectable(), Window::setStickyButtonLock(), setupWindow, Window::setWindowName(), ServerCommandType::size, and updatePage().

65  :
66  // TRANSLATORS: equipment window name
67  Window(_("Equipment"), Modal_false, nullptr, "equipment.xml"),
69  mEquipment(equipment),
70  mPlayerBox(new PlayerBox(this,
71  "equipment_playerbox.xml",
72  "equipment_selectedplayerbox.xml")),
73  // TRANSLATORS: equipment window button
74  mUnequip(new Button(this, _("Unequip"), "unequip", this)),
75  mImageSet(nullptr),
76  mBeing(being),
80  mPages(),
81  mTabs(nullptr),
86  mSelected(-1),
87  mItemPadding(getOption("itemPadding")),
88  mBoxSize(getOption("boxSize")),
89  mButtonPadding(getOption("buttonPadding", 5)),
90  mMinX(180),
91  mMinY(345),
92  mMaxX(0),
93  mMaxY(0),
94  mYPadding(0),
95  mSelectedTab(0),
96  mForing(foring),
97  mHaveDefaultPage(false)
98 {
99  const int size = config.getIntValue("fontSize")
100  + getOption("tabHeightAdjust", 16);
101  mTabs = new TabStrip(this, "equipment", size);
102  mTabs->addActionListener(this);
103  mTabs->setActionEventId("tab_");
104  mTabs->setSelectable(false);
105 
106  mYPadding = mTabs->getHeight() + getOption("tabPadding", 2);
107 
108  if (setupWindow != nullptr)
110 
111  if (mBoxSize == 0)
112  mBoxSize = 36;
113 
114  // Control that shows the Player
115  mPlayerBox->setDimension(Rect(50, 80 + mYPadding, 74, 168));
116  mPlayerBox->setPlayer(being);
117  mPlayerBox->setSelectable(false);
118 
119  if (foring)
120  setWindowName("Being equipment");
121  else
122  setWindowName("Equipment");
123 
124  setCloseButton(true);
125  setSaveVisible(true);
126  setStickyButtonLock(true);
127 
128  fillBoxes();
129  recalcSize();
130  updatePage();
131  loadWindowState();
132 }
void setPlayer(Being *being)
Definition: playerbox.h:73
#define _(s)
Definition: gettext.h:34
ImageSet * mImageSet
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha=255U) const A_INLINE
Definition: widget2.h:44
void loadWindowState()
Definition: window.cpp:1075
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
Definition: rect.h:72
ImageCollection * mVertexes
Definition: button.h:94
Configuration config
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
int getIntValue(const std::string &key) const
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
void registerWindowForReset(Window *const window)
void setSelectable(const bool selectable)
Definition: widget.h:947
std::vector< EquipmentPage * > mPages
void setCloseButton(const bool flag)
Definition: window.cpp:737
Equipment * mEquipment
void setSaveVisible(const bool save)
Definition: window.h:298
Image * mSlotHighlightedBackground
int getHeight() const
Definition: widget.h:239
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:760
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
int getOption(const std::string &name, const int def=0) const
Definition: window.cpp:1442
Window(const std::string &caption="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
Definition: window.cpp:108
void setWindowName(const std::string &name)
Definition: window.h:353
PlayerBox * mPlayerBox

◆ ~EquipmentWindow()

EquipmentWindow::~EquipmentWindow ( )

Destructor.

Definition at line 154 of file equipmentwindow.cpp.

References Resource::decRef(), Image::decRef(), delete2, delete_all(), FOR_EACH, Equipment::getBackend(), mEquipment, mImageSet, mPages, mSlotBackground, mSlotHighlightedBackground, and mVertexes.

155 {
156  if (this == beingEquipmentWindow)
157  {
158  if (mEquipment != nullptr)
159  delete mEquipment->getBackend();
161  }
162  FOR_EACH (STD_VECTOR<EquipmentPage*>::iterator, it, mPages)
163  {
164  STD_VECTOR<EquipmentBox*> &boxes = (*it)->boxes;
165  delete_all(boxes);
166  boxes.clear();
167  delete *it;
168  }
169  if (mImageSet != nullptr)
170  {
171  mImageSet->decRef();
172  mImageSet = nullptr;
173  }
174  if (mSlotBackground != nullptr)
176  if (mSlotHighlightedBackground != nullptr)
179 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
ImageSet * mImageSet
virtual void decRef()
Definition: resource.cpp:49
ImageCollection * mVertexes
const Backend * getBackend() const
Definition: equipment.h:88
#define delete2(var)
Definition: delete2.h:24
std::vector< EquipmentPage * > mPages
void delete_all(Container &c)
Definition: dtor.h:55
EquipmentWindow * beingEquipmentWindow
Equipment * mEquipment
Image * mSlotHighlightedBackground
void decRef()
Definition: image.cpp:521

Member Function Documentation

◆ action()

void EquipmentWindow::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 343 of file equipmentwindow.cpp.

References dragDrop, PlayerInfo::equipItem(), Equipm_true, DragDropSource::Equipment, Equipped_false, Inventory::findItem(), Equipment::getEquipment(), PlayerInfo::getInventory(), DragDrop::getItem(), DragDrop::getItemColor(), DragDrop::getSource(), Button::getTag(), DragDropSource::Inventory, DragDrop::isEmpty(), Item::isEquipment(), Item::isEquipped(), ServerCommandType::item, localPlayer, mEquipment, mSelected, mSelectedTab, setSelected(), Sfx_true, PlayerInfo::unequipItem(), and updatePage().

344 {
345  const std::string &eventId = event.getId();
346  if (eventId == "unequip")
347  {
348  if ((mEquipment == nullptr) || mSelected == -1)
349  return;
350 
351  const Item *const item = mEquipment->getEquipment(mSelected);
353  setSelected(-1);
354  }
355  else if (eventId.find("tab_") == 0u)
356  {
357  Button *const button = dynamic_cast<Button*>(event.getSource());
358  if (button == nullptr)
359  return;
360  mSelectedTab = button->getTag();
361  updatePage();
362  }
363  else if (eventId == "playerbox")
364  {
365  const DragDropSourceT src = dragDrop.getSource();
367  && src != DragDropSource::Equipment))
368  {
369  return;
370  }
371  Inventory *const inventory = localPlayer != nullptr
373  if (inventory == nullptr)
374  return;
375  Item *const item = inventory->findItem(dragDrop.getItem(),
377  if (item == nullptr)
378  return;
379 
381  {
382  if (item->isEquipment() == Equipm_true)
383  {
384  if (item->isEquipped() == Equipped_false)
386  }
387  }
388  }
389 }
DragDropSource ::T DragDropSourceT
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
Inventory * getInventory()
Definition: playerinfo.cpp:207
Definition: button.h:94
const bool Sfx_true
Definition: sfx.h:29
DragDrop dragDrop
bool isEmpty() const
Definition: dragdrop.h:195
const bool Equipped_false
Definition: equipped.h:29
const Item * getEquipment(const int index) const
Definition: equipment.h:68
const bool Equipm_true
Definition: equipm.h:29
LocalPlayer * localPlayer
int getTag() const
Definition: button.h:179
Definition: item.h:48
#define nullptr
Definition: localconsts.h:44
Equipment * mEquipment
void unequipItem(const Item *const item, const Sfx sfx)
Definition: playerinfo.cpp:258
ItemColor getItemColor() const
Definition: dragdrop.h:68
Equipm isEquipment() const
Definition: item.h:116
DragDropSourceT getSource() const
Definition: dragdrop.h:83
void setSelected(const int index)
int getItem() const
Definition: dragdrop.h:65

◆ addBox()

void EquipmentWindow::addBox ( const int  idx,
int  x,
int  y,
const int  imageIndex 
)
private

Definition at line 802 of file equipmentwindow.cpp.

References CAST_S32, ImageSet::get(), Window::getPadding(), Window::getTitleBarHeight(), mBoxSize, mImageSet, mMaxX, mMaxY, mMinX, mMinY, mPages, mYPadding, ImageSet::size(), x, and y.

Referenced by fillDefault(), and getEquipment().

803 {
804  Image *image = nullptr;
805 
806  if ((mImageSet != nullptr) && imageIndex >= 0 && imageIndex
807  < CAST_S32(mImageSet->size()))
808  {
809  image = mImageSet->get(imageIndex);
810  }
811 
812  x += getPadding();
814  STD_VECTOR<EquipmentBox*> &boxes = mPages[0]->boxes;
815  boxes[idx] = new EquipmentBox(x, y, image);
816 
817  if (x < mMinX)
818  mMinX = x;
819  if (y < mMinY)
820  mMinY = y;
821  if (x + mBoxSize > mMaxX)
822  mMaxX = x + mBoxSize;
823  if (y + mBoxSize > mMaxY)
824  mMaxY = y + mBoxSize;
825 }
unsigned int getTitleBarHeight() const
Definition: window.h:514
Image * get(const size_type i) const
Definition: imageset.cpp:66
ImageSet * mImageSet
std::vector< EquipmentPage * > mPages
#define CAST_S32
Definition: cast.h:29
size_type size() const
Definition: imageset.h:69
Definition: image.h:61
int getPadding() const
Definition: window.h:496

◆ addDefaultPage()

void EquipmentWindow::addDefaultPage ( )
private

Definition at line 660 of file equipmentwindow.cpp.

References _, addPage(), and mHaveDefaultPage.

Referenced by fillDefault(), and getEquipment().

661 {
662  if (!mHaveDefaultPage)
663  {
664  mHaveDefaultPage = true;
665  // TRANSLATORS: equipment window tab
666  addPage(_("default"));
667  }
668 }
#define _(s)
Definition: gettext.h:34
int addPage(const std::string &name)

◆ addPage()

int EquipmentWindow::addPage ( const std::string &  name)
private

Definition at line 836 of file equipmentwindow.cpp.

References WidgetGroup::addButton(), BOX_COUNT, EquipmentPage::boxes, CAST_S32, mPages, and mTabs.

Referenced by addDefaultPage(), getEquipment(), and loadPage().

837 {
838  EquipmentPage *const page = new EquipmentPage;
839  mPages.push_back(page);
840  STD_VECTOR<EquipmentBox*> &boxes = page->boxes;
841 
842  boxes.reserve(BOX_COUNT);
843  for (int f = 0; f < BOX_COUNT; f ++)
844  boxes.push_back(nullptr);
845 
846  mTabs->addButton(name, name, false);
847  return CAST_S32(mPages.size()) - 1;
848 }
virtual void addButton(const std::string &text, const std::string &tag, const bool pressed)
Definition: widgetgroup.cpp:41
std::vector< EquipmentBox * > boxes
Definition: equipmentpage.h:45
std::vector< EquipmentPage * > mPages
#define CAST_S32
Definition: cast.h:29
static const int BOX_COUNT

◆ draw()

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

Draws the equipment window.

Reimplemented from Window.

Definition at line 181 of file equipmentwindow.cpp.

References BLOCK_END, BLOCK_START, Graphics::calcTileCollection(), ImageCollection::clear(), Window::draw(), Graphics::drawImage(), Font::drawString(), Graphics::drawTileCollection(), Graphics::finalize(), ServerCommandType::font, FOR_EACH, Equipment::getEquipment(), Widget::getFont(), Font::getHeight(), Item::getImage(), Net::InventoryHandler::getProjectileSlot(), Item::getQuantity(), Font::getWidth(), EquipmentBox::image, inventoryHandler, ServerCommandType::item, mBoxSize, mEquipment, mItemPadding, mLabelsColor, mLabelsColor2, Window::mLastRedraw, mPages, mSelected, mSelectedTab, mSlotBackground, mSlotHighlightedBackground, mVertexes, Image::setAlpha(), ServerCommandType::str, Catch::toString(), EquipmentBox::x, and EquipmentBox::y.

182 {
183  BLOCK_START("EquipmentWindow::draw")
184  // Draw window graphics
185  Window::draw(graphics);
186 
187  int i = 0;
188  Font *const font = getFont();
189  const int fontHeight = font->getHeight();
190  const STD_VECTOR<EquipmentBox*> &boxes = mPages[mSelectedTab]->boxes;
191 
192  if (mLastRedraw)
193  {
194  mVertexes->clear();
195  FOR_EACH (STD_VECTOR<EquipmentBox*>::const_iterator, it, boxes)
196  {
197  const EquipmentBox *const box = *it;
198  if (box == nullptr)
199  {
200  i ++;
201  continue;
202  }
203  if (i == mSelected)
204  {
205  graphics->calcTileCollection(mVertexes,
207  box->x, box->y);
208  }
209  else
210  {
211  graphics->calcTileCollection(mVertexes,
213  box->x, box->y);
214  }
215  i ++;
216  }
217  graphics->finalize(mVertexes);
218  }
219  graphics->drawTileCollection(mVertexes);
220 
221  if (mEquipment == nullptr)
222  {
223  BLOCK_END("EquipmentWindow::draw")
224  return;
225  }
226 
227  i = 0;
228  const int projSlot = inventoryHandler->getProjectileSlot();
229  for (STD_VECTOR<EquipmentBox*>::const_iterator it = boxes.begin(),
230  it_end = boxes.end(); it != it_end; ++ it, ++ i)
231  {
232  const EquipmentBox *const box = *it;
233  if (box == nullptr)
234  continue;
235  const Item *const item = mEquipment->getEquipment(i);
236  if (item != nullptr)
237  {
238  // Draw Item.
239  Image *const image = item->getImage();
240  if (image != nullptr)
241  {
242  image->setAlpha(1.0F); // Ensure the image is drawn
243  // with maximum opacity
244  graphics->drawImage(image, box->x + mItemPadding,
245  box->y + mItemPadding);
246  if (i == projSlot)
247  {
248  const std::string str = toString(item->getQuantity());
249  font->drawString(graphics,
250  mLabelsColor,
252  str,
253  box->x + (mBoxSize - font->getWidth(str)) / 2,
254  box->y - fontHeight);
255  }
256  }
257  }
258  else if (box->image != nullptr)
259  {
260  graphics->drawImage(box->image,
261  box->x + mItemPadding,
262  box->y + mItemPadding);
263  }
264  }
265  BLOCK_END("EquipmentWindow::draw")
266 }
Font * getFont() const
Definition: widget.cpp:330
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Definition: font.h:88
ImageCollection * mVertexes
Definition: window.h:98
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
#define STD_VECTOR
Definition: vector.h:29
const Item * getEquipment(const int index) const
Definition: equipment.h:68
virtual void setAlpha(const float alpha)
Definition: image.cpp:285
std::vector< EquipmentPage * > mPages
int getQuantity() const
Definition: item.h:104
bool mLastRedraw
Definition: window.h:649
Definition: item.h:48
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:82
Equipment * mEquipment
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
void draw(Graphics *const graphics)
Image * getImage() const
Definition: item.h:86
Image * mSlotHighlightedBackground
Definition: image.h:61
int getHeight() const
Definition: widget.h:239
Image * image
Definition: equipmentbox.h:38

◆ fillBoxes()

void EquipmentWindow::fillBoxes ( )
private

Definition at line 628 of file equipmentwindow.cpp.

References Resource::decRef(), fillDefault(), for_each_xml_child_node, Theme::getImageSetFromTheme(), XML::getProperty(), Configuration::getStringValue(), loadPage(), mImageSet, mPages, paths, reportTrue, XML::Document::rootNode(), SkipError_false, and UseVirtFs_true.

Referenced by EquipmentWindow(), and getEquipment().

629 {
630  XML::Document *const doc = new XML::Document(
631  paths.getStringValue("equipmentWindowFile"),
634  XmlNodeConstPtr root = doc->rootNode();
635  if (root == nullptr)
636  {
637  delete doc;
638  fillDefault();
639  return;
640  }
641 
642  if (mImageSet != nullptr)
643  mImageSet->decRef();
644 
646  root, "image", "equipmentbox.png"), 32, 32);
647 
648  for_each_xml_child_node(node, root)
649  {
650  if (xmlNameEqual(node, "page"))
651  {
652  loadPage(node);
653  }
654  }
655  delete doc;
656  if (reportTrue(mPages.empty()))
657  fillDefault();
658 }
std::string getStringValue(const std::string &key) const
const bool SkipError_false
Definition: skiperror.h:29
ImageSet * mImageSet
virtual void decRef()
Definition: resource.cpp:49
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:171
std::vector< EquipmentPage * > mPages
static ImageSet * getImageSetFromTheme(const std::string &path, const int w, const int h)
Definition: theme.cpp:659
const bool UseVirtFs_true
Definition: usevirtfs.h:29
xmlNodePtr rootNode()
Definition: libxml.cpp:166
Configuration paths
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:160
#define reportTrue(val)
Definition: checkutils.h:251
void loadPage(const xmlNodePtr node)

◆ fillDefault()

void EquipmentWindow::fillDefault ( )
private

Definition at line 778 of file equipmentwindow.cpp.

References addBox(), addDefaultPage(), Resource::decRef(), Theme::getImageSetFromTheme(), and mImageSet.

Referenced by fillBoxes(), and getEquipment().

779 {
780  if (mImageSet != nullptr)
781  mImageSet->decRef();
782 
783  addDefaultPage();
785  "equipmentbox.png", 32, 32);
786 
787  addBox(0, 90, 40, 0); // torso
788  addBox(1, 8, 78, 1); // gloves
789  addBox(2, 70, 0, 2); // hat
790  addBox(3, 50, 253, 3); // pants
791  addBox(4, 90, 253, 4); // boots
792  addBox(5, 8, 213, 5); // FREE
793  addBox(6, 129, 213, 6); // wings
794  addBox(7, 50, 40, 5); // scarf
795  addBox(8, 8, 168, 7); // weapon
796  addBox(9, 129, 168, 8); // shield
797  addBox(10, 129, 78, 9); // ammo
798  addBox(11, 8, 123, 5); // amulet
799  addBox(12, 129, 123, 5); // ring
800 }
ImageSet * mImageSet
virtual void decRef()
Definition: resource.cpp:49
static ImageSet * getImageSetFromTheme(const std::string &path, const int w, const int h)
Definition: theme.cpp:659
void addBox(const int idx, int x, int y, const int imageIndex)

◆ getEquipment()

const Item* EquipmentWindow::getEquipment ( const int  i) const
inline

◆ getItem()

const Item * EquipmentWindow::getItem ( const int  x,
const int  y 
) const
private

Definition at line 404 of file equipmentwindow.cpp.

References Equipment::getEquipment(), Rect::isPointInRect(), mBoxSize, mEquipment, mPages, mSelectedTab, EquipmentBox::x, and EquipmentBox::y.

Referenced by getEquipment(), mouseMoved(), and mousePressed().

405 {
406  if (mEquipment == nullptr)
407  return nullptr;
408 
409  int i = 0;
410 
411  STD_VECTOR<EquipmentBox*> &boxes = mPages[mSelectedTab]->boxes;
412  for (STD_VECTOR<EquipmentBox*>::const_iterator it = boxes.begin(),
413  it_end = boxes.end(); it != it_end; ++ it, ++ i)
414  {
415  const EquipmentBox *const box = *it;
416  if (box == nullptr)
417  continue;
418  const Rect tRect(box->x, box->y, mBoxSize, mBoxSize);
419 
420  if (tRect.isPointInRect(x, y))
421  return mEquipment->getEquipment(i);
422  }
423  return nullptr;
424 }
Definition: rect.h:72
const Item * getEquipment(const int index) const
Definition: equipment.h:68
std::vector< EquipmentPage * > mPages
Equipment * mEquipment

◆ loadPage()

void EquipmentWindow::loadPage ( const xmlNodePtr  node)
private

Definition at line 670 of file equipmentwindow.cpp.

References _, addPage(), for_each_xml_child_node, XML::langProperty(), loadPlayerBox(), loadSlot(), and mImageSet.

Referenced by fillBoxes(), and getEquipment().

671 {
672  if (node == nullptr)
673  return;
674  // TRANSLATORS: unknown equipment page name
675  const std::string &name = XML::langProperty(node, "name", _("Unknown"));
676  const int page = addPage(name);
677  for_each_xml_child_node(childNode, node)
678  {
679  if (xmlNameEqual(childNode, "playerbox"))
680  loadPlayerBox(childNode, page);
681  else if (xmlNameEqual(childNode, "slot"))
682  loadSlot(childNode, mImageSet, page);
683  }
684 }
#define _(s)
Definition: gettext.h:34
ImageSet * mImageSet
void loadPlayerBox(const xmlNodePtr playerBoxNode, const int page)
void loadSlot(const xmlNodePtr slotNode, const ImageSet *const imageset, const int page)
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:255
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:160
int addPage(const std::string &name)

◆ loadPlayerBox()

void EquipmentWindow::loadPlayerBox ( const xmlNodePtr  playerBoxNode,
const int  page 
)
private

Definition at line 686 of file equipmentwindow.cpp.

References data, XML::getProperty(), EquipmentPage::height, mPages, mYPadding, EquipmentPage::width, EquipmentPage::x, and EquipmentPage::y.

Referenced by getEquipment(), and loadPage().

688 {
689  EquipmentPage *const data = mPages[page];
690  data->x = XML::getProperty(playerBoxNode, "x", 50);
691  data->y = XML::getProperty(playerBoxNode, "y", 80) + mYPadding;
692  data->width = XML::getProperty(playerBoxNode, "width", 74);
693  data->height = XML::getProperty(playerBoxNode, "height", 168);
694 }
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:171
std::vector< EquipmentPage * > mPages
uint32_t data

◆ loadSlot()

void EquipmentWindow::loadSlot ( const xmlNodePtr  slotNode,
const ImageSet *const  imageset,
const int  page 
)
private

Definition at line 696 of file equipmentwindow.cpp.

References CAST_S32, ImageSet::get(), Window::getPadding(), XML::getProperty(), Window::getTitleBarHeight(), EquipmentBox::image, mBoxSize, mMaxX, mMaxY, mMinX, mMinY, mPages, mYPadding, parseSlotName(), ImageSet::size(), EquipmentBox::x, x, EquipmentBox::y, and y.

Referenced by getEquipment(), and loadPage().

699 {
700  if (imageset == nullptr)
701  return;
702  const int slot = parseSlotName(XML::getProperty(slotNode, "name", ""));
703  if (slot < 0)
704  return;
705 
706  const int x = XML::getProperty(slotNode, "x", 0) + getPadding();
707  const int y = XML::getProperty(slotNode, "y", 0)
709  const int imageIndex = XML::getProperty(slotNode, "image", -1);
710  Image *image = nullptr;
711 
712  if (imageIndex >= 0 && imageIndex < CAST_S32(imageset->size()))
713  image = imageset->get(imageIndex);
714 
715  STD_VECTOR<EquipmentBox*> &boxes = mPages[page]->boxes;
716  if (boxes[slot] != nullptr)
717  {
718  EquipmentBox *const box = boxes[slot];
719  box->x = x;
720  box->y = y;
721  box->image = image;
722  }
723  else
724  {
725  boxes[slot] = new EquipmentBox(x, y, image);
726  }
727  if (x < mMinX)
728  mMinX = x;
729  if (y < mMinY)
730  mMinY = y;
731  if (x + mBoxSize > mMaxX)
732  mMaxX = x + mBoxSize;
733  if (y + mBoxSize > mMaxY)
734  mMaxY = y + mBoxSize;
735 }
unsigned int getTitleBarHeight() const
Definition: window.h:514
Image * get(const size_type i) const
Definition: imageset.cpp:66
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:171
std::vector< EquipmentPage * > mPages
#define CAST_S32
Definition: cast.h:29
size_type size() const
Definition: imageset.h:69
static int parseSlotName(const std::string &name)
Definition: image.h:61
int getPadding() const
Definition: window.h:496
Image * image
Definition: equipmentbox.h:38

◆ loadWindow()

void EquipmentWindow::loadWindow ( const xmlNode *const  windowNode)
private

Referenced by getEquipment().

◆ mouseExited()

void EquipmentWindow::mouseExited ( MouseEvent event)
virtual

When the mouse leaves the window this ensures that the custom cursor is restored back to it's standard image.

Reimplemented from Window.

Definition at line 585 of file equipmentwindow.cpp.

References itemPopup, Widget::setVisible(), and Visible_false.

Referenced by getEquipment().

586 {
587  if (itemPopup != nullptr)
589 }
void setVisible(Visible visible)
Definition: widget.cpp:224
const bool Visible_false
Definition: visible.h:29
ItemPopup * itemPopup
Definition: itempopup.cpp:63

◆ mouseMoved()

void EquipmentWindow::mouseMoved ( MouseEvent event)
virtual

Implements custom cursor image changing context, based on mouse relative position.

Reimplemented from Window.

Definition at line 561 of file equipmentwindow.cpp.

References getItem(), Widget::getX(), Widget::getY(), ServerCommandType::item, itemPopup, Window::mouseMoved(), Popup::position(), ItemPopup::setItem(), Widget::setVisible(), Visible_false, x, and y.

Referenced by getEquipment().

562 {
563  Window::mouseMoved(event);
564 
565  if (itemPopup == nullptr)
566  return;
567 
568  const int x = event.getX();
569  const int y = event.getY();
570 
571  const Item *const item = getItem(x, y);
572 
573  if (item != nullptr)
574  {
575  itemPopup->setItem(item, false);
576  itemPopup->position(x + getX(), y + getY());
577  }
578  else
579  {
581  }
582 }
int getY() const
Definition: widget.h:287
void setVisible(Visible visible)
Definition: widget.cpp:224
const Item * getItem(const int x, const int y) const
void mouseMoved(MouseEvent &event)
Definition: window.cpp:955
const bool Visible_false
Definition: visible.h:29
void position(const int x, const int y)
Definition: popup.cpp:229
Definition: item.h:48
void setItem(const ItemInfo &item, const ItemColor color, const bool showImage, int id, const int *const cards, const ItemOptionsList *const options)
Definition: itempopup.cpp:183
int getX() const
Definition: widget.h:268
ItemPopup * itemPopup
Definition: itempopup.cpp:63

◆ mousePressed()

void EquipmentWindow::mousePressed ( MouseEvent event)
virtual

Starts window resizing when appropriate.

Reimplemented from Window.

Definition at line 426 of file equipmentwindow.cpp.

References dragDrop, DragDrop::dragItem(), DragDropSource::Equipment, MouseEvent::getButton(), Equipment::getEquipment(), getItem(), Widget::getX(), Widget::getY(), InventoryType::Inventory, Rect::isPointInRect(), ServerCommandType::item, itemPopup, MouseButton::LEFT, mBeing, mBoxSize, mEquipment, mForing, Window::mousePressed(), mPages, mSelectedTab, popupMenu, MouseButton::RIGHT, setSelected(), Widget::setVisible(), PopupMenu::showPopup(), PopupMenu::showUndressPopup(), Visible_false, EquipmentBox::x, x, EquipmentBox::y, and y.

427 {
428  if (mEquipment == nullptr)
429  {
430  Window::mousePressed(event);
431  return;
432  }
433 
434  const int x = event.getX();
435  const int y = event.getY();
436 
437  if (event.getButton() == MouseButton::LEFT)
438  {
439  if (mForing)
440  {
441  Window::mousePressed(event);
442  return;
443  }
444  // Checks if any of the presses were in the equip boxes.
445  int i = 0;
446 
447  bool inBox(false);
448 
449  STD_VECTOR<EquipmentBox*> &boxes = mPages[mSelectedTab]->boxes;
450  for (STD_VECTOR<EquipmentBox*>::const_iterator it = boxes.begin(),
451  it_end = boxes.end(); it != it_end; ++ it, ++ i)
452  {
453  const EquipmentBox *const box = *it;
454  if (box == nullptr)
455  continue;
456  const Item *const item = mEquipment->getEquipment(i);
457  const Rect tRect(box->x, box->y, mBoxSize, mBoxSize);
458 
459  if (tRect.isPointInRect(x, y))
460  {
461  inBox = true;
462  if (item != nullptr)
463  {
464  event.consume();
465  setSelected(i);
467  return;
468  }
469  }
470  if (inBox)
471  return;
472  }
473  }
474  else if (event.getButton() == MouseButton::RIGHT)
475  {
476  if (const Item *const item = getItem(x, y))
477  {
478  if (itemPopup != nullptr)
480 
481  /* Convert relative to the window coordinates to absolute screen
482  * coordinates.
483  */
484  const int mx = x + getX();
485  const int my = y + getY();
486  if (popupMenu != nullptr)
487  {
488  event.consume();
489  if (mForing)
490  {
491  popupMenu->showUndressPopup(mx, my, mBeing, item);
492  }
493  else
494  {
495  popupMenu->showPopup(this, mx, my, item,
497  }
498  return;
499  }
500  }
501  }
502  Window::mousePressed(event);
503 }
void dragItem(const Item *const item, const DragDropSourceT source, const int tag=0)
Definition: dragdrop.h:86
int getY() const
Definition: widget.h:287
void setVisible(Visible visible)
Definition: widget.cpp:224
void showUndressPopup(const int x, const int y, const Being *const being, const Item *const item)
Definition: popupmenu.cpp:2120
MouseButtonT getButton() const
Definition: mouseevent.h:113
Definition: rect.h:72
const Item * getItem(const int x, const int y) const
DragDrop dragDrop
const Item * getEquipment(const int index) const
Definition: equipment.h:68
std::vector< EquipmentPage * > mPages
const bool Visible_false
Definition: visible.h:29
PopupMenu * popupMenu
Definition: popupmenu.cpp:102
Definition: item.h:48
Equipment * mEquipment
int getX() const
Definition: widget.h:268
void mousePressed(MouseEvent &event)
Definition: window.cpp:824
ItemPopup * itemPopup
Definition: itempopup.cpp:63
void setSelected(const int index)
void showPopup(const int x, const int y, const Being *const being)
Definition: popupmenu.cpp:201

◆ mouseReleased()

void EquipmentWindow::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 505 of file equipmentwindow.cpp.

References DragDrop::clear(), DragDrop::deselect(), dragDrop, PlayerInfo::equipItem(), Equipm_true, DragDropSource::Equipment, Equipped_false, Equipped_true, Inventory::findItem(), PlayerInfo::getInventory(), DragDrop::getItem(), DragDrop::getItemColor(), DragDrop::getSource(), DragDropSource::Inventory, DragDrop::isEmpty(), Item::isEquipment(), Item::isEquipped(), Rect::isPointInRect(), ServerCommandType::item, localPlayer, mBoxSize, Window::mouseReleased(), mPages, mSelectedTab, Sfx_true, PlayerInfo::unequipItem(), EquipmentBox::x, x, EquipmentBox::y, and y.

Referenced by getEquipment().

506 {
507  Window::mouseReleased(event);
508  const DragDropSourceT src = dragDrop.getSource();
510  && src != DragDropSource::Equipment))
511  {
512  return;
513  }
514  Inventory *const inventory = localPlayer != nullptr
516  if (inventory == nullptr)
517  return;
518 
519  Item *const item = inventory->findItem(dragDrop.getItem(),
521  if (item == nullptr)
522  return;
523 
525  {
526  if (item->isEquipment() == Equipm_true)
527  {
528  if (item->isEquipped() == Equipped_false)
530  }
531  }
533  {
534  if (item->isEquipment() == Equipm_true)
535  {
536  const int x = event.getX();
537  const int y = event.getY();
538  STD_VECTOR<EquipmentBox*> &boxes = mPages[mSelectedTab]->boxes;
539  for (STD_VECTOR<EquipmentBox*>::const_iterator
540  it = boxes.begin(), it_end = boxes.end();
541  it != it_end; ++ it)
542  {
543  const EquipmentBox *const box = *it;
544  if (box == nullptr)
545  continue;
546  const Rect tRect(box->x, box->y, mBoxSize, mBoxSize);
547 
548  if (tRect.isPointInRect(x, y))
549  return;
550  }
551 
552  if (item->isEquipped() == Equipped_true)
554  }
555  }
556  dragDrop.clear();
557  dragDrop.deselect();
558 }
DragDropSource ::T DragDropSourceT
void equipItem(const Item *const item, const Sfx sfx)
Definition: playerinfo.cpp:250
void clear()
Definition: dragdrop.h:182
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
Equipped isEquipped() const
Definition: item.h:128
Definition: rect.h:72
Inventory * getInventory()
Definition: playerinfo.cpp:207
const bool Sfx_true
Definition: sfx.h:29
DragDrop dragDrop
const bool Equipped_true
Definition: equipped.h:29
bool isEmpty() const
Definition: dragdrop.h:195
const bool Equipped_false
Definition: equipped.h:29
std::vector< EquipmentPage * > mPages
const bool Equipm_true
Definition: equipm.h:29
LocalPlayer * localPlayer
Definition: item.h:48
#define nullptr
Definition: localconsts.h:44
void deselect()
Definition: dragdrop.h:212
void mouseReleased(MouseEvent &event)
Definition: window.cpp:895
void unequipItem(const Item *const item, const Sfx sfx)
Definition: playerinfo.cpp:258
ItemColor getItemColor() const
Definition: dragdrop.h:68
Equipm isEquipment() const
Definition: item.h:116
DragDropSourceT getSource() const
Definition: dragdrop.h:83
int getItem() const
Definition: dragdrop.h:65

◆ parseSlotName()

int EquipmentWindow::parseSlotName ( const std::string &  name)
staticprivate

Definition at line 770 of file equipmentwindow.cpp.

References mSlotNames.

Referenced by getEquipment(), and loadSlot().

771 {
772  StringIntMapCIter it = mSlotNames.find(name);
773  if (it != mSlotNames.end())
774  return (*it).second;
775  return -1;
776 }
StringIntMap::const_iterator StringIntMapCIter
Definition: stringmap.h:29
static StringIntMap mSlotNames

◆ postInit()

void EquipmentWindow::postInit ( )
virtual

Reimplemented from Window.

Definition at line 134 of file equipmentwindow.cpp.

References BasicContainer2::add(), Widget::addActionListener(), Window::enableVisibleSound(), Window::getChildrenArea(), Widget::getHeight(), Widget::getWidth(), ImageRect::grid, Rect::height, Theme::loadRect(), mButtonPadding, mPlayerBox, mSlotBackground, mSlotHighlightedBackground, mTabs, mUnequip, Window::postInit(), Widget::setActionEventId(), Widget::setEnabled(), Widget::setPosition(), theme, and Rect::width.

135 {
137  const Rect &area = getChildrenArea();
140  mUnequip->setEnabled(false);
141 
142  ImageRect rect;
143  theme->loadRect(rect, "equipment_background.xml", "", 0, 1);
144  mSlotBackground = rect.grid[0];
146  add(mTabs);
147  add(mPlayerBox);
148  add(mUnequip);
149  enableVisibleSound(true);
150  mPlayerBox->setActionEventId("playerbox");
152 }
int width
Definition: rect.h:218
int getWidth() const
Definition: widget.h:220
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
Rect getChildrenArea()
Definition: window.cpp:1461
Definition: rect.h:72
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
Image * grid[9]
Definition: imagerect.h:41
virtual void add(Widget *const widget)
void loadRect(ImageRect &image, const std::string &name, const std::string &name2, const int start=0, const int end=8)
Definition: theme.cpp:1092
void setPosition(const int x, const int y)
Definition: widget.cpp:160
int height
Definition: rect.h:223
void enableVisibleSound(bool b)
Definition: window.h:473
void setEnabled(const bool enabled)
Definition: widget.h:351
Theme * theme
Definition: theme.cpp:61
Image * mSlotHighlightedBackground
int getHeight() const
Definition: widget.h:239
void postInit()
Definition: window.cpp:241
PlayerBox * mPlayerBox

◆ prepareSlotNames()

void EquipmentWindow::prepareSlotNames ( )
static

Definition at line 737 of file equipmentwindow.cpp.

References BOX_COUNT, for_each_xml_child_node, XML::getProperty(), Configuration::getStringValue(), mSlotNames, paths, reportAlways, XML::Document::rootNode(), SkipError_false, and UseVirtFs_true.

Referenced by getEquipment(), and Client::loadData().

738 {
739  mSlotNames.clear();
740  XML::Document doc(paths.getStringValue("equipmentSlotsFile"),
743  XmlNodeConstPtrConst root = doc.rootNode();
744  if (root == nullptr)
745  return;
746 
747  for_each_xml_child_node(slotNode, root)
748  {
749  if (!xmlNameEqual(slotNode, "slot"))
750  continue;
751  const std::string name = XML::getProperty(slotNode, "name", "");
752  if (name.empty())
753  {
754  reportAlways("Empty slot name detected.");
755  continue;
756  }
757 
758  const int slot = XML::getProperty(slotNode, "slot", -1);
759  if (slot < 0 || slot >= BOX_COUNT)
760  {
761  reportAlways("Wrong slot id '%d' for slot with name '%s'",
762  slot,
763  name.c_str());
764  continue;
765  }
766  mSlotNames[name] = slot;
767  }
768 }
std::string getStringValue(const std::string &key) const
const bool SkipError_false
Definition: skiperror.h:29
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:171
const bool UseVirtFs_true
Definition: usevirtfs.h:29
static StringIntMap mSlotNames
xmlNodePtr rootNode()
Definition: libxml.cpp:166
Configuration paths
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:160
static const int BOX_COUNT
#define reportAlways(...)
Definition: checkutils.h:252

◆ recalcSize()

void EquipmentWindow::recalcSize ( )

◆ resetBeing()

void EquipmentWindow::resetBeing ( const Being *const  being)

Definition at line 622 of file equipmentwindow.cpp.

References mBeing, and setBeing().

Referenced by getEquipment(), and ActorManager::logic().

623 {
624  if (being == mBeing)
625  setBeing(nullptr);
626 }
void setBeing(Being *const being)

◆ safeDraw()

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

Reimplemented from Window.

Definition at line 268 of file equipmentwindow.cpp.

References BLOCK_END, BLOCK_START, Graphics::drawImage(), Font::drawString(), ServerCommandType::font, Equipment::getEquipment(), Widget::getFont(), Font::getHeight(), Item::getImage(), Net::InventoryHandler::getProjectileSlot(), Item::getQuantity(), Font::getWidth(), EquipmentBox::image, inventoryHandler, ServerCommandType::item, mBoxSize, mEquipment, mItemPadding, mLabelsColor, mLabelsColor2, mPages, mSelected, mSelectedTab, mSlotBackground, mSlotHighlightedBackground, Window::safeDraw(), Image::setAlpha(), ServerCommandType::str, Catch::toString(), EquipmentBox::x, and EquipmentBox::y.

269 {
270  BLOCK_START("EquipmentWindow::draw")
271  // Draw window graphics
272  Window::safeDraw(graphics);
273 
274  int i = 0;
275  Font *const font = getFont();
276  const int fontHeight = font->getHeight();
277  const STD_VECTOR<EquipmentBox*> &boxes = mPages[mSelectedTab]->boxes;
278 
279  for (STD_VECTOR<EquipmentBox*>::const_iterator it = boxes.begin(),
280  it_end = boxes.end(); it != it_end; ++ it, ++ i)
281  {
282  const EquipmentBox *const box = *it;
283  if (box == nullptr)
284  continue;
285  if (i == mSelected)
286  {
287  graphics->drawImage(mSlotHighlightedBackground,
288  box->x, box->y);
289  }
290  else
291  {
292  graphics->drawImage(mSlotBackground, box->x, box->y);
293  }
294  }
295 
296  if (mEquipment == nullptr)
297  {
298  BLOCK_END("EquipmentWindow::draw")
299  return;
300  }
301 
302  i = 0;
303  const int projSlot = inventoryHandler->getProjectileSlot();
304  for (STD_VECTOR<EquipmentBox*>::const_iterator it = boxes.begin(),
305  it_end = boxes.end(); it != it_end; ++ it, ++ i)
306  {
307  const EquipmentBox *const box = *it;
308  if (box == nullptr)
309  continue;
310  const Item *const item = mEquipment->getEquipment(i);
311  if (item != nullptr)
312  {
313  // Draw Item.
314  Image *const image = item->getImage();
315  if (image != nullptr)
316  {
317  image->setAlpha(1.0F); // Ensure the image is drawn
318  // with maximum opacity
319  graphics->drawImage(image, box->x + mItemPadding,
320  box->y + mItemPadding);
321  if (i == projSlot)
322  {
323  const std::string str = toString(item->getQuantity());
324  font->drawString(graphics,
325  mLabelsColor,
327  str,
328  box->x + (mBoxSize - font->getWidth(str)) / 2,
329  box->y - fontHeight);
330  }
331  }
332  }
333  else if (box->image != nullptr)
334  {
335  graphics->drawImage(box->image,
336  box->x + mItemPadding,
337  box->y + mItemPadding);
338  }
339  }
340  BLOCK_END("EquipmentWindow::draw")
341 }
Font * getFont() const
Definition: widget.cpp:330
Definition: font.h:88
void safeDraw(Graphics *const graphics)
Definition: window.h:98
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79
#define STD_VECTOR
Definition: vector.h:29
const Item * getEquipment(const int index) const
Definition: equipment.h:68
virtual void setAlpha(const float alpha)
Definition: image.cpp:285
std::vector< EquipmentPage * > mPages
int getQuantity() const
Definition: item.h:104
Definition: item.h:48
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:82
Equipment * mEquipment
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
Image * getImage() const
Definition: item.h:86
Image * mSlotHighlightedBackground
Definition: image.h:61
int getHeight() const
Definition: widget.h:239
Image * image
Definition: equipmentbox.h:38

◆ setBeing()

void EquipmentWindow::setBeing ( Being *const  being)

Definition at line 601 of file equipmentwindow.cpp.

References Equipment::getBackend(), Being::getEquipment(), mBeing, mEquipment, mPlayerBox, and PlayerBox::setPlayer().

Referenced by ActorManager::clear(), getEquipment(), resetBeing(), Actions::showHideWindow(), and updateBeing().

602 {
603  mPlayerBox->setPlayer(being);
604  mBeing = being;
605  if (mEquipment != nullptr)
606  delete mEquipment->getBackend();
607  delete mEquipment;
608  if (being == nullptr)
609  {
610  mEquipment = nullptr;
611  return;
612  }
613  mEquipment = being->getEquipment();
614 }
void setPlayer(Being *being)
Definition: playerbox.h:73
const Backend * getBackend() const
Definition: equipment.h:88
Equipment * mEquipment
Equipment * getEquipment()
Definition: being.cpp:4624
PlayerBox * mPlayerBox

◆ setSelected()

void EquipmentWindow::setSelected ( const int  index)
private

Definition at line 591 of file equipmentwindow.cpp.

References itemPopup, Widget::mRedraw, mSelected, mUnequip, Widget::setEnabled(), Widget::setVisible(), and Visible_false.

Referenced by action(), getEquipment(), and mousePressed().

592 {
593  mSelected = index;
594  mRedraw = true;
595  if (mUnequip != nullptr)
596  mUnequip->setEnabled(mSelected != -1);
597  if (itemPopup != nullptr)
599 }
void setVisible(Visible visible)
Definition: widget.cpp:224
const bool Visible_false
Definition: visible.h:29
void setEnabled(const bool enabled)
Definition: widget.h:351
bool mRedraw
Definition: widget.h:1163
ItemPopup * itemPopup
Definition: itempopup.cpp:63

◆ updateBeing()

void EquipmentWindow::updateBeing ( Being *const  being)

Definition at line 616 of file equipmentwindow.cpp.

References mBeing, and setBeing().

Referenced by getEquipment(), Being::setGender(), Being::setSpriteCards(), Being::setSpriteColor(), Being::setSpriteColorId(), Being::setSpriteId(), and Being::unSetSprite().

617 {
618  if (being == mBeing)
619  setBeing(being);
620 }
void setBeing(Being *const being)

◆ updatePage()

void EquipmentWindow::updatePage ( )
private

Definition at line 391 of file equipmentwindow.cpp.

References fromBool, EquipmentPage::height, mPages, mPlayerBox, Widget::mRedraw, mSelectedTab, Widget::setDimension(), Widget::setVisible(), EquipmentPage::showPlayerBox, Visible_true, EquipmentPage::width, EquipmentPage::x, and EquipmentPage::y.

Referenced by action(), EquipmentWindow(), and getEquipment().

392 {
393  EquipmentPage *const page = mPages[mSelectedTab];
394  const Visible visible = fromBool(page->showPlayerBox, Visible);
395  mPlayerBox->setVisible(visible);
396  if (visible == Visible_true)
397  {
398  mPlayerBox->setDimension(Rect(page->x, page->y,
399  page->width, page->height));
400  }
401  mRedraw = true;
402 }
const bool Visible_true
Definition: visible.h:29
void setVisible(Visible visible)
Definition: widget.cpp:224
Definition: rect.h:72
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
std::vector< EquipmentPage * > mPages
#define fromBool(val, name)
Definition: booldefines.h:48
bool mRedraw
Definition: widget.h:1163
PlayerBox * mPlayerBox

Field Documentation

◆ mBeing

Being* EquipmentWindow::mBeing
private

Definition at line 140 of file equipmentwindow.h.

Referenced by mousePressed(), resetBeing(), setBeing(), and updateBeing().

◆ mBorderColor

Color EquipmentWindow::mBorderColor
private

Definition at line 147 of file equipmentwindow.h.

◆ mBoxSize

int EquipmentWindow::mBoxSize
private

◆ mButtonPadding

int EquipmentWindow::mButtonPadding
private

Definition at line 153 of file equipmentwindow.h.

Referenced by postInit().

◆ mEquipment

Equipment* EquipmentWindow::mEquipment
private

◆ mForing

bool EquipmentWindow::mForing
private

Definition at line 160 of file equipmentwindow.h.

Referenced by mousePressed().

◆ mHaveDefaultPage

bool EquipmentWindow::mHaveDefaultPage
private

Definition at line 161 of file equipmentwindow.h.

Referenced by addDefaultPage().

◆ mHighlightColor

Color EquipmentWindow::mHighlightColor
private

Definition at line 146 of file equipmentwindow.h.

◆ mImageSet

ImageSet* EquipmentWindow::mImageSet
private

Definition at line 139 of file equipmentwindow.h.

Referenced by addBox(), fillBoxes(), fillDefault(), loadPage(), and ~EquipmentWindow().

◆ mItemPadding

int EquipmentWindow::mItemPadding
private

Definition at line 151 of file equipmentwindow.h.

Referenced by draw(), and safeDraw().

◆ mLabelsColor

Color EquipmentWindow::mLabelsColor
private

Definition at line 148 of file equipmentwindow.h.

Referenced by draw(), and safeDraw().

◆ mLabelsColor2

Color EquipmentWindow::mLabelsColor2
private

Definition at line 149 of file equipmentwindow.h.

Referenced by draw(), and safeDraw().

◆ mMaxX

int EquipmentWindow::mMaxX
private

Definition at line 156 of file equipmentwindow.h.

Referenced by addBox(), loadSlot(), and recalcSize().

◆ mMaxY

int EquipmentWindow::mMaxY
private

Definition at line 157 of file equipmentwindow.h.

Referenced by addBox(), loadSlot(), and recalcSize().

◆ mMinX

int EquipmentWindow::mMinX
private

Definition at line 154 of file equipmentwindow.h.

Referenced by addBox(), loadSlot(), and recalcSize().

◆ mMinY

int EquipmentWindow::mMinY
private

Definition at line 155 of file equipmentwindow.h.

Referenced by addBox(), loadSlot(), and recalcSize().

◆ mPages

std::vector<EquipmentPage*> EquipmentWindow::mPages
private

◆ mPlayerBox

PlayerBox* EquipmentWindow::mPlayerBox
private

Definition at line 136 of file equipmentwindow.h.

Referenced by EquipmentWindow(), postInit(), setBeing(), and updatePage().

◆ mSelected

int EquipmentWindow::mSelected
private

Index of selected item.

Definition at line 150 of file equipmentwindow.h.

Referenced by action(), draw(), safeDraw(), and setSelected().

◆ mSelectedTab

int EquipmentWindow::mSelectedTab
private

Definition at line 159 of file equipmentwindow.h.

Referenced by action(), draw(), getItem(), mousePressed(), mouseReleased(), safeDraw(), and updatePage().

◆ mSlotBackground

Image* EquipmentWindow::mSlotBackground
private

Definition at line 141 of file equipmentwindow.h.

Referenced by draw(), postInit(), safeDraw(), and ~EquipmentWindow().

◆ mSlotHighlightedBackground

Image* EquipmentWindow::mSlotHighlightedBackground
private

Definition at line 142 of file equipmentwindow.h.

Referenced by draw(), postInit(), safeDraw(), and ~EquipmentWindow().

◆ mSlotNames

StringIntMap EquipmentWindow::mSlotNames
staticprivate

Definition at line 132 of file equipmentwindow.h.

Referenced by parseSlotName(), and prepareSlotNames().

◆ mTabs

TabStrip* EquipmentWindow::mTabs
private

Definition at line 145 of file equipmentwindow.h.

Referenced by addPage(), EquipmentWindow(), postInit(), and recalcSize().

◆ mUnequip

Button* EquipmentWindow::mUnequip
private

Definition at line 137 of file equipmentwindow.h.

Referenced by postInit(), recalcSize(), and setSelected().

◆ mVertexes

ImageCollection* EquipmentWindow::mVertexes
private

Definition at line 143 of file equipmentwindow.h.

Referenced by draw(), and ~EquipmentWindow().

◆ mYPadding

int EquipmentWindow::mYPadding
private

Definition at line 158 of file equipmentwindow.h.

Referenced by addBox(), EquipmentWindow(), loadPlayerBox(), loadSlot(), and recalcSize().


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