Skip to content

Commit

Permalink
Fixes OpenMW#1158 (Armor rating label issues)
Browse files Browse the repository at this point in the history
  • Loading branch information
scrawl committed Feb 5, 2014
1 parent 8aed4fc commit f608cee
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
36 changes: 18 additions & 18 deletions apps/openmw/mwgui/inventorywindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace MWGui
getWidget(mRightPane, "RightPane");
getWidget(mArmorRating, "ArmorRating");

mAvatar->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onAvatarClicked);
mAvatarImage->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onAvatarClicked);

getWidget(mItemView, "ItemView");
mItemView->eventItemClicked += MyGUI::newDelegate(this, &InventoryWindow::onItemSelected);
Expand All @@ -76,11 +76,12 @@ namespace MWGui

void InventoryWindow::adjustPanes()
{
const float aspect = 0.5; // fixed aspect ratio for the left pane
mLeftPane->setSize( (mMainWidget->getSize().height-44) * aspect, mMainWidget->getSize().height-44 );
mRightPane->setCoord( mLeftPane->getPosition().left + (mMainWidget->getSize().height-44) * aspect + 4,
const float aspect = 0.5; // fixed aspect ratio for the avatar image
float leftPaneWidth = (mMainWidget->getSize().height-44-mArmorRating->getHeight()) * aspect;
mLeftPane->setSize( leftPaneWidth, mMainWidget->getSize().height-44 );
mRightPane->setCoord( mLeftPane->getPosition().left + leftPaneWidth + 4,
mRightPane->getPosition().top,
mMainWidget->getSize().width - 12 - (mMainWidget->getSize().height-44) * aspect - 15,
mMainWidget->getSize().width - 12 - leftPaneWidth - 15,
mMainWidget->getSize().height-44 );
}

Expand Down Expand Up @@ -418,9 +419,9 @@ namespace MWGui
else
{
MyGUI::IntPoint mousePos = MyGUI::InputManager::getInstance ().getLastPressedPosition (MyGUI::MouseButton::Left);
MyGUI::IntPoint relPos = mousePos - mAvatar->getAbsolutePosition ();
int realX = int(float(relPos.left) / float(mAvatar->getSize().width) * 512.f );
int realY = int(float(relPos.top) / float(mAvatar->getSize().height) * 1024.f );
MyGUI::IntPoint relPos = mousePos - mAvatarImage->getAbsolutePosition ();
int realX = int(float(relPos.left) / float(mAvatarImage->getSize().width) * 512.f );
int realY = int(float(relPos.top) / float(mAvatarImage->getSize().height) * 1024.f );

MWWorld::Ptr itemSelected = getAvatarSelectedItem (realX, realY);
if (itemSelected.isEmpty ())
Expand Down Expand Up @@ -487,11 +488,18 @@ namespace MWGui
if (mPreviewDirty)
{
mPreviewDirty = false;
MyGUI::IntSize size = mAvatar->getSize();
MyGUI::IntSize size = mAvatarImage->getSize();

mPreview.update (size.width, size.height);
mAvatarImage->setSize(MyGUI::IntSize(std::max(mAvatar->getSize().width, 512), std::max(mAvatar->getSize().height, 1024)));

mAvatarImage->setImageTexture("CharacterPreview");
mAvatarImage->setImageCoord(MyGUI::IntCoord(0, 0, std::min(512, size.width), std::min(1024, size.height)));
mAvatarImage->setImageTile(MyGUI::IntSize(std::min(512, size.width), std::min(1024, size.height)));

mArmorRating->setCaptionWithReplacing ("#{sArmor}: "
+ boost::lexical_cast<std::string>(static_cast<int>(MWWorld::Class::get(mPtr).getArmorRating(mPtr))));
if (mArmorRating->getTextSize().width > mArmorRating->getSize().width)
mArmorRating->setCaptionWithReplacing (boost::lexical_cast<std::string>(static_cast<int>(MWWorld::Class::get(mPtr).getArmorRating(mPtr))));
}
}

Expand All @@ -502,9 +510,6 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->getSpellWindow()->updateSpells();

mPreviewDirty = true;

mArmorRating->setCaptionWithReplacing ("#{sArmor}: "
+ boost::lexical_cast<std::string>(static_cast<int>(MWWorld::Class::get(mPtr).getArmorRating(mPtr))));
}

void InventoryWindow::pickUpObject (MWWorld::Ptr object)
Expand Down Expand Up @@ -551,9 +556,4 @@ namespace MWGui

MWBase::Environment::get().getMechanicsManager()->itemTaken(player, newObject, count);
}

MyGUI::IntCoord InventoryWindow::getAvatarScreenCoord ()
{
return mAvatar->getAbsoluteCoord ();
}
}
2 changes: 0 additions & 2 deletions apps/openmw/mwgui/inventorywindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ namespace MWGui

void pickUpObject (MWWorld::Ptr object);

MyGUI::IntCoord getAvatarScreenCoord();

MWWorld::Ptr getAvatarSelectedItem(int x, int y);

void rebuildAvatar() {
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwgui/tooltips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ namespace MWGui
}
else if (type == "AvatarItemSelection")
{
MyGUI::IntCoord avatarPos = MWBase::Environment::get().getWindowManager()->getInventoryWindow ()->getAvatarScreenCoord ();
MyGUI::IntCoord avatarPos = focus->getAbsoluteCoord();
MyGUI::IntPoint relMousePos = MyGUI::InputManager::getInstance ().getMousePosition () - MyGUI::IntPoint(avatarPos.left, avatarPos.top);
int realX = int(float(relMousePos.left) / float(avatarPos.width) * 512.f );
int realY = int(float(relMousePos.top) / float(avatarPos.height) * 1024.f );
Expand Down
7 changes: 3 additions & 4 deletions files/mygui/openmw_inventory_window.layout
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@

<!-- Avatar -->
<Widget type="Widget" skin="MW_Box" position="8 38 212 185" name="Avatar" align="Left Top Stretch">
<UserString key="ToolTipType" value="AvatarItemSelection"/>
<Widget type="ImageBox" skin="ImageBox" position="0 0 212 185" align="Stretch" name="AvatarImage">
<Property key="NeedMouse" value="false"/>
<Widget type="ImageBox" skin="ImageBox" position="0 0 212 161" align="Stretch" name="AvatarImage">
<UserString key="ToolTipType" value="AvatarItemSelection"/>
</Widget>
<Widget type="TextBox" skin="ProgressText" position="0 150 212 24" align="HCenter Bottom" name="ArmorRating">
<Widget type="TextBox" skin="ProgressText" position="0 161 212 24" align="HStretch Bottom" name="ArmorRating">
<Property key="NeedMouse" value="false"/>
</Widget>
</Widget>
Expand Down

0 comments on commit f608cee

Please sign in to comment.