コード例 #1
0
        public static void RegisterWindow(GameWindow window)
        {
            if (window.IsDestroyed)
            {
                throw new Exception("Window is destroyed: " + window);
            }

            if (openedWindows.Contains(window))
            {
                return;
            }

            openedWindows.Add(window);
            BringToFront(window);
            window.Open();

            // ReSharper disable once CanExtractXamlLocalizableStringCSharp
            window.CloseByEscapeKeyInputContext
                = ClientInputContext.Start("Close window")
                  .HandleAll(
                      () =>
            {
                const GameButton button = GameButton.CancelOrClose;
                if (ClientInputManager.IsButtonDown(button) &&
                    window.CloseByEscapeKey)
                {
                    window.Close(DialogResult.Cancel);
                    ClientInputManager.ConsumeButton(button);
                }
            });
        }
コード例 #2
0
        public void Update()
        {
            if (this.IsFrozen ||
                this.IsDestroyed)
            {
                return;
            }

            if (WindowsManager.OpenedWindowsCount > 0)
            {
                // a window is opened - disable all the renderers
                this.DestroyComponents();
                return;
            }

            if (this.delayRemainsSeconds > 0)
            {
                this.delayRemainsSeconds -= Client.Core.DeltaTime;
            }

            var isUpdateRequired = false;

            this.isCanBuildChanged = false;
            if (this.blueprintRenderer == null)
            {
                // first update called
                this.SetupComponents();
                isUpdateRequired = true;
            }

            if (!isUpdateRequired &&
                this.isCancelable)
            {
                if (ClientInputManager.IsButtonDown(GameButton.CancelOrClose) ||
                    ClientInputManager.IsButtonDown(GameButton.ActionInteract))
                {
                    // cancel/quit placement mode by Escape key or interaction (RMB click)
                    ClientInputManager.ConsumeButton(GameButton.CancelOrClose);
                    ClientInputManager.ConsumeButton(GameButton.ActionInteract);
                    this.Destroy();
                    return;
                }
            }

            var tilePosition         = Client.Input.MousePointedTilePosition;
            var tilePositionVector2D = tilePosition.ToVector2D();

            this.cachedTimeRemainsSeconds -= Client.Core.DeltaTime;

            var isCanBuildThisPhase = !isUpdateRequired;

            var isPositionChanged = this.SceneObject.Position != tilePositionVector2D;

            if (isUpdateRequired ||
                isPositionChanged ||
                this.cachedTimeRemainsSeconds <= 0)
            {
                this.SceneObject.Position = tilePositionVector2D;
                this.UpdateBlueprint(tilePosition);

                if (this.isRepeatCallbackIfHeld &&
                    (isPositionChanged ||
                     this.isCanBuildChanged) &&
                    (this.blueprintRenderer?.IsEnabled ?? false) &&
                    ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem))
                {
                    // mouse moved while LMB is held
                    this.OnPlaceSelected(tilePosition, isButtonHeld: true);
                }
            }

            if (isCanBuildThisPhase &&
                (this.blueprintRenderer?.IsEnabled ?? false) &&
                ClientInputManager.IsButtonDown(GameButton.ActionUseCurrentItem))
            {
                // clicked on place
                this.OnPlaceSelected(tilePosition, isButtonHeld: false);
            }
        }