Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MomTV Replay Controls #150

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions layout/hud/replay-controls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,36 @@
<Label class="vertical-align-bottom" text="Tick: {i:curr_tick}/{i:total_ticks}" />
<TextEntry class="textentry replaycontrols__gototick" id="ReplayControlsGotoTick" placeholder="Goto tick" oninputsubmit="ReplayControlsHandler.gotoTick()" clearaftersubmit="true" />
</Panel>
<Label text="Time: {g:time:curr_time}/{g:time:total_time}" />
<SettingsSlider text="#Replay_Timescale" min="0" max="10" percentage="true" value100percent="1" convar="mom_replay_timescale" />
<Label text="Time: {g:time:curr_time}/{g:time:end_time}" />
<!-- <SettingsSlider text="#Replay_Timescale" min="0" max="10" percentage="true" value100percent="1" convar="mom_replay_timescale" /> -->
</Panel>
<Panel class="flow-right">
<Button class="button" onactivate="GameInterfaceAPI.ConsoleCommand('mom_replay_restart');">
<Button class="button" onactivate="GameInterfaceAPI.ConsoleCommand('mom_tv_replay_goto 0%');">
<Image class="button__icon" src="file://{images}/skip-next.svg" textureheight="32" orientation="180" />
</Button>
<HoldButton class="replaycontrols__holdbutton button ml-3" onmousedown="GameInterfaceAPI.ConsoleCommand('+mom_replay_backward');" onmouseup="GameInterfaceAPI.ConsoleCommand('-mom_replay_backward');">
<!-- <HoldButton class="replaycontrols__holdbutton button ml-3" onmousedown="GameInterfaceAPI.ConsoleCommand('+mom_replay_backward');" onmouseup="GameInterfaceAPI.ConsoleCommand('-mom_replay_backward');">
<Image class="button__icon" src="file://{images}/fast-forward.svg" textureheight="32" orientation="180" />
</HoldButton>
<Button class="button ml-3" onactivate="GameInterfaceAPI.ConsoleCommand('mom_replay_step -1');">
</HoldButton> -->
<Button class="button ml-3" onactivate="GameInterfaceAPI.ConsoleCommand('mom_tv_replay_goto -#1');">
<Image class="button__icon" src="file://{images}/fast-forward.svg" textureheight="32" orientation="180" />
</Button>
<Button class="button ml-3" onactivate="GameInterfaceAPI.ConsoleCommand('mom_tv_replay_goto -1 pause');">
<Image class="button__icon" src="file://{images}/subtract.svg" textureheight="32" />
</Button>
<ToggleButton id="ReplayControlsPausePlay" class="replaycontrols__bigbutton button togglebutton togglebutton--blue ml-3" onactivate="GameInterfaceAPI.ConsoleCommand('mom_replay_pause');">
<ToggleButton id="ReplayControlsPausePlay" class="replaycontrols__bigbutton button togglebutton togglebutton--blue ml-3" onactivate="GameInterfaceAPI.ConsoleCommand('mom_tv_replay_playpause');">
<Image class="button__icon replaycontrols__playicon" src="file://{images}/play.svg" textureheight="32" />
<Image class="button__icon replaycontrols__pauseicon" src="file://{images}/pause.svg" textureheight="32" />
</ToggleButton>
<Button class="button ml-3" onactivate="GameInterfaceAPI.ConsoleCommand('mom_replay_step 1');">
<Button class="button ml-3" onactivate="GameInterfaceAPI.ConsoleCommand('mom_tv_replay_goto +1 pause');">
<Image class="button__icon" src="file://{images}/add.svg" textureheight="32" />
</Button>
<HoldButton class="replaycontrols__holdbutton button ml-3" onmousedown="GameInterfaceAPI.ConsoleCommand('+mom_replay_forward');" onmouseup="GameInterfaceAPI.ConsoleCommand('-mom_replay_forward');">
<Button class="button ml-3" onactivate="GameInterfaceAPI.ConsoleCommand('mom_tv_replay_goto +#1');">
<Image class="button__icon" src="file://{images}/fast-forward.svg" textureheight="32"/>
</Button>
<!-- <HoldButton class="replaycontrols__holdbutton button ml-3" onmousedown="GameInterfaceAPI.ConsoleCommand('+mom_replay_forward');" onmouseup="GameInterfaceAPI.ConsoleCommand('-mom_replay_forward');">
<Image class="button__icon" src="file://{images}/fast-forward.svg" textureheight="32" />
</HoldButton>
<Button class="button ml-3" onactivate="GameInterfaceAPI.ConsoleCommand('mom_replay_goto_end');">
</HoldButton> -->
<Button class="button ml-3" onactivate="GameInterfaceAPI.ConsoleCommand('mom_tv_replay_goto 100%');">
<Image class="button__icon" src="file://{images}/skip-next.svg" textureheight="32" />
</Button>
</Panel>
Expand Down
26 changes: 15 additions & 11 deletions scripts/hud/replay-controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ReplayControlsHandler {
constructor() {
$.RegisterForUnhandledEvent('HudProcessInput', () => this.onHudUpdate());
$.RegisterEventHandler('SliderValueChanged', $.GetContextPanel(), (_, value) => {
MomentumReplayAPI.SetProgress(value);
GameInterfaceAPI.ConsoleCommand(`mom_tv_replay_goto ${value * 100}%`);
});
}

Expand All @@ -21,25 +21,29 @@ class ReplayControlsHandler {
}

onHudUpdate() {
const state = MomentumReplayAPI.GetReplayState();

if (state === MomentumReplayAPI.ReplayState.NONE) return;

const progress = MomentumReplayAPI.GetReplayProgress();

// Deal with the slider
const currentTick = MomentumReplayAPI.GetCurrentTick();
const totalTicks = MomentumReplayAPI.GetTotalTicks();
const flProgress = currentTick / totalTicks;
const progressPercent = progress.curtick / progress.totalticks;
// Don't interfere with the slider while the user is dragging it
if (!this.panels.timeSlider.dragging) this.panels.timeSlider.SetValueNoEvents(flProgress);
if (!this.panels.timeSlider.dragging) this.panels.timeSlider.SetValueNoEvents(progressPercent);

// Deal with pause/play -- play == selected
const bPlaying = !MomentumReplayAPI.IsPaused();
const bPlaying = state === MomentumReplayAPI.ReplayState.PLAYING;
if (this.panels.pausePlayButton.checked !== bPlaying) this.panels.pausePlayButton.checked = bPlaying;

this.panels.cp.SetDialogVariableInt('curr_tick', currentTick);
this.panels.cp.SetDialogVariableInt('total_ticks', totalTicks);
this.panels.cp.SetDialogVariableInt('curr_tick', progress.curtick);
this.panels.cp.SetDialogVariableInt('total_ticks', progress.totalticks);

this.panels.cp.SetDialogVariableFloat('curr_time', MomentumReplayAPI.GetCurrentTime());
this.panels.cp.SetDialogVariableFloat('total_time', MomentumReplayAPI.GetTotalTime());
this.panels.cp.SetDialogVariableFloat('curr_time', progress.curtime);
this.panels.cp.SetDialogVariableFloat('end_time', progress.endtime);
}

gotoTick() {
GameInterfaceAPI.ConsoleCommand(`mom_replay_goto ${this.panels.gotoTick.text}`);
GameInterfaceAPI.ConsoleCommand(`mom_tv_replay_goto ${this.panels.gotoTick.text}`);
}
}
17 changes: 17 additions & 0 deletions scripts/types-mom/apis.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,23 @@ declare namespace MomentumReplayAPI {

/** Sets the progress of the replay */
function SetProgress(progress: float): void;

const enum ReplayState {
NONE = 0,
PLAYING = 1,
PAUSED = 2
}

interface ReplayProgress {
curtick: int32;
totalticks: int32;
curtime: float;
endtime: float;
}

function GetReplayState(): ReplayState;

function GetReplayProgress(): ReplayProgress;
}

declare namespace ChatAPI {
Expand Down
Loading