146 lines
No EOL
4.4 KiB
C#
146 lines
No EOL
4.4 KiB
C#
using System.Diagnostics;
|
|
using JD.Application.Properties;
|
|
using JD.Application.Utils;
|
|
using JD.Application.View.Misc;
|
|
using JD.Audio.SoundPlayer;
|
|
using JD.Core;
|
|
using JD.Interfaces.Player;
|
|
using JD.WinFormExtensions;
|
|
using TeaBox;
|
|
using TeaBox.Core.Source.Gui;
|
|
using TeaBox.Core.Source.Gui.Misc;
|
|
using TeaBox.Gui;
|
|
|
|
namespace JD.Application.View.Actions
|
|
{
|
|
public class PlayActionHandler : PlaybackActionHandlerBase
|
|
{
|
|
public PlayActionHandler()
|
|
{
|
|
|
|
}
|
|
|
|
protected override void Update(ActionInfo info, IPlayer player)
|
|
{
|
|
var iconResource = ResourcesCache.Icons_30x30_Play;
|
|
|
|
if (player.Playing)
|
|
{
|
|
iconResource = ResourcesCache.Icons_30x30_Pause;
|
|
}
|
|
|
|
info.Icon = new ImageOrIcon(iconResource);
|
|
}
|
|
|
|
private float _timeOnPlay = 0;
|
|
|
|
protected override void Execute(IPlayer player)
|
|
{
|
|
if (!SetFocusOnUAFWindow())
|
|
{
|
|
player.Playing = !player.Playing;
|
|
|
|
if (player.Playing)
|
|
{
|
|
_timeOnPlay = player.CurrentTime;
|
|
}
|
|
else
|
|
{
|
|
if (EditionOptions.RememberSeekTime)
|
|
{
|
|
player.CurrentTime = _timeOnPlay;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool SetFocusOnUAFWindow()
|
|
{
|
|
// Users have to toggle play while mouse is not over the UAF main window.
|
|
// When mouse is over UAF main window, it gives Windows focus to it instead of toggling play, so users may move elements in the engine.
|
|
System.Drawing.Point cursorPos;
|
|
uint processId;
|
|
|
|
User32.GetCursorPos(out cursorPos);
|
|
var windowHandle = User32.WindowFromPoint(cursorPos);
|
|
User32.GetWindowThreadProcessId(windowHandle, out processId);
|
|
|
|
var mouseProcess = Process.GetProcessById((int) processId);
|
|
if (mouseProcess.ProcessName.Contains("ITF_AppFramework") ||
|
|
mouseProcess.ProcessName.Contains("UA_Engine"))
|
|
{
|
|
User32.SetForegroundWindow(windowHandle);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public class MarkCheckpointActionHandler : PlaybackActionHandlerBase
|
|
{
|
|
protected override void Execute(IPlayer player)
|
|
{
|
|
var checkpoint = player.Components.GetOrCreate<Checkpoint>();
|
|
checkpoint.Time = player.CurrentTime;
|
|
}
|
|
}
|
|
|
|
public class ClearCheckpointActionHandler : PlaybackActionHandlerBase
|
|
{
|
|
protected override void Update(ActionInfo info, IPlayer player)
|
|
{
|
|
var checkpoint = player.Components.GetOrCreate<Checkpoint>();
|
|
info.Enabled = checkpoint.Time.HasValue;
|
|
}
|
|
|
|
protected override void Execute(IPlayer player)
|
|
{
|
|
var checkpoint = player.Components.GetOrCreate<Checkpoint>();
|
|
checkpoint.Time = null;
|
|
}
|
|
}
|
|
|
|
public class GoToCheckpointActionHandler : PlaybackActionHandlerBase
|
|
{
|
|
protected override void Update(ActionInfo info, IPlayer player)
|
|
{
|
|
var checkpoint = player.Components.GetOrCreate<Checkpoint>();
|
|
info.Enabled = checkpoint.Time.HasValue;
|
|
}
|
|
|
|
protected override void Execute(IPlayer player)
|
|
{
|
|
var checkpoint = player.Components.GetOrCreate<Checkpoint>();
|
|
if (checkpoint.Time.HasValue)
|
|
{
|
|
player.CurrentTime = checkpoint.Time.Value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class RewindActionHandler : PlaybackActionHandlerBase
|
|
{
|
|
protected override void Execute(IPlayer player)
|
|
{
|
|
player.CurrentTime = 0;
|
|
}
|
|
}
|
|
|
|
public class PreviousFrameActionHandler : PlaybackActionHandlerBase
|
|
{
|
|
protected override void Execute(IPlayer player)
|
|
{
|
|
var newTime = player.CurrentTime - FrameConverter.TimeFromFrame(1);
|
|
player.CurrentTime = FrameConverter.SnapTimeToFrame(newTime);
|
|
}
|
|
}
|
|
|
|
public class NextFrameActionHandler : PlaybackActionHandlerBase
|
|
{
|
|
protected override void Execute(IPlayer player)
|
|
{
|
|
var newTime = player.CurrentTime + FrameConverter.TimeFromFrame(1);
|
|
player.CurrentTime = FrameConverter.SnapTimeToFrame(newTime);
|
|
}
|
|
}
|
|
} |