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(); } }
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; } }
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(); }
private void ClientOnPaintZone(List <Vector2Ushort> tilePositions, bool isRepeat) { var selectedZoneForBrush = this.settings.SelectedZoneForBrush; if (selectedZoneForBrush is null || !selectedZoneForBrush.IsRendered) { // no zone selected for brush or zone is not visible return; } var protoZone = selectedZoneForBrush.Zone; var zoneProvider = ClientZoneProvider.Get(protoZone); if (!zoneProvider.IsDataReceived) { return; } var world = Client.World; var onlyOnTheSameHeight = this.settings.IsAllowZoneChangeOnlyOnTheSameHeight; if (this.settings.IsFillZoneMode) { if (isRepeat) { // fill doesn't support repeat return; } tilePositions = EditorTileHelper.GatherAllTilePositionsOfTheSameProtoTile( tilePositions[0], onlyOnTheSameHeight, ignoreCliffsAndSlopes: true); } this.lastUsedZoneProvider = zoneProvider; if (onlyOnTheSameHeight && !isRepeat) { // capture height when starting painting the zone this.capturedHeight = this.settings.IsFillZoneMode ? world.GetTile(tilePositions[0]).Height : EditorTileHelper.CalculateAverageHeight(tilePositions); } var onlyOnTheSameTileProto = this.settings.IsAllowZoneChangeOnlyOnTheSameTileProto; if (onlyOnTheSameTileProto && !isRepeat) { // capture tile proto when starting painting the zone this.capturedTileProto = this.settings.IsFillZoneMode ? world.GetTile(tilePositions[0]).ProtoTile : EditorTileHelper.CalculateMostFrequentTileProto(tilePositions); } // determine the mode - adding points to zone or removing them var isAddMode = ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem, evenIfHandled: true) || ClientInputManager.IsButtonUp(GameButton.ActionUseCurrentItem, evenIfHandled: true); if (isAddMode) { // remove points which are already added to the zone tilePositions.RemoveAll(tilePosition => zoneProvider.IsFilledPosition(tilePosition)); } else { // remove points which are not presented in the zone tilePositions.RemoveAll(tilePosition => !zoneProvider.IsFilledPosition(tilePosition)); } if (tilePositions.Count == 0) { // nothing to add/remove return; } if (onlyOnTheSameHeight) { // remove tiles with different height tilePositions.RemoveAll( tilePosition => { var tile = world.GetTile(tilePosition); return(tile.Height != this.capturedHeight // also do not allow painting on cliffs and slopes || tile.IsCliff || tile.IsSlope); }); if (tilePositions.Count == 0) { // nothing to add/remove return; } } if (onlyOnTheSameTileProto) { // remove tiles with different proto var worldService = Client.World; tilePositions.RemoveAll( tilePosition => worldService.GetTile(tilePosition).ProtoTile != this.capturedTileProto); if (tilePositions.Count == 0) { // nothing to add/remove return; } } foreach (var tilePosition in tilePositions) { if (isAddMode) { // add point to the zone zoneProvider.SetFilledPosition(tilePosition); } else { // remove point from the zone zoneProvider.ResetFilledPosition(tilePosition); } } this.lastUsedZoneProvider.ApplyClientChanges(forcePushChangesImmediately: tilePositions.Count > 10000); }