eradicate 'delegate' misuse

This commit is contained in:
Chris Forbes
2011-05-22 21:58:39 +12:00
parent 4b12a19af0
commit ef03d46f13
72 changed files with 234 additions and 269 deletions

View File

@@ -12,7 +12,7 @@ using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Widgets.Delegates;
using OpenRA.Mods.RA.Widgets.Logic;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA
public void AdjustPalette(Dictionary<string, Palette> palettes)
{
palettes["colorpicker"] = new Palette(palettes["colorpicker"],
new PlayerColorRemap(LobbyDelegate.CurrentColorPreview, format));
new PlayerColorRemap(LobbyLogic.CurrentColorPreview, format));
}
}
}

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -260,9 +260,9 @@
<Compile Include="WaterPaletteRotation.cs" />
<Compile Include="Weapon.cs" />
<Compile Include="Widgets\BuildPaletteWidget.cs" />
<Compile Include="Widgets\Delegates\IngameObserverChromeDelegate.cs" />
<Compile Include="Widgets\Delegates\IngameChromeDelegate.cs" />
<Compile Include="Widgets\Delegates\ReplayBrowserDelegate.cs" />
<Compile Include="Widgets\Logic\IngameObserverChromeLogic.cs" />
<Compile Include="Widgets\Logic\IngameChromeLogic.cs" />
<Compile Include="Widgets\Logic\ReplayBrowserLogic.cs" />
<Compile Include="Widgets\MoneyBinWidget.cs" />
<Compile Include="Widgets\OrderButtonWidget.cs" />
<Compile Include="Widgets\PowerBinWidget.cs" />
@@ -277,7 +277,7 @@
<Compile Include="Invulnerable.cs" />
<Compile Include="ReplaceWithActor.cs" />
<Compile Include="StoresOre.cs" />
<Compile Include="Widgets\Delegates\OrderButtonsChromeDelegate.cs" />
<Compile Include="Widgets\Logic\OrderButtonsChromeLogic.cs" />
<Compile Include="RadarColorFromTerrain.cs" />
<Compile Include="EngineerRepair.cs" />
<Compile Include="Activities\RepairBuilding.cs" />
@@ -308,17 +308,17 @@
<Compile Include="ServerTraits\LobbyCommands.cs" />
<Compile Include="Scripting\RASpecialPowers.cs" />
<Compile Include="PaletteFromCurrentTileset.cs" />
<Compile Include="Widgets\Delegates\ConnectionDialogsDelegate.cs" />
<Compile Include="Widgets\Delegates\CreateServerMenuDelegate.cs" />
<Compile Include="Widgets\Delegates\DeveloperModeDelegate.cs" />
<Compile Include="Widgets\Delegates\DiplomacyDelegate.cs" />
<Compile Include="Widgets\Delegates\LobbyDelegate.cs" />
<Compile Include="Widgets\Delegates\MainMenuButtonsDelegate.cs" />
<Compile Include="Widgets\Delegates\MapChooserDelegate.cs" />
<Compile Include="Widgets\Delegates\MusicPlayerDelegate.cs" />
<Compile Include="Widgets\Delegates\PerfDebugDelegate.cs" />
<Compile Include="Widgets\Delegates\ServerBrowserDelegate.cs" />
<Compile Include="Widgets\Delegates\SettingsMenuDelegate.cs" />
<Compile Include="Widgets\Logic\ConnectionDialogsLogic.cs" />
<Compile Include="Widgets\Logic\CreateServerMenuLogic.cs" />
<Compile Include="Widgets\Logic\DeveloperModeLogic.cs" />
<Compile Include="Widgets\Logic\DiplomacyLogic.cs" />
<Compile Include="Widgets\Logic\LobbyLogic.cs" />
<Compile Include="Widgets\Logic\MainMenuButtonsLogic.cs" />
<Compile Include="Widgets\Logic\MapChooserLogic.cs" />
<Compile Include="Widgets\Logic\MusicPlayerLogic.cs" />
<Compile Include="Widgets\Logic\PerfDebugLogic.cs" />
<Compile Include="Widgets\Logic\ServerBrowserLogic.cs" />
<Compile Include="Widgets\Logic\SettingsMenuLogic.cs" />
<Compile Include="TargetableSubmarine.cs" />
<Compile Include="Effects\RallyPoint.cs" />
<Compile Include="AttackMedic.cs" />
@@ -328,7 +328,7 @@
<Compile Include="Buildings\SoundOnDamageTransition.cs" />
<Compile Include="Activities\RAHarvesterDockSequence.cs" />
<Compile Include="Widgets\GameInitInfoWidget.cs" />
<Compile Include="Widgets\Delegates\GameInitDelegate.cs" />
<Compile Include="Widgets\Logic\GameInitLogic.cs" />
<Compile Include="AttackWander.cs" />
<Compile Include="ScaredyCat.cs" />
<Compile Include="Widgets\SidebarButtonWidget.cs" />

