1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-18 03:21:27 +02:00

Merge remote-tracking branch 'origin/cpp-map-editor' into EraseAction

+ Some workaround for View -> LayerSelection communication
This commit is contained in:
Tomasz Zieliński 2022-09-06 08:59:28 +02:00
commit b826bc00b9
25 changed files with 868 additions and 222 deletions

View File

@ -478,6 +478,9 @@
"object" : {
"index" : 0,
"aiValue" : 500,
"sounds" : {
"removal" : [ "PICKUP01", "PICKUP02", "PICKUP03", "PICKUP04", "PICKUP05", "PICKUP06", "PICKUP07" ]
},
"templates" : {
"normal" : {
"visitableFrom" : [ "+++", "+-+", "+++" ],

View File

@ -113,7 +113,10 @@
"battleFields" : ["ship"],
"transitionRequired" : true,
"terrainViewPatterns" : "water",
"horseSoundId" : 8
"horseSoundId" : 8,
"sounds": {
"ambient": ["LOOPOCEA"]
}
},
"rock" :
{

View File

@ -656,6 +656,18 @@ void CMap::removeObject(CGObjectInstance * obj)
{
(*iter)->id = ObjectInstanceID(i);
}
auto iterTown = std::find(towns.begin(), towns.end(), obj);
if(iterTown != towns.end())
towns.erase(iterTown);
auto iterHero = std::find(allHeroes.begin(), allHeroes.end(), obj);
if(iterHero != allHeroes.end())
allHeroes.erase(iterHero);
iterHero = std::find(heroesOnMap.begin(), heroesOnMap.end(), obj);
if(iterHero != heroesOnMap.end())
heroesOnMap.erase(iterHero);
//TOOD: Clean artifact instances (mostly worn by hero?) and quests related to this object
}
void CMap::initTerrain()

View File

@ -46,7 +46,7 @@ void TownPlacer::init()
void TownPlacer::placeTowns(ObjectManager & manager)
{
if((zone.getType() == ETemplateZoneType::CPU_START) || (zone.getType() == ETemplateZoneType::PLAYER_START))
if(zone.getOwner() && ((zone.getType() == ETemplateZoneType::CPU_START) || (zone.getType() == ETemplateZoneType::PLAYER_START)))
{
//set zone types to player faction, generate main town
logGlobal->info("Preparing playing zone");

View File

@ -2,6 +2,9 @@
#include "../Global.h"
#define VCMI_EDITOR_VERSION "0.1"
#define VCMI_EDITOR_NAME "VCMI Map Editor"
#include <QtWidgets>
#include <QStringList>
#include <QSet>

View File

@ -1,25 +1,155 @@
#include "StdInc.h"
#include "inspector.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/mapObjects/CGTownInstance.h"
#include "../lib/CArtHandler.h"
#include "../lib/spells/CSpellHandler.h"
#include "../lib/CRandomGenerator.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
//===============IMPLEMENT OBJECT INITIALIZATION FUNCTIONS================
Initializer::Initializer(CGObjectInstance * o)
{
///IMPORTANT! initialize order should be from base objects to derived objects
INIT_OBJ_TYPE(CGResource);
INIT_OBJ_TYPE(CGArtifact);
INIT_OBJ_TYPE(CArmedInstance);
INIT_OBJ_TYPE(CGMine);
INIT_OBJ_TYPE(CGTownInstance);
}
void initialize(CArmedInstance * o)
{
if(!o) return;
o->tempOwner = PlayerColor::NEUTRAL;
}
void initialize(CGTownInstance * o)
{
if(!o) return;
o->builtBuildings.insert(BuildingID::FORT);
o->builtBuildings.insert(BuildingID::DEFAULT);
for(auto spell : VLC->spellh->objects) //add all regular spells to town
{
if(!spell->isSpecial() && !spell->isCreatureAbility())
o->possibleSpells.push_back(spell->id);
}
}
void initialize(CGArtifact * o)
{
if(!o) return;
if(o->ID == Obj::SPELL_SCROLL)
{
std::vector<SpellID> out;
for(auto spell : VLC->spellh->objects) //spellh size appears to be greater (?)
{
if(/*map.isAllowedSpell(spell->id) && spell->level == i + 1*/ true)
{
out.push_back(spell->id);
}
}
auto a = CArtifactInstance::createScroll(*RandomGeneratorUtil::nextItem(out, CRandomGenerator::getDefault()));
o->storedArtifact = a;
}
}
void initialize(CGMine * o)
{
if(!o) return;
o->producedResource = Res::ERes(o->subID);
o->producedQuantity = o->defaultResProduction();
}
void initialize(CGResource * o)
{
if(!o) return;
o->amount = CGResource::RANDOM_AMOUNT;
}
//===============IMPLEMENT PROPERTIES SETUP===============================
void Inspector::updateProperties(CArmedInstance * o)
{
if(!o) return;
addProperty("Owner", o->tempOwner);
}
void Inspector::updateProperties(CGTownInstance * o)
{
if(!o) return;
addProperty("Owner", o->tempOwner, false);
addProperty("Town name", o->name, false);
}
void Inspector::updateProperties(CGArtifact * o)
{
if(!o) return;
}
void Inspector::updateProperties(CGMine * o)
{
if(!o) return;
addProperty("Owner", o->tempOwner, false);
addProperty("Resource", o->producedResource);
addProperty("Productivity", o->producedQuantity, false);
}
void Inspector::updateProperties(CGResource * o)
{
if(!o) return;
addProperty("Amount", o->amount, false);
}
void Inspector::updateProperties()
{
if(!obj)
return;
table->setRowCount(0); //cleanup table
addProperty("Indentifier", obj);
addProperty("ID", obj->ID.getNum());
addProperty("SubID", obj->subID);
addProperty("InstanceName", obj->instanceName);
addProperty("TypeName", obj->typeName);
addProperty("SubTypeName", obj->subTypeName);
auto factory = VLC->objtypeh->getHandlerFor(obj->ID, obj->subID);
addProperty("IsStatic", factory->isStaticObject());
UPDATE_OBJ_PROPERTIES(CArmedInstance);
UPDATE_OBJ_PROPERTIES(CGTownInstance);
UPDATE_OBJ_PROPERTIES(CGArtifact);
UPDATE_OBJ_PROPERTIES(CGMine);
UPDATE_OBJ_PROPERTIES(CGResource);
table->show();
}
//===============IMPLEMENT PROPERTY UPDATE================================
void Inspector::setProperty(const QString & key, const QVariant & value)
{
if(!obj)
return;
setProperty(dynamic_cast<CGTownInstance*>(obj), key, value);
//updateProperties();
SET_PROPERTIES(CArmedInstance);
SET_PROPERTIES(CGTownInstance);
SET_PROPERTIES(CGArtifact);
SET_PROPERTIES(CGMine);
SET_PROPERTIES(CGResource);
}
void Inspector::setProperty(CGTownInstance * object, const QString & key, const QVariant & value)
void Inspector::setProperty(CArmedInstance * object, const QString & key, const QVariant & value)
{
if(!object)
return;
if(key == "Owner")
{
PlayerColor owner(value.toString().toInt());
@ -32,78 +162,53 @@ void Inspector::setProperty(CGTownInstance * object, const QString & key, const
}
}
CGTownInstance * initialize(CGTownInstance * o)
void Inspector::setProperty(CGTownInstance * object, const QString & key, const QVariant & value)
{
if(!o)
return nullptr;
o->tempOwner = PlayerColor::NEUTRAL;
o->builtBuildings.insert(BuildingID::FORT);
o->builtBuildings.insert(BuildingID::DEFAULT);
for(auto spell : VLC->spellh->objects) //add all regular spells to town
{
if(!spell->isSpecial() && !spell->isCreatureAbility())
o->possibleSpells.push_back(spell->id);
}
return o;
}
Initializer::Initializer(CGObjectInstance * o)
{
initialize(dynamic_cast<CGTownInstance*>(o));
}
Inspector::Inspector(CGObjectInstance * o, QTableWidget * t): obj(o), table(t)
{
/*
/// Position of bottom-right corner of object on map
int3 pos;
/// Type of object, e.g. town, hero, creature.
Obj ID;
/// Subtype of object, depends on type
si32 subID;
/// Current owner of an object (when below PLAYER_LIMIT)
PlayerColor tempOwner;
/// Index of object in map's list of objects
ObjectInstanceID id;
/// Defines appearance of object on map (animation, blocked tiles, blit order, etc)
ObjectTemplate appearance;
/// If true hero can visit this object only from neighbouring tiles and can't stand on this object
bool blockVisit;
std::string instanceName;
std::string typeName;
std::string subTypeName;*/
}
void Inspector::updateProperties()
{
if(!obj)
if(!object)
return;
addProperty("Indentifier", obj);
addProperty("ID", obj->ID.getNum());
addProperty("SubID", obj->subID);
addProperty("InstanceName", obj->instanceName);
addProperty("TypeName", obj->typeName);
addProperty("SubTypeName", obj->subTypeName);
addProperty("Owner", obj->tempOwner, false);
auto factory = VLC->objtypeh->getHandlerFor(obj->ID, obj->subID);
addProperty("IsStatic", factory->isStaticObject());
table->show();
if(key == "Town name")
object->name = value.toString().toStdString();
}
void Inspector::setProperty(CGMine * object, const QString & key, const QVariant & value)
{
if(!object)
return;
if(key == "Productivity")
object->producedQuantity = value.toString().toInt();
}
void Inspector::setProperty(CGArtifact * object, const QString & key, const QVariant & value)
{
if(!object)
return;
}
void Inspector::setProperty(CGResource * object, const QString & key, const QVariant & value)
{
if(!object)
return;
if(key == "Amount")
object->amount = value.toString().toInt();
}
//===============IMPLEMENT PROPERTY VALUE TYPE============================
QTableWidgetItem * Inspector::addProperty(CGObjectInstance * value)
{
using NumericPointer = unsigned long long;
static_assert(sizeof(CGObjectInstance *) == sizeof(NumericPointer),
"Compilied for 64 bit arcitecture. Use NumericPointer = unsigned int");
"Compilied for 64 bit arcitecture. Use NumericPointer = unsigned int");
return new QTableWidgetItem(QString::number(reinterpret_cast<NumericPointer>(value)));
}
QTableWidgetItem * Inspector::addProperty(unsigned int value)
{
return new QTableWidgetItem(QString::number(value));
}
QTableWidgetItem * Inspector::addProperty(int value)
{
return new QTableWidgetItem(QString::number(value));
@ -140,6 +245,47 @@ QTableWidgetItem * Inspector::addProperty(const PlayerColor & value)
return new QTableWidgetItem(str);
}
QTableWidgetItem * Inspector::addProperty(const Res::ERes & value)
{
QString str;
switch (value) {
case Res::ERes::WOOD:
str = "WOOD";
break;
case Res::ERes::ORE:
str = "ORE";
break;
case Res::ERes::SULFUR:
str = "SULFUR";
break;
case Res::ERes::GEMS:
str = "GEMS";
break;
case Res::ERes::MERCURY:
str = "MERCURY";
break;
case Res::ERes::CRYSTAL:
str = "CRYSTAL";
break;
case Res::ERes::GOLD:
str = "GOLD";
break;
default:
break;
}
return new QTableWidgetItem(str);
}
//========================================================================
Inspector::Inspector(CGObjectInstance * o, QTableWidget * t): obj(o), table(t)
{
}
/*
* Delegates
*/
QWidget * PlayerColorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.data().canConvert<int>())

View File

@ -6,56 +6,94 @@
#include <QStyledItemDelegate>
#include "../lib/int3.h"
#include "../lib/GameConstants.h"
#include "../lib/mapObjects/MapObjects.h"
#include "../lib/ResourceSet.h"
class CGObjectInstance;
class CGTownInstance;
#define DECLARE_OBJ_TYPE(x) void initialize(x*);
#define DECLARE_OBJ_PROPERTY_METHODS(x) \
void updateProperties(x*); \
void setProperty(x*, const QString &, const QVariant &);
class Initializer
{
public:
Initializer(CGObjectInstance *);
};
#define INIT_OBJ_TYPE(x) initialize(dynamic_cast<x*>(o))
#define UPDATE_OBJ_PROPERTIES(x) updateProperties(dynamic_cast<x*>(obj))
#define SET_PROPERTIES(x) setProperty(dynamic_cast<x*>(obj), key, value)
//===============DECLARE MAP OBJECTS======================================
DECLARE_OBJ_TYPE(CArmedInstance);
DECLARE_OBJ_TYPE(CGTownInstance);
DECLARE_OBJ_TYPE(CGArtifact);
DECLARE_OBJ_TYPE(CGMine);
DECLARE_OBJ_TYPE(CGResource);
class Inspector
{
protected:
//===============DECLARE PROPERTIES SETUP=================================
DECLARE_OBJ_PROPERTY_METHODS(CArmedInstance);
DECLARE_OBJ_PROPERTY_METHODS(CGTownInstance);
DECLARE_OBJ_PROPERTY_METHODS(CGArtifact);
DECLARE_OBJ_PROPERTY_METHODS(CGMine);
DECLARE_OBJ_PROPERTY_METHODS(CGResource);
//===============DECLARE PROPERTY VALUE TYPE==============================
QTableWidgetItem * addProperty(unsigned int value);
QTableWidgetItem * addProperty(int value);
QTableWidgetItem * addProperty(const std::string & value);
QTableWidgetItem * addProperty(const QString & value);
QTableWidgetItem * addProperty(const int3 & value);
QTableWidgetItem * addProperty(const PlayerColor & value);
QTableWidgetItem * addProperty(const Res::ERes & value);
QTableWidgetItem * addProperty(bool value);
QTableWidgetItem * addProperty(CGObjectInstance * value);
//===============END OF DECLARATION=======================================
public:
Inspector(CGObjectInstance *, QTableWidget *);
void setProperty(const QString & key, const QVariant & value);
void updateProperties();
protected:
QTableWidgetItem * addProperty(int value);
QTableWidgetItem * addProperty(const std::string & value);
QTableWidgetItem * addProperty(const QString & value);
QTableWidgetItem * addProperty(const int3 & value);
QTableWidgetItem * addProperty(const PlayerColor & value);
QTableWidgetItem * addProperty(bool value);
QTableWidgetItem * addProperty(CGObjectInstance * value);
void setProperty(CGTownInstance * obj, const QString & key, const QVariant & value);
template<class T>
void addProperty(const QString & key, const T & value, bool restricted = true)
{
auto * itemKey = new QTableWidgetItem(key);
auto * itemValue = addProperty(value);
itemKey->setFlags(Qt::NoItemFlags);
if(restricted)
itemValue->setFlags(Qt::NoItemFlags);
if(table->rowCount() < row + 1)
QTableWidgetItem * itemKey = nullptr;
if(keyItems.contains(key))
{
itemKey = keyItems[key];
table->setItem(table->row(itemKey), 1, itemValue);
}
else
{
itemKey = new QTableWidgetItem(key);
itemKey->setFlags(Qt::NoItemFlags);
keyItems[key] = itemKey;
table->setRowCount(row + 1);
table->setItem(row, 0, itemKey);
table->setItem(row, 1, itemValue);
++row;
table->setItem(row, 0, itemKey);
table->setItem(row, 1, itemValue);
++row;
}
}
protected:
int row = 0;
QTableWidget * table;
CGObjectInstance * obj;
QMap<QString, QTableWidgetItem*> keyItems;
};
class Initializer
{
public:
Initializer(CGObjectInstance *);
};
class PlayerColorDelegate : public QStyledItemDelegate

View File

@ -62,6 +62,7 @@ MainWindow::MainWindow(QWidget *parent) :
controller(this)
{
ui->setupUi(this);
setTitle();
// Set current working dir to executable folder.
// This is important on Mac for relative paths to work inside DMG.
@ -120,8 +121,9 @@ MainWindow::MainWindow(QWidget *parent) :
ui->mapView->setController(&controller);
connect(ui->mapView, &MapView::openObjectProperties, this, &MainWindow::loadInspector);
sceneMini = new QGraphicsScene(this);
ui->minimapView->setScene(sceneMini);
ui->minimapView->setScene(controller.miniScene(0));
ui->minimapView->setController(&controller);
connect(ui->minimapView, &MinimapView::cameraPositionChanged, ui->mapView, &MapView::cameraChanged);
scenePreview = new QGraphicsScene(this);
ui->objectPreview->setScene(scenePreview);
@ -157,25 +159,29 @@ void MainWindow::reloadMap(int level)
//sceneMini->addPixmap(minimap);
}
void MainWindow::setTitle()
{
QString title = QString("%1%2 - %3 (v%4)").arg(filename, unsaved ? "*" : "", VCMI_EDITOR_NAME, VCMI_EDITOR_VERSION);
setWindowTitle(title);
}
void MainWindow::mapChanged()
{
unsaved = true;
setWindowTitle(filename + "* - VCMI Map Editor");
setTitle();
}
void MainWindow::initializeMap(bool isNew)
{
unsaved = isNew;
if(isNew)
{
filename.clear();
setWindowTitle("* - VCMI Map Editor");
}
else
setWindowTitle(filename + " - VCMI Map Editor");
setTitle();
mapLevel = 0;
ui->mapView->setScene(controller.scene(mapLevel));
ui->minimapView->setScene(controller.miniScene(mapLevel));
ui->minimapView->dimensions();
setStatusMessage(QString("Scene objects: %1").arg(ui->mapView->scene()->items().size()));
@ -213,6 +219,7 @@ void MainWindow::on_actionOpen_triggered()
QMessageBox::critical(this, "Failed to open map", e.what());
}
filename = filenameSelect;
initializeMap(false);
}
@ -227,7 +234,7 @@ void MainWindow::saveMap()
CMapService mapService;
try
{
mapService.saveMap(std::unique_ptr<CMap>(controller.map()), filename.toStdString());
mapService.saveMap(controller.getMapUniquePtr(), filename.toStdString());
}
catch(const std::exception & e)
{
@ -235,7 +242,7 @@ void MainWindow::saveMap()
}
unsaved = false;
setWindowTitle(filename + " - VCMI Map Editor");
setTitle();
}
void MainWindow::on_actionSave_as_triggered()
@ -551,6 +558,7 @@ void MainWindow::on_actionLevel_triggered()
{
mapLevel = mapLevel ? 0 : 1;
ui->mapView->setScene(controller.scene(mapLevel));
ui->minimapView->setScene(controller.miniScene(mapLevel));
}
}
@ -784,15 +792,17 @@ void MainWindow::on_inspectorWidget_itemChanged(QTableWidgetItem *item)
void MainWindow::on_actionMapSettings_triggered()
{
auto mapSettingsDialog = new MapSettings(controller, this);
mapSettingsDialog->setModal(true);
auto settingsDialog = new MapSettings(controller, this);
settingsDialog->setWindowModality(Qt::WindowModal);
settingsDialog->setModal(true);
}
void MainWindow::on_actionPlayers_settings_triggered()
{
auto mapSettingsDialog = new PlayerSettings(*controller.map(), this);
mapSettingsDialog->setModal(true);
auto settingsDialog = new PlayerSettings(controller, this);
settingsDialog->setWindowModality(Qt::WindowModal);
settingsDialog->setModal(true);
}
void MainWindow::enableUndo(bool enable)
@ -815,4 +825,4 @@ void MainWindow::onSelectionMade(int level, bool anythingSelected)
ui->actionErase->setEnabled(anythingSelected);
ui->toolErase->setEnabled(anythingSelected);
}
}
}

