ManaPlus
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
ItemPopup Class Reference

#include <itempopup.h>

Inheritance diagram for ItemPopup:
Popup Container MouseListener WidgetListener BasicContainer2 BasicContainer Widget WidgetDeathListener Widget2

Public Member Functions

 ItemPopup ()
 
 ~ItemPopup ()
 
void postInit ()
 
void setItem (const ItemInfo &item, const ItemColor color, const bool showImage, int id, const int *const cards, const ItemOptionsList *const options)
 
void setItem (const Item *const item, const bool showImage)
 
void mouseMoved (MouseEvent &event)
 
void resetPopup ()
 
- Public Member Functions inherited from Popup
 Popup (const std::string &name, std::string skin)
 
 ~Popup ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void setContentSize (int width, int height)
 
void setLocationRelativeTo (const Widget *const widget)
 
void mouseMoved (MouseEvent &event)
 
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
 
int getPadding () const
 
void setPadding (int padding)
 
void setPopupName (const std::string &name)
 
const std::string & getPopupName () const
 
void scheduleDelete ()
 
Rect getChildrenArea ()
 
void position (const int x, const int y)
 
void hide ()
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
bool isPopupVisible () const
 
void postInit ()
 
- Public Member Functions inherited from Container
 Container (const Widget2 *const widget)
 
 ~Container ()
 
bool safeRemove (Widget *const widget)
 
void removeControls ()
 
- 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 mouseEntered (MouseEvent &event)
 
virtual void mouseExited (MouseEvent &event)
 
virtual void mousePressed (MouseEvent &event)
 
virtual void mouseReleased (MouseEvent &event)
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
virtual void mouseDragged (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetHidden (const Event &event)
 
virtual void widgetShown (const Event &event)
 

Private Member Functions

std::string getCardsString (const int *const cards)
 
void setLabelColor (Label *label, const ItemDbTypeT type) const
 

Static Private Member Functions

static std::string getOptionsString (const ItemOptionsList *const options)
 

Private Attributes

LabelmItemName
 
TextBoxmItemDesc
 
TextBoxmItemEffect
 
TextBoxmItemWeight
 
TextBoxmItemCards
 
TextBoxmItemOptions
 
ItemDbTypeT mItemType
 
IconmIcon
 
std::string mLastName
 
std::string mCardsStr
 
std::string mItemOptionsStr
 
int mLastId
 
ItemColor mLastColor
 

Additional Inherited Members

- Static Public Member Functions inherited from Popup
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)
 
- 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 BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Attributes inherited from Popup
int mPadding
 
SkinmSkin
 
- 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

A popup that displays information about an item.

Definition at line 45 of file itempopup.h.

Constructor & Destructor Documentation

◆ ItemPopup()

ItemPopup::ItemPopup ( )

Constructor. Initializes the item popup.

Definition at line 66 of file itempopup.cpp.

