Skip to content

Commit

Permalink
Only use uppercase forms for system-defined colour codes. This allows…
Browse files Browse the repository at this point in the history
… users to use their lowercase forms in /ccols.
  • Loading branch information
UnknownShadow200 committed May 20, 2017
1 parent cc8003d commit e5bfd94
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 35 deletions.
2 changes: 1 addition & 1 deletion ConfigGUI/ChatPreview.cs
Expand Up @@ -81,7 +81,7 @@ sealed class TextSegment {
if( plainTextSegments[j].Length == 0 ) continue;
if( plainTextSegments[j][0] == '&' ) {
colorCode = plainTextSegments[j][1];
// Conver system color codes into actual color codes
// Convert system color codes into actual color codes
string converted = Color.Parse( colorCode );
if( converted != null ) colorCode = converted[1];
} else {
Expand Down
10 changes: 6 additions & 4 deletions ConfigGUI/ColorPicker.cs
Expand Up @@ -54,10 +54,12 @@ internal struct ColorPair {
SuspendLayout();
for( char code = '0'; code <= '9'; code++ )
MakeButton(code);
for ( char code = 'a'; code <= 'f'; code++ )
for( char code = 'a'; code <= 'f'; code++ )
MakeButton(code);
for (int i = 0; i < Color.ExtColors.Length; i++) {
if (!Color.ExtColors[i].Undefined) MakeButton(Color.ExtColors[i].Code);

for( int i = 0; i < Color.ExtColors.Length; i++ ) {
if( Color.ExtColors[i].Undefined ) continue;
MakeButton(Color.ExtColors[i].Code);
}
MakeCancelButton();
MakeWindow( title );
Expand Down Expand Up @@ -98,7 +100,7 @@ internal struct ColorPair {
if ((rows & 1) == 0) {
x = (rows * btnWidth) / 2 - (100 / 2);
} else {
x = ((rows / 2) * btnWidth) + (btnWidth - 100) / 2;
x = ((rows / 2) * btnWidth) + (btnWidth - 100) / 2;
}

bCancel.Location = new System.Drawing.Point( 8 + x, 10 + btnHeight * btnsPerCol );
Expand Down
4 changes: 0 additions & 4 deletions fCraft/Commands/CpeCommands.cs
Expand Up @@ -651,10 +651,6 @@ static class CpeCommands {
static void RemoveCustomColorsHandler(Player p, CommandReader cmd) {
string fullCode = cmd.Next();
if (fullCode == null) { p.Message("Usage: &H/ccols remove [code]"); return; }
if (fullCode.Contains("\"")) {
p.Message("Color code cannot be \"");
return;
}
if (!p.Can(Permission.DefineCustomBlocks)) {
p.MessageNoAccess(Permission.DefineCustomBlocks);
return;
Expand Down
50 changes: 24 additions & 26 deletions fCraft/System/Utils/Color.cs
Expand Up @@ -143,16 +143,16 @@ public static class Color
}

internal static char ConvertNonStandard(char code) {
switch (Char.ToLower(code)) {
case 's': return Sys[1];
case 'y': return Say[1];
case 'p': return PM[1];
case 'r': return Announcement[1];
case 'h': return Help[1];
case 'w': return Warning[1];
case 'm': return Me[1];
case 'i': return IRC[1];
case 't': return White[1];
switch (code) {
case 'S': return Sys[1];
case 'Y': return Say[1];
case 'P': return PM[1];
case 'R': return Announcement[1];
case 'H': return Help[1];
case 'W': return Warning[1];
case 'M': return Me[1];
case 'I': return IRC[1];
case 'T': return White[1];
default:
char fallback = GetFallback(code);
return fallback == '\0' ? '\0' : code;
Expand Down Expand Up @@ -199,12 +199,10 @@ public static class Color
[Pure]
public static bool IsColorCode(char code) {
return (code >= '0' && code <= '9') || (code >= 'a' && code <= 'f') ||
(code >= 'A' && code <= 'F') || code == 'H' || code == 'h' ||
code == 'I' || code == 'i' || code == 'M' || code == 'm' ||
code == 'N' || code == 'n' || code == 'P' || code == 'p' ||
code == 'R' || code == 'r' || code == 'S' || code == 's' ||
code == 'T' || code == 't' || code == 'W' || code == 'w' ||
code == 'Y' || code == 'y' || GetFallback(code) != '\0';
(code >= 'A' && code <= 'F') || code == 'H' || code == 'I' ||
code == 'M' || code == 'N' || code == 'P' || code == 'R' ||
code == 'S' || code == 'T' || code == 'W' || code == 'Y' ||
GetFallback(code) != '\0';
}


Expand All @@ -221,16 +219,16 @@ public static class Color
for (int i = sb.Length - 1; i > 0; i--) {
if (sb[i - 1] != '&') continue;

switch (Char.ToLower(sb[i])) {
case 's': sb[i] = Sys[1]; break;
case 'y': sb[i] = Say[1]; break;
case 'p': sb[i] = PM[1]; break;
case 'r': sb[i] = Announcement[1]; break;
case 'h': sb[i] = Help[1]; break;
case 'w': sb[i] = Warning[1]; break;
case 'm': sb[i] = Me[1]; break;
case 'i': sb[i] = IRC[1]; break;
case 't': sb[i] = White[1]; break;
switch (sb[i]) {
case 'S': sb[i] = Sys[1]; break;
case 'Y': sb[i] = Say[1]; break;
case 'P': sb[i] = PM[1]; break;
case 'R': sb[i] = Announcement[1]; break;
case 'H': sb[i] = Help[1]; break;
case 'W': sb[i] = Warning[1]; break;
case 'M': sb[i] = Me[1]; break;
case 'I': sb[i] = IRC[1]; break;
case 'T': sb[i] = White[1]; break;
}

char fallback = GetFallback(sb[i]);
Expand Down

0 comments on commit e5bfd94

Please sign in to comment.