diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/inventorywindow.cpp | 104 | ||||
-rw-r--r-- | src/gui/inventorywindow.h | 20 |
2 files changed, 86 insertions, 38 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 0f7b6792..5add1d4f 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -27,8 +27,6 @@ #include <guichan/mouseinput.hpp> -#include <guichan/widgets/label.hpp> - #include "button.h" #include "gui.h" #include "item_amount.h" @@ -63,13 +61,21 @@ InventoryWindow::InventoryWindow(): mInvenScroll = new ScrollArea(mItems); mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - mItemNameLabel = new gcn::Label("Name:"); - mItemDescriptionLabel = new gcn::Label("Description:"); - mItemEffectLabel = new gcn::Label("Effect:"); - mWeightLabel = new gcn::Label("Total Weight: - Maximum Weight: "); + mTotalWeight = toString(player_node->mTotalWeight); + mMaxWeight = toString(player_node->mMaxWeight); + + mItemName = "Name:"; + mItemNameLabel = new TextBox(); + mItemDescription = "Description:"; + mItemDescriptionLabel = new TextBox(); + mItemEffect = "Effect:"; + mItemEffectLabel = new TextBox(); + mWeight = "Total Weight: " + mTotalWeight + " g - " + + "Maximum Weight: " + mMaxWeight + " g"; + mWeightLabel = new TextBox(); mWeightLabel->setPosition(8, 8); - mInvenScroll->setPosition(8, - mWeightLabel->getY() + mWeightLabel->getHeight() + 5); + + draw(); add(mUseButton); add(mDropButton); @@ -92,10 +98,18 @@ void InventoryWindow::logic() // redesign of InventoryWindow and ItemContainer probably. updateButtons(); - // Update weight information - mWeightLabel->setCaption( - "Total Weight: " + toString(player_node->mTotalWeight) + " g - " + - "Maximum Weight: " + toString(player_node->mMaxWeight) + " g"); + if ((mMaxWeight != toString(player_node->mMaxWeight)) || + mTotalWeight != toString(player_node->mTotalWeight)) + { + mTotalWeight = toString(player_node->mTotalWeight); + mMaxWeight = toString(player_node->mMaxWeight); + + // Adjust widgets + mWeight = "Total Weight: " + mTotalWeight + " g - " + + "Maximum Weight: " + mMaxWeight + " g"; + + draw(); + } } void InventoryWindow::action(const gcn::ActionEvent &event) @@ -137,21 +151,25 @@ void InventoryWindow::valueChanged(const gcn::SelectionEvent &event) // Update name, effect and description if (!item) { - mItemNameLabel->setCaption("Name:"); - mItemEffectLabel->setCaption("Effect:"); - mItemDescriptionLabel->setCaption("Description:"); + mItemName = "Name:"; + mItemNameLabel->setTextWrapped(mItemName); + mItemEffect = "Effect:"; + mItemEffectLabel->setTextWrapped(mItemEffect); + mItemDescription = "Description:"; + mItemDescriptionLabel->setTextWrapped(mItemDescription); } else { const ItemInfo& itemInfo = item->getInfo(); - std::string SomeText; - SomeText = "Name: " + itemInfo.getName(); - mItemNameLabel->setCaption(SomeText); - SomeText = "Effect: " + itemInfo.getEffect(); - mItemEffectLabel->setCaption(SomeText); - SomeText = "Description: " + itemInfo.getDescription(); - mItemDescriptionLabel->setCaption(SomeText); + mItemName = "Name: " + itemInfo.getName(); + mItemNameLabel->setTextWrapped(mItemName); + mItemEffect = "Effect: " + itemInfo.getEffect(); + mItemEffectLabel->setTextWrapped(mItemEffect); + mItemDescription = "Description: " + itemInfo.getDescription(); + mItemDescriptionLabel->setTextWrapped(mItemDescription); } + + draw(); } void InventoryWindow::mouseClicked(gcn::MouseEvent &event) @@ -173,36 +191,54 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) } } -void InventoryWindow::widgetResized(const gcn::Event &event) +void InventoryWindow::draw() { - Window::widgetResized(event); - const gcn::Rectangle &area = getChildrenArea(); const int width = area.width; const int height = area.height; - // Adjust widgets + // Update weight information + mWeightLabel->setTextWrapped(mWeight); + mWeightLabel->setMinWidth(width - 16); + mWeightLabel->setWidth(width - 16); + mUseButton->setPosition(8, height - 8 - mUseButton->getHeight()); mDropButton->setPosition(8 + mUseButton->getWidth() + 5, mUseButton->getY()); + mItemNameLabel->setMinWidth(width - 16); + mItemNameLabel->setTextWrapped(mItemName); mItemNameLabel->setDimension(gcn::Rectangle(8, - mUseButton->getY() - 5 - mItemNameLabel->getHeight(), + mUseButton->getY() - 5 - (mItemNameLabel->getNumberOfRows()*15), width - 16, - mItemNameLabel->getHeight())); + (mItemNameLabel->getNumberOfRows()*15))); + mItemEffectLabel->setMinWidth(width - 16); + mItemEffectLabel->setTextWrapped(mItemEffect); mItemEffectLabel->setDimension(gcn::Rectangle(8, - mItemNameLabel->getY() - 5 - mItemEffectLabel->getHeight(), + mItemNameLabel->getY() - 5 - (mItemEffectLabel->getNumberOfRows()*15), width - 16, - mItemEffectLabel->getHeight())); + (mItemEffectLabel->getNumberOfRows()*15))); + mItemDescriptionLabel->setMinWidth(width - 16); + mItemDescriptionLabel->setTextWrapped(mItemDescription); mItemDescriptionLabel->setDimension(gcn::Rectangle(8, - mItemEffectLabel->getY() - 5 - mItemDescriptionLabel->getHeight(), + mItemEffectLabel->getY() - 5 - (mItemDescriptionLabel->getNumberOfRows()*15), width - 16, - mItemDescriptionLabel->getHeight())); + (mItemDescriptionLabel->getNumberOfRows()*15))); mInvenScroll->setSize(width - 16, - mItemDescriptionLabel->getY() - mWeightLabel->getHeight() - 18); + mItemDescriptionLabel->getY() - (mWeightLabel->getNumberOfRows()*15) - 18); + mInvenScroll->setPosition(8, (mWeightLabel->getNumberOfRows()*15) + 10); - mWeightLabel->setWidth(width - 16); + setMinHeight(130 + (mWeightLabel->getNumberOfRows()*15) + + (mItemDescriptionLabel->getNumberOfRows()*15) + + (mItemEffectLabel->getNumberOfRows()*15) + + (mItemNameLabel->getNumberOfRows()*15)); +} + +void InventoryWindow::widgetResized(const gcn::Event &event) +{ + Window::widgetResized(event); + draw(); } void InventoryWindow::updateButtons() diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index 4793069c..e6170dac 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -27,6 +27,7 @@ #include <guichan/actionlistener.hpp> #include <guichan/selectionlistener.hpp> +#include "textbox.h" #include "window.h" #include "../guichanfwd.h" @@ -71,6 +72,11 @@ class InventoryWindow : public Window, gcn::ActionListener, void mouseClicked(gcn::MouseEvent &event); /** + * Updates window drawing. + */ + void draw(); + + /** * Called whenever the widget changes size. */ void widgetResized(const gcn::Event &event); @@ -80,12 +86,18 @@ class InventoryWindow : public Window, gcn::ActionListener, ItemContainer *mItems; + std::string mItemName; + std::string mItemDescription; + std::string mItemEffect; + std::string mWeight; + std::string mTotalWeight; + std::string mMaxWeight; gcn::Button *mUseButton, *mDropButton; gcn::ScrollArea *mInvenScroll; - gcn::Label *mItemNameLabel; - gcn::Label *mItemDescriptionLabel; - gcn::Label *mItemEffectLabel; - gcn::Label *mWeightLabel; + TextBox *mItemNameLabel; + TextBox *mItemDescriptionLabel; + TextBox *mItemEffectLabel; + TextBox *mWeightLabel; }; extern InventoryWindow *inventoryWindow; |