ManaPlus
Public Member Functions | Private Types | Private Member Functions | Private Attributes

#include <tradewindow.h>

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

Public Member Functions

 TradeWindow ()
 
 ~TradeWindow ()
 
void setMoney (const int quantity)
 
void addItem (const int id, const ItemTypeT type, const bool own, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite) const
 
void reset ()
 
void addItem2 (const int id, const ItemTypeT type, const int *const cards, const ItemOptionsList *const options, const int sz, const bool own, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite, const Equipm equipment) const
 
void changeQuantity (const int index, const bool own, const int quantity) const
 
void increaseQuantity (const int index, const bool own, const int quantity) const
 
void receivedOk (const bool own)
 
void tradeItem (const Item *const item, const int quantity, const bool check) const
 
void valueChanged (const SelectionEvent &event)
 
void action (const ActionEvent &event)
 
void close ()
 
void clear ()
 
void addAutoItem (const std::string &nick, Item *const item, const int amount)
 
void addAutoMoney (const std::string &nick, const int money)
 
void initTrade (const std::string &nick)
 
std::string getAutoTradeNick () const
 
bool checkItem (const Item *const item) const
 
bool isInpupFocused () const
 
void completeTrade ()
 
- Public Member Functions inherited from Window
 Window (const std::string &caption, const Modal modal, Window *const parent, std::string skin)
 
 ~Window ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void setContentSize (int width, int height)
 
void setLocationRelativeTo (const Widget *const widget)
 
void setLocationHorisontallyRelativeTo (const Widget *const widget)
 
void setLocationRelativeTo (const ImagePosition::Type &position, int offsetX, int offsetY)
 
void setResizable (const bool resize)
 
void redraw ()
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
void widgetHidden (const Event &event)
 
void setCloseButton (const bool flag)
 
bool getCloseButton () const
 
void setAllowClose (const bool b)
 
bool getAlowClose () const
 
bool isResizable () const
 
void setMinWidth (const int width)
 
int getMinWidth () const
 
void setMinHeight (const int height)
 
int getMinHeight () const
 
void setMaxWidth (const int width)
 
int getMaxWidth () const
 
void setMaxHeight (const int height)
 
int getMaxHeight () const
 
void setShowTitle (bool flag)
 
void setStickyButton (const bool flag)
 
void setSticky (const bool sticky)
 
bool isSticky () const
 
void setStickyButtonLock (const bool sticky)
 
bool isStickyButtonLock () const
 
virtual void setVisible (Visible visible)
 
void setVisible (const Visible visible, const bool forceSticky)
 
bool isDefaultVisible () const
 
void setDefaultVisible (const bool save)
 
bool willSaveVisible () const
 
void setSaveVisible (const bool save)
 
void postInit ()
 
WindowgetParentWindow () const
 
virtual void scheduleDelete ()
 
void mousePressed (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void mouseEntered (MouseEvent &event)
 
void updateResizeHandler (MouseEvent &event)
 
void setWindowName (const std::string &name)
 
const std::string & getWindowName () const
 
void loadWindowState ()
 
void saveWindowState ()
 
void setDefaultSize (const int defaultX, const int defaultY, int defaultWidth, int defaultHeight)
 
void setDefaultSize ()
 
void setDefaultSize (const int defaultWidth, const int defaultHeight, const ImagePosition::Type &position, const int offsetx, const int offsetY)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w, int h)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w, const int h)
 
ContainerPlacer getPlacer (const int x, const int y)
 
void center ()
 
void centerHorisontally ()
 
void setModal (const Modal modal)
 
Rect getWindowArea () const
 
bool isResizeAllowed (const MouseEvent &event) const
 
void setCaptionFont (Font *font)
 
void enableVisibleSound (bool b)
 
bool isWindowVisible () const
 
void setPadding (int padding)
 
int getPadding () const
 
void setTitleBarHeight (unsigned int height)
 
unsigned int getTitleBarHeight () const
 
void setCaption (const std::string &caption)
 
const std::string & getCaption () const
 
void setAlignment (Graphics::Alignment alignment)
 
Graphics::Alignment getAlignment () const
 
void setMovable (Move movable)
 
bool isMovable () const
 
Rect getChildrenArea ()
 
virtual void resizeToContent ()
 
- Public Member Functions inherited from BasicContainer2
 BasicContainer2 (const Widget2 *const widget)
 
 ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
void focusNext ()
 
void focusPrevious ()
 
void logic ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget *> &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetShown (const Event &event)
 

Private Types

enum  Status { PREPARING = 0, PROPOSING, ACCEPTING, ACCEPTED }
 

Private Member Functions

void setStatus (const Status s)
 
- Private Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
 ActionListener ()
 
- Private Member Functions inherited from SelectionListener
virtual ~SelectionListener ()
 
 SelectionListener ()
 

Private Attributes

InventorymMyInventory
 
InventorymPartnerInventory
 
ItemContainermMyItemContainer
 
ItemContainermPartnerItemContainer
 
LabelmMoneyLabel
 
ButtonmAddButton
 
ButtonmOkButton
 
ButtonmMoneyChangeButton
 
TextFieldmMoneyField
 
ItemmAutoAddItem
 
std::string mAutoAddToNick
 
int mGotMoney
 
int mGotMaxMoney
 
int mAutoMoney
 
int mAutoAddAmount
 
Status mStatus
 
bool mOkOther
 
bool mOkMe
 

Additional Inherited Members

- Static Public Member Functions inherited from Window
static void setWindowContainer (WindowContainer *const windowContainer)
 
- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Member Functions inherited from Window
bool canMove () const
 
int getOption (const std::string &name, const int def) const
 
bool getOptionBool (const std::string &name, const bool def) const
 
void setTitlePadding (const int p)
 
int getTitlePadding () const
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Attributes inherited from Window
std::string mCaption
 
Graphics::Alignment mAlignment
 
int mPadding
 
unsigned int mTitleBarHeight
 
Move mMovable
 
int mDragOffsetX
 
int mDragOffsetY
 
bool mMoved
 
SkinmSkin
 
int mDefaultX
 
int mDefaultY
 
int mDefaultWidth
 
int mDefaultHeight
 
int mCaptionOffsetX
 
int mCaptionOffsetY
 
bool mShowTitle
 
bool mLastRedraw
 
- Protected Attributes inherited from BasicContainer2
Opaque mOpaque
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

Trade dialog.

Definition at line 53 of file tradewindow.h.

Member Enumeration Documentation

◆ Status

enum TradeWindow::Status
private
Enumerator
PREPARING 

Players are adding items. (1)

PROPOSING 

Local player has confirmed the trade. (1)

ACCEPTING 

Accepting the trade. (2)

ACCEPTED 

Local player has accepted the trade.

Definition at line 176 of file tradewindow.h.

Constructor & Destructor Documentation

◆ TradeWindow()

TradeWindow::TradeWindow ( )

Constructor.

Definition at line 75 of file tradewindow.cpp.

References _, ItemContainer::addSelectionListener(), CAPTION_ACCEPT, CAPTION_ACCEPTED, CAPTION_CONFIRMED, CAPTION_PROPOSE, ImagePosition::CENTER, Window::enableVisibleSound(), LayoutCell::extend(), Widget::getFont(), Window::getLayout(), Window::getPlacer(), Font::getWidth(), LayoutCell::LEFT, Window::loadWindowState(), mAddButton, mMoneyChangeButton, mMoneyField, mMoneyLabel, mMyItemContainer, mOkButton, mPartnerItemContainer, Opaque_true, Window::place(), SetupWindow::registerWindowForReset(), reset(), LayoutType::SET, Window::setCloseButton(), LayoutCell::setColWidth(), Window::setDefaultSize(), ScrollArea::setHorizontalScrollPolicy(), Window::setMinHeight(), Window::setMinWidth(), LayoutCell::setPadding(), Window::setResizable(), LayoutCell::setRowHeight(), Window::setStickyButtonLock(), setupWindow, Widget::setWidth(), Window::setWindowName(), and ScrollArea::SHOW_NEVER.

