mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-17 20:58:07 +02:00
Use exact position of object to remove + add object name to list of objects to remove
This commit is contained in:
parent
253af651cc
commit
e50ba14bbe
@ -960,7 +960,8 @@ void CGameState::initTimedEventsRemovableObjects()
|
||||
{
|
||||
if(isInTheMap(coordinate))
|
||||
{
|
||||
for(const CGObjectInstance * object : getBlockingObjs(coordinate))
|
||||
auto * object = map->getObjectFrom(coordinate);
|
||||
if(object)
|
||||
{
|
||||
timedEvent.deletedObjectsInstances.push_back(object->id);
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ void CGTownInstance::onHeroLeave(const CGHeroInstance * h) const
|
||||
|
||||
std::string CGTownInstance::getObjectName() const
|
||||
{
|
||||
return getNameTranslated() + ", " + town->faction->getNameTranslated();
|
||||
return getNameTranslated() + ", " + (ID == Obj::RANDOM_TOWN ? "Random town" :town->faction->getNameTranslated());
|
||||
}
|
||||
|
||||
bool CGTownInstance::townEnvisagesBuilding(BuildingSubID::EBuildingSubID subId) const
|
||||
|
@ -489,6 +489,16 @@ const CGObjectInstance * CMap::getObjectiveObjectFrom(const int3 & pos, Obj type
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
const CGObjectInstance * CMap::getObjectFrom(const int3 & pos)
|
||||
{
|
||||
for(CGObjectInstance * object : objects)
|
||||
{
|
||||
if(object->pos == pos)
|
||||
return object;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CMap::checkForObjectives()
|
||||
{
|
||||
// NOTE: probably should be moved to MapFormatH3M.cpp
|
||||
|
@ -132,6 +132,7 @@ public:
|
||||
|
||||
/// Gets object of specified type on requested position
|
||||
const CGObjectInstance * getObjectiveObjectFrom(const int3 & pos, Obj type);
|
||||
const CGObjectInstance * getObjectFrom(const int3 & pos);
|
||||
CGHeroInstance * getHero(HeroTypeID heroId);
|
||||
|
||||
/// Sets the victory/loss condition objectives ??
|
||||
|
@ -16,5 +16,6 @@ enum MapEditorRoles
|
||||
TownEventRole = Qt::UserRole + 1,
|
||||
PlayerIDRole,
|
||||
BuildingIDRole,
|
||||
SpellIDRole
|
||||
SpellIDRole,
|
||||
ObjectInstanceIDRole
|
||||
};
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "timedevent.h"
|
||||
#include "ui_timedevent.h"
|
||||
#include "eventsettings.h"
|
||||
#include "../mapeditorroles.h"
|
||||
#include "../../lib/constants/EntityIdentifiers.h"
|
||||
#include "../../lib/constants/StringConstants.h"
|
||||
|
||||
@ -56,7 +57,9 @@ TimedEvent::TimedEvent(MapController & c, QListWidgetItem * t, QWidget *parent)
|
||||
for(auto const & pos : deletedObjectPositions)
|
||||
{
|
||||
int3 position = pos.value<int3>();
|
||||
ui->deletedObjects->addItem(QString("x: %1, y: %2, z: %3").arg(position.x).arg(position.y).arg(position.z));
|
||||
auto obj = controller.map()->getObjectFrom(position);
|
||||
if(obj)
|
||||
insertObjectToDelete(obj);
|
||||
}
|
||||
show();
|
||||
}
|
||||
@ -98,11 +101,10 @@ void TimedEvent::on_TimedEvent_finished(int result)
|
||||
QVariantList deletedObjects;
|
||||
for(int i = 0; i < ui->deletedObjects->count(); ++i)
|
||||
{
|
||||
auto const & pos = ui->deletedObjects->item(i)->text();
|
||||
int3 position;
|
||||
position.x = pos.split(", ").at(0).split(": ").at(1).toInt();
|
||||
position.y = pos.split(", ").at(1).split(": ").at(1).toInt();
|
||||
position.z = pos.split(", ").at(2).split(": ").at(1).toInt();
|
||||
auto const & item = ui->deletedObjects->item(i);
|
||||
auto data = item->data(MapEditorRoles::ObjectInstanceIDRole);
|
||||
auto id = ObjectInstanceID(data.value<int>());
|
||||
auto position = controller.map()->objects[id]->pos;
|
||||
deletedObjects.push_back(QVariant::fromValue<int3>(position));
|
||||
}
|
||||
descriptor["deletedObjectsPositions"] = QVariant::fromValue(deletedObjects);
|
||||
@ -144,7 +146,15 @@ void TimedEvent::onObjectPicked(const CGObjectInstance * obj)
|
||||
|
||||
if(!obj)
|
||||
return;
|
||||
ui->deletedObjects->addItem(QString("x: %1, y: %2, z: %3").arg(obj->pos.x).arg(obj->pos.y).arg(obj->pos.z));
|
||||
insertObjectToDelete(obj);
|
||||
}
|
||||
|
||||
void TimedEvent::insertObjectToDelete(const CGObjectInstance * obj)
|
||||
{
|
||||
QString objectLabel = QString("%1, x: %2, y: %3, z: %4").arg(QString::fromStdString(obj->getObjectName())).arg(obj->pos.x).arg(obj->pos.y).arg(obj->pos.z);
|
||||
auto * item = new QListWidgetItem(objectLabel);
|
||||
item->setData(MapEditorRoles::ObjectInstanceIDRole, QVariant::fromValue(obj->id.num));
|
||||
ui->deletedObjects->addItem(item);
|
||||
}
|
||||
|
||||
void TimedEvent::on_pushButton_clicked()
|
||||
|
@ -35,6 +35,8 @@ private slots:
|
||||
|
||||
void onObjectPicked(const CGObjectInstance * obj);
|
||||
|
||||
void insertObjectToDelete(const CGObjectInstance * obj);
|
||||
|
||||
void on_pushButton_clicked();
|
||||
|
||||
void on_resources_itemDoubleClicked(QTableWidgetItem * item);
|
||||
|
Loading…
x
Reference in New Issue
Block a user