66  :
67  Popup("ItemPopup", "itempopup.xml"),
68  mItemName(new Label(this)),
69  mItemDesc(new TextBox(this)),
70  mItemEffect(new TextBox(this)),
71  mItemWeight(new TextBox(this)),
72  mItemCards(new TextBox(this)),
73  mItemOptions(new TextBox(this)),
75  mIcon(new Icon(this, nullptr, AutoRelease_false)),
76  mLastName(),
77  mCardsStr(),
79  mLastId(0),
81 {
82  // Item name
84  mItemName->setPosition(0, 0);
85 
86  const int fontHeight = getFont()->getHeight();
87 
88  // Item description
89  mItemDesc->setEditable(false);
90  mItemDesc->setPosition(0, fontHeight);
92  getThemeColor(ThemeColorId::POPUP, 255U),
93  getThemeColor(ThemeColorId::POPUP_OUTLINE, 255U));
94 
95  // Item effect
96  mItemEffect->setEditable(false);
97  mItemEffect->setPosition(0, 2 * fontHeight);
99  getThemeColor(ThemeColorId::POPUP, 255U),
100  getThemeColor(ThemeColorId::POPUP_OUTLINE, 255U));
101 
102  // Item weight
103  mItemWeight->setEditable(false);
104  mItemWeight->setPosition(0, 3 * fontHeight);
106  getThemeColor(ThemeColorId::POPUP, 255U),
107  getThemeColor(ThemeColorId::POPUP_OUTLINE, 255U));
108 
109  // Item cards
110  mItemCards->setEditable(false);
111  mItemCards->setPosition(0, 4 * fontHeight);
113  getThemeColor(ThemeColorId::POPUP, 255U),
114  getThemeColor(ThemeColorId::POPUP_OUTLINE, 255U));
115 
116  // Item options
117  mItemOptions->setEditable(false);
118  mItemOptions->setPosition(0, 5 * fontHeight);
120  getThemeColor(ThemeColorId::POPUP, 255U),
121  getThemeColor(ThemeColorId::POPUP_OUTLINE, 255U));
122 }
const bool AutoRelease_false
Definition: autorelease.h:30
int getHeight() const
Definition: font.cpp:362
Definition: icon.h:41
Icon * mIcon
Definition: itempopup.h:92
std::string mLastName
Definition: itempopup.h:93
TextBox * mItemCards
Definition: itempopup.h:89
Label * mItemName
Definition: itempopup.h:85
ItemDbTypeT mItemType
Definition: itempopup.h:91
TextBox * mItemDesc
Definition: itempopup.h:86
ItemColor mLastColor
Definition: itempopup.h:97
int mLastId
Definition: itempopup.h:96
TextBox * mItemWeight
Definition: itempopup.h:88
std::string mCardsStr
Definition: itempopup.h:94
std::string mItemOptionsStr
Definition: itempopup.h:95
TextBox * mItemEffect
Definition: itempopup.h:87
TextBox * mItemOptions
Definition: itempopup.h:90
Definition: label.h:91
Popup(const std::string &name, std::string skin)
Definition: popup.cpp:40
void setEditable(const bool editable)
Definition: textbox.cpp:650
void setForegroundColorAll(const Color &color1, const Color &color2)
Definition: textbox.cpp:488
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45
void setFont(Font *const font)
Definition: widget.cpp:349
Font * getFont() const
Definition: widget.cpp:331
void setPosition(const int x, const int y)
Definition: widget.cpp:161
Font * boldFont
Definition: gui.cpp:112
const ItemColor ItemColor_one
Definition: itemcolor.h:30

References boldFont, Widget::getFont(), Font::getHeight(), Widget2::getThemeColor(), mItemCards, mItemDesc, mItemEffect, mItemName, mItemOptions, mItemWeight, TextBox::setEditable(), Widget::setFont(), TextBox::setForegroundColorAll(), and Widget::setPosition().

◆ ~ItemPopup()

ItemPopup::~ItemPopup ( )

Destructor. Cleans up the item popup on deletion.

Definition at line 138 of file itempopup.cpp.

139 {
140  if (mIcon != nullptr)
141  {
142  Image *const image = mIcon->getImage();
143  if (image != nullptr)
144  image->decRef();
145  }
146 }
Image * getImage() const
Definition: icon.h:64

References Icon::getImage(), and mIcon.

Member Function Documentation

◆ getCardsString()

std::string ItemPopup::getCardsString ( const int *const  cards)
private

Definition at line 330 of file itempopup.cpp.

331 {
332  if (cards == nullptr)
333  return std::string();
334 
335  std::string label;
336 
337  switch (cards[0])
338  {
339  case CARD0_CREATE: // named item
340  {
341  const int32_t charId = cards[2] + 65536 * cards[3];
342  std::string name = actorManager->findCharById(charId);
343  if (name.empty())
344  {
345  name = toString(charId);
347  mLastId = 0; // allow recreate popup with same data
348  }
349  // TRANSLATORS: named item description
350  label.append(strprintf(_("Item named: %s"), name.c_str()));
351  return label;
352  }
353  case CARD0_FORGE: // forged item
354  case CARD0_PET:
355  {
356  return label;
357  }
358  default:
359  {
360  for (int f = 0; f < maxCards; f ++)
361  {
362  const int id = cards[f];
363  if (id != 0)
364  {
365  if (!label.empty())
366  label.append(" / ");
367  const ItemInfo &info = ItemDB::get(id);
368  label.append(info.getName());
369  }
370  }
371  if (label.empty())
372  return label;
373  // TRANSLATORS: popup label
374  return _("Cards: ") + label;
375  }
376  }
377 }
ActorManager * actorManager
Net::BeingHandler * beingHandler
Definition: net.cpp:99
#define CARD0_CREATE
Definition: cards.h:29
#define maxCards
Definition: cards.h:25
#define CARD0_PET
Definition: cards.h:30
#define CARD0_FORGE
Definition: cards.h:28
std::string findCharById(const int32_t id)
virtual void requestNameByCharId(const int id) const =0
#define _(s)
Definition: gettext.h:35
bool info(InputEvent &event)
Definition: commands.cpp:57
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
const ItemInfo & get(const int id)
Definition: itemdb.cpp:792
std::string strprintf(const char *const format,...)

