Skip to content

Commit

Permalink
Hud mirror chat vote as an option
Browse files Browse the repository at this point in the history
  • Loading branch information
abnerfs committed Feb 16, 2024
1 parent e7ec4dc commit e3296c0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
9 changes: 5 additions & 4 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ public interface IEndOfMapConfig
public int MapsToShow { get; set; }
public bool ChangeMapImmediatly { get; set; }
public int VoteDuration { get; set; }
public int VotePercentage { get; set; }
public bool HudMenu { get; set; }
}

public class EndOfMapConfig : IVoteConfig, IEndOfMapConfig
public class EndOfMapConfig : IEndOfMapConfig
{
public bool Enabled { get; set; } = true;
public int MapsToShow { get; set; } = 6;
public bool HudMenu { get; set; } = true;
public bool ChangeMapImmediatly { get; set; } = false;
public int VoteDuration { get; set; } = 30;
public int VotePercentage { get; set; } = 60;
}

public class RtvConfig : ICommandConfig, IVoteConfig, IEndOfMapConfig
Expand All @@ -43,6 +43,7 @@ public class RtvConfig : ICommandConfig, IVoteConfig, IEndOfMapConfig
public int MapsToShow { get; set; } = 6;
public int VoteDuration { get; set; } = 30;
public int VotePercentage { get; set; } = 60;
public bool HudMenu { get; set; } = true;
}

public class VotemapConfig : ICommandConfig, IVoteConfig
Expand All @@ -58,7 +59,7 @@ public class VotemapConfig : ICommandConfig, IVoteConfig

