forked from teamnwah/openmw-tes3coop
Update to upstream/master. Resolve merge conflicts in MWWorld::Store
commit
2ed182b144
@ -0,0 +1,49 @@
|
||||
#include "tableeditidaction.hpp"
|
||||
|
||||
#include <QTableView>
|
||||
|
||||
#include "../../model/world/tablemimedata.hpp"
|
||||
|
||||
CSVWorld::TableEditIdAction::CellData CSVWorld::TableEditIdAction::getCellData(int row, int column) const
|
||||
{
|
||||
QModelIndex index = mTable.model()->index(row, column);
|
||||
if (index.isValid())
|
||||
{
|
||||
QVariant display = mTable.model()->data(index, CSMWorld::ColumnBase::Role_Display);
|
||||
QString value = mTable.model()->data(index).toString();
|
||||
return std::make_pair(static_cast<CSMWorld::ColumnBase::Display>(display.toInt()), value);
|
||||
}
|
||||
return std::make_pair(CSMWorld::ColumnBase::Display_None, "");
|
||||
}
|
||||
|
||||
CSVWorld::TableEditIdAction::TableEditIdAction(const QTableView &table, QWidget *parent)
|
||||
: QAction(parent),
|
||||
mTable(table),
|
||||
mCurrentId(CSMWorld::UniversalId::Type_None)
|
||||
{}
|
||||
|
||||
void CSVWorld::TableEditIdAction::setCell(int row, int column)
|
||||
{
|
||||
CellData data = getCellData(row, column);
|
||||
CSMWorld::UniversalId::Type idType = CSMWorld::TableMimeData::convertEnums(data.first);
|
||||
|
||||
if (idType != CSMWorld::UniversalId::Type_None)
|
||||
{
|
||||
mCurrentId = CSMWorld::UniversalId(idType, data.second.toUtf8().constData());
|
||||
setText("Edit '" + data.second + "'");
|
||||
}
|
||||
}
|
||||
|
||||
CSMWorld::UniversalId CSVWorld::TableEditIdAction::getCurrentId() const
|
||||
{
|
||||
return mCurrentId;
|
||||
}
|
||||
|
||||
bool CSVWorld::TableEditIdAction::isValidIdCell(int row, int column) const
|
||||
{
|
||||
CellData data = getCellData(row, column);
|
||||
CSMWorld::UniversalId::Type idType = CSMWorld::TableMimeData::convertEnums(data.first);
|
||||
return CSMWorld::ColumnBase::isId(data.first) &&
|
||||
idType != CSMWorld::UniversalId::Type_None &&
|
||||
!data.second.isEmpty();
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#ifndef CSVWORLD_TABLEEDITIDACTION_HPP
|
||||
#define CSVWORLD_TABLEEDITIDACTION_HPP
|
||||
|
||||
#include <QAction>
|
||||
|
||||
#include "../../model/world/columnbase.hpp"
|
||||
#include "../../model/world/universalid.hpp"
|
||||
|
||||
class QTableView;
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class TableEditIdAction : public QAction
|
||||
{
|
||||
const QTableView &mTable;
|
||||
CSMWorld::UniversalId mCurrentId;
|
||||
|
||||
typedef std::pair<CSMWorld::ColumnBase::Display, QString> CellData;
|
||||
CellData getCellData(int row, int column) const;
|
||||
|
||||
public:
|
||||
TableEditIdAction(const QTableView &table, QWidget *parent = 0);
|
||||
|
||||
void setCell(int row, int column);
|
||||
|
||||
CSMWorld::UniversalId getCurrentId() const;
|
||||
bool isValidIdCell(int row, int column) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,28 +1,276 @@
|
||||
|
||||
#include "stat.hpp"
|
||||
|
||||
void MWMechanics::AttributeValue::writeState (ESM::StatState<int>& state) const
|
||||
{
|
||||
state.mBase = mBase;
|
||||
state.mMod = mModifier;
|
||||
state.mDamage = mDamage;
|
||||
}
|
||||
#include <components/esm/statstate.hpp>
|
||||
|
||||
void MWMechanics::AttributeValue::readState (const ESM::StatState<int>& state)
|
||||
namespace MWMechanics
|
||||
{
|
||||
mBase = state.mBase;
|
||||
mModifier = state.mMod;
|
||||
mDamage = state.mDamage;
|
||||
}
|
||||
template<typename T>
|
||||
Stat<T>::Stat() : mBase (0), mModified (0) {}
|
||||
template<typename T>
|
||||
Stat<T>::Stat(T base) : mBase (base), mModified (base) {}
|
||||
template<typename T>
|
||||
Stat<T>::Stat(T base, T modified) : mBase (base), mModified (modified) {}
|
||||
|
||||
void MWMechanics::SkillValue::writeState (ESM::StatState<int>& state) const
|
||||
{
|
||||
AttributeValue::writeState (state);
|
||||
state.mProgress = mProgress;
|
||||
}
|
||||
template<typename T>
|
||||
const T& Stat<T>::getBase() const
|
||||
{
|
||||
return mBase;
|
||||
}
|
||||
|
||||
void MWMechanics::SkillValue::readState (const ESM::StatState<int>& state)
|
||||
{
|
||||
AttributeValue::readState (state);
|
||||
mProgress = state.mProgress;
|
||||
template<typename T>
|
||||
T Stat<T>::getModified() const
|
||||
{
|
||||
return std::max(static_cast<T>(0), mModified);
|
||||
}
|
||||
template<typename T>
|
||||
T Stat<T>::getModifier() const
|
||||
{
|
||||
return mModified-mBase;
|
||||
}
|
||||
template<typename T>
|
||||
void Stat<T>::set (const T& value)
|
||||
{
|
||||
mBase = mModified = value;
|
||||
}
|
||||
template<typename T>
|
||||
void Stat<T>::modify(const T& diff)
|
||||
{
|
||||
mBase += diff;
|
||||
if(mBase >= static_cast<T>(0))
|
||||
mModified += diff;
|
||||
else
|
||||
{
|
||||
mModified += diff - mBase;
|
||||
mBase = static_cast<T>(0);
|
||||
}
|
||||
}
|
||||
template<typename T>
|
||||
void Stat<T>::setBase (const T& value)
|
||||
{
|
||||
T diff = value - mBase;
|
||||
mBase = value;
|
||||
mModified += diff;
|
||||
}
|
||||
template<typename T>
|
||||
void Stat<T>::setModified (T value, const T& min, const T& max)
|
||||
{
|
||||
T diff = value - mModified;
|
||||
|
||||
if (mBase+diff<min)
|
||||
{
|
||||
value = min + (mModified - mBase);
|
||||
diff = value - mModified;
|
||||
}
|
||||
else if (mBase+diff>max)
|
||||
{
|
||||
value = max + (mModified - mBase);
|
||||
diff = value - mModified;
|
||||
}
|
||||
|
||||
mModified = value;
|
||||
mBase += diff;
|
||||
}
|
||||
template<typename T>
|
||||
void Stat<T>::setModifier (const T& modifier)
|
||||
{
|
||||
mModified = mBase + modifier;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Stat<T>::writeState (ESM::StatState<T>& state) const
|
||||
{
|
||||
state.mBase = mBase;
|
||||
state.mMod = mModified;
|
||||
}
|
||||
template<typename T>
|
||||
void Stat<T>::readState (const ESM::StatState<T>& state)
|
||||
{
|
||||
mBase = state.mBase;
|
||||
mModified = state.mMod;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
DynamicStat<T>::DynamicStat() : mStatic (0), mCurrent (0) {}
|
||||
template<typename T>
|
||||
DynamicStat<T>::DynamicStat(T base) : mStatic (base), mCurrent (base) {}
|
||||
template<typename T>
|
||||
DynamicStat<T>::DynamicStat(T base, T modified, T current) : mStatic(base, modified), mCurrent (current) {}
|
||||
template<typename T>
|
||||
DynamicStat<T>::DynamicStat(const Stat<T> &stat, T current) : mStatic(stat), mCurrent (current) {}
|
||||
|
||||
|
||||
template<typename T>
|
||||
const T& DynamicStat<T>::getBase() const
|
||||
{
|
||||
return mStatic.getBase();
|
||||
}
|
||||
template<typename T>
|
||||
T DynamicStat<T>::getModified() const
|
||||
{
|
||||
return mStatic.getModified();
|
||||
}
|
||||
template<typename T>
|
||||
const T& DynamicStat<T>::getCurrent() const
|
||||
{
|
||||
return mCurrent;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void DynamicStat<T>::set (const T& value)
|
||||
{
|
||||
mStatic.set (value);
|
||||
mCurrent = value;
|
||||
}
|
||||
template<typename T>
|
||||
void DynamicStat<T>::setBase (const T& value)
|
||||
{
|
||||
mStatic.setBase (value);
|
||||
|
||||
if (mCurrent>getModified())
|
||||
mCurrent = getModified();
|
||||
}
|
||||
template<typename T>
|
||||
void DynamicStat<T>::setModified (T value, const T& min, const T& max)
|
||||
{
|
||||
mStatic.setModified (value, min, max);
|
||||
|
||||
if (mCurrent>getModified())
|
||||
mCurrent = getModified();
|
||||
}
|
||||
template<typename T>
|
||||
void DynamicStat<T>::modify (const T& diff, bool allowCurrentDecreaseBelowZero)
|
||||
{
|
||||
mStatic.modify (diff);
|
||||
setCurrent (getCurrent()+diff, allowCurrentDecreaseBelowZero);
|
||||
}
|
||||
template<typename T>
|
||||
void DynamicStat<T>::setCurrent (const T& value, bool allowDecreaseBelowZero)
|
||||
{
|
||||
if (value > mCurrent)
|
||||
{
|
||||
// increase
|
||||
mCurrent = value;
|
||||
|
||||
if (mCurrent > getModified())
|
||||
mCurrent = getModified();
|
||||
}
|
||||
else if (value > 0 || allowDecreaseBelowZero)
|
||||
{
|
||||
// allowed decrease
|
||||
mCurrent = value;
|
||||
}
|
||||
else if (mCurrent > 0)
|
||||
{
|
||||
// capped decrease
|
||||
mCurrent = 0;
|
||||
}
|
||||
}
|
||||
template<typename T>
|
||||
void DynamicStat<T>::setModifier (const T& modifier, bool allowCurrentDecreaseBelowZero)
|
||||
{
|
||||
T diff = modifier - mStatic.getModifier();
|
||||
mStatic.setModifier (modifier);
|
||||
setCurrent (getCurrent()+diff, allowCurrentDecreaseBelowZero);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void DynamicStat<T>::writeState (ESM::StatState<T>& state) const
|
||||
{
|
||||
mStatic.writeState (state);
|
||||
state.mCurrent = mCurrent;
|
||||
}
|
||||
template<typename T>
|
||||
void DynamicStat<T>::readState (const ESM::StatState<T>& state)
|
||||
{
|
||||
mStatic.readState (state);
|
||||
mCurrent = state.mCurrent;
|
||||
}
|
||||
|
||||
AttributeValue::AttributeValue() :
|
||||
mBase(0), mModifier(0), mDamage(0)
|
||||
{
|
||||
}
|
||||
|
||||
int AttributeValue::getModified() const
|
||||
{
|
||||
return std::max(0, mBase - (int) mDamage + mModifier);
|
||||
}
|
||||
int AttributeValue::getBase() const
|
||||
{
|
||||
return mBase;
|
||||
}
|
||||
int AttributeValue::getModifier() const
|
||||
{
|
||||
return mModifier;
|
||||
}
|
||||
|
||||
void AttributeValue::setBase(int base)
|
||||
{
|
||||
mBase = std::max(0, base);
|
||||
}
|
||||
|
||||
void AttributeValue::setModifier(int mod)
|
||||
{
|
||||
mModifier = mod;
|
||||
}
|
||||
|
||||
void AttributeValue::damage(float damage)
|
||||
{
|
||||
mDamage += std::min(damage, (float)getModified());
|
||||
}
|
||||
void AttributeValue::restore(float amount)
|
||||
{
|
||||
mDamage -= std::min(mDamage, amount);
|
||||
}
|
||||
|
||||
float AttributeValue::getDamage() const
|
||||
{
|
||||
return mDamage;
|
||||
}
|
||||
|
||||
void AttributeValue::writeState (ESM::StatState<int>& state) const
|
||||
{
|
||||
state.mBase = mBase;
|
||||
state.mMod = mModifier;
|
||||
state.mDamage = mDamage;
|
||||
}
|
||||
|
||||
void AttributeValue::readState (const ESM::StatState<int>& state)
|
||||
{
|
||||
mBase = state.mBase;
|
||||
mModifier = state.mMod;
|
||||
mDamage = state.mDamage;
|
||||
}
|
||||
|
||||
SkillValue::SkillValue() :
|
||||
mProgress(0)
|
||||
{
|
||||
}
|
||||
|
||||
float SkillValue::getProgress() const
|
||||
{
|
||||
return mProgress;
|
||||
}
|
||||
void SkillValue::setProgress(float progress)
|
||||
{
|
||||
mProgress = progress;
|
||||
}
|
||||
|
||||
void SkillValue::writeState (ESM::StatState<int>& state) const
|
||||
{
|
||||
AttributeValue::writeState (state);
|
||||
state.mProgress = mProgress;
|
||||
}
|
||||
|
||||
void SkillValue::readState (const ESM::StatState<int>& state)
|
||||
{
|
||||
AttributeValue::readState (state);
|
||||
mProgress = state.mProgress;
|
||||
}
|
||||
}
|
||||
|
||||
template class MWMechanics::Stat<int>;
|
||||
template class MWMechanics::Stat<float>;
|
||||
template class MWMechanics::DynamicStat<int>;
|
||||
template class MWMechanics::DynamicStat<float>;
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,52 @@
|
||||
#include "statstate.hpp"
|
||||
|
||||
#include "esmreader.hpp"
|
||||
#include "esmwriter.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
template<typename T>
|
||||
StatState<T>::StatState() : mBase(0), mMod(0), mCurrent(0), mDamage(0), mProgress(0) {}
|
||||
|
||||
template<typename T>
|
||||
void StatState<T>::load(ESMReader &esm)
|
||||
{
|
||||
esm.getHNT(mBase, "STBA");
|
||||
|
||||
mMod = 0;
|
||||
esm.getHNOT(mMod, "STMO");
|
||||
mCurrent = 0;
|
||||
esm.getHNOT(mCurrent, "STCU");
|
||||
|
||||
// mDamage was changed to a float; ensure backwards compatibility
|
||||
T oldDamage = 0;
|
||||
esm.getHNOT(oldDamage, "STDA");
|
||||
mDamage = static_cast<float>(oldDamage);
|
||||
|
||||
esm.getHNOT(mDamage, "STDF");
|
||||
|
||||
mProgress = 0;
|
||||
esm.getHNOT(mProgress, "STPR");
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void StatState<T>::save(ESMWriter &esm) const
|
||||
{
|
||||
esm.writeHNT("STBA", mBase);
|
||||
|
||||
if (mMod != 0)
|
||||
esm.writeHNT("STMO", mMod);
|
||||
|
||||
if (mCurrent)
|
||||
esm.writeHNT("STCU", mCurrent);
|
||||
|
||||
if (mDamage)
|
||||
esm.writeHNT("STDF", mDamage);
|
||||
|
||||
if (mProgress)
|
||||
esm.writeHNT("STPR", mProgress);
|
||||
}
|
||||
}
|
||||
|
||||
template struct ESM::StatState<int>;
|
||||
template struct ESM::StatState<float>;
|
Loading…
Reference in New Issue