mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
fa5e9997ef
here we go Reviewed-on: https://codeberg.org/Eroax/Re-DotDeck/pulls/2 Co-authored-by: Lera Elvoé <yagich@poto.cafe> Co-committed-by: Lera Elvoé <yagich@poto.cafe>
127 lines
4 KiB
GDScript
127 lines
4 KiB
GDScript
extends Control
|
|
|
|
const DECK_SCENE := preload("res://graph_node_renderer/deck_renderer_graph_edit.tscn")
|
|
|
|
@onready var tab_container: TabContainerCustom = %TabContainerCustom as TabContainerCustom
|
|
@onready var file_dialog: FileDialog = $FileDialog
|
|
|
|
enum FileMenuId {
|
|
NEW,
|
|
OPEN,
|
|
SAVE = 3,
|
|
SAVE_AS,
|
|
CLOSE = 6,
|
|
}
|
|
|
|
var _deck_to_save: WeakRef
|
|
|
|
|
|
func _ready() -> void:
|
|
tab_container.add_button_pressed.connect(add_empty_deck)
|
|
|
|
tab_container.tab_close_requested.connect(
|
|
func(tab: int):
|
|
DeckHolder.close_deck(tab_container.get_tab_metadata(tab))
|
|
tab_container.close_tab(tab)
|
|
)
|
|
|
|
file_dialog.canceled.connect(disconnect_file_dialog_signals)
|
|
|
|
|
|
func _on_file_id_pressed(id: int) -> void:
|
|
match id:
|
|
FileMenuId.NEW:
|
|
add_empty_deck()
|
|
FileMenuId.OPEN:
|
|
open_open_dialog("res://")
|
|
FileMenuId.SAVE:
|
|
save_active_deck()
|
|
FileMenuId.SAVE_AS:
|
|
open_save_dialog("res://")
|
|
FileMenuId.CLOSE:
|
|
close_current_tab()
|
|
|
|
|
|
func add_empty_deck() -> void:
|
|
var deck := DeckHolder.add_empty_deck()
|
|
var inst: DeckRendererGraphEdit = DECK_SCENE.instantiate()
|
|
inst.deck = deck
|
|
tab_container.add_content(inst, "Deck %s" % (tab_container.get_tab_count() + 1))
|
|
tab_container.set_tab_metadata(tab_container.get_current_tab(), deck)
|
|
inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested.bind(deck))
|
|
|
|
|
|
func close_current_tab() -> void:
|
|
tab_container.close_tab(tab_container.get_current_tab())
|
|
|
|
|
|
func open_save_dialog(path: String) -> void:
|
|
file_dialog.file_mode = FileDialog.FILE_MODE_SAVE_FILE
|
|
file_dialog.title = "Save a Deck"
|
|
file_dialog.current_path = path
|
|
_deck_to_save = weakref(get_active_deck())
|
|
file_dialog.popup_centered()
|
|
file_dialog.file_selected.connect(_on_file_dialog_save_file, CONNECT_ONE_SHOT)
|
|
|
|
|
|
func open_open_dialog(path: String) -> void:
|
|
file_dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILES
|
|
file_dialog.title = "Open Deck(s)"
|
|
file_dialog.current_path = path
|
|
file_dialog.popup_centered()
|
|
file_dialog.files_selected.connect(_on_file_dialog_open_files, CONNECT_ONE_SHOT)
|
|
|
|
|
|
func _on_file_dialog_save_file(path: String) -> void:
|
|
var deck: Deck = _deck_to_save.get_ref() as Deck
|
|
if !deck:
|
|
return
|
|
|
|
deck.save_path = path
|
|
var json := JSON.stringify(deck.to_dict(), "\t")
|
|
var f := FileAccess.open(path, FileAccess.WRITE)
|
|
f.store_string(json)
|
|
|
|
|
|
func _on_file_dialog_open_files(paths: PackedStringArray) -> void:
|
|
for path in paths:
|
|
var deck := DeckHolder.open_deck_from_file(path)
|
|
var inst: DeckRendererGraphEdit = DECK_SCENE.instantiate()
|
|
inst.deck = deck
|
|
tab_container.add_content(inst, "Deck %s" % (tab_container.get_tab_count() + 1))
|
|
inst.initialize_from_deck()
|
|
inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested.bind(deck))
|
|
|
|
|
|
func get_active_deck() -> Deck:
|
|
if tab_container.is_empty():
|
|
return null
|
|
|
|
return (tab_container.get_content(tab_container.get_current_tab()) as DeckRendererGraphEdit).deck
|
|
|
|
|
|
func save_active_deck() -> void:
|
|
if get_active_deck().save_path.is_empty():
|
|
open_save_dialog("res://")
|
|
else:
|
|
var json := JSON.stringify(get_active_deck().to_dict(), "\t")
|
|
var f := FileAccess.open(get_active_deck().save_path, FileAccess.WRITE)
|
|
f.store_string(json)
|
|
|
|
|
|
func disconnect_file_dialog_signals() -> void:
|
|
if file_dialog.file_selected.is_connected(_on_file_dialog_save_file):
|
|
file_dialog.file_selected.disconnect(_on_file_dialog_save_file)
|
|
|
|
if file_dialog.files_selected.is_connected(_on_file_dialog_open_files):
|
|
file_dialog.files_selected.disconnect(_on_file_dialog_open_files)
|
|
|
|
|
|
func _on_deck_renderer_group_enter_requested(group_id: String, deck: Deck) -> void:
|
|
var group_deck := deck.get_group(group_id)
|
|
var deck_renderer: DeckRendererGraphEdit = DECK_SCENE.instantiate()
|
|
deck_renderer.deck = group_deck
|
|
deck_renderer.initialize_from_deck()
|
|
tab_container.add_content(deck_renderer, "Group %s" % (tab_container.get_tab_count() + 1))
|
|
tab_container.set_tab_metadata(tab_container.get_current_tab(), group_deck)
|
|
deck_renderer.group_enter_requested.connect(_on_deck_renderer_group_enter_requested.bind(deck_renderer.deck))
|