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;
|
||||
|
||||
// standard public methods
|
||||
|
|
|
@ -6,6 +6,21 @@
|
|||
|
||||
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() {
|
||||
if (this->eventFrame)
|
||||
this->eventFrame->deleteLater();
|
||||
|
|
|
@ -2003,10 +2003,10 @@ void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) {
|
|||
selected_events->clear();
|
||||
selected_events->append(object);
|
||||
} else if (!selected_events->contains(object)) {
|
||||
// Adding event to selection
|
||||
// Adding event to group selection
|
||||
selected_events->append(object);
|
||||
} else if (selected_events->length() > 1) {
|
||||
// Removing from group selection
|
||||
// Removing event from group selection
|
||||
selected_events->removeOne(object);
|
||||
} else {
|
||||
// Attempting to toggle the only currently-selected event.
|
||||
|
@ -2068,56 +2068,24 @@ void Editor::duplicateSelectedEvents() {
|
|||
}
|
||||
|
||||
DraggablePixmapItem *Editor::addNewEvent(Event::Type type) {
|
||||
Event *event = nullptr;
|
||||
if (!project || !map || eventLimitReached(type))
|
||||
return nullptr;
|
||||
|
||||
if (project && map && !eventLimitReached(type)) {
|
||||
switch (type) {
|
||||
case Event::Type::Object:
|
||||
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 *event = Event::create(type);
|
||||
if (!event)
|
||||
return nullptr;
|
||||
|
||||
event->setMap(this->map);
|
||||
event->setDefaultValues(this->project);
|
||||
event->setMap(this->map);
|
||||
event->setDefaultValues(this->project);
|
||||
|
||||
map->editHistory.push(new EventCreate(this, map, event));
|
||||
return event->getPixmapItem();
|
||||
if (type == Event::Type::HealLocation) {
|
||||
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
|
||||
|
|
|
@ -1761,7 +1761,7 @@ void MainWindow::paste() {
|
|||
editor->metatile_selector_item->setExternalSelection(width, height, metatiles, collisions);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
case MainTab::Events:
|
||||
{
|
||||
// can only paste events to this tab
|
||||
if (pasteObject["object"].toString() != "events") {
|
||||
|
@ -1773,56 +1773,25 @@ void MainWindow::paste() {
|
|||
QJsonArray events = pasteObject["events"].toArray();
|
||||
for (QJsonValue event : events) {
|
||||
// paste the event to the map
|
||||
Event *pasteEvent = nullptr;
|
||||
|
||||
Event::Type type = Event::eventTypeFromString(event["event_type"].toString());
|
||||
const QString typeString = event["event_type"].toString();
|
||||
Event::Type type = Event::eventTypeFromString(typeString);
|
||||
|
||||
if (this->editor->eventLimitReached(type)) {
|
||||
logWarn(QString("Cannot paste event, the limit for type '%1' has been reached.").arg(event["event_type"].toString()));
|
||||
break;
|
||||
logWarn(QString("Cannot paste event, the limit for type '%1' has been reached.").arg(typeString));
|
||||
continue;
|
||||
}
|
||||
if (type == Event::Type::HealLocation) {
|
||||
logWarn(QString("Cannot paste events of type '%1'").arg(typeString));
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case Event::Type::Object:
|
||||
pasteEvent = new ObjectEvent();
|
||||
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;
|
||||
}
|
||||
Event *pasteEvent = Event::create(type);
|
||||
if (!pasteEvent)
|
||||
continue;
|
||||
|
||||
if (pasteEvent) {
|
||||
pasteEvent->setMap(this->editor->map);
|
||||
newEvents.append(pasteEvent);
|
||||
}
|
||||
pasteEvent->loadFromJson(event["event"].toObject(), this->editor->project);
|
||||
pasteEvent->setMap(this->editor->map);
|
||||
newEvents.append(pasteEvent);
|
||||
}
|
||||
|
||||
if (!newEvents.empty()) {
|
||||
|
|
Loading…
Reference in a new issue