(3dc4135ce) v0.9.5.1
This commit is contained in:
@@ -260,6 +260,42 @@ namespace Barotrauma
|
||||
return val;
|
||||
}
|
||||
|
||||
public static UInt64 GetAttributeUInt64(this XElement element, string name, UInt64 defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
|
||||
UInt64 val = defaultValue;
|
||||
|
||||
try
|
||||
{
|
||||
val = UInt64.Parse(element.Attribute(name).Value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in " + element + "! ", e);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public static UInt64 GetAttributeSteamID(this XElement element, string name, UInt64 defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
|
||||
UInt64 val = defaultValue;
|
||||
|
||||
try
|
||||
{
|
||||
val = Steam.SteamManager.SteamIDStringToUInt64(element.Attribute(name).Value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in " + element + "! ", e);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public static int[] GetAttributeIntArray(this XElement element, string name, int[] defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
@@ -497,27 +533,54 @@ namespace Barotrauma
|
||||
|
||||
Color color = Color.White;
|
||||
|
||||
if (strComponents.Length < 3)
|
||||
{
|
||||
if (errorMessages) DebugConsole.ThrowError("Failed to parse the string \"" + stringColor + "\" to Color");
|
||||
return Color.White;
|
||||
}
|
||||
|
||||
float[] components = new float[4] { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
|
||||
for (int i = 0; i < 4 && i < strComponents.Length; i++)
|
||||
{
|
||||
float.TryParse(strComponents[i], NumberStyles.Float, CultureInfo.InvariantCulture, out components[i]);
|
||||
}
|
||||
|
||||
if (components.Any(c => c > 1.0f))
|
||||
if (strComponents.Length == 1)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
bool hexFailed = true;
|
||||
stringColor = stringColor.Trim();
|
||||
if (stringColor[0]=='#')
|
||||
{
|
||||
components[i] = components[i] / 255.0f;
|
||||
stringColor = stringColor.Substring(1);
|
||||
|
||||
int colorInt = 0;
|
||||
if (int.TryParse(stringColor, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out colorInt))
|
||||
{
|
||||
if (stringColor.Length == 6)
|
||||
{
|
||||
colorInt = (colorInt << 8) | 0xff;
|
||||
}
|
||||
components[0] = ((float)((colorInt & 0xff000000) >> 24)) / 255.0f;
|
||||
components[1] = ((float)((colorInt & 0x00ff0000) >> 16)) / 255.0f;
|
||||
components[2] = ((float)((colorInt & 0x0000ff00) >> 8)) / 255.0f;
|
||||
components[3] = ((float)(colorInt & 0x000000ff)) / 255.0f;
|
||||
|
||||
hexFailed = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (hexFailed)
|
||||
{
|
||||
if (errorMessages) DebugConsole.ThrowError("Failed to parse the string \"" + stringColor + "\" to Color");
|
||||
return Color.White;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 4 && i < strComponents.Length; i++)
|
||||
{
|
||||
float.TryParse(strComponents[i], NumberStyles.Float, CultureInfo.InvariantCulture, out components[i]);
|
||||
}
|
||||
|
||||
if (components.Any(c => c > 1.0f))
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
components[i] = components[i] / 255.0f;
|
||||
}
|
||||
//alpha defaults to 1.0 if not given
|
||||
if (strComponents.Length < 4) components[3] = 1.0f;
|
||||
}
|
||||
//alpha defaults to 255 if not given
|
||||
if (strComponents.Length < 4) components[3] = 255;
|
||||
}
|
||||
|
||||
return new Color(components[0], components[1], components[2], components[3]);
|
||||
|
||||
Reference in New Issue
Block a user