diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-10-21 15:24:58 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-10-21 15:24:58 +0300 |
commit | a77b9d248fdaadef39248dd3773354b75138a831 (patch) | |
tree | f8c80394510fb7f16bc948338e2a5507d7016e78 | |
parent | 8048bed1e902feba8c623f68badbba946b0a24ac (diff) | |
download | plus-a77b9d248fdaadef39248dd3773354b75138a831.tar.gz plus-a77b9d248fdaadef39248dd3773354b75138a831.tar.bz2 plus-a77b9d248fdaadef39248dd3773354b75138a831.tar.xz plus-a77b9d248fdaadef39248dd3773354b75138a831.zip |
Extend theming itemcontainer (used in inventory, trade window etc)
New theme file: itemcontainer.xml
Options in file:
boxWidth - item box width. Default value 35.
boxHeight - item box height. Default value 53.
equippedTextPadding - padding for item amount or equipped text.
Default value 29.
-rw-r--r-- | data/graphics/gui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | data/graphics/gui/Makefile.am | 1 | ||||
-rw-r--r-- | data/graphics/gui/itemcontainer.xml | 7 | ||||
-rw-r--r-- | src/gui/theme.h | 8 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 40 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.h | 4 |
6 files changed, 47 insertions, 14 deletions
diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index afb60b61d..b3822cbdb 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -26,6 +26,7 @@ SET (FILES inventory.xml item_selection.xml item_shortcut_background.xml + itemcontainer.xml label.xml listbox.xml mouse.png diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index 1e3d802f8..3f789b401 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -29,6 +29,7 @@ gui_DATA = \ inventory.xml \ item_selection.xml \ item_shortcut_background.xml \ + itemcontainer.xml \ label.xml \ listbox.xml \ mouse.png \ diff --git a/data/graphics/gui/itemcontainer.xml b/data/graphics/gui/itemcontainer.xml new file mode 100644 index 000000000..1e320ddef --- /dev/null +++ b/data/graphics/gui/itemcontainer.xml @@ -0,0 +1,7 @@ +<skinset name="Default" image="window.png"> + <widget type="Window"> + <option name="boxWidth" value="35" /> + <option name="boxHeight" value="53" /> + <option name="equippedTextPadding" value="29" /> + </widget> +</skinset> diff --git a/src/gui/theme.h b/src/gui/theme.h index 42f3495c8..5cf1a50f4 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -120,6 +120,14 @@ class Skin final return 0; } + int getOption(const std::string &name, const int def) const + { + if (mOptions->find(name) != mOptions->end()) + return (*mOptions)[name]; + else + return def; + } + int instances; private: diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 7e71287fe..9ae8918f5 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -46,8 +46,6 @@ #include "debug.h" -static const int BOX_WIDTH = 35; -static const int BOX_HEIGHT = 43; class ItemIdPair final { @@ -174,6 +172,12 @@ ItemContainer::ItemContainer(const Widget2 *const widget, mItemPopup(new ItemPopup), mShowMatrix(nullptr), mClicks(1), + mSkin(Theme::instance() ? Theme::instance()->load( + "itemcontainer.xml", "") : nullptr), + mBoxWidth(mSkin ? mSkin->getOption("boxWidth", 35) : 35), + mBoxHeight(mSkin ? mSkin->getOption("boxHeight", 43) : 43), + mEquippedTextPadding(mSkin ? mSkin->getOption( + "equippedTextPadding", 29) : 29), mEquipedColor(getThemeColor(Theme::ITEM_EQUIPPED)), mUnEquipedColor(getThemeColor(Theme::ITEM_NOT_EQUIPPED)) { @@ -190,6 +194,9 @@ ItemContainer::~ItemContainer() mSelImg->decRef(); mSelImg = nullptr; } + if (Theme::instance()) + Theme::instance()->unload(mSkin); + delete mItemPopup; mItemPopup = nullptr; delete []mShowMatrix; @@ -222,11 +229,11 @@ void ItemContainer::draw(gcn::Graphics *graphics) for (int j = 0; j < mGridRows; j++) { - const int intY0 = j * BOX_HEIGHT; + const int intY0 = j * mBoxHeight; int itemIndex = j * mGridColumns - 1; for (int i = 0; i < mGridColumns; i++) { - int itemX = i * BOX_WIDTH; + int itemX = i * mBoxWidth; int itemY = intY0; itemIndex ++; if (mShowMatrix[itemIndex] < 0) @@ -246,8 +253,8 @@ void ItemContainer::draw(gcn::Graphics *graphics) if (mSelectionStatus == SEL_DRAGGING) { // Reposition the coords to that of the cursor. - itemX = mDragPosX - (BOX_WIDTH / 2); - itemY = mDragPosY - (BOX_HEIGHT / 2); + itemX = mDragPosX - (mBoxWidth / 2); + itemY = mDragPosY - (mBoxHeight / 2); } else { @@ -264,11 +271,11 @@ void ItemContainer::draw(gcn::Graphics *graphics) for (int j = 0; j < mGridRows; j++) { - const int intY0 = j * BOX_HEIGHT; + const int intY0 = j * mBoxHeight; int itemIndex = j * mGridColumns - 1; for (int i = 0; i < mGridColumns; i++) { - int itemX = i * BOX_WIDTH; + int itemX = i * mBoxWidth; int itemY = intY0; itemIndex ++; if (mShowMatrix[itemIndex] < 0) @@ -283,17 +290,22 @@ void ItemContainer::draw(gcn::Graphics *graphics) // Draw item caption std::string caption; if (item->getQuantity() > 1 || mForceQuantity) + { caption = toString(item->getQuantity()); + } else if (item->isEquipped()) - caption = "Eq."; + { + // TRANSLATORS: Text under equipped items (should be small) + caption = _("Eq."); + } if (item->isEquipped()) g->setColor(mEquipedColor); else g->setColor(mUnEquipedColor); - g->drawText(caption, itemX + BOX_WIDTH / 2, - itemY + BOX_HEIGHT - 14, gcn::Graphics::CENTER); + g->drawText(caption, itemX + mBoxWidth / 2, + itemY + mEquippedTextPadding, gcn::Graphics::CENTER); } } } @@ -474,7 +486,7 @@ void ItemContainer::mouseExited(gcn::MouseEvent &event A_UNUSED) void ItemContainer::widgetResized(const gcn::Event &event A_UNUSED) { - mGridColumns = std::max(1, getWidth() / BOX_WIDTH); + mGridColumns = std::max(1, getWidth() / mBoxWidth); adjustHeight(); } @@ -487,7 +499,7 @@ void ItemContainer::adjustHeight() if (mGridRows == 0 || (mLastUsedSlot + 1) % mGridColumns > 0) ++mGridRows; - setHeight(mGridRows * BOX_HEIGHT); + setHeight(mGridRows * mBoxHeight); updateMatrix(); } @@ -585,7 +597,7 @@ int ItemContainer::getSlotIndex(const int x, const int y) const if (x < getWidth() && y < getHeight()) { - const int idx = (y / BOX_HEIGHT) * mGridColumns + (x / BOX_WIDTH); + const int idx = (y / mBoxHeight) * mGridColumns + (x / mBoxWidth); if (idx < mGridRows * mGridColumns && mShowMatrix[idx] >= 0) return mShowMatrix[idx]; } diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h index 87ccfe7df..cc5c21c64 100644 --- a/src/gui/widgets/itemcontainer.h +++ b/src/gui/widgets/itemcontainer.h @@ -211,6 +211,10 @@ class ItemContainer final : public gcn::Widget, ItemPopup *mItemPopup; int *mShowMatrix; int mClicks; + Skin *mSkin; + int mBoxWidth; + int mBoxHeight; + int mEquippedTextPadding; typedef std::list<gcn::SelectionListener*> SelectionListenerList; typedef SelectionListenerList::iterator SelectionListenerIterator; |