New slider Range parameter. Palette modifications. Potential crash fix. Clamp function.
Range parameter added to slider. Supports returning a range of values rather than just 0-1. Allows you to not have to post process the offset. Modified palette selector to not have full range, which was causing blown out units. Introduced exension method Clamp<T>(min, max) Fixed crash deserializing out of bound color value using above extension.
This commit is contained in:
committed by
Paul Chote
parent
06b20c8ba5
commit
7bdf6a953f
10
OpenRA.FileFormats/Exts.cs
Normal file → Executable file
10
OpenRA.FileFormats/Exts.cs
Normal file → Executable file
@@ -85,5 +85,15 @@ namespace OpenRA
|
||||
{
|
||||
return (T[])mi.GetCustomAttributes( typeof( T ), true );
|
||||
}
|
||||
|
||||
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
|
||||
{
|
||||
if (val.CompareTo(min) < 0)
|
||||
return min;
|
||||
else if (val.CompareTo(max) > 0)
|
||||
return max;
|
||||
else
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
OpenRA.FileFormats/FieldLoader.cs
Normal file → Executable file
9
OpenRA.FileFormats/FieldLoader.cs
Normal file → Executable file
@@ -112,9 +112,9 @@ namespace OpenRA.FileFormats
|
||||
{
|
||||
var parts = x.Split(',');
|
||||
if (parts.Length == 3)
|
||||
return Color.FromArgb(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]));
|
||||
return Color.FromArgb(int.Parse(parts[0]).Clamp(0, 255), int.Parse(parts[1]).Clamp(0, 255), int.Parse(parts[2]).Clamp(0, 255));
|
||||
if (parts.Length == 4)
|
||||
return Color.FromArgb(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3]));
|
||||
return Color.FromArgb(int.Parse(parts[0]).Clamp(0, 255), int.Parse(parts[1]).Clamp(0, 255), int.Parse(parts[2]).Clamp(0, 255), int.Parse(parts[3]).Clamp(0, 255));
|
||||
return InvalidValueAction(x,fieldType, field);
|
||||
}
|
||||
|
||||
@@ -264,7 +264,10 @@ namespace OpenRA.FileFormats
|
||||
if (f.FieldType == typeof(Color))
|
||||
{
|
||||
var c = (Color)v;
|
||||
return "{0},{1},{2},{3}".F(c.A,c.R,c.G,c.B);
|
||||
return "{0},{1},{2},{3}".F(((int)c.A).Clamp(0, 255),
|
||||
((int)c.R).Clamp(0, 255),
|
||||
((int)c.G).Clamp(0, 255),
|
||||
((int)c.B).Clamp(0, 255));
|
||||
}
|
||||
|
||||
return f.FieldType.IsArray
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
|
||||
10
OpenRA.Game/Exts.cs
Normal file → Executable file
10
OpenRA.Game/Exts.cs
Normal file → Executable file
@@ -67,5 +67,15 @@ namespace OpenRA
|
||||
Log.Write("perf", text, x, dt * 1000, Game.LocalTick);
|
||||
});
|
||||
}
|
||||
|
||||
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
|
||||
{
|
||||
if (val.CompareTo(min) < 0)
|
||||
return min;
|
||||
else if (val.CompareTo(max) > 0)
|
||||
return max;
|
||||
else
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
OpenRA.Game/Server/Exts.cs
Normal file → Executable file
11
OpenRA.Game/Server/Exts.cs
Normal file → Executable file
@@ -11,6 +11,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
namespace OpenRA.Server
|
||||
{
|
||||
@@ -32,5 +33,15 @@ namespace OpenRA.Server
|
||||
{
|
||||
return ts.Except( new[] { t } );
|
||||
}
|
||||
|
||||
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
|
||||
{
|
||||
if (val.CompareTo(min) < 0)
|
||||
return min;
|
||||
else if (val.CompareTo(max) > 0)
|
||||
return max;
|
||||
else
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
8
OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs
Normal file → Executable file
8
OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs
Normal file → Executable file
@@ -317,16 +317,16 @@ namespace OpenRA.Widgets.Delegates
|
||||
{
|
||||
var colorChooser = Widget.RootWidget.GetWidget("SERVER_LOBBY").GetWidget("COLOR_CHOOSER");
|
||||
var hueSlider = colorChooser.GetWidget<SliderWidget>("HUE_SLIDER");
|
||||
hueSlider.Offset = Game.LocalClient.Color1.GetHue()/360f;
|
||||
hueSlider.SetOffset(Game.LocalClient.Color1.GetHue()/360f);
|
||||
|
||||
var satSlider = colorChooser.GetWidget<SliderWidget>("SAT_SLIDER");
|
||||
satSlider.Offset = Game.LocalClient.Color1.GetSaturation();
|
||||
satSlider.SetOffset(Game.LocalClient.Color1.GetSaturation());
|
||||
|
||||
var lumSlider = colorChooser.GetWidget<SliderWidget>("LUM_SLIDER");
|
||||
lumSlider.Offset = Game.LocalClient.Color1.GetBrightness();
|
||||
lumSlider.SetOffset(Game.LocalClient.Color1.GetBrightness());
|
||||
|
||||
var rangeSlider = colorChooser.GetWidget<SliderWidget>("RANGE_SLIDER");
|
||||
rangeSlider.Offset = Game.LocalClient.Color1.GetBrightness() == 0 ? 0 : Game.LocalClient.Color2.GetBrightness()/Game.LocalClient.Color1.GetBrightness();
|
||||
rangeSlider.SetOffset(Game.LocalClient.Color1.GetBrightness() == 0 ? 0 : Game.LocalClient.Color2.GetBrightness()/Game.LocalClient.Color1.GetBrightness());
|
||||
|
||||
UpdateColorPreview(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset());
|
||||
colorChooser.IsVisible = () => true;
|
||||
|
||||
30
OpenRA.Game/Widgets/SliderWidget.cs
Normal file → Executable file
30
OpenRA.Game/Widgets/SliderWidget.cs
Normal file → Executable file
@@ -17,9 +17,11 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
public event Action<float> OnChange;
|
||||
public Func<float> GetOffset;
|
||||
public float Offset = 0;
|
||||
public int Ticks = 0;
|
||||
public int TrackHeight = 5;
|
||||
public float2 Range = new float2(0f, 1f);
|
||||
|
||||
private float Offset = 0;
|
||||
|
||||
int2 lastMouseLocation;
|
||||
bool isMoving = false;
|
||||
@@ -27,7 +29,14 @@ namespace OpenRA.Widgets
|
||||
public SliderWidget()
|
||||
: base()
|
||||
{
|
||||
GetOffset = () => Offset;
|
||||
GetOffset = () =>
|
||||
{
|
||||
var Big = Math.Max(Range.X, Range.Y);
|
||||
var Little = Math.Min(Range.X, Range.Y);
|
||||
var Spread = Big - Little;
|
||||
|
||||
return Spread * Offset + Little;
|
||||
};
|
||||
OnChange = x => Offset = x;
|
||||
}
|
||||
|
||||
@@ -43,6 +52,15 @@ namespace OpenRA.Widgets
|
||||
isMoving = other.isMoving;
|
||||
}
|
||||
|
||||
public void SetOffset(float newOffset)
|
||||
{
|
||||
var Big = Math.Max(Range.X, Range.Y);
|
||||
var Little = Math.Min(Range.X, Range.Y);
|
||||
var Spread = Big - Little;
|
||||
|
||||
Offset = (newOffset - Little) / Spread;
|
||||
}
|
||||
|
||||
public override bool HandleInputInner(MouseInput mi)
|
||||
{
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||
@@ -72,7 +90,7 @@ namespace OpenRA.Widgets
|
||||
}
|
||||
else if (Ticks != 0)
|
||||
{
|
||||
var pos = GetOffset();
|
||||
var pos = Offset;
|
||||
|
||||
// Offset slightly the direction we want to move so we don't get stuck on a tick
|
||||
var delta = 0.001;
|
||||
@@ -92,7 +110,7 @@ namespace OpenRA.Widgets
|
||||
var thumb = thumbRect;
|
||||
var center = thumb.X + thumb.Width / 2;
|
||||
var newOffset = OffsetBy((mi.Location.X - center) * 1f / (RenderBounds.Width - thumb.Width));
|
||||
if (newOffset != GetOffset())
|
||||
if (newOffset != Offset)
|
||||
{
|
||||
OnChange(newOffset);
|
||||
|
||||
@@ -127,7 +145,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
float OffsetBy(float amount)
|
||||
{
|
||||
var centerPos = GetOffset() + amount;
|
||||
var centerPos = Offset + amount;
|
||||
if (centerPos < 0) centerPos = 0;
|
||||
if (centerPos > 1) centerPos = 1;
|
||||
return centerPos;
|
||||
@@ -141,7 +159,7 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
var width = RenderBounds.Height;
|
||||
var height = RenderBounds.Height;
|
||||
var origin = (int)((RenderBounds.X + width / 2) + GetOffset() * (RenderBounds.Width - width) - width / 2f);
|
||||
var origin = (int)((RenderBounds.X + width / 2) + Offset * (RenderBounds.Width - width) - width / 2f);
|
||||
return new Rectangle(origin, RenderBounds.Y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,10 +370,12 @@ Background@SERVER_LOBBY:
|
||||
Slider@LUM:
|
||||
Id:LUM_SLIDER
|
||||
X:120
|
||||
Id:LUM_SLIDER
|
||||
Y:90
|
||||
Width:260
|
||||
Height:20
|
||||
Ticks:5
|
||||
Range:0.2,1
|
||||
Label@RANGE_LABEL:
|
||||
X:0
|
||||
Y:120
|
||||
@@ -388,6 +390,7 @@ Background@SERVER_LOBBY:
|
||||
Width:260
|
||||
Height:20
|
||||
Ticks:5
|
||||
Range:0,0.25
|
||||
Background@MAP_CHOOSER:
|
||||
Id:MAP_CHOOSER
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
|
||||
@@ -371,10 +371,12 @@ Background@SERVER_LOBBY:
|
||||
Slider@LUM:
|
||||
Id:LUM_SLIDER
|
||||
X:120
|
||||
Id:LUM_SLIDER
|
||||
Y:90
|
||||
Width:260
|
||||
Height:20
|
||||
Ticks:5
|
||||
Range:0.2,1
|
||||
Label@RANGE_LABEL:
|
||||
X:0
|
||||
Y:120
|
||||
@@ -389,6 +391,7 @@ Background@SERVER_LOBBY:
|
||||
Width:260
|
||||
Height:20
|
||||
Ticks:5
|
||||
Range:0,0.25
|
||||
Background@MAP_CHOOSER:
|
||||
Id:MAP_CHOOSER
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
|
||||
Reference in New Issue
Block a user