Skip to content

Commit 3ca82a0

Browse files
feat: add extended help message
also format other messages nicely
1 parent 281f71d commit 3ca82a0

File tree

2 files changed

+203
-29
lines changed

2 files changed

+203
-29
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ The core commands are also avalibale in a guest code version. e.g.
3131
### Other Commands
3232

3333
- `code quiet` - Toggle quiet mode. In this mode less messages will be displayed and your auto-code will be hidden.
34+
- `code help` - Shows a detailed help message.
3435

3536
## Console Commands
3637

src/AutoCode.cs

+202-29
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System;
88
using System.Collections.Generic;
99
using System.Globalization;
10+
using System.Linq;
1011
using UnityEngine;
1112

1213
namespace Oxide.Plugins
@@ -166,7 +167,8 @@ protected override void LoadDefaultMessages()
166167
lang.RegisterMessages(new Dictionary<string, string>
167168
{
168169
{ "Help", "Usage:\n{0}" },
169-
{ "Description", "Automatically set the code on code locks you place.\n\nCode: {0}\nGuest Code: {1}\nQuiet Mode: {2}" },
170+
{ "Description", "Automatically set the code on code locks you place." },
171+
{ "Info", "Code: {0}\nGuest Code: {1}\nQuiet Mode: {2}" },
170172
{ "NoPermission", "You don't have permission." },
171173
{ "CodeAutoLocked", "Code lock placed with code {0}." },
172174
{ "CodeAutoLockedWithGuest", "Code lock placed with code {0} and guest code {1}." },
@@ -185,10 +187,21 @@ protected override void LoadDefaultMessages()
185187
{ "ErrorMoreThanOnePlayerFound", "Error: More than one player found." },
186188
{ "ResettingAllLockOuts", "Resetting lock outs for all players." },
187189
{ "ResettingLockOut", "Resetting lock outs for {0}." },
188-
{ "QuietModeEnable", "Quiet mode now enabled.\nLess messages will be shown and your auto-code will be hidden." },
190+
{ "QuietModeEnable", "Quiet mode now enabled." },
189191
{ "QuietModeDisable", "Quiet mode now disabled." },
190192
{ "Enabled", "Enabled" },
191-
{ "Disabled", "Disabled" }
193+
{ "Disabled", "Disabled" },
194+
{ "HelpExtendedCoreCommands", "Core Commands:" },
195+
{ "HelpExtendedOtherCommands", "Other Commands:" },
196+
{ "HelpExtendedInfo", "Show your settings:\n{0}" },
197+
{ "HelpExtendedSetCode", "Set your auto-code to 1234:\n{0}" },
198+
{ "HelpExtendedPickCode", "Open the code lock interface to set your auto-code:\n{0}" },
199+
{ "HelpExtendedRandomCode", "Set your auto-code to a randomly generated code:\n{0}" },
200+
{ "HelpExtendedRemoveCode", "Remove your set auto-code:\n{0}" },
201+
{ "HelpExtendedCoreGuestCommands", "Each core command is also avalibale in a guest code version. e.g.\n{0}" },
202+
{ "HelpExtendedQuietMode", "Toggles on/off quiet mode:\n{0}" },
203+
{ "HelpExtendedQuietModeDetails", "Less messages will be shown and your auto-code will be hidden." },
204+
{ "HelpExtendedHelp", "Displays this help message:\n{0}" },
192205
}, this);
193206
}
194207

@@ -314,7 +327,7 @@ public void SetCode(BasePlayer player, string code, bool guest = false, bool qui
314327
? lang.GetMessage(guest ? "GuestCodeUpdatedHidden" : "CodeUpdatedHidden", this, player.UserIDString)
315328
: string.Format(
316329
lang.GetMessage(guest ? "GuestCodeUpdated" : "CodeUpdated", this, player.UserIDString),
317-
code
330+
Formatter.Value(code)
318331
)
319332
);
320333
}
@@ -465,10 +478,24 @@ public void ToggleQuietMode(BasePlayer player, bool quiet = false)
465478

466479
if (!quiet)
467480
{
468-
Message(
469-
player,
470-
lang.GetMessage(settings.quietMode ? "QuietModeEnable" : "QuietModeDisable", this, player.UserIDString)
471-
);
481+
if (settings.quietMode)
482+
{
483+
Message(
484+
player,
485+
string.Format(
486+
"{0}\n" + Formatter.SmallLineGap + "{1}",
487+
lang.GetMessage("QuietModeEnable", this, player.UserIDString),
488+
lang.GetMessage("HelpExtendedQuietModeDetails", this, player.UserIDString)
489+
)
490+
);
491+
}
492+
else
493+
{
494+
Message(
495+
player,
496+
lang.GetMessage("QuietModeDisable", this, player.UserIDString)
497+
);
498+
}
472499
}
473500
}
474501

