コード例 #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
        private void ClientUpdateCallback()
        {
            if (!ClientInputManager.IsButtonDown(EditorButton.ToggleEditorMode))
            {
                return;
            }

            var currentPlayerCharacter = Client.Characters.CurrentPlayerCharacter;

            if (currentPlayerCharacter is null)
            {
                return;
            }

            // reset focus (workaround for NoesisGUI crash when not focused unloaded control receives OnKeyDown)
            Client.UI.BlurFocus();

            var protoCharacterEditorMode = Api.GetProtoEntity <PlayerCharacterEditorMode>();

            if (currentPlayerCharacter.ProtoCharacter is PlayerCharacterEditorMode)
            {
                // switch to player mode
                EditorActiveToolManager.Deactivate();
                protoCharacterEditorMode
                .CallServer(_ => _.ServerRemote_SwitchToPlayerMode());
            }
            else
            {
                // switch to editor mode
                protoCharacterEditorMode
                .CallServer(_ => _.ServerRemote_SwitchToEditorMode());
            }
        }
コード例 #3
0
        private void Open()
        {
            if (this.isOpened)
            {
                return;
            }

            this.isOpened = true;
            this.UpdateLayout();
            this.storyboardFadeIn?.Begin(this);

            Menu.CloseAll();

            // ReSharper disable once CanExtractXamlLocalizableStringCSharp
            inputContext = ClientInputContext.Start("Respawn menu - intercept all other input")
                           .HandleAll(
                () =>
            {
                if (ClientInputManager.IsButtonDown(GameButton.CancelOrClose))
                {
                    MainMenuOverlay.Toggle();
                }

                ClientInputManager.ConsumeAllButtons();
            });
        }
コード例 #4
0
        public static void Open()
        {
            if (!isClosed)
            {
                return;
            }

            isClosed = false;
            var menu = new MenuCharacterCreation();

            instance = menu;

            Api.Client.UI.LayoutRootChildren.Add(instance);

            Menu.CloseAll();

            // ReSharper disable once CanExtractXamlLocalizableStringCSharp
            inputContext = ClientInputContext.Start("Character creation menu - intercept all other input")
                           .HandleAll(
                () =>
            {
                if (ClientInputManager.IsButtonDown(GameButton.CancelOrClose))
                {
                    MainMenuOverlay.Toggle();
                }

                ClientInputManager.ConsumeAllButtons();
            });
        }
コード例 #5
0
 public override void Update(double deltaTime)
 {
     if (ClientInputManager.IsButtonDown(GameButton.ConstructionMenu))
     {
         ConstructionPlacementSystem.ClientToggleConstructionMenu();
     }
 }
コード例 #6
0
        protected override void OnUpdated()
        {
            base.OnUpdated();

            if (!WorldService.WorldBounds.Contains(this.CurrentMouseTilePosition))
            {
                return;
            }

            var tile = WorldService.GetTile(this.CurrentMouseTilePosition);
            var staticWorldObjects = tile.StaticObjects;

            this.RefreshTooltip(staticWorldObjects);

            if (ClientInputManager.IsButtonDown(EditorButton.EditorDeleteSelectedObjects))
            {
                this.deleteCallback(this.SelectedWorldObjects);
            }

            this.selectedWorldObjects.RemoveWhere(
                worldObject =>
            {
                if (!worldObject.IsDestroyed)
                {
                    return(false);
                }

                this.selectionComponent.Deselect(worldObject);
                return(true);
            });
        }
コード例 #7
0
        private void ProcessInputUpdate()
        {
            if (this.publicState.IsDead)
            {
                // cannot use hotbar items
                this.InputIsUsingItem = false;
                return;
            }

            if (!MainMenuOverlay.IsHidden)
            {
                // cannot use hotbar items - main menu overlay is displayed
                this.InputIsUsingItem = false;
                return;
            }

            const bool evenIfHandled  = true;
            var        isQuickUseItem = (Input.IsKeyHeld(InputKey.Control, evenIfHandled) ||
                                         Input.IsKeyHeld(InputKey.Alt, evenIfHandled)) &&
                                        !(ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem, evenIfHandled) ||
                                          ClientInputManager.IsButtonHeld(GameButton.ActionInteract, evenIfHandled));

            foreach (var pair in KeysMapping)
            {
                if (!ClientInputManager.IsButtonDown(pair.Key))
                {
                    continue;
                }

                // the key was pressed
                var hotbarSlotId = pair.Value;

                if (isQuickUseItem)
                {
                    // try to use an item from the hotbar slot
                    var item = ClientHotbarSelectedItemManager.ContainerHotbar.GetItemAtSlot(hotbarSlotId);
                    ClientItemManagementCases.TryUseItem(item);
                }
                else
                {
                    // select the hotbar slot
                    ClientHotbarSelectedItemManager.SelectedSlotId = hotbarSlotId;
                }

                break;
            }

            var canUseHotbarItems = WindowsManager.OpenedWindowsCount == 0;

            if (!canUseHotbarItems)
            {
                this.InputIsUsingItem = false;
                return;
            }

            this.InputIsUsingItem = ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem);
        }