75  :
76  // TRANSLATORS: trade window caption
77  Window(_("Trade: You"), Modal_false, nullptr, "trade.xml"),
86  // TRANSLATORS: trade window money label
87  mMoneyLabel(new Label(this, strprintf(_("You get %s"), ""))),
88  // TRANSLATORS: trade window button
89  mAddButton(new Button(this, _("Add"), "add", BUTTON_SKIN, this)),
90  mOkButton(new Button(this, "", "",
91  BUTTON_SKIN, this)), // Will be filled in later
92  // TRANSLATORS: trade window money change button
93  mMoneyChangeButton(new Button(this, _("Change"), "money",
94  BUTTON_SKIN, this)),
95  mMoneyField(new TextField(this, std::string(),
96  LoseFocusOnTab_true, nullptr, std::string(), false)),
97  mAutoAddItem(nullptr),
98  mAutoAddToNick(""),
99  mGotMoney(0),
100  mGotMaxMoney(0),
101  mAutoMoney(0),
102  mAutoAddAmount(0),
104  mOkOther(false),
105  mOkMe(false)
106 {
107  setWindowName("Trade");
108  setResizable(true);
109  setCloseButton(true);
110  setStickyButtonLock(true);
111  setDefaultSize(386, 180, ImagePosition::CENTER, 0, 0);
112  setMinWidth(310);
113  setMinHeight(180);
114 
115  if (setupWindow != nullptr)
117 
118  const Font *const fnt = mOkButton->getFont();
119  int width = std::max(fnt->getWidth(CAPTION_PROPOSE),
121  width = std::max(width, fnt->getWidth(CAPTION_ACCEPT));
122  width = std::max(width, fnt->getWidth(CAPTION_ACCEPTED));
123 
124  mOkButton->setWidth(8 + width);
125 
127 
128  ScrollArea *const myScroll = new ScrollArea(this, mMyItemContainer,
129  Opaque_true, "trade_background.xml");
131 
133 
134  ScrollArea *const partnerScroll = new ScrollArea(this,
136  Opaque_true, "trade_background.xml");
138 
139  // TRANSLATORS: trade window money label
140  Label *const moneyLabel2 = new Label(this, _("You give:"));
141 
142  mMoneyField->setWidth(40);
143 
144  place(1, 0, mMoneyLabel, 1, 1);
145  place(0, 1, myScroll, 1, 1).setPadding(3);
146  place(1, 1, partnerScroll, 1, 1).setPadding(3);
147  ContainerPlacer placer = getPlacer(0, 0);
148  placer(0, 0, moneyLabel2, 1, 1);
149  placer(1, 0, mMoneyField, 2, 1);
150  placer(3, 0, mMoneyChangeButton, 1, 1).setHAlign(LayoutCell::LEFT);
151  placer = getPlacer(0, 2);
152  placer(0, 0, mAddButton, 1, 1);
153  placer(1, 0, mOkButton, 1, 1);
154  Layout &layout = getLayout();
155  layout.extend(0, 2, 2, 1);
156  layout.setRowHeight(1, LayoutType::SET);
157  layout.setRowHeight(2, 0);
158  layout.setColWidth(0, LayoutType::SET);
159  layout.setColWidth(1, LayoutType::SET);
160 
161  loadWindowState();
162  enableVisibleSound(true);
163 
164  reset();
165 }
Font * getFont() const
Definition: widget.cpp:330
#define CAPTION_ACCEPT
Definition: tradewindow.cpp:71
void setDefaultSize()
Definition: window.cpp:1197
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1383
#define _(s)
Definition: gettext.h:34
ItemContainer * mPartnerItemContainer
Definition: tradewindow.h:193
const bool LoseFocusOnTab_true
void setWidth(const int width)
Definition: widget.cpp:132
Definition: font.h:88
void loadWindowState()
Definition: window.cpp:1086
const bool ShowEmptyRows_false
Definition: showemptyrows.h:29
Inventory * mMyInventory
Definition: tradewindow.h:189
void extend(const int x, const int y, const int w, const int h)
Definition: layoutcell.cpp:132
void setMinWidth(const int width)
Definition: window.cpp:590
Definition: button.h:96
void setColWidth(const int n, const int w)
Definition: layoutcell.cpp:122
Button * mAddButton
Definition: tradewindow.h:196
void registerWindowForReset(Window *const window)
#define CAPTION_CONFIRMED
Definition: tradewindow.cpp:69
#define CAPTION_ACCEPTED
Definition: tradewindow.cpp:73
ItemContainer * mMyItemContainer
Definition: tradewindow.h:192
const std::string BUTTON_SKIN
Definition: button.h:88
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
Definition: label.h:87
Label * mMoneyLabel
Definition: tradewindow.h:195
#define CAPTION_PROPOSE
Definition: tradewindow.cpp:67
int mAutoAddAmount
Definition: tradewindow.h:206
Item * mAutoAddItem
Definition: tradewindow.h:201
Button * mMoneyChangeButton
Definition: tradewindow.h:198
Status mStatus
Definition: tradewindow.h:207
void setCloseButton(const bool flag)
Definition: window.cpp:748
int mGotMaxMoney
Definition: tradewindow.h:204
void enableVisibleSound(bool b)
Definition: window.h:480
void setMinHeight(const int height)
Definition: window.cpp:603
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1390
LayoutCell & setPadding(int p)
Definition: layoutcell.h:59
Layout & getLayout()
Definition: window.cpp:1364
void addSelectionListener(SelectionListener *listener)
const bool Opaque_true
Definition: opaque.h:29
int getWidth(const std::string &text) const
Definition: font.cpp:333
const bool ForceQuantity_false
Definition: forcequantity.h:29
Button * mOkButton
Definition: tradewindow.h:197
void setResizable(const bool resize)
Definition: window.cpp:626
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:771
TextField * mMoneyField
Definition: tradewindow.h:199
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
Definition: layout.h:43
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:127
Inventory * mPartnerInventory
Definition: tradewindow.h:190
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:108
void setWindowName(const std::string &name)
Definition: window.h:354
std::string mAutoAddToNick
Definition: tradewindow.h:202
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)

◆ ~TradeWindow()

TradeWindow::~TradeWindow ( )

Destructor.

Definition at line 167 of file tradewindow.cpp.

References delete2, mMyInventory, and mPartnerInventory.

168 {
171 }
Inventory * mMyInventory
Definition: tradewindow.h:189
#define delete2(var)
Definition: delete2.h:24
Inventory * mPartnerInventory
Definition: tradewindow.h:190

Member Function Documentation

◆ action()

void TradeWindow::action ( const ActionEvent event)
virtual

Called when receiving actions from the widgets.

Implements ActionListener.

Definition at line 377 of file tradewindow.cpp.

References _, ACCEPTED, ChatMsgType::BY_SERVER, Net::TradeHandler::cancel(), ChatTab::chatLog(), checkItem(), Net::TradeHandler::confirm(), Net::TradeHandler::finish(), PlayerInfo::getAttribute(), Inventory::getFreeSlot(), Item::getId(), InventoryWindow::getSelectedItem(), TextField::getText(), IgnoreRecord_false, inventoryWindow, Window::isWindowVisible(), ServerCommandType::item, localChatTab, mAddButton, mMoneyChangeButton, mMoneyField, mMyInventory, Attributes::MONEY, mStatus, PREPARING, PROPOSING, receivedOk(), reset(), Widget::setEnabled(), Net::TradeHandler::setMoney(), setStatus(), TextField::setText(), PlayerInfo::setTrading(), InventoryWindow::setVisible(), Window::setVisible(), ItemAmountWindow::showWindow(), strprintf(), ItemAmountWindowUsage::TradeAdd, tradeHandler, Trading_false, TryRemoveColors_true, Visible_false, and Visible_true.

