-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Main.gd
96 lines (62 loc) · 2.65 KB
/
Main.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
###################################################
# Part of Bosca Ceoil Blue #
# Copyright (c) 2024 Yuri Sizov and contributors #
# Provided under MIT #
###################################################
extends MarginContainer
var _default_window_title: String = ""
@onready var _pattern_editor: Control = %PatternEditor
@onready var _locked_indicator: Control = %LockedIndicator
@onready var _highlight_manager: CanvasLayer = %HighlightManager
func _enter_tree() -> void:
Controller.window_manager.register_window()
_default_window_title = get_window().title
func _ready() -> void:
Controller.window_manager.restore_window()
_pattern_editor.visible = true
_locked_indicator.visible = false
Controller.io_manager.initialize_song()
_edit_current_song()
if not Engine.is_editor_hint():
if Controller.settings_manager.is_first_time():
Controller.show_welcome_message()
Controller.song_loaded.connect(_edit_current_song)
Controller.song_saved.connect(_update_window_title)
Controller.controls_locked.connect(_show_locked_indicator)
Controller.controls_unlocked.connect(_hide_locked_indicator)
Controller.help_manager.highlight_requested.connect(_set_highlighted_node)
Controller.help_manager.highlight_cleared.connect(_clear_highlighted_node)
# Window decorations.
func _edit_current_song() -> void:
if Engine.is_editor_hint():
return
_update_window_title()
if Controller.current_song:
Controller.current_song.song_changed.connect(_update_window_title)
func _update_window_title() -> void:
if Engine.is_editor_hint():
return
if not Controller.current_song:
get_window().title = _default_window_title
return
var song_name := "<New Song>" if Controller.current_song.filename.is_empty() else Controller.current_song.filename.get_file()
var song_dirty := "* " if Controller.current_song.is_dirty() else ""
get_window().title = "%s%s - %s" % [ song_dirty, song_name, _default_window_title ]
# Editor locking.
func _show_locked_indicator(message: String) -> void:
_pattern_editor.visible = false
_locked_indicator.message = message
_locked_indicator.visible = true
func _hide_locked_indicator() -> void:
_pattern_editor.visible = true
_locked_indicator.visible = false
# Node highlighting.
func _set_highlighted_node(rect_getter: Callable) -> void:
if rect_getter.is_valid():
_highlight_manager.highlight_rect_getter = rect_getter
else:
_highlight_manager.highlight_rect_getter = Callable()
_highlight_manager.update_highlight()
func _clear_highlighted_node() -> void:
_highlight_manager.highlight_rect_getter = Callable()
_highlight_manager.update_highlight()