remove plenty of redundant junk

This commit is contained in:
Chris Forbes
2010-07-14 19:00:03 +12:00
parent 17bf4610f1
commit fed33fdb00
32 changed files with 1184 additions and 1178 deletions

View File

@@ -67,7 +67,7 @@ namespace OpenRA.FileFormats
}
Preview = Lazy.New(
() => { return new Bitmap(Package.GetContent("preview.png")); }
() => new Bitmap(Package.GetContent("preview.png"))
);
Uid = Package.GetContent("map.uid").ReadAllText();

View File

@@ -18,11 +18,11 @@
*/
#endregion
using System.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
namespace OpenRA

View File

@@ -1,10 +1,29 @@
using System;
using System.Collections.Generic;
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using System.Linq;
using System.Text;
using System.Net;
using OpenRA.FileFormats;
using System.Text;
using System.Threading;
using OpenRA.FileFormats;
namespace OpenRA.Server
{

View File

@@ -1,4 +1,3 @@
using System.Drawing;
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
@@ -32,10 +31,10 @@ namespace OpenRA.Widgets
public BackgroundWidget() : base() { }
public BackgroundWidget(Widget other)
protected BackgroundWidget(BackgroundWidget other)
: base(other)
{
Background = (other as BackgroundWidget).Background;
Background = other.Background;
}
public override Widget Clone() { return new BackgroundWidget(this); }

View File

@@ -18,15 +18,14 @@
*/
#endregion
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using OpenRA;
using OpenRA.Traits;
using OpenRA.Graphics;
using OpenRA.FileFormats;
using OpenRA.Orders;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Orders;
using OpenRA.Traits;
namespace OpenRA.Widgets
{
@@ -53,14 +52,6 @@ namespace OpenRA.Widgets
public BuildPaletteWidget() : base() { }
public BuildPaletteWidget(Widget other)
: base(other)
{
throw new NotImplementedException("Why are you Cloning BuildPalette?");
}
public override Widget Clone() { return new BuildPaletteWidget(this); }
public override void Initialize()
{
base.Initialize();

View File

@@ -18,8 +18,8 @@
*/
#endregion
using System.Drawing;
using System;
using System.Drawing;
namespace OpenRA.Widgets
{
@@ -37,13 +37,13 @@ namespace OpenRA.Widgets
GetText = () => { return Text; };
}
public ButtonWidget(Widget widget)
protected ButtonWidget(ButtonWidget widget)
: base(widget)
{
Text = (widget as ButtonWidget).Text;
Depressed = (widget as ButtonWidget).Depressed;
VisualHeight = (widget as ButtonWidget).VisualHeight;
GetText = (widget as ButtonWidget).GetText;
Text = widget.Text;
Depressed = widget.Depressed;
VisualHeight = widget.VisualHeight;
GetText = widget.GetText;
}
public override bool LoseFocus(MouseInput mi)
@@ -85,10 +85,7 @@ namespace OpenRA.Widgets
font.Measure(text).Y / 2) + stateOffset, Color.White);
}
public override Widget Clone()
{
return new ButtonWidget(this);
}
public override Widget Clone() { return new ButtonWidget(this); }
}
}

View File

@@ -18,12 +18,9 @@
*/
#endregion
using OpenRA.FileFormats;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System;
namespace OpenRA.Widgets
{
@@ -37,7 +34,7 @@ namespace OpenRA.Widgets
public ChatDisplayWidget()
: base() { }
public ChatDisplayWidget(Widget widget)
protected ChatDisplayWidget(Widget widget)
: base(widget) { }
public override void DrawInner(World world)
@@ -74,11 +71,13 @@ namespace OpenRA.Widgets
while (recentLines.Count > logLength) recentLines.RemoveAt(0);
}
public override Widget Clone()
{
return new ChatDisplayWidget(this);
public override Widget Clone() { return new ChatDisplayWidget(this); }
}
}
class ChatLine { public Color Color = Color.White; public string Owner, Text; public bool wrapped = false; }
class ChatLine
{
public Color Color = Color.White;
public string Owner, Text;
public bool wrapped = false;
}
}

View File

