From f88be67556f93596c3f2d2cd62fa6e8d70a14a30 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Sat, 18 Apr 2015 09:37:19 +1000 Subject: [PATCH] Convert AI package type and AI wander repeat columns in the nested tables to use enum delegate --- apps/opencs/model/world/columnbase.cpp | 2 + apps/opencs/model/world/columnbase.hpp | 2 + apps/opencs/model/world/columns.cpp | 15 +++- apps/opencs/model/world/columns.hpp | 2 +- apps/opencs/model/world/refidadapterimp.hpp | 77 +++++++-------------- apps/opencs/model/world/refidcollection.cpp | 4 +- apps/opencs/view/doc/viewmanager.cpp | 4 +- 7 files changed, 48 insertions(+), 58 deletions(-) diff --git a/apps/opencs/model/world/columnbase.cpp b/apps/opencs/model/world/columnbase.cpp index cea00b7bc..659954f48 100644 --- a/apps/opencs/model/world/columnbase.cpp +++ b/apps/opencs/model/world/columnbase.cpp @@ -79,6 +79,8 @@ bool CSMWorld::ColumnBase::isId (Display display) Display_EffectRange, Display_EffectId, Display_PartRefType, + Display_AiPackageType, + Display_YesNo, Display_None }; diff --git a/apps/opencs/model/world/columnbase.hpp b/apps/opencs/model/world/columnbase.hpp index 20e3ccce6..4c3f9385a 100644 --- a/apps/opencs/model/world/columnbase.hpp +++ b/apps/opencs/model/world/columnbase.hpp @@ -113,6 +113,8 @@ namespace CSMWorld Display_EffectRange, Display_EffectId, Display_PartRefType, + Display_AiPackageType, + Display_YesNo, //top level columns that nest other columns Display_NestedHeader diff --git a/apps/opencs/model/world/columns.cpp b/apps/opencs/model/world/columns.cpp index fd090d181..1b5aefee9 100644 --- a/apps/opencs/model/world/columns.cpp +++ b/apps/opencs/model/world/columns.cpp @@ -248,7 +248,7 @@ namespace CSMWorld { ColumnId_EffectArea, "Area" }, { ColumnId_AiPackageList, "Ai Packages" }, - { ColumnId_AiPackage, "Package" }, + { ColumnId_AiPackageType, "Package" }, { ColumnId_AiWanderDist, "Wander Dist" }, { ColumnId_AiDuration, "Duration" }, { ColumnId_AiWanderToD, "Wander ToD" }, @@ -487,6 +487,17 @@ namespace "Weapon", "Tail", 0 }; + // see the enums in + static const char *sAiPackageType[] = + { + "AI Wander", "AI Travel", "AI Follow", "AI Escort", "AI Activate", 0 + }; + + static const char *sAiWanderRepeat[] = + { + "No", "Yes", 0 + }; + const char **getEnumNames (CSMWorld::Columns::ColumnId column) { switch (column) @@ -513,6 +524,8 @@ namespace case CSMWorld::Columns::ColumnId_EffectRange: return sEffectRange; case CSMWorld::Columns::ColumnId_EffectId: return sEffectId; case CSMWorld::Columns::ColumnId_PartRefType: return sPartRefType; + case CSMWorld::Columns::ColumnId_AiPackageType: return sAiPackageType; + case CSMWorld::Columns::ColumnId_AiWanderRepeat: return sAiWanderRepeat; default: return 0; } diff --git a/apps/opencs/model/world/columns.hpp b/apps/opencs/model/world/columns.hpp index 7508c9880..1760bff30 100644 --- a/apps/opencs/model/world/columns.hpp +++ b/apps/opencs/model/world/columns.hpp @@ -237,7 +237,7 @@ namespace CSMWorld ColumnId_EffectArea = 218, ColumnId_AiPackageList = 219, - ColumnId_AiPackage = 220, + ColumnId_AiPackageType = 220, ColumnId_AiWanderDist = 221, ColumnId_AiDuration = 222, ColumnId_AiWanderToD = 223, diff --git a/apps/opencs/model/world/refidadapterimp.hpp b/apps/opencs/model/world/refidadapterimp.hpp index 489808393..5fd888441 100644 --- a/apps/opencs/model/world/refidadapterimp.hpp +++ b/apps/opencs/model/world/refidadapterimp.hpp @@ -1318,34 +1318,13 @@ namespace CSMWorld switch(subColIndex) { - case 0: - list.at(subRowIndex).mCellName = std::string(value.toString().toUtf8().constData()); - break; - - case 1: - list.at(subRowIndex).mPos.pos[0] = value.toFloat(); - break; - - case 2: - list.at(subRowIndex).mPos.pos[1] = value.toFloat(); - break; - - case 3: - list.at(subRowIndex).mPos.pos[2] = value.toFloat(); - break; - - case 4: - list.at(subRowIndex).mPos.rot[0] = value.toFloat(); - break; - - case 5: - list.at(subRowIndex).mPos.rot[1] = value.toFloat(); - break; - - case 6: - list.at(subRowIndex).mPos.rot[2] = value.toFloat(); - break; - + case 0: list.at(subRowIndex).mCellName = std::string(value.toString().toUtf8().constData()); break; + case 1: list.at(subRowIndex).mPos.pos[0] = value.toFloat(); break; + case 2: list.at(subRowIndex).mPos.pos[1] = value.toFloat(); break; + case 3: list.at(subRowIndex).mPos.pos[2] = value.toFloat(); break; + case 4: list.at(subRowIndex).mPos.rot[0] = value.toFloat(); break; + case 5: list.at(subRowIndex).mPos.rot[1] = value.toFloat(); break; + case 6: list.at(subRowIndex).mPos.rot[2] = value.toFloat(); break; default: throw std::runtime_error("Trying to access non-existing column in the nested table!"); } @@ -1461,13 +1440,13 @@ namespace CSMWorld case 0: switch (content.mType) { - case ESM::AI_Wander: return QString("AI Wander"); - case ESM::AI_Travel: return QString("AI Travel"); - case ESM::AI_Follow: return QString("AI Follow"); - case ESM::AI_Escort: return QString("AI Escort"); - case ESM::AI_Activate: return QString("AI Activate"); + case ESM::AI_Wander: return 0; + case ESM::AI_Travel: return 1; + case ESM::AI_Follow: return 2; + case ESM::AI_Escort: return 3; + case ESM::AI_Activate: return 4; case ESM::AI_CNDT: - default: return QString("None"); + default: return QVariant(); } case 1: // wander dist if (content.mType == ESM::AI_Wander) @@ -1494,7 +1473,7 @@ namespace CSMWorld return QVariant(); case 5: // wander repeat if (content.mType == ESM::AI_Wander) - return QString(content.mWander.mShouldRepeat ? "Yes" : "No"); + return content.mWander.mShouldRepeat; else return QVariant(); case 6: // activate name @@ -1554,18 +1533,14 @@ namespace CSMWorld switch(subColIndex) { case 0: // ai package type - if ("AI Wander" == value.toString().toStdString()) - content.mType = ESM::AI_Wander; - else if ("AI Travel" == value.toString().toStdString()) - content.mType = ESM::AI_Travel; - else if ("AI Follow" == value.toString().toStdString()) - content.mType = ESM::AI_Follow; - else if ("AI Escort" == value.toString().toStdString()) - content.mType = ESM::AI_Escort; - else if ("AI Activate" == value.toString().toStdString()) - content.mType = ESM::AI_Activate; - else - content.mType = ESM::AI_CNDT; + switch (value.toInt()) + { + case 0: content.mType = ESM::AI_Wander; + case 1: content.mType = ESM::AI_Travel; + case 2: content.mType = ESM::AI_Follow; + case 3: content.mType = ESM::AI_Escort; + case 4: content.mType = ESM::AI_Activate; + } break; // always save case 1: @@ -1592,12 +1567,8 @@ namespace CSMWorld case 5: if (content.mType == ESM::AI_Wander) { - if ("Yes" == value.toString().toStdString()) - content.mWander.mShouldRepeat = 1; - if ("No" == value.toString().toStdString()) - content.mWander.mShouldRepeat = 0; - else - return; // return without saving + content.mWander.mShouldRepeat = static_cast(value.toInt()); + break; } case 6: // NAME32 if (content.mType == ESM::AI_Activate) diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 3bdf8361f..caf1041c6 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -188,7 +188,7 @@ CSMWorld::RefIdCollection::RefIdCollection() new ActorAiRefIdAdapter (UniversalId::Type_Creature))); mNestedAdapters.push_back (std::make_pair(&mColumns.back(), aiMap)); mColumns.back().addColumn( - new RefIdColumn (Columns::ColumnId_AiPackage, CSMWorld::ColumnBase::Display_String)); + new RefIdColumn (Columns::ColumnId_AiPackageType, CSMWorld::ColumnBase::Display_AiPackageType)); mColumns.back().addColumn( new RefIdColumn (Columns::ColumnId_AiWanderDist, CSMWorld::ColumnBase::Display_Integer)); mColumns.back().addColumn( @@ -198,7 +198,7 @@ CSMWorld::RefIdCollection::RefIdCollection() mColumns.back().addColumn( new RefIdColumn (Columns::ColumnId_AiWanderIdle, CSMWorld::ColumnBase::Display_Integer)); mColumns.back().addColumn( - new RefIdColumn (Columns::ColumnId_AiWanderRepeat, CSMWorld::ColumnBase::Display_String)); + new RefIdColumn (Columns::ColumnId_AiWanderRepeat, CSMWorld::ColumnBase::Display_YesNo)); mColumns.back().addColumn( new RefIdColumn (Columns::ColumnId_AiActivateName, CSMWorld::ColumnBase::Display_String)); mColumns.back().addColumn( diff --git a/apps/opencs/view/doc/viewmanager.cpp b/apps/opencs/view/doc/viewmanager.cpp index 3f0c10053..5908c67a1 100644 --- a/apps/opencs/view/doc/viewmanager.cpp +++ b/apps/opencs/view/doc/viewmanager.cpp @@ -88,7 +88,9 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager) { CSMWorld::ColumnBase::Display_SkillImpact, CSMWorld::Columns::ColumnId_SkillImpact, true }, { CSMWorld::ColumnBase::Display_EffectRange, CSMWorld::Columns::ColumnId_EffectRange, false }, { CSMWorld::ColumnBase::Display_EffectId, CSMWorld::Columns::ColumnId_EffectId, false }, - { CSMWorld::ColumnBase::Display_PartRefType, CSMWorld::Columns::ColumnId_PartRefType, false } + { CSMWorld::ColumnBase::Display_PartRefType, CSMWorld::Columns::ColumnId_PartRefType, false }, + { CSMWorld::ColumnBase::Display_AiPackageType, CSMWorld::Columns::ColumnId_AiPackageType, false }, + { CSMWorld::ColumnBase::Display_YesNo, CSMWorld::Columns::ColumnId_AiWanderRepeat, false } }; for (std::size_t i=0; i