References _, actorManager, beingHandler, CARD0_CREATE, CARD0_FORGE, CARD0_PET, ActorManager::findCharById(), ItemDB::get(), Actions::info(), maxCards, mLastId, Net::BeingHandler::requestNameByCharId(), strprintf(), and Catch::toString().

Referenced by setItem().

◆ getOptionsString()

std::string ItemPopup::getOptionsString ( const ItemOptionsList *const  options)
staticprivate

Definition at line 379 of file itempopup.cpp.

380 {
381  if (options == nullptr || translator == nullptr)
382  return std::string();
383  const size_t sz = options->size();
384  std::string effect;
385  for (size_t f = 0; f < sz; f ++)
386  {
387  const ItemOption &option = options->get(f);
388  if (option.index == 0)
389  continue;
390  const STD_VECTOR<ItemFieldType*> &fields = ItemOptionDb::getFields(
391  option.index);
392  if (fields.empty())
393  continue;
394  const std::string valueStr = toString(option.value);
395  FOR_EACH (STD_VECTOR<ItemFieldType*>::const_iterator, it, fields)
396  {
397  const ItemFieldType *const field = *it;
398  std::string value = valueStr;
399  if (!effect.empty())
400  effect.append(" / ");
401  if (field->sign && value[0] != '-')
402  value = std::string("+").append(value);
403  const std::string format = translator->getStr(field->description);
404  effect.append(strprintf(format.c_str(),
405  value.c_str()));
406  }
407  }
408  if (effect.empty())
409  return effect;
410  // TRANSLATORS: popup label
411  return _("Options: ") + effect;
412 }
const std::string getStr(const std::string &str)
Definition: podict.cpp:45
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
const std::vector< ItemFieldType * > & getFields(const int id)
PoDict * translator
Definition: podict.cpp:28
const bool sign
Definition: itemfieldtype.h:43
const std::string description
Definition: itemfieldtype.h:42
uint16_t index
Definition: itemoption.h:36
int16_t value
Definition: itemoption.h:37
const ItemOption & get(const size_t index) const
size_t size() const

References _, ItemFieldType::description, FOR_EACH, ItemOptionsList::get(), ItemOptionDb::getFields(), PoDict::getStr(), ItemOption::index, ItemFieldType::sign, ItemOptionsList::size(), strprintf(), Catch::toString(), translator, and ItemOption::value.

Referenced by setItem().

◆ mouseMoved()

void ItemPopup::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 455 of file itempopup.cpp.

456 {
457  Popup::mouseMoved(event);
458 
459  // When the mouse moved on top of the popup, hide it
461  resetPopup();
462 }
void resetPopup()
Definition: itempopup.cpp:464
void mouseMoved(MouseEvent &event)
Definition: popup.cpp:255
void setVisible(Visible visible)
Definition: widget.cpp:225
const bool Visible_false
Definition: visible.h:30

References Popup::mouseMoved(), resetPopup(), Widget::setVisible(), and Visible_false.

◆ postInit()

void ItemPopup::postInit ( )
virtual

Reimplemented from Widget.

Definition at line 124 of file itempopup.cpp.

125 {
126  Popup::postInit();
127  add(mItemName);
128  add(mItemDesc);
129  add(mItemEffect);
130  add(mItemWeight);
131  add(mItemCards);
132  add(mItemOptions);
133  add(mIcon);
134 
135  addMouseListener(this);
136 }
virtual void add(Widget *const widget)
void postInit()
Definition: popup.h:177
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:292

References BasicContainer2::add(), Widget::addMouseListener(), mIcon, mItemCards, mItemDesc, mItemEffect, mItemName, mItemOptions, mItemWeight, and Popup::postInit().

◆ resetPopup()

