Merge pull request #296 from OpenMW/master while resolving conflicts

# Conflicts:
#	apps/openmw/mwgui/container.cpp
experimental
David Cernat 7 years ago
commit 73e7aa838d

@ -25,6 +25,7 @@
#include "../mwmechanics/actorutil.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwmechanics/pickpocket.hpp"
#include "../mwmechanics/creaturestats.hpp"
@ -303,11 +304,29 @@ namespace MWGui
void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender)
{
if(mDragAndDrop == NULL || !mDragAndDrop->mIsOnDragAndDrop)
{
if(mDragAndDrop != NULL && mDragAndDrop->mIsOnDragAndDrop)
return;
// transfer everything into the player's inventory
ItemModel* playerModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getModel();
mModel->update();
// unequip all items to avoid unequipping/reequipping
if (mPtr.getClass().hasInventoryStore(mPtr))
{
MWWorld::InventoryStore& invStore = mPtr.getClass().getInventoryStore(mPtr);
for (size_t i=0; i<mModel->getItemCount(); ++i)
{
const ItemStack& item = mModel->getItem(i);
if (invStore.isEquipped(item.mBase) == false)
continue;
invStore.unequipItem(item.mBase, mPtr);
}
}
mModel->update();
for (size_t i=0; i<mModel->getItemCount(); ++i)
{
if (i==0)
@ -354,7 +373,6 @@ namespace MWGui
End of tes3mp addition
*/
}
}
void ContainerWindow::onDisposeCorpseButtonClicked(MyGUI::Widget *sender)
{

@ -1,5 +1,10 @@
#include "inventoryitemmodel.hpp"
#include <sstream>
#include "../mwmechanics/actorutil.hpp"
#include "../mwmechanics/npcstats.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/inventorystore.hpp"
@ -45,16 +50,33 @@ MWWorld::Ptr InventoryItemModel::copyItem (const ItemStack& item, size_t count,
return *mActor.getClass().getContainerStore(mActor).add(item.mBase, count, mActor, setNewOwner);
}
void InventoryItemModel::removeItem (const ItemStack& item, size_t count)
{
int removed = 0;
// Re-equipping makes sense only if a target has inventory
if (mActor.getClass().hasInventoryStore(mActor))
{
MWWorld::InventoryStore& store = mActor.getClass().getInventoryStore(mActor);
removed = store.remove(item.mBase, count, mActor, true);
}
else
{
MWWorld::ContainerStore& store = mActor.getClass().getContainerStore(mActor);
int removed = store.remove(item.mBase, count, mActor);
removed = store.remove(item.mBase, count, mActor);
}
std::stringstream error;
if (removed == 0)
throw std::runtime_error("Item to remove not found in container store");
{
error << "Item '" << item.mBase.getCellRef().getRefId() << "' was not found in container store to remove";
throw std::runtime_error(error.str());
}
else if (removed < static_cast<int>(count))
throw std::runtime_error("Not enough items in the stack to remove");
{
error << "Not enough items '" << item.mBase.getCellRef().getRefId() << "' in the stack to remove (" << static_cast<int>(count) << " requested, " << removed << " found)";
throw std::runtime_error(error.str());
}
}
MWWorld::Ptr InventoryItemModel::moveItem(const ItemStack &item, size_t count, ItemModel *otherModel)

@ -1061,6 +1061,9 @@ namespace MWGui
mGlobalMapOverlayTexture.reset(new osgMyGUI::OSGTexture(mGlobalMapRender->getOverlayTexture()));
mGlobalMapOverlay->setRenderItemTexture(mGlobalMapOverlayTexture.get());
mGlobalMapOverlay->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 0.f, 1.f, 1.f));
// Redraw children in proper order
mGlobalMap->getParent()->_updateChilds();
}
}

