StyleCop clean OpenRA.Game

This commit is contained in:
Matthias Mailänder
2015-01-02 15:11:36 +01:00
parent 9dd607c846
commit 44cd174a8d
61 changed files with 628 additions and 581 deletions

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Widgets
public readonly bool UseContrast = false;
public string Notification = "";
const int logLength = 9;
const int LogLength = 9;
List<ChatLine> recentLines = new List<ChatLine>();
public override Rectangle EventBounds { get { return Rectangle.Empty; } }
@@ -72,7 +72,7 @@ namespace OpenRA.Widgets
if (Notification != null)
Sound.Play(Notification);
while (recentLines.Count > logLength)
while (recentLines.Count > LogLength)
recentLines.RemoveAt(0);
}

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Widgets
Game.Renderer.LineRenderer.DrawLine(origin + new float2(100, 0) * basis, origin + new float2(100, 100) * basis, Color.White, Color.White);
var k = 0;
foreach (var item in PerfHistory.items.Values.ToArray())
foreach (var item in PerfHistory.Items.Values.ToArray())
{
var n = 0;
item.Samples().Aggregate((a, b) =>
@@ -34,7 +34,7 @@ namespace OpenRA.Widgets
Game.Renderer.LineRenderer.DrawLine(
origin + new float2(n, (float)a) * basis,
origin + new float2(n + 1, (float)b) * basis,
item.c, item.c);
item.C, item.C);
++n;
return b;
});
@@ -44,18 +44,18 @@ namespace OpenRA.Widgets
Game.Renderer.LineRenderer.DrawLine(
u + new float2(10, 10 * k + 5),
u + new float2(12, 10 * k + 5),
item.c, item.c);
item.C, item.C);
Game.Renderer.LineRenderer.DrawLine(
u + new float2(10, 10 * k + 4),
u + new float2(12, 10 * k + 4),
item.c, item.c);
item.C, item.C);
++k;
}
k = 0;
foreach (var item in PerfHistory.items.Values.ToArray())
foreach (var item in PerfHistory.Items.Values.ToArray())
{
Game.Renderer.Fonts["Tiny"].DrawText(item.Name, new float2(rect.Left, rect.Top) + new float2(18, 10 * k - 3), Color.White);
++k;

View File

@@ -43,11 +43,11 @@ namespace OpenRA.Widgets
public bool CollapseHiddenChildren;
public float SmoothScrollSpeed = 0.333f;
protected bool UpPressed;
protected bool DownPressed;
protected bool UpDisabled;
protected bool DownDisabled;
protected bool ThumbPressed;
protected bool upPressed;
protected bool downPressed;
protected bool upDisabled;
protected bool downDisabled;
protected bool thumbPressed;
protected Rectangle upButtonRect;
protected Rectangle downButtonRect;
protected Rectangle backgroundRect;
@@ -119,40 +119,40 @@ namespace OpenRA.Widgets
var rb = RenderBounds;
var ScrollbarHeight = rb.Height - 2 * ScrollbarWidth;
var scrollbarHeight = rb.Height - 2 * ScrollbarWidth;
var thumbHeight = ContentHeight == 0 ? 0 : Math.Max(MinimumThumbSize, (int)(ScrollbarHeight * Math.Min(rb.Height * 1f / ContentHeight, 1f)));
var thumbOrigin = rb.Y + ScrollbarWidth + (int)((ScrollbarHeight - thumbHeight) * (-1f * currentListOffset / (ContentHeight - rb.Height)));
if (thumbHeight == ScrollbarHeight)
var thumbHeight = ContentHeight == 0 ? 0 : Math.Max(MinimumThumbSize, (int)(scrollbarHeight * Math.Min(rb.Height * 1f / ContentHeight, 1f)));
var thumbOrigin = rb.Y + ScrollbarWidth + (int)((scrollbarHeight - thumbHeight) * (-1f * currentListOffset / (ContentHeight - rb.Height)));
if (thumbHeight == scrollbarHeight)
thumbHeight = 0;
backgroundRect = new Rectangle(rb.X, rb.Y, rb.Width - ScrollbarWidth + 1, rb.Height);
upButtonRect = new Rectangle(rb.Right - ScrollbarWidth, rb.Y, ScrollbarWidth, ScrollbarWidth);
downButtonRect = new Rectangle(rb.Right - ScrollbarWidth, rb.Bottom - ScrollbarWidth, ScrollbarWidth, ScrollbarWidth);
scrollbarRect = new Rectangle(rb.Right - ScrollbarWidth, rb.Y + ScrollbarWidth - 1, ScrollbarWidth, ScrollbarHeight + 2);
scrollbarRect = new Rectangle(rb.Right - ScrollbarWidth, rb.Y + ScrollbarWidth - 1, ScrollbarWidth, scrollbarHeight + 2);
thumbRect = new Rectangle(rb.Right - ScrollbarWidth, thumbOrigin, ScrollbarWidth, thumbHeight);
var upHover = Ui.MouseOverWidget == this && upButtonRect.Contains(Viewport.LastMousePos);
UpDisabled = thumbHeight == 0 || currentListOffset >= 0;
upDisabled = thumbHeight == 0 || currentListOffset >= 0;
var downHover = Ui.MouseOverWidget == this && downButtonRect.Contains(Viewport.LastMousePos);
DownDisabled = thumbHeight == 0 || currentListOffset <= Bounds.Height - ContentHeight;
downDisabled = thumbHeight == 0 || currentListOffset <= Bounds.Height - ContentHeight;
var thumbHover = Ui.MouseOverWidget == this && thumbRect.Contains(Viewport.LastMousePos);
WidgetUtils.DrawPanel(Background, backgroundRect);
WidgetUtils.DrawPanel(Background, scrollbarRect);
ButtonWidget.DrawBackground(Button, upButtonRect, UpDisabled, UpPressed, upHover, false);
ButtonWidget.DrawBackground(Button, downButtonRect, DownDisabled, DownPressed, downHover, false);
ButtonWidget.DrawBackground(Button, upButtonRect, upDisabled, upPressed, upHover, false);
ButtonWidget.DrawBackground(Button, downButtonRect, downDisabled, downPressed, downHover, false);
if (thumbHeight > 0)
ButtonWidget.DrawBackground(Button, thumbRect, false, HasMouseFocus && thumbHover, thumbHover, false);
var upOffset = !UpPressed || UpDisabled ? 4 : 4 + ButtonDepth;
var downOffset = !DownPressed || DownDisabled ? 4 : 4 + ButtonDepth;
var upOffset = !upPressed || upDisabled ? 4 : 4 + ButtonDepth;
var downOffset = !downPressed || downDisabled ? 4 : 4 + ButtonDepth;
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", UpPressed || UpDisabled ? "up_pressed" : "up_arrow"),
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", upPressed || upDisabled ? "up_pressed" : "up_arrow"),
new float2(upButtonRect.Left + upOffset, upButtonRect.Top + upOffset));
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", DownPressed || DownDisabled ? "down_pressed" : "down_arrow"),
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", downPressed || downDisabled ? "down_pressed" : "down_arrow"),
new float2(downButtonRect.Left + downOffset, downButtonRect.Top + downOffset));
Game.Renderer.EnableScissor(backgroundRect.InflateBy(-1, -1, -1, -1));
@@ -225,10 +225,10 @@ namespace OpenRA.Widgets
public override void Tick()
{
if (UpPressed)
if (upPressed)
Scroll(1);
if (DownPressed)
if (downPressed)
Scroll(-1);
var offsetDiff = targetListOffset - currentListOffset;
@@ -241,7 +241,7 @@ namespace OpenRA.Widgets
public override bool YieldMouseFocus(MouseInput mi)
{
UpPressed = DownPressed = ThumbPressed = false;
upPressed = downPressed = thumbPressed = false;
return base.YieldMouseFocus(mi);
}
@@ -267,14 +267,14 @@ namespace OpenRA.Widgets
if (HasMouseFocus && mi.Event == MouseInputEvent.Up)
return YieldMouseFocus(mi);
if (ThumbPressed && mi.Event == MouseInputEvent.Move)
if (thumbPressed && mi.Event == MouseInputEvent.Move)
{
var rb = RenderBounds;
var ScrollbarHeight = rb.Height - 2 * ScrollbarWidth;
var thumbHeight = ContentHeight == 0 ? 0 : Math.Max(MinimumThumbSize, (int)(ScrollbarHeight * Math.Min(rb.Height * 1f / ContentHeight, 1f)));
var scrollbarHeight = rb.Height - 2 * ScrollbarWidth;
var thumbHeight = ContentHeight == 0 ? 0 : Math.Max(MinimumThumbSize, (int)(scrollbarHeight * Math.Min(rb.Height * 1f / ContentHeight, 1f)));
var oldOffset = currentListOffset;
var newOffset = currentListOffset + ((int)((lastMouseLocation.Y - mi.Location.Y) * (ContentHeight - rb.Height) * 1f / (ScrollbarHeight - thumbHeight)));
var newOffset = currentListOffset + ((int)((lastMouseLocation.Y - mi.Location.Y) * (ContentHeight - rb.Height) * 1f / (scrollbarHeight - thumbHeight)));
newOffset = Math.Min(0, Math.Max(rb.Height - ContentHeight, newOffset));
SetListOffset(newOffset, false);
@@ -283,17 +283,17 @@ namespace OpenRA.Widgets
}
else
{
UpPressed = upButtonRect.Contains(mi.Location);
DownPressed = downButtonRect.Contains(mi.Location);
ThumbPressed = thumbRect.Contains(mi.Location);
if (ThumbPressed)
upPressed = upButtonRect.Contains(mi.Location);
downPressed = downButtonRect.Contains(mi.Location);
thumbPressed = thumbRect.Contains(mi.Location);
if (thumbPressed)
lastMouseLocation = mi.Location;
if (mi.Event == MouseInputEvent.Down && ((UpPressed && !UpDisabled) || (DownPressed && !DownDisabled) || ThumbPressed))
if (mi.Event == MouseInputEvent.Down && ((upPressed && !upDisabled) || (downPressed && !downDisabled) || thumbPressed))
Sound.PlayNotification(modRules, null, "Sounds", "ClickSound", null);
}
return UpPressed || DownPressed || ThumbPressed;
return upPressed || downPressed || thumbPressed;
}
IObservableCollection collection;

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Widgets
if (Unit != null && Sequence != null)
{
var anim = new Animation(worldRenderer.world, Unit, () => Facing);
var anim = new Animation(WorldRenderer.world, Unit, () => Facing);
anim.PlayFetchIndex(Sequence, () => Frame);
GetAnimation = () => anim;
}

