ManaPlus
inventorywindow.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2018 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
24 
25 #include "configuration.h"
26 
27 #include "being/playerinfo.h"
28 
29 #include "const/sound.h"
30 
31 #include "enums/gui/layouttype.h"
32 
33 #include "input/inputmanager.h"
34 
35 #include "gui/gui.h"
36 
37 #include "gui/fonts/font.h"
38 
40 
41 #include "gui/popups/itempopup.h"
42 #include "gui/popups/popupmenu.h"
43 #include "gui/popups/textpopup.h"
44 
47 #include "gui/windows/npcdialog.h"
50 
51 #include "gui/widgets/button.h"
54 #include "gui/widgets/dropdown.h"
56 #include "gui/widgets/layout.h"
58 #include "gui/widgets/scrollarea.h"
59 #include "gui/widgets/tabstrip.h"
60 #include "gui/widgets/textfield.h"
62 
64 
65 #include "net/npchandler.h"
66 
67 #include "resources/iteminfo.h"
68 
69 #include "resources/db/unitsdb.h"
70 
71 #include "resources/item/item.h"
72 
73 #include "utils/delete2.h"
74 #include "utils/foreach.h"
75 
76 #include "debug.h"
77 
83 
85  Window("Inventory", Modal_false, nullptr, "inventory.xml"),
87  KeyListener(),
91  mInventory(inventory),
92  mItems(new ItemContainer(this, mInventory, 100000,
94  mUseButton(nullptr),
95  mDropButton(nullptr),
96  mOutfitButton(nullptr),
97  mShopButton(nullptr),
98  mCartButton(nullptr),
99  mEquipmentButton(nullptr),
100  mStoreButton(nullptr),
101  mRetrieveButton(nullptr),
102  mInvCloseButton(nullptr),
103  mWeightBar(nullptr),
104  mSlotsBar(new ProgressBar(this, 0.0F, 100, 0,
106  "slotsprogressbar.xml", "slotsprogressbar_fill.xml")),
107  mFilter(nullptr),
108  mSortModel(new SortListModelInv),
109  mSortDropDown(new DropDown(this, mSortModel, false,
110  Modal_false, this, "sort")),
111  mNameFilter(new TextField(this, "", LoseFocusOnTab_true,
112  this, "namefilter", true)),
113  mSortDropDownCell(nullptr),
114  mNameFilterCell(nullptr),
115  mFilterCell(nullptr),
116  mSlotsBarCell(nullptr),
117  mSplit(false),
118  mCompactMode(false)
119 {
122 
123  if (inventory != nullptr)
124  {
125  setCaption(gettext(inventory->getName().c_str()));
126  setWindowName(inventory->getName());
127  switch (inventory->getType())
128  {
131  case InventoryType::Npc:
137  default:
139  "inventorySortOrder"));
140  break;
143  "storageSortOrder"));
144  break;
145  case InventoryType::Cart:
147  "cartSortOrder"));
148  break;
149  };
150  }
151  else
152  {
153  // TRANSLATORS: inventory window name
154  setCaption(_("Inventory"));
155  setWindowName("Inventory");
157  }
158 
159  if ((setupWindow != nullptr) &&
160  (inventory != nullptr) &&
161  inventory->getType() != InventoryType::Storage)
162  {
164  }
165 
166  setResizable(true);
167  setCloseButton(true);
168  setSaveVisible(true);
169  setStickyButtonLock(true);
170 
171  if (mainGraphics->mWidth > 600)
172  setDefaultSize(450, 310, ImagePosition::CENTER, 0, 0);
173  else
174  setDefaultSize(387, 307, ImagePosition::CENTER, 0, 0);
175  setMinWidth(310);
176  setMinHeight(179);
177  addKeyListener(this);
178 
180 
181  const int size = config.getIntValue("fontSize");
182  mFilter = new TabStrip(this, "filter_" + getWindowName(), size + 16, 0);
183  mFilter->addActionListener(this);
184  mFilter->setActionEventId("tag_");
185  mFilter->setSelectable(false);
186 
187  StringVect tags = ItemDB::getTags();
188  const size_t sz = tags.size();
189  for (size_t f = 0; f < sz; f ++)
190  mFilter->addButton(tags[f], tags[f], false);
191 
192  if (mInventory == nullptr)
193  {
194  invInstances.push_back(this);
195  return;
196  }
197 
198  ScrollArea *const invenScroll = new ScrollArea(this, mItems,
199  fromBool(getOptionBool("showbackground", false), Opaque),
200  "inventory_background.xml");
202 
203  switch (mInventory->getType())
204  {
206  {
207  // TRANSLATORS: inventory button
208  const std::string equip = _("Equip");
209  // TRANSLATORS: inventory button
210  const std::string use = _("Use");
211  // TRANSLATORS: inventory button
212  const std::string unequip = _("Unequip");
213 
214  std::string longestUseString = getFont()->getWidth(equip) >
215  getFont()->getWidth(use) ? equip : use;
216 
217  if (getFont()->getWidth(longestUseString) <
218  getFont()->getWidth(unequip))
219  {
220  longestUseString = unequip;
221  }
222 
223  mUseButton = new Button(this,
224  longestUseString,
225  "use",
226  BUTTON_SKIN,
227  this);
228  mDropButton = new Button(this,
229  // TRANSLATORS: inventory button
230  _("Drop..."),
231  "drop",
232  BUTTON_SKIN,
233  this);
234  mOutfitButton = new Button(this,
235  // TRANSLATORS: inventory outfits button
236  _("O"),
237  "outfit",
238  BUTTON_SKIN,
239  this);
240  mCartButton = new Button(this,
241  // TRANSLATORS: inventory cart button
242  _("C"),
243  "cart",
244  BUTTON_SKIN,
245  this);
246  mShopButton = new Button(this,
247  // TRANSLATORS: inventory shop button
248  _("S"),
249  "shop",
250  BUTTON_SKIN,
251  this);
252  mEquipmentButton = new Button(this,
253  // TRANSLATORS: inventory equipment button
254  _("E"),
255  "equipment",
256  BUTTON_SKIN,
257  this);
258  mWeightBar = new ProgressBar(this, 0.0F, 100, 0,
260  "weightprogressbar.xml", "weightprogressbar_fill.xml");
263 
264  // TRANSLATORS: outfits button tooltip
265  mOutfitButton->setDescription(_("Outfits"));
266  // TRANSLATORS: cart button tooltip
267  mCartButton->setDescription(_("Cart"));
268  // TRANSLATORS: shop button tooltip
269  mShopButton->setDescription(_("Shop"));
270  // TRANSLATORS: equipment button tooltip
271  mEquipmentButton->setDescription(_("Equipment"));
272 
273  place(0, 0, mWeightBar, 4, 1);
274  mSlotsBarCell = &place(4, 0, mSlotsBar, 4, 1);
275  mSortDropDownCell = &place(8, 0, mSortDropDown, 3, 1);
276 
277  mFilterCell = &place(0, 1, mFilter, 10, 1).setPadding(3);
278  mNameFilterCell = &place(8, 1, mNameFilter, 3, 1);
279 
280  place(0, 2, invenScroll, 11, 1).setPadding(3);
281  place(0, 3, mUseButton, 1, 1);
282  place(1, 3, mDropButton, 1, 1);
283  ContainerPlacer placer = getPlacer(10, 3);
284  placer(0, 0, mShopButton, 1, 1);
285  placer(1, 0, mOutfitButton, 1, 1);
286  placer(2, 0, mCartButton, 1, 1);
287  placer(3, 0, mEquipmentButton, 1, 1);
288 
289  updateWeight();
290  break;
291  }
292 
294  {
295  mStoreButton = new Button(this,
296  // TRANSLATORS: storage button
297  _("Store"),
298  "store",
299  BUTTON_SKIN,
300  this);
301  mRetrieveButton = new Button(this,
302  // TRANSLATORS: storage button
303  _("Retrieve"),
304  "retrieve",
305  BUTTON_SKIN,
306  this);
307  mInvCloseButton = new Button(this,
308  // TRANSLATORS: storage button
309  _("Close"),
310  "close",
311  BUTTON_SKIN,
312  this);
313 
314  mSlotsBarCell = &place(0, 0, mSlotsBar, 6, 1);
315  mSortDropDownCell = &place(6, 0, mSortDropDown, 1, 1);
316 
317  mFilterCell = &place(0, 1, mFilter, 7, 1).setPadding(3);
318  mNameFilterCell = &place(6, 1, mNameFilter, 1, 1);
319 
320  place(0, 2, invenScroll, 7, 4);
321  place(0, 6, mStoreButton, 1, 1);
322  place(1, 6, mRetrieveButton, 1, 1);
323  place(6, 6, mInvCloseButton, 1, 1);
324  break;
325  }
326 
327  case InventoryType::Cart:
328  {
329  mStoreButton = new Button(this,
330  // TRANSLATORS: storage button
331  _("Store"),
332  "store",
333  BUTTON_SKIN,
334  this);
335  mRetrieveButton = new Button(this,
336  // TRANSLATORS: storage button
337  _("Retrieve"),
338  "retrieve",
339  BUTTON_SKIN,
340  this);
341  mInvCloseButton = new Button(this,
342  // TRANSLATORS: storage button
343  _("Close"),
344  "close",
345  BUTTON_SKIN,
346  this);
347 
348  mWeightBar = new ProgressBar(this, 0.0F, 100, 0,
350  "weightprogressbar.xml", "weightprogressbar_fill.xml");
353 
354  mSlotsBarCell = &place(3, 0, mSlotsBar, 3, 1);
355  mSortDropDownCell = &place(6, 0, mSortDropDown, 1, 1);
356 
357  mFilterCell = &place(0, 1, mFilter, 7, 1).setPadding(3);
358  mNameFilterCell = &place(6, 1, mNameFilter, 1, 1);
359 
360  place(0, 0, mWeightBar, 3, 1);
361  place(0, 2, invenScroll, 7, 4);
362  place(0, 6, mStoreButton, 1, 1);
363  place(1, 6, mRetrieveButton, 1, 1);
364  place(6, 6, mInvCloseButton, 1, 1);
365  break;
366  }
367 
368  default:
370  case InventoryType::Npc:
376  break;
377  };
378 
379  Layout &layout = getLayout();
380  layout.setRowHeight(2, LayoutType::SET);
381 
383 
384  invInstances.push_back(this);
385 
386  if (inventory->isMainInventory())
387  {
389  }
390  else
391  {
392  if (!invInstances.empty())
393  invInstances.front()->updateDropButton();
394  }
395 
396  loadWindowState();
397  enableVisibleSound(true);
398 }
399 
401 {
404 
406  widgetResized(Event(nullptr));
407  if (mInventory != nullptr &&
409  {
411  }
412 }
413 
415 {
416  invInstances.remove(this);
417  if (mInventory != nullptr)
419  if (!invInstances.empty())
420  invInstances.front()->updateDropButton();
421 
422  mSortDropDown->hideDrop(false);
424 }
425 
427 {
428  if (mInventory != nullptr)
429  {
430  switch (mInventory->getType())
431  {
434  case InventoryType::Npc:
440  default:
441  config.setValue("inventorySortOrder",
443  break;
445  config.setValue("storageSortOrder",
447  break;
448  case InventoryType::Cart:
449  config.setValue("cartSortOrder",
451  break;
452  };
453  }
454 }
455 
457 {
458  const std::string &eventId = event.getId();
459  if (eventId == "outfit")
460  {
462  }
463  else if (eventId == "shop")
464  {
466  }
467  else if (eventId == "equipment")
468  {
470  }
471  else if (eventId == "cart")
472  {
474  }
475  else if (eventId == "close")
476  {
477  close();
478  }
479  else if (eventId == "store")
480  {
481  if (inventoryWindow == nullptr || !inventoryWindow->isWindowVisible())
482  return;
483 
484  Item *const item = inventoryWindow->getSelectedItem();
485 
486  if (item == nullptr)
487  return;
488 
489  if (storageWindow != nullptr)
490  {
492  this,
493  item,
494  0,
495  0);
496  }
497  else if ((cartWindow != nullptr) && cartWindow->isWindowVisible())
498  {
500  this,
501  item,
502  0,
503  0);
504  }
505  }
506  else if (eventId == "sort")
507  {
509  storeSortOrder();
510  return;
511  }
512  else if (eventId == "namefilter")
513  {
515  mItems->updateMatrix();
516  }
517  else if (eventId.find("tag_") == 0u)
518  {
519  std::string tagName = event.getId().substr(4);
520  mItems->setFilter(ItemDB::getTagId(tagName));
521  return;
522  }
523 
524  Item *const item = mItems->getSelectedItem();
525 
526  if (item == nullptr)
527  return;
528 
529  if (eventId == "use")
530  {
532  }
533  if (eventId == "equip")
534  {
536  }
537  else if (eventId == "drop")
538  {
539  if (isStorageActive())
540  {
542  item->getInvIndex(),
543  item->getQuantity(),
545  }
546  else if ((cartWindow != nullptr) && cartWindow->isWindowVisible())
547  {
549  item->getInvIndex(),
550  item->getQuantity(),
552  }
553  else
554  {
555  if (PlayerInfo::isItemProtected(item->getId()))
556  return;
557 
559  {
560  PlayerInfo::dropItem(item, item->getQuantity(), Sfx_true);
561  }
562  else
563  {
565  this,
566  item,
567  0,
568  0);
569  }
570  }
571  }
572  else if (eventId == "split")
573  {
575  this,
576  item,
577  item->getQuantity() - 1,
578  9);
579  }
580  else if (eventId == "retrieve")
581  {
582  if (storageWindow != nullptr)
583  {
585  this,
586  item,
587  0,
588  0);
589  }
590  else if ((cartWindow != nullptr) && cartWindow->isWindowVisible())
591  {
593  this,
594  item,
595  0,
596  0);
597  }
598  }
599 }
600 
602 {
603  return mItems->getSelectedItem();
604 }
605 
607 {
608  mItems->selectNone();
609 }
610 
612 {
613  Window::widgetHidden(event);
614  if (itemPopup != nullptr)
616 }
617 
619 {
620  Window::mouseClicked(event);
621 
622  const int clicks = event.getClickCount();
623 
624  if (clicks == 2 && (gui != nullptr))
625  gui->resetClickCount();
626 
627  const bool mod = (isStorageActive() &&
629 
630  const bool mod2 = (tradeWindow != nullptr &&
633 
634  if (mInventory != nullptr)
635  {
636  if (!mod && !mod2 && event.getButton() == MouseButton::RIGHT)
637  {
638  Item *const item = mItems->getSelectedItem();
639 
640  if (item == nullptr)
641  return;
642 
643  /* Convert relative to the window coordinates to absolute screen
644  * coordinates.
645  */
646  const int mx = event.getX() + getX();
647  const int my = event.getY() + getY();
648 
649  if (popupMenu != nullptr)
650  {
651  popupMenu->showPopup(this,
652  mx, my,
653  item,
654  mInventory->getType());
655  }
656  }
657  }
658  else
659  {
660  return;
661  }
662 
663  if (event.getButton() == MouseButton::LEFT ||
664  event.getButton() == MouseButton::RIGHT)
665  {
666  Item *const item = mItems->getSelectedItem();
667 
668  if (item == nullptr)
669  return;
670 
671  if (mod)
672  {
674  {
675  if (event.getButton() == MouseButton::RIGHT)
676  {
679  inventoryWindow,
680  item,
681  0,
682  0);
683  }
684  else
685  {
687  item->getInvIndex(),
688  item->getQuantity(),
690  }
691  }
692  else
693  {
694  if (event.getButton() == MouseButton::RIGHT)
695  {
698  inventoryWindow,
699  item,
700  0,
701  0);
702  }
703  else
704  {
706  item->getInvIndex(),
707  item->getQuantity(),
709  }
710  }
711  }
712  else if (mod2 && mInventory->isMainInventory())
713  {
714  if (PlayerInfo::isItemProtected(item->getId()))
715  return;
716  if (event.getButton() == MouseButton::RIGHT)
717  {
719  tradeWindow,
720  item,
721  0,
722  0);
723  }
724  else
725  {
726  if (tradeWindow != nullptr)
727  tradeWindow->tradeItem(item, item->getQuantity(), true);
728  }
729  }
730  else if (clicks == 2)
731  {
733  {
734  if (isStorageActive())
735  {
738  inventoryWindow,
739  item,
740  0,
741  0);
742  }
743  else if (tradeWindow != nullptr &&
745  {
746  if (PlayerInfo::isItemProtected(item->getId()))
747  return;
750  tradeWindow,
751  item,
752  0,
753  0);
754  }
755  else
756  {
758  }
759  }
760  else
761  {
762  if (isStorageActive())
763  {
766  inventoryWindow,
767  item,
768  0,
769  0);
770  }
771  }
772  }
773  }
774 }
775 
777 {
778  Window::mouseMoved(event);
779  if (textPopup == nullptr)
780  return;
781 
782  const Widget *const src = event.getSource();
783  if (src == nullptr)
784  {
785  textPopup->hide();
786  return;
787  }
788  const int x = event.getX();
789  const int y = event.getY();
790  const Rect &rect = mDimension;
791  if (src == mSlotsBar || src == mWeightBar)
792  {
793  // TRANSLATORS: money label
794  textPopup->show(rect.x + x, rect.y + y, strprintf(_("Money: %s"),
796  Attributes::MONEY)).c_str()));
797  }
798  else
799  {
800  const Button *const btn = dynamic_cast<const Button *>(src);
801  if (btn == nullptr)
802  {
803  textPopup->hide();
804  return;
805  }
806  const std::string text = btn->getDescription();
807  if (!text.empty())
808  textPopup->show(x + rect.x, y + rect.y, text);
809  }
810 }
811 
813 {
814  textPopup->hide();
815 }
816 
818 {
819  if (event.getActionId() == InputAction::GUI_MOD)
820  mSplit = true;
821 }
822 
824 {
825  if (event.getActionId() == InputAction::GUI_MOD)
826  mSplit = false;
827 }
828 
830 {
831  if ((mInventory == nullptr) || !mInventory->isMainInventory())
832  return;
833 
834  Item *const item = mItems->getSelectedItem();
835 
836  if (mSplit && (item != nullptr) && inventoryHandler->
837  canSplit(mItems->getSelectedItem()))
838  {
840  this,
841  item,
842  item->getQuantity() - 1,
843  0);
844  }
845  updateButtons(item);
846 }
847 
849 {
850  if ((mInventory == nullptr) || !mInventory->isMainInventory())
851  return;
852 
853  const Item *const selectedItem = mItems->getSelectedItem();
854  if ((item != nullptr) && selectedItem != item)
855  return;
856 
857  if (item == nullptr)
858  item = selectedItem;
859 
860  if ((item == nullptr) || item->getQuantity() == 0)
861  {
862  if (mUseButton != nullptr)
863  mUseButton->setEnabled(false);
864  if (mDropButton != nullptr)
865  mDropButton->setEnabled(false);
866  return;
867  }
868 
869  if (mDropButton != nullptr)
870  mDropButton->setEnabled(true);
871 
872  if (mUseButton != nullptr)
873  {
874  const ItemInfo &info = item->getInfo();
875  const std::string &str = (item->isEquipment() == Equipm_true
876  && item->isEquipped() == Equipped_true)
877  ? info.getUseButton2() : info.getUseButton();
878  if (str.empty())
879  {
880  mUseButton->setEnabled(false);
881  // TRANSLATORS: default use button name
882  mUseButton->setCaption(_("Use"));
883  }
884  else
885  {
886  mUseButton->setEnabled(true);
887  mUseButton->setCaption(str);
888  }
889  }
890 
892 }
893 
895 {
896  if (mInventory == nullptr)
897  {
898  Window::close();
899  return;
900  }
901 
902  switch (mInventory->getType())
903  {
905  case InventoryType::Cart:
907  break;
908 
910  if (inventoryHandler != nullptr)
911  {
914  }
915  scheduleDelete();
916  break;
917 
918  default:
920  case InventoryType::Npc:
926  break;
927  }
928 }
929 
931 {
932  if ((mInventory == nullptr) || (mWeightBar == nullptr))
933  return;
934  const InventoryTypeT type = mInventory->getType();
935  if (type != InventoryType::Inventory &&
936  type != InventoryType::Cart)
937  {
938  return;
939  }
940 
941  const bool isInv = type == InventoryType::Inventory;
942  const int total = PlayerInfo::getAttribute(isInv
944  const int max = PlayerInfo::getAttribute(isInv
946 
947  if (max <= 0)
948  return;
949 
950  // Adjust progress bar
951  mWeightBar->setProgress(static_cast<float>(total)
952  / static_cast<float>(max));
953  mWeightBar->setText(strprintf("%s/%s",
954  UnitsDb::formatWeight(total).c_str(),
955  UnitsDb::formatWeight(max).c_str()));
956 }
957 
958 void InventoryWindow::slotsChanged(const Inventory *const inventory)
959 {
960  if (inventory == mInventory)
961  {
962  const int usedSlots = mInventory->getNumberOfSlotsUsed();
963  const int maxSlots = mInventory->getSize();
964 
965  if (maxSlots != 0)
966  {
967  mSlotsBar->setProgress(static_cast<float>(usedSlots)
968  / static_cast<float>(maxSlots));
969  }
970 
971  mSlotsBar->setText(strprintf("%d/%d", usedSlots, maxSlots));
972  mItems->updateMatrix();
973  }
974 }
975 
977 {
978  if (mDropButton == nullptr)
979  return;
980 
981  if (isStorageActive() ||
982  (cartWindow != nullptr && cartWindow->isWindowVisible()))
983  {
984  // TRANSLATORS: inventory button
985  mDropButton->setCaption(_("Store"));
986  }
987  else
988  {
989  const Item *const item = mItems->getSelectedItem();
990  if ((item != nullptr) && item->getQuantity() > 1)
991  {
992  // TRANSLATORS: inventory button
993  mDropButton->setCaption(_("Drop..."));
994  }
995  else
996  {
997  // TRANSLATORS: inventory button
998  mDropButton->setCaption(_("Drop"));
999  }
1000  }
1001 }
1002 
1004 {
1005  return (mNameFilter != nullptr) && mNameFilter->isFocused();
1006 }
1007 
1009 {
1010  FOR_EACH (WindowList::const_iterator, it, invInstances)
1011  {
1012  if (((*it) != nullptr) && (*it)->isInputFocused())
1013  return true;
1014  }
1015  return false;
1016 }
1017 
1019 {
1020  std::set<Widget*> list;
1021  FOR_EACH (WindowList::const_iterator, it, invInstances)
1022  {
1023  if (((*it) != nullptr) && (*it)->isWindowVisible())
1024  list.insert(*it);
1025  }
1026  return dynamic_cast<InventoryWindow*>(
1028 }
1029 
1031 {
1032  const InventoryWindow *const window = getFirstVisible();
1033  if (window != nullptr)
1034  window->mFilter->nextTab();
1035 }
1036 
1038 {
1039  const InventoryWindow *const window = getFirstVisible();
1040  if (window != nullptr)
1041  window->mFilter->prevTab();
1042 }
1043 
1045 {
1046  Window::widgetResized(event);
1047 
1048  if (mInventory == nullptr)
1049  return;
1050  const InventoryTypeT type = mInventory->getType();
1051  if (type != InventoryType::Inventory &&
1052  type != InventoryType::Cart)
1053  {
1054  return;
1055  }
1056 
1057  if (getWidth() < 600)
1058  {
1059  if (!mCompactMode)
1060  {
1064  mCompactMode = true;
1065  }
1066  }
1067  else if (mCompactMode)
1068  {
1072  mCompactMode = false;
1073  }
1074 }
1075 
1077 {
1078  if (visible == Visible_false)
1079  mSortDropDown->hideDrop(true);
1080  Window::setVisible(visible);
1081 }
1082 
1084 {
1085  if (mInventory != nullptr)
1086  {
1088  if (mItems != nullptr)
1090  }
1091  mInventory = nullptr;
1092 }
1093 
1095  const int64_t oldVal A_UNUSED,
1096  const int64_t newVal A_UNUSED)
1097 {
1098  if (id == Attributes::TOTAL_WEIGHT
1099  || id == Attributes::MAX_WEIGHT
1101  || id == Attributes::CART_MAX_WEIGHT)
1102  {
1103  updateWeight();
1104  }
1105 }
1106 
1107 void InventoryWindow::combineItems(const int index1,
1108  const int index2)
1109 {
1110  if (mInventory == nullptr)
1111  return;
1112  const Item *item1 = mInventory->getItem(index1);
1113  if (item1 == nullptr)
1114  return;
1115  const Item *item2 = mInventory->getItem(index2);
1116  if (item2 == nullptr)
1117  return;
1118 
1119  if (item1->getType() != ItemType::Card)
1120  {
1121  const Item *tmpItem = item1;
1122  item1 = item2;
1123  item2 = tmpItem;
1124  }
1125 
1127  // TRANSLATORS: question dialog title
1128  _("Insert card request"),
1129  // TRANSLATORS: question dialog message
1130  strprintf(_("Insert %s into %s?"),
1131  item1->getName().c_str(),
1132  item2->getName().c_str()),
1133  SOUND_REQUEST,
1134  false,
1135  Modal_true,
1136  nullptr);
1137  insertCardListener.itemIndex = item2->getInvIndex();
1138  insertCardListener.cardIndex = item1->getInvIndex();
1139  confirmDlg->addActionListener(&insertCardListener);
1140 }
1141 
1142 void InventoryWindow::moveItemToCraft(const int craftSlot)
1143 {
1144  if (npcHandler == nullptr)
1145  return;
1146 
1147  Item *const item = mItems->getSelectedItem();
1148  if (item == nullptr)
1149  return;
1150 
1151  NpcDialog *const dialog = npcHandler->getCurrentNpcDialog();
1152  if ((dialog != nullptr) &&
1154  {
1155  if (item->getQuantity() > 1
1157  {
1160  item,
1161  0,
1162  craftSlot);
1163  }
1164  else
1165  {
1166  dialog->addCraftItem(item, 1, craftSlot);
1167  }
1168  }
1169 }
int getInvIndex() const
Definition: item.h:164
Font * getFont() const
Definition: widget.cpp:330
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
static bool isStorageActive()
void setDefaultSize()
Definition: window.cpp:1193
void unsetInventory()
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1379
void show(const int x, const int y, const std::string &str1)
Definition: textpopup.h:56
#define _(s)
Definition: gettext.h:34
virtual void moveItem2(const InventoryTypeT source, const int slot, const int amount, const InventoryTypeT destination) const =0
std::string getName() const
Definition: inventory.cpp:350
int getWidth() const
Definition: widget.h:220
int getNumberOfSlotsUsed() const
Definition: inventory.h:163
const bool LoseFocusOnTab_true
bool getOptionBool(const std::string &name, const bool def) const
Definition: window.cpp:1461
TradeWindow * tradeWindow
Definition: tradewindow.cpp:64
static void prevTab()
const StringVect & getTags()
Definition: itemdb.cpp:749
Gui * gui
Definition: gui.cpp:110
void action(const ActionEvent &event)
const bool Visible_true
Definition: visible.h:29
void storeSortOrder() const
Item * getSelectedItem() const
NpcInputStateT getInputState()
Definition: npcdialog.h:236
void loadWindowState()
Definition: window.cpp:1082
WindowContainer * windowContainer
const bool ShowEmptyRows_false
Definition: showemptyrows.h:29
virtual void addButton(const std::string &text, const std::string &tag, const bool pressed)
Definition: widgetgroup.cpp:41
void keyPressed(KeyEvent &event)
int getY() const
Definition: widget.h:287
TextField * mNameFilter
void hideDrop(bool event)
Definition: dropdown.cpp:378
InventoryType ::T InventoryTypeT
Definition: inventorytype.h:41
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
void setVisible(Visible visible)
Definition: widget.cpp:224
Equipped isEquipped() const
Definition: item.h:128
std::string formatWeight(const int value)
Definition: unitsdb.cpp:351
MouseButtonT getButton() const
Definition: mouseevent.h:115
Widget * findFirstWidget(const std::set< Widget *> &list)
Definition: rect.h:72
void widgetHidden(const Event &event)
void setMinWidth(const int width)
Definition: window.cpp:586
Definition: window.h:98
int mWidth
Definition: graphics.h:483
std::list< InventoryWindow * > WindowList
Definition: button.h:96
Configuration config
const bool Sfx_true
Definition: sfx.h:29
static void showWindow(const ItemAmountWindowUsageT usage, Window *const parent, Item *const item, int maxRange, const int tag)
static const std::string SOUND_REQUEST
Definition: sound.h:28
void updateButtons(const Item *item)
void mouseMoved(MouseEvent &event)
Definition: window.cpp:962
std::string formatCurrency(const int value)
Definition: unitsdb.cpp:323
InputActionT getActionId() const
Definition: keyevent.h:126
LayoutCell * mSlotsBarCell
int getIntValue(const std::string &key) const
ItemContainer * mItems
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
void mouseMoved(MouseEvent &event)
std::vector< std::string > StringVect
Definition: stringvector.h:28
#define delete2(var)
Definition: delete2.h:24
SortListModelInv * mSortModel
const bool Equipped_true
Definition: equipped.h:29
InsertCardListener insertCardListener
void setVisible(Visible visible)
InventoryWindow * inventoryWindow
void nextTab()
Definition: tabstrip.cpp:89
bool isActionActive(const InputActionT index) const
virtual bool isFocused() const
Definition: widget.cpp:183
void registerWindowForReset(Window *const window)
const std::string & getUseButton() const
Definition: iteminfo.h:117
void setName(const std::string &str)
ProgressBar * mWeightBar
InventoryWindow(Inventory *const inventory)
bool isInputFocused() const
void setSelectable(const bool selectable)
Definition: widget.h:947
virtual void close()
Definition: window.cpp:897
void widgetHidden(const Event &event)
Definition: window.cpp:720
#define new
Definition: debug_new.h:147
virtual NpcDialog * getCurrentNpcDialog() const =0
int x
Definition: rect.h:208
int getTagId(const std::string &tagName)
Definition: itemdb.cpp:754
void widgetResized(const Event &event)
Definition: window.cpp:650
void hide()
Definition: popup.cpp:262
void useEquipItem(const Item *const item, const int16_t useType, const Sfx sfx)
Definition: playerinfo.cpp:259
void setCaption(const std::string &caption)
Definition: button.h:213
InventoryWindow * storageWindow
std::string getDescription() const
Definition: button.h:167
const std::string & getUseButton2() const
Definition: iteminfo.h:123
void attributeChanged(const AttributesT id, const int64_t oldVal, const int64_t newVal)
void slotsChanged(const Inventory *const inventory)
const std::string BUTTON_SKIN
Definition: button.h:88
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
Inventory * mInventory
void prevTab()
Definition: tabstrip.cpp:107
const bool Equipm_true
Definition: equipm.h:29
void setType(int t)
Definition: layoutcell.h:133
const bool Visible_false
Definition: visible.h:29
int getQuantity() const
Definition: item.h:104
#define fromBool(val, name)
Definition: booldefines.h:48
Button * mRetrieveButton
static InventoryWindow * getFirstVisible()
bool info(InputEvent &event)
Definition: commands.cpp:56
void useEquipItem2(const Item *const item, const int16_t useType, const Sfx sfx)
Definition: playerinfo.cpp:310
virtual void forgotStorage() const =0
static bool isAnyInputFocused()
int y
Definition: rect.h:213
bool isMainInventory() const
Definition: inventory.h:178
PopupMenu * popupMenu
Definition: popupmenu.cpp:102
void combineItems(const int index1, const int index2)
void resetClickCount()
Definition: gui.cpp:978
Definition: item.h:48
#define nullptr
Definition: localconsts.h:44
Graphics * mainGraphics
Definition: graphics.cpp:108
bool isWindowVisible() const
Definition: window.h:483
void setCloseButton(const bool flag)
Definition: window.cpp:744
const ItemInfo & getInfo() const
Definition: item.h:170
void moveItemToCraft(const int craftSlot)
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:271
TabStrip * mFilter
virtual void closeStorage() const =0
void enableVisibleSound(bool b)
Definition: window.h:480
void widgetResized(const Event &event)
const std::string & getWindowName() const
Definition: window.h:360
void setMinHeight(const int height)
Definition: window.cpp:599
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1386
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:85
void setEnabled(const bool enabled)
Definition: widget.h:351
LayoutCell & setPadding(int p)
Definition: layoutcell.h:59
void setText(const std::string &str)
Inventory * mInventory
Definition: playerinfo.cpp:57
virtual void scheduleDelete()
Definition: window.cpp:826
Layout & getLayout()
Definition: window.cpp:1360
void tradeItem(const Item *const item, const int quantity, const bool check) const
std::string getName() const
Definition: item.cpp:139
void setSaveVisible(const bool save)
Definition: window.h:299
Button * mOutfitButton
int getX() const
Definition: widget.h:268
void addSelectionListener(SelectionListener *listener)
bool isItemProtected(const int id)
Definition: playerinfo.cpp:511
LayoutCell * mSortDropDownCell
int getId() const
Definition: item.h:80
#define A_UNUSED
Definition: localconsts.h:151
static void nextTab()
virtual void setVisible(Visible visible)
Definition: window.cpp:773
InventoryWindow * cartWindow
Item * getSelectedItem() const
ConfirmDialog * confirmDlg
Definition: traderecv.cpp:48
Definition: widget.h:97
ProgressBar * mSlotsBar
int getWidth(const std::string &text) const
Definition: font.cpp:333
Definition: event.h:77
void valueChanged(const SelectionEvent &event)
const bool ForceQuantity_false
Definition: forcequantity.h:29
Attributes ::T AttributesT
Definition: attributes.h:117
ItemTypeT getType() const
Definition: item.h:224
Equipm isEquipment() const
Definition: item.h:116
Button * mEquipmentButton
int getWidth() const
Definition: layoutcell.h:136
void setSortType(const int sortType)
static WindowList invInstances
void keyReleased(KeyEvent &event)
Button * mInvCloseButton
void setResizable(const bool resize)
Definition: window.cpp:622
virtual void mouseClicked(MouseEvent &event)
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:767
Net::NpcHandler * npcHandler
Definition: net.cpp:89
void setWidth(const int w)
Definition: layoutcell.h:142
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
InputManager inputManager
void addInventoyListener(InventoryListener *const listener)
Definition: inventory.cpp:301
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
ItemPopup * itemPopup
Definition: itempopup.cpp:63
void setDescription(const std::string &text)
Definition: button.h:164
Item * getItem(const int index) const
Definition: inventory.cpp:82
LayoutCell * mNameFilterCell
Definition: layout.h:43
void addCraftItem(Item *const item, const int amount, const int slot)
Definition: npcdialog.cpp:1381
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:100
Rect mDimension
Definition: widget.h:1100
void setCaption(const std::string &caption)
Definition: window.h:530
void setColor(const Color &color1, const Color &color2)
InventoryTypeT getType() const
Definition: inventory.h:175
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:127
LayoutCell * mFilterCell
void setSelected(int selected)
Definition: dropdown.cpp:514
void setValue(const std::string &key, const std::string &value)
void executeAction(const InputActionT keyNum)
void showPopup(const int x, const int y, const Being *const being)
Definition: popupmenu.cpp:202
void setFilter(const int tag)
const std::string & getText() const
Definition: textfield.h:223
int getSelected() const
Definition: dropdown.cpp:509
void mouseClicked(MouseEvent &event)
void setProgress(const float progress)
void postInit()
Definition: window.cpp:248
void dropItem(const Item *const item, const int amount, const Sfx sfx)
Definition: playerinfo.cpp:351
TextPopup * textPopup
Definition: textpopup.cpp:32
DropDown * mSortDropDown
void mouseExited(MouseEvent &event)
void setWindowName(const std::string &name)
Definition: window.h:354
unsigned getSize() const
Definition: inventory.h:75
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)
void removeInventoyListener(InventoryListener *const listener)
Definition: inventory.cpp:306