/// <summary> /// Injects power control UI into the window menu for electricity consumers and producers. /// </summary> public static void ClientTryInjectPowerSwitchUI( IStaticWorldObject worldObject, BaseUserControlWithWindow window) { if (worldObject.ProtoStaticWorldObject is IProtoObjectElectricityConsumer protoConsumer && protoConsumer.ElectricityConsumptionPerSecondWhenActive > 0 || worldObject.ProtoStaticWorldObject is IProtoObjectElectricityProducer) { // consumer or producer object }
public static void Register( IStaticWorldObject worldObject, BaseUserControlWithWindow menu, Action onMenuClosedByClient) { Unregister(worldObject); Action handler = () => { if (Unregister(worldObject)) { onMenuClosedByClient(); } }; menu.EventWindowClosing += handler; RegisteredWindows[worldObject] = new Token(menu, handler); }
public static void RegisterMenuWindow(BaseUserControlWithWindow menuWindow) { TryCloseCurrentMenu(); currentMenuWindow = menuWindow; menuWindow.EventWindowClosing += CloseHandler; menuWindow.EventWindowClosed += CloseHandler; void CloseHandler() { menuWindow.EventWindowClosing -= CloseHandler; menuWindow.EventWindowClosed -= CloseHandler; if (ReferenceEquals(currentMenuWindow, menuWindow)) { currentMenuWindow = null; isOpened = false; MenuInstance.IsOpenedChanged?.Invoke(); } } }
public Token(BaseUserControlWithWindow menu, Action handler) { this.Menu = new WeakReference <BaseUserControlWithWindow>(menu); this.Handler = handler; }