Skip to content

Commit

Permalink
Merge pull request #42 from MrEliptik/video
Browse files Browse the repository at this point in the history
Implementing ability to play trailer in ogv format using a button #40
  • Loading branch information
MrEliptik authored Sep 25, 2024
2 parents 0293bea + 5add972 commit 22d2485
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 4 deletions.
2 changes: 2 additions & 0 deletions autoload/signal_bus.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
extends Node

signal shortcut_close_game_pressed()
signal game_launched()
signal game_closed()
1 change: 1 addition & 0 deletions games/config_template.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ executable = "game.exe"
capsule = "capsule.png"
background = "bg.png"
description = "Here is the description"
video = ""
category = ["Tools", "Tests"]
release_date = "2023"
platforms = "Steam, Itch"
Expand Down
46 changes: 43 additions & 3 deletions scenes/app/app.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=16 format=3 uid="uid://dh01oxe50pj27"]
[gd_scene load_steps=18 format=3 uid="uid://dh01oxe50pj27"]

[ext_resource type="Script" path="res://scenes/app/scripts/app.gd" id="1_ov0up"]
[ext_resource type="PackedScene" uid="uid://dweckt5oraox7" path="res://scenes/game_button/game_button.tscn" id="2_t5myg"]
Expand All @@ -9,6 +9,8 @@
[ext_resource type="Script" path="res://scenes/carousel/scripts/carousel.gd" id="4_yrr54"]
[ext_resource type="Texture2D" uid="uid://dph8j6sb0fjbv" path="res://scenes/game_button/visuals/bg_test.png" id="5_o0uvn"]
[ext_resource type="Script" path="res://scenes/app/scripts/bg_blend.gd" id="6_2ddv3"]
[ext_resource type="Script" path="res://scenes/video_player/scripts/video_player.gd" id="10_dod4b"]
[ext_resource type="Texture2D" uid="uid://dr4kg5w8jskhd" path="res://shared/visuals/play.png" id="10_gt0gt"]

[sub_resource type="ShaderMaterial" id="ShaderMaterial_psg6v"]
shader = ExtResource("4_7um57")
Expand Down Expand Up @@ -138,7 +140,7 @@ anchor_bottom = 0.5
offset_left = -478.0
offset_top = 140.0
offset_right = 478.0
offset_bottom = 307.0
offset_bottom = 432.0
grow_horizontal = 2
size_flags_horizontal = 3
size_flags_vertical = 0
Expand Down Expand Up @@ -185,7 +187,6 @@ vertical_alignment = 1
autowrap_mode = 3

[node name="QRContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer/HBoxContainer"]
visible = false
layout_mode = 2
theme_override_constants/separation = 5

Expand All @@ -208,6 +209,32 @@ label_settings = SubResource("LabelSettings_wrab5")
horizontal_alignment = 1
vertical_alignment = 1

[node name="VideoBtn" type="Button" parent="PanelContainer/MarginContainer/HBoxContainer/QRContainer"]
custom_minimum_size = Vector2(0, 40)
layout_mode = 2
size_flags_vertical = 3

