From cda5f5ac3ba092bdfe65b9e9793a1ee2bc6757d7 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Fri, 29 Jan 2021 16:59:52 +1030 Subject: [PATCH] Add Video singleton. This enables multiple video views across the game and will aid in the upcoming multiplayer-driven refactoring. --- Menu.tscn | 9 --------- OptionPanel.tscn | 21 +++++++++++++++++++-- RadialGame.tscn | 37 ++++++++++--------------------------- main.tscn | 8 ++++++++ project.godot | 1 + scripts/NoteHandler.gd | 4 +--- scripts/video.gd | 13 ------------- singletons/Library.gd | 4 +--- singletons/Video.gd | 17 +++++++++++++++++ 9 files changed, 57 insertions(+), 57 deletions(-) delete mode 100644 scripts/video.gd create mode 100644 singletons/Video.gd diff --git a/Menu.tscn b/Menu.tscn index 544ee51..21eea01 100644 --- a/Menu.tscn +++ b/Menu.tscn @@ -11,17 +11,8 @@ _data = [ Vector2( -1, -1 ), 0.0, 0.0, 0, 0, Vector2( 0, 0 ), 2.0, 2.0, 1, 1, Ve [node name="Menu" type="Control"] material = ExtResource( 3 ) -margin_left = -540.0 -margin_top = -540.0 -margin_right = 540.0 -margin_bottom = 540.0 -rect_pivot_offset = Vector2( 540, 540 ) rect_clip_content = true script = ExtResource( 2 ) -__meta__ = { -"_edit_use_anchors_": false -} -NoteHandlerPath = NodePath("../NoteHandler") ease_curve = SubResource( 1 ) [node name="ScoreText" type="Node2D" parent="."] diff --git a/OptionPanel.tscn b/OptionPanel.tscn index 227d2d7..5e66e1f 100644 --- a/OptionPanel.tscn +++ b/OptionPanel.tscn @@ -71,7 +71,7 @@ __meta__ = { [node name="PanelContainer" type="PanelContainer" parent="."] margin_top = 38.0 margin_right = 267.0 -margin_bottom = 374.0 +margin_bottom = 626.0 __meta__ = { "_edit_use_anchors_": false } @@ -80,7 +80,7 @@ __meta__ = { margin_left = 7.0 margin_top = 7.0 margin_right = 260.0 -margin_bottom = 329.0 +margin_bottom = 581.0 [node name="cb_qsettings" type="CheckBox" parent="PanelContainer/VBoxContainer"] margin_right = 253.0 @@ -301,6 +301,23 @@ __meta__ = { "_edit_use_anchors_": false } +[node name="HSeparator2" type="HSeparator" parent="PanelContainer/VBoxContainer"] +margin_top = 326.0 +margin_right = 253.0 +margin_bottom = 330.0 + +[node name="VidTextureRect" type="TextureRect" parent="PanelContainer/VBoxContainer" groups=[ +"VideoTexRects", +]] +margin_top = 334.0 +margin_right = 253.0 +margin_bottom = 574.0 +rect_min_size = Vector2( 240, 240 ) +size_flags_horizontal = 7 +size_flags_vertical = 7 +expand = true +stretch_mode = 6 + [connection signal="toggled" from="PanelContainer/VBoxContainer/cb_qsettings" to="PanelContainer/VBoxContainer/vbox_qsettings" method="set_visible"] [connection signal="item_selected" from="PanelContainer/VBoxContainer/vbox_qsettings/hbox_language/btn_language" to="." method="_on_btn_language_item_selected"] [connection signal="value_changed" from="PanelContainer/VBoxContainer/vbox_qsettings/sl_volume" to="." method="_on_sl_volume_value_changed"] diff --git a/RadialGame.tscn b/RadialGame.tscn index 185bc04..901a825 100644 --- a/RadialGame.tscn +++ b/RadialGame.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=20 format=2] +[gd_scene load_steps=19 format=2] [ext_resource path="res://scripts/InputHandler.gd" type="Script" id=1] [ext_resource path="res://assets/text-4k.png" type="Texture" id=2] -[ext_resource path="res://scripts/video.gd" type="Script" id=3] [ext_resource path="res://scripts/ScreenFilter.gd" type="Script" id=4] [ext_resource path="res://scripts/NoteViewport.gd" type="Script" id=5] [ext_resource path="res://scripts/NotePainter.gd" type="Script" id=6] @@ -72,34 +71,23 @@ min_value = -1.0 _data = [ Vector2( -1, -1 ), 0.0, 0.0, 0, 0, Vector2( 0, 0 ), 2.0, 2.0, 1, 1, Vector2( 1, 1 ), 0.0, 0.0, 0, 0 ] [node name="RadialGame" type="Control"] -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -margin_left = -540.0 -margin_top = -540.0 -margin_right = 540.0 -margin_bottom = 540.0 +anchor_right = 1.0 +anchor_bottom = 1.0 __meta__ = { "_edit_use_anchors_": false } -[node name="video" type="VideoPlayer" parent="."] -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -margin_left = -540.0 -margin_top = -540.0 -margin_right = 540.0 -margin_bottom = 540.0 +[node name="video" type="TextureRect" parent="." groups=[ +"VideoTexRects", +]] +anchor_right = 1.0 +anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 rect_pivot_offset = Vector2( 540, 540 ) mouse_filter = 2 -volume_db = -80.0 -bus = "Music" -script = ExtResource( 3 ) +expand = true +stretch_mode = 6 __meta__ = { "_edit_use_anchors_": false } @@ -160,11 +148,6 @@ script = ExtResource( 6 ) [node name="Menu" parent="." instance=ExtResource( 15 )] anchor_right = 1.0 anchor_bottom = 1.0 -margin_left = 0.0 -margin_top = 0.0 -margin_right = 0.0 -margin_bottom = 0.0 -NoteHandlerPath = NodePath("../Center/NoteHandler") ease_curve = SubResource( 6 ) [node name="Bezel" type="Control" parent="."] diff --git a/main.tscn b/main.tscn index b182412..c7c3d9d 100644 --- a/main.tscn +++ b/main.tscn @@ -12,6 +12,14 @@ __meta__ = { } [node name="RadialGame" parent="." instance=ExtResource( 1 )] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -540.0 +margin_top = -540.0 +margin_right = 540.0 +margin_bottom = 540.0 [node name="OptionPanel" parent="." instance=ExtResource( 13 )] diff --git a/project.godot b/project.godot index 2fc0116..e1f30d7 100644 --- a/project.godot +++ b/project.godot @@ -31,6 +31,7 @@ FileLoader="*res://singletons/FileLoader.gd" Library="*res://singletons/Library.gd" GameTheme="*res://singletons/GameTheme.gd" SoundPlayer="*res://singletons/SoundPlayer.gd" +Video="*res://singletons/Video.gd" [debug] diff --git a/scripts/NoteHandler.gd b/scripts/NoteHandler.gd index 3daa800..750449c 100644 --- a/scripts/NoteHandler.gd +++ b/scripts/NoteHandler.gd @@ -7,9 +7,8 @@ signal finished_song(song_key, score_data) var running := false var song_key = '' -export var VideoPlayerPath := @'../../video' onready var MusicPlayer := SoundPlayer.music_player -onready var VideoPlayer := get_node(VideoPlayerPath) +onready var VideoPlayer := Video.video onready var Painter = $Painter onready var SlideTrailHandler = $'Viewport/Center/SlideTrailHandler' @@ -480,7 +479,6 @@ func load_track(song_key: String, difficulty_key: String): var videostream = FileLoader.load_video('songs/' + data.filepath.rstrip('/') + '/' + data.video_filelist[0]) MusicPlayer.set_stream(FileLoader.load_ogg('songs/' + data.filepath.rstrip('/') + '/' + data.audio_filelist[0])) VideoPlayer.set_stream(videostream) - VideoPlayer.update_aspect_ratio(data.video_dimensions[0]/data.video_dimensions[1]) # all_notes = FileLoader.Test.stress_pattern() Note.process_note_list(all_notes, false) diff --git a/scripts/video.gd b/scripts/video.gd deleted file mode 100644 index 4d91a09..0000000 --- a/scripts/video.gd +++ /dev/null @@ -1,13 +0,0 @@ -extends VideoPlayer - -func _ready(): - pass - # I need to put videoplayer resizing logic somewhere else, this is placeholder - update_aspect_ratio(1440.0/1080.0) - -func update_aspect_ratio(ratio: float): - # e.g. for a 1920x1080 video you'd call update_aspect_ratio(1920.0/1080.0) - # e.g. for a 1440x1080 video you'd call update_aspect_ratio(1440.0/1080.0) - var height = 1080/ratio - margin_top = -height/2.0 - margin_bottom = height/2.0 diff --git a/singletons/Library.gd b/singletons/Library.gd index 32b7037..db10b7c 100644 --- a/singletons/Library.gd +++ b/singletons/Library.gd @@ -45,7 +45,6 @@ class Song: var audio_offsets: Array var video_offsets: Array var audio_preview_times: Array - var video_dimensions: Array var chart_difficulties := {} const default_difficulty_keys = ['Z', 'B', 'A', 'E', 'M', 'R', '宴'] const difficulty_key_ids = {'Z':0, 'B':1, 'A':2, 'E':3, 'M':4, 'R':5, '宴':6} @@ -70,8 +69,7 @@ class Song: video_filelist = values.get('video_filelist', ['%s.webm'%values.get('index', 'video')]) audio_offsets = values.get('audio_filelist', [0.0, 240.0/BPM]) video_offsets = values.get('video_filelist', [0.0, 240.0/BPM]) - video_dimensions = values.get('video_dimensions', [1.0, 1.0]) - audio_preview_times = values.get('video_dimensions', [1.0, 1.0]) + audio_preview_times = values.get('audio_preview_times', [1.0, 1.0]) genre = values.get('genre', 'None') chart_filelist = values.get('chart_filelist', ['%s.rgtm'%values.get('index', 'charts')]) diff --git a/singletons/Video.gd b/singletons/Video.gd new file mode 100644 index 0000000..14272f6 --- /dev/null +++ b/singletons/Video.gd @@ -0,0 +1,17 @@ +extends Node + +# Video decoding is relatively expensive for Godot so we only want to do it once at a time. + +var video := VideoPlayer.new() + +var texture: Texture setget , get_texture +func get_texture() -> Texture: + return video.get_video_texture() + +func _ready(): + video.expand = false + add_child(video) # Needs to be in scene tree to make the textures + video.visible = false # Luckily this is enough to make the textures without rendering + +func _process(delta: float) -> void: + get_tree().call_group('VideoTexRects', 'set_texture', self.texture)