From 5e38fcac369c085f2ea4d3be2d9c657f2a3514cd Mon Sep 17 00:00:00 2001 From: Aesylwinn Date: Wed, 6 Apr 2016 02:18:19 -0400 Subject: [PATCH] Add ability to edit region weather probabilities. --- apps/opencs/model/world/columnbase.hpp | 1 + apps/opencs/model/world/columns.cpp | 4 + apps/opencs/model/world/columns.hpp | 4 + apps/opencs/model/world/data.cpp | 10 +- .../model/world/nestedcoladapterimp.cpp | 101 ++++++++++++++++++ .../model/world/nestedcoladapterimp.hpp | 25 +++++ apps/opencs/view/world/util.cpp | 7 ++ 7 files changed, 151 insertions(+), 1 deletion(-) diff --git a/apps/opencs/model/world/columnbase.hpp b/apps/opencs/model/world/columnbase.hpp index c75a3c2a12..1eb6a88c1c 100644 --- a/apps/opencs/model/world/columnbase.hpp +++ b/apps/opencs/model/world/columnbase.hpp @@ -85,6 +85,7 @@ namespace CSMWorld Display_Enchantment, //CONCRETE TYPES ENDS HERE + Display_UnsignedInteger8, Display_Integer, Display_Float, Display_Var, diff --git a/apps/opencs/model/world/columns.cpp b/apps/opencs/model/world/columns.cpp index 32aa7edcab..b72634bee8 100644 --- a/apps/opencs/model/world/columns.cpp +++ b/apps/opencs/model/world/columns.cpp @@ -326,6 +326,10 @@ namespace CSMWorld { ColumnId_Idle7, "Idle 7" }, { ColumnId_Idle8, "Idle 8" }, + { ColumnId_RegionWeather, "Weather" }, + { ColumnId_WeatherName, "Type" }, + { ColumnId_WeatherChance, "Clear" }, + { ColumnId_UseValue1, "Use value 1" }, { ColumnId_UseValue2, "Use value 2" }, { ColumnId_UseValue3, "Use value 3" }, diff --git a/apps/opencs/model/world/columns.hpp b/apps/opencs/model/world/columns.hpp index a504e5f659..05bedb77d5 100644 --- a/apps/opencs/model/world/columns.hpp +++ b/apps/opencs/model/world/columns.hpp @@ -325,6 +325,10 @@ namespace CSMWorld ColumnId_Idle7 = 292, ColumnId_Idle8 = 293, + ColumnId_RegionWeather = 294, + ColumnId_WeatherName = 295, + ColumnId_WeatherChance = 296, + // Allocated to a separate value range, so we don't get a collision should we ever need // to extend the number of use values. ColumnId_UseValue1 = 0x10000, diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index b54df596cb..5c81d3b08b 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -177,6 +177,14 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc mRegions.addColumn (new NameColumn); mRegions.addColumn (new MapColourColumn); mRegions.addColumn (new SleepListColumn); + // Region Weather + mRegions.addColumn (new NestedParentColumn (Columns::ColumnId_RegionWeather)); + index = mRegions.getColumns()-1; + mRegions.addAdapter (std::make_pair(&mRegions.getColumn(index), new RegionWeatherAdapter ())); + mRegions.getNestableColumn(index)->addColumn( + new NestedChildColumn (Columns::ColumnId_WeatherName, ColumnBase::Display_String, false)); + mRegions.getNestableColumn(index)->addColumn( + new NestedChildColumn (Columns::ColumnId_WeatherChance, ColumnBase::Display_UnsignedInteger8)); // Region Sounds mRegions.addColumn (new NestedParentColumn (Columns::ColumnId_RegionSounds)); index = mRegions.getColumns()-1; @@ -1046,7 +1054,7 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Messages& messages) else { mTopics.load (record, mBase); - mDialogue = &mTopics.getRecord (record.mId).get(); + mDialogue = &mTopics.getRecord (record.mId).get(); } } diff --git a/apps/opencs/model/world/nestedcoladapterimp.cpp b/apps/opencs/model/world/nestedcoladapterimp.cpp index 1bcd6b1b4c..3189f76ed9 100644 --- a/apps/opencs/model/world/nestedcoladapterimp.cpp +++ b/apps/opencs/model/world/nestedcoladapterimp.cpp @@ -1027,4 +1027,105 @@ namespace CSMWorld { return 1; // fixed at size 1 } + + RegionWeatherAdapter::RegionWeatherAdapter () {} + + void RegionWeatherAdapter::addRow(Record& record, int position) const + { + throw std::logic_error ("cannot add a row to a fixed table"); + } + + void RegionWeatherAdapter::removeRow(Record& record, int rowToRemove) const + { + throw std::logic_error ("cannot remove a row from a fixed table"); + } + + void RegionWeatherAdapter::setTable(Record& record, const NestedTableWrapperBase& nestedTable) const + { + throw std::logic_error ("table operation not supported"); + } + + NestedTableWrapperBase* RegionWeatherAdapter::table(const Record& record) const + { + throw std::logic_error ("table operation not supported"); + } + + QVariant RegionWeatherAdapter::getData(const Record& record, int subRowIndex, int subColIndex) const + { + const char* WeatherNames[] = { + "Clear", + "Cloudy", + "Fog", + "Overcast", + "Rain", + "Thunder", + "Ash", + "Blight", + "Snow", + "Blizzard" + }; + + const ESM::Region& region = record.get(); + + if (subColIndex == 0 && subRowIndex >= 0 && subRowIndex < 10) + { + return WeatherNames[subRowIndex]; + } + else if (subColIndex == 1) + { + switch (subRowIndex) + { + case 0: return region.mData.mClear; + case 1: return region.mData.mCloudy; + case 2: return region.mData.mFoggy; + case 3: return region.mData.mOvercast; + case 4: return region.mData.mRain; + case 5: return region.mData.mThunder; + case 6: return region.mData.mAsh; + case 7: return region.mData.mBlight; + case 8: return region.mData.mA; // Snow + case 9: return region.mData.mB; // Blizzard + default: break; + } + } + + throw std::runtime_error("index out of range"); + } + + void RegionWeatherAdapter::setData(Record& record, const QVariant& value, int subRowIndex, + int subColIndex) const + { + ESM::Region region = record.get(); + unsigned char chance = static_cast(value.toInt()); + + if (subColIndex == 1) + { + switch (subRowIndex) + { + case 0: region.mData.mClear = chance; break; + case 1: region.mData.mCloudy = chance; break; + case 2: region.mData.mFoggy = chance; break; + case 3: region.mData.mOvercast = chance; break; + case 4: region.mData.mRain = chance; break; + case 5: region.mData.mThunder = chance; break; + case 6: region.mData.mAsh = chance; break; + case 7: region.mData.mBlight = chance; break; + case 8: region.mData.mA = chance; break; + case 9: region.mData.mB = chance; break; + default: throw std::runtime_error("index out of range"); + } + + record.setModified (region); + } + } + + int RegionWeatherAdapter::getColumnsCount(const Record& record) const + { + return 2; + } + + int RegionWeatherAdapter::getRowsCount(const Record& record) const + { + return 10; + } } diff --git a/apps/opencs/model/world/nestedcoladapterimp.hpp b/apps/opencs/model/world/nestedcoladapterimp.hpp index 2fd569bd0d..e24bcb1346 100644 --- a/apps/opencs/model/world/nestedcoladapterimp.hpp +++ b/apps/opencs/model/world/nestedcoladapterimp.hpp @@ -540,6 +540,31 @@ namespace CSMWorld virtual int getRowsCount(const Record& record) const; }; + + class RegionWeatherAdapter : public NestedColumnAdapter + { + public: + RegionWeatherAdapter (); + + virtual void addRow(Record& record, int position) const; + + virtual void removeRow(Record& record, int rowToRemove) const; + + virtual void setTable(Record& record, + const NestedTableWrapperBase& nestedTable) const; + + virtual NestedTableWrapperBase* table(const Record& record) const; + + virtual QVariant getData(const Record& record, + int subRowIndex, int subColIndex) const; + + virtual void setData(Record& record, + const QVariant& value, int subRowIndex, int subColIndex) const; + + virtual int getColumnsCount(const Record& record) const; + + virtual int getRowsCount(const Record& record) const; + }; } #endif // CSM_WOLRD_NESTEDCOLADAPTERIMP_H diff --git a/apps/opencs/view/world/util.cpp b/apps/opencs/view/world/util.cpp index b0431f71a0..e44606652b 100644 --- a/apps/opencs/view/world/util.cpp +++ b/apps/opencs/view/world/util.cpp @@ -212,6 +212,13 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO return sb; } + case CSMWorld::ColumnBase::Display_UnsignedInteger8: + { + DialogueSpinBox *sb = new DialogueSpinBox(parent); + sb->setRange(0, UCHAR_MAX); + return sb; + } + case CSMWorld::ColumnBase::Display_Var: return new QLineEdit(parent);