Remove static handler crap from widget delegates - Register/unregister events manually (ra & cnc).
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user