2023-12-15 22:44:25 +01:00
|
|
|
# (c) 2023-present Eroax
|
|
|
|
# (c) 2023-present Yagich
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2023-11-22 05:26:11 +01:00
|
|
|
extends Control
|
2023-11-25 11:40:43 +01:00
|
|
|
class_name DeckHolderRenderer
|
2023-11-22 05:26:11 +01:00
|
|
|
|
2023-11-25 11:40:43 +01:00
|
|
|
## Renderer class for [DeckHolder]
|
|
|
|
##
|
|
|
|
## Entry point for the [GraphEdit] based Renderer
|
|
|
|
|
2023-12-15 22:44:25 +01:00
|
|
|
## Reference to the base scene for [DeckRessssssndererGraphEdit]
|
2023-11-22 05:26:11 +01:00
|
|
|
const DECK_SCENE := preload("res://graph_node_renderer/deck_renderer_graph_edit.tscn")
|
2023-12-15 22:44:25 +01:00
|
|
|
const DEBUG_DECKS_LIST := preload("res://graph_node_renderer/debug_decks_list.tscn")
|
|
|
|
|
|
|
|
const PERSISTENCE_NAMESPACE := "default"
|
2023-11-22 05:26:11 +01:00
|
|
|
|
2023-11-25 11:40:43 +01:00
|
|
|
## Reference to the main windows [TabContainerCustom]
|
2023-12-15 22:44:25 +01:00
|
|
|
@onready var tab_container := %TabContainerCustom as TabContainerCustom
|
2023-11-25 11:40:43 +01:00
|
|
|
## Reference to the [FileDialog] used for File operations through the program.
|
2023-11-22 05:26:11 +01:00
|
|
|
@onready var file_dialog: FileDialog = $FileDialog
|
|
|
|
|
2023-12-15 22:44:25 +01:00
|
|
|
@export var new_deck_shortcut: Shortcut
|
|
|
|
@export var open_deck_shortcut: Shortcut
|
|
|
|
@export var save_deck_shortcut: Shortcut
|
|
|
|
@export var save_deck_as_shortcut: Shortcut
|
|
|
|
@export var close_deck_shortcut: Shortcut
|
|
|
|
|
2023-11-25 11:40:43 +01:00
|
|
|
## Enum for storing the Options in the "File" PopupMenu.
|
2023-11-22 05:26:11 +01:00
|
|
|
enum FileMenuId {
|
|
|
|
NEW,
|
|
|
|
OPEN,
|
|
|
|
SAVE = 3,
|
|
|
|
SAVE_AS,
|
|
|
|
CLOSE = 6,
|
2023-12-15 22:44:25 +01:00
|
|
|
RECENTS,
|
|
|
|
}
|
|
|
|
@onready var file_popup_menu: PopupMenu = %File as PopupMenu
|
|
|
|
var max_recents := 4
|
|
|
|
var recent_files := []
|
|
|
|
var recent_path: String
|
|
|
|
@onready var unsaved_changes_dialog_single_deck := $UnsavedChangesDialogSingleDeck as UnsavedChangesDialogSingleDeck
|
|
|
|
@onready var unsaved_changes_dialog: ConfirmationDialog = $UnsavedChangesDialog
|
|
|
|
|
|
|
|
enum ConnectionsMenuId {
|
|
|
|
OBS,
|
|
|
|
TWITCH,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum DebugMenuId {
|
|
|
|
DECKS,
|
|
|
|
EMBED_SUBWINDOWS,
|
|
|
|
}
|
|
|
|
@onready var debug_popup_menu: PopupMenu = %Debug
|
|
|
|
|
|
|
|
enum HelpMenuId {
|
|
|
|
DOCS,
|
|
|
|
ABOUT,
|
2023-11-22 05:26:11 +01:00
|
|
|
}
|
2023-12-15 22:44:25 +01:00
|
|
|
@onready var about_dialog: AcceptDialog = %AboutDialog
|
2023-11-22 05:26:11 +01:00
|
|
|
|
2023-11-25 11:40:43 +01:00
|
|
|
## Weak Reference to the Deck that is currently going to be saved.
|
2023-11-22 05:26:11 +01:00
|
|
|
var _deck_to_save: WeakRef
|
|
|
|
|
2023-12-15 22:44:25 +01:00
|
|
|
@onready var no_obsws := %NoOBSWS as NoOBSWS
|
|
|
|
|
|
|
|
@onready var obs_setup_dialog := $OBSWebsocketSetupDialog as OBSWebsocketSetupDialog
|
|
|
|
@onready var twitch_setup_dialog := $Twitch_Setup_Dialog as TwitchSetupDialog
|
2024-01-17 03:07:24 +01:00
|
|
|
@onready var bottom_dock: TabContainer = %BottomDock
|
2023-12-15 22:44:25 +01:00
|
|
|
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
func _ready() -> void:
|
2023-12-15 22:44:25 +01:00
|
|
|
get_tree().auto_accept_quit = false
|
2023-11-22 05:26:11 +01:00
|
|
|
tab_container.add_button_pressed.connect(add_empty_deck)
|
2023-12-15 22:44:25 +01:00
|
|
|
tab_container.tab_changed.connect(_on_tab_container_tab_changed)
|
|
|
|
RendererPersistence.init_namespace(PERSISTENCE_NAMESPACE)
|
|
|
|
|
|
|
|
var embed_subwindows: bool = RendererPersistence.get_or_create(PERSISTENCE_NAMESPACE, "config", "embed_subwindows", true)
|
|
|
|
debug_popup_menu.set_item_checked(
|
|
|
|
DebugMenuId.EMBED_SUBWINDOWS,
|
|
|
|
embed_subwindows
|
|
|
|
)
|
|
|
|
|
|
|
|
get_tree().get_root().gui_embed_subwindows = embed_subwindows
|
|
|
|
file_dialog.use_native_dialog = !embed_subwindows
|
|
|
|
|
|
|
|
recent_files = RendererPersistence.get_or_create(
|
|
|
|
PERSISTENCE_NAMESPACE, "config",
|
|
|
|
"recent_files", []
|
|
|
|
)
|
|
|
|
recent_path = RendererPersistence.get_or_create(
|
|
|
|
PERSISTENCE_NAMESPACE, "config",
|
|
|
|
"recent_path", OS.get_system_dir(OS.SYSTEM_DIR_DOCUMENTS)
|
|
|
|
)
|
|
|
|
add_recents_to_menu()
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
tab_container.tab_close_requested.connect(
|
|
|
|
func(tab: int):
|
2023-12-15 22:44:25 +01:00
|
|
|
if tab_container.get_tab_metadata(tab, "dirty") && !tab_container.get_tab_metadata(tab, "group"):
|
|
|
|
unsaved_changes_dialog_single_deck.set_meta("tab", tab)
|
|
|
|
unsaved_changes_dialog_single_deck.show()
|
|
|
|
return
|
2024-01-15 08:23:47 +01:00
|
|
|
await close_tab(tab)
|
2023-11-22 05:26:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
file_dialog.canceled.connect(disconnect_file_dialog_signals)
|
2023-12-15 22:44:25 +01:00
|
|
|
Connections.obs_websocket = no_obsws
|
|
|
|
Connections.twitch = %Twitch_Connection
|
|
|
|
|
|
|
|
Connections.twitch.chat_socket.chat_received_rich.connect(Connections._twitch_chat_received)
|
|
|
|
|
|
|
|
file_popup_menu.set_item_shortcut(FileMenuId.NEW, new_deck_shortcut)
|
|
|
|
file_popup_menu.set_item_shortcut(FileMenuId.OPEN, open_deck_shortcut)
|
|
|
|
file_popup_menu.set_item_shortcut(FileMenuId.SAVE, save_deck_shortcut)
|
|
|
|
file_popup_menu.set_item_shortcut(FileMenuId.SAVE_AS, save_deck_as_shortcut)
|
|
|
|
file_popup_menu.set_item_shortcut(FileMenuId.CLOSE, close_deck_shortcut)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_tab_container_tab_changed(tab: int) -> void:
|
|
|
|
var is_group = tab_container.get_tab_metadata(tab, "group", false)
|
|
|
|
file_popup_menu.set_item_disabled(FileMenuId.SAVE, is_group)
|
|
|
|
file_popup_menu.set_item_disabled(FileMenuId.SAVE_AS, is_group)
|
|
|
|
|
2023-11-22 05:26:11 +01:00
|
|
|
|
2023-11-25 12:01:17 +01:00
|
|
|
## Called when the File button in the [MenuBar] is pressed with the [param id]
|
2023-11-25 11:40:43 +01:00
|
|
|
## of the button within it that was pressed.
|
2023-11-22 05:26:11 +01:00
|
|
|
func _on_file_id_pressed(id: int) -> void:
|
|
|
|
match id:
|
|
|
|
FileMenuId.NEW:
|
|
|
|
add_empty_deck()
|
|
|
|
FileMenuId.OPEN:
|
2023-12-15 22:44:25 +01:00
|
|
|
open_open_dialog(recent_path)
|
|
|
|
FileMenuId.SAVE when tab_container.get_tab_count() > 0:
|
2023-11-22 05:26:11 +01:00
|
|
|
save_active_deck()
|
2023-12-15 22:44:25 +01:00
|
|
|
FileMenuId.SAVE_AS when tab_container.get_tab_count() > 0:
|
|
|
|
open_save_dialog(tab_container.get_tab_metadata(tab_container.get_current_tab(), "path"))
|
2023-11-22 05:26:11 +01:00
|
|
|
FileMenuId.CLOSE:
|
|
|
|
close_current_tab()
|
2023-12-15 22:44:25 +01:00
|
|
|
_ when id in range(FileMenuId.RECENTS, FileMenuId.RECENTS + max_recents + 1):
|
|
|
|
open_deck_at_path(recent_files[id - FileMenuId.RECENTS - 1])
|
2023-11-22 05:26:11 +01:00
|
|
|
|
2023-11-25 11:40:43 +01:00
|
|
|
## Adds an empty [DeckRendererGraphEdit] with a corresponding [Deck] for it's data.
|
2023-11-22 05:26:11 +01:00
|
|
|
func add_empty_deck() -> void:
|
|
|
|
var deck := DeckHolder.add_empty_deck()
|
|
|
|
var inst: DeckRendererGraphEdit = DECK_SCENE.instantiate()
|
|
|
|
inst.deck = deck
|
2023-12-15 22:44:25 +01:00
|
|
|
var tab := tab_container.add_content(inst, "<unsaved deck>")
|
|
|
|
tab_container.set_tab_metadata(tab, "id", deck.id)
|
|
|
|
tab_container.set_tab_metadata(tab, "group", false)
|
|
|
|
tab_container.set_tab_metadata(tab, "path", recent_path.path_join(""))
|
|
|
|
inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested)
|
|
|
|
inst.dirty_state_changed.connect(_on_deck_renderer_dirty_state_changed.bind(inst))
|
|
|
|
tab_container.set_current_tab(tab)
|
2023-11-22 05:26:11 +01:00
|
|
|
|
2023-11-25 11:40:43 +01:00
|
|
|
## Closes the current tab in [member tab_container]
|
2023-11-22 05:26:11 +01:00
|
|
|
func close_current_tab() -> void:
|
|
|
|
tab_container.close_tab(tab_container.get_current_tab())
|
|
|
|
|
2023-12-15 22:44:25 +01:00
|
|
|
|
|
|
|
func close_tab(tab: int) -> void:
|
|
|
|
if !tab_container.get_tab_metadata(tab, "group"):
|
|
|
|
var groups := DeckHolder.close_deck(tab_container.get_tab_metadata(tab, "id"))
|
|
|
|
# close tabs associated with this deck's groups
|
|
|
|
for group in groups:
|
2024-01-15 08:23:47 +01:00
|
|
|
for c_tab in range(tab_container.get_tab_count() - 1, -1, -1):
|
2023-12-15 22:44:25 +01:00
|
|
|
if tab_container.get_tab_metadata(c_tab, "id") == group:
|
2024-01-15 08:23:47 +01:00
|
|
|
tab_container.close_tab(c_tab)
|
2023-12-15 22:44:25 +01:00
|
|
|
await get_tree().process_frame
|
|
|
|
|
|
|
|
tab_container.close_tab(tab)
|
|
|
|
|
2023-11-25 12:01:17 +01:00
|
|
|
## Opens [member file_dialog] with the mode [member FileDialog.FILE_MODE_SAVE_FILE]
|
2023-11-25 11:40:43 +01:00
|
|
|
## as well as getting a weakref to the active [Deck]
|
2023-11-22 05:26:11 +01:00
|
|
|
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)
|
|
|
|
|
2023-11-25 12:01:17 +01:00
|
|
|
## Opens [member file_dialog] with the mode [FileDialog.FILE_MODE_OPEN_FILES]
|
2023-11-25 11:40:43 +01:00
|
|
|
## with the supplied [param path]
|
2023-11-22 05:26:11 +01:00
|
|
|
func open_open_dialog(path: String) -> void:
|
|
|
|
file_dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILES
|
|
|
|
file_dialog.title = "Open Deck(s)"
|
2023-12-15 22:44:25 +01:00
|
|
|
file_dialog.current_path = path + "/"
|
2023-11-22 05:26:11 +01:00
|
|
|
file_dialog.popup_centered()
|
|
|
|
file_dialog.files_selected.connect(_on_file_dialog_open_files, CONNECT_ONE_SHOT)
|
|
|
|
|
2023-11-25 12:01:17 +01:00
|
|
|
## Connected to [signal FileDialog.save_file] on [member file_dialog].
|
2023-11-25 11:40:43 +01:00
|
|
|
## Saves the selected [Deck] if it still exists.
|
2023-11-22 05:26:11 +01:00
|
|
|
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
|
2023-12-15 22:44:25 +01:00
|
|
|
tab_container.set_tab_title(tab_container.get_current_tab(), path.get_file())
|
|
|
|
var renderer: DeckRendererGraphEdit = tab_container.get_content(tab_container.get_current_tab()) as DeckRendererGraphEdit
|
|
|
|
renderer.dirty = false
|
|
|
|
# TODO: put this into DeckHolder instead
|
2023-11-22 05:26:11 +01:00
|
|
|
var json := JSON.stringify(deck.to_dict(), "\t")
|
|
|
|
var f := FileAccess.open(path, FileAccess.WRITE)
|
|
|
|
f.store_string(json)
|
2023-12-15 22:44:25 +01:00
|
|
|
add_recent_file(get_active_deck().save_path)
|
|
|
|
recent_path = path.get_base_dir()
|
|
|
|
RendererPersistence.set_value(PERSISTENCE_NAMESPACE, "config", "recent_path", recent_path)
|
|
|
|
|
2023-11-22 05:26:11 +01:00
|
|
|
|
2023-11-25 12:01:17 +01:00
|
|
|
## Connected to [signal FileDialog.open_files] on [member file_dialog]. Opens
|
2023-11-25 11:40:43 +01:00
|
|
|
## the selected paths, instantiating [DeckRenderGraphEdit]s and [Deck]s for each.
|
2023-11-22 05:26:11 +01:00
|
|
|
func _on_file_dialog_open_files(paths: PackedStringArray) -> void:
|
|
|
|
for path in paths:
|
2023-12-15 22:44:25 +01:00
|
|
|
open_deck_at_path(path)
|
|
|
|
|
|
|
|
|
|
|
|
func open_deck_at_path(path: String) -> void:
|
|
|
|
for tab in tab_container.get_tab_count():
|
|
|
|
if tab_container.get_tab_metadata(tab, "path") == path:
|
|
|
|
tab_container.set_current_tab(tab)
|
|
|
|
return
|
|
|
|
|
|
|
|
var deck := DeckHolder.open_deck_from_file(path)
|
|
|
|
var inst: DeckRendererGraphEdit = DECK_SCENE.instantiate()
|
|
|
|
inst.deck = deck
|
|
|
|
var tab := tab_container.add_content(inst, path.get_file())
|
|
|
|
tab_container.set_tab_metadata(tab, "id", deck.id)
|
|
|
|
tab_container.set_tab_metadata(tab, "group", false)
|
|
|
|
tab_container.set_tab_metadata(tab, "path", path)
|
|
|
|
inst.initialize_from_deck()
|
|
|
|
inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested)
|
|
|
|
inst.dirty_state_changed.connect(_on_deck_renderer_dirty_state_changed.bind(inst))
|
|
|
|
add_recent_file(path)
|
|
|
|
recent_path = path.get_base_dir()
|
|
|
|
RendererPersistence.set_value(PERSISTENCE_NAMESPACE, "config", "recent_path", recent_path)
|
|
|
|
tab_container.set_current_tab(tab)
|
|
|
|
|
2023-11-22 05:26:11 +01:00
|
|
|
|
2023-11-25 11:40:43 +01:00
|
|
|
## Gets the currently active [Deck] from [member tab_container]
|
2023-11-22 05:26:11 +01:00
|
|
|
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
|
|
|
|
|
2023-11-25 11:40:43 +01:00
|
|
|
## Saves the active [Deck] in [member tab_container]
|
2023-11-22 05:26:11 +01:00
|
|
|
func save_active_deck() -> void:
|
2023-12-15 22:44:25 +01:00
|
|
|
save_tab(tab_container.get_current_tab())
|
|
|
|
|
|
|
|
|
|
|
|
func save_tab(tab: int) -> void:
|
|
|
|
if tab_container.get_tab_metadata(tab, "group"):
|
|
|
|
return
|
|
|
|
|
|
|
|
var renderer := tab_container.get_content(tab) as DeckRendererGraphEdit
|
|
|
|
var deck := renderer.deck
|
|
|
|
if deck.save_path.is_empty():
|
2023-11-22 05:26:11 +01:00
|
|
|
open_save_dialog("res://")
|
|
|
|
else:
|
2023-12-15 22:44:25 +01:00
|
|
|
var json := JSON.stringify(deck.to_dict(), "\t")
|
|
|
|
var f := FileAccess.open(deck.save_path, FileAccess.WRITE)
|
2023-11-22 05:26:11 +01:00
|
|
|
f.store_string(json)
|
2023-12-15 22:44:25 +01:00
|
|
|
add_recent_file(deck.save_path)
|
|
|
|
renderer.dirty = false
|
|
|
|
|
2023-11-22 05:26:11 +01:00
|
|
|
|
2023-11-25 11:40:43 +01:00
|
|
|
## Disconnects the [FileDialog] signals if they are already connected.
|
2023-11-22 05:26:11 +01:00
|
|
|
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)
|
|
|
|
|
2023-11-25 12:01:17 +01:00
|
|
|
## Connected to [signal DeckRenderGraphEdit.group_entered_request] to allow entering
|
|
|
|
## groups based off the given [param group_id] and [param deck]. As well as adding
|
2023-11-25 11:40:43 +01:00
|
|
|
## a corresponding tab to [member tab_container]
|
2023-12-15 22:44:25 +01:00
|
|
|
func _on_deck_renderer_group_enter_requested(group_id: String) -> void:
|
|
|
|
#var group_deck := deck.get_group(group_id)
|
|
|
|
for tab in tab_container.get_tab_count():
|
|
|
|
if tab_container.get_tab_metadata(tab, "id") == group_id:
|
|
|
|
tab_container.set_current_tab(tab)
|
|
|
|
return
|
|
|
|
var group_deck := DeckHolder.get_deck(group_id)
|
2023-11-22 05:26:11 +01:00
|
|
|
var deck_renderer: DeckRendererGraphEdit = DECK_SCENE.instantiate()
|
|
|
|
deck_renderer.deck = group_deck
|
|
|
|
deck_renderer.initialize_from_deck()
|
2023-12-15 22:44:25 +01:00
|
|
|
var tab := tab_container.add_content(deck_renderer, "(g) %s" % group_id.left(8))
|
|
|
|
tab_container.set_tab_metadata(tab, "id", group_id)
|
|
|
|
tab_container.set_tab_metadata(tab, "group", true)
|
|
|
|
deck_renderer.group_enter_requested.connect(_on_deck_renderer_group_enter_requested)
|
|
|
|
tab_container.set_current_tab(tab)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_connections_id_pressed(id: int) -> void:
|
|
|
|
match id:
|
|
|
|
ConnectionsMenuId.OBS:
|
|
|
|
obs_setup_dialog.popup_centered()
|
|
|
|
ConnectionsMenuId.TWITCH:
|
|
|
|
twitch_setup_dialog.popup_centered()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_obs_websocket_setup_dialog_connect_button_pressed(state: OBSWebsocketSetupDialog.ConnectionState) -> void:
|
|
|
|
match state:
|
|
|
|
OBSWebsocketSetupDialog.ConnectionState.DISCONNECTED:
|
|
|
|
obs_setup_dialog.set_button_state(OBSWebsocketSetupDialog.ConnectionState.CONNECTING)
|
|
|
|
no_obsws.connect_to_obsws(obs_setup_dialog.get_port(), obs_setup_dialog.get_password())
|
|
|
|
await no_obsws.connection_ready
|
|
|
|
obs_setup_dialog.set_button_state(OBSWebsocketSetupDialog.ConnectionState.CONNECTED)
|
|
|
|
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
DeckHolder.send_event(&"process", {"delta": delta})
|
|
|
|
|
|
|
|
|
|
|
|
func _on_debug_id_pressed(id: int) -> void:
|
|
|
|
match id:
|
|
|
|
DebugMenuId.DECKS:
|
|
|
|
var d := AcceptDialog.new()
|
|
|
|
var debug_decks: DebugDecksList = DEBUG_DECKS_LIST.instantiate()
|
|
|
|
d.add_child(debug_decks)
|
|
|
|
d.canceled.connect(d.queue_free)
|
|
|
|
d.confirmed.connect(d.queue_free)
|
|
|
|
debug_decks.item_pressed.connect(_on_debug_decks_viewer_item_pressed)
|
|
|
|
add_child(d)
|
|
|
|
d.popup_centered()
|
|
|
|
DebugMenuId.EMBED_SUBWINDOWS:
|
|
|
|
var c := debug_popup_menu.is_item_checked(id)
|
|
|
|
debug_popup_menu.set_item_checked(id, !c)
|
|
|
|
get_tree().get_root().gui_embed_subwindows = !c
|
|
|
|
RendererPersistence.set_value(PERSISTENCE_NAMESPACE, "config", "embed_subwindows", !c)
|
|
|
|
file_dialog.use_native_dialog = c
|
|
|
|
|
|
|
|
|
|
|
|
func _on_debug_decks_viewer_item_pressed(deck_id: String, instance_id: String) -> void:
|
|
|
|
if instance_id == "":
|
|
|
|
var deck := DeckHolder.get_deck(deck_id)
|
|
|
|
var inst: DeckRendererGraphEdit = DECK_SCENE.instantiate()
|
|
|
|
inst.deck = deck
|
|
|
|
var tab := tab_container.add_content(inst, "<Deck %s>" % [deck_id.left(8)])
|
|
|
|
tab_container.set_tab_metadata(tab, "id", deck.id)
|
|
|
|
inst.initialize_from_deck()
|
|
|
|
inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested)
|
|
|
|
tab_container.set_current_tab(tab)
|
|
|
|
else:
|
|
|
|
var deck := DeckHolder.get_group_instance(deck_id, instance_id)
|
|
|
|
var inst: DeckRendererGraphEdit = DECK_SCENE.instantiate()
|
|
|
|
inst.deck = deck
|
|
|
|
var tab := tab_container.add_content(inst, "<Group %s::%s>" % [deck_id.left(8), instance_id.left(8)])
|
|
|
|
tab_container.set_tab_metadata(tab, "id", deck.id)
|
|
|
|
inst.initialize_from_deck()
|
|
|
|
inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested)
|
|
|
|
tab_container.set_current_tab(tab)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_deck_renderer_dirty_state_changed(renderer: DeckRendererGraphEdit) -> void:
|
|
|
|
var idx: int = range(tab_container.get_tab_count()).filter(
|
|
|
|
func(x: int):
|
|
|
|
return tab_container.get_content(x) == renderer
|
|
|
|
)[0]
|
|
|
|
var title := tab_container.get_tab_title(idx).trim_suffix("(*)")
|
|
|
|
if renderer.dirty:
|
|
|
|
tab_container.set_tab_title(idx, "%s(*)" % title)
|
|
|
|
else:
|
|
|
|
tab_container.set_tab_title(idx, title.trim_suffix("(*)"))
|
|
|
|
tab_container.set_tab_metadata(idx, "dirty", renderer.dirty)
|
|
|
|
|
|
|
|
|
|
|
|
func add_recent_file(path: String) -> void:
|
|
|
|
var item := recent_files.find(path)
|
|
|
|
if item == -1:
|
|
|
|
recent_files.push_front(path)
|
|
|
|
else:
|
|
|
|
recent_files.push_front(recent_files.pop_at(item))
|
|
|
|
recent_files = recent_files.slice(0, max_recents)
|
|
|
|
|
|
|
|
add_recents_to_menu()
|
|
|
|
|
|
|
|
|
|
|
|
func add_recents_to_menu() -> void:
|
|
|
|
if recent_files.is_empty():
|
|
|
|
return
|
|
|
|
|
|
|
|
if file_popup_menu.get_item_count() > FileMenuId.RECENTS + 1:
|
|
|
|
var end := file_popup_menu.get_item_count() - FileMenuId.RECENTS - 1
|
|
|
|
for i in end:
|
|
|
|
file_popup_menu.remove_item(file_popup_menu.get_item_count() - 1)
|
|
|
|
|
|
|
|
var reduce_length := recent_files.any(func(x: String): return x.length() > 35)
|
|
|
|
|
|
|
|
for i in recent_files.size():
|
|
|
|
var file = recent_files[i] as String
|
|
|
|
if reduce_length:
|
|
|
|
# shorten the basepath to be the first letter of all folders
|
|
|
|
var base: String = Array(
|
|
|
|
file.get_base_dir().split("/", false)
|
|
|
|
).reduce(
|
|
|
|
func(a: String, s: String):
|
|
|
|
return a + s[0] + "/",
|
|
|
|
"/")
|
|
|
|
var filename := file.get_file()
|
|
|
|
file = base.path_join(filename)
|
|
|
|
|
|
|
|
file_popup_menu.add_item(file)
|
|
|
|
var s := Shortcut.new()
|
|
|
|
var k := InputEventKey.new()
|
|
|
|
k.keycode = KEY_1 + i
|
|
|
|
k.ctrl_pressed = true
|
|
|
|
s.events.append(k)
|
|
|
|
file_popup_menu.set_item_shortcut(file_popup_menu.get_item_count() - 1, s)
|
|
|
|
|
|
|
|
RendererPersistence.set_value(PERSISTENCE_NAMESPACE, "config", "recent_files", recent_files)
|
|
|
|
|
|
|
|
|
|
|
|
func _notification(what: int) -> void:
|
|
|
|
if what == NOTIFICATION_WM_CLOSE_REQUEST:
|
|
|
|
RendererPersistence.commit(PERSISTENCE_NAMESPACE)
|
|
|
|
|
|
|
|
if range(tab_container.get_tab_count()).any(func(x: int): return tab_container.get_content(x).dirty):
|
|
|
|
unsaved_changes_dialog.show()
|
|
|
|
else:
|
2024-01-15 08:23:47 +01:00
|
|
|
#for i in tab_container.get_tab_count():
|
|
|
|
#close_tab(i)
|
|
|
|
for i in range(tab_container.get_tab_count() - 1, -1, -1):
|
|
|
|
await close_tab(i)
|
2023-12-15 22:44:25 +01:00
|
|
|
|
|
|
|
get_tree().quit()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_unsaved_changes_dialog_single_deck_confirmed() -> void:
|
|
|
|
save_tab(unsaved_changes_dialog_single_deck.get_meta("tab"))
|
2024-01-15 08:23:47 +01:00
|
|
|
await close_tab(unsaved_changes_dialog_single_deck.get_meta("tab"))
|
2023-12-15 22:44:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _on_unsaved_changes_dialog_single_deck_custom_action(action: StringName) -> void:
|
|
|
|
if action == &"force_close":
|
2024-01-15 08:23:47 +01:00
|
|
|
await close_tab(unsaved_changes_dialog_single_deck.get_meta("tab"))
|
2023-12-15 22:44:25 +01:00
|
|
|
unsaved_changes_dialog_single_deck.hide()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_unsaved_changes_dialog_confirmed() -> void:
|
2024-01-15 08:23:47 +01:00
|
|
|
for i in range(tab_container.get_tab_count() - 1, -1, -1):
|
|
|
|
await close_tab(i)
|
2023-12-15 22:44:25 +01:00
|
|
|
get_tree().quit()
|
|
|
|
|
|
|
|
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
2024-01-17 03:07:24 +01:00
|
|
|
if event.is_action_pressed("toggle_bottom_dock"):
|
|
|
|
bottom_dock.visible = !bottom_dock.visible
|
2023-12-15 22:44:25 +01:00
|
|
|
accept_event()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_help_id_pressed(id: int) -> void:
|
|
|
|
match id:
|
|
|
|
HelpMenuId.ABOUT:
|
|
|
|
about_dialog.show()
|
|
|
|
HelpMenuId.DOCS:
|
|
|
|
OS.shell_open("https://codeberg.org/Eroax/StreamGraph/wiki")
|