Add ability to edit region weather probabilities.

pull/1/head
Aesylwinn 9 years ago
parent f2b2a760b3
commit 5e38fcac36

@ -85,6 +85,7 @@ namespace CSMWorld
Display_Enchantment,
//CONCRETE TYPES ENDS HERE
Display_UnsignedInteger8,
Display_Integer,
Display_Float,
Display_Var,

@ -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" },

@ -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,

@ -177,6 +177,14 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
mRegions.addColumn (new NameColumn<ESM::Region>);
mRegions.addColumn (new MapColourColumn<ESM::Region>);
mRegions.addColumn (new SleepListColumn<ESM::Region>);
// Region Weather
mRegions.addColumn (new NestedParentColumn<ESM::Region> (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<ESM::Region> (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();
}
}

@ -1027,4 +1027,105 @@ namespace CSMWorld
{
return 1; // fixed at size 1
}
RegionWeatherAdapter::RegionWeatherAdapter () {}
void RegionWeatherAdapter::addRow(Record<ESM::Region>& record, int position) const
{
throw std::logic_error ("cannot add a row to a fixed table");
}
void RegionWeatherAdapter::removeRow(Record<ESM::Region>& record, int rowToRemove) const
{
throw std::logic_error ("cannot remove a row from a fixed table");
}
void RegionWeatherAdapter::setTable(Record<ESM::Region>& record, const NestedTableWrapperBase& nestedTable) const
{
throw std::logic_error ("table operation not supported");
}
NestedTableWrapperBase* RegionWeatherAdapter::table(const Record<ESM::Region>& record) const
{
throw std::logic_error ("table operation not supported");
}
QVariant RegionWeatherAdapter::getData(const Record<ESM::Region>& 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<ESM::Region>& record, const QVariant& value, int subRowIndex,
int subColIndex) const
{
ESM::Region region = record.get();
unsigned char chance = static_cast<unsigned char>(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<ESM::Region>& record) const
{
return 2;
}
int RegionWeatherAdapter::getRowsCount(const Record<ESM::Region>& record) const
{
return 10;
}
}

@ -540,6 +540,31 @@ namespace CSMWorld
virtual int getRowsCount(const Record<CSMWorld::Cell>& record) const;
};
class RegionWeatherAdapter : public NestedColumnAdapter<ESM::Region>
{
public:
RegionWeatherAdapter ();
virtual void addRow(Record<ESM::Region>& record, int position) const;
virtual void removeRow(Record<ESM::Region>& record, int rowToRemove) const;
virtual void setTable(Record<ESM::Region>& record,
const NestedTableWrapperBase& nestedTable) const;
virtual NestedTableWrapperBase* table(const Record<ESM::Region>& record) const;
virtual QVariant getData(const Record<ESM::Region>& record,
int subRowIndex, int subColIndex) const;
virtual void setData(Record<ESM::Region>& record,
const QVariant& value, int subRowIndex, int subColIndex) const;
virtual int getColumnsCount(const Record<ESM::Region>& record) const;
virtual int getRowsCount(const Record<ESM::Region>& record) const;
};
}
#endif // CSM_WOLRD_NESTEDCOLADAPTERIMP_H

@ -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);

Loading…
Cancel
Save