ManaPlus
Public Member Functions | Private Attributes
VirtShortcutContainer Class Reference

#include <virtshortcutcontainer.h>

Inheritance diagram for VirtShortcutContainer:
ShortcutContainer Widget WidgetListener MouseListener Widget2

Public Member Functions

 VirtShortcutContainer (Widget2 *const widget, ShortcutBase *const shortcut)
 
 ~VirtShortcutContainer ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void mouseDragged (MouseEvent &event)
 
void mousePressed (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void widgetHidden (const Event &event)
 
void mouseExited (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void setSkin (const Widget2 *const widget, Skin *const skin)
 
- Public Member Functions inherited from ShortcutContainer
 ~ShortcutContainer ()
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
int getMaxItems () const
 
int getBoxWidth () const
 
int getBoxHeight () const
 
void drawBackground (Graphics *const g)
 
void safeDrawBackground (Graphics *const g)
 
- 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
 
virtual void logic ()
 
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 ()
 
virtual void setFocusHandler (FocusHandler *const focusHandler)
 
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
 
virtual WidgetgetWidgetAt (int x, int y)
 
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 Rect getChildrenArea ()
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
virtual void moveToTop (Widget *widget)
 
virtual void moveToBottom (Widget *widget)
 
virtual void focusNext ()
 
virtual void focusPrevious ()
 
virtual void showWidgetPart (Widget *const widget, const Rect &area)
 
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 ()
 
virtual void postInit ()
 
- 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 WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetShown (const Event &event)
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseEntered (MouseEvent &event)
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 

Private Attributes

bool mItemClicked
 
Color mEquipedColor
 
Color mEquipedColor2
 
Color mUnEquipedColor
 
Color mUnEquipedColor2
 
ShortcutBasemShortcut
 

Additional Inherited Members

- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from 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 ShortcutContainer
 ShortcutContainer (Widget2 *const widget)
 
int getIndexFromGrid (const int pointX, const int pointY) const
 
- 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 WidgetListener
 WidgetListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Attributes inherited from ShortcutContainer
ImagemBackgroundImg
 
SkinmSkin
 
unsigned mMaxItems
 
int mBoxWidth
 
int mBoxHeight
 
int mGridWidth
 
int mGridHeight
 
int mImageOffsetX
 
int mImageOffsetY
 
int mTextOffsetX
 
int mTextOffsetY
 
ImageCollectionmVertexes
 
- 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 ShortcutContainer
static float mAlpha = 1.0
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

An item shortcut container. Used to quickly use items.

Definition at line 35 of file virtshortcutcontainer.h.

Constructor & Destructor Documentation

◆ VirtShortcutContainer()

VirtShortcutContainer::VirtShortcutContainer ( Widget2 *const  widget,
ShortcutBase *const  shortcut 
)

Constructor. Initializes the graphic.

Definition at line 45 of file virtshortcutcontainer.cpp.

References ShortcutBase::getItemCount(), ShortcutContainer::mMaxItems, and mShortcut.

46  :
47  ShortcutContainer(widget),
48  mItemClicked(false),
53  255U)),
54  mShortcut(shortcut)
55 {
56  if (mShortcut != nullptr)
58  else
59  mMaxItems = 0;
60 }
ShortcutContainer(Widget2 *const widget)
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
int getItemCount() const
Definition: shortcutbase.h:80

◆ ~VirtShortcutContainer()

VirtShortcutContainer::~VirtShortcutContainer ( )

Destructor.

Definition at line 62 of file virtshortcutcontainer.cpp.

63 {
64 }

Member Function Documentation

◆ draw()

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

Draws the items.

Implements Widget.

Definition at line 77 of file virtshortcutcontainer.cpp.

