Merge branch 'master' into handle-collision

This commit is contained in:
GriffinR
2022-09-03 12:09:14 -04:00
committed by GitHub
9 changed files with 153 additions and 14 deletions

View File

@@ -2031,7 +2031,7 @@ void Editor::duplicateSelectedEvents() {
for (int i = 0; i < selected_events->length(); i++) {
Event *original = selected_events->at(i)->event;
QString eventType = original->get("event_type");
if (eventLimitReached(map, eventType)) {
if (eventLimitReached(eventType)) {
logWarn(QString("Skipping duplication, the map limit for events of type '%1' has been reached.").arg(eventType));
continue;
}
@@ -2045,7 +2045,7 @@ void Editor::duplicateSelectedEvents() {
}
DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
if (project && map && !event_type.isEmpty() && !eventLimitReached(map, event_type)) {
if (project && map && !event_type.isEmpty() && !eventLimitReached(event_type)) {
Event *event = Event::createNewEvent(event_type, map->name, project);
event->put("map_name", map->name);
if (event_type == EventType::HealLocation) {
@@ -2061,7 +2061,7 @@ DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
}
// Currently only object events have an explicit limit
bool Editor::eventLimitReached(Map *map, QString event_type)
bool Editor::eventLimitReached(QString event_type)
{
if (project && map && !event_type.isEmpty()) {
if (Event::typeToGroup(event_type) == EventGroup::Object)

View File

@@ -1520,6 +1520,7 @@ void MainWindow::copy() {
if (type == EventType::HealLocation) {
// no copy on heal locations
logWarn(QString("Copying events of type '%1' is not allowed.").arg(type));
continue;
}
@@ -1531,11 +1532,11 @@ void MainWindow::copy() {
eventsArray.append(eventJson);
}
copyObject["events"] = eventsArray;
setClipboardData(copyObject);
logInfo("Copied currently selected events to clipboard");
if (!eventsArray.isEmpty()) {
copyObject["events"] = eventsArray;
setClipboardData(copyObject);
logInfo("Copied currently selected events to clipboard");
}
break;
}
}
@@ -1620,6 +1621,11 @@ void MainWindow::paste() {
// paste the event to the map
QString type = event["event_type"].toString();
if (editor->eventLimitReached(type)) {
logWarn(QString("Skipping paste, the map limit for events of type '%1' has been reached.").arg(type));
continue;
}
Event *pasteEvent = Event::createNewEvent(type, editor->map->name, editor->project);
for (auto key : event.toObject().keys())
@@ -1651,9 +1657,10 @@ void MainWindow::paste() {
newEvents.append(pasteEvent);
}
editor->map->editHistory.push(new EventPaste(this->editor, editor->map, newEvents));
updateObjects();
if (!newEvents.isEmpty()) {
updateObjects();
editor->map->editHistory.push(new EventPaste(this->editor, editor->map, newEvents));
}
break;
}
}

View File

@@ -793,6 +793,55 @@ void MainWindow::error(QString message) {
logError(message);
}
void MainWindow::runMessageBox(QString text, QString informativeText, QString detailedText, QMessageBox::Icon icon) {
QMessageBox messageBox(this);
messageBox.setText(text);
messageBox.setInformativeText(informativeText);
messageBox.setDetailedText(detailedText);
messageBox.setIcon(icon);
messageBox.exec();
}
void MainWindow::showMessage(QString text, QString informativeText, QString detailedText) {
this->runMessageBox(text, informativeText, detailedText, QMessageBox::Information);
}
void MainWindow::showWarning(QString text, QString informativeText, QString detailedText) {
this->runMessageBox(text, informativeText, detailedText, QMessageBox::Warning);
}
void MainWindow::showError(QString text, QString informativeText, QString detailedText) {
this->runMessageBox(text, informativeText, detailedText, QMessageBox::Critical);
}
bool MainWindow::showQuestion(QString text, QString informativeText, QString detailedText) {
QMessageBox messageBox(this);
messageBox.setText(text);
messageBox.setInformativeText(informativeText);
messageBox.setDetailedText(detailedText);
messageBox.setIcon(QMessageBox::Question);
messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
return messageBox.exec() == QMessageBox::Yes;
}
QJSValue MainWindow::getInputText(QString title, QString label, QString defaultValue) {
bool ok;
QString input = QInputDialog::getText(this, title, label, QLineEdit::Normal, defaultValue, &ok);
return Scripting::dialogInput(input, ok);
}
QJSValue MainWindow::getInputNumber(QString title, QString label, double defaultValue, double min, double max, int decimals, double step) {
bool ok;
double input = QInputDialog::getDouble(this, title, label, defaultValue, min, max, decimals, &ok, Qt::WindowFlags(), step);
return Scripting::dialogInput(input, ok);
}
QJSValue MainWindow::getInputItem(QString title, QString label, QStringList items, int defaultValue, bool editable) {
bool ok;
QString input = QInputDialog::getItem(this, title, label, items, defaultValue, editable, &ok);
return Scripting::dialogInput(input, ok);
}
QList<int> MainWindow::getMetatileLayerOrder() {
if (!this->editor || !this->editor->map)
return QList<int>();

View File

@@ -262,6 +262,13 @@ QJSValue Scripting::fromTile(Tile tile) {
return obj;
}
QJSValue Scripting::dialogInput(QJSValue input, bool selectedOk) {
QJSValue obj = instance->engine->newObject();
obj.setProperty("input", input);
obj.setProperty("ok", selectedOk);
return obj;
}
QJSEngine *Scripting::getEngine() {
return instance->engine;
}