Consolidate event constructor calls
This commit is contained in:
parent
0b4f02779b
commit
9ae336080e
4 changed files with 47 additions and 93 deletions
|
@ -118,6 +118,8 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Event* create(Event::Type type);
|
||||||
|
|
||||||
static QMap<Event::Group, const QPixmap*> icons;
|
static QMap<Event::Group, const QPixmap*> icons;
|
||||||
|
|
||||||
// standard public methods
|
// standard public methods
|
||||||
|
|
|
@ -6,6 +6,21 @@
|
||||||
|
|
||||||
QMap<Event::Group, const QPixmap*> Event::icons;
|
QMap<Event::Group, const QPixmap*> Event::icons;
|
||||||
|
|
||||||
|
Event* Event::create(Event::Type type) {
|
||||||
|
switch (type) {
|
||||||
|
case Event::Type::Object: return new ObjectEvent();
|
||||||
|
case Event::Type::CloneObject: return new CloneObjectEvent();
|
||||||
|
case Event::Type::Warp: return new WarpEvent();
|
||||||
|
case Event::Type::Trigger: return new TriggerEvent();
|
||||||
|
case Event::Type::WeatherTrigger: return new WeatherTriggerEvent();
|
||||||
|
case Event::Type::Sign: return new SignEvent();
|
||||||
|
case Event::Type::HiddenItem: return new HiddenItemEvent();
|
||||||
|
case Event::Type::SecretBase: return new SecretBaseEvent();
|
||||||
|
case Event::Type::HealLocation: return new HealLocationEvent();
|
||||||
|
default: return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Event::~Event() {
|
Event::~Event() {
|
||||||
if (this->eventFrame)
|
if (this->eventFrame)
|
||||||
this->eventFrame->deleteLater();
|
this->eventFrame->deleteLater();
|
||||||
|
|
|
@ -2003,10 +2003,10 @@ void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) {
|
||||||
selected_events->clear();
|
selected_events->clear();
|
||||||
selected_events->append(object);
|
selected_events->append(object);
|
||||||
} else if (!selected_events->contains(object)) {
|
} else if (!selected_events->contains(object)) {
|
||||||
// Adding event to selection
|
// Adding event to group selection
|
||||||
selected_events->append(object);
|
selected_events->append(object);
|
||||||
} else if (selected_events->length() > 1) {
|
} else if (selected_events->length() > 1) {
|
||||||
// Removing from group selection
|
// Removing event from group selection
|
||||||
selected_events->removeOne(object);
|
selected_events->removeOne(object);
|
||||||
} else {
|
} else {
|
||||||
// Attempting to toggle the only currently-selected event.
|
// Attempting to toggle the only currently-selected event.
|
||||||
|
@ -2068,56 +2068,24 @@ void Editor::duplicateSelectedEvents() {
|
||||||
}
|
}
|
||||||
|
|
||||||
DraggablePixmapItem *Editor::addNewEvent(Event::Type type) {
|
DraggablePixmapItem *Editor::addNewEvent(Event::Type type) {
|
||||||
Event *event = nullptr;
|
if (!project || !map || eventLimitReached(type))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
if (project && map && !eventLimitReached(type)) {
|
Event *event = Event::create(type);
|
||||||
switch (type) {
|
if (!event)
|
||||||
case Event::Type::Object:
|
return nullptr;
|
||||||
event = new ObjectEvent();
|
|
||||||
break;
|
|
||||||
case Event::Type::CloneObject:
|
|
||||||
event = new CloneObjectEvent();
|
|
||||||
break;
|
|
||||||
case Event::Type::Warp:
|
|
||||||
event = new WarpEvent();
|
|
||||||
break;
|
|
||||||
case Event::Type::Trigger:
|
|
||||||
event = new TriggerEvent();
|
|
||||||
break;
|
|
||||||
case Event::Type::WeatherTrigger:
|
|
||||||
event = new WeatherTriggerEvent();
|
|
||||||
break;
|
|
||||||
case Event::Type::Sign:
|
|
||||||
event = new SignEvent();
|
|
||||||
break;
|
|
||||||
case Event::Type::HiddenItem:
|
|
||||||
event = new HiddenItemEvent();
|
|
||||||
break;
|
|
||||||
case Event::Type::SecretBase:
|
|
||||||
event = new SecretBaseEvent();
|
|
||||||
break;
|
|
||||||
case Event::Type::HealLocation: {
|
|
||||||
event = new HealLocationEvent();
|
|
||||||
event->setMap(this->map);
|
|
||||||
event->setDefaultValues(this->project);
|
|
||||||
HealLocation healLocation = HealLocation::fromEvent(event);
|
|
||||||
project->healLocations.append(healLocation);
|
|
||||||
((HealLocationEvent *)event)->setIndex(project->healLocations.length());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!event) return nullptr;
|
|
||||||
|
|
||||||
event->setMap(this->map);
|
event->setMap(this->map);
|
||||||
event->setDefaultValues(this->project);
|
event->setDefaultValues(this->project);
|
||||||
|
|
||||||
map->editHistory.push(new EventCreate(this, map, event));
|
if (type == Event::Type::HealLocation) {
|
||||||
return event->getPixmapItem();
|
HealLocation healLocation = HealLocation::fromEvent(event);
|
||||||
|
project->healLocations.append(healLocation);
|
||||||
|
((HealLocationEvent *)event)->setIndex(project->healLocations.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
map->editHistory.push(new EventCreate(this, map, event));
|
||||||
|
return event->getPixmapItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currently only object events have an explicit limit
|
// Currently only object events have an explicit limit
|
||||||
|
|
|
@ -1761,7 +1761,7 @@ void MainWindow::paste() {
|
||||||
editor->metatile_selector_item->setExternalSelection(width, height, metatiles, collisions);
|
editor->metatile_selector_item->setExternalSelection(width, height, metatiles, collisions);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1:
|
case MainTab::Events:
|
||||||
{
|
{
|
||||||
// can only paste events to this tab
|
// can only paste events to this tab
|
||||||
if (pasteObject["object"].toString() != "events") {
|
if (pasteObject["object"].toString() != "events") {
|
||||||
|
@ -1773,56 +1773,25 @@ void MainWindow::paste() {
|
||||||
QJsonArray events = pasteObject["events"].toArray();
|
QJsonArray events = pasteObject["events"].toArray();
|
||||||
for (QJsonValue event : events) {
|
for (QJsonValue event : events) {
|
||||||
// paste the event to the map
|
// paste the event to the map
|
||||||
Event *pasteEvent = nullptr;
|
const QString typeString = event["event_type"].toString();
|
||||||
|
Event::Type type = Event::eventTypeFromString(typeString);
|
||||||
Event::Type type = Event::eventTypeFromString(event["event_type"].toString());
|
|
||||||
|
|
||||||
if (this->editor->eventLimitReached(type)) {
|
if (this->editor->eventLimitReached(type)) {
|
||||||
logWarn(QString("Cannot paste event, the limit for type '%1' has been reached.").arg(event["event_type"].toString()));
|
logWarn(QString("Cannot paste event, the limit for type '%1' has been reached.").arg(typeString));
|
||||||
break;
|
continue;
|
||||||
|
}
|
||||||
|
if (type == Event::Type::HealLocation) {
|
||||||
|
logWarn(QString("Cannot paste events of type '%1'").arg(typeString));
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
Event *pasteEvent = Event::create(type);
|
||||||
case Event::Type::Object:
|
if (!pasteEvent)
|
||||||
pasteEvent = new ObjectEvent();
|
continue;
|
||||||
pasteEvent->loadFromJson(event["event"].toObject(), this->editor->project);
|
|
||||||
break;
|
|
||||||
case Event::Type::CloneObject:
|
|
||||||
pasteEvent = new CloneObjectEvent();
|
|
||||||
pasteEvent->loadFromJson(event["event"].toObject(), this->editor->project);
|
|
||||||
break;
|
|
||||||
case Event::Type::Warp:
|
|
||||||
pasteEvent = new WarpEvent();
|
|
||||||
pasteEvent->loadFromJson(event["event"].toObject(), this->editor->project);
|
|
||||||
break;
|
|
||||||
case Event::Type::Trigger:
|
|
||||||
pasteEvent = new TriggerEvent();
|
|
||||||
pasteEvent->loadFromJson(event["event"].toObject(), this->editor->project);
|
|
||||||
break;
|
|
||||||
case Event::Type::WeatherTrigger:
|
|
||||||
pasteEvent = new WeatherTriggerEvent();
|
|
||||||
pasteEvent->loadFromJson(event["event"].toObject(), this->editor->project);
|
|
||||||
break;
|
|
||||||
case Event::Type::Sign:
|
|
||||||
pasteEvent = new SignEvent();
|
|
||||||
pasteEvent->loadFromJson(event["event"].toObject(), this->editor->project);
|
|
||||||
break;
|
|
||||||
case Event::Type::HiddenItem:
|
|
||||||
pasteEvent = new HiddenItemEvent();
|
|
||||||
pasteEvent->loadFromJson(event["event"].toObject(), this->editor->project);
|
|
||||||
break;
|
|
||||||
case Event::Type::SecretBase:
|
|
||||||
pasteEvent = new SecretBaseEvent();
|
|
||||||
pasteEvent->loadFromJson(event["event"].toObject(), this->editor->project);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pasteEvent) {
|
pasteEvent->loadFromJson(event["event"].toObject(), this->editor->project);
|
||||||
pasteEvent->setMap(this->editor->map);
|
pasteEvent->setMap(this->editor->map);
|
||||||
newEvents.append(pasteEvent);
|
newEvents.append(pasteEvent);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!newEvents.empty()) {
|
if (!newEvents.empty()) {
|
||||||
|
|
Loading…
Reference in a new issue