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, longestUseString, "use", this);
224  // TRANSLATORS: inventory button
225  mDropButton = new Button(this, _("Drop..."), "drop", this);
226  // TRANSLATORS: inventory outfits button
227  mOutfitButton = new Button(this, _("O"), "outfit", this);
228  // TRANSLATORS: inventory cart button
229  mCartButton = new Button(this, _("C"), "cart", this);
230  // TRANSLATORS: inventory shop button
231  mShopButton = new Button(this, _("S"), "shop", this);
232  // TRANSLATORS: inventory equipment button
233  mEquipmentButton = new Button(this, _("E"), "equipment", this);
234  mWeightBar = new ProgressBar(this, 0.0F, 100, 0,
236  "weightprogressbar.xml", "weightprogressbar_fill.xml");
239 
240  // TRANSLATORS: outfits button tooltip
241  mOutfitButton->setDescription(_("Outfits"));
242  // TRANSLATORS: cart button tooltip
243  mCartButton->setDescription(_("Cart"));
244  // TRANSLATORS: shop button tooltip
245  mShopButton->setDescription(_("Shop"));
246  // TRANSLATORS: equipment button tooltip
247  mEquipmentButton->setDescription(_("Equipment"));
248 
249  place(0, 0, mWeightBar, 4, 1);
250  mSlotsBarCell = &place(4, 0, mSlotsBar, 4, 1);
251  mSortDropDownCell = &place(8, 0, mSortDropDown, 3, 1);
252 
253  mFilterCell = &place(0, 1, mFilter, 10, 1).setPadding(3);
254  mNameFilterCell = &place(8, 1, mNameFilter, 3, 1);
255 
256  place(0, 2, invenScroll, 11, 1).setPadding(3);
257  place(0, 3, mUseButton, 1, 1);
258  place(1, 3, mDropButton, 1, 1);
259  ContainerPlacer placer = getPlacer(10, 3);
260  placer(0, 0, mShopButton, 1, 1);
261  placer(1, 0, mOutfitButton, 1, 1);
262  placer(2, 0, mCartButton, 1, 1);
263  placer(3, 0, mEquipmentButton, 1, 1);
264 
265  updateWeight();
266  break;
267  }
268 
270  {
271  // TRANSLATORS: storage button
272  mStoreButton = new Button(this, _("Store"), "store", this);
273  // TRANSLATORS: storage button
274  mRetrieveButton = new Button(this, _("Retrieve"),
275  "retrieve", this);
276  // TRANSLATORS: storage button
277  mInvCloseButton = new Button(this, _("Close"), "close", this);
278 
279  mSlotsBarCell = &place(0, 0, mSlotsBar, 6, 1);
280  mSortDropDownCell = &place(6, 0, mSortDropDown, 1, 1);
281 
282  mFilterCell = &place(0, 1, mFilter, 7, 1).setPadding(3);
283  mNameFilterCell = &place(6, 1, mNameFilter, 1, 1);
284 
285  place(0, 2, invenScroll, 7, 4);
286  place(0, 6, mStoreButton, 1, 1);
287  place(1, 6, mRetrieveButton, 1, 1);
288  place(6, 6, mInvCloseButton, 1, 1);
289  break;
290  }
291 
292  case InventoryType::Cart:
293  {
294  // TRANSLATORS: storage button
295  mStoreButton = new Button(this, _("Store"), "store", this);
296  // TRANSLATORS: storage button
297  mRetrieveButton = new Button(this, _("Retrieve"),
298  "retrieve", this);
299  // TRANSLATORS: storage button
300  mInvCloseButton = new Button(this, _("Close"), "close", this);
301 
302  mWeightBar = new ProgressBar(this, 0.0F, 100, 0,
304  "weightprogressbar.xml", "weightprogressbar_fill.xml");
307 
308  mSlotsBarCell = &place(3, 0, mSlotsBar, 3, 1);
309  mSortDropDownCell = &place(6, 0, mSortDropDown, 1, 1);
310 
311  mFilterCell = &place(0, 1, mFilter, 7, 1).setPadding(3);
312  mNameFilterCell = &place(6, 1, mNameFilter, 1, 1);
313 
314  place(0, 0, mWeightBar, 3, 1);
315  place(0, 2, invenScroll, 7, 4);
316  place(0, 6, mStoreButton, 1, 1);
317  place(1, 6, mRetrieveButton, 1, 1);
318  place(6, 6, mInvCloseButton, 1, 1);
319  break;
320  }
321 
322  default:
324  case InventoryType::Npc:
330  break;
331  };
332 
333  Layout &layout = getLayout();
334  layout.setRowHeight(2, LayoutType::SET);
335 
337 
338  invInstances.push_back(this);
339 
340  if (inventory->isMainInventory())
341  {
343  }
344  else
345  {
346  if (!invInstances.empty())
347  invInstances.front()->updateDropButton();
348  }
349 
350  loadWindowState();
351  enableVisibleSound(true);
352 }
353 
355 {
358 
360  widgetResized(Event(nullptr));
361  if (mInventory != nullptr &&
363  {
365  }
366 }
367 
369 {
370  invInstances.remove(this);
371  if (mInventory != nullptr)
373  if (!invInstances.empty())
374  invInstances.front()->updateDropButton();
375 
376  mSortDropDown->hideDrop(false);
378 }
379 
381 {
382  if (mInventory != nullptr)
383  {
384  switch (mInventory->getType())
385  {
388  case InventoryType::Npc:
394  default:
395  config.setValue("inventorySortOrder",
397  break;
399  config.setValue("storageSortOrder",
401  break;
402  case InventoryType::Cart:
403  config.setValue("cartSortOrder",
405  break;
406  };
407  }
408 }
409 
411 {
412  const std::string &eventId = event.getId();
413  if (eventId == "outfit")
414  {
416  }
417  else if (eventId == "shop")
418  {
420  }
421  else if (eventId == "equipment")
422  {
424  }
425  else if (eventId == "cart")
426  {
428  }
429  else if (eventId == "close")
430  {
431  close();
432  }
433  else if (eventId == "store")
434  {
435  if (inventoryWindow == nullptr || !inventoryWindow->isWindowVisible())
436  return;
437 
438  Item *const item = inventoryWindow->getSelectedItem();
439 
440  if (item == nullptr)
441  return;
442 
443  if (storageWindow != nullptr)
444  {
446  this,
447  item,
448  0,
449  0);
450  }
451  else if ((cartWindow != nullptr) && cartWindow->isWindowVisible())
452  {
454  this,
455  item,
456  0,
457  0);
458  }
459  }
460  else if (eventId == "sort")
461  {
463  storeSortOrder();
464  return;
465  }
466  else if (eventId == "namefilter")
467  {
469  mItems->updateMatrix();
470  }
471  else if (eventId.find("tag_") == 0u)
472  {
473  std::string tagName = event.getId().substr(4);
474  mItems->setFilter(ItemDB::getTagId(tagName));
475  return;
476  }
477 
478  Item *const item = mItems->getSelectedItem();
479 
480  if (item == nullptr)
481  return;
482 
483  if (eventId == "use")
484  {
486  }
487  if (eventId == "equip")
488  {
490  }
491  else if (eventId == "drop")
492  {
493  if (isStorageActive())
494  {
496  item->getInvIndex(),
497  item->getQuantity(),
499  }
500  else if ((cartWindow != nullptr) && cartWindow->isWindowVisible())
501  {
503  item->getInvIndex(),
504  item->getQuantity(),
506  }
507  else
508  {
509  if (PlayerInfo::isItemProtected(item->getId()))
510  return;
511 
513  {
514  PlayerInfo::dropItem(item, item->getQuantity(), Sfx_true);
515  }
516  else
517  {
519  this,
520  item,
521  0,
522  0);
523  }
524  }
525  }
526  else if (eventId == "split")
527  {
529  this,
530  item,
531  item->getQuantity() - 1,
532  9);
533  }
534  else if (eventId == "retrieve")
535  {
536  if (storageWindow != nullptr)
537  {
539  this,
540  item,
541  0,
542  0);
543  }
544  else if ((cartWindow != nullptr) && cartWindow->isWindowVisible())
545  {
547  this,
548  item,
549  0,
550  0);
551  }
552  }
553 }
554 
556 {
557  return mItems->getSelectedItem();
558 }
559 
561 {
562  mItems->selectNone();
563 }
564 
566 {
567  Window::widgetHidden(event);
568  if (itemPopup != nullptr)
570 }
571 
573 {
574  Window::mouseClicked(event);
575 
576  const int clicks = event.getClickCount();
577 
578  if (clicks == 2 && (gui != nullptr))
579  gui->resetClickCount();
580 
581  const bool mod = (isStorageActive() &&
583 
584  const bool mod2 = (tradeWindow != nullptr &&
587 
588  if (mInventory != nullptr)
589  {
590  if (!mod && !mod2 && event.getButton() == MouseButton::RIGHT)
591  {
592  Item *const item = mItems->getSelectedItem();
593 
594  if (item == nullptr)
595  return;
596 
597  /* Convert relative to the window coordinates to absolute screen
598  * coordinates.
599  */
600  const int mx = event.getX() + getX();
601  const int my = event.getY() + getY();
602 
603  if (popupMenu != nullptr)
604  {
605  popupMenu->showPopup(this,
606  mx, my,
607  item,
608  mInventory->getType());
609  }
610  }
611  }
612  else
613  {
614  return;
615  }
616 
617  if (event.getButton() == MouseButton::LEFT ||
618  event.getButton() == MouseButton::RIGHT)
619  {
620  Item *const item = mItems->getSelectedItem();
621 
622  if (item == nullptr)
623  return;
624 
625  if (mod)
626  {
628  {
629  if (event.getButton() == MouseButton::RIGHT)
630  {
633  inventoryWindow,
634  item,
635  0,
636  0);
637  }
638  else
639  {
641  item->getInvIndex(),
642  item->getQuantity(),
644  }
645  }
646  else
647  {
648  if (event.getButton() == MouseButton::RIGHT)
649  {
652  inventoryWindow,
653  item,
654  0,
655  0);
656  }
657  else
658  {
660  item->getInvIndex(),
661  item->getQuantity(),
663  }
664  }
665  }
666  else if (mod2 && mInventory->isMainInventory())
667  {
668  if (PlayerInfo::isItemProtected(item->getId()))
669  return;
670  if (event.getButton() == MouseButton::RIGHT)
671  {
673  tradeWindow,
674  item,
675  0,
676  0);
677  }
678  else
679  {
680  if (tradeWindow != nullptr)
681  tradeWindow->tradeItem(item, item->getQuantity(), true);
682  }
683  }
684  else if (clicks == 2)
685  {
687  {
688  if (isStorageActive())
689  {
692  inventoryWindow,
693  item,
694  0,
695  0);
696  }
697  else if (tradeWindow != nullptr &&
699  {
700  if (PlayerInfo::isItemProtected(item->getId()))
701  return;
704  tradeWindow,
705  item,
706  0,
707  0);
708  }
709  else
710  {
712  }
713  }
714  else
715  {
716  if (isStorageActive())
717  {
720  inventoryWindow,
721  item,
722  0,
723  0);
724  }
725  }
726  }
727  }
728 }
729 
731 {
732  Window::mouseMoved(event);
733  if (textPopup == nullptr)
734  return;
735 
736  const Widget *const src = event.getSource();
737  if (src == nullptr)
738  {
739  textPopup->hide();
740  return;
741  }
742  const int x = event.getX();
743  const int y = event.getY();
744  const Rect &rect = mDimension;
745  if (src == mSlotsBar || src == mWeightBar)
746  {
747  // TRANSLATORS: money label
748  textPopup->show(rect.x + x, rect.y + y, strprintf(_("Money: %s"),
750  Attributes::MONEY)).c_str()));
751  }
752  else
753  {
754  const Button *const btn = dynamic_cast<const Button *>(src);
755  if (btn == nullptr)
756  {
757  textPopup->hide();
758  return;
759  }
760  const std::string text = btn->getDescription();
761  if (!text.empty())
762  textPopup->show(x + rect.x, y + rect.y, text);
763  }
764 }
765 
767 {
768  textPopup->hide();
769 }
770 
772 {
773  if (event.getActionId() == InputAction::GUI_MOD)
774  mSplit = true;
775 }
776 
778 {
779  if (event.getActionId() == InputAction::GUI_MOD)
780  mSplit = false;
781 }
782 
784 {
785  if ((mInventory == nullptr) || !mInventory->isMainInventory())
786  return;
787 
788  Item *const item = mItems->getSelectedItem();
789 
790  if (mSplit && (item != nullptr) && inventoryHandler->
791  canSplit(mItems->getSelectedItem()))
792  {
794  this,
795  item,
796  item->getQuantity() - 1,
797  0);
798  }
799  updateButtons(item);
800 }
801 
803 {
804  if ((mInventory == nullptr) || !mInventory->isMainInventory())
805  return;
806 
807  const Item *const selectedItem = mItems->getSelectedItem();
808  if ((item != nullptr) && selectedItem != item)
809  return;
810 
811  if (item == nullptr)
812  item = selectedItem;
813 
814  if ((item == nullptr) || item->getQuantity() == 0)
815  {
816  if (mUseButton != nullptr)
817  mUseButton->setEnabled(false);
818  if (mDropButton != nullptr)
819  mDropButton->setEnabled(false);
820  return;
821  }
822 
823  if (mDropButton != nullptr)
824  mDropButton->setEnabled(true);
825 
826  if (mUseButton != nullptr)
827  {
828  const ItemInfo &info = item->getInfo();
829  const std::string &str = (item->isEquipment() == Equipm_true
830  && item->isEquipped() == Equipped_true)
831  ? info.getUseButton2() : info.getUseButton();
832  if (str.empty())
833  {
834  mUseButton->setEnabled(false);
835  // TRANSLATORS: default use button name
836  mUseButton->setCaption(_("Use"));
837  }
838  else
839  {
840  mUseButton->setEnabled(true);
841  mUseButton->setCaption(str);
842  }
843  }
844 
846 }
847 
849 {
850  if (mInventory == nullptr)
851  {
852  Window::close();
853  return;
854  }
855 
856  switch (mInventory->getType())
857  {
859  case InventoryType::Cart:
861  break;
862 
864  if (inventoryHandler != nullptr)
865  {
868  }
869  scheduleDelete();
870  break;
871 
872  default:
874  case InventoryType::Npc:
880  break;
881  }
882 }
883 
885 {
886  if ((mInventory == nullptr) || (mWeightBar == nullptr))
887  return;
888  const InventoryTypeT type = mInventory->getType();
889  if (type != InventoryType::Inventory &&
890  type != InventoryType::Cart)
891  {
892  return;
893  }
894 
895  const bool isInv = type == InventoryType::Inventory;
896  const int total = PlayerInfo::getAttribute(isInv
898  const int max = PlayerInfo::getAttribute(isInv
900 
901  if (max <= 0)
902  return;
903 
904  // Adjust progress bar
905  mWeightBar->setProgress(static_cast<float>(total)
906  / static_cast<float>(max));
907  mWeightBar->setText(strprintf("%s/%s",
908  UnitsDb::formatWeight(total).c_str(),
909  UnitsDb::formatWeight(max).c_str()));
910 }
911 
912 void InventoryWindow::slotsChanged(const Inventory *const inventory)
913 {
914  if (inventory == mInventory)
915  {
916  const int usedSlots = mInventory->getNumberOfSlotsUsed();
917  const int maxSlots = mInventory->getSize();
918 
919  if (maxSlots != 0)
920  {
921  mSlotsBar->setProgress(static_cast<float>(usedSlots)
922  / static_cast<float>(maxSlots));
923  }
924 
925  mSlotsBar->setText(strprintf("%d/%d", usedSlots, maxSlots));
926  mItems->updateMatrix();
927  }
928 }
929 
931 {
932  if (mDropButton == nullptr)
933  return;
934 
935  if (isStorageActive() ||
936  (cartWindow != nullptr && cartWindow->isWindowVisible()))
937  {
938  // TRANSLATORS: inventory button
939  mDropButton->setCaption(_("Store"));
940  }
941  else
942  {
943  const Item *const item = mItems->getSelectedItem();
944  if ((item != nullptr) && item->getQuantity() > 1)
945  {
946  // TRANSLATORS: inventory button
947  mDropButton->setCaption(_("Drop..."));
948  }
949  else
950  {
951  // TRANSLATORS: inventory button
952  mDropButton->setCaption(_("Drop"));
953  }
954  }
955 }
956 
958 {
959  return (mNameFilter != nullptr) && mNameFilter->isFocused();
960 }
961 
963 {
964  FOR_EACH (WindowList::const_iterator, it, invInstances)
965  {
966  if (((*it) != nullptr) && (*it)->isInputFocused())
967  return true;
968  }
969  return false;
970 }
971 
973 {
974  std::set<Widget*> list;
975  FOR_EACH (WindowList::const_iterator, it, invInstances)
976  {
977  if (((*it) != nullptr) && (*it)->isWindowVisible())
978  list.insert(*it);
979  }
980  return dynamic_cast<InventoryWindow*>(
982 }
983 
985 {
986  const InventoryWindow *const window = getFirstVisible();
987  if (window != nullptr)
988  window->mFilter->nextTab();
989 }
990 
992 {
993  const InventoryWindow *const window = getFirstVisible();
994  if (window != nullptr)
995  window->mFilter->prevTab();
996 }
997 
999 {
1000  Window::widgetResized(event);
1001 
1002  if (mInventory == nullptr)
1003  return;
1004  const InventoryTypeT type = mInventory->getType();
1005  if (type != InventoryType::Inventory &&
1006  type != InventoryType::Cart)
1007  {
1008  return;
1009  }
1010 
1011  if (getWidth() < 600)
1012  {
1013  if (!mCompactMode)
1014  {
1018  mCompactMode = true;
1019  }
1020  }
1021  else if (mCompactMode)
1022  {
1026  mCompactMode = false;
1027  }
1028 }
1029 
1031 {
1032  if (visible == Visible_false)
1033  mSortDropDown->hideDrop(true);
1034  Window::setVisible(visible);
1035 }
1036 
1038 {
1039  if (mInventory != nullptr)
1040  {
1042  if (mItems != nullptr)
1044  }
1045  mInventory = nullptr;
1046 }
1047 
1049  const int64_t oldVal A_UNUSED,
1050  const int64_t newVal A_UNUSED)
1051 {
1052  if (id == Attributes::TOTAL_WEIGHT
1053  || id == Attributes::MAX_WEIGHT
1055  || id == Attributes::CART_MAX_WEIGHT)
1056  {
1057  updateWeight();
1058  }
1059 }
1060 
1061 void InventoryWindow::combineItems(const int index1,
1062  const int index2)
1063 {
1064  if (mInventory == nullptr)
1065  return;
1066  const Item *item1 = mInventory->getItem(index1);
1067  if (item1 == nullptr)
1068  return;
1069  const Item *item2 = mInventory->getItem(index2);
1070  if (item2 == nullptr)
1071  return;
1072 
1073  if (item1->getType() != ItemType::Card)
1074  {
1075  const Item *tmpItem = item1;
1076  item1 = item2;
1077  item2 = tmpItem;
1078  }
1079 
1081  // TRANSLATORS: question dialog title
1082  _("Insert card request"),
1083  // TRANSLATORS: question dialog message
1084  strprintf(_("Insert %s into %s?"),
1085  item1->getName().c_str(),
1086  item2->getName().c_str()),
1087  SOUND_REQUEST,
1088  false,
1089  Modal_true,
1090  nullptr);
1091  insertCardListener.itemIndex = item2->getInvIndex();
1092  insertCardListener.cardIndex = item1->getInvIndex();
1093  confirmDlg->addActionListener(&insertCardListener);
1094 }
1095 
1096 void InventoryWindow::moveItemToCraft(const int craftSlot)
1097 {
1098  if (npcHandler == nullptr)
1099  return;
1100 
1101  Item *const item = mItems->getSelectedItem();
1102  if (item == nullptr)
1103  return;
1104 
1105  NpcDialog *const dialog = npcHandler->getCurrentNpcDialog();
1106  if ((dialog != nullptr) &&
1108  {
1109  if (item->getQuantity() > 1
1111  {
1114  item,
1115  0,
1116  craftSlot);
1117  }
1118  else
1119  {
1120  dialog->addCraftItem(item, 1, craftSlot);
1121  }
1122  }
1123 }
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:771
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:94
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:88
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:776
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:214
InventoryWindow * storageWindow
std::string getDescription() const
Definition: button.h:170
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)
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
Inventory * mInventory
void prevTab()
Definition: tabstrip.cpp:106
const bool Equipm_true
Definition: equipm.h:29
void setType(int t)
Definition: layoutcell.h:127
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:82
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:171
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:130
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:86
void setWidth(const int w)
Definition: layoutcell.h:136
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:167
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:1380
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