mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-15 09:39:53 +00:00
Make the Equip script function "use" items (drink potion, use alchemy, etc)
This commit is contained in:
parent
76fb68a9c0
commit
fd48c1d6f4
@ -148,6 +148,9 @@ namespace MWBase
|
||||
virtual MWGui::ConfirmationDialog* getConfirmationDialog() = 0;
|
||||
virtual MWGui::TradeWindow* getTradeWindow() = 0;
|
||||
|
||||
/// Make the player use an item, while updating GUI state accordingly
|
||||
virtual void useItem(const MWWorld::Ptr& item) = 0;
|
||||
|
||||
virtual void updateSpellWindow() = 0;
|
||||
|
||||
virtual void setConsoleSelectedObject(const MWWorld::Ptr& object) = 0;
|
||||
|
@ -21,8 +21,6 @@
|
||||
#include "../mwmechanics/creaturestats.hpp"
|
||||
#include "../mwmechanics/actorutil.hpp"
|
||||
|
||||
#include "../mwgui/inventorywindow.hpp"
|
||||
|
||||
#include "itemselection.hpp"
|
||||
#include "spellview.hpp"
|
||||
#include "itemwidget.hpp"
|
||||
@ -311,7 +309,7 @@ namespace MWGui
|
||||
else if (type == Type_Item)
|
||||
{
|
||||
MWWorld::Ptr item = *button->getUserData<MWWorld::Ptr>();
|
||||
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->useItem(item);
|
||||
MWBase::Environment::get().getWindowManager()->useItem(item);
|
||||
MWWorld::ContainerStoreIterator rightHand = store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
|
||||
// change draw state only if the item is in player's right hand
|
||||
if (rightHand != store.end() && item == *rightHand)
|
||||
@ -337,7 +335,7 @@ namespace MWGui
|
||||
// equip, if it can be equipped
|
||||
if (!item.getClass().getEquipmentSlots(item).first.empty())
|
||||
{
|
||||
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->useItem(item);
|
||||
MWBase::Environment::get().getWindowManager()->useItem(item);
|
||||
|
||||
// make sure that item was successfully equipped
|
||||
if (!store.isEquipped(item))
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "../mwmechanics/actorutil.hpp"
|
||||
|
||||
#include "spellicons.hpp"
|
||||
#include "inventorywindow.hpp"
|
||||
#include "confirmationdialog.hpp"
|
||||
#include "spellview.hpp"
|
||||
|
||||
@ -104,7 +103,7 @@ namespace MWGui
|
||||
if (!alreadyEquipped
|
||||
&& !item.getClass().getEquipmentSlots(item).first.empty())
|
||||
{
|
||||
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->useItem(item);
|
||||
MWBase::Environment::get().getWindowManager()->useItem(item);
|
||||
// make sure that item was successfully equipped
|
||||
if (!store.isEquipped(item))
|
||||
return;
|
||||
|
@ -1327,6 +1327,12 @@ namespace MWGui
|
||||
MWGui::ConfirmationDialog* WindowManager::getConfirmationDialog() { return mConfirmationDialog; }
|
||||
MWGui::TradeWindow* WindowManager::getTradeWindow() { return mTradeWindow; }
|
||||
|
||||
void WindowManager::useItem(const MWWorld::Ptr &item)
|
||||
{
|
||||
if (mInventoryWindow)
|
||||
mInventoryWindow->useItem(item);
|
||||
}
|
||||
|
||||
bool WindowManager::isAllowed (GuiWindow wnd) const
|
||||
{
|
||||
return (mAllowed & wnd) != 0;
|
||||
|
@ -173,6 +173,9 @@ namespace MWGui
|
||||
virtual MWGui::ConfirmationDialog* getConfirmationDialog();
|
||||
virtual MWGui::TradeWindow* getTradeWindow();
|
||||
|
||||
/// Make the player use an item, while updating GUI state accordingly
|
||||
virtual void useItem(const MWWorld::Ptr& item);
|
||||
|
||||
virtual void updateSpellWindow();
|
||||
|
||||
virtual void setConsoleSelectedObject(const MWWorld::Ptr& object);
|
||||
|
@ -191,11 +191,13 @@ namespace MWScript
|
||||
if (it == invStore.end())
|
||||
throw std::runtime_error("Item to equip not found");
|
||||
|
||||
MWWorld::ActionEquip action (*it);
|
||||
action.execute(ptr);
|
||||
|
||||
if (ptr == MWMechanics::getPlayer() && !ptr.getClass().getScript(ptr).empty())
|
||||
ptr.getRefData().getLocals().setVarByInt(ptr.getClass().getScript(ptr), "onpcequip", 1);
|
||||
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())
|
||||
MWBase::Environment::get().getWindowManager()->useItem(*it);
|
||||
else
|
||||
{
|
||||
boost::shared_ptr<MWWorld::Action> action = it->getClass().use(*it);
|
||||
action->execute(ptr);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user