View File

@ -100,13 +100,12 @@ private:
void addGroupIntoCatalog(const std::string & groupName, bool staticOnly, int ID);
void changeBrushState(int idx);
void setTitle();
private:
Ui::MainWindow *ui;
ObjectBrowser * objectBrowser = nullptr;
QGraphicsScene * sceneMini;
QGraphicsScene * scenePreview;
QPixmap minimap;
QString filename;
bool unsaved = false;

View File

@ -78,9 +78,16 @@
<addaction name="actionRedo"/>
<addaction name="actionErase"/>
</widget>
<widget class="QMenu" name="menuPlayer">
<property name="title">
<string>Player</string>
</property>
<addaction name="actionNeutral"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuMap"/>
<addaction name="menuPlayer"/>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
@ -150,7 +157,7 @@
<number>0</number>
</property>
<item>
<widget class="QGraphicsView" name="minimapView">
<widget class="MinimapView" name="minimapView">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -878,6 +885,14 @@
<string>Del</string>
</property>
</action>
<action name="actionNeutral">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Neutral</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
@ -885,6 +900,11 @@
<extends>QGraphicsView</extends>
<header>mapview.h</header>
</customwidget>
<customwidget>
<class>MinimapView</class>
<extends>QGraphicsView</extends>
<header>mapview.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View File