View File

@@ -19,14 +19,14 @@ namespace OpenRA.Widgets
public Func<string> GetPalette;
public Func<Sprite> GetSprite;
protected readonly WorldRenderer worldRenderer;
protected readonly WorldRenderer WorldRenderer;
[ObjectCreator.UseCtor]
public SpriteWidget(WorldRenderer worldRenderer)
{
GetPalette = () => Palette;
this.worldRenderer = worldRenderer;
this.WorldRenderer = worldRenderer;
}
protected SpriteWidget(SpriteWidget other)
@@ -36,7 +36,7 @@ namespace OpenRA.Widgets
GetPalette = other.GetPalette;
GetSprite = other.GetSprite;
worldRenderer = other.worldRenderer;
WorldRenderer = other.WorldRenderer;
}
public override Widget Clone() { return new SpriteWidget(this); }
@@ -62,7 +62,7 @@ namespace OpenRA.Widgets
if (palette != cachedPalette)
{
pr = worldRenderer.Palette(palette);
pr = WorldRenderer.Palette(palette);
cachedPalette = palette;
}

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Widgets
public static int LastTickTime = Game.RunTime;
static Stack<Widget> WindowList = new Stack<Widget>();
static readonly Stack<Widget> WindowList = new Stack<Widget>();
public static Widget MouseFocusWidget;
public static Widget KeyboardFocusWidget;