summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-10-21 15:24:58 +0300
committerAndrei Karas <akaras@inbox.ru>2012-10-21 15:24:58 +0300
commita77b9d248fdaadef39248dd3773354b75138a831 (patch)
treef8c80394510fb7f16bc948338e2a5507d7016e78 /src/gui
parent8048bed1e902feba8c623f68badbba946b0a24ac (diff)
downloadmv-a77b9d248fdaadef39248dd3773354b75138a831.tar.gz
mv-a77b9d248fdaadef39248dd3773354b75138a831.tar.bz2
mv-a77b9d248fdaadef39248dd3773354b75138a831.tar.xz
mv-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.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/theme.h8
-rw-r--r--src/gui/widgets/itemcontainer.cpp40
-rw-r--r--src/gui/widgets/itemcontainer.h4
3 files changed, 38 insertions, 14 deletions
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;