@ -18,6 +18,8 @@ MapController::MapController(MainWindow * m): main(m)
{
_scenes[0].reset(new MapScene(0));
_scenes[1].reset(new MapScene(1));
_miniscenes[0].reset(new MinimapScene(0));
_miniscenes[1].reset(new MinimapScene(1));
connectScenes();
}
@ -37,6 +39,11 @@ MapController::~MapController()
{
}
const std::unique_ptr<CMap> & MapController::getMapUniquePtr() const
{
return _map;
}
CMap * MapController::map()
{
return _map.get();
@ -52,11 +59,18 @@ MapScene * MapController::scene(int level)
return _scenes[level].get();
}
MinimapScene * MapController::miniScene(int level)
{
return _miniscenes[level].get();
}
void MapController::setMap(std::unique_ptr<CMap> cmap)
{
_map = std::move(cmap);
_scenes[0].reset(new MapScene(0));
_scenes[1].reset(new MapScene(1));
_miniscenes[0].reset(new MinimapScene(0));
_miniscenes[1].reset(new MinimapScene(1));
resetMapHandler();
sceneForceUpdate();
@ -73,13 +87,18 @@ void MapController::setMap(std::unique_ptr<CMap> cmap)
void MapController::sceneForceUpdate()
{
_scenes[0]->updateViews();
_miniscenes[0]->updateViews();
if(_map->twoLevel)
{
_scenes[1]->updateViews();
_miniscenes[1]->updateViews();
}
}
void MapController::sceneForceUpdate(int level)
{
_scenes[level]->updateViews();
_miniscenes[level]->updateViews();
}
void MapController::resetMapHandler()
@ -87,6 +106,8 @@ void MapController::resetMapHandler()
_mapHandler.reset(new MapHandler(_map.get()));
_scenes[0]->initialize(*this);
_scenes[1]->initialize(*this);
_miniscenes[0]->initialize(*this);
_miniscenes[1]->initialize(*this);
}
void MapController::commitTerrainChange(int level, const Terrain & terrain)
@ -106,6 +127,7 @@ void MapController::commitTerrainChange(int level, const Terrain & terrain)
_scenes[level]->terrainView.setDirty(t);
_scenes[level]->terrainView.draw();
_miniscenes[level]->updateViews();
main->mapChanged();
}
@ -120,6 +142,7 @@ void MapController::commitObjectErase(int level)
resetMapHandler();
_scenes[level]->updateViews();
_miniscenes[level]->updateViews();
main->mapChanged();
}
@ -171,6 +194,7 @@ void MapController::commitObstacleFill(int level)
resetMapHandler();
_scenes[level]->updateViews();
_miniscenes[level]->updateViews();
main->mapChanged();
}
@ -180,6 +204,7 @@ void MapController::commitObjectChange(int level)
_scenes[level]->objectsView.draw();
_scenes[level]->selectionObjectsView.draw();
_miniscenes[level]->updateViews();
main->mapChanged();
}
@ -220,6 +245,7 @@ void MapController::commitObjectShiftOrCreate(int level)
resetMapHandler();
_scenes[level]->updateViews();
_miniscenes[level]->updateViews();
main->mapChanged();
}
@ -228,9 +254,9 @@ void MapController::commitObjectCreate(int level)
auto * newObj = _scenes[level]->selectionObjectsView.newObject;
if(!newObj)
return;
_map->getEditManager()->insertObject(newObj);
Initializer init(newObj);
_map->getEditManager()->insertObject(newObj);
main->mapChanged();
}
@ -248,4 +274,4 @@ void MapController::redo()
resetMapHandler();
sceneForceUpdate();
main->mapChanged();
}
}

