From 2a11618ee7b4b6370f2ebe3d3898df43a7721006 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 17 Nov 2013 13:38:54 +0100 Subject: [PATCH] Make sure the equipped weapon HUD icon is updated properly --- apps/openmw/mwgui/inventorywindow.cpp | 8 -------- apps/openmw/mwgui/quickkeysmenu.cpp | 3 ++- apps/openmw/mwmechanics/character.cpp | 6 ++---- .../openmw/mwmechanics/mechanicsmanagerimp.cpp | 2 +- apps/openmw/mwworld/inventorystore.cpp | 18 ++++++++++++------ 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 8f8744917f..022e0a47d8 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -455,14 +455,6 @@ namespace MWGui if (MWBase::Environment::get().getWindowManager()->getSpellWindow()) MWBase::Environment::get().getWindowManager()->getSpellWindow()->updateSpells(); - // update selected weapon icon - MWWorld::InventoryStore& invStore = MWWorld::Class::get(mPtr).getInventoryStore(mPtr); - MWWorld::ContainerStoreIterator weaponSlot = invStore.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); - if (weaponSlot == invStore.end()) - MWBase::Environment::get().getWindowManager()->unsetSelectedWeapon(); - else - MWBase::Environment::get().getWindowManager()->setSelectedWeapon(*weaponSlot); - mPreviewDirty = true; mArmorRating->setCaptionWithReplacing ("#{sArmor}: " diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp index 503bf7c114..3956766499 100644 --- a/apps/openmw/mwgui/quickkeysmenu.cpp +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -284,8 +284,9 @@ namespace MWGui MWWorld::Ptr item = *button->getChildAt (0)->getUserData(); // make sure the item is available - if (item.getRefData ().getCount() == 0) + if (item.getRefData ().getCount() < 1) { + // TODO: Try to find a replacement with the same ID? MWBase::Environment::get().getWindowManager ()->messageBox ( "#{sQuickMenu5} " + MWWorld::Class::get(item).getName(item)); return; diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 240695a1cb..88c9f0ff6f 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -563,10 +563,8 @@ bool CharacterController::updateNpcState(bool onground, bool inwater, bool isrun if(!resultSound.empty()) MWBase::Environment::get().getSoundManager()->playSound(resultSound, 1.0f, 1.0f); - // tool used up? - if(!item.getRefData().getCount()) - MWBase::Environment::get().getWindowManager()->unsetSelectedWeapon(); - else + // Set again, just to update the charge bar + if(item.getRefData().getCount()) MWBase::Environment::get().getWindowManager()->setSelectedWeapon(item); } else diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index bbebcd6939..29b12b0f3a 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -159,7 +159,7 @@ namespace MWMechanics // auto-equip again. we need this for when the race is changed to a beast race MWWorld::InventoryStore& invStore = MWWorld::Class::get(ptr).getInventoryStore(ptr); for (int i=0; i=static_cast (mSlots.size())) throw std::runtime_error ("slot number out of range"); @@ -99,13 +102,11 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite throw std::runtime_error ("attempt to equip an item that is not in the inventory"); std::pair, bool> slots_; - if (iterator!=end()) - { - slots_ = Class::get (*iterator).getEquipmentSlots (*iterator); - if (std::find (slots_.first.begin(), slots_.first.end(), slot)==slots_.first.end()) - throw std::runtime_error ("invalid slot"); - } + slots_ = Class::get (*iterator).getEquipmentSlots (*iterator); + + if (std::find (slots_.first.begin(), slots_.first.end(), slot)==slots_.first.end()) + throw std::runtime_error ("invalid slot"); if (mSlots[slot] != end()) unequipSlot(slot, actor); @@ -126,6 +127,10 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite fireEquipmentChangedEvent(); updateMagicEffects(actor); + + // Update HUD icon for player weapon + if (slot == MWWorld::InventoryStore::Slot_CarriedRight) + MWBase::Environment::get().getWindowManager()->setSelectedWeapon(*getSlot(slot)); } void MWWorld::InventoryStore::unequipAll(const MWWorld::Ptr& actor) @@ -482,6 +487,7 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipSlot(int slot, c if ((mSelectedEnchantItem != end()) && (mSelectedEnchantItem == it)) { // enchanted item + mSelectedEnchantItem = end(); MWBase::Environment::get().getWindowManager()->unsetSelectedSpell(); } }