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

Current next map theme update #253

Merged
merged 8 commits into from
Jul 30, 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
18 changes: 18 additions & 0 deletions src/Modules/CurrentMapModule/Config/ICurrentMapSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.ComponentModel;
using Config.Net;
using EvoSC.Modules.Attributes;

namespace EvoSC.Modules.Official.CurrentMapModule.Config;

[Settings]
public interface ICurrentMapSettings
{
[Option(DefaultValue = 80.0), Description("Specifies the Y position of the widget.")]
public double Y { get; set; }

[Option(DefaultValue = 36.0), Description("Specifies the width of the widget.")]
public double Width { get; set; }

[Option(DefaultValue = "right"), Description("Specifies on which side the widget is displayed.")]
public string Position { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace EvoSC.Modules.Official.CurrentMapModule.Controllers;

[Controller]
public class CurrentMapController(ICurrentMapService service) : EvoScController<IEventControllerContext>
public class CurrentMapEventController(ICurrentMapService service) : EvoScController<IEventControllerContext>
{
[Subscribe(GbxRemoteEvent.BeginMatch)]
public Task OnBeginMatchAsync(object sender, EventArgs args)
Expand Down
35 changes: 19 additions & 16 deletions src/Modules/CurrentMapModule/Services/CurrentMapService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
using EvoSC.Common.Services.Attributes;
using EvoSC.Common.Services.Models;
using EvoSC.Manialinks.Interfaces;
using EvoSC.Modules.Official.CurrentMapModule.Config;
using EvoSC.Modules.Official.CurrentMapModule.Interfaces;
using EvoSC.Modules.Official.WorldRecordModule.Interfaces;
using GbxRemoteNet.Events;
using Microsoft.Extensions.Logging;

namespace EvoSC.Modules.Official.CurrentMapModule.Services;

[Service(LifeStyle = ServiceLifeStyle.Transient)]
public class CurrentMapService(IManialinkManager manialinkManager, ILogger<CurrentMapService> logger,
IMapRepository mapRepository, IServerClient client, IWorldRecordService worldRecordService)
public class CurrentMapService(
IManialinkManager manialinkManager,
ILogger<CurrentMapService> logger,
IMapRepository mapRepository,
IServerClient client,
ICurrentMapSettings settings
)
: ICurrentMapService
{
[ExcludeFromCodeCoverage(Justification = "GBXRemoteClient cannot be mocked.")]
Expand All @@ -37,24 +42,22 @@ public async Task HideWidgetAsync()
private async Task ShowManialinkAsync(string mapUId)
{
var dbMap = await mapRepository.GetMapByUidAsync(mapUId);
string author;
var worldRecord = await worldRecordService.GetRecordAsync();
if (dbMap?.Author?.NickName == dbMap?.Author?.AccountId)

if (dbMap == null)
{
var serverMap = await client.Remote.GetCurrentMapInfoAsync();
author = serverMap.AuthorNickname.Length > 0 ? serverMap.AuthorNickname : serverMap.Author;
return;
}
else

var author = dbMap.Author?.NickName;

if (dbMap.Author?.NickName == dbMap.Author?.AccountId)
{
author = dbMap.Author?.NickName;
var serverMap = await client.Remote.GetCurrentMapInfoAsync();
author = serverMap.AuthorNickname.Length > 0 ? serverMap.AuthorNickname : serverMap.Author;
}

await manialinkManager.SendPersistentManialinkAsync("CurrentMapModule.CurrentMapWidget",
new
{
map = dbMap,
mapauthor = author,
record = worldRecord
});
new { map = dbMap, mapAuthor = author, settings });
logger.LogDebug("Showing current map widget");
}
}
137 changes: 25 additions & 112 deletions src/Modules/CurrentMapModule/Templates/CurrentMapWidget.mt
Original file line number Diff line number Diff line change
@@ -1,123 +1,36 @@
<component>
<using namespace="EvoSC.Common.Interfaces.Models"/>
<using namespace="EvoSC.Modules.Official.WorldRecordModule.Models"/>
<using namespace="EvoSC.Modules.Official.CurrentMapModule.Config"/>

<property type="IMap?" name="map" default="null" />
<property type="string" name="mapauthor" default="null" />
<property type="WorldRecord?" name="record" default="null" />
<import component="EvoSC.Containers.Widget" as="Widget"/>
<import component="EvoSC.Style.UIStyle" as="UIStyle"/>

<property type="double" name="scale" default="0.9" />
<property type="double" name="w" default="68.0" />
<property type="double" name="y" default="85.0" />
<property type="double" name="headerHeight" default="8.0" />
<property type="double" name="bodyHeight" default="22.0" />
<property type="ICurrentMapSettings" name="settings"/>
<property type="IMap?" name="map" default="null"/>
<property type="string" name="mapAuthor" default="null"/>

<template>
<frame pos="{{ 160.0 - w * scale }} {{ y }}" scale="{{ scale }}" z-index="100">
<frame>
<frame size="{{ w }} {{ headerHeight - 0.1 }}">
<!-- HEADER -->
<quad pos="-0.15 0"
size="{{ w + 20.1 }} {{ headerHeight + 0.3 }}"
style="UICommon64_1"
substyle="BgFrame1"
colorize="{{ Theme.CurrentMapModule_CurrentMapWidget_Default_BgHeaderGrad1 }}"
<UIStyle/>
<Widget header="current map" height="10" position="{{ settings.Position }}" y="{{ settings.Y }}">
<template slot="body">
<frame pos='{{ settings.Position=="right" ? settings.Width-2.0 : 0 }} 0'>
<label text="{{ map?.Name }}"
class="text-primary"
pos="0 -3"
valign="center"
halign="right"
size="{{ settings.Width-2 }} 5"
/>

<!-- GRADIENT -->
<quad pos="{{ w }} {{ -headerHeight }}"
size="{{ w }} {{ headerHeight - 0.1 }}"
image="file://Media/Painter/Stencils/15-Stripes/_Stripe0Grad/Brush.tga"
modulatecolor="{{ Theme.CurrentMapModule_CurrentMapWidget_Default_BgHeaderGrad2 }}"
rot="180"
/>

<!-- LABEL -->
<label pos="2 {{ headerHeight / -2.0 - 0.4 }}"
text="Current Map"
valign="center2"
textfont="{{ Font.Bold }}"
textprefix="$i$t"
textsize="2"
textcolor="{{ Theme.CurrentMapModule_CurrentMapWidget_Default_Text }}"
/>

<!-- LOGO -->
<quad if='Theme.CurrentMapModule_CurrentMapWidget_Default_Logo != ""'
pos="{{ w - 3.0 }} {{ headerHeight / -2.0 }}"
size="20 3.2"
valign="center"
halign="right"
keepratio="Fit"
image="{{ Theme.CurrentMapModule_CurrentMapWidget_Default_Logo }}"
opacity="0.75"
/>
</frame>

<!-- BACKGROUND -->
<quad pos="0 {{ -headerHeight + 0.1 }}"
size="{{ w }} {{ bodyHeight }}"
bgcolor="{{ Theme.CurrentMapModule_CurrentMapWidget_Default_BgContent }}"
opacity="0.9"
/>
</frame>

<framemodel id="gradient_box">
<frame size="0.95 8">
<quad pos="0 0.2"
size="2 8.4"
style="UICommon64_1"
substyle="BgFrame2"
colorize="{{ Theme.CurrentMapModule_CurrentMapWidget_Default_BgRow }}"
opacity="0.75"
/>
</frame>

<!-- GRADIENT -->
<quad pos="1 0"
size="{{ w - 10.0 }} 8"
image="file://Media/Painter/Stencils/15-Stripes/_Stripe0Grad/Brush.tga"
modulatecolor="{{ Theme.CurrentMapModule_CurrentMapWidget_Default_BgRow }}"
opacity="0.75"
/>
</framemodel>

<!-- CONTENT -->
<frame pos="2 {{ -headerHeight - 2.0 }}" size="{{ w }} 999" z-index="10">
<frameinstance modelid="gradient_box" />
<frame pos="-0.2 -1">
<label pos="2 0"
text='{{ map?.Name ?? "loading..." }}'
textsize="1.4"
textfont="{{ Font.Regular }}"
textcolor="{{ Theme.CurrentMapModule_CurrentMapWidget_Default_Text }}"
/>
<label pos="2 -3.2"
text='by {{ mapauthor ?? "loading..." }}'
textsize="1.1"
textfont="{{ Font.Thin }}"
textcolor="{{ Theme.CurrentMapModule_CurrentMapWidget_Default_Text }}"
<label text="$<$tby {{ mapAuthor }}$>"
class="text-primary"
textsize="0.75"
pos="0 -6.5"
valign="center"
halign="right"
size="{{ settings.Width-2 }} 5"
/>
</frame>

<frame v-if="record != null">
<frameinstance modelid="gradient_box" pos="0 -9" />
<frame pos="-0.2 -10">
<label pos="2 0"
text="Record: {{ record?.Time.ToString() }} [{{ record?.Source }}]"
textsize="1.4"
textfont="{{ Font.Regular }}"
textcolor="{{ Theme.CurrentMapModule_CurrentMapWidget_Default_Text }}"
/>
<label pos="2 -3.2"
text="by {{ record?.PlayerName }}"
textsize="1.1"
textfont="{{ Font.Thin }}"
textcolor="{{ Theme.CurrentMapModule_CurrentMapWidget_Default_Text }}"
/>
</frame>
</frame>
</frame>
</frame>
</template>
</Widget>
</template>
</component>
5 changes: 1 addition & 4 deletions src/Modules/CurrentMapModule/info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@
name = "CurrentMapModule"
title = "Current Map Module"
summary = "A module for showing the current map"
version = "1.0.0"
version = "1.0.1"
author = "Evo"

[dependencies]
WorldRecordModule = "1.0.0"
18 changes: 18 additions & 0 deletions src/Modules/NextMapModule/Config/INextMapSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.ComponentModel;
using Config.Net;
using EvoSC.Modules.Attributes;

namespace EvoSC.Modules.Official.NextMapModule.Config;

[Settings]
public interface INextMapSettings
{
[Option(DefaultValue = 80.0), Description("Specifies the Y position of the widget.")]
public double Y { get; set; }

[Option(DefaultValue = 36.0), Description("Specifies the width of the widget.")]
public double Width { get; set; }

[Option(DefaultValue = "right"), Description("Specifies on which side the widget is displayed.")]
public string Position { get; set; }
}
31 changes: 10 additions & 21 deletions src/Modules/NextMapModule/Controllers/NextMapEventController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
using EvoSC.Common.Remote;
using EvoSC.Common.Remote.EventArgsModels;
using EvoSC.Manialinks.Interfaces;
using EvoSC.Modules.Official.NextMapModule.Config;
using EvoSC.Modules.Official.NextMapModule.Interfaces;
using GbxRemoteNet.Events;

namespace EvoSC.Modules.Official.NextMapModule.Controllers;

[Controller]
public class NextMapEventController(INextMapService nextMapService, IManialinkManager manialinkManager)
: EvoScController<IEventControllerContext>
public class NextMapEventController(
INextMapService nextMapService,
IManialinkManager manialinkManager,
INextMapSettings settings
) : EvoScController<IEventControllerContext>
{
private const string Template = "NextMapModule.NextMap";

Expand All @@ -20,27 +25,11 @@ public async Task ShowNextMapOnPodiumStartAsync(object sender, PodiumEventArgs a
{
var nextMap = await nextMapService.GetNextMapAsync();
await manialinkManager.SendManialinkAsync(Template,
new
{
mapName = nextMap.Name,
author = nextMap.Author?.NickName
});
new { mapName = nextMap.Name, author = nextMap.Author?.NickName, settings });
}

[Subscribe(ModeScriptEvent.PodiumEnd)]
public async Task HideNextMapOnPodiumEndAsync(object sender, PodiumEventArgs args)
{
await manialinkManager.HideManialinkAsync(Template);
}

[Subscribe(ModeScriptEvent.StartMapStart)]
public async Task HideNextMapOnMapStartAsync(object sender, MapEventArgs args)
{
await manialinkManager.HideManialinkAsync(Template);
}

[Subscribe(ModeScriptEvent.EndMapEnd)]
public async Task HideNextMapOnMapEndAsync(object sender, MapEventArgs args)
[Subscribe(GbxRemoteEvent.BeginMap)]
public async Task HideNextMapOnBeginMapAsync(object sender, MapGbxEventArgs args)
{
await manialinkManager.HideManialinkAsync(Template);
}
Expand Down
Loading
Loading