378 {
379  if (inventoryWindow == nullptr)
380  return;
381 
383  const std::string &eventId = event.getId();
384 
385  if (eventId == "add")
386  {
387  if (mStatus != PREPARING)
388  return;
389 
391  {
393  return;
394  }
395 
396  if (item == nullptr)
397  return;
398 
399  if (mMyInventory->getFreeSlot() == -1)
400  return;
401 
402  if (!checkItem(item))
403  return;
404 
405  // Choose amount of items to trade
407  this,
408  item,
409  0,
410  0);
411 
413  }
414  else if (eventId == "cancel")
415  {
417  reset();
419  tradeHandler->cancel();
420  }
421  else if (eventId == "ok")
422  {
423  mMoneyField->setEnabled(false);
424  mAddButton->setEnabled(false);
426  receivedOk(true);
429  }
430  else if (eventId == "trade")
431  {
432  receivedOk(true);
434  tradeHandler->finish();
435  }
436  else if (eventId == "money")
437  {
438  if (mStatus != PREPARING)
439  return;
440 
441  int v = atoi(mMoneyField->getText().c_str());
442  const int curMoney = PlayerInfo::getAttribute(Attributes::MONEY);
443  if (v > curMoney)
444  {
445  if (localChatTab != nullptr)
446  {
447  // TRANSLATORS: trade error
448  localChatTab->chatLog(_("You don't have enough money."),
452  }
453  v = curMoney;
454  }
456  mMoneyField->setText(strprintf("%d", v));
457  }
458 }
#define _(s)
Definition: gettext.h:34
virtual void finish() const
Definition: tradehandler.h:65
ChatTab * localChatTab
Definition: chattab.cpp:61
const bool Visible_true
Definition: visible.h:29
const bool Trading_false
Definition: trading.h:29
virtual void setMoney(const int amount) const
Definition: tradehandler.h:59
Inventory * mMyInventory
Definition: tradewindow.h:189
static void showWindow(const ItemAmountWindowUsageT usage, Window *const parent, Item *const item, int maxRange, const int tag)
Button * mAddButton
Definition: tradewindow.h:196
const bool TryRemoveColors_true
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:110
void setStatus(const Status s)
void setVisible(Visible visible)
InventoryWindow * inventoryWindow
void setText(const std::string &text)
Definition: textfield.cpp:802
virtual void cancel() const
Definition: tradehandler.h:68
int getFreeSlot() const
Definition: inventory.cpp:281
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
const bool Visible_false
Definition: visible.h:29
bool checkItem(const Item *const item) const
const bool IgnoreRecord_false
Definition: ignorerecord.h:29
Definition: item.h:48
bool isWindowVisible() const
Definition: window.h:483
Button * mMoneyChangeButton
Definition: tradewindow.h:198
Status mStatus
Definition: tradewindow.h:207
virtual void confirm() const
Definition: tradehandler.h:62
void receivedOk(const bool own)
void setEnabled(const bool enabled)
Definition: widget.h:351
int getId() const
Definition: item.h:80
virtual void setVisible(Visible visible)
Definition: window.cpp:777
Item * getSelectedItem() const
Net::TradeHandler * tradeHandler
Definition: net.cpp:95
TextField * mMoneyField
Definition: tradewindow.h:199
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:100
const std::string & getText() const
Definition: textfield.h:223
void setTrading(const Trading trading)
Definition: playerinfo.cpp:394

◆ addAutoItem()

void TradeWindow::addAutoItem ( const std::string &  nick,
Item *const  item,
const int  amount 
)

Add item what will be added to trade.

Definition at line 479 of file tradewindow.cpp.

References ServerCommandType::item, mAutoAddAmount, mAutoAddItem, and mAutoAddToNick.

Referenced by ShopSellDialog::sellAction(), and ShopWindow::startTrade().

481 {
482  mAutoAddToNick = nick;
483  mAutoAddItem = item;
484  mAutoAddAmount = amount;
485 }
int mAutoAddAmount
Definition: tradewindow.h:206
Item * mAutoAddItem
Definition: tradewindow.h:201
std::string mAutoAddToNick
Definition: tradewindow.h:202

◆ addAutoMoney()

void TradeWindow::addAutoMoney ( const std::string &  nick,
const int  money 
)

Definition at line 487 of file tradewindow.cpp.

References mAutoAddToNick, and mAutoMoney.

Referenced by BuyDialog::action(), and ShopWindow::startTrade().

488 {
489  mAutoAddToNick = nick;
490  mAutoMoney = money;
491 }
std::string mAutoAddToNick
Definition: tradewindow.h:202

◆ addItem()

void TradeWindow::addItem ( const int  id,
const ItemTypeT  type,
const bool  own,
const int  quantity,
const uint8_t  refine,
const ItemColor  color,
const Identified  identified,
const Damaged  damaged,
const Favorite  favorite 
) const

Add an item to the trade window.

Definition at line 201 of file tradewindow.cpp.

References Inventory::addItem(), Equipm_false, Equipped_false, mMyInventory, and mPartnerInventory.

210 {
211  Inventory *const inv = own ? mMyInventory : mPartnerInventory;
212  inv->addItem(id,
213  type,
214  quantity,
215  refine,
216  color,
217  identified,
218  damaged,
219  favorite,
220  Equipm_false,
222 }
int addItem(const int id, const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite, const Equipm equipment, const Equipped equipped)
Definition: inventory.cpp:114
Inventory * mMyInventory
Definition: tradewindow.h:189
const bool Equipped_false
Definition: equipped.h:29
Inventory * mPartnerInventory
Definition: tradewindow.h:190
const bool Equipm_false
Definition: equipm.h:29

◆ addItem2()

void TradeWindow::addItem2 ( const int  id,
const ItemTypeT  type,
const int *const  cards,
const ItemOptionsList *const  options,
const int  sz,
const bool  own,
const int  quantity,
const uint8_t  refine,
const ItemColor  color,
const Identified  identified,
const Damaged  damaged,
const Favorite  favorite,
const Equipm  equipment 
) const

Add an item to the trade window.

Definition at line 224 of file tradewindow.cpp.

References Inventory::addItem(), Equipped_false, mMyInventory, mPartnerInventory, Inventory::setCards(), and Inventory::setOptions().

Referenced by TmwAthena::TradeRecv::processTradeItemAdd(), EAthena::TradeRecv::processTradeItemAdd(), TmwAthena::TradeRecv::processTradeItemAddResponse(), and EAthena::TradeRecv::processTradeItemAddResponse().

237 {
238  Inventory *const inv = own ? mMyInventory : mPartnerInventory;
239  const int slot = inv->addItem(id,
240  type,
241  quantity,
242  refine,
243  color,
244  identified,
245  damaged,
246  favorite,
247  equipment,
249  if (slot >= 0)
250  {
251  inv->setCards(slot, cards, sz);
252  inv->setOptions(slot, options);
253  }
254 }
int addItem(const int id, const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite, const Equipm equipment, const Equipped equipped)
Definition: inventory.cpp:114
Inventory * mMyInventory
Definition: tradewindow.h:189
const bool Equipped_false
Definition: equipped.h:29
void setCards(const int index, const int *const cards, const int size) const
Definition: inventory.cpp:193
void setOptions(const int index, const ItemOptionsList *const options)
Definition: inventory.cpp:209
Inventory * mPartnerInventory
Definition: tradewindow.h:190

◆ changeQuantity()

void TradeWindow::changeQuantity ( const int  index,
const bool  own,
const int  quantity 
) const

Change quantity of an item.

Definition at line 256 of file tradewindow.cpp.

References Inventory::getItem(), ServerCommandType::item, mMyInventory, mPartnerInventory, and Item::setQuantity().

258 {
259  Item *item;
260  if (own)
261  item = mMyInventory->getItem(index);
262  else
263  item = mPartnerInventory->getItem(index);
264  if (item != nullptr)
265  item->setQuantity(quantity);
266 }
Inventory * mMyInventory
Definition: tradewindow.h:189
Definition: item.h:48
void setQuantity(const int quantity)
Definition: item.h:92
Item * getItem(const int index) const
Definition: inventory.cpp:82
Inventory * mPartnerInventory
Definition: tradewindow.h:190

◆ checkItem()

bool TradeWindow::checkItem ( const Item *const  item) const

Definition at line 522 of file tradewindow.cpp.

References _, ChatMsgType::BY_SERVER, ChatTab::chatLog(), Equipped_true, Inventory::findItem(), Item::getColor(), Item::getId(), Net::getNetworkType(), Item::getQuantity(), IgnoreRecord_false, Item::isEquipped(), PlayerInfo::isItemProtected(), localChatTab, mMyInventory, ServerType::TMWATHENA, and TryRemoveColors_true.

Referenced by action(), getAutoTradeNick(), and tradeItem().

523 {
524  if (item == nullptr)
525  return false;
526 
527  const int itemId = item->getId();
528  if (PlayerInfo::isItemProtected(itemId))
529  return false;
530  const Item *const tItem = mMyInventory->findItem(
531  itemId, item->getColor());
532 
533  if ((tItem != nullptr) && (tItem->getQuantity() > 1
534  || item->getQuantity() > 1))
535  {
536  if (localChatTab != nullptr)
537  {
538  // TRANSLATORS: trade error
539  localChatTab->chatLog(_("Failed adding item. You can not "
540  "overlap one kind of item on the window."),
544  }
545  return false;
546  }
548  item->isEquipped() == Equipped_true)
549  {
550  if (localChatTab != nullptr)
551  {
553  // TRANSLATORS: trade error
554  _("Failed adding item. You can not trade equipped items."),
558  }
559  return false;
560  }
561  return true;
562 }
#define _(s)
Definition: gettext.h:34
ChatTab * localChatTab
Definition: chattab.cpp:61
Inventory * mMyInventory
Definition: tradewindow.h:189
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
Equipped isEquipped() const
Definition: item.h:128
const bool TryRemoveColors_true
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:110
const bool Equipped_true
Definition: equipped.h:29
int getQuantity() const
Definition: item.h:104
const bool IgnoreRecord_false
Definition: ignorerecord.h:29
ItemColor getColor() const
Definition: item.h:180
Definition: item.h:48
ServerTypeT getNetworkType()
Definition: net.cpp:184
bool isItemProtected(const int id)
Definition: playerinfo.cpp:512
int getId() const
Definition: item.h:80

◆ clear()

void TradeWindow::clear ( )
virtual

Clear auto trade items.

Reimplemented from BasicContainer.

Definition at line 466 of file tradewindow.cpp.

References Widget2::getThemeColor(), ThemeColorId::LABEL, ThemeColorId::LABEL_OUTLINE, mAutoAddAmount, mAutoAddItem, mAutoAddToNick, mAutoMoney, mGotMaxMoney, mGotMoney, mMoneyLabel, and Label::setForegroundColorAll().

Referenced by close(), Actions::doSit(), initTrade(), Ea::TradeRecv::processTradeRequestContinue(), Ea::TradeRecv::processTradeResponseContinue(), and ShopWindow::startTrade().

467 {
468  mAutoAddItem = nullptr;
469  mAutoAddToNick.clear();
470  mAutoMoney = 0;
471  mAutoAddAmount = 0;
472  mGotMoney = 0;
473  mGotMaxMoney = 0;
477 }
Label * mMoneyLabel
Definition: tradewindow.h:195
int mAutoAddAmount
Definition: tradewindow.h:206
Item * mAutoAddItem
Definition: tradewindow.h:201
int mGotMaxMoney
Definition: tradewindow.h:204
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
void setForegroundColorAll(const Color &color1, const Color &color2)
Definition: label.cpp:214
std::string mAutoAddToNick
Definition: tradewindow.h:202

◆ close()

void TradeWindow::close ( )
virtual

Closes the Trade Window, as well as telling the server that the window has been closed.

Reimplemented from Window.

Definition at line 460 of file tradewindow.cpp.

References Net::TradeHandler::cancel(), clear(), and tradeHandler.

Referenced by setMoney().

461 {
462  tradeHandler->cancel();
463  clear();
464 }
virtual void cancel() const
Definition: tradehandler.h:68
Net::TradeHandler * tradeHandler
Definition: net.cpp:95

◆ completeTrade()

void TradeWindow::completeTrade ( )

Definition at line 310 of file tradewindow.cpp.

References config, Game::createScreenshot(), Configuration::getBoolValue(), reset(), Window::setVisible(), and Visible_false.

Referenced by getAutoTradeNick(), and Ea::TradeRecv::processTradeComplete().

311 {
312  if (config.getBoolValue("tradescreenshot"))
313  Game::createScreenshot(std::string());
315  reset();
316 }
static bool createScreenshot(const std::string &prefix)
Definition: game.cpp:534
Configuration config
bool getBoolValue(const std::string &key) const
const bool Visible_false
Definition: visible.h:29
virtual void setVisible(Visible visible)
Definition: window.cpp:777

◆ getAutoTradeNick()

std::string TradeWindow::getAutoTradeNick ( ) const
inline

Definition at line 166 of file tradewindow.h.

References A_WARN_UNUSED, checkItem(), completeTrade(), isInpupFocused(), and mAutoAddToNick.

Referenced by Ea::TradeRecv::processTradeRequestContinue().

167  { return mAutoAddToNick; }
std::string mAutoAddToNick
Definition: tradewindow.h:202

◆ increaseQuantity()

void TradeWindow::increaseQuantity ( const int  index,
const bool  own,
const int  quantity 
) const

Increase quantity of an item.

Definition at line 268 of file tradewindow.cpp.

References Inventory::getItem(), Item::increaseQuantity(), ServerCommandType::item, mMyInventory, and mPartnerInventory.

270 {
271  Item *item;
272  if (own)
273  item = mMyInventory->getItem(index);
274  else
275  item = mPartnerInventory->getItem(index);
276  if (item != nullptr)
277  item->increaseQuantity(quantity);
278 }
Inventory * mMyInventory
Definition: tradewindow.h:189
Definition: item.h:48
Item * getItem(const int index) const
Definition: inventory.cpp:82
Inventory * mPartnerInventory
Definition: tradewindow.h:190
void increaseQuantity(const int amount)
Definition: item.h:98

◆ initTrade()

void TradeWindow::initTrade ( const std::string &  nick)

Definition at line 493 of file tradewindow.cpp.

References clear(), Inventory::findItem(), Item::getColor(), Item::getId(), PlayerInfo::getInventory(), Item::getQuantity(), Gui::getSecureFont(), gui, PlayerRelationsManager::isGoodName(), ServerCommandType::item, localPlayer, mAutoAddAmount, mAutoAddItem, mAutoAddToNick, mAutoMoney, mMoneyField, playerRelations, Window::setCaptionFont(), Net::TradeHandler::setMoney(), TextField::setText(), strprintf(), tradeHandler, and tradeItem().

Referenced by Ea::TradeRecv::processTradeResponseContinue().

494 {
495  if (localPlayer == nullptr)
496  return;
497 
498  if (!mAutoAddToNick.empty() && mAutoAddToNick == nick)
499  {
500  if ((mAutoAddItem != nullptr) && (mAutoAddItem->getQuantity() != 0))
501  {
502  const Inventory *const inv = PlayerInfo::getInventory();
503  if (inv != nullptr)
504  {
505  const Item *const item = inv->findItem(mAutoAddItem->getId(),
507  if (item != nullptr)
508  tradeItem(item, mAutoAddAmount, false);
509  }
510  }
511  if (mAutoMoney != 0)
512  {
515  }
516  }
517  clear();
518  if (!playerRelations.isGoodName(nick))
520 }
Gui * gui
Definition: gui.cpp:110
virtual void setMoney(const int amount) const
Definition: tradehandler.h:59
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
Inventory * getInventory()
Definition: playerinfo.cpp:193
void setText(const std::string &text)
Definition: textfield.cpp:802
bool isGoodName(Being *const being) const
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void setCaptionFont(Font *font)
Definition: window.h:477
int getQuantity() const
Definition: item.h:104
LocalPlayer * localPlayer
ItemColor getColor() const
Definition: item.h:180
int mAutoAddAmount
Definition: tradewindow.h:206
Definition: item.h:48
Item * mAutoAddItem
Definition: tradewindow.h:201
void tradeItem(const Item *const item, const int quantity, const bool check) const
int getId() const
Definition: item.h:80
Font * getSecureFont() const
Definition: gui.h:171
Net::TradeHandler * tradeHandler
Definition: net.cpp:95
TextField * mMoneyField
Definition: tradewindow.h:199
PlayerRelationsManager playerRelations
std::string mAutoAddToNick
Definition: tradewindow.h:202

◆ isInpupFocused()

bool TradeWindow::isInpupFocused ( ) const

Definition at line 564 of file tradewindow.cpp.

References Widget::isFocused(), and mMoneyField.

Referenced by getAutoTradeNick(), and InputManager::updateConditionMask().

565 {
566  return mMoneyField != nullptr && mMoneyField->isFocused();
567 }
virtual bool isFocused() const
Definition: widget.cpp:183
TextField * mMoneyField
Definition: tradewindow.h:199

◆ receivedOk()

void TradeWindow::receivedOk ( const bool  own)

Player received ok message from server

Definition at line 299 of file tradewindow.cpp.

References ACCEPTING, mOkMe, mOkOther, and setStatus().

Referenced by action(), TmwAthena::TradeRecv::processTradeItemAddResponse(), and Ea::TradeRecv::processTradeOk().

300 {
301  if (own)
302  mOkMe = true;
303  else
304  mOkOther = true;
305 
306  if (mOkMe && mOkOther)
308 }
void setStatus(const Status s)

◆ reset()

void TradeWindow::reset ( )

Reset both item containers

Definition at line 280 of file tradewindow.cpp.

References Inventory::clear(), Widget2::getThemeColor(), ThemeColorId::LABEL, ThemeColorId::LABEL_OUTLINE, mAddButton, mGotMaxMoney, mGotMoney, mMoneyChangeButton, mMoneyField, mMoneyLabel, mMyInventory, mOkMe, mOkOther, mPartnerInventory, PREPARING, Widget::setEnabled(), Label::setForegroundColorAll(), setMoney(), setStatus(), and TextField::setText().

Referenced by action(), completeTrade(), Ea::TradeRecv::processTradeCancel(), Ea::TradeRecv::processTradeResponseContinue(), and TradeWindow().

281 {
282  mMyInventory->clear();
284  mOkOther = false;
285  mOkMe = false;
286  setMoney(0);
287  mMoneyField->setEnabled(true);
288  mMoneyField->setText("");
292  mAddButton->setEnabled(true);
294  mGotMoney = 0;
295  mGotMaxMoney = 0;
297 }
Inventory * mMyInventory
Definition: tradewindow.h:189
Button * mAddButton
Definition: tradewindow.h:196
void setStatus(const Status s)
void setMoney(const int quantity)
void setText(const std::string &text)
Definition: textfield.cpp:802
void clear()
Definition: inventory.cpp:237
Label * mMoneyLabel
Definition: tradewindow.h:195
Button * mMoneyChangeButton
Definition: tradewindow.h:198
int mGotMaxMoney
Definition: tradewindow.h:204
void setEnabled(const bool enabled)
Definition: widget.h:351
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
TextField * mMoneyField
Definition: tradewindow.h:199
void setForegroundColorAll(const Color &color1, const Color &color2)
Definition: label.cpp:214
Inventory * mPartnerInventory
Definition: tradewindow.h:190

◆ setMoney()

void TradeWindow::setMoney ( const int  quantity)

Displays expected money in the trade window.

Definition at line 173 of file tradewindow.cpp.

References _, Label::adjustSize(), close(), config, UnitsDb::formatCurrency(), Configuration::getBoolValue(), Widget2::getThemeColor(), ThemeColorId::LABEL, ThemeColorId::LABEL_OUTLINE, mGotMaxMoney, mGotMoney, mMoneyLabel, Label::setCaption(), Label::setForegroundColorAll(), strprintf(), ThemeColorId::WARNING, and ThemeColorId::WARNING_OUTLINE.

Referenced by TmwAthena::TradeRecv::processTradeItemAdd(), EAthena::TradeRecv::processTradeItemAdd(), and reset().

174 {
175  if (amount < 0 || amount < mGotMaxMoney)
176  {
177  if (config.getBoolValue("securetrades"))
178  {
179  close();
180  return;
181  }
185  }
186  else
187  {
191  mGotMaxMoney = amount;
192  }
193 
194  mGotMoney = amount;
195  // TRANSLATORS: trade window money label
196  mMoneyLabel->setCaption(strprintf(_("You get %s"),
197  UnitsDb::formatCurrency(amount).c_str()));
199 }
#define _(s)
Definition: gettext.h:34
Configuration config
std::string formatCurrency(const int value)
Definition: unitsdb.cpp:323
bool getBoolValue(const std::string &key) const
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void setCaption(const std::string &caption)
Definition: label.cpp:261
Label * mMoneyLabel
Definition: tradewindow.h:195
int mGotMaxMoney
Definition: tradewindow.h:204
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
void setForegroundColorAll(const Color &color1, const Color &color2)
Definition: label.cpp:214
void adjustSize()
Definition: label.cpp:197

◆ setStatus()

void TradeWindow::setStatus ( const Status  s)
private

Sets the current status of the trade.

Definition at line 346 of file tradewindow.cpp.

References ACCEPTED, ACCEPTING, CAPTION_ACCEPT, CAPTION_ACCEPTED, CAPTION_CONFIRMED, CAPTION_PROPOSE, mOkButton, mStatus, PREPARING, PROPOSING, Widget::setActionEventId(), Button::setCaption(), and Widget::setEnabled().

Referenced by action(), receivedOk(), and reset().

347 {
348  if (s == mStatus)
349  return;
350  mStatus = s;
351 
352  switch (s)
353  {
354  case PREPARING:
357  break;
358  case PROPOSING:
361  break;
362  case ACCEPTING:
364  mOkButton->setActionEventId("trade");
365  break;
366  case ACCEPTED:
369  break;
370  default:
371  break;
372  }
373 
374  mOkButton->setEnabled((s != PROPOSING && s != ACCEPTED));
375 }
#define CAPTION_ACCEPT
Definition: tradewindow.cpp:71
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
#define CAPTION_CONFIRMED
Definition: tradewindow.cpp:69
#define CAPTION_ACCEPTED
Definition: tradewindow.cpp:73
void setCaption(const std::string &caption)
Definition: button.h:213
#define CAPTION_PROPOSE
Definition: tradewindow.cpp:67
Status mStatus
Definition: tradewindow.h:207
void setEnabled(const bool enabled)
Definition: widget.h:351
Button * mOkButton
Definition: tradewindow.h:197

◆ tradeItem()

void TradeWindow::tradeItem ( const Item *const  item,
const int  quantity,
const bool  check 
) const

Send trade packet.

Definition at line 318 of file tradewindow.cpp.

References Net::TradeHandler::addItem(), checkItem(), and tradeHandler.

Referenced by Actions::doSit(), ItemAmountWindow::finish(), initTrade(), and InventoryWindow::mouseClicked().

320 {
321  if (check && !checkItem(item))
322  return;
323 
324  tradeHandler->addItem(item, quantity);
325 }
virtual void addItem(const Item *const item, const int amount) const
Definition: tradehandler.h:51
bool checkItem(const Item *const item) const
Net::TradeHandler * tradeHandler
Definition: net.cpp:95

◆ valueChanged()

void TradeWindow::valueChanged ( const SelectionEvent event)
virtual

Updates the labels and makes sure only one item is selected in either my inventory or partner inventory.

Reimplemented from SelectionListener.

Definition at line 327 of file tradewindow.cpp.

References ItemContainer::getSelectedItem(), Event::getSource(), mMyItemContainer, mPartnerItemContainer, and ItemContainer::selectNone().

328 {
329  if ((mMyItemContainer == nullptr) || (mPartnerItemContainer == nullptr))
330  return;
331 
332  /* If an item is selected in one container, make sure no item is selected
333  * in the other container.
334  */
335  if (event.getSource() == mMyItemContainer &&
336  (mMyItemContainer->getSelectedItem() != nullptr))
337  {
339  }
340  else if (mPartnerItemContainer->getSelectedItem() != nullptr)
341  {
343  }
344 }
ItemContainer * mPartnerItemContainer
Definition: tradewindow.h:193
Item * getSelectedItem() const
ItemContainer * mMyItemContainer
Definition: tradewindow.h:192
Widget * getSource() const
Definition: event.h:103

Field Documentation

◆ mAddButton

Button* TradeWindow::mAddButton
private

Definition at line 196 of file tradewindow.h.

Referenced by action(), reset(), and TradeWindow().

◆ mAutoAddAmount

int TradeWindow::mAutoAddAmount
private

Definition at line 206 of file tradewindow.h.

Referenced by addAutoItem(), clear(), and initTrade().

◆ mAutoAddItem

Item* TradeWindow::mAutoAddItem
private

Definition at line 201 of file tradewindow.h.

Referenced by addAutoItem(), clear(), and initTrade().

◆ mAutoAddToNick

std::string TradeWindow::mAutoAddToNick
private

Definition at line 202 of file tradewindow.h.

Referenced by addAutoItem(), addAutoMoney(), clear(), getAutoTradeNick(), and initTrade().

◆ mAutoMoney

int TradeWindow::mAutoMoney
private

Definition at line 205 of file tradewindow.h.

Referenced by addAutoMoney(), clear(), and initTrade().

◆ mGotMaxMoney

int TradeWindow::mGotMaxMoney
private

Definition at line 204 of file tradewindow.h.

Referenced by clear(), reset(), and setMoney().

◆ mGotMoney

int TradeWindow::mGotMoney
private

Definition at line 203 of file tradewindow.h.

Referenced by clear(), reset(), and setMoney().

◆ mMoneyChangeButton

Button* TradeWindow::mMoneyChangeButton
private

Definition at line 198 of file tradewindow.h.

Referenced by action(), reset(), and TradeWindow().

◆ mMoneyField

TextField* TradeWindow::mMoneyField
private

Definition at line 199 of file tradewindow.h.

Referenced by action(), initTrade(), isInpupFocused(), reset(), and TradeWindow().

◆ mMoneyLabel

Label* TradeWindow::mMoneyLabel
private

Definition at line 195 of file tradewindow.h.

Referenced by clear(), reset(), setMoney(), and TradeWindow().

◆ mMyInventory

Inventory* TradeWindow::mMyInventory
private

◆ mMyItemContainer

ItemContainer* TradeWindow::mMyItemContainer
private

Definition at line 192 of file tradewindow.h.

Referenced by TradeWindow(), and valueChanged().

◆ mOkButton

Button* TradeWindow::mOkButton
private

Definition at line 197 of file tradewindow.h.

Referenced by setStatus(), and TradeWindow().

◆ mOkMe

bool TradeWindow::mOkMe
private

Definition at line 209 of file tradewindow.h.

Referenced by receivedOk(), and reset().

◆ mOkOther

bool TradeWindow::mOkOther
private

Definition at line 208 of file tradewindow.h.

Referenced by receivedOk(), and reset().

◆ mPartnerInventory

Inventory* TradeWindow::mPartnerInventory
private

Definition at line 190 of file tradewindow.h.

Referenced by addItem(), addItem2(), changeQuantity(), increaseQuantity(), reset(), and ~TradeWindow().

◆ mPartnerItemContainer

ItemContainer* TradeWindow::mPartnerItemContainer
private

Definition at line 193 of file tradewindow.h.

Referenced by TradeWindow(), and valueChanged().

◆ mStatus

Status TradeWindow::mStatus
private

Definition at line 207 of file tradewindow.h.

Referenced by action(), and setStatus().


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