Merge pull request 'video player feature' (#11) from gymkhana/video-player into gymkhana/main

Reviewed-on: gymkhana/gymkhana#11
This commit is contained in:
2023-09-18 22:47:47 +02:00
11 changed files with 102 additions and 3 deletions

View File

@@ -0,0 +1,41 @@
# `play_video file`
#
# Plays the specified video blocking the currently running event .
#
# **Parameters**
#
# - *file*: Video file to play
#
# @ESC
extends ESCBaseCommand
class_name PlayVideoCommand
# Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new(
1,
[TYPE_STRING, TYPE_STRING]
)
# Validate whether the given arguments match the command descriptor
func validate(arguments: Array):
if not .validate(arguments):
return false
if not ResourceLoader.exists(arguments[0]):
escoria.logger.error(
self,
"[%s]: invalid parameter. File %s not found."
% [get_command_name(), arguments[0]]
)
return false
return true
# Run the command
func run(command_params: Array) -> int:
escoria.game_scene.play_video(command_params[0])
#We wait for the video to emit "finished" fignal with yield
yield(escoria.game_scene.get_video_player(),"finished")
return ESCExecution.RC_OK

View File

@@ -82,6 +82,8 @@ var _current_mouse_pos = Vector2.ZERO
var tooltip2_node: Object
var last_target: Object
var video_player: Object
func _ready():
# We need a slightly modified version of Action Manager to combine items with different actions.
escoria.action_manager = ESCActionManagerMonkey.new()
@@ -455,3 +457,10 @@ func _on_event_done(return_code: int, _event_name: String):
func _on_MenuButton_pressed() -> void:
pause_game()
func get_video_player() -> Node:
return $CanvasLayer/video_player
func play_video(video_file: String) -> void:
$CanvasLayer/video_player.visible = true
$CanvasLayer/video_player.play(video_file)

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=12 format=2]
[gd_scene load_steps=13 format=2]
[ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/inventory/inventory_ui.tscn" type="PackedScene" id=1]
[ext_resource path="res://addons/escoria-core/game/scenes/dialogs/esc_dialog_player.gd" type="Script" id=2]
@@ -11,6 +11,7 @@
[ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/theme.tres" type="Theme" id=9]
[ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/tooltip/target_tooltip2.tscn" type="PackedScene" id=10]
[ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/icons/cog-64.svg" type="Texture" id=11]
[ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/video_player/video_player.tscn" type="PackedScene" id=12]
[node name="game" type="Node2D"]
script = ExtResource( 5 )
@@ -84,6 +85,9 @@ theme = ExtResource( 9 )
[node name="main_menu" parent="CanvasLayer" instance=ExtResource( 7 )]
visible = false
[node name="video_player" parent="CanvasLayer" instance=ExtResource( 12 )]
visible = false
[node name="tooltip_layer" type="CanvasLayer" parent="."]
layer = 2

View File

@@ -0,0 +1,12 @@
tool
extends Node
signal finished
func play(video_file: String):
$VideoPlayer.set_stream(load(video_file))
$VideoPlayer.play()
func _on_VideoPlayer_finished():
self.visible = false
emit_signal("finished")

View File

@@ -0,0 +1,23 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/video_player/video_player.gd" type="Script" id=1]
[sub_resource type="VideoStreamTheora" id=1]
[node name="video_player" type="Control"]
margin_right = 1285.0
margin_bottom = 753.0
script = ExtResource( 1 )
[node name="ColorRect" type="ColorRect" parent="."]
margin_right = 1275.0
margin_bottom = 744.0
color = Color( 0, 0, 0, 1 )
[node name="VideoPlayer" type="VideoPlayer" parent="."]
margin_right = 1279.0
margin_bottom = 747.0
stream = SubResource( 1 )
expand = false
[connection signal="finished" from="VideoPlayer" to="." method="_on_VideoPlayer_finished"]

View File

@@ -18,6 +18,7 @@
:ready
set_global new_game true
> [new_game]
set_global new_game false
accept_input SKIP

View File

@@ -1,3 +1,6 @@
:action1
accept_input SKIP
play_video res://gymkhana/videos/test_video.ogv
accept_input ALL
play_snd res://gymkhana/sounds/cocina_delante_open.ogg
change_scene "res://gymkhana/rooms/turno_cocina/cocina/cocina.tscn"
change_scene "res://gymkhana/rooms/turno_cocina/cocina/cocina.tscn"

View File

@@ -1,2 +1,3 @@
:action1
change_scene "res://gymkhana/rooms/turno_cocina/cocina_detras/cocina_detras.tscn"

View File

@@ -2,7 +2,6 @@
# Play Escoria logo cutscene
# change_scene res://gymkhana/rooms/intro/intro_room.tscn false
show_menu main
# When control is passed back after the logo, start the music
play_snd res://game/sfx/Game-Menu_Looping.mp3 _music

Binary file not shown.

View File

@@ -505,6 +505,11 @@ _global_script_classes=[ {
"path": "res://addons/escoria-core/game/core-scripts/esc/commands/play_snd.gd"
}, {
"base": "ESCBaseCommand",
"class": "PlayVideoCommand",
"language": "GDScript",
"path": "res://gymkhana/addons/escoria-ui-return-monkey-island/esc/commands/play_video.gd"
}, {
"base": "ESCBaseCommand",
"class": "PrintCommand",
"language": "GDScript",
"path": "res://addons/escoria-core/game/core-scripts/esc/commands/print.gd"
@@ -794,6 +799,7 @@ _global_script_class_icons={
"InventoryRemoveCommand": "",
"ItemOutline": "res://addons/escoria-core/design/esc_item.svg",
"PlaySndCommand": "",
"PlayVideoCommand": "",
"PrintCommand": "",
"QueueEventCommand": "",
"QueueResourceCommand": "",