@@ -752,9 +752,9 @@ def changeTileCurrent(self, changeTo):
752752 self .myMapWidget .currentTile = changeTo
753753 self .myPaletteWidget .setImageCurrent (changeTo )
754754
755- def __init__ (self , parent = None , ** kwargs ):
755+ def __init__ (self , filelist , ** kwargs ):
756756 global sSettings
757- super ().__init__ (parent , ** kwargs )
757+ super ().__init__ (None , ** kwargs )
758758
759759 self .resize (1024 , 768 )
760760
@@ -781,6 +781,40 @@ def __init__(self, parent=None, **kwargs):
781781
782782 self .FancyWindow (self )
783783
784+ self .opemFileIfDropped (filelist )
785+
786+ self .setAcceptDrops (True )
787+
788+ def dragEnterEvent (self , event ):
789+ if event .mimeData ().hasUrls :
790+ event .accept ()
791+ else :
792+ event .ignore ()
793+
794+ def dragMoveEvent (self , event ):
795+ if event .mimeData ().hasUrls :
796+ event .accept ()
797+ else :
798+ event .ignore ()
799+
800+ def dropEvent (self , event ):
801+ if event .mimeData ().hasUrls :
802+ event .accept ()
803+ self .opemFileIfDropped (event .mimeData ().urls ()[0 ].toLocalFile ())
804+
805+ else :
806+ event .ignore ()
807+
808+ def opemFileIfDropped (self , filelist ):
809+ if (isinstance (filelist ,str )):
810+ if (".map.json" in filelist ):
811+ self .openFileByName (filelist )
812+
813+ else :
814+ matching = [s for s in filelist if ".map.json" in s ]
815+ if len (matching ) > 0 :
816+ self .openFileByName (matching [0 ])
817+
784818 def selectStartPosition (self ):
785819 result = gameInit .selectStartingPosition (self , sSettings )
786820
@@ -995,12 +1029,8 @@ def exportToJsAs(self):
9951029 sSettings ["workingFile" ] = filename
9961030 self .myMap .exportJS (sSettings ["workingFile" ])
9971031
998- def openFile (self ):
1032+ def openFileByName (self , filename ):
9991033 global sSettings
1000- if (sSettings ["gamefolder" ] == "" ):
1001- sSettings ["gamefolder" ] = os .path .expanduser ("~" )
1002- filename = QtWidgets .QFileDialog .getOpenFileName (
1003- self , 'Open File' , sSettings ["gamefolder" ], "JSON Level (*.map.json);;All Files (*)" )[0 ]
10041034 if os .path .isfile (filename ):
10051035 sSettings ["gamefolder" ] = os .path .abspath (
10061036 os .path .join (os .path .dirname (str (filename )), "../../" ))
@@ -1016,6 +1046,14 @@ def openFile(self):
10161046 self .myEventsWidget .updateEventsList ()
10171047 self .myCharasPalWidget .reinit ()
10181048
1049+ def openFile (self ):
1050+ global sSettings
1051+ if (sSettings ["gamefolder" ] == "" ):
1052+ sSettings ["gamefolder" ] = os .path .expanduser ("~" )
1053+ filename = QtWidgets .QFileDialog .getOpenFileName (
1054+ self , 'Open File' , sSettings ["gamefolder" ], "JSON Level (*.map.json);;All Files (*)" )[0 ]
1055+ self .openFileByName (filename )
1056+
10191057 def helpAbout (self ):
10201058 credits = "Made by Erico\n With help from the internet.\n Higly based in Tsubasa's Redo, and inspired in Enterbrain's RPG Maker 2000.\n Thanks Nintendo for making the SNES."
10211059 QMessageBox .about (self , "About..." , credits )
@@ -1035,23 +1073,3 @@ def closeEvent(self, event):
10351073
10361074def Icon ():
10371075 return QPixmap ('icon.png' )
1038-
1039- def Editor ():
1040- from sys import argv , exit
1041- global __mwind__
1042-
1043- a = QApplication (argv )
1044- start = time ()
1045- splash_pix = Icon ()
1046- splash = QSplashScreen (splash_pix , Qt .WindowStaysOnTopHint )
1047- splash .setMask (splash_pix .mask ())
1048- splash .show ()
1049- while time () - start < 1 :
1050- sleep (0.001 )
1051- a .processEvents ()
1052- __mwind__ = MainWindow ()
1053- a .processEvents ()
1054- __mwind__ .show ()
1055- splash .finish (__mwind__ )
1056- __mwind__ .raise_ ()
1057- exit (a .exec_ ())
0 commit comments