2018-09-27 00:33:08 +01:00
# include "mainwindow.h"
# include "ui_mainwindow.h"
2019-01-08 16:28:20 +00:00
# include "aboutporymap.h"
2018-09-27 00:33:08 +01:00
# include "project.h"
2018-12-20 23:30:35 +00:00
# include "log.h"
2018-09-27 00:33:08 +01:00
# include "editor.h"
2022-09-08 02:38:30 +01:00
# include "prefabcreationdialog.h"
2022-07-19 22:56:12 +01:00
# include "eventframes.h"
2018-09-27 00:33:08 +01:00
# include "bordermetatilespixmapitem.h"
# include "currentselectedmetatilespixmapitem.h"
2020-04-27 01:38:20 +01:00
# include "customattributestable.h"
# include "scripting.h"
2020-05-01 00:44:54 +01:00
# include "adjustingstackedwidget.h"
2020-07-30 21:35:48 +01:00
# include "draggablepixmapitem.h"
2020-07-29 20:51:04 +01:00
# include "editcommands.h"
2020-10-20 20:02:06 +01:00
# include "flowlayout.h"
2020-11-03 10:58:10 +00:00
# include "shortcut.h"
2020-09-19 20:05:27 +01:00
# include "mapparser.h"
2022-09-06 02:51:31 +01:00
# include "prefab.h"
2018-09-27 00:33:08 +01:00
# include <QFileDialog>
2021-04-14 06:08:18 +01:00
# include <QClipboard>
2019-08-14 22:39:23 +01:00
# include <QDirIterator>
2018-09-27 00:33:08 +01:00
# include <QStandardItemModel>
# include <QSpinBox>
# include <QTextEdit>
# include <QSpacerItem>
# include <QFont>
# include <QScrollBar>
# include <QPushButton>
# include <QMessageBox>
# include <QDialogButtonBox>
# include <QScroller>
# include <math.h>
# include <QSysInfo>
# include <QDesktopServices>
2020-08-16 00:30:46 +01:00
# include <QTransform>
2020-04-07 19:20:31 +01:00
# include <QSignalBlocker>
2020-04-18 19:07:41 +01:00
# include <QSet>
2021-06-27 17:25:13 +01:00
# include <QLoggingCategory>
2018-09-27 00:33:08 +01:00
2021-04-14 06:08:18 +01:00
using OrderedJson = poryjson : : Json ;
using OrderedJsonDoc = poryjson : : JsonDoc ;
2020-08-07 00:46:23 +01:00
2018-09-27 00:33:08 +01:00
MainWindow : : MainWindow ( QWidget * parent ) :
QMainWindow ( parent ) ,
2018-11-28 01:39:57 +00:00
ui ( new Ui : : MainWindow ) ,
selectedObject ( nullptr ) ,
selectedWarp ( nullptr ) ,
selectedTrigger ( nullptr ) ,
selectedBG ( nullptr ) ,
selectedHealspot ( nullptr ) ,
isProgrammaticEventTabChange ( false )
2018-09-27 00:33:08 +01:00
{
QCoreApplication : : setOrganizationName ( " pret " ) ;
QCoreApplication : : setApplicationName ( " porymap " ) ;
2018-09-27 19:27:57 +01:00
QApplication : : setApplicationDisplayName ( " porymap " ) ;
2020-04-21 02:54:16 +01:00
QApplication : : setWindowIcon ( QIcon ( " :/icons/porymap-icon-2.ico " ) ) ;
2018-09-27 00:33:08 +01:00
ui - > setupUi ( this ) ;
2018-12-20 23:30:35 +00:00
2020-10-10 19:06:51 +01:00
cleanupLargeLog ( ) ;
2018-12-20 23:30:35 +00:00
this - > initWindow ( ) ;
if ( ! this - > openRecentProject ( ) ) {
2020-09-13 23:34:18 +01:00
setWindowDisabled ( true ) ;
} else {
setWindowDisabled ( false ) ;
on_toolButton_Paint_clicked ( ) ;
2018-12-20 23:30:35 +00:00
}
2021-06-27 17:25:13 +01:00
// there is a bug affecting macOS users, where the trackpad deilveres a bad touch-release gesture
// the warning is a bit annoying, so it is disabled here
QLoggingCategory : : setFilterRules ( QStringLiteral ( " qt.pointer.dispatch=false " ) ) ;
2018-09-27 00:33:08 +01:00
}
MainWindow : : ~ MainWindow ( )
{
2020-10-26 03:49:00 +00:00
delete label_MapRulerStatus ;
2018-09-27 00:33:08 +01:00
delete ui ;
}
2020-08-03 22:37:54 +01:00
void MainWindow : : setWindowDisabled ( bool disabled ) {
2020-10-30 19:08:40 +00:00
for ( auto action : findChildren < QAction * > ( ) )
action - > setDisabled ( disabled ) ;
for ( auto child : findChildren < QWidget * > ( QString ( ) , Qt : : FindDirectChildrenOnly ) )
child - > setDisabled ( disabled ) ;
for ( auto menu : ui - > menuBar - > findChildren < QMenu * > ( QString ( ) , Qt : : FindDirectChildrenOnly ) )
menu - > setDisabled ( disabled ) ;
ui - > menuBar - > setDisabled ( false ) ;
ui - > menuFile - > setDisabled ( false ) ;
ui - > action_Open_Project - > setDisabled ( false ) ;
ui - > action_Exit - > setDisabled ( false ) ;
ui - > menuHelp - > setDisabled ( false ) ;
ui - > actionAbout_Porymap - > setDisabled ( false ) ;
2021-02-03 15:32:00 +00:00
ui - > actionOpen_Log_File - > setDisabled ( false ) ;
2021-02-03 16:24:07 +00:00
ui - > actionOpen_Config_Folder - > setDisabled ( false ) ;
2020-12-01 15:13:56 +00:00
if ( ! disabled )
togglePreferenceSpecificUi ( ) ;
2020-08-03 22:37:54 +01:00
}
2018-12-20 23:30:35 +00:00
void MainWindow : : initWindow ( ) {
2018-12-25 20:41:06 +00:00
porymapConfig . load ( ) ;
2018-12-20 23:30:35 +00:00
this - > initCustomUI ( ) ;
this - > initExtraSignals ( ) ;
this - > initEditor ( ) ;
this - > initMiscHeapObjects ( ) ;
this - > initMapSortOrder ( ) ;
2020-11-08 13:36:02 +00:00
this - > initShortcuts ( ) ;
2019-01-07 23:14:44 +00:00
this - > restoreWindowState ( ) ;
2020-08-03 20:31:14 +01:00
2020-08-04 00:28:26 +01:00
setWindowDisabled ( true ) ;
2018-12-20 23:30:35 +00:00
}
2020-11-08 13:36:02 +00:00
void MainWindow : : initShortcuts ( ) {
initExtraShortcuts ( ) ;
shortcutsConfig . load ( ) ;
shortcutsConfig . setDefaultShortcuts ( shortcutableObjects ( ) ) ;
applyUserShortcuts ( ) ;
}
2018-09-27 00:33:08 +01:00
void MainWindow : : initExtraShortcuts ( ) {
2020-11-13 04:48:03 +00:00
ui - > actionZoom_In - > setShortcuts ( { ui - > actionZoom_In - > shortcut ( ) , QKeySequence ( " Ctrl+= " ) } ) ;
2020-11-03 10:58:10 +00:00
auto * shortcutReset_Zoom = new Shortcut ( QKeySequence ( " Ctrl+0 " ) , this , SLOT ( resetMapViewScale ( ) ) ) ;
2020-11-08 13:36:02 +00:00
shortcutReset_Zoom - > setObjectName ( " shortcutZoom_Reset " ) ;
shortcutReset_Zoom - > setWhatsThis ( " Zoom Reset " ) ;
2020-11-03 10:58:10 +00:00
auto * shortcutToggle_Grid = new Shortcut ( QKeySequence ( " Ctrl+G " ) , ui - > checkBox_ToggleGrid , SLOT ( toggle ( ) ) ) ;
shortcutToggle_Grid - > setObjectName ( " shortcutToggle_Grid " ) ;
2020-11-08 13:36:02 +00:00
shortcutToggle_Grid - > setWhatsThis ( " Toggle Grid " ) ;
2020-11-03 10:58:10 +00:00
auto * shortcutDuplicate_Events = new Shortcut ( QKeySequence ( " Ctrl+D " ) , this , SLOT ( duplicate ( ) ) ) ;
shortcutDuplicate_Events - > setObjectName ( " shortcutDuplicate_Events " ) ;
2020-11-08 13:36:02 +00:00
shortcutDuplicate_Events - > setWhatsThis ( " Duplicate Selected Event(s) " ) ;
2020-11-03 10:58:10 +00:00
auto * shortcutDelete_Object = new Shortcut (
{ QKeySequence ( " Del " ) , QKeySequence ( " Backspace " ) } , this , SLOT ( on_toolButton_deleteObject_clicked ( ) ) ) ;
shortcutDelete_Object - > setObjectName ( " shortcutDelete_Object " ) ;
2020-11-08 13:36:02 +00:00
shortcutDelete_Object - > setWhatsThis ( " Delete Selected Event(s) " ) ;
2020-11-03 10:58:10 +00:00
2020-11-13 04:48:03 +00:00
auto * shortcutToggle_Border = new Shortcut ( QKeySequence ( ) , ui - > checkBox_ToggleBorder , SLOT ( toggle ( ) ) ) ;
shortcutToggle_Border - > setObjectName ( " shortcutToggle_Border " ) ;
shortcutToggle_Border - > setWhatsThis ( " Toggle Border " ) ;
auto * shortcutToggle_Smart_Paths = new Shortcut ( QKeySequence ( ) , ui - > checkBox_smartPaths , SLOT ( toggle ( ) ) ) ;
shortcutToggle_Smart_Paths - > setObjectName ( " shortcutToggle_Smart_Paths " ) ;
shortcutToggle_Smart_Paths - > setWhatsThis ( " Toggle Smart Paths " ) ;
auto * shortcutExpand_All = new Shortcut ( QKeySequence ( ) , this , SLOT ( on_toolButton_ExpandAll_clicked ( ) ) ) ;
shortcutExpand_All - > setObjectName ( " shortcutExpand_All " ) ;
shortcutExpand_All - > setWhatsThis ( " Map List: Expand all folders " ) ;
auto * shortcutCollapse_All = new Shortcut ( QKeySequence ( ) , this , SLOT ( on_toolButton_CollapseAll_clicked ( ) ) ) ;
shortcutCollapse_All - > setObjectName ( " shortcutCollapse_All " ) ;
shortcutCollapse_All - > setWhatsThis ( " Map List: Collapse all folders " ) ;
2020-12-13 09:00:00 +00:00
auto * shortcut_Open_Scripts = new Shortcut ( QKeySequence ( ) , ui - > toolButton_Open_Scripts , SLOT ( click ( ) ) ) ;
shortcut_Open_Scripts - > setObjectName ( " shortcut_Open_Scripts " ) ;
shortcut_Open_Scripts - > setWhatsThis ( " Open Map Scripts " ) ;
2021-04-14 06:08:18 +01:00
2021-05-03 20:47:29 +01:00
copyAction = new QAction ( " Copy " , this ) ;
copyAction - > setShortcut ( QKeySequence ( " Ctrl+C " ) ) ;
connect ( copyAction , & QAction : : triggered , this , & MainWindow : : copy ) ;
ui - > menuEdit - > addSeparator ( ) ;
ui - > menuEdit - > addAction ( copyAction ) ;
pasteAction = new QAction ( " Paste " , this ) ;
pasteAction - > setShortcut ( QKeySequence ( " Ctrl+V " ) ) ;
connect ( pasteAction , & QAction : : triggered , this , & MainWindow : : paste ) ;
ui - > menuEdit - > addAction ( pasteAction ) ;
2018-09-27 00:33:08 +01:00
}
2020-11-08 13:36:02 +00:00
QObjectList MainWindow : : shortcutableObjects ( ) const {
QObjectList shortcutable_objects ;
2020-11-13 04:48:03 +00:00
2020-11-01 12:35:20 +00:00
for ( auto * action : findChildren < QAction * > ( ) )
2020-11-13 04:48:03 +00:00
if ( ! action - > objectName ( ) . isEmpty ( ) )
2020-11-08 13:36:02 +00:00
shortcutable_objects . append ( qobject_cast < QObject * > ( action ) ) ;
2020-11-03 10:58:10 +00:00
for ( auto * shortcut : findChildren < Shortcut * > ( ) )
2020-11-13 04:48:03 +00:00
if ( ! shortcut - > objectName ( ) . isEmpty ( ) )
2020-11-08 13:36:02 +00:00
shortcutable_objects . append ( qobject_cast < QObject * > ( shortcut ) ) ;
2020-11-13 04:48:03 +00:00
2020-11-08 13:36:02 +00:00
return shortcutable_objects ;
}
void MainWindow : : applyUserShortcuts ( ) {
for ( auto * action : findChildren < QAction * > ( ) )
2020-11-13 04:48:03 +00:00
if ( ! action - > objectName ( ) . isEmpty ( ) )
2020-11-08 13:36:02 +00:00
action - > setShortcuts ( shortcutsConfig . userShortcuts ( action ) ) ;
for ( auto * shortcut : findChildren < Shortcut * > ( ) )
2020-11-13 04:48:03 +00:00
if ( ! shortcut - > objectName ( ) . isEmpty ( ) )
2020-11-08 13:36:02 +00:00
shortcut - > setKeys ( shortcutsConfig . userShortcuts ( shortcut ) ) ;
2018-09-27 00:33:08 +01:00
}
2018-10-05 23:39:50 +01:00
void MainWindow : : initCustomUI ( ) {
2019-11-02 01:19:39 +00:00
// Set up the tab bar
2020-09-13 23:34:18 +01:00
while ( ui - > mainTabBar - > count ( ) ) ui - > mainTabBar - > removeTab ( 0 ) ;
2020-01-02 19:59:31 +00:00
ui - > mainTabBar - > addTab ( " Map " ) ;
2019-11-02 01:19:39 +00:00
ui - > mainTabBar - > setTabIcon ( 0 , QIcon ( QStringLiteral ( " :/icons/map.ico " ) ) ) ;
ui - > mainTabBar - > addTab ( " Events " ) ;
ui - > mainTabBar - > addTab ( " Header " ) ;
ui - > mainTabBar - > addTab ( " Connections " ) ;
2020-01-02 19:59:31 +00:00
ui - > mainTabBar - > addTab ( " Wild Pokemon " ) ;
2019-11-02 01:19:39 +00:00
ui - > mainTabBar - > setTabIcon ( 4 , QIcon ( QStringLiteral ( " :/icons/tall_grass.ico " ) ) ) ;
2020-09-13 23:34:18 +01:00
}
2019-11-02 01:19:39 +00:00
2020-09-13 23:34:18 +01:00
void MainWindow : : initExtraSignals ( ) {
2018-10-05 23:39:50 +01:00
// Right-clicking on items in the map list tree view brings up a context menu.
ui - > mapList - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
2021-02-14 14:16:23 +00:00
connect ( ui - > mapList , & QTreeView : : customContextMenuRequested ,
this , & MainWindow : : onOpenMapListContextMenu ) ;
2019-06-26 20:15:50 +01:00
2020-09-13 23:34:18 +01:00
// other signals
2021-02-14 14:16:23 +00:00
connect ( ui - > newEventToolButton , & NewEventToolButton : : newEventAdded , this , & MainWindow : : addNewEvent ) ;
2020-09-13 23:34:18 +01:00
connect ( ui - > tabWidget_EventType , & QTabWidget : : currentChanged , this , & MainWindow : : eventTabChanged ) ;
// Change pages on wild encounter groups
2019-06-26 20:15:50 +01:00
QStackedWidget * stack = ui - > stackedWidget_WildMons ;
QComboBox * labelCombo = ui - > comboBox_EncounterGroupLabel ;
connect ( labelCombo , QOverload < int > : : of ( & QComboBox : : currentIndexChanged ) , [ = ] ( int index ) {
stack - > setCurrentIndex ( index ) ;
} ) ;
2020-10-20 20:02:06 +01:00
// Convert the layout of the map tools' frame into an adjustable FlowLayout
FlowLayout * flowLayout = new FlowLayout ;
flowLayout - > setContentsMargins ( ui - > frame_mapTools - > layout ( ) - > contentsMargins ( ) ) ;
flowLayout - > setSpacing ( ui - > frame_mapTools - > layout ( ) - > spacing ( ) ) ;
for ( auto * child : ui - > frame_mapTools - > findChildren < QWidget * > ( QString ( ) , Qt : : FindDirectChildrenOnly ) ) {
flowLayout - > addWidget ( child ) ;
child - > setFixedHeight (
ui - > frame_mapTools - > height ( ) - flowLayout - > contentsMargins ( ) . top ( ) - flowLayout - > contentsMargins ( ) . bottom ( )
) ;
}
delete ui - > frame_mapTools - > layout ( ) ;
ui - > frame_mapTools - > setLayout ( flowLayout ) ;
2020-10-26 03:49:00 +00:00
// Floating QLabel tool-window that displays over the map when the ruler is active
label_MapRulerStatus = new QLabel ( ui - > graphicsView_Map ) ;
label_MapRulerStatus - > setObjectName ( " label_MapRulerStatus " ) ;
label_MapRulerStatus - > setWindowFlags ( Qt : : Tool | Qt : : CustomizeWindowHint | Qt : : FramelessWindowHint ) ;
label_MapRulerStatus - > setFrameShape ( QFrame : : Box ) ;
label_MapRulerStatus - > setMargin ( 3 ) ;
label_MapRulerStatus - > setPalette ( palette ( ) ) ;
label_MapRulerStatus - > setAlignment ( Qt : : AlignCenter ) ;
label_MapRulerStatus - > setTextFormat ( Qt : : PlainText ) ;
label_MapRulerStatus - > setTextInteractionFlags ( Qt : : TextSelectableByMouse ) ;
2018-10-05 23:39:50 +01:00
}
2018-09-27 00:33:08 +01:00
void MainWindow : : initEditor ( ) {
this - > editor = new Editor ( ui ) ;
2021-02-14 14:16:23 +00:00
connect ( this - > editor , & Editor : : objectsChanged , this , & MainWindow : : updateObjects ) ;
connect ( this - > editor , & Editor : : loadMapRequested , this , & MainWindow : : onLoadMapRequested ) ;
connect ( this - > editor , & Editor : : warpEventDoubleClicked , this , & MainWindow : : openWarpMap ) ;
connect ( this - > editor , & Editor : : currentMetatilesSelectionChanged , this , & MainWindow : : currentMetatilesSelectionChanged ) ;
connect ( this - > editor , & Editor : : wildMonDataChanged , this , & MainWindow : : onWildMonDataChanged ) ;
2020-10-26 03:49:00 +00:00
connect ( this - > editor , & Editor : : mapRulerStatusChanged , this , & MainWindow : : onMapRulerStatusChanged ) ;
2021-09-08 22:25:21 +01:00
connect ( this - > editor , & Editor : : editedMapData , this , & MainWindow : : markMapEdited ) ;
2021-11-30 22:24:46 +00:00
connect ( this - > editor , & Editor : : tilesetUpdated , this , & Scripting : : cb_TilesetUpdated ) ;
2020-12-13 09:00:00 +00:00
connect ( ui - > toolButton_Open_Scripts , & QToolButton : : pressed , this - > editor , & Editor : : openMapScripts ) ;
2020-12-01 12:12:32 +00:00
connect ( ui - > actionOpen_Project_in_Text_Editor , & QAction : : triggered , this - > editor , & Editor : : openProjectInTextEditor ) ;
2018-09-27 00:33:08 +01:00
this - > loadUserSettings ( ) ;
2020-07-29 20:51:04 +01:00
undoAction = editor - > editGroup . createUndoAction ( this , tr ( " &Undo " ) ) ;
2020-11-01 12:35:20 +00:00
undoAction - > setObjectName ( " action_Undo " ) ;
2020-07-29 20:51:04 +01:00
undoAction - > setShortcut ( QKeySequence ( " Ctrl+Z " ) ) ;
redoAction = editor - > editGroup . createRedoAction ( this , tr ( " &Redo " ) ) ;
2020-11-01 12:35:20 +00:00
redoAction - > setObjectName ( " action_Redo " ) ;
2020-08-04 02:12:13 +01:00
redoAction - > setShortcuts ( { QKeySequence ( " Ctrl+Y " ) , QKeySequence ( " Ctrl+Shift+Z " ) } ) ;
2020-07-29 20:51:04 +01:00
ui - > menuEdit - > addAction ( undoAction ) ;
ui - > menuEdit - > addAction ( redoAction ) ;
QUndoView * undoView = new QUndoView ( & editor - > editGroup ) ;
undoView - > setWindowTitle ( tr ( " Edit History " ) ) ;
undoView - > setAttribute ( Qt : : WA_QuitOnClose , false ) ;
2020-07-31 18:24:58 +01:00
2020-08-04 02:12:13 +01:00
// Show the EditHistory dialog with Ctrl+E
2020-11-01 12:35:20 +00:00
QAction * showHistory = new QAction ( " Show Edit History... " , this ) ;
showHistory - > setObjectName ( " action_ShowEditHistory " ) ;
2020-08-04 02:12:13 +01:00
showHistory - > setShortcut ( QKeySequence ( " Ctrl+E " ) ) ;
connect ( showHistory , & QAction : : triggered , [ undoView ] ( ) { undoView - > show ( ) ; } ) ;
ui - > menuEdit - > addAction ( showHistory ) ;
2020-07-31 22:12:08 +01:00
// Toggle an asterisk in the window title when the undo state is changed
connect ( & editor - > editGroup , & QUndoGroup : : cleanChanged , this , & MainWindow : : showWindowTitle ) ;
2022-07-19 22:56:12 +01:00
// selecting objects from the spinners
connect ( this - > ui - > spinner_ObjectID , QOverload < int > : : of ( & QSpinBox : : valueChanged ) , [ this ] ( int value ) {
this - > editor - > selectedEventIndexChanged ( value , Event : : Group : : Object ) ;
} ) ;
connect ( this - > ui - > spinner_WarpID , QOverload < int > : : of ( & QSpinBox : : valueChanged ) , [ this ] ( int value ) {
this - > editor - > selectedEventIndexChanged ( value , Event : : Group : : Warp ) ;
} ) ;
connect ( this - > ui - > spinner_TriggerID , QOverload < int > : : of ( & QSpinBox : : valueChanged ) , [ this ] ( int value ) {
this - > editor - > selectedEventIndexChanged ( value , Event : : Group : : Coord ) ;
} ) ;
connect ( this - > ui - > spinner_BgID , QOverload < int > : : of ( & QSpinBox : : valueChanged ) , [ this ] ( int value ) {
this - > editor - > selectedEventIndexChanged ( value , Event : : Group : : Bg ) ;
} ) ;
connect ( this - > ui - > spinner_HealID , QOverload < int > : : of ( & QSpinBox : : valueChanged ) , [ this ] ( int value ) {
this - > editor - > selectedEventIndexChanged ( value , Event : : Group : : Heal ) ;
} ) ;
2018-09-27 00:33:08 +01:00
}
2018-10-05 07:02:40 +01:00
void MainWindow : : initMiscHeapObjects ( ) {
2019-02-26 01:40:46 +00:00
mapIcon = new QIcon ( QStringLiteral ( " :/icons/map.ico " ) ) ;
mapEditedIcon = new QIcon ( QStringLiteral ( " :/icons/map_edited.ico " ) ) ;
mapOpenedIcon = new QIcon ( QStringLiteral ( " :/icons/map_opened.ico " ) ) ;
2018-10-05 07:02:40 +01:00
mapListModel = new QStandardItemModel ;
mapGroupItemsList = new QList < QStandardItem * > ;
mapListProxyModel = new FilterChildrenProxyModel ;
mapListProxyModel - > setSourceModel ( mapListModel ) ;
ui - > mapList - > setModel ( mapListProxyModel ) ;
2018-11-28 01:39:57 +00:00
eventTabObjectWidget = ui - > tab_Objects ;
eventTabWarpWidget = ui - > tab_Warps ;
eventTabTriggerWidget = ui - > tab_Triggers ;
eventTabBGWidget = ui - > tab_BGs ;
eventTabHealspotWidget = ui - > tab_Healspots ;
eventTabMultipleWidget = ui - > tab_Multiple ;
ui - > tabWidget_EventType - > clear ( ) ;
2018-10-05 07:02:40 +01:00
}
void MainWindow : : initMapSortOrder ( ) {
2019-09-11 13:42:06 +01:00
QMenu * mapSortOrderMenu = new QMenu ( this ) ;
2018-10-05 07:02:40 +01:00
QActionGroup * mapSortOrderActionGroup = new QActionGroup ( ui - > toolButton_MapSortOrder ) ;
mapSortOrderMenu - > addAction ( ui - > actionSort_by_Group ) ;
2018-10-05 23:39:50 +01:00
mapSortOrderMenu - > addAction ( ui - > actionSort_by_Area ) ;
2018-10-05 07:02:40 +01:00
mapSortOrderMenu - > addAction ( ui - > actionSort_by_Layout ) ;
ui - > toolButton_MapSortOrder - > setMenu ( mapSortOrderMenu ) ;
mapSortOrderActionGroup - > addAction ( ui - > actionSort_by_Group ) ;
2018-10-05 23:39:50 +01:00
mapSortOrderActionGroup - > addAction ( ui - > actionSort_by_Area ) ;
2018-10-05 07:02:40 +01:00
mapSortOrderActionGroup - > addAction ( ui - > actionSort_by_Layout ) ;
2020-11-13 14:06:03 +00:00
connect ( mapSortOrderActionGroup , & QActionGroup : : triggered , this , & MainWindow : : mapSortOrder_changed ) ;
2018-10-05 07:02:40 +01:00
QAction * sortOrder = ui - > toolButton_MapSortOrder - > menu ( ) - > actions ( ) [ mapSortOrder ] ;
ui - > toolButton_MapSortOrder - > setIcon ( sortOrder - > icon ( ) ) ;
sortOrder - > setChecked ( true ) ;
}
2020-07-31 22:12:08 +01:00
void MainWindow : : showWindowTitle ( ) {
if ( editor - > map ) {
setWindowTitle ( QString ( " %1%2 - %3 " )
. arg ( editor - > map - > hasUnsavedChanges ( ) ? " * " : " " )
. arg ( editor - > map - > name )
. arg ( editor - > project - > getProjectTitle ( ) )
) ;
}
}
2021-09-08 22:25:21 +01:00
void MainWindow : : markMapEdited ( ) {
if ( editor & & editor - > map ) {
editor - > map - > hasUnsavedDataChanges = true ;
showWindowTitle ( ) ;
}
}
2022-03-23 03:49:49 +00:00
void MainWindow : : setWildEncountersUIEnabled ( bool enabled ) {
ui - > actionUse_Encounter_Json - > setChecked ( enabled ) ;
ui - > mainTabBar - > setTabEnabled ( 4 , enabled ) ;
}
2018-12-26 18:20:51 +00:00
void MainWindow : : setProjectSpecificUIVisibility ( )
{
2020-04-21 02:54:16 +01:00
ui - > actionUse_Poryscript - > setChecked ( projectConfig . getUsePoryScript ( ) ) ;
2022-09-01 05:57:31 +01:00
this - > setWildEncountersUIEnabled ( userConfig . getEncounterJsonActive ( ) ) ;
2019-11-02 01:19:39 +00:00
2022-10-26 08:56:46 +01:00
bool hasFlags = projectConfig . getMapAllowFlagsEnabled ( ) ;
ui - > checkBox_AllowRunning - > setVisible ( hasFlags ) ;
ui - > checkBox_AllowBiking - > setVisible ( hasFlags ) ;
ui - > checkBox_AllowEscaping - > setVisible ( hasFlags ) ;
ui - > label_AllowRunning - > setVisible ( hasFlags ) ;
ui - > label_AllowBiking - > setVisible ( hasFlags ) ;
ui - > label_AllowEscaping - > setVisible ( hasFlags ) ;
2020-05-22 22:51:56 +01:00
2022-02-06 02:31:54 +00:00
ui - > newEventToolButton - > newWeatherTriggerAction - > setVisible ( projectConfig . getEventWeatherTriggerEnabled ( ) ) ;
ui - > newEventToolButton - > newSecretBaseAction - > setVisible ( projectConfig . getEventSecretBaseEnabled ( ) ) ;
ui - > newEventToolButton - > newCloneObjectAction - > setVisible ( projectConfig . getEventCloneObjectEnabled ( ) ) ;
bool floorNumEnabled = projectConfig . getFloorNumberEnabled ( ) ;
ui - > spinBox_FloorNumber - > setVisible ( floorNumEnabled ) ;
ui - > label_FloorNumber - > setVisible ( floorNumEnabled ) ;
2018-12-26 18:20:51 +00:00
}
2018-10-05 07:02:40 +01:00
void MainWindow : : mapSortOrder_changed ( QAction * action )
{
QList < QAction * > items = ui - > toolButton_MapSortOrder - > menu ( ) - > actions ( ) ;
int i = 0 ;
for ( ; i < items . count ( ) ; i + + )
{
2018-10-05 23:39:50 +01:00
if ( items [ i ] = = action )
2018-10-05 07:02:40 +01:00
{
break ;
}
}
if ( i ! = mapSortOrder )
{
ui - > toolButton_MapSortOrder - > setIcon ( action - > icon ( ) ) ;
mapSortOrder = static_cast < MapSortOrder > ( i ) ;
2018-12-25 20:41:06 +00:00
porymapConfig . setMapSortOrder ( mapSortOrder ) ;
2018-10-05 07:02:40 +01:00
if ( isProjectOpen ( ) )
{
sortMapList ( ) ;
2020-06-26 00:34:46 +01:00
applyMapListFilter ( ui - > lineEdit_filterBox - > text ( ) ) ;
2018-10-05 07:02:40 +01:00
}
}
}
void MainWindow : : on_lineEdit_filterBox_textChanged ( const QString & arg1 )
{
2020-06-26 00:34:46 +01:00
this - > applyMapListFilter ( arg1 ) ;
}
void MainWindow : : applyMapListFilter ( QString filterText )
{
2021-02-06 00:43:49 +00:00
mapListProxyModel - > setFilterRegularExpression ( QRegularExpression ( filterText , QRegularExpression : : CaseInsensitiveOption ) ) ;
2020-06-26 00:34:46 +01:00
if ( filterText . isEmpty ( ) ) {
2019-01-05 22:38:37 +00:00
ui - > mapList - > collapseAll ( ) ;
} else {
ui - > mapList - > expandToDepth ( 0 ) ;
}
2018-10-05 07:02:40 +01:00
ui - > mapList - > setExpanded ( mapListProxyModel - > mapFromSource ( mapListIndexes . value ( editor - > map - > name ) ) , true ) ;
2019-01-05 22:38:37 +00:00
ui - > mapList - > scrollTo ( mapListProxyModel - > mapFromSource ( mapListIndexes . value ( editor - > map - > name ) ) , QAbstractItemView : : PositionAtCenter ) ;
2018-10-05 07:02:40 +01:00
}
2018-09-27 00:33:08 +01:00
void MainWindow : : loadUserSettings ( ) {
2018-12-25 20:41:06 +00:00
ui - > actionBetter_Cursors - > setChecked ( porymapConfig . getPrettyCursors ( ) ) ;
this - > editor - > settings - > betterCursors = porymapConfig . getPrettyCursors ( ) ;
2019-01-09 15:35:34 +00:00
ui - > actionPlayer_View_Rectangle - > setChecked ( porymapConfig . getShowPlayerView ( ) ) ;
this - > editor - > settings - > playerViewRectEnabled = porymapConfig . getShowPlayerView ( ) ;
ui - > actionCursor_Tile_Outline - > setChecked ( porymapConfig . getShowCursorTile ( ) ) ;
this - > editor - > settings - > cursorTileRectEnabled = porymapConfig . getShowCursorTile ( ) ;
2021-11-08 03:00:20 +00:00
ui - > checkBox_ToggleBorder - > setChecked ( porymapConfig . getShowBorder ( ) ) ;
ui - > checkBox_ToggleGrid - > setChecked ( porymapConfig . getShowGrid ( ) ) ;
2018-12-25 20:41:06 +00:00
mapSortOrder = porymapConfig . getMapSortOrder ( ) ;
2019-01-06 18:53:31 +00:00
ui - > horizontalSlider_CollisionTransparency - > blockSignals ( true ) ;
this - > editor - > collisionOpacity = static_cast < qreal > ( porymapConfig . getCollisionOpacity ( ) ) / 100 ;
ui - > horizontalSlider_CollisionTransparency - > setValue ( porymapConfig . getCollisionOpacity ( ) ) ;
ui - > horizontalSlider_CollisionTransparency - > blockSignals ( false ) ;
2019-02-16 20:32:19 +00:00
ui - > horizontalSlider_MetatileZoom - > blockSignals ( true ) ;
ui - > horizontalSlider_MetatileZoom - > setValue ( porymapConfig . getMetatilesZoom ( ) ) ;
ui - > horizontalSlider_MetatileZoom - > blockSignals ( false ) ;
2020-04-21 02:54:16 +01:00
ui - > actionMonitor_Project_Files - > setChecked ( porymapConfig . getMonitorFiles ( ) ) ;
2022-07-04 21:03:13 +01:00
ui - > actionOpen_Recent_Project_On_Launch - > setChecked ( porymapConfig . getReopenOnLaunch ( ) ) ;
2019-08-14 23:02:00 +01:00
setTheme ( porymapConfig . getTheme ( ) ) ;
2018-09-27 00:33:08 +01:00
}
2019-01-07 23:14:44 +00:00
void MainWindow : : restoreWindowState ( ) {
2020-09-15 19:57:46 +01:00
logInfo ( " Restoring main window geometry from previous session. " ) ;
QMap < QString , QByteArray > geometry = porymapConfig . getMainGeometry ( ) ;
this - > restoreGeometry ( geometry . value ( " main_window_geometry " ) ) ;
this - > restoreState ( geometry . value ( " main_window_state " ) ) ;
2019-01-07 23:14:44 +00:00
this - > ui - > splitter_map - > restoreState ( geometry . value ( " map_splitter_state " ) ) ;
this - > ui - > splitter_main - > restoreState ( geometry . value ( " main_splitter_state " ) ) ;
}
2019-08-14 23:02:00 +01:00
void MainWindow : : setTheme ( QString theme ) {
if ( theme = = " default " ) {
setStyleSheet ( " " ) ;
} else {
QFile File ( QString ( " :/themes/%1.qss " ) . arg ( theme ) ) ;
File . open ( QFile : : ReadOnly ) ;
QString stylesheet = QLatin1String ( File . readAll ( ) ) ;
setStyleSheet ( stylesheet ) ;
}
}
2018-12-20 23:30:35 +00:00
bool MainWindow : : openRecentProject ( ) {
2022-07-04 20:47:03 +01:00
if ( ! porymapConfig . getReopenOnLaunch ( ) )
return false ;
2018-12-25 20:41:06 +00:00
QString default_dir = porymapConfig . getRecentProject ( ) ;
2018-12-21 15:25:28 +00:00
if ( ! default_dir . isNull ( ) & & default_dir . length ( ) > 0 ) {
logInfo ( QString ( " Opening recent project: '%1' " ) . arg ( default_dir ) ) ;
return openProject ( default_dir ) ;
2018-09-27 00:33:08 +01:00
}
2018-12-20 23:30:35 +00:00
2020-12-15 00:06:38 +00:00
return false ;
2018-09-27 00:33:08 +01:00
}
2018-12-20 23:30:35 +00:00
bool MainWindow : : openProject ( QString dir ) {
2018-09-27 00:33:08 +01:00
if ( dir . isNull ( ) ) {
2020-09-13 23:34:18 +01:00
projectOpenFailure = true ;
2018-12-20 23:30:35 +00:00
return false ;
2018-09-27 00:33:08 +01:00
}
2019-01-05 22:38:37 +00:00
QString nativeDir = QDir : : toNativeSeparators ( dir ) ;
this - > statusBar ( ) - > showMessage ( QString ( " Opening project %1 " ) . arg ( nativeDir ) ) ;
2018-09-27 00:33:08 +01:00
2018-12-20 23:30:35 +00:00
bool success = true ;
2022-09-01 05:57:31 +01:00
userConfig . setProjectDir ( dir ) ;
userConfig . load ( ) ;
2018-12-25 21:26:13 +00:00
projectConfig . setProjectDir ( dir ) ;
projectConfig . load ( ) ;
2020-03-31 17:41:15 +01:00
this - > closeSupplementaryWindows ( ) ;
2018-12-26 18:20:51 +00:00
this - > setProjectSpecificUIVisibility ( ) ;
2020-07-02 02:19:08 +01:00
Scripting : : init ( this ) ;
2018-10-05 07:02:40 +01:00
bool already_open = isProjectOpen ( ) & & ( editor - > project - > root = = dir ) ;
2018-09-27 00:33:08 +01:00
if ( ! already_open ) {
2020-04-07 19:20:31 +01:00
editor - > closeProject ( ) ;
2020-04-12 01:39:50 +01:00
editor - > project = new Project ( this ) ;
2021-02-14 14:16:23 +00:00
QObject : : connect ( editor - > project , & Project : : reloadProject , this , & MainWindow : : on_action_Reload_Project_triggered ) ;
QObject : : connect ( editor - > project , & Project : : mapCacheCleared , this , & MainWindow : : onMapCacheCleared ) ;
2022-03-23 03:49:49 +00:00
QObject : : connect ( editor - > project , & Project : : disableWildEncountersUI , [ this ] ( ) { this - > setWildEncountersUIEnabled ( false ) ; } ) ;
2021-02-14 14:16:23 +00:00
QObject : : connect ( editor - > project , & Project : : uncheckMonitorFilesAction , [ this ] ( ) { ui - > actionMonitor_Project_Files - > setChecked ( false ) ; } ) ;
2020-04-21 03:02:14 +01:00
on_actionMonitor_Project_Files_triggered ( porymapConfig . getMonitorFiles ( ) ) ;
2019-05-06 17:42:09 +01:00
editor - > project - > set_root ( dir ) ;
2020-02-12 16:22:40 +00:00
success = loadDataStructures ( )
& & populateMapList ( )
& & setMap ( getDefaultMap ( ) , true ) ;
2018-09-27 00:33:08 +01:00
} else {
2020-04-08 01:25:09 +01:00
QString open_map = editor - > map - > name ;
2020-04-25 22:11:14 +01:00
editor - > project - > fileWatcher . removePaths ( editor - > project - > fileWatcher . files ( ) ) ;
2020-04-08 01:25:09 +01:00
editor - > project - > clearMapCache ( ) ;
editor - > project - > clearTilesetCache ( ) ;
success = loadDataStructures ( ) & & populateMapList ( ) & & setMap ( open_map , true ) ;
2018-09-27 00:33:08 +01:00
}
2022-09-12 18:01:22 +01:00
projectOpenFailure = ! success ;
if ( projectOpenFailure ) {
2019-01-05 22:38:37 +00:00
this - > statusBar ( ) - > showMessage ( QString ( " Failed to open project %1 " ) . arg ( nativeDir ) ) ;
2020-02-12 17:23:28 +00:00
QMessageBox msgBox ( this ) ;
2020-02-12 21:45:21 +00:00
QString errorMsg = QString ( " There was an error opening the project %1. Please see %2 for full error details. \n \n %3 " )
2020-02-12 17:23:28 +00:00
. arg ( dir )
. arg ( getLogPath ( ) )
. arg ( getMostRecentError ( ) ) ;
msgBox . critical ( nullptr , " Error Opening Project " , errorMsg ) ;
2022-09-12 18:01:22 +01:00
return false ;
2018-12-20 23:30:35 +00:00
}
2022-09-12 18:01:22 +01:00
showWindowTitle ( ) ;
this - > statusBar ( ) - > showMessage ( QString ( " Opened project %1 " ) . arg ( nativeDir ) ) ;
prefab . initPrefabUI (
editor - > metatile_selector_item ,
ui - > scrollAreaWidgetContents_Prefabs ,
ui - > label_prefabHelp ,
editor - > map ) ;
Scripting : : cb_ProjectOpened ( dir ) ;
return true ;
2018-09-27 00:33:08 +01:00
}
2018-10-05 07:02:40 +01:00
bool MainWindow : : isProjectOpen ( ) {
2020-09-13 23:34:18 +01:00
return ! projectOpenFailure & & editor & & editor - > project ;
2018-10-05 07:02:40 +01:00
}
2018-09-27 00:33:08 +01:00
QString MainWindow : : getDefaultMap ( ) {
if ( editor & & editor - > project ) {
QList < QStringList > names = editor - > project - > groupedMapNames ;
if ( ! names . isEmpty ( ) ) {
2022-09-01 05:57:31 +01:00
QString recentMap = userConfig . getRecentMap ( ) ;
2018-12-21 15:25:28 +00:00
if ( ! recentMap . isNull ( ) & & recentMap . length ( ) > 0 ) {
for ( int i = 0 ; i < names . length ( ) ; i + + ) {
if ( names . value ( i ) . contains ( recentMap ) ) {
return recentMap ;
2018-09-27 00:33:08 +01:00
}
}
}
// Failing that, just get the first map in the list.
for ( int i = 0 ; i < names . length ( ) ; i + + ) {
QStringList list = names . value ( i ) ;
if ( list . length ( ) ) {
return list . value ( 0 ) ;
}
}
}
}
return QString ( ) ;
}
QString MainWindow : : getExistingDirectory ( QString dir ) {
return QFileDialog : : getExistingDirectory ( this , " Open Directory " , dir , QFileDialog : : ShowDirsOnly | QFileDialog : : DontResolveSymlinks ) ;
}
void MainWindow : : on_action_Open_Project_triggered ( )
{
QString recent = " . " ;
2022-09-01 05:57:31 +01:00
if ( ! userConfig . getRecentMap ( ) . isEmpty ( ) ) {
recent = userConfig . getRecentMap ( ) ;
2018-09-27 00:33:08 +01:00
}
QString dir = getExistingDirectory ( recent ) ;
if ( ! dir . isEmpty ( ) ) {
2020-05-11 22:12:37 +01:00
if ( this - > editor & & this - > editor - > project ) {
Scripting : : cb_ProjectClosed ( this - > editor - > project - > root ) ;
2022-09-05 02:17:50 +01:00
this - > ui - > graphicsView_Map - > clearOverlayMap ( ) ;
2020-05-11 22:12:37 +01:00
}
2018-12-25 20:41:06 +00:00
porymapConfig . setRecentProject ( dir ) ;
2020-09-13 23:34:18 +01:00
setWindowDisabled ( ! openProject ( dir ) ) ;
2018-09-27 00:33:08 +01:00
}
}
2020-04-08 01:25:09 +01:00
void MainWindow : : on_action_Reload_Project_triggered ( ) {
// TODO: when undo history is complete show only if has unsaved changes
QMessageBox warning ( this ) ;
warning . setText ( " WARNING " ) ;
warning . setInformativeText ( " Reloading this project will discard any unsaved changes. " ) ;
warning . setStandardButtons ( QMessageBox : : Ok | QMessageBox : : Cancel ) ;
2022-10-25 22:40:40 +01:00
warning . setDefaultButton ( QMessageBox : : Cancel ) ;
2020-04-08 01:25:09 +01:00
warning . setIcon ( QMessageBox : : Warning ) ;
if ( warning . exec ( ) = = QMessageBox : : Ok ) {
openProject ( editor - > project - > root ) ;
}
}
2018-12-20 23:30:35 +00:00
bool MainWindow : : setMap ( QString map_name , bool scrollTreeView ) {
logInfo ( QString ( " Setting map to '%1' " ) . arg ( map_name ) ) ;
2020-02-12 16:22:40 +00:00
if ( map_name . isEmpty ( ) ) {
2018-12-20 23:30:35 +00:00
return false ;
}
if ( ! editor - > setMap ( map_name ) ) {
2020-02-12 17:23:28 +00:00
logWarn ( QString ( " Failed to set map to '%1' " ) . arg ( map_name ) ) ;
2018-12-20 23:30:35 +00:00
return false ;
2018-09-27 00:33:08 +01:00
}
2018-12-20 23:30:35 +00:00
2018-10-03 03:46:08 +01:00
if ( editor - > map ! = nullptr & & ! editor - > map - > name . isNull ( ) ) {
2018-10-05 07:02:40 +01:00
ui - > mapList - > setExpanded ( mapListProxyModel - > mapFromSource ( mapListIndexes . value ( editor - > map - > name ) ) , false ) ;
2018-10-03 03:46:08 +01:00
}
2018-12-20 23:30:35 +00:00
2020-05-21 00:30:17 +01:00
refreshMapScene ( ) ;
2018-09-27 00:33:08 +01:00
displayMapProperties ( ) ;
2018-09-29 15:22:50 +01:00
if ( scrollTreeView ) {
2018-10-05 17:23:40 +01:00
// Make sure we clear the filter first so we actually have a scroll target
2021-02-06 00:43:49 +00:00
mapListProxyModel - > setFilterRegularExpression ( QString ( ) ) ;
2018-10-05 07:02:40 +01:00
ui - > mapList - > setCurrentIndex ( mapListProxyModel - > mapFromSource ( mapListIndexes . value ( map_name ) ) ) ;
2018-09-29 15:22:50 +01:00
ui - > mapList - > scrollTo ( ui - > mapList - > currentIndex ( ) , QAbstractItemView : : PositionAtCenter ) ;
}
2018-10-05 17:23:40 +01:00
ui - > mapList - > setExpanded ( mapListProxyModel - > mapFromSource ( mapListIndexes . value ( map_name ) ) , true ) ;
2020-07-31 22:12:08 +01:00
showWindowTitle ( ) ;
2018-09-27 00:33:08 +01:00
2021-02-14 14:16:23 +00:00
connect ( editor - > map , & Map : : mapChanged , this , & MainWindow : : onMapChanged ) ;
connect ( editor - > map , & Map : : mapNeedsRedrawing , this , & MainWindow : : onMapNeedsRedrawing ) ;
2022-09-28 05:21:01 +01:00
connect ( editor - > map , & Map : : modified , [ this ] ( ) { this - > markMapEdited ( ) ; } ) ;
2018-09-27 00:33:08 +01:00
setRecentMap ( map_name ) ;
updateMapList ( ) ;
2020-05-02 22:25:35 +01:00
Scripting : : cb_MapOpened ( map_name ) ;
2022-09-10 02:09:28 +01:00
prefab . updatePrefabUi ( editor - > map ) ;
2020-07-02 02:19:08 +01:00
updateTilesetEditor ( ) ;
2018-12-20 23:30:35 +00:00
return true ;
2018-09-27 00:33:08 +01:00
}
void MainWindow : : redrawMapScene ( )
{
2020-02-12 16:22:40 +00:00
if ( ! editor - > displayMap ( ) )
return ;
2020-05-21 00:30:17 +01:00
this - > refreshMapScene ( ) ;
}
void MainWindow : : refreshMapScene ( )
{
2021-12-13 16:41:46 +00:00
on_mainTabBar_tabBarClicked ( ui - > mainTabBar - > currentIndex ( ) ) ;
2018-09-27 00:33:08 +01:00
ui - > graphicsView_Map - > setScene ( editor - > scene ) ;
ui - > graphicsView_Map - > setSceneRect ( editor - > scene - > sceneRect ( ) ) ;
2019-11-02 01:19:39 +00:00
ui - > graphicsView_Map - > editor = editor ;
2018-09-27 00:33:08 +01:00
ui - > graphicsView_Connections - > setScene ( editor - > scene ) ;
ui - > graphicsView_Connections - > setSceneRect ( editor - > scene - > sceneRect ( ) ) ;
ui - > graphicsView_Metatiles - > setScene ( editor - > scene_metatiles ) ;
//ui->graphicsView_Metatiles->setSceneRect(editor->scene_metatiles->sceneRect());
ui - > graphicsView_Metatiles - > setFixedSize ( editor - > metatile_selector_item - > pixmap ( ) . width ( ) + 2 , editor - > metatile_selector_item - > pixmap ( ) . height ( ) + 2 ) ;
ui - > graphicsView_BorderMetatile - > setScene ( editor - > scene_selected_border_metatiles ) ;
ui - > graphicsView_BorderMetatile - > setFixedSize ( editor - > selected_border_metatiles_item - > pixmap ( ) . width ( ) + 2 , editor - > selected_border_metatiles_item - > pixmap ( ) . height ( ) + 2 ) ;
ui - > graphicsView_currentMetatileSelection - > setScene ( editor - > scene_current_metatile_selection ) ;
2020-08-16 00:30:46 +01:00
ui - > graphicsView_currentMetatileSelection - > setFixedSize ( editor - > current_metatile_selection_item - > pixmap ( ) . width ( ) + 2 , editor - > current_metatile_selection_item - > pixmap ( ) . height ( ) + 2 ) ;
2018-09-27 00:33:08 +01:00
ui - > graphicsView_Collision - > setScene ( editor - > scene_collision_metatiles ) ;
//ui->graphicsView_Collision->setSceneRect(editor->scene_collision_metatiles->sceneRect());
ui - > graphicsView_Collision - > setFixedSize ( editor - > movement_permissions_selector_item - > pixmap ( ) . width ( ) + 2 , editor - > movement_permissions_selector_item - > pixmap ( ) . height ( ) + 2 ) ;
2019-02-16 20:32:19 +00:00
on_horizontalSlider_MetatileZoom_valueChanged ( ui - > horizontalSlider_MetatileZoom - > value ( ) ) ;
2018-09-27 00:33:08 +01:00
}
2022-07-19 22:56:12 +01:00
void MainWindow : : openWarpMap ( QString map_name , int event_id , Event : : Group event_group ) {
2022-10-18 18:44:45 +01:00
// Can't warp to dynamic maps
if ( map_name = = DYNAMIC_MAP_NAME )
return ;
2018-09-27 00:33:08 +01:00
// Ensure valid destination map name.
2021-02-15 09:21:41 +00:00
if ( ! editor - > project - > mapNames . contains ( map_name ) ) {
2022-02-07 14:28:59 +00:00
logError ( QString ( " Invalid map name '%1' " ) . arg ( map_name ) ) ;
2018-09-27 00:33:08 +01:00
return ;
}
2022-02-07 14:28:59 +00:00
// Open the destination map.
2018-12-20 23:30:35 +00:00
if ( ! setMap ( map_name , true ) ) {
2020-02-12 17:23:28 +00:00
QMessageBox msgBox ( this ) ;
2020-02-12 21:45:21 +00:00
QString errorMsg = QString ( " There was an error opening map %1. Please see %2 for full error details. \n \n %3 " )
2020-02-12 17:23:28 +00:00
. arg ( map_name )
. arg ( getLogPath ( ) )
. arg ( getMostRecentError ( ) ) ;
msgBox . critical ( nullptr , " Error Opening Map " , errorMsg ) ;
2018-12-20 23:30:35 +00:00
return ;
}
2022-02-07 14:28:59 +00:00
// Select the target event.
2022-10-18 18:44:45 +01:00
int index = event_id - Event : : getIndexOffset ( event_group ) ;
2022-02-07 14:28:59 +00:00
QList < Event * > events = editor - > map - > events [ event_group ] ;
2022-10-18 18:44:45 +01:00
if ( index < events . length ( ) & & index > = 0 ) {
Event * event = events . at ( index ) ;
2020-08-07 00:46:23 +01:00
for ( DraggablePixmapItem * item : editor - > getObjects ( ) ) {
2022-02-07 14:28:59 +00:00
if ( item - > event = = event ) {
2018-09-27 00:33:08 +01:00
editor - > selected_events - > clear ( ) ;
editor - > selected_events - > append ( item ) ;
editor - > updateSelectedEvents ( ) ;
}
}
2022-10-18 18:44:45 +01:00
} else {
// Can still warp to this map, but can't select the specified event
logWarn ( QString ( " %1 %2 doesn't exist on map '%3' " ) . arg ( Event : : eventGroupToString ( event_group ) ) . arg ( event_id ) . arg ( map_name ) ) ;
2018-09-27 00:33:08 +01:00
}
}
2018-12-21 15:25:28 +00:00
void MainWindow : : setRecentMap ( QString mapName ) {
2022-09-01 05:57:31 +01:00
userConfig . setRecentMap ( mapName ) ;
2018-09-27 00:33:08 +01:00
}
void MainWindow : : displayMapProperties ( ) {
2021-09-08 03:40:07 +01:00
// Block signals to the comboboxes while they are being modified
const QSignalBlocker blocker1 ( ui - > comboBox_Song ) ;
const QSignalBlocker blocker2 ( ui - > comboBox_Location ) ;
const QSignalBlocker blocker3 ( ui - > comboBox_PrimaryTileset ) ;
const QSignalBlocker blocker4 ( ui - > comboBox_SecondaryTileset ) ;
const QSignalBlocker blocker5 ( ui - > comboBox_Weather ) ;
const QSignalBlocker blocker6 ( ui - > comboBox_BattleScene ) ;
const QSignalBlocker blocker7 ( ui - > comboBox_Type ) ;
const QSignalBlocker blocker8 ( ui - > checkBox_Visibility ) ;
const QSignalBlocker blocker9 ( ui - > checkBox_ShowLocation ) ;
const QSignalBlocker blockerA ( ui - > checkBox_AllowRunning ) ;
const QSignalBlocker blockerB ( ui - > checkBox_AllowBiking ) ;
const QSignalBlocker blockerC ( ui - > spinBox_FloorNumber ) ;
2022-10-14 23:11:11 +01:00
const QSignalBlocker blockerD ( ui - > checkBox_AllowEscaping ) ;
2021-09-08 03:40:07 +01:00
2018-09-27 00:33:08 +01:00
ui - > checkBox_Visibility - > setChecked ( false ) ;
ui - > checkBox_ShowLocation - > setChecked ( false ) ;
2018-12-26 18:20:51 +00:00
ui - > checkBox_AllowRunning - > setChecked ( false ) ;
ui - > checkBox_AllowBiking - > setChecked ( false ) ;
2022-10-14 23:11:11 +01:00
ui - > checkBox_AllowEscaping - > setChecked ( false ) ;
2018-09-27 00:33:08 +01:00
if ( ! editor | | ! editor - > map | | ! editor - > project ) {
ui - > frame_3 - > setEnabled ( false ) ;
return ;
}
2020-05-21 01:21:18 +01:00
2018-09-27 00:33:08 +01:00
ui - > frame_3 - > setEnabled ( true ) ;
Map * map = editor - > map ;
2020-05-21 01:21:18 +01:00
ui - > comboBox_PrimaryTileset - > blockSignals ( true ) ;
ui - > comboBox_SecondaryTileset - > blockSignals ( true ) ;
2018-09-27 00:33:08 +01:00
ui - > comboBox_PrimaryTileset - > setCurrentText ( map - > layout - > tileset_primary_label ) ;
ui - > comboBox_SecondaryTileset - > setCurrentText ( map - > layout - > tileset_secondary_label ) ;
2020-05-21 01:21:18 +01:00
ui - > comboBox_PrimaryTileset - > blockSignals ( false ) ;
ui - > comboBox_SecondaryTileset - > blockSignals ( false ) ;
ui - > comboBox_Song - > setCurrentText ( map - > song ) ;
ui - > comboBox_Location - > setCurrentText ( map - > location ) ;
2022-10-14 23:11:11 +01:00
ui - > checkBox_Visibility - > setChecked ( map - > requiresFlash ) ;
2018-09-27 00:33:08 +01:00
ui - > comboBox_Weather - > setCurrentText ( map - > weather ) ;
ui - > comboBox_Type - > setCurrentText ( map - > type ) ;
ui - > comboBox_BattleScene - > setCurrentText ( map - > battle_scene ) ;
2022-10-14 23:11:11 +01:00
ui - > checkBox_ShowLocation - > setChecked ( map - > show_location ) ;
2022-10-26 08:56:46 +01:00
ui - > checkBox_AllowRunning - > setChecked ( map - > allowRunning ) ;
ui - > checkBox_AllowBiking - > setChecked ( map - > allowBiking ) ;
ui - > checkBox_AllowEscaping - > setChecked ( map - > allowEscaping ) ;
2020-03-11 05:52:00 +00:00
ui - > spinBox_FloorNumber - > setValue ( map - > floorNumber ) ;
2019-02-03 16:38:45 +00:00
// Custom fields table.
ui - > tableWidget_CustomHeaderFields - > blockSignals ( true ) ;
ui - > tableWidget_CustomHeaderFields - > setRowCount ( 0 ) ;
2022-10-16 03:32:05 +01:00
for ( auto it = map - > customHeaders . begin ( ) ; it ! = map - > customHeaders . end ( ) ; it + + )
2022-10-19 00:52:35 +01:00
CustomAttributesTable : : addAttribute ( ui - > tableWidget_CustomHeaderFields , it . key ( ) , it . value ( ) ) ;
2022-10-15 08:22:51 +01:00
ui - > tableWidget_CustomHeaderFields - > horizontalHeader ( ) - > setSectionResizeMode ( QHeaderView : : ResizeToContents ) ;
2019-02-03 16:38:45 +00:00
ui - > tableWidget_CustomHeaderFields - > blockSignals ( false ) ;
2018-09-27 00:33:08 +01:00
}
2019-09-21 21:59:14 +01:00
void MainWindow : : on_comboBox_Song_currentTextChanged ( const QString & song )
2018-09-27 00:33:08 +01:00
{
if ( editor & & editor - > map ) {
editor - > map - > song = song ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2018-09-27 00:33:08 +01:00
}
}
2019-09-21 21:59:14 +01:00
void MainWindow : : on_comboBox_Location_currentTextChanged ( const QString & location )
2018-09-27 00:33:08 +01:00
{
if ( editor & & editor - > map ) {
editor - > map - > location = location ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2018-09-27 00:33:08 +01:00
}
}
2019-09-21 21:59:14 +01:00
void MainWindow : : on_comboBox_Weather_currentTextChanged ( const QString & weather )
2018-09-27 00:33:08 +01:00
{
if ( editor & & editor - > map ) {
editor - > map - > weather = weather ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2018-09-27 00:33:08 +01:00
}
}
2019-09-21 21:59:14 +01:00
void MainWindow : : on_comboBox_Type_currentTextChanged ( const QString & type )
2018-09-27 00:33:08 +01:00
{
if ( editor & & editor - > map ) {
editor - > map - > type = type ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2018-09-27 00:33:08 +01:00
}
}
2019-09-21 21:59:14 +01:00
void MainWindow : : on_comboBox_BattleScene_currentTextChanged ( const QString & battle_scene )
2018-09-27 00:33:08 +01:00
{
if ( editor & & editor - > map ) {
editor - > map - > battle_scene = battle_scene ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2018-09-27 00:33:08 +01:00
}
}
2022-01-01 21:03:43 +00:00
void MainWindow : : on_checkBox_Visibility_stateChanged ( int selected )
2018-09-27 00:33:08 +01:00
{
if ( editor & & editor - > map ) {
2022-10-14 23:11:11 +01:00
editor - > map - > requiresFlash = ( selected = = Qt : : Checked ) ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2018-09-27 00:33:08 +01:00
}
}
2022-01-01 21:03:43 +00:00
void MainWindow : : on_checkBox_ShowLocation_stateChanged ( int selected )
2018-09-27 00:33:08 +01:00
{
if ( editor & & editor - > map ) {
2022-10-14 23:11:11 +01:00
editor - > map - > show_location = ( selected = = Qt : : Checked ) ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2018-09-27 00:33:08 +01:00
}
}
2022-01-01 21:03:43 +00:00
void MainWindow : : on_checkBox_AllowRunning_stateChanged ( int selected )
2018-12-26 18:20:51 +00:00
{
if ( editor & & editor - > map ) {
2022-10-14 23:11:11 +01:00
editor - > map - > allowRunning = ( selected = = Qt : : Checked ) ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2018-12-26 18:20:51 +00:00
}
}
2022-01-01 21:03:43 +00:00
void MainWindow : : on_checkBox_AllowBiking_stateChanged ( int selected )
2018-12-26 18:20:51 +00:00
{
if ( editor & & editor - > map ) {
2022-10-14 23:11:11 +01:00
editor - > map - > allowBiking = ( selected = = Qt : : Checked ) ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2018-12-26 18:20:51 +00:00
}
}
2022-10-14 23:11:11 +01:00
void MainWindow : : on_checkBox_AllowEscaping_stateChanged ( int selected )
2018-12-26 18:20:51 +00:00
{
if ( editor & & editor - > map ) {
2022-10-14 23:11:11 +01:00
editor - > map - > allowEscaping = ( selected = = Qt : : Checked ) ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2018-12-26 18:20:51 +00:00
}
}
2020-03-11 21:06:26 +00:00
void MainWindow : : on_spinBox_FloorNumber_valueChanged ( int offset )
{
if ( editor & & editor - > map ) {
editor - > map - > floorNumber = offset ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2020-03-11 21:06:26 +00:00
}
}
2020-02-12 00:34:08 +00:00
bool MainWindow : : loadDataStructures ( ) {
2018-09-27 00:33:08 +01:00
Project * project = editor - > project ;
2020-02-12 14:12:12 +00:00
bool success = project - > readMapLayouts ( )
2020-02-12 15:13:58 +00:00
& & project - > readRegionMapSections ( )
& & project - > readItemNames ( )
& & project - > readFlagNames ( )
& & project - > readVarNames ( )
& & project - > readMovementTypes ( )
& & project - > readInitialFacingDirections ( )
& & project - > readMapTypes ( )
& & project - > readMapBattleScenes ( )
& & project - > readWeatherNames ( )
2020-05-22 22:51:56 +01:00
& & project - > readCoordEventWeatherNames ( )
& & project - > readSecretBaseIds ( )
2020-02-12 15:13:58 +00:00
& & project - > readBgEventFacingDirections ( )
2020-03-27 14:51:57 +00:00
& & project - > readTrainerTypes ( )
2020-02-12 15:13:58 +00:00
& & project - > readMetatileBehaviors ( )
& & project - > readTilesetProperties ( )
2022-09-28 01:17:55 +01:00
& & project - > readTilesetLabels ( )
2020-05-16 23:52:46 +01:00
& & project - > readMaxMapDataSize ( )
2020-02-12 15:13:58 +00:00
& & project - > readHealLocations ( )
& & project - > readMiscellaneousConstants ( )
& & project - > readSpeciesIconPaths ( )
2021-01-30 03:05:40 +00:00
& & project - > readWildMonData ( )
2022-01-21 20:22:20 +00:00
& & project - > readEventScriptLabels ( )
& & project - > readObjEventGfxConstants ( )
2022-01-24 22:17:31 +00:00
& & project - > readEventGraphics ( )
2022-01-21 20:22:20 +00:00
& & project - > readSongNames ( ) ;
2021-01-30 03:05:40 +00:00
2022-10-27 12:52:07 +01:00
Metatile : : setCustomLayout ( project ) ;
2022-09-05 04:41:42 +01:00
Scripting : : populateGlobalObject ( this ) ;
2020-04-07 19:20:31 +01:00
return success & & loadProjectCombos ( ) ;
}
2019-09-21 21:59:14 +01:00
2020-04-07 19:20:31 +01:00
bool MainWindow : : loadProjectCombos ( ) {
2019-09-21 21:59:14 +01:00
// set up project ui comboboxes
2020-04-07 19:20:31 +01:00
Project * project = editor - > project ;
// Block signals to the comboboxes while they are being modified
const QSignalBlocker blocker1 ( ui - > comboBox_Song ) ;
const QSignalBlocker blocker2 ( ui - > comboBox_Location ) ;
const QSignalBlocker blocker3 ( ui - > comboBox_PrimaryTileset ) ;
const QSignalBlocker blocker4 ( ui - > comboBox_SecondaryTileset ) ;
const QSignalBlocker blocker5 ( ui - > comboBox_Weather ) ;
const QSignalBlocker blocker6 ( ui - > comboBox_BattleScene ) ;
const QSignalBlocker blocker7 ( ui - > comboBox_Type ) ;
2020-02-12 15:13:58 +00:00
ui - > comboBox_Song - > clear ( ) ;
2022-01-21 20:22:20 +00:00
ui - > comboBox_Song - > addItems ( project - > songNames ) ;
2020-02-12 15:13:58 +00:00
ui - > comboBox_Location - > clear ( ) ;
2019-09-21 21:59:14 +01:00
ui - > comboBox_Location - > addItems ( project - > mapSectionValueToName . values ( ) ) ;
2020-02-12 15:13:58 +00:00
ui - > comboBox_PrimaryTileset - > clear ( ) ;
2022-10-23 23:59:59 +01:00
ui - > comboBox_PrimaryTileset - > addItems ( project - > primaryTilesetLabels ) ;
2020-02-12 15:13:58 +00:00
ui - > comboBox_SecondaryTileset - > clear ( ) ;
2022-10-23 23:59:59 +01:00
ui - > comboBox_SecondaryTileset - > addItems ( project - > secondaryTilesetLabels ) ;
2020-02-12 15:13:58 +00:00
ui - > comboBox_Weather - > clear ( ) ;
2021-02-15 16:33:30 +00:00
ui - > comboBox_Weather - > addItems ( project - > weatherNames ) ;
2020-02-12 15:13:58 +00:00
ui - > comboBox_BattleScene - > clear ( ) ;
2021-02-15 16:33:30 +00:00
ui - > comboBox_BattleScene - > addItems ( project - > mapBattleScenes ) ;
2020-02-12 15:13:58 +00:00
ui - > comboBox_Type - > clear ( ) ;
2021-02-15 16:33:30 +00:00
ui - > comboBox_Type - > addItems ( project - > mapTypes ) ;
2020-04-07 19:20:31 +01:00
2020-02-12 00:34:08 +00:00
return true ;
2018-09-27 00:33:08 +01:00
}
2020-02-12 16:22:40 +00:00
bool MainWindow : : populateMapList ( ) {
bool success = editor - > project - > readMapGroups ( ) ;
if ( success ) {
sortMapList ( ) ;
}
return success ;
2018-10-05 07:02:40 +01:00
}
void MainWindow : : sortMapList ( ) {
2018-09-27 00:33:08 +01:00
Project * project = editor - > project ;
QIcon mapFolderIcon ;
mapFolderIcon . addFile ( QStringLiteral ( " :/icons/folder_closed_map.ico " ) , QSize ( ) , QIcon : : Normal , QIcon : : Off ) ;
mapFolderIcon . addFile ( QStringLiteral ( " :/icons/folder_map.ico " ) , QSize ( ) , QIcon : : Normal , QIcon : : On ) ;
QIcon folderIcon ;
folderIcon . addFile ( QStringLiteral ( " :/icons/folder_closed.ico " ) , QSize ( ) , QIcon : : Normal , QIcon : : Off ) ;
2018-10-05 07:02:40 +01:00
//folderIcon.addFile(QStringLiteral(":/icons/folder.ico"), QSize(), QIcon::Normal, QIcon::On);
ui - > mapList - > setUpdatesEnabled ( false ) ;
mapListModel - > clear ( ) ;
mapGroupItemsList - > clear ( ) ;
QStandardItem * root = mapListModel - > invisibleRootItem ( ) ;
switch ( mapSortOrder )
{
case MapSortOrder : : Group :
2021-02-15 09:21:41 +00:00
for ( int i = 0 ; i < project - > groupNames . length ( ) ; i + + ) {
QString group_name = project - > groupNames . value ( i ) ;
2018-10-05 07:02:40 +01:00
QStandardItem * group = new QStandardItem ;
group - > setText ( group_name ) ;
group - > setIcon ( mapFolderIcon ) ;
group - > setEditable ( false ) ;
group - > setData ( group_name , Qt : : UserRole ) ;
group - > setData ( " map_group " , MapListUserRoles : : TypeRole ) ;
group - > setData ( i , MapListUserRoles : : GroupRole ) ;
root - > appendRow ( group ) ;
mapGroupItemsList - > append ( group ) ;
QStringList names = project - > groupedMapNames . value ( i ) ;
for ( int j = 0 ; j < names . length ( ) ; j + + ) {
QString map_name = names . value ( j ) ;
QStandardItem * map = createMapItem ( map_name , i , j ) ;
group - > appendRow ( map ) ;
mapListIndexes . insert ( map_name , map - > index ( ) ) ;
}
}
break ;
2018-12-21 15:25:28 +00:00
case MapSortOrder : : Area :
2018-10-05 07:02:40 +01:00
{
QMap < QString , int > mapsecToGroupNum ;
2019-02-25 18:31:34 +00:00
for ( int i = 0 ; i < project - > mapSectionNameToValue . size ( ) ; i + + ) {
QString mapsec_name = project - > mapSectionValueToName . value ( i ) ;
2018-10-05 07:02:40 +01:00
QStandardItem * mapsec = new QStandardItem ;
mapsec - > setText ( mapsec_name ) ;
mapsec - > setIcon ( folderIcon ) ;
mapsec - > setEditable ( false ) ;
mapsec - > setData ( mapsec_name , Qt : : UserRole ) ;
mapsec - > setData ( " map_sec " , MapListUserRoles : : TypeRole ) ;
mapsec - > setData ( i , MapListUserRoles : : GroupRole ) ;
root - > appendRow ( mapsec ) ;
mapGroupItemsList - > append ( mapsec ) ;
mapsecToGroupNum . insert ( mapsec_name , i ) ;
}
2021-02-15 09:21:41 +00:00
for ( int i = 0 ; i < project - > groupNames . length ( ) ; i + + ) {
2018-10-05 07:02:40 +01:00
QStringList names = project - > groupedMapNames . value ( i ) ;
for ( int j = 0 ; j < names . length ( ) ; j + + ) {
QString map_name = names . value ( j ) ;
QStandardItem * map = createMapItem ( map_name , i , j ) ;
QString location = project - > readMapLocation ( map_name ) ;
QStandardItem * mapsecItem = mapGroupItemsList - > at ( mapsecToGroupNum [ location ] ) ;
mapsecItem - > setIcon ( mapFolderIcon ) ;
mapsecItem - > appendRow ( map ) ;
mapListIndexes . insert ( map_name , map - > index ( ) ) ;
}
}
break ;
}
case MapSortOrder : : Layout :
{
2019-02-01 17:43:25 +00:00
QMap < QString , int > layoutIndices ;
2018-10-05 07:02:40 +01:00
for ( int i = 0 ; i < project - > mapLayoutsTable . length ( ) ; i + + ) {
2019-02-01 17:43:25 +00:00
QString layoutId = project - > mapLayoutsTable . value ( i ) ;
MapLayout * layout = project - > mapLayouts . value ( layoutId ) ;
QStandardItem * layoutItem = new QStandardItem ;
layoutItem - > setText ( layout - > name ) ;
layoutItem - > setIcon ( folderIcon ) ;
layoutItem - > setEditable ( false ) ;
layoutItem - > setData ( layout - > name , Qt : : UserRole ) ;
layoutItem - > setData ( " map_layout " , MapListUserRoles : : TypeRole ) ;
layoutItem - > setData ( layout - > id , MapListUserRoles : : TypeRole2 ) ;
layoutItem - > setData ( i , MapListUserRoles : : GroupRole ) ;
root - > appendRow ( layoutItem ) ;
mapGroupItemsList - > append ( layoutItem ) ;
layoutIndices [ layoutId ] = i ;
2018-10-05 07:02:40 +01:00
}
2021-02-15 09:21:41 +00:00
for ( int i = 0 ; i < project - > groupNames . length ( ) ; i + + ) {
2018-10-05 07:02:40 +01:00
QStringList names = project - > groupedMapNames . value ( i ) ;
for ( int j = 0 ; j < names . length ( ) ; j + + ) {
QString map_name = names . value ( j ) ;
QStandardItem * map = createMapItem ( map_name , i , j ) ;
QString layoutId = project - > readMapLayoutId ( map_name ) ;
2019-02-01 17:43:25 +00:00
QStandardItem * layoutItem = mapGroupItemsList - > at ( layoutIndices . value ( layoutId ) ) ;
2018-10-05 07:02:40 +01:00
layoutItem - > setIcon ( mapFolderIcon ) ;
layoutItem - > appendRow ( map ) ;
mapListIndexes . insert ( map_name , map - > index ( ) ) ;
}
}
break ;
2018-09-27 00:33:08 +01:00
}
}
ui - > mapList - > setUpdatesEnabled ( true ) ;
ui - > mapList - > repaint ( ) ;
2019-04-06 22:58:18 +01:00
updateMapList ( ) ;
2018-09-27 00:33:08 +01:00
}
QStandardItem * MainWindow : : createMapItem ( QString mapName , int groupNum , int inGroupNum ) {
QStandardItem * map = new QStandardItem ;
map - > setText ( QString ( " [%1.%2] " ) . arg ( groupNum ) . arg ( inGroupNum , 2 , 10 , QLatin1Char ( ' 0 ' ) ) + mapName ) ;
map - > setIcon ( * mapIcon ) ;
map - > setEditable ( false ) ;
map - > setData ( mapName , Qt : : UserRole ) ;
map - > setData ( " map_name " , MapListUserRoles : : TypeRole ) ;
return map ;
}
void MainWindow : : onOpenMapListContextMenu ( const QPoint & point )
{
2018-10-05 07:02:40 +01:00
QModelIndex index = mapListProxyModel - > mapToSource ( ui - > mapList - > indexAt ( point ) ) ;
2018-09-27 00:33:08 +01:00
if ( ! index . isValid ( ) ) {
return ;
}
QStandardItem * selectedItem = mapListModel - > itemFromIndex ( index ) ;
QVariant itemType = selectedItem - > data ( MapListUserRoles : : TypeRole ) ;
if ( ! itemType . isValid ( ) ) {
return ;
}
// Build custom context menu depending on which type of item was selected (map group, map name, etc.)
if ( itemType = = " map_group " ) {
QString groupName = selectedItem - > data ( Qt : : UserRole ) . toString ( ) ;
int groupNum = selectedItem - > data ( MapListUserRoles : : GroupRole ) . toInt ( ) ;
2018-10-05 23:39:50 +01:00
QMenu * menu = new QMenu ( this ) ;
2018-09-27 00:33:08 +01:00
QActionGroup * actions = new QActionGroup ( menu ) ;
actions - > addAction ( menu - > addAction ( " Add New Map to Group " ) ) - > setData ( groupNum ) ;
2021-02-14 14:16:23 +00:00
connect ( actions , & QActionGroup : : triggered , this , & MainWindow : : onAddNewMapToGroupClick ) ;
2018-09-27 00:33:08 +01:00
menu - > exec ( QCursor : : pos ( ) ) ;
2019-01-07 23:14:44 +00:00
} else if ( itemType = = " map_sec " ) {
QString secName = selectedItem - > data ( Qt : : UserRole ) . toString ( ) ;
QMenu * menu = new QMenu ( this ) ;
QActionGroup * actions = new QActionGroup ( menu ) ;
actions - > addAction ( menu - > addAction ( " Add New Map to Area " ) ) - > setData ( secName ) ;
2021-02-14 14:16:23 +00:00
connect ( actions , & QActionGroup : : triggered , this , & MainWindow : : onAddNewMapToAreaClick ) ;
2019-01-07 23:14:44 +00:00
menu - > exec ( QCursor : : pos ( ) ) ;
} else if ( itemType = = " map_layout " ) {
2019-02-01 17:43:25 +00:00
QString layoutId = selectedItem - > data ( MapListUserRoles : : TypeRole2 ) . toString ( ) ;
2019-01-07 23:14:44 +00:00
QMenu * menu = new QMenu ( this ) ;
QActionGroup * actions = new QActionGroup ( menu ) ;
2019-02-01 17:43:25 +00:00
actions - > addAction ( menu - > addAction ( " Add New Map with Layout " ) ) - > setData ( layoutId ) ;
2021-02-14 14:16:23 +00:00
connect ( actions , & QActionGroup : : triggered , this , & MainWindow : : onAddNewMapToLayoutClick ) ;
2019-01-07 23:14:44 +00:00
menu - > exec ( QCursor : : pos ( ) ) ;
2018-09-27 00:33:08 +01:00
}
}
void MainWindow : : onAddNewMapToGroupClick ( QAction * triggeredAction )
{
2022-10-24 21:18:50 +01:00
openNewMapPopupWindow ( ) ;
this - > newMapPrompt - > init ( MapSortOrder : : Group , triggeredAction - > data ( ) ) ;
2019-01-07 23:14:44 +00:00
}
void MainWindow : : onAddNewMapToAreaClick ( QAction * triggeredAction )
{
2022-10-24 21:18:50 +01:00
openNewMapPopupWindow ( ) ;
this - > newMapPrompt - > init ( MapSortOrder : : Area , triggeredAction - > data ( ) ) ;
2019-01-07 23:14:44 +00:00
}
void MainWindow : : onAddNewMapToLayoutClick ( QAction * triggeredAction )
{
2022-10-24 21:18:50 +01:00
openNewMapPopupWindow ( ) ;
this - > newMapPrompt - > init ( MapSortOrder : : Layout , triggeredAction - > data ( ) ) ;
2019-01-07 23:14:44 +00:00
}
void MainWindow : : onNewMapCreated ( ) {
2022-04-29 02:42:47 +01:00
QString newMapName = this - > newMapPrompt - > map - > name ;
int newMapGroup = this - > newMapPrompt - > group ;
Map * newMap = this - > newMapPrompt - > map ;
bool existingLayout = this - > newMapPrompt - > existingLayout ;
bool importedMap = this - > newMapPrompt - > importedMap ;
2019-01-07 23:14:44 +00:00
2021-07-24 07:35:56 +01:00
newMap = editor - > project - > addNewMapToGroup ( newMapName , newMapGroup , newMap , existingLayout , importedMap ) ;
2019-01-07 23:14:44 +00:00
logInfo ( QString ( " Created a new map named %1. " ) . arg ( newMapName ) ) ;
2018-09-27 00:33:08 +01:00
editor - > project - > saveMap ( newMap ) ;
editor - > project - > saveAllDataStructures ( ) ;
2019-01-07 23:14:44 +00:00
QStandardItem * groupItem = mapGroupItemsList - > at ( newMapGroup ) ;
2018-09-27 00:33:08 +01:00
int numMapsInGroup = groupItem - > rowCount ( ) ;
2019-01-07 23:14:44 +00:00
QStandardItem * newMapItem = createMapItem ( newMapName , newMapGroup , numMapsInGroup ) ;
2018-09-27 00:33:08 +01:00
groupItem - > appendRow ( newMapItem ) ;
2018-09-29 15:22:50 +01:00
mapListIndexes . insert ( newMapName , newMapItem - > index ( ) ) ;
2018-09-27 00:33:08 +01:00
2019-01-07 23:14:44 +00:00
sortMapList ( ) ;
setMap ( newMapName , true ) ;
2022-10-14 23:11:11 +01:00
if ( newMap - > needsHealLocation ) {
2022-07-19 22:56:12 +01:00
addNewEvent ( Event : : Type : : HealLocation ) ;
2022-09-10 03:44:42 +01:00
editor - > project - > saveHealLocations ( newMap ) ;
2022-07-19 22:56:12 +01:00
editor - > save ( ) ;
2019-01-07 23:14:44 +00:00
}
2022-04-29 02:42:47 +01:00
disconnect ( this - > newMapPrompt , & NewMapPopup : : applied , this , & MainWindow : : onNewMapCreated ) ;
2021-02-19 00:37:55 +00:00
delete newMap ;
2019-01-07 23:14:44 +00:00
}
2022-10-24 21:18:50 +01:00
void MainWindow : : openNewMapPopupWindow ( ) {
2022-10-24 20:23:53 +01:00
if ( ! openedNewMapDialog ) {
2022-10-24 21:18:50 +01:00
NewMapPopup : : setDefaultSettings ( this - > editor - > project ) ;
openedNewMapDialog = true ;
2022-10-24 20:23:53 +01:00
}
2022-04-29 02:42:47 +01:00
if ( ! this - > newMapPrompt ) {
this - > newMapPrompt = new NewMapPopup ( this , this - > editor - > project ) ;
2019-01-07 23:14:44 +00:00
}
2022-04-29 02:42:47 +01:00
if ( ! this - > newMapPrompt - > isVisible ( ) ) {
this - > newMapPrompt - > show ( ) ;
2019-01-07 23:14:44 +00:00
} else {
2022-04-29 02:42:47 +01:00
this - > newMapPrompt - > raise ( ) ;
this - > newMapPrompt - > activateWindow ( ) ;
2019-01-07 23:14:44 +00:00
}
2022-04-29 02:42:47 +01:00
connect ( this - > newMapPrompt , & NewMapPopup : : applied , this , & MainWindow : : onNewMapCreated ) ;
this - > newMapPrompt - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
2019-01-07 23:14:44 +00:00
}
void MainWindow : : on_action_NewMap_triggered ( ) {
2022-10-24 21:18:50 +01:00
openNewMapPopupWindow ( ) ;
this - > newMapPrompt - > init ( ) ;
2018-09-27 00:33:08 +01:00
}
2022-10-24 14:33:51 +01:00
// Insert label for newly-created tileset into sorted list of existing labels
int MainWindow : : insertTilesetLabel ( QStringList * list , QString label ) {
int i = 0 ;
for ( ; i < list - > length ( ) ; i + + )
if ( list - > at ( i ) > label ) break ;
list - > insert ( i , label ) ;
return i ;
}
2019-03-21 23:50:50 +00:00
void MainWindow : : on_actionNew_Tileset_triggered ( ) {
NewTilesetDialog * createTilesetDialog = new NewTilesetDialog ( editor - > project , this ) ;
if ( createTilesetDialog - > exec ( ) = = QDialog : : Accepted ) {
if ( createTilesetDialog - > friendlyName . isEmpty ( ) ) {
logError ( QString ( " Tried to create a directory with an empty name. " ) ) ;
QMessageBox msgBox ( this ) ;
msgBox . setText ( " Failed to add new tileset. " ) ;
QString message = QString ( " The given name was empty. " ) ;
msgBox . setInformativeText ( message ) ;
msgBox . setDefaultButton ( QMessageBox : : Ok ) ;
msgBox . setIcon ( QMessageBox : : Icon : : Critical ) ;
msgBox . exec ( ) ;
return ;
}
2022-10-07 19:29:51 +01:00
QString fullDirectoryPath = editor - > project - > root + " / " + createTilesetDialog - > path ;
2019-03-21 23:50:50 +00:00
QDir directory ;
2019-03-23 14:44:21 +00:00
if ( directory . exists ( fullDirectoryPath ) ) {
logError ( QString ( " Could not create tileset \" %1 \" , the folder \" %2 \" already exists. " ) . arg ( createTilesetDialog - > friendlyName , fullDirectoryPath ) ) ;
2019-03-21 23:50:50 +00:00
QMessageBox msgBox ( this ) ;
msgBox . setText ( " Failed to add new tileset. " ) ;
2019-03-23 14:44:21 +00:00
QString message = QString ( " The folder for tileset \" %1 \" already exists. View porymap.log for specific errors. " ) . arg ( createTilesetDialog - > friendlyName ) ;
msgBox . setInformativeText ( message ) ;
msgBox . setDefaultButton ( QMessageBox : : Ok ) ;
msgBox . setIcon ( QMessageBox : : Icon : : Critical ) ;
msgBox . exec ( ) ;
return ;
}
2022-10-23 23:59:59 +01:00
if ( editor - > project - > tilesetLabelsOrdered . contains ( createTilesetDialog - > fullSymbolName ) ) {
2019-03-23 14:44:21 +00:00
logError ( QString ( " Could not create tileset \" %1 \" , the symbol \" %2 \" already exists. " ) . arg ( createTilesetDialog - > friendlyName , createTilesetDialog - > fullSymbolName ) ) ;
QMessageBox msgBox ( this ) ;
msgBox . setText ( " Failed to add new tileset. " ) ;
QString message = QString ( " The symbol for tileset \" %1 \" ( \" %2 \" ) already exists. " ) . arg ( createTilesetDialog - > friendlyName , createTilesetDialog - > fullSymbolName ) ;
2019-03-21 23:50:50 +00:00
msgBox . setInformativeText ( message ) ;
msgBox . setDefaultButton ( QMessageBox : : Ok ) ;
msgBox . setIcon ( QMessageBox : : Icon : : Critical ) ;
msgBox . exec ( ) ;
return ;
}
directory . mkdir ( fullDirectoryPath ) ;
directory . mkdir ( fullDirectoryPath + " /palettes " ) ;
2021-02-18 20:02:25 +00:00
Tileset newSet ;
newSet . name = createTilesetDialog - > fullSymbolName ;
newSet . tilesImagePath = fullDirectoryPath + " /tiles.png " ;
newSet . metatiles_path = fullDirectoryPath + " /metatiles.bin " ;
newSet . metatile_attrs_path = fullDirectoryPath + " /metatile_attributes.bin " ;
2022-10-24 04:38:27 +01:00
newSet . is_secondary = createTilesetDialog - > isSecondary ;
2019-03-21 23:50:50 +00:00
int numMetaTiles = createTilesetDialog - > isSecondary ? ( Project : : getNumTilesTotal ( ) - Project : : getNumTilesPrimary ( ) ) : Project : : getNumTilesPrimary ( ) ;
2021-02-17 02:45:54 +00:00
QImage tilesImage ( " :/images/blank_tileset.png " ) ;
2021-02-18 20:02:25 +00:00
editor - > project - > loadTilesetTiles ( & newSet , tilesImage ) ;
2022-10-04 02:28:16 +01:00
int tilesPerMetatile = projectConfig . getNumTilesInMetatile ( ) ;
2019-03-21 23:50:50 +00:00
for ( int i = 0 ; i < numMetaTiles ; + + i ) {
Metatile * mt = new Metatile ( ) ;
2020-06-30 15:05:56 +01:00
for ( int j = 0 ; j < tilesPerMetatile ; + + j ) {
2021-02-17 02:45:54 +00:00
Tile tile ( 0 , false , false , 0 ) ;
2019-03-21 23:50:50 +00:00
//Create a checkerboard-style dummy tileset
if ( ( ( i / 8 ) % 2 ) = = 0 )
2021-11-24 04:53:41 +00:00
tile . tileId = ( ( i % 2 ) = = 0 ) ? 1 : 2 ;
2019-03-21 23:50:50 +00:00
else
2021-11-24 04:53:41 +00:00
tile . tileId = ( ( i % 2 ) = = 1 ) ? 1 : 2 ;
2021-02-16 17:14:27 +00:00
mt - > tiles . append ( tile ) ;
2019-03-21 23:50:50 +00:00
}
2021-02-18 20:02:25 +00:00
newSet . metatiles . append ( mt ) ;
2019-03-21 23:50:50 +00:00
}
for ( int i = 0 ; i < 16 ; + + i ) {
2021-02-17 02:45:54 +00:00
QList < QRgb > currentPal ;
2019-03-21 23:50:50 +00:00
for ( int i = 0 ; i < 16 ; + + i ) {
2021-02-17 02:45:54 +00:00
currentPal . append ( qRgb ( 0 , 0 , 0 ) ) ;
2019-03-21 23:50:50 +00:00
}
2021-02-18 20:02:25 +00:00
newSet . palettes . append ( currentPal ) ;
newSet . palettePreviews . append ( currentPal ) ;
2020-08-27 01:42:42 +01:00
QString fileName = QString ( " %1.pal " ) . arg ( i , 2 , 10 , QLatin1Char ( ' 0 ' ) ) ;
2021-02-18 20:02:25 +00:00
newSet . palettePaths . append ( fullDirectoryPath + " /palettes/ " + fileName ) ;
2019-03-21 23:50:50 +00:00
}
2021-02-18 20:02:25 +00:00
newSet . palettes [ 0 ] [ 1 ] = qRgb ( 255 , 0 , 255 ) ;
newSet . palettePreviews [ 0 ] [ 1 ] = qRgb ( 255 , 0 , 255 ) ;
editor - > project - > saveTilesetTilesImage ( & newSet ) ;
editor - > project - > saveTilesetMetatiles ( & newSet ) ;
editor - > project - > saveTilesetMetatileAttributes ( & newSet ) ;
editor - > project - > saveTilesetPalettes ( & newSet ) ;
2019-03-21 23:50:50 +00:00
//append to tileset specific files
2022-09-28 01:17:55 +01:00
newSet . appendToHeaders ( editor - > project - > root , createTilesetDialog - > friendlyName , editor - > project - > usingAsmTilesets ) ;
2022-10-07 19:29:51 +01:00
newSet . appendToGraphics ( editor - > project - > root , createTilesetDialog - > friendlyName , editor - > project - > usingAsmTilesets ) ;
newSet . appendToMetatiles ( editor - > project - > root , createTilesetDialog - > friendlyName , editor - > project - > usingAsmTilesets ) ;
2019-03-21 23:50:50 +00:00
2022-10-24 14:33:51 +01:00
if ( ! createTilesetDialog - > isSecondary ) {
int index = insertTilesetLabel ( & editor - > project - > primaryTilesetLabels , createTilesetDialog - > fullSymbolName ) ;
this - > ui - > comboBox_PrimaryTileset - > insertItem ( index , createTilesetDialog - > fullSymbolName ) ;
2019-03-21 23:50:50 +00:00
} else {
2022-10-24 14:33:51 +01:00
int index = insertTilesetLabel ( & editor - > project - > secondaryTilesetLabels , createTilesetDialog - > fullSymbolName ) ;
this - > ui - > comboBox_SecondaryTileset - > insertItem ( index , createTilesetDialog - > fullSymbolName ) ;
2019-03-21 23:50:50 +00:00
}
2022-10-24 14:33:51 +01:00
insertTilesetLabel ( & editor - > project - > tilesetLabelsOrdered , createTilesetDialog - > fullSymbolName ) ;
2020-07-01 00:20:07 +01:00
2019-03-22 02:01:38 +00:00
QMessageBox msgBox ( this ) ;
msgBox . setText ( " Successfully created tileset. " ) ;
QString message = QString ( " Tileset \" %1 \" was created successfully. " ) . arg ( createTilesetDialog - > friendlyName ) ;
msgBox . setInformativeText ( message ) ;
msgBox . setDefaultButton ( QMessageBox : : Ok ) ;
msgBox . setIcon ( QMessageBox : : Icon : : Information ) ;
msgBox . exec ( ) ;
2019-03-21 23:50:50 +00:00
}
}
2018-10-03 01:01:18 +01:00
void MainWindow : : updateTilesetEditor ( ) {
if ( this - > tilesetEditor ) {
2020-09-25 13:12:13 +01:00
this - > tilesetEditor - > update (
this - > editor - > map ,
editor - > ui - > comboBox_PrimaryTileset - > currentText ( ) ,
editor - > ui - > comboBox_SecondaryTileset - > currentText ( )
) ;
2018-10-03 01:01:18 +01:00
}
}
2020-07-06 18:36:59 +01:00
void MainWindow : : redrawMetatileSelection ( )
2018-09-27 00:33:08 +01:00
{
2019-02-25 20:09:36 +00:00
double scale = pow ( 3.0 , static_cast < double > ( porymapConfig . getMetatilesZoom ( ) - 30 ) / 30.0 ) ;
2020-08-16 00:30:46 +01:00
QTransform transform ;
transform . scale ( scale , scale ) ;
ui - > graphicsView_currentMetatileSelection - > setTransform ( transform ) ;
ui - > graphicsView_currentMetatileSelection - > setFixedSize ( editor - > current_metatile_selection_item - > pixmap ( ) . width ( ) * scale + 2 , editor - > current_metatile_selection_item - > pixmap ( ) . height ( ) * scale + 2 ) ;
2018-10-08 20:42:51 +01:00
QPoint size = editor - > metatile_selector_item - > getSelectionDimensions ( ) ;
if ( size . x ( ) = = 1 & & size . y ( ) = = 1 ) {
2022-09-05 17:35:17 +01:00
MetatileSelection selection = editor - > metatile_selector_item - > getMetatileSelection ( ) ;
QPoint pos = editor - > metatile_selector_item - > getMetatileIdCoordsOnWidget ( selection . metatileItems . first ( ) . metatileId ) ;
2019-02-25 19:36:59 +00:00
pos * = scale ;
ui - > scrollArea_2 - > ensureVisible ( pos . x ( ) , pos . y ( ) , 8 * scale , 8 * scale ) ;
2018-10-08 20:42:51 +01:00
}
2020-07-06 18:36:59 +01:00
}
void MainWindow : : currentMetatilesSelectionChanged ( )
{
redrawMetatileSelection ( ) ;
2022-09-05 17:35:17 +01:00
if ( this - > tilesetEditor ) {
MetatileSelection selection = editor - > metatile_selector_item - > getMetatileSelection ( ) ;
this - > tilesetEditor - > selectMetatile ( selection . metatileItems . first ( ) . metatileId ) ;
}
2018-09-27 00:33:08 +01:00
}
void MainWindow : : on_mapList_activated ( const QModelIndex & index )
{
QVariant data = index . data ( Qt : : UserRole ) ;
2018-09-27 19:27:57 +01:00
if ( index . data ( MapListUserRoles : : TypeRole ) = = " map_name " & & ! data . isNull ( ) ) {
2020-02-12 17:23:28 +00:00
QString mapName = data . toString ( ) ;
if ( ! setMap ( mapName ) ) {
QMessageBox msgBox ( this ) ;
2020-02-12 21:45:21 +00:00
QString errorMsg = QString ( " There was an error opening map %1. Please see %2 for full error details. \n \n %3 " )
2020-02-12 17:23:28 +00:00
. arg ( mapName )
. arg ( getLogPath ( ) )
. arg ( getMostRecentError ( ) ) ;
msgBox . critical ( nullptr , " Error Opening Map " , errorMsg ) ;
}
2018-09-27 00:33:08 +01:00
}
}
2019-02-26 01:40:46 +00:00
void MainWindow : : drawMapListIcons ( QAbstractItemModel * model ) {
2019-08-07 15:48:07 +01:00
projectHasUnsavedChanges = false ;
2018-09-27 00:33:08 +01:00
QList < QModelIndex > list ;
list . append ( QModelIndex ( ) ) ;
while ( list . length ( ) ) {
QModelIndex parent = list . takeFirst ( ) ;
for ( int i = 0 ; i < model - > rowCount ( parent ) ; i + + ) {
QModelIndex index = model - > index ( i , 0 , parent ) ;
if ( model - > hasChildren ( index ) ) {
list . append ( index ) ;
}
2019-02-26 01:40:46 +00:00
QVariant data = index . data ( Qt : : UserRole ) ;
if ( ! data . isNull ( ) ) {
QString map_name = data . toString ( ) ;
2021-02-15 16:33:30 +00:00
if ( editor - > project & & editor - > project - > mapCache . contains ( map_name ) ) {
2019-02-26 01:40:46 +00:00
QStandardItem * map = mapListModel - > itemFromIndex ( mapListIndexes . value ( map_name ) ) ;
map - > setIcon ( * mapIcon ) ;
2021-02-15 16:33:30 +00:00
if ( editor - > project - > mapCache . value ( map_name ) - > hasUnsavedChanges ( ) ) {
2019-02-26 01:40:46 +00:00
map - > setIcon ( * mapEditedIcon ) ;
2019-08-07 15:48:07 +01:00
projectHasUnsavedChanges = true ;
2019-02-26 01:40:46 +00:00
}
if ( editor - > map - > name = = map_name ) {
map - > setIcon ( * mapOpenedIcon ) ;
}
2018-10-03 03:46:08 +01:00
}
2018-09-27 00:33:08 +01:00
}
}
}
}
void MainWindow : : updateMapList ( ) {
2019-04-06 05:20:57 +01:00
drawMapListIcons ( mapListModel ) ;
2018-09-27 00:33:08 +01:00
}
2022-07-19 22:56:12 +01:00
void MainWindow : : on_action_Save_Project_triggered ( ) {
2018-09-27 00:33:08 +01:00
editor - > saveProject ( ) ;
updateMapList ( ) ;
2022-09-28 05:21:01 +01:00
showWindowTitle ( ) ;
2018-09-27 00:33:08 +01:00
}
2020-07-09 23:31:35 +01:00
void MainWindow : : duplicate ( ) {
editor - > duplicateSelectedEvents ( ) ;
}
2021-04-14 06:08:18 +01:00
void MainWindow : : copy ( ) {
auto focused = QApplication : : focusWidget ( ) ;
if ( focused ) {
QString objectName = focused - > objectName ( ) ;
if ( objectName = = " graphicsView_currentMetatileSelection " ) {
// copy the current metatile selection as json data
OrderedJson : : object copyObject ;
copyObject [ " object " ] = " metatile_selection " ;
OrderedJson : : array metatiles ;
2022-09-05 17:35:17 +01:00
MetatileSelection selection = editor - > metatile_selector_item - > getMetatileSelection ( ) ;
for ( auto item : selection . metatileItems ) {
metatiles . append ( static_cast < int > ( item . metatileId ) ) ;
2021-04-14 06:08:18 +01:00
}
OrderedJson : : array collisions ;
2022-09-05 17:35:17 +01:00
if ( selection . hasCollision ) {
for ( auto item : selection . collisionItems ) {
OrderedJson : : object collision ;
collision [ " collision " ] = item . collision ;
collision [ " elevation " ] = item . elevation ;
collisions . append ( collision ) ;
}
2021-04-14 06:08:18 +01:00
}
if ( collisions . length ( ) ! = metatiles . length ( ) ) {
// fill in collisions
collisions . clear ( ) ;
for ( int i = 0 ; i < metatiles . length ( ) ; i + + ) {
OrderedJson : : object collision ;
collision [ " collision " ] = 0 ;
collision [ " elevation " ] = 3 ;
collisions . append ( collision ) ;
}
}
copyObject [ " metatile_selection " ] = metatiles ;
copyObject [ " collision_selection " ] = collisions ;
copyObject [ " width " ] = editor - > metatile_selector_item - > getSelectionDimensions ( ) . x ( ) ;
copyObject [ " height " ] = editor - > metatile_selector_item - > getSelectionDimensions ( ) . y ( ) ;
setClipboardData ( copyObject ) ;
logInfo ( " Copied metatile selection to clipboard " ) ;
} else if ( objectName = = " graphicsView_Map " ) {
// which tab are we in?
switch ( ui - > mainTabBar - > currentIndex ( ) )
{
default :
break ;
case 0 :
{
// copy the map image
QPixmap pixmap = editor - > map ? editor - > map - > render ( true ) : QPixmap ( ) ;
setClipboardData ( pixmap . toImage ( ) ) ;
logInfo ( " Copied current map image to clipboard " ) ;
break ;
}
case 1 :
{
2022-07-19 22:56:12 +01:00
if ( ! editor | | ! editor - > project ) break ;
2021-04-14 06:08:18 +01:00
// copy the currently selected event(s) as a json object
OrderedJson : : object copyObject ;
copyObject [ " object " ] = " events " ;
QList < DraggablePixmapItem * > events ;
if ( editor - > selected_events & & editor - > selected_events - > length ( ) ) {
events = * editor - > selected_events ;
}
OrderedJson : : array eventsArray ;
for ( auto item : events ) {
Event * event = item - > event ;
2022-07-19 22:56:12 +01:00
if ( event - > getEventType ( ) = = Event : : Type : : HealLocation ) {
2021-04-14 06:08:18 +01:00
// no copy on heal locations
2022-07-19 22:56:12 +01:00
logWarn ( QString ( " Copying heal location events is not allowed. " ) ) ;
2021-04-14 06:08:18 +01:00
continue ;
}
2022-07-19 22:56:12 +01:00
OrderedJson : : object eventContainer ;
eventContainer [ " event_type " ] = Event : : eventTypeToString ( event - > getEventType ( ) ) ;
OrderedJson : : object eventJson = event - > buildEventJson ( editor - > project ) ;
eventContainer [ " event " ] = eventJson ;
eventsArray . append ( eventContainer ) ;
2021-04-14 06:08:18 +01:00
}
2022-07-19 22:56:12 +01:00
2022-07-05 19:38:23 +01:00
if ( ! eventsArray . isEmpty ( ) ) {
copyObject [ " events " ] = eventsArray ;
setClipboardData ( copyObject ) ;
logInfo ( " Copied currently selected events to clipboard " ) ;
}
2021-04-14 06:08:18 +01:00
break ;
}
}
}
}
}
void MainWindow : : setClipboardData ( OrderedJson : : object object ) {
QClipboard * clipboard = QGuiApplication : : clipboard ( ) ;
QString newText ;
int indent = 0 ;
object [ " application " ] = " porymap " ;
OrderedJson data ( object ) ;
data . dump ( newText , & indent ) ;
clipboard - > setText ( newText ) ;
}
void MainWindow : : setClipboardData ( QImage image ) {
QClipboard * clipboard = QGuiApplication : : clipboard ( ) ;
clipboard - > setImage ( image ) ;
}
void MainWindow : : paste ( ) {
if ( ! editor | | ! editor - > project | | ! editor - > map ) return ;
QClipboard * clipboard = QGuiApplication : : clipboard ( ) ;
QString clipboardText ( clipboard - > text ( ) ) ;
if ( ! clipboardText . isEmpty ( ) ) {
// we only can paste json text
// so, check if clipboard text is valid json
QString parseError ;
QJsonDocument pasteJsonDoc = QJsonDocument : : fromJson ( clipboardText . toUtf8 ( ) ) ;
// test empty
QJsonObject pasteObject = pasteJsonDoc . object ( ) ;
//OrderedJson::object pasteObject = pasteJson.object_items();
if ( pasteObject [ " application " ] . toString ( ) ! = " porymap " ) {
return ;
}
logInfo ( " Attempting to paste from JSON in clipboard " ) ;
switch ( ui - > mainTabBar - > currentIndex ( ) )
{
default :
break ;
case 0 :
{
// can only paste currently selected metatiles on this tab
if ( pasteObject [ " object " ] . toString ( ) ! = " metatile_selection " ) {
return ;
}
QJsonArray metatilesArray = pasteObject [ " metatile_selection " ] . toArray ( ) ;
QJsonArray collisionsArray = pasteObject [ " collision_selection " ] . toArray ( ) ;
2022-10-14 23:55:18 +01:00
int width = ParseUtil : : jsonToInt ( pasteObject [ " width " ] ) ;
int height = ParseUtil : : jsonToInt ( pasteObject [ " height " ] ) ;
2021-04-14 06:08:18 +01:00
QList < uint16_t > metatiles ;
QList < QPair < uint16_t , uint16_t > > collisions ;
for ( auto tile : metatilesArray ) {
metatiles . append ( static_cast < uint16_t > ( tile . toInt ( ) ) ) ;
}
for ( QJsonValue collision : collisionsArray ) {
collisions . append ( { static_cast < uint16_t > ( collision [ " collision " ] . toInt ( ) ) , static_cast < uint16_t > ( collision [ " elevation " ] . toInt ( ) ) } ) ;
}
editor - > metatile_selector_item - > setExternalSelection ( width , height , metatiles , collisions ) ;
break ;
}
case 1 :
{
// can only paste events to this tab
if ( pasteObject [ " object " ] . toString ( ) ! = " events " ) {
return ;
}
QList < Event * > newEvents ;
QJsonArray events = pasteObject [ " events " ] . toArray ( ) ;
for ( QJsonValue event : events ) {
// paste the event to the map
2022-07-19 22:56:12 +01:00
Event * pasteEvent = nullptr ;
2021-04-14 06:08:18 +01:00
2022-07-19 22:56:12 +01:00
Event : : Type type = Event : : eventTypeFromString ( event [ " event_type " ] . toString ( ) ) ;
2022-08-31 23:53:07 +01:00
if ( this - > editor - > eventLimitReached ( type ) ) {
logWarn ( QString ( " Cannot paste event, the limit for type '%1' has been reached. " ) . arg ( event [ " event_type " ] . toString ( ) ) ) ;
break ;
2022-07-05 19:38:23 +01:00
}
2022-07-19 22:56:12 +01:00
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 ;
2021-04-14 06:08:18 +01:00
}
2022-07-19 22:56:12 +01:00
if ( pasteEvent ) {
pasteEvent - > setMap ( this - > editor - > map ) ;
newEvents . append ( pasteEvent ) ;
}
2021-04-14 06:08:18 +01:00
}
2022-07-19 22:56:12 +01:00
if ( ! newEvents . empty ( ) ) {
2022-07-05 19:50:17 +01:00
editor - > map - > editHistory . push ( new EventPaste ( this - > editor , editor - > map , newEvents ) ) ;
2022-07-19 22:56:12 +01:00
updateObjects ( ) ;
2022-07-05 19:38:23 +01:00
}
2022-07-19 22:56:12 +01:00
2021-04-14 06:08:18 +01:00
break ;
}
}
}
}
2018-09-27 00:33:08 +01:00
void MainWindow : : on_action_Save_triggered ( ) {
editor - > save ( ) ;
updateMapList ( ) ;
2022-09-28 05:21:01 +01:00
showWindowTitle ( ) ;
2018-09-27 00:33:08 +01:00
}
2021-12-10 21:52:17 +00:00
void MainWindow : : on_mapViewTab_tabBarClicked ( int index )
{
2021-12-13 16:41:46 +00:00
int oldIndex = ui - > mapViewTab - > currentIndex ( ) ;
2021-12-26 16:53:31 +00:00
ui - > mapViewTab - > setCurrentIndex ( index ) ;
2021-12-13 16:41:46 +00:00
if ( index ! = oldIndex )
Scripting : : cb_MapViewTabChanged ( oldIndex , index ) ;
2018-09-27 00:33:08 +01:00
if ( index = = 0 ) {
editor - > setEditingMap ( ) ;
} else if ( index = = 1 ) {
editor - > setEditingCollision ( ) ;
2022-09-10 02:09:28 +01:00
} else if ( index = = 2 ) {
editor - > setEditingMap ( ) ;
2022-10-09 20:36:12 +01:00
prefab . tryImportDefaultPrefabs ( this - > editor - > map ) ;
2018-09-27 00:33:08 +01:00
}
2021-12-12 17:19:59 +00:00
editor - > setCursorRectVisible ( false ) ;
2018-09-27 00:33:08 +01:00
}
void MainWindow : : on_action_Exit_triggered ( )
{
QApplication : : quit ( ) ;
}
2019-11-02 01:19:39 +00:00
void MainWindow : : on_mainTabBar_tabBarClicked ( int index )
2021-12-10 06:54:27 +00:00
{
int oldIndex = ui - > mainTabBar - > currentIndex ( ) ;
2021-12-26 16:53:31 +00:00
ui - > mainTabBar - > setCurrentIndex ( index ) ;
2021-12-10 06:54:27 +00:00
if ( index ! = oldIndex )
2021-12-10 21:52:17 +00:00
Scripting : : cb_MainTabChanged ( oldIndex , index ) ;
2021-12-10 06:54:27 +00:00
2019-11-02 01:19:39 +00:00
int tabIndexToStackIndex [ 5 ] = { 0 , 0 , 1 , 2 , 3 } ;
ui - > mainStackedWidget - > setCurrentIndex ( tabIndexToStackIndex [ index ] ) ;
2018-09-27 00:33:08 +01:00
if ( index = = 0 ) {
2019-11-02 01:19:39 +00:00
ui - > stackedWidget_MapEvents - > setCurrentIndex ( 0 ) ;
2021-12-13 16:41:46 +00:00
on_mapViewTab_tabBarClicked ( ui - > mapViewTab - > currentIndex ( ) ) ;
2020-05-18 02:25:28 +01:00
clickToolButtonFromEditMode ( editor - > map_edit_mode ) ;
2018-09-27 00:33:08 +01:00
} else if ( index = = 1 ) {
2019-11-02 01:19:39 +00:00
ui - > stackedWidget_MapEvents - > setCurrentIndex ( 1 ) ;
2018-09-27 00:33:08 +01:00
editor - > setEditingObjects ( ) ;
2020-05-18 02:25:28 +01:00
clickToolButtonFromEditMode ( editor - > obj_edit_mode ) ;
2018-09-27 00:33:08 +01:00
} else if ( index = = 3 ) {
editor - > setEditingConnections ( ) ;
}
2019-10-01 03:24:39 +01:00
if ( index ! = 4 ) {
2022-09-01 05:57:31 +01:00
if ( userConfig . getEncounterJsonActive ( ) )
2020-04-21 19:08:44 +01:00
editor - > saveEncounterTabData ( ) ;
2019-10-01 03:24:39 +01:00
}
2020-10-02 17:12:19 +01:00
if ( index ! = 1 ) {
2020-10-24 12:45:08 +01:00
editor - > map_ruler - > setEnabled ( false ) ;
2020-10-02 17:12:19 +01:00
}
2018-09-27 00:33:08 +01:00
}
void MainWindow : : on_actionZoom_In_triggered ( ) {
2020-10-13 11:07:31 +01:00
editor - > scaleMapView ( 1 ) ;
2018-09-27 00:33:08 +01:00
}
void MainWindow : : on_actionZoom_Out_triggered ( ) {
2020-10-13 11:07:31 +01:00
editor - > scaleMapView ( - 1 ) ;
2018-09-27 00:33:08 +01:00
}
void MainWindow : : on_actionBetter_Cursors_triggered ( ) {
2018-12-25 20:41:06 +00:00
porymapConfig . setPrettyCursors ( ui - > actionBetter_Cursors - > isChecked ( ) ) ;
2018-09-27 00:33:08 +01:00
this - > editor - > settings - > betterCursors = ui - > actionBetter_Cursors - > isChecked ( ) ;
}
2019-01-09 00:04:48 +00:00
void MainWindow : : on_actionPlayer_View_Rectangle_triggered ( )
{
2019-01-09 15:35:34 +00:00
bool enabled = ui - > actionPlayer_View_Rectangle - > isChecked ( ) ;
porymapConfig . setShowPlayerView ( enabled ) ;
this - > editor - > settings - > playerViewRectEnabled = enabled ;
2022-02-07 22:38:29 +00:00
if ( ( this - > editor - > map_item & & this - > editor - > map_item - > has_mouse )
| | ( this - > editor - > collision_item & & this - > editor - > collision_item - > has_mouse ) ) {
2020-09-07 19:05:17 +01:00
this - > editor - > playerViewRect - > setVisible ( enabled ) ;
2021-12-12 17:19:59 +00:00
ui - > graphicsView_Map - > scene ( ) - > update ( ) ;
2020-09-07 19:05:17 +01:00
}
2019-01-09 15:35:34 +00:00
}
void MainWindow : : on_actionCursor_Tile_Outline_triggered ( )
{
bool enabled = ui - > actionCursor_Tile_Outline - > isChecked ( ) ;
porymapConfig . setShowCursorTile ( enabled ) ;
this - > editor - > settings - > cursorTileRectEnabled = enabled ;
2022-02-07 22:38:29 +00:00
if ( ( this - > editor - > map_item & & this - > editor - > map_item - > has_mouse )
| | ( this - > editor - > collision_item & & this - > editor - > collision_item - > has_mouse ) ) {
2021-12-13 16:41:46 +00:00
this - > editor - > cursorMapTileRect - > setVisible ( enabled & & this - > editor - > cursorMapTileRect - > getActive ( ) ) ;
2021-12-12 17:19:59 +00:00
ui - > graphicsView_Map - > scene ( ) - > update ( ) ;
2020-09-07 19:05:17 +01:00
}
2019-01-09 00:04:48 +00:00
}
2020-04-21 02:54:16 +01:00
void MainWindow : : on_actionUse_Encounter_Json_triggered ( bool checked )
{
QMessageBox warning ( this ) ;
warning . setText ( " You must reload the project for this setting to take effect. " ) ;
warning . setIcon ( QMessageBox : : Information ) ;
warning . exec ( ) ;
2022-09-01 05:57:31 +01:00
userConfig . setEncounterJsonActive ( checked ) ;
2020-04-21 02:54:16 +01:00
}
void MainWindow : : on_actionMonitor_Project_Files_triggered ( bool checked )
{
porymapConfig . setMonitorFiles ( checked ) ;
}
void MainWindow : : on_actionUse_Poryscript_triggered ( bool checked )
{
projectConfig . setUsePoryScript ( checked ) ;
}
2022-07-04 21:03:13 +01:00
void MainWindow : : on_actionOpen_Recent_Project_On_Launch_triggered ( bool checked )
{
porymapConfig . setReopenOnLaunch ( checked ) ;
}
2020-11-01 12:35:20 +00:00
void MainWindow : : on_actionEdit_Shortcuts_triggered ( )
{
2020-11-09 10:50:15 +00:00
if ( ! shortcutsEditor )
initShortcutsEditor ( ) ;
2020-11-01 12:35:20 +00:00
2022-10-05 16:55:43 +01:00
if ( shortcutsEditor - > isHidden ( ) ) {
2020-11-01 12:35:20 +00:00
shortcutsEditor - > show ( ) ;
2022-10-05 16:55:43 +01:00
} else if ( shortcutsEditor - > isMinimized ( ) ) {
2020-11-01 12:35:20 +00:00
shortcutsEditor - > showNormal ( ) ;
2022-10-05 16:55:43 +01:00
} else {
shortcutsEditor - > raise ( ) ;
2020-11-01 12:35:20 +00:00
shortcutsEditor - > activateWindow ( ) ;
2022-10-05 16:55:43 +01:00
}
2020-11-01 12:35:20 +00:00
}
2020-11-09 10:50:15 +00:00
void MainWindow : : initShortcutsEditor ( ) {
shortcutsEditor = new ShortcutsEditor ( this ) ;
connect ( shortcutsEditor , & ShortcutsEditor : : shortcutsSaved ,
this , & MainWindow : : applyUserShortcuts ) ;
connectSubEditorsToShortcutsEditor ( ) ;
shortcutsEditor - > setShortcutableObjects ( shortcutableObjects ( ) ) ;
}
void MainWindow : : connectSubEditorsToShortcutsEditor ( ) {
/* Initialize sub-editors so that their children are added to MainWindow's object tree and will
* be returned by shortcutableObjects ( ) to be passed to ShortcutsEditor . */
if ( ! tilesetEditor )
initTilesetEditor ( ) ;
connect ( shortcutsEditor , & ShortcutsEditor : : shortcutsSaved ,
tilesetEditor , & TilesetEditor : : applyUserShortcuts ) ;
2022-04-29 01:52:31 +01:00
if ( ! regionMapEditor )
initRegionMapEditor ( ) ;
if ( regionMapEditor )
connect ( shortcutsEditor , & ShortcutsEditor : : shortcutsSaved ,
regionMapEditor , & RegionMapEditor : : applyUserShortcuts ) ;
2020-11-09 10:50:15 +00:00
}
2018-09-27 00:33:08 +01:00
void MainWindow : : on_actionPencil_triggered ( )
{
on_toolButton_Paint_clicked ( ) ;
}
void MainWindow : : on_actionPointer_triggered ( )
{
on_toolButton_Select_clicked ( ) ;
}
void MainWindow : : on_actionFlood_Fill_triggered ( )
{
on_toolButton_Fill_clicked ( ) ;
}
void MainWindow : : on_actionEyedropper_triggered ( )
{
on_toolButton_Dropper_clicked ( ) ;
}
void MainWindow : : on_actionMove_triggered ( )
{
on_toolButton_Move_clicked ( ) ;
}
void MainWindow : : on_actionMap_Shift_triggered ( )
{
on_toolButton_Shift_clicked ( ) ;
}
2018-09-27 19:27:57 +01:00
void MainWindow : : resetMapViewScale ( ) {
2020-10-13 11:07:31 +01:00
editor - > scaleMapView ( 0 ) ;
2018-09-27 00:33:08 +01:00
}
2022-07-19 22:56:12 +01:00
void MainWindow : : addNewEvent ( Event : : Type type ) {
2020-07-10 21:34:42 +01:00
if ( editor & & editor - > project ) {
2022-07-19 22:56:12 +01:00
DraggablePixmapItem * object = editor - > addNewEvent ( type ) ;
2018-09-27 00:33:08 +01:00
if ( object ) {
2021-03-20 15:20:29 +00:00
auto halfSize = ui - > graphicsView_Map - > size ( ) / 2 ;
auto centerPos = ui - > graphicsView_Map - > mapToScene ( halfSize . width ( ) , halfSize . height ( ) ) ;
2021-03-23 01:57:34 +00:00
object - > moveTo ( Metatile : : coordFromPixmapCoord ( centerPos ) ) ;
2020-09-13 23:48:03 +01:00
updateObjects ( ) ;
2018-09-27 00:33:08 +01:00
editor - > selectMapEvent ( object , false ) ;
2020-07-10 21:34:42 +01:00
} else {
QMessageBox msgBox ( this ) ;
msgBox . setText ( " Failed to add new event " ) ;
2022-07-19 22:56:12 +01:00
if ( Event : : typeToGroup ( type ) = = Event : : Group : : Object ) {
2020-07-10 21:34:42 +01:00
msgBox . setInformativeText ( QString ( " The limit for object events (%1) has been reached. \n \n "
2022-09-01 17:14:47 +01:00
" This limit can be adjusted with OBJECT_EVENT_TEMPLATES_COUNT in '%2'. " )
. arg ( editor - > project - > getMaxObjectEvents ( ) )
. arg ( projectConfig . getFilePath ( ProjectFilePath : : constants_global ) ) ) ;
2020-07-10 21:34:42 +01:00
}
msgBox . setDefaultButton ( QMessageBox : : Ok ) ;
msgBox . setIcon ( QMessageBox : : Icon : : Warning ) ;
msgBox . exec ( ) ;
2018-09-27 00:33:08 +01:00
}
}
}
2022-10-18 18:44:45 +01:00
void MainWindow : : tryAddEventTab ( QWidget * tab , Event : : Group group ) {
if ( editor - > map - > events . value ( group ) . length ( ) )
ui - > tabWidget_EventType - > addTab ( tab , QString ( " %1s " ) . arg ( Event : : eventGroupToString ( group ) ) ) ;
}
2022-09-06 22:11:36 +01:00
void MainWindow : : displayEventTabs ( ) {
const QSignalBlocker blocker ( ui - > tabWidget_EventType ) ;
2018-12-05 04:14:16 +00:00
ui - > tabWidget_EventType - > clear ( ) ;
2022-10-18 18:44:45 +01:00
tryAddEventTab ( eventTabObjectWidget , Event : : Group : : Object ) ;
tryAddEventTab ( eventTabWarpWidget , Event : : Group : : Warp ) ;
tryAddEventTab ( eventTabTriggerWidget , Event : : Group : : Coord ) ;
tryAddEventTab ( eventTabBGWidget , Event : : Group : : Bg ) ;
tryAddEventTab ( eventTabHealspotWidget , Event : : Group : : Heal ) ;
2022-09-06 22:11:36 +01:00
}
void MainWindow : : updateObjects ( ) {
2022-10-16 23:37:51 +01:00
QList < DraggablePixmapItem * > all_objects = editor - > getObjects ( ) ;
if ( selectedObject & & ! all_objects . contains ( selectedObject ) ) {
selectedObject = nullptr ;
}
if ( selectedWarp & & ! all_objects . contains ( selectedWarp ) ) {
selectedWarp = nullptr ;
}
if ( selectedTrigger & & ! all_objects . contains ( selectedTrigger ) ) {
selectedTrigger = nullptr ;
}
if ( selectedBG & & ! all_objects . contains ( selectedBG ) ) {
selectedBG = nullptr ;
}
if ( selectedHealspot & & ! all_objects . contains ( selectedHealspot ) ) {
selectedHealspot = nullptr ;
}
2022-09-06 22:11:36 +01:00
displayEventTabs ( ) ;
2018-11-28 01:39:57 +00:00
updateSelectedObjects ( ) ;
2018-09-27 00:33:08 +01:00
}
void MainWindow : : updateSelectedObjects ( ) {
2020-08-07 00:46:23 +01:00
QList < DraggablePixmapItem * > all_events = editor - > getObjects ( ) ;
QList < DraggablePixmapItem * > events ;
2018-09-27 00:33:08 +01:00
if ( editor - > selected_events & & editor - > selected_events - > length ( ) ) {
2020-08-07 00:46:23 +01:00
events = * editor - > selected_events ;
2022-07-19 22:56:12 +01:00
}
else {
2022-10-16 23:37:51 +01:00
QList < Event * > all_events ;
if ( editor - > map ) {
all_events = editor - > map - > getAllEvents ( ) ;
}
2020-08-07 00:46:23 +01:00
if ( all_events . length ( ) ) {
2022-10-16 23:37:51 +01:00
DraggablePixmapItem * selectedEvent = all_events . first ( ) - > getPixmapItem ( ) ;
if ( selectedEvent ) {
editor - > selected_events - > append ( selectedEvent ) ;
editor - > redrawObject ( selectedEvent ) ;
events . append ( selectedEvent ) ;
}
2018-09-27 00:33:08 +01:00
}
}
2018-11-30 03:59:03 +00:00
QScrollArea * scrollTarget = ui - > scrollArea_Multiple ;
2018-11-28 01:39:57 +00:00
QWidget * target = ui - > scrollAreaWidgetContents_Multiple ;
2018-09-27 00:33:08 +01:00
2022-08-31 23:53:07 +01:00
this - > isProgrammaticEventTabChange = true ;
2018-11-30 03:59:03 +00:00
2022-07-19 22:56:12 +01:00
if ( events . length ( ) = = 1 ) {
2022-08-31 23:53:07 +01:00
// single selected event case
2022-07-19 22:56:12 +01:00
Event * current = events [ 0 ] - > event ;
2022-08-31 23:53:07 +01:00
Event : : Group eventGroup = current - > getEventGroup ( ) ;
int event_offs = Event : : getIndexOffset ( eventGroup ) ;
2018-11-28 01:39:57 +00:00
2022-08-31 23:53:07 +01:00
switch ( eventGroup ) {
case Event : : Group : : Object : {
2018-11-30 03:59:03 +00:00
scrollTarget = ui - > scrollArea_Objects ;
2018-11-28 01:39:57 +00:00
target = ui - > scrollAreaWidgetContents_Objects ;
2018-11-13 19:32:36 +00:00
ui - > tabWidget_EventType - > setCurrentWidget ( ui - > tab_Objects ) ;
2022-07-19 22:56:12 +01:00
2022-10-16 23:37:51 +01:00
selectedObject = current - > getPixmapItem ( ) ;
2022-07-19 22:56:12 +01:00
this - > ui - > spinner_ObjectID - > setMinimum ( event_offs ) ;
2022-08-31 23:53:07 +01:00
this - > ui - > spinner_ObjectID - > setMaximum ( current - > getMap ( ) - > events . value ( eventGroup ) . length ( ) + event_offs - 1 ) ;
2022-09-28 08:25:08 +01:00
this - > ui - > spinner_ObjectID - > setValue ( current - > getEventIndex ( ) + event_offs ) ;
2022-08-31 23:53:07 +01:00
break ;
2018-11-13 17:36:34 +00:00
}
2022-08-31 23:53:07 +01:00
case Event : : Group : : Warp : {
2018-11-30 03:59:03 +00:00
scrollTarget = ui - > scrollArea_Warps ;
2018-11-28 01:39:57 +00:00
target = ui - > scrollAreaWidgetContents_Warps ;
2018-11-13 19:32:36 +00:00
ui - > tabWidget_EventType - > setCurrentWidget ( ui - > tab_Warps ) ;
2022-07-19 22:56:12 +01:00
2022-10-16 23:37:51 +01:00
selectedWarp = current - > getPixmapItem ( ) ;
2022-07-19 22:56:12 +01:00
this - > ui - > spinner_WarpID - > setMinimum ( event_offs ) ;
2022-08-31 23:53:07 +01:00
this - > ui - > spinner_WarpID - > setMaximum ( current - > getMap ( ) - > events . value ( eventGroup ) . length ( ) + event_offs - 1 ) ;
2022-09-28 08:25:08 +01:00
this - > ui - > spinner_WarpID - > setValue ( current - > getEventIndex ( ) + event_offs ) ;
2022-08-31 23:53:07 +01:00
break ;
2018-11-13 17:36:34 +00:00
}
2022-08-31 23:53:07 +01:00
case Event : : Group : : Coord : {
2018-11-30 03:59:03 +00:00
scrollTarget = ui - > scrollArea_Triggers ;
2018-11-28 01:39:57 +00:00
target = ui - > scrollAreaWidgetContents_Triggers ;
2018-11-13 19:32:36 +00:00
ui - > tabWidget_EventType - > setCurrentWidget ( ui - > tab_Triggers ) ;
2022-07-19 22:56:12 +01:00
2022-10-16 23:37:51 +01:00
selectedTrigger = current - > getPixmapItem ( ) ;
2022-07-19 22:56:12 +01:00
this - > ui - > spinner_TriggerID - > setMinimum ( event_offs ) ;
2022-08-31 23:53:07 +01:00
this - > ui - > spinner_TriggerID - > setMaximum ( current - > getMap ( ) - > events . value ( eventGroup ) . length ( ) + event_offs - 1 ) ;
2022-09-28 08:25:08 +01:00
this - > ui - > spinner_TriggerID - > setValue ( current - > getEventIndex ( ) + event_offs ) ;
2022-08-31 23:53:07 +01:00
break ;
2018-11-13 17:36:34 +00:00
}
2022-08-31 23:53:07 +01:00
case Event : : Group : : Bg : {
2018-11-30 03:59:03 +00:00
scrollTarget = ui - > scrollArea_BGs ;
2018-11-28 01:39:57 +00:00
target = ui - > scrollAreaWidgetContents_BGs ;
2018-11-13 19:32:36 +00:00
ui - > tabWidget_EventType - > setCurrentWidget ( ui - > tab_BGs ) ;
2022-07-19 22:56:12 +01:00
2022-10-16 23:37:51 +01:00
selectedBG = current - > getPixmapItem ( ) ;
2022-07-19 22:56:12 +01:00
this - > ui - > spinner_BgID - > setMinimum ( event_offs ) ;
2022-08-31 23:53:07 +01:00
this - > ui - > spinner_BgID - > setMaximum ( current - > getMap ( ) - > events . value ( eventGroup ) . length ( ) + event_offs - 1 ) ;
2022-09-28 08:25:08 +01:00
this - > ui - > spinner_BgID - > setValue ( current - > getEventIndex ( ) + event_offs ) ;
2022-08-31 23:53:07 +01:00
break ;
2018-11-13 17:36:34 +00:00
}
2022-08-31 23:53:07 +01:00
case Event : : Group : : Heal : {
2018-11-30 03:59:03 +00:00
scrollTarget = ui - > scrollArea_Healspots ;
2018-11-28 01:39:57 +00:00
target = ui - > scrollAreaWidgetContents_Healspots ;
ui - > tabWidget_EventType - > setCurrentWidget ( ui - > tab_Healspots ) ;
2022-07-19 22:56:12 +01:00
2022-10-16 23:37:51 +01:00
selectedHealspot = current - > getPixmapItem ( ) ;
2022-07-19 22:56:12 +01:00
this - > ui - > spinner_HealID - > setMinimum ( event_offs ) ;
2022-08-31 23:53:07 +01:00
this - > ui - > spinner_HealID - > setMaximum ( current - > getMap ( ) - > events . value ( eventGroup ) . length ( ) + event_offs - 1 ) ;
2022-09-28 08:25:08 +01:00
this - > ui - > spinner_HealID - > setValue ( current - > getEventIndex ( ) + event_offs ) ;
2022-08-31 23:53:07 +01:00
break ;
}
default :
break ;
2018-11-28 01:39:57 +00:00
}
2018-11-13 17:36:34 +00:00
ui - > tabWidget_EventType - > removeTab ( ui - > tabWidget_EventType - > indexOf ( ui - > tab_Multiple ) ) ;
}
2022-07-19 22:56:12 +01:00
else if ( events . length ( ) > 1 ) {
2018-11-13 17:36:34 +00:00
ui - > tabWidget_EventType - > addTab ( ui - > tab_Multiple , " Multiple " ) ;
ui - > tabWidget_EventType - > setCurrentWidget ( ui - > tab_Multiple ) ;
2018-09-27 00:33:08 +01:00
}
2022-08-31 23:53:07 +01:00
this - > isProgrammaticEventTabChange = false ;
2018-11-30 03:59:03 +00:00
2022-09-06 05:20:14 +01:00
QList < QFrame * > frames ;
2022-07-19 22:56:12 +01:00
for ( DraggablePixmapItem * item : events ) {
Event * event = item - > event ;
EventFrame * eventFrame = event - > createEventFrame ( ) ;
eventFrame - > populate ( this - > editor - > project ) ;
eventFrame - > initialize ( ) ;
eventFrame - > connectSignals ( ) ;
frames . append ( eventFrame ) ;
}
if ( target - > layout ( ) & & target - > children ( ) . length ( ) ) {
for ( QFrame * frame : target - > findChildren < EventFrame * > ( ) ) {
2022-08-31 23:53:07 +01:00
if ( ! frames . contains ( frame ) )
frame - > hide ( ) ;
2018-11-13 17:36:34 +00:00
}
2022-07-19 22:56:12 +01:00
delete target - > layout ( ) ;
}
if ( ! events . empty ( ) ) {
QVBoxLayout * layout = new QVBoxLayout ;
2018-11-13 17:36:34 +00:00
target - > setLayout ( layout ) ;
2018-11-30 03:59:03 +00:00
scrollTarget - > setWidgetResizable ( true ) ;
scrollTarget - > setWidget ( target ) ;
2018-09-27 00:33:08 +01:00
2022-09-06 05:20:14 +01:00
for ( QFrame * frame : frames ) {
2018-11-13 17:36:34 +00:00
layout - > addWidget ( frame ) ;
}
layout - > addStretch ( 1 ) ;
2022-10-18 01:37:26 +01:00
// Show the frames after the vertical spacer is added to avoid visual jank
// where the frame would stretch to the bottom of the layout.
for ( QFrame * frame : frames ) {
frame - > show ( ) ;
}
2018-09-27 00:33:08 +01:00
2018-11-13 17:36:34 +00:00
ui - > label_NoEvents - > hide ( ) ;
ui - > tabWidget_EventType - > show ( ) ;
}
2022-07-19 22:56:12 +01:00
else {
2018-11-13 17:36:34 +00:00
ui - > tabWidget_EventType - > hide ( ) ;
ui - > label_NoEvents - > show ( ) ;
2018-09-27 00:33:08 +01:00
}
}
2022-07-19 22:56:12 +01:00
Event : : Group MainWindow : : getEventGroupFromTabWidget ( QWidget * tab )
2018-11-30 03:59:03 +00:00
{
2022-07-19 22:56:12 +01:00
Event : : Group ret = Event : : Group : : None ;
2018-11-30 03:59:03 +00:00
if ( tab = = eventTabObjectWidget )
{
2022-07-19 22:56:12 +01:00
ret = Event : : Group : : Object ;
2018-11-30 03:59:03 +00:00
}
else if ( tab = = eventTabWarpWidget )
{
2022-07-19 22:56:12 +01:00
ret = Event : : Group : : Warp ;
2018-11-30 03:59:03 +00:00
}
else if ( tab = = eventTabTriggerWidget )
{
2022-07-19 22:56:12 +01:00
ret = Event : : Group : : Coord ;
2018-11-30 03:59:03 +00:00
}
else if ( tab = = eventTabBGWidget )
{
2022-07-19 22:56:12 +01:00
ret = Event : : Group : : Bg ;
2018-11-30 03:59:03 +00:00
}
else if ( tab = = eventTabHealspotWidget )
{
2022-07-19 22:56:12 +01:00
ret = Event : : Group : : Heal ;
2018-11-30 03:59:03 +00:00
}
return ret ;
}
2020-08-17 18:39:15 +01:00
void MainWindow : : eventTabChanged ( int index ) {
if ( editor - > map ) {
2022-07-19 22:56:12 +01:00
Event : : Group group = getEventGroupFromTabWidget ( ui - > tabWidget_EventType - > widget ( index ) ) ;
2018-11-28 01:39:57 +00:00
DraggablePixmapItem * selectedEvent = nullptr ;
2022-08-31 23:53:07 +01:00
switch ( group ) {
case Event : : Group : : Object :
2018-11-28 01:39:57 +00:00
selectedEvent = selectedObject ;
2020-08-17 18:39:15 +01:00
ui - > newEventToolButton - > setDefaultAction ( ui - > newEventToolButton - > newObjectAction ) ;
2022-08-31 23:53:07 +01:00
break ;
case Event : : Group : : Warp :
2018-11-28 01:39:57 +00:00
selectedEvent = selectedWarp ;
2020-08-17 18:39:15 +01:00
ui - > newEventToolButton - > setDefaultAction ( ui - > newEventToolButton - > newWarpAction ) ;
2022-08-31 23:53:07 +01:00
break ;
case Event : : Group : : Coord :
2018-11-28 01:39:57 +00:00
selectedEvent = selectedTrigger ;
2020-08-17 18:39:15 +01:00
ui - > newEventToolButton - > setDefaultAction ( ui - > newEventToolButton - > newTriggerAction ) ;
2022-08-31 23:53:07 +01:00
break ;
case Event : : Group : : Bg :
2018-11-28 01:39:57 +00:00
selectedEvent = selectedBG ;
2020-08-17 18:39:15 +01:00
ui - > newEventToolButton - > setDefaultAction ( ui - > newEventToolButton - > newSignAction ) ;
2022-08-31 23:53:07 +01:00
break ;
case Event : : Group : : Heal :
2020-08-17 18:39:15 +01:00
selectedEvent = selectedHealspot ;
2022-08-31 23:53:07 +01:00
break ;
2022-10-18 17:29:07 +01:00
default :
break ;
2020-08-17 18:39:15 +01:00
}
if ( ! isProgrammaticEventTabChange ) {
if ( ! selectedEvent & & editor - > map - > events . value ( group ) . count ( ) ) {
2018-11-30 03:59:03 +00:00
Event * event = editor - > map - > events . value ( group ) . at ( 0 ) ;
for ( QGraphicsItem * child : editor - > events_group - > childItems ( ) ) {
DraggablePixmapItem * item = static_cast < DraggablePixmapItem * > ( child ) ;
if ( item - > event = = event ) {
2020-08-17 18:39:15 +01:00
selectedEvent = item ;
2018-11-28 01:39:57 +00:00
break ;
}
}
}
2020-08-17 18:39:15 +01:00
if ( selectedEvent ) editor - > selectMapEvent ( selectedEvent ) ;
2018-11-28 01:39:57 +00:00
}
2018-09-27 00:33:08 +01:00
}
2018-11-28 01:39:57 +00:00
isProgrammaticEventTabChange = false ;
}
2019-01-06 18:53:31 +00:00
void MainWindow : : on_horizontalSlider_CollisionTransparency_valueChanged ( int value ) {
this - > editor - > collisionOpacity = static_cast < qreal > ( value ) / 100 ;
porymapConfig . setCollisionOpacity ( value ) ;
this - > editor - > collision_item - > draw ( true ) ;
}
2020-07-31 22:12:08 +01:00
void MainWindow : : on_toolButton_deleteObject_clicked ( ) {
if ( ui - > mainTabBar - > currentIndex ( ) ! = 1 ) {
// do not delete an event when not on event tab
return ;
}
2018-09-27 00:33:08 +01:00
if ( editor & & editor - > selected_events ) {
if ( editor - > selected_events - > length ( ) ) {
2020-08-01 00:16:16 +01:00
DraggablePixmapItem * nextSelectedEvent = nullptr ;
2020-07-31 18:24:58 +01:00
QList < Event * > selectedEvents ;
2020-08-04 01:49:00 +01:00
int numDeleted = 0 ;
2018-09-27 00:33:08 +01:00
for ( DraggablePixmapItem * item : * editor - > selected_events ) {
2022-07-19 22:56:12 +01:00
Event : : Group event_group = item - > event - > getEventGroup ( ) ;
if ( event_group ! = Event : : Group : : Heal ) {
2022-10-16 23:37:51 +01:00
numDeleted + + ;
2020-07-31 18:24:58 +01:00
item - > event - > setPixmapItem ( item ) ;
selectedEvents . append ( item - > event ) ;
2018-09-27 00:33:08 +01:00
}
else { // don't allow deletion of heal locations
2022-07-19 22:56:12 +01:00
logWarn ( QString ( " Cannot delete event of type '%1' " ) . arg ( Event : : eventTypeToString ( item - > event - > getEventType ( ) ) ) ) ;
2018-09-27 00:33:08 +01:00
}
}
2020-08-04 05:58:43 +01:00
if ( numDeleted ) {
2022-10-16 23:37:51 +01:00
// Get the index for the event that should be selected after this event has been deleted.
// Select event at next smallest index when deleting a single event.
// If deleting multiple events, just let editor work out next selected.
if ( numDeleted = = 1 ) {
Event : : Group event_group = selectedEvents [ 0 ] - > getEventGroup ( ) ;
int index = editor - > map - > events . value ( event_group ) . indexOf ( selectedEvents [ 0 ] ) ;
if ( index ! = editor - > map - > events . value ( event_group ) . size ( ) - 1 )
index + + ;
else
index - - ;
Event * event = nullptr ;
if ( index > = 0 )
event = editor - > map - > events . value ( event_group ) . at ( index ) ;
for ( QGraphicsItem * child : editor - > events_group - > childItems ( ) ) {
DraggablePixmapItem * event_item = static_cast < DraggablePixmapItem * > ( child ) ;
if ( event_item - > event = = event ) {
nextSelectedEvent = event_item ;
break ;
}
}
}
2020-08-04 05:58:43 +01:00
editor - > map - > editHistory . push ( new EventDelete ( editor , editor - > map , selectedEvents , nextSelectedEvent ? nextSelectedEvent - > event : nullptr ) ) ;
}
2018-09-27 00:33:08 +01:00
}
}
}
void MainWindow : : on_toolButton_Paint_clicked ( )
{
2020-05-18 02:25:28 +01:00
if ( ui - > mainTabBar - > currentIndex ( ) = = 0 )
editor - > map_edit_mode = " paint " ;
else
editor - > obj_edit_mode = " paint " ;
2018-09-27 00:33:08 +01:00
editor - > settings - > mapCursor = QCursor ( QPixmap ( " :/icons/pencil_cursor.ico " ) , 10 , 10 ) ;
2019-04-06 04:22:07 +01:00
// do not stop single tile mode when editing collision
2021-12-10 21:52:17 +00:00
if ( ui - > mapViewTab - > currentIndex ( ) = = 0 )
2019-04-06 04:22:07 +01:00
editor - > cursorMapTileRect - > stopSingleTileMode ( ) ;
2018-09-27 19:27:57 +01:00
2020-10-11 17:07:11 +01:00
ui - > graphicsView_Map - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
ui - > graphicsView_Map - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
QScroller : : ungrabGesture ( ui - > graphicsView_Map ) ;
2021-02-12 22:10:25 +00:00
ui - > graphicsView_Map - > setViewportUpdateMode ( QGraphicsView : : ViewportUpdateMode : : MinimalViewportUpdate ) ;
2018-09-27 00:33:08 +01:00
checkToolButtons ( ) ;
}
void MainWindow : : on_toolButton_Select_clicked ( )
{
2020-05-18 02:25:28 +01:00
if ( ui - > mainTabBar - > currentIndex ( ) = = 0 )
editor - > map_edit_mode = " select " ;
else
editor - > obj_edit_mode = " select " ;
2020-01-02 19:59:31 +00:00
editor - > settings - > mapCursor = QCursor ( ) ;
2019-01-11 14:52:35 +00:00
editor - > cursorMapTileRect - > setSingleTileMode ( ) ;
2018-09-27 19:27:57 +01:00
2020-10-11 17:07:11 +01:00
ui - > graphicsView_Map - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
ui - > graphicsView_Map - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
QScroller : : ungrabGesture ( ui - > graphicsView_Map ) ;
2021-02-12 22:10:25 +00:00
ui - > graphicsView_Map - > setViewportUpdateMode ( QGraphicsView : : ViewportUpdateMode : : MinimalViewportUpdate ) ;
2018-09-27 00:33:08 +01:00
checkToolButtons ( ) ;
}
void MainWindow : : on_toolButton_Fill_clicked ( )
{
2020-05-18 02:25:28 +01:00
if ( ui - > mainTabBar - > currentIndex ( ) = = 0 )
editor - > map_edit_mode = " fill " ;
else
editor - > obj_edit_mode = " fill " ;
2018-09-27 00:33:08 +01:00
editor - > settings - > mapCursor = QCursor ( QPixmap ( " :/icons/fill_color_cursor.ico " ) , 10 , 10 ) ;
2019-01-11 14:52:35 +00:00
editor - > cursorMapTileRect - > setSingleTileMode ( ) ;
2018-09-27 19:27:57 +01:00
2020-10-11 17:07:11 +01:00
ui - > graphicsView_Map - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
ui - > graphicsView_Map - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
QScroller : : ungrabGesture ( ui - > graphicsView_Map ) ;
2021-02-12 22:10:25 +00:00
ui - > graphicsView_Map - > setViewportUpdateMode ( QGraphicsView : : ViewportUpdateMode : : MinimalViewportUpdate ) ;
2018-09-27 00:33:08 +01:00
checkToolButtons ( ) ;
}
void MainWindow : : on_toolButton_Dropper_clicked ( )
{
2020-05-18 02:25:28 +01:00
if ( ui - > mainTabBar - > currentIndex ( ) = = 0 )
editor - > map_edit_mode = " pick " ;
else
editor - > obj_edit_mode = " pick " ;
2018-09-27 00:33:08 +01:00
editor - > settings - > mapCursor = QCursor ( QPixmap ( " :/icons/pipette_cursor.ico " ) , 10 , 10 ) ;
2019-01-11 14:52:35 +00:00
editor - > cursorMapTileRect - > setSingleTileMode ( ) ;
2018-09-27 00:33:08 +01:00
2020-10-11 17:07:11 +01:00
ui - > graphicsView_Map - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
ui - > graphicsView_Map - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
QScroller : : ungrabGesture ( ui - > graphicsView_Map ) ;
2021-02-12 22:10:25 +00:00
ui - > graphicsView_Map - > setViewportUpdateMode ( QGraphicsView : : ViewportUpdateMode : : MinimalViewportUpdate ) ;
2018-09-27 00:33:08 +01:00
checkToolButtons ( ) ;
}
void MainWindow : : on_toolButton_Move_clicked ( )
{
2020-05-18 02:25:28 +01:00
if ( ui - > mainTabBar - > currentIndex ( ) = = 0 )
editor - > map_edit_mode = " move " ;
else
editor - > obj_edit_mode = " move " ;
2018-09-27 00:33:08 +01:00
editor - > settings - > mapCursor = QCursor ( QPixmap ( " :/icons/move.ico " ) , 7 , 7 ) ;
2019-01-11 14:52:35 +00:00
editor - > cursorMapTileRect - > setSingleTileMode ( ) ;
2018-09-27 19:27:57 +01:00
2020-10-11 17:07:11 +01:00
ui - > graphicsView_Map - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAlwaysOff ) ;
ui - > graphicsView_Map - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAlwaysOff ) ;
QScroller : : grabGesture ( ui - > graphicsView_Map , QScroller : : LeftMouseButtonGesture ) ;
2021-02-12 22:10:25 +00:00
ui - > graphicsView_Map - > setViewportUpdateMode ( QGraphicsView : : ViewportUpdateMode : : FullViewportUpdate ) ;
2018-09-27 19:27:57 +01:00
2018-09-27 00:33:08 +01:00
checkToolButtons ( ) ;
}
void MainWindow : : on_toolButton_Shift_clicked ( )
{
2020-05-18 02:25:28 +01:00
if ( ui - > mainTabBar - > currentIndex ( ) = = 0 )
editor - > map_edit_mode = " shift " ;
else
editor - > obj_edit_mode = " shift " ;
2018-09-27 00:33:08 +01:00
editor - > settings - > mapCursor = QCursor ( QPixmap ( " :/icons/shift_cursor.ico " ) , 10 , 10 ) ;
2019-01-11 14:52:35 +00:00
editor - > cursorMapTileRect - > setSingleTileMode ( ) ;
2018-09-27 00:33:08 +01:00
2020-10-11 17:07:11 +01:00
ui - > graphicsView_Map - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
ui - > graphicsView_Map - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
QScroller : : ungrabGesture ( ui - > graphicsView_Map ) ;
2021-02-12 22:10:25 +00:00
ui - > graphicsView_Map - > setViewportUpdateMode ( QGraphicsView : : ViewportUpdateMode : : MinimalViewportUpdate ) ;
2018-09-27 00:33:08 +01:00
checkToolButtons ( ) ;
}
void MainWindow : : checkToolButtons ( ) {
2020-05-18 02:25:28 +01:00
QString edit_mode ;
2020-10-24 12:45:08 +01:00
if ( ui - > mainTabBar - > currentIndex ( ) = = 0 ) {
2020-05-18 02:25:28 +01:00
edit_mode = editor - > map_edit_mode ;
2020-10-24 12:45:08 +01:00
} else {
2020-05-18 02:25:28 +01:00
edit_mode = editor - > obj_edit_mode ;
2020-10-24 12:45:08 +01:00
if ( edit_mode = = " select " & & editor - > map_ruler )
editor - > map_ruler - > setEnabled ( true ) ;
else if ( editor - > map_ruler )
editor - > map_ruler - > setEnabled ( false ) ;
}
2020-10-02 19:06:58 +01:00
2020-05-18 02:25:28 +01:00
ui - > toolButton_Paint - > setChecked ( edit_mode = = " paint " ) ;
ui - > toolButton_Select - > setChecked ( edit_mode = = " select " ) ;
ui - > toolButton_Fill - > setChecked ( edit_mode = = " fill " ) ;
ui - > toolButton_Dropper - > setChecked ( edit_mode = = " pick " ) ;
ui - > toolButton_Move - > setChecked ( edit_mode = = " move " ) ;
ui - > toolButton_Shift - > setChecked ( edit_mode = = " shift " ) ;
2018-09-27 00:33:08 +01:00
}
2020-04-21 20:12:20 +01:00
void MainWindow : : clickToolButtonFromEditMode ( QString editMode ) {
if ( editMode = = " paint " ) {
on_toolButton_Paint_clicked ( ) ;
} else if ( editMode = = " select " ) {
on_toolButton_Select_clicked ( ) ;
} else if ( editMode = = " fill " ) {
on_toolButton_Fill_clicked ( ) ;
} else if ( editMode = = " pick " ) {
on_toolButton_Dropper_clicked ( ) ;
} else if ( editMode = = " move " ) {
on_toolButton_Move_clicked ( ) ;
} else if ( editMode = = " shift " ) {
on_toolButton_Shift_clicked ( ) ;
}
}
2018-09-27 00:33:08 +01:00
void MainWindow : : onLoadMapRequested ( QString mapName , QString fromMapName ) {
2018-12-20 23:30:35 +00:00
if ( ! setMap ( mapName , true ) ) {
2020-02-12 17:23:28 +00:00
QMessageBox msgBox ( this ) ;
2020-02-12 21:45:21 +00:00
QString errorMsg = QString ( " There was an error opening map %1. Please see %2 for full error details. \n \n %3 " )
2020-02-12 17:23:28 +00:00
. arg ( mapName )
. arg ( getLogPath ( ) )
. arg ( getMostRecentError ( ) ) ;
msgBox . critical ( nullptr , " Error Opening Map " , errorMsg ) ;
2018-12-20 23:30:35 +00:00
return ;
}
2018-09-27 00:33:08 +01:00
editor - > setSelectedConnectionFromMap ( fromMapName ) ;
}
2020-08-27 01:42:42 +01:00
void MainWindow : : onMapChanged ( Map * ) {
2018-09-27 00:33:08 +01:00
updateMapList ( ) ;
}
void MainWindow : : onMapNeedsRedrawing ( ) {
redrawMapScene ( ) ;
}
2020-06-06 14:51:36 +01:00
void MainWindow : : onMapCacheCleared ( ) {
editor - > map = nullptr ;
}
2018-10-03 01:01:15 +01:00
void MainWindow : : onTilesetsSaved ( QString primaryTilesetLabel , QString secondaryTilesetLabel ) {
2020-07-02 03:08:36 +01:00
// If saved tilesets are currently in-use, update them and redraw
// Otherwise overwrite the cache for the saved tileset
bool updated = false ;
if ( primaryTilesetLabel = = this - > editor - > map - > layout - > tileset_primary_label ) {
this - > editor - > updatePrimaryTileset ( primaryTilesetLabel , true ) ;
2021-11-30 22:24:46 +00:00
Scripting : : cb_TilesetUpdated ( primaryTilesetLabel ) ;
2020-07-02 03:08:36 +01:00
updated = true ;
} else {
this - > editor - > project - > getTileset ( primaryTilesetLabel , true ) ;
}
if ( secondaryTilesetLabel = = this - > editor - > map - > layout - > tileset_secondary_label ) {
this - > editor - > updateSecondaryTileset ( secondaryTilesetLabel , true ) ;
2021-11-30 22:24:46 +00:00
Scripting : : cb_TilesetUpdated ( secondaryTilesetLabel ) ;
2020-07-02 03:08:36 +01:00
updated = true ;
} else {
this - > editor - > project - > getTileset ( secondaryTilesetLabel , true ) ;
}
if ( updated )
redrawMapScene ( ) ;
2018-10-03 01:01:15 +01:00
}
2020-05-11 15:45:11 +01:00
void MainWindow : : onWildMonDataChanged ( ) {
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2020-05-11 15:45:11 +01:00
}
2020-10-26 03:49:00 +00:00
void MainWindow : : onMapRulerStatusChanged ( const QString & status ) {
if ( status . isEmpty ( ) ) {
label_MapRulerStatus - > hide ( ) ;
} else if ( label_MapRulerStatus - > parentWidget ( ) ) {
label_MapRulerStatus - > setText ( status ) ;
label_MapRulerStatus - > adjustSize ( ) ;
label_MapRulerStatus - > show ( ) ;
label_MapRulerStatus - > move ( label_MapRulerStatus - > parentWidget ( ) - > mapToGlobal ( QPoint ( 6 , 6 ) ) ) ;
}
}
void MainWindow : : moveEvent ( QMoveEvent * event ) {
QMainWindow : : moveEvent ( event ) ;
2021-11-05 19:39:19 +00:00
if ( label_MapRulerStatus & & label_MapRulerStatus - > isVisible ( ) & & label_MapRulerStatus - > parentWidget ( ) )
2020-10-26 03:49:00 +00:00
label_MapRulerStatus - > move ( label_MapRulerStatus - > parentWidget ( ) - > mapToGlobal ( QPoint ( 6 , 6 ) ) ) ;
}
2020-04-18 19:07:41 +01:00
void MainWindow : : on_action_Export_Map_Image_triggered ( ) {
2021-01-18 21:13:51 +00:00
showExportMapImageWindow ( ImageExporterMode : : Normal ) ;
2020-04-18 19:07:41 +01:00
}
void MainWindow : : on_actionExport_Stitched_Map_Image_triggered ( ) {
2021-01-18 21:13:51 +00:00
showExportMapImageWindow ( ImageExporterMode : : Stitch ) ;
2020-04-18 19:07:41 +01:00
}
2021-01-18 21:13:51 +00:00
void MainWindow : : on_actionExport_Map_Timelapse_Image_triggered ( ) {
showExportMapImageWindow ( ImageExporterMode : : Timelapse ) ;
}
2020-09-19 20:05:27 +01:00
void MainWindow : : on_actionImport_Map_from_Advance_Map_1_92_triggered ( ) {
importMapFromAdvanceMap1_92 ( ) ;
}
void MainWindow : : importMapFromAdvanceMap1_92 ( )
{
QString filepath = QFileDialog : : getOpenFileName (
this ,
QString ( " Import Map from Advance Map 1.92 " ) ,
this - > editor - > project - > root ,
" Advance Map 1.92 Map Files (*.map) " ) ;
if ( filepath . isEmpty ( ) ) {
return ;
}
MapParser parser ;
bool error = false ;
MapLayout * mapLayout = parser . parse ( filepath , & error , editor - > project ) ;
if ( error ) {
QMessageBox msgBox ( this ) ;
msgBox . setText ( " Failed to import map from Advance Map 1.92 .map file. " ) ;
QString message = QString ( " The .map file could not be processed. View porymap.log for specific errors. " ) ;
msgBox . setInformativeText ( message ) ;
msgBox . setDefaultButton ( QMessageBox : : Ok ) ;
msgBox . setIcon ( QMessageBox : : Icon : : Critical ) ;
msgBox . exec ( ) ;
return ;
}
2022-10-24 21:18:50 +01:00
openNewMapPopupWindow ( ) ;
this - > newMapPrompt - > init ( mapLayout ) ;
2020-09-19 20:05:27 +01:00
}
2021-01-18 21:13:51 +00:00
void MainWindow : : showExportMapImageWindow ( ImageExporterMode mode ) {
2020-08-03 22:37:54 +01:00
if ( ! editor - > project ) return ;
2020-04-18 19:07:41 +01:00
if ( this - > mapImageExporter )
delete this - > mapImageExporter ;
2021-01-18 21:13:51 +00:00
this - > mapImageExporter = new MapImageExporter ( this , this - > editor , mode ) ;
2020-04-18 19:07:41 +01:00
this - > mapImageExporter - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
2019-05-21 03:08:04 +01:00
if ( ! this - > mapImageExporter - > isVisible ( ) ) {
this - > mapImageExporter - > show ( ) ;
} else if ( this - > mapImageExporter - > isMinimized ( ) ) {
this - > mapImageExporter - > showNormal ( ) ;
} else {
this - > mapImageExporter - > activateWindow ( ) ;
2018-09-27 00:33:08 +01:00
}
}
2021-02-06 00:43:49 +00:00
void MainWindow : : on_comboBox_ConnectionDirection_currentTextChanged ( const QString & direction )
2018-09-27 00:33:08 +01:00
{
editor - > updateCurrentConnectionDirection ( direction ) ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2018-09-27 00:33:08 +01:00
}
void MainWindow : : on_spinBox_ConnectionOffset_valueChanged ( int offset )
{
editor - > updateConnectionOffset ( offset ) ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2018-09-27 00:33:08 +01:00
}
2019-09-21 21:59:14 +01:00
void MainWindow : : on_comboBox_ConnectedMap_currentTextChanged ( const QString & mapName )
2018-09-27 00:33:08 +01:00
{
2021-09-08 03:40:07 +01:00
if ( editor - > project - > mapNames . contains ( mapName ) ) {
2019-09-21 21:59:14 +01:00
editor - > setConnectionMap ( mapName ) ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2021-09-08 03:40:07 +01:00
}
2018-09-27 00:33:08 +01:00
}
void MainWindow : : on_pushButton_AddConnection_clicked ( )
{
editor - > addNewConnection ( ) ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2018-09-27 00:33:08 +01:00
}
void MainWindow : : on_pushButton_RemoveConnection_clicked ( )
{
editor - > removeCurrentConnection ( ) ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2018-09-27 00:33:08 +01:00
}
2019-06-20 17:40:36 +01:00
void MainWindow : : on_pushButton_NewWildMonGroup_clicked ( ) {
2019-09-11 13:42:06 +01:00
editor - > addNewWildMonGroup ( this ) ;
2019-06-20 17:40:36 +01:00
}
2020-11-14 03:00:09 +00:00
void MainWindow : : on_pushButton_DeleteWildMonGroup_clicked ( ) {
editor - > deleteWildMonGroup ( ) ;
}
2019-06-20 17:40:36 +01:00
void MainWindow : : on_pushButton_ConfigureEncountersJSON_clicked ( ) {
2019-09-11 13:42:06 +01:00
editor - > configureEncounterJSON ( this ) ;
2019-06-20 17:40:36 +01:00
}
2019-09-21 21:59:14 +01:00
void MainWindow : : on_comboBox_DiveMap_currentTextChanged ( const QString & mapName )
2018-09-27 00:33:08 +01:00
{
2021-09-08 03:40:07 +01:00
if ( editor - > project - > mapNames . contains ( mapName ) ) {
2019-09-21 21:59:14 +01:00
editor - > updateDiveMap ( mapName ) ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2021-09-08 03:40:07 +01:00
}
2018-09-27 00:33:08 +01:00
}
2019-09-21 21:59:14 +01:00
void MainWindow : : on_comboBox_EmergeMap_currentTextChanged ( const QString & mapName )
2018-09-27 00:33:08 +01:00
{
2021-09-08 03:40:07 +01:00
if ( editor - > project - > mapNames . contains ( mapName ) ) {
2019-09-21 21:59:14 +01:00
editor - > updateEmergeMap ( mapName ) ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2021-09-08 03:40:07 +01:00
}
2018-09-27 00:33:08 +01:00
}
2019-09-21 21:59:14 +01:00
void MainWindow : : on_comboBox_PrimaryTileset_currentTextChanged ( const QString & tilesetLabel )
2018-09-27 00:33:08 +01:00
{
2022-10-23 23:59:59 +01:00
if ( editor - > project - > primaryTilesetLabels . contains ( tilesetLabel ) & & editor - > map ) {
2019-09-21 21:59:14 +01:00
editor - > updatePrimaryTileset ( tilesetLabel ) ;
2020-05-21 01:21:18 +01:00
redrawMapScene ( ) ;
2019-09-21 21:59:14 +01:00
on_horizontalSlider_MetatileZoom_valueChanged ( ui - > horizontalSlider_MetatileZoom - > value ( ) ) ;
2020-07-02 00:31:09 +01:00
updateTilesetEditor ( ) ;
2022-09-10 02:09:28 +01:00
prefab . updatePrefabUi ( editor - > map ) ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2019-09-21 21:59:14 +01:00
}
2018-09-27 00:33:08 +01:00
}
2019-09-21 21:59:14 +01:00
void MainWindow : : on_comboBox_SecondaryTileset_currentTextChanged ( const QString & tilesetLabel )
2018-09-27 00:33:08 +01:00
{
2022-10-23 23:59:59 +01:00
if ( editor - > project - > secondaryTilesetLabels . contains ( tilesetLabel ) & & editor - > map ) {
2019-09-21 21:59:14 +01:00
editor - > updateSecondaryTileset ( tilesetLabel ) ;
2020-05-21 01:21:18 +01:00
redrawMapScene ( ) ;
2019-09-21 21:59:14 +01:00
on_horizontalSlider_MetatileZoom_valueChanged ( ui - > horizontalSlider_MetatileZoom - > value ( ) ) ;
2020-07-02 00:31:09 +01:00
updateTilesetEditor ( ) ;
2022-09-10 02:09:28 +01:00
prefab . updatePrefabUi ( editor - > map ) ;
2021-09-08 22:25:21 +01:00
markMapEdited ( ) ;
2019-09-21 21:59:14 +01:00
}
2018-09-27 00:33:08 +01:00
}
2020-03-14 07:44:55 +00:00
void MainWindow : : on_pushButton_ChangeDimensions_clicked ( )
2018-09-27 00:33:08 +01:00
{
QDialog dialog ( this , Qt : : WindowTitleHint | Qt : : WindowCloseButtonHint ) ;
dialog . setWindowTitle ( " Change Map Dimensions " ) ;
dialog . setWindowModality ( Qt : : NonModal ) ;
QFormLayout form ( & dialog ) ;
QSpinBox * widthSpinBox = new QSpinBox ( ) ;
QSpinBox * heightSpinBox = new QSpinBox ( ) ;
2020-03-14 07:44:55 +00:00
QSpinBox * bwidthSpinBox = new QSpinBox ( ) ;
QSpinBox * bheightSpinBox = new QSpinBox ( ) ;
2018-09-27 00:33:08 +01:00
widthSpinBox - > setMinimum ( 1 ) ;
heightSpinBox - > setMinimum ( 1 ) ;
2020-03-14 07:44:55 +00:00
bwidthSpinBox - > setMinimum ( 1 ) ;
bheightSpinBox - > setMinimum ( 1 ) ;
2020-05-16 21:57:03 +01:00
widthSpinBox - > setMaximum ( editor - > project - > getMaxMapWidth ( ) ) ;
heightSpinBox - > setMaximum ( editor - > project - > getMaxMapHeight ( ) ) ;
2022-08-29 17:44:17 +01:00
bwidthSpinBox - > setMaximum ( MAX_BORDER_WIDTH ) ;
bheightSpinBox - > setMaximum ( MAX_BORDER_HEIGHT ) ;
2018-09-27 00:33:08 +01:00
widthSpinBox - > setValue ( editor - > map - > getWidth ( ) ) ;
heightSpinBox - > setValue ( editor - > map - > getHeight ( ) ) ;
2020-03-14 07:44:55 +00:00
bwidthSpinBox - > setValue ( editor - > map - > getBorderWidth ( ) ) ;
bheightSpinBox - > setValue ( editor - > map - > getBorderHeight ( ) ) ;
if ( projectConfig . getUseCustomBorderSize ( ) ) {
form . addRow ( new QLabel ( " Map Width " ) , widthSpinBox ) ;
form . addRow ( new QLabel ( " Map Height " ) , heightSpinBox ) ;
form . addRow ( new QLabel ( " Border Width " ) , bwidthSpinBox ) ;
form . addRow ( new QLabel ( " Border Height " ) , bheightSpinBox ) ;
} else {
form . addRow ( new QLabel ( " Width " ) , widthSpinBox ) ;
form . addRow ( new QLabel ( " Height " ) , heightSpinBox ) ;
}
2018-09-27 00:33:08 +01:00
QLabel * errorLabel = new QLabel ( ) ;
2022-10-25 06:59:48 +01:00
errorLabel - > setStyleSheet ( " QLabel { color: red } " ) ;
2018-09-27 00:33:08 +01:00
errorLabel - > setVisible ( false ) ;
QDialogButtonBox buttonBox ( QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel , Qt : : Horizontal , & dialog ) ;
form . addRow ( & buttonBox ) ;
2020-05-16 21:57:03 +01:00
connect ( & buttonBox , & QDialogButtonBox : : accepted , [ & dialog , & widthSpinBox , & heightSpinBox , & errorLabel , this ] ( ) {
2018-09-27 00:33:08 +01:00
// Ensure width and height are an acceptable size.
// The maximum number of metatiles in a map is the following:
// max = (width + 15) * (height + 14)
2020-05-16 21:57:03 +01:00
// This limit can be found in fieldmap.c in pokeruby/pokeemerald/pokefirered.
int numMetatiles = editor - > project - > getMapDataSize ( widthSpinBox - > value ( ) , heightSpinBox - > value ( ) ) ;
int maxMetatiles = editor - > project - > getMaxMapDataSize ( ) ;
if ( numMetatiles < = maxMetatiles ) {
2018-09-27 00:33:08 +01:00
dialog . accept ( ) ;
} else {
QString errorText = QString ( " Error: The specified width and height are too large. \n "
2020-05-16 21:57:03 +01:00
" The maximum map width and height is the following: (width + 15) * (height + 14) <= %1 \n "
" The specified map width and height was: (%2 + 15) * (%3 + 14) = %4 " )
. arg ( maxMetatiles )
2018-09-27 00:33:08 +01:00
. arg ( widthSpinBox - > value ( ) )
. arg ( heightSpinBox - > value ( ) )
. arg ( numMetatiles ) ;
errorLabel - > setText ( errorText ) ;
errorLabel - > setVisible ( true ) ;
}
} ) ;
2021-02-14 14:16:23 +00:00
connect ( & buttonBox , & QDialogButtonBox : : rejected , & dialog , & QDialog : : reject ) ;
2018-09-27 00:33:08 +01:00
form . addRow ( errorLabel ) ;
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
2020-07-29 20:51:04 +01:00
Map * map = editor - > map ;
2021-02-14 21:34:17 +00:00
Blockdata oldMetatiles = map - > layout - > blockdata ;
Blockdata oldBorder = map - > layout - > border ;
2020-07-29 20:51:04 +01:00
QSize oldMapDimensions ( map - > getWidth ( ) , map - > getHeight ( ) ) ;
QSize oldBorderDimensions ( map - > getBorderWidth ( ) , map - > getBorderHeight ( ) ) ;
QSize newMapDimensions ( widthSpinBox - > value ( ) , heightSpinBox - > value ( ) ) ;
QSize newBorderDimensions ( bwidthSpinBox - > value ( ) , bheightSpinBox - > value ( ) ) ;
if ( oldMapDimensions ! = newMapDimensions | | oldBorderDimensions ! = newBorderDimensions ) {
2022-10-12 03:50:08 +01:00
editor - > map - > setDimensions ( newMapDimensions . width ( ) , newMapDimensions . height ( ) , true ) ;
editor - > map - > setBorderDimensions ( newBorderDimensions . width ( ) , newBorderDimensions . height ( ) , true ) ;
2021-02-14 23:14:04 +00:00
editor - > map - > editHistory . push ( new ResizeMap ( map ,
2020-07-29 20:51:04 +01:00
oldMapDimensions , newMapDimensions ,
2021-02-14 21:34:17 +00:00
oldMetatiles , map - > layout - > blockdata ,
2020-07-29 20:51:04 +01:00
oldBorderDimensions , newBorderDimensions ,
2021-02-14 21:34:17 +00:00
oldBorder , map - > layout - > border
2020-07-29 20:51:04 +01:00
) ) ;
}
2018-09-27 00:33:08 +01:00
}
}
void MainWindow : : on_checkBox_smartPaths_stateChanged ( int selected )
{
2019-01-11 14:52:35 +00:00
bool enabled = selected = = Qt : : Checked ;
editor - > settings - > smartPathsEnabled = enabled ;
if ( enabled ) {
2020-08-25 21:32:40 +01:00
editor - > cursorMapTileRect - > setSmartPathMode ( true ) ;
2019-01-11 14:52:35 +00:00
} else {
2020-08-25 21:32:40 +01:00
editor - > cursorMapTileRect - > setSmartPathMode ( false ) ;
2019-01-11 14:52:35 +00:00
}
2018-09-27 00:33:08 +01:00
}
void MainWindow : : on_checkBox_ToggleBorder_stateChanged ( int selected )
{
bool visible = selected ! = 0 ;
editor - > toggleBorderVisibility ( visible ) ;
}
2018-09-29 20:13:07 +01:00
void MainWindow : : on_actionTileset_Editor_triggered ( )
{
if ( ! this - > tilesetEditor ) {
2020-11-09 10:50:15 +00:00
initTilesetEditor ( ) ;
2018-09-29 20:13:07 +01:00
}
if ( ! this - > tilesetEditor - > isVisible ( ) ) {
this - > tilesetEditor - > show ( ) ;
2018-10-03 01:01:31 +01:00
} else if ( this - > tilesetEditor - > isMinimized ( ) ) {
this - > tilesetEditor - > showNormal ( ) ;
2018-09-29 20:13:07 +01:00
} else {
2022-10-05 16:55:43 +01:00
this - > tilesetEditor - > raise ( ) ;
2018-09-29 20:13:07 +01:00
this - > tilesetEditor - > activateWindow ( ) ;
}
2022-09-05 17:35:17 +01:00
MetatileSelection selection = this - > editor - > metatile_selector_item - > getMetatileSelection ( ) ;
this - > tilesetEditor - > selectMetatile ( selection . metatileItems . first ( ) . metatileId ) ;
2018-09-29 20:13:07 +01:00
}
2019-01-06 18:53:31 +00:00
2020-11-09 10:50:15 +00:00
void MainWindow : : initTilesetEditor ( ) {
this - > tilesetEditor = new TilesetEditor ( this - > editor - > project , this - > editor - > map , this ) ;
2021-02-14 14:16:23 +00:00
connect ( this - > tilesetEditor , & TilesetEditor : : tilesetsSaved , this , & MainWindow : : onTilesetsSaved ) ;
2020-11-09 10:50:15 +00:00
}
2019-01-08 15:30:36 +00:00
void MainWindow : : on_toolButton_ExpandAll_clicked ( )
{
if ( ui - > mapList ) {
ui - > mapList - > expandToDepth ( 0 ) ;
}
}
void MainWindow : : on_toolButton_CollapseAll_clicked ( )
{
if ( ui - > mapList ) {
ui - > mapList - > collapseAll ( ) ;
}
}
2019-01-08 16:28:20 +00:00
void MainWindow : : on_actionAbout_Porymap_triggered ( )
{
AboutPorymap * window = new AboutPorymap ( this ) ;
window - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
window - > show ( ) ;
}
2021-02-03 15:24:59 +00:00
void MainWindow : : on_actionOpen_Log_File_triggered ( ) {
const QString logPath = getLogPath ( ) ;
const int lineCount = ParseUtil : : textFileLineCount ( logPath ) ;
2022-08-31 23:53:07 +01:00
this - > editor - > openInTextEditor ( logPath , lineCount ) ;
2021-02-03 15:24:59 +00:00
}
2021-02-03 16:24:07 +00:00
void MainWindow : : on_actionOpen_Config_Folder_triggered ( ) {
2022-10-25 13:07:14 +01:00
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( QStandardPaths : : writableLocation ( QStandardPaths : : AppDataLocation ) ) ) ;
2021-02-03 16:24:07 +00:00
}
2020-11-16 12:39:42 +00:00
void MainWindow : : on_actionEdit_Preferences_triggered ( ) {
if ( ! preferenceEditor ) {
preferenceEditor = new PreferenceEditor ( this ) ;
2020-11-16 14:35:55 +00:00
connect ( preferenceEditor , & PreferenceEditor : : themeChanged ,
this , & MainWindow : : setTheme ) ;
connect ( preferenceEditor , & PreferenceEditor : : themeChanged ,
editor , & Editor : : maskNonVisibleConnectionTiles ) ;
2020-12-01 15:13:56 +00:00
connect ( preferenceEditor , & PreferenceEditor : : preferencesSaved ,
this , & MainWindow : : togglePreferenceSpecificUi ) ;
2019-08-14 22:39:23 +01:00
}
2020-11-16 12:39:42 +00:00
if ( ! preferenceEditor - > isVisible ( ) ) {
preferenceEditor - > show ( ) ;
} else if ( preferenceEditor - > isMinimized ( ) ) {
preferenceEditor - > showNormal ( ) ;
} else {
2022-10-05 16:55:43 +01:00
preferenceEditor - > raise ( ) ;
2020-11-16 12:39:42 +00:00
preferenceEditor - > activateWindow ( ) ;
}
}
2019-08-14 22:39:23 +01:00
2020-12-01 15:13:56 +00:00
void MainWindow : : togglePreferenceSpecificUi ( ) {
if ( porymapConfig . getTextEditorOpenFolder ( ) . isEmpty ( ) )
ui - > actionOpen_Project_in_Text_Editor - > setEnabled ( false ) ;
else
ui - > actionOpen_Project_in_Text_Editor - > setEnabled ( true ) ;
2019-08-14 22:39:23 +01:00
}
2019-02-03 16:38:45 +00:00
void MainWindow : : on_pushButton_AddCustomHeaderField_clicked ( )
{
2022-10-16 03:32:05 +01:00
bool ok ;
2022-10-19 00:52:35 +01:00
QJsonValue value = CustomAttributesTable : : pickType ( this , & ok ) ;
if ( ok ) {
CustomAttributesTable : : addAttribute ( this - > ui - > tableWidget_CustomHeaderFields , " " , value , true ) ;
this - > editor - > updateCustomMapHeaderValues ( this - > ui - > tableWidget_CustomHeaderFields ) ;
}
2019-02-03 16:38:45 +00:00
}
void MainWindow : : on_pushButton_DeleteCustomHeaderField_clicked ( )
{
2022-10-19 00:52:35 +01:00
if ( CustomAttributesTable : : deleteSelectedAttributes ( this - > ui - > tableWidget_CustomHeaderFields ) )
2019-02-03 16:38:45 +00:00
this - > editor - > updateCustomMapHeaderValues ( this - > ui - > tableWidget_CustomHeaderFields ) ;
}
2019-08-07 04:35:02 +01:00
void MainWindow : : on_tableWidget_CustomHeaderFields_cellChanged ( int , int )
2019-02-03 16:38:45 +00:00
{
this - > editor - > updateCustomMapHeaderValues ( this - > ui - > tableWidget_CustomHeaderFields ) ;
}
2019-02-09 23:19:11 +00:00
void MainWindow : : on_horizontalSlider_MetatileZoom_valueChanged ( int value ) {
2019-02-16 20:32:19 +00:00
porymapConfig . setMetatilesZoom ( value ) ;
2019-02-09 23:19:11 +00:00
double scale = pow ( 3.0 , static_cast < double > ( value - 30 ) / 30.0 ) ;
2020-08-16 00:30:46 +01:00
QTransform transform ;
transform . scale ( scale , scale ) ;
2019-02-09 23:19:11 +00:00
QSize size ( editor - > metatile_selector_item - > pixmap ( ) . width ( ) ,
editor - > metatile_selector_item - > pixmap ( ) . height ( ) ) ;
size * = scale ;
ui - > graphicsView_Metatiles - > setResizeAnchor ( QGraphicsView : : NoAnchor ) ;
2020-08-16 00:30:46 +01:00
ui - > graphicsView_Metatiles - > setTransform ( transform ) ;
2019-02-09 23:19:11 +00:00
ui - > graphicsView_Metatiles - > setFixedSize ( size . width ( ) + 2 , size . height ( ) + 2 ) ;
2019-02-25 20:09:36 +00:00
2020-08-16 00:30:46 +01:00
ui - > graphicsView_BorderMetatile - > setTransform ( transform ) ;
2019-02-25 20:09:36 +00:00
ui - > graphicsView_BorderMetatile - > setFixedSize ( ceil ( static_cast < double > ( editor - > selected_border_metatiles_item - > pixmap ( ) . width ( ) ) * scale ) + 2 ,
ceil ( static_cast < double > ( editor - > selected_border_metatiles_item - > pixmap ( ) . height ( ) ) * scale ) + 2 ) ;
2020-07-06 18:36:59 +01:00
redrawMetatileSelection ( ) ;
2019-02-09 23:19:11 +00:00
}
2019-01-07 19:46:27 +00:00
void MainWindow : : on_actionRegion_Map_Editor_triggered ( ) {
if ( ! this - > regionMapEditor ) {
2020-11-09 10:50:15 +00:00
if ( ! initRegionMapEditor ( ) ) {
2020-02-12 21:45:21 +00:00
return ;
}
2019-01-07 19:46:27 +00:00
}
if ( ! this - > regionMapEditor - > isVisible ( ) ) {
this - > regionMapEditor - > show ( ) ;
} else if ( this - > regionMapEditor - > isMinimized ( ) ) {
this - > regionMapEditor - > showNormal ( ) ;
} else {
2022-10-05 16:55:43 +01:00
this - > regionMapEditor - > raise ( ) ;
2019-01-07 19:46:27 +00:00
this - > regionMapEditor - > activateWindow ( ) ;
}
2019-01-05 22:59:57 +00:00
}
2022-09-08 02:38:30 +01:00
void MainWindow : : on_pushButton_CreatePrefab_clicked ( ) {
PrefabCreationDialog dialog ( this , this - > editor - > metatile_selector_item , this - > editor - > map ) ;
dialog . setWindowTitle ( " Create Prefab " ) ;
dialog . setWindowModality ( Qt : : NonModal ) ;
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
dialog . savePrefab ( ) ;
}
}
2020-11-09 10:50:15 +00:00
bool MainWindow : : initRegionMapEditor ( ) {
this - > regionMapEditor = new RegionMapEditor ( this , this - > editor - > project ) ;
2022-05-06 02:40:13 +01:00
this - > regionMapEditor - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
connect ( this - > regionMapEditor , & QObject : : destroyed , [ this ] ( ) {
this - > regionMapEditor = nullptr ;
} ) ;
2022-03-01 20:32:44 +00:00
bool success = this - > regionMapEditor - > load ( ) ;
2020-11-09 10:50:15 +00:00
if ( ! success ) {
delete this - > regionMapEditor ;
this - > regionMapEditor = nullptr ;
QMessageBox msgBox ( this ) ;
QString errorMsg = QString ( " There was an error opening the region map data. Please see %1 for full error details. \n \n %3 " )
. arg ( getLogPath ( ) )
. arg ( getMostRecentError ( ) ) ;
msgBox . critical ( nullptr , " Error Opening Region Map Editor " , errorMsg ) ;
return false ;
}
return true ;
}
2020-03-31 17:41:15 +01:00
void MainWindow : : closeSupplementaryWindows ( ) {
2022-04-29 02:42:47 +01:00
if ( this - > tilesetEditor ) {
2020-03-31 17:41:15 +01:00
delete this - > tilesetEditor ;
2022-04-29 02:42:47 +01:00
this - > tilesetEditor = nullptr ;
}
if ( this - > regionMapEditor ) {
2020-03-31 17:41:15 +01:00
delete this - > regionMapEditor ;
2022-04-29 02:42:47 +01:00
this - > regionMapEditor = nullptr ;
}
if ( this - > mapImageExporter ) {
2020-03-31 17:41:15 +01:00
delete this - > mapImageExporter ;
2022-04-29 02:42:47 +01:00
this - > mapImageExporter = nullptr ;
}
if ( this - > newMapPrompt ) {
delete this - > newMapPrompt ;
this - > newMapPrompt = nullptr ;
}
if ( this - > shortcutsEditor ) {
2020-11-09 10:50:15 +00:00
delete this - > shortcutsEditor ;
2022-04-29 02:42:47 +01:00
this - > shortcutsEditor = nullptr ;
}
2020-03-31 17:41:15 +01:00
}
2019-01-06 18:53:31 +00:00
void MainWindow : : closeEvent ( QCloseEvent * event ) {
2020-09-13 23:34:18 +01:00
if ( isProjectOpen ( ) ) {
if ( projectHasUnsavedChanges | | ( editor - > map & & editor - > map - > hasUnsavedChanges ( ) ) ) {
QMessageBox : : StandardButton result = QMessageBox : : question (
this , " porymap " , " The project has been modified, save changes? " ,
QMessageBox : : No | QMessageBox : : Yes | QMessageBox : : Cancel , QMessageBox : : Yes ) ;
if ( result = = QMessageBox : : Yes ) {
editor - > saveProject ( ) ;
} else if ( result = = QMessageBox : : No ) {
logWarn ( " Closing porymap with unsaved changes. " ) ;
} else if ( result = = QMessageBox : : Cancel ) {
event - > ignore ( ) ;
return ;
}
2019-08-07 15:48:07 +01:00
}
2020-09-13 23:34:18 +01:00
projectConfig . save ( ) ;
2022-09-01 05:57:31 +01:00
userConfig . save ( ) ;
2019-08-07 15:48:07 +01:00
}
2020-09-15 19:57:46 +01:00
porymapConfig . setMainGeometry (
2019-01-07 23:14:44 +00:00
this - > saveGeometry ( ) ,
this - > saveState ( ) ,
this - > ui - > splitter_map - > saveState ( ) ,
this - > ui - > splitter_main - > saveState ( )
) ;
2019-01-06 18:53:31 +00:00
porymapConfig . save ( ) ;
2020-11-09 10:50:15 +00:00
shortcutsConfig . save ( ) ;
2019-01-06 18:53:31 +00:00
QMainWindow : : closeEvent ( event ) ;
}