1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-03 13:19:40 +00:00

added a scrollbar to the item container, dynamic positioning of items, fixed the item count display bug

This commit is contained in:
scrawl 2012-05-12 18:24:47 +02:00
parent a31a9e51d3
commit 1abf70692c
7 changed files with 35 additions and 14 deletions

View file

@ -125,7 +125,8 @@ void ContainerBase::drawItems()
int x = 4; int x = 4;
int y = 4; int y = 4;
int count = 0; int maxHeight = mItemView->getSize().height - 48;
int index = 0; int index = 0;
for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter)
@ -133,21 +134,21 @@ void ContainerBase::drawItems()
index++; index++;
if(iter->getRefData().getCount() > 0) if(iter->getRefData().getCount() > 0)
{ {
count++;
std::string path = std::string("icons\\"); std::string path = std::string("icons\\");
path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter);
ItemWidget* image = mContainerWidget->createWidget<ItemWidget>("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); ItemWidget* image = mContainerWidget->createWidget<ItemWidget>("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default);
MyGUI::TextBox* text = image->createWidget<MyGUI::TextBox>("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); MyGUI::TextBox* text = image->createWidget<MyGUI::TextBox>("SandBrightText", MyGUI::IntCoord(14, 14, 18, 18), MyGUI::Align::Default, std::string("Label"));
text->setTextAlign(MyGUI::Align::Right);
text->setNeedMouseFocus(false);
image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerBase::onSelectedItem); image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerBase::onSelectedItem);
image->setUserString("ToolTipType", "ItemPtr"); image->setUserString("ToolTipType", "ItemPtr");
image->setUserData(*iter); image->setUserData(*iter);
image->mPos = index; image->mPos = index;
x += 36;
if(count % 20 == 0)
{
y += 36; y += 36;
x = 4; if (y > maxHeight)
count = 0; {
x += 36;
y = 4;
} }
if(iter->getRefData().getCount() > 1) if(iter->getRefData().getCount() > 1)
@ -158,7 +159,11 @@ void ContainerBase::drawItems()
path.append(".dds"); path.append(".dds");
image->setImageTexture(path); image->setImageTexture(path);
} }
} }
MyGUI::IntSize size = MyGUI::IntSize(std::max(mItemView->getSize().width, x), 2048);
mItemView->setCanvasSize(size);
mContainerWidget->setSize(size);
} }
void ContainerBase::Update() void ContainerBase::Update()
@ -204,6 +209,7 @@ ContainerWindow::~ContainerWindow()
void ContainerWindow::onWindowResize(MyGUI::Window* window) void ContainerWindow::onWindowResize(MyGUI::Window* window)
{ {
drawItems();
} }
void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender) void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender)

View file

@ -24,6 +24,7 @@ namespace MWGui
InventoryWindow::InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) InventoryWindow::InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop)
: ContainerBase(parWindowManager,dragAndDrop,"openmw_inventory_window_layout.xml") : ContainerBase(parWindowManager,dragAndDrop,"openmw_inventory_window_layout.xml")
{ {
static_cast<MyGUI::Window*>(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize);
} }
void InventoryWindow::openInventory() void InventoryWindow::openInventory()
@ -31,4 +32,9 @@ namespace MWGui
open(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); open(MWBase::Environment::get().getWorld()->getPlayer().getPlayer());
} }
void InventoryWindow::onWindowResize(MyGUI::Window* _sender)
{
drawItems();
}
} }

View file

@ -27,6 +27,9 @@ namespace MWGui
InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop); InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop);
void openInventory(); void openInventory();
protected:
void onWindowResize(MyGUI::Window* _sender);
}; };
} }
#endif // Inventory_H #endif // Inventory_H

View file

@ -4,10 +4,10 @@
<Widget type="Window" skin="MW_Window" layer="Windows" position="900 500 600 300" name="_Main"> <Widget type="Window" skin="MW_Window" layer="Windows" position="900 500 600 300" name="_Main">
<!-- Items --> <!-- Items -->
<Widget type="Widget" skin="MW_Box" position="5 10 570 220" name="box" align="Left Top Stretch"> <Widget type="Widget" skin="MW_Box" position="5 5 575 225" name="box" align="Left Top Stretch">
<Widget type="ScrollView" skin="MW_ScrollView" position="4 4 566 216" name="ItemView" align="Left Top Stretch"> <Widget type="ScrollView" skin="MW_ScrollViewH" position="4 4 571 221" name="ItemView" align="Left Top Stretch">
<Property key="CanvasSize" value="1024 1024"/> <Property key="CanvasSize" value="1024 1024"/>
<Widget type="Button" skin="" name="Items" position="0 0 566 216" name="Items" align="Left Top Stretch"/> <Widget type="Button" skin="" name="Items" position="0 0 571 221" name="Items" align="Left Top Stretch"/>
</Widget> </Widget>
</Widget> </Widget>

