Make QuickKey type a fixed size enum class

depth-refraction
elsid 2 years ago
parent eb79b29512
commit d1e8e56619
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -76,12 +76,12 @@ namespace MWGui
MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player);
switch (mKey[index].type) switch (mKey[index].type)
{ {
case Type_Unassigned: case ESM::QuickKeys::Type::Unassigned:
case Type_HandToHand: case ESM::QuickKeys::Type::HandToHand:
case Type_Magic: case ESM::QuickKeys::Type::Magic:
break; break;
case Type_Item: case ESM::QuickKeys::Type::Item:
case Type_MagicItem: case ESM::QuickKeys::Type::MagicItem:
{ {
MWWorld::Ptr item = *mKey[index].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
@ -133,7 +133,7 @@ namespace MWGui
if (key->index == 10) if (key->index == 10)
{ {
key->type = Type_HandToHand; key->type = ESM::QuickKeys::Type::HandToHand;
MyGUI::ImageBox* image = key->button->createWidget<MyGUI::ImageBox>( MyGUI::ImageBox* image = key->button->createWidget<MyGUI::ImageBox>(
"ImageBox", MyGUI::IntCoord(14, 13, 32, 32), MyGUI::Align::Default); "ImageBox", MyGUI::IntCoord(14, 13, 32, 32), MyGUI::Align::Default);
@ -143,7 +143,7 @@ namespace MWGui
} }
else else
{ {
key->type = Type_Unassigned; key->type = ESM::QuickKeys::Type::Unassigned;
key->id = ESM::RefId(); key->id = ESM::RefId();
key->name.clear(); key->name.clear();
@ -176,7 +176,7 @@ namespace MWGui
mSelected = &mKey[index]; mSelected = &mKey[index];
// prevent reallocation of zero key from Type_HandToHand // prevent reallocation of zero key from ESM::QuickKeys::Type::HandToHand
if (mSelected->index == 10) if (mSelected->index == 10)
return; return;
@ -236,7 +236,7 @@ namespace MWGui
while (mSelected->button->getChildCount()) // Destroy number label while (mSelected->button->getChildCount()) // Destroy number label
MyGUI::Gui::getInstance().destroyWidget(mSelected->button->getChildAt(0)); MyGUI::Gui::getInstance().destroyWidget(mSelected->button->getChildAt(0));
mSelected->type = Type_Item; mSelected->type = ESM::QuickKeys::Type::Item;
mSelected->id = item.getCellRef().getRefId(); mSelected->id = item.getCellRef().getRefId();
mSelected->name = item.getClass().getName(item); mSelected->name = item.getClass().getName(item);
@ -260,7 +260,7 @@ namespace MWGui
while (mSelected->button->getChildCount()) // Destroy number label while (mSelected->button->getChildCount()) // Destroy number label
MyGUI::Gui::getInstance().destroyWidget(mSelected->button->getChildAt(0)); MyGUI::Gui::getInstance().destroyWidget(mSelected->button->getChildAt(0));
mSelected->type = Type_MagicItem; mSelected->type = ESM::QuickKeys::Type::MagicItem;
mSelected->id = item.getCellRef().getRefId(); mSelected->id = item.getCellRef().getRefId();
mSelected->name = item.getClass().getName(item); mSelected->name = item.getClass().getName(item);
@ -290,7 +290,7 @@ namespace MWGui
const MWWorld::ESMStore& esmStore = MWBase::Environment::get().getWorld()->getStore(); const MWWorld::ESMStore& esmStore = MWBase::Environment::get().getWorld()->getStore();
const ESM::Spell* spell = esmStore.get<ESM::Spell>().find(spellId); const ESM::Spell* spell = esmStore.get<ESM::Spell>().find(spellId);
mSelected->type = Type_Magic; mSelected->type = ESM::QuickKeys::Type::Magic;
mSelected->id = spellId; mSelected->id = spellId;
mSelected->name = spell->mName; mSelected->name = spell->mName;
@ -369,7 +369,7 @@ namespace MWGui
mActivated = nullptr; mActivated = nullptr;
} }
if (key->type == Type_Item || key->type == Type_MagicItem) if (key->type == ESM::QuickKeys::Type::Item || key->type == ESM::QuickKeys::Type::MagicItem)
{ {
MWWorld::Ptr item = *key->button->getUserData<MWWorld::Ptr>(); MWWorld::Ptr item = *key->button->getUserData<MWWorld::Ptr>();
@ -396,7 +396,7 @@ namespace MWGui
} }
} }
if (key->type == Type_Item) if (key->type == ESM::QuickKeys::Type::Item)
{ {
if (!store.isEquipped(item)) if (!store.isEquipped(item))
MWBase::Environment::get().getWindowManager()->useItem(item); MWBase::Environment::get().getWindowManager()->useItem(item);
@ -408,7 +408,7 @@ namespace MWGui
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState::Weapon); MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState::Weapon);
} }
} }
else if (key->type == Type_MagicItem) else if (key->type == ESM::QuickKeys::Type::MagicItem)
{ {
// equip, if it can be equipped and isn't yet equipped // equip, if it can be equipped and isn't yet equipped
if (!item.getClass().getEquipmentSlots(item).first.empty() && !store.isEquipped(item)) if (!item.getClass().getEquipmentSlots(item).first.empty() && !store.isEquipped(item))
@ -424,7 +424,7 @@ namespace MWGui
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState::Spell); MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState::Spell);
} }
} }
else if (key->type == Type_Magic) else if (key->type == ESM::QuickKeys::Type::Magic)
{ {
const ESM::RefId& spellId = key->id; const ESM::RefId& spellId = key->id;
@ -443,7 +443,7 @@ namespace MWGui
spellId, int(MWMechanics::getSpellSuccessChance(spellId, player))); spellId, int(MWMechanics::getSpellSuccessChance(spellId, player)));
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState::Spell); MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState::Spell);
} }
else if (key->type == Type_HandToHand) else if (key->type == ESM::QuickKeys::Type::HandToHand)
{ {
store.unequipSlot(MWWorld::InventoryStore::Slot_CarriedRight); store.unequipSlot(MWWorld::InventoryStore::Slot_CarriedRight);
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState::Weapon); MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState::Weapon);
@ -499,24 +499,24 @@ namespace MWGui
{ {
ItemWidget* button = mKey[i].button; ItemWidget* button = mKey[i].button;
int type = mKey[i].type; const ESM::QuickKeys::Type type = mKey[i].type;
ESM::QuickKeys::QuickKey key; ESM::QuickKeys::QuickKey key;
key.mType = type; key.mType = type;
switch (type) switch (type)
{ {
case Type_Unassigned: case ESM::QuickKeys::Type::Unassigned:
case Type_HandToHand: case ESM::QuickKeys::Type::HandToHand:
break; break;
case Type_Item: case ESM::QuickKeys::Type::Item:
case Type_MagicItem: case ESM::QuickKeys::Type::MagicItem:
{ {
MWWorld::Ptr item = *button->getUserData<MWWorld::Ptr>(); MWWorld::Ptr item = *button->getUserData<MWWorld::Ptr>();
key.mId = item.getCellRef().getRefId(); key.mId = item.getCellRef().getRefId();
break; break;
} }
case Type_Magic: case ESM::QuickKeys::Type::Magic:
key.mId = ESM::RefId::stringRefId(button->getUserString("Spell")); key.mId = ESM::RefId::stringRefId(button->getUserString("Spell"));
break; break;
} }
@ -551,12 +551,12 @@ namespace MWGui
switch (quickKey.mType) switch (quickKey.mType)
{ {
case Type_Magic: case ESM::QuickKeys::Type::Magic:
if (MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(quickKey.mId)) if (MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(quickKey.mId))
onAssignMagic(quickKey.mId); onAssignMagic(quickKey.mId);
break; break;
case Type_Item: case ESM::QuickKeys::Type::Item:
case Type_MagicItem: case ESM::QuickKeys::Type::MagicItem:
{ {
// Find the item by id // Find the item by id
MWWorld::Ptr item = store.findReplacement(quickKey.mId); MWWorld::Ptr item = store.findReplacement(quickKey.mId);
@ -565,16 +565,16 @@ namespace MWGui
unassign(mSelected); unassign(mSelected);
else else
{ {
if (quickKey.mType == Type_Item) if (quickKey.mType == ESM::QuickKeys::Type::Item)
onAssignItem(item); onAssignItem(item);
else // if (quickKey.mType == Type_MagicItem) else // if (quickKey.mType == ESM::QuickKeys::Type::MagicItem)
onAssignMagicItem(item); onAssignMagicItem(item);
} }
break; break;
} }
case Type_Unassigned: case ESM::QuickKeys::Type::Unassigned:
case Type_HandToHand: case ESM::QuickKeys::Type::HandToHand:
unassign(mSelected); unassign(mSelected);
break; break;
} }

@ -3,6 +3,8 @@
#include <memory> #include <memory>
#include "components/esm3/quickkeys.hpp"
#include "itemselection.hpp" #include "itemselection.hpp"
#include "spellmodel.hpp" #include "spellmodel.hpp"
#include "windowbase.hpp" #include "windowbase.hpp"
@ -38,16 +40,6 @@ namespace MWGui
void activateQuickKey(int index); void activateQuickKey(int index);
void updateActivatedQuickKey(); void updateActivatedQuickKey();
/// @note This enum is serialized, so don't move the items around!
enum QuickKeyType
{
Type_Item,
Type_Magic,
Type_MagicItem,
Type_Unassigned,
Type_HandToHand
};
void write(ESM::ESMWriter& writer); void write(ESM::ESMWriter& writer);
void readRecord(ESM::ESMReader& reader, uint32_t type); void readRecord(ESM::ESMReader& reader, uint32_t type);
void clear() override; void clear() override;
@ -57,7 +49,7 @@ namespace MWGui
{ {
int index = -1; int index = -1;
ItemWidget* button = nullptr; ItemWidget* button = nullptr;
QuickKeysMenu::QuickKeyType type = Type_Unassigned; ESM::QuickKeys::Type type = ESM::QuickKeys::Type::Unassigned;
ESM::RefId id; ESM::RefId id;
std::string name; std::string name;
}; };

@ -63,7 +63,8 @@ namespace ESM
inline std::ostream& operator<<(std::ostream& stream, const ESM::QuickKeys::QuickKey& value) inline std::ostream& operator<<(std::ostream& stream, const ESM::QuickKeys::QuickKey& value)
{ {
return stream << "ESM::QuickKeys::QuickKey {.mType = '" << value.mType << "', .mId = " << value.mId << "}"; return stream << "ESM::QuickKeys::QuickKey {.mType = '" << static_cast<std::uint32_t>(value.mType)
<< "', .mId = " << value.mId << "}";
} }
namespace namespace
@ -312,11 +313,11 @@ namespace ESM
const QuickKeys record { const QuickKeys record {
.mKeys = { .mKeys = {
{ {
.mType = 42, .mType = QuickKeys::Type::Magic,
.mId = generateRandomRefId(32), .mId = generateRandomRefId(32),
}, },
{ {
.mType = 13, .mType = QuickKeys::Type::MagicItem,
.mId = generateRandomRefId(32), .mId = generateRandomRefId(32),
}, },
}, },

@ -13,11 +13,8 @@ namespace ESM
while (esm.isNextSub("TYPE")) while (esm.isNextSub("TYPE"))
{ {
int keyType;
esm.getHT(keyType);
QuickKey key; QuickKey key;
key.mType = keyType; esm.getHT(key.mType);
key.mId = esm.getHNRefId("ID__"); key.mId = esm.getHNRefId("ID__");
mKeys.push_back(key); mKeys.push_back(key);

@ -13,9 +13,18 @@ namespace ESM
struct QuickKeys struct QuickKeys
{ {
enum class Type : std::uint32_t
{
Item = 0,
Magic = 1,
MagicItem = 2,
Unassigned = 3,
HandToHand = 4,
};
struct QuickKey struct QuickKey
{ {
int mType; Type mType;
RefId mId; // Spell or Item ID RefId mId; // Spell or Item ID
}; };

Loading…
Cancel
Save