diff --git a/apps/openmw/mwgui/alchemywindow.cpp b/apps/openmw/mwgui/alchemywindow.cpp index 427e5bdd7..0fa9121b7 100644 --- a/apps/openmw/mwgui/alchemywindow.cpp +++ b/apps/openmw/mwgui/alchemywindow.cpp @@ -203,12 +203,7 @@ namespace MWGui ingredient->setUserString("ToolTipType", "ItemPtr"); ingredient->setUserData(item); - MyGUI::TextBox* text = ingredient->createWidget("SandBrightText", MyGUI::IntCoord(0, 14, 32, 18), MyGUI::Align::Default, std::string("Label")); - text->setTextAlign(MyGUI::Align::Right); - text->setNeedMouseFocus(false); - text->setTextShadow(true); - text->setTextShadowColour(MyGUI::Colour(0,0,0)); - text->setCaption(ItemView::getCountString(ingredient->getUserData()->getRefData().getCount())); + ingredient->setCount(ingredient->getUserData()->getRefData().getCount()); } mItemView->update(); diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 18488b9b3..7aac65bd3 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -92,16 +92,7 @@ namespace MWGui mDraggedWidget = baseWidget; baseWidget->setItem(mItem.mBase); baseWidget->setNeedMouseFocus(false); - - // text widget that shows item count - // TODO: move to ItemWidget - MyGUI::TextBox* text = baseWidget->createWidget("SandBrightText", - MyGUI::IntCoord(0, 14, 32, 18), MyGUI::Align::Default, std::string("Label")); - text->setTextAlign(MyGUI::Align::Right); - text->setNeedMouseFocus(false); - text->setTextShadow(true); - text->setTextShadowColour(MyGUI::Colour(0,0,0)); - text->setCaption(ItemView::getCountString(count)); + baseWidget->setCount(count); sourceView->update(); diff --git a/apps/openmw/mwgui/itemview.cpp b/apps/openmw/mwgui/itemview.cpp index bb838e340..a51ada275 100644 --- a/apps/openmw/mwgui/itemview.cpp +++ b/apps/openmw/mwgui/itemview.cpp @@ -17,16 +17,6 @@ namespace MWGui { -std::string ItemView::getCountString(int count) -{ - if (count == 1) - return ""; - if (count > 9999) - return boost::lexical_cast(int(count/1000.f)) + "k"; - else - return boost::lexical_cast(count); -} - ItemView::ItemView() : mModel(NULL) , mScrollView(NULL) @@ -123,19 +113,10 @@ void ItemView::update() if (item.mType == ItemStack::Type_Equipped) state = ItemWidget::Equip; itemWidget->setItem(item.mBase, state); + itemWidget->setCount(item.mCount); itemWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ItemView::onSelectedItem); itemWidget->eventMouseWheel += MyGUI::newDelegate(this, &ItemView::onMouseWheel); - - // text widget that shows item count - // TODO: move to ItemWidget - MyGUI::TextBox* text = itemWidget->createWidget("SandBrightText", - MyGUI::IntCoord(5, 19, 32, 18), MyGUI::Align::Default, std::string("Label")); - text->setTextAlign(MyGUI::Align::Right); - text->setNeedMouseFocus(false); - text->setTextShadow(true); - text->setTextShadowColour(MyGUI::Colour(0,0,0)); - text->setCaption(getCountString(item.mCount)); } layoutWidgets(); diff --git a/apps/openmw/mwgui/itemview.hpp b/apps/openmw/mwgui/itemview.hpp index 68704d219..1a5bd79a3 100644 --- a/apps/openmw/mwgui/itemview.hpp +++ b/apps/openmw/mwgui/itemview.hpp @@ -30,8 +30,6 @@ namespace MWGui void update(); - static std::string getCountString(int count); - private: virtual void initialiseOverride(); diff --git a/apps/openmw/mwgui/itemwidget.cpp b/apps/openmw/mwgui/itemwidget.cpp index ade8f5731..430b57ef3 100644 --- a/apps/openmw/mwgui/itemwidget.cpp +++ b/apps/openmw/mwgui/itemwidget.cpp @@ -2,16 +2,34 @@ #include #include +#include + +#include #include #include "../mwworld/class.hpp" +namespace +{ + std::string getCountString(int count) + { + if (count == 1) + return ""; + if (count > 9999) + return boost::lexical_cast(int(count/1000.f)) + "k"; + else + return boost::lexical_cast(count); + } +} + namespace MWGui { ItemWidget::ItemWidget() : mItem(NULL) + , mFrame(NULL) + , mText(NULL) { } @@ -29,10 +47,20 @@ namespace MWGui assignWidget(mFrame, "Frame"); if (mFrame) mFrame->setNeedMouseFocus(false); + assignWidget(mText, "Text"); + if (mText) + mText->setNeedMouseFocus(false); Base::initialiseOverride(); } + void ItemWidget::setCount(int count) + { + if (!mText) + return; + mText->setCaption(getCountString(count)); + } + void ItemWidget::setIcon(const std::string &icon) { if (mItem) diff --git a/apps/openmw/mwgui/itemwidget.hpp b/apps/openmw/mwgui/itemwidget.hpp index 3de98489d..e7a902239 100644 --- a/apps/openmw/mwgui/itemwidget.hpp +++ b/apps/openmw/mwgui/itemwidget.hpp @@ -29,6 +29,9 @@ namespace MWGui Magic }; + /// Set count to be displayed in a textbox over the item + void setCount(int count); + /// \a ptr may be empty void setItem (const MWWorld::Ptr& ptr, ItemState state = None); @@ -42,6 +45,7 @@ namespace MWGui MyGUI::ImageBox* mItem; MyGUI::ImageBox* mFrame; + MyGUI::TextBox* mText; }; } diff --git a/files/mygui/openmw_resources.xml b/files/mygui/openmw_resources.xml index a37d3335c..1c8251a39 100644 --- a/files/mygui/openmw_resources.xml +++ b/files/mygui/openmw_resources.xml @@ -322,6 +322,10 @@ + + + + @@ -338,6 +342,10 @@ + + + +