diff --git a/mod/Gangs.BaseImpl/BasePerk.cs b/mod/Gangs.BaseImpl/BasePerk.cs index d05fe6ec..27576d36 100644 --- a/mod/Gangs.BaseImpl/BasePerk.cs +++ b/mod/Gangs.BaseImpl/BasePerk.cs @@ -5,14 +5,14 @@ namespace Gangs.BaseImpl; -public abstract class BasePerk(IServiceProvider provider) : BaseStat, IPerk { +public abstract class BasePerk : BaseStat, IPerk { public abstract Task GetCost(IGangPlayer player); public abstract Task OnPurchase(IGangPlayer player); public abstract Task GetMenu(IGangPlayer player); } public abstract class BasePerk(IServiceProvider provider) - : BasePerk(provider), IPerk, IStat { + : BasePerk(), IPerk, IStat { protected IServiceProvider Provider { get; } = provider; public override Type ValueType => typeof(TV); public abstract TV Value { get; set; } diff --git a/mod/Gangs.BaseImpl/GangCommandManager.cs b/mod/Gangs.BaseImpl/GangCommandManager.cs deleted file mode 100644 index b92c64f2..00000000 --- a/mod/Gangs.BaseImpl/GangCommandManager.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Gangs.BaseImpl; - -public class GangCommandManager { - -} \ No newline at end of file diff --git a/mod/Gangs.BombIconPerk/BombIconCommand.cs b/mod/Gangs.BombIconPerk/BombIconCommand.cs index 26160ddc..c8ead5b3 100644 --- a/mod/Gangs.BombIconPerk/BombIconCommand.cs +++ b/mod/Gangs.BombIconPerk/BombIconCommand.cs @@ -71,7 +71,7 @@ public async Task Execute(PlayerWrapper? executor, if (!success || data == null) data = new BombPerkData(); if (info.ArgCount == 1) { - var menu = new BombIconMenu(provider, gang.GangId); + var menu = new BombIconMenu(provider, data); await menus.OpenMenu(executor, menu); return CommandResult.SUCCESS; } diff --git a/mod/Gangs.BombIconPerk/BombIconMenu.cs b/mod/Gangs.BombIconPerk/BombIconMenu.cs index 5860f3cc..f272a9bc 100644 --- a/mod/Gangs.BombIconPerk/BombIconMenu.cs +++ b/mod/Gangs.BombIconPerk/BombIconMenu.cs @@ -4,51 +4,46 @@ using GangsAPI.Extensions; using GangsAPI.Services.Gang; using GangsAPI.Services.Menu; +using Menu; using Microsoft.Extensions.DependencyInjection; namespace Gangs.BombIconPerk; -public class BombIconMenu(IServiceProvider provider, int gangId) : IMenu { - private readonly IGangStatManager gangStats = - provider.GetRequiredService(); - - private readonly IGangManager gangs = - provider.GetRequiredService(); - - public async Task Open(PlayerWrapper player) { - player.PrintToChat(ChatColors.DarkBlue + "Gang Perk: " - + ChatColors.LightBlue + "Bomb Icon"); - - var (success, data) = - await gangStats.GetForGang(gangId, BombPerk.STAT_ID); - if (!success || data == null) data = new BombPerkData(); - - var unlocked = data.Unlocked; - var equipped = data.Equipped; - - var index = 0; - foreach (var icon in Enum.GetValues()) { - index++; - if (unlocked.HasFlag(icon)) { - player.PrintToChat( - $"{index}. {ChatColors.LightBlue}{icon.ToString().ToTitleCase()} {ChatColors.LightRed}{icon.GetCost()}"); - continue; - } - - if (equipped == icon) { - player.PrintToChat( - $"{index}. {ChatColors.LightBlue}{icon.ToString().ToTitleCase()} {ChatColors.Green}(Equipped)"); - continue; - } - - player.PrintToChat( - $"{index}. {ChatColors.LightBlue}{icon.ToString().ToTitleCase()} {ChatColors.LightYellow}(Select)"); +public class BombIconMenu(IServiceProvider provider, BombPerkData data) + : AbstractPagedMenu(provider, NativeSenders.Chat, 7) { + // Method to sort bomb icons + private int CompareBombIcons(BombIcon a, BombIcon b) { + // If the icon is equipped, it should be first + if (a == data.Equipped) return -1; + + // If icon is unlocked, it should be next + // If both are unlocked, sort by cost (highest first) + if (a == data.Unlocked) { + if (b == data.Equipped) return 1; + return b == data.Unlocked ? a.GetCost().CompareTo(b.GetCost()) : -1; } + + // If both are locked, sort by cost (lowest first) + if (b == data.Equipped) return 1; + return b == data.Unlocked ? 1 : a.GetCost().CompareTo(b.GetCost()); } - public Task Close(PlayerWrapper player) { return Task.CompletedTask; } + override protected Task> GetItems(PlayerWrapper player) { + var list = Enum.GetValues().ToList(); + list.Sort(CompareBombIcons); + return Task.FromResult(list); + } - public Task AcceptInput(PlayerWrapper player, int input) { + override protected Task HandleItemSelection(PlayerWrapper player, + List items, int selectedIndex) { + player.PrintToChat("Selected " + items[selectedIndex]); return Task.CompletedTask; } + + override protected Task FormatItem(PlayerWrapper player, int index, + BombIcon item) { + if (item == data.Equipped) return Task.FromResult($"{item} (Equipped)"); + if (item == data.Unlocked) return Task.FromResult($"{item} (Unlocked)"); + return Task.FromResult($"{item} ({item.GetCost()})"); + } } \ No newline at end of file diff --git a/mod/Gangs.BombIconPerk/BombPerk.cs b/mod/Gangs.BombIconPerk/BombPerk.cs index d1dfb754..f05d05db 100644 --- a/mod/Gangs.BombIconPerk/BombPerk.cs +++ b/mod/Gangs.BombIconPerk/BombPerk.cs @@ -1,7 +1,9 @@ using System.Diagnostics; using Gangs.BaseImpl; using GangsAPI.Data.Gang; +using GangsAPI.Services.Gang; using GangsAPI.Services.Menu; +using Microsoft.Extensions.DependencyInjection; namespace Gangs.BombIconPerk; @@ -11,6 +13,9 @@ public class BombPerk(IServiceProvider provider) public override string StatId => STAT_ID; public override string Name => "Bomb Icon"; + private readonly IGangStatManager gangStats = + provider.GetRequiredService(); + public override string? Description => "Customize the icon that is shown when you bomb a CT"; @@ -24,10 +29,15 @@ public override Task OnPurchase(IGangPlayer player) { throw new NotImplementedException(); } - public override Task GetMenu(IGangPlayer player) { + public override async Task GetMenu(IGangPlayer player) { Debug.Assert(player.GangId != null, "player.GangId != null"); - return Task.FromResult(new BombIconMenu(Provider, - player.GangId.Value)); + + var (success, data) = + await gangStats.GetForGang(player.GangId.Value, STAT_ID); + + if (!success || data == null) data = new BombPerkData(); + + return new BombIconMenu(Provider, data); } } diff --git a/mod/Gangs.Boostrap/GangsServiceExtension.cs b/mod/Gangs.Boostrap/GangsServiceExtension.cs index dec37380..88222009 100644 --- a/mod/Gangs.Boostrap/GangsServiceExtension.cs +++ b/mod/Gangs.Boostrap/GangsServiceExtension.cs @@ -17,11 +17,7 @@ public static void AddGangs(this IServiceCollection services) { public class GangsInit : IPluginBehavior { public void Start(BasePlugin basePlugin) { - basePlugin.Logger.LogInformation("Timer fired"); var services = API.Gangs?.Services; - basePlugin.Logger.LogInformation( - "Found services: {services} (is null: {null}) ({Gangs}) (null: {isNull})", - services, services == null, API.Gangs, API.Gangs == null); if (services == null) return; _ = new BombIconBootstrap(services, basePlugin); diff --git a/public/Jailbreak.Public/Mixin/GangsAPI.dll b/public/Jailbreak.Public/Mixin/GangsAPI.dll index 3fb11694..9ead2129 100644 Binary files a/public/Jailbreak.Public/Mixin/GangsAPI.dll and b/public/Jailbreak.Public/Mixin/GangsAPI.dll differ