void ItemPopup::resetPopup ( )

Definition at line 464 of file itempopup.cpp.

465 {
466  mLastName.clear();
468  mLastId = 0;
469 }

References ItemColor_one, mLastColor, mLastId, and mLastName.

Referenced by mouseMoved(), and EAthena::InventoryRecv::processPlayerInsertCard().

◆ setItem() [1/2]

void ItemPopup::setItem ( const Item *const  item,
const bool  showImage 
)

Definition at line 148 of file itempopup.cpp.

150 {
151  if (item == nullptr)
152  return;
153 
154  const ItemInfo &ii = item->getInfo();
155  setItem(ii,
156  item->getColor(),
157  showImage,
158  item->getId(),
159  item->getCards(),
160  item->getOptions());
161  if (item->getRefine() > 0)
162  {
163  mLastName = ii.getName();
164  mLastColor = item->getColor();
165  mLastId = item->getId();
166 #ifdef TMWA_SUPPORT
168  {
169  mItemName->setCaption(strprintf("%s (+%u), %d",
170  ii.getName().c_str(),
171  CAST_U32(item->getRefine()),
172  ii.getId()));
173  }
174  else
175 #endif // TMWA_SUPPORT
176  {
177  mItemName->setCaption(strprintf("%s (+%u), %d",
178  ii.getName(item->getColor()).c_str(),
179  CAST_U32(item->getRefine()),
180  ii.getId()));
181  }
183  const unsigned minWidth = mItemName->getWidth() + 8;
184  if (CAST_U32(getWidth()) < minWidth)
185  setWidth(minWidth);
186  }
187 }
#define CAST_U32
Definition: cast.h:31
int getId() const
Definition: iteminfo.h:68
const std::string & getName() const
Definition: iteminfo.h:74
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
uint8_t getRefine() const
Definition: item.h:141
const ItemOptionsList * getOptions() const
Definition: item.h:219
int getId() const
Definition: item.h:81
ItemColor getColor() const
Definition: item.h:181
const int * getCards() const
Definition: item.h:214
const ItemInfo & getInfo() const
Definition: item.h:171
void adjustSize()
Definition: label.cpp:200
void setCaption(const std::string &caption)
Definition: label.cpp:264
void setWidth(const int width)
Definition: widget.cpp:133
int getWidth() const
Definition: widget.h:221
ServerTypeT getNetworkType()
Definition: net.cpp:189

References Label::adjustSize(), CAST_U32, Item::getCards(), Item::getColor(), Item::getId(), ItemInfo::getId(), Item::getInfo(), ItemInfo::getName(), Net::getNetworkType(), Item::getOptions(), Item::getRefine(), Widget::getWidth(), mItemName, mLastColor, mLastId, mLastName, Label::setCaption(), setItem(), Widget::setWidth(), strprintf(), and ServerType::TMWATHENA.

◆ setItem() [2/2]

void ItemPopup::setItem ( const ItemInfo item,
const ItemColor  color,
const bool  showImage,
int  id,
const int *const  cards,
const ItemOptionsList *const  options 
)

Sets the info to be displayed given a particular item.

Definition at line 189 of file itempopup.cpp.

