ManaPlus
Public Member Functions | Private Attributes
ItemShortcutContainer Class Reference

#include <itemshortcutcontainer.h>

Inheritance diagram for ItemShortcutContainer:
ShortcutContainer Widget WidgetListener MouseListener Widget2

Public Member Functions

 ItemShortcutContainer (Widget2 *const widget, const unsigned number)
 
 ~ItemShortcutContainer ()
 
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)
 
void mouseDragged (MouseEvent &event)
 
void mousePressed (MouseEvent &event)
 
void mouseReleased (MouseEvent &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

Color mEquipedColor
 
Color mEquipedColor2
 
Color mUnEquipedColor
 
Color mUnEquipedColor2
 
unsigned mNumber
 
int mKeyOffsetX
 
int mKeyOffsetY
 
bool mItemClicked
 

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 34 of file itemshortcutcontainer.h.

Constructor & Destructor Documentation

◆ ItemShortcutContainer()

ItemShortcutContainer::ItemShortcutContainer ( Widget2 *const  widget,
const unsigned  number 
)

Constructor. Initializes the graphic.

Definition at line 58 of file itemshortcutcontainer.cpp.

59  :
60  ShortcutContainer(widget),
61  mEquipedColor(getThemeColor(ThemeColorId::ITEM_EQUIPPED, 255U)),
62  mEquipedColor2(getThemeColor(ThemeColorId::ITEM_EQUIPPED_OUTLINE, 255U)),
63  mUnEquipedColor(getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED, 255U)),
64  mUnEquipedColor2(getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED_OUTLINE,
65  255U)),
66  mNumber(number),
67  mKeyOffsetX(2),
68  mKeyOffsetY(2),
69  mItemClicked(false)
70 {
72 }
static int getItemCount()
Definition: itemshortcut.h:86
ShortcutContainer(Widget2 *const widget)
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45

References ItemShortcut::getItemCount(), and ShortcutContainer::mMaxItems.

◆ ~ItemShortcutContainer()

ItemShortcutContainer::~ItemShortcutContainer ( )

Destructor.

Definition at line 74 of file itemshortcutcontainer.cpp.

75 {
76 }

Member Function Documentation

◆ draw()

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

Draws the items.

Implements Widget.

Definition at line 96 of file itemshortcutcontainer.cpp.

