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( Preview = Lazy.New(
() => { return new Bitmap(Package.GetContent("preview.png")); } () => new Bitmap(Package.GetContent("preview.png"))
); );
Uid = Package.GetContent("map.uid").ReadAllText(); Uid = Package.GetContent("map.uid").ReadAllText();

View File

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

View File

@@ -1,10 +1,29 @@
using System; #region Copyright & License Information
using System.Collections.Generic; /*
* 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.Linq;
using System.Text;
using System.Net; using System.Net;
using OpenRA.FileFormats; using System.Text;
using System.Threading; using System.Threading;
using OpenRA.FileFormats;
namespace OpenRA.Server namespace OpenRA.Server
{ {

View File

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

View File

@@ -18,15 +18,14 @@
*/ */
#endregion #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;
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 namespace OpenRA.Widgets
{ {
@@ -53,14 +52,6 @@ namespace OpenRA.Widgets
public BuildPaletteWidget() : base() { } 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() public override void Initialize()
{ {
base.Initialize(); base.Initialize();

View File

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

View File

@@ -18,12 +18,9 @@
*/ */
#endregion #endregion
using OpenRA.FileFormats;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Text;
using System;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
@@ -37,7 +34,7 @@ namespace OpenRA.Widgets
public ChatDisplayWidget() public ChatDisplayWidget()
: base() { } : base() { }
public ChatDisplayWidget(Widget widget) protected ChatDisplayWidget(Widget widget)
: base(widget) { } : base(widget) { }
public override void DrawInner(World world) public override void DrawInner(World world)
@@ -74,11 +71,13 @@ namespace OpenRA.Widgets
while (recentLines.Count > logLength) recentLines.RemoveAt(0); while (recentLines.Count > logLength) recentLines.RemoveAt(0);
} }
public override Widget Clone() public override Widget Clone() { return new ChatDisplayWidget(this); }
{
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(); Game.chrome.lineRenderer.Flush();
} }
} }
public override bool HandleInput(MouseInput mi) { return true; } public override bool HandleInput(MouseInput mi) { return true; }
public CheckboxWidget() : base() { } public CheckboxWidget() : base() { }
public CheckboxWidget(Widget other) protected CheckboxWidget(CheckboxWidget other)
: base(other) : base(other)
{ {
Text = (other as CheckboxWidget).Text; Text = other.Text;
Checked = (other as CheckboxWidget).Checked; Checked = other.Checked;
} }
public override Widget Clone() { return new CheckboxWidget(this); } public override Widget Clone() { return new CheckboxWidget(this); }

View File

@@ -33,10 +33,10 @@ namespace OpenRA.Widgets
GetColor = () => Color.White; GetColor = () => Color.White;
} }
public ColorBlockWidget(Widget widget) protected ColorBlockWidget(ColorBlockWidget widget)
: base(widget) : base(widget)
{ {
GetColor = (widget as ColorBlockWidget).GetColor; GetColor = widget.GetColor;
} }
public override Widget Clone() public override Widget Clone()
@@ -47,7 +47,8 @@ namespace OpenRA.Widgets
public override void DrawInner(World world) public override void DrawInner(World world)
{ {
var pos = RenderOrigin; 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()); 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing; using System.Drawing;
using System.Linq;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Widgets.Delegates namespace OpenRA.Widgets.Delegates

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -18,25 +18,24 @@ namespace OpenRA.Widgets
GetImageCollection = () => { return ImageCollection; }; GetImageCollection = () => { return ImageCollection; };
} }
public ImageWidget(Widget other) protected ImageWidget(ImageWidget other)
: base(other) : base(other)
{ {
ImageName = (other as ImageWidget).ImageName; ImageName = other.ImageName;
GetImageName = (other as ImageWidget).GetImageName; GetImageName = other.GetImageName;
ImageCollection = (other as ImageWidget).ImageCollection; ImageCollection = other.ImageCollection;
GetImageCollection = (other as ImageWidget).GetImageCollection; GetImageCollection = other.GetImageCollection;
} }
public override Widget Clone() public override Widget Clone() { return new ImageWidget(this); }
{
return new ImageWidget(this);
}
public override void DrawInner(World world) public override void DrawInner(World world)
{ {
var name = GetImageName(); var name = GetImageName();
var collection = GetImageCollection(); 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 #endregion
using System.Drawing;
using System; using System;
using System.Drawing;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
class LabelWidget : Widget class LabelWidget : Widget
{ {
public enum TextAlign public enum TextAlign { Left, Center, Right }
{
Left,
Center,
Right
}
public string Text = null; public string Text = null;
public string Background = null; public string Background = null;
@@ -46,14 +41,14 @@ namespace OpenRA.Widgets
GetBackground = () => { return Background; }; GetBackground = () => { return Background; };
} }
public LabelWidget(Widget other) protected LabelWidget(LabelWidget other)
: base(other) : base(other)
{ {
Text = (other as LabelWidget).Text; Text = other.Text;
Align = (other as LabelWidget).Align; Align = other.Align;
Bold = (other as LabelWidget).Bold; Bold = other.Bold;
GetText = (other as LabelWidget).GetText; GetText = other.GetText;
GetBackground = (other as LabelWidget).GetBackground; GetBackground = other.GetBackground;
} }
public override void DrawInner(World world) public override void DrawInner(World world)
@@ -80,9 +75,6 @@ namespace OpenRA.Widgets
font.DrawText(text, position, Color.White); font.DrawText(text, position, Color.White);
} }
public override Widget Clone() public override Widget Clone() { return new LabelWidget(this); }
{
return new LabelWidget(this);
}
} }
} }

