Skip to content

Commit

Permalink
Merge branch 'master' into scoreboard-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
araszka authored Oct 4, 2024
2 parents aacc420 + af73895 commit 77ecac6
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 75 deletions.
14 changes: 14 additions & 0 deletions src/EvoSC.Common/Remote/EventArgsModels/WarmUpRoundEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace EvoSC.Common.Remote.EventArgsModels;

public class WarmUpRoundEventArgs: EventArgs
{
/// <summary>
/// The current warm-up round.
/// </summary>
public required int Current { get; init; }

/// <summary>
/// The total amount of warm-ups.
/// </summary>
public required int Total { get; init; }
}
12 changes: 12 additions & 0 deletions src/EvoSC.Common/Remote/ModeScriptEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ public enum ModeScriptEvent
[Identifier(Name = "ModeScript.WarmUpStart")]
WarmUpStart,

/// <summary>
/// When a warm-up round starts.
/// </summary>
[Identifier(Name = "ModeScript.WarmUpStartRound")]
WarmUpStartRound,

/// <summary>
/// When a warm-up round starts.
/// </summary>
[Identifier(Name = "ModeScript.WarmUpEndRound")]
WarmUpEndRound,

/// <summary>
/// When a player got eliminated by an obstacle.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions src/EvoSC.Common/Remote/ServerCallbackHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ await _events.RaiseAsync(ModeScriptEvent.StartLine,
case "Trackmania.WarmUp.Start":
await _events.RaiseAsync(ModeScriptEvent.WarmUpStart, EventArgs.Empty);
break;
case "Trackmania.WarmUp.StartRound":
await _events.RaiseAsync(ModeScriptEvent.WarmUpStartRound,
new WarmUpRoundEventArgs
{
Current = data.GetValue("current", StringComparison.Ordinal).ToObject<int>(),
Total = data.GetValue("total", StringComparison.Ordinal).ToObject<int>()
});
break;
case "Trackmania.WarmUp.EndRound":
await _events.RaiseAsync(ModeScriptEvent.WarmUpEndRound,
new WarmUpRoundEventArgs
{
Current = data.GetValue("current", StringComparison.Ordinal).ToObject<int>(),
Total = data.GetValue("total", StringComparison.Ordinal).ToObject<int>()
});
break;
case "Trackmania.Event.Eliminated":
await _events.RaiseAsync(ModeScriptEvent.Eliminated,
new PlayerUpdateEventArgs
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ public interface ISpectatorCamModeService
/// </summary>
/// <returns></returns>
public Task SendPersistentCamModeWidgetAsync();

/// <summary>
/// Hides the previously send widget.
/// </summary>
/// <returns></returns>
public Task HideCamModeWidgetAsync();

/// <summary>
/// Hides the default UI provided by the game mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ ISpectatorCamModeSettings settings
public Task SendPersistentCamModeWidgetAsync() =>
manialinks.SendPersistentManialinkAsync(WidgetTemplate, new { settings });

public Task HideCamModeWidgetAsync() =>
manialinks.HideManialinkAsync(WidgetTemplate);

public Task HideGameModeUiAsync() =>
gameModeUiModuleService.ApplyComponentSettingsAsync(GetGameModeUiSettings());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,24 @@ Void SetCamModeNameAndIcon(Integer _CamMode, CMlFrame camModeFrame) {
}

declare Real spacing = 1.0;
declare Real offset = 0.0;
declare Real width = 0.0;
if (camModeLabel != Null){
camModeLabel.Value = TextLib::ToUpperCase(Text_CamMode);
offset = spacing * 2.0 + camModeLabel.ComputeWidth(camModeLabel.Value);
width = spacing * 2.0 + camModeLabel.ComputeWidth(camModeLabel.Value);
}
if (camModeQuad != Null){
camModeQuad.ImageUrl = Icon_CamMode;
camModeQuad.RelativePosition_V3.X = offset + spacing;
width = width + spacing + camModeQuad.Size.X;
camModeQuad.RelativePosition_V3.X = {{ width }} * 1.0 - spacing - camModeQuad.Size.X;
}
if (camModeLabel != Null){
camModeLabel.Value = TextLib::ToUpperCase(Text_CamMode);
camModeLabel.RelativePosition_V3.X = camModeQuad.RelativePosition_V3.X - spacing;
}
width = width + spacing * 2.0;
camModeFrame.Size.X = width;
camModeBg.Size.X = width;
camModeFrame.Size.X = 32.0;
camModeBg.Size.X = 32.0;

declare Integer targetCamMode for camModeFrame;
targetCamMode = _CamMode;

if({{ settings.Alignment == WidgetPosition.Right ? "True" : "False" }}){
camModeFrame.RelativePosition_V3.X = width * -1.0;
camModeFrame.RelativePosition_V3.X = camModeFrame.Size.X * -1.0;
}else if({{ settings.Alignment == WidgetPosition.Center ? "True" : "False" }}){
camModeFrame.RelativePosition_V3.X = width / -2.0;
camModeFrame.RelativePosition_V3.X = camModeFrame.Size.X / -2.0;
}
}

