mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:23:53 +00:00
Move item count text to ItemWidget
This commit is contained in:
parent
b145d183ae
commit
cbc242d857
7 changed files with 43 additions and 38 deletions
|
@ -203,12 +203,7 @@ namespace MWGui
|
|||
ingredient->setUserString("ToolTipType", "ItemPtr");
|
||||
ingredient->setUserData(item);
|
||||
|
||||
MyGUI::TextBox* text = ingredient->createWidget<MyGUI::TextBox>("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<MWWorld::Ptr>()->getRefData().getCount()));
|
||||
ingredient->setCount(ingredient->getUserData<MWWorld::Ptr>()->getRefData().getCount());
|
||||
}
|
||||
|
||||
mItemView->update();
|
||||
|
|
|
@ -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<MyGUI::TextBox>("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();
|
||||
|
||||
|
|
|
@ -17,16 +17,6 @@
|
|||
namespace MWGui
|
||||
{
|
||||
|
||||
std::string ItemView::getCountString(int count)
|
||||
{
|
||||
if (count == 1)
|
||||
return "";
|
||||
if (count > 9999)
|
||||
return boost::lexical_cast<std::string>(int(count/1000.f)) + "k";
|
||||
else
|
||||
return boost::lexical_cast<std::string>(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<MyGUI::TextBox>("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();
|
||||
|
|
|
@ -30,8 +30,6 @@ namespace MWGui
|
|||
|
||||
void update();
|
||||
|
||||
static std::string getCountString(int count);
|
||||
|
||||
private:
|
||||
virtual void initialiseOverride();
|
||||
|
||||
|
|
|
@ -2,16 +2,34 @@
|
|||
|
||||
#include <MyGUI_FactoryManager.h>
|
||||
#include <MyGUI_ImageBox.h>
|
||||
#include <MyGUI_TextBox.h>
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <components/misc/resourcehelpers.hpp>
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string getCountString(int count)
|
||||
{
|
||||
if (count == 1)
|
||||
return "";
|
||||
if (count > 9999)
|
||||
return boost::lexical_cast<std::string>(int(count/1000.f)) + "k";
|
||||
else
|
||||
return boost::lexical_cast<std::string>(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)
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -322,6 +322,10 @@
|
|||
<Resource type="ResourceLayout" name="MW_ItemIcon" version="3.2.0">
|
||||
<Widget type="Widget" skin="" position="0 0 42 42" name="Root">
|
||||
<Widget type="ImageBox" skin="ImageBox" position="0 0 42 42" align="Stretch" name="Frame">
|
||||
<Widget type="TextBox" skin="SandBrightText" position="5 19 32 18" align="Right Bottom" name="Text">
|
||||
<Property key="TextAlign" value="Right"/>
|
||||
<Property key="TextShadow" value="true"/>
|
||||
</Widget>
|
||||
<Widget type="ImageBox" skin="ImageBox" position="5 5 32 32" align="Stretch" name="Item"/>
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
@ -338,6 +342,10 @@
|
|||
<Resource type="ResourceLayout" name="MW_ItemIconBox" version="3.2.0">
|
||||
<Widget type="Widget" skin="" position="0 0 50 50" name="Root">
|
||||
<Widget type="ImageBox" skin="ImageBox" position="4 4 42 42" align="Center" name="Frame">
|
||||
<Widget type="TextBox" skin="SandBrightText" position="5 19 32 18" align="Right Bottom" name="Text">
|
||||
<Property key="TextAlign" value="Right"/>
|
||||
<Property key="TextShadow" value="true"/>
|
||||
</Widget>
|
||||
<Widget type="ImageBox" skin="ImageBox" position="5 5 32 32" align="Center" name="Item"/>
|
||||
</Widget>
|
||||
|
||||
|
|
Loading…
Reference in a new issue