View File

@ -17,9 +17,11 @@ public:
void setMap(std::unique_ptr<CMap>);
const std::unique_ptr<CMap> & getMapUniquePtr() const; //to be used for map saving
CMap * map();
MapHandler * mapHandler();
MapScene * scene(int level);
MinimapScene * miniScene(int level);
void resetMapHandler();
@ -46,6 +48,7 @@ private:
std::unique_ptr<MapHandler> _mapHandler;
MainWindow * main;
mutable std::array<std::unique_ptr<MapScene>, 2> _scenes;
mutable std::array<std::unique_ptr<MinimapScene>, 2> _miniscenes;
void connectScenes();
};

View File

@ -502,3 +502,39 @@ void MapHandler::drawObjectAt(QPainter & painter, const CGObjectInstance * obj,
}
}
}
QRgb MapHandler::getTileColor(int x, int y, int z)
{
// if object at tile is owned - it will be colored as its owner
for(auto & object : getObjects(x, y, z))
{
//heroes will be blitted later
switch (object.obj->ID)
{
case Obj::HERO:
case Obj::PRISON:
continue;
}
PlayerColor player = object.obj->getOwner();
if(player == PlayerColor::NEUTRAL)
return graphics->neutralColor;
else
if (player < PlayerColor::PLAYER_LIMIT)
return graphics->playerColors[player.getNum()];
}
// else - use terrain color (blocked version or normal)
auto & tile = map->getTile(int3(x, y, z));
auto color = Terrain::Manager::getInfo(tile.terType).minimapUnblocked;
if (tile.blocked && (!tile.visitable))
color = Terrain::Manager::getInfo(tile.terType).minimapBlocked;
return qRgb(color[0], color[1], color[2]);
}
void MapHandler::drawMinimapTile(QPainter & painter, int x, int y, int z)
{
painter.setPen(getTileColor(x, y, z));
painter.drawPoint(x, y);
}