Expand Down Expand Up @@ -236,7 +231,9 @@ main(){
while(True){
yield;

declare shouldBeDisplayed = InputPlayer != Null && InputPlayer.SpawnStatus == CSmPlayer::ESpawnStatus::NotSpawned;
declare shouldBeDisplayed = InputPlayer != Null
&& InputPlayer.SpawnStatus == CSmPlayer::ESpawnStatus::NotSpawned
&& UI.UISequence == CUIConfig::EUISequence::Playing;

if(!shouldBeDisplayed){
if(mainFrame.Visible){
Expand Down
11 changes: 6 additions & 5 deletions src/Modules/SpectatorCamModeModule/Templates/SpectatorMode.mt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<property type="ISpectatorCamModeSettings" name="settings"/>
<property type="double" name="width" default="32.0"/>
<property type="double" name="height" default="5.5"/>
<property type="double" name="opacityUnfocused" default="0.1"/>
<property type="double" name="opacityUnfocused" default="0.001"/>

<template>
<UIStyle/>
Expand All @@ -27,6 +27,7 @@
textfont="{{ Font.Bold }}"
text="CAM MODE"
valign="center2"
halign="right"
/>
<quad id="cam_mode_icon"
size="3.5 3.5"
Expand All @@ -43,10 +44,10 @@
size="{{ width }} {{ height * 3.0 }}"
hidden="1"
>
<frameinstance modelid="option"/>
<frameinstance modelid="option"/>
<frameinstance modelid="option"/>
<frameinstance modelid="option"/>
<frameinstance modelid="option" size="{{ width }} {{ height }}"/>
<frameinstance modelid="option" size="{{ width }} {{ height }}"/>
<frameinstance modelid="option" size="{{ width }} {{ height }}"/>
<frameinstance modelid="option" size="{{ width }} {{ height }}"/>
</frame>
</frame>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,14 @@ public async Task OnNewRoundAsync(object sender, RoundEventArgs roundEventArgs)
{
await spectatorTargetInfoService.ClearCheckpointsAsync();
await spectatorTargetInfoService.FetchAndCacheTeamInfoAsync();
await spectatorTargetInfoService.ResetWidgetForSpectatorsAsync();
}

[Subscribe(ModeScriptEvent.WarmUpStartRound)]
public async Task OnNewWarmUpRoundAsync(object sender, WarmUpRoundEventArgs roundEventArgs)
{
await spectatorTargetInfoService.ClearCheckpointsAsync();
await spectatorTargetInfoService.FetchAndCacheTeamInfoAsync();
await spectatorTargetInfoService.ResetWidgetForSpectatorsAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,37 @@ Void FocusPlayer(CSmPlayer _Player) {
}
}

Text SpecPrevious(CMlLabel button, Boolean focus){
Void SpecPrevious(CMlLabel button, Boolean focus){
AnimatePop(button);
declare CSmPlayer target <=> GetNextSpawnedPlayer();
if(focus){
if(target == Null && focus){
FocusPlayer(target);
}
return target.User.Login;
}

Text SpecNext(CMlLabel button, Boolean focus){
Void SpecNext(CMlLabel button, Boolean focus){
AnimatePop(button);
declare CSmPlayer target <=> GetNextSpawnedPlayer();
if(focus){
if(target != Null && focus){
FocusPlayer(target);
}
return target.User.Login;
}

main() {
declare mainFrame <=> (Page.MainFrame.GetFirstChild("main_frame") as CMlFrame);
declare previousButton <=> (Page.MainFrame.GetFirstChild("left_button") as CMlLabel);
declare nextButton <=> (Page.MainFrame.GetFirstChild("right_button") as CMlLabel);
declare targetLogin = "{{ playerLogin }}";

while(True){
yield;

if(GUIPlayer == Null){
declare shouldBeDisplayed = GUIPlayer != Null && UI.UISequence == CUIConfig::EUISequence::Playing;

if(!shouldBeDisplayed){
if(mainFrame.Visible){
mainFrame.Hide();
}
sleep(100);
continue;
}

Expand All @@ -122,10 +122,10 @@ main() {
foreach(Event in PendingEvents){
if(Event.Type == CMlScriptEvent::Type::MouseClick){
if(Event.Control == previousButton){
targetLogin = SpecPrevious(previousButton, True);
SpecPrevious(previousButton, True);
continue;
}else if(Event.Control == nextButton){
targetLogin = SpecNext(nextButton, True);
SpecNext(nextButton, True);
continue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
size="{{ (h*3.4)*0.8 }} {{ h }}"
textsize="{{ Theme.UI_FontSize*2 }}"
textfont="{{ Font.Regular }}"
text='{{ timeDifference > 0 ? RaceTime.FromMilliseconds(timeDifference) : "000" }}'
text='{{ RaceTime.FromMilliseconds(timeDifference) }}'
textprefix="+"
halign="center"
valign="center2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ public async Task SendsPersistentCamModeWidget()
m.SendPersistentManialinkAsync("SpectatorCamModeModule.SpectatorMode", It.IsAny<object>()), Times.Once);
}

[Fact]
public async Task HidesCamModeWidget()
{
var camModeService = CamModeServiceMock();
await camModeService.HideCamModeWidgetAsync();

_manialinkManager.Verify(m =>
m.HideManialinkAsync("SpectatorCamModeModule.SpectatorMode"), Times.Once);
}

[Fact]
public async Task HidesDefaultGameModeUi()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,13 @@ public async Task Resets_Collected_Data_On_New_Round()
_spectatorTargetService.Verify(sts => sts.ClearCheckpointsAsync());
_spectatorTargetService.Verify(sts => sts.FetchAndCacheTeamInfoAsync());
}

[Fact]
public async Task Resets_Collected_Data_On_New_Warm_Up_Round()
{
await Controller.OnNewWarmUpRoundAsync(null, new WarmUpRoundEventArgs { Total = 3, Current = 1 });

_spectatorTargetService.Verify(sts => sts.ClearCheckpointsAsync());
_spectatorTargetService.Verify(sts => sts.FetchAndCacheTeamInfoAsync());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit 77ecac6

Please sign in to comment.