References BLOCK_END, BLOCK_START, ShortcutContainer::drawBackground(), Graphics::drawImage(), Font::drawString(), Equipped_true, Inventory::findItem(), ServerCommandType::font, Widget::getFont(), Item::getImage(), PlayerInfo::getInventory(), ShortcutBase::getItem(), ShortcutBase::getItemColor(), Item::getQuantity(), Font::getWidth(), Settings::guiAlpha, Item::isEquipped(), ServerCommandType::item, ShortcutContainer::mAlpha, ShortcutContainer::mBackgroundImg, ShortcutContainer::mBoxHeight, ShortcutContainer::mBoxWidth, mEquipedColor, mEquipedColor2, ShortcutContainer::mGridWidth, ShortcutContainer::mImageOffsetX, ShortcutContainer::mImageOffsetY, ShortcutContainer::mMaxItems, mShortcut, mUnEquipedColor, mUnEquipedColor2, Image::setAlpha(), settings, and Catch::toString().

78 {
79  if (mShortcut == nullptr)
80  return;
81 
82  BLOCK_START("VirtShortcutContainer::draw")
83  if (settings.guiAlpha != mAlpha)
84  {
85  mAlpha = settings.guiAlpha;
86  if (mBackgroundImg != nullptr)
87  mBackgroundImg->setAlpha(mAlpha);
88  }
89 
90  drawBackground(graphics);
91 
92  const Inventory *const inv = PlayerInfo::getInventory();
93  if (inv == nullptr)
94  {
95  BLOCK_END("VirtShortcutContainer::draw")
96  return;
97  }
98 
99  Font *const font = getFont();
100 
101  for (unsigned i = 0; i < mMaxItems; i++)
102  {
103  const int itemX = (i % mGridWidth) * mBoxWidth;
104  const int itemY = (i / mGridWidth) * mBoxHeight;
105 
106  if (mShortcut->getItem(i) < 0)
107  continue;
108 
109  const Item *const item = inv->findItem(mShortcut->getItem(i),
110  mShortcut->getItemColor(i));
111 
112  if (item != nullptr)
113  {
114  // Draw item icon.
115  Image *const image = item->getImage();
116 
117  if (image != nullptr)
118  {
119  std::string caption;
120  if (item->getQuantity() > 1)
121  caption = toString(item->getQuantity());
122  else if (item->isEquipped() == Equipped_true)
123  caption = "Eq.";
124 
125  image->setAlpha(1.0F);
126  graphics->drawImage(image,
127  itemX + mImageOffsetX,
128  itemY + mImageOffsetY);
129  if (item->isEquipped() == Equipped_true)
130  {
131  font->drawString(graphics,
134  caption,
135  itemX + (mBoxWidth - font->getWidth(caption)) / 2,
136  itemY + mBoxHeight - 14);
137  }
138  else
139  {
140  font->drawString(graphics,
143  caption,
144  itemX + (mBoxWidth - font->getWidth(caption)) / 2,
145  itemY + mBoxHeight - 14);
146  }
147  }
148  }
149  }
150  BLOCK_END("VirtShortcutContainer::draw")
151 }
Font * getFont() const
Definition: widget.cpp:330
Definition: font.h:88
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:193
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
const bool Equipped_true
Definition: equipped.h:29
Settings settings
Definition: settings.cpp:31
virtual void setAlpha(const float alpha)
Definition: image.cpp:286
int getQuantity() const
Definition: item.h:104
Definition: item.h:48
int getItem(const size_t index) const
Definition: shortcutbase.h:71
void drawBackground(Graphics *const g)
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
Image * getImage() const
Definition: item.h:86
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
Definition: image.h:61
float guiAlpha
Definition: settings.h:129
ItemColor getItemColor(const size_t index) const
Definition: shortcutbase.h:74

◆ mouseDragged()

void VirtShortcutContainer::mouseDragged ( MouseEvent event)
virtual

Handles mouse when dragged.

Reimplemented from ShortcutContainer.

Definition at line 229 of file virtshortcutcontainer.cpp.

