mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 18:35:20 +00:00
some cleanup; added handling of deleted cells (now displayed instead of ignored)
This commit is contained in:
parent
116320cc0d
commit
121978a69e
@ -6,9 +6,11 @@
|
|||||||
#include "data.hpp"
|
#include "data.hpp"
|
||||||
#include "universalid.hpp"
|
#include "universalid.hpp"
|
||||||
|
|
||||||
|
CSMWorld::RegionMap::CellDescription::CellDescription() : mDeleted (false) {}
|
||||||
|
|
||||||
std::pair<int, int> CSMWorld::RegionMap::getIndex (const QModelIndex& index) const
|
std::pair<int, int> CSMWorld::RegionMap::getIndex (const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
return std::make_pair (index.column()+mMin.first, index.row()+mMin.second);
|
return CellIndex (index.column()+mMin.first, index.row()+mMin.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::RegionMap::buildRegions (Data& data)
|
void CSMWorld::RegionMap::buildRegions (Data& data)
|
||||||
@ -38,34 +40,38 @@ void CSMWorld::RegionMap::buildMap (Data& data)
|
|||||||
{
|
{
|
||||||
const Record<Cell>& cell = cells.getRecord (i);
|
const Record<Cell>& cell = cells.getRecord (i);
|
||||||
|
|
||||||
if (!cell.isDeleted())
|
const Cell& cell2 = cell.get();
|
||||||
|
|
||||||
|
if (cell2.isExterior())
|
||||||
{
|
{
|
||||||
const Cell& cell2 = cell.get();
|
CellDescription description;
|
||||||
|
|
||||||
if (cell2.isExterior())
|
if (cell.isDeleted())
|
||||||
|
description.mDeleted = true;
|
||||||
|
else
|
||||||
|
description.mRegion = cell2.mRegion;
|
||||||
|
|
||||||
|
CellIndex index (cell2.mData.mX, cell2.mData.mY);
|
||||||
|
|
||||||
|
if (mMap.empty())
|
||||||
{
|
{
|
||||||
std::pair<int, int> index (cell2.mData.mX, cell2.mData.mY);
|
mMin = index;
|
||||||
|
mMax = std::make_pair (mMin.first+1, mMin.second+1);
|
||||||
if (mMap.empty())
|
|
||||||
{
|
|
||||||
mMin = index;
|
|
||||||
mMax = std::make_pair (mMin.first+1, mMin.second+1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (index.first<mMin.first)
|
|
||||||
mMin.first = index.first;
|
|
||||||
else if (index.first>=mMax.first)
|
|
||||||
mMax.first = index.first + 1;
|
|
||||||
|
|
||||||
if (index.second<mMin.second)
|
|
||||||
mMin.second = index.second;
|
|
||||||
else if (index.second>=mMax.second)
|
|
||||||
mMax.second = index.second + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
mMap.insert (std::make_pair (index, cell2.mRegion));
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (index.first<mMin.first)
|
||||||
|
mMin.first = index.first;
|
||||||
|
else if (index.first>=mMax.first)
|
||||||
|
mMax.first = index.first + 1;
|
||||||
|
|
||||||
|
if (index.second<mMin.second)
|
||||||
|
mMin.second = index.second;
|
||||||
|
else if (index.second>=mMax.second)
|
||||||
|
mMax.second = index.second + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mMap.insert (std::make_pair (index, description));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,22 +125,26 @@ QVariant CSMWorld::RegionMap::data (const QModelIndex& index, int role) const
|
|||||||
{
|
{
|
||||||
/// \todo GUI class in non-GUI code. Needs to be addressed eventually.
|
/// \todo GUI class in non-GUI code. Needs to be addressed eventually.
|
||||||
|
|
||||||
std::map<std::pair<int, int>, std::string>::const_iterator cell =
|
std::map<CellIndex, CellDescription>::const_iterator cell =
|
||||||
mMap.find (getIndex (index));
|
mMap.find (getIndex (index));
|
||||||
|
|
||||||
if (cell!=mMap.end())
|
if (cell!=mMap.end())
|
||||||
{
|
{
|
||||||
std::map<std::string, unsigned int>::const_iterator iter = mColours.find (cell->second);
|
if (cell->second.mDeleted)
|
||||||
|
return QBrush (Qt::red, Qt::DiagCrossPattern);
|
||||||
|
|
||||||
|
std::map<std::string, unsigned int>::const_iterator iter =
|
||||||
|
mColours.find (cell->second.mRegion);
|
||||||
|
|
||||||
if (iter!=mColours.end())
|
if (iter!=mColours.end())
|
||||||
return QBrush (
|
return QBrush (
|
||||||
QColor (iter->second>>24, (iter->second>>16) & 255, (iter->second>>8) & 255,
|
QColor (iter->second>>24, (iter->second>>16) & 255, (iter->second>>8) & 255,
|
||||||
iter->second & 255));
|
iter->second & 255));
|
||||||
|
|
||||||
if (cell->second.empty())
|
if (cell->second.mRegion.empty())
|
||||||
return QBrush (Qt::Dense6Pattern); // no region
|
return QBrush (Qt::Dense6Pattern); // no region
|
||||||
|
|
||||||
return QBrush (Qt::red, Qt::Dense6Pattern);
|
return QBrush (Qt::red, Qt::Dense6Pattern); // invalid region
|
||||||
}
|
}
|
||||||
|
|
||||||
return QBrush (Qt::DiagCrossPattern);
|
return QBrush (Qt::DiagCrossPattern);
|
||||||
|
@ -17,12 +17,26 @@ namespace CSMWorld
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
std::map<std::pair<int, int>, std::string> mMap; ///< cell index, region
|
public:
|
||||||
std::pair<int, int> mMin; ///< inclusive
|
|
||||||
std::pair<int, int> mMax; ///< exclusive
|
typedef std::pair<int, int> CellIndex;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct CellDescription
|
||||||
|
{
|
||||||
|
bool mDeleted;
|
||||||
|
std::string mRegion;
|
||||||
|
|
||||||
|
CellDescription();
|
||||||
|
};
|
||||||
|
|
||||||
|
std::map<CellIndex, CellDescription> mMap;
|
||||||
|
CellIndex mMin; ///< inclusive
|
||||||
|
CellIndex mMax; ///< exclusive
|
||||||
std::map<std::string, unsigned int> mColours; ///< region ID, colour (RGBA)
|
std::map<std::string, unsigned int> mColours; ///< region ID, colour (RGBA)
|
||||||
|
|
||||||
std::pair<int, int> getIndex (const QModelIndex& index) const;
|
CellIndex getIndex (const QModelIndex& index) const;
|
||||||
///< Translates a Qt model index into a cell index (which can contain negative components)
|
///< Translates a Qt model index into a cell index (which can contain negative components)
|
||||||
|
|
||||||
void buildRegions (Data& data);
|
void buildRegions (Data& data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user