public bool IsDown() { switch (MouseButton) { case null: return(PlayerInput.KeyDown(Key)); case 0: return(PlayerInput.LeftButtonHeld()); case 1: return(PlayerInput.RightButtonHeld()); case 2: return(PlayerInput.MidButtonHeld()); case 3: return(PlayerInput.Mouse4ButtonHeld()); case 4: return(PlayerInput.Mouse5ButtonHeld()); case 5: // No real way of "holding" a mouse wheel key, but then again it makes no sense to bind the key to this kind of task. return(PlayerInput.MouseWheelUpClicked()); case 6: return(PlayerInput.MouseWheelDownClicked()); } return(false); }
public override void Update(double deltaTime) { base.Update(deltaTime); Widget.EnableMultiSelect = PlayerInput.KeyDown(Keys.LeftControl); spriteList.SelectMultiple = Widget.EnableMultiSelect; // Select rects with the mouse if (Widget.selectedWidgets.None() || Widget.EnableMultiSelect) { if (selectedTexture != null) { foreach (Sprite sprite in loadedSprites) { if (sprite.Texture != selectedTexture) { continue; } if (PlayerInput.LeftButtonClicked()) { var scaledRect = new Rectangle(textureRect.Location + sprite.SourceRect.Location.Multiply(zoom), sprite.SourceRect.Size.Multiply(zoom)); if (scaledRect.Contains(PlayerInput.MousePosition)) { spriteList.Select(sprite, autoScroll: false); UpdateScrollBar(spriteList); UpdateScrollBar(textureList); } } } } } if (GUI.MouseOn == null) { if (PlayerInput.ScrollWheelSpeed != 0) { zoom = MathHelper.Clamp(zoom + PlayerInput.ScrollWheelSpeed * (float)deltaTime * 0.05f * zoom, minZoom, maxZoom); zoomBar.BarScroll = GetBarScrollValue(); } widgets.Values.ForEach(w => w.Update((float)deltaTime)); if (PlayerInput.MidButtonHeld()) { // "Camera" Pan Vector2 moveSpeed = PlayerInput.MouseSpeed * (float)deltaTime * 100.0f; viewAreaOffset += moveSpeed.ToPoint(); } } }
public bool IsDown() { switch (MouseButton) { case MouseButton.None: return(PlayerInput.KeyDown(Key)); case MouseButton.PrimaryMouse: return(PlayerInput.PrimaryMouseButtonHeld()); case MouseButton.SecondaryMouse: return(PlayerInput.SecondaryMouseButtonHeld()); case MouseButton.LeftMouse: return(PlayerInput.LeftButtonHeld()); case MouseButton.RightMouse: return(PlayerInput.RightButtonHeld()); case MouseButton.MiddleMouse: return(PlayerInput.MidButtonHeld()); case MouseButton.MouseButton4: return(PlayerInput.Mouse4ButtonHeld()); case MouseButton.MouseButton5: return(PlayerInput.Mouse5ButtonHeld()); case MouseButton.MouseWheelUp: // No real way of "holding" a mouse wheel key, but then again it makes no sense to bind the key to this kind of task. return(PlayerInput.MouseWheelUpClicked()); case MouseButton.MouseWheelDown: return(PlayerInput.MouseWheelDownClicked()); } return(false); }
public void Update(float deltaTime, GUICustomComponent mapContainer) { Rectangle rect = mapContainer.Rect; subReticlePosition = Vector2.Lerp(subReticlePosition, CurrentLocation.MapPosition, deltaTime); subReticleAnimState = 0.8f - Vector2.Distance(subReticlePosition, CurrentLocation.MapPosition) / 50.0f; subReticleAnimState = MathHelper.Clamp(subReticleAnimState + (float)Math.Sin(Timing.TotalTime * 3.5f) * 0.2f, 0.0f, 1.0f); targetReticleAnimState = SelectedLocation == null? Math.Max(targetReticleAnimState - deltaTime, 0.0f) : Math.Min(targetReticleAnimState + deltaTime, 0.6f + (float)Math.Sin(Timing.TotalTime * 2.5f) * 0.4f); #if DEBUG if (GameMain.DebugDraw) { if (editor == null) { CreateEditor(); } editor.AddToGUIUpdateList(order: 1); } #endif if (mapAnimQueue.Count > 0) { hudOpenState = Math.Max(hudOpenState - deltaTime, 0.0f); UpdateMapAnim(mapAnimQueue.Peek(), deltaTime); if (mapAnimQueue.Peek().Finished) { mapAnimQueue.Dequeue(); } return; } hudOpenState = Math.Min(hudOpenState + deltaTime, 0.75f + (float)Math.Sin(Timing.TotalTime * 3.0f) * 0.25f); Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y); float closestDist = 0.0f; highlightedLocation = null; if (GUI.MouseOn == null || GUI.MouseOn == mapContainer) { for (int i = 0; i < Locations.Count; i++) { Location location = Locations[i]; Vector2 pos = rectCenter + (location.MapPosition + drawOffset) * zoom; if (!rect.Contains(pos)) { continue; } float iconScale = MapGenerationParams.Instance.LocationIconSize / location.Type.Sprite.size.X; Rectangle drawRect = location.Type.Sprite.SourceRect; drawRect.Width = (int)(drawRect.Width * iconScale * zoom * 1.4f); drawRect.Height = (int)(drawRect.Height * iconScale * zoom * 1.4f); drawRect.X = (int)pos.X - drawRect.Width / 2; drawRect.Y = (int)pos.Y - drawRect.Width / 2; if (!drawRect.Contains(PlayerInput.MousePosition)) { continue; } float dist = Vector2.Distance(PlayerInput.MousePosition, pos); if (highlightedLocation == null || dist < closestDist) { closestDist = dist; highlightedLocation = location; } } } foreach (LocationConnection connection in connections) { if (highlightedLocation != CurrentLocation && connection.Locations.Contains(highlightedLocation) && connection.Locations.Contains(CurrentLocation)) { if (PlayerInput.LeftButtonClicked() && SelectedLocation != highlightedLocation && highlightedLocation != null) { //clients aren't allowed to select the location without a permission if (GameMain.Client == null || GameMain.Client.HasPermission(Networking.ClientPermissions.ManageCampaign)) { SelectedConnection = connection; SelectedLocation = highlightedLocation; targetReticleAnimState = 0.0f; OnLocationSelected?.Invoke(SelectedLocation, SelectedConnection); GameMain.Client?.SendCampaignState(); } } } } if (GUI.KeyboardDispatcher.Subscriber == null) { float moveSpeed = 1000.0f; Vector2 moveAmount = Vector2.Zero; if (PlayerInput.KeyDown(InputType.Left)) { moveAmount += Vector2.UnitX; } if (PlayerInput.KeyDown(InputType.Right)) { moveAmount -= Vector2.UnitX; } if (PlayerInput.KeyDown(InputType.Up)) { moveAmount += Vector2.UnitY; } if (PlayerInput.KeyDown(InputType.Down)) { moveAmount -= Vector2.UnitY; } drawOffset += moveAmount * moveSpeed / zoom * deltaTime; } if (GUI.MouseOn == mapContainer) { zoom += PlayerInput.ScrollWheelSpeed / 1000.0f; zoom = MathHelper.Clamp(zoom, 1.0f, 4.0f); if (PlayerInput.MidButtonHeld() || (highlightedLocation == null && PlayerInput.LeftButtonHeld())) { drawOffset += PlayerInput.MouseSpeed / zoom; } #if DEBUG if (PlayerInput.DoubleClicked() && highlightedLocation != null) { var passedConnection = CurrentLocation.Connections.Find(c => c.OtherLocation(CurrentLocation) == highlightedLocation); if (passedConnection != null) { passedConnection.Passed = true; } Location prevLocation = CurrentLocation; CurrentLocation = highlightedLocation; CurrentLocation.Discovered = true; OnLocationChanged?.Invoke(prevLocation, CurrentLocation); SelectLocation(-1); ProgressWorld(); } #endif } }
public override void Update(double deltaTime) { if (GameMain.GraphicsWidth != screenResolution.X || GameMain.GraphicsHeight != screenResolution.Y) { CreateGUI(); } Cam.MoveCamera((float)deltaTime, true, true); Vector2 mousePos = Cam.ScreenToWorld(PlayerInput.MousePosition); mousePos.Y = -mousePos.Y; foreach (EditorNode node in nodeList) { if (PlayerInput.PrimaryMouseButtonDown()) { NodeConnection?connection = node.GetConnectionOnMouse(mousePos); if (connection != null && connection.Type.NodeSide == NodeConnectionType.Side.Right) { if (connection.Type != NodeConnectionType.Out) { if (connection.ConnectedTo.Any()) { return; } } DraggedConnection = connection; } } // ReSharper disable once AssignmentInConditionalExpression if (node.IsHighlighted = node.HeaderRectangle.Contains(mousePos)) { if (PlayerInput.PrimaryMouseButtonDown()) { // Ctrl + clicking the headers add them to the "selection" that allows us to drag multiple nodes at once if (PlayerInput.IsCtrlDown()) { if (selectedNodes.Contains(node)) { selectedNodes.Remove(node); } else { selectedNodes.Add(node); } node.IsSelected = selectedNodes.Contains(node); break; } draggedNode = node; dragOffset = draggedNode.Position - mousePos; foreach (EditorNode selectedNode in selectedNodes) { if (!markedNodes.ContainsKey(selectedNode)) { markedNodes.Add(selectedNode, selectedNode.Position - mousePos); } } } } if (PlayerInput.SecondaryMouseButtonClicked()) { NodeConnection?connection = node.GetConnectionOnMouse(mousePos); if (node.GetDrawRectangle().Contains(mousePos) || connection != null) { CreateContextMenu(node, node.GetConnectionOnMouse(mousePos)); break; } } } if (PlayerInput.SecondaryMouseButtonClicked()) { foreach (var selectedNode in selectedNodes) { selectedNode.IsSelected = false; } selectedNodes.Clear(); } if (draggedNode != null) { if (!PlayerInput.PrimaryMouseButtonHeld()) { draggedNode = null; markedNodes.Clear(); } else { Vector2 offsetChange = Vector2.Zero; draggedNode.IsHighlighted = true; draggedNode.Position = mousePos + dragOffset; if (PlayerInput.KeyHit(Keys.Up)) { offsetChange.Y--; } if (PlayerInput.KeyHit(Keys.Down)) { offsetChange.Y++; } if (PlayerInput.KeyHit(Keys.Left)) { offsetChange.X--; } if (PlayerInput.KeyHit(Keys.Right)) { offsetChange.X++; } dragOffset += offsetChange; foreach (var(editorNode, offset) in markedNodes.Where(pair => pair.Key != draggedNode)) { editorNode.Position = mousePos + offset; } if (offsetChange != Vector2.Zero) { foreach (var(key, value) in markedNodes.ToList()) { markedNodes[key] = value + offsetChange; } } } } if (DraggedConnection != null) { if (!PlayerInput.PrimaryMouseButtonHeld()) { foreach (EditorNode node in nodeList) { var nodeOnMouse = node.GetConnectionOnMouse(mousePos); if (nodeOnMouse != null && nodeOnMouse != DraggedConnection && nodeOnMouse.Type.NodeSide == NodeConnectionType.Side.Left) { if (!DraggedConnection.CanConnect(nodeOnMouse)) { continue; } nodeOnMouse.ClearConnections(); DraggedConnection.Parent.Connect(DraggedConnection, nodeOnMouse); break; } } DraggedConnection = null; } else { DraggingPosition = mousePos; } } else { DraggingPosition = Vector2.Zero; } if (contextMenu != null) { Rectangle expandedRect = contextMenu.Rect; expandedRect.Inflate(20, 20); if (!expandedRect.Contains(PlayerInput.MousePosition)) { contextMenu = null; } } if (PlayerInput.MidButtonHeld()) { Vector2 moveSpeed = PlayerInput.MouseSpeed * (float)deltaTime * 60.0f / Cam.Zoom; moveSpeed.X = -moveSpeed.X; Cam.Position += moveSpeed; } base.Update(deltaTime); }
private SubmarinePreview(SubmarineInfo subInfo) { camera = new Camera(); submarineInfo = subInfo; spriteRecorder = new SpriteRecorder(); isDisposed = false; loadTask = null; hullCollections = new Dictionary <string, HullCollection>(); doors = new List <Door>(); previewFrame = new GUIFrame(new RectTransform(Vector2.One, GUI.Canvas, Anchor.Center), style: null); new GUIFrame(new RectTransform(GUI.Canvas.RelativeSize, previewFrame.RectTransform, Anchor.Center), style: "GUIBackgroundBlocker"); new GUIButton(new RectTransform(Vector2.One, previewFrame.RectTransform), "", style: null) { OnClicked = (btn, obj) => { Dispose(); return(false); } }; var innerFrame = new GUIFrame(new RectTransform(Vector2.One * 0.9f, previewFrame.RectTransform, Anchor.Center)); int innerPadding = GUI.IntScale(100f); var innerPadded = new GUIFrame(new RectTransform(new Point(innerFrame.Rect.Width - innerPadding, innerFrame.Rect.Height - innerPadding), previewFrame.RectTransform, Anchor.Center), style: null) { OutlineColor = Color.Black, OutlineThickness = 2 }; GUITextBlock titleText = null; GUIListBox specsContainer = null; new GUICustomComponent(new RectTransform(Vector2.One, innerPadded.RectTransform, Anchor.Center), (spriteBatch, component) => { camera.UpdateTransform(interpolate: true, updateListener: false); Rectangle drawRect = new Rectangle(component.Rect.X + 1, component.Rect.Y + 1, component.Rect.Width - 2, component.Rect.Height - 2); RenderSubmarine(spriteBatch, drawRect); }, (deltaTime, component) => { bool isMouseOnComponent = GUI.MouseOn == component; camera.MoveCamera(deltaTime, allowZoom: isMouseOnComponent, followSub: false); if (isMouseOnComponent && (PlayerInput.MidButtonHeld() || PlayerInput.LeftButtonHeld())) { Vector2 moveSpeed = PlayerInput.MouseSpeed * (float)deltaTime * 60.0f / camera.Zoom; moveSpeed.X = -moveSpeed.X; camera.Position += moveSpeed; } if (titleText != null && specsContainer != null) { specsContainer.Visible = GUI.IsMouseOn(titleText); } }); var topContainer = new GUIFrame(new RectTransform(new Vector2(1f, 0.07f), innerPadded.RectTransform, Anchor.TopLeft), style: null) { Color = Color.Black * 0.65f }; var topLayout = new GUILayoutGroup(new RectTransform(new Vector2(0.97f, 5f / 7f), topContainer.RectTransform, Anchor.Center), isHorizontal: true, childAnchor: Anchor.CenterLeft); titleText = new GUITextBlock(new RectTransform(new Vector2(0.95f, 1f), topLayout.RectTransform), subInfo.DisplayName, font: GUI.LargeFont); new GUIButton(new RectTransform(new Vector2(0.05f, 1f), topLayout.RectTransform), TextManager.Get("Close")) { OnClicked = (btn, obj) => { Dispose(); return(false); } }; specsContainer = new GUIListBox(new RectTransform(new Vector2(0.4f, 1f), innerPadded.RectTransform, Anchor.TopLeft) { RelativeOffset = new Vector2(0.015f, 0.07f) }) { Color = Color.Black * 0.65f, ScrollBarEnabled = false, ScrollBarVisible = false, Spacing = 5 }; subInfo.CreateSpecsWindow(specsContainer, GUI.Font, includeTitle: false, includeDescription: true); int width = specsContainer.Rect.Width; void recalculateSpecsContainerHeight() { int totalSize = 0; var children = specsContainer.Content.Children.Where(c => c.Visible); foreach (GUIComponent child in children) { totalSize += child.Rect.Height; } totalSize += specsContainer.Content.CountChildren * specsContainer.Spacing; if (specsContainer.PadBottom) { GUIComponent last = specsContainer.Content.Children.LastOrDefault(); if (last != null) { totalSize += specsContainer.Rect.Height - last.Rect.Height; } } specsContainer.RectTransform.Resize(new Point(width, totalSize), true); specsContainer.RecalculateChildren(); } //hell recalculateSpecsContainerHeight(); specsContainer.Content.GetAllChildren <GUITextBlock>().ForEach(c => { var firstChild = c.Children.FirstOrDefault() as GUITextBlock; if (firstChild != null) { firstChild.CalculateHeightFromText(); firstChild.SetTextPos(); c.RectTransform.MinSize = new Point(0, firstChild.Rect.Height); } c.CalculateHeightFromText(); c.SetTextPos(); }); recalculateSpecsContainerHeight(); GeneratePreviewMeshes(); }
public void Update(float deltaTime, GUICustomComponent mapContainer) { Rectangle rect = mapContainer.Rect; if (CurrentDisplayLocation != null) { if (!CurrentDisplayLocation.Discovered) { RemoveFogOfWar(CurrentDisplayLocation); CurrentDisplayLocation.Discovered = true; if (CurrentDisplayLocation.MapPosition.X > furthestDiscoveredLocation.MapPosition.X) { furthestDiscoveredLocation = CurrentDisplayLocation; } } } currLocationIndicatorPos = Vector2.Lerp(currLocationIndicatorPos, CurrentDisplayLocation.MapPosition, deltaTime); #if DEBUG if (GameMain.DebugDraw) { if (editor == null) { CreateEditor(); } editor.AddToGUIUpdateList(order: 1); } #endif if (mapAnimQueue.Count > 0) { hudVisibility = Math.Max(hudVisibility - deltaTime, 0.0f); UpdateMapAnim(mapAnimQueue.Peek(), deltaTime); if (mapAnimQueue.Peek().Finished) { mapAnimQueue.Dequeue(); } return; } hudVisibility = Math.Min(hudVisibility + deltaTime, 0.75f + (float)Math.Sin(Timing.TotalTime * 3.0f) * 0.25f); Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y); Vector2 viewOffset = DrawOffset + drawOffsetNoise; float closestDist = 0.0f; HighlightedLocation = null; if (GUI.MouseOn == null || GUI.MouseOn == mapContainer) { for (int i = 0; i < Locations.Count; i++) { Location location = Locations[i]; if (IsInFogOfWar(location) && !(CurrentDisplayLocation?.Connections.Any(c => c.Locations.Contains(location)) ?? false) && !GameMain.DebugDraw) { continue; } Vector2 pos = rectCenter + (location.MapPosition + viewOffset) * zoom; if (!rect.Contains(pos)) { continue; } float iconScale = generationParams.LocationIconSize / location.Type.Sprite.size.X; if (location == CurrentDisplayLocation) { iconScale *= 1.2f; } Rectangle drawRect = location.Type.Sprite.SourceRect; drawRect.Width = (int)(drawRect.Width * iconScale * zoom * 1.4f); drawRect.Height = (int)(drawRect.Height * iconScale * zoom * 1.4f); drawRect.X = (int)pos.X - drawRect.Width / 2; drawRect.Y = (int)pos.Y - drawRect.Width / 2; if (!drawRect.Contains(PlayerInput.MousePosition)) { continue; } float dist = Vector2.Distance(PlayerInput.MousePosition, pos); if (HighlightedLocation == null || dist < closestDist) { closestDist = dist; HighlightedLocation = location; } } } if (GUI.KeyboardDispatcher.Subscriber == null) { float moveSpeed = 1000.0f; Vector2 moveAmount = Vector2.Zero; if (PlayerInput.KeyDown(InputType.Left)) { moveAmount += Vector2.UnitX; } if (PlayerInput.KeyDown(InputType.Right)) { moveAmount -= Vector2.UnitX; } if (PlayerInput.KeyDown(InputType.Up)) { moveAmount += Vector2.UnitY; } if (PlayerInput.KeyDown(InputType.Down)) { moveAmount -= Vector2.UnitY; } DrawOffset += moveAmount * moveSpeed / zoom * deltaTime; } targetZoom = MathHelper.Clamp(targetZoom, generationParams.MinZoom, generationParams.MaxZoom); zoom = MathHelper.Lerp(zoom, targetZoom, 0.1f); if (GUI.MouseOn == mapContainer) { foreach (LocationConnection connection in Connections) { if (HighlightedLocation != CurrentDisplayLocation && connection.Locations.Contains(HighlightedLocation) && connection.Locations.Contains(CurrentDisplayLocation)) { if (PlayerInput.PrimaryMouseButtonClicked() && SelectedLocation != HighlightedLocation && HighlightedLocation != null) { //clients aren't allowed to select the location without a permission if ((GameMain.GameSession?.GameMode as CampaignMode)?.AllowedToManageCampaign() ?? false) { SelectedConnection = connection; SelectedLocation = HighlightedLocation; OnLocationSelected?.Invoke(SelectedLocation, SelectedConnection); GameMain.Client?.SendCampaignState(); } } } } targetZoom += PlayerInput.ScrollWheelSpeed / 500.0f; if (PlayerInput.MidButtonHeld() || (HighlightedLocation == null && PlayerInput.PrimaryMouseButtonHeld())) { DrawOffset += PlayerInput.MouseSpeed / zoom; } if (AllowDebugTeleport) { if (PlayerInput.DoubleClicked() && HighlightedLocation != null) { var passedConnection = CurrentDisplayLocation.Connections.Find(c => c.OtherLocation(CurrentDisplayLocation) == HighlightedLocation); if (passedConnection != null) { passedConnection.Passed = true; } Location prevLocation = CurrentDisplayLocation; CurrentLocation = HighlightedLocation; Level.Loaded.DebugSetStartLocation(CurrentLocation); Level.Loaded.DebugSetEndLocation(null); CurrentLocation.Discovered = true; CurrentLocation.CreateStore(); OnLocationChanged?.Invoke(prevLocation, CurrentLocation); SelectLocation(-1); if (GameMain.Client == null) { ProgressWorld(); } else { GameMain.Client.SendCampaignState(); } } if (PlayerInput.KeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift) && PlayerInput.PrimaryMouseButtonClicked() && HighlightedLocation != null) { int distance = DistanceToClosestLocationWithOutpost(HighlightedLocation, out Location foundLocation); DebugConsole.NewMessage($"Distance to closest outpost from {HighlightedLocation.Name} to {foundLocation?.Name} is {distance}"); } if (PlayerInput.PrimaryMouseButtonClicked() && HighlightedLocation == null) { SelectLocation(-1); } } } }