References DragDrop::clear(), dragDrop, DragDrop::dragItem(), DragDropSource::Drop, Inventory::findItem(), MouseEvent::getButton(), ShortcutContainer::getIndexFromGrid(), PlayerInfo::getInventory(), ShortcutBase::getItem(), ShortcutBase::getItemColor(), MouseEvent::getX(), DragDrop::isEmpty(), ServerCommandType::item, MouseButton::LEFT, mItemClicked, mShortcut, and ShortcutBase::removeItem().

230 {
231  if (mShortcut == nullptr)
232  return;
233 
234  if (event.getButton() == MouseButton::LEFT)
235  {
236  if (dragDrop.isEmpty() && mItemClicked)
237  {
238  const int index = getIndexFromGrid(event.getX(), event.getY());
239 
240  if (index == -1)
241  return;
242 
243  const int itemId = mShortcut->getItem(index);
244  const ItemColor itemColor = mShortcut->getItemColor(index);
245 
246  if (itemId < 0)
247  return;
248 
249  const Inventory *const inv = PlayerInfo::getInventory();
250  if (inv == nullptr)
251  return;
252 
253  Item *const item = inv->findItem(itemId, itemColor);
254 
255  if (item != nullptr)
256  {
258  mShortcut->removeItem(index);
259  }
260  else
261  {
262  dragDrop.clear();
263  }
264  }
265  }
266 }
void clear()
Definition: dragdrop.h:182
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
MouseButtonT getButton() const
Definition: mouseevent.h:115
Inventory * getInventory()
Definition: playerinfo.cpp:193
DragDrop dragDrop
uint16_t ItemColor
Definition: itemcolor.h:29
bool isEmpty() const
Definition: dragdrop.h:195
void dragItem(const Item *const item, const DragDropSourceT source, const int tag)
Definition: dragdrop.h:86
int getIndexFromGrid(const int pointX, const int pointY) const
void removeItem(const size_t index)
Definition: shortcutbase.h:126
Definition: item.h:48
int getItem(const size_t index) const
Definition: shortcutbase.h:71
int getX() const
Definition: mouseevent.h:126
ItemColor getItemColor(const size_t index) const
Definition: shortcutbase.h:74

◆ mouseExited()

void VirtShortcutContainer::mouseExited ( MouseEvent event)
virtual

Called when the mouse has exited the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 380 of file virtshortcutcontainer.cpp.

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

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

◆ mouseMoved()

void VirtShortcutContainer::mouseMoved ( MouseEvent event)
virtual

Called when the mouse has moved in the widget area and no mouse button has been pressed (i.e no widget is being dragged).

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 347 of file virtshortcutcontainer.cpp.

References Inventory::findItem(), ShortcutContainer::getIndexFromGrid(), PlayerInfo::getInventory(), ShortcutBase::getItem(), ShortcutBase::getItemColor(), MouseEvent::getX(), ServerCommandType::item, itemPopup, Viewport::mMouseX, Viewport::mMouseY, mShortcut, Popup::position(), ItemPopup::setItem(), Widget::setVisible(), viewport, and Visible_false.

348 {
349  if (mShortcut == nullptr)
350  return;
351 
352  const int index = getIndexFromGrid(event.getX(), event.getY());
353 
354  if (index == -1)
355  return;
356 
357  const int itemId = mShortcut->getItem(index);
358  const ItemColor itemColor = mShortcut->getItemColor(index);
359 
360  if (itemId < 0)
361  return;
362 
363  const Inventory *const inv = PlayerInfo::getInventory();
364  if (inv == nullptr)
365  return;
366 
367  const Item *const item = inv->findItem(itemId, itemColor);
368 
369  if ((item != nullptr) && (viewport != nullptr))
370  {
371  itemPopup->setItem(item, false);
373  }
374  else
375  {
377  }
378 }
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
void setVisible(Visible visible)
Definition: widget.cpp:224
Inventory * getInventory()
Definition: playerinfo.cpp:193
uint16_t ItemColor
Definition: itemcolor.h:29
int mMouseX
Definition: viewport.h:153
int getIndexFromGrid(const int pointX, const int pointY) const
const bool Visible_false
Definition: visible.h:29
void position(const int x, const int y)
Definition: popup.cpp:234
Definition: item.h:48
int getItem(const size_t index) const
Definition: shortcutbase.h:71
void setItem(const ItemInfo &item, const ItemColor color, const bool showImage, int id, const int *const cards, const ItemOptionsList *const options)
Definition: itempopup.cpp:188
int mMouseY
Definition: viewport.h:154
int getX() const
Definition: mouseevent.h:126
ItemPopup * itemPopup
Definition: itempopup.cpp:63
ItemColor getItemColor(const size_t index) const
Definition: shortcutbase.h:74
Viewport * viewport
Definition: viewport.cpp:35