@ -59,15 +59,91 @@ namespace
if (mSortByType && left.mType != right.mType)
return left.mType < right.mType;
if (left.mBase.getTypeName() == right.mBase.getTypeName())
{
std::string leftName = Misc::StringUtils::lowerCase(left.mBase.getClass().getName(left.mBase));
std::string rightName = Misc::StringUtils::lowerCase(right.mBase.getClass().getName(right.mBase));
float result = 0;
// compare items by type
std::string leftName = left.mBase.getTypeName();
std::string rightName = right.mBase.getTypeName();
if (leftName != rightName)
return compareType(leftName, rightName);
// compare items by name
leftName = Misc::StringUtils::lowerCase(left.mBase.getClass().getName(left.mBase));
rightName = Misc::StringUtils::lowerCase(right.mBase.getClass().getName(right.mBase));
result = leftName.compare(rightName);
if (result != 0)
return result < 0;
// compare items by enchantment:
// 1. enchanted items showed before non-enchanted
// 2. item with lesser charge percent comes after items with more charge percent
// 3. item with constant effect comes before items with non-constant effects
int leftChargePercent = -1;
int rightChargePercent = -1;
leftName = left.mBase.getClass().getEnchantment(left.mBase);
rightName = right.mBase.getClass().getEnchantment(right.mBase);
return leftName.compare(rightName) < 0;
if (!leftName.empty())
{
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(leftName);
if (ench)
{
if (ench->mData.mType == ESM::Enchantment::ConstantEffect)
leftChargePercent = 101;
else
leftChargePercent = (left.mBase.getCellRef().getEnchantmentCharge() == -1) ? 100
: static_cast<int>(left.mBase.getCellRef().getEnchantmentCharge() / static_cast<float>(ench->mData.mCharge) * 100);
}
}
if (!rightName.empty())
{
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(rightName);
if (ench)
{
if (ench->mData.mType == ESM::Enchantment::ConstantEffect)
rightChargePercent = 101;
else
return compareType(left.mBase.getTypeName(), right.mBase.getTypeName());
rightChargePercent = (right.mBase.getCellRef().getEnchantmentCharge() == -1) ? 100
: static_cast<int>(right.mBase.getCellRef().getEnchantmentCharge() / static_cast<float>(ench->mData.mCharge) * 100);
}
}
result = leftChargePercent - rightChargePercent;
if (result != 0)
return result > 0;
// compare items by condition
if (left.mBase.getClass().hasItemHealth(left.mBase) && right.mBase.getClass().hasItemHealth(right.mBase))
{
result = left.mBase.getClass().getItemHealth(left.mBase) - right.mBase.getClass().getItemHealth(right.mBase);
if (result != 0)
return result > 0;
}
// compare items by remaining usage time
result = left.mBase.getClass().getRemainingUsageTime(left.mBase) - right.mBase.getClass().getRemainingUsageTime(right.mBase);
if (result != 0)
return result > 0;
// compare items by value
result = left.mBase.getClass().getValue(left.mBase) - right.mBase.getClass().getValue(right.mBase);
if (result != 0)
return result > 0;
// compare items by weight
result = left.mBase.getClass().getWeight(left.mBase) - right.mBase.getClass().getWeight(right.mBase);
if (result != 0)
return result > 0;
// compare items by Id
leftName = left.mBase.getCellRef().getRefId();
rightName = right.mBase.getCellRef().getRefId();
result = leftName.compare(rightName);
return result < 0;
}
};
}

@ -235,6 +235,9 @@ namespace MWMechanics
gem->getContainerStore()->unstack(*gem, caster);
gem->getCellRef().setSoul(mCreature.getCellRef().getRefId());
// Restack the gem with other gems with the same soul
gem->getContainerStore()->restack(*gem);
mTrapped = true;
if (caster == getPlayer())

