diff --git a/apps/openmw-mp/GUI.cpp b/apps/openmw-mp/GUI.cpp index 1601be65b..c439fb1b6 100644 --- a/apps/openmw-mp/GUI.cpp +++ b/apps/openmw-mp/GUI.cpp @@ -189,7 +189,7 @@ QuickKey QuickKeys::getQuickKey(int id) const return QuickKey(player->quickKeyChanges.quickKeys.at(id)); } -void QuickKeys::setQuickKey(int id, QuickKey quickKey) +void QuickKeys::setQuickKey(int id, const QuickKey &quickKey) { player->quickKeyChanges.quickKeys.at(id) = quickKey.quickKey; changed = true; @@ -230,12 +230,12 @@ void QuickKey::setSlot(unsigned short slot) quickKey.slot = slot; } -int QuickKey::getType() const +mwmp::QuickKey::Type QuickKey::getType() const { return quickKey.type; } -void QuickKey::setType(int type) +void QuickKey::setType(mwmp::QuickKey::Type type) { quickKey.type = type; } diff --git a/apps/openmw-mp/GUI.hpp b/apps/openmw-mp/GUI.hpp index 854027f0c..87ae35b9b 100644 --- a/apps/openmw-mp/GUI.hpp +++ b/apps/openmw-mp/GUI.hpp @@ -76,14 +76,13 @@ public: void update(); - void addQuickKey(QuickKey quickKey); + void addQuickKey(const QuickKey &quickKey); QuickKey getQuickKey(int id) const; - void setQuickKey(int id, QuickKey quickKey); + void setQuickKey(int id, const QuickKey &quickKey); size_t size() const; void clear(); private: - mwmp::QuickKey tempQuickKey; Player *player; bool changed; }; diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp index aa2726799..1c90d1503 100644 --- a/apps/openmw/mwgui/quickkeysmenu.cpp +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -128,7 +128,7 @@ namespace MWGui */ if (mwmp::Main::get().getLocalPlayer()->hasFinishedCharGen() && !mwmp::Main::get().getLocalPlayer()->isReceivingQuickKeys) { - mwmp::Main::get().getLocalPlayer()->sendQuickKey(index, Type_Unassigned); + mwmp::Main::get().getLocalPlayer()->sendQuickKey(index, mwmp::QuickKey::Type::Unassigned); } /* End of tes3mp addition @@ -235,7 +235,7 @@ namespace MWGui Send a PLAYER_QUICKKEYS packet whenever a key is assigned to an item */ if (!mwmp::Main::get().getLocalPlayer()->isReceivingQuickKeys) - mwmp::Main::get().getLocalPlayer()->sendQuickKey(mSelectedIndex, Type_Item, item.getCellRef().getRefId()); + mwmp::Main::get().getLocalPlayer()->sendQuickKey(mSelectedIndex, mwmp::QuickKey::Type::Item, item.getCellRef().getRefId()); /* End of tes3mp addition */ @@ -270,7 +270,7 @@ namespace MWGui Send a PLAYER_QUICKKEYS packet whenever a key is assigned to an item's magic */ if (!mwmp::Main::get().getLocalPlayer()->isReceivingQuickKeys) - mwmp::Main::get().getLocalPlayer()->sendQuickKey(mSelectedIndex, Type_MagicItem, item.getCellRef().getRefId()); + mwmp::Main::get().getLocalPlayer()->sendQuickKey(mSelectedIndex, mwmp::QuickKey::Type::MagicItem, item.getCellRef().getRefId()); /* End of tes3mp addition */ @@ -315,7 +315,7 @@ namespace MWGui Send a PLAYER_QUICKKEYS packet whenever a key is assigned to a spell */ if (!mwmp::Main::get().getLocalPlayer()->isReceivingQuickKeys) - mwmp::Main::get().getLocalPlayer()->sendQuickKey(mSelectedIndex, Type_Magic, spellId); + mwmp::Main::get().getLocalPlayer()->sendQuickKey(mSelectedIndex, mwmp::QuickKey::Type::Magic, spellId); /* End of tes3mp addition */ diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 63676a449..0b9015492 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -1032,9 +1032,9 @@ void LocalPlayer::setQuickKeys() for (const auto &quickKey : quickKeyChanges.quickKeys) { - LOG_APPEND(Log::LOG_INFO, "- slot: %i, type: %i, itemId: %s", quickKey.slot, quickKey.type, quickKey.itemId.c_str()); + LOG_APPEND(Log::LOG_INFO, "- slot: %i, type: %i, itemId: %s", quickKey.slot, (int)quickKey.type, quickKey.itemId.c_str()); - if (quickKey.type == QuickKey::ITEM || quickKey.type == QuickKey::ITEM_MAGIC) + if (quickKey.type == QuickKey::Type::Item || quickKey.type == QuickKey::Type::MagicItem) { MWWorld::InventoryStore &ptrInventory = ptrPlayer.getClass().getInventoryStore(ptrPlayer); @@ -1043,18 +1043,16 @@ void LocalPlayer::setQuickKeys() }); if (it != ptrInventory.end()) - MWBase::Environment::get().getWindowManager()->setQuickKey(quickKey.slot, quickKey.type, (*it)); + MWBase::Environment::get().getWindowManager()->setQuickKey(quickKey.slot, (int) quickKey.type, *it); } - else if (quickKey.type == QuickKey::MAGIC) + else if (quickKey.type == QuickKey::Type::Magic) { MWMechanics::Spells &ptrSpells = ptrPlayer.getClass().getCreatureStats(ptrPlayer).getSpells(); bool hasSpell = false; - MWMechanics::Spells::TIterator iter = ptrSpells.begin(); - for (; iter != ptrSpells.end(); iter++) + for (const auto &ptrSpell : ptrSpells) { - const ESM::Spell *spell = iter->first; - if (Misc::StringUtils::ciEqual(spell->mId, quickKey.itemId)) + if (Misc::StringUtils::ciEqual(ptrSpell.first->mId, quickKey.itemId)) { hasSpell = true; break; @@ -1062,10 +1060,10 @@ void LocalPlayer::setQuickKeys() } if (hasSpell) - MWBase::Environment::get().getWindowManager()->setQuickKey(quickKey.slot, quickKey.type, 0, quickKey.itemId); + MWBase::Environment::get().getWindowManager()->setQuickKey(quickKey.slot, (int) quickKey.type, 0, quickKey.itemId); } else - MWBase::Environment::get().getWindowManager()->setQuickKey(quickKey.slot, quickKey.type, 0); + MWBase::Environment::get().getWindowManager()->setQuickKey(quickKey.slot, (int) quickKey.type, 0); } isReceivingQuickKeys = false; @@ -1274,17 +1272,17 @@ void LocalPlayer::sendSpellRemoval(const ESM::Spell &spell) */ } -void LocalPlayer::sendQuickKey(unsigned short slot, int type, const std::string& itemId) +void LocalPlayer::sendQuickKey(int slot, QuickKey::Type type, const std::string& itemId) { quickKeyChanges.quickKeys.clear(); mwmp::QuickKey quickKey; - quickKey.slot = slot; + quickKey.slot = static_cast(slot); quickKey.type = type; quickKey.itemId = itemId; LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_PLAYER_QUICKKEYS", itemId.c_str()); - LOG_APPEND(Log::LOG_INFO, "- slot: %i, type: %i, itemId: %s", quickKey.slot, quickKey.type, quickKey.itemId.c_str()); + LOG_APPEND(Log::LOG_INFO, "- slot: %i, type: %i, itemId: %s", quickKey.slot, (int) quickKey.type, quickKey.itemId.c_str()); quickKeyChanges.quickKeys.push_back(quickKey); diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index b351de95c..9a19fb4a5 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -74,7 +74,7 @@ namespace mwmp void sendSpellAddition(const ESM::Spell &spell); void sendSpellRemoval(std::string id); void sendSpellRemoval(const ESM::Spell &spell); - void sendQuickKey(unsigned short slot, int type, const std::string& itemId = ""); + void sendQuickKey(int slot, QuickKey::Type type, const std::string& itemId = ""); void sendJournalEntry(const std::string& quest, int index, const MWWorld::Ptr& actor); void sendJournalIndex(const std::string& quest, int index); void sendFactionRank(const std::string& factionId, int rank); diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index c9cb7966d..c5807f828 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -85,16 +85,16 @@ namespace mwmp { std::string itemId; - enum QUICKKEY_TYPE + enum class Type : uint8_t { - ITEM = 0, - MAGIC = 1, - ITEM_MAGIC = 2, - UNASSIGNED = 3 + Item = 0, + Magic, + MagicItem, + Unassigned }; unsigned short slot; - int type; + Type type; }; struct CellState diff --git a/components/openmw-mp/Packets/Player/PacketPlayerQuickKeys.cpp b/components/openmw-mp/Packets/Player/PacketPlayerQuickKeys.cpp index 770c31b18..d60a8f8e5 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerQuickKeys.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerQuickKeys.cpp @@ -25,7 +25,7 @@ void PacketPlayerQuickKeys::Packet(RakNet::BitStream *bs, bool send) RW(quickKey.type, send); RW(quickKey.slot, send); - if (quickKey.type != QuickKey::UNASSIGNED) + if (quickKey.type != QuickKey::Type::Unassigned) RW(quickKey.itemId, send); } }