protected override void Draw(DrawingHandleBase handle, OverlaySpace currentSpace) { if (_parallaxTexture == null) { return; } handle.UseShader(_shader); var screenHandle = (DrawingHandleScreen)handle; var(sizeX, sizeY) = _parallaxTexture.Size; var(posX, posY) = _eyeManager.ScreenToMap(Vector2.Zero).Position; var(ox, oy) = (Vector2i) new Vector2(-posX / Slowness, posY / Slowness); ox = MathHelper.Mod(ox, sizeX); oy = MathHelper.Mod(oy, sizeY); var(screenSizeX, screenSizeY) = _displayManager.ScreenSize; for (var x = -sizeX; x < screenSizeX; x += sizeX) { for (var y = -sizeY; y < screenSizeY; y += sizeY) { screenHandle.DrawTexture(_parallaxTexture, new Vector2(ox + x, oy + y)); } } }
public override void Update(float frameTime) { base.Update(frameTime); if (!Enabled || !_gameTiming.IsFirstTimePredicted) { return; } var state = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use); if (state != BoundKeyState.Down) { StopDragging(); return; } var mouseScreenPos = _inputManager.MouseScreenPosition; var mousePos = _eyeManager.ScreenToMap(mouseScreenPos); if (_dragging == null) { if (!_mapManager.TryFindGridAt(mousePos, out var grid)) { return; } StartDragging(grid.GridEntityId, Transform(grid.GridEntityId).InvWorldMatrix.Transform(mousePos.Position)); } if (!TryComp <TransformComponent>(_dragging, out var xform)) { StopDragging(); return; } if (xform.MapID != mousePos.MapId) { StopDragging(); return; } var localToWorld = xform.WorldMatrix.Transform(_localPosition); if (localToWorld.EqualsApprox(mousePos.Position, 0.01f)) { return; } var requestedGridOrigin = mousePos.Position - xform.WorldRotation.RotateVec(_localPosition); _lastMousePosition = new MapCoordinates(requestedGridOrigin, mousePos.MapId); RaiseNetworkEvent(new GridDragRequestPosition() { Grid = _dragging.Value, WorldPosition = requestedGridOrigin, }); }
public override void FrameUpdate(FrameEventArgs e) { base.FrameUpdate(e); // If there is no local player, there is no session, and therefore nothing to do here. var localPlayer = PlayerManager.LocalPlayer; if (localPlayer == null) { return; } var mousePosWorld = EyeManager.ScreenToMap(InputManager.MouseScreenPosition); var entityToClick = UserInterfaceManager.CurrentlyHovered != null ? null : GetEntityUnderPosition(mousePosWorld); var inRange = false; if (localPlayer.ControlledEntity != null && entityToClick != null) { inRange = localPlayer.InRangeUnobstructed(entityToClick, ignoreInsideBlocker: true); } InteractionOutlineComponent outline; if (!ConfigurationManager.GetCVar <bool>("outline.enabled")) { if (entityToClick != null && entityToClick.TryGetComponent(out outline)) { outline.OnMouseLeave(); //Prevent outline remains from persisting post command. } return; } if (entityToClick == _lastHoveredEntity) { if (entityToClick != null && entityToClick.TryGetComponent(out outline)) { outline.UpdateInRange(inRange); } return; } if (_lastHoveredEntity != null && !_lastHoveredEntity.Deleted && _lastHoveredEntity.TryGetComponent(out outline)) { outline.OnMouseLeave(); } _lastHoveredEntity = entityToClick; if (_lastHoveredEntity != null && _lastHoveredEntity.TryGetComponent(out outline)) { outline.OnMouseEnter(inRange); } }
public override void FrameUpdate(FrameEventArgs e) { base.FrameUpdate(e); var mousePosWorld = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition); var entityToClick = _userInterfaceManager.CurrentlyHovered != null ? null : GetEntityUnderPosition(mousePosWorld); var inRange = false; if (_playerManager.LocalPlayer.ControlledEntity != null && entityToClick != null) { var playerPos = _playerManager.LocalPlayer.ControlledEntity.Transform.MapPosition; var entityPos = entityToClick.Transform.MapPosition; inRange = _entitySystemManager.GetEntitySystem <SharedInteractionSystem>() .InRangeUnobstructed(playerPos, entityPos, predicate: entity => entity == _playerManager.LocalPlayer.ControlledEntity || entity == entityToClick, insideBlockerValid: true); } InteractionOutlineComponent outline; if (!_configurationManager.GetCVar <bool>("outline.enabled")) { if (entityToClick != null && entityToClick.TryGetComponent(out outline)) { outline.OnMouseLeave(); //Prevent outline remains from persisting post command. } return; } if (entityToClick == _lastHoveredEntity) { if (entityToClick != null && entityToClick.TryGetComponent(out outline)) { outline.UpdateInRange(inRange); } return; } if (_lastHoveredEntity != null && !_lastHoveredEntity.Deleted && _lastHoveredEntity.TryGetComponent(out outline)) { outline.OnMouseLeave(); } _lastHoveredEntity = entityToClick; if (_lastHoveredEntity != null && _lastHoveredEntity.TryGetComponent(out outline)) { outline.OnMouseEnter(inRange); } }
public override void Update(float frameTime) { base.Update(frameTime); if (!_gameTiming.IsFirstTimePredicted) { return; } var canFireSemi = _isFirstShot; var state = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use); if (!_combatModeSystem.IsInCombatMode() || state != BoundKeyState.Down) { _isFirstShot = true; _blocked = false; return; } _isFirstShot = false; var entity = _playerManager.LocalPlayer.ControlledEntity; if (entity == null || !entity.TryGetComponent(out IHandsComponent hands)) { return; } var held = hands.ActiveHand; if (held == null || !held.TryGetComponent(out ClientRangedWeaponComponent weapon)) { _blocked = true; return; } if (_blocked) { return; } var worldPos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition); if (!_mapManager.TryFindGridAt(worldPos, out var grid)) { grid = _mapManager.GetDefaultGrid(worldPos.MapId); } if (weapon.Automatic || canFireSemi) { weapon.SyncFirePos(grid.MapToGrid(worldPos)); } }
public bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity?item) { if (item == null) { return(false); } if (args.Function == ContentKeyFunctions.ExamineEntity) { _entitySystemManager.GetEntitySystem <ExamineSystem>() .DoExamine(item); } else if (args.Function == ContentKeyFunctions.OpenContextMenu) { _entitySystemManager.GetEntitySystem <VerbSystem>() .OpenContextMenu(item, _uiMgr.ScreenToUIPosition(args.PointerLocation)); } else if (args.Function == ContentKeyFunctions.ActivateItemInWorld) { var inputSys = _entitySystemManager.GetEntitySystem <InputSystem>(); var func = args.Function; var funcId = _inputManager.NetworkBindMap.KeyFunctionID(args.Function); var mousePosWorld = _eyeManager.ScreenToMap(args.PointerLocation); var coordinates = _mapManager.TryFindGridAt(mousePosWorld, out var grid) ? grid.MapToGrid(mousePosWorld) : EntityCoordinates.FromMap(_mapManager, mousePosWorld); var message = new FullInputCmdMessage(_gameTiming.CurTick, _gameTiming.TickFraction, funcId, BoundKeyState.Down, coordinates, args.PointerLocation, item.Uid); // client side command handlers will always be sent the local player session. var session = _playerManager.LocalPlayer?.Session; if (session == null) { return(false); } inputSys.HandleInputCommand(session, func, message); } else { return(false); } args.Handle(); return(true); }
protected override void Draw(DrawingHandleBase handle) { if (_parallaxTexture == null) { return; } var screenHandle = (DrawingHandleScreen)handle; var(sizeX, sizeY) = _parallaxTexture.Size; var(posX, posY) = _eyeManager.ScreenToMap(Vector2.Zero).Position; var(ox, oy) = (Vector2i) new Vector2(-posX / Slowness, posY / Slowness); ox = MathHelper.Mod(ox, sizeX); oy = MathHelper.Mod(oy, sizeY); screenHandle.DrawTexture(_parallaxTexture, new Vector2(ox, oy)); screenHandle.DrawTexture(_parallaxTexture, new Vector2(ox - sizeX, oy)); screenHandle.DrawTexture(_parallaxTexture, new Vector2(ox, oy - sizeY)); screenHandle.DrawTexture(_parallaxTexture, new Vector2(ox - sizeX, oy - sizeY)); }
public override void Update(float frameTime) { base.Update(frameTime); if (!_gameTiming.IsFirstTimePredicted) { return; } var state = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use); if (!_combatModeSystem.IsInCombatMode() || state != BoundKeyState.Down) { _shotCounter = 0; _blocked = false; return; } var entity = _playerManager.LocalPlayer.ControlledEntity; if (entity == null || !entity.TryGetComponent(out HandsComponent hands)) { return; } var held = hands.ActiveHand; if (held == null || !held.TryGetComponent(out ClientRangedWeaponComponent weapon)) { _blocked = true; return; } switch (weapon.FireRateSelector) { case FireRateSelector.Safety: _blocked = true; return; case FireRateSelector.Single: if (_shotCounter >= 1) { _blocked = true; return; } break; case FireRateSelector.Automatic: break; default: throw new ArgumentOutOfRangeException(); } if (_blocked) { return; } var worldPos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition); if (!_mapManager.TryFindGridAt(worldPos, out var grid)) { weapon.SyncFirePos(GridId.Invalid, worldPos.Position); } else { weapon.SyncFirePos(grid.Index, grid.MapToGrid(worldPos).Position); } }
public override void Update(float frameTime) { base.Update(frameTime); if (!Enabled || !_gameTiming.IsFirstTimePredicted) { return; } var state = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use); if (state != BoundKeyState.Down) { StopDragging(); return; } var mouseScreenPos = _inputManager.MouseScreenPosition; var mousePos = _eyeManager.ScreenToMap(mouseScreenPos); if (_dragging == null) { var bodyQuery = GetEntityQuery <PhysicsComponent>(); var lowest = new List <(int DrawDepth, uint RenderOrder, EntityUid Entity)>(); foreach (var ent in _lookup.GetEntitiesIntersecting(mousePos, LookupFlags.Approximate | LookupFlags.Anchored)) { if (!bodyQuery.HasComponent(ent) || !TryComp <ClickableComponent>(ent, out var clickable) || !clickable.CheckClick(mousePos.Position, out var drawDepth, out var renderOrder)) { continue; } lowest.Add((drawDepth, renderOrder, ent)); } lowest.Sort((x, y) => y.DrawDepth == x.DrawDepth ? y.RenderOrder.CompareTo(x.RenderOrder) : y.DrawDepth.CompareTo(x.DrawDepth)); foreach (var ent in lowest) { StartDragging(ent.Entity, mousePos); break; } if (_dragging == null) { return; } } if (!TryComp <TransformComponent>(_dragging !.Value, out var xform) || _lastMousePosition !.Value.MapId != xform.MapID || !TryComp <PhysicsComponent>(_dragging, out var body)) { StopDragging(); return; } body.Predict = true; if (TryComp <PhysicsComponent>(_tether, out var tetherBody)) { tetherBody.Predict = true; } if (_lastMousePosition.Value.Position.EqualsApprox(mousePos.Position)) { return; } _lastMousePosition = mousePos; RaiseNetworkEvent(new TetherMoveEvent() { Coordinates = _lastMousePosition !.Value, });
protected override void FrameUpdate(FrameEventArgs args) { if (!VisibleInTree) { return; } var stringBuilder = new StringBuilder(); var mouseScreenPos = _inputManager.MouseScreenPosition; var screenSize = _displayManager.ScreenSize; MapCoordinates mouseWorldMap; EntityCoordinates mouseGridPos; TileRef tile; mouseWorldMap = _eyeManager.ScreenToMap(mouseScreenPos); if (_mapManager.TryFindGridAt(mouseWorldMap, out var mouseGrid)) { mouseGridPos = mouseGrid.MapToGrid(mouseWorldMap); tile = mouseGrid.GetTileRef(mouseGridPos); } else { mouseGridPos = new EntityCoordinates(_mapManager.GetMapEntityId(mouseWorldMap.MapId), mouseWorldMap.Position); tile = new TileRef(mouseWorldMap.MapId, GridId.Invalid, mouseGridPos.ToVector2i(_entityManager, _mapManager), Tile.Empty); } var controlHovered = UserInterfaceManager.CurrentlyHovered; stringBuilder.AppendFormat(@"Positioning Debug: Screen Size: {0} Mouse Pos: Screen: {1} {2} {3} {4} GUI: {5}", screenSize, mouseScreenPos, mouseWorldMap, mouseGridPos, tile, controlHovered); stringBuilder.AppendLine("\nAttached Entity:"); if (_playerManager.LocalPlayer?.ControlledEntity == null) { stringBuilder.AppendLine("No attached entity."); } else { var entityTransform = _playerManager.LocalPlayer.ControlledEntity.Transform; var playerWorldOffset = entityTransform.MapPosition; var playerScreen = _eyeManager.WorldToScreen(playerWorldOffset.Position); var playerCoordinates = _playerManager.LocalPlayer.ControlledEntity.Transform.Coordinates; stringBuilder.AppendFormat(@" Screen: {0} {1} {2} EntId: {3} GridID: {4}", playerScreen, playerWorldOffset, playerCoordinates, entityTransform.Owner.Uid, entityTransform.GridID); } if (controlHovered != null) { _uiBox = UIBox2i.FromDimensions(controlHovered.GlobalPixelPosition, controlHovered.PixelSize); } _contents.Text = stringBuilder.ToString(); MinimumSizeChanged(); }
protected override void FrameUpdate(FrameEventArgs args) { if (!VisibleInTree) { return; } var stringBuilder = new StringBuilder(); var mouseScreenPos = inputManager.MouseScreenPosition; var screenSize = _displayManager.ScreenSize; MapCoordinates mouseWorldMap; GridCoordinates mouseGridPos; TileRef tile; mouseWorldMap = eyeManager.ScreenToMap(mouseScreenPos); if (_mapManager.TryFindGridAt(mouseWorldMap, out var mouseGrid)) { mouseGridPos = mouseGrid.MapToGrid(mouseWorldMap); tile = mouseGrid.GetTileRef(mouseGridPos); } else { mouseGridPos = new GridCoordinates(mouseWorldMap.Position, GridId.Invalid); tile = default; } stringBuilder.AppendFormat(@"Positioning Debug: Screen Size: {0} Mouse Pos: Screen: {1} {2} {3} {4} GUI: {5}", screenSize, mouseScreenPos, mouseWorldMap, mouseGridPos, tile, UserInterfaceManager.CurrentlyHovered); stringBuilder.AppendLine("\nAttached Entity:"); if (playerManager.LocalPlayer?.ControlledEntity == null) { stringBuilder.AppendLine("No attached entity."); } else { var entityTransform = playerManager.LocalPlayer.ControlledEntity.Transform; var playerWorldOffset = entityTransform.MapPosition; var playerScreen = eyeManager.WorldToScreen(playerWorldOffset.Position); GridCoordinates playerGridPos; if (_mapManager.TryFindGridAt(playerWorldOffset, out var playerGrid)) { playerGridPos = playerGrid.MapToGrid(playerWorldOffset); } else { playerGridPos = new GridCoordinates(playerWorldOffset.Position, GridId.Invalid); } stringBuilder.AppendFormat(@" Screen: {0} {1} {2} EntityUid: {3}", playerScreen, playerWorldOffset, playerGridPos, entityTransform.Owner.Uid); } contents.Text = stringBuilder.ToString(); MinimumSizeChanged(); }
public override void Update(float frameTime) { base.Update(frameTime); if (!_gameTiming.IsFirstTimePredicted) { return; } var state = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use); if (!_combatModeSystem.IsInCombatMode() || state != BoundKeyState.Down) { _shotCounter = 0; _blocked = false; return; } var entity = _playerManager.LocalPlayer?.ControlledEntity; if (!EntityManager.TryGetComponent(entity, out SharedHandsComponent? hands)) { return; } if (!hands.TryGetActiveHeldEntity(out var held) || !EntityManager.TryGetComponent(held, out ClientRangedWeaponComponent? weapon)) { _blocked = true; return; } switch (weapon.FireRateSelector) { case FireRateSelector.Safety: _blocked = true; return; case FireRateSelector.Single: if (_shotCounter >= 1) { _blocked = true; return; } break; case FireRateSelector.Automatic: break; default: throw new ArgumentOutOfRangeException(); } if (_blocked) { return; } var mapCoordinates = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition); EntityCoordinates coordinates; if (_mapManager.TryFindGridAt(mapCoordinates, out var grid)) { coordinates = EntityCoordinates.FromMap(grid.GridEntityId, mapCoordinates); } else { coordinates = EntityCoordinates.FromMap(_mapManager.GetMapEntityId(mapCoordinates.MapId), mapCoordinates); } SyncFirePos(coordinates); }