@ -1176,6 +1176,11 @@ bool CharacterController::updateWeaponState()
priorityWeapon[MWRender::Animation::BoneGroup_LowerBody] = Priority_WeaponLowerBody;
bool forcestateupdate = false;
// We should not play equipping animation and sound during weapon->weapon transition
bool isStillWeapon = weaptype > WeapType_HandToHand && weaptype < WeapType_Spell &&
mWeaponType > WeapType_HandToHand && mWeaponType < WeapType_Spell;
if(weaptype != mWeaponType && mHitState != CharState_KnockDown && mHitState != CharState_KnockOut
&& mHitState != CharState_Hit)
{
@ -1198,13 +1203,16 @@ bool CharacterController::updateWeaponState()
else
{
getWeaponGroup(weaptype, weapgroup);
mAnimation->showWeapons(false);
mAnimation->setWeaponGroup(weapgroup);
if (!isStillWeapon)
{
mAnimation->showWeapons(false);
mAnimation->play(weapgroup, priorityWeapon,
MWRender::Animation::BlendMask_All, true,
1.0f, "equip start", "equip stop", 0.0f, 0);
mUpperBodyState = UpperCharState_EquipingWeap;
}
if(isWerewolf)
{
@ -1218,7 +1226,7 @@ bool CharacterController::updateWeaponState()
}
}
if(!soundid.empty())
if(!soundid.empty() && !isStillWeapon)
{
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
sndMgr->playSound3D(mPtr, soundid, 1.0f, 1.0f);

@ -165,8 +165,7 @@ namespace MWScript
if (::Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), item))
itemName = iter->getClass().getName(*iter);
// Actors should not equip a replacement when items are removed with RemoveItem
int numRemoved = store.remove(item, count, ptr, false);
int numRemoved = store.remove(item, count, ptr);
// Spawn a messagebox (only for items removed from player's inventory)
if ((numRemoved > 0)

@ -408,13 +408,13 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::addNewStack (const Cons
return it;
}
int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const Ptr& actor, bool equipReplacement)
int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const Ptr& actor)
{
int toRemove = count;
for (ContainerStoreIterator iter(begin()); iter != end() && toRemove > 0; ++iter)
if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), itemId))
toRemove -= remove(*iter, toRemove, actor, equipReplacement);
toRemove -= remove(*iter, toRemove, actor);
flagAsModified();
@ -422,7 +422,7 @@ int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const
return count - toRemove;
}
int MWWorld::ContainerStore::remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement)
int MWWorld::ContainerStore::remove(const Ptr& item, int count, const Ptr& actor)
{
assert(this == item.getContainerStore());

@ -142,12 +142,12 @@ namespace MWWorld
ContainerStoreIterator add(const std::string& id, int count, const Ptr& actorPtr);
///< Utility to construct a ManualRef and call add(ptr, count, actorPtr, true)
int remove(const std::string& itemId, int count, const Ptr& actor, bool equipReplacement = true);
int remove(const std::string& itemId, int count, const Ptr& actor);
///< Remove \a count item(s) designated by \a itemId from this container.
///
/// @return the number of items actually removed
virtual int remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement = true);
virtual int remove(const Ptr& item, int count, const Ptr& actor);
///< Remove \a count item(s) designated by \a item from this inventory.
///
/// @return the number of items actually removed

@ -678,6 +678,11 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSelectedEnchantItem(
return mSelectedEnchantItem;
}
int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor)
{
return remove(item, count, actor, false);
}
int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement)
{
int retCount = ContainerStore::remove(item, count, actor);

@ -177,7 +177,8 @@ namespace MWWorld
virtual bool stacks (const ConstPtr& ptr1, const ConstPtr& ptr2) const;
///< @return true if the two specified objects can stack with each other
virtual int remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement = true);
virtual int remove(const Ptr& item, int count, const Ptr& actor);
virtual int remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement);
///< Remove \a count item(s) designated by \a item from this inventory.
///
/// @return the number of items actually removed

