private void UpdateMapping() { var mapping = ClientInputManager.GetMappingForAbstractButton(this.Button); this.PrimaryKeyText = InputKeyNameHelper.GetKeyText(mapping.PrimaryKey); this.SecondaryKeyText = InputKeyNameHelper.GetKeyText(mapping.SecondaryKey); }
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); } }); }
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); }); }
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()); } }
public override void Update(double deltaTime) { if (ClientInputManager.IsButtonDown(GameButton.ConstructionMenu)) { ConstructionPlacementSystem.ClientToggleConstructionMenu(); } }
protected override void ClientItemUseStart(ClientItemData data) { var item = data.Item; var playerCharacter = Client.Characters.CurrentPlayerCharacter; if (ItemFuelRefillSystem.Instance.SharedGetCurrentActionState(playerCharacter) != null) { return; } ClientTryRefill(item); if (ItemFuelRefillSystem.Instance.SharedGetCurrentActionState(playerCharacter) != null) { return; } var inputKey = ClientInputManager.GetKeyForAbstractButton( WrappedButton <GameButton> .GetWrappedButton(GameButton.HeadEquipmentLightToggle)); var key = inputKey != InputKey.None ? inputKey.ToString() : "<" + TitleButtonNotSet + ">"; NotificationSystem.ClientShowNotification( string.Format(NotificationPressKeyToActivate, key), icon: this.Icon); }
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; }); }
public static void ClientTryStartAction() { if (!(ClientHotbarSelectedItemManager.SelectedItem?.ProtoGameObject is IProtoItemVehicleRepairKit)) { // no tool is selected return; } if (!ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem)) { // the tool is not currently used return; } var vehicleToRepair = ClientGetObjectToRepairAtCurrentMousePosition(); 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); }
private bool CheckIsBarShouldBeVisible() { if (this.vehicle is null) { return(false); } if (ClientInputManager.IsButtonHeld(GameButton.DisplayLandClaim) || Input.IsKeyHeld(InputKey.Alt, evenIfHandled: true) || Api.IsEditor && Client.Characters.IsCurrentPlayerCharacterSpectator || (this.lastStructurePointsValueUpdateTimestamp > 0 && Core.ClientRealTime - this.lastStructurePointsValueUpdateTimestamp < ClientComponentAutoDisplayStructurePointsBar.SecondsToDisplayHealthbarAfterDamage)) { return(true); } if (this.IsDisplayedOnlyOnMouseOver && (!ReferenceEquals(ClientComponentObjectInteractionHelper.MouseOverObject, this.vehicle))) { return(false); } return(true); }
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(); }); }
public MultiplayerGameScene(Game game, NetworkManager networkManager, BaseConnection connectionInfo) : base(game, networkManager, connectionInfo) { this.scene = new GUIScene(); this.background = new Background(Assets.Get <Texture2D>(GameConfig.Folders.Particles, "circle"), new Rectangle(Point.Zero, GameConfig.WorldSize)); this.intentManager = new IntentManager(); this.clientInputManager = new ClientInputManager(this.connectionInfo, this.intentManager); List <Texture2D> list = new List <Texture2D> { Assets.Get <Texture2D>(GameConfig.Folders.Particles, "circle") }; this.particleEngine = new ParticleEngine(list, Vector2.Zero, 0, 50, false); this.entityWorld = new EntityWorld(); this.entityFactory = new ClientEntityFactory(this.entityWorld); this.scoreboardUI = new Scoreboard(GameConfig.Fonts.Medium, true); this.scoreboardUI.Hide(); this.scene.AddChild(this.scoreboardUI); this.entityWorld.SystemManager.AddSystem(new MotionSystem(this.entityWorld)); //dead reckoning (for client side prediction) this.entityWorld.SystemManager.AddSystem(new RespawnTimeoutSystem(this.entityWorld)); this.entityWorld.SystemManager.AddSystem(new TextureRenderSystem(this.entityWorld)); this.entityWorld.SystemManager.AddSystem(new ScoreboardSystem(this.entityWorld, this.scoreboardUI)); this.entityWorld.SystemManager.AddSystem(new ParticleSystem(this.entityWorld, this.particleEngine)); this.CreateScene(); this.CreateEscMenu(); }
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(); }); }
private bool CheckIsBarShouldBeVisible() { if (ClientInputManager.IsButtonHeld(GameButton.DisplayLandClaim) || Input.IsKeyHeld(InputKey.Alt, evenIfHandled: true) || (this.lastStructurePointsValueUpdateTimestamp > 0 && Core.ClientRealTime - this.lastStructurePointsValueUpdateTimestamp < SecondsToDisplayHealthbarAfterDamage) || Api.IsEditor && Client.Characters.IsCurrentPlayerCharacterSpectator) { return(true); } if (ClientComponentObjectInteractionHelper.CurrentMouseOverObject == this.data.StaticWorldObject) { return(true); } if (this.isDamagedBelowThreshold) { var playerPosition = ClientCurrentCharacterHelper.Character.TilePosition; var tilePosition = this.data.StaticWorldObject.TilePosition; return(tilePosition.TileSqrDistanceTo(playerPosition) <= MaxDistance * MaxDistance); } return(false); }
private static void Update() { var frameNumber = Api.Client.Core.ClientFrameNumber; using var tempChangesList = Api.Shared.GetTempList <(IStaticWorldObject worldObject, StructureLandClaimIndicator control)>(); var forceDisplayAll = ClientInputManager.IsButtonHeld(GameButton.DisplayLandClaim) || Api.Client.Input.IsKeyHeld(InputKey.Alt, evenIfHandled: true); var playerPosition = ClientCurrentCharacterHelper.Character?.TilePosition ?? Vector2Ushort.Zero; foreach (var pair in initializedOverlays) { var worldObject = pair.Key; if ((frameNumber + worldObject.Id) % 10 != 0) { // don't refresh every object every frame continue; } var isDisplayed = false; if (forceDisplayAll || IsNearby(worldObject, playerPosition)) { // can display only if close enough of if Alt/L key is held isDisplayed = !LandClaimSystem.SharedIsObjectInsideAnyArea(worldObject); } var control = pair.Value; if (isDisplayed) { if (control != null) { continue; } var component = SetupFor(worldObject, isClaimed: false); control = (StructureLandClaimIndicator)component.Control; tempChangesList.Add((worldObject, control)); continue; } if (control is null) { continue; } tempChangesList.Add((worldObject, null)); DestroyControl(control); } foreach (var entry in tempChangesList.AsList()) { initializedOverlays[entry.worldObject] = entry.control; } }
public override void ClientInitialize() { ClientInputManager.RegisterButtonsEnum <MarketplaceButton>(); BootstrapperClientGame.InitEndCallback += GameInitHandler; BootstrapperClientGame.ResetCallback += ResetHandler; }
private static void ClientUpdate() { if (ClientConstructionCooldownIsWaitingButtonRelease && !ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem)) { ClientConstructionCooldownIsWaitingButtonRelease = false; } }
protected override void PrepareHints(List <string> hints) { base.PrepareHints(hints); var key = ClientInputManager.GetKeyForButton(GameButton.HeadEquipmentLightToggle); hints.Add(string.Format(ItemHints.HelmetLightAndNightVision, InputKeyNameHelper.GetKeyText(key))); }
private static async Task Main() { var loginManager = new LoginManager("https://localhost:5001"); var hubManager = new HubManager("chat", loginManager); while (true) { try { var user = ClientInputManager.GetInput("Username: "******"Password: "******"Failed to connect to server. It may not be running. Please try again."); await Task.Delay(TimeSpan.FromSeconds(2)); } } await hubManager.ConnectAsync(); Console.CancelKeyPress += async(s, e) => { e.Cancel = true; await CloseAsync(); }; while (true) { var input = ClientInputManager.GetInput(); if (string.IsNullOrWhiteSpace(input)) { continue; } foreach (var command in ClientInputManager.Process(input)) { switch (command) { case ClientInputManager.InputCommand.Exit: await CloseAsync(); break; default: Console.WriteLine("Unrecognized client command."); break; } } await hubManager.SendAsync(HubMessages.HubMethod.SendMessage, input); } }
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); }
private void UpdateMapping() { var mapping = ClientInputManager.GetMappingForAbstractButton(this.Button); this.PrimaryKeyText = InputKeyNameHelper.GetKeyText(mapping.PrimaryKey, returnPlaceholderIfNone: false); this.SecondaryKeyText = InputKeyNameHelper.GetKeyText(mapping.SecondaryKey, returnPlaceholderIfNone: false); }
public override void ClientInitialize() { ClientInputManager.RegisterButtonsEnum <CNEIbutton>(); EntityViewModelsManager.Init(); BootstrapperClientGame.InitEndCallback += GameInitHandler; BootstrapperClientGame.ResetCallback += ResetHandler; }
public override void ClientInitialize() { ClientInputManager.RegisterButtonsEnum <AutomatonButton>(); AutomatonManager.Init(); BootstrapperClientGame.InitCallback += GameInitHandler; BootstrapperClientGame.ResetCallback += ResetHandler; }
private bool CheckIsBarShouldBeVisible() { if (ClientInputManager.IsButtonHeld(GameButton.DisplayLandClaim) || InputClientService.IsKeyHeld(InputKey.Alt, evenIfHandled: true)) { return(true); } return(ClientComponentObjectInteractionHelper.CurrentMouseOverObject == this.data.StaticWorldObject); }
private void InputCallback() { var keyDown = Client.Input .GetAllKeysDown(evenIfHandled: true) .FirstOrDefault(); if (keyDown != InputKey.None) { this.HandleKeyDown(keyDown); } ClientInputManager.ConsumeAllButtons(); }
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(); } }
public override void ClientInitialize() { ClientInputManager.RegisterButtonsEnum <CNEIButton>(); UpdateChecker.CheckNewReleases( EntityViewModelsManager.ModId, EntityViewModelsManager.CurrentVersion, EntityViewModelsManager.RssFeed); EntityViewModelsManager.Init(); BootstrapperClientGame.InitEndCallback += GameInitHandler; BootstrapperClientGame.ResetCallback += ResetHandler; }
public override void ClientInitialize() { ClientInputManager.RegisterButtonsEnum <AutomatonButton>(); UpdateChecker.CheckNewReleases( AutomatonManager.ModId, AutomatonManager.CurrentVersion, AutomatonManager.RssFeed); AutomatonManager.Init(); BootstrapperClientGame.InitCallback += GameInitHandler; BootstrapperClientGame.ResetCallback += ResetHandler; }
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; } }
protected override void PrepareQuest(QuestsList prerequisites, TasksList tasks, HintsList hints) { tasks .Add(TaskCraftRecipe.RequireHandRecipe <RecipePickaxeStone>()); prerequisites .Add <QuestChopDownATree>(); hints .Add(() => { var keyForButton = InputKeyNameHelper.GetKeyText(ClientInputManager.GetKeyForButton(GameButton.CraftingMenu)); return(string.Format(HintCrafting, keyForButton)); }) .Add(HintRope); }
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); }