mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-20 21:23:52 +00:00
Don't allow changing the spell that is being cast mid-animation
This commit is contained in:
parent
5054d8e6c1
commit
a3017e16d4
6 changed files with 23 additions and 70 deletions
|
@ -204,6 +204,7 @@ namespace MWBase
|
||||||
|
|
||||||
virtual void activateQuickKey (int index) = 0;
|
virtual void activateQuickKey (int index) = 0;
|
||||||
|
|
||||||
|
virtual std::string getSelectedSpell() = 0;
|
||||||
virtual void setSelectedSpell(const std::string& spellId, int successChancePercent) = 0;
|
virtual void setSelectedSpell(const std::string& spellId, int successChancePercent) = 0;
|
||||||
virtual void setSelectedEnchantItem(const MWWorld::Ptr& item) = 0;
|
virtual void setSelectedEnchantItem(const MWWorld::Ptr& item) = 0;
|
||||||
virtual void setSelectedWeapon(const MWWorld::Ptr& item) = 0;
|
virtual void setSelectedWeapon(const MWWorld::Ptr& item) = 0;
|
||||||
|
|
|
@ -275,7 +275,6 @@ namespace MWGui
|
||||||
if (type == Type_Magic)
|
if (type == Type_Magic)
|
||||||
{
|
{
|
||||||
std::string spellId = button->getChildAt(0)->getUserString("Spell");
|
std::string spellId = button->getChildAt(0)->getUserString("Spell");
|
||||||
spells.setSelectedSpell(spellId);
|
|
||||||
store.setSelectedEnchantItem(store.end());
|
store.setSelectedEnchantItem(store.end());
|
||||||
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player)));
|
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player)));
|
||||||
}
|
}
|
||||||
|
@ -342,7 +341,6 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
|
|
||||||
store.setSelectedEnchantItem(it);
|
store.setSelectedEnchantItem(it);
|
||||||
spells.setSelectedSpell("");
|
|
||||||
MWBase::Environment::get().getWindowManager()->setSelectedEnchantItem(item);
|
MWBase::Environment::get().getWindowManager()->setSelectedEnchantItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,61 +86,8 @@ namespace MWGui
|
||||||
MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player);
|
MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player);
|
||||||
MWMechanics::Spells& spells = stats.getSpells();
|
MWMechanics::Spells& spells = stats.getSpells();
|
||||||
|
|
||||||
// the following code switches between selected enchanted item and selected spell (only one of these
|
|
||||||
// can be active at a time)
|
|
||||||
std::string selectedSpell = spells.getSelectedSpell();
|
|
||||||
MWWorld::Ptr selectedItem;
|
|
||||||
if (store.getSelectedEnchantItem() != store.end())
|
|
||||||
{
|
|
||||||
selectedSpell = "";
|
|
||||||
selectedItem = *store.getSelectedEnchantItem();
|
|
||||||
|
|
||||||
bool allowSelectedItem = true;
|
|
||||||
|
|
||||||
// make sure that the item is still in the player inventory, otherwise it can't be selected
|
|
||||||
bool found = false;
|
|
||||||
for (MWWorld::ContainerStoreIterator it(store.begin()); it != store.end(); ++it)
|
|
||||||
{
|
|
||||||
if (*it == selectedItem)
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
if (!found)
|
|
||||||
allowSelectedItem = false;
|
|
||||||
|
|
||||||
// if the selected item can be equipped, make sure that it actually is equipped
|
|
||||||
std::pair<std::vector<int>, bool> slots_;
|
|
||||||
slots_ = MWWorld::Class::get(selectedItem).getEquipmentSlots(selectedItem);
|
|
||||||
if (!slots_.first.empty())
|
|
||||||
{
|
|
||||||
bool equipped = false;
|
|
||||||
for (int i=0; i < MWWorld::InventoryStore::Slots; ++i)
|
|
||||||
{
|
|
||||||
if (store.getSlot(i) != store.end() && *store.getSlot(i) == selectedItem)
|
|
||||||
{
|
|
||||||
equipped = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!equipped)
|
|
||||||
allowSelectedItem = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!allowSelectedItem)
|
|
||||||
{
|
|
||||||
store.setSelectedEnchantItem(store.end());
|
|
||||||
spells.setSelectedSpell("");
|
|
||||||
MWBase::Environment::get().getWindowManager()->unsetSelectedSpell();
|
|
||||||
selectedItem = MWWorld::Ptr();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (MWMechanics::Spells::TIterator it = spells.begin(); it != spells.end(); ++it)
|
for (MWMechanics::Spells::TIterator it = spells.begin(); it != spells.end(); ++it)
|
||||||
{
|
|
||||||
spellList.push_back (it->first);
|
spellList.push_back (it->first);
|
||||||
}
|
|
||||||
|
|
||||||
const MWWorld::ESMStore &esmStore =
|
const MWWorld::ESMStore &esmStore =
|
||||||
MWBase::Environment::get().getWorld()->getStore();
|
MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
@ -210,7 +157,7 @@ namespace MWGui
|
||||||
t->eventMouseWheel += MyGUI::newDelegate(this, &SpellWindow::onMouseWheel);
|
t->eventMouseWheel += MyGUI::newDelegate(this, &SpellWindow::onMouseWheel);
|
||||||
t->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellWindow::onSpellSelected);
|
t->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellWindow::onSpellSelected);
|
||||||
|
|
||||||
if (*it == selectedSpell)
|
if (*it == MWBase::Environment::get().getWindowManager()->getSelectedSpell())
|
||||||
t->setStateSelected(true);
|
t->setStateSelected(true);
|
||||||
|
|
||||||
mHeight += spellHeight;
|
mHeight += spellHeight;
|
||||||
|
@ -229,7 +176,7 @@ namespace MWGui
|
||||||
t->setUserString("Spell", *it);
|
t->setUserString("Spell", *it);
|
||||||
t->eventMouseWheel += MyGUI::newDelegate(this, &SpellWindow::onMouseWheel);
|
t->eventMouseWheel += MyGUI::newDelegate(this, &SpellWindow::onMouseWheel);
|
||||||
t->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellWindow::onSpellSelected);
|
t->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellWindow::onSpellSelected);
|
||||||
t->setStateSelected(*it == selectedSpell);
|
t->setStateSelected(*it == MWBase::Environment::get().getWindowManager()->getSelectedSpell());
|
||||||
|
|
||||||
// cost / success chance
|
// cost / success chance
|
||||||
MyGUI::Button* costChance = mSpellView->createWidget<MyGUI::Button>("SpellText",
|
MyGUI::Button* costChance = mSpellView->createWidget<MyGUI::Button>("SpellText",
|
||||||
|
@ -239,7 +186,7 @@ namespace MWGui
|
||||||
costChance->setCaption(cost + "/" + chance);
|
costChance->setCaption(cost + "/" + chance);
|
||||||
costChance->setTextAlign(MyGUI::Align::Right);
|
costChance->setTextAlign(MyGUI::Align::Right);
|
||||||
costChance->setNeedMouseFocus(false);
|
costChance->setNeedMouseFocus(false);
|
||||||
costChance->setStateSelected(*it == selectedSpell);
|
costChance->setStateSelected(*it == MWBase::Environment::get().getWindowManager()->getSelectedSpell());
|
||||||
|
|
||||||
|
|
||||||
mHeight += spellHeight;
|
mHeight += spellHeight;
|
||||||
|
@ -276,7 +223,9 @@ namespace MWGui
|
||||||
t->setUserString("Equipped", equipped ? "true" : "false");
|
t->setUserString("Equipped", equipped ? "true" : "false");
|
||||||
t->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellWindow::onEnchantedItemSelected);
|
t->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellWindow::onEnchantedItemSelected);
|
||||||
t->eventMouseWheel += MyGUI::newDelegate(this, &SpellWindow::onMouseWheel);
|
t->eventMouseWheel += MyGUI::newDelegate(this, &SpellWindow::onMouseWheel);
|
||||||
t->setStateSelected(item == selectedItem);
|
if (store.getSelectedEnchantItem() != store.end())
|
||||||
|
t->setStateSelected(item == *store.getSelectedEnchantItem());
|
||||||
|
|
||||||
|
|
||||||
// cost / charge
|
// cost / charge
|
||||||
MyGUI::Button* costCharge = mSpellView->createWidget<MyGUI::Button>(equipped ? "SpellText" : "SpellTextUnequipped",
|
MyGUI::Button* costCharge = mSpellView->createWidget<MyGUI::Button>(equipped ? "SpellText" : "SpellTextUnequipped",
|
||||||
|
@ -302,7 +251,8 @@ namespace MWGui
|
||||||
costCharge->setCaption(cost + "/" + charge);
|
costCharge->setCaption(cost + "/" + charge);
|
||||||
costCharge->setTextAlign(MyGUI::Align::Right);
|
costCharge->setTextAlign(MyGUI::Align::Right);
|
||||||
costCharge->setNeedMouseFocus(false);
|
costCharge->setNeedMouseFocus(false);
|
||||||
costCharge->setStateSelected(item == selectedItem);
|
if (store.getSelectedEnchantItem() != store.end())
|
||||||
|
costCharge->setStateSelected(item == *store.getSelectedEnchantItem());
|
||||||
|
|
||||||
mHeight += spellHeight;
|
mHeight += spellHeight;
|
||||||
}
|
}
|
||||||
|
@ -349,9 +299,7 @@ namespace MWGui
|
||||||
void SpellWindow::onEnchantedItemSelected(MyGUI::Widget* _sender)
|
void SpellWindow::onEnchantedItemSelected(MyGUI::Widget* _sender)
|
||||||
{
|
{
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player);
|
|
||||||
MWWorld::InventoryStore& store = MWWorld::Class::get(player).getInventoryStore(player);
|
MWWorld::InventoryStore& store = MWWorld::Class::get(player).getInventoryStore(player);
|
||||||
MWMechanics::Spells& spells = stats.getSpells();
|
|
||||||
MWWorld::Ptr item = *_sender->getUserData<MWWorld::Ptr>();
|
MWWorld::Ptr item = *_sender->getUserData<MWWorld::Ptr>();
|
||||||
|
|
||||||
// retrieve ContainerStoreIterator to the item
|
// retrieve ContainerStoreIterator to the item
|
||||||
|
@ -379,7 +327,6 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
|
|
||||||
store.setSelectedEnchantItem(it);
|
store.setSelectedEnchantItem(it);
|
||||||
spells.setSelectedSpell("");
|
|
||||||
MWBase::Environment::get().getWindowManager()->setSelectedEnchantItem(item);
|
MWBase::Environment::get().getWindowManager()->setSelectedEnchantItem(item);
|
||||||
|
|
||||||
updateSpells();
|
updateSpells();
|
||||||
|
@ -389,9 +336,7 @@ namespace MWGui
|
||||||
{
|
{
|
||||||
std::string spellId = _sender->getUserString("Spell");
|
std::string spellId = _sender->getUserString("Spell");
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player);
|
|
||||||
MWWorld::InventoryStore& store = MWWorld::Class::get(player).getInventoryStore(player);
|
MWWorld::InventoryStore& store = MWWorld::Class::get(player).getInventoryStore(player);
|
||||||
MWMechanics::Spells& spells = stats.getSpells();
|
|
||||||
|
|
||||||
if (MyGUI::InputManager::getInstance().isShiftPressed())
|
if (MyGUI::InputManager::getInstance().isShiftPressed())
|
||||||
{
|
{
|
||||||
|
@ -419,7 +364,6 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
spells.setSelectedSpell(spellId);
|
|
||||||
store.setSelectedEnchantItem(store.end());
|
store.setSelectedEnchantItem(store.end());
|
||||||
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player)));
|
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player)));
|
||||||
}
|
}
|
||||||
|
@ -450,10 +394,7 @@ namespace MWGui
|
||||||
MWMechanics::Spells& spells = stats.getSpells();
|
MWMechanics::Spells& spells = stats.getSpells();
|
||||||
|
|
||||||
if (spells.getSelectedSpell() == mSpellToDelete)
|
if (spells.getSelectedSpell() == mSpellToDelete)
|
||||||
{
|
|
||||||
spells.setSelectedSpell("");
|
|
||||||
MWBase::Environment::get().getWindowManager()->unsetSelectedSpell();
|
MWBase::Environment::get().getWindowManager()->unsetSelectedSpell();
|
||||||
}
|
|
||||||
|
|
||||||
spells.remove(mSpellToDelete);
|
spells.remove(mSpellToDelete);
|
||||||
|
|
||||||
|
|
|
@ -1010,6 +1010,7 @@ namespace MWGui
|
||||||
|
|
||||||
void WindowManager::setSelectedSpell(const std::string& spellId, int successChancePercent)
|
void WindowManager::setSelectedSpell(const std::string& spellId, int successChancePercent)
|
||||||
{
|
{
|
||||||
|
mSelectedSpell = spellId;
|
||||||
mHud->setSelectedSpell(spellId, successChancePercent);
|
mHud->setSelectedSpell(spellId, successChancePercent);
|
||||||
|
|
||||||
const ESM::Spell* spell =
|
const ESM::Spell* spell =
|
||||||
|
@ -1020,6 +1021,7 @@ namespace MWGui
|
||||||
|
|
||||||
void WindowManager::setSelectedEnchantItem(const MWWorld::Ptr& item)
|
void WindowManager::setSelectedEnchantItem(const MWWorld::Ptr& item)
|
||||||
{
|
{
|
||||||
|
mSelectedSpell = "";
|
||||||
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>()
|
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>()
|
||||||
.find(MWWorld::Class::get(item).getEnchantment(item));
|
.find(MWWorld::Class::get(item).getEnchantment(item));
|
||||||
|
|
||||||
|
@ -1039,6 +1041,7 @@ namespace MWGui
|
||||||
|
|
||||||
void WindowManager::unsetSelectedSpell()
|
void WindowManager::unsetSelectedSpell()
|
||||||
{
|
{
|
||||||
|
mSelectedSpell = "";
|
||||||
mHud->unsetSelectedSpell();
|
mHud->unsetSelectedSpell();
|
||||||
mSpellWindow->setTitle("#{sNone}");
|
mSpellWindow->setTitle("#{sNone}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,6 +200,7 @@ namespace MWGui
|
||||||
|
|
||||||
virtual void activateQuickKey (int index);
|
virtual void activateQuickKey (int index);
|
||||||
|
|
||||||
|
virtual std::string getSelectedSpell() { return mSelectedSpell; }
|
||||||
virtual void setSelectedSpell(const std::string& spellId, int successChancePercent);
|
virtual void setSelectedSpell(const std::string& spellId, int successChancePercent);
|
||||||
virtual void setSelectedEnchantItem(const MWWorld::Ptr& item);
|
virtual void setSelectedEnchantItem(const MWWorld::Ptr& item);
|
||||||
virtual void setSelectedWeapon(const MWWorld::Ptr& item);
|
virtual void setSelectedWeapon(const MWWorld::Ptr& item);
|
||||||
|
@ -288,6 +289,8 @@ namespace MWGui
|
||||||
void trackWindow(OEngine::GUI::Layout* layout, const std::string& name);
|
void trackWindow(OEngine::GUI::Layout* layout, const std::string& name);
|
||||||
void onWindowChangeCoord(MyGUI::Window* _sender);
|
void onWindowChangeCoord(MyGUI::Window* _sender);
|
||||||
|
|
||||||
|
std::string mSelectedSpell;
|
||||||
|
|
||||||
OEngine::GUI::MyGUIManager *mGuiManager;
|
OEngine::GUI::MyGUIManager *mGuiManager;
|
||||||
OEngine::Render::OgreRenderer *mRendering;
|
OEngine::Render::OgreRenderer *mRendering;
|
||||||
HUD *mHud;
|
HUD *mHud;
|
||||||
|
|
|
@ -511,7 +511,14 @@ bool CharacterController::updateNpcState(bool onground, bool inwater, bool isrun
|
||||||
|
|
||||||
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
|
||||||
const std::string spellid = stats.getSpells().getSelectedSpell();
|
// For the player, set the spell we want to cast
|
||||||
|
// This has to be done at the start of the casting animation,
|
||||||
|
// *not* when selecting a spell in the GUI (otherwise you could change the spell mid-animation)
|
||||||
|
if (mPtr.getRefData().getHandle() == "player")
|
||||||
|
stats.getSpells().setSelectedSpell(MWBase::Environment::get().getWindowManager()->getSelectedSpell());
|
||||||
|
|
||||||
|
std::string spellid = stats.getSpells().getSelectedSpell();
|
||||||
|
|
||||||
if(!spellid.empty() && MWBase::Environment::get().getWorld()->startSpellCast(mPtr))
|
if(!spellid.empty() && MWBase::Environment::get().getWorld()->startSpellCast(mPtr))
|
||||||
{
|
{
|
||||||
static const std::string schools[] = {
|
static const std::string schools[] = {
|
||||||
|
|
Loading…
Reference in a new issue