Browse Source

Merge pull request #31068 from neikeq/issue-31065

C#: Fix Color.ToHtml()
Ignacio Roldán Etcheverry 6 năm trước cách đây
mục cha
commit
7126654eaf
1 tập tin đã thay đổi với 16 bổ sung11 xóa
  1. 16 11
      modules/mono/glue/Managed/Files/Color.cs

+ 16 - 11
modules/mono/glue/Managed/Files/Color.cs

@@ -375,7 +375,7 @@ namespace Godot
             return c;
         }
 
-        public string ToHtml(bool include_alpha = true)
+        public string ToHtml(bool includeAlpha = true)
         {
             var txt = string.Empty;
 
@@ -383,7 +383,7 @@ namespace Godot
             txt += ToHex32(g);
             txt += ToHex32(b);
 
-            if (include_alpha)
+            if (includeAlpha)
                 txt = ToHex32(a) + txt;
 
             return txt;
@@ -465,13 +465,13 @@ namespace Godot
 
             for (int i = 0; i < 2; i++)
             {
-                char[] c = { (char)0, (char)0 };
+                char c;
                 int lv = v & 0xF;
 
                 if (lv < 10)
-                    c[0] = (char)('0' + lv);
+                    c = (char)('0' + lv);
                 else
-                    c[0] = (char)('a' + lv - 10);
+                    c = (char)('a' + lv - 10);
 
                 v >>= 4;
                 ret = c + ret;
@@ -490,12 +490,17 @@ namespace Godot
 
             bool alpha;
 
-            if (color.Length == 8)
-                alpha = true;
-            else if (color.Length == 6)
-                alpha = false;
-            else
-                return false;
+            switch (color.Length)
+            {
+                case 8:
+                    alpha = true;
+                    break;
+                case 6:
+                    alpha = false;
+                    break;
+                default:
+                    return false;
+            }
 
             if (alpha)
             {