129 lines
3.4 KiB
GDScript
129 lines
3.4 KiB
GDScript
extends Control
|
|
|
|
|
|
var dir = Directory.new()
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
OS.request_permissions()
|
|
$ImportDialog.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)
|
|
$ExportDialog.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)
|
|
if OS.get_name() == "HTML5":
|
|
$pm/opts/save.hide()
|
|
$pm/opts/delete.hide()
|
|
get_tree().connect("files_dropped",self,"_on_file_drop")
|
|
|
|
|
|
func _on_List_item_selected(index):
|
|
#update buttons if to be clickable.
|
|
var preyname = $pm/List.get_item_text(index)
|
|
var dat = Global.preydata[preyname]
|
|
#print(dat)
|
|
$pm/opts/delete.disabled = (dat.get('file') == null)
|
|
$pm/opts/remove.disabled = false
|
|
$pm/opts/save.disabled = (dat.get('file') != null)
|
|
$pm/opts/edit.disabled = false
|
|
$pm/opts/copy.disabled = false
|
|
$pm/opts/export.disabled = false
|
|
|
|
|
|
func _on_List_nothing_selected():
|
|
#print("nothing selected")
|
|
$pm/opts/delete.disabled = true
|
|
$pm/opts/remove.disabled = true
|
|
$pm/opts/save.disabled = true
|
|
$pm/opts/edit.disabled = true
|
|
$pm/opts/copy.disabled = true
|
|
$pm/opts/export.disabled = true
|
|
|
|
|
|
func _on_remove_pressed():
|
|
var index = $pm/List.get_selected_items()[0]
|
|
var preyname = $pm/List.get_item_text(index)
|
|
Global.preydata.erase(preyname)
|
|
$pm/List.remove_item(index)
|
|
_on_List_nothing_selected()
|
|
|
|
|
|
func _on_delete_pressed():
|
|
$DelConf.popup_centered()
|
|
|
|
|
|
func _on_save_pressed():
|
|
$SaveConf.popup_centered()
|
|
|
|
|
|
func _on_DelConf_confirmed():
|
|
#delete prey file from disk
|
|
var index = $pm/List.get_selected_items()[0]
|
|
var preyname = $pm/List.get_item_text(index)
|
|
dir.remove(Global.preydata[preyname]['file'])
|
|
Global.preydata[preyname]['file'] = null
|
|
$pm/opts/save.disabled = false
|
|
$pm/opts/delete.disabled = true
|
|
|
|
|
|
func _on_edit_pressed():
|
|
var preyname = $pm/List.prey_selected()
|
|
Global.preytoedit = preyname
|
|
get_tree().change_scene("res://PreyEdit.tscn")
|
|
|
|
|
|
func _on_add_pressed():
|
|
if OS.get_name() == "HTML5":
|
|
OS.alert("To import prey in the browser, drag and drop a PNG image or .prey file into the Prey Manager.")
|
|
else:
|
|
$ImportDialog.popup_centered()
|
|
|
|
|
|
func _on_ImportDialog_file_selected(path):
|
|
if Global.import_prey(path,true):
|
|
$pm/List.refresh()
|
|
else:
|
|
print("err")
|
|
|
|
|
|
func _on_SaveConf_confirmed():
|
|
var preyname = $pm/List.prey_selected()
|
|
print("selected is ",preyname)
|
|
var fname = "user://prey/"+preyname+".prey"
|
|
Global.save_prey(fname,preyname)
|
|
Global.preydata[preyname]['file'] = fname
|
|
$pm/opts/save.disabled = true
|
|
$pm/opts/delete.disabled = false
|
|
|
|
|
|
func _on_export_pressed():
|
|
var preyname = $pm/List.prey_selected()
|
|
if OS.get_name() == "HTML5":
|
|
Global.save_prey("/tmp/prey",preyname)
|
|
var temp = File.new()
|
|
temp.open("/tmp/prey",File.READ)
|
|
JavaScript.download_buffer(temp.get_buffer(temp.get_len()),preyname+".prey")
|
|
temp.close()
|
|
else:
|
|
$ExportDialog.popup_centered()
|
|
|
|
|
|
func _on_file_drop(files:PoolStringArray,from_screen):
|
|
for file in files:
|
|
Global.import_prey(file,true)
|
|
$pm/List.refresh()
|
|
|
|
|
|
func _on_copy_pressed():
|
|
var preyname = $pm/List.prey_selected()
|
|
var newprey:String = preyname+" Copy "
|
|
var i:int = 1
|
|
while Global.preydata.has(newprey+str(i)):
|
|
i+=1
|
|
newprey += str(i)
|
|
Global.preydata[newprey] = Global.preydata[preyname].duplicate(true)
|
|
Global.preydata[newprey]["file"] = null #make sure new prey is only in memory
|
|
Global.preydata[newprey]["shape"] = Global.preydata[preyname]["shape"].duplicate()
|
|
$pm/List.refresh()
|
|
|
|
|
|
func _on_ExportDialog_file_selected(path):
|
|
var preyname = $pm/List.prey_selected()
|
|
Global.save_prey(path,preyname)
|