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

@@ -21,30 +21,17 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
Widget ingameRoot;
static CncIngameChromeLogic()
{
Game.AddChatLine += AddChatLineStub;
}
static void AddChatLineStub(Color c, string from, string text)
{
var panel = Widget.RootWidget.GetWidget("INGAME_ROOT");
if (panel == null)
return;
var handler = panel.LogicObject as CncIngameChromeLogic;
if (handler == null)
return;
handler.AddChatLine(c, from, text);
}
void AddChatLine(Color c, string from, string text)
{
ingameRoot.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").AddLine(c, from, text);
}
public void UnregisterEvents()
{
Game.AddChatLine -= AddChatLine;
Game.BeforeGameStart -= UnregisterEvents;
}
[ObjectCreator.UseCtor]
public CncIngameChromeLogic([ObjectCreator.Param] Widget widget,
[ObjectCreator.Param] World world )
@@ -52,6 +39,10 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
world.WorldActor.Trait<CncMenuPaletteEffect>()
.Fade(CncMenuPaletteEffect.EffectType.None);
Game.AddChatLine += AddChatLine;
Game.BeforeGameStart += UnregisterEvents;
ingameRoot = widget.GetWidget("INGAME_ROOT");
if (world.LocalPlayer != null)