View File

@ -98,7 +98,9 @@ public:
std::vector<TerrainTileObject> & getObjects(int x, int y, int z);
//void drawObject(SDL_Surface * targetSurf, std::shared_ptr<IImage> source, SDL_Rect * sourceRect, bool moving) const;
//void drawHeroFlag(SDL_Surface * targetSurf, std::shared_ptr<IImage> source, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const;
QRgb getTileColor(int x, int y, int z);
void drawMinimapTile(QPainter & painter, int x, int y, int z);
mutable std::map<const CGObjectInstance*, ui8> animationPhase;
MapHandler(const CMap * Map);

View File

@ -4,12 +4,62 @@
#include <QGraphicsSceneMouseEvent>
#include "mapcontroller.h"
MinimapView::MinimapView(QWidget * parent):
QGraphicsView(parent)
{
// Disable scrollbars
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
void MinimapView::dimensions()
{
fitInView(0, 0, controller->map()->width, controller->map()->height, Qt::KeepAspectRatio);
}
void MinimapView::setController(MapController * ctrl)
{
controller = ctrl;
}
void MinimapView::mouseMoveEvent(QMouseEvent *mouseEvent)
{
this->update();
auto * sc = static_cast<MinimapScene*>(scene());
if(!sc)
return;
int w = sc->viewport.viewportWidth();
int h = sc->viewport.viewportHeight();
auto pos = mapToScene(mouseEvent->pos());
pos.setX(pos.x() - w / 2);
pos.setY(pos.y() - h / 2);
QPointF point = pos * 32;
emit cameraPositionChanged(point);
}
void MinimapView::mousePressEvent(QMouseEvent* event)
{
mouseMoveEvent(event);
}
MapView::MapView(QWidget * parent):
QGraphicsView(parent),
selectionTool(MapView::SelectionTool::None)
{
}
void MapView::cameraChanged(const QPointF & pos)
{
//ui->mapView->translate(pos.x(), pos.y());
horizontalScrollBar()->setValue(pos.x());
verticalScrollBar()->setValue(pos.y());
}
void MapView::setController(MapController * ctrl)
{
controller = ctrl;
@ -273,15 +323,43 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
}
}
MapScene::MapScene(int lev):
bool MapView::viewportEvent(QEvent *event)
{
if(auto * sc = static_cast<MapScene*>(scene()))
{
//auto rect = sceneRect();
auto rect = mapToScene(viewport()->geometry()).boundingRect();
controller->miniScene(sc->level)->viewport.setViewport(rect.x() / 32, rect.y() / 32, rect.width() / 32, rect.height() / 32);
}
return QGraphicsView::viewportEvent(event);
}
MapSceneBase::MapSceneBase(int lvl):
QGraphicsScene(nullptr),
level(lvl)
{
}
void MapSceneBase::initialize(MapController & controller)
{
for(auto * layer : getAbstractLayers())
layer->initialize(controller);
}
void MapSceneBase::updateViews()
{
for(auto * layer : getAbstractLayers())
layer->update();
}
MapScene::MapScene(int lvl):
MapSceneBase(lvl),
gridView(this),
passabilityView(this),
selectionTerrainView(this),
terrainView(this),
objectsView(this),
selectionObjectsView(this),
level(lev),
isTerrainSelected(false),
isObjectSelected(false)
{
@ -300,16 +378,9 @@ std::list<AbstractLayer *> MapScene::getAbstractLayers()
};
}
void MapScene::initialize(MapController & controller)
{
for(auto * layer : getAbstractLayers())
layer->initialize(controller);
}
void MapScene::updateViews()
{
for(auto * layer : getAbstractLayers())
layer->update();
MapSceneBase::updateViews();
terrainView.show(true);
objectsView.show(true);
@ -327,4 +398,28 @@ void MapScene::objectSelected(bool anythingSelected)
{
isObjectSelected = anythingSelected;
emit selected(isTerrainSelected || isObjectSelected);
}
}
MinimapScene::MinimapScene(int lvl):
MapSceneBase(lvl),
minimapView(this),
viewport(this)
{
}
std::list<AbstractLayer *> MinimapScene::getAbstractLayers()
{
//sequence is important because it defines rendering order
return {
&minimapView,
&viewport
};
}
void MinimapScene::updateViews()
{
MapSceneBase::updateViews();
minimapView.show(true);
viewport.show(true);
}

View File

