From 863794d3c0b611d7fad86c7d4d672db4a9446391 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 1 May 2024 01:30:03 +0200 Subject: [PATCH] Add playback buttons and info label to Video Player actor editor --- .../SceneGraph/Actors/VideoPlayerEditor.cs | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Source/Editor/SceneGraph/Actors/VideoPlayerEditor.cs diff --git a/Source/Editor/SceneGraph/Actors/VideoPlayerEditor.cs b/Source/Editor/SceneGraph/Actors/VideoPlayerEditor.cs new file mode 100644 index 000000000..c497d05f3 --- /dev/null +++ b/Source/Editor/SceneGraph/Actors/VideoPlayerEditor.cs @@ -0,0 +1,69 @@ +// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. + +using System; +using FlaxEngine; +using FlaxEngine.GUI; + +namespace FlaxEditor.CustomEditors.Dedicated +{ + /// + /// Custom editor for . + /// + [CustomEditor(typeof(VideoPlayer)), DefaultEditor] + public class VideoPlayerEditor : ActorEditor + { + private Label _infoLabel; + + /// + public override void Initialize(LayoutElementsContainer layout) + { + base.Initialize(layout); + + // Show playback options during simulation + if (Editor.IsPlayMode) + { + var playbackGroup = layout.Group("Playback"); + playbackGroup.Panel.Open(); + + _infoLabel = playbackGroup.Label(string.Empty).Label; + _infoLabel.AutoHeight = true; + + var grid = playbackGroup.CustomContainer(); + var gridControl = grid.CustomControl; + gridControl.ClipChildren = false; + gridControl.Height = Button.DefaultHeight; + gridControl.SlotsHorizontally = 3; + gridControl.SlotsVertically = 1; + grid.Button("Play").Button.Clicked += () => Foreach(x => x.Play()); + grid.Button("Pause").Button.Clicked += () => Foreach(x => x.Pause()); + grid.Button("Stop").Button.Clicked += () => Foreach(x => x.Stop()); + } + } + + /// + public override void Refresh() + { + base.Refresh(); + + if (_infoLabel != null) + { + var text = string.Empty; + foreach (var value in Values) + { + if (value is VideoPlayer player) + text += $"Time: {player.Time:##0.0}s / {player.Duration:##0.0}s\nResolution: {player.Size.X}x{player.Size.Y}, Frame Rate: {player.FrameRate}"; + } + _infoLabel.Text = text; + } + } + + private void Foreach(Action func) + { + foreach (var value in Values) + { + if (value is VideoPlayer player) + func(player); + } + } + } +}