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"
# include "eventpropertiesframe.h"
2018-09-27 17:23:40 +01:00
# include "ui_eventpropertiesframe.h"
2018-09-27 00:33:08 +01:00
# include "bordermetatilespixmapitem.h"
# include "currentselectedmetatilespixmapitem.h"
2019-02-03 18:26:27 +00:00
# include "customattributestable.h"
2018-09-27 00:33:08 +01:00
# include <QFileDialog>
2019-08-14 22:39:23 +01:00
# include <QDirIterator>
2018-09-27 00:33:08 +01:00
# include <QStandardItemModel>
# include <QShortcut>
# include <QSpinBox>
# include <QTextEdit>
# include <QSpacerItem>
# include <QFont>
# include <QScrollBar>
# include <QPushButton>
# include <QMessageBox>
# include <QDialogButtonBox>
# include <QScroller>
# include <math.h>
# include <QProcess>
# include <QSysInfo>
# include <QDesktopServices>
2019-02-09 23:19:11 +00:00
# include <QMatrix>
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 " ) ;
2018-09-27 00:33:08 +01:00
QApplication : : setWindowIcon ( QIcon ( " :/icons/porymap-icon-1.ico " ) ) ;
ui - > setupUi ( this ) ;
2018-12-20 23:30:35 +00:00
this - > initWindow ( ) ;
if ( ! this - > openRecentProject ( ) ) {
// Re-initialize everything to a blank slate if opening the recent project failed.
this - > initWindow ( ) ;
}
2018-09-27 00:33:08 +01:00
on_toolButton_Paint_clicked ( ) ;
}
MainWindow : : ~ MainWindow ( )
{
delete ui ;
}
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 - > initExtraShortcuts ( ) ;
this - > initEditor ( ) ;
this - > initMiscHeapObjects ( ) ;
this - > initMapSortOrder ( ) ;
2019-01-07 23:14:44 +00:00
this - > restoreWindowState ( ) ;
2018-12-20 23:30:35 +00:00
}
2018-09-27 00:33:08 +01:00
void MainWindow : : initExtraShortcuts ( ) {
2018-10-04 17:03:33 +01:00
new QShortcut ( QKeySequence ( " Ctrl+Shift+Z " ) , this , SLOT ( redo ( ) ) ) ;
2018-09-27 19:27:57 +01:00
new QShortcut ( QKeySequence ( " Ctrl+0 " ) , this , SLOT ( resetMapViewScale ( ) ) ) ;
2020-01-16 01:44:01 +00:00
new QShortcut ( QKeySequence ( " Ctrl+G " ) , ui - > checkBox_ToggleGrid , SLOT ( toggle ( ) ) ) ;
2018-09-27 19:27:57 +01:00
ui - > actionZoom_In - > setShortcuts ( { QKeySequence ( " Ctrl++ " ) , QKeySequence ( " Ctrl+= " ) } ) ;
2018-09-27 00:33:08 +01:00
}
2018-10-05 23:39:50 +01:00
void MainWindow : : initCustomUI ( ) {
// Right-clicking on items in the map list tree view brings up a context menu.
ui - > mapList - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > mapList , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) ,
this , SLOT ( onOpenMapListContextMenu ( const QPoint & ) ) ) ;
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 ) ;
} ) ;
2018-10-05 23:39:50 +01:00
}
2018-09-27 00:33:08 +01:00
void MainWindow : : initExtraSignals ( ) {
connect ( ui - > newEventToolButton , SIGNAL ( newEventAdded ( QString ) ) , this , SLOT ( addNewEvent ( QString ) ) ) ;
2018-11-28 01:39:57 +00:00
connect ( ui - > tabWidget_EventType , & QTabWidget : : currentChanged , this , & MainWindow : : eventTabChanged ) ;
2018-09-27 00:33:08 +01:00
}
void MainWindow : : initEditor ( ) {
this - > editor = new Editor ( ui ) ;
2018-11-28 01:39:57 +00:00
connect ( this - > editor , SIGNAL ( objectsChanged ( ) ) , this , SLOT ( updateObjects ( ) ) ) ;
2018-09-27 00:33:08 +01:00
connect ( this - > editor , SIGNAL ( selectedObjectsChanged ( ) ) , this , SLOT ( updateSelectedObjects ( ) ) ) ;
connect ( this - > editor , SIGNAL ( loadMapRequested ( QString , QString ) ) , this , SLOT ( onLoadMapRequested ( QString , QString ) ) ) ;
connect ( this - > editor , SIGNAL ( tilesetChanged ( QString ) ) , this , SLOT ( onTilesetChanged ( QString ) ) ) ;
connect ( this - > editor , SIGNAL ( warpEventDoubleClicked ( QString , QString ) ) , this , SLOT ( openWarpMap ( QString , QString ) ) ) ;
connect ( this - > editor , SIGNAL ( currentMetatilesSelectionChanged ( ) ) , this , SLOT ( currentMetatilesSelectionChanged ( ) ) ) ;
2018-09-27 19:27:57 +01:00
connect ( this - > editor , & Editor : : wheelZoom , this , & MainWindow : : scaleMapView ) ;
2018-09-27 00:33:08 +01:00
this - > loadUserSettings ( ) ;
}
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 ) ;
connect ( ui - > toolButton_MapSortOrder , & QToolButton : : triggered , this , & MainWindow : : mapSortOrder_changed ) ;
QAction * sortOrder = ui - > toolButton_MapSortOrder - > menu ( ) - > actions ( ) [ mapSortOrder ] ;
ui - > toolButton_MapSortOrder - > setIcon ( sortOrder - > icon ( ) ) ;
sortOrder - > setChecked ( true ) ;
}
2018-12-26 18:20:51 +00:00
void MainWindow : : setProjectSpecificUIVisibility ( )
{
2019-07-03 21:21:48 +01:00
if ( ! projectConfig . getEncounterJsonActive ( ) )
ui - > tabWidget - > removeTab ( 4 ) ;
2018-12-26 18:20:51 +00:00
switch ( projectConfig . getBaseGameVersion ( ) )
{
case BaseGameVersion : : pokeruby :
ui - > checkBox_AllowRunning - > setVisible ( false ) ;
ui - > checkBox_AllowBiking - > setVisible ( false ) ;
ui - > checkBox_AllowEscapeRope - > setVisible ( false ) ;
2020-03-11 05:52:00 +00:00
ui - > spinBox_FloorNumber - > setVisible ( false ) ;
2018-12-26 18:20:51 +00:00
ui - > label_AllowRunning - > setVisible ( false ) ;
ui - > label_AllowBiking - > setVisible ( false ) ;
ui - > label_AllowEscapeRope - > setVisible ( false ) ;
2020-03-11 05:52:00 +00:00
ui - > label_FloorNumber - > setVisible ( false ) ;
2020-03-18 07:12:43 +00:00
ui - > actionRegion_Map_Editor - > setVisible ( true ) ;
2018-12-26 18:20:51 +00:00
break ;
case BaseGameVersion : : pokeemerald :
ui - > checkBox_AllowRunning - > setVisible ( true ) ;
ui - > checkBox_AllowBiking - > setVisible ( true ) ;
ui - > checkBox_AllowEscapeRope - > setVisible ( true ) ;
2020-03-11 05:52:00 +00:00
ui - > spinBox_FloorNumber - > setVisible ( false ) ;
2018-12-26 18:20:51 +00:00
ui - > label_AllowRunning - > setVisible ( true ) ;
ui - > label_AllowBiking - > setVisible ( true ) ;
ui - > label_AllowEscapeRope - > setVisible ( true ) ;
2020-03-11 05:52:00 +00:00
ui - > label_FloorNumber - > setVisible ( false ) ;
2020-03-18 07:12:43 +00:00
ui - > actionRegion_Map_Editor - > setVisible ( true ) ;
2018-12-26 18:20:51 +00:00
break ;
2019-08-07 04:35:02 +01:00
case BaseGameVersion : : pokefirered :
2020-03-11 05:52:00 +00:00
ui - > checkBox_AllowRunning - > setVisible ( true ) ;
ui - > checkBox_AllowBiking - > setVisible ( true ) ;
ui - > checkBox_AllowEscapeRope - > setVisible ( true ) ;
ui - > spinBox_FloorNumber - > setVisible ( true ) ;
ui - > label_AllowRunning - > setVisible ( true ) ;
ui - > label_AllowBiking - > setVisible ( true ) ;
ui - > label_AllowEscapeRope - > setVisible ( true ) ;
ui - > label_FloorNumber - > setVisible ( true ) ;
2020-03-12 16:30:37 +00:00
ui - > newEventToolButton - > newWeatherTriggerAction - > setVisible ( false ) ;
ui - > newEventToolButton - > newSecretBaseAction - > setVisible ( false ) ;
// TODO: pokefirered is not set up for the Region Map Editor and vice versa.
// porymap will crash on attempt. Remove below once resolved
ui - > actionRegion_Map_Editor - > setVisible ( false ) ;
2019-08-07 04:35:02 +01:00
break ;
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 ( ) ;
}
}
}
void MainWindow : : on_lineEdit_filterBox_textChanged ( const QString & arg1 )
{
mapListProxyModel - > setFilterRegExp ( QRegExp ( arg1 , Qt : : CaseInsensitive , QRegExp : : FixedString ) ) ;
2019-01-05 22:38:37 +00:00
if ( arg1 . isEmpty ( ) ) {
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 ( ) ;
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 ) ;
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 ( ) {
logInfo ( " Restoring window geometry from previous session. " ) ;
QMap < QString , QByteArray > geometry = porymapConfig . getGeometry ( ) ;
this - > restoreGeometry ( geometry . value ( " window_geometry " ) ) ;
this - > restoreState ( geometry . value ( " window_state " ) ) ;
this - > ui - > splitter_map - > restoreState ( geometry . value ( " map_splitter_state " ) ) ;
this - > ui - > splitter_events - > restoreState ( geometry . value ( " events_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 ( ) {
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
return true ;
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 ( ) ) {
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 ;
2018-12-25 21:26:13 +00:00
projectConfig . setProjectDir ( dir ) ;
projectConfig . load ( ) ;
2018-12-26 18:20:51 +00:00
this - > setProjectSpecificUIVisibility ( ) ;
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 ) {
editor - > project = new Project ;
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-02-12 16:22:40 +00:00
success = loadDataStructures ( ) & & populateMapList ( ) ;
2018-09-27 00:33:08 +01:00
}
2018-12-20 23:30:35 +00:00
if ( success ) {
2020-02-12 00:34:08 +00:00
setWindowTitle ( editor - > project - > getProjectTitle ( ) ) ;
2019-01-05 22:38:37 +00:00
this - > statusBar ( ) - > showMessage ( QString ( " Opened project %1 " ) . arg ( nativeDir ) ) ;
2018-12-20 23:30:35 +00:00
} else {
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 ) ;
2018-12-20 23:30:35 +00:00
}
return success ;
2018-09-27 00:33:08 +01:00
}
2018-10-05 07:02:40 +01:00
bool MainWindow : : isProjectOpen ( ) {
2020-02-12 00:34:08 +00:00
return editor ! = nullptr & & editor - > project ! = nullptr ;
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 ( ) ) {
2018-12-25 20:41:06 +00:00
QString recentMap = porymapConfig . 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 = " . " ;
2018-12-25 20:41:06 +00:00
if ( ! porymapConfig . getRecentMap ( ) . isNull ( ) & & porymapConfig . getRecentMap ( ) . length ( ) > 0 ) {
recent = porymapConfig . getRecentMap ( ) ;
2018-09-27 00:33:08 +01:00
}
QString dir = getExistingDirectory ( recent ) ;
if ( ! dir . isEmpty ( ) ) {
2018-12-25 20:41:06 +00:00
porymapConfig . setRecentProject ( dir ) ;
2020-02-12 17:23:28 +00:00
if ( ! openProject ( dir ) ) {
this - > initWindow ( ) ;
}
2018-09-27 00:33:08 +01:00
}
}
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
2018-09-27 00:33:08 +01:00
redrawMapScene ( ) ;
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
2019-09-09 23:24:30 +01:00
mapListProxyModel - > setFilterRegExp ( 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 ) ;
2018-09-27 19:27:57 +01:00
setWindowTitle ( map_name + " - " + editor - > project - > getProjectTitle ( ) ) ;
2018-09-27 00:33:08 +01:00
connect ( editor - > map , SIGNAL ( mapChanged ( Map * ) ) , this , SLOT ( onMapChanged ( Map * ) ) ) ;
connect ( editor - > map , SIGNAL ( mapNeedsRedrawing ( ) ) , this , SLOT ( onMapNeedsRedrawing ( ) ) ) ;
setRecentMap ( map_name ) ;
updateMapList ( ) ;
2018-10-03 01:01:18 +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 ;
2018-09-27 00:33:08 +01:00
on_tabWidget_currentChanged ( ui - > tabWidget - > currentIndex ( ) ) ;
2018-09-27 19:27:57 +01:00
double base = editor - > scale_base ;
double exp = editor - > scale_exp ;
int width = static_cast < int > ( ceil ( ( editor - > scene - > width ( ) ) * pow ( base , exp ) ) ) + 2 ;
int height = static_cast < int > ( ceil ( ( editor - > scene - > height ( ) ) * pow ( base , exp ) ) ) + 2 ;
2018-09-27 00:33:08 +01:00
ui - > graphicsView_Map - > setScene ( editor - > scene ) ;
ui - > graphicsView_Map - > setSceneRect ( editor - > scene - > sceneRect ( ) ) ;
2018-09-27 19:27:57 +01:00
ui - > graphicsView_Map - > setFixedSize ( width , height ) ;
2018-09-27 00:33:08 +01:00
ui - > graphicsView_Objects_Map - > setScene ( editor - > scene ) ;
ui - > graphicsView_Objects_Map - > setSceneRect ( editor - > scene - > sceneRect ( ) ) ;
2018-09-27 19:27:57 +01:00
ui - > graphicsView_Objects_Map - > setFixedSize ( width , height ) ;
2018-09-27 00:33:08 +01:00
ui - > graphicsView_Objects_Map - > editor = editor ;
ui - > graphicsView_Connections - > setScene ( editor - > scene ) ;
ui - > graphicsView_Connections - > setSceneRect ( editor - > scene - > sceneRect ( ) ) ;
2018-09-27 19:27:57 +01:00
ui - > graphicsView_Connections - > setFixedSize ( width , height ) ;
2018-09-27 00:33:08 +01:00
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 ) ;
ui - > graphicsView_currentMetatileSelection - > setFixedSize ( editor - > scene_current_metatile_selection_item - > pixmap ( ) . width ( ) + 2 , editor - > scene_current_metatile_selection_item - > pixmap ( ) . height ( ) + 2 ) ;
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
}
void MainWindow : : openWarpMap ( QString map_name , QString warp_num ) {
// Ensure valid destination map name.
if ( ! editor - > project - > mapNames - > contains ( map_name ) ) {
2018-12-20 23:30:35 +00:00
logError ( QString ( " Invalid warp destination map name '%1' " ) . arg ( map_name ) ) ;
2018-09-27 00:33:08 +01:00
return ;
}
// Ensure valid destination warp number.
bool ok ;
int warpNum = warp_num . toInt ( & ok , 0 ) ;
if ( ! ok ) {
2018-12-20 23:30:35 +00:00
logError ( QString ( " Invalid warp number '%1' for destination map '%2' " ) . arg ( warp_num ) . arg ( map_name ) ) ;
2018-09-27 00:33:08 +01:00
return ;
}
// Open the destination map, and select the target warp event.
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 ;
}
2018-09-27 00:33:08 +01:00
QList < Event * > warp_events = editor - > map - > events [ " warp_event_group " ] ;
if ( warp_events . length ( ) > warpNum ) {
Event * warp_event = warp_events . at ( warpNum ) ;
QList < DraggablePixmapItem * > * all_events = editor - > getObjects ( ) ;
for ( DraggablePixmapItem * item : * all_events ) {
if ( item - > event = = warp_event ) {
editor - > selected_events - > clear ( ) ;
editor - > selected_events - > append ( item ) ;
editor - > updateSelectedEvents ( ) ;
}
}
delete all_events ;
}
}
2018-12-21 15:25:28 +00:00
void MainWindow : : setRecentMap ( QString mapName ) {
2018-12-25 20:41:06 +00:00
porymapConfig . setRecentMap ( mapName ) ;
2018-09-27 00:33:08 +01:00
}
void MainWindow : : displayMapProperties ( ) {
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 ) ;
ui - > checkBox_AllowEscapeRope - > setChecked ( false ) ;
2018-09-27 00:33:08 +01:00
if ( ! editor | | ! editor - > map | | ! editor - > project ) {
ui - > frame_3 - > setEnabled ( false ) ;
return ;
}
ui - > frame_3 - > setEnabled ( true ) ;
Map * map = editor - > map ;
ui - > comboBox_Song - > setCurrentText ( map - > song ) ;
ui - > comboBox_Location - > setCurrentText ( map - > location ) ;
ui - > comboBox_PrimaryTileset - > setCurrentText ( map - > layout - > tileset_primary_label ) ;
ui - > comboBox_SecondaryTileset - > setCurrentText ( map - > layout - > tileset_secondary_label ) ;
ui - > checkBox_Visibility - > setChecked ( map - > requiresFlash . toInt ( ) > 0 | | map - > requiresFlash = = " TRUE " ) ;
ui - > comboBox_Weather - > setCurrentText ( map - > weather ) ;
ui - > comboBox_Type - > setCurrentText ( map - > type ) ;
ui - > comboBox_BattleScene - > setCurrentText ( map - > battle_scene ) ;
ui - > checkBox_ShowLocation - > setChecked ( map - > show_location . toInt ( ) > 0 | | map - > show_location = = " TRUE " ) ;
2018-12-26 18:20:51 +00:00
ui - > checkBox_AllowRunning - > setChecked ( map - > allowRunning . toInt ( ) > 0 | | map - > allowRunning = = " TRUE " ) ;
ui - > checkBox_AllowBiking - > setChecked ( map - > allowBiking . toInt ( ) > 0 | | map - > allowBiking = = " TRUE " ) ;
ui - > checkBox_AllowEscapeRope - > setChecked ( map - > allowEscapeRope . toInt ( ) > 0 | | map - > allowEscapeRope = = " TRUE " ) ;
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 ) ;
for ( auto it = map - > customHeaders . begin ( ) ; it ! = map - > customHeaders . end ( ) ; it + + ) {
int rowIndex = ui - > tableWidget_CustomHeaderFields - > rowCount ( ) ;
ui - > tableWidget_CustomHeaderFields - > insertRow ( rowIndex ) ;
ui - > tableWidget_CustomHeaderFields - > setItem ( rowIndex , 0 , new QTableWidgetItem ( it . key ( ) ) ) ;
ui - > tableWidget_CustomHeaderFields - > setItem ( rowIndex , 1 , new QTableWidgetItem ( it . value ( ) ) ) ;
}
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 ;
}
}
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 ;
}
}
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 ;
}
}
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 ;
}
}
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 ;
}
}
void MainWindow : : on_checkBox_Visibility_clicked ( bool checked )
{
if ( editor & & editor - > map ) {
if ( checked ) {
editor - > map - > requiresFlash = " TRUE " ;
} else {
editor - > map - > requiresFlash = " FALSE " ;
}
}
}
void MainWindow : : on_checkBox_ShowLocation_clicked ( bool checked )
{
if ( editor & & editor - > map ) {
if ( checked ) {
editor - > map - > show_location = " TRUE " ;
} else {
editor - > map - > show_location = " FALSE " ;
}
}
}
2018-12-26 18:20:51 +00:00
void MainWindow : : on_checkBox_AllowRunning_clicked ( bool checked )
{
if ( editor & & editor - > map ) {
if ( checked ) {
editor - > map - > allowRunning = " 1 " ;
} else {
editor - > map - > allowRunning = " 0 " ;
}
}
}
void MainWindow : : on_checkBox_AllowBiking_clicked ( bool checked )
{
if ( editor & & editor - > map ) {
if ( checked ) {
editor - > map - > allowBiking = " 1 " ;
} else {
editor - > map - > allowBiking = " 0 " ;
}
}
}
void MainWindow : : on_checkBox_AllowEscapeRope_clicked ( bool checked )
{
if ( editor & & editor - > map ) {
if ( checked ) {
editor - > map - > allowEscapeRope = " 1 " ;
} else {
editor - > map - > allowEscapeRope = " 0 " ;
}
}
}
2020-03-11 21:06:26 +00:00
void MainWindow : : on_spinBox_FloorNumber_valueChanged ( int offset )
{
if ( editor & & editor - > map ) {
editor - > map - > floorNumber = offset ;
}
}
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 ( )
& & project - > readBgEventFacingDirections ( )
& & project - > readMetatileBehaviors ( )
& & project - > readTilesetProperties ( )
& & project - > readHealLocations ( )
& & project - > readMiscellaneousConstants ( )
& & project - > readSpeciesIconPaths ( )
& & project - > readWildMonData ( ) ;
2020-03-11 05:52:00 +00:00
if ( projectConfig . getBaseGameVersion ( ) = = BaseGameVersion : : pokeemerald | | projectConfig . getBaseGameVersion ( ) = = BaseGameVersion : : pokeruby )
2020-03-12 16:30:37 +00:00
success = success
& & project - > readSecretBaseIds ( )
& & project - > readCoordEventWeatherNames ( ) ;
2020-02-12 00:34:08 +00:00
if ( ! success ) {
return false ;
}
2019-09-21 21:59:14 +01:00
// set up project ui comboboxes
QStringList songs = project - > getSongNames ( ) ;
2020-02-12 15:13:58 +00:00
ui - > comboBox_Song - > clear ( ) ;
2019-09-21 21:59:14 +01:00
ui - > comboBox_Song - > addItems ( songs ) ;
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
2019-09-21 21:59:14 +01:00
QMap < QString , QStringList > tilesets = project - > getTilesetLabels ( ) ;
2020-02-12 15:13:58 +00:00
if ( tilesets . isEmpty ( ) ) {
return false ;
}
ui - > comboBox_PrimaryTileset - > clear ( ) ;
2019-09-21 21:59:14 +01:00
ui - > comboBox_PrimaryTileset - > addItems ( tilesets . value ( " primary " ) ) ;
2020-02-12 15:13:58 +00:00
ui - > comboBox_SecondaryTileset - > clear ( ) ;
2019-09-21 21:59:14 +01:00
ui - > comboBox_SecondaryTileset - > addItems ( tilesets . value ( " secondary " ) ) ;
2020-02-12 15:13:58 +00:00
ui - > comboBox_Weather - > clear ( ) ;
2019-09-21 21:59:14 +01:00
ui - > comboBox_Weather - > addItems ( * project - > weatherNames ) ;
2020-02-12 15:13:58 +00:00
ui - > comboBox_BattleScene - > clear ( ) ;
2019-09-21 21:59:14 +01:00
ui - > comboBox_BattleScene - > addItems ( * project - > mapBattleScenes ) ;
2020-02-12 15:13:58 +00:00
ui - > comboBox_Type - > clear ( ) ;
2019-09-21 21:59:14 +01:00
ui - > comboBox_Type - > addItems ( * project - > mapTypes ) ;
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 :
for ( int i = 0 ; i < project - > groupNames - > length ( ) ; i + + ) {
QString group_name = project - > groupNames - > value ( i ) ;
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 ) ;
}
for ( int i = 0 ; i < project - > groupNames - > length ( ) ; i + + ) {
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
}
for ( int i = 0 ; i < project - > groupNames - > length ( ) ; i + + ) {
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 ) ;
connect ( actions , SIGNAL ( triggered ( QAction * ) ) , this , SLOT ( onAddNewMapToGroupClick ( QAction * ) ) ) ;
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 ) ;
connect ( actions , SIGNAL ( triggered ( QAction * ) ) , this , SLOT ( onAddNewMapToAreaClick ( QAction * ) ) ) ;
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 ) ;
2019-01-07 23:14:44 +00:00
connect ( actions , SIGNAL ( triggered ( QAction * ) ) , this , SLOT ( onAddNewMapToLayoutClick ( QAction * ) ) ) ;
menu - > exec ( QCursor : : pos ( ) ) ;
2018-09-27 00:33:08 +01:00
}
}
void MainWindow : : onAddNewMapToGroupClick ( QAction * triggeredAction )
{
int groupNum = triggeredAction - > data ( ) . toInt ( ) ;
2019-01-07 23:14:44 +00:00
openNewMapPopupWindow ( MapSortOrder : : Group , groupNum ) ;
}
void MainWindow : : onAddNewMapToAreaClick ( QAction * triggeredAction )
{
QString secName = triggeredAction - > data ( ) . toString ( ) ;
openNewMapPopupWindow ( MapSortOrder : : Area , secName ) ;
}
void MainWindow : : onAddNewMapToLayoutClick ( QAction * triggeredAction )
{
2019-02-01 17:43:25 +00:00
QString layoutId = triggeredAction - > data ( ) . toString ( ) ;
openNewMapPopupWindow ( MapSortOrder : : Layout , layoutId ) ;
2019-01-07 23:14:44 +00:00
}
void MainWindow : : onNewMapCreated ( ) {
QString newMapName = this - > newmapprompt - > map - > name ;
int newMapGroup = this - > newmapprompt - > group ;
Map * newMap_ = this - > newmapprompt - > map ;
2019-02-01 17:43:25 +00:00
bool existingLayout = this - > newmapprompt - > existingLayout ;
2019-01-07 23:14:44 +00:00
2019-02-01 17:43:25 +00:00
Map * newMap = editor - > project - > addNewMapToGroup ( newMapName , newMapGroup , newMap_ , existingLayout ) ;
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 ) ;
if ( newMap - > isFlyable = = " TRUE " ) {
addNewEvent ( " event_heal_location " ) ;
editor - > project - > saveHealLocationStruct ( newMap ) ;
editor - > save ( ) ; // required
}
disconnect ( this - > newmapprompt , SIGNAL ( applied ( ) ) , this , SLOT ( onNewMapCreated ( ) ) ) ;
}
void MainWindow : : openNewMapPopupWindow ( int type , QVariant data ) {
if ( ! this - > newmapprompt ) {
this - > newmapprompt = new NewMapPopup ( this , this - > editor - > project ) ;
}
if ( ! this - > newmapprompt - > isVisible ( ) ) {
this - > newmapprompt - > show ( ) ;
} else {
this - > newmapprompt - > raise ( ) ;
this - > newmapprompt - > activateWindow ( ) ;
}
switch ( type )
{
case MapSortOrder : : Group :
this - > newmapprompt - > init ( type , data . toInt ( ) , QString ( ) , QString ( ) ) ;
break ;
case MapSortOrder : : Area :
this - > newmapprompt - > init ( type , 0 , data . toString ( ) , QString ( ) ) ;
break ;
case MapSortOrder : : Layout :
this - > newmapprompt - > init ( type , 0 , QString ( ) , data . toString ( ) ) ;
break ;
}
connect ( this - > newmapprompt , SIGNAL ( applied ( ) ) , this , SLOT ( onNewMapCreated ( ) ) ) ;
connect ( this - > newmapprompt , & QObject : : destroyed , [ = ] ( QObject * ) { this - > newmapprompt = nullptr ; } ) ;
this - > newmapprompt - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
}
void MainWindow : : on_action_NewMap_triggered ( ) {
openNewMapPopupWindow ( MapSortOrder : : Group , 0 ) ;
2018-09-27 00:33:08 +01:00
}
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 ;
}
QString fullDirectoryPath = editor - > project - > root + createTilesetDialog - > path ;
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 ;
}
2019-03-23 14:49:30 +00:00
QMap < QString , QStringList > tilesets = this - > editor - > project - > getTilesetLabels ( ) ;
2019-03-23 14:44:21 +00:00
if ( tilesets . value ( " primary " ) . contains ( createTilesetDialog - > fullSymbolName ) | | tilesets . value ( " secondary " ) . contains ( createTilesetDialog - > fullSymbolName ) ) {
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 " ) ;
Tileset * newSet = new Tileset ( ) ;
newSet - > name = createTilesetDialog - > fullSymbolName ;
newSet - > tilesImagePath = fullDirectoryPath + " /tiles.png " ;
newSet - > metatiles_path = fullDirectoryPath + " /metatiles.bin " ;
newSet - > metatile_attrs_path = fullDirectoryPath + " /metatile_attributes.bin " ;
newSet - > is_secondary = createTilesetDialog - > isSecondary ? " TRUE " : " FALSE " ;
int numMetaTiles = createTilesetDialog - > isSecondary ? ( Project : : getNumTilesTotal ( ) - Project : : getNumTilesPrimary ( ) ) : Project : : getNumTilesPrimary ( ) ;
QImage * tilesImage = new QImage ( " :/images/blank_tileset.png " ) ;
editor - > project - > loadTilesetTiles ( newSet , * tilesImage ) ;
newSet - > metatiles = new QList < Metatile * > ( ) ;
for ( int i = 0 ; i < numMetaTiles ; + + i ) {
Metatile * mt = new Metatile ( ) ;
for ( int j = 0 ; j < 8 ; + + j ) {
Tile * tile = new Tile ( ) ;
//Create a checkerboard-style dummy tileset
if ( ( ( i / 8 ) % 2 ) = = 0 )
tile - > tile = ( ( i % 2 ) = = 0 ) ? 1 : 2 ;
else
tile - > tile = ( ( i % 2 ) = = 1 ) ? 1 : 2 ;
tile - > xflip = false ;
tile - > yflip = false ;
tile - > palette = 0 ;
mt - > tiles - > append ( * tile ) ;
}
mt - > behavior = 0 ;
mt - > layerType = 0 ;
2020-03-16 20:31:08 +00:00
mt - > encounterType = 0 ;
mt - > terrainType = 0 ;
2019-03-21 23:50:50 +00:00
newSet - > metatiles - > append ( mt ) ;
}
newSet - > palettes = new QList < QList < QRgb > > ( ) ;
newSet - > palettePaths = * new QList < QString > ( ) ;
for ( int i = 0 ; i < 16 ; + + i ) {
QList < QRgb > * currentPal = new QList < QRgb > ( ) ;
for ( int i = 0 ; i < 16 ; + + i ) {
currentPal - > append ( qRgb ( 0 , 0 , 0 ) ) ;
}
newSet - > palettes - > append ( * currentPal ) ;
QString fileName ;
fileName . sprintf ( " %02d.pal " , i ) ;
newSet - > palettePaths . append ( fullDirectoryPath + " /palettes/ " + fileName ) ;
}
( * newSet - > palettes ) [ 0 ] [ 1 ] = qRgb ( 255 , 0 , 255 ) ;
newSet - > is_compressed = " TRUE " ;
newSet - > padding = " 0 " ;
editor - > project - > saveTilesetTilesImage ( newSet ) ;
editor - > project - > saveTilesetMetatiles ( newSet ) ;
editor - > project - > saveTilesetMetatileAttributes ( newSet ) ;
editor - > project - > saveTilesetPalettes ( newSet , ! createTilesetDialog - > isSecondary ) ;
//append to tileset specific files
newSet - > appendToHeaders ( editor - > project - > root + " /data/tilesets/headers.inc " , createTilesetDialog - > friendlyName ) ;
newSet - > appendToGraphics ( editor - > project - > root + " /data/tilesets/graphics.inc " , createTilesetDialog - > friendlyName , ! createTilesetDialog - > isSecondary ) ;
newSet - > appendToMetatiles ( editor - > project - > root + " /data/tilesets/metatiles.inc " , createTilesetDialog - > friendlyName , ! createTilesetDialog - > isSecondary ) ;
if ( ! createTilesetDialog - > isSecondary ) {
this - > ui - > comboBox_PrimaryTileset - > addItem ( createTilesetDialog - > fullSymbolName ) ;
} else {
this - > ui - > comboBox_SecondaryTileset - > addItem ( createTilesetDialog - > fullSymbolName ) ;
}
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-09-27 00:33:08 +01:00
void MainWindow : : onTilesetChanged ( QString mapName )
{
setMap ( mapName ) ;
}
2018-10-03 01:01:18 +01:00
void MainWindow : : updateTilesetEditor ( ) {
if ( this - > tilesetEditor ) {
this - > tilesetEditor - > setTilesets ( editor - > ui - > comboBox_PrimaryTileset - > currentText ( ) , editor - > ui - > comboBox_SecondaryTileset - > currentText ( ) ) ;
}
}
2018-09-27 00:33:08 +01:00
void MainWindow : : currentMetatilesSelectionChanged ( )
{
2019-02-25 20:09:36 +00:00
double scale = pow ( 3.0 , static_cast < double > ( porymapConfig . getMetatilesZoom ( ) - 30 ) / 30.0 ) ;
ui - > graphicsView_currentMetatileSelection - > setFixedSize ( editor - > scene_current_metatile_selection_item - > pixmap ( ) . width ( ) * scale + 2 , editor - > scene_current_metatile_selection_item - > pixmap ( ) . height ( ) * scale + 2 ) ;
ui - > graphicsView_currentMetatileSelection - > setSceneRect ( 0 , 0 , editor - > scene_current_metatile_selection_item - > pixmap ( ) . width ( ) * scale , editor - > scene_current_metatile_selection_item - > pixmap ( ) . height ( ) * scale ) ;
2018-10-08 20:42:51 +01:00
QPoint size = editor - > metatile_selector_item - > getSelectionDimensions ( ) ;
if ( size . x ( ) = = 1 & & size . y ( ) = = 1 ) {
QPoint pos = editor - > metatile_selector_item - > getMetatileIdCoordsOnWidget ( editor - > metatile_selector_item - > getSelectedMetatiles ( ) - > at ( 0 ) ) ;
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
}
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 ( ) ;
if ( editor - > project & & editor - > project - > map_cache - > contains ( map_name ) ) {
QStandardItem * map = mapListModel - > itemFromIndex ( mapListIndexes . value ( map_name ) ) ;
map - > setIcon ( * mapIcon ) ;
if ( editor - > project - > map_cache - > value ( map_name ) - > hasUnsavedChanges ( ) ) {
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
}
void MainWindow : : on_action_Save_Project_triggered ( )
{
editor - > saveProject ( ) ;
updateMapList ( ) ;
}
void MainWindow : : undo ( ) {
editor - > undo ( ) ;
}
void MainWindow : : redo ( ) {
editor - > redo ( ) ;
}
// Open current map scripts in system default editor for .inc files
void MainWindow : : openInTextEditor ( ) {
2019-10-22 13:48:41 +01:00
QString path = QDir : : cleanPath ( " file:// " + editor - > project - > root + QDir : : separator ( ) + " data/maps/ " + editor - > map - > name + " /scripts " + editor - > project - > getScriptFileExtension ( projectConfig . getUsePoryScript ( ) ) ) ;
2018-09-27 00:33:08 +01:00
QDesktopServices : : openUrl ( QUrl ( path ) ) ;
}
void MainWindow : : on_action_Save_triggered ( ) {
editor - > save ( ) ;
updateMapList ( ) ;
}
void MainWindow : : on_tabWidget_2_currentChanged ( int index )
{
if ( index = = 0 ) {
editor - > setEditingMap ( ) ;
} else if ( index = = 1 ) {
editor - > setEditingCollision ( ) ;
}
2019-04-06 04:22:07 +01:00
editor - > playerViewRect - > setVisible ( false ) ;
editor - > cursorMapTileRect - > setVisible ( false ) ;
2018-09-27 00:33:08 +01:00
}
void MainWindow : : on_action_Exit_triggered ( )
{
QApplication : : quit ( ) ;
}
void MainWindow : : on_tabWidget_currentChanged ( int index )
{
if ( index = = 0 ) {
on_tabWidget_2_currentChanged ( ui - > tabWidget_2 - > currentIndex ( ) ) ;
} else if ( index = = 1 ) {
editor - > setEditingObjects ( ) ;
} else if ( index = = 3 ) {
editor - > setEditingConnections ( ) ;
}
2019-10-01 03:24:39 +01:00
if ( index ! = 4 ) {
editor - > saveEncounterTabData ( ) ;
}
2018-09-27 00:33:08 +01:00
}
void MainWindow : : on_actionUndo_triggered ( )
{
undo ( ) ;
}
void MainWindow : : on_actionRedo_triggered ( )
{
redo ( ) ;
}
void MainWindow : : on_actionZoom_In_triggered ( ) {
scaleMapView ( 1 ) ;
}
void MainWindow : : on_actionZoom_Out_triggered ( ) {
scaleMapView ( - 1 ) ;
}
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 ;
}
void MainWindow : : on_actionCursor_Tile_Outline_triggered ( )
{
bool enabled = ui - > actionCursor_Tile_Outline - > isChecked ( ) ;
porymapConfig . setShowCursorTile ( enabled ) ;
this - > editor - > settings - > cursorTileRectEnabled = enabled ;
2019-01-09 00:04:48 +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 ( ) ;
}
void MainWindow : : scaleMapView ( int s ) {
2018-09-27 19:27:57 +01:00
if ( ( editor - > scale_exp + s ) < = 5 & & ( editor - > scale_exp + s ) > = - 2 ) // sane limits
{
if ( s = = 0 )
{
s = - editor - > scale_exp ;
}
2018-09-27 00:33:08 +01:00
2018-09-27 19:27:57 +01:00
editor - > scale_exp + = s ;
2018-09-27 00:33:08 +01:00
2018-09-27 19:27:57 +01:00
double base = editor - > scale_base ;
double exp = editor - > scale_exp ;
double sfactor = pow ( base , s ) ;
2018-09-27 00:33:08 +01:00
2018-09-27 19:27:57 +01:00
ui - > graphicsView_Map - > scale ( sfactor , sfactor ) ;
ui - > graphicsView_Objects_Map - > scale ( sfactor , sfactor ) ;
ui - > graphicsView_Connections - > scale ( sfactor , sfactor ) ;
int width = static_cast < int > ( ceil ( ( editor - > scene - > width ( ) ) * pow ( base , exp ) ) ) + 2 ;
int height = static_cast < int > ( ceil ( ( editor - > scene - > height ( ) ) * pow ( base , exp ) ) ) + 2 ;
ui - > graphicsView_Map - > setFixedSize ( width , height ) ;
ui - > graphicsView_Objects_Map - > setFixedSize ( width , height ) ;
ui - > graphicsView_Connections - > setFixedSize ( width , height ) ;
}
}
void MainWindow : : resetMapViewScale ( ) {
scaleMapView ( 0 ) ;
2018-09-27 00:33:08 +01:00
}
void MainWindow : : addNewEvent ( QString event_type )
{
if ( editor ) {
DraggablePixmapItem * object = editor - > addNewEvent ( event_type ) ;
2018-12-20 23:46:43 +00:00
updateObjects ( ) ;
2018-09-27 00:33:08 +01:00
if ( object ) {
editor - > selectMapEvent ( object , false ) ;
}
}
}
2018-11-28 01:39:57 +00:00
void MainWindow : : updateObjects ( ) {
selectedObject = nullptr ;
selectedWarp = nullptr ;
selectedTrigger = nullptr ;
selectedBG = nullptr ;
selectedHealspot = nullptr ;
2018-12-05 04:14:16 +00:00
ui - > tabWidget_EventType - > clear ( ) ;
2018-11-28 01:39:57 +00:00
bool hasObjects = false ;
bool hasWarps = false ;
bool hasTriggers = false ;
bool hasBGs = false ;
bool hasHealspots = false ;
for ( DraggablePixmapItem * item : * editor - > getObjects ( ) )
{
QString event_type = item - > event - > get ( " event_type " ) ;
if ( event_type = = EventType : : Object ) {
hasObjects = true ;
}
else if ( event_type = = EventType : : Warp ) {
hasWarps = true ;
}
2018-12-26 20:15:35 +00:00
else if ( event_type = = EventType : : Trigger | | event_type = = EventType : : WeatherTrigger ) {
2018-11-28 01:39:57 +00:00
hasTriggers = true ;
}
else if ( event_type = = EventType : : Sign | | event_type = = EventType : : HiddenItem | | event_type = = EventType : : SecretBase ) {
hasBGs = true ;
}
else if ( event_type = = EventType : : HealLocation ) {
hasHealspots = true ;
}
}
if ( hasObjects )
{
ui - > tabWidget_EventType - > addTab ( eventTabObjectWidget , " Objects " ) ;
}
if ( hasWarps )
{
ui - > tabWidget_EventType - > addTab ( eventTabWarpWidget , " Warps " ) ;
}
if ( hasTriggers )
{
ui - > tabWidget_EventType - > addTab ( eventTabTriggerWidget , " Triggers " ) ;
}
if ( hasBGs )
{
ui - > tabWidget_EventType - > addTab ( eventTabBGWidget , " BGs " ) ;
}
if ( hasHealspots )
{
ui - > tabWidget_EventType - > addTab ( eventTabHealspotWidget , " Healspots " ) ;
2018-09-27 00:33:08 +01:00
}
2018-11-28 01:39:57 +00:00
updateSelectedObjects ( ) ;
2018-09-27 00:33:08 +01:00
}
// Should probably just pass layout and let the editor work it out
void MainWindow : : updateSelectedObjects ( ) {
QList < DraggablePixmapItem * > * all_events = editor - > getObjects ( ) ;
QList < DraggablePixmapItem * > * events = nullptr ;
if ( editor - > selected_events & & editor - > selected_events - > length ( ) ) {
events = editor - > selected_events ;
} else {
events = new QList < DraggablePixmapItem * > ;
if ( all_events & & all_events - > length ( ) ) {
DraggablePixmapItem * selectedEvent = all_events - > first ( ) ;
editor - > selected_events - > append ( selectedEvent ) ;
editor - > redrawObject ( selectedEvent ) ;
events - > append ( selectedEvent ) ;
}
}
QMap < QString , int > event_obj_gfx_constants = editor - > project - > getEventObjGfxConstants ( ) ;
QList < EventPropertiesFrame * > frames ;
for ( DraggablePixmapItem * item : * events ) {
EventPropertiesFrame * frame = new EventPropertiesFrame ;
// frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
QSpinBox * x = frame - > ui - > spinBox_x ;
QSpinBox * y = frame - > ui - > spinBox_y ;
QSpinBox * z = frame - > ui - > spinBox_z ;
x - > setValue ( item - > event - > x ( ) ) ;
connect ( x , SIGNAL ( valueChanged ( QString ) ) , item , SLOT ( set_x ( QString ) ) ) ;
connect ( item , SIGNAL ( xChanged ( int ) ) , x , SLOT ( setValue ( int ) ) ) ;
y - > setValue ( item - > event - > y ( ) ) ;
connect ( y , SIGNAL ( valueChanged ( QString ) ) , item , SLOT ( set_y ( QString ) ) ) ;
connect ( item , SIGNAL ( yChanged ( int ) ) , y , SLOT ( setValue ( int ) ) ) ;
z - > setValue ( item - > event - > elevation ( ) ) ;
connect ( z , SIGNAL ( valueChanged ( QString ) ) , item , SLOT ( set_elevation ( QString ) ) ) ;
connect ( item , SIGNAL ( elevationChanged ( int ) ) , z , SLOT ( setValue ( int ) ) ) ;
QString event_type = item - > event - > get ( " event_type " ) ;
QString event_group_type = item - > event - > get ( " event_group_type " ) ;
QString map_name = item - > event - > get ( " map_name " ) ;
int event_offs ;
if ( event_type = = " event_warp " ) { event_offs = 0 ; }
else { event_offs = 1 ; }
2018-12-26 20:15:35 +00:00
frame - > ui - > label_name - > setText ( QString ( " %1 Id " ) . arg ( event_type ) ) ;
2018-09-27 00:33:08 +01:00
2018-12-04 18:58:49 +00:00
if ( events - > count ( ) = = 1 )
{
frame - > ui - > spinBox_index - > setValue ( editor - > project - > getMap ( map_name ) - > events . value ( event_group_type ) . indexOf ( item - > event ) + event_offs ) ;
frame - > ui - > spinBox_index - > setMinimum ( event_offs ) ;
frame - > ui - > spinBox_index - > setMaximum ( editor - > project - > getMap ( map_name ) - > events . value ( event_group_type ) . length ( ) + event_offs - 1 ) ;
connect ( frame - > ui - > spinBox_index , QOverload < int > : : of ( & QSpinBox : : valueChanged ) , this , & MainWindow : : selectedEventIndexChanged ) ;
}
else
{
frame - > ui - > spinBox_index - > setVisible ( false ) ;
}
2018-11-30 03:59:03 +00:00
2018-09-27 00:33:08 +01:00
frame - > ui - > label_spritePixmap - > setPixmap ( item - > event - > pixmap ) ;
connect ( item , SIGNAL ( spriteChanged ( QPixmap ) ) , frame - > ui - > label_spritePixmap , SLOT ( setPixmap ( QPixmap ) ) ) ;
frame - > ui - > sprite - > setVisible ( false ) ;
QMap < QString , QString > field_labels ;
field_labels [ " script_label " ] = " Script " ;
field_labels [ " event_flag " ] = " Event Flag " ;
field_labels [ " movement_type " ] = " Movement " ;
field_labels [ " radius_x " ] = " Movement Radius X " ;
field_labels [ " radius_y " ] = " Movement Radius Y " ;
2019-01-20 16:42:01 +00:00
field_labels [ " trainer_type " ] = " Trainer Type " ;
2018-09-27 00:33:08 +01:00
field_labels [ " sight_radius_tree_id " ] = " Sight Radius / Berry Tree ID " ;
2020-03-11 20:45:52 +00:00
field_labels [ " in_connection " ] = " In Connection " ;
2018-09-27 00:33:08 +01:00
field_labels [ " destination_warp " ] = " Destination Warp " ;
field_labels [ " destination_map_name " ] = " Destination Map " ;
field_labels [ " script_var " ] = " Var " ;
field_labels [ " script_var_value " ] = " Var Value " ;
field_labels [ " player_facing_direction " ] = " Player Facing Direction " ;
field_labels [ " item " ] = " Item " ;
2020-03-11 20:23:07 +00:00
field_labels [ " quantity " ] = " Quantity " ;
field_labels [ " underfoot " ] = " Requires Itemfinder " ;
2018-09-27 00:33:08 +01:00
field_labels [ " weather " ] = " Weather " ;
field_labels [ " flag " ] = " Flag " ;
field_labels [ " secret_base_id " ] = " Secret Base Id " ;
2020-03-20 17:41:40 +00:00
field_labels [ " respawn_map " ] = " Respawn Map " ;
field_labels [ " respawn_npc " ] = " Respawn NPC " ;
2018-09-27 00:33:08 +01:00
QStringList fields ;
if ( event_type = = EventType : : Object ) {
frame - > ui - > sprite - > setVisible ( true ) ;
frame - > ui - > comboBox_sprite - > addItems ( event_obj_gfx_constants . keys ( ) ) ;
frame - > ui - > comboBox_sprite - > setCurrentText ( item - > event - > get ( " sprite " ) ) ;
2019-09-21 18:04:17 +01:00
connect ( frame - > ui - > comboBox_sprite , & QComboBox : : currentTextChanged , item , & DraggablePixmapItem : : set_sprite ) ;
2018-09-27 00:33:08 +01:00
/*
frame - > ui - > script - > setVisible ( true ) ;
frame - > ui - > comboBox_script - > addItem ( item - > event - > get ( " script_label " ) ) ;
frame - > ui - > comboBox_script - > setCurrentText ( item - > event - > get ( " script_label " ) ) ;
//item->bind(frame->ui->comboBox_script, "script_label");
connect ( frame - > ui - > comboBox_script , SIGNAL ( activated ( QString ) ) , item , SLOT ( set_script ( QString ) ) ) ;
//connect(frame->ui->comboBox_script, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::activated), item, [item](QString script_label){ item->event->put("script_label", script_label); });
//connect(item, SIGNAL(scriptChanged(QString)), frame->ui->comboBox_script, SLOT(setValue(QString)));
*/
fields < < " movement_type " ;
fields < < " radius_x " ;
fields < < " radius_y " ;
fields < < " script_label " ;
fields < < " event_flag " ;
2019-01-20 16:42:01 +00:00
fields < < " trainer_type " ;
2018-09-27 00:33:08 +01:00
fields < < " sight_radius_tree_id " ;
2020-03-11 20:45:52 +00:00
if ( projectConfig . getBaseGameVersion ( ) = = BaseGameVersion : : pokefirered ) {
fields < < " in_connection " ;
}
2018-09-27 00:33:08 +01:00
}
else if ( event_type = = EventType : : Warp ) {
fields < < " destination_map_name " ;
fields < < " destination_warp " ;
}
2018-12-26 20:15:35 +00:00
else if ( event_type = = EventType : : Trigger ) {
2018-09-27 00:33:08 +01:00
fields < < " script_label " ;
fields < < " script_var " ;
fields < < " script_var_value " ;
}
2018-12-26 20:15:35 +00:00
else if ( event_type = = EventType : : WeatherTrigger ) {
2018-09-27 00:33:08 +01:00
fields < < " weather " ;
}
else if ( event_type = = EventType : : Sign ) {
fields < < " player_facing_direction " ;
fields < < " script_label " ;
}
else if ( event_type = = EventType : : HiddenItem ) {
fields < < " item " ;
fields < < " flag " ;
2020-03-11 20:23:07 +00:00
if ( projectConfig . getBaseGameVersion ( ) = = BaseGameVersion : : pokefirered ) {
fields < < " quantity " ;
fields < < " underfoot " ;
}
2018-09-27 00:33:08 +01:00
}
else if ( event_type = = EventType : : SecretBase ) {
fields < < " secret_base_id " ;
}
2019-05-01 04:03:28 +01:00
else if ( event_type = = EventType : : HealLocation ) {
// Hide elevation so users don't get impression that editing it is meaningful.
2019-05-02 16:05:20 +01:00
frame - > ui - > spinBox_z - > setVisible ( false ) ;
2019-05-01 04:03:28 +01:00
frame - > ui - > label_z - > setVisible ( false ) ;
2020-03-20 17:41:40 +00:00
fields < < " respawn_map " ;
fields < < " respawn_npc " ;
2019-05-01 04:03:28 +01:00
}
2018-09-27 00:33:08 +01:00
2020-03-20 17:41:40 +00:00
// Some keys shouldn't use a combobox
QStringList spinKeys = { " quantity " , " respawn_npc " } ;
QStringList checkKeys = { " underfoot " , " in_connection " } ;
2018-09-27 00:33:08 +01:00
for ( QString key : fields ) {
QString value = item - > event - > get ( key ) ;
QWidget * widget = new QWidget ( frame ) ;
QFormLayout * fl = new QFormLayout ( widget ) ;
fl - > setContentsMargins ( 9 , 0 , 9 , 0 ) ;
2018-12-26 20:15:35 +00:00
fl - > setRowWrapPolicy ( QFormLayout : : WrapLongRows ) ;
2018-09-27 00:33:08 +01:00
2020-03-11 20:23:07 +00:00
NoScrollSpinBox * spin ;
NoScrollComboBox * combo ;
QCheckBox * check ;
2020-03-20 17:41:40 +00:00
if ( spinKeys . contains ( key ) ) {
2020-03-11 20:23:07 +00:00
spin = new NoScrollSpinBox ( widget ) ;
2020-03-20 17:41:40 +00:00
} else if ( checkKeys . contains ( key ) ) {
2020-03-11 20:23:07 +00:00
check = new QCheckBox ( widget ) ;
} else {
combo = new NoScrollComboBox ( widget ) ;
combo - > setEditable ( true ) ;
}
2019-01-20 16:42:01 +00:00
// trainer_type has custom values, so it has special signal logic.
if ( key = = " trainer_type " ) {
combo - > setEditable ( false ) ;
combo - > addItem ( " NONE " , " 0 " ) ;
combo - > addItem ( " NORMAL " , " 1 " ) ;
combo - > addItem ( " SEE ALL DIRECTIONS " , " 3 " ) ;
2019-11-22 16:06:11 +00:00
combo - > setToolTip ( " The trainer type of this object event. \n "
2019-04-28 14:05:37 +01:00
" If it is not a trainer, use NONE. SEE ALL DIRECTIONS \n "
" should only be used with a sight radius of 1. " ) ;
2019-08-19 03:33:36 +01:00
combo - > setMinimumContentsLength ( 10 ) ;
2019-01-20 16:42:01 +00:00
int index = combo - > findData ( value ) ;
if ( index ! = - 1 ) {
combo - > setCurrentIndex ( index ) ;
}
fl - > addRow ( new QLabel ( field_labels [ key ] , widget ) , combo ) ;
2018-09-27 00:33:08 +01:00
widget - > setLayout ( fl ) ;
frame - > layout ( ) - > addWidget ( widget ) ;
2019-01-20 16:42:01 +00:00
item - > bindToUserData ( combo , key ) ;
2018-09-27 00:33:08 +01:00
continue ;
}
if ( key = = " destination_map_name " ) {
if ( ! editor - > project - > mapNames - > contains ( value ) ) {
combo - > addItem ( value ) ;
}
combo - > addItems ( * editor - > project - > mapNames ) ;
combo - > setToolTip ( " The destination map name of the warp. " ) ;
} else if ( key = = " destination_warp " ) {
combo - > setToolTip ( " The warp id on the destination map. " ) ;
} else if ( key = = " item " ) {
if ( ! editor - > project - > itemNames - > contains ( value ) ) {
combo - > addItem ( value ) ;
}
combo - > addItems ( * editor - > project - > itemNames ) ;
2020-03-11 20:23:07 +00:00
} else if ( key = = " quantity " ) {
spin - > setToolTip ( " The number of items received when the hidden item is picked up. " ) ;
2020-03-20 17:41:40 +00:00
// Min 1 not needed. 0 is treated as a valid quantity and works as expected in-game.
2020-03-11 20:23:07 +00:00
spin - > setMaximum ( 127 ) ;
} else if ( key = = " underfoot " ) {
check - > setToolTip ( " If checked, hidden item can only be picked up using the Itemfinder " ) ;
2018-09-27 00:33:08 +01:00
} else if ( key = = " flag " | | key = = " event_flag " ) {
if ( ! editor - > project - > flagNames - > contains ( value ) ) {
combo - > addItem ( value ) ;
}
combo - > addItems ( * editor - > project - > flagNames ) ;
if ( key = = " flag " )
combo - > setToolTip ( " The flag which is set when the hidden item is picked up. " ) ;
else if ( key = = " event_flag " )
combo - > setToolTip ( " The flag which hides the object when set. " ) ;
} else if ( key = = " script_var " ) {
if ( ! editor - > project - > varNames - > contains ( value ) ) {
combo - > addItem ( value ) ;
}
combo - > addItems ( * editor - > project - > varNames ) ;
2019-04-28 14:05:37 +01:00
combo - > setToolTip ( " The variable by which the script is triggered. \n "
" The script is triggered when this variable's value matches 'Var Value'. " ) ;
} else if ( key = = " script_var_value " ) {
2018-09-27 00:33:08 +01:00
combo - > setToolTip ( " The variable's value which triggers the script. " ) ;
} else if ( key = = " movement_type " ) {
if ( ! editor - > project - > movementTypes - > contains ( value ) ) {
combo - > addItem ( value ) ;
}
2019-04-03 00:51:33 +01:00
connect ( combo , static_cast < void ( QComboBox : : * ) ( const QString & ) > ( & QComboBox : : currentTextChanged ) ,
this , [ this , item , frame ] ( QString value ) {
item - > event - > setFrameFromMovement ( editor - > project - > facingDirections . value ( value ) ) ;
item - > updatePixmap ( ) ;
} ) ;
2018-09-27 00:33:08 +01:00
combo - > addItems ( * editor - > project - > movementTypes ) ;
2019-04-28 14:05:37 +01:00
combo - > setToolTip ( " The object's natural movement behavior when \n "
" the player is not interacting with it. " ) ;
2018-09-27 00:33:08 +01:00
} else if ( key = = " weather " ) {
if ( ! editor - > project - > coordEventWeatherNames - > contains ( value ) ) {
combo - > addItem ( value ) ;
}
combo - > addItems ( * editor - > project - > coordEventWeatherNames ) ;
combo - > setToolTip ( " The weather that starts when the player steps on this spot. " ) ;
} else if ( key = = " secret_base_id " ) {
if ( ! editor - > project - > secretBaseIds - > contains ( value ) ) {
combo - > addItem ( value ) ;
}
combo - > addItems ( * editor - > project - > secretBaseIds ) ;
2019-04-28 14:05:37 +01:00
combo - > setToolTip ( " The secret base id which is inside this secret \n "
" base entrance. Secret base ids are meant to be \n "
" unique to each and every secret base entrance. " ) ;
2018-09-27 00:33:08 +01:00
} else if ( key = = " player_facing_direction " ) {
if ( ! editor - > project - > bgEventFacingDirections - > contains ( value ) ) {
combo - > addItem ( value ) ;
}
combo - > addItems ( * editor - > project - > bgEventFacingDirections ) ;
2019-04-28 14:05:37 +01:00
combo - > setToolTip ( " The direction which the player must be facing \n "
" to be able to interact with this event. " ) ;
2018-09-27 00:33:08 +01:00
} else if ( key = = " radius_x " ) {
2019-04-28 14:05:37 +01:00
combo - > setToolTip ( " The maximum number of metatiles this object \n "
" is allowed to move left or right during its \n "
" normal movement behavior actions. " ) ;
2019-08-19 03:33:36 +01:00
combo - > setMinimumContentsLength ( 4 ) ;
2018-09-27 00:33:08 +01:00
} else if ( key = = " radius_y " ) {
2019-04-28 14:05:37 +01:00
combo - > setToolTip ( " The maximum number of metatiles this object \n "
" is allowed to move up or down during its \n "
" normal movement behavior actions. " ) ;
2019-08-19 03:33:36 +01:00
combo - > setMinimumContentsLength ( 4 ) ;
2018-09-27 00:33:08 +01:00
} else if ( key = = " script_label " ) {
combo - > setToolTip ( " The script which is executed with this event. " ) ;
} else if ( key = = " sight_radius_tree_id " ) {
2019-04-28 14:05:37 +01:00
combo - > setToolTip ( " The maximum sight range of a trainer, \n "
" OR the unique id of the berry tree. " ) ;
2019-08-19 03:33:36 +01:00
combo - > setMinimumContentsLength ( 4 ) ;
2020-03-11 20:45:52 +00:00
} else if ( key = = " in_connection " ) {
check - > setToolTip ( " Check if object is positioned in the connection to another map. " ) ;
2020-03-20 17:41:40 +00:00
} else if ( key = = " respawn_map " ) {
if ( ! editor - > project - > mapNames - > contains ( value ) ) {
combo - > addItem ( value ) ;
}
combo - > addItems ( * editor - > project - > mapNames ) ;
combo - > setToolTip ( " The map where the player will respawn after whiteout. " ) ;
} else if ( key = = " respawn_npc " ) {
spin - > setToolTip ( " event_object ID of the NPC the player interacts with upon respawning after whiteout. " ) ;
spin - > setMinimum ( 1 ) ;
spin - > setMaximum ( 126 ) ;
2018-09-27 00:33:08 +01:00
} else {
combo - > addItem ( value ) ;
}
2020-03-11 21:06:26 +00:00
// Keys using spin boxes
2020-03-20 17:41:40 +00:00
if ( spinKeys . contains ( key ) ) {
2020-03-11 20:23:07 +00:00
spin - > setValue ( value . toInt ( ) ) ;
fl - > addRow ( new QLabel ( field_labels [ key ] , widget ) , spin ) ;
widget - > setLayout ( fl ) ;
frame - > layout ( ) - > addWidget ( widget ) ;
2020-03-11 20:45:52 +00:00
connect ( spin , QOverload < int > : : of ( & NoScrollSpinBox : : valueChanged ) , [ item , key ] ( int value ) {
item - > event - > put ( key , value ) ;
} ) ;
2020-03-11 21:06:26 +00:00
// Keys using check boxes
2020-03-20 17:41:40 +00:00
} else if ( checkKeys . contains ( key ) ) {
2020-03-11 20:23:07 +00:00
check - > setChecked ( value . toInt ( ) ) ;
2018-09-27 00:33:08 +01:00
2020-03-11 20:23:07 +00:00
fl - > addRow ( new QLabel ( field_labels [ key ] , widget ) , check ) ;
widget - > setLayout ( fl ) ;
frame - > layout ( ) - > addWidget ( widget ) ;
2020-03-11 20:45:52 +00:00
connect ( check , & QCheckBox : : stateChanged , [ item , key ] ( int state ) {
switch ( state )
{
case Qt : : Checked :
item - > event - > put ( key , true ) ;
break ;
case Qt : : Unchecked :
item - > event - > put ( key , false ) ;
break ;
}
} ) ;
2020-03-11 21:06:26 +00:00
// Keys using combo boxes
2020-03-11 20:23:07 +00:00
} else {
combo - > setCurrentText ( value ) ;
fl - > addRow ( new QLabel ( field_labels [ key ] , widget ) , combo ) ;
widget - > setLayout ( fl ) ;
frame - > layout ( ) - > addWidget ( widget ) ;
item - > bind ( combo , key ) ;
}
2018-09-27 00:33:08 +01:00
}
2019-02-03 18:26:27 +00:00
// Custom fields table.
2019-02-03 20:05:57 +00:00
if ( event_type ! = EventType : : HealLocation ) {
CustomAttributesTable * customAttributes = new CustomAttributesTable ( item - > event , frame ) ;
frame - > layout ( ) - > addWidget ( customAttributes ) ;
}
2018-09-27 00:33:08 +01:00
2019-02-03 18:26:27 +00:00
frames . append ( frame ) ;
2018-09-27 00:33:08 +01:00
}
//int scroll = ui->scrollArea_4->verticalScrollBar()->value();
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
2018-11-30 03:59:03 +00:00
isProgrammaticEventTabChange = true ;
2018-11-13 17:36:34 +00:00
if ( events - > length ( ) = = 1 )
{
2018-11-30 03:59:03 +00:00
QString event_group_type = ( * events ) [ 0 ] - > event - > get ( " event_group_type " ) ;
2018-11-28 01:39:57 +00:00
2018-11-30 03:59:03 +00:00
if ( event_group_type = = " object_event_group " ) {
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 ) ;
2018-11-13 17:36:34 +00:00
}
2018-11-30 03:59:03 +00:00
else if ( event_group_type = = " warp_event_group " ) {
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 ) ;
2018-11-13 17:36:34 +00:00
}
2018-11-30 03:59:03 +00:00
else if ( event_group_type = = " coord_event_group " ) {
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 ) ;
2018-11-13 17:36:34 +00:00
}
2018-11-30 03:59:03 +00:00
else if ( event_group_type = = " bg_event_group " ) {
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 ) ;
2018-11-13 17:36:34 +00:00
}
2018-11-30 03:59:03 +00:00
else if ( event_group_type = = " heal_event_group " ) {
scrollTarget = ui - > scrollArea_Healspots ;
2018-11-28 01:39:57 +00:00
target = ui - > scrollAreaWidgetContents_Healspots ;
ui - > tabWidget_EventType - > setCurrentWidget ( ui - > tab_Healspots ) ;
}
2018-11-13 17:36:34 +00:00
ui - > tabWidget_EventType - > removeTab ( ui - > tabWidget_EventType - > indexOf ( ui - > tab_Multiple ) ) ;
}
else if ( events - > length ( ) > 1 )
{
ui - > tabWidget_EventType - > addTab ( ui - > tab_Multiple , " Multiple " ) ;
ui - > tabWidget_EventType - > setCurrentWidget ( ui - > tab_Multiple ) ;
2018-09-27 00:33:08 +01:00
}
2018-11-30 03:59:03 +00:00
isProgrammaticEventTabChange = false ;
2018-11-13 17:36:34 +00:00
if ( events - > length ( ) ! = 0 )
{
2018-11-30 03:59:03 +00:00
if ( target - > children ( ) . length ( ) )
{
for ( QObject * obj : target - > children ( ) )
{
obj - > deleteLater ( ) ;
}
delete target - > layout ( ) ;
2018-11-13 17:36:34 +00:00
}
QVBoxLayout * layout = new QVBoxLayout ( target ) ;
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
2018-11-13 17:36:34 +00:00
for ( EventPropertiesFrame * frame : frames ) {
layout - > addWidget ( frame ) ;
}
layout - > addStretch ( 1 ) ;
2018-09-27 00:33:08 +01:00
2018-11-13 17:36:34 +00:00
// doesn't work
//QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
//ui->scrollArea_4->ensureVisible(0, scroll);
ui - > label_NoEvents - > hide ( ) ;
ui - > tabWidget_EventType - > show ( ) ;
}
else
{
ui - > tabWidget_EventType - > hide ( ) ;
ui - > label_NoEvents - > show ( ) ;
2018-09-27 00:33:08 +01:00
}
}
2018-11-30 03:59:03 +00:00
QString MainWindow : : getEventGroupFromTabWidget ( QWidget * tab )
{
QString ret = " " ;
if ( tab = = eventTabObjectWidget )
{
ret = " object_event_group " ;
}
else if ( tab = = eventTabWarpWidget )
{
ret = " warp_event_group " ;
}
else if ( tab = = eventTabTriggerWidget )
{
ret = " coord_event_group " ;
}
else if ( tab = = eventTabBGWidget )
{
ret = " bg_event_group " ;
}
else if ( tab = = eventTabHealspotWidget )
{
ret = " heal_event_group " ;
}
return ret ;
}
2018-11-28 01:39:57 +00:00
void MainWindow : : eventTabChanged ( int index )
{
if ( ! isProgrammaticEventTabChange & & editor - > map ! = nullptr )
{
2018-11-30 03:59:03 +00:00
QString group = getEventGroupFromTabWidget ( ui - > tabWidget_EventType - > widget ( index ) ) ;
2018-11-28 01:39:57 +00:00
DraggablePixmapItem * selectedEvent = nullptr ;
2018-11-30 03:59:03 +00:00
if ( group = = " object_event_group " )
2018-11-28 01:39:57 +00:00
{
2018-12-04 19:36:22 +00:00
if ( selectedObject = = nullptr & & editor - > map - > events . value ( group ) . count ( ) )
2018-11-28 01:39:57 +00:00
{
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 ) {
2018-11-28 01:39:57 +00:00
selectedObject = item ;
break ;
}
}
}
selectedEvent = selectedObject ;
}
2018-11-30 03:59:03 +00:00
else if ( group = = " warp_event_group " )
2018-11-28 01:39:57 +00:00
{
2018-12-04 19:36:22 +00:00
if ( selectedWarp = = nullptr & & editor - > map - > events . value ( group ) . count ( ) )
2018-11-28 01:39:57 +00:00
{
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 ) {
2018-11-28 01:39:57 +00:00
selectedWarp = item ;
break ;
}
}
}
2018-09-27 00:33:08 +01:00
2018-11-28 01:39:57 +00:00
selectedEvent = selectedWarp ;
}
2018-11-30 03:59:03 +00:00
else if ( group = = " coord_event_group " )
2018-11-28 01:39:57 +00:00
{
2018-12-04 19:36:22 +00:00
if ( selectedTrigger = = nullptr & & editor - > map - > events . value ( group ) . count ( ) )
2018-11-28 01:39:57 +00:00
{
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 ) {
2018-11-28 01:39:57 +00:00
selectedTrigger = item ;
break ;
}
}
}
selectedEvent = selectedTrigger ;
}
2018-11-30 03:59:03 +00:00
else if ( group = = " bg_event_group " )
2018-11-28 01:39:57 +00:00
{
2018-12-04 19:36:22 +00:00
if ( selectedBG = = nullptr & & editor - > map - > events . value ( group ) . count ( ) )
2018-11-28 01:39:57 +00:00
{
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 ) {
2018-11-28 01:39:57 +00:00
selectedBG = item ;
break ;
}
}
}
2018-09-27 00:33:08 +01:00
2018-11-28 01:39:57 +00:00
selectedEvent = selectedBG ;
}
2018-11-30 03:59:03 +00:00
else if ( group = = " heal_event_group " )
2018-11-28 01:39:57 +00:00
{
2018-12-04 19:36:22 +00:00
if ( selectedHealspot = = nullptr & & editor - > map - > events . value ( group ) . count ( ) )
2018-11-28 01:39:57 +00:00
{
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 ) {
2018-11-28 01:39:57 +00:00
selectedHealspot = item ;
break ;
}
}
}
selectedEvent = selectedHealspot ;
}
2018-11-30 03:59:03 +00:00
if ( selectedEvent ! = nullptr )
2018-11-28 01:39:57 +00:00
editor - > selectMapEvent ( selectedEvent ) ;
2018-09-27 00:33:08 +01:00
}
2018-11-28 01:39:57 +00:00
isProgrammaticEventTabChange = false ;
}
2018-11-30 03:59:03 +00:00
void MainWindow : : selectedEventIndexChanged ( int index )
{
QString group = getEventGroupFromTabWidget ( ui - > tabWidget_EventType - > currentWidget ( ) ) ;
2019-04-06 00:21:28 +01:00
int event_offs = group = = " warp_event_group " ? 0 : 1 ;
2018-11-30 03:59:03 +00:00
Event * event = editor - > map - > events . value ( group ) . at ( index - event_offs ) ;
DraggablePixmapItem * selectedEvent = nullptr ;
for ( QGraphicsItem * child : editor - > events_group - > childItems ( ) ) {
DraggablePixmapItem * item = static_cast < DraggablePixmapItem * > ( child ) ;
if ( item - > event = = event ) {
selectedEvent = item ;
break ;
}
}
2018-09-27 00:33:08 +01:00
2018-11-30 03:59:03 +00:00
if ( selectedEvent ! = nullptr )
editor - > selectMapEvent ( selectedEvent ) ;
2018-09-27 00:33:08 +01:00
}
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 ) ;
}
2019-04-06 00:21:28 +01:00
// TODO: connect this to the DEL key when undo/redo history is extended to events
2018-09-27 00:33:08 +01:00
void MainWindow : : on_toolButton_deleteObject_clicked ( )
{
if ( editor & & editor - > selected_events ) {
if ( editor - > selected_events - > length ( ) ) {
2019-04-06 00:21:28 +01:00
DraggablePixmapItem * next_selected_event = nullptr ;
2018-09-27 00:33:08 +01:00
for ( DraggablePixmapItem * item : * editor - > selected_events ) {
2019-04-06 00:21:28 +01:00
QString event_group = item - > event - > get ( " event_group_type " ) ;
int index = editor - > map - > events . value ( event_group ) . indexOf ( item - > event ) ;
2019-11-02 23:20:41 +00:00
// Get the index for the event that should be selected after this event has been deleted.
// If it's at the end of the list, select the previous event, otherwise select the next one.
2019-04-06 00:21:28 +01:00
if ( index ! = editor - > map - > events . value ( event_group ) . size ( ) - 1 )
index + + ;
else
index - - ;
2019-11-02 23:20:41 +00:00
Event * event = nullptr ;
if ( index > = 0 )
event = editor - > map - > events . value ( event_group ) . at ( index ) ;
2019-04-06 00:21:28 +01:00
if ( event_group ! = " heal_event_group " ) {
for ( QGraphicsItem * child : editor - > events_group - > childItems ( ) ) {
DraggablePixmapItem * event_item = static_cast < DraggablePixmapItem * > ( child ) ;
if ( event_item - > event = = event ) {
next_selected_event = event_item ;
break ;
}
}
2018-09-27 00:33:08 +01:00
editor - > deleteEvent ( item - > event ) ;
if ( editor - > scene - > items ( ) . contains ( item ) ) {
editor - > scene - > removeItem ( item ) ;
}
editor - > selected_events - > removeOne ( item ) ;
}
else { // don't allow deletion of heal locations
2018-12-20 23:30:35 +00:00
logWarn ( QString ( " Cannot delete event of type '%1' " ) . arg ( item - > event - > get ( " event_type " ) ) ) ;
2018-09-27 00:33:08 +01:00
}
}
2019-04-06 00:21:28 +01:00
if ( next_selected_event ) {
editor - > selectMapEvent ( next_selected_event ) ;
}
else {
updateObjects ( ) ;
}
2018-09-27 00:33:08 +01:00
}
}
}
void MainWindow : : on_toolButton_Open_Scripts_clicked ( )
{
openInTextEditor ( ) ;
}
void MainWindow : : on_toolButton_Paint_clicked ( )
{
editor - > map_edit_mode = " paint " ;
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
if ( ui - > tabWidget_2 - > currentIndex ( ) = = 0 )
editor - > cursorMapTileRect - > stopSingleTileMode ( ) ;
2018-09-27 19:27:57 +01:00
2018-09-27 00:33:08 +01:00
ui - > scrollArea - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
ui - > scrollArea - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
QScroller : : ungrabGesture ( ui - > scrollArea ) ;
checkToolButtons ( ) ;
}
void MainWindow : : on_toolButton_Select_clicked ( )
{
editor - > map_edit_mode = " select " ;
editor - > settings - > mapCursor = QCursor ( QPixmap ( " :/icons/cursor.ico " ) , 0 , 0 ) ;
2019-01-11 14:52:35 +00:00
editor - > cursorMapTileRect - > setSingleTileMode ( ) ;
2018-09-27 19:27:57 +01:00
2018-09-27 00:33:08 +01:00
ui - > scrollArea - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
ui - > scrollArea - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
QScroller : : ungrabGesture ( ui - > scrollArea ) ;
checkToolButtons ( ) ;
}
void MainWindow : : on_toolButton_Fill_clicked ( )
{
editor - > map_edit_mode = " fill " ;
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
2018-09-27 00:33:08 +01:00
ui - > scrollArea - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
ui - > scrollArea - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
QScroller : : ungrabGesture ( ui - > scrollArea ) ;
checkToolButtons ( ) ;
}
void MainWindow : : on_toolButton_Dropper_clicked ( )
{
editor - > map_edit_mode = " pick " ;
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
ui - > scrollArea - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
ui - > scrollArea - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
QScroller : : ungrabGesture ( ui - > scrollArea ) ;
checkToolButtons ( ) ;
}
void MainWindow : : on_toolButton_Move_clicked ( )
{
editor - > map_edit_mode = " move " ;
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
2018-09-27 00:33:08 +01:00
ui - > scrollArea - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAlwaysOff ) ;
ui - > scrollArea - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAlwaysOff ) ;
QScroller : : grabGesture ( ui - > scrollArea , QScroller : : LeftMouseButtonGesture ) ;
2018-09-27 19:27:57 +01:00
2018-09-27 00:33:08 +01:00
checkToolButtons ( ) ;
}
void MainWindow : : on_toolButton_Shift_clicked ( )
{
editor - > map_edit_mode = " shift " ;
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
ui - > scrollArea - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
ui - > scrollArea - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
QScroller : : ungrabGesture ( ui - > scrollArea ) ;
checkToolButtons ( ) ;
}
void MainWindow : : checkToolButtons ( ) {
ui - > toolButton_Paint - > setChecked ( editor - > map_edit_mode = = " paint " ) ;
ui - > toolButton_Select - > setChecked ( editor - > map_edit_mode = = " select " ) ;
ui - > toolButton_Fill - > setChecked ( editor - > map_edit_mode = = " fill " ) ;
ui - > toolButton_Dropper - > setChecked ( editor - > map_edit_mode = = " pick " ) ;
ui - > toolButton_Move - > setChecked ( editor - > map_edit_mode = = " move " ) ;
ui - > toolButton_Shift - > setChecked ( editor - > map_edit_mode = = " shift " ) ;
}
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 ) ;
}
void MainWindow : : onMapChanged ( Map * map ) {
map - > layout - > has_unsaved_changes = true ;
updateMapList ( ) ;
}
void MainWindow : : onMapNeedsRedrawing ( ) {
redrawMapScene ( ) ;
}
2018-10-03 01:01:15 +01:00
void MainWindow : : onTilesetsSaved ( QString primaryTilesetLabel , QString secondaryTilesetLabel ) {
this - > editor - > updatePrimaryTileset ( primaryTilesetLabel , true ) ;
this - > editor - > updateSecondaryTileset ( secondaryTilesetLabel , true ) ;
}
2018-09-27 00:33:08 +01:00
void MainWindow : : on_action_Export_Map_Image_triggered ( )
{
2019-05-21 03:08:04 +01:00
if ( ! this - > mapImageExporter ) {
this - > mapImageExporter = new MapImageExporter ( this , this - > editor ) ;
connect ( this - > mapImageExporter , & QObject : : destroyed , [ = ] ( QObject * ) { this - > mapImageExporter = nullptr ; } ) ;
this - > mapImageExporter - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
}
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
}
}
void MainWindow : : on_comboBox_ConnectionDirection_currentIndexChanged ( const QString & direction )
{
editor - > updateCurrentConnectionDirection ( direction ) ;
}
void MainWindow : : on_spinBox_ConnectionOffset_valueChanged ( int offset )
{
editor - > updateConnectionOffset ( offset ) ;
}
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
{
2019-09-21 21:59:14 +01:00
if ( editor - > project - > mapNames - > contains ( mapName ) )
editor - > setConnectionMap ( mapName ) ;
2018-09-27 00:33:08 +01:00
}
void MainWindow : : on_pushButton_AddConnection_clicked ( )
{
editor - > addNewConnection ( ) ;
}
void MainWindow : : on_pushButton_RemoveConnection_clicked ( )
{
editor - > removeCurrentConnection ( ) ;
}
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
}
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
{
2019-09-21 21:59:14 +01:00
if ( editor - > project - > mapNames - > contains ( mapName ) )
editor - > updateDiveMap ( mapName ) ;
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
{
2019-09-21 21:59:14 +01:00
if ( editor - > project - > mapNames - > contains ( mapName ) )
editor - > updateEmergeMap ( mapName ) ;
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
{
2019-09-21 21:59:14 +01:00
if ( editor - > project - > tilesetLabels [ " primary " ] . contains ( tilesetLabel ) & & editor - > map ) {
editor - > updatePrimaryTileset ( tilesetLabel ) ;
on_horizontalSlider_MetatileZoom_valueChanged ( ui - > horizontalSlider_MetatileZoom - > value ( ) ) ;
}
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
{
2019-09-21 21:59:14 +01:00
if ( editor - > project - > tilesetLabels [ " secondary " ] . contains ( tilesetLabel ) & & editor - > map ) {
editor - > updateSecondaryTileset ( tilesetLabel ) ;
on_horizontalSlider_MetatileZoom_valueChanged ( ui - > horizontalSlider_MetatileZoom - > value ( ) ) ;
}
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 ) ;
2018-09-27 00:33:08 +01:00
// See below for explanation of maximum map dimensions
widthSpinBox - > setMaximum ( 0x1E7 ) ;
heightSpinBox - > setMaximum ( 0x1D1 ) ;
2020-03-14 07:44:55 +00:00
// Maximum based only on data type (u8) of map border width/height
bwidthSpinBox - > setMaximum ( 255 ) ;
bheightSpinBox - > setMaximum ( 255 ) ;
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 ( ) ;
QPalette errorPalette ;
errorPalette . setColor ( QPalette : : WindowText , Qt : : red ) ;
errorLabel - > setPalette ( errorPalette ) ;
errorLabel - > setVisible ( false ) ;
QDialogButtonBox buttonBox ( QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel , Qt : : Horizontal , & dialog ) ;
form . addRow ( & buttonBox ) ;
2020-03-14 07:44:55 +00:00
connect ( & buttonBox , & QDialogButtonBox : : accepted , [ & dialog , & widthSpinBox , & heightSpinBox , & bwidthSpinBox , & bheightSpinBox , & errorLabel ] ( ) {
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)
// This limit can be found in fieldmap.c in pokeruby/pokeemerald.
int realWidth = widthSpinBox - > value ( ) + 15 ;
int realHeight = heightSpinBox - > value ( ) + 14 ;
int numMetatiles = realWidth * realHeight ;
if ( numMetatiles < = 0x2800 ) {
dialog . accept ( ) ;
} else {
QString errorText = QString ( " Error: The specified width and height are too large. \n "
2020-03-14 07:44:55 +00:00
" The maximum map width and height is the following: (width + 15) * (height + 14) <= 10240 \n "
" The specified map width and height was: (%1 + 15) * (%2 + 14) = %3 " )
2018-09-27 00:33:08 +01:00
. arg ( widthSpinBox - > value ( ) )
. arg ( heightSpinBox - > value ( ) )
. arg ( numMetatiles ) ;
errorLabel - > setText ( errorText ) ;
errorLabel - > setVisible ( true ) ;
}
} ) ;
connect ( & buttonBox , SIGNAL ( rejected ( ) ) , & dialog , SLOT ( reject ( ) ) ) ;
form . addRow ( errorLabel ) ;
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
editor - > map - > setDimensions ( widthSpinBox - > value ( ) , heightSpinBox - > value ( ) ) ;
2020-03-14 07:44:55 +00:00
editor - > map - > setBorderDimensions ( bwidthSpinBox - > value ( ) , bheightSpinBox - > value ( ) ) ;
2018-09-27 00:33:08 +01:00
editor - > map - > commit ( ) ;
onMapNeedsRedrawing ( ) ;
}
}
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 ) {
editor - > cursorMapTileRect - > setSmartPathMode ( ) ;
} else {
editor - > cursorMapTileRect - > setNormalPathMode ( ) ;
}
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 ) {
2018-10-03 01:01:24 +01:00
this - > tilesetEditor = new TilesetEditor ( this - > editor - > project , this - > editor - > map - > layout - > tileset_primary_label , this - > editor - > map - > layout - > tileset_secondary_label , this ) ;
2018-10-03 01:01:15 +01:00
connect ( this - > tilesetEditor , SIGNAL ( tilesetsSaved ( QString , QString ) ) , this , SLOT ( onTilesetsSaved ( QString , QString ) ) ) ;
2018-12-26 22:49:43 +00:00
connect ( this - > tilesetEditor , & QObject : : destroyed , [ = ] ( QObject * ) { this - > tilesetEditor = nullptr ; } ) ;
this - > tilesetEditor - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
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 {
this - > tilesetEditor - > activateWindow ( ) ;
}
}
2019-01-06 18:53:31 +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 ( ) ;
}
2019-08-14 22:39:23 +01:00
void MainWindow : : on_actionThemes_triggered ( )
{
QStringList themes ;
2019-08-21 20:30:44 +01:00
QRegularExpression re ( " :/themes/([A-z0-9_-]+) . qss " ) ;
2019-08-14 22:39:23 +01:00
themes . append ( " default " ) ;
QDirIterator it ( " :/themes " , QDirIterator : : Subdirectories ) ;
while ( it . hasNext ( ) ) {
QString themeName = re . match ( it . next ( ) ) . captured ( 1 ) ;
themes . append ( themeName ) ;
}
QDialog themeSelectorWindow ( this ) ;
QFormLayout form ( & themeSelectorWindow ) ;
NoScrollComboBox * themeSelector = new NoScrollComboBox ( ) ;
themeSelector - > addItems ( themes ) ;
2019-08-14 23:02:00 +01:00
themeSelector - > setCurrentText ( porymapConfig . getTheme ( ) ) ;
2019-08-14 22:39:23 +01:00
form . addRow ( new QLabel ( " Themes " ) , themeSelector ) ;
QDialogButtonBox buttonBox ( QDialogButtonBox : : Apply | QDialogButtonBox : : Close , Qt : : Horizontal , & themeSelectorWindow ) ;
form . addRow ( & buttonBox ) ;
connect ( & buttonBox , & QDialogButtonBox : : clicked , [ & themeSelectorWindow , & buttonBox , themeSelector , this ] ( QAbstractButton * button ) {
if ( button = = buttonBox . button ( QDialogButtonBox : : Apply ) ) {
QString theme = themeSelector - > currentText ( ) ;
2019-08-14 23:02:00 +01:00
porymapConfig . setTheme ( theme ) ;
this - > setTheme ( theme ) ;
2019-08-14 22:39:23 +01:00
}
} ) ;
connect ( & buttonBox , SIGNAL ( rejected ( ) ) , & themeSelectorWindow , SLOT ( reject ( ) ) ) ;
themeSelectorWindow . exec ( ) ;
}
2019-02-03 16:38:45 +00:00
void MainWindow : : on_pushButton_AddCustomHeaderField_clicked ( )
{
int rowIndex = this - > ui - > tableWidget_CustomHeaderFields - > rowCount ( ) ;
this - > ui - > tableWidget_CustomHeaderFields - > insertRow ( rowIndex ) ;
this - > ui - > tableWidget_CustomHeaderFields - > selectRow ( rowIndex ) ;
this - > editor - > updateCustomMapHeaderValues ( this - > ui - > tableWidget_CustomHeaderFields ) ;
}
void MainWindow : : on_pushButton_DeleteCustomHeaderField_clicked ( )
{
int rowCount = this - > ui - > tableWidget_CustomHeaderFields - > rowCount ( ) ;
if ( rowCount > 0 ) {
QModelIndexList indexList = ui - > tableWidget_CustomHeaderFields - > selectionModel ( ) - > selectedIndexes ( ) ;
QList < QPersistentModelIndex > persistentIndexes ;
for ( QModelIndex index : indexList ) {
QPersistentModelIndex persistentIndex ( index ) ;
persistentIndexes . append ( persistentIndex ) ;
}
for ( QPersistentModelIndex index : persistentIndexes ) {
this - > ui - > tableWidget_CustomHeaderFields - > removeRow ( index . row ( ) ) ;
}
if ( this - > ui - > tableWidget_CustomHeaderFields - > rowCount ( ) > 0 ) {
this - > ui - > tableWidget_CustomHeaderFields - > selectRow ( 0 ) ;
}
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 ) ;
QMatrix matrix ;
matrix . scale ( scale , scale ) ;
QSize size ( editor - > metatile_selector_item - > pixmap ( ) . width ( ) ,
editor - > metatile_selector_item - > pixmap ( ) . height ( ) ) ;
size * = scale ;
ui - > graphicsView_Metatiles - > setResizeAnchor ( QGraphicsView : : NoAnchor ) ;
ui - > graphicsView_Metatiles - > setMatrix ( matrix ) ;
ui - > graphicsView_Metatiles - > setFixedSize ( size . width ( ) + 2 , size . height ( ) + 2 ) ;
2019-02-25 20:09:36 +00:00
ui - > graphicsView_BorderMetatile - > setMatrix ( matrix ) ;
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 ) ;
ui - > graphicsView_currentMetatileSelection - > setMatrix ( matrix ) ;
currentMetatilesSelectionChanged ( ) ;
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 ) {
this - > regionMapEditor = new RegionMapEditor ( this , this - > editor - > project ) ;
2020-02-12 21:45:21 +00:00
bool success = this - > regionMapEditor - > loadRegionMapData ( )
& & this - > regionMapEditor - > loadCityMaps ( ) ;
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 ;
}
2019-01-07 19:46:27 +00:00
connect ( this - > regionMapEditor , & QObject : : destroyed , [ = ] ( QObject * ) { this - > regionMapEditor = nullptr ; } ) ;
this - > regionMapEditor - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
}
if ( ! this - > regionMapEditor - > isVisible ( ) ) {
this - > regionMapEditor - > show ( ) ;
} else if ( this - > regionMapEditor - > isMinimized ( ) ) {
this - > regionMapEditor - > showNormal ( ) ;
} else {
this - > regionMapEditor - > activateWindow ( ) ;
}
2019-01-05 22:59:57 +00:00
}
2019-01-06 18:53:31 +00:00
void MainWindow : : closeEvent ( QCloseEvent * event ) {
2019-08-07 15:48:07 +01:00
if ( projectHasUnsavedChanges | | 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-01-07 23:14:44 +00:00
porymapConfig . setGeometry (
this - > saveGeometry ( ) ,
this - > saveState ( ) ,
this - > ui - > splitter_map - > saveState ( ) ,
this - > ui - > splitter_events - > saveState ( ) ,
this - > ui - > splitter_main - > saveState ( )
) ;
2019-01-06 18:53:31 +00:00
porymapConfig . save ( ) ;
2019-07-03 21:21:48 +01:00
projectConfig . save ( ) ;
2019-01-06 18:53:31 +00:00
QMainWindow : : closeEvent ( event ) ;
}