97 {
98  BLOCK_START("ItemShortcutContainer::draw")
99  const ItemShortcut *const selShortcut = itemShortcut[mNumber];
100  if (selShortcut == nullptr)
101  {
102  BLOCK_END("ItemShortcutContainer::draw")
103  return;
104  }
105 
106  if (settings.guiAlpha != mAlpha)
107  {
108  if (mBackgroundImg != nullptr)
109  mBackgroundImg->setAlpha(mAlpha);
111  }
112 
113  Font *const font = getFont();
114  drawBackground(graphics);
115 
116  const Inventory *const inv = PlayerInfo::getInventory();
117  if (inv == nullptr)
118  {
119  BLOCK_END("ItemShortcutContainer::draw")
120  return;
121  }
122 
123  // +++ for future usage need reorder drawing images before text or back
124  for (unsigned i = 0; i < mMaxItems; i++)
125  {
126  const int itemX = (i % mGridWidth) * mBoxWidth;
127  const int itemY = (i / mGridWidth) * mBoxHeight;
128 
129  // Draw item keyboard shortcut.
130  const std::string key = inputManager.getKeyValueString(
132  font->drawString(graphics,
135  key,
136  itemX + mKeyOffsetX,
137  itemY + mKeyOffsetY);
138 
139  const int itemId = selShortcut->getItem(i);
140  const ItemColor itemColor = selShortcut->getItemColor(i);
141 
142  if (itemId < 0)
143  continue;
144 
145  // this is item
146  if (itemId < SPELL_MIN_ID)
147  {
148  const Item *const item = inv->findItem(itemId, itemColor);
149  if (item != nullptr)
150  {
151  // Draw item icon.
152  Image *const image = item->getImage();
153  if (image != nullptr)
154  {
155  std::string caption;
156  if (item->getQuantity() > 1)
157  caption = toString(item->getQuantity());
158  else if (item->isEquipped() == Equipped_true)
159  caption = "Eq.";
160 
161  image->setAlpha(1.0F);
162  graphics->drawImage(image,
163  itemX + mImageOffsetX,
164  itemY + mImageOffsetY);
165  if (item->isEquipped() == Equipped_true)
166  {
167  font->drawString(graphics,
170  caption,
171  itemX + (mBoxWidth - font->getWidth(caption)) / 2,
172  itemY + mBoxHeight - 14);
173  }
174  else
175  {
176  font->drawString(graphics,
179  caption,
180  itemX + (mBoxWidth - font->getWidth(caption)) / 2,
181  itemY + mBoxHeight - 14);
182  }
183  }
184  }
185  }
186  else if (itemId < SKILL_MIN_ID && (spellManager != nullptr))
187  { // this is magic shortcut
188  const TextCommand *const spell = spellManager
189  ->getSpellByItem(itemId);
190  if (spell != nullptr)
191  {
192  if (!spell->isEmpty())
193  {
194  Image *const image = spell->getImage();
195 
196  if (image != nullptr)
197  {
198  image->setAlpha(1.0F);
199  graphics->drawImage(image,
200  itemX + mImageOffsetX,
201  itemY + mImageOffsetY);
202  }
203  }
204 
205  font->drawString(graphics,
208  spell->getSymbol(),
209  itemX + mTextOffsetX,
210  itemY + mTextOffsetY);
211  }
212  }
213  else if (skillDialog != nullptr)
214  {
215  const SkillInfo *const skill = skillDialog->getSkill(
216  itemId - SKILL_MIN_ID);
217  if (skill != nullptr)
218  {
219  Image *const image = skill->data->icon;
220 
221  if (image != nullptr)
222  {
223  image->setAlpha(1.0F);
224  graphics->drawImage(image,
225  itemX + mImageOffsetX,
226  itemY + mImageOffsetY);
227  }
228  if (!skill->data->haveIcon)
229  {
230  font->drawString(graphics,
233  skill->data->shortName,
234  itemX + mTextOffsetX,
235  itemY + mTextOffsetY);
236  }
237  }
238  }
239  }
240  BLOCK_END("ItemShortcutContainer::draw")
241 }
Definition: font.h:90
int getWidth(const std::string &text) const
Definition: font.cpp:334
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:254
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
std::string getKeyValueString(const InputActionT index) const
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:94
Definition: item.h:50
int getQuantity() const
Definition: item.h:105
Equipped isEquipped() const
Definition: item.h:129
Image * getImage() const
Definition: item.h:87
float guiAlpha
Definition: settings.h:131
void drawBackground(Graphics *const g)
SkillInfo * getSkill(const int id) const
const TextCommand * getSpellByItem(const int itemId) const
bool isEmpty() const
Definition: textcommand.h:153
std::string getSymbol() const
Definition: textcommand.h:91
Image * getImage() const
Definition: textcommand.h:156
Color mForegroundColor
Definition: widget.h:1086
Font * getFont() const
Definition: widget.cpp:331
const bool Equipped_true
Definition: equipped.h:30
if(!vert) return
InputManager inputManager
uint16_t ItemColor
Definition: itemcolor.h:30
ItemShortcut * itemShortcut[SHORTCUT_TABS]
bool skill(InputEvent &event)
Definition: commands.cpp:97
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
Inventory * getInventory()
Definition: playerinfo.cpp:195
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
const int SKILL_MIN_ID
Definition: skill.h:25
Settings settings
Definition: settings.cpp:32
SkillDialog * skillDialog
Definition: skilldialog.cpp:66
SpellManager * spellManager
const int SPELL_MIN_ID
Definition: spells.h:27

References BLOCK_END, BLOCK_START, ShortcutContainer::drawBackground(), Graphics::drawImage(), Font::drawString(), Equipped_true, Inventory::findItem(), Widget::getFont(), Item::getImage(), TextCommand::getImage(), PlayerInfo::getInventory(), ItemShortcut::getItem(), ItemShortcut::getItemColor(), InputManager::getKeyValueString(), Item::getQuantity(), SkillDialog::getSkill(), SpellManager::getSpellByItem(), TextCommand::getSymbol(), Font::getWidth(), Settings::guiAlpha, inputManager, TextCommand::isEmpty(), Item::isEquipped(), itemShortcut, ShortcutContainer::mAlpha, ShortcutContainer::mBackgroundImg, ShortcutContainer::mBoxHeight, ShortcutContainer::mBoxWidth, mEquipedColor, mEquipedColor2, Widget::mForegroundColor, ShortcutContainer::mGridWidth, ShortcutContainer::mImageOffsetX, ShortcutContainer::mImageOffsetY, mKeyOffsetX, mKeyOffsetY, ShortcutContainer::mMaxItems, mNumber, ShortcutContainer::mTextOffsetX, ShortcutContainer::mTextOffsetY, mUnEquipedColor, mUnEquipedColor2, settings, InputAction::SHORTCUT_1, Actions::skill(), SKILL_MIN_ID, skillDialog, SPELL_MIN_ID, spellManager, and Catch::toString().

◆ mouseDragged()

void ItemShortcutContainer::mouseDragged ( MouseEvent event)
virtual

Handles mouse when dragged.

Reimplemented from MouseListener.

Definition at line 390 of file itemshortcutcontainer.cpp.

391 {
392  if (mNumber == SHORTCUT_AUTO_TAB)
393  return;
394  ItemShortcut *const selShortcut = itemShortcut[mNumber];
395  if (selShortcut == nullptr)
396  return;
397 
398  if (event.getButton() == MouseButton::LEFT)
399  {
400  if (dragDrop.isEmpty() && mItemClicked)
401  {
402  mItemClicked = false;
403 
404  const int index = getIndexFromGrid(event.getX(), event.getY());
405  if (index == -1)
406  return;
407 
408  const int itemId = selShortcut->getItem(index);
409  const ItemColor itemColor = selShortcut->getItemColor(index);
410 
411  if (itemId < 0)
412  return;
413 
414  event.consume();
415  if (itemId < SPELL_MIN_ID)
416  { // items
417  if (PlayerInfo::getInventory() == nullptr)
418  return;
419 
420  const Item *const item = PlayerInfo::getInventory()->findItem(
421  itemId, itemColor);
422 
423  if (item != nullptr)
424  {
425  selShortcut->removeItem(index);
427  }
428  else
429  {
430  dragDrop.clear();
431  }
432  }
433  else if (itemId < SKILL_MIN_ID)
434  { // spells/commands
435  if (spellManager == nullptr)
436  {
437  dragDrop.clear();
438  return;
439  }
440 
441  const TextCommand *const spell = spellManager->getSpellByItem(
442  itemId);
443  if (spell != nullptr)
444  {
445  selShortcut->removeItem(index);
446  dragDrop.dragCommand(spell,
448  dragDrop.setItem(itemId);
449  }
450  else
451  {
452  dragDrop.clear();
453  }
454  }
455  else
456  { // skills
457  if (skillDialog == nullptr)
458  {
459  dragDrop.clear();
460  return;
461  }
462  const SkillInfo *const skill
463  = skillDialog->getSkillByItem(itemId);
464  if (skill != nullptr)
465  {
466  const std::string itemData = selShortcut->getItemData(
467  index);
468  selShortcut->removeItem(index);
471  index);
472  dragDrop.setItem(itemId);
473  dragDrop.setItemColor(itemColor);
474  dragDrop.setItemData(itemData);
475  }
476  else
477  {
478  dragDrop.clear();
479  }
480  }
481  }
482  }
483 }
void dragItem(const Item *const item, const DragDropSourceT source, const int tag)
Definition: dragdrop.h:87
void setItem(const int item)
Definition: dragdrop.h:238
void dragCommand(const TextCommand *const command, const DragDropSourceT source, const int tag)
Definition: dragdrop.h:117
void dragSkill(const SkillInfo *const info, const DragDropSourceT source, const int tag)
Definition: dragdrop.h:152
void setItemColor(const ItemColor color)
Definition: dragdrop.h:72
bool isEmpty() const
Definition: dragdrop.h:196
void clear()
Definition: dragdrop.h:183
void setItemData(const std::string &data)
Definition: dragdrop.h:78
ItemColor getItemColor(const size_t index) const
Definition: itemshortcut.h:73
int getItem(const size_t index) const
Definition: itemshortcut.h:70
void removeItem(const size_t index)
Definition: itemshortcut.h:146
std::string getItemData(const size_t index) const
Definition: itemshortcut.h:80
MouseButtonT getButton() const
Definition: mouseevent.h:116
int getX() const
Definition: mouseevent.h:127
int getY() const
Definition: mouseevent.h:138
int getIndexFromGrid(const int pointX, const int pointY) const
SkillInfo * getSkillByItem(const int itemId) const
const size_t SHORTCUT_AUTO_TAB
Definition: itemshortcut.h:29
DragDrop dragDrop

References DragDrop::clear(), DragDrop::dragCommand(), dragDrop, DragDrop::dragItem(), DragDrop::dragSkill(), Inventory::findItem(), MouseEvent::getButton(), ShortcutContainer::getIndexFromGrid(), PlayerInfo::getInventory(), ItemShortcut::getItem(), ItemShortcut::getItemColor(), ItemShortcut::getItemData(), SkillDialog::getSkillByItem(), SpellManager::getSpellByItem(), MouseEvent::getX(), MouseEvent::getY(), DragDrop::isEmpty(), itemShortcut, MouseButton::LEFT, mItemClicked, mNumber, ItemShortcut::removeItem(), DragDrop::setItem(), DragDrop::setItemColor(), DragDrop::setItemData(), SHORTCUT_AUTO_TAB, DragDropSource::Shortcuts, Actions::skill(), SKILL_MIN_ID, skillDialog, SPELL_MIN_ID, and spellManager.

◆ mouseExited()

void ItemShortcutContainer::mouseExited ( MouseEvent event)
virtual

Called when the mouse has exited the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 662 of file itemshortcutcontainer.cpp.

663 {
664  if (itemPopup != nullptr)
666  if (spellPopup != nullptr)
668  if (skillPopup != nullptr)
670 }
void setVisible(Visible visible)
Definition: widget.cpp:225
ItemPopup * itemPopup
Definition: itempopup.cpp:64
SkillPopup * skillPopup
Definition: skillpopup.cpp:42
SpellPopup * spellPopup
Definition: spellpopup.cpp:34
const bool Visible_false
Definition: visible.h:30

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

◆ mouseMoved()

void ItemShortcutContainer::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 573 of file itemshortcutcontainer.cpp.

574 {
575  const ItemShortcut *const selShortcut = itemShortcut[mNumber];
576  if (selShortcut == nullptr)
577  return;
578 
579  const int index = getIndexFromGrid(event.getX(), event.getY());
580 
581  if (index == -1)
582  return;
583 
584  const int itemId = selShortcut->getItem(index);
585  const ItemColor itemColor = selShortcut->getItemColor(index);
586 
587  if (itemId < 0)
588  return;
589 
590  if (itemId < SPELL_MIN_ID)
591  {
594 
595  Inventory *const inv = PlayerInfo::getInventory();
596  if (inv == nullptr)
597  return;
598 
599  const Item *const item = inv->findItem(itemId, itemColor);
600  if ((item != nullptr) && (viewport != nullptr))
601  {
602  itemPopup->setItem(item, false);
604  }
605  else
606  {
608  }
609  }
610  else if (itemId < SKILL_MIN_ID && (spellManager != nullptr))
611  {
614  const TextCommand *const spell = spellManager->getSpellByItem(itemId);
615  if ((spell != nullptr) && (viewport != nullptr))
616  {
617  spellPopup->setItem(spell);
619  viewport->mMouseY);
620  }
621  else
622  {
624  }
625  }
626  else if (skillDialog != nullptr)
627  {
630  const SkillInfo *const skill = skillDialog->getSkillByItem(itemId);
631  if (skill == nullptr)
632  return;
633 
634  const std::string data = selShortcut->getItemData(index);
635  CastTypeT castType = CastType::Default;
636  int offsetX = 0;
637  int offsetY = 0;
638  if (!data.empty())
639  {
640  STD_VECTOR<int> vect;
641  splitToIntVector(vect, data, ' ');
642  const size_t sz = vect.size();
643  if (sz > 0)
644  castType = static_cast<CastTypeT>(vect[0]);
645  if (sz > 2)
646  {
647  offsetX = vect[1];
648  offsetY = vect[2];
649  }
650  }
652  toInt(itemColor, int),
653  castType,
654  offsetX,
655  offsetY);
657  viewport->mMouseY);
658  }
659 }
CastType ::T CastTypeT
Definition: casttype.h:34
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
void show(const SkillInfo *const skill, const int level, const CastTypeT type, const int offsetX, const int offsetY)
Definition: skillpopup.cpp:106
void view(const int x, const int y)
Definition: spellpopup.cpp:91
void setItem(const TextCommand *const spell)
Definition: spellpopup.cpp:63
int mMouseX
Definition: viewport.h:154
int mMouseY
Definition: viewport.h:155
Viewport * viewport
Definition: viewport.cpp:36
#define toInt(val, name)
Definition: intdefines.h:47
uint32_t data
@ Default
Definition: casttype.h:29
void splitToIntVector(std::vector< int > &tokens, const std::string &text, const char separator)

