1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Add map editor ui to set objects to remove on timed event

This commit is contained in:
godric3
2024-09-28 14:21:04 +02:00
parent 99f49ee6ad
commit 253af651cc
5 changed files with 131 additions and 26 deletions

View File

@@ -104,24 +104,39 @@ void CMapEvent::serializeJson(JsonSerializeFormat & handler)
handler.serializeInt("nextOccurrence", nextOccurrence);
resources.serializeJson(handler, "resources");
JsonNode deletedObjectsJson;
for (const auto & entry : deletedObjectsCoordinates)
if(handler.saving)
{
JsonNode values;
JsonNode valueX;
JsonNode valueY;
JsonNode valueZ;
valueX.Float() = static_cast<int>(entry.x);
valueY.Float() = static_cast<int>(entry.y);
valueZ.Float() = static_cast<int>(entry.z);
values.Vector().push_back(valueX);
values.Vector().push_back(valueY);
values.Vector().push_back(valueZ);
deletedObjectsJson.Vector().push_back(values);
}
JsonNode deletedObjectsJson;
handler.serializeRaw("deletedObjectsCoordinates", deletedObjectsJson, std::nullopt);
for(const auto & entry : deletedObjectsCoordinates)
{
JsonNode values;
JsonNode valueX;
JsonNode valueY;
JsonNode valueZ;
valueX.Float() = static_cast<int>(entry.x);
valueY.Float() = static_cast<int>(entry.y);
valueZ.Float() = static_cast<int>(entry.z);
values.Vector().push_back(valueX);
values.Vector().push_back(valueY);
values.Vector().push_back(valueZ);
deletedObjectsJson.Vector().push_back(values);
}
handler.serializeRaw("deletedObjectsCoordinates", deletedObjectsJson, std::nullopt);
}
else
{
JsonNode deletedObjectsJson = handler.getCurrent()["deletedObjectsCoordinates"];
for(auto const & entry : deletedObjectsJson.Vector())
{
int3 position;
position.x = static_cast<int>(entry[0].Float());
position.y = static_cast<int>(entry[1].Float());
position.z = static_cast<int>(entry[2].Float());
deletedObjectsCoordinates.push_back(position);
}
}
}
void CCastleEvent::serializeJson(JsonSerializeFormat & handler)

View File

@@ -161,6 +161,6 @@ void EventSettings::on_timedEventRemove_clicked()
void EventSettings::on_eventsList_itemActivated(QListWidgetItem *item)
{
new TimedEvent(item, parentWidget());
new TimedEvent(*controller, item, parentWidget());
}

View File

@@ -14,10 +14,11 @@
#include "../../lib/constants/EntityIdentifiers.h"
#include "../../lib/constants/StringConstants.h"
TimedEvent::TimedEvent(QListWidgetItem * t, QWidget *parent) :
TimedEvent::TimedEvent(MapController & c, QListWidgetItem * t, QWidget *parent) :
controller(c),
QDialog(parent),
target(t),
ui(new Ui::TimedEvent)
ui(new Ui::TimedEvent),
target(t)
{
ui->setupUi(this);
@@ -51,7 +52,12 @@ TimedEvent::TimedEvent(QListWidgetItem * t, QWidget *parent) :
nval->setFlags(nval->flags() | Qt::ItemIsEditable);
ui->resources->setItem(i, 1, nval);
}
auto deletedObjectPositions = params.value("deletedObjectsPositions").toList();
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));
}
show();
}
@@ -89,10 +95,57 @@ void TimedEvent::on_TimedEvent_finished(int result)
}
descriptor["resources"] = res;
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();
deletedObjects.push_back(QVariant::fromValue<int3>(position));
}
descriptor["deletedObjectsPositions"] = QVariant::fromValue(deletedObjects);
target->setData(Qt::UserRole, descriptor);
target->setText(ui->eventNameText->text());
}
void TimedEvent::on_addObjectToDelete_clicked()
{
for(int lvl : {0, 1})
{
auto & l = controller.scene(lvl)->objectPickerView;
l.highlight<const CGObjectInstance>();
l.update();
QObject::connect(&l, &ObjectPickerLayer::selectionMade, this, &TimedEvent::onObjectPicked);
}
hide();
dynamic_cast<QWidget *>(parent()->parent()->parent()->parent()->parent()->parent()->parent())->hide();
}
void TimedEvent::on_removeObjectToDelete_clicked()
{
delete ui->deletedObjects->takeItem(ui->deletedObjects->currentRow());
}
void TimedEvent::onObjectPicked(const CGObjectInstance * obj)
{
show();
dynamic_cast<QWidget *>(parent()->parent()->parent()->parent()->parent()->parent()->parent())->show();
for(int lvl : {0, 1})
{
auto & l = controller.scene(lvl)->objectPickerView;
l.clear();
l.update();
QObject::disconnect(&l, &ObjectPickerLayer::selectionMade, this, &TimedEvent::onObjectPicked);
}
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));
}
void TimedEvent::on_pushButton_clicked()
{

View File

@@ -11,6 +11,8 @@
#include <QDialog>
#include "mapcontroller.h"
namespace Ui {
class TimedEvent;
}
@@ -20,18 +22,25 @@ class TimedEvent : public QDialog
Q_OBJECT
public:
explicit TimedEvent(QListWidgetItem *, QWidget *parent = nullptr);
explicit TimedEvent(MapController & map, QListWidgetItem *, QWidget * parent = nullptr);
~TimedEvent();
private slots:
void on_TimedEvent_finished(int result);
void on_addObjectToDelete_clicked();
void on_removeObjectToDelete_clicked();
void onObjectPicked(const CGObjectInstance * obj);
void on_pushButton_clicked();
void on_resources_itemDoubleClicked(QTableWidgetItem *item);
void on_resources_itemDoubleClicked(QTableWidgetItem * item);
private:
Ui::TimedEvent *ui;
MapController & controller;
Ui::TimedEvent * ui;
QListWidgetItem * target;
};

View File

@@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>620</width>
<height>371</height>
<width>730</width>
<height>422</height>
</rect>
</property>
<property name="windowTitle">
@@ -197,6 +197,34 @@
</column>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="deletedObjectsLabel">
<property name="text">
<string>Objects to delete</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addObjectToDelete">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeObjectToDelete">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="deletedObjects"/>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">