◆ mousePressed()

void VirtShortcutContainer::mousePressed ( MouseEvent event)
virtual

Handles mouse when pressed.

Reimplemented from ShortcutContainer.

Definition at line 268 of file virtshortcutcontainer.cpp.

References DragDrop::deselect(), dragDrop, Inventory::findItem(), ShortcutContainer::getIndexFromGrid(), PlayerInfo::getInventory(), ShortcutBase::getItem(), ShortcutBase::getItemColor(), DragDrop::getSelected(), DragDrop::getSelectedColor(), MouseEvent::getX(), inventoryWindow, DragDrop::isSelected(), ServerCommandType::item, MouseButton::LEFT, mItemClicked, Viewport::mMouseX, Viewport::mMouseY, mShortcut, popupMenu, MouseButton::RIGHT, ShortcutBase::setItems(), PopupMenu::showDropPopup(), and viewport.

269 {
270  if ((mShortcut == nullptr) || (inventoryWindow == nullptr))
271  return;
272 
273  const int index = getIndexFromGrid(event.getX(), event.getY());
274 
275  if (index == -1)
276  return;
277 
278  event.consume();
279 
280  const MouseButtonT eventButton = event.getButton();
281  if (eventButton == MouseButton::LEFT)
282  {
283  if (mShortcut->getItem(index) > 0)
284  {
285  mItemClicked = true;
286  }
287  else
288  {
289  if (dragDrop.isSelected())
290  {
293  dragDrop.deselect();
294  }
295  }
296  }
297  else if (eventButton == MouseButton::RIGHT)
298  {
299  const Inventory *const inv = PlayerInfo::getInventory();
300  if (inv == nullptr)
301  return;
302 
303  Item *const item = inv->findItem(mShortcut->getItem(index),
304  mShortcut->getItemColor(index));
305 
306  if (popupMenu != nullptr)
307  {
309  viewport->mMouseY,
310  item);
311  }
312  }
313 }
bool isSelected() const
Definition: dragdrop.h:224
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
Inventory * getInventory()
Definition: playerinfo.cpp:193
DragDrop dragDrop
int mMouseX
Definition: viewport.h:153
InventoryWindow * inventoryWindow
void setItems(const size_t index, const int itemId, const ItemColor color)
Definition: shortcutbase.h:102
int getIndexFromGrid(const int pointX, const int pointY) const
void showDropPopup(const int x, const int y, const Item *const item)
Definition: popupmenu.cpp:1848
int getSelected() const
Definition: dragdrop.h:218
PopupMenu * popupMenu
Definition: popupmenu.cpp:102
Definition: item.h:48
void deselect()
Definition: dragdrop.h:212
int getItem(const size_t index) const
Definition: shortcutbase.h:71
int mMouseY
Definition: viewport.h:154
int getX() const
Definition: mouseevent.h:126
MouseButton ::T MouseButtonT
Definition: mousebutton.h:77
ItemColor getSelectedColor() const
Definition: dragdrop.h:221
ItemColor getItemColor(const size_t index) const
Definition: shortcutbase.h:74
Viewport * viewport
Definition: viewport.cpp:35

