Remove static handler crap from widget delegates - Register/unregister events manually (ra & cnc).

This commit is contained in:
Paul Chote
2011-05-30 20:48:19 +12:00
parent add29e845e
commit 2ebb2ae921
6 changed files with 102 additions and 136 deletions

View File

@@ -20,35 +20,17 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
string host;
int port;
static CncConnectingLogic()
{
Game.ConnectionStateChanged += ConnectionStateChangedStub;
}
static void ConnectionStateChangedStub(OrderManager om)
{
var panel = Widget.RootWidget.GetWidget("CONNECTING_PANEL");
if (panel == null)
return;
var handler = panel.LogicObject as CncConnectingLogic;
if (handler == null)
return;
handler.ConnectionStateChanged(om);
}
void ConnectionStateChanged(OrderManager om)
{
if (om.Connection.ConnectionState == ConnectionState.Connected)
{
Widget.CloseWindow();
CloseWindow();
onConnect();
}
else if (om.Connection.ConnectionState == ConnectionState.NotConnected)
{
// Show connection failed dialog
Widget.CloseWindow();
CloseWindow();
Widget.OpenWindow("CONNECTIONFAILED_PANEL", new WidgetArgs()
{
{ "onAbort", onAbort },
@@ -59,6 +41,12 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
}
}
public void CloseWindow()
{
Game.ConnectionStateChanged -= ConnectionStateChanged;
Widget.CloseWindow();
}
[ObjectCreator.UseCtor]
public CncConnectingLogic([ObjectCreator.Param] Widget widget,
[ObjectCreator.Param] string host,
@@ -73,8 +61,10 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
this.onRetry = onRetry;
this.onAbort = onAbort;
Game.ConnectionStateChanged += ConnectionStateChanged;
var panel = widget.GetWidget("CONNECTING_PANEL");
panel.GetWidget<ButtonWidget>("ABORT_BUTTON").OnClick = () => { Widget.CloseWindow(); onAbort(); };
panel.GetWidget<ButtonWidget>("ABORT_BUTTON").OnClick = () => { CloseWindow(); onAbort(); };
widget.GetWidget<LabelWidget>("CONNECTING_DESC").GetText = () =>
"Connecting to {0}:{1}...".F(host, port);