195 {
196  if (mIcon == nullptr)
197  return;
198 
199  std::string cardsStr;
200  std::string optionsStr;
201 
202  if (item.getName() == mLastName &&
203  color == mLastColor &&
204  id == mLastId)
205  {
206  cardsStr = getCardsString(cards);
207  optionsStr = getOptionsString(options);
208  if (mItemOptionsStr == optionsStr &&
209  mCardsStr == cardsStr)
210  {
211  return;
212  }
213  }
214  else
215  {
216  cardsStr = getCardsString(cards);
217  optionsStr = getOptionsString(options);
218  }
219  mItemOptionsStr = STD_MOVE(optionsStr);
220  mCardsStr = STD_MOVE(cardsStr);
221 
222  if (id == -1)
223  id = item.getId();
224 
225  int space = 0;
226 
227  Image *const oldImage = mIcon->getImage();
228  if (oldImage != nullptr)
229  oldImage->decRef();
230 
231  if (showImage)
232  {
233  Image *const image = Loader::getImage(combineDye2(
234  pathJoin(paths.getStringValue("itemIcons"),
235  item.getDisplay().image),
236  item.getDyeIconColorsString(color)));
237 
238  mIcon->setImage(image);
239  if (image != nullptr)
240  {
241  mIcon->setPosition(0, 0);
242  space = mIcon->getWidth();
243  }
244  }
245  else
246  {
247  mIcon->setImage(nullptr);
248  }
249 
250  mItemType = item.getType();
251 
252  mLastName = item.getName();
253  mLastColor = color;
254  mLastId = id;
255 
256 #ifdef TMWA_SUPPORT
258  {
259  mItemName->setCaption(strprintf("%s, %d",
260  item.getName().c_str(), id));
262  }
263  else
264 #endif // TMWA_SUPPORT
265  {
266  mItemName->setCaption(strprintf("%s, %d",
267  item.getName(color).c_str(), id));
268  mItemDesc->setTextWrapped(item.getDescription(color), 196);
269  }
270 
273  mItemName->setPosition(space, 0);
274 
275  mItemEffect->setTextWrapped(item.getEffect(), 196);
276  // TRANSLATORS: popup label
277  mItemWeight->setTextWrapped(strprintf(_("Weight: %s"),
278  UnitsDb::formatWeight(item.getWeight()).c_str()), 196);
281 
282  int minWidth = mItemName->getWidth() + space;
283 
284  if (mItemName->getWidth() + space > minWidth)
285  minWidth = mItemName->getWidth() + space;
286  if (mItemDesc->getMinWidth() > minWidth)
287  minWidth = mItemDesc->getMinWidth();
288  if (mItemEffect->getMinWidth() > minWidth)
289  minWidth = mItemEffect->getMinWidth();
290  if (mItemWeight->getMinWidth() > minWidth)
291  minWidth = mItemWeight->getMinWidth();
292  if (mItemCards->getMinWidth() > minWidth)
293  minWidth = mItemCards->getMinWidth();
294  if (mItemOptions->getMinWidth() > minWidth)
295  minWidth = mItemOptions->getMinWidth();
296 
297  const int numRowsDesc = mItemDesc->getNumberOfRows();
298  const int numRowsWeight = mItemWeight->getNumberOfRows();
299  const int numRowsCards = mItemCards->getNumberOfRows();
300  const int numRowsOptions = mItemOptions->getNumberOfRows();
301  const int height = getFont()->getHeight();
302 
303  if (item.getEffect().empty())
304  {
305  setContentSize(minWidth,
306  (numRowsDesc + 2 + numRowsWeight + numRowsCards + numRowsOptions) *
307  height);
308  mItemWeight->setPosition(0, (numRowsDesc + 2) * height);
309  mItemCards->setPosition(0, (numRowsDesc + numRowsWeight + 2) * height);
311  (numRowsDesc + numRowsWeight + numRowsCards + 2) * height);
312  }
313  else
314  {
315  const int numRowsEffect = mItemEffect->getNumberOfRows();
316  setContentSize(minWidth, (numRowsDesc + numRowsEffect + 2
317  + numRowsWeight + numRowsCards + numRowsOptions) * height);
318  mItemEffect->setPosition(0, (numRowsDesc + 2) * height);
319  mItemWeight->setPosition(0, (numRowsDesc + numRowsEffect + 2)
320  * height);
321  mItemCards->setPosition(0, (numRowsDesc + numRowsEffect
322  + numRowsWeight + 2) * height);
323  mItemOptions->setPosition(0, (numRowsDesc + numRowsEffect
324  + numRowsWeight + numRowsCards + 2) * height);
325  }
326 
327  mItemDesc->setPosition(0, 2 * height);
328 }
std::string getStringValue(const std::string &key) const
void setImage(Image *const image)
Definition: icon.cpp:74
const std::string & getDescription() const
Definition: iteminfo.h:100
int getWeight() const
Definition: iteminfo.h:133
ItemDbTypeT getType() const
Definition: iteminfo.h:127
const SpriteDisplay & getDisplay() const
Definition: iteminfo.h:94
const std::string & getEffect() const
Definition: iteminfo.h:109
std::string getDyeIconColorsString(const ItemColor color) const
Definition: iteminfo.cpp:240
static std::string getOptionsString(const ItemOptionsList *const options)
Definition: itempopup.cpp:379
void setLabelColor(Label *label, const ItemDbTypeT type) const
Definition: itempopup.cpp:421
std::string getCardsString(const int *const cards)
Definition: itempopup.cpp:330
void setContentSize(int width, int height)
Definition: popup.cpp:155
unsigned int getNumberOfRows() const
Definition: textbox.h:162
int getMinWidth() const
Definition: textbox.h:108
void setTextWrapped(const std::string &text, const int minDimension)
Definition: textbox.cpp:109
Configuration paths
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:86
std::string formatWeight(const int value)
Definition: unitsdb.cpp:352
#define STD_MOVE(var)
Definition: stdmove.h:28
std::string combineDye2(std::string file, const std::string &dye)
std::string pathJoin(std::string str1, const std::string &str2)
std::string image
Definition: spritedisplay.h:45

