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)
 
 ~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, 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)
 
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, 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)
 
- 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) const
 
bool getOptionBool (const std::string &name, const bool def) const
 
void setTitlePadding (const int p)
 
int getTitlePadding () const
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected 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 52 of file equipmentwindow.h.

Constructor & Destructor Documentation

◆ EquipmentWindow()

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

Constructor.

Definition at line 64 of file equipmentwindow.cpp.

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

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(), EmoteDB::size(), and updatePage().

◆ ~EquipmentWindow()

EquipmentWindow::~EquipmentWindow ( )

Destructor.

Definition at line 155 of file equipmentwindow.cpp.

156 {
157  if (this == beingEquipmentWindow)
158  {
159  if (mEquipment != nullptr)
160  delete mEquipment->getBackend();
162  }
163  FOR_EACH (STD_VECTOR<EquipmentPage*>::iterator, it, mPages)
164  {
165  STD_VECTOR<EquipmentBox*> &boxes = (*it)->boxes;
166  delete_all(boxes);
167  boxes.clear();
168  delete *it;
169  }
170  if (mImageSet != nullptr)
171  {
172  mImageSet->decRef();
173  mImageSet = nullptr;
174  }
175  if (mSlotBackground != nullptr)
176  mSlotBackground->decRef();
177  if (mSlotHighlightedBackground != nullptr)
178  mSlotHighlightedBackground->decRef();
180 }
const Backend * getBackend() const
Definition: equipment.h:91
virtual void decRef()
Definition: resource.cpp:50
#define delete2(var)
Definition: delete2.h:25
void delete_all(Container &c)
Definition: dtor.h:56
EquipmentWindow * beingEquipmentWindow
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25

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

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 344 of file equipmentwindow.cpp.

345 {
346  const std::string &eventId = event.getId();
347  if (eventId == "unequip")
348  {
349  if ((mEquipment == nullptr) || mSelected == -1)
350  return;
351 
352  const Item *const item = mEquipment->getEquipment(mSelected);
354  setSelected(-1);
355  }
356  else if (eventId.find("tab_") == 0U)
357  {
358  Button *const button = dynamic_cast<Button*>(event.getSource());
359  if (button == nullptr)
360  return;
361  mSelectedTab = button->getTag();
362  updatePage();
363  }
364  else if (eventId == "playerbox")
365  {
366  const DragDropSourceT src = dragDrop.getSource();
368  && src != DragDropSource::Equipment))
369  {
370  return;
371  }
372  Inventory *const inventory = localPlayer != nullptr
374  if (inventory == nullptr)
375  return;
376  Item *const item = inventory->findItem(dragDrop.getItem(),
378  if (item == nullptr)
379  return;
380 
382  {
383  if (item->isEquipment() == Equipm_true)
384  {
385  if (item->isEquipped() == Equipped_false)
387  }
388  }
389  }
390 }
int getTag() const
Definition: button.h:177
DragDropSourceT getSource() const
Definition: dragdrop.h:84
bool isEmpty() const
Definition: dragdrop.h:196
int getItem() const
Definition: dragdrop.h:66
ItemColor getItemColor() const
Definition: dragdrop.h:69
void setSelected(const int index)
const Item * getEquipment(const int index) const
Definition: equipment.h:69
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:94
Definition: item.h:50
Equipm isEquipment() const
Definition: item.h:117
Equipped isEquipped() const
Definition: item.h:129
DragDrop dragDrop
DragDropSource ::T DragDropSourceT
const bool Equipm_true
Definition: equipm.h:30
const bool Equipped_false
Definition: equipped.h:30
#define nullptr
Definition: localconsts.h:45
LocalPlayer * localPlayer
Inventory * getInventory()
Definition: playerinfo.cpp:195
void equipItem(const Item *const item, const Sfx sfx)
Definition: playerinfo.cpp:238
void unequipItem(const Item *const item, const Sfx sfx)
Definition: playerinfo.cpp:246
const bool Sfx_true
Definition: sfx.h:30

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(), localPlayer, mEquipment, mSelected, mSelectedTab, setSelected(), Sfx_true, PlayerInfo::unequipItem(), and updatePage().

