From 6161f81c2475550feea994b405b6adb8df0ea762 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 27 Aug 2012 20:44:14 +0200 Subject: [PATCH] last bits of the quick key menu. --- apps/openmw/mwgui/itemselection.cpp | 6 ++ apps/openmw/mwgui/quickkeysmenu.cpp | 79 ++++++++++++++++++- apps/openmw/mwgui/spellwindow.cpp | 29 +------ apps/openmw/mwmechanics/spellsuccess.hpp | 2 + .../mygui/openmw_magicselection_dialog.layout | 8 +- 5 files changed, 91 insertions(+), 33 deletions(-) diff --git a/apps/openmw/mwgui/itemselection.cpp b/apps/openmw/mwgui/itemselection.cpp index 14b1cf8ee..d93a621ac 100644 --- a/apps/openmw/mwgui/itemselection.cpp +++ b/apps/openmw/mwgui/itemselection.cpp @@ -23,6 +23,12 @@ namespace MWGui getWidget(cancelButton, "CancelButton"); cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ItemSelectionDialog::onCancelButtonClicked); + int dx = (cancelButton->getTextSize().width + 24) - cancelButton->getWidth(); + cancelButton->setCoord(cancelButton->getLeft() - dx, + cancelButton->getTop(), + cancelButton->getTextSize ().width + 24, + cancelButton->getHeight()); + center(); } diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp index 853e2ed14..fcfac8d5d 100644 --- a/apps/openmw/mwgui/quickkeysmenu.cpp +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -6,8 +6,13 @@ #include "../mwbase/world.hpp" #include "../mwworld/player.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/actionequip.hpp" #include "../mwmechanics/spells.hpp" #include "../mwmechanics/creaturestats.hpp" +#include "../mwmechanics/spellsuccess.hpp" +#include "../mwgui/inventorywindow.hpp" +#include "../mwgui/bookwindow.hpp" +#include "../mwgui/scrollwindow.hpp" #include "windowmanagerimp.hpp" #include "itemselection.hpp" @@ -263,20 +268,82 @@ namespace MWGui QuickKeyType type = *button->getUserData(); + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + MWWorld::InventoryStore& store = MWWorld::Class::get(player).getInventoryStore(player); + MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); + MWMechanics::Spells& spells = stats.getSpells(); + if (type == Type_Magic) { std::string spellId = button->getChildAt(0)->getUserString("Spell"); - MWBase::Environment::get().getWindowManager ()->setSelectedSpell (spellId, 100); + spells.setSelectedSpell(spellId); + store.setSelectedEnchantItem(store.end()); + mWindowManager.setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player))); } else if (type == Type_Item) { MWWorld::Ptr item = *button->getChildAt (0)->getUserData(); - MWBase::Environment::get().getWindowManager ()->setSelectedWeapon(item, 100); + + // make sure the item is available + if (item.getRefData ().getCount() == 0) + { + MWBase::Environment::get().getWindowManager ()->messageBox ( + "#{sQuickMenu5} " + MWWorld::Class::get(item).getName(item), std::vector()); + return; + } + + boost::shared_ptr action = MWWorld::Class::get(item).use(item); + + action->execute (MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); + + // this is necessary for books/scrolls: if they are already in the player's inventory, + // the "Take" button should not be visible. + // NOTE: the take button is "reset" when the window opens, so we can safely do the following + // without screwing up future book windows + mWindowManager.getBookWindow()->setTakeButtonShow(false); + mWindowManager.getScrollWindow()->setTakeButtonShow(false); + + // since we changed equipping status, update the inventory window + mWindowManager.getInventoryWindow()->drawItems(); } else if (type == Type_MagicItem) { MWWorld::Ptr item = *button->getChildAt (0)->getUserData(); - MWBase::Environment::get().getWindowManager ()->setSelectedEnchantItem (item, 100); + + // make sure the item is available + if (item.getRefData ().getCount() == 0) + { + MWBase::Environment::get().getWindowManager ()->messageBox ( + "#{sQuickMenu5} " + MWWorld::Class::get(item).getName(item), std::vector()); + return; + } + + // retrieve ContainerStoreIterator to the item + MWWorld::ContainerStoreIterator it = store.begin(); + for (; it != store.end(); ++it) + { + if (*it == item) + { + break; + } + } + assert(it != store.end()); + + // equip, if it can be equipped + if (!MWWorld::Class::get(item).getEquipmentSlots(item).first.empty()) + { + // Note: can't use Class::use here because enchanted scrolls for example would then open the scroll window instead of equipping + + MWWorld::ActionEquip action(item); + action.execute (MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer ()); + + // since we changed equipping status, update the inventory window + mWindowManager.getInventoryWindow()->drawItems(); + } + + store.setSelectedEnchantItem(it); + spells.setSelectedSpell(""); + mWindowManager.setSelectedEnchantItem(item, 100); /// \todo track charge % } } @@ -339,6 +406,12 @@ namespace MWGui getWidget(mMagicList, "MagicList"); mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &MagicSelectionDialog::onCancelButtonClicked); + int dx = (mCancelButton->getTextSize().width + 24) - mCancelButton->getWidth(); + mCancelButton->setCoord(mCancelButton->getLeft() - dx, + mCancelButton->getTop(), + mCancelButton->getTextSize ().width + 24, + mCancelButton->getHeight()); + center(); } diff --git a/apps/openmw/mwgui/spellwindow.cpp b/apps/openmw/mwgui/spellwindow.cpp index 8754f5d10..bd671cab6 100644 --- a/apps/openmw/mwgui/spellwindow.cpp +++ b/apps/openmw/mwgui/spellwindow.cpp @@ -13,6 +13,7 @@ #include "../mwworld/player.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/actionequip.hpp" #include "../mwmechanics/spells.hpp" #include "../mwmechanics/creaturestats.hpp" @@ -350,34 +351,10 @@ namespace MWGui if (_sender->getUserString("Equipped") == "false" && !MWWorld::Class::get(item).getEquipmentSlots(item).first.empty()) { - // sound - MWBase::Environment::get().getSoundManager()->playSound(MWWorld::Class::get(item).getUpSoundId(item), 1.0, 1.0); - // Note: can't use Class::use here because enchanted scrolls for example would then open the scroll window instead of equipping - /// \todo the following code is pretty much copy&paste from ActionEquip, put it in a function? - // slots that this item can be equipped in - std::pair, bool> slots = MWWorld::Class::get(item).getEquipmentSlots(item); - - // equip the item in the first free slot - for (std::vector::const_iterator slot=slots.first.begin(); - slot!=slots.first.end(); ++slot) - { - // if all slots are occupied, replace the last slot - if (slot == --slots.first.end()) - { - store.equip(*slot, it); - break; - } - - if (store.getSlot(*slot) == store.end()) - { - // slot is not occupied - store.equip(*slot, it); - break; - } - } - /// \todo scripts? + MWWorld::ActionEquip action(item); + action.execute (MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer ()); // since we changed equipping status, update the inventory window mWindowManager.getInventoryWindow()->drawItems(); diff --git a/apps/openmw/mwmechanics/spellsuccess.hpp b/apps/openmw/mwmechanics/spellsuccess.hpp index 1ab1bb11f..e4778be69 100644 --- a/apps/openmw/mwmechanics/spellsuccess.hpp +++ b/apps/openmw/mwmechanics/spellsuccess.hpp @@ -8,6 +8,8 @@ #include "../mwworld/class.hpp" #include "../mwmechanics/creaturestats.hpp" +#include + #include "npcstats.hpp" namespace MWMechanics diff --git a/files/mygui/openmw_magicselection_dialog.layout b/files/mygui/openmw_magicselection_dialog.layout index bf942b32f..31ad7b4c9 100644 --- a/files/mygui/openmw_magicselection_dialog.layout +++ b/files/mygui/openmw_magicselection_dialog.layout @@ -2,16 +2,16 @@ - + - - + + - +