References data, CastType::Default, Inventory::findItem(), ShortcutContainer::getIndexFromGrid(), PlayerInfo::getInventory(), ItemShortcut::getItem(), ItemShortcut::getItemColor(), ItemShortcut::getItemData(), SkillDialog::getSkillByItem(), SpellManager::getSpellByItem(), MouseEvent::getX(), MouseEvent::getY(), itemPopup, itemShortcut, Viewport::mMouseX, Viewport::mMouseY, mNumber, Popup::position(), ItemPopup::setItem(), SpellPopup::setItem(), Widget::setVisible(), SkillPopup::show(), Actions::skill(), SKILL_MIN_ID, skillDialog, skillPopup, SPELL_MIN_ID, spellManager, spellPopup, splitToIntVector(), toInt, SpellPopup::view(), viewport, and Visible_false.

◆ mousePressed()

void ItemShortcutContainer::mousePressed ( MouseEvent event)
virtual

Handles mouse when pressed.

Reimplemented from MouseListener.

Definition at line 485 of file itemshortcutcontainer.cpp.

486 {
487  ItemShortcut *const selShortcut = itemShortcut[mNumber];
488  if (selShortcut == nullptr)
489  return;
490 
491  const int index = getIndexFromGrid(event.getX(), event.getY());
492 
493  if (index == -1)
494  return;
495 
496  if (event.getButton() == MouseButton::LEFT)
497  {
498  event.consume();
499  // Stores the selected item if theirs one.
500  if (selShortcut->isItemSelected() && (inventoryWindow != nullptr) &&
502  || selShortcut->getSelectedItem() >= SPELL_MIN_ID))
503  {
504  selShortcut->setItem(index);
505  selShortcut->setItemSelected(-1);
506  if (spellShortcut != nullptr)
509  }
510  else if (selShortcut->getItem(index) != 0)
511  {
512  mItemClicked = true;
513  }
514  }
515  else if (event.getButton() == MouseButton::RIGHT)
516  {
517  event.consume();
518  if (popupMenu != nullptr &&
519  viewport != nullptr)
520  {
522  viewport->mMouseY,
523  selShortcut->getItem(index),
524  selShortcut->getItemColor(index));
525  }
526  }
527 }
int getSelectedItem() const
Definition: itemshortcut.h:134
void setItemSelected(const int itemId)
Definition: itemshortcut.h:126
bool isItemSelected() const
Definition: itemshortcut.h:140
void setItem(const size_t index)
void showItemPopup(const int x, const int y, const Item *const item)
Definition: popupmenu.cpp:1790
void setItemSelected(const int itemId)
Definition: spellshortcut.h:58
bool isWindowVisible() const
Definition: window.h:484
InventoryWindow * inventoryWindow
PopupMenu * popupMenu
Definition: popupmenu.cpp:103
SpellShortcut * spellShortcut