コード例 #8
0
        public override void Update(double deltaTime)
        {
            var isUpdateRequired = false;

            if (!this.isInitialized)
            {
                // first update called
                this.InititializeBlueprint();
                isUpdateRequired = true;
            }

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

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

            if (isPositionChanged ||
                isUpdateRequired)
            {
                // position changed, update sprite renderer
                this.SceneObject.Position = tilePositionVector2D;
                this.OnPositionChanged();
                this.UpdateBlueprint(tilePosition);
            }

            if (this.isMouseButtonHeld &&
                isPositionChanged &&
                this.isRepeatOnMove)
            {
                // moved mouse while holding key
                this.OnSelected(isRepeat: true);
            }
            else if (ClientInputManager.IsButtonDown(GameButton.ActionUseCurrentItem) ||
                     this.IsReactOnRightMouseButton &&
                     ClientInputManager.IsButtonDown(GameButton.ActionInteract))
            {
                // pressed mouse button
                this.OnSelected(isRepeat: false);
                this.isMouseButtonHeld = true;
            }

            if (ClientInputManager.IsButtonUp(GameButton.ActionUseCurrentItem) ||
                this.IsReactOnRightMouseButton &&
                ClientInputManager.IsButtonUp(GameButton.ActionInteract))
            {
                this.isMouseButtonHeld = false;
                this.inputReleasedCallback?.Invoke();
            }
        }
コード例 #9
0
        private void ProcessInputUpdate()
        {
            if (this.publicState.IsDead)
            {
                // cannot use hotbar items
                this.InputIsUsingItem = false;
                return;
            }

            if (!MainMenuOverlay.IsHidden)
            {
                // cannot use hotbar items - main menu overlay is displayed
                this.InputIsUsingItem = false;
                return;
            }

            var keysMapping = Api.Client.Input.IsKeyHeld(InputKey.Control, evenIfHandled: true)
                                  ? KeysMappingWhileControlKeyHeld
                                  : KeysMapping;

            foreach (var pair in keysMapping)
            {
                if (ClientInputManager.IsButtonDown(pair.Key))
                {
                    // the key was pressed - select according slot
                    ClientHotbarSelectedItemManager.SelectedSlotId = pair.Value;
                    break;
                }
            }

            var canUseHotbarItems = WindowsManager.OpenedWindowsCount == 0;

            if (!canUseHotbarItems)
            {
                this.InputIsUsingItem = false;
                return;
            }

            if (ClientInputManager.IsButtonDown(GameButton.ActionUseCurrentItem))
            {
                this.InputIsUsingItem = true;
            }

            if (ClientInputManager.IsButtonUp(GameButton.ActionUseCurrentItem))
            {
                this.InputIsUsingItem = false;
            }
        }
コード例 #10
0
        protected override void WindowOpening()
        {
            this.suppressInputContext = ClientInputContext
                                        .Start("Window items browser - intercept all other input")
                                        .HandleAll(() =>
            {
                if (ClientInputManager.IsButtonDown(GameButton.CancelOrClose))
                {
                    this.CloseWindow();
                }

                ClientInputManager.ConsumeAllButtons();
            });

            this.DataContext = this.viewModel = new ViewModelWindowEditorItemsBrowser(
                closeCallback: () => this.CloseWindow());
        }
コード例 #11
0
        public ViewModelFeaturesSlideshow()
        {
            this.inputContext = ClientInputContext
                                .Start(nameof(ViewModelFeaturesSlideshow))
                                .HandleAll(
                () =>
            {
                if (ClientInputManager.IsButtonDown(GameButton.CancelOrClose) &&
                    (this.IsCloseButtonVisible
                     // for debug purposes allow to skip the slideshow
                     // in a debug build or when the Shift key is held
                     || Api.Shared.IsDebug ||
                     Api.Client.Input.IsKeyHeld(InputKey.Shift)))
                {
                    this.ExecuteCommandClose();
                }

                ClientInputManager.ConsumeAllButtons();
            });

            this.Entries = FeaturesSlideshowEntries
                           .Entries
                           .Select(e => new ViewModelFeaturesSlideshowEntry(
                                       e.Title,
                                       e.Description,
                                       new TextureResource(e.TextureImagePath)))
                           .ToArray();

            this.IsCloseButtonVisible = FeaturesSlideshow.IsSlideShowFinishedAtLeastOnce;

            if (this.IsCloseButtonVisible)
            {
                this.maxDisplayedEntryIndex = this.Entries.Count - 1;
            }
            else
            {
                this.maxDisplayedEntryIndex = -1;
            }

            this.RefreshNavigationButtons();
        }
