diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-10-22 02:39:05 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-10-22 22:16:47 +0300 |
commit | ad0c5a085c3c6531db2a84a77d590311ed1d2d8f (patch) | |
tree | 6d9d53668eb26f6ae94126a80298d3791b0f8962 /src/gui/equipmentwindow.cpp | |
parent | c70f14d7dc7d2cde472deb3a7aca60a482b7eb17 (diff) | |
download | ManaVerse-ad0c5a085c3c6531db2a84a77d590311ed1d2d8f.tar.gz ManaVerse-ad0c5a085c3c6531db2a84a77d590311ed1d2d8f.tar.bz2 ManaVerse-ad0c5a085c3c6531db2a84a77d590311ed1d2d8f.tar.xz ManaVerse-ad0c5a085c3c6531db2a84a77d590311ed1d2d8f.zip |
Add auto resize feature to equipment window for correct placing slots.
Diffstat (limited to 'src/gui/equipmentwindow.cpp')
-rw-r--r-- | src/gui/equipmentwindow.cpp | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 17c243734..3fa5f68cf 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -65,7 +65,11 @@ EquipmentWindow::EquipmentWindow(Equipment *const equipment, mBorderColor(getThemeColor(Theme::BORDER)), mLabelsColor(getThemeColor(Theme::LABEL)), mItemPadding(getOption("itemPadding")), - mBoxSize(getOption("boxSize")) + mBoxSize(getOption("boxSize")), + mMinX(180), + mMinY(345), + mMaxX(0), + mMaxY(0) { if (setupWindow) setupWindow->registerWindowForReset(this); @@ -86,20 +90,20 @@ EquipmentWindow::EquipmentWindow(Equipment *const equipment, setSaveVisible(true); setStickyButtonLock(true); - setDefaultSize(180, 345, ImageRect::CENTER); - mBoxes.reserve(BOX_COUNT); for (int f = 0; f < BOX_COUNT; f ++) mBoxes.push_back(nullptr); + mButtonPadding = getOption("buttonPadding", 5); + fillBoxes(); + recalcSize(); loadWindowState(); const gcn::Rectangle &area = getChildrenArea(); - const int buttonPadding = getOption("buttonPadding", 5); - mUnequip->setPosition(area.width - mUnequip->getWidth() - buttonPadding, - area.height - mUnequip->getHeight() - buttonPadding); + mUnequip->setPosition(area.width - mUnequip->getWidth() - mButtonPadding, + area.height - mUnequip->getHeight() - mButtonPadding); mUnequip->setEnabled(false); ImageRect rect; @@ -369,9 +373,7 @@ void EquipmentWindow::fillBoxes() for_each_xml_child_node(node, root) { - if (xmlNameEqual(node, "window")) - loadWindow(node); - else if (xmlNameEqual(node, "playerbox")) + if (xmlNameEqual(node, "playerbox")) loadPlayerBox(node); else if (xmlNameEqual(node, "slot")) loadSlot(node, mImageSet); @@ -379,12 +381,6 @@ void EquipmentWindow::fillBoxes() delete doc; } -void EquipmentWindow::loadWindow(const XmlNodePtr windowNode) -{ - setDefaultSize(XML::getProperty(windowNode, "width", 180), - XML::getProperty(windowNode, "height", 345), ImageRect::CENTER); -} - void EquipmentWindow::loadPlayerBox(const XmlNodePtr playerBoxNode) { mPlayerBox->setDimension(gcn::Rectangle( @@ -423,6 +419,14 @@ void EquipmentWindow::loadSlot(const XmlNodePtr slotNode, { mBoxes[slot] = new EquipmentBox(x, y, image); } + if (x < mMinX) + mMinX = x; + if (y < mMinY) + mMinY = y; + if (x + mBoxSize > mMaxX) + mMaxX = x + mBoxSize; + if (y + mBoxSize > mMaxY) + mMaxY = y + mBoxSize; } int EquipmentWindow::parseSlotName(std::string name) const @@ -508,8 +512,7 @@ void EquipmentWindow::fillDefault() addBox(12, 129, 123, 5); // ring } -void EquipmentWindow::addBox(const int idx, const int x, const int y, - const int imageIndex) +void EquipmentWindow::addBox(const int idx, int x, int y, const int imageIndex) { Image *image = nullptr; @@ -519,6 +522,23 @@ void EquipmentWindow::addBox(const int idx, const int x, const int y, image = mImageSet->get(imageIndex); } - mBoxes[idx] = new EquipmentBox(x + getPadding(), y + getTitleBarHeight(), - image); + x += getPadding(); + y += getTitleBarHeight(); + mBoxes[idx] = new EquipmentBox(x, y, image); + + if (x < mMinX) + mMinX = x; + if (y < mMinY) + mMinY = y; + if (x + mBoxSize > mMaxX) + mMaxX = x + mBoxSize; + if (y + mBoxSize > mMaxY) + mMaxY = y + mBoxSize; +} + +void EquipmentWindow::recalcSize() +{ + mMaxX += mMinX; + mMaxY += mMinY + mUnequip->getHeight() + mButtonPadding; + setDefaultSize(mMaxX, mMaxY, ImageRect::CENTER); } |