1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 03:35:27 +00:00

Merge branch 'minor_simpl_sortfilteritemodel' into 'master'

Minor simplifications in sortfilteritemmodel.cpp

See merge request OpenMW/openmw!1975
This commit is contained in:
psi29a 2022-06-12 18:43:50 +00:00
commit b7918282ad

View File

@ -28,27 +28,30 @@
namespace namespace
{ {
unsigned int getTypeOrder(unsigned int type)
{
switch (type)
{
case ESM::Weapon::sRecordId: return 0;
case ESM::Armor::sRecordId: return 1;
case ESM::Clothing::sRecordId: return 2;
case ESM::Potion::sRecordId: return 3;
case ESM::Ingredient::sRecordId: return 4;
case ESM::Apparatus::sRecordId: return 5;
case ESM::Book::sRecordId: return 6;
case ESM::Light::sRecordId: return 7;
case ESM::Miscellaneous::sRecordId: return 8;
case ESM::Lockpick::sRecordId: return 9;
case ESM::Repair::sRecordId: return 10;
case ESM::Probe::sRecordId: return 11;
}
assert(false && "Invalid type value");
return std::numeric_limits<unsigned int>::max();
}
bool compareType(unsigned int type1, unsigned int type2) bool compareType(unsigned int type1, unsigned int type2)
{ {
// this defines the sorting order of types. types that are first in the vector appear before other types. return getTypeOrder(type1) < getTypeOrder(type2);
std::vector<unsigned int> mapping;
mapping.emplace_back(ESM::Weapon::sRecordId );
mapping.emplace_back(ESM::Armor::sRecordId );
mapping.emplace_back(ESM::Clothing::sRecordId );
mapping.emplace_back(ESM::Potion::sRecordId );
mapping.emplace_back(ESM::Ingredient::sRecordId );
mapping.emplace_back(ESM::Apparatus::sRecordId );
mapping.emplace_back(ESM::Book::sRecordId );
mapping.emplace_back(ESM::Light::sRecordId );
mapping.emplace_back(ESM::Miscellaneous::sRecordId );
mapping.emplace_back(ESM::Lockpick::sRecordId );
mapping.emplace_back(ESM::Repair::sRecordId );
mapping.emplace_back(ESM::Probe::sRecordId );
assert( std::find(mapping.begin(), mapping.end(), type1) != mapping.end() );
assert( std::find(mapping.begin(), mapping.end(), type2) != mapping.end() );
return std::find(mapping.begin(), mapping.end(), type1) < std::find(mapping.begin(), mapping.end(), type2);
} }
struct Compare struct Compare
@ -180,23 +183,29 @@ namespace MWGui
MWWorld::Ptr base = item.mBase; MWWorld::Ptr base = item.mBase;
int category = 0; int category = 0;
if (base.getType() == ESM::Armor::sRecordId switch (base.getType())
|| base.getType() == ESM::Clothing::sRecordId) {
category = Category_Apparel; case ESM::Armor::sRecordId:
else if (base.getType() == ESM::Weapon::sRecordId) case ESM::Clothing::sRecordId:
category = Category_Weapon; category = Category_Apparel;
else if (base.getType() == ESM::Ingredient::sRecordId break;
|| base.getType() == ESM::Potion::sRecordId) case ESM::Weapon::sRecordId:
category = Category_Magic; category = Category_Weapon;
else if (base.getType() == ESM::Miscellaneous::sRecordId break;
|| base.getType() == ESM::Ingredient::sRecordId case ESM::Ingredient::sRecordId:
|| base.getType() == ESM::Repair::sRecordId case ESM::Potion::sRecordId:
|| base.getType() == ESM::Lockpick::sRecordId category = Category_Magic;
|| base.getType() == ESM::Light::sRecordId break;
|| base.getType() == ESM::Apparatus::sRecordId case ESM::Miscellaneous::sRecordId:
|| base.getType() == ESM::Book::sRecordId case ESM::Repair::sRecordId:
|| base.getType() == ESM::Probe::sRecordId) case ESM::Lockpick::sRecordId:
category = Category_Misc; case ESM::Light::sRecordId:
case ESM::Apparatus::sRecordId:
case ESM::Book::sRecordId:
case ESM::Probe::sRecordId:
category = Category_Misc;
break;
}
if (item.mFlags & ItemStack::Flag_Enchanted) if (item.mFlags & ItemStack::Flag_Enchanted)
category |= Category_Magic; category |= Category_Magic;