From 4b70908a529317ce4e57448fe4f4a59e75416537 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 27 Mar 2009 18:54:04 +0100 Subject: Fixed inventory window. Not resizable though. Resizing of the inventory window may come back later. Also did some more code cleanups, moving defines to enums, getting rid of eAthena-specific offset handling (to be done in the network layer), etc. Mantis-issue: 666 --- src/gui/char_select.h | 4 +-- src/gui/inventorywindow.cpp | 75 ++++++++++++++++++++------------------------- src/gui/inventorywindow.h | 4 +-- src/gui/item_amount.cpp | 26 ++++++++-------- src/gui/item_amount.h | 20 +++++++----- src/gui/itemcontainer.cpp | 31 ++++++------------- src/gui/itemcontainer.h | 57 +++++++++++++++------------------- src/gui/popupmenu.cpp | 6 ++-- src/gui/sdlinput.h | 4 +-- src/gui/storagewindow.cpp | 6 ++-- src/gui/trade.cpp | 14 ++------- src/imageparticle.cpp | 9 ++++-- src/imageparticle.h | 4 +-- src/net/messagein.h | 4 +-- src/net/messageout.h | 4 +-- 15 files changed, 120 insertions(+), 148 deletions(-) diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 7f376692..b29953d3 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -19,8 +19,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _CHAR_SELECT_H -#define _CHAR_SELECT_H +#ifndef CHAR_SELECT_H +#define CHAR_SELECT_H #include diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 21d2df3f..612c978a 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -19,32 +19,33 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include "gui/inventorywindow.h" -#include -#include +#include "gui/button.h" +#include "gui/item_amount.h" +#include "gui/itemcontainer.h" +#include "gui/label.h" +#include "gui/progressbar.h" +#include "gui/scrollarea.h" +#include "gui/sdlinput.h" +#include "gui/viewport.h" -#include "button.h" -#include "inventorywindow.h" -#include "item_amount.h" -#include "itemcontainer.h" -#include "label.h" -#include "progressbar.h" -#include "scrollarea.h" -#include "sdlinput.h" -#include "viewport.h" +#include "gui/widgets/layout.h" -#include "widgets/layout.h" +#include "inventory.h" +#include "item.h" +#include "localplayer.h" +#include "units.h" -#include "../inventory.h" -#include "../item.h" -#include "../localplayer.h" -#include "../units.h" +#include "resources/iteminfo.h" -#include "../resources/iteminfo.h" +#include "utils/gettext.h" +#include "utils/strprintf.h" + +#include +#include -#include "../utils/gettext.h" -#include "../utils/strprintf.h" +#include InventoryWindow::InventoryWindow(int invSize): Window(_("Inventory")), @@ -55,12 +56,8 @@ InventoryWindow::InventoryWindow(int invSize): setWindowName("Inventory"); setResizable(false); setCloseButton(true); - // LEEOR/TODO: Since this window is not resizable, do we really need to set these - // values or can we drop them? - setMinWidth(375); - setMinHeight(283); - // If you adjust these defaults, don't forget to adjust the trade window's. - setDefaultSize(375, 300, ImageRect::CENTER); + + setDefaultSize(375, 307, ImageRect::CENTER); addKeyListener(this); std::string longestUseString = getFont()->getWidth(_("Equip")) > @@ -79,34 +76,29 @@ InventoryWindow::InventoryWindow(int invSize): mSplitButton = new Button(_("Split"), "split", this); #endif -#ifdef TMWSERV_SUPPORT mItems = new ItemContainer(player_node->getInventory(), 10, 5); -#else - mItems = new ItemContainer(player_node->getInventory(), 10, 5, 2); -#endif mItems->addSelectionListener(this); + // The window is supposed to be exactly large enough for now mInvenScroll = new ScrollArea(mItems); + mInvenScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mTotalWeight = -1; mMaxWeight = -1; mUsedSlots = -1; - mSlotsLabel = new Label(_("Slots: ")); - mWeightLabel = new Label(_("Weight: ")); + mSlotsLabel = new Label(_("Slots:")); + mWeightLabel = new Label(_("Weight:")); mSlotsBar = new ProgressBar(1.0f, 100, 20, 225, 200, 25); mWeightBar = new ProgressBar(1.0f, 100, 20, 0, 0, 255); - setMinHeight(130); - setMinWidth(mWeightLabel->getWidth() + mSlotsLabel->getWidth() + 280); - place(0, 0, mWeightLabel).setPadding(3); place(1, 0, mWeightBar, 3); place(4, 0, mSlotsLabel).setPadding(3); place(5, 0, mSlotsBar, 2); - place(0, 1, mInvenScroll, 100).setPadding(3); + place(0, 1, mInvenScroll, 7).setPadding(3); place(0, 2, mUseButton); place(1, 2, mDropButton); #ifdef TMWSERV_SUPPORT @@ -114,7 +106,7 @@ InventoryWindow::InventoryWindow(int invSize): #endif Layout &layout = getLayout(); - layout.setRowHeight(0, Layout::AUTO_SET); + layout.setRowHeight(1, Layout::AUTO_SET); loadWindowState(); } @@ -196,7 +188,7 @@ void InventoryWindow::action(const gcn::ActionEvent &event) { if (item->getQuantity() > 1) { // Choose amount of items to drop - new ItemAmountWindow(AMOUNT_ITEM_DROP, this, item); + new ItemAmountWindow(ItemAmountWindow::ItemDrop, this, item); } else { player_node->dropItem(item, 1); @@ -206,8 +198,8 @@ void InventoryWindow::action(const gcn::ActionEvent &event) else if (event.getId() == "split") { if (item && !item->isEquipment() && item->getQuantity() > 1) { - new ItemAmountWindow(AMOUNT_ITEM_SPLIT, this, item, - (item->getQuantity() - 1)); + new ItemAmountWindow(ItemAmountWindow::ItemSplit, this, item, + (item->getQuantity() - 1)); } } } @@ -270,7 +262,8 @@ void InventoryWindow::valueChanged(const gcn::SelectionEvent &event) if (item && !item->isEquipment() && item->getQuantity() > 1) { mSplit = false; - new ItemAmountWindow(AMOUNT_ITEM_SPLIT, this, item, (item->getQuantity() - 1)); + new ItemAmountWindow(ItemAmountWindow::ItemSplit, this, item, + (item->getQuantity() - 1)); } } } diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index 0bdc8809..6e19114c 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -22,9 +22,9 @@ #ifndef INVENTORYWINDOW_H #define INVENTORYWINDOW_H -#include "window.h" +#include "gui/window.h" -#include "../inventory.h" +#include "inventory.h" #include #include diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 0f6aa593..f539f8ab 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -36,8 +36,8 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item, - int maxRange): +ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item, + int maxRange): Window("", true, parent), mItem(item), mMax(maxRange), @@ -87,23 +87,21 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item, switch (usage) { - case AMOUNT_TRADE_ADD: + case TradeAdd: setCaption(_("Select amount of items to trade.")); break; - case AMOUNT_ITEM_DROP: + case ItemDrop: setCaption(_("Select amount of items to drop.")); break; - case AMOUNT_STORE_ADD: + case StoreAdd: setCaption(_("Select amount of items to store.")); break; - case AMOUNT_STORE_REMOVE: + case StoreRemove: setCaption(_("Select amount of items to retrieve.")); break; - case AMOUNT_ITEM_SPLIT: + case ItemSplit: setCaption(_("Select amount of items to split.")); break; - default: - break; } setLocationRelativeTo(getParentWindow()); @@ -142,21 +140,21 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) switch (mUsage) { - case AMOUNT_TRADE_ADD: + case TradeAdd: tradeWindow->tradeItem(mItem, amount); break; - case AMOUNT_ITEM_DROP: + case ItemDrop: player_node->dropItem(mItem, amount); break; #ifdef TMWSERV_SUPPORT - case AMOUNT_ITEM_SPLIT: + case ItemSplit: player_node->splitItem(mItem, amount); break; #else - case AMOUNT_STORE_ADD: + case StoreAdd: storageWindow->addStore(mItem, amount); break; - case AMOUNT_STORE_REMOVE: + case StoreRemove: storageWindow->removeStore(mItem, amount); break; #endif diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index 344f8c28..24c50290 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -29,12 +29,6 @@ class IntTextField; class Item; -#define AMOUNT_TRADE_ADD 1 -#define AMOUNT_ITEM_DROP 2 -#define AMOUNT_STORE_ADD 3 -#define AMOUNT_STORE_REMOVE 4 -#define AMOUNT_ITEM_SPLIT 5 - /** * Window used for selecting the amount of items to drop, trade or split. * @@ -43,10 +37,19 @@ class Item; class ItemAmountWindow : public Window, public gcn::ActionListener { public: + enum Usage { + TradeAdd, + ItemDrop, + StoreAdd, + StoreRemove, + ItemSplit + }; + /** * Constructor. */ - ItemAmountWindow(int usage, Window *parent, Item *item, int maxRange = 0); + ItemAmountWindow(Usage usage, Window *parent, Item *item, + int maxRange = 0); /** * Called when receiving actions from widget. @@ -67,7 +70,8 @@ class ItemAmountWindow : public Window, public gcn::ActionListener gcn::Label *mItemAmountLabel; /**< Item amount caption. */ Item *mItem; - int mMax, mUsage; + int mMax; + Usage mUsage; /** * Item Amount buttons. diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 960f58ad..abce257d 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -49,23 +49,12 @@ static const int BOX_WIDTH = 36; static const int BOX_HEIGHT = 44; -enum -{ - SEL_NONE = 0, - SEL_SELECTED, - SEL_SELECTING, - SEL_DESELECTING, - SEL_DRAGGING -}; - ItemContainer::ItemContainer(Inventory *inventory, int gridColumns, - int gridRows, - int offset): + int gridRows): mInventory(inventory), mGridColumns(gridColumns), mGridRows(gridRows), - mOffset(offset), mSelectedItem(NULL), mHighlightedItem(NULL), mSelectionStatus(SEL_NONE), @@ -188,16 +177,16 @@ void ItemContainer::keyPressed(gcn::KeyEvent &event) switch (event.getKey().getValue()) { case Key::LEFT: - moveHighlight(MOVE_SELECTED_LEFT); + moveHighlight(Left); break; case Key::RIGHT: - moveHighlight(MOVE_SELECTED_RIGHT); + moveHighlight(Right); break; case Key::UP: - moveHighlight(MOVE_SELECTED_UP); + moveHighlight(Up); break; case Key::DOWN: - moveHighlight(MOVE_SELECTED_DOWN); + moveHighlight(Down); break; case Key::SPACE: keyAction(); @@ -372,7 +361,7 @@ void ItemContainer::keyAction() } } -void ItemContainer::moveHighlight(int direction) +void ItemContainer::moveHighlight(Direction direction) { if (!mHighlightedItem) { @@ -387,14 +376,14 @@ void ItemContainer::moveHighlight(int direction) switch (direction) { - case MOVE_SELECTED_LEFT: + case Left: if (mHighlightedItem->getInvIndex() % mGridColumns == 0) { mHighlightedItem += mGridColumns; } mHighlightedItem--; break; - case MOVE_SELECTED_RIGHT: + case Right: if ((mHighlightedItem->getInvIndex() % mGridColumns) == (mGridColumns - 1)) { @@ -402,14 +391,14 @@ void ItemContainer::moveHighlight(int direction) } mHighlightedItem++; break; - case MOVE_SELECTED_UP: + case Up: if (mHighlightedItem->getInvIndex() / mGridColumns == 0) { mHighlightedItem += (mGridColumns * mGridRows); } mHighlightedItem -= mGridColumns; break; - case MOVE_SELECTED_DOWN: + case Down: if ((mHighlightedItem->getInvIndex() / mGridColumns) == (mGridRows - 1)) { diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index 38eaba01..a28ca392 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -22,12 +22,12 @@ #ifndef ITEMCONTAINER_H #define ITEMCONTAINER_H -#include - #include #include #include +#include + class Image; class Inventory; class Item; @@ -49,13 +49,13 @@ class ItemContainer : public gcn::Widget, public: /** * Constructor. Initializes the graphic. + * * @param inventory * @param gridColumns Amount of columns in grid. * @param gridRows Amount of rows in grid. * @param offset Index offset */ - ItemContainer(Inventory *inventory, int gridColumns, int gridRows, - int offset = 0); + ItemContainer(Inventory *inventory, int gridColumns, int gridRows); /** * Destructor. @@ -67,35 +67,16 @@ class ItemContainer : public gcn::Widget, */ void draw(gcn::Graphics *graphics); - /** - * Handles the key presses. - */ void keyPressed(gcn::KeyEvent &event); - - /** - * Handles the key releases. - */ void keyReleased(gcn::KeyEvent &event); - - /** - * Handles mouse click. - */ void mousePressed(gcn::MouseEvent &event); - - /** - * Handles mouse dragged. - */ void mouseDragged(gcn::MouseEvent &event); - - /** - * Handles mouse released. - */ void mouseReleased(gcn::MouseEvent &event); /** * Returns the selected item. */ - Item* getSelectedItem() const + Item *getSelectedItem() const { return mSelectedItem; } /** @@ -121,13 +102,24 @@ class ItemContainer : public gcn::Widget, mSelectionListeners.remove(listener); } - enum { - MOVE_SELECTED_LEFT, // 0 - MOVE_SELECTED_RIGHT, // 1 - MOVE_SELECTED_UP, // 2 - MOVE_SELECTED_DOWN // 3 - }; private: + enum Direction + { + Left, + Right, + Up, + Down + }; + + enum SelectionState + { + SEL_NONE = 0, + SEL_SELECTED, + SEL_SELECTING, + SEL_DESELECTING, + SEL_DRAGGING + }; + /** * Execute all the functionality associated with the action key. */ @@ -141,7 +133,7 @@ class ItemContainer : public gcn::Widget, * * @param direction The move direction of the highlighter. */ - void moveHighlight(int direction); + void moveHighlight(Direction direction); /** * Sets the currently selected item. @@ -174,10 +166,9 @@ class ItemContainer : public gcn::Widget, Inventory *mInventory; int mGridColumns, mGridRows; - int mOffset; Image *mSelImg; Item *mSelectedItem, *mHighlightedItem; - int mSelectionStatus; + SelectionState mSelectionStatus; bool mSwapItems; bool mDescItems; int mDragPosX, mDragPosY; diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 0b019fef..5b5b2b8c 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -284,11 +284,13 @@ void PopupMenu::handleLink(const std::string &link) else if (link == "split") { - new ItemAmountWindow(AMOUNT_ITEM_SPLIT, inventoryWindow, mItem); + new ItemAmountWindow(ItemAmountWindow::ItemSplit, + inventoryWindow, mItem); } else if (link == "drop") { - new ItemAmountWindow(AMOUNT_ITEM_DROP, inventoryWindow, mItem); + new ItemAmountWindow(ItemAmountWindow::ItemDrop, + inventoryWindow, mItem); } #ifdef EATHENA_SUPPORT else if (link == "party-invite" && diff --git a/src/gui/sdlinput.h b/src/gui/sdlinput.h index 3901589a..209cc9ea 100644 --- a/src/gui/sdlinput.h +++ b/src/gui/sdlinput.h @@ -55,8 +55,8 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SDLINPUT_ -#define SDLINPUT_ +#ifndef SDLINPUT_H +#define SDLINPUT_H #include diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 479348aa..1289a4e7 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -67,7 +67,7 @@ StorageWindow::StorageWindow(Network *network, int invSize): mStoreButton = new Button(_("Store"), "store", this); mRetrieveButton = new Button(_("Retrieve"), "retrieve", this); - mItems = new ItemContainer(player_node->getStorage(), 10, 5, 1); + mItems = new ItemContainer(player_node->getStorage(), 10, 5); mItems->addSelectionListener(this); mInvenScroll = new ScrollArea(mItems); @@ -136,7 +136,7 @@ void StorageWindow::action(const gcn::ActionEvent &event) else { // Choose amount of items to trade - new ItemAmountWindow(AMOUNT_STORE_ADD, this, item); + new ItemAmountWindow(ItemAmountWindow::StoreAdd, this, item); } } else if (event.getId() == "retrieve") @@ -153,7 +153,7 @@ void StorageWindow::action(const gcn::ActionEvent &event) else { // Choose amount of items to trade - new ItemAmountWindow(AMOUNT_STORE_REMOVE, this, item); + new ItemAmountWindow(ItemAmountWindow::StoreRemove, this, item); } } } diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 2d80d12d..8aa3c3ea 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -90,20 +90,12 @@ TradeWindow::TradeWindow(Network *network): mTradeButton->getFont()->getWidth(_("Propose trade")), mTradeButton->getFont()->getWidth(_("Confirm trade")))); -#ifdef TMWSERV_SUPPORT - mMyItemContainer = new ItemContainer(mMyInventory.get(), 4, 3, 0); -#else - mMyItemContainer = new ItemContainer(mMyInventory.get(), 4, 3, 2); -#endif + mMyItemContainer = new ItemContainer(mMyInventory.get(), 4, 3); mMyItemContainer->addSelectionListener(this); ScrollArea *myScroll = new ScrollArea(mMyItemContainer); -#ifdef TMWSERV_SUPPORT - mPartnerItemContainer = new ItemContainer(mPartnerInventory.get(), 4, 3, 0); -#else - mPartnerItemContainer = new ItemContainer(mPartnerInventory.get(), 4, 3, 2); -#endif + mPartnerItemContainer = new ItemContainer(mPartnerInventory.get(), 4, 3); mPartnerItemContainer->addSelectionListener(this); ScrollArea *partnerScroll = new ScrollArea(mPartnerItemContainer); @@ -322,7 +314,7 @@ void TradeWindow::action(const gcn::ActionEvent &event) else { // Choose amount of items to trade - new ItemAmountWindow(AMOUNT_TRADE_ADD, this, item); + new ItemAmountWindow(ItemAmountWindow::TradeAdd, this, item); } #ifdef TMWSERV_SUPPORT diff --git a/src/imageparticle.cpp b/src/imageparticle.cpp index 557b3553..865c3046 100644 --- a/src/imageparticle.cpp +++ b/src/imageparticle.cpp @@ -19,21 +19,24 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "graphics.h" #include "imageparticle.h" +#include "graphics.h" + #include "resources/image.h" ImageParticle::ImageParticle(Map *map, Image *image): Particle(map), mImage(image) { - if (mImage) mImage->incRef(); + if (mImage) + mImage->incRef(); } ImageParticle::~ImageParticle() { - if (mImage) mImage->decRef(); + if (mImage) + mImage->decRef(); } void ImageParticle::draw(Graphics *graphics, int offsetX, int offsetY) const diff --git a/src/imageparticle.h b/src/imageparticle.h index 317b17ea..82f185cd 100644 --- a/src/imageparticle.h +++ b/src/imageparticle.h @@ -19,8 +19,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _IMAGEPARTICLE_H -#define _IMAGEPARTICLE_H +#ifndef IMAGEPARTICLE_H +#define IMAGEPARTICLE_H #include "particle.h" diff --git a/src/net/messagein.h b/src/net/messagein.h index 0d0e9981..ab206dde 100644 --- a/src/net/messagein.h +++ b/src/net/messagein.h @@ -19,8 +19,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef MESSAGEIN_ -#define MESSAGEIN_ +#ifndef MESSAGEIN_H +#define MESSAGEIN_H #include #include diff --git a/src/net/messageout.h b/src/net/messageout.h index bc701b92..1ddd040d 100644 --- a/src/net/messageout.h +++ b/src/net/messageout.h @@ -19,8 +19,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef MESSAGEOUT_ -#define MESSAGEOUT_ +#ifndef MESSAGEOUT_H +#define MESSAGEOUT_H #include #include -- cgit v1.2.3-60-g2f50