Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ namespace MapChooserSharp.Modules.MapVote.Countdown.Chat;
public class McsChatCountdownUi(IServiceProvider provider): IMcsCountdownUi
{
private readonly TncssPluginBase _plugin = provider.GetRequiredService<TncssPluginBase>();

private bool _isFirstNotificationNotified = false;

public void ShowCountdownToPlayer(CCSPlayerController player, int secondsLeft)
{
player.PrintToChat(_plugin.LocalizeStringForPlayer(player, "MapVote.Broadcast.Countdown", secondsLeft));
if (!_isFirstNotificationNotified || secondsLeft <= 10)
{
player.PrintToChat(_plugin.LocalizeStringForPlayer(player, "MapVote.Broadcast.Countdown", secondsLeft));
_isFirstNotificationNotified = true;
}
}

public void Close(CCSPlayerController player){}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using MapChooserSharp.Modules.MapVote.Countdown.CenterHud;
using MapChooserSharp.Modules.MapVote.Countdown.Chat;
using MapChooserSharp.Modules.MapVote.Countdown.Interfaces;
using MapChooserSharp.Modules.PluginConfig.Interfaces;
using Microsoft.Extensions.DependencyInjection;
using TNCSSPluginFoundation.Models.Plugin;

Expand All @@ -22,7 +23,7 @@ internal sealed class McsCountdownUiController(IServiceProvider serviceProvider,

private readonly Dictionary<McsCountdownType, IMcsCountdownUi> _countdownUis = new();


private IMcsPluginConfigProvider _mcsPluginConfigProvider = null!;

public override void RegisterServices(IServiceCollection services)
{
Expand All @@ -37,6 +38,8 @@ protected override void OnInitialize()
_countdownUis[McsCountdownType.CenterHtml] = new McsCenterHtmlCountdownUi(ServiceProvider);
_countdownUis[McsCountdownType.Chat] = new McsChatCountdownUi(ServiceProvider);

_mcsPluginConfigProvider = ServiceProvider.GetRequiredService<IMcsPluginConfigProvider>();

if (hotReload)
{
foreach (CCSPlayerController player in Utilities.GetPlayers())
Expand Down Expand Up @@ -68,9 +71,9 @@ private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventI

private void PlayerConnectFull(CCSPlayerController player)
{
McsCountdownType type = _mcsPluginConfigProvider.PluginConfig.VoteConfig.CurrentCountdownType;

// TODO() Player preference from DB

McsCountdownType type = McsCountdownType.CenterHtml;

UpdateCountdownType(player, type);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MapChooserSharp.Models;
using MapChooserSharp.Modules.MapVote.Countdown;
using MapChooserSharp.Modules.McsMenu;

namespace MapChooserSharp.Modules.PluginConfig.Interfaces;
Expand All @@ -9,6 +10,8 @@ internal interface IMcsVoteConfig

internal McsSupportedMenuType CurrentMenuType { get; }

internal McsCountdownType CurrentCountdownType { get; }

internal int MaxMenuElements { get; }

internal bool ShouldPrintVoteToChat { get; }
Expand Down
15 changes: 13 additions & 2 deletions MapChooserSharp/Modules/PluginConfig/McsPluginConfigParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CounterStrikeSharp.API;
using MapChooserSharp.Models;
using MapChooserSharp.Modules.MapVote.Countdown;
using MapChooserSharp.Modules.McsDatabase;
using MapChooserSharp.Modules.McsMenu;
using MapChooserSharp.Modules.PluginConfig.Interfaces;
Expand Down Expand Up @@ -178,6 +179,11 @@ private IMcsVoteConfig ParseVoteConfig(TomlTable tomlModel)
{
throw new InvalidOperationException("MapVote.MenuType is not found or invalid");
}

if (!voteTable.TryGetValue("CountdownUiType", out var countdownUiTypeObj) || countdownUiTypeObj is not string countdownUiType)
{
throw new InvalidOperationException("MapVote.MenCountdownUiTypeuType is not found or invalid");
}


if (!voteTable.TryGetValue("MaxVoteElements", out var maxVoteElementsObj) || maxVoteElementsObj is not long maxVoteElementsLong)
Expand All @@ -192,11 +198,16 @@ private IMcsVoteConfig ParseVoteConfig(TomlTable tomlModel)

var availableMenus = _avaiableMenuTypes;

var currentMenuType = DecideMenuType(menuTypeStr, availableMenus);
var currentMenuType = DecideMenuType(countdownUiType, availableMenus);

var soundConfig = ParseVoteSoundConfig(voteTable);

return new McsVoteConfig(availableMenus, currentMenuType, (int)maxVoteElementsLong, shouldPrintVoteToChatBool, soundConfig);
if (!Enum.TryParse(countdownUiType, true, out McsCountdownType countdownType))
{
throw new InvalidOperationException("MapVote.MenCountdownUiTypeuType is invalid");
}

return new McsVoteConfig(availableMenus, currentMenuType, (int)maxVoteElementsLong, shouldPrintVoteToChatBool, soundConfig, countdownType);
}

private IMcsVoteSoundConfig ParseVoteSoundConfig(TomlTable tomlModel)
Expand Down
4 changes: 3 additions & 1 deletion MapChooserSharp/Modules/PluginConfig/Models/McsVoteConfig.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using MapChooserSharp.Models;
using MapChooserSharp.Modules.MapVote.Countdown;
using MapChooserSharp.Modules.McsMenu;
using MapChooserSharp.Modules.PluginConfig.Interfaces;

namespace MapChooserSharp.Modules.PluginConfig.Models;

internal class McsVoteConfig(List<McsSupportedMenuType> availableVoteMenuTypes, McsSupportedMenuType currentMcsVoteMenuType, int maxMenuElements, bool shouldPrintVoteToChat, IMcsVoteSoundConfig voteSoundConfig)
internal class McsVoteConfig(List<McsSupportedMenuType> availableVoteMenuTypes, McsSupportedMenuType currentMcsVoteMenuType, int maxMenuElements, bool shouldPrintVoteToChat, IMcsVoteSoundConfig voteSoundConfig, McsCountdownType currentCountdownType)
: IMcsVoteConfig
{
public List<McsSupportedMenuType> AvailableMenuTypes { get; } = availableVoteMenuTypes;
public McsSupportedMenuType CurrentMenuType { get; } = currentMcsVoteMenuType;
public McsCountdownType CurrentCountdownType { get; } = currentCountdownType;
public int MaxMenuElements { get; } = maxMenuElements;
public bool ShouldPrintVoteToChat { get; } = shouldPrintVoteToChat;
public IMcsVoteSoundConfig VoteSoundConfig { get; } = voteSoundConfig;
Expand Down