Ejemplo n.º 1
0
 /// <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);
        }
Ejemplo n.º 3
0
        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;
 }