From 429821f6c49f69dbd8e421b1c8a27d65ee45c2ff Mon Sep 17 00:00:00 2001 From: alzeih Date: Sat, 24 Apr 2010 20:14:33 +1200 Subject: [PATCH] copy constructors --- OpenRA.Game/Widgets/BackgroundWidget.cs | 11 +++++++++++ OpenRA.Game/Widgets/BuildPaletteWidget.cs | 10 ++++++++++ OpenRA.Game/Widgets/MapPreviewWidget.cs | 10 ++++++++++ OpenRA.Game/Widgets/MoneyBinWidget.cs | 5 +++++ OpenRA.Game/Widgets/PerfGraphWidget.cs | 6 ++++++ OpenRA.Game/Widgets/PostGameWidget.cs | 8 +++++++- OpenRA.Game/Widgets/RadarBinWidget.cs | 13 ++++++++++++- OpenRA.Game/Widgets/SpecialPowerBinWidget.cs | 12 ++++++++++++ OpenRA.Game/Widgets/Widget.cs | 15 +++++++++------ OpenRA.Game/Widgets/WorldTooltipWidget.cs | 8 +++++++- 10 files changed, 89 insertions(+), 9 deletions(-) diff --git a/OpenRA.Game/Widgets/BackgroundWidget.cs b/OpenRA.Game/Widgets/BackgroundWidget.cs index aca11260ca..81cdc9990a 100644 --- a/OpenRA.Game/Widgets/BackgroundWidget.cs +++ b/OpenRA.Game/Widgets/BackgroundWidget.cs @@ -24,6 +24,7 @@ namespace OpenRA.Widgets class BackgroundWidget : Widget { public readonly string Background = "dialog"; + public override void Draw(World world) { if (!IsVisible()) @@ -36,5 +37,15 @@ namespace OpenRA.Widgets WidgetUtils.DrawPanel(Background, rect); base.Draw(world); } + + public BackgroundWidget() : base() { } + + public BackgroundWidget(Widget other) + : base(other) + { + Background = (other as BackgroundWidget).Background; + } + + public override Widget Clone() { return new BackgroundWidget(this); } } } \ No newline at end of file diff --git a/OpenRA.Game/Widgets/BuildPaletteWidget.cs b/OpenRA.Game/Widgets/BuildPaletteWidget.cs index 505b95d8e4..f84d67344c 100644 --- a/OpenRA.Game/Widgets/BuildPaletteWidget.cs +++ b/OpenRA.Game/Widgets/BuildPaletteWidget.cs @@ -50,7 +50,17 @@ namespace OpenRA.Widgets Animation ready; Animation clock; List visibleTabs = new List(); + + 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(); diff --git a/OpenRA.Game/Widgets/MapPreviewWidget.cs b/OpenRA.Game/Widgets/MapPreviewWidget.cs index 66a3390669..f5e073902a 100755 --- a/OpenRA.Game/Widgets/MapPreviewWidget.cs +++ b/OpenRA.Game/Widgets/MapPreviewWidget.cs @@ -14,6 +14,16 @@ namespace OpenRA.Widgets Sprite mapChooserSprite; bool mapPreviewDirty = true; MapStub lastMap; + + public MapPreviewWidget() : base() { } + + public MapPreviewWidget(Widget other) + : base(other) + { + lastMap = (other as MapPreviewWidget).lastMap; + } + + public override Widget Clone() { return new MapPreviewWidget(this); } public override void Draw( World world ) { diff --git a/OpenRA.Game/Widgets/MoneyBinWidget.cs b/OpenRA.Game/Widgets/MoneyBinWidget.cs index bfb3e8979c..ac8ed7ac7b 100644 --- a/OpenRA.Game/Widgets/MoneyBinWidget.cs +++ b/OpenRA.Game/Widgets/MoneyBinWidget.cs @@ -35,7 +35,12 @@ namespace OpenRA.Widgets /* legacy crap!!! */ List>> buttons = new List>>(); void AddButton(Rectangle r, Action b) { buttons.Add(Pair.New(r, b)); } + + public MoneyBinWidget() : base() { } + public MoneyBinWidget(Widget other) : base(other) { } + public override Widget Clone() { return new MoneyBinWidget(this); } + public override void Draw(World world) { var digitCollection = "digits-" + world.LocalPlayer.Country.Race; diff --git a/OpenRA.Game/Widgets/PerfGraphWidget.cs b/OpenRA.Game/Widgets/PerfGraphWidget.cs index 7b4d788e73..116055148a 100644 --- a/OpenRA.Game/Widgets/PerfGraphWidget.cs +++ b/OpenRA.Game/Widgets/PerfGraphWidget.cs @@ -26,6 +26,12 @@ namespace OpenRA.Widgets { class PerfGraphWidget : Widget { + public PerfGraphWidget() : base() { } + + public PerfGraphWidget(Widget other) : base(other) { } + + public override Widget Clone() { return new PerfGraphWidget(this); } + public override void Draw(World world) { if (!IsVisible()) diff --git a/OpenRA.Game/Widgets/PostGameWidget.cs b/OpenRA.Game/Widgets/PostGameWidget.cs index f0b42aff41..99de63400b 100644 --- a/OpenRA.Game/Widgets/PostGameWidget.cs +++ b/OpenRA.Game/Widgets/PostGameWidget.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,6 +9,12 @@ namespace OpenRA.Widgets { class PostGameWidget : Widget { + public PostGameWidget() : base() { } + + public PostGameWidget(Widget other) : base(other) { } + + public override Widget Clone() { return new PostGameWidget(this); } + public override void Draw(World world) { base.Draw(world); diff --git a/OpenRA.Game/Widgets/RadarBinWidget.cs b/OpenRA.Game/Widgets/RadarBinWidget.cs index ac41e9bf77..6ef9b09269 100644 --- a/OpenRA.Game/Widgets/RadarBinWidget.cs +++ b/OpenRA.Game/Widgets/RadarBinWidget.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#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. @@ -47,6 +47,17 @@ namespace OpenRA.Widgets float? lastPowerDrainedPos; string radarCollection; + + public RadarBinWidget() : base() { } + + public RadarBinWidget(Widget other) + : base(other) + { + throw new NotImplementedException("Why are you Cloning RadarBin?"); + } + + public override Widget Clone() { return new RadarBinWidget(this); } + public override void Draw(World world) { diff --git a/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs b/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs index e35532e42d..b598076d3a 100644 --- a/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs +++ b/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs @@ -35,6 +35,18 @@ namespace OpenRA.Widgets Animation clock; readonly List>> buttons = new List>>(); + 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(); diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 52493cbc60..cd511331c6 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -27,7 +27,7 @@ using OpenRA.Widgets.Delegates; namespace OpenRA.Widgets { - public class Widget + public abstract class Widget { // Info defined in YAML public string Id = null; @@ -78,10 +78,7 @@ namespace OpenRA.Widgets AddChild(child.Clone()); } - public virtual Widget Clone() - { - return new Widget(this); - } + public abstract Widget Clone(); public int2 DrawPosition() { @@ -219,6 +216,12 @@ namespace OpenRA.Widgets } } - class ContainerWidget : Widget { } + class ContainerWidget : Widget { + public ContainerWidget() : base() { } + + public ContainerWidget(Widget other) : base(other) { } + + public override Widget Clone() { return new ContainerWidget(this); } + } public interface IWidgetDelegate { } } \ No newline at end of file diff --git a/OpenRA.Game/Widgets/WorldTooltipWidget.cs b/OpenRA.Game/Widgets/WorldTooltipWidget.cs index ba255029ed..92e1fce88e 100644 --- a/OpenRA.Game/Widgets/WorldTooltipWidget.cs +++ b/OpenRA.Game/Widgets/WorldTooltipWidget.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#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. @@ -30,6 +30,12 @@ namespace OpenRA.Widgets { const int worldTooltipDelay = 10; /* ticks */ + public WorldTooltipWidget() : base() { } + + public WorldTooltipWidget(Widget other) : base(other) { } + + public override Widget Clone() { return new WorldTooltipWidget(this); } + public override void Draw(World world) { if (Game.chrome.ticksSinceLastMove < worldTooltipDelay || world == null || world.LocalPlayer == null)