@ -11,14 +11,42 @@ class CGObjectInstance;
class MainWindow;
class MapController;
class MapScene : public QGraphicsScene
class MapSceneBase : public QGraphicsScene
{
Q_OBJECT;
public:
MapScene(int lev);
MapSceneBase(int lvl);
void updateViews();
void initialize(MapController &);
const int level;
virtual void updateViews();
virtual void initialize(MapController &);
protected:
virtual std::list<AbstractLayer *> getAbstractLayers() = 0;
};
class MinimapScene : public MapSceneBase
{
public:
MinimapScene(int lvl);
void updateViews() override;
MinimapLayer minimapView;
MinimapViewLayer viewport;
protected:
virtual std::list<AbstractLayer *> getAbstractLayers();
};
class MapScene : public MapSceneBase
{
Q_OBJECT
public:
MapScene(int lvl);
void updateViews() override;
GridLayer gridView;
PassabilityLayer passabilityView;
@ -26,8 +54,6 @@ public:
TerrainLayer terrainView;
ObjectsLayer objectsView;
SelectionObjectsLayer selectionObjectsView;
const int level;
signals:
void selected(bool anything);
@ -36,11 +62,12 @@ public slots:
void terrainSelected(bool anything);
void objectSelected(bool anything);
private:
std::list<AbstractLayer *> getAbstractLayers();
protected:
std::list<AbstractLayer *> getAbstractLayers() override;
bool isTerrainSelected;
bool isObjectSelected;
};
class MapView : public QGraphicsView
@ -63,9 +90,15 @@ public slots:
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void cameraChanged(const QPointF & pos);
signals:
void openObjectProperties(CGObjectInstance *);
//void viewportChanged(const QRectF & rect);
protected:
bool viewportEvent(QEvent *event) override;
private:
MapController * controller = nullptr;
QPointF mouseStart;
@ -74,4 +107,27 @@ private:
bool pressedOnSelected;
};
class MinimapView : public QGraphicsView
{
Q_OBJECT
public:
MinimapView(QWidget * parent);
void setController(MapController *);
void dimensions();
public slots:
void mouseMoveEvent(QMouseEvent * mouseEvent) override;
void mousePressEvent(QMouseEvent* event) override;
signals:
void cameraPositionChanged(const QPointF & newPosition);
private:
MapController * controller = nullptr;
int displayWidth = 192;
int displayHeight = 192;
};
#endif // MAPVIEW_H

View File

@ -1,21 +1,68 @@
#include "StdInc.h"
#include "playerparams.h"
#include "ui_playerparams.h"
#include "../lib/CTownHandler.h"
PlayerParams::PlayerParams(const CMapHeader & mapHeader, int playerId, QWidget *parent) :
PlayerParams::PlayerParams(MapController & ctrl, int playerId, QWidget *parent) :
QWidget(parent),
ui(new Ui::PlayerParams)
ui(new Ui::PlayerParams),
controller(ctrl)
{
ui->setupUi(this);
playerColor = playerId;
assert(mapHeader.players.size() > playerColor);
playerInfo = mapHeader.players[playerColor];
assert(controller.map()->players.size() > playerColor);
playerInfo = controller.map()->players[playerColor];
//load factions
for(auto idx : VLC->townh->getAllowedFactions())
{
CFaction * faction = VLC->townh->objects.at(idx);
auto * item = new QListWidgetItem(QString::fromStdString(faction->name));
item->setData(Qt::UserRole, QVariant::fromValue(idx));
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
ui->allowedFactions->addItem(item);
if(playerInfo.allowedFactions.count(idx))
item->setCheckState(Qt::Checked);
else
item->setCheckState(Qt::Unchecked);
}
QObject::connect(ui->allowedFactions, SIGNAL(itemChanged(QListWidgetItem*)),
this, SLOT(allowedFactionsCheck(QListWidgetItem*)));
if(playerInfo.canComputerPlay)
ui->radioCpu->setChecked(true);
if(playerInfo.canHumanPlay)
//load checks
bool canHumanPlay = playerInfo.canHumanPlay; //need variable to restore after signal received
playerInfo.canComputerPlay = true; //computer always can play
ui->radioCpu->setChecked(true);
if(canHumanPlay)
ui->radioHuman->setChecked(true);
if(playerInfo.isFactionRandom)
ui->randomFaction->setChecked(true);
if(playerInfo.generateHeroAtMainTown)
ui->generateHero->setChecked(true);
//load towns
int foundMainTown = -1;
for(int i = 0; i < controller.map()->towns.size(); ++i)
{
auto town = controller.map()->towns[i];
if(town->getOwner().getNum() == playerColor)
{
if(playerInfo.hasMainTown && playerInfo.posOfMainTown == town->pos)
foundMainTown = i;
ui->mainTown->addItem(QString::fromStdString(town->getObjectName()), QVariant::fromValue(i));
}
}
if(foundMainTown > -1)
{
ui->mainTown->setCurrentIndex(foundMainTown + 1);
}
else
{
playerInfo.hasMainTown = false;
playerInfo.posOfMainTown = int3(-1, -1, -1);
}
ui->playerColor->setTitle(QString("PlayerID: %1").arg(playerId));
show();
@ -39,3 +86,40 @@ void PlayerParams::on_radioCpu_toggled(bool checked)
playerInfo.canHumanPlay = false;
}
void PlayerParams::on_generateHero_stateChanged(int arg1)
{
playerInfo.generateHeroAtMainTown = ui->generateHero->isChecked();
}
void PlayerParams::on_randomFaction_stateChanged(int arg1)
{
playerInfo.isFactionRandom = ui->randomFaction->isChecked();
}
void PlayerParams::allowedFactionsCheck(QListWidgetItem * item)
{
if(item->checkState() == Qt::Checked)
playerInfo.allowedFactions.insert(item->data(Qt::UserRole).toInt());
else
playerInfo.allowedFactions.erase(item->data(Qt::UserRole).toInt());
}
void PlayerParams::on_mainTown_activated(int index)
{
if(index == 0) //default
{
playerInfo.hasMainTown = false;
playerInfo.posOfMainTown = int3(-1, -1, -1);
}
else
{
auto town = controller.map()->towns.at(ui->mainTown->currentData().toInt());
playerInfo.hasMainTown = true;
playerInfo.posOfMainTown = town->pos;
}
}

View File

