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-2019 The ManaPlus Developers 6 * Copyright (C) 2019-2021 Andrei Karas 7 * 8 * This file is part of The ManaPlus Client. 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program. If not, see <http://www.gnu.org/licenses/>. 22 */ 23 24 #ifndef GUI_WINDOWS_INVENTORYWINDOW_H 25 #define GUI_WINDOWS_INVENTORYWINDOW_H 26 27 #include "resources/inventory/inventory.h" 28 29 #include "gui/widgets/window.h" 30 31 #include "listeners/actionlistener.h" 32 #include "listeners/attributelistener.h" 33 #include "listeners/inventorylistener.h" 34 #include "listeners/keylistener.h" 35 #include "listeners/selectionlistener.h" 36 37 class Button; 38 class DropDown; 39 class InventoryWindow; 40 class Item; 41 class ItemContainer; 42 class LayoutCell; 43 class ProgressBar; 44 class SortListModelInv; 45 class TabStrip; 46 class TextField; 47 48 extern InventoryWindow *inventoryWindow; 49 extern InventoryWindow *storageWindow; 50 extern InventoryWindow *cartWindow; 51 52 /** 53 * Inventory dialog. 54 * 55 * \ingroup Interface 56 */ 57 class InventoryWindow final : public Window, 58 public ActionListener, 59 public KeyListener, 60 public SelectionListener, 61 public InventoryListener, 62 public AttributeListener 63 { 64 public: 65 /** 66 * Constructor. 67 */ 68 explicit InventoryWindow(Inventory *const inventory); 69 70 A_DELETE_COPY(InventoryWindow) 71 72 /** 73 * Destructor. 74 */ 75 ~InventoryWindow() override final; 76 77 void postInit() override final; 78 79 void storeSortOrder() const; 80 81 /** 82 * Called when receiving actions from the widgets. 83 */ 84 void action(const ActionEvent &event) override final; 85 86 /** 87 * Returns the selected item. 88 */ 89 Item* getSelectedItem() const A_WARN_UNUSED; 90 91 /** 92 * Unselect item 93 */ 94 void unselectItem(); 95 96 /** 97 * Handles closing of the window 98 */ 99 void widgetHidden(const Event &event) override final; 100 101 /** 102 * Handles the mouse clicks. 103 */ 104 void mouseClicked(MouseEvent &event) override final; 105 106 /** 107 * Handles the key presses. 108 */ 109 void keyPressed(KeyEvent &event) override final; 110 111 /** 112 * Handles the key releases. 113 */ 114 void keyReleased(KeyEvent &event) override final; 115 116 /** 117 * Updates labels to currently selected item. 118 */ 119 void valueChanged(const SelectionEvent &event) override final; 120 121 /** 122 * Closes the Storage Window, as well as telling the server that the 123 * window has been closed. 124 */ 125 void close() override final; 126 127 void slotsChanged(const Inventory *const inventory) override final; 128 isMainInventory()129 bool isMainInventory() const A_WARN_UNUSED 130 { 131 return mInventory != nullptr ? 132 mInventory->isMainInventory() : false; 133 } 134 135 /** 136 * Returns true if any instances exist. 137 */ isStorageActive()138 static bool isStorageActive() A_WARN_UNUSED 139 { return storageWindow != nullptr; } 140 141 void updateDropButton(); 142 143 void updateButtons(const Item *item); 144 145 bool isInputFocused() const A_WARN_UNUSED; 146 147 void widgetResized(const Event &event) override final; 148 149 void mouseMoved(MouseEvent &event) override final; 150 151 void mouseExited(MouseEvent &event) override final; 152 153 void setVisible(Visible visible) override final; 154 155 void unsetInventory(); 156 157 void attributeChanged(const AttributesT id, 158 const int64_t oldVal, 159 const int64_t newVal) override final; 160 161 void combineItems(const int index1, 162 const int index2); 163 164 void moveItemToCraft(const int craftSlot); 165 166 static bool isAnyInputFocused(); 167 168 static InventoryWindow *getFirstVisible(); 169 170 static void nextTab(); 171 172 static void prevTab(); 173 174 private: 175 /** 176 * Updates the weight bar. 177 */ 178 void updateWeight(); 179 180 typedef std::list<InventoryWindow*> WindowList; 181 static WindowList invInstances; 182 183 Inventory *mInventory; 184 ItemContainer *mItems A_NONNULLPOINTER; 185 186 Button *mUseButton; 187 Button *mDropButton; 188 Button *mOutfitButton; 189 Button *mShopButton; 190 Button *mCartButton; 191 Button *mEquipmentButton; 192 Button *mStoreButton; 193 Button *mRetrieveButton; 194 Button *mInvCloseButton; 195 196 ProgressBar *mWeightBar; 197 ProgressBar *mSlotsBar A_NONNULLPOINTER; 198 TabStrip *mFilter; 199 SortListModelInv *mSortModel A_NONNULLPOINTER; 200 DropDown *mSortDropDown A_NONNULLPOINTER; 201 TextField *mNameFilter A_NONNULLPOINTER; 202 LayoutCell *mSortDropDownCell; 203 LayoutCell *mNameFilterCell; 204 LayoutCell *mFilterCell; 205 LayoutCell *mSlotsBarCell; 206 207 bool mSplit; 208 bool mCompactMode; 209 }; 210 211 #endif // GUI_WINDOWS_INVENTORYWINDOW_H 212