Example #1
0
 protected override void OnLoaded()
 {
     base.OnLoaded();
     DataContext        = entityVMStack.Peek();
     windowInputContext = ClientInputContext.Start("CNEI details")
                          .HandleButtonDown(CNEIbutton.MenuBack, OnBackButtonDown);
 }
Example #2
0
        static ClientLandClaimAreaManager()
        {
            RendererGraceAreas = new ClientLandClaimAreaRenderer(
                ZoneColorGraceArea,
                inflateSize: LandClaimSystem.LandClaimAreaGracePaddingSize,
                drawOrder: DrawOrder.Overlay - 3);

            RendererAreasOwnedByPlayer = new ClientLandClaimAreaRenderer(
                ZoneColorOwnedByPlayer,
                drawOrder: DrawOrder.Overlay - 2);

            RendererAreasNotOwnedByPlayer = new ClientLandClaimAreaRenderer(
                ZoneColorNotOwnedByPlayer,
                drawOrder: DrawOrder.Overlay - 1);

            Api.Client.World.WorldBoundsChanged += WorldBoundsChangedHandler;
            WorldBoundsChangedHandler();

            // ReSharper disable once CanExtractXamlLocalizableStringCSharp
            ClientInputContext.Start("Land claim visualizer")
            .HandleAll(
                () =>
            {
                var isDisplayed = ClientInputManager.IsButtonHeld(GameButton.DisplayLandClaim) ||
                                  Api.Client.Input.IsKeyHeld(InputKey.Alt) ||
                                  (ConstructionPlacementSystem
                                   .IsObjectPlacementComponentEnabled);

                RendererAreasOwnedByPlayer.IsVisible    = isDisplayed;
                RendererAreasNotOwnedByPlayer.IsVisible = isDisplayed;
                RendererGraceAreas.IsVisible            = isDisplayed;
            });
        }
Example #3
0
        public static void Init()
        {
            if (isInitialized)
            {
                return;
            }

            Api.ValidateIsClient();
            isInitialized = true;

            // ReSharper disable once CanExtractXamlLocalizableStringCSharp
            ClientInputContext.Start("Head equipment light toggle")
            .HandleButtonDown(GameButton.HeadEquipmentLightToggle,
                              () =>
            {
                var item = ClientCurrentCharacterHelper
                           .PublicState?
                           .ContainerEquipment
                           .Items
                           .FirstOrDefault(
                    i => i.ProtoItem is
                    IProtoItemEquipmentHeadWithLight);

                if (item == null)
                {
                    NotificationSystem.ClientShowNotification(
                        NotificationNoHelmetLightEquipped,
                        color: NotificationColor.Bad);
                    return;
                }

                var protoLight = (IProtoItemEquipmentHeadWithLight)item.ProtoItem;
                protoLight.ClientToggleLight(item);
            });
        }
Example #4
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();
            });
        }
Example #5
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();
            });
        }
Example #6
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);
                }
            });
        }
        private static void GameInitHandler(ICharacter currentCharacter)
        {
            InitPVE();

            hudButton = new ViewModelHUDButton();

            foreach (var child in Api.Client.UI.LayoutRootChildren)
            {
                if (child is HUDLayoutControl layoutControl)
                {
                    hudLayoutControl = layoutControl;
                }
            }

            if (hudLayoutControl != null)
            {
                hudLayoutControl.Loaded += LayoutControl_Loaded;
            }
            else
            {
                //Api.Logger.Error("Marketplace: HUDLayoutControl not found.");
            }

            gameplayInputContext = ClientInputContext
                                   .Start("Marketplace menu")
                                   .HandleButtonDown(MarketplaceButton.MenuOpen, Menu.Toggle <MainWindow>);
        }