@ -3,6 +3,7 @@
#include <QWidget>
#include "../lib/mapping/CMap.h"
#include "mapcontroller.h"
namespace Ui {
class PlayerParams;
@ -13,7 +14,7 @@ class PlayerParams : public QWidget
Q_OBJECT
public:
explicit PlayerParams(const CMapHeader & mapHeader, int playerId, QWidget *parent = nullptr);
explicit PlayerParams(MapController & controller, int playerId, QWidget *parent = nullptr);
~PlayerParams();
PlayerInfo playerInfo;
@ -24,8 +25,18 @@ private slots:
void on_radioCpu_toggled(bool checked);
void on_mainTown_activated(int index);
void on_generateHero_stateChanged(int arg1);
void on_randomFaction_stateChanged(int arg1);
void allowedFactionsCheck(QListWidgetItem *);
private:
Ui::PlayerParams *ui;
MapController & controller;
};
#endif // PLAYERPARAMS_H

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>505</width>
<height>146</height>
<height>160</height>
</rect>
</property>
<property name="sizePolicy">
@ -101,23 +101,34 @@
</property>
</widget>
</item>
<item row="1" column="2" rowspan="2">
<item row="1" column="1">
<widget class="QComboBox" name="mainTown">
<item>
<property name="text">
<string>(default)</string>
</property>
</item>
</widget>
</item>
<item row="0" column="2" rowspan="3">
<widget class="QListWidget" name="allowedFactions">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mainTown"/>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>All factions allowed</string>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
</widget>
</item>

View File

@ -4,20 +4,20 @@
#include "playerparams.h"
#include "mainwindow.h"
PlayerSettings::PlayerSettings(CMapHeader & mapHeader, QWidget *parent) :
PlayerSettings::PlayerSettings(MapController & ctrl, QWidget *parent) :
QDialog(parent),
ui(new Ui::PlayerSettings),
header(mapHeader)
controller(ctrl)
{
ui->setupUi(this);
show();
int players = 0;
for(auto & p : header.players)
for(auto & p : controller.map()->players)
{
if(p.canAnyonePlay())
{
paramWidgets.push_back(new PlayerParams(header, players));
paramWidgets.push_back(new PlayerParams(controller, players));
ui->playersLayout->addWidget(paramWidgets.back());
++players;
}
@ -36,23 +36,23 @@ PlayerSettings::~PlayerSettings()
void PlayerSettings::on_playersCount_currentIndexChanged(int index)
{
assert(index + 2 <= header.players.size());
assert(index + 2 <= controller.map()->players.size());
for(int i = 0; i < index + 2; ++i)
{
if(i < paramWidgets.size())
continue;
auto & p = header.players[i];
auto & p = controller.map()->players[i];
p.canComputerPlay = true;
paramWidgets.push_back(new PlayerParams(header, i));
paramWidgets.push_back(new PlayerParams(controller, i));
ui->playersLayout->addWidget(paramWidgets.back());
}
assert(!paramWidgets.empty());
for(int i = paramWidgets.size() - 1; i >= index + 2; --i)
{
auto & p = header.players[i];
auto & p = controller.map()->players[i];
p.canComputerPlay = false;
p.canHumanPlay = false;
ui->playersLayout->removeWidget(paramWidgets[i]);
@ -66,10 +66,10 @@ void PlayerSettings::on_pushButton_clicked()
{
for(auto * w : paramWidgets)
{
header.players[w->playerColor] = w->playerInfo;
controller.map()->players[w->playerColor] = w->playerInfo;
}
static_cast<MainWindow*>(parent())->controller.commitChangeWithoutRedraw();
controller.commitChangeWithoutRedraw();
close();
}

View File

@ -14,7 +14,7 @@ class PlayerSettings : public QDialog
Q_OBJECT
public:
explicit PlayerSettings(CMapHeader & mapHeader, QWidget *parent = nullptr);
explicit PlayerSettings(MapController & controller, QWidget *parent = nullptr);
~PlayerSettings();
private slots:
@ -27,8 +27,8 @@ private:
Ui::PlayerSettings *ui;
std::vector<PlayerParams*> paramWidgets;
CMapHeader & header;
MapController & controller;
};
#endif // PLAYERSETTINGS_H

View File

@ -2,6 +2,9 @@
<ui version="4.0">
<class>PlayerSettings</class>
<widget class="QDialog" name="PlayerSettings">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
@ -10,8 +13,14 @@
<height>283</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Player settings</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="8">

View File

@ -6,7 +6,7 @@
#include "mapview.h"
#include "mapcontroller.h"
AbstractLayer::AbstractLayer(MapScene * s): scene(s)
AbstractLayer::AbstractLayer(MapSceneBase * s): scene(s)
{
}
@ -21,29 +21,9 @@ void AbstractLayer::show(bool show)
if(isShown == show)
return;
if(show)
{
if(pixmap)
{
if(item)
item->setPixmap(*pixmap);
else
item.reset(scene->addPixmap(*pixmap));
}
else
{
if(item)
item->setPixmap(emptyPixmap);
else
item.reset(scene->addPixmap(emptyPixmap));
}
}
else
{
item->setPixmap(emptyPixmap);
}
isShown = show;
redraw();
}
void AbstractLayer::redraw()
@ -64,7 +44,7 @@ void AbstractLayer::redraw()
}
}
GridLayer::GridLayer(MapScene * s): AbstractLayer(s)
GridLayer::GridLayer(MapSceneBase * s): AbstractLayer(s)
{
}
@ -90,7 +70,7 @@ void GridLayer::update()
redraw();
}
PassabilityLayer::PassabilityLayer(MapScene * s): AbstractLayer(s)
PassabilityLayer::PassabilityLayer(MapSceneBase * s): AbstractLayer(s)
{
}
@ -206,10 +186,11 @@ const std::set<int3> & SelectionTerrainLayer::selection() const
void SelectionTerrainLayer::selectionMade()
{
scene->objectSelected(!area.empty());
dynamic_cast<MapScene*>(scene)->objectSelected(!area.empty());
}
TerrainLayer::TerrainLayer(MapScene * s): AbstractLayer(s)
TerrainLayer::TerrainLayer(MapSceneBase * s): AbstractLayer(s)
{
}
@ -284,7 +265,7 @@ void TerrainLayer::draw(bool onlyDirty)
redraw();
}
ObjectsLayer::ObjectsLayer(MapScene * s): AbstractLayer(s)
ObjectsLayer::ObjectsLayer(MapSceneBase * s): AbstractLayer(s)
{
}
@ -508,7 +489,76 @@ void SelectionObjectsLayer::clear()
shift.setY(0);
}
void SelectionObjectsLayer::selectionMade()
{
scene->objectSelected(!selectedObjects.empty());
}
dynamic_cast<MapScene*>(scene)->objectSelected(!selectedObjects.empty());
}
MinimapLayer::MinimapLayer(MapSceneBase * s): AbstractLayer(s)
{
}
void MinimapLayer::update()
{
if(!map)
return;
pixmap.reset(new QPixmap(map->width, map->height));
QPainter painter(pixmap.get());
//coordinate transfomation
for(int j = 0; j < map->height; ++j)
{
for(int i = 0; i < map->width; ++i)
{
handler->drawMinimapTile(painter, i, j, scene->level);
}
}
redraw();
}
MinimapViewLayer::MinimapViewLayer(MapSceneBase * s): AbstractLayer(s)
{
}
void MinimapViewLayer::update()
{
if(!map)
return;
pixmap.reset(new QPixmap(map->width, map->height));
pixmap->fill(QColor(0, 0, 0, 0));
QPainter painter(pixmap.get());
painter.setPen(QColor(255, 255, 255));
painter.drawRect(x, y, w, h);
redraw();
}
void MinimapViewLayer::draw()
{
if(!map)
return;
pixmap->fill(QColor(0, 0, 0, 0));
//maybe not optimal but ok
QPainter painter(pixmap.get());
painter.setPen(QColor(255, 255, 255));
painter.drawRect(x, y, w, h);
redraw();
}
void MinimapViewLayer::setViewport(int _x, int _y, int _w, int _h)
{
x = _x;
y = _y;
w = _w;
h = _h;
draw();
}