@@ -56,15 +56,16 @@ namespace OpenRA.Widgets
Game.chrome.lineRenderer.Flush();
}
}
public override bool HandleInput(MouseInput mi) { return true; }
public CheckboxWidget() : base() { }
public CheckboxWidget(Widget other)
protected CheckboxWidget(CheckboxWidget other)
: base(other)
{
Text = (other as CheckboxWidget).Text;
Checked = (other as CheckboxWidget).Checked;
Text = other.Text;
Checked = other.Checked;
}
public override Widget Clone() { return new CheckboxWidget(this); }

View File

@@ -33,10 +33,10 @@ namespace OpenRA.Widgets
GetColor = () => Color.White;
}
public ColorBlockWidget(Widget widget)
protected ColorBlockWidget(ColorBlockWidget widget)
: base(widget)
{
GetColor = (widget as ColorBlockWidget).GetColor;
GetColor = widget.GetColor;
}
public override Widget Clone()
@@ -47,7 +47,8 @@ namespace OpenRA.Widgets
public override void DrawInner(World world)
{
var pos = RenderOrigin;
var paletteRect = new RectangleF(pos.X + Game.viewport.Location.X, pos.Y + Game.viewport.Location.Y, Bounds.Width, Bounds.Height);
var paletteRect = new RectangleF(pos.X + Game.viewport.Location.X,
pos.Y + Game.viewport.Location.Y, Bounds.Width, Bounds.Height);
Game.chrome.lineRenderer.FillRect(paletteRect, GetColor());
}
}

View File

@@ -1,8 +1,27 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Widgets.Delegates

View File

