Skip to content

Commit d55c5cc

Browse files
committed
Improve GlobalUI
* Rename overlayRect to tintRect, pauseOverlayRect to pauseTintRect, & related * Add "Now Playing" music label UI & showMusicLabel() * Reorganize code
1 parent f1faae0 commit d55c5cc

File tree

3 files changed

+89
-16
lines changed

3 files changed

+89
-16
lines changed

AutoLoad/GlobalUI.gd

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ const pauseOverlayScene := preload("res://UI/PauseOverlay.tscn")
4141
@onready var foregroundOverlay: CanvasLayer = %ForegroundOverlay
4242
@onready var labelsList: TemporaryLabelList = %LabelsList
4343
@onready var navigationContainer: UINavigationContainer = %NavigationContainer ## For top-level UI
44-
@onready var overlayRect: ColorRect = %GlobalOverlayRect
45-
@onready var pauseOverlayRect: ColorRect = %PauseOverlayRect
44+
@onready var tintRect: ColorRect = %GlobalTintRect
45+
46+
@onready var pauseTintRect: ColorRect = %PauseTintRect
4647
@onready var pauseOverlayContainer: UINavigationContainer = %PauseOverlayContainer
48+
49+
@onready var musicLabelContainer: Container = %MusicLabelContainer
50+
@onready var musicLabel: Label = %MusicLabel
4751
#endregion
4852

4953

@@ -59,6 +63,9 @@ func _ready() -> void:
5963
if windowMode != DisplayServer.WINDOW_MODE_FULLSCREEN and windowMode != DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN:
6064
GlobalUI.setWindowSize(Settings.windowWidth, Settings.windowHeight, false) # !showLabel to avoid clutter
6165

66+
musicLabelContainer.position.y = musicLabel.get_viewport_rect().end.y
67+
Tools.connectSignal(GlobalSonic.musicPlayerDidPlay, self.onGlobalSonic_musicPlayerDidPlay)
68+
6269

6370
func setWindowSize(width: int, height: int, showLabel: bool = true) -> void:
6471
var viewport: Viewport = self.get_viewport()
@@ -100,7 +107,7 @@ func showPauseVisuals(isPaused: bool) -> void:
100107
# Ensure visibility just in case
101108
pauseOverlay.pauseButton.visible = true
102109
pauseOverlay.visible = true
103-
Animations.fadeIn(pauseOverlayRect)
110+
Animations.fadeIn(pauseTintRect)
104111
if pauseOverlayTween: pauseOverlayTween.kill()
105112
pauseOverlayTween = Animations.fadeIn(pauseOverlayContainer, 0.2)
106113
didShowPauseOverlay.emit(pauseOverlay)
@@ -109,7 +116,7 @@ func showPauseVisuals(isPaused: bool) -> void:
109116

110117
if pauseOverlay: pauseOverlay.pauseButton.visible = false
111118

112-
Animations.fadeOut(pauseOverlayRect)
119+
Animations.fadeOut(pauseTintRect)
113120
if pauseOverlayTween: pauseOverlayTween.kill()
114121
pauseOverlayTween = Animations.fadeOut(pauseOverlayContainer, 0.2)
115122
await pauseOverlayTween.finished
@@ -125,23 +132,55 @@ func showPauseVisuals(isPaused: bool) -> void:
125132
navigationContainer.visible = not pauseOverlayContainer.visible
126133

127134

128-
func createTemporaryLabel(text: String) -> Label:
129-
return labelsList.createTemporaryLabel(text)
130-
135+
func onGlobalSonic_musicPlayerDidPlay(fileName: String) -> void:
136+
showMusicLabel(fileName.get_basename().get_file())
131137

132138
#region Animations
133139

134140
## Fades in the global overlay, which may be a solid black rectangle, effectively fading OUT the actual game content.
135-
func fadeInOverlayRect() -> Tween:
141+
func fadeInTintRect() -> Tween:
136142
if rectFadeTween: rectFadeTween.kill()
137-
rectFadeTween = Animations.fadeIn(overlayRect)
143+
rectFadeTween = Animations.fadeIn(tintRect)
138144
return rectFadeTween
139145

140146

141147
## Fades out the global overlay, which may be a solid black rectangle, effectively fading IN the actual game content.
142-
func fadeOutOverlayRect() -> Tween:
148+
func fadeOutTintRect() -> Tween:
143149
if rectFadeTween: rectFadeTween.kill()
144-
rectFadeTween = Animations.fadeOut(overlayRect)
150+
rectFadeTween = Animations.fadeOut(tintRect)
145151
return rectFadeTween
146152

153+
154+
## @experimental
155+
func showMusicLabel(title: String) -> void:
156+
# TODO: Fix interrupted animations
157+
158+
const margin: float = 4.0
159+
const showTime: float = 0.5
160+
const hideTime: float = 0.5
161+
const waitTIme: float = 2.0
162+
163+
# musicLabel.text = "" # Let any existing title be animated into the new one ^^
164+
musicLabelContainer.position.y = musicLabelContainer.get_viewport_rect().end.y
165+
musicLabelContainer.modulate = Color(Color.CYAN, 0)
166+
musicLabelContainer.visible = true
167+
168+
Animations.tweenProperty(musicLabel, ^"text", title, showTime)
169+
170+
var slideAnimation: Tween = Animations.tweenProperty(musicLabelContainer, ^"position:y", musicLabelContainer.get_viewport_rect().end.y - 16 - margin, showTime) \
171+
.set_ease(Tween.EASE_OUT)
172+
Animations.fadeIn(musicLabelContainer, showTime)
173+
174+
await slideAnimation.finished
175+
await SceneManager.sceneTree.create_timer(waitTIme).timeout
176+
177+
Animations.tweenProperty(musicLabel, ^"text", "", hideTime)
178+
Animations.tweenProperty(musicLabelContainer, ^"position:y", musicLabelContainer.get_viewport_rect().end.y, hideTime) \
179+
.set_ease(Tween.EASE_OUT)
180+
Animations.fadeOut(musicLabelContainer, hideTime)
181+
182+
183+
func createTemporaryLabel(text: String) -> Label:
184+
return labelsList.createTemporaryLabel(text)
185+
147186
#endregion