◆ mouseReleased()

void VirtShortcutContainer::mouseReleased ( MouseEvent event)
virtual

Handles mouse release.

Reimplemented from ShortcutContainer.

Definition at line 315 of file virtshortcutcontainer.cpp.

References DragDrop::clear(), DragDrop::deselect(), dragDrop, MouseEvent::getButton(), ShortcutContainer::getIndexFromGrid(), DragDrop::getItem(), DragDrop::getItemColor(), MouseEvent::getX(), DragDrop::isEmpty(), ShortcutBase::isItemSelected(), DragDrop::isSourceItemContainer(), MouseButton::LEFT, mItemClicked, mShortcut, ShortcutBase::setItems(), and ShortcutBase::setItemSelected().

316 {
317  if (mShortcut == nullptr)
318  return;
319 
320  if (event.getButton() == MouseButton::LEFT)
321  {
322  if (mShortcut->isItemSelected())
324 
325  const int index = getIndexFromGrid(event.getX(), event.getY());
326  if (index == -1)
327  {
328  dragDrop.clear();
329  return;
330  }
331  if (!dragDrop.isEmpty())
332  {
334  {
337  dragDrop.clear();
338  dragDrop.deselect();
339  }
340  }
341 
342  mItemClicked = false;
343  }
344 }
void clear()
Definition: dragdrop.h:182
void setItemSelected(const int itemId)
Definition: shortcutbase.h:112
MouseButtonT getButton() const
Definition: mouseevent.h:115
DragDrop dragDrop
bool isItemSelected() const
Definition: shortcutbase.h:120
bool isEmpty() const
Definition: dragdrop.h:195
void setItems(const size_t index, const int itemId, const ItemColor color)
Definition: shortcutbase.h:102
int getIndexFromGrid(const int pointX, const int pointY) const
bool isSourceItemContainer() const
Definition: dragdrop.h:240
void deselect()
Definition: dragdrop.h:212
ItemColor getItemColor() const
Definition: dragdrop.h:68
int getX() const
Definition: mouseevent.h:126
int getItem() const
Definition: dragdrop.h:65

◆ safeDraw()

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

Implements Widget.

Definition at line 153 of file virtshortcutcontainer.cpp.

References BLOCK_END, BLOCK_START, Graphics::drawImage(), Font::drawString(), Equipped_true, Inventory::findItem(), ServerCommandType::font, Widget::getFont(), Item::getImage(), PlayerInfo::getInventory(), ShortcutBase::getItem(), ShortcutBase::getItemColor(), Item::getQuantity(), Font::getWidth(), Settings::guiAlpha, Item::isEquipped(), ServerCommandType::item, ShortcutContainer::mAlpha, ShortcutContainer::mBackgroundImg, ShortcutContainer::mBoxHeight, ShortcutContainer::mBoxWidth, mEquipedColor, mEquipedColor2, ShortcutContainer::mGridWidth, ShortcutContainer::mImageOffsetX, ShortcutContainer::mImageOffsetY, ShortcutContainer::mMaxItems, mShortcut, mUnEquipedColor, mUnEquipedColor2, ShortcutContainer::safeDrawBackground(), Image::setAlpha(), settings, and Catch::toString().