References _, Label::adjustSize(), combineDye2(), UnitsDb::formatWeight(), getCardsString(), ItemInfo::getDescription(), ItemInfo::getDisplay(), ItemInfo::getDyeIconColorsString(), ItemInfo::getEffect(), Widget::getFont(), Font::getHeight(), ItemInfo::getId(), Icon::getImage(), Loader::getImage(), TextBox::getMinWidth(), ItemInfo::getName(), Net::getNetworkType(), TextBox::getNumberOfRows(), getOptionsString(), Configuration::getStringValue(), ItemInfo::getType(), ItemInfo::getWeight(), Widget::getWidth(), SpriteDisplay::image, mCardsStr, mIcon, mItemCards, mItemDesc, mItemEffect, mItemName, mItemOptions, mItemOptionsStr, mItemType, mItemWeight, mLastColor, mLastId, mLastName, pathJoin(), paths, Label::setCaption(), Popup::setContentSize(), Icon::setImage(), setLabelColor(), Widget::setPosition(), TextBox::setTextWrapped(), STD_MOVE, strprintf(), and ServerType::TMWATHENA.

Referenced by ItemLinkHandler::handleItemLink(), ItemContainer::mouseMoved(), ItemShortcutContainer::mouseMoved(), ShopListBox::mouseMoved(), VirtShortcutContainer::mouseMoved(), EquipmentWindow::mouseMoved(), ItemAmountWindow::mouseMoved(), and setItem().

◆ setLabelColor()

void ItemPopup::setLabelColor ( Label label,
const ItemDbTypeT  type 
) const
private

Definition at line 421 of file itempopup.cpp.

423 {
424  switch (type)
425  {
426  caseSetColor(ItemDbType::UNUSABLE, ThemeColorId::GENERIC)
429  ThemeColorId::ONEHAND)
431  ThemeColorId::TWOHAND)
432  caseSetColor(ItemDbType::EQUIPMENT_TORSO, ThemeColorId::TORSO)
433  caseSetColor(ItemDbType::EQUIPMENT_ARMS, ThemeColorId::ARMS)
434  caseSetColor(ItemDbType::EQUIPMENT_HEAD, ThemeColorId::HEAD)
435  caseSetColor(ItemDbType::EQUIPMENT_LEGS, ThemeColorId::LEGS)
436  caseSetColor(ItemDbType::EQUIPMENT_SHIELD, ThemeColorId::SHIELD)
437  caseSetColor(ItemDbType::EQUIPMENT_RING, ThemeColorId::RING)
438  caseSetColor(ItemDbType::EQUIPMENT_NECKLACE, ThemeColorId::NECKLACE)
439  caseSetColor(ItemDbType::EQUIPMENT_FEET, ThemeColorId::FEET)
440  caseSetColor(ItemDbType::EQUIPMENT_AMMO, ThemeColorId::AMMO)
441  caseSetColor(ItemDbType::EQUIPMENT_CHARM, ThemeColorId::CHARM)
442  caseSetColor(ItemDbType::SPRITE_RACE, ThemeColorId::UNKNOWN_ITEM)
443  caseSetColor(ItemDbType::SPRITE_HAIR, ThemeColorId::UNKNOWN_ITEM)
445  default:
446  {
447  return label->setForegroundColorAll(
448  getThemeColor(ThemeColorId::UNKNOWN_ITEM, 255U),
449  getThemeColor(ThemeColorId::UNKNOWN_ITEM_OUTLINE, 255U));
450  }
451  }
452 }
void setForegroundColorAll(const Color &color1, const Color &color2)
Definition: label.cpp:217
#define caseSetColor(name1, name2)
Definition: itempopup.cpp:414
@ EQUIPMENT_HEAD
Definition: itemdbtype.h:38
@ EQUIPMENT_RING
Definition: itemdbtype.h:41
@ EQUIPMENT_LEGS
Definition: itemdbtype.h:39
@ EQUIPMENT_TWO_HANDS_WEAPON
Definition: itemdbtype.h:34
@ EQUIPMENT_FEET
Definition: itemdbtype.h:43
@ EQUIPMENT_AMMO
Definition: itemdbtype.h:44
@ EQUIPMENT_SHIELD
Definition: itemdbtype.h:40
@ EQUIPMENT_ONE_HAND_WEAPON
Definition: itemdbtype.h:33
@ EQUIPMENT_CHARM
Definition: itemdbtype.h:45
@ EQUIPMENT_TORSO
Definition: itemdbtype.h:35
@ EQUIPMENT_ARMS
Definition: itemdbtype.h:36
@ EQUIPMENT_NECKLACE
Definition: itemdbtype.h:42