Example #8
0
        private static void GameInitHandler(ICharacter currentCharacter)
        {
            hudButton = new ViewModelHUDButton();

            foreach (var child in Api.Client.UI.LayoutRootChildren)
            {
                if (child is HUDLayoutControl layoutControl)
                {
                    hudLayoutControl = layoutControl;
                }
            }

            if (hudLayoutControl != null)
            {
                hudLayoutControl.Loaded += LayoutControl_Loaded;
            }
            else
            {
                Api.Logger.Error("CNEI: HUDLayoutControl not found.");
            }

            gameplayInputContext = ClientInputContext
                                   .Start("CNEI menu")
                                   .HandleButtonDown(CNEIbutton.MenuOpen, Menu.Toggle <WindowCNEImenu>)
                                   .HandleButtonDown(CNEIbutton.MenuDetails, ShowContextDetails);

            CreativePanelManager.Init();
        }
        protected override void OnEnable()
        {
            this.publicState = ClientCurrentCharacterHelper.PublicState;
            ClientHotbarSelectedItemManager.Init();

            this.clientInputContext =
                ClientInputContext.Start(nameof(ClientComponentWorldCameraZoomManager))
                .HandleAll(() =>
            {
                if (!IsUsingMouseWheelInputToScrollHotbar ||
                    WindowsManager.OpenedWindowsCount > 0)
                {
                    return;
                }

                var delta = Input.MouseScrollDeltaValue;
                if (delta == 0)
                {
                    return;
                }

                if (IsMouseWheelReversedDirection)
                {
                    delta *= -1;
                }

                ClientHotbarSelectedItemManager.SelectNextSlot(
                    indexDelta: (int)Math.Round(
                        delta,
                        MidpointRounding.AwayFromZero));
            });
        }
Example #10
0
        private static void Reset()
        {
            if (!isInitialized)
            {
                return;
            }

            isInitialized = false;

            Menu.CloseAll();

            ClientComponentObjectPlacementHelper.DestroyInstanceIfExist();

            if (HUDLayoutControl.Instance is not null)
            {
                Api.Client.UI.LayoutRootChildren.Remove(HUDLayoutControl.Instance);
            }

            if (ChatPanel.Instance is not null)
            {
                Api.Client.UI.LayoutRootChildren.Remove(ChatPanel.Instance);
            }

            ResetCallback?.Invoke();

            ClientContainersExchangeManager.Reset();

            ClientCurrentCharacterContainersHelper.Reset();

            sceneObjectInputComponents?.Destroy();
            sceneObjectInputComponents = null;

            gameplayInputContext?.Stop();
            gameplayInputContext = null;
        }
Example #11
0
        private static void InitGameplayMode(ICharacter currentCharacter)
        {
            ClientCurrentCharacterContainersHelper.Init(currentCharacter);
            ClientItemsManager.Init(currentCharacter);
            ClientDroppedItemsNotifier.Init(currentCharacter);

            var layoutRootChildren = Api.Client.UI.LayoutRootChildren;

            layoutRootChildren.Add(new HUDLayoutControl());
            layoutRootChildren.Add(new ChatPanel());

            ClientContainersExchangeManager.Reset();

            CraftingQueueControl.Instance?.Refresh();

            var input = Api.Client.Scene.CreateSceneObject("Input components");

            input.AddComponent <ClientComponentHotbarHelper>();
            input.AddComponent <ClientComponentWindowStructureSelectListToogle>();
            input.AddComponent <ClientComponentObjectInteractionHelper>();

            // ReSharper disable once CanExtractXamlLocalizableStringCSharp
            gameplayInputContext =
                ClientInputContext
                .Start("Menu toggles")
                .HandleButtonDown(
                    GameButton.InventoryMenu,
                    () =>
            {
                if (Menu.IsOpenedAny())
                {
                    // shortcut to close currently opened menus
                    // (basically, it's alternative to pressing ESC in such case)
                    Menu.CloseAll();
                    return;
                }

                Menu.Toggle <WindowInventory>();
            })
                .HandleButtonDown(GameButton.CraftingMenu, Menu.Toggle <WindowHandCrafting>)
                .HandleButtonDown(GameButton.MapMenu, Menu.Toggle <WindowWorldMap>)
                .HandleButtonDown(GameButton.SkillsMenu, Menu.Toggle <WindowSkills>)
                .HandleButtonDown(GameButton.TechnologiesMenu, Menu.Toggle <WindowTechnologies>)
                .HandleButtonDown(GameButton.SocialMenu, Menu.Toggle <WindowSocial>)
                .HandleButtonDown(GameButton.PoliticsMenu, Menu.Toggle <WindowPolitics>)
                .HandleButtonDown(GameButton.QuestsMenu, Menu.Toggle <WindowQuests>)
                .HandleButtonDown(GameButton.CompletionistMenu, Menu.Toggle <WindowCompletionist>)
                .HandleButtonDown(GameButton.OpenChat,
                                  () =>
            {
                if (WindowsManager.OpenedWindowsCount == 0)
                {
                    ChatPanel.Instance.Open();
                }
            });

            sceneObjectInputComponents = input;

            ClientComponentWorldCameraZoomManager.Instance.ZoomBounds = ZoomBoundsGameplayMode;
        }
