1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-30 07:21:12 +00:00

Validate Argument is Index instead of Player

This commit is contained in:
kuyondo 2021-11-23 14:55:50 +08:00
parent 1b1de86b4a
commit 503f0e62e7
2 changed files with 16 additions and 16 deletions

View File

@ -79,14 +79,11 @@ namespace MWGui
delete mMagicSelectionDialog; delete mMagicSelectionDialog;
} }
// Check if quick keys are still valid inline void QuickKeysMenu::validate(int index)
void QuickKeysMenu::validate(MWWorld::Ptr player)
{ {
MWWorld::Ptr player = MWMechanics::getPlayer();
MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player);
switch (mKey[index].type)
for (int i = 0; i < 10; ++i)
{
switch (mKey[i].type)
{ {
case Type_Unassigned: case Type_Unassigned:
case Type_HandToHand: case Type_HandToHand:
@ -95,31 +92,34 @@ namespace MWGui
case Type_Item: case Type_Item:
case Type_MagicItem: case Type_MagicItem:
{ {
MWWorld::Ptr item = *mKey[i].button->getUserData<MWWorld::Ptr>(); MWWorld::Ptr item = *mKey[index].button->getUserData<MWWorld::Ptr>();
// Make sure the item is available and is not broken // Make sure the item is available and is not broken
std::cout << item << std::endl;
if (!item || item.getRefData().getCount() < 1 || if (!item || item.getRefData().getCount() < 1 ||
(item.getClass().hasItemHealth(item) && (item.getClass().hasItemHealth(item) &&
item.getClass().getItemHealth(item) <= 0)) item.getClass().getItemHealth(item) <= 0))
{ {
// Try searching for a compatible replacement // Try searching for a compatible replacement
item = store.findReplacement(mKey[i].id); item = store.findReplacement(mKey[index].id);
if (item) if (item)
mKey[i].button->setUserData(MWWorld::Ptr(item)); mKey[index].button->setUserData(MWWorld::Ptr(item));
break; break;
} }
} }
} }
}
} }
void QuickKeysMenu::onOpen() void QuickKeysMenu::onOpen()
{ {
WindowBase::onOpen(); WindowBase::onOpen();
MWWorld::Ptr player = MWMechanics::getPlayer(); // Quick key index
validate(player); for (int index = 0; index < 10; ++index)
{
validate(index);
}
} }
void QuickKeysMenu::unassign(keyData* key) void QuickKeysMenu::unassign(keyData* key)
@ -334,12 +334,12 @@ namespace MWGui
assert(index >= 1 && index <= 10); assert(index >= 1 && index <= 10);
keyData *key = &mKey[index-1]; keyData *key = &mKey[index-1];
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player);
const MWMechanics::CreatureStats &playerStats = player.getClass().getCreatureStats(player); const MWMechanics::CreatureStats &playerStats = player.getClass().getCreatureStats(player);
validate(player); validate(index-1);
// Delay action executing, // Delay action executing,
// if player is busy for now (casting a spell, attacking someone, etc.) // if player is busy for now (casting a spell, attacking someone, etc.)

View File

@ -32,7 +32,6 @@ namespace MWGui
void onAssignMagicItem (MWWorld::Ptr item); void onAssignMagicItem (MWWorld::Ptr item);
void onAssignMagic (const std::string& spellId); void onAssignMagic (const std::string& spellId);
void onAssignMagicCancel (); void onAssignMagicCancel ();
void validate(MWWorld::Ptr player);
void onOpen() override; void onOpen() override;
void activateQuickKey(int index); void activateQuickKey(int index);
@ -77,7 +76,8 @@ namespace MWGui
void onQuickKeyButtonClicked(MyGUI::Widget* sender); void onQuickKeyButtonClicked(MyGUI::Widget* sender);
void onOkButtonClicked(MyGUI::Widget* sender); void onOkButtonClicked(MyGUI::Widget* sender);
// Check if quick key is still valid
inline void validate(int index);
void unassign(keyData* key); void unassign(keyData* key);
}; };