View File

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

View File

@@ -1,10 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRA.Graphics;
using System.Drawing; using System.Drawing;
using System.Linq;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Graphics;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
@@ -15,24 +14,25 @@ namespace OpenRA.Widgets
bool mapPreviewDirty = true; bool mapPreviewDirty = true;
MapStub lastMap; MapStub lastMap;
public Func<MapStub> Map = () => {return null;}; public Func<MapStub> Map = () => null;
public Action<int> OnSpawnClick = spawn => {}; 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() : base() { }
public MapPreviewWidget(Widget other) protected MapPreviewWidget(MapPreviewWidget other)
: base(other) : base(other)
{ {
lastMap = (other as MapPreviewWidget).lastMap; lastMap = other.lastMap;
Map = (other as MapPreviewWidget).Map; Map = other.Map;
OnSpawnClick = (other as MapPreviewWidget).OnSpawnClick; OnSpawnClick = other.OnSpawnClick;
SpawnColors = (other as MapPreviewWidget).SpawnColors; SpawnColors = other.SpawnColors;
} }
static Sprite UnownedSpawn = null; static Sprite UnownedSpawn = null;
static Sprite OwnedSpawn = null; static Sprite OwnedSpawn = null;
const int closeEnough = 50; const int closeEnough = 50;
public override bool HandleInput(MouseInput mi) public override bool HandleInput(MouseInput mi)
{ {
var map = Map(); 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)); } void AddButton(Rectangle r, Action<MouseInput> b) { buttons.Add(Pair.New(r, b)); }
public MoneyBinWidget() : base() { } public MoneyBinWidget() : base() { }
public MoneyBinWidget(Widget other) : base(other) { } protected MoneyBinWidget(Widget other) : base(other) { }
public override Widget Clone() { return new MoneyBinWidget(this); } 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/>. * along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/ */
#endregion #endregion
using System.Drawing; using System.Drawing;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Support; using OpenRA.Support;
@@ -28,10 +28,6 @@ namespace OpenRA.Widgets
{ {
public PerfGraphWidget() : base() { } public PerfGraphWidget() : base() { }
public PerfGraphWidget(Widget other) : base(other) { }
public override Widget Clone() { return new PerfGraphWidget(this); }
public override void DrawInner(World world) public override void DrawInner(World world)
{ {
var rect = RenderBounds; var rect = RenderBounds;

View File

@@ -28,10 +28,6 @@ namespace OpenRA.Widgets
{ {
public PostGameWidget() : base() { } 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; } 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. // todo: all this shit needs to move, probably to Player.

View File

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

View File

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

View File

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

View File

@@ -18,14 +18,14 @@
*/ */
#endregion #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;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
class SpecialPowerBinWidget : Widget class SpecialPowerBinWidget : Widget
@@ -37,16 +37,6 @@ namespace OpenRA.Widgets
public SpecialPowerBinWidget() : base() { } 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() public override void Initialize()
{ {
base.Initialize(); base.Initialize();

View File

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

View File

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

View File

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

View File

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