[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer/HBoxContainer/QRContainer/VideoBtn"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
alignment = 1

[node name="TextureRect" type="TextureRect" parent="PanelContainer/MarginContainer/HBoxContainer/QRContainer/VideoBtn/HBoxContainer"]
custom_minimum_size = Vector2(25, 25)
layout_mode = 2
texture = ExtResource("10_gt0gt")
expand_mode = 1
stretch_mode = 5

[node name="Label" type="Label" parent="PanelContainer/MarginContainer/HBoxContainer/QRContainer/VideoBtn/HBoxContainer"]
layout_mode = 2
text = "Play trailer"
label_settings = SubResource("LabelSettings_wrab5")

[node name="MouseFilter" type="ColorRect" parent="."]
visible = false
self_modulate = Color(1, 1, 1, 0)
Expand All @@ -217,3 +244,16 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="VideoPlayer" type="VideoStreamPlayer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
expand = true
loop = true
script = ExtResource("10_dod4b")

[connection signal="pressed" from="PanelContainer/MarginContainer/HBoxContainer/QRContainer/VideoBtn" to="." method="_on_video_btn_pressed"]
20 changes: 20 additions & 0 deletions scenes/app/scripts/app.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var gamepad_kill_btn_pressed: Array = []
@onready var qr_container: VBoxContainer = $PanelContainer/MarginContainer/HBoxContainer/QRContainer
@onready var qr_rect: TextureRect = $PanelContainer/MarginContainer/HBoxContainer/QRContainer/QRRect
@onready var qr_label: Label = $PanelContainer/MarginContainer/HBoxContainer/QRContainer/QRLabel
@onready var video_btn: Button = $PanelContainer/MarginContainer/HBoxContainer/QRContainer/VideoBtn
@onready var video_player: VideoPlayer = $VideoPlayer

@onready var update_checker := UpdateChecker.new()
@onready var global_shortcut: GlobalShortcut
Expand Down Expand Up @@ -233,6 +235,7 @@ func parse_config(path: String, dir: String, dict: Dictionary) -> bool:
dict["bg"] = dir.path_join(config.get_value("GAME", "background"))
dict["description"] = config.get_value("GAME", "description")
dict["players_nb"] = config.get_value("GAME", "players_nb")
dict["video"] = config.get_value("GAME", "video", null)
dict["release_date"] = config.get_value("GAME", "release_date")
dict["platforms"] = config.get_value("GAME", "platforms")
dict["arguments"] = config.get_value("GAME", "arguments")
Expand Down Expand Up @@ -262,6 +265,7 @@ func launch_game(game_name: String) -> void:
else:
pid_watching = OS.create_process(executable_path, [])
timer.start()
SignalBus.game_launched.emit()

launched_game_name = game_name
if games[game_name].has("relaunch_on_crash") and games[game_name]["relaunch_on_crash"]:
Expand All @@ -273,6 +277,7 @@ func stop_game(pid: int) -> void:
OS.kill(pid)
relaunch_on_crash = false
launched_game_name = ""
SignalBus.game_closed.emit()

func on_timer_timeout() -> void:
if OS.is_process_running(pid_watching):
Expand All @@ -281,12 +286,24 @@ func on_timer_timeout() -> void:
print("Stopped")
timer.stop()
pid_watching = -1
SignalBus.game_closed.emit()
if curr_game_btn:
curr_game_btn.button_pressed = false
games_container.can_move = true
DisplayServer.window_move_to_foreground()

func on_game_btn_focused(who: Button) -> void:
if who.properties.has("video") and who.properties["video"] or who.properties["video"] != "":
var video_stream_theora = VideoStreamTheora.new()
# File extension is ignored, so it is possible to load Ogg Theora videos
# that have an `.ogg` extension this way.
video_stream_theora.file = who.properties["video"]
video_player.stream = video_stream_theora
video_btn.show()
else:
video_btn.hide()
video_player.stream = null

if not who.properties.has("description"):
description.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
else:
Expand Down Expand Up @@ -349,3 +366,6 @@ func _physics_process(_delta: float) -> void:
# crash / taskmanager
if OS.get_process_exit_code(pid_watching) > 0:
launch_game(launched_game_name)

func _on_video_btn_pressed() -> void:
video_player.play_video()
49 changes: 49 additions & 0 deletions scenes/video_player/scripts/video_player.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
extends VideoStreamPlayer

class_name VideoPlayer

@export var timeout_before_play: float = 10.0

var game_running: bool = false

@onready var timer: Timer = Timer.new()

func _ready() -> void:
SignalBus.game_launched.connect(func(): game_running = true)
SignalBus.game_closed.connect(func():
game_running = false
#timer.start()
)

#add_child(timer)
#timer.one_shot = true
#timer.wait_time = timeout_before_play
#timer.start()
#visible = false
#
#timer.timeout.connect(on_timer_timeout)

func _input(event: InputEvent) -> void:
if game_running or not visible: return

# Check if any input to stop the player and restart the timer
if event is InputEventMouseButton or event is InputEventJoypadButton \
or event is InputEventKey:
stop_video()
#timer.start()
# Prevent the rest of the app from reacting to this event
get_viewport().set_input_as_handled()

func play_video() -> void:
show()
play()

func stop_video() -> void:
hide()
stop()

func on_timer_timeout() -> void:
return
if game_running: return
visible = true
play()
2 changes: 1 addition & 1 deletion shared/utils/update_checker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func new_version_available(project_version: String, latest_version: String) -> b

func on_request_completed(result, response_code, headers, body) -> void:
var json = JSON.parse_string(body.get_string_from_utf8())

if not json: return
if json.has("message"):
print(json["message"])
return
Expand Down
Binary file added shared/visuals/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions shared/visuals/play.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://dr4kg5w8jskhd"
path="res://.godot/imported/play.png-0e338f240fd05097c5b13b1d530d0f46.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://shared/visuals/play.png"
dest_files=["res://.godot/imported/play.png-0e338f240fd05097c5b13b1d530d0f46.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

0 comments on commit 22d2485

Please sign in to comment.