public class Config : IBasePluginConfig
{
public int Version { get; set; } = 6;
public int Version { get; set; } = 7;
public RtvConfig Rtv { get; set; } = new();
public VotemapConfig Votemap { get; set; } = new();
public EndOfMapConfig EndOfMapVote { get; set; } = new();
Expand Down
6 changes: 4 additions & 2 deletions Core/ChangeMapManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Core;
using System.Numerics;

namespace cs2_rockthevote
{
Expand Down Expand Up @@ -84,7 +83,10 @@ public void OnLoad(Plugin plugin)
{
if (_pluginState.MapChangeScheduled)
{
ChangeNextMap(true);
_plugin.AddTimer(3.0F, () =>
{
ChangeNextMap(true);
});
}
return HookResult.Continue;
});
Expand Down
26 changes: 20 additions & 6 deletions Core/EndMapVoteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace cs2_rockthevote

public class EndMapVoteManager : IPluginDependency<Plugin, Config>
{
const int MAX_OPTIONS_HUD_MENU = 6;
public EndMapVoteManager(MapLister mapLister, ChangeMapManager changeMapManager, NominationCommand nominationManager, StringLocalizer localizer, PluginState pluginState)
{
_mapLister = mapLister;
Expand Down Expand Up @@ -105,10 +106,17 @@ public void VoteDisplayTick()
int index = 1;
StringBuilder stringBuilder = new();
stringBuilder.AppendFormat($"<b>{_localizer.Localize("emv.hud.hud-timer", timeLeft)}</b>");
foreach (var kv in Votes.OrderByDescending(x => x.Value).Take(5))
{
stringBuilder.AppendFormat($"<br>{index++} {kv.Key} <font color='green'>({kv.Value})</font>");
}
if(!_config!.HudMenu)
foreach (var kv in Votes.OrderByDescending(x => x.Value).Take(MAX_OPTIONS_HUD_MENU).Where(x => x.Value > 0))
{
stringBuilder.AppendFormat($"<br>{kv.Key} <font color='green'>({kv.Value})</font>");
}
else
foreach (var kv in Votes.Take(MAX_OPTIONS_HUD_MENU))
{
stringBuilder.AppendFormat($"<br><font color='yellow'>!{index++}</font> {kv.Key} <font color='green'>({kv.Value})</font>");
}

foreach (CCSPlayerController player in ServerManager.ValidPlayers())
{
player.PrintToCenterHtml(stringBuilder.ToString());
Expand Down Expand Up @@ -164,7 +172,10 @@ public void StartVote(IEndOfMapConfig config)
Votes.Clear();
_pluginState.EofVoteHappening = true;
_config = config;
var mapsToShow = _config!.MapsToShow == 0 ? 5 : _config!.MapsToShow;
int mapsToShow = _config!.MapsToShow == 0 ? MAX_OPTIONS_HUD_MENU : _config!.MapsToShow;
if (config.HudMenu)
mapsToShow = MAX_OPTIONS_HUD_MENU;

var mapsScrambled = Shuffle(new Random(), _mapLister.Maps!.Where(x => x != Server.MapName).ToList());
mapsEllected = _nominationManager.NominationWinners().Concat(mapsScrambled).Distinct().ToList();

Expand All @@ -173,7 +184,10 @@ public void StartVote(IEndOfMapConfig config)
foreach (var map in mapsEllected.Take(mapsToShow))
{
Votes[map] = 0;
menu.AddMenuOption(map, (player, option) => MapVoted(player, map));
menu.AddMenuOption(map, (player, option) => {
MapVoted(player, map);
MenuManager.CloseActiveMenu(player);
});
}

foreach (var player in ServerManager.ValidPlayers())
Expand Down
7 changes: 3 additions & 4 deletions Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Core.Plugin;
using Microsoft.Extensions.DependencyInjection;
using static CounterStrikeSharp.API.Core.Listeners;

Expand All @@ -21,7 +20,7 @@ public void ConfigureServices(IServiceCollection serviceCollection)
public partial class Plugin : BasePlugin, IPluginConfig<Config>
{
public override string ModuleName => "RockTheVote";
public override string ModuleVersion => "1.3.0";
public override string ModuleVersion => "1.4.0";
public override string ModuleAuthor => "abnerfs";
public override string ModuleDescription => "General purpose map voting plugin";

Expand Down Expand Up @@ -67,7 +66,7 @@ public HookResult OnChat(EventPlayerChat @event, GameEventInfo info)
var player = Utilities.GetPlayerFromUserid(@event.Userid);

var text = @event.Text.Trim().ToLower();
if (@event.Text.Trim() == "rtv")
if (text == "rtv")
{
_rtvManager.CommandHandler(player);
}
Expand All @@ -93,7 +92,7 @@ public HookResult OnChat(EventPlayerChat @event, GameEventInfo info)
public void OnConfigParsed(Config config)
{
Config = config;
if (Config.Version < 6)
if (Config.Version < 7)
throw new Exception("Your config file is too old, please delete it from addons/counterstrikesharp/configs/plugins/RockTheVote and let the plugin recreate it on load");

_dependencyManager.OnConfigParsed(config);
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# CS2 Rock The Vote
![image](https://github.com/abnerfs/cs2-rockthevote/assets/14078661/a603d1b6-ba35-4d5a-b887-1b14058a8050)

General purpose map voting plugin, started as a simple RTV and now has more features

## RockTheVote
Expand Down Expand Up @@ -43,18 +45,18 @@ Players can type `timeleft` to see how much time is left in the current map
- Changes in the config file will require you to reload the plugin or restart the server (change the map won't work).

```json
// This configuration was automatically generated by CounterStrikeSharp for plugin 'RockTheVote', at 2024/02/15 10:33:07
{
"Version": 6,
"Version": 7,
"Rtv": {
"Enabled": true,
"EnabledInWarmup": true,
"MinPlayers": 0,
"MinRounds": 0,
"ChangeMapImmediatly": false,
"ChangeMapImmediatly": true,
"MapsToShow": 6,
"VoteDuration": 30,
"VotePercentage": 60
"VotePercentage": 60,
"HudMenu": true
},
"Votemap": {
"Enabled": true,
Expand All @@ -65,11 +67,11 @@ Players can type `timeleft` to see how much time is left in the current map
"MinRounds": 0
},
"EndOfMapVote": {
"Enabled": false,
"Enabled": true,
"MapsToShow": 6,
"HudMenu": true,
"ChangeMapImmediatly": false,
"VoteDuration": 30,
"VotePercentage": 60
"VoteDuration": 30
}
}
```
Expand Down

0 comments on commit e3296c0

Please sign in to comment.