View File

@ -3,6 +3,7 @@
#include "../lib/int3.h"
class MapSceneBase;
class MapScene;
class CGObjectInstance;
class MapController;
@ -12,7 +13,7 @@ class MapHandler;
class AbstractLayer
{
public:
AbstractLayer(MapScene * s);
AbstractLayer(MapSceneBase * s);
virtual void update() = 0;
@ -21,7 +22,7 @@ public:
void initialize(MapController & controller);
protected:
MapScene * scene;
MapSceneBase * scene;
CMap * map = nullptr;
MapHandler * handler = nullptr;
bool isShown = false;
@ -37,7 +38,7 @@ private:
class GridLayer: public AbstractLayer
{
public:
GridLayer(MapScene * s);
GridLayer(MapSceneBase * s);
void update() override;
};
@ -45,7 +46,7 @@ public:
class PassabilityLayer: public AbstractLayer
{
public:
PassabilityLayer(MapScene * s);
PassabilityLayer(MapSceneBase * s);
void update() override;
};
@ -54,6 +55,7 @@ public:
class SelectionTerrainLayer: public AbstractLayer
{
public:
//FIXME: now it depends on MapScene::selected, this is getting messy
SelectionTerrainLayer(MapScene * s);
void update() override;
@ -75,7 +77,7 @@ private:
class TerrainLayer: public AbstractLayer
{
public:
TerrainLayer(MapScene * s);
TerrainLayer(MapSceneBase * s);
void update() override;
@ -90,7 +92,7 @@ private:
class ObjectsLayer: public AbstractLayer
{
public:
ObjectsLayer(MapScene * s);
ObjectsLayer(MapSceneBase * s);
void update() override;
@ -107,6 +109,7 @@ private:
class SelectionObjectsLayer: public AbstractLayer
{
public:
//FIXME: now it depends on MapScene::selected, this is getting messy
SelectionObjectsLayer(MapScene * s);
void update() override;
@ -131,4 +134,32 @@ private:
void selectionMade(); //TODO: consider making it a signal
};
class MinimapLayer: public AbstractLayer
{
public:
MinimapLayer(MapSceneBase * s);
void update() override;
};
class MinimapViewLayer: public AbstractLayer
{
public:
MinimapViewLayer(MapSceneBase * s);
void setViewport(int x, int y, int w, int h);
void draw();
void update() override;
int viewportX() const {return x;}
int viewportY() const {return y;}
int viewportWidth() const {return w;}
int viewportHeight() const {return h;}
private:
int x = 0, y = 0, w = 1, h = 1;
};
#endif // SCENELAYER_H

View File

@ -54,13 +54,10 @@ std::unique_ptr<CMap> generateEmptyMap(CMapGenOptions & options)
map->width = options.getWidth();
map->height = options.getHeight();
map->twoLevel = options.getHasTwoLevels();
map->initTerrain();
map->getEditManager()->clearTerrain(&CRandomGenerator::getDefault());
map->getEditManager()->getTerrainSelection().selectRange(MapRect(int3(0, 0, 0), options.getWidth(), options.getHeight()));
map->getEditManager()->drawTerrain(Terrain("grass"), &CRandomGenerator::getDefault());
//window->controller.setMap(std::move(map));
return std::move(map);
}
@ -98,22 +95,15 @@ void WindowNewMap::on_okButtong_clicked()
auto progressBarWnd = new GeneratorProgress(generator, this);
progressBarWnd->show();
//std::thread generate(&::generateRandomMap, std::ref(generator), static_cast<MainWindow*>(parent()));
//progressBarWnd->update();
//generate.join();
//generateRandomMap(generator, static_cast<MainWindow*>(parent()));
auto f = std::async(std::launch::async, &CMapGenerator::generate, &generator);
progressBarWnd->update();
nmap = f.get();
}
else
{
{
auto f = std::async(std::launch::async, &::generateEmptyMap, std::ref(mapGenOptions));
nmap = f.get();
//nmap = generateEmptyMap(mapGenOptions, static_cast<MainWindow*>(parent()));
}
@ -250,15 +240,23 @@ void WindowNewMap::on_templateCombo_activated(int index)
void WindowNewMap::on_widthTxt_textChanged(const QString &arg1)
{
mapGenOptions.setWidth(arg1.toInt());
updateTemplateList();
int sz = arg1.toInt();
if(sz > 1)
{
mapGenOptions.setWidth(arg1.toInt());
updateTemplateList();
}
}
void WindowNewMap::on_heightTxt_textChanged(const QString &arg1)
{
mapGenOptions.setHeight(arg1.toInt());
updateTemplateList();
int sz = arg1.toInt();
if(sz > 1)
{
mapGenOptions.setHeight(arg1.toInt());
updateTemplateList();
}
}
void WindowNewMap::updateTemplateList()