@@ -820,6 +847,7 @@ private class Commands
820847
public string RemoveCode = "remove";
821848
public string SetCode = "set";
822849
public string QuietMode = "quiet";
850+
public string Help = "help";
823851

824852
public Commands(AutoCode plugin)
825853
{
@@ -975,6 +1003,13 @@ private void HandleUse(BasePlayer player, string label, string[] args)
9751003
argsRemainingCount--;
9761004
}
9771005

1006+
// Help.
1007+
if (operation == Help)
1008+
{
1009+
plugin.Message(player, GetHelpExtended(player, label));
1010+
return;
1011+
}
1012+
9781013
// Pick code.
9791014
if (operation == PickCode)
9801015
{
@@ -1096,12 +1131,13 @@ private void ShowInfo(BasePlayer player, string label, string[] args)
10961131
plugin.Message(
10971132
player,
10981133
string.Format(
1099-
"{0}\n\n{1}",
1134+
"{0}\n" + Formatter.SmallLineGap + "{1}\n" + Formatter.SmallLineGap + "{2}",
1135+
Formatter.H2(plugin.lang.GetMessage("Description", plugin, player.UserIDString)),
11001136
string.Format(
1101-
plugin.lang.GetMessage("Description", plugin, player.UserIDString),
1102-
code ?? plugin.lang.GetMessage("NotSet", plugin, player.UserIDString),
1103-
guestCode ?? plugin.lang.GetMessage("NotSet", plugin, player.UserIDString),
1104-
plugin.lang.GetMessage(quietMode ? "Enabled" : "Disabled", plugin, player.UserIDString)
1137+
plugin.lang.GetMessage("Info", plugin, player.UserIDString),
1138+
code != null ? Formatter.Value(code) : Formatter.NoValue(plugin.lang.GetMessage("NotSet", plugin, player.UserIDString)),
1139+
guestCode != null ? Formatter.Value(guestCode) : Formatter.NoValue(plugin.lang.GetMessage("NotSet", plugin, player.UserIDString)),
1140+
quietMode ? Formatter.Value(plugin.lang.GetMessage("Enabled", plugin, player.UserIDString)) : Formatter.NoValue(plugin.lang.GetMessage("Disabled", plugin, player.UserIDString))
11051141
),
11061142
GetHelp(player, label)
11071143
)
@@ -1138,27 +1174,87 @@ public string GetHelp(BasePlayer player, string label)
11381174
/// </summary>
11391175
/// <returns></returns>
11401176
private string GetUsage(string label)
1177+
{
1178+
return Formatter.Command(
1179+
string.Format(
1180+
"{0} [<{1}>]",
1181+
label,
1182+
string.Join("|", new string[] {
1183+
string.Format(
1184+
"[{0}] <{1}>",
1185+
Guest,
1186+
string.Join("|", new string[] {
1187+
string.Format(
1188+
"[{0}] {1}",
1189+
SetCode,
1190+
"1234"
1191+
),
1192+
PickCode,
1193+
RandomCode,
1194+
RemoveCode
1195+
})
1196+
),
1197+
QuietMode,
1198+
Help
1199+
})
1200+
)
1201+
);
1202+
}
1203+
1204+
/// <summary>
1205+
/// Display an extended help messsage to the player.
1206+
/// </summary>
1207+
public string GetHelpExtended(BasePlayer player, string label)
11411208
{
11421209
return string.Format(
1143-
"{0} <{1}>",
1144-
label,
1145-
string.Join("|", new string[] {
1146-
string.Format(
1147-
"[{0}] <{1}>",
1148-
Guest,
1149-
string.Join("|", new string[] {
1210+
"{0}",
1211+
string.Join(
1212+
"\n" + Formatter.SmallLineGap,
1213+
string.Join(
1214+
"\n" + Formatter.SmallLineGap,
1215+
Formatter.H2(plugin.lang.GetMessage("HelpExtendedCoreCommands", plugin, player.UserIDString)),
1216+
Formatter.UL(
1217+
string.Format(
1218+
plugin.lang.GetMessage("HelpExtendedInfo", plugin, player.UserIDString),
1219+
Formatter.Indent(Formatter.Command(string.Format("{0}", label)))
1220+
),
11501221
string.Format(
1151-
"[{0}] {1}",
1152-
SetCode,
1153-
"1234"
1222+
plugin.lang.GetMessage("HelpExtendedSetCode", plugin, player.UserIDString),
1223+
Formatter.Indent(Formatter.Command(string.Format("{0} {1}", label, "1234")))
11541224
),
1155-
PickCode,
1156-
RandomCode,
1157-
RemoveCode
1158-
})
1225+
string.Format(
1226+
plugin.lang.GetMessage("HelpExtendedPickCode", plugin, player.UserIDString),
1227+
Formatter.Indent(Formatter.Command(string.Format("{0} {1}", label, PickCode)))
1228+
),
1229+
string.Format(
1230+
plugin.lang.GetMessage("HelpExtendedRandomCode", plugin, player.UserIDString),
1231+
Formatter.Indent(Formatter.Command(string.Format("{0} {1}", label, RandomCode)))
1232+
),
1233+
string.Format(
1234+
plugin.lang.GetMessage("HelpExtendedRemoveCode", plugin, player.UserIDString),
1235+
Formatter.Indent(Formatter.Command(string.Format("{0} {1}", label, RemoveCode)))
1236+
)
1237+
),
1238+
string.Format(
1239+
plugin.lang.GetMessage("HelpExtendedCoreGuestCommands", plugin, player.UserIDString),
1240+
Formatter.Indent(Formatter.Command(string.Format("{0} {1} {2}", label, Guest, "5678")))
1241+
)
11591242
),
1160-
QuietMode
1161-
})
1243+
string.Join(
1244+
"\n" + Formatter.SmallLineGap,
1245+
Formatter.H2(plugin.lang.GetMessage("HelpExtendedOtherCommands", plugin, player.UserIDString)),
1246+
Formatter.UL(
1247+
string.Format(
1248+
plugin.lang.GetMessage("HelpExtendedQuietMode", plugin, player.UserIDString),
1249+
Formatter.Indent(Formatter.Command(string.Format("{0} {1}", label, QuietMode)))
1250+
),
1251+
string.Format(
1252+
plugin.lang.GetMessage("HelpExtendedHelp", plugin, player.UserIDString),
1253+
Formatter.Indent(Formatter.Command(string.Format("{0} {1}", label, Help)))
1254+
)
1255+
)
1256+
)
1257+
)
11621258
);
11631259
}
11641260
}
@@ -1183,6 +1279,83 @@ public static bool ShouldHideCode(BasePlayer player, Data.Structure.PlayerSettin
11831279
}
11841280
}
11851281

1282+
/// <summary>
1283+
/// Text formatting functions for in-game chat.
1284+
/// </summary>
1285+
private static class Formatter
1286+
{
1287+
/// <summary>
1288+
/// A line break in a very small font.
1289+
/// </summary>
1290+
public const string SmallestLineGap = "<size=6>\n</size>";
1291+
1292+
/// <summary>
1293+
/// A line break in a small font.
1294+
/// </summary>
1295+
public const string SmallLineGap = "<size=9>\n</size>";
1296+
1297+
/// <summary>
1298+
/// Format the given text as a header level 1.
1299+
/// </summary>
1300+
public static string H1(string text)
1301+
{
1302+
return string.Format("<size=20>{0}</size>", text);
1303+
}
1304+
1305+
/// <summary>
1306+
/// Format the given text as a header level 2.
1307+
/// </summary>
1308+
public static string H2(string text)
1309+
{
1310+
return string.Format("<size=16>{0}</size>", text);
1311+
}
1312+
1313+
/// <summary>
1314+
/// Small text.
1315+
/// </summary>
1316+
public static string Small(string text)
1317+
{
1318+
return string.Format("<size=12>{0}</size>", text);
1319+
}
1320+
1321+
/// <summary>
1322+
/// Format the items as an unordered list.
1323+
/// </summary>
1324+
public static string UL(params string[] items)
1325+
{
1326+
return string.Join(
1327+
"\n" + SmallestLineGap,
1328+
items.Select(item => string.Format(" - {0}", item))
1329+
);
1330+
}
1331+
1332+
/// <summary>
1333+
/// Indent the given text.
1334+
/// </summary>
1335+
public static string Indent(string text)
1336+
{
1337+
return string.Format(" {0}", text);
1338+
}
1339+
1340+
/// <summary>
1341+
/// Format the given text as a command.
1342+
/// </summary>
1343+
public static string Command(string text)
1344+
{
1345+
return string.Format("<color=#e0e0e0>{0}</color>", text);
1346+
}
1347+
1348+
public static string Value(string text)
1349+
{
1350+
return string.Format("<color=#bfff75>{0}</color>", text);
1351+
}
1352+
1353+
public static string NoValue(string text)
1354+
{
1355+
return string.Format("<color=#ff7771>{0}</color>", text);
1356+
}
1357+
}
1358+
11861359
/// <summary>
11871360
/// The data stored for temp code locks.
11881361
/// </summary>

0 commit comments

Comments
 (0)