diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/inventorywindow.cpp | 14 | ||||
-rw-r--r-- | src/gui/inventorywindow.h | 1 | ||||
-rw-r--r-- | src/gui/itemcontainer.cpp | 72 | ||||
-rw-r--r-- | src/gui/itemcontainer.h | 12 | ||||
-rw-r--r-- | src/gui/storagewindow.cpp | 9 | ||||
-rw-r--r-- | src/gui/storagewindow.h | 1 | ||||
-rw-r--r-- | src/gui/trade.cpp | 10 | ||||
-rw-r--r-- | src/gui/widgets/window.cpp | 3 |
8 files changed, 67 insertions, 55 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index a808945e..50b0bd78 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -54,10 +54,12 @@ InventoryWindow::InventoryWindow(int invSize): mItemDesc(false) { setWindowName("Inventory"); - setResizable(false); + setResizable(true); setCloseButton(true); setDefaultSize(387, 307, ImageRect::CENTER); + setMinWidth(316); + setMinHeight(179); addKeyListener(this); std::string longestUseString = getFont()->getWidth(_("Equip")) > @@ -74,14 +76,14 @@ InventoryWindow::InventoryWindow(int invSize): mDropButton = new Button(_("Drop"), "drop", this); #ifdef TMWSERV_SUPPORT mSplitButton = new Button(_("Split"), "split", this); - mItems = new ItemContainer(player_node->getInventory(), 10, 5); + mItems = new ItemContainer(player_node->getInventory()); #else - mItems = new ItemContainer(player_node->getInventory(), 10, 10); + mItems = new ItemContainer(player_node->getInventory()); #endif mItems->addSelectionListener(this); - mInvenScroll = new ScrollArea(mItems); - mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + gcn::ScrollArea *invenScroll = new ScrollArea(mItems); + invenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mTotalWeight = -1; mMaxWeight = -1; @@ -97,7 +99,7 @@ InventoryWindow::InventoryWindow(int invSize): place(1, 0, mWeightBar, 3); place(4, 0, mSlotsLabel).setPadding(3); place(5, 0, mSlotsBar, 2); - place(0, 1, mInvenScroll, 7).setPadding(3); + place(0, 1, invenScroll, 7).setPadding(3); place(0, 2, mUseButton); place(1, 2, mDropButton); #ifdef TMWSERV_SUPPORT diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index 93ffdc11..a39ea34b 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -112,7 +112,6 @@ class InventoryWindow : public Window, #ifdef TMWSERV_SUPPORT gcn::Button *mSplitButton; #endif - gcn::ScrollArea *mInvenScroll; /**< Inventory Scroll Area. */ gcn::Label *mWeightLabel; gcn::Label *mSlotsLabel; diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index a672f3b5..4779b004 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -46,15 +46,13 @@ // TODO: Add support for adding items to the item shortcut window (global // itemShortcut). -static const int BOX_WIDTH = 36; -static const int BOX_HEIGHT = 44; +static const int BOX_WIDTH = 35; +static const int BOX_HEIGHT = 43; -ItemContainer::ItemContainer(Inventory *inventory, - int gridColumns, int gridRows, - bool forceQuantity): +ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity): mInventory(inventory), - mGridColumns(gridColumns), - mGridRows(gridRows), + mGridColumns(1), + mGridRows(1), mSelectedItem(NULL), mHighlightedItem(NULL), mSelectionStatus(SEL_NONE), @@ -68,13 +66,12 @@ ItemContainer::ItemContainer(Inventory *inventory, ResourceManager *resman = ResourceManager::getInstance(); mSelImg = resman->getImage("graphics/gui/selection.png"); - if (!mSelImg) logger->error("Unable to load selection.png"); + if (!mSelImg) + logger->error("Unable to load selection.png"); addKeyListener(this); addMouseListener(this); - - setSize((BOX_WIDTH - 1) * mGridColumns + 1, - (BOX_HEIGHT - 1) * mGridRows + 1); + addWidgetListener(this); } ItemContainer::~ItemContainer() @@ -87,19 +84,14 @@ void ItemContainer::draw(gcn::Graphics *graphics) { Graphics *g = static_cast<Graphics*>(graphics); + g->setFont(getFont()); + for (int i = 0; i < mGridColumns; i++) { for (int j = 0; j < mGridRows; j++) { - // Items positions made to overlap on another. - int itemX = i * (BOX_WIDTH - 1); - int itemY = j * (BOX_HEIGHT - 1); - - // Set color to black. - g->setColor(gcn::Color(0, 0, 0)); - // Draw box border. - g->drawRectangle( - gcn::Rectangle(itemX, itemY, BOX_WIDTH, BOX_HEIGHT)); + int itemX = i * BOX_WIDTH; + int itemY = j * BOX_HEIGHT; Item *item = mInventory->getItem((j * mGridColumns) + i); @@ -128,23 +120,25 @@ void ItemContainer::draw(gcn::Graphics *graphics) if (item->getQuantity() > 1 || mForceQuantity) caption = toString(item->getQuantity()); else if (item->isEquipped()) - caption = "(Eq)"; + caption = "Eq."; if (item->isEquipped()) g->setColor(guiPalette->getColor(Palette::ITEM_EQUIPPED)); + else + g->setColor(gcn::Color(0, 0, 0)); + g->drawText(caption, itemX + BOX_WIDTH / 2, itemY + BOX_HEIGHT - 14, gcn::Graphics::CENTER); } } - if (isFocused() && mHighlightedItem) { - // Items positions made to overlap on another. + // Draw an orange box around the selected item + if (isFocused() && mHighlightedItem) + { const int i = mHighlightedItem->getInvIndex(); - const int itemX = (i % mGridColumns) * (BOX_WIDTH - 1); - const int itemY = (i / mGridColumns) * (BOX_HEIGHT - 1); - // Set color to orange. + const int itemX = (i % mGridColumns) * BOX_WIDTH; + const int itemY = (i / mGridColumns) * BOX_HEIGHT; g->setColor(gcn::Color(255, 128, 0)); - // Draw box border. g->drawRectangle(gcn::Rectangle(itemX, itemY, BOX_WIDTH, BOX_HEIGHT)); } } @@ -165,13 +159,13 @@ void ItemContainer::setSelectedItem(Item *item) void ItemContainer::distributeValueChangedEvent() { - SelectionListenerIterator iter; + SelectionListenerIterator i, i_end; - for (iter = mSelectionListeners.begin(); iter != mSelectionListeners.end(); - ++iter) + for (i = mSelectionListeners.begin(), i_end = mSelectionListeners.end(); + i != i_end; ++i) { gcn::SelectionEvent event(this); - (*iter)->valueChanged(event); + (*i)->valueChanged(event); } } @@ -224,9 +218,8 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event) if (button == gcn::MouseEvent::LEFT || button == gcn::MouseEvent::RIGHT) { const int index = getSlotIndex(event.getX(), event.getY()); - if (index == Inventory::NO_SLOT_INDEX) { + if (index == Inventory::NO_SLOT_INDEX) return; - } Item *item = mInventory->getItem(index); @@ -317,12 +310,21 @@ void ItemContainer::mouseExited(gcn::MouseEvent &event) mItemPopup->setVisible(false); } +void ItemContainer::widgetResized(const gcn::Event &event) +{ + mGridColumns = std::max(1, getWidth() / BOX_WIDTH); + mGridRows = mInventory->getSize() / mGridColumns; + if (mGridRows == 0 || mInventory->getSize() % mGridColumns > 0) + ++mGridRows; + + setHeight(mGridRows * BOX_HEIGHT); +} + int ItemContainer::getSlotIndex(int x, int y) const { if (x < getWidth() && y < getHeight()) { - // Takes into account, boxes are overlapping each other. - return (y / (BOX_HEIGHT - 1)) * mGridColumns + (x / (BOX_WIDTH - 1)); + return (y / BOX_HEIGHT) * mGridColumns + (x / BOX_WIDTH); } return Inventory::NO_SLOT_INDEX; } diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index ba834d01..bc7caf5d 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -25,6 +25,7 @@ #include <guichan/keylistener.hpp> #include <guichan/mouselistener.hpp> #include <guichan/widget.hpp> +#include <guichan/widgetlistener.hpp> #include <list> @@ -44,7 +45,8 @@ namespace gcn { */ class ItemContainer : public gcn::Widget, public gcn::KeyListener, - public gcn::MouseListener + public gcn::MouseListener, + public gcn::WidgetListener { public: /** @@ -55,8 +57,7 @@ class ItemContainer : public gcn::Widget, * @param gridRows Amount of rows in grid. * @param offset Index offset */ - ItemContainer(Inventory *inventory, int gridColumns, int gridRows, - bool forceQuantity = false); + ItemContainer(Inventory *inventory, bool forceQuantity = false); /** * Destructor. @@ -68,15 +69,20 @@ class ItemContainer : public gcn::Widget, */ void draw(gcn::Graphics *graphics); + // KeyListener void keyPressed(gcn::KeyEvent &event); void keyReleased(gcn::KeyEvent &event); + // MouseListener void mousePressed(gcn::MouseEvent &event); void mouseDragged(gcn::MouseEvent &event); void mouseReleased(gcn::MouseEvent &event); void mouseMoved(gcn::MouseEvent &event); void mouseExited(gcn::MouseEvent &event); + // WidgetListener + void widgetResized(const gcn::Event &event); + /** * Returns the selected item. */ diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 076dfccf..efa2bdd4 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -64,11 +64,11 @@ StorageWindow::StorageWindow(int invSize): mStoreButton = new Button(_("Store"), "store", this); mRetrieveButton = new Button(_("Retrieve"), "retrieve", this); - mItems = new ItemContainer(player_node->getStorage(), 10, 30, true); + mItems = new ItemContainer(player_node->getStorage(), true); mItems->addSelectionListener(this); - mInvenScroll = new ScrollArea(mItems); - mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + gcn::ScrollArea *invenScroll = new ScrollArea(mItems); + invenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mUsedSlots = player_node->getStorage()->getNumberOfSlotsUsed(); @@ -83,7 +83,7 @@ StorageWindow::StorageWindow(int invSize): place(0, 0, mSlotsLabel).setPadding(3); place(1, 0, mSlotsBar, 3); - place(0, 1, mInvenScroll, 4, 4); + place(0, 1, invenScroll, 4, 4); place(2, 5, mStoreButton); place(3, 5, mRetrieveButton); @@ -95,7 +95,6 @@ StorageWindow::StorageWindow(int invSize): StorageWindow::~StorageWindow() { - delete mItems; } void StorageWindow::logic() diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h index caf31b90..4ccf324c 100644 --- a/src/gui/storagewindow.h +++ b/src/gui/storagewindow.h @@ -92,7 +92,6 @@ class StorageWindow : public Window, gcn::ActionListener, int mSlots; int mUsedSlots; gcn::Button *mStoreButton, *mRetrieveButton; - gcn::ScrollArea *mInvenScroll; gcn::Label *mSlotsLabel; diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 899c55d5..c67b0b7b 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -59,9 +59,11 @@ TradeWindow::TradeWindow(): mStatus(PROPOSING) { setWindowName("Trade"); - setResizable(false); + setResizable(true); setCloseButton(true); setDefaultSize(386, 180, ImageRect::CENTER); + setMinWidth(386); + setMinHeight(180); std::string longestName = getFont()->getWidth(_("OK")) > getFont()->getWidth(_("Trade")) ? @@ -76,15 +78,17 @@ TradeWindow::TradeWindow(): mOkButton->setWidth(8 + width); - mMyItemContainer = new ItemContainer(mMyInventory.get(), 5, 2); + mMyItemContainer = new ItemContainer(mMyInventory.get()); mMyItemContainer->addSelectionListener(this); ScrollArea *myScroll = new ScrollArea(mMyItemContainer); + myScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - mPartnerItemContainer = new ItemContainer(mPartnerInventory.get(), 5, 2); + mPartnerItemContainer = new ItemContainer(mPartnerInventory.get()); mPartnerItemContainer->addSelectionListener(this); ScrollArea *partnerScroll = new ScrollArea(mPartnerItemContainer); + partnerScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mMoneyLabel = new Label(strprintf(_("You get %s."), "")); gcn::Label *mMoneyLabel2 = new Label(_("You give:")); diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index f252c5f6..de48dfa2 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -242,7 +242,8 @@ void Window::setMaxHeight(int height) void Window::setResizable(bool r) { - if ((bool) mGrip == r) return; + if ((bool) mGrip == r) + return; if (r) { |