AutoLoad/GlobalUI.tscn

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
[gd_scene load_steps=5 format=3 uid="uid://bqsh8lrdxmljt"]
1+
[gd_scene load_steps=8 format=3 uid="uid://bqsh8lrdxmljt"]
22

33
[ext_resource type="Script" uid="uid://152oaj1p6c27" path="res://AutoLoad/GlobalUI.gd" id="1_6ujyj"]
44
[ext_resource type="Script" uid="uid://dlj44gyo6xh11" path="res://UI/UINavigationContainer.gd" id="2_vibvi"]
55
[ext_resource type="Script" uid="uid://cyqog03afsper" path="res://UI/Lists/TemporaryLabelList.gd" id="3_vibvi"]
6+
[ext_resource type="Material" uid="uid://b3pgi66bf5g2e" path="res://Assets/Materials/AddUnshaded.tres" id="4_c88uu"]
67
[ext_resource type="Shortcut" uid="uid://c4er757mljhl4" path="res://Resources/Shortcuts/BackShortcut.tres" id="4_u63o5"]
8+
[ext_resource type="Texture2D" uid="uid://clox863hbl6dx" path="res://Assets/Tiles/Kenney1Bit-Monochrome-Transparent.png" id="4_vibvi"]
9+
10+
[sub_resource type="AtlasTexture" id="AtlasTexture_c88uu"]
11+
atlas = ExtResource("4_vibvi")
12+
region = Rect2(624, 256, 16, 16)
713

814
[node name="GlobalUI" type="Node"]
915
process_mode = 3
@@ -38,7 +44,7 @@ size_flags_vertical = 4
3844
shortcut = ExtResource("4_u63o5")
3945
text = "<"
4046

41-
[node name="GlobalOverlayRect" type="ColorRect" parent="ForegroundOverlay"]
47+
[node name="GlobalTintRect" type="ColorRect" parent="ForegroundOverlay"]
4248
unique_name_in_owner = true
4349
visible = false
4450
modulate = Color(1, 1, 1, 0)
@@ -50,7 +56,35 @@ grow_vertical = 2
5056
mouse_filter = 2
5157
color = Color(0.15, 0, 0.3, 1)
5258

53-
[node name="PauseOverlayRect" type="ColorRect" parent="ForegroundOverlay"]
59+
[node name="MusicLabelContainer" type="HBoxContainer" parent="ForegroundOverlay"]
60+
unique_name_in_owner = true
61+
modulate = Color(0, 1, 1, 1)
62+
material = ExtResource("4_c88uu")
63+
custom_minimum_size = Vector2(64, 16)
64+
anchors_preset = 2
65+
anchor_top = 1.0
66+
anchor_bottom = 1.0
67+
offset_left = 4.0
68+
offset_top = -16.0
69+
offset_right = 96.0
70+
grow_vertical = 0
71+
size_flags_horizontal = 3
72+
size_flags_vertical = 8
73+
74+
[node name="MusicIcon" type="TextureRect" parent="ForegroundOverlay/MusicLabelContainer"]
75+
layout_mode = 2
76+
size_flags_horizontal = 0
77+
size_flags_vertical = 4
78+
texture = SubResource("AtlasTexture_c88uu")
79+
stretch_mode = 2
80+
81+
[node name="MusicLabel" type="Label" parent="ForegroundOverlay/MusicLabelContainer"]
82+
unique_name_in_owner = true
83+
custom_minimum_size = Vector2(0, 8)
84+
layout_mode = 2
85+
text = "Now Playing"
86+
87+
[node name="PauseTintRect" type="ColorRect" parent="ForegroundOverlay"]
5488
unique_name_in_owner = true
5589
visible = false
5690
modulate = Color(1, 1, 1, 0)

AutoLoad/SceneManager.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func transitionToScene(nextScene: PackedScene, pauseSceneTree: bool = true, anim
7777

7878
# Pause
7979
sceneTree.paused = pauseSceneTree
80-
if animate: await GlobalUI.fadeInOverlayRect().finished # Fade the overlay in, fade the game out.
80+
if animate: await GlobalUI.fadeInTintRect().finished # Fade the overlay in, fade the game out.
8181

8282
# Transition
8383
sceneTree.change_scene_to_packed(nextScene)
@@ -86,7 +86,7 @@ func transitionToScene(nextScene: PackedScene, pauseSceneTree: bool = true, anim
8686
# Unpause
8787
await sceneTree.create_timer(0.1).timeout # A little breath before showing the next scene
8888
sceneTree.paused = false # Unpause to begin the gameplay motion before the overlay fades-out for a smoother feel, instead of an abrupt movement.
89-
if animate: await GlobalUI.fadeOutOverlayRect().finished # Fade the overlay out, fade the game in.
89+
if animate: await GlobalUI.fadeOutTintRect().finished # Fade the overlay out, fade the game in.
9090

9191
ongoingTransitionScene = null # Clear the transition tracker
9292
if Debug.shouldPrintDebugLogs: Debug.printDebug(str("SceneTree.current_scene: ", sceneTree.current_scene), logName)

0 commit comments

Comments
 (0)