Add color support and improve menu option formatting
This commit is contained in:
parent
5ee1764318
commit
6422436252
15 changed files with 65 additions and 40 deletions
|
|
@ -8,36 +8,36 @@ public class WasdManager : IWasdMenuManager
|
|||
public void OpenMainMenu(CCSPlayerController? player, IWasdMenu? menu)
|
||||
{
|
||||
if(!TryGetPlayer(player, out var menuPlayer)) return;
|
||||
menuPlayer.OpenMainMenu((WasdMenu?)menu);
|
||||
menuPlayer?.OpenMainMenu((WasdMenu?)menu);
|
||||
}
|
||||
|
||||
public void CloseMenu(CCSPlayerController? player)
|
||||
{
|
||||
if (!TryGetPlayer(player, out var menuPlayer)) return;
|
||||
menuPlayer.OpenMainMenu(null);
|
||||
menuPlayer?.OpenMainMenu(null);
|
||||
}
|
||||
|
||||
public void CloseSubMenu(CCSPlayerController? player)
|
||||
{
|
||||
if (!TryGetPlayer(player, out var menuPlayer)) return;
|
||||
menuPlayer.CloseSubMenu();
|
||||
menuPlayer?.CloseSubMenu();
|
||||
}
|
||||
|
||||
public void CloseAllSubMenus(CCSPlayerController? player)
|
||||
{
|
||||
if (!TryGetPlayer(player, out var menuPlayer)) return;
|
||||
menuPlayer.CloseAllSubMenus();
|
||||
menuPlayer?.CloseAllSubMenus();
|
||||
}
|
||||
|
||||
public void OpenSubMenu(CCSPlayerController? player, IWasdMenu? menu)
|
||||
{
|
||||
if (!TryGetPlayer(player, out var menuPlayer)) return;
|
||||
menuPlayer.OpenSubMenu(menu);
|
||||
menuPlayer?.OpenSubMenu(menu);
|
||||
}
|
||||
|
||||
public IWasdMenu CreateMenu(string title = "", string controlText = "")
|
||||
{
|
||||
WasdMenu menu = new WasdMenu
|
||||
WasdMenu menu = new()
|
||||
{
|
||||
Title = title,
|
||||
ControlText = controlText
|
||||
|
|
@ -53,10 +53,10 @@ public class WasdManager : IWasdMenuManager
|
|||
public void UpdateActiveMenu(CCSPlayerController? player, Dictionary<string, Action<CCSPlayerController, IWasdMenuOption>> list)
|
||||
{
|
||||
if (!TryGetPlayer(player, out var menuPlayer)) return;
|
||||
menuPlayer.UpdateActiveMenu(list);
|
||||
menuPlayer?.UpdateActiveMenu(list);
|
||||
}
|
||||
|
||||
private bool TryGetPlayer(CCSPlayerController? player, out WasdMenuPlayer menuPlayer)
|
||||
private static bool TryGetPlayer(CCSPlayerController? player, out WasdMenuPlayer? menuPlayer)
|
||||
{
|
||||
menuPlayer = null!;
|
||||
if (player == null || !player.IsValid || player.IsBot || player.SteamID == 0) return false;
|
||||
|
|
|
|||
|
|
@ -11,9 +11,8 @@ public class WasdMenu : IWasdMenu
|
|||
public LinkedListNode<IWasdMenuOption>? Prev { get; set; } = null;
|
||||
public LinkedListNode<IWasdMenuOption> Add(string display, Action<CCSPlayerController, IWasdMenuOption> onChoice)
|
||||
{
|
||||
if (Options == null)
|
||||
Options = new();
|
||||
WasdMenuOption newOption = new WasdMenuOption
|
||||
Options ??= new();
|
||||
WasdMenuOption newOption = new()
|
||||
{
|
||||
OptionDisplay = display,
|
||||
OnChoose = onChoice,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace WASDMenuAPI;
|
|||
|
||||
public class WasdMenuPlayer
|
||||
{
|
||||
public CCSPlayerController player { get; set; }
|
||||
public required CCSPlayerController Player { get; set; }
|
||||
public WasdMenu? MainMenu = null;
|
||||
public LinkedListNode<IWasdMenuOption>? CurrentChoice = null;
|
||||
public LinkedListNode<IWasdMenuOption>? MenuStart = null;
|
||||
|
|
@ -87,7 +87,7 @@ public class WasdMenuPlayer
|
|||
|
||||
public void Choose()
|
||||
{
|
||||
CurrentChoice?.Value.OnChoose?.Invoke(player, CurrentChoice.Value);
|
||||
CurrentChoice?.Value.OnChoose?.Invoke(Player, CurrentChoice.Value);
|
||||
}
|
||||
|
||||
public void ScrollDown()
|
||||
|
|
@ -126,10 +126,10 @@ public class WasdMenuPlayer
|
|||
string endControl = "";
|
||||
LinkedListNode<IWasdMenuOption>? option = MenuStart;
|
||||
|
||||
if (option?.Value?.Parent?.Title != "")
|
||||
if (!string.IsNullOrEmpty(option?.Value?.Parent?.Title))
|
||||
builder.AppendLine($"{option.Value.Parent?.Title}</u><font class='fontSize-m' color='white'><br>");
|
||||
|
||||
if (option?.Value?.Parent?.ControlText != "")
|
||||
if (!string.IsNullOrEmpty(option?.Value?.Parent?.ControlText))
|
||||
endControl = option?.Value?.Parent?.ControlText ?? "";
|
||||
|
||||
int shown = 0;
|
||||
|
|
@ -143,29 +143,43 @@ public class WasdMenuPlayer
|
|||
$"<img src='https://raw.githubusercontent.com/oqyh/cs2-Kill-Sound-GoldKingZ/main/Resources/arrow.gif' class=''> <img src='https://raw.githubusercontent.com/oqyh/cs2-Kill-Sound-GoldKingZ/main/Resources/arrow.gif' class=''> <img src='https://raw.githubusercontent.com/oqyh/cs2-Kill-Sound-GoldKingZ/main/Resources/arrow.gif' class=''> <br>");
|
||||
break;
|
||||
}*/
|
||||
string text = option.Value.OptionDisplay!;
|
||||
|
||||
string input = option.Value.OptionDisplay ?? string.Empty;
|
||||
string color = string.Empty;
|
||||
string text = input;
|
||||
|
||||
if (input.Contains('|'))
|
||||
{
|
||||
string[] parts = input.Split("|", 2);
|
||||
color = parts[0].StartsWith("#") && parts[0].Length == 7 ? parts[0] : string.Empty;
|
||||
text = parts.Length > 1 ? parts[1] : "";
|
||||
}
|
||||
|
||||
if (option == CurrentChoice)
|
||||
{
|
||||
if (text.Length > maxLength)
|
||||
{
|
||||
if (scrollIndex >= text.Length - maxLength)
|
||||
int remaining = text.Length - scrollIndex;
|
||||
if (remaining <= maxLength)
|
||||
{
|
||||
text = text.Substring(scrollIndex);
|
||||
text = SafeSubstring(text, scrollIndex, remaining);
|
||||
if (Server.TickCount % 32 == 0)
|
||||
scrollIndex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
text = text.Substring(scrollIndex, maxLength);
|
||||
text = SafeSubstring(text, scrollIndex, maxLength);
|
||||
if (Server.TickCount % 32 == 0)
|
||||
scrollIndex += scrollJump;
|
||||
}
|
||||
}
|
||||
else
|
||||
text = SafeSubstring(text, 0, maxLength);
|
||||
|
||||
builder.AppendLine($"</font><font color='purple'>[ </font><font color='orange'>{text}</font><font color='purple'> ]</font><font color='white'> <br>");
|
||||
}
|
||||
else
|
||||
builder.AppendLine($"{text.Substring(0, maxLength)} <br>");
|
||||
builder.AppendLine($"<font color='{color ?? "white"}'>{SafeSubstring(text, 0, maxLength)}</font> <br>");
|
||||
|
||||
option = option.Next;
|
||||
shown++;
|
||||
|
|
@ -194,7 +208,7 @@ public class WasdMenuPlayer
|
|||
|
||||
foreach (var item in list)
|
||||
{
|
||||
WasdMenuOption newOption = new WasdMenuOption
|
||||
WasdMenuOption newOption = new()
|
||||
{
|
||||
OptionDisplay = item.Key,
|
||||
OnChoose = item.Value,
|
||||
|
|
@ -226,4 +240,14 @@ public class WasdMenuPlayer
|
|||
|
||||
UpdateCenterHtml();
|
||||
}
|
||||
|
||||
private static string SafeSubstring(string text, int start, int length)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return "";
|
||||
if (start < 0) start = 0;
|
||||
if (start >= text.Length) return "";
|
||||
if (start + length > text.Length)
|
||||
length = text.Length - start;
|
||||
return text.Substring(start, length);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,9 +6,9 @@ namespace WASDMenuAPI;
|
|||
|
||||
public class WASDMenuAPI
|
||||
{
|
||||
public string ModuleName => "WASDMenuAPI";
|
||||
public string ModuleVersion => "1.0.2";
|
||||
public string ModuleAuthor => "Interesting";
|
||||
public static string ModuleName => "WASDMenuAPI";
|
||||
public static string ModuleVersion => "1.0.2";
|
||||
public static string ModuleAuthor => "Interesting";
|
||||
|
||||
public static readonly Dictionary<ulong, WasdMenuPlayer> Players = [];
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ public class WASDMenuAPI
|
|||
if (@event.Userid != null)
|
||||
Players[@event.Userid.SteamID] = new WasdMenuPlayer
|
||||
{
|
||||
player = @event.Userid,
|
||||
Player = @event.Userid,
|
||||
Buttons = 0
|
||||
};
|
||||
return HookResult.Continue;
|
||||
|
|
@ -38,7 +38,7 @@ public class WASDMenuAPI
|
|||
{
|
||||
Players[pl.SteamID] = new WasdMenuPlayer
|
||||
{
|
||||
player = pl,
|
||||
Player = pl,
|
||||
Buttons = pl.Buttons
|
||||
};
|
||||
}
|
||||
|
|
@ -48,23 +48,23 @@ public class WASDMenuAPI
|
|||
{
|
||||
foreach (var player in Players.Values.Where(p => p.MainMenu != null))
|
||||
{
|
||||
if ((player.Buttons & PlayerButtons.Forward) == 0 && (player.player.Buttons & PlayerButtons.Forward) != 0)
|
||||
if ((player.Buttons & PlayerButtons.Forward) == 0 && (player.Player.Buttons & PlayerButtons.Forward) != 0)
|
||||
{
|
||||
player.ScrollUp();
|
||||
}
|
||||
else if((player.Buttons & PlayerButtons.Back) == 0 && (player.player.Buttons & PlayerButtons.Back) != 0)
|
||||
else if((player.Buttons & PlayerButtons.Back) == 0 && (player.Player.Buttons & PlayerButtons.Back) != 0)
|
||||
{
|
||||
player.ScrollDown();
|
||||
}
|
||||
else if((player.Buttons & PlayerButtons.Use) == 0 && (player.player.Buttons & PlayerButtons.Use) != 0)
|
||||
else if((player.Buttons & PlayerButtons.Use) == 0 && (player.Player.Buttons & PlayerButtons.Use) != 0)
|
||||
{
|
||||
player.Choose();
|
||||
}
|
||||
|
||||
player.Buttons = player.player.Buttons;
|
||||
player.Buttons = player.Player.Buttons;
|
||||
if(player.CenterHtml != "")
|
||||
Server.NextFrame(() =>
|
||||
player.player.PrintToCenterHtml(player.CenterHtml)
|
||||
player.Player.PrintToCenterHtml(player.CenterHtml)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@
|
|||
"gambler": "Gambler",
|
||||
"gambler_desc": "Select a skill from the list provided.",
|
||||
"gambler_select_info": "Select your skill:",
|
||||
"gambler_more": "<font class='fontSize-m' color='#00FF00'>Refresh for $100</font>",
|
||||
"gambler_more": "#00FF00|Refresh for ${0}",
|
||||
|
||||
"ghost": "Ghost",
|
||||
"ghost_desc": "You are completely invisible",
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@
|
|||
"gambler": "Hazardzista",
|
||||
"gambler_desc": "Wybierz umiejętność z podanej listy.",
|
||||
"gambler_select_info": "Wybierz umiejętność:",
|
||||
"gambler_more": "<font class='fontSize-m' color='#00FF00'>Odśwież za $100</font>",
|
||||
"gambler_more": "#00FF00|Odśwież za ${0}",
|
||||
|
||||
"ghost": "Duszek",
|
||||
"ghost_desc": "Jesteś całkowicie niewidzialny",
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@
|
|||
"gambler": "Apostador",
|
||||
"gambler_desc": "Selecione uma habilidade da lista.",
|
||||
"gambler_select_info": "Escolha sua habilidade:",
|
||||
"gambler_more": "<font class='fontSize-m' color='#00FF00'>Atualizar por $100</font>",
|
||||
"gambler_more": "#00FF00|Atualizar por ${0}",
|
||||
|
||||
"ghost": "Fantasma",
|
||||
"ghost_desc": "Você é completamente invisível",
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@
|
|||
"gambler": "赌徒",
|
||||
"gambler_desc": "从提供的列表中选择一个技能。",
|
||||
"gambler_select_info": "选择你的技能:",
|
||||
"gambler_more": "<font class='fontSize-m' color='#00FF00'>刷新 $100</font>",
|
||||
"gambler_more": "#00FF00|刷新 ${0}",
|
||||
|
||||
"ghost": "幽灵",
|
||||
"ghost_desc": "你完全隐形",
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ namespace jRandomSkills
|
|||
Instance.AddTimer(.1f, () =>
|
||||
{
|
||||
playerInfo.Skill = skill.Skill;
|
||||
if (skill.Skill != skillName)
|
||||
playerInfo.SpecialSkill = skillName;
|
||||
playerInfo.SkillChance = 1;
|
||||
Instance.SkillAction(skill.Skill.ToString(), "EnableSkill", [player]);
|
||||
});
|
||||
|
|
@ -73,7 +75,7 @@ namespace jRandomSkills
|
|||
|
||||
HashSet<(string, string)> menuItems = [(firstSkill.Name, firstSkill.Skill.ToString()),
|
||||
(secondSkill.Name, secondSkill.Skill.ToString()),
|
||||
(Localization.GetTranslation("gambler_more"), skillName.ToString())];
|
||||
(Localization.GetTranslation("gambler_more", refreshPrice), skillName.ToString())];
|
||||
SkillUtils.CreateMenu(player, menuItems);
|
||||
}
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -132,7 +132,7 @@
|
|||
"gambler": "Gambler",
|
||||
"gambler_desc": "Select a skill from the list provided.",
|
||||
"gambler_select_info": "Select your skill:",
|
||||
"gambler_more": "<font class='fontSize-m' color='#00FF00'>Refresh for $100</font>",
|
||||
"gambler_more": "#00FF00|Refresh for ${0}",
|
||||
|
||||
"ghost": "Ghost",
|
||||
"ghost_desc": "You are completely invisible",
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@
|
|||
"gambler": "Hazardzista",
|
||||
"gambler_desc": "Wybierz umiejętność z podanej listy.",
|
||||
"gambler_select_info": "Wybierz umiejętność:",
|
||||
"gambler_more": "<font class='fontSize-m' color='#00FF00'>Odśwież za $100</font>",
|
||||
"gambler_more": "#00FF00|Odśwież za ${0}",
|
||||
|
||||
"ghost": "Duszek",
|
||||
"ghost_desc": "Jesteś całkowicie niewidzialny",
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@
|
|||
"gambler": "Apostador",
|
||||
"gambler_desc": "Selecione uma habilidade da lista.",
|
||||
"gambler_select_info": "Escolha sua habilidade:",
|
||||
"gambler_more": "<font class='fontSize-m' color='#00FF00'>Atualizar por $100</font>",
|
||||
"gambler_more": "#00FF00|Atualizar por ${0}",
|
||||
|
||||
"ghost": "Fantasma",
|
||||
"ghost_desc": "Você é completamente invisível",
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@
|
|||
"gambler": "赌徒",
|
||||
"gambler_desc": "从提供的列表中选择一个技能。",
|
||||
"gambler_select_info": "选择你的技能:",
|
||||
"gambler_more": "<font class='fontSize-m' color='#00FF00'>刷新 $100</font>",
|
||||
"gambler_more": "#00FF00|刷新 ${0}",
|
||||
|
||||
"ghost": "幽灵",
|
||||
"ghost_desc": "你完全隐形",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue