Fix StyleCop warnings in OpenRA.Game

This commit is contained in:
Hellhake
2015-01-01 23:04:18 +01:00
parent e9989496c4
commit 5a97a4b63b
119 changed files with 547 additions and 529 deletions

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Widgets
if (ClickThrough || !RenderBounds.Contains(mi.Location))
return false;
if (!Draggable || moving && (!TakeMouseFocus(mi) || mi.Button != MouseButton.Left))
if (!Draggable || (moving && (!TakeMouseFocus(mi) || mi.Button != MouseButton.Left)))
return true;
if (prevMouseLocation == null)

View File

@@ -15,7 +15,10 @@ namespace OpenRA.Widgets
{
public class ButtonWidget : Widget
{
public readonly string TooltipContainer;
public readonly string TooltipTemplate = "BUTTON_TOOLTIP";
public Func<ButtonWidget, Hotkey> GetKey = _ => Hotkey.Invalid;
public Hotkey Key
{
get { return GetKey(this); }
@@ -40,19 +43,17 @@ namespace OpenRA.Widgets
public Func<Color> GetContrastColor;
public Func<bool> IsDisabled;
public Func<bool> IsHighlighted;
public Action<MouseInput> OnMouseDown = _ => {};
public Action<MouseInput> OnMouseUp = _ => {};
public Action<MouseInput> OnMouseDown = _ => { };
public Action<MouseInput> OnMouseUp = _ => { };
Lazy<TooltipContainerWidget> tooltipContainer;
public readonly string TooltipContainer;
public readonly string TooltipTemplate = "BUTTON_TOOLTIP";
[Translate] public string TooltipText;
public Func<string> GetTooltipText;
// Equivalent to OnMouseUp, but without an input arg
public Action OnClick = () => {};
public Action OnDoubleClick = () => {};
public Action<KeyInput> OnKeyPress = _ => {};
public Action OnClick = () => { };
public Action OnDoubleClick = () => { };
public Action<KeyInput> OnKeyPress = _ => { };
protected readonly Ruleset ModRules;
@@ -149,14 +150,15 @@ namespace OpenRA.Widgets
return YieldMouseFocus(mi);
}
}
// Only fire the onMouseUp event if we successfully lost focus, and were pressed
else if (HasMouseFocus && mi.Event == MouseInputEvent.Up)
{
// Only fire the onMouseUp event if we successfully lost focus, and were pressed
if (Depressed && !disabled)
OnMouseUp(mi);
return YieldMouseFocus(mi);
}
if (mi.Event == MouseInputEvent.Down)
{
// OnMouseDown returns false if the button shouldn't be pressed
@@ -210,7 +212,7 @@ namespace OpenRA.Widgets
var colordisabled = GetColorDisabled();
var contrast = GetContrastColor();
var s = font.Measure(text);
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
var stateOffset = Depressed ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
var position = new int2(rb.X + (UsableWidth - s.X) / 2, rb.Y - BaseLine + (Bounds.Height - s.Y) / 2);
DrawBackground(rb, disabled, Depressed, Ui.MouseOverWidget == this, highlighted);

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Widgets
"checkbox";
WidgetUtils.DrawPanel(state, check);
var position = new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y)/2);
var position = new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y) / 2);
if (Contrast)
font.DrawTextWithContrast(text, position,

View File

@@ -8,7 +8,6 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
@@ -42,6 +41,7 @@ namespace OpenRA.Widgets
result = default(T);
return false;
}
result = FieldLoader.GetValue<T>(key, s);
return true;
}

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Widgets
{
if (TooltipContainer == null)
return;
tooltipContainer.Value.SetTooltip(Template, new WidgetArgs() {{"orderManager", orderManager}, {"clientIndex", clientIndex}});
tooltipContainer.Value.SetTooltip(Template, new WidgetArgs() { { "orderManager", orderManager }, { "clientIndex", clientIndex } });
}
public override void MouseExited()

View File

@@ -36,16 +36,14 @@ namespace OpenRA.Widgets
public override void Draw()
{
base.Draw();
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
var stateOffset = Depressed ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
var image = ChromeProvider.GetImage("scrollbar", IsDisabled() ? "down_pressed" : "down_arrow");
var rb = RenderBounds;
var color = GetColor();
var colorDisabled = GetColorDisabled();
WidgetUtils.DrawRGBA( image,
stateOffset + new float2( rb.Right - rb.Height + 4,
rb.Top + (rb.Height - image.bounds.Height) / 2 ));
WidgetUtils.DrawRGBA(image, stateOffset + new float2(rb.Right - rb.Height + 4, rb.Top + (rb.Height - image.bounds.Height) / 2));
WidgetUtils.FillRectWithColor(new Rectangle(stateOffset.X + rb.Right - rb.Height,
stateOffset.Y + rb.Top + 3, 1, rb.Height - 6),
@@ -102,9 +100,9 @@ namespace OpenRA.Widgets
public void ShowDropDown<T>(string panelTemplate, int maxHeight, IEnumerable<T> options, Func<T, ScrollItemWidget, ScrollItemWidget> setupItem)
{
var substitutions = new Dictionary<string,int>() {{ "DROPDOWN_WIDTH", Bounds.Width }};
var substitutions = new Dictionary<string, int>() { { "DROPDOWN_WIDTH", Bounds.Width } };
var panel = (ScrollPanelWidget)Ui.LoadWidget(panelTemplate, null, new WidgetArgs()
{{ "substitutions", substitutions }});
{ { "substitutions", substitutions } });
var itemTemplate = panel.Get<ScrollItemWidget>("TEMPLATE");
panel.RemoveChildren();
@@ -125,9 +123,9 @@ namespace OpenRA.Widgets
public void ShowDropDown<T>(string panelTemplate, int height, Dictionary<string, IEnumerable<T>> groups, Func<T, ScrollItemWidget, ScrollItemWidget> setupItem)
{
var substitutions = new Dictionary<string,int>() {{ "DROPDOWN_WIDTH", Bounds.Width }};
var substitutions = new Dictionary<string, int>() { { "DROPDOWN_WIDTH", Bounds.Width } };
var panel = (ScrollPanelWidget)Ui.LoadWidget(panelTemplate, null, new WidgetArgs()
{{ "substitutions", substitutions }});
{ { "substitutions", substitutions } });
var headerTemplate = panel.GetOrNull<ScrollItemWidget>("HEADER");
var itemTemplate = panel.Get<ScrollItemWidget>("TEMPLATE");
@@ -138,7 +136,7 @@ namespace OpenRA.Widgets
var group = kv.Key;
if (group.Length > 0 && headerTemplate != null)
{
var header = ScrollItemWidget.Setup(headerTemplate, () => true, () => {});
var header = ScrollItemWidget.Setup(headerTemplate, () => true, () => { });
header.Get<LabelWidget>("LABEL").GetText = () => group;
panel.AddChild(header);
}
@@ -154,6 +152,7 @@ namespace OpenRA.Widgets
panel.AddChild(item);
}
}
panel.Bounds.Height = Math.Min(height, panel.ContentHeight);
AttachPanel(panel);
}
@@ -161,7 +160,7 @@ namespace OpenRA.Widgets
public class MaskWidget : Widget
{
public event Action<MouseInput> OnMouseDown = _ => {};
public event Action<MouseInput> OnMouseDown = _ => { };
public MaskWidget() { }
public MaskWidget(MaskWidget other)
: base(other)
@@ -183,4 +182,4 @@ namespace OpenRA.Widgets
public override string GetCursor(int2 pos) { return null; }
public override Widget Clone() { return new MaskWidget(this); }
}
}
}

View File

@@ -44,8 +44,6 @@ namespace OpenRA.Widgets
public void AdjustChildren()
{
}
}
}
}

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Widgets
public Color TextColor = ChromeMetrics.Get<Color>("HotkeyColor");
public Color TextColorDisabled = ChromeMetrics.Get<Color>("HotkeyColorDisabled");
public HotkeyEntryWidget() {}
public HotkeyEntryWidget() { }
protected HotkeyEntryWidget(HotkeyEntryWidget widget)
: base(widget)
{
@@ -135,4 +135,4 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new HotkeyEntryWidget(this); }
}
}
}

View File

@@ -67,16 +67,16 @@ namespace OpenRA.Widgets
var position = RenderOrigin;
if (VAlign == TextVAlign.Middle)
position += new int2(0, (Bounds.Height - textSize.Y)/2);
position += new int2(0, (Bounds.Height - textSize.Y) / 2);
if (VAlign == TextVAlign.Bottom)
position += new int2(0, Bounds.Height - textSize.Y);
if (Align == TextAlign.Center)
position += new int2((Bounds.Width - textSize.X)/2, 0);
position += new int2((Bounds.Width - textSize.X) / 2, 0);
if (Align == TextAlign.Right)
position += new int2(Bounds.Width - textSize.X,0);
position += new int2(Bounds.Width - textSize.X, 0);
if (WordWrap)
text = WidgetUtils.WrapText(text, Bounds.Width, font);
@@ -91,4 +91,4 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new LabelWidget(this); }
}
}
}

View File

@@ -87,6 +87,7 @@ namespace OpenRA.Widgets
{
return;
}
var rect = RenderBounds;
var origin = new float2(rect.Left, rect.Bottom);
@@ -141,20 +142,22 @@ namespace OpenRA.Widgets
keyOffset++;
}
//TODO: make this stuff not draw outside of the RenderBounds
// TODO: make this stuff not draw outside of the RenderBounds
for (int n = pointStart, x = 0; n <= pointEnd; n++, x += xStep)
{
Game.Renderer.LineRenderer.DrawLine(origin + new float2(x, 0), origin + new float2(x, -5), Color.White, Color.White);
tiny.DrawText(GetXAxisValueFormat().F(n), origin + new float2(x, 2), Color.White);
}
bold.DrawText(GetXAxisLabel(), origin + new float2(width / 2, 20), Color.White);
for (var y = (GetDisplayFirstYAxisValue() ? 0 : yStep); y <= height; y += yStep)
for (var y = GetDisplayFirstYAxisValue() ? 0 : yStep; y <= height; y += yStep)
{
var yValue = y / scale;
Game.Renderer.LineRenderer.DrawLine(origin + new float2(width - 5, -y), origin + new float2(width, -y), Color.White, Color.White);
tiny.DrawText(GetYAxisValueFormat().F(yValue), origin + new float2(width + 2, -y), Color.White);
}
bold.DrawText(GetYAxisLabel(), origin + new float2(width + 40, -(height / 2)), Color.White);
Game.Renderer.LineRenderer.DrawLine(origin, origin + new float2(width, 0), Color.White, Color.White);

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Widgets
WidgetUtils.DrawPanel("progressbar-bg", rb);
var barRect = wasIndeterminate ?
new Rectangle(rb.X + 2 + (int)(0.75*offset*(rb.Width - 4)), rb.Y + 2, (rb.Width - 4) / 4, rb.Height - 4) :
new Rectangle(rb.X + 2 + (int)(0.75 * offset * (rb.Width - 4)), rb.Y + 2, (rb.Width - 4) / 4, rb.Height - 4) :
new Rectangle(rb.X + 2, rb.Y + 2, percentage * (rb.Width - 4) / 100, rb.Height - 4);
if (barRect.Width > 0)
@@ -73,4 +73,4 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new ProgressBarWidget(this); }
}
}
}

View File

@@ -40,8 +40,8 @@ namespace OpenRA.Widgets
public override void Draw()
{
var state = IsSelected() ? BaseName+"-selected" :
Ui.MouseOverWidget == this ? BaseName+"-hover" :
var state = IsSelected() ? BaseName + "-selected" :
Ui.MouseOverWidget == this ? BaseName + "-hover" :
null;
if (state != null)
@@ -74,4 +74,4 @@ namespace OpenRA.Widgets
return w;
}
}
}
}

View File

@@ -30,6 +30,7 @@ namespace OpenRA.Widgets
public class ScrollPanelWidget : Widget
{
readonly Ruleset modRules;
public int ScrollbarWidth = 24;
public int ItemSpacing = 2;
public int ButtonDepth = ChromeMetrics.Get<int>("ButtonDepth");
@@ -59,8 +60,6 @@ namespace OpenRA.Widgets
// The current value is the actual list offset at the moment
float currentListOffset;
readonly Ruleset modRules;
// Setting "smooth" to true will only update the target list offset.
// Setting "smooth" to false will also set the current list offset,
// i.e. it will scroll immediately.

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Widgets
public class SliderWidget : Widget
{
public Func<bool> IsDisabled = () => false;
public event Action<float> OnChange = _ => {};
public event Action<float> OnChange = _ => { };
public int Ticks = 0;
public int TrackHeight = 5;
public string Thumb = "slider-thumb";
@@ -59,7 +59,7 @@ namespace OpenRA.Widgets
if (mi.Event == MouseInputEvent.Down && !TakeMouseFocus(mi)) return false;
if (!HasMouseFocus) return false;
switch(mi.Event)
switch (mi.Event)
{
case MouseInputEvent.Up:
isMoving = false;
@@ -95,7 +95,7 @@ namespace OpenRA.Widgets
var rb = RenderBounds;
var width = rb.Height;
var height = rb.Height;
var origin = (int)(rb.X + thumbPos - width/2f);
var origin = (int)(rb.X + thumbPos - width / 2f);
return new Rectangle(origin, rb.Y, width, height);
}
}
@@ -132,5 +132,4 @@ namespace OpenRA.Widgets
ButtonWidget.DrawBackground(Thumb, tr, IsDisabled(), isMoving, thumbHover, false);
}
}
}
}

View File

@@ -16,7 +16,7 @@ namespace OpenRA.Widgets
{
public class TooltipContainerWidget : Widget
{
static readonly Action Nothing = () => {};
static readonly Action Nothing = () => { };
public int2 CursorOffset = new int2(0, 20);
public Action BeforeRender = Nothing;
public int TooltipDelay = 5;
@@ -30,7 +30,7 @@ namespace OpenRA.Widgets
public void SetTooltip(string id, WidgetArgs args)
{
RemoveTooltip();
tooltip = Ui.LoadWidget(id, this, new WidgetArgs(args) {{ "tooltipContainer", this }});
tooltip = Ui.LoadWidget(id, this, new WidgetArgs(args) { { "tooltipContainer", this } });
}
public void RemoveTooltip()

View File

@@ -72,7 +72,7 @@ namespace OpenRA.Widgets
return;
tooltipContainer.Value.SetTooltip(TooltipTemplate,
new WidgetArgs() {{ "world", world }, { "viewport", this }});
new WidgetArgs() { { "world", world }, { "viewport", this } });
}
public override void MouseExited()

View File

@@ -133,6 +133,8 @@ namespace OpenRA.Widgets
public abstract class Widget
{
public readonly List<Widget> Children = new List<Widget>();
// Info defined in YAML
public string Id = null;
public string X = "0";
@@ -150,7 +152,6 @@ namespace OpenRA.Widgets
public Widget Parent = null;
public Func<bool> IsVisible;
public Widget() { IsVisible = () => Visible; }
public readonly List<Widget> Children = new List<Widget>();
public Widget(Widget widget)
{
@@ -324,8 +325,8 @@ namespace OpenRA.Widgets
return EventBounds.Contains(pos) ? GetCursor(pos) : null;
}
public virtual void MouseEntered() {}
public virtual void MouseExited() {}
public virtual void MouseEntered() { }
public virtual void MouseExited() { }
public virtual bool HandleMouseInput(MouseInput mi) { return false; }
public bool HandleMouseInputOuter(MouseInput mi)
@@ -335,6 +336,7 @@ namespace OpenRA.Widgets
return false;
var oldMouseOver = Ui.MouseOverWidget;
// Send the event to the deepest children first and bubble up if unhandled
foreach (var child in Children.OfType<Widget>().Reverse())
if (child.HandleMouseInputOuter(mi))
@@ -385,7 +387,7 @@ namespace OpenRA.Widgets
return handled;
}
public virtual void Draw() {}
public virtual void Draw() { }
public virtual void DrawOuter()
{
@@ -397,7 +399,7 @@ namespace OpenRA.Widgets
}
}
public virtual void Tick() {}
public virtual void Tick() { }
public virtual void TickOuter()
{
@@ -427,7 +429,7 @@ namespace OpenRA.Widgets
public virtual void RemoveChildren()
{
while (Children.Count > 0)
RemoveChild(Children[Children.Count-1]);
RemoveChild(Children[Children.Count - 1]);
}
public virtual void Removed()
@@ -452,12 +454,13 @@ namespace OpenRA.Widgets
if (w != null)
return w;
}
return null;
}
public T GetOrNull<T>(string id) where T : Widget
{
return (T) GetOrNull(id);
return (T)GetOrNull(id);
}
public T Get<T>(string id) where T : Widget

View File

@@ -25,9 +25,9 @@ namespace OpenRA
this.modData = modData;
foreach (var file in modData.Manifest.ChromeLayout.Select(a => MiniYaml.FromFile(a)))
foreach( var w in file )
foreach (var w in file)
{
var key = w.Key.Substring( w.Key.IndexOf('@') + 1);
var key = w.Key.Substring(w.Key.IndexOf('@') + 1);
if (widgets.ContainsKey(key))
throw new InvalidDataException("Widget has duplicate Key `{0}` at {1}".F(w.Key, w.Location));
widgets.Add(key, w);
@@ -40,7 +40,7 @@ namespace OpenRA
if (!widgets.TryGetValue(w, out ret))
throw new InvalidDataException("Cannot find widget with Id `{0}`".F(w));
return LoadWidget( args, parent, ret );
return LoadWidget(args, parent, ret);
}
public Widget LoadWidget(WidgetArgs args, Widget parent, MiniYamlNode node)
@@ -51,7 +51,7 @@ namespace OpenRA
var widget = NewWidget(node.Key, args);
if (parent != null)
parent.AddChild( widget );
parent.AddChild(widget);
if (node.Key.Contains("@"))
FieldLoader.LoadField(widget, "Id", node.Key.Split('@')[1]);
@@ -65,7 +65,7 @@ namespace OpenRA
foreach (var child in node.Value.Nodes)
if (child.Key == "Children")
foreach (var c in child.Value.Nodes)
LoadWidget( args, widget, c);
LoadWidget(args, widget, c);
widget.PostInit(args);
return widget;

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Widgets
public static void DrawRGBA(Sprite s, float2 pos)
{
Game.Renderer.RgbaSpriteRenderer.DrawSprite(s,pos);
Game.Renderer.RgbaSpriteRenderer.DrawSprite(s, pos);
}
public static void DrawSHPCentered(Sprite s, float2 pos, WorldRenderer wr)
@@ -53,10 +53,11 @@ namespace OpenRA.Widgets
{
var rr = new Rectangle(s.bounds.Left,
s.bounds.Top,
Math.Min(left.X,(int)s.size.X),
Math.Min(left.Y,(int)s.size.Y));
ss = new Sprite(s.sheet,rr,s.channel);
Math.Min(left.X, (int)s.size.X),
Math.Min(left.Y, (int)s.size.Y));
ss = new Sprite(s.sheet, rr, s.channel);
}
DrawRGBA(ss, new float2(x, y));
}
}
@@ -175,7 +176,7 @@ namespace OpenRA.Widgets
{
var lines = text.Split('\n').ToList();
for (var i=0; i<lines.Count; i++)
for (var i = 0; i < lines.Count; i++)
{
var line = lines[i];
var m = font.Measure(line);
@@ -206,10 +207,11 @@ namespace OpenRA.Widgets
return string.Join("\n", lines);
}
return text;
}
public static Action Once( Action a ) { return () => { if (a != null) { a(); a = null; } }; }
public static Action Once(Action a) { return () => { if (a != null) { a(); a = null; } }; }
public static string ChooseInitialMap(string initialUid)
{