References MouseEvent::getButton(), ShortcutContainer::getIndexFromGrid(), ItemShortcut::getItem(), ItemShortcut::getItemColor(), ItemShortcut::getSelectedItem(), MouseEvent::getX(), MouseEvent::getY(), inventoryWindow, ItemShortcut::isItemSelected(), Window::isWindowVisible(), itemShortcut, MouseButton::LEFT, mItemClicked, Viewport::mMouseX, Viewport::mMouseY, mNumber, popupMenu, MouseButton::RIGHT, ItemShortcut::setItem(), ItemShortcut::setItemSelected(), SpellShortcut::setItemSelected(), PopupMenu::showItemPopup(), SPELL_MIN_ID, spellShortcut, InventoryWindow::unselectItem(), and viewport.

◆ mouseReleased()

void ItemShortcutContainer::mouseReleased ( MouseEvent event)
virtual

Handles mouse release.

Reimplemented from MouseListener.

Definition at line 529 of file itemshortcutcontainer.cpp.

530 {
531  ItemShortcut *const selShortcut = itemShortcut[mNumber];
532  if (selShortcut == nullptr)
533  return;
534 
535  if (event.getButton() == MouseButton::LEFT)
536  {
537  if (selShortcut->isItemSelected())
538  selShortcut->setItemSelected(-1);
539 
540  const int index = getIndexFromGrid(event.getX(), event.getY());
541  if (index == -1)
542  return;
543 
544  if (dragDrop.isEmpty())
545  {
546  if ((selShortcut->getItem(index) != 0) && mItemClicked)
547  selShortcut->useItem(index);
548  }
549  else
550  {
552  {
553  const int oldIndex = dragDrop.getTag();
554  selShortcut->setItem(oldIndex, dragDrop.getItem(),
556  selShortcut->swap(oldIndex, index);
557  }
558  else
559  {
560  selShortcut->setItemData(index,
562  selShortcut->setItem(index, dragDrop.getItem(),
564  }
565  dragDrop.clear();
566  dragDrop.deselect();
567  }
568 
569  mItemClicked = false;
570  }
571 }
DragDropSourceT getSource() const
Definition: dragdrop.h:84
void deselect()
Definition: dragdrop.h:213
std::string getItemData()
Definition: dragdrop.h:81
int getTag() const
Definition: dragdrop.h:235
int getItem() const
Definition: dragdrop.h:66
ItemColor getItemColor() const
Definition: dragdrop.h:69
void setItemData(const size_t index, const std::string &data)
Definition: itemshortcut.h:76
void swap(const size_t index1, const size_t index2)
void useItem(const size_t index) const

References DragDrop::clear(), DragDrop::deselect(), dragDrop, MouseEvent::getButton(), ShortcutContainer::getIndexFromGrid(), DragDrop::getItem(), ItemShortcut::getItem(), DragDrop::getItemColor(), DragDrop::getItemData(), DragDrop::getSource(), DragDrop::getTag(), MouseEvent::getX(), MouseEvent::getY(), DragDrop::isEmpty(), ItemShortcut::isItemSelected(), itemShortcut, MouseButton::LEFT, mItemClicked, mNumber, ItemShortcut::setItem(), ItemShortcut::setItemData(), ItemShortcut::setItemSelected(), DragDropSource::Shortcuts, ItemShortcut::swap(), and ItemShortcut::useItem().

◆ safeDraw()

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

Implements Widget.

Definition at line 243 of file itemshortcutcontainer.cpp.

244 {
245  BLOCK_START("ItemShortcutContainer::draw")
246  const ItemShortcut *const selShortcut = itemShortcut[mNumber];
247  if (selShortcut == nullptr)
248  {
249  BLOCK_END("ItemShortcutContainer::draw")
250  return;
251  }
252 
253  if (settings.guiAlpha != mAlpha)
254  {
255  if (mBackgroundImg != nullptr)
256  mBackgroundImg->setAlpha(mAlpha);
258  }
259 
260  Font *const font = getFont();
261  safeDrawBackground(graphics);
262 
263  const Inventory *const inv = PlayerInfo::getInventory();
264  if (inv == nullptr)
265  {
266  BLOCK_END("ItemShortcutContainer::draw")
267  return;
268  }
269 
270  // +++ for future usage need reorder drawing images before text or back
271  for (unsigned i = 0; i < mMaxItems; i++)
272  {
273  const int itemX = (i % mGridWidth) * mBoxWidth;
274  const int itemY = (i / mGridWidth) * mBoxHeight;
275 
276  // Draw item keyboard shortcut.
277  const std::string key = inputManager.getKeyValueString(
279  font->drawString(graphics,
282  key,
283  itemX + mKeyOffsetX,
284  itemY + mKeyOffsetY);
285 
286  const int itemId = selShortcut->getItem(i);
287  const ItemColor itemColor = selShortcut->getItemColor(i);
288 
289  if (itemId < 0)
290  continue;
291 
292  // this is item
293  if (itemId < SPELL_MIN_ID)
294  {
295  const Item *const item = inv->findItem(itemId, itemColor);
296  if (item != nullptr)
297  {
298  // Draw item icon.
299  Image *const image = item->getImage();
300  if (image != nullptr)
301  {
302  std::string caption;
303  if (item->getQuantity() > 1)
304  caption = toString(item->getQuantity());
305  else if (item->isEquipped() == Equipped_true)
306  caption = "Eq.";
307 
308  image->setAlpha(1.0F);
309  graphics->drawImage(image,
310  itemX + mImageOffsetX,
311  itemY + mImageOffsetY);
312  if (item->isEquipped() == Equipped_true)
313  {
314  font->drawString(graphics,
317  caption,
318  itemX + (mBoxWidth - font->getWidth(caption)) / 2,
319  itemY + mBoxHeight - 14);
320  }
321  else
322  {
323  font->drawString(graphics,
326  caption,
327  itemX + (mBoxWidth - font->getWidth(caption)) / 2,
328  itemY + mBoxHeight - 14);
329  }
330  }
331  }
332  }
333  else if (itemId < SKILL_MIN_ID && (spellManager != nullptr))
334  { // this is magic shortcut
335  const TextCommand *const spell = spellManager
336  ->getSpellByItem(itemId);
337  if (spell != nullptr)
338  {
339  if (!spell->isEmpty())
340  {
341  Image *const image = spell->getImage();
342 
343  if (image != nullptr)
344  {
345  image->setAlpha(1.0F);
346  graphics->drawImage(image,
347  itemX + mImageOffsetX,
348  itemY + mImageOffsetY);
349  }
350  }
351 
352  font->drawString(graphics,
355  spell->getSymbol(),
356  itemX + mTextOffsetX,
357  itemY + mTextOffsetY);
358  }
359  }
360  else if (skillDialog != nullptr)
361  {
362  const SkillInfo *const skill = skillDialog->getSkill(
363  itemId - SKILL_MIN_ID);
364  if (skill != nullptr)
365  {
366  Image *const image = skill->data->icon;
367 
368  if (image != nullptr)
369  {
370  image->setAlpha(1.0F);
371  graphics->drawImage(image,
372  itemX + mImageOffsetX,
373  itemY + mImageOffsetY);
374  }
375  if (!skill->data->haveIcon)
376  {
377  font->drawString(graphics,
380  skill->data->shortName,
381  itemX + mTextOffsetX,
382  itemY + mTextOffsetY);
383  }
384  }
385  }
386  }
387  BLOCK_END("ItemShortcutContainer::draw")
388 }
void safeDrawBackground(Graphics *const g)

References BLOCK_END, BLOCK_START, Graphics::drawImage(), Font::drawString(), Equipped_true, Inventory::findItem(), Widget::getFont(), Item::getImage(), TextCommand::getImage(), PlayerInfo::getInventory(), ItemShortcut::getItem(), ItemShortcut::getItemColor(), InputManager::getKeyValueString(), Item::getQuantity(), SkillDialog::getSkill(), SpellManager::getSpellByItem(), TextCommand::getSymbol(), Font::getWidth(), Settings::guiAlpha, inputManager, TextCommand::isEmpty(), Item::isEquipped(), itemShortcut, ShortcutContainer::mAlpha, ShortcutContainer::mBackgroundImg, ShortcutContainer::mBoxHeight, ShortcutContainer::mBoxWidth, mEquipedColor, mEquipedColor2, Widget::mForegroundColor, ShortcutContainer::mGridWidth, ShortcutContainer::mImageOffsetX, ShortcutContainer::mImageOffsetY, mKeyOffsetX, mKeyOffsetY, ShortcutContainer::mMaxItems, mNumber, ShortcutContainer::mTextOffsetX, ShortcutContainer::mTextOffsetY, mUnEquipedColor, mUnEquipedColor2, ShortcutContainer::safeDrawBackground(), settings, InputAction::SHORTCUT_1, Actions::skill(), SKILL_MIN_ID, skillDialog, SPELL_MIN_ID, spellManager, and Catch::toString().

◆ setSkin()

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

Reimplemented from ShortcutContainer.

Definition at line 78 of file itemshortcutcontainer.cpp.

80 {
81  ShortcutContainer::setSkin(widget, skin);
82  mEquipedColor = getThemeColor(ThemeColorId::ITEM_EQUIPPED, 255U);
83  mEquipedColor2 = getThemeColor(ThemeColorId::ITEM_EQUIPPED_OUTLINE, 255U);
84  mUnEquipedColor = getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED, 255U);
85  mUnEquipedColor2 = getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED_OUTLINE,
86  255U);
88  mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE, 255U);
89  if (mSkin != nullptr)
90  {
91  mKeyOffsetX = mSkin->getOption("keyOffsetX", 2);
92  mKeyOffsetY = mSkin->getOption("keyOffsetY", 2);
93  }
94 }
virtual void setSkin(const Widget2 *const widget, Skin *const skin)
int getOption(const std::string &name) const
Definition: skin.h:106
Color mForegroundColor2
Definition: widget2.h:113

References Skin::getOption(), Widget2::getThemeColor(), mEquipedColor, mEquipedColor2, Widget::mForegroundColor, Widget2::mForegroundColor2, mKeyOffsetX, mKeyOffsetY, ShortcutContainer::mSkin, mUnEquipedColor, mUnEquipedColor2, ShortcutContainer::setSkin(), and QuestType::TEXT.

◆ widgetHidden()

void ItemShortcutContainer::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 672 of file itemshortcutcontainer.cpp.

673 {
674  if (itemPopup != nullptr)
676  if (spellPopup != nullptr)
678 }

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

Field Documentation

◆ mEquipedColor

Color ItemShortcutContainer::mEquipedColor
private

Definition at line 82 of file itemshortcutcontainer.h.

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

◆ mEquipedColor2

Color ItemShortcutContainer::mEquipedColor2
private

Definition at line 83 of file itemshortcutcontainer.h.

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

◆ mItemClicked

bool ItemShortcutContainer::mItemClicked
private

Definition at line 89 of file itemshortcutcontainer.h.

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

◆ mKeyOffsetX

int ItemShortcutContainer::mKeyOffsetX
private

Definition at line 87 of file itemshortcutcontainer.h.

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

◆ mKeyOffsetY

int ItemShortcutContainer::mKeyOffsetY
private

Definition at line 88 of file itemshortcutcontainer.h.

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

◆ mNumber

unsigned ItemShortcutContainer::mNumber
private

◆ mUnEquipedColor

Color ItemShortcutContainer::mUnEquipedColor
private

Definition at line 84 of file itemshortcutcontainer.h.

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

◆ mUnEquipedColor2

Color ItemShortcutContainer::mUnEquipedColor2
private

Definition at line 85 of file itemshortcutcontainer.h.

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


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