154 {
155  if (mShortcut == nullptr)
156  return;
157 
158  BLOCK_START("VirtShortcutContainer::safeDraw")
159  if (settings.guiAlpha != mAlpha)
160  {
161  mAlpha = settings.guiAlpha;
162  if (mBackgroundImg != nullptr)
163  mBackgroundImg->setAlpha(mAlpha);
164  }
165 
166  safeDrawBackground(graphics);
167 
168  const Inventory *const inv = PlayerInfo::getInventory();
169  if (inv == nullptr)
170  {
171  BLOCK_END("VirtShortcutContainer::safeDraw")
172  return;
173  }
174 
175  Font *const font = getFont();
176 
177  for (unsigned i = 0; i < mMaxItems; i++)
178  {
179  const int itemX = (i % mGridWidth) * mBoxWidth;
180  const int itemY = (i / mGridWidth) * mBoxHeight;
181 
182  if (mShortcut->getItem(i) < 0)
183  continue;
184 
185  const Item *const item = inv->findItem(mShortcut->getItem(i),
186  mShortcut->getItemColor(i));
187 
188  if (item != nullptr)
189  {
190  // Draw item icon.
191  Image *const image = item->getImage();
192 
193  if (image != nullptr)
194  {
195  std::string caption;
196  if (item->getQuantity() > 1)
197  caption = toString(item->getQuantity());
198  else if (item->isEquipped() == Equipped_true)
199  caption = "Eq.";
200 
201  image->setAlpha(1.0F);
202  graphics->drawImage(image,
203  itemX + mImageOffsetX,
204  itemY + mImageOffsetY);
205  if (item->isEquipped() == Equipped_true)
206  {
207  font->drawString(graphics,
210  caption,
211  itemX + (mBoxWidth - font->getWidth(caption)) / 2,
212  itemY + mBoxHeight - 14);
213  }
214  else
215  {
216  font->drawString(graphics,
219  caption,
220  itemX + (mBoxWidth - font->getWidth(caption)) / 2,
221  itemY + mBoxHeight - 14);
222  }
223  }
224  }
225  }
226  BLOCK_END("VirtShortcutContainer::safeDraw")
227 }
Font * getFont() const
Definition: widget.cpp:330
Definition: font.h:88
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:193
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
const bool Equipped_true
Definition: equipped.h:29
Settings settings
Definition: settings.cpp:31
virtual void setAlpha(const float alpha)
Definition: image.cpp:286
int getQuantity() const
Definition: item.h:104
Definition: item.h:48
int getItem(const size_t index) const
Definition: shortcutbase.h:71
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
Image * getImage() const
Definition: item.h:86
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
Definition: image.h:61
void safeDrawBackground(Graphics *const g)
float guiAlpha
Definition: settings.h:129
ItemColor getItemColor(const size_t index) const
Definition: shortcutbase.h:74

◆ setSkin()

void VirtShortcutContainer::setSkin ( const Widget2 *const  widget,
Skin *const  skin 
)
virtual

Reimplemented from ShortcutContainer.

Definition at line 66 of file virtshortcutcontainer.cpp.

References Widget2::getThemeColor(), ThemeColorId::ITEM_EQUIPPED, ThemeColorId::ITEM_EQUIPPED_OUTLINE, ThemeColorId::ITEM_NOT_EQUIPPED, ThemeColorId::ITEM_NOT_EQUIPPED_OUTLINE, mEquipedColor, mEquipedColor2, mUnEquipedColor, mUnEquipedColor2, and ShortcutContainer::setSkin().

◆ widgetHidden()

void VirtShortcutContainer::widgetHidden ( const Event event)
virtual

Invoked when a widget is hidden, i.e it's set to be not visible.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 386 of file virtshortcutcontainer.cpp.

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

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

Field Documentation

◆ mEquipedColor

Color VirtShortcutContainer::mEquipedColor
private

Definition at line 85 of file virtshortcutcontainer.h.

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

◆ mEquipedColor2

Color VirtShortcutContainer::mEquipedColor2
private

Definition at line 86 of file virtshortcutcontainer.h.

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

◆ mItemClicked

bool VirtShortcutContainer::mItemClicked
private

Definition at line 83 of file virtshortcutcontainer.h.

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

◆ mShortcut

ShortcutBase* VirtShortcutContainer::mShortcut
private

◆ mUnEquipedColor

Color VirtShortcutContainer::mUnEquipedColor
private

Definition at line 87 of file virtshortcutcontainer.h.

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

◆ mUnEquipedColor2

Color VirtShortcutContainer::mUnEquipedColor2
private

Definition at line 88 of file virtshortcutcontainer.h.

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


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