View file

@ -15,7 +15,7 @@
<!-- Items in inventory --> <!-- Items in inventory -->
<Widget type="Widget" skin="MW_Box" position="228 32 300 215" name="box" align="Left Top Stretch"> <Widget type="Widget" skin="MW_Box" position="228 32 300 215" name="box" align="Left Top Stretch">
<Widget type="ScrollView" skin="MW_ScrollView" position="4 4 296 211" align="Left Top Stretch" name="ItemView"> <Widget type="ScrollView" skin="MW_ScrollViewH" position="4 4 296 211" align="Left Top Stretch" name="ItemView">
<Property key="CanvasSize" value="1024 1024"/> <Property key="CanvasSize" value="1024 1024"/>
<Widget type="Button" skin="" name="Items" position="0 0 296 211" name="Items" align="Left Top Stretch"/> <Widget type="Button" skin="" name="Items" position="0 0 296 211" name="Items" align="Left Top Stretch"/>
</Widget> </Widget>

View file

@ -131,6 +131,7 @@
<Skin name = "MW_HScroll" size = "90 14"> <Skin name = "MW_HScroll" size = "90 14">
<Property key="TrackRangeMargins" value = "14 14" /> <Property key="TrackRangeMargins" value = "14 14" />
<Property key="MinTrackSize" value = "14" /> <Property key="MinTrackSize" value = "14" />
<Property key="VerticalAlignment" value="false"/>
<!-- Background widget trick that must go first to be placed behind Track and FirstPart/SecondPart widgets, provides the bar texture --> <!-- Background widget trick that must go first to be placed behind Track and FirstPart/SecondPart widgets, provides the bar texture -->
<Child type="Button" skin="MW_HScrollBackground" offset = "14 0 62 14" align = "ALIGN_STRETCH" name = "Background"/> <Child type="Button" skin="MW_HScrollBackground" offset = "14 0 62 14" align = "ALIGN_STRETCH" name = "Background"/>
@ -143,7 +144,7 @@
<Child type="Button" skin="MW_ScrollEmptyPart" offset = "52 0 24 14" align = "ALIGN_TOP ALIGN_HSTRETCH" name = "SecondPart"/> <Child type="Button" skin="MW_ScrollEmptyPart" offset = "52 0 24 14" align = "ALIGN_TOP ALIGN_HSTRETCH" name = "SecondPart"/>
<!-- Tracker must be last to be on top and receive mouse events --> <!-- Tracker must be last to be on top and receive mouse events -->
<Child type="Button" skin="MW_ScrollTrack" offset = "38 0 14 14" align = "ALIGN_TOP ALIGN_VSTRETCH" name = "Track"/> <Child type="Button" skin="MW_ScrollTrack" offset = "38 0 14 14" align = "ALIGN_LEFT ALIGN_VSTRETCH" name = "Track"/>
</Skin> </Skin>
<!-- Morrowind has a 1 pixel gap between the top arrow and the inner bar, this skin does not replicate that --> <!-- Morrowind has a 1 pixel gap between the top arrow and the inner bar, this skin does not replicate that -->

View file

@ -7,4 +7,9 @@
<Child type="ScrollBar" skin="MW_VScroll" offset="498 3 14 509" align="ALIGN_RIGHT ALIGN_VSTRETCH" name="VScroll"/> <Child type="ScrollBar" skin="MW_VScroll" offset="498 3 14 509" align="ALIGN_RIGHT ALIGN_VSTRETCH" name="VScroll"/>
</Skin> </Skin>
<Skin name="MW_ScrollViewH" size="516 516" texture="mwgui.png">
<Child type="Widget" skin="" offset="0 0 516 516" align="Stretch" name="Client"/>
<Child type="ScrollBar" skin="MW_HScroll" offset="3 498 509 14" align="ALIGN_LEFT ALIGN_BOTTOM ALIGN_HSTRETCH" name="HScroll"/>
</Skin>
</MyGUI> </MyGUI>