Merge 730718e432
into 3808750c23
This commit is contained in:
commit
4afdd43487
6 changed files with 134 additions and 30 deletions
106
mainwindow.cpp
106
mainwindow.cpp
|
@ -19,7 +19,7 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QScroller>
|
#include <QScroller>
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QSysInfo>
|
#include <QSysInfo>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
@ -54,9 +54,16 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
if (settings.contains(key)) {
|
if (settings.contains(key)) {
|
||||||
QString default_dir = settings.value(key).toStringList().last();
|
QString default_dir = settings.value(key).toStringList().last();
|
||||||
if (!default_dir.isNull()) {
|
if (!default_dir.isNull()) {
|
||||||
|
QDir dir(default_dir);
|
||||||
|
if (dir.exists()) {
|
||||||
qDebug() << QString("default_dir: '%1'").arg(default_dir);
|
qDebug() << QString("default_dir: '%1'").arg(default_dir);
|
||||||
openProject(default_dir);
|
openProject(default_dir);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
qDebug() << "No project found at" << default_dir;
|
||||||
|
closeProject();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.contains("cursor_mode") && settings.value("cursor_mode") == "0") {
|
if (settings.contains("cursor_mode") && settings.value("cursor_mode") == "0") {
|
||||||
|
@ -101,6 +108,12 @@ void MainWindow::openProject(QString dir) {
|
||||||
setStatusBarMessage(QString("Opened project %1").arg(dir));
|
setStatusBarMessage(QString("Opened project %1").arg(dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::closeProject() {
|
||||||
|
QSettings settings;
|
||||||
|
settings.remove("recent_projects");
|
||||||
|
//ui->setupUi(this);
|
||||||
|
}
|
||||||
|
|
||||||
QString MainWindow::getDefaultMap() {
|
QString MainWindow::getDefaultMap() {
|
||||||
if (editor && editor->project) {
|
if (editor && editor->project) {
|
||||||
QList<QStringList> names = editor->project->groupedMapNames;
|
QList<QStringList> names = editor->project->groupedMapNames;
|
||||||
|
@ -156,15 +169,30 @@ void MainWindow::on_action_Open_Project_triggered()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_action_Close_Project_triggered()
|
||||||
|
{
|
||||||
|
closeProject();
|
||||||
|
QApplication::quit();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::setMap(QString map_name) {
|
void MainWindow::setMap(QString map_name) {
|
||||||
|
// if clicking on map group, open first map in group
|
||||||
|
if (map_name.startsWith("gMapGroup")) {
|
||||||
|
int groupNum = map_name.remove("gMapGroup").toInt();
|
||||||
|
map_name = editor->project->groupedMapNames[groupNum][0];
|
||||||
|
}
|
||||||
qDebug() << QString("setMap(%1)").arg(map_name);
|
qDebug() << QString("setMap(%1)").arg(map_name);
|
||||||
if (map_name.isNull()) {
|
if (map_name.isNull()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
editor->setMap(map_name);
|
editor->setMap(map_name);
|
||||||
redrawMapScene();
|
redrawMapScene();
|
||||||
|
scaleMapView(0);
|
||||||
displayMapProperties();
|
displayMapProperties();
|
||||||
|
|
||||||
|
ui->mapList->scrollTo(mapListIndexes.value(map_name));
|
||||||
|
ui->mapList->setCurrentIndex(mapListIndexes.value(map_name));
|
||||||
|
|
||||||
setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - porymap");
|
setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - porymap");
|
||||||
|
|
||||||
connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *)));
|
connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *)));
|
||||||
|
@ -426,6 +454,7 @@ void MainWindow::populateMapList() {
|
||||||
QString map_name = names.value(j);
|
QString map_name = names.value(j);
|
||||||
QStandardItem *map = createMapItem(map_name, i, j);
|
QStandardItem *map = createMapItem(map_name, i, j);
|
||||||
group->appendRow(map);
|
group->appendRow(map);
|
||||||
|
mapListIndexes.insert(map_name, map->index());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,6 +467,7 @@ void MainWindow::populateMapList() {
|
||||||
ui->mapList->setUpdatesEnabled(true);
|
ui->mapList->setUpdatesEnabled(true);
|
||||||
ui->mapList->expandToDepth(2);
|
ui->mapList->expandToDepth(2);
|
||||||
ui->mapList->repaint();
|
ui->mapList->repaint();
|
||||||
|
ui->mapList->setExpandsOnDoubleClick(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStandardItem* MainWindow::createMapItem(QString mapName, int groupNum, int inGroupNum) {
|
QStandardItem* MainWindow::createMapItem(QString mapName, int groupNum, int inGroupNum) {
|
||||||
|
@ -488,6 +518,7 @@ void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction)
|
||||||
int numMapsInGroup = groupItem->rowCount();
|
int numMapsInGroup = groupItem->rowCount();
|
||||||
QStandardItem *newMapItem = createMapItem(newMapName, groupNum, numMapsInGroup);
|
QStandardItem *newMapItem = createMapItem(newMapName, groupNum, numMapsInGroup);
|
||||||
groupItem->appendRow(newMapItem);
|
groupItem->appendRow(newMapItem);
|
||||||
|
mapListIndexes.insert(newMapName, newMapItem->index());
|
||||||
|
|
||||||
setMap(newMapName);
|
setMap(newMapName);
|
||||||
}
|
}
|
||||||
|
@ -649,20 +680,77 @@ void MainWindow::on_actionMap_Shift_triggered()
|
||||||
on_toolButton_Shift_clicked();
|
on_toolButton_Shift_clicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::scaleMapView(int s) {
|
void MainWindow::wheelEvent(QWheelEvent *event) {
|
||||||
editor->map->scale_exp += s;
|
const int THRESHOLD = 16;
|
||||||
|
|
||||||
|
QPoint moved = event->pixelDelta();
|
||||||
|
|
||||||
|
if (event->modifiers() & Qt::ControlModifier) {
|
||||||
|
|
||||||
|
ui->scrollArea->verticalScrollBar()->setEnabled(false);
|
||||||
|
ui->scrollArea->horizontalScrollBar()->setEnabled(false);
|
||||||
|
|
||||||
|
if (moved.y() >= THRESHOLD) {
|
||||||
|
scaleMapView(1);
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
else if (moved.y() <= -THRESHOLD) {
|
||||||
|
scaleMapView(-1);
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::keyReleaseEvent(QKeyEvent *event) {
|
||||||
|
// when CTRL key is released after wheelEvent zooming, re-enable scrollbars
|
||||||
|
if(event->key() == Qt::Key_Control) {
|
||||||
|
ui->scrollArea->verticalScrollBar()->setEnabled(true);
|
||||||
|
ui->scrollArea->horizontalScrollBar()->setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::scaleMapView(int s) {
|
||||||
|
if (s == 0) { // reset to default scale then scale again
|
||||||
|
int scaleTo = editor->project->scale_exp;
|
||||||
|
if (scaleTo != 0) {
|
||||||
|
resetMapScale(scaleTo);
|
||||||
|
scaleMapView(scaleTo);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
editor->project->scale_exp += s;
|
||||||
|
|
||||||
|
double base = editor->project->scale_base;
|
||||||
|
double exp = editor->project->scale_exp;
|
||||||
|
|
||||||
double base = editor->map->scale_base;
|
|
||||||
double exp = editor->map->scale_exp;
|
|
||||||
double sfactor = pow(base,s);
|
double sfactor = pow(base,s);
|
||||||
|
|
||||||
ui->graphicsView_Map->scale(sfactor,sfactor);
|
ui->graphicsView_Map->scale(sfactor,sfactor);
|
||||||
ui->graphicsView_Objects_Map->scale(sfactor,sfactor);
|
ui->graphicsView_Objects_Map->scale(sfactor,sfactor);
|
||||||
|
|
||||||
int width = static_cast<int>((editor->scene->width() + 2) * pow(base,exp));
|
auto newWidth = floor((editor->scene->width() + 8) * pow(base,exp) + 2);
|
||||||
int height = static_cast<int>((editor->scene->height() + 2) * pow(base,exp));
|
auto newHeight = floor((editor->scene->height() + 8) * pow(base,exp) + 2);
|
||||||
ui->graphicsView_Map->setFixedSize(width, height);
|
|
||||||
ui->graphicsView_Objects_Map->setFixedSize(width, height);
|
ui->graphicsView_Map->setFixedSize(newWidth, newHeight);
|
||||||
|
ui->graphicsView_Objects_Map->setFixedSize(newWidth, newHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::resetMapScale(int mag)
|
||||||
|
{
|
||||||
|
// easiest way to un-scale map
|
||||||
|
if (mag > 0) {
|
||||||
|
for (int i = 0; i < mag; i++) {
|
||||||
|
scaleMapView(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mag = -mag;
|
||||||
|
for (int i = 0; i < mag; i++) {
|
||||||
|
scaleMapView(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addNewEvent(QString event_type)
|
void MainWindow::addNewEvent(QString event_type)
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#include <QGraphicsItemGroup>
|
#include <QGraphicsItemGroup>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
#include <QWheelEvent>
|
||||||
|
#include <QKeyEvent>
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
|
@ -25,11 +27,15 @@ public:
|
||||||
explicit MainWindow(QWidget *parent = nullptr);
|
explicit MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
virtual void wheelEvent(QWheelEvent *event);
|
||||||
|
virtual void keyReleaseEvent(QKeyEvent *event);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setStatusBarMessage(QString message, int timeout = 0);
|
void setStatusBarMessage(QString message, int timeout = 0);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_action_Open_Project_triggered();
|
void on_action_Open_Project_triggered();
|
||||||
|
void on_action_Close_Project_triggered();
|
||||||
void on_mapList_activated(const QModelIndex &index);
|
void on_mapList_activated(const QModelIndex &index);
|
||||||
void on_action_Save_Project_triggered();
|
void on_action_Save_Project_triggered();
|
||||||
void openWarpMap(QString map_name, QString warp_num);
|
void openWarpMap(QString map_name, QString warp_num);
|
||||||
|
@ -125,6 +131,7 @@ private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
QStandardItemModel *mapListModel;
|
QStandardItemModel *mapListModel;
|
||||||
QList<QStandardItem*> *mapGroupsModel;
|
QList<QStandardItem*> *mapGroupsModel;
|
||||||
|
QMap<QString, QModelIndex> mapListIndexes;
|
||||||
Editor *editor = nullptr;
|
Editor *editor = nullptr;
|
||||||
QIcon* mapIcon;
|
QIcon* mapIcon;
|
||||||
void setMap(QString);
|
void setMap(QString);
|
||||||
|
@ -133,6 +140,7 @@ private:
|
||||||
void populateMapList();
|
void populateMapList();
|
||||||
QString getExistingDirectory(QString);
|
QString getExistingDirectory(QString);
|
||||||
void openProject(QString dir);
|
void openProject(QString dir);
|
||||||
|
void closeProject();
|
||||||
QString getDefaultMap();
|
QString getDefaultMap();
|
||||||
void setRecentMap(QString map_name);
|
void setRecentMap(QString map_name);
|
||||||
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);
|
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);
|
||||||
|
@ -145,6 +153,7 @@ private:
|
||||||
void checkToolButtons();
|
void checkToolButtons();
|
||||||
|
|
||||||
void scaleMapView(int);
|
void scaleMapView(int);
|
||||||
|
void resetMapScale(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
enum MapListUserRoles {
|
enum MapListUserRoles {
|
||||||
|
|
|
@ -378,8 +378,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>469</width>
|
<width>545</width>
|
||||||
<height>608</height>
|
<height>587</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_8">
|
<layout class="QGridLayout" name="gridLayout_8">
|
||||||
|
@ -687,8 +687,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>324</width>
|
<width>256</width>
|
||||||
<height>77</height>
|
<height>74</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||||
|
@ -797,10 +797,10 @@
|
||||||
</property>
|
</property>
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>8</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>307</width>
|
<width>222</width>
|
||||||
<height>387</height>
|
<height>353</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -1116,8 +1116,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>381</width>
|
<width>371</width>
|
||||||
<height>657</height>
|
<height>643</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_7">
|
<layout class="QGridLayout" name="gridLayout_7">
|
||||||
|
@ -1294,8 +1294,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>432</width>
|
<width>428</width>
|
||||||
<height>596</height>
|
<height>578</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -1914,8 +1914,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>826</width>
|
<width>818</width>
|
||||||
<height>557</height>
|
<height>539</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_14">
|
<layout class="QGridLayout" name="gridLayout_14">
|
||||||
|
@ -2087,7 +2087,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1117</width>
|
<width>1117</width>
|
||||||
<height>21</height>
|
<height>22</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
|
@ -2095,6 +2095,7 @@
|
||||||
<string>File</string>
|
<string>File</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="action_Open_Project"/>
|
<addaction name="action_Open_Project"/>
|
||||||
|
<addaction name="action_Close_Project"/>
|
||||||
<addaction name="action_Save"/>
|
<addaction name="action_Save"/>
|
||||||
<addaction name="action_Save_Project"/>
|
<addaction name="action_Save_Project"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
|
@ -2268,6 +2269,11 @@
|
||||||
<string>P</string>
|
<string>P</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="action_Close_Project">
|
||||||
|
<property name="text">
|
||||||
|
<string>Close Project</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|
5
map.cpp
5
map.cpp
|
@ -525,11 +525,10 @@ bool Map::hasUnsavedChanges() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::hoveredTileChanged(int x, int y, int block) {
|
void Map::hoveredTileChanged(int x, int y, int block) {
|
||||||
emit statusBarMessage(QString("X: %1, Y: %2, Metatile: 0x%3, Scale = %4x")
|
emit statusBarMessage(QString("X: %1, Y: %2, Metatile: 0x%3")
|
||||||
.arg(x)
|
.arg(x)
|
||||||
.arg(y)
|
.arg(y)
|
||||||
.arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper())
|
.arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper()));
|
||||||
.arg(QString::number(pow(this->scale_base,this->scale_exp))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::clearHoveredTile() {
|
void Map::clearHoveredTile() {
|
||||||
|
|
2
map.h
2
map.h
|
@ -141,8 +141,6 @@ public:
|
||||||
QString show_location;
|
QString show_location;
|
||||||
QString battle_scene;
|
QString battle_scene;
|
||||||
MapLayout *layout;
|
MapLayout *layout;
|
||||||
int scale_exp = 0;
|
|
||||||
double scale_base = sqrt(2); // adjust scale factor with this
|
|
||||||
|
|
||||||
bool isPersistedToFile = true;
|
bool isPersistedToFile = true;
|
||||||
|
|
||||||
|
|
|
@ -116,12 +116,16 @@ public:
|
||||||
QString readCIncbin(QString text, QString label);
|
QString readCIncbin(QString text, QString label);
|
||||||
QMap<QString, int> readCDefines(QString text, QStringList prefixes);
|
QMap<QString, int> readCDefines(QString text, QStringList prefixes);
|
||||||
|
|
||||||
|
int scale_exp = 0;
|
||||||
|
double scale_base = sqrt(2); // adjust scale factor with this
|
||||||
|
|
||||||
static int getNumTilesPrimary();
|
static int getNumTilesPrimary();
|
||||||
static int getNumTilesTotal();
|
static int getNumTilesTotal();
|
||||||
static int getNumMetatilesPrimary();
|
static int getNumMetatilesPrimary();
|
||||||
static int getNumMetatilesTotal();
|
static int getNumMetatilesTotal();
|
||||||
static int getNumPalettesPrimary();
|
static int getNumPalettesPrimary();
|
||||||
static int getNumPalettesTotal();
|
static int getNumPalettesTotal();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString getMapLayoutsTableFilepath();
|
QString getMapLayoutsTableFilepath();
|
||||||
QString getMapLayoutFilepath(QString);
|
QString getMapLayoutFilepath(QString);
|
||||||
|
|
Loading…
Reference in a new issue