References ItemDbType::CARD, caseSetColor, ItemDbType::EQUIPMENT_AMMO, ItemDbType::EQUIPMENT_ARMS, ItemDbType::EQUIPMENT_CHARM, ItemDbType::EQUIPMENT_FEET, ItemDbType::EQUIPMENT_HEAD, ItemDbType::EQUIPMENT_LEGS, ItemDbType::EQUIPMENT_NECKLACE, ItemDbType::EQUIPMENT_ONE_HAND_WEAPON, ItemDbType::EQUIPMENT_RING, ItemDbType::EQUIPMENT_SHIELD, ItemDbType::EQUIPMENT_TORSO, ItemDbType::EQUIPMENT_TWO_HANDS_WEAPON, Widget2::getThemeColor(), Label::setForegroundColorAll(), ItemDbType::SPRITE_HAIR, ItemDbType::SPRITE_RACE, ItemDbType::UNUSABLE, and ItemDbType::USABLE.

Referenced by setItem().

Field Documentation

◆ mCardsStr

std::string ItemPopup::mCardsStr
private

Definition at line 94 of file itempopup.h.

Referenced by setItem().

◆ mIcon

Icon* ItemPopup::mIcon
private

Definition at line 92 of file itempopup.h.

Referenced by postInit(), setItem(), and ~ItemPopup().

◆ mItemCards

TextBox* ItemPopup::mItemCards
private

Definition at line 89 of file itempopup.h.

Referenced by ItemPopup(), postInit(), and setItem().

◆ mItemDesc

TextBox* ItemPopup::mItemDesc
private

Definition at line 86 of file itempopup.h.

Referenced by ItemPopup(), postInit(), and setItem().

◆ mItemEffect

TextBox* ItemPopup::mItemEffect
private

Definition at line 87 of file itempopup.h.

Referenced by ItemPopup(), postInit(), and setItem().

◆ mItemName

Label* ItemPopup::mItemName
private

Definition at line 85 of file itempopup.h.

Referenced by ItemPopup(), postInit(), and setItem().

◆ mItemOptions

TextBox* ItemPopup::mItemOptions
private

Definition at line 90 of file itempopup.h.

Referenced by ItemPopup(), postInit(), and setItem().

◆ mItemOptionsStr

std::string ItemPopup::mItemOptionsStr
private

Definition at line 95 of file itempopup.h.

Referenced by setItem().

◆ mItemType

ItemDbTypeT ItemPopup::mItemType
private

Definition at line 91 of file itempopup.h.

Referenced by setItem().

◆ mItemWeight

TextBox* ItemPopup::mItemWeight
private

Definition at line 88 of file itempopup.h.

Referenced by ItemPopup(), postInit(), and setItem().

◆ mLastColor

ItemColor ItemPopup::mLastColor
private

Definition at line 97 of file itempopup.h.

Referenced by resetPopup(), and setItem().

◆ mLastId

int ItemPopup::mLastId
private

Definition at line 96 of file itempopup.h.

Referenced by getCardsString(), resetPopup(), and setItem().

◆ mLastName

std::string ItemPopup::mLastName
private

Definition at line 93 of file itempopup.h.

Referenced by resetPopup(), and setItem().


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