Example #12
0
        public ViewModelItemsContainerExchange(IItemsContainer container, Action callbackTakeAllItemsSuccess)
        {
            this.callbackTakeAllItemsSuccess = callbackTakeAllItemsSuccess;
            this.Container = (IClientItemsContainer)container;

            var character = ClientCurrentCharacterHelper.Character;

            ClientContainersExchangeManager.Register(
                this,
                this.Container,
                allowedTargets: new[]
            {
                character.SharedGetPlayerContainerInventory(),
                character.SharedGetPlayerContainerHotbar()
            });

            ClientContainersExchangeManager.Register(
                this,
                character.SharedGetPlayerContainerHotbar(),
                allowedTargets: new[] { this.Container });

            ClientContainersExchangeManager.Register(
                this,
                character.SharedGetPlayerContainerInventory(),
                allowedTargets: new[] { this.Container });

            // ReSharper disable once CanExtractXamlLocalizableStringCSharp
            this.inputListener = ClientInputContext
                                 .Start("Container exchange")
                                 .HandleButtonDown(GameButton.ContainerTakeAll, this.ExecuteCommandTakeAll)
                                 .HandleButtonDown(GameButton.ContainerMoveItemsMatchDown, this.ExecuteCommandMatchDown)
                                 .HandleButtonDown(GameButton.ContainerMoveItemsMatchUp, this.ExecuteCommandMatchUp);
        }
        protected override void WindowOpening()
        {
            this.suppressInputContext = ClientInputContext
                                        .Start("Window noise - intercept all other input")
                                        .HandleAll(ClientInputManager.ConsumeAllButtons);

            this.DataContext = this.viewModel = new ViewModelWindowEditorNoiseForGround();
        }
Example #14
0
        private static void ResetHandler()
        {
            clientComponentAutomaton?.Destroy();
            clientComponentAutomaton = null;

            gameplayInputContext?.Stop();
            gameplayInputContext = null;
        }
Example #15
0
        protected override void DisposeViewModel()
        {
            IsActive = false;
            inputListener?.Stop();
            inputListener = null;

            base.DisposeViewModel();
        }
Example #16
0
        private static void ResetHandler()
        {
            ClientComponentAutomaton.Instance?.Destroy();
            ClientComponentAutomaton.Instance = null;

            gameplayInputContext?.Stop();
            gameplayInputContext = null;
        }
Example #17
0
        protected override void WindowClosing()
        {
            this.suppressInputContext.Stop();
            this.suppressInputContext = null;

            this.DataContext = null;
            this.viewModel.Dispose();
            this.viewModel = null;
        }
Example #18
0
        protected override void ClientItemHotbarSelectionChanged(ClientHotbarItemData data)
        {
            var item = data.Item;

            if (data.IsSelected)
            {
                // ReSharper disable once CanExtractXamlLocalizableStringCSharp
                this.helperInputListener = ClientInputContext
                                           .Start("Current light item refill action listener")
                                           .HandleButtonDown(
                    GameButton.ItemReload,
                    ItemFuelRefillSystem.Instance.ClientTryStartAction);

                if (!data.IsByPlayer)
                {
                    // it's automatic selection (player just logged in)
                    if (!TimeOfDaySystem.ClientIsInitialized)
                    {
                        Logger.Warning(nameof(TimeOfDaySystem) + " is not initialized - cannot enable a hand lamp");
                        return;
                    }

                    // don't enable the light automatically if it's not night
                    var isLightRequired = TimeOfDaySystem.IsNight;
                    Logger.Info(string.Format("Light auto selection! Time: {0:hh\\:mm}, is light required: {1}",
                                              TimeSpan.FromHours(TimeOfDaySystem.CurrentTimeOfDayHours),
                                              isLightRequired));

                    if (!isLightRequired)
                    {
                        return;
                    }
                }

                if (data.PrivateState.FuelAmount > 0)
                {
                    // have fuel - turn on automatically
                    this.ClientTrySetActiveState(item, setIsActive: true);
                }
                else
                {
                    this.ClientShowOutOfFuelNotification();
                }
            }
            else
            {
                this.helperInputListener?.Stop();
                this.helperInputListener = null;

                // deactivate the item automatically on the client side
                GetPublicState(item).IsActive = false;
                Logger.Info($"Item light deselected, light turns off: {item}");
                // no need to sync with the server - it will automatically notice that the selected hotbar item has been changed
                //this.ClientTrySetActiveState(data.Item, setIsActive: false);
            }
        }
        protected override void OnEnable()
        {
            base.OnEnable();

            DestroyInstanceIfExist();
            instance = this;

            this.inputContext = ClientInputContext.Start(nameof(ClientComponentObjectPlacementHelper))
                                .HandleAll(this.Update);
        }
Example #20
0
        private static void GameInitHandler(ICharacter currentCharacter)
        {
            ClientComponentAutomaton.Init();

            gameplayInputContext = ClientInputContext
                                   .Start("Automaton options toggle")
                                   .HandleButtonDown(AutomatonButton.OpenSettings, MainWindow.Toggle)
                                   .HandleButtonDown(AutomatonButton.Toggle, () =>
                                                     { AutomatonManager.IsEnabled = !AutomatonManager.IsEnabled; });
        }
Example #21
0
        private void RemoveControl()
        {
            if (instance == this)
            {
                instance = null;
            }

            Api.Client.UI.LayoutRootChildren.Remove(this);
            inputContext?.Stop();
            inputContext = null;
        }
        public void Setup(ICharacter character)
        {
            this.character = character;

            // ReSharper disable once CanExtractXamlLocalizableStringCSharp
            this.inputContext = ClientInputContext
                                .Start("Player character Movement")
                                .HandleAll(this.UpdateInput);

            StorageRunMode.TryLoad(out this.runToggle);
        }
        protected override void OnUnloaded()
        {
            if (IsDesignTime)
            {
                return;
            }

            this.DataContext = null;
            this.overlay.MouseLeftButtonDown -= this.OverlayMouseLeftButtonDownHandler;
            this.inputContext.Stop();
            this.inputContext = null;
        }
Example #24
0
        protected override void DisposeViewModel()
        {
            this.viewModelMapping = null;
            base.DisposeViewModel();
            this.clientInputContext.Stop();
            this.clientInputContext = null;

            if (Instance == this)
            {
                Instance = null;
            }
        }
Example #25
0
 protected override void OnUnloaded()
 {
     base.OnUnloaded();
     DataContext = null;
     entityVMStack.Clear();
     windowInputContext?.Stop();
     windowInputContext = null;
     if (Instance == this)
     {
         Instance = null;
     }
 }
        private void Reset()
        {
            if (EditorHUDLayoutControl.Instance is not null)
            {
                Api.Client.UI.LayoutRootChildren.Remove(EditorHUDLayoutControl.Instance);
            }

            this.inputContextEditorMapMenu?.Stop();
            this.inputContextEditorMapMenu = null;

            this.inputContextEditorUndoRedo?.Stop();
            this.inputContextEditorUndoRedo = null;
        }
Example #27
0
 protected override void PrepareSystem()
 {
     if (IsClient)
     {
         ClientInputContext.Start("Enter/Exit vehicle")
         .HandleButtonDown(GameButton.VehicleEnterExit,
                           this.ClientOnVehicleEnterExitButtonPress);
     }
     else
     {
         TriggerEveryFrame.ServerRegister(ServerProcessVehicleQuitRequests,
                                          nameof(VehicleSystem));
     }
 }
        protected override void OnLoaded()
        {
            if (IsDesignTime)
            {
                return;
            }

            this.DataContext = ViewModelDebugToolsOverlay.Instance;
            this.overlay.MouseLeftButtonDown += this.OverlayMouseLeftButtonDownHandler;

            // ReSharper disable once CanExtractXamlLocalizableStringCSharp
            this.inputContext = ClientInputContext
                                .Start("Debug tools overlay")
                                .HandleButtonDown(GameButton.CancelOrClose, () => Toggle(isEnabled: false));
        }
        public override void ClientInitialize()
        {
            ClientInputManager.RegisterButtonsEnum <EditorButton>();

            ClientComponentUpdateHelper.UpdateCallback    += this.ClientUpdateCallback;
            BootstrapperClientGame.InitEditorModeCallback += this.InitEditorMode;
            BootstrapperClientGame.ResetCallback          += this.Reset;

            ClientInputContext.Start("Editor quick save/load")
            .HandleButtonDown(
                EditorButton.LoadQuickSavegame,
                EditorToolMap.ClientLoadSavegameQuick)
            .HandleButtonDown(
                EditorButton.MakeQuickSavegame,
                EditorToolMap.ClientSaveSavegameQuick);
        }
Example #30
0
        public static void Init()
        {
            if (isInitialized)
            {
                return;
            }

            Api.ValidateIsClient();
            isInitialized = true;

            // ReSharper disable once CanExtractXamlLocalizableStringCSharp

            ClientInputContext.Start("Head equipment light toggle")
            .HandleButtonDown(GameButton.HeadEquipmentLightToggle,
                              ToggleHelmetLight);
        }