View File

@@ -157,7 +157,6 @@ namespace OpenRA.Mods.RA.Widgets
return DoBuildingHotkey(e.KeyName, world);
}
// TODO: BuildPaletteWidget doesn't support delegate methods for mouse input
public override bool HandleMouseInput(MouseInput mi)
{
if (mi.Event != MouseInputEvent.Down)

View File

@@ -9,9 +9,6 @@
#endregion
using OpenRA.Widgets;
using System;
using OpenRA.Mods.RA.Widgets.Delegates;
using System.IO;
namespace OpenRA.Mods.RA.Widgets
{

View File

@@ -11,12 +11,12 @@
using OpenRA.Network;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class ConnectionDialogsDelegate : IWidgetDelegate
public class ConnectionDialogsLogic
{
[ObjectCreator.UseCtor]
public ConnectionDialogsDelegate(
public ConnectionDialogsLogic(
[ObjectCreator.Param] Widget widget,
[ObjectCreator.Param] string host,
[ObjectCreator.Param] int port )
@@ -35,10 +35,10 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
}
}
public class ConnectionFailedDelegate : IWidgetDelegate
public class ConnectionFailedLogic
{
[ObjectCreator.UseCtor]
public ConnectionFailedDelegate(
public ConnectionFailedLogic(
[ObjectCreator.Param] Widget widget,
[ObjectCreator.Param] OrderManager orderManager)
{

View File

@@ -13,12 +13,12 @@ using System.Net;
using OpenRA.Widgets;
using OpenRA.GameRules;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class CreateServerMenuDelegate : IWidgetDelegate
public class CreateServerMenuLogic
{
[ObjectCreator.UseCtor]
public CreateServerMenuDelegate( [ObjectCreator.Param( "widget" )] Widget cs )
public CreateServerMenuLogic( [ObjectCreator.Param( "widget" )] Widget cs )
{
var settings = Game.Settings;

View File

@@ -23,12 +23,12 @@ using OpenRA;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class DeveloperModeDelegate : IWidgetDelegate
public class DeveloperModeLogic
{
[ObjectCreator.UseCtor]
public DeveloperModeDelegate( [ObjectCreator.Param] World world )
public DeveloperModeLogic( [ObjectCreator.Param] World world )
{
var devmodeBG = Widget.RootWidget.GetWidget("INGAME_ROOT").GetWidget("DEVELOPERMODE_BG");
var devModeButton = Widget.RootWidget.GetWidget<ButtonWidget>("INGAME_DEVELOPERMODE_BUTTON");

View File

@@ -15,9 +15,9 @@ using System.Linq;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class DiplomacyDelegate : IWidgetDelegate
public class DiplomacyLogic
{
static List<Widget> controls = new List<Widget>();
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
readonly World world;
[ObjectCreator.UseCtor]
public DiplomacyDelegate( [ObjectCreator.Param] World world )
public DiplomacyLogic( [ObjectCreator.Param] World world )
{
this.world = world;
var root = Widget.RootWidget.GetWidget("INGAME_ROOT");

View File

@@ -17,51 +17,49 @@ using OpenRA.FileFormats;
using OpenRA.Network;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class GameInitDelegate : IWidgetDelegateEx
public class GameInitLogic : ILogicWithInit
{
GameInitInfoWidget Info;
[ObjectCreator.UseCtor]
public GameInitDelegate([ObjectCreator.Param] Widget widget)
public GameInitLogic([ObjectCreator.Param] Widget widget)
{
Info = (widget as GameInitInfoWidget);
}
public void Init()
{
if (Info.InstallMode != "cnc")
{
Game.ConnectionStateChanged += orderManager =>
{
Widget.CloseWindow();
switch (orderManager.Connection.ConnectionState)
{
case ConnectionState.PreConnecting:
Widget.LoadWidget("MAINMENU_BG", Widget.RootWidget, new WidgetArgs());
break;
case ConnectionState.Connecting:
Widget.OpenWindow("CONNECTING_BG",
new WidgetArgs() { { "host", orderManager.Host }, { "port", orderManager.Port } });
break;
case ConnectionState.NotConnected:
Widget.OpenWindow("CONNECTION_FAILED_BG",
new WidgetArgs() { { "orderManager", orderManager } });
break;
case ConnectionState.Connected:
var lobby = Game.OpenWindow(orderManager.world, "SERVER_LOBBY");
lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true;
lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true;
lobby.GetWidget("ALLOWCHEATS_CHECKBOX").Visible = true;
lobby.GetWidget("DISCONNECT_BUTTON").Visible = true;
break;
}
};
}
void ILogicWithInit.Init()
{
Game.ConnectionStateChanged += orderManager =>
{
Widget.CloseWindow();
switch (orderManager.Connection.ConnectionState)
{
case ConnectionState.PreConnecting:
Widget.LoadWidget("MAINMENU_BG", Widget.RootWidget, new WidgetArgs());
break;
case ConnectionState.Connecting:
Widget.OpenWindow("CONNECTING_BG",
new WidgetArgs() { { "host", orderManager.Host }, { "port", orderManager.Port } });
break;
case ConnectionState.NotConnected:
Widget.OpenWindow("CONNECTION_FAILED_BG",
new WidgetArgs() { { "orderManager", orderManager } });
break;
case ConnectionState.Connected:
var lobby = Game.OpenWindow(orderManager.world, "SERVER_LOBBY");
lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true;
lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true;
lobby.GetWidget("ALLOWCHEATS_CHECKBOX").Visible = true;
lobby.GetWidget("DISCONNECT_BUTTON").Visible = true;
break;
}
};
TestAndContinue();
}
}
void TestAndContinue()
{
@@ -76,7 +74,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
}
else
{
MainMenuButtonsDelegate.DisplayModSelector();
MainMenuButtonsLogic.DisplayModSelector();
ShowInstallMethodDialog();
}
}

View File

@@ -11,12 +11,12 @@
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class IngameChromeDelegate : IWidgetDelegate
public class IngameChromeLogic
{
[ObjectCreator.UseCtor]
public IngameChromeDelegate( [ObjectCreator.Param] World world )
public IngameChromeLogic( [ObjectCreator.Param] World world )
{
var r = Widget.RootWidget;
var gameRoot = r.GetWidget("INGAME_ROOT");

View File

@@ -11,12 +11,12 @@
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class IngameObserverChromeDelegate : IWidgetDelegate
public class IngameObserverChromeLogic
{
[ObjectCreator.UseCtor]
public IngameObserverChromeDelegate([ObjectCreator.Param] World world)
public IngameObserverChromeLogic([ObjectCreator.Param] World world)
{
var r = Widget.RootWidget;
var gameRoot = r.GetWidget("OBSERVER_ROOT");

View File

@@ -13,14 +13,14 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Network;
using OpenRA.Traits;
using OpenRA.Widgets;
using OpenRA.Graphics;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class LobbyDelegate : IWidgetDelegate
public class LobbyLogic
{
Widget LocalPlayerTemplate, RemotePlayerTemplate, EmptySlotTemplate, EmptySlotTemplateHost;
ScrollPanelWidget Players;
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
readonly OrderManager orderManager;
readonly WorldRenderer worldRenderer;
[ObjectCreator.UseCtor]
internal LobbyDelegate( [ObjectCreator.Param( "widget" )] Widget lobby, [ObjectCreator.Param] OrderManager orderManager, [ObjectCreator.Param] WorldRenderer worldRenderer)
internal LobbyLogic( [ObjectCreator.Param( "widget" )] Widget lobby, [ObjectCreator.Param] OrderManager orderManager, [ObjectCreator.Param] WorldRenderer worldRenderer)
{
this.orderManager = orderManager;
this.worldRenderer = worldRenderer;

View File

@@ -17,12 +17,12 @@ using System;
using System.Drawing;
using System.Linq;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class MainMenuButtonsDelegate : IWidgetDelegate
public class MainMenuButtonsLogic
{
[ObjectCreator.UseCtor]
public MainMenuButtonsDelegate([ObjectCreator.Param] Widget widget)
public MainMenuButtonsLogic([ObjectCreator.Param] Widget widget)
{
Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Widget.RootWidget, "PERF_BG" );
widget.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp = mi => { Widget.OpenWindow("JOINSERVER_BG"); return true; };

View File

@@ -15,16 +15,16 @@ using OpenRA.Network;
using OpenRA.Widgets;
using System.IO;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class MapChooserDelegate : IWidgetDelegate
public class MapChooserLogic
{
Map Map = null;
Widget scrollpanel;
ScrollItemWidget itemTemplate;
[ObjectCreator.UseCtor]
internal MapChooserDelegate(
internal MapChooserLogic(
[ObjectCreator.Param( "widget" )] Widget bg,
[ObjectCreator.Param] OrderManager orderManager,
[ObjectCreator.Param] string mapName )

View File

@@ -14,12 +14,12 @@ using OpenRA.FileFormats;
using OpenRA.Support;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class MusicPlayerDelegate : IWidgetDelegate
public class MusicPlayerLogic
{
string CurrentSong = null;
public MusicPlayerDelegate()
public MusicPlayerLogic()
{
var bg = Widget.RootWidget.GetWidget("MUSIC_MENU");
CurrentSong = GetNextSong();

View File

@@ -12,12 +12,12 @@ using OpenRA;
using OpenRA.Mods.RA.Orders;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class OrderButtonsChromeDelegate : IWidgetDelegate
public class OrderButtonsChromeLogic
{
[ObjectCreator.UseCtor]
public OrderButtonsChromeDelegate( [ObjectCreator.Param] World world )
public OrderButtonsChromeLogic( [ObjectCreator.Param] World world )
{
var r = Widget.RootWidget;
var gameRoot = r.GetWidget("INGAME_ROOT");

View File

@@ -11,11 +11,11 @@
using OpenRA.Support;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class PerfDebugDelegate : IWidgetDelegate
public class PerfDebugLogic
{
public PerfDebugDelegate()
public PerfDebugLogic()
{
var r = Widget.RootWidget;
var perfRoot = r.GetWidget("PERF_BG");

View File

@@ -16,14 +16,14 @@ using OpenRA.FileFormats;
using OpenRA.Network;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class ReplayBrowserDelegate : IWidgetDelegate
public class ReplayBrowserLogic
{
Widget widget;
[ObjectCreator.UseCtor]
public ReplayBrowserDelegate( [ObjectCreator.Param] Widget widget )
public ReplayBrowserLogic( [ObjectCreator.Param] Widget widget )
{
this.widget = widget;

View File

@@ -12,12 +12,11 @@ using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Network;
using OpenRA.Server;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class ServerBrowserDelegate : IWidgetDelegate
public class ServerBrowserLogic
{
static List<Widget> GameButtons = new List<Widget>();
@@ -25,7 +24,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
ScrollItemWidget ServerTemplate;
[ObjectCreator.UseCtor]
public ServerBrowserDelegate( [ObjectCreator.Param] Widget widget )
public ServerBrowserLogic( [ObjectCreator.Param] Widget widget )
{
var bg = widget.GetWidget("JOINSERVER_BG");
@@ -170,10 +169,10 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
}
public class DirectConnectDelegate : IWidgetDelegate
public class DirectConnectLogic
{
[ObjectCreator.UseCtor]
public DirectConnectDelegate( [ObjectCreator.Param] Widget widget )
public DirectConnectLogic( [ObjectCreator.Param] Widget widget )
{
var dc = widget.GetWidget("DIRECTCONNECT_BG");

View File

@@ -13,12 +13,12 @@ using OpenRA.FileFormats.Graphics;
using OpenRA.GameRules;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Delegates
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class SettingsMenuDelegate : IWidgetDelegate
public class SettingsMenuLogic
{
Widget bg;
public SettingsMenuDelegate()
public SettingsMenuLogic()
{
bg = Widget.RootWidget.GetWidget<BackgroundWidget>("SETTINGS_MENU");
var tabs = bg.GetWidget<ContainerWidget>("TAB_CONTAINER");

View File

@@ -7,6 +7,7 @@
* see COPYING.
*/
#endregion
using System;
using System.Drawing;
using System.Linq;
@@ -84,7 +85,6 @@ namespace OpenRA.Mods.RA.Widgets
return CursorProvider.HasCursorSequence(cursor+"-minimap") ? cursor+"-minimap" : cursor;
}
// TODO: RadarBinWidget doesn't support delegate methods for mouse input
public override bool HandleMouseInput(MouseInput mi)
{
if (!hasRadar || radarAnimating) return false; // we're not set up for this.

View File

@@ -11,7 +11,6 @@ using System;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets
@@ -85,7 +84,6 @@ namespace OpenRA.Mods.RA.Widgets
return CursorProvider.HasCursorSequence(cursor+"-minimap") ? cursor+"-minimap" : cursor;
}
// TODO: RadarWidget doesn't support delegate methods for mouse input
public override bool HandleMouseInput(MouseInput mi)
{
if (!hasRadar || Animating) return false;

View File

@@ -54,7 +54,6 @@ namespace OpenRA.Mods.RA.Widgets
get { return buttons.Any() ? buttons.Select(b => b.First).Aggregate(Rectangle.Union) : Bounds; }
}
// TODO: SpecialPowerBin doesn't support delegate methods for mouse input
public override bool HandleMouseInput(MouseInput mi)
{
if (mi.Event == MouseInputEvent.Down)