◆ addBox()

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

Definition at line 803 of file equipmentwindow.cpp.

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

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().

◆ addDefaultPage()

void EquipmentWindow::addDefaultPage ( )
private

Definition at line 661 of file equipmentwindow.cpp.

662 {
663  if (!mHaveDefaultPage)
664  {
665  mHaveDefaultPage = true;
666  // TRANSLATORS: equipment window tab
667  addPage(_("default"));
668  }
669 }
int addPage(const std::string &name)

References _, addPage(), and mHaveDefaultPage.

Referenced by fillDefault().

◆ addPage()

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

Definition at line 837 of file equipmentwindow.cpp.

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

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

Referenced by addDefaultPage(), and loadPage().

◆ draw()

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

Draws the equipment window.

Reimplemented from Window.

Definition at line 182 of file equipmentwindow.cpp.

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

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

◆ fillBoxes()

void EquipmentWindow::fillBoxes ( )
private

Definition at line 629 of file equipmentwindow.cpp.

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

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().

◆ fillDefault()

void EquipmentWindow::fillDefault ( )
private

Definition at line 779 of file equipmentwindow.cpp.

780 {
781  if (mImageSet != nullptr)
782  mImageSet->decRef();
783 
784  addDefaultPage();
786  "equipmentbox.png", 32, 32);
787 
788  addBox(0, 90, 40, 0); // torso
789  addBox(1, 8, 78, 1); // gloves
790  addBox(2, 70, 0, 2); // hat
791  addBox(3, 50, 253, 3); // pants
792  addBox(4, 90, 253, 4); // boots
793  addBox(5, 8, 213, 5); // FREE
794  addBox(6, 129, 213, 6); // wings
795  addBox(7, 50, 40, 5); // scarf
796  addBox(8, 8, 168, 7); // weapon
797  addBox(9, 129, 168, 8); // shield
798  addBox(10, 129, 78, 9); // ammo
799  addBox(11, 8, 123, 5); // amulet
800  addBox(12, 129, 123, 5); // ring
801 }
void addBox(const int idx, int x, int y, const int imageIndex)

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

Referenced by fillBoxes().

◆ getEquipment()

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

Definition at line 83 of file equipmentwindow.h.

84  {
85  return mEquipment != nullptr ?
86  mEquipment->getEquipment(i) : nullptr;
87  }

References Equipment::getEquipment(), and mEquipment.

Referenced by StatusWindow::updateArrowsBar().

◆ getItem()

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

Definition at line 405 of file equipmentwindow.cpp.

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

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

Referenced by mouseMoved(), and mousePressed().

◆ loadPage()

void EquipmentWindow::loadPage ( const xmlNodePtr  node)
private

Definition at line 671 of file equipmentwindow.cpp.

672 {
673  if (node == nullptr)
674  return;
675  // TRANSLATORS: unknown equipment page name
676  const std::string &name = XML::langProperty(node, "name", _("Unknown"));
677  const int page = addPage(name);
678  for_each_xml_child_node(childNode, node)
679  {
680  if (xmlNameEqual(childNode, "playerbox"))
681  loadPlayerBox(childNode, page);
682  else if (xmlNameEqual(childNode, "slot"))
683  loadSlot(childNode, mImageSet, page);
684  }
685 }
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:258

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

Referenced by fillBoxes().

◆ loadPlayerBox()

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

Definition at line 687 of file equipmentwindow.cpp.

689 {
690  EquipmentPage *const data = mPages[page];
691  data->x = XML::getProperty(playerBoxNode, "x", 50);
692  data->y = XML::getProperty(playerBoxNode, "y", 80) + mYPadding;
693  data->width = XML::getProperty(playerBoxNode, "width", 74);
694  data->height = XML::getProperty(playerBoxNode, "height", 168);
695 }
uint32_t data

References data, XML::getProperty(), mPages, and mYPadding.

Referenced by loadPage().

◆ loadSlot()

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

Definition at line 697 of file equipmentwindow.cpp.

700 {
701  if (imageset == nullptr)
702  return;
703  const int slot = parseSlotName(XML::getProperty(slotNode, "name", ""));
704  if (slot < 0)
705  return;
706 
707  const int x = XML::getProperty(slotNode, "x", 0) + getPadding();
708  const int y = XML::getProperty(slotNode, "y", 0)
710  const int imageIndex = XML::getProperty(slotNode, "image", -1);
711  Image *image = nullptr;
712 
713  if (imageIndex >= 0 && imageIndex < CAST_S32(imageset->size()))
714  image = imageset->get(imageIndex);
715 
716  STD_VECTOR<EquipmentBox*> &boxes = mPages[page]->boxes;
717  if (boxes[slot] != nullptr)
718  {
719  EquipmentBox *const box = boxes[slot];
720  box->x = x;
721  box->y = y;
722  box->image = image;
723  }
724  else
725  {
726  boxes[slot] = new EquipmentBox(x, y, image);
727  }
728  if (x < mMinX)
729  mMinX = x;
730  if (y < mMinY)
731  mMinY = y;
732  if (x + mBoxSize > mMaxX)
733  mMaxX = x + mBoxSize;
734  if (y + mBoxSize > mMaxY)
735  mMaxY = y + mBoxSize;
736 }
static int parseSlotName(const std::string &name)

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 loadPage().

◆ loadWindow()

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

◆ 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 586 of file equipmentwindow.cpp.

587 {
588  if (itemPopup != nullptr)
590 }
void setVisible(Visible visible)
Definition: widget.cpp:225
ItemPopup * itemPopup
Definition: itempopup.cpp:64
const bool Visible_false
Definition: visible.h:30

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

◆ mouseMoved()

void EquipmentWindow::mouseMoved ( MouseEvent event)
virtual

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

Reimplemented from Window.

Definition at line 562 of file equipmentwindow.cpp.

563 {
564  Window::mouseMoved(event);
565 
566  if (itemPopup == nullptr)
567  return;
568 
569  const int x = event.getX();
570  const int y = event.getY();
571 
572  const Item *const item = getItem(x, y);
573 
574  if (item != nullptr)
575  {
576  itemPopup->setItem(item, false);
577  itemPopup->position(x + getX(), y + getY());
578  }
579  else
580  {
582  }
583 }
const Item * getItem(const int x, const int y) const
void setItem(const ItemInfo &item, const ItemColor color, const bool showImage, int id, const int *const cards, const ItemOptionsList *const options)
Definition: itempopup.cpp:189
void position(const int x, const int y)
Definition: popup.cpp:235
int getY() const
Definition: widget.h:288
int getX() const
Definition: widget.h:269
void mouseMoved(MouseEvent &event)
Definition: window.cpp:967

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

◆ mousePressed()

void EquipmentWindow::mousePressed ( MouseEvent event)
virtual

Starts window resizing when appropriate.

Reimplemented from Window.

Definition at line 427 of file equipmentwindow.cpp.

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

References dragDrop, DragDrop::dragItem(), DragDropSource::Equipment, MouseEvent::getButton(), Equipment::getEquipment(), getItem(), Widget::getX(), Widget::getY(), InventoryType::Inventory, Rect::isPointInRect(), 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.

◆ 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 506 of file equipmentwindow.cpp.

507 {
508  Window::mouseReleased(event);
509  const DragDropSourceT src = dragDrop.getSource();
511  && src != DragDropSource::Equipment))
512  {
513  return;
514  }
515  Inventory *const inventory = localPlayer != nullptr
517  if (inventory == nullptr)
518  return;
519 
520  Item *const item = inventory->findItem(dragDrop.getItem(),
522  if (item == nullptr)
523  return;
524 
526  {
527  if (item->isEquipment() == Equipm_true)
528  {
529  if (item->isEquipped() == Equipped_false)
531  }
532  }
534  {
535  if (item->isEquipment() == Equipm_true)
536  {
537  const int x = event.getX();
538  const int y = event.getY();
539  STD_VECTOR<EquipmentBox*> &boxes = mPages[mSelectedTab]->boxes;
540  for (STD_VECTOR<EquipmentBox*>::const_iterator
541  it = boxes.begin(), it_end = boxes.end();
542  it != it_end; ++ it)
543  {
544  const EquipmentBox *const box = *it;
545  if (box == nullptr)
546  continue;
547  const Rect tRect(box->x, box->y, mBoxSize, mBoxSize);
548 
549  if (tRect.isPointInRect(x, y))
550  return;
551  }
552 
553  if (item->isEquipped() == Equipped_true)
555  }
556  }
557  dragDrop.clear();
558  dragDrop.deselect();
559 }
void deselect()
Definition: dragdrop.h:213
void clear()
Definition: dragdrop.h:183
void mouseReleased(MouseEvent &event)
Definition: window.cpp:907
const bool Equipped_true
Definition: equipped.h:30

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(), localPlayer, mBoxSize, Window::mouseReleased(), mPages, mSelectedTab, Sfx_true, PlayerInfo::unequipItem(), EquipmentBox::x, x, EquipmentBox::y, and y.

◆ parseSlotName()

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

Definition at line 771 of file equipmentwindow.cpp.

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

References mSlotNames.

Referenced by loadSlot().

◆ postInit()

void EquipmentWindow::postInit ( )
virtual

Reimplemented from Window.

Definition at line 135 of file equipmentwindow.cpp.

136 {
138  const Rect &area = getChildrenArea();
141  mUnequip->setEnabled(false);
142 
143  ImageRect rect;
144  theme->loadRect(rect, "equipment_background.xml", "", 0, 1);
145  mSlotBackground = rect.grid[0];
147  add(mTabs);
148  add(mPlayerBox);
149  add(mUnequip);
150  enableVisibleSound(true);
151  mPlayerBox->setActionEventId("playerbox");
153 }
virtual void add(Widget *const widget)
Image * grid[9]
Definition: imagerect.h:42
int width
Definition: rect.h:219
int height
Definition: rect.h:224
void loadRect(ImageRect &image, const std::string &name, const std::string &name2, const int start, const int end)
Definition: theme.cpp:883
void setEnabled(const bool enabled)
Definition: widget.h:352
void setPosition(const int x, const int y)
Definition: widget.cpp:161
int getWidth() const
Definition: widget.h:221
void postInit()
Definition: window.cpp:249
void enableVisibleSound(bool b)
Definition: window.h:481
Rect getChildrenArea()
Definition: window.cpp:1473
Theme * theme
Definition: theme.cpp:62

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.

◆ prepareSlotNames()

void EquipmentWindow::prepareSlotNames ( )
static

Definition at line 738 of file equipmentwindow.cpp.

739 {
740  mSlotNames.clear();
741  XML::Document doc(paths.getStringValue("equipmentSlotsFile"),
744  XmlNodeConstPtrConst root = doc.rootNode();
745  if (root == nullptr)
746  return;
747 
748  for_each_xml_child_node(slotNode, root)
749  {
750  if (!xmlNameEqual(slotNode, "slot"))
751  continue;
752  const std::string name = XML::getProperty(slotNode, "name", "");
753  if (name.empty())
754  {
755  reportAlways("Empty slot name detected.")
756  continue;
757  }
758 
759  const int slot = XML::getProperty(slotNode, "slot", -1);
760  if (slot < 0 || slot >= BOX_COUNT)
761  {
762  reportAlways("Wrong slot id '%d' for slot with name '%s'",
763  slot,
764  name.c_str())
765  continue;
766  }
767  mSlotNames[name] = slot;
768  }
769 }
#define reportAlways(...)
Definition: checkutils.h:253
Definition: libxml.cpp:86

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 Client::loadData().

◆ recalcSize()

void EquipmentWindow::recalcSize ( )

Definition at line 828 of file equipmentwindow.cpp.

829 {
830  mMaxX += mMinX;
831  mMaxY += mMinY;
832  mTabs->setWidth(mMaxX);
835 }
void setWidth(const int width)
Definition: widget.cpp:133
void setDefaultSize()
Definition: window.cpp:1198

References ImagePosition::CENTER, Widget::getHeight(), mMaxX, mMaxY, mMinX, mMinY, mTabs, mUnequip, mYPadding, Window::setDefaultSize(), and Widget::setWidth().

Referenced by EquipmentWindow().

◆ resetBeing()

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

Definition at line 623 of file equipmentwindow.cpp.

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

References mBeing, and setBeing().

Referenced by ActorManager::logic().

◆ safeDraw()

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

Reimplemented from Window.

Definition at line 269 of file equipmentwindow.cpp.

270 {
271  BLOCK_START("EquipmentWindow::draw")
272  // Draw window graphics
273  Window::safeDraw(graphics);
274 
275  int i = 0;
276  Font *const font = getFont();
277  const int fontHeight = font->getHeight();
278  const STD_VECTOR<EquipmentBox*> &boxes = mPages[mSelectedTab]->boxes;
279 
280  for (STD_VECTOR<EquipmentBox*>::const_iterator it = boxes.begin(),
281  it_end = boxes.end(); it != it_end; ++ it, ++ i)
282  {
283  const EquipmentBox *const box = *it;
284  if (box == nullptr)
285  continue;
286  if (i == mSelected)
287  {
288  graphics->drawImage(mSlotHighlightedBackground,
289  box->x, box->y);
290  }
291  else
292  {
293  graphics->drawImage(mSlotBackground, box->x, box->y);
294  }
295  }
296 
297  if (mEquipment == nullptr)
298  {
299  BLOCK_END("EquipmentWindow::draw")
300  return;
301  }
302 
303  i = 0;
304  const int projSlot = inventoryHandler->getProjectileSlot();
305  for (STD_VECTOR<EquipmentBox*>::const_iterator it = boxes.begin(),
306  it_end = boxes.end(); it != it_end; ++ it, ++ i)
307  {
308  const EquipmentBox *const box = *it;
309  if (box == nullptr)
310  continue;
311  const Item *const item = mEquipment->getEquipment(i);
312  if (item != nullptr)
313  {
314  // Draw Item.
315  Image *const image = item->getImage();
316  if (image != nullptr)
317  {
318  image->setAlpha(1.0F); // Ensure the image is drawn
319  // with maximum opacity
320  graphics->drawImage(image, box->x + mItemPadding,
321  box->y + mItemPadding);
322  if (i == projSlot)
323  {
324  const std::string str = toString(item->getQuantity());
325  font->drawString(graphics,
326  mLabelsColor,
328  str,
329  box->x + (mBoxSize - font->getWidth(str)) / 2,
330  box->y - fontHeight);
331  }
332  }
333  }
334  else if (box->image != nullptr)
335  {
336  graphics->drawImage(box->image,
337  box->x + mItemPadding,
338  box->y + mItemPadding);
339  }
340  }
341  BLOCK_END("EquipmentWindow::draw")
342 }
void safeDraw(Graphics *const graphics)

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

◆ setBeing()

void EquipmentWindow::setBeing ( Being *const  being)

Definition at line 602 of file equipmentwindow.cpp.

603 {
604  mPlayerBox->setPlayer(being);
605  mBeing = being;
606  if (mEquipment != nullptr)
607  delete mEquipment->getBackend();
608  delete mEquipment;
609  if (being == nullptr)
610  {
611  mEquipment = nullptr;
612  return;
613  }
614  mEquipment = being->getEquipment();
615 }
Equipment * getEquipment()
Definition: being.cpp:4697

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

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

◆ setSelected()

void EquipmentWindow::setSelected ( const int  index)
private

Definition at line 592 of file equipmentwindow.cpp.

593 {
594  mSelected = index;
595  mRedraw = true;
596  if (mUnequip != nullptr)
597  mUnequip->setEnabled(mSelected != -1);
598  if (itemPopup != nullptr)
600 }
bool mRedraw
Definition: widget.h:1164

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

Referenced by action(), and mousePressed().

◆ updateBeing()

void EquipmentWindow::updateBeing ( Being *const  being)

Definition at line 617 of file equipmentwindow.cpp.

618 {
619  if (being == mBeing)
620  setBeing(being);
621 }

References mBeing, and setBeing().

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

◆ updatePage()

void EquipmentWindow::updatePage ( )
private

Definition at line 392 of file equipmentwindow.cpp.

393 {
394  EquipmentPage *const page = mPages[mSelectedTab];
395  const Visible visible = fromBool(page->showPlayerBox, Visible);
396  mPlayerBox->setVisible(visible);
397  if (visible == Visible_true)
398  {
399  mPlayerBox->setDimension(Rect(page->x, page->y,
400  page->width, page->height));
401  }
402  mRedraw = true;
403 }
#define fromBool(val, name)
Definition: booldefines.h:49
bool Visible
Definition: visible.h:30
const bool Visible_true
Definition: visible.h:30

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(), and EquipmentWindow().

Field Documentation

◆ mBeing

Being* EquipmentWindow::mBeing
private

Definition at line 142 of file equipmentwindow.h.

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

◆ mBorderColor

Color EquipmentWindow::mBorderColor
private

Definition at line 149 of file equipmentwindow.h.

◆ mBoxSize

int EquipmentWindow::mBoxSize
private

◆ mButtonPadding

int EquipmentWindow::mButtonPadding
private

Definition at line 155 of file equipmentwindow.h.

Referenced by postInit().

◆ mEquipment

Equipment* EquipmentWindow::mEquipment
private

◆ mForing

bool EquipmentWindow::mForing
private

Definition at line 162 of file equipmentwindow.h.

Referenced by mousePressed().

◆ mHaveDefaultPage

bool EquipmentWindow::mHaveDefaultPage
private

Definition at line 163 of file equipmentwindow.h.

Referenced by addDefaultPage().

◆ mHighlightColor

Color EquipmentWindow::mHighlightColor
private

Definition at line 148 of file equipmentwindow.h.

◆ mImageSet

ImageSet* EquipmentWindow::mImageSet
private

Definition at line 141 of file equipmentwindow.h.

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

◆ mItemPadding

int EquipmentWindow::mItemPadding
private

Definition at line 153 of file equipmentwindow.h.

Referenced by draw(), and safeDraw().

◆ mLabelsColor

Color EquipmentWindow::mLabelsColor
private

Definition at line 150 of file equipmentwindow.h.

Referenced by draw(), and safeDraw().

◆ mLabelsColor2

Color EquipmentWindow::mLabelsColor2
private

Definition at line 151 of file equipmentwindow.h.

Referenced by draw(), and safeDraw().

◆ mMaxX

int EquipmentWindow::mMaxX
private

Definition at line 158 of file equipmentwindow.h.

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

◆ mMaxY

int EquipmentWindow::mMaxY
private

Definition at line 159 of file equipmentwindow.h.

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

◆ mMinX

int EquipmentWindow::mMinX
private

Definition at line 156 of file equipmentwindow.h.

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

◆ mMinY

int EquipmentWindow::mMinY
private

Definition at line 157 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 138 of file equipmentwindow.h.

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

◆ mSelected

int EquipmentWindow::mSelected
private

Index of selected item.

Definition at line 152 of file equipmentwindow.h.

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

◆ mSelectedTab

int EquipmentWindow::mSelectedTab
private

Definition at line 161 of file equipmentwindow.h.

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

◆ mSlotBackground

Image* EquipmentWindow::mSlotBackground
private

Definition at line 143 of file equipmentwindow.h.

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

◆ mSlotHighlightedBackground

Image* EquipmentWindow::mSlotHighlightedBackground
private

Definition at line 144 of file equipmentwindow.h.

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

◆ mSlotNames

StringIntMap EquipmentWindow::mSlotNames
staticprivate

Definition at line 134 of file equipmentwindow.h.

Referenced by parseSlotName(), and prepareSlotNames().

◆ mTabs

TabStrip* EquipmentWindow::mTabs
private

Definition at line 147 of file equipmentwindow.h.

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

◆ mUnequip

Button* EquipmentWindow::mUnequip
private

Definition at line 139 of file equipmentwindow.h.

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

◆ mVertexes

ImageCollection* EquipmentWindow::mVertexes
private

Definition at line 145 of file equipmentwindow.h.

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

◆ mYPadding

int EquipmentWindow::mYPadding
private

Definition at line 160 of file equipmentwindow.h.

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


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