mirror of
https://github.com/huderlem/porymap.git
synced 2026-09-30 20:06:56 -05:00
Reorganize overlay functions under MapView
This commit is contained in:
@@ -604,7 +604,7 @@ void MainWindow::on_action_Open_Project_triggered()
|
||||
if (!dir.isEmpty()) {
|
||||
if (this->editor && this->editor->project) {
|
||||
Scripting::cb_ProjectClosed(this->editor->project->root);
|
||||
this->ui->graphicsView_Map->clearOverlays();
|
||||
this->ui->graphicsView_Map->clearOverlayMap();
|
||||
}
|
||||
porymapConfig.setRecentProject(dir);
|
||||
setWindowDisabled(!openProject(dir));
|
||||
@@ -3236,3 +3236,7 @@ void MainWindow::closeEvent(QCloseEvent *event) {
|
||||
|
||||
QMainWindow::closeEvent(event);
|
||||
}
|
||||
|
||||
MapView *MainWindow::getMapView() {
|
||||
return this->ui->graphicsView_Map;
|
||||
}
|
||||
|
||||
@@ -1,195 +1,162 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "mapview.h"
|
||||
#include "scripting.h"
|
||||
#include "config.h"
|
||||
#include "imageproviders.h"
|
||||
|
||||
void MainWindow::clearOverlay(int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->getOverlay(layer)->clearItems();
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
void MapView::clear(int layer) {
|
||||
this->getOverlay(layer)->clearItems();
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::clearOverlays() {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->clearOverlays();
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
// Overload. No layer provided, clear all layers
|
||||
void MapView::clear() {
|
||||
this->clearOverlayMap();
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::hideOverlay(int layer) {
|
||||
this->setOverlayVisibility(false, layer);
|
||||
void MapView::hide(int layer) {
|
||||
this->setVisibility(false, layer);
|
||||
}
|
||||
|
||||
void MainWindow::hideOverlays() {
|
||||
this->setOverlaysVisibility(false);
|
||||
// Overload. No layer provided, hide all layers
|
||||
void MapView::hide() {
|
||||
this->setVisibility(false);
|
||||
}
|
||||
|
||||
void MainWindow::showOverlay(int layer) {
|
||||
this->setOverlayVisibility(true, layer);
|
||||
void MapView::show(int layer) {
|
||||
this->setVisibility(true, layer);
|
||||
}
|
||||
|
||||
void MainWindow::showOverlays() {
|
||||
this->setOverlaysVisibility(true);
|
||||
// Overload. No layer provided, show all layers
|
||||
void MapView::show() {
|
||||
this->setVisibility(true);
|
||||
}
|
||||
|
||||
bool MainWindow::getOverlayVisibility(int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return false;
|
||||
return !(this->ui->graphicsView_Map->getOverlay(layer)->getHidden());
|
||||
bool MapView::getVisibility(int layer) {
|
||||
return !(this->getOverlay(layer)->getHidden());
|
||||
}
|
||||
|
||||
void MainWindow::setOverlayVisibility(bool visible, int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->getOverlay(layer)->setHidden(!visible);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
void MapView::setVisibility(bool visible, int layer) {
|
||||
this->getOverlay(layer)->setHidden(!visible);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::setOverlaysVisibility(bool visible) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->setOverlaysHidden(!visible);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
// Overload. No layer provided, set visibility of all layers
|
||||
void MapView::setVisibility(bool visible) {
|
||||
foreach (Overlay * layer, this->overlayMap)
|
||||
layer->setHidden(!visible);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
int MainWindow::getOverlayX(int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return 0;
|
||||
return this->ui->graphicsView_Map->getOverlay(layer)->getX();
|
||||
int MapView::getX(int layer) {
|
||||
return this->getOverlay(layer)->getX();
|
||||
}
|
||||
|
||||
int MainWindow::getOverlayY(int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return 0;
|
||||
return this->ui->graphicsView_Map->getOverlay(layer)->getY();
|
||||
int MapView::getY(int layer) {
|
||||
return this->getOverlay(layer)->getY();
|
||||
}
|
||||
|
||||
void MainWindow::setOverlayX(int x, int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->getOverlay(layer)->setX(x);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
void MapView::setX(int x, int layer) {
|
||||
this->getOverlay(layer)->setX(x);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::setOverlayY(int y, int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->getOverlay(layer)->setY(y);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
// Overload. No layer provided, set x of all layers
|
||||
void MapView::setX(int x) {
|
||||
foreach (Overlay * layer, this->overlayMap)
|
||||
layer->setX(x);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::setOverlaysX(int x) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->setOverlaysX(x);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
void MapView::setY(int y, int layer) {
|
||||
this->getOverlay(layer)->setY(y);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::setOverlaysY(int y) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->setOverlaysY(y);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
// Overload. No layer provided, set y of all layers
|
||||
void MapView::setY(int y) {
|
||||
foreach (Overlay * layer, this->overlayMap)
|
||||
layer->setY(y);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
QJSValue MainWindow::getOverlayPosition(int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return QJSValue();
|
||||
Overlay * overlay = this->ui->graphicsView_Map->getOverlay(layer);
|
||||
QJSValue MapView::getPosition(int layer) {
|
||||
Overlay * overlay = this->getOverlay(layer);
|
||||
return Scripting::position(overlay->getX(), overlay->getY());
|
||||
}
|
||||
|
||||
void MainWindow::setOverlayPosition(int x, int y, int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->getOverlay(layer)->setPosition(x, y);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
void MapView::setPosition(int x, int y, int layer) {
|
||||
this->getOverlay(layer)->setPosition(x, y);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::setOverlaysPosition(int x, int y) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->setOverlaysPosition(x, y);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
// Overload. No layer provided, set position of all layers
|
||||
void MapView::setPosition(int x, int y) {
|
||||
foreach (Overlay * layer, this->overlayMap)
|
||||
layer->setPosition(x, y);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::moveOverlay(int deltaX, int deltaY, int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->getOverlay(layer)->move(deltaX, deltaY);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
void MapView::move(int deltaX, int deltaY, int layer) {
|
||||
this->getOverlay(layer)->move(deltaX, deltaY);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::moveOverlays(int deltaX, int deltaY) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->moveOverlays(deltaX, deltaY);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
// Overload. No layer provided, move all layers
|
||||
void MapView::move(int deltaX, int deltaY) {
|
||||
foreach (Overlay * layer, this->overlayMap)
|
||||
layer->move(deltaX, deltaY);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
int MainWindow::getOverlayOpacity(int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return 0;
|
||||
return this->ui->graphicsView_Map->getOverlay(layer)->getOpacity();
|
||||
int MapView::getOpacity(int layer) {
|
||||
return this->getOverlay(layer)->getOpacity();
|
||||
}
|
||||
|
||||
void MainWindow::setOverlayOpacity(int opacity, int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->getOverlay(layer)->setOpacity(opacity);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
void MapView::setOpacity(int opacity, int layer) {
|
||||
this->getOverlay(layer)->setOpacity(opacity);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::setOverlaysOpacity(int opacity) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->setOverlaysOpacity(opacity);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
// Overload. No layer provided, set opacity of all layers
|
||||
void MapView::setOpacity(int opacity) {
|
||||
foreach (Overlay * layer, this->overlayMap)
|
||||
layer->setOpacity(opacity);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::addText(QString text, int x, int y, QString color, int fontSize, int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->getOverlay(layer)->addText(text, x, y, color, fontSize);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
void MapView::addText(QString text, int x, int y, QString color, int fontSize, int layer) {
|
||||
this->getOverlay(layer)->addText(text, x, y, color, fontSize);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::addRect(int x, int y, int width, int height, QString color, int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->getOverlay(layer)->addRect(x, y, width, height, color, false);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
void MapView::addRect(int x, int y, int width, int height, QString color, int layer) {
|
||||
this->getOverlay(layer)->addRect(x, y, width, height, color, false);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::addFilledRect(int x, int y, int width, int height, QString color, int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
this->ui->graphicsView_Map->getOverlay(layer)->addRect(x, y, width, height, color, true);
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
void MapView::addFilledRect(int x, int y, int width, int height, QString color, int layer) {
|
||||
this->getOverlay(layer)->addRect(x, y, width, height, color, true);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::addImage(int x, int y, QString filepath, int layer, bool useCache) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map)
|
||||
return;
|
||||
if (this->ui->graphicsView_Map->getOverlay(layer)->addImage(x, y, filepath, useCache))
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
void MapView::addImage(int x, int y, QString filepath, int layer, bool useCache) {
|
||||
if (this->getOverlay(layer)->addImage(x, y, filepath, useCache))
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::createImage(int x, int y, QString filepath, int width, int height, unsigned offset, qreal hScale, qreal vScale, int paletteId, bool setTransparency, int layer, bool useCache) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map || !this->editor || !this->editor->map || !this->editor->map->layout
|
||||
void MapView::createImage(int x, int y, QString filepath, int width, int height, unsigned offset, qreal hScale, qreal vScale, int paletteId, bool setTransparency, int layer, bool useCache) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout
|
||||
|| !this->editor->map->layout->tileset_primary || !this->editor->map->layout->tileset_secondary)
|
||||
return;
|
||||
QList<QRgb> palette;
|
||||
if (paletteId != -1)
|
||||
palette = Tileset::getPalette(paletteId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
|
||||
if (this->ui->graphicsView_Map->getOverlay(layer)->addImage(x, y, filepath, useCache, width, height, offset, hScale, vScale, palette, setTransparency))
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
if (this->getOverlay(layer)->addImage(x, y, filepath, useCache, width, height, offset, hScale, vScale, palette, setTransparency))
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::addTileImage(int x, int y, int tileId, bool xflip, bool yflip, int paletteId, bool setTransparency, int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map || !this->editor || !this->editor->map || !this->editor->map->layout
|
||||
void MapView::addTileImage(int x, int y, int tileId, bool xflip, bool yflip, int paletteId, bool setTransparency, int layer) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout
|
||||
|| !this->editor->map->layout->tileset_primary || !this->editor->map->layout->tileset_secondary)
|
||||
return;
|
||||
QImage image = getPalettedTileImage(tileId,
|
||||
@@ -199,17 +166,17 @@ void MainWindow::addTileImage(int x, int y, int tileId, bool xflip, bool yflip,
|
||||
.mirrored(xflip, yflip);
|
||||
if (setTransparency)
|
||||
image.setColor(0, qRgba(0, 0, 0, 0));
|
||||
if (this->ui->graphicsView_Map->getOverlay(layer)->addImage(x, y, image))
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
if (this->getOverlay(layer)->addImage(x, y, image))
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::addTileImage(int x, int y, QJSValue tileObj, bool setTransparency, int layer) {
|
||||
void MapView::addTileImage(int x, int y, QJSValue tileObj, bool setTransparency, int layer) {
|
||||
Tile tile = Scripting::toTile(tileObj);
|
||||
this->addTileImage(x, y, tile.tileId, tile.xflip, tile.yflip, tile.palette, setTransparency, layer);
|
||||
}
|
||||
|
||||
void MainWindow::addMetatileImage(int x, int y, int metatileId, bool setTransparency, int layer) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map || !this->editor || !this->editor->map || !this->editor->map->layout
|
||||
void MapView::addMetatileImage(int x, int y, int metatileId, bool setTransparency, int layer) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout
|
||||
|| !this->editor->map->layout->tileset_primary || !this->editor->map->layout->tileset_secondary)
|
||||
return;
|
||||
QImage image = getMetatileImage(static_cast<uint16_t>(metatileId),
|
||||
@@ -219,6 +186,6 @@ void MainWindow::addMetatileImage(int x, int y, int metatileId, bool setTranspar
|
||||
this->editor->map->metatileLayerOpacity);
|
||||
if (setTransparency)
|
||||
image.setColor(0, qRgba(0, 0, 0, 0));
|
||||
if (this->ui->graphicsView_Map->getOverlay(layer)->addImage(x, y, image))
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
if (this->getOverlay(layer)->addImage(x, y, image))
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ Scripting::Scripting(MainWindow *mainWindow) {
|
||||
this->engine = new QJSEngine(mainWindow);
|
||||
this->engine->installExtensions(QJSEngine::ConsoleExtension);
|
||||
this->engine->globalObject().setProperty("map", this->engine->newQObject(mainWindow));
|
||||
this->engine->globalObject().setProperty("overlay", this->engine->newQObject(mainWindow->getMapView()));
|
||||
for (QString script : projectConfig.getCustomScripts()) {
|
||||
this->filepaths.append(script);
|
||||
}
|
||||
|
||||
@@ -41,44 +41,14 @@ void MapView::drawForeground(QPainter *painter, const QRectF&) {
|
||||
editor->cursorMapTileRect->paint(painter, &option, this);
|
||||
}
|
||||
|
||||
void MapView::clearOverlays() {
|
||||
foreach (Overlay * overlay, this->overlayMap) {
|
||||
overlay->clearItems();
|
||||
delete overlay;
|
||||
void MapView::clearOverlayMap() {
|
||||
foreach (Overlay * layer, this->overlayMap) {
|
||||
layer->clearItems();
|
||||
delete layer;
|
||||
}
|
||||
this->overlayMap.clear();
|
||||
}
|
||||
|
||||
void MapView::setOverlaysHidden(bool hidden) {
|
||||
foreach (Overlay * overlay, this->overlayMap)
|
||||
overlay->setHidden(hidden);
|
||||
}
|
||||
|
||||
void MapView::setOverlaysX(int x) {
|
||||
foreach (Overlay * overlay, this->overlayMap)
|
||||
overlay->setX(x);
|
||||
}
|
||||
|
||||
void MapView::setOverlaysY(int y) {
|
||||
foreach (Overlay * overlay, this->overlayMap)
|
||||
overlay->setY(y);
|
||||
}
|
||||
|
||||
void MapView::setOverlaysPosition(int x, int y) {
|
||||
foreach (Overlay * overlay, this->overlayMap)
|
||||
overlay->setPosition(x, y);
|
||||
}
|
||||
|
||||
void MapView::setOverlaysOpacity(int opacity) {
|
||||
foreach (Overlay * overlay, this->overlayMap)
|
||||
overlay->setOpacity(opacity);
|
||||
}
|
||||
|
||||
void MapView::moveOverlays(int deltaX, int deltaY) {
|
||||
foreach (Overlay * overlay, this->overlayMap)
|
||||
overlay->move(deltaX, deltaY);
|
||||
}
|
||||
|
||||
Overlay * MapView::getOverlay(int layer) {
|
||||
Overlay * overlay = this->overlayMap.value(layer, nullptr);
|
||||
if (!overlay) {
|
||||
|
||||
Reference in New Issue
Block a user