diff options
author | Ira Rice <irarice@gmail.com> | 2009-01-20 22:47:48 -0700 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-01-20 22:47:48 -0700 |
commit | 8b88dffb8222bb4c59d09e11c00b1046f93d51fe (patch) | |
tree | c8356ddf4e4c72734c5f33bab72c82ef82fc29fc /src/gui/inventorywindow.cpp | |
parent | b0ff8cc281d7e7f8f3c2666d6bbe6424fec74f9c (diff) | |
download | mana-8b88dffb8222bb4c59d09e11c00b1046f93d51fe.tar.gz mana-8b88dffb8222bb4c59d09e11c00b1046f93d51fe.tar.bz2 mana-8b88dffb8222bb4c59d09e11c00b1046f93d51fe.tar.xz mana-8b88dffb8222bb4c59d09e11c00b1046f93d51fe.zip |
Reflowed inventory window to use layout code, as well as fixed the npc
list dialog to be more consistant with other windows. Also revised the
skill window to default to being only as big as the number of skills
listed.
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui/inventorywindow.cpp')
-rw-r--r-- | src/gui/inventorywindow.cpp | 93 |
1 files changed, 34 insertions, 59 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index efe1cd51..72507d23 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -21,8 +21,11 @@ #include <string> +#include <guichan/font.hpp> #include <guichan/mouseinput.hpp> +#include <guichan/widgets/label.hpp> + #include "button.h" #include "gui.h" #include "inventorywindow.h" @@ -31,6 +34,8 @@ #include "scrollarea.h" #include "viewport.h" +#include "widgets/layout.h" + #include "../inventory.h" #include "../item.h" #include "../localplayer.h" @@ -48,7 +53,7 @@ InventoryWindow::InventoryWindow(): setWindowName(_("Inventory")); setResizable(true); setCloseButton(true); - setMinWidth(240); + // If you adjust these defaults, don't forget to adjust the trade window's. setDefaultSize(115, 25, 322, 200); @@ -68,19 +73,24 @@ InventoryWindow::InventoryWindow(): mMaxWeight + _(" g Slots: ") + toString(player_node->getInventory()->getNumberOfSlotsUsed()) + "/" + toString(player_node->getInventory()->getInventorySize()); - mWeightLabel = new TextBox(); - mWeightLabel->setPosition(8, 8); + mWeightLabel = new gcn::Label(mWeight); - draw(); + setMinHeight(130); + setMinWidth(getFont()->getWidth(mWeight)); - add(mUseButton); - add(mDropButton); - add(mInvenScroll); - add(mWeightLabel); + ContainerPlacer place; + place = getPlacer(0, 0); - mUseButton->setSize(60, mUseButton->getHeight()); + place(0, 0, mInvenScroll, 5, 4); + place(0, 4, mWeightLabel, 5); + place(3, 5, mDropButton); + place(4, 5, mUseButton); + + Layout &layout = getLayout(); + layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); + setLocationRelativeTo(getParent()); } void InventoryWindow::logic() @@ -103,7 +113,7 @@ void InventoryWindow::logic() toString(player_node->getInventory()->getNumberOfSlotsUsed()) + "/" + toString(player_node->getInventory()->getInventorySize()); - draw(); + setMinWidth(getFont()->getWidth(mWeight)); } } @@ -114,36 +124,30 @@ void InventoryWindow::action(const gcn::ActionEvent &event) if (!item) return; - if (event.getId() == "use") { - if (item->isEquipment()) { - if (item->isEquipped()) { + if (event.getId() == "use") + { + if (item->isEquipment()) + { + if (item->isEquipped()) player_node->unequipItem(item); - } - else { + else player_node->equipItem(item); - } } - else { + else player_node->useItem(item); - } } else if (event.getId() == "drop") { - if (item->getQuantity() == 1) { + if (item->getQuantity() == 1) player_node->dropItem(item, 1); - } - else { + else + { // Choose amount of items to drop new ItemAmountWindow(AMOUNT_ITEM_DROP, this, item); } } } -void InventoryWindow::valueChanged(const gcn::SelectionEvent &event) -{ - draw(); -} - void InventoryWindow::mouseClicked(gcn::MouseEvent &event) { Window::mouseClicked(event); @@ -164,48 +168,19 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) } } -void InventoryWindow::draw() -{ - const gcn::Rectangle &area = getChildrenArea(); - const int width = area.width; - const int height = area.height; - - // Update weight information - mWeightLabel->setTextWrapped(mWeight); - mWeightLabel->setMinWidth(width - 16); - - mUseButton->setPosition(8, height - 8 - mUseButton->getHeight()); - mDropButton->setPosition(8 + mUseButton->getWidth() + 5, - mUseButton->getY()); - - mInvenScroll->setSize(width - 16, - mUseButton->getY() - (mWeightLabel->getNumberOfRows()*15) - 18); - mInvenScroll->setPosition(8, (mWeightLabel->getNumberOfRows()*15) + 10); - - setMinHeight(130 + (mWeightLabel->getNumberOfRows()*15)); -} - -void InventoryWindow::widgetResized(const gcn::Event &event) -{ - Window::widgetResized(event); - draw(); -} - void InventoryWindow::updateButtons() { const Item *selectedItem = mItems->getSelectedItem(); if (selectedItem && selectedItem->isEquipment()) { - if (selectedItem->isEquipped()) { + if (selectedItem->isEquipped()) mUseButton->setCaption(_("Unequip")); - } - else { + else mUseButton->setCaption(_("Equip")); - } } - else { - mUseButton->setCaption(_("Use")); } + else + mUseButton->setCaption(_("Use")); mUseButton->setEnabled(selectedItem != 0); mDropButton->setEnabled(selectedItem != 0); |