@ -171,9 +171,11 @@ namespace Gui
total_width += mSpacing;
}
if (mAutoResize && (total_width+mPadding*2 != getSize().width || total_height+mPadding*2 != getSize().height))
if (mAutoResize && (total_width+mPadding*2 != getClientCoord().width || total_height+mPadding*2 != getClientCoord().height))
{
setSize(MyGUI::IntSize(total_width+mPadding*2, total_height+mPadding*2));
int xmargin = getSize().width - getClientCoord().width;
int ymargin = getSize().height - getClientCoord().height;
setSize(MyGUI::IntSize(total_width+mPadding*2 + xmargin, total_height+mPadding*2 + ymargin));
return;
}
@ -191,19 +193,19 @@ namespace Gui
continue;
bool vstretch = w->getUserString ("VStretch") == "true";
int max_height = getSize().height - mPadding*2;
int max_height = getClientCoord().height - mPadding*2;
int height = vstretch ? max_height : sizes[i].first.height;
MyGUI::IntCoord widgetCoord;
widgetCoord.left = curX;
widgetCoord.top = mPadding + (getSize().height-mPadding*2 - height) / 2;
widgetCoord.top = mPadding + (getClientCoord().height-mPadding*2 - height) / 2;
int width = 0;
if (sizes[i].second)
{
if (h_stretched_count == 0)
throw std::logic_error("unexpected");
width = sizes[i].first.width + (getSize().width-mPadding*2 - total_width)/h_stretched_count;
width = sizes[i].first.width + (getClientCoord().width-mPadding*2 - total_width)/h_stretched_count;
}
else
width = sizes[i].first.width;
@ -317,13 +319,14 @@ namespace Gui
total_height += mSpacing;
}
if (mAutoResize && (total_width+mPadding*2 != getSize().width || total_height+mPadding*2 != getSize().height))
if (mAutoResize && (total_width+mPadding*2 != getClientCoord().width || total_height+mPadding*2 != getClientCoord().height))
{
setSize(MyGUI::IntSize(total_width+mPadding*2, total_height+mPadding*2));
int xmargin = getSize().width - getClientCoord().width;
int ymargin = getSize().height - getClientCoord().height;
setSize(MyGUI::IntSize(total_width+mPadding*2 + xmargin, total_height+mPadding*2 + ymargin));
return;
}
int curY = 0;
for (unsigned int i = 0; i < count; ++i)
{
@ -337,19 +340,19 @@ namespace Gui
continue;
bool hstretch = w->getUserString ("HStretch") == "true";
int maxWidth = getSize().width - mPadding*2;
int maxWidth = getClientCoord().width - mPadding*2;
int width = hstretch ? maxWidth : sizes[i].first.width;
MyGUI::IntCoord widgetCoord;
widgetCoord.top = curY;
widgetCoord.left = mPadding + (getSize().width-mPadding*2 - width) / 2;
widgetCoord.left = mPadding + (getClientCoord().width-mPadding*2 - width) / 2;
int height = 0;
if (sizes[i].second)
{
if (v_stretched_count == 0)
throw std::logic_error("unexpected");
height = sizes[i].first.height + (getSize().height-mPadding*2 - total_height)/v_stretched_count;
height = sizes[i].first.height + (getClientCoord().height-mPadding*2 - total_height)/v_stretched_count;
}
else
height = sizes[i].first.height;

@ -4,7 +4,7 @@
<Widget type="Window" skin="MW_DialogNoTransp" layer="Windows" position="0 0 244 248" align="Center" name="_Main">
<!-- Edit box -->
<Widget type="Widget" skin="MW_Box" position="8 8 220 192" align="Stretch" name="Client"/>
<Widget type="Widget" skin="MW_Box" position="8 8 220 192" align="Stretch"/>
<Widget type="EditBox" skin="MW_TextBoxEdit" position="10 10 218 190" name="TextEdit" align="Left Top Stretch">
<Property key="MultiLine" value="true"/>

@ -4,7 +4,7 @@
<Widget type="Window" skin="MW_Window" layer="Windows" position="0 0 588 433" name="_Main">
<Property key="MinSize" value="380 230"/>
<Widget type="Widget" skin="MW_Box" position="8 8 381 381" align="Stretch" name="Client"/>
<Widget type="Widget" skin="MW_Box" position="8 8 381 381" align="Stretch"/>
<Widget type="Widget" position="15 15 364 370" align="Left Top Stretch">
<Widget type="BookPage" skin="MW_BookPage" position="0 0 364 370" name="History" align="Left Top Stretch">

@ -32,19 +32,19 @@
</Widget>
<!-- Drowning bar -->
<Widget type="Widget" skin="MW_Dialog" position="0 36 230 58" align="Center Top" name="DrowningFrame">
<Widget type="Window" skin="MW_Dialog" position="0 36 230 58" align="Center Top" name="DrowningFrame">
<Property key="Visible" value="false"/>
<Widget type="TextBox" skin="SandText" position="2 7 226 24" name="DrowningTitle" align="Center Top HStretch">
<Widget type="TextBox" skin="SandText" position="0 3 222 24" name="DrowningTitle" align="Center Top HStretch">
<Property key="Caption" value="#{sBreath}"/>
<Property key="TextAlign" value="Center"/>
<Property key="TextShadow" value="true"/>
<Property key="TextShadowColour" value="0 0 0"/>
</Widget>
<Widget type="Widget" skin="MW_Box" position="15 33 200 10" align="Stretch" name="BoundingBox"/>
<Widget type="ProgressBar" skin="MW_Progress_Drowning_Full" position="17 35 196 6" align="Center Top" name="Drowning">
<Widget type="Widget" skin="MW_Box" position="11 29 200 10" align="Stretch" name="BoundingBox"/>
<Widget type="ProgressBar" skin="MW_Progress_Drowning_Full" position="13 31 196 6" align="Center Top" name="Drowning">
<Property key="NeedMouse" value="false"/>
</Widget>
<Widget type="Widget" skin="MW_Progress_Drowning_Small" position="19 37 192 2" align="Center Top" name="Flash"/>
<Widget type="Widget" skin="MW_Progress_Drowning_Small" position="15 33 192 2" align="Center Top" name="Flash"/>
</Widget>
<!-- Equipped weapon/selected spell name display for a few seconds after it changes -->

@ -8,27 +8,27 @@
<!-- The interior of the box -->
<Child type="Widget" skin="BlackBG" offset="0 0 40 40" align="Stretch" name="Client"/>
<Child type="Widget" skin="BlackBG" offset="0 0 40 40" align="Stretch"/>
<!-- Borders -->
<Child type="Widget" skin="MW_Box" offset="0 0 40 40" align="Left Stretch" name="Client"/>
<Child type="Widget" skin="MW_Box" offset="0 0 40 40" align="Left Stretch"/>
</Resource>
<Resource type="ResourceSkin" name="HUD_Box_Transparent" size="40 40">
<Child type="Widget" skin="MW_Box" offset="0 0 40 40" align="Left Stretch" name="Client"/>
<Child type="Widget" skin="MW_Box" offset="0 0 40 40" align="Left Stretch"/>
</Resource>
<Resource type="ResourceSkin" name="HUD_Box_NoTransp" size="40 40">
<!-- The interior of the box -->
<Child type="Widget" skin="DialogBG" offset="0 0 40 40" align="Stretch" name="Client"/>
<Child type="Widget" skin="DialogBG" offset="0 0 40 40" align="Stretch"/>
<!-- Borders -->
<Child type="Widget" skin="MW_Box" offset="0 0 40 40" align="Left Stretch" name="Client"/>
<Child type="Widget" skin="MW_Box" offset="0 0 40 40" align="Left Stretch"/>
</Resource>
@ -36,11 +36,11 @@
<!-- The interior of the box -->
<Child type="Widget" skin="DialogBG_NoTransp_Owned" offset="0 0 40 40" align="Stretch" name="Client"/>
<Child type="Widget" skin="DialogBG_NoTransp_Owned" offset="0 0 40 40" align="Stretch"/>
<!-- Borders -->
<Child type="Widget" skin="MW_Box" offset="0 0 40 40" align="Left Stretch" name="Client"/>
<Child type="Widget" skin="MW_Box" offset="0 0 40 40" align="Left Stretch"/>
</Resource>
@ -48,11 +48,11 @@
<!-- The interior of the box -->
<Child type="Widget" skin="DialogBG_Owned" offset="0 0 40 40" align="Stretch" name="Client"/>
<Child type="Widget" skin="DialogBG_Owned" offset="0 0 40 40" align="Stretch"/>
<!-- Borders -->
<Child type="Widget" skin="MW_Box" offset="0 0 40 40" align="Left Stretch" name="Client"/>
<Child type="Widget" skin="MW_Box" offset="0 0 40 40" align="Left Stretch"/>
</Resource>

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout">
<Widget type="Widget" skin="MW_Dialog" layer="LoadingScreen" position="0 0 300 48" align="Center" name="_Main">
<Widget type="Window" skin="MW_Dialog" layer="LoadingScreen" position="0 0 300 48" align="Center" name="_Main">
<Widget type="TextBox" skin="SandText" position="20 8 260 18" align="Stretch" name="LoadingText">
<Widget type="TextBox" skin="SandText" position="16 4 260 18" align="Stretch" name="LoadingText">
<Property key="TextAlign" value="Center"/>
<Property key="Caption" value="#{sInPrisonTitle}"/>
</Widget>
<Widget type="ScrollBar" skin="MW_ProgressScroll_Loading" position="20 30 260 6" name="ProgressBar">
<Widget type="ScrollBar" skin="MW_ProgressScroll_Loading" position="16 26 260 6" name="ProgressBar">
</Widget>
</Widget>

@ -4,13 +4,13 @@
<!-- The entire screen -->
<Widget type="Widget" layer="LoadingScreen" position="0 0 300 300" name="_Main" align="Stretch">
<Widget type="Widget" skin="MW_Dialog" position="0 245 300 48" align="Bottom HCenter" name="LoadingBox">
<Widget type="Window" skin="MW_Dialog" position="0 245 300 48" align="Bottom HCenter" name="LoadingBox">
<Widget type="TextBox" skin="SandText" position="20 9 260 18" align="Stretch" name="LoadingText">
<Widget type="TextBox" skin="SandText" position="16 5 260 18" align="Stretch" name="LoadingText">
<Property key="TextAlign" value="Center"/>
</Widget>
<Widget type="ScrollBar" skin="MW_ProgressScroll_Loading" position="20 30 260 6" align="Top HCenter" name="ProgressBar">
<Widget type="ScrollBar" skin="MW_ProgressScroll_Loading" position="16 26 260 6" align="Top HCenter" name="ProgressBar">
</Widget>
</Widget>

Loading…
Cancel
Save