コード例 #12
0
        public override void Update(double deltaTime)
        {
            var worldPosition = (Vector2Int)ClientInputManager.MouseWorldPosition;
            var deltaPos      = worldPosition - this.lastWorldPosition;

            this.lastWorldPosition = worldPosition;

            if (ClientInputManager.IsButtonDown(GameButton.ActionUseCurrentItem, evenIfHandled: true) &&
                this.SelectionBounds.Contains(this.lastWorldPosition) &&
                this.IsMouseOverSelectionRectange())
            {
                this.isMouseHeld = true;
                deltaPos         = default;
            }

            if (!this.isMouseHeld)
            {
                return;
            }

            if (ClientInputManager.IsButtonUp(GameButton.ActionUseCurrentItem, evenIfHandled: true))
            {
                this.isMouseHeld = false;
            }

            var isMoved = deltaPos != default;

            if (!isMoved)
            {
                return;
            }

            this.SelectionRectStartPosition
                = (this.SelectionRectStartPosition.ToVector2Int() + deltaPos).ToVector2Ushort();

            this.SelectionRectEndPosition
                = (this.SelectionRectEndPosition.ToVector2Int() + deltaPos).ToVector2Ushort();

            this.UpdateSelectionRectange();
        }
コード例 #13
0
        public static void ClientTryStartAction()
        {
            if (ClientHotbarSelectedItemManager.SelectedItem?.ProtoGameObject
                is not IProtoItemVehicleRepairKit protoItemVehicleRepairKit)
            {
                // no tool is selected
                return;
            }

            if (!ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem))
            {
                // the tool is not currently used
                return;
            }

            var vehicleToRepair = ClientGetObjectToRepairAtCurrentMousePosition(
                showErrorIfNoCompatibleVehicle: ClientInputManager.IsButtonDown(GameButton.ActionUseCurrentItem,
                                                                                evenIfHandled: true));

            if (vehicleToRepair is null)
            {
                return;
            }

            var currentCharacter = Client.Characters.CurrentPlayerCharacter;
            var privateState     = PlayerCharacter.GetPrivateState(currentCharacter);

            if (privateState.CurrentActionState is VehicleRepairActionState actionState &&
                ReferenceEquals(actionState.Vehicle, vehicleToRepair))
            {
                // the same object is already repairing
                return;
            }

            SharedStartAction(currentCharacter, vehicleToRepair);
        }
コード例 #14
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);
            }
        }
コード例 #15
0
        public static void ClientTryStartAction(bool allowReplacingCurrentConstructionAction)
        {
            if (ClientHotbarSelectedItemManager.SelectedItem?.ProtoGameObject
                is not IProtoItemToolToolbox)
            {
                // no tool is selected
                return;
            }

            if (!ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem))
            {
                // the tool is not currently used
                return;
            }

            if (ConstructionPlacementSystem.ClientConstructionCooldownIsWaitingButtonRelease)
            {
                // under cooldown since a structure was placed recently
                return;
            }

            var worldObjects = ClientGetObjectsAtCurrentMousePosition();

            IStaticWorldObject worldObjectToBuildOrRepair = null;

            // find first damaged or incomplete structure there
            foreach (var worldObject in worldObjects)
            {
                if (worldObject.ProtoGameObject is not IProtoObjectStructure protoObjectStructure)
                {
                    continue;
                }

                var maxStructurePointsMax = protoObjectStructure.SharedGetStructurePointsMax(
                    (IStaticWorldObject)worldObject);
                var structurePointsCurrent = worldObject.GetPublicState <StaticObjectPublicState>()
                                             .StructurePointsCurrent;
                if (structurePointsCurrent < maxStructurePointsMax)
                {
                    worldObjectToBuildOrRepair = (IStaticWorldObject)worldObject;
                    break;
                }
            }

            if (worldObjectToBuildOrRepair is null)
            {
                if (ClientInputManager.IsButtonDown(GameButton.ActionUseCurrentItem))
                {
                    var worldObjectToRelocate = ClientFindWorldObjectToRelocate(worldObjects);
                    if (worldObjectToRelocate is not null)
                    {
                        ConstructionRelocationSystem.ClientStartRelocation(worldObjectToRelocate);
                    }
                }

                return;
            }

            var currentCharacter = Client.Characters.CurrentPlayerCharacter;
            var privateState     = PlayerCharacter.GetPrivateState(currentCharacter);

            if (privateState.CurrentActionState is ConstructionActionState actionState)
            {
                if (!allowReplacingCurrentConstructionAction)
                {
                    // already performing the action
                    return;
                }

                if (ReferenceEquals(actionState.WorldObject, worldObjectToBuildOrRepair))
                {
                    // the same object is already building/repairing
                    return;
                }
            }

            SharedStartAction(currentCharacter, worldObjectToBuildOrRepair);
        }