@@ -17,9 +17,6 @@
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using OpenRA.FileFormats;
using OpenRA.Support;
namespace OpenRA.Widgets.Delegates
{

View File

@@ -18,7 +18,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
@@ -46,9 +45,9 @@ namespace OpenRA.Widgets.Delegates
RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE");
var map = lobby.GetWidget<MapPreviewWidget>("LOBBY_MAP_PREVIEW");
map.Map = () => {return Map;};
map.OnSpawnClick = sp =>
var mapPreview = lobby.GetWidget<MapPreviewWidget>("LOBBY_MAP_PREVIEW");
mapPreview.Map = () => Map;
mapPreview.OnSpawnClick = sp =>
{
if (Game.LocalClient.State == Session.ClientState.Ready) return;
var owned = Game.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp);
@@ -56,7 +55,7 @@ namespace OpenRA.Widgets.Delegates
Game.IssueOrder(Order.Command("spawn {0}".F(sp)));
};
map.SpawnColors = () =>
mapPreview.SpawnColors = () =>
{
var spawns = Map.SpawnPoints;
var playerColors = Game.world.PlayerColors();
@@ -76,7 +75,8 @@ namespace OpenRA.Widgets.Delegates
CountryNames.Add("random", "Random");
var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON");
mapButton.OnMouseUp = mi => {
mapButton.OnMouseUp = mi =>
{
r.GetWidget("MAP_CHOOSER").SpecialOneArg(MapUid);
r.OpenWindow("MAP_CHOOSER");
return true;
@@ -85,7 +85,8 @@ namespace OpenRA.Widgets.Delegates
mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
var disconnectButton = lobby.GetWidget("DISCONNECT_BUTTON");
disconnectButton.OnMouseUp = mi => {
disconnectButton.OnMouseUp = mi =>
{
Game.Disconnect();
return true;
};

View File

@@ -17,8 +17,9 @@
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using OpenRA.FileFormats;
namespace OpenRA.Widgets.Delegates
{
public class MainMenuButtonsDelegate : IWidgetDelegate

View File

@@ -18,8 +18,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
@@ -36,19 +34,21 @@ namespace OpenRA.Widgets.Delegates
bg.SpecialOneArg = (map) => RefreshMapList(map);
var ml = bg.GetWidget<ListBoxWidget>("MAP_LIST");
bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => {return Map;};
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => {return Map.Title;};
bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => {return "{0}x{1}".F(Map.Width, Map.Height);};
bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => {return Rules.TileSets[Map.Tileset].Name;};
bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => {return Map.PlayerCount.ToString();};
bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => Map;
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => Map.Title;
bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => "{0}x{1}".F(Map.Width, Map.Height);
bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => Rules.TileSets[Map.Tileset].Name;
bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => Map.PlayerCount.ToString();
bg.GetWidget("BUTTON_OK").OnMouseUp = mi => {
bg.GetWidget("BUTTON_OK").OnMouseUp = mi =>
{
Game.IssueOrder(Order.Command("map " + Map.Uid));
r.CloseWindow();
return true;
};
bg.GetWidget("BUTTON_CANCEL").OnMouseUp = mi => {
bg.GetWidget("BUTTON_CANCEL").OnMouseUp = mi =>
{
r.CloseWindow();
return true;
};

View File

@@ -17,7 +17,7 @@
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
namespace OpenRA.Widgets.Delegates
{
public class MusicPlayerDelegate : IWidgetDelegate
@@ -27,7 +27,8 @@ namespace OpenRA.Widgets.Delegates
var bg = Chrome.rootWidget.GetWidget("MUSIC_BG");
bg.Visible = Game.Settings.MusicPlayer;
bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi => {
bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi =>
{
if (Sound.MusicStopped)
Sound.PlayMusic(GetSong());
Sound.MusicStopped = false;
@@ -36,19 +37,25 @@ namespace OpenRA.Widgets.Delegates
bg.GetWidget("BUTTON_PAUSE").Visible = true;
return true;
};
bg.GetWidget("BUTTON_PAUSE").OnMouseUp = mi => {
bg.GetWidget("BUTTON_PAUSE").OnMouseUp = mi =>
{
Sound.MusicPaused = true;
bg.GetWidget("BUTTON_PAUSE").Visible = false;
bg.GetWidget("BUTTON_PLAY").Visible = true;
return true;
};
bg.GetWidget("BUTTON_STOP").OnMouseUp = mi => {
bg.GetWidget("BUTTON_STOP").OnMouseUp = mi =>
{
Sound.MusicStopped = true;
bg.GetWidget("BUTTON_PAUSE").Visible = false;
bg.GetWidget("BUTTON_PLAY").Visible = true;
return true;
};
bg.GetWidget("BUTTON_NEXT").OnMouseUp = mi => {
bg.GetWidget("BUTTON_NEXT").OnMouseUp = mi =>
{
Sound.PlayMusic(GetNextSong());
Sound.MusicStopped = false;
Sound.MusicPaused = false;
@@ -56,7 +63,9 @@ namespace OpenRA.Widgets.Delegates
bg.GetWidget("BUTTON_PAUSE").Visible = true;
return true;
};
bg.GetWidget("BUTTON_PREV").OnMouseUp = mi => {
bg.GetWidget("BUTTON_PREV").OnMouseUp = mi =>
{
Sound.PlayMusic(GetPrevSong());
Sound.MusicStopped = false;
Sound.MusicPaused = false;
@@ -71,11 +80,13 @@ namespace OpenRA.Widgets.Delegates
if (!Rules.Music.ContainsKey("allmusic")) return null;
return Rules.Music["allmusic"].Pool.GetNext();
}
string GetPrevSong()
{
if (!Rules.Music.ContainsKey("allmusic")) return null;
return Rules.Music["allmusic"].Pool.GetPrev();
}
string GetSong()
{
if (!Rules.Music.ContainsKey("allmusic")) return null;

View File

@@ -17,8 +17,7 @@
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using OpenRA.FileFormats;
using OpenRA.Support;
namespace OpenRA.Widgets.Delegates
@@ -29,19 +28,17 @@ namespace OpenRA.Widgets.Delegates
{
var r = Chrome.rootWidget;
var perfRoot = r.GetWidget("PERF_BG");
perfRoot.IsVisible = () => {return (perfRoot.Visible && Game.Settings.PerfDebug);};
perfRoot.IsVisible = () => perfRoot.Visible && Game.Settings.PerfDebug;
// Perf text
var perfText = perfRoot.GetWidget<LabelWidget>("TEXT");
perfText.GetText = () => {
return "Render {0} ({5}={2:F1} ms)\nTick {4} ({3:F1} ms)".F(
perfText.GetText = () => "Render {0} ({5}={2:F1} ms)\nTick {4} ({3:F1} ms)".F(
Game.RenderFrame,
Game.orderManager.FrameNumber,
PerfHistory.items["render"].LastValue,
PerfHistory.items["tick_time"].LastValue,
Game.LocalTick,
PerfHistory.items["batches"].LastValue);
};
}
}
}

View File

@@ -21,9 +21,8 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Server;
using OpenRA.FileFormats;
using System;
using OpenRA.Server;
namespace OpenRA.Widgets.Delegates
{
@@ -137,7 +136,8 @@ namespace OpenRA.Widgets.Delegates
};
// Direct Connect
dc.GetWidget("JOIN_BUTTON").OnMouseUp = mi => {
dc.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
{
var address = dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text;
var cpts = address.Split(':').ToArray();
@@ -152,7 +152,8 @@ namespace OpenRA.Widgets.Delegates
return true;
};
dc.GetWidget("CANCEL_BUTTON").OnMouseUp = mi => {
dc.GetWidget("CANCEL_BUTTON").OnMouseUp = mi =>
{
r.CloseWindow();
return r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp(mi);
};
@@ -160,7 +161,8 @@ namespace OpenRA.Widgets.Delegates
MapStub CurrentMap()
{
return (currentServer == null || !Game.AvailableMaps.ContainsKey(currentServer.Map)) ? null : Game.AvailableMaps[currentServer.Map];
return (currentServer == null || !Game.AvailableMaps.ContainsKey(currentServer.Map))
? null : Game.AvailableMaps[currentServer.Map];
}
void RefreshServerList(IEnumerable<GameServer> games)
@@ -197,7 +199,7 @@ namespace OpenRA.Widgets.Delegates
template.GetText = () => " {0} ({1})".F( /* /8 = hack */
game.Name,
game.Address);
template.GetBackground = () => ((currentServer == game) ? "dialog2" : null);
template.GetBackground = () => (currentServer == game) ? "dialog2" : null;
template.OnMouseDown = mi => { currentServer = game; return true; };
template.Parent = sl;

View File

@@ -18,25 +18,24 @@ namespace OpenRA.Widgets
GetImageCollection = () => { return ImageCollection; };
}
public ImageWidget(Widget other)
protected ImageWidget(ImageWidget other)
: base(other)
{
ImageName = (other as ImageWidget).ImageName;
GetImageName = (other as ImageWidget).GetImageName;
ImageCollection = (other as ImageWidget).ImageCollection;
GetImageCollection = (other as ImageWidget).GetImageCollection;
ImageName = other.ImageName;
GetImageName = other.GetImageName;
ImageCollection = other.ImageCollection;
GetImageCollection = other.GetImageCollection;
}
public override Widget Clone()
{
return new ImageWidget(this);
}
public override Widget Clone() { return new ImageWidget(this); }
public override void DrawInner(World world)
{
var name = GetImageName();
var collection = GetImageCollection();
WidgetUtils.DrawRGBA(ChromeProvider.GetImage(Game.chrome.renderer, collection, name), RenderOrigin);
WidgetUtils.DrawRGBA(
ChromeProvider.GetImage(Game.chrome.renderer, collection, name),
RenderOrigin);
}
}
}

View File

@@ -18,19 +18,14 @@
*/
#endregion
using System.Drawing;
using System;
using System.Drawing;
namespace OpenRA.Widgets
{
class LabelWidget : Widget
{
public enum TextAlign
{
Left,
Center,
Right
}
public enum TextAlign { Left, Center, Right }
public string Text = null;
public string Background = null;
@@ -46,14 +41,14 @@ namespace OpenRA.Widgets
GetBackground = () => { return Background; };
}
public LabelWidget(Widget other)
protected LabelWidget(LabelWidget other)
: base(other)
{
Text = (other as LabelWidget).Text;
Align = (other as LabelWidget).Align;
Bold = (other as LabelWidget).Bold;
GetText = (other as LabelWidget).GetText;
GetBackground = (other as LabelWidget).GetBackground;
Text = other.Text;
Align = other.Align;
Bold = other.Bold;
GetText = other.GetText;
GetBackground = other.GetBackground;
}
public override void DrawInner(World world)
@@ -80,9 +75,6 @@ namespace OpenRA.Widgets
font.DrawText(text, position, Color.White);
}
public override Widget Clone()
{
return new LabelWidget(this);
}
public override Widget Clone() { return new LabelWidget(this); }
}
}

View File

@@ -1,4 +1,3 @@
using System.Drawing;
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
@@ -19,6 +18,8 @@ using System.Drawing;
*/
#endregion
using System.Drawing;
namespace OpenRA.Widgets
{
class ListBoxWidget : Widget
@@ -39,17 +40,17 @@ namespace OpenRA.Widgets
Rectangle scrollbarRect;
public ListBoxWidget() : base() {}
public ListBoxWidget(Widget other)
protected ListBoxWidget(ListBoxWidget other)
: base(other)
{
Background = (other as ListBoxWidget).Background;
upButtonRect = (other as ListBoxWidget).upButtonRect;
downButtonRect = (other as ListBoxWidget).downButtonRect;
scrollbarRect = (other as ListBoxWidget).scrollbarRect;
backgroundRect = (other as ListBoxWidget).backgroundRect;
Background = other.Background;
upButtonRect = other.upButtonRect;
downButtonRect = other.downButtonRect;
scrollbarRect = other.scrollbarRect;
backgroundRect = other.backgroundRect;
UpPressed = (other as ListBoxWidget).UpPressed;
DownPressed = (other as ListBoxWidget).DownPressed;
UpPressed = other.UpPressed;
DownPressed = other.DownPressed;
}
public override void DrawInner(World world) {}
@@ -65,14 +66,12 @@ namespace OpenRA.Widgets
string upButtonBg = (UpPressed) ? "dialog3" : "dialog2";
string downButtonBg = (DownPressed) ? "dialog3" : "dialog2";
string scrolbarBg = "dialog3";
string scrollbarButton = "dialog2";
string scrollbarBg = "dialog3";
WidgetUtils.DrawPanel(Background, backgroundRect);
WidgetUtils.DrawPanel(upButtonBg, upButtonRect);
WidgetUtils.DrawPanel(downButtonBg, downButtonRect);
WidgetUtils.DrawPanel(scrolbarBg, scrollbarRect);
WidgetUtils.DrawPanel(scrollbarBg, scrollbarRect);
Game.chrome.renderer.Device.EnableScissor(backgroundRect.X, backgroundRect.Y + HeaderHeight, backgroundRect.Width, backgroundRect.Height - HeaderHeight);
@@ -82,6 +81,7 @@ namespace OpenRA.Widgets
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
Game.chrome.renderer.Device.DisableScissor();
}
public override int2 ChildOrigin { get { return RenderOrigin + new int2(0, (int)ListOffset); } }
public override void Tick (World world)

View File

@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRA.Graphics;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
namespace OpenRA.Widgets
{
@@ -15,24 +14,25 @@ namespace OpenRA.Widgets
bool mapPreviewDirty = true;
MapStub lastMap;
public Func<MapStub> Map = () => {return null;};
public Func<MapStub> Map = () => null;
public Action<int> OnSpawnClick = spawn => {};
public Func<Dictionary<int2,Color>> SpawnColors = () => {return new Dictionary<int2, Color>(); };
public Func<Dictionary<int2, Color>> SpawnColors = () => new Dictionary<int2, Color>();
public MapPreviewWidget() : base() { }
public MapPreviewWidget(Widget other)
protected MapPreviewWidget(MapPreviewWidget other)
: base(other)
{
lastMap = (other as MapPreviewWidget).lastMap;
Map = (other as MapPreviewWidget).Map;
OnSpawnClick = (other as MapPreviewWidget).OnSpawnClick;
SpawnColors = (other as MapPreviewWidget).SpawnColors;
lastMap = other.lastMap;
Map = other.Map;
OnSpawnClick = other.OnSpawnClick;
SpawnColors = other.SpawnColors;
}
static Sprite UnownedSpawn = null;
static Sprite OwnedSpawn = null;
const int closeEnough = 50;
public override bool HandleInput(MouseInput mi)
{
var map = Map();

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Widgets
void AddButton(Rectangle r, Action<MouseInput> b) { buttons.Add(Pair.New(r, b)); }
public MoneyBinWidget() : base() { }
public MoneyBinWidget(Widget other) : base(other) { }
protected MoneyBinWidget(Widget other) : base(other) { }
public override Widget Clone() { return new MoneyBinWidget(this); }

View File

@@ -17,8 +17,8 @@
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Support;
@@ -28,10 +28,6 @@ namespace OpenRA.Widgets
{
public PerfGraphWidget() : base() { }
public PerfGraphWidget(Widget other) : base(other) { }
public override Widget Clone() { return new PerfGraphWidget(this); }
public override void DrawInner(World world)
{
var rect = RenderBounds;

View File

@@ -28,10 +28,6 @@ namespace OpenRA.Widgets
{
public PostGameWidget() : base() { }
public PostGameWidget(Widget other) : base(other) { }
public override Widget Clone() { return new PostGameWidget(this); }
bool AreMutualAllies(Player a, Player b) { return a.Stances[b] == Stance.Ally && b.Stances[a] == Stance.Ally; }
// todo: all this shit needs to move, probably to Player.

View File

@@ -25,7 +25,6 @@ using OpenRA.Traits;
namespace OpenRA.Widgets
{
public class PowerBinWidget : Widget
{
// Power bar
@@ -35,8 +34,6 @@ namespace OpenRA.Widgets
float? lastPowerDrainedPos;
string powerCollection;
public override Widget Clone() { throw new NotImplementedException("Why are you Cloning PowerBin?"); }
public override void DrawInner(World world)
{
powerCollection = "power-" + world.LocalPlayer.Country.Race;

View File

@@ -76,8 +76,6 @@ namespace OpenRA.Widgets
return true;
}
public override Widget Clone() { throw new NotImplementedException("Why are you Cloning RadarBin?"); }
public override void DrawInner(World world)
{
radarCollection = "radar-" + world.LocalPlayer.Country.Race;

View File

@@ -14,22 +14,23 @@ namespace OpenRA.Widgets
int2 lastMouseLocation;
bool isMoving = false;
public SliderWidget () : base()
public SliderWidget()
: base()
{
GetOffset = () => Offset;
OnChange = x => Offset = x;
}
public SliderWidget(Widget other)
public SliderWidget(SliderWidget other)
: base(other)
{
OnChange = (other as SliderWidget).OnChange;
GetOffset = (other as SliderWidget).GetOffset;
Offset = (other as SliderWidget).Offset;
Ticks = (other as SliderWidget).Ticks;
TrackHeight = (other as SliderWidget).TrackHeight;
lastMouseLocation = (other as SliderWidget).lastMouseLocation;
isMoving = (other as SliderWidget).isMoving;
OnChange = other.OnChange;
GetOffset = other.GetOffset;
Offset = other.Offset;
Ticks = other.Ticks;
TrackHeight = other.TrackHeight;
lastMouseLocation = other.lastMouseLocation;
isMoving = other.isMoving;
}
public override bool HandleInput(MouseInput mi)
@@ -125,14 +126,18 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new SliderWidget(this); }
Rectangle thumbRect
{ get {
{
get
{
var width = RenderBounds.Height;
var height = RenderBounds.Height;
var origin = (int)((RenderBounds.X + width / 2) + GetOffset() * (RenderBounds.Width - width) - width / 2f);
return new Rectangle(origin, RenderBounds.Y, width, height);
} }
}
}
public override void DrawInner(World world) {
public override void DrawInner(World world)
{
if (!IsVisible())
return;

View File

@@ -18,14 +18,14 @@
*/
#endregion
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using OpenRA;
using OpenRA.Traits;
using OpenRA.Graphics;
using OpenRA.FileFormats;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Widgets
{
class SpecialPowerBinWidget : Widget
@@ -37,16 +37,6 @@ namespace OpenRA.Widgets
public SpecialPowerBinWidget() : base() { }
public SpecialPowerBinWidget(Widget other)
: base(other)
{
ready = (other as SpecialPowerBinWidget).ready;
clock = (other as SpecialPowerBinWidget).clock;
buttons = (other as SpecialPowerBinWidget).buttons;
}
public override Widget Clone() { return new SpecialPowerBinWidget(this); }
public override void Initialize()
{
base.Initialize();

View File

@@ -18,8 +18,8 @@
*/
#endregion
using System.Drawing;
using System;
using System.Drawing;
namespace OpenRA.Widgets
{
@@ -29,8 +29,8 @@ namespace OpenRA.Widgets
public int MaxLength = 0;
public bool Bold = false;
public int VisualHeight = 1;
public Func<bool> OnEnterKey = () => {return false;};
public Func<bool> OnTabKey = () => {return false;};
public Func<bool> OnEnterKey = () => false;
public Func<bool> OnTabKey = () => false;
public Action OnLoseFocus = () => { };
public TextFieldWidget()
@@ -38,13 +38,13 @@ namespace OpenRA.Widgets
{
}
public TextFieldWidget(Widget widget)
protected TextFieldWidget(TextFieldWidget widget)
: base(widget)
{
Text = (widget as TextFieldWidget).Text;
MaxLength = (widget as TextFieldWidget).MaxLength;
Bold = (widget as TextFieldWidget).Bold;
VisualHeight = (widget as TextFieldWidget).VisualHeight;
Text = widget.Text;
MaxLength = widget.MaxLength;
Bold = widget.Bold;
VisualHeight = widget.VisualHeight;
}
public override bool LoseFocus(MouseInput mi)
@@ -147,9 +147,6 @@ namespace OpenRA.Widgets
}
}
public override Widget Clone()
{
return new TextFieldWidget(this);
}
public override Widget Clone() { return new TextFieldWidget(this); }
}
}

View File

@@ -22,8 +22,8 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using OpenRA.FileFormats;
using OpenRA.Widgets.Delegates;
namespace OpenRA.Widgets
{
@@ -49,10 +49,10 @@ namespace OpenRA.Widgets
// Common Funcs that most widgets will want
public Action<object> SpecialOneArg = (arg) => {};
public Func<MouseInput,bool> OnMouseDown = mi => {return false;};
public Func<MouseInput,bool> OnMouseUp = mi => {return false;};
public Func<MouseInput,bool> OnMouseMove = mi => {return false;};
public Func<System.Windows.Forms.KeyPressEventArgs, Modifiers,bool> OnKeyPress = (e,modifiers) => {return false;};
public Func<MouseInput, bool> OnMouseDown = mi => false;
public Func<MouseInput, bool> OnMouseUp = mi => false;
public Func<MouseInput, bool> OnMouseMove = mi => false;
public Func<KeyPressEventArgs, Modifiers, bool> OnKeyPress = (e, modifiers) => false;
public Func<bool> IsVisible;
@@ -83,26 +83,31 @@ namespace OpenRA.Widgets
AddChild(child.Clone());
}
public abstract Widget Clone();
public virtual Widget Clone()
{
throw new InvalidOperationException("Widget type `{0}` is not cloneable.".F(GetType().Name));
}
public virtual int2 RenderOrigin
{
get {
get
{
var offset = (Parent == null) ? int2.Zero : Parent.ChildOrigin;
return new int2(Bounds.X, Bounds.Y) + offset;
}
}
public virtual int2 ChildOrigin { get { return RenderOrigin; } }
public virtual Rectangle RenderBounds { get { return new Rectangle(RenderOrigin.X, RenderOrigin.Y, Bounds.Width, Bounds.Height); } }
public virtual void Initialize()
{
// Parse the YAML equations to find the widget bounds
Rectangle parentBounds = (Parent == null)
var parentBounds = (Parent == null)
? new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height)
: Parent.Bounds;
Dictionary<string, int> substitutions = new Dictionary<string, int>();
var substitutions = new Dictionary<string, int>();
substitutions.Add("WINDOW_RIGHT", Game.viewport.Width);
substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height);
substitutions.Add("PARENT_RIGHT", parentBounds.Width);

View File

@@ -18,7 +18,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.FileFormats;
using OpenRA.Widgets;

View File

@@ -18,12 +18,11 @@
*/
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.Traits;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Widgets
{
@@ -33,10 +32,6 @@ namespace OpenRA.Widgets
public WorldTooltipWidget() : base() { }
public WorldTooltipWidget(Widget other) : base(other) { }
public override Widget Clone() { return new WorldTooltipWidget(this); }
public override void DrawInner(World world)
{
if (Game.chrome.ticksSinceLastMove < worldTooltipDelay || world == null || world.LocalPlayer == null)
@@ -80,7 +75,9 @@ namespace OpenRA.Widgets
renderer.RegularFont.DrawText(text3,
new float2(Game.chrome.lastMousePos.X + 65 + sz2.X, Game.chrome.lastMousePos.Y + 50), Color.White);
WidgetUtils.DrawRGBA(ChromeProvider.GetImage(Game.chrome.renderer, "flags", actor.Owner.Country.Race), new float2(Game.chrome.lastMousePos.X + 30, Game.chrome.lastMousePos.Y + 50));
WidgetUtils.DrawRGBA(
ChromeProvider.GetImage(Game.chrome.renderer, "flags", actor.Owner.Country.Race),
new float2(Game.chrome.lastMousePos.X + 30, Game.chrome.lastMousePos.Y + 50));
}
renderer.RgbaSpriteRenderer.Flush();