public void DrawPinnedEvent(SpriteBatch spriteBatch) { if (PinnedEvent != null) { Rectangle rect = DrawEvent(spriteBatch, PinnedEvent, null); if (rect != Rectangle.Empty) { if (rect.Contains(PlayerInput.MousePosition) && !isDragging) { GUI.MouseCursor = CursorState.Move; if (PlayerInput.PrimaryMouseButtonDown() || PlayerInput.PrimaryMouseButtonHeld()) { isDragging = true; } if (PlayerInput.SecondaryMouseButtonClicked() || PlayerInput.SecondaryMouseButtonHeld()) { PinnedEvent = null; isDragging = false; } } } if (isDragging) { GUI.MouseCursor = CursorState.Dragging; pinnedPosition = PlayerInput.MousePosition - (new Vector2(rect.Width / 2.0f, -24)); if (!PlayerInput.PrimaryMouseButtonHeld()) { isDragging = false; } } } }
partial void UpdateProjSpecific(float deltaTime) { if (GUI.DisableHUD) { return; } if (GameMode.IsRunning) { if (tabMenu == null) { if (PlayerInput.KeyHit(InputType.InfoTab) && GUI.KeyboardDispatcher.Subscriber is GUITextBox == false) { ToggleTabMenu(); } } else { tabMenu.Update(); if (PlayerInput.KeyHit(InputType.InfoTab) && GUI.KeyboardDispatcher.Subscriber is GUITextBox == false) { ToggleTabMenu(); } } } else { if (tabMenu != null) { ToggleTabMenu(); } } if (GameMain.NetworkMember != null) { if (GameMain.NetLobbyScreen?.HeadSelectionList != null) { if (PlayerInput.PrimaryMouseButtonDown() && !GUI.IsMouseOn(GameMain.NetLobbyScreen.HeadSelectionList)) { if (GameMain.NetLobbyScreen.HeadSelectionList != null) { GameMain.NetLobbyScreen.HeadSelectionList.Visible = false; } } } if (GameMain.NetLobbyScreen?.JobSelectionFrame != null) { if (PlayerInput.PrimaryMouseButtonDown() && !GUI.IsMouseOn(GameMain.NetLobbyScreen.JobSelectionFrame)) { GameMain.NetLobbyScreen.JobList.Deselect(); if (GameMain.NetLobbyScreen.JobSelectionFrame != null) { GameMain.NetLobbyScreen.JobSelectionFrame.Visible = false; } } } } }
protected override void Update(float deltaTime) { if (!Visible) { return; } base.Update(deltaTime); if (Rect.Contains(PlayerInput.MousePosition) && CanBeSelected && CanBeFocused && Enabled && GUI.IsMouseOn(this)) { State = Selected ? ComponentState.HoverSelected : ComponentState.Hover; if (PlayerInput.PrimaryMouseButtonDown()) { OnButtonDown?.Invoke(); } if (PlayerInput.PrimaryMouseButtonHeld()) { if (OnPressed != null) { if (OnPressed()) { State = ComponentState.Pressed; } } else { State = ComponentState.Pressed; } } else if (PlayerInput.PrimaryMouseButtonClicked()) { GUI.PlayUISound(GUISoundType.Click); if (OnClicked != null) { if (OnClicked(this, UserData)) { State = ComponentState.Selected; } } else { Selected = !Selected; } } } else { State = Selected ? ComponentState.Selected : ComponentState.None; } foreach (GUIComponent child in Children) { child.State = State; } }
public void Update(float deltaTime) { if (!Selected) { return; } if (widgets.Values.Any(w => w.IsSelected)) { return; } if (PlayerInput.PrimaryMouseButtonDown() && !disableMove && IsMouseOn()) { isDragging = true; } if (isDragging) { Camera cam = Screen.Selected.Cam; if (PlayerInput.MouseSpeed != Vector2.Zero) { Vector2 mouseSpeed = PlayerInput.MouseSpeed; if (DrawTarget == DrawTargetType.World) { mouseSpeed /= cam.Zoom; } Position += mouseSpeed; UpdateRectangle(); } } if (PlayerInput.KeyDown(Keys.OemPlus) || PlayerInput.KeyDown(Keys.Up)) { Opacity += 0.01f; } if (PlayerInput.KeyDown(Keys.OemMinus) || PlayerInput.KeyDown(Keys.Down)) { Opacity -= 0.01f; } if (PlayerInput.KeyHit(Keys.D0)) { Opacity = 1f; } Opacity = Math.Clamp(Opacity, 0, 1f); if (!PlayerInput.PrimaryMouseButtonHeld()) { isDragging = false; } }
private bool SelectBar() { if (!enabled || !PlayerInput.PrimaryMouseButtonDown()) { return(false); } if (barSize >= 1.0f) { return(false); } DraggingBar = this; return(true); }
public virtual void Update(float deltaTime) { PreUpdate?.Invoke(deltaTime); if (!enabled) { return; } if (IsMouseOver || (!RequireMouseOn && selectedWidgets.Contains(this) && PlayerInput.PrimaryMouseButtonHeld())) { Hovered?.Invoke(); System.Diagnostics.Debug.WriteLine("hovered"); if (RequireMouseOn || PlayerInput.PrimaryMouseButtonDown()) { if ((multiselect && !selectedWidgets.Contains(this)) || selectedWidgets.None()) { selectedWidgets.Add(this); Selected?.Invoke(); } } } else if (selectedWidgets.Contains(this)) { System.Diagnostics.Debug.WriteLine("selectedWidgets.Contains(this) -> remove"); selectedWidgets.Remove(this); Deselected?.Invoke(); } if (IsSelected) { if (PlayerInput.PrimaryMouseButtonDown()) { MouseDown?.Invoke(); } if (PlayerInput.PrimaryMouseButtonHeld()) { MouseHeld?.Invoke(deltaTime); } if (PlayerInput.PrimaryMouseButtonClicked()) { MouseUp?.Invoke(); } } PostUpdate?.Invoke(deltaTime); }
partial void UpdateProjSpecific(float deltaTime) { if (GUI.DisableHUD) { return; } if (tabMenu == null) { if (PlayerInput.KeyHit(InputType.InfoTab) && !(GUI.KeyboardDispatcher.Subscriber is GUITextBox)) { ToggleTabMenu(); } } else { tabMenu.Update(); if ((PlayerInput.KeyHit(InputType.InfoTab) || PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.Escape)) && !(GUI.KeyboardDispatcher.Subscriber is GUITextBox)) { ToggleTabMenu(); } } UpdateTalentNotificationIndicator(talentPointNotification); if (GameMain.NetworkMember != null) { GameMain.NetLobbyScreen?.CharacterAppearanceCustomizationMenu?.Update(); if (GameMain.NetLobbyScreen?.JobSelectionFrame != null) { if (GameMain.NetLobbyScreen.JobSelectionFrame != null && PlayerInput.PrimaryMouseButtonDown() && !GUI.IsMouseOn(GameMain.NetLobbyScreen.JobSelectionFrame)) { GameMain.NetLobbyScreen.JobList.Deselect(); GameMain.NetLobbyScreen.JobSelectionFrame.Visible = false; } } } HintManager.Update(); }
public static bool CloseHUD(Rectangle rect) { // Always close when hitting escape if (PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.Escape)) { return(true); } //don't close when the cursor is on a UI element if (GUI.MouseOn != null) { return(false); } //don't close when hovering over an inventory element if (Inventory.IsMouseOnInventory()) { return(false); } bool input = PlayerInput.PrimaryMouseButtonDown() || PlayerInput.SecondaryMouseButtonClicked(); return(input && !rect.Contains(PlayerInput.MousePosition)); }
private void UpdateChildrenRect() { //dragging if (CanDragElements && draggedElement != null) { if (!PlayerInput.PrimaryMouseButtonHeld()) { OnRearranged?.Invoke(this, draggedElement.UserData); draggedElement = null; RepositionChildren(); } else { draggedElement.RectTransform.AbsoluteOffset = isHorizontal ? draggedReferenceOffset + new Point((int)PlayerInput.MousePosition.X - draggedReferenceRectangle.Center.X, 0) : draggedReferenceOffset + new Point(0, (int)PlayerInput.MousePosition.Y - draggedReferenceRectangle.Center.Y); int index = Content.RectTransform.GetChildIndex(draggedElement.RectTransform); int currIndex = index; if (isHorizontal) { while (currIndex > 0 && PlayerInput.MousePosition.X < draggedReferenceRectangle.Left) { currIndex--; draggedReferenceRectangle.X -= draggedReferenceRectangle.Width; draggedReferenceOffset.X -= draggedReferenceRectangle.Width; } while (currIndex < Content.CountChildren - 1 && PlayerInput.MousePosition.X > draggedReferenceRectangle.Right) { currIndex++; draggedReferenceRectangle.X += draggedReferenceRectangle.Width; draggedReferenceOffset.X += draggedReferenceRectangle.Width; } } else { while (currIndex > 0 && PlayerInput.MousePosition.Y < draggedReferenceRectangle.Top) { currIndex--; draggedReferenceRectangle.Y -= draggedReferenceRectangle.Height; draggedReferenceOffset.Y -= draggedReferenceRectangle.Height; } while (currIndex < Content.CountChildren - 1 && PlayerInput.MousePosition.Y > draggedReferenceRectangle.Bottom) { currIndex++; draggedReferenceRectangle.Y += draggedReferenceRectangle.Height; draggedReferenceOffset.Y += draggedReferenceRectangle.Height; } } if (currIndex != index) { draggedElement.RectTransform.RepositionChildInHierarchy(currIndex); } return; } } if (SelectTop) { foreach (GUIComponent child in Content.Children) { child.CanBeFocused = !selected.Contains(child); if (!child.CanBeFocused) { child.State = ComponentState.None; } } } if (SelectTop && Content.Children.Any() && scrollToElement == null) { GUIComponent component = Content.Children.FirstOrDefault(c => (c.Rect.Y - Content.Rect.Y) / (float)c.Rect.Height > -0.1f); if (component != null && !selected.Contains(component)) { int index = Content.Children.ToList().IndexOf(component); if (index >= 0) { Select(index, false, false, takeKeyBoardFocus: true); } } } for (int i = 0; i < Content.CountChildren; i++) { var child = Content.RectTransform.GetChild(i)?.GUIComponent; if (child == null || !child.Visible) { continue; } // selecting if (Enabled && CanBeFocused && child.CanBeFocused && child.Rect.Contains(PlayerInput.MousePosition) && GUI.IsMouseOn(child)) { child.State = ComponentState.Hover; var mouseDown = useMouseDownToSelect ? PlayerInput.PrimaryMouseButtonDown() : PlayerInput.PrimaryMouseButtonClicked(); if (mouseDown) { if (SelectTop) { ScrollToElement(child); Select(i, autoScroll: false, takeKeyBoardFocus: true); } else { Select(i, autoScroll: false, takeKeyBoardFocus: true); } } if (CanDragElements && PlayerInput.PrimaryMouseButtonDown() && GUI.MouseOn == child) { draggedElement = child; draggedReferenceRectangle = child.Rect; draggedReferenceOffset = child.RectTransform.AbsoluteOffset; } } else if (selected.Contains(child)) { child.State = ComponentState.Selected; if (CheckSelected != null) { if (CheckSelected() != child.UserData) { selected.Remove(child); } } } else { child.State = !child.ExternalHighlight ? ComponentState.None : ComponentState.Hover; } } }
protected override void Update(float deltaTime) { base.Update(deltaTime); if (!isInitialized) { Init(); isInitialized = true; } if (!PlayerInput.PrimaryMouseButtonHeld()) { mouseHeld = false; } if (GUI.MouseOn != this) { return; } Rectangle mainArea = MainArea, hueArea = HueArea; hueArea.Location += Rect.Location; mainArea.Location += Rect.Location; if (PlayerInput.PrimaryMouseButtonDown()) { mouseHeld = true; if (hueArea.Contains(PlayerInput.MousePosition)) { selectedRect = HueArea; } else if (mainArea.Contains(PlayerInput.MousePosition)) { selectedRect = MainArea; } else { mouseHeld = false; } } if (!PlayerInput.PrimaryMouseButtonHeld()) { mouseHeld = false; } if (mouseHeld && (PlayerInput.MouseSpeed != Vector2.Zero || PlayerInput.PrimaryMouseButtonDown())) { if (selectedRect == HueArea) { Vector2 pos = PlayerInput.MousePosition - hueArea.Location.ToVector2(); SelectedHue = Math.Clamp(pos.Y / hueArea.Height * 360f, 0, 360); RefreshHue(); } else if (selectedRect == MainArea) { var(x, y) = PlayerInput.MousePosition - mainArea.Location.ToVector2(); SelectedSaturation = Math.Clamp(x / mainArea.Width, 0, 1); SelectedValue = Math.Clamp(1f - (y / mainArea.Height), 0, 1); } CurrentColor = ToolBox.HSVToRGB(SelectedHue, SelectedSaturation, SelectedValue); OnColorSelected?.Invoke(this, CurrentColor); } }
private void UpdateChildrenRect() { //dragging if (CanDragElements && draggedElement != null) { if (!PlayerInput.LeftButtonHeld()) { OnRearranged?.Invoke(this, draggedElement.UserData); draggedElement = null; RepositionChildren(); } else { draggedElement.RectTransform.AbsoluteOffset = draggedReferenceOffset + new Point(0, (int)PlayerInput.MousePosition.Y - draggedReferenceRectangle.Center.Y); int index = Content.RectTransform.GetChildIndex(draggedElement.RectTransform); int currIndex = index; while (currIndex > 0 && PlayerInput.MousePosition.Y < draggedReferenceRectangle.Top) { currIndex--; draggedReferenceRectangle.Y -= draggedReferenceRectangle.Height; draggedReferenceOffset.Y -= draggedReferenceRectangle.Height; } while (currIndex < Content.CountChildren - 1 && PlayerInput.MousePosition.Y > draggedReferenceRectangle.Bottom) { currIndex++; draggedReferenceRectangle.Y += draggedReferenceRectangle.Height; draggedReferenceOffset.Y += draggedReferenceRectangle.Height; } if (currIndex != index) { draggedElement.RectTransform.RepositionChildInHierarchy(currIndex); } return; } } for (int i = 0; i < Content.CountChildren; i++) { var child = Content.RectTransform.GetChild(i)?.GUIComponent; if (child == null) { continue; } // selecting if (Enabled && CanBeFocused && child.CanBeFocused && (GUI.IsMouseOn(child)) && child.Rect.Contains(PlayerInput.MousePosition)) { child.State = ComponentState.Hover; var mouseDown = useMouseDownToSelect ? PlayerInput.PrimaryMouseButtonDown() : PlayerInput.PrimaryMouseButtonClicked(); if (mouseDown) { Select(i, autoScroll: false); } if (CanDragElements && PlayerInput.LeftButtonDown() && GUI.MouseOn == child) { draggedElement = child; draggedReferenceRectangle = child.Rect; draggedReferenceOffset = child.RectTransform.AbsoluteOffset; } } else if (selected.Contains(child)) { child.State = ComponentState.Selected; if (CheckSelected != null) { if (CheckSelected() != child.UserData) { selected.Remove(child); } } } else { child.State = !child.ExternalHighlight ? ComponentState.None : ComponentState.Hover; } } }
private void DrawSplashScreen(SpriteBatch spriteBatch, GraphicsDevice graphics) { if (currSplashScreen == null && PendingSplashScreens.Count == 0) { return; } if (currSplashScreen == null) { var newSplashScreen = PendingSplashScreens.Dequeue(); string fileName = newSplashScreen.Filename; try { currSplashScreen = Video.Load(graphics, GameMain.SoundManager, fileName); currSplashScreen.AudioGain = newSplashScreen.Gain; videoStartTime = DateTime.Now; } catch (Exception e) { GameMain.Config.EnableSplashScreen = false; DebugConsole.ThrowError("Playing the splash screen \"" + fileName + "\" failed.", e); PendingSplashScreens.Clear(); currSplashScreen = null; } if (currSplashScreen == null) { return; } } if (currSplashScreen.IsPlaying) { spriteBatch.Begin(); spriteBatch.Draw(currSplashScreen.GetTexture(), new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White); spriteBatch.End(); if (DateTime.Now > videoStartTime + new TimeSpan(0, 0, 0, 0, milliseconds: 500) && GameMain.WindowActive && (PlayerInput.KeyHit(Keys.Space) || PlayerInput.KeyHit(Keys.Enter) || PlayerInput.PrimaryMouseButtonDown())) { currSplashScreen.Dispose(); currSplashScreen = null; } } else if (DateTime.Now > videoStartTime + new TimeSpan(0, 0, 0, 0, milliseconds: 1500)) { currSplashScreen.Dispose(); currSplashScreen = null; } }
public void Update(float deltaTime) { if (!EditorMode) { return; } foreach (EditorImage image in Images) { image.Update(deltaTime); } if (PlayerInput.PrimaryMouseButtonDown()) { EditorImage?hover = Images.FirstOrDefault(img => img.IsMouseOn()); if (hover != null) { foreach (EditorImage image in Images) { image.Selected = false; } hover.Selected = true; } } if (PlayerInput.KeyHit(Keys.Delete) || (PlayerInput.IsCtrlDown() && PlayerInput.KeyHit(Keys.D))) { Images.RemoveAll(img => img.Selected); UpdateImageCategories(); } if (PlayerInput.KeyHit(Keys.Space)) { foreach (EditorImage image in Images) { if (image.Selected) { if (image.DrawTarget == EditorImage.DrawTargetType.World) { Vector2 pos = image.Position; pos.Y = -pos.Y; pos = Screen.Selected.Cam.WorldToScreen(pos); if (PlayerInput.IsShiftDown()) { pos = new Vector2(GameMain.GraphicsWidth / 2f, GameMain.GraphicsHeight / 2f); } image.Position = pos; image.DrawTarget = EditorImage.DrawTargetType.Camera; image.Scale *= Screen.Selected.Cam.Zoom; image.UpdateRectangle(); } else { Vector2 pos = Screen.Selected.Cam.ScreenToWorld(image.Position); pos.Y = -pos.Y; image.Position = pos; image.DrawTarget = EditorImage.DrawTargetType.World; image.Scale /= Screen.Selected.Cam.Zoom; image.UpdateRectangle(); } } } UpdateImageCategories(); } MapEntity.DisableSelect = true; }
public void DebugDrawHUD(SpriteBatch spriteBatch, int y) { foreach (ScriptedEvent scriptedEvent in activeEvents.Where(ev => !ev.IsFinished && ev is ScriptedEvent).Cast <ScriptedEvent>()) { DrawEventTargetTags(spriteBatch, scriptedEvent); } GUI.DrawString(spriteBatch, new Vector2(10, y), "EventManager", Color.White, Color.Black * 0.6f, 0, GUI.SmallFont); GUI.DrawString(spriteBatch, new Vector2(15, y + 20), "Event cooldown: " + (int)Math.Max(eventCoolDown, 0), Color.White, Color.Black * 0.6f, 0, GUI.SmallFont); GUI.DrawString(spriteBatch, new Vector2(15, y + 35), "Current intensity: " + (int)Math.Round(currentIntensity * 100), Color.Lerp(Color.White, GUI.Style.Red, currentIntensity), Color.Black * 0.6f, 0, GUI.SmallFont); GUI.DrawString(spriteBatch, new Vector2(15, y + 50), "Target intensity: " + (int)Math.Round(targetIntensity * 100), Color.Lerp(Color.White, GUI.Style.Red, targetIntensity), Color.Black * 0.6f, 0, GUI.SmallFont); GUI.DrawString(spriteBatch, new Vector2(15, y + 65), "AvgHealth: " + (int)Math.Round(avgCrewHealth * 100), Color.Lerp(GUI.Style.Red, GUI.Style.Green, avgCrewHealth), Color.Black * 0.6f, 0, GUI.SmallFont); GUI.DrawString(spriteBatch, new Vector2(15, y + 80), "AvgHullIntegrity: " + (int)Math.Round(avgHullIntegrity * 100), Color.Lerp(GUI.Style.Red, GUI.Style.Green, avgHullIntegrity), Color.Black * 0.6f, 0, GUI.SmallFont); GUI.DrawString(spriteBatch, new Vector2(15, y + 95), "FloodingAmount: " + (int)Math.Round(floodingAmount * 100), Color.Lerp(GUI.Style.Green, GUI.Style.Red, floodingAmount), Color.Black * 0.6f, 0, GUI.SmallFont); GUI.DrawString(spriteBatch, new Vector2(15, y + 110), "FireAmount: " + (int)Math.Round(fireAmount * 100), Color.Lerp(GUI.Style.Green, GUI.Style.Red, fireAmount), Color.Black * 0.6f, 0, GUI.SmallFont); GUI.DrawString(spriteBatch, new Vector2(15, y + 125), "EnemyDanger: " + (int)Math.Round(enemyDanger * 100), Color.Lerp(GUI.Style.Green, GUI.Style.Red, enemyDanger), Color.Black * 0.6f, 0, GUI.SmallFont); #if DEBUG if (PlayerInput.KeyDown(Microsoft.Xna.Framework.Input.Keys.LeftAlt) && PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.T)) { eventCoolDown = 1.0f; } #endif if (intensityGraph == null) { intensityGraph = new Graph(); targetIntensityGraph = new Graph(); } intensityGraphUpdateInterval = 5.0f; if (Timing.TotalTime > lastIntensityUpdate + intensityGraphUpdateInterval) { intensityGraph.Update(currentIntensity); targetIntensityGraph.Update(targetIntensity); lastIntensityUpdate = (float)Timing.TotalTime; } Rectangle graphRect = new Rectangle(15, y + 150, 150, 50); GUI.DrawRectangle(spriteBatch, graphRect, Color.Black * 0.5f, true); intensityGraph.Draw(spriteBatch, graphRect, 1.0f, 0.0f, Color.Lerp(Color.White, GUI.Style.Red, currentIntensity)); targetIntensityGraph.Draw(spriteBatch, graphRect, 1.0f, 0.0f, Color.Lerp(Color.White, GUI.Style.Red, targetIntensity) * 0.5f); GUI.DrawLine(spriteBatch, new Vector2(graphRect.Right, graphRect.Y + graphRect.Height * (1.0f - eventThreshold)), new Vector2(graphRect.Right + 5, graphRect.Y + graphRect.Height * (1.0f - eventThreshold)), Color.Orange, 0, 1); y = graphRect.Bottom + 20; int x = graphRect.X; if (isCrewAway && crewAwayDuration < settings.FreezeDurationWhenCrewAway) { GUI.DrawString(spriteBatch, new Vector2(x, y), "Events frozen (crew away from sub): " + ToolBox.SecondsToReadableTime(settings.FreezeDurationWhenCrewAway - crewAwayDuration), Color.LightGreen * 0.8f, null, 0, GUI.SmallFont); y += 15; } else if (crewAwayResetTimer > 0.0f) { GUI.DrawString(spriteBatch, new Vector2(x, y), "Events frozen (crew just returned to the sub): " + ToolBox.SecondsToReadableTime(crewAwayResetTimer), Color.LightGreen * 0.8f, null, 0, GUI.SmallFont); y += 15; } else if (eventCoolDown > 0.0f) { GUI.DrawString(spriteBatch, new Vector2(x, y), "Event cooldown active: " + ToolBox.SecondsToReadableTime(eventCoolDown), Color.LightGreen * 0.8f, null, 0, GUI.SmallFont); y += 15; } else if (currentIntensity > eventThreshold) { GUI.DrawString(spriteBatch, new Vector2(x, y), "Intensity too high for new events: " + (int)(currentIntensity * 100) + "%/" + (int)(eventThreshold * 100) + "%", Color.LightGreen * 0.8f, null, 0, GUI.SmallFont); y += 15; } foreach (EventSet eventSet in pendingEventSets) { if (Submarine.MainSub == null) { break; } GUI.DrawString(spriteBatch, new Vector2(x, y), "New event (ID " + eventSet.DebugIdentifier + ") after: ", Color.Orange * 0.8f, null, 0, GUI.SmallFont); y += 12; if (eventSet.PerCave) { GUI.DrawString(spriteBatch, new Vector2(x, y), " submarine near cave", Color.Orange * 0.8f, null, 0, GUI.SmallFont); y += 12; } if (eventSet.PerWreck) { GUI.DrawString(spriteBatch, new Vector2(x, y), " submarine near the wreck", Color.Orange * 0.8f, null, 0, GUI.SmallFont); y += 12; } if (eventSet.PerRuin) { GUI.DrawString(spriteBatch, new Vector2(x, y), " submarine near the ruins", Color.Orange * 0.8f, null, 0, GUI.SmallFont); y += 12; } if (roundDuration < eventSet.MinMissionTime) { GUI.DrawString(spriteBatch, new Vector2(x, y), " " + (int)(eventSet.MinDistanceTraveled * 100.0f) + "% travelled (current: " + (int)(distanceTraveled * 100.0f) + " %)", ((Submarine.MainSub == null || distanceTraveled < eventSet.MinDistanceTraveled) ? Color.Lerp(GUI.Style.Yellow, GUI.Style.Red, eventSet.MinDistanceTraveled - distanceTraveled) : GUI.Style.Green) * 0.8f, null, 0, GUI.SmallFont); y += 12; } if (CurrentIntensity < eventSet.MinIntensity || CurrentIntensity > eventSet.MaxIntensity) { GUI.DrawString(spriteBatch, new Vector2(x, y), " intensity between " + ((int)eventSet.MinIntensity) + " and " + ((int)eventSet.MaxIntensity), Color.Orange * 0.8f, null, 0, GUI.SmallFont); y += 12; } if (roundDuration < eventSet.MinMissionTime) { GUI.DrawString(spriteBatch, new Vector2(x, y), " " + (int)(eventSet.MinMissionTime - roundDuration) + " s", Color.Lerp(GUI.Style.Yellow, GUI.Style.Red, (eventSet.MinMissionTime - roundDuration)), null, 0, GUI.SmallFont); } y += 15; if (y > GameMain.GraphicsHeight * 0.9f) { y = graphRect.Bottom + 35; x += 250; } } GUI.DrawString(spriteBatch, new Vector2(x, y), "Current events: ", Color.White * 0.9f, null, 0, GUI.SmallFont); y += 15; foreach (Event ev in activeEvents.Where(ev => !ev.IsFinished || PlayerInput.IsShiftDown())) { GUI.DrawString(spriteBatch, new Vector2(x + 5, y), ev.ToString(), (!ev.IsFinished ? Color.White : Color.Red) * 0.8f, null, 0, GUI.SmallFont); Rectangle rect = new Rectangle(new Point(x + 5, y), GUI.SmallFont.MeasureString(ev.ToString()).ToPoint()); Rectangle outlineRect = new Rectangle(rect.Location, rect.Size); outlineRect.Inflate(4, 4); if (PinnedEvent == ev) { GUI.DrawRectangle(spriteBatch, outlineRect, Color.White); } if (rect.Contains(PlayerInput.MousePosition)) { GUI.MouseCursor = CursorState.Hand; GUI.DrawRectangle(spriteBatch, outlineRect, Color.White); if (ev != PinnedEvent) { DrawEvent(spriteBatch, ev, rect); } else if (PlayerInput.SecondaryMouseButtonHeld() || PlayerInput.SecondaryMouseButtonDown()) { PinnedEvent = null; } if (PlayerInput.PrimaryMouseButtonHeld() || PlayerInput.PrimaryMouseButtonDown()) { PinnedEvent = ev; } } y += 18; if (y > GameMain.GraphicsHeight * 0.9f) { y = graphRect.Bottom + 35; x += 250; } } }
protected override void Update(float deltaTime) { if (Draggable) { GUIComponent parent = GUI.MouseOn?.Parent?.Parent; if ((GUI.MouseOn == InnerFrame || InnerFrame.IsParentOf(GUI.MouseOn)) && !(GUI.MouseOn is GUIButton || GUI.MouseOn is GUIColorPicker || GUI.MouseOn is GUITextBox || parent is GUITextBox)) { GUI.MouseCursor = CursorState.Move; if (PlayerInput.PrimaryMouseButtonDown()) { DraggingPosition = RectTransform.ScreenSpaceOffset.ToVector2() - PlayerInput.MousePosition; } } if (PlayerInput.PrimaryMouseButtonHeld() && DraggingPosition != Vector2.Zero) { GUI.MouseCursor = CursorState.Dragging; RectTransform.ScreenSpaceOffset = (PlayerInput.MousePosition + DraggingPosition).ToPoint(); } else { DraggingPosition = Vector2.Zero; } } if (type == Type.InGame) { Vector2 initialPos = new Vector2(0.0f, GameMain.GraphicsHeight); Vector2 defaultPos = new Vector2(0.0f, HUDLayoutSettings.InventoryAreaLower.Y - InnerFrame.Rect.Height - 20 * GUI.Scale); Vector2 endPos = new Vector2(GameMain.GraphicsWidth, defaultPos.Y); if (!closing) { Point step = Vector2.SmoothStep(initialPos, defaultPos, openState).ToPoint(); InnerFrame.RectTransform.AbsoluteOffset = step; if (BackgroundIcon != null) { BackgroundIcon.RectTransform.AbsoluteOffset = new Point(InnerFrame.Rect.Location.X - (int)(BackgroundIcon.Rect.Size.X / 1.25f), (int)defaultPos.Y - BackgroundIcon.Rect.Size.Y / 2); if (!MathUtils.NearlyEqual(openState, 1.0f)) { BackgroundIcon.Color = ToolBox.GradientLerp(openState, Color.Transparent, Color.White); } } if (!(Screen.Selected is RoundSummaryScreen) && !MessageBoxes.Any(mb => mb.UserData is RoundSummary)) { openState = Math.Min(openState + deltaTime * 2.0f, 1.0f); } if (GUI.MouseOn != InnerFrame && !InnerFrame.IsParentOf(GUI.MouseOn) && AutoClose) { inGameCloseTimer += deltaTime; } if (inGameCloseTimer >= inGameCloseTime) { Close(); } } else { openState += deltaTime * 2.0f; Point step = Vector2.SmoothStep(defaultPos, endPos, openState - 1.0f).ToPoint(); InnerFrame.RectTransform.AbsoluteOffset = step; if (BackgroundIcon != null) { BackgroundIcon.Color *= 0.9f; } if (openState >= 2.0f) { if (Parent != null) { Parent.RemoveChild(this); } if (MessageBoxes.Contains(this)) { MessageBoxes.Remove(this); } } } if (newBackgroundIcon != null) { if (!iconSwitching) { if (BackgroundIcon != null) { BackgroundIcon.Color *= 0.9f; if (BackgroundIcon.Color.A == 0) { BackgroundIcon = null; iconSwitching = true; RemoveChild(BackgroundIcon); } } else { iconSwitching = true; } iconState = 0; } else { newBackgroundIcon.SetAsFirstChild(); newBackgroundIcon.RectTransform.AbsoluteOffset = new Point(InnerFrame.Rect.Location.X - (int)(newBackgroundIcon.Rect.Size.X / 1.25f), (int)defaultPos.Y - newBackgroundIcon.Rect.Size.Y / 2); newBackgroundIcon.Color = ToolBox.GradientLerp(iconState, Color.Transparent, Color.White); if (newBackgroundIcon.Color.A == 255) { BackgroundIcon = newBackgroundIcon; BackgroundIcon.SetAsFirstChild(); newBackgroundIcon = null; iconSwitching = false; } iconState = Math.Min(iconState + deltaTime * 2.0f, 1.0f); } } } }
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 void UpdateResizing(Camera cam) { isHighlighted = true; int startX = ResizeHorizontal ? -1 : 0; int StartY = ResizeVertical ? -1 : 0; for (int x = startX; x < 2; x += 2) { for (int y = StartY; y < 2; y += 2) { Vector2 handlePos = cam.WorldToScreen(Position + new Vector2(x * (rect.Width * 0.5f + 5), y * (rect.Height * 0.5f + 5))); bool highlighted = Vector2.Distance(PlayerInput.MousePosition, handlePos) < 5.0f; if (highlighted && PlayerInput.PrimaryMouseButtonDown()) { selectionPos = Vector2.Zero; resizeDirX = x; resizeDirY = y; resizing = true; startMovingPos = Vector2.Zero; } } } if (resizing) { if (rectMemento == null) { rectMemento = new Memento <Rectangle>(); rectMemento.Store(Rect); } Vector2 placePosition = new Vector2(rect.X, rect.Y); Vector2 placeSize = new Vector2(rect.Width, rect.Height); Vector2 mousePos = Submarine.MouseToWorldGrid(cam, Submarine.MainSub); if (PlayerInput.IsShiftDown()) { mousePos = cam.ScreenToWorld(PlayerInput.MousePosition); } if (resizeDirX > 0) { mousePos.X = Math.Max(mousePos.X, rect.X + Submarine.GridSize.X); placeSize.X = mousePos.X - placePosition.X; } else if (resizeDirX < 0) { mousePos.X = Math.Min(mousePos.X, rect.Right - Submarine.GridSize.X); placeSize.X = (placePosition.X + placeSize.X) - mousePos.X; placePosition.X = mousePos.X; } if (resizeDirY < 0) { mousePos.Y = Math.Min(mousePos.Y, rect.Y - Submarine.GridSize.Y); placeSize.Y = placePosition.Y - mousePos.Y; } else if (resizeDirY > 0) { mousePos.Y = Math.Max(mousePos.Y, rect.Y - rect.Height + Submarine.GridSize.X); placeSize.Y = mousePos.Y - (rect.Y - rect.Height); placePosition.Y = mousePos.Y; } if ((int)placePosition.X != rect.X || (int)placePosition.Y != rect.Y || (int)placeSize.X != rect.Width || (int)placeSize.Y != rect.Height) { Rect = new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y); } if (!PlayerInput.PrimaryMouseButtonHeld()) { rectMemento.Store(Rect); resizing = false; Resized?.Invoke(rect); } } }
protected override void Update(float deltaTime) { if (!Visible) { return; } if (flashTimer > 0.0f) { flashTimer -= deltaTime; } if (!Enabled) { return; } if (skipUpdate) { skipUpdate = false; return; } if (MouseRect.Contains(PlayerInput.MousePosition) && (GUI.MouseOn == null || (!(GUI.MouseOn is GUIButton) && GUI.IsMouseOn(this)))) { State = ComponentState.Hover; if (PlayerInput.PrimaryMouseButtonDown()) { mouseHeldInside = true; Select(); } else { isSelecting = PlayerInput.PrimaryMouseButtonHeld(); } if (PlayerInput.DoubleClicked()) { SelectAll(); } if (isSelecting) { if (!MathUtils.NearlyEqual(PlayerInput.MouseSpeed.X, 0)) { CaretIndex = textBlock.GetCaretIndexFromScreenPos(PlayerInput.MousePosition); CalculateCaretPos(); CalculateSelection(); } } } else { if ((PlayerInput.LeftButtonClicked() || PlayerInput.RightButtonClicked()) && selected) { if (!mouseHeldInside) { Deselect(); } mouseHeldInside = false; } isSelecting = false; State = ComponentState.None; } if (!isSelecting) { isSelecting = PlayerInput.KeyDown(Keys.LeftShift) || PlayerInput.KeyDown(Keys.RightShift); } if (CaretEnabled) { if (textBlock.OverflowClipActive) { if (CaretScreenPos.X < textBlock.Rect.X + textBlock.Padding.X) { textBlock.TextPos = new Vector2(textBlock.TextPos.X + ((textBlock.Rect.X + textBlock.Padding.X) - CaretScreenPos.X), textBlock.TextPos.Y); CalculateCaretPos(); } else if (CaretScreenPos.X > textBlock.Rect.Right - textBlock.Padding.Z) { textBlock.TextPos = new Vector2(textBlock.TextPos.X - (CaretScreenPos.X - (textBlock.Rect.Right - textBlock.Padding.Z)), textBlock.TextPos.Y); CalculateCaretPos(); } } caretTimer += deltaTime; caretVisible = ((caretTimer * 1000.0f) % 1000) < 500; if (caretVisible && caretPosDirty) { CalculateCaretPos(); } } if (GUI.KeyboardDispatcher.Subscriber == this) { State = ComponentState.Selected; Character.DisableControls = true; if (OnEnterPressed != null && PlayerInput.KeyHit(Keys.Enter)) { OnEnterPressed(this, Text); } } else if (Selected) { Deselect(); } textBlock.State = State; }
protected override void Update(float deltaTime) { if (!Visible) { return; } base.Update(deltaTime); if (Rect.Contains(PlayerInput.MousePosition) && CanBeSelected && CanBeFocused && Enabled && GUI.IsMouseOn(this)) { State = Selected ? ComponentState.HoverSelected : ComponentState.Hover; if (PlayerInput.PrimaryMouseButtonDown()) { OnButtonDown?.Invoke(); } if (PlayerInput.PrimaryMouseButtonHeld()) { if (OnPressed != null) { if (OnPressed()) { State = ComponentState.Pressed; } } else { State = ComponentState.Pressed; } } else if (PlayerInput.PrimaryMouseButtonClicked()) { GUI.PlayUISound(GUISoundType.Click); if (OnClicked != null) { if (OnClicked(this, UserData)) { State = ComponentState.Selected; } } else { Selected = !Selected; } } } else { if (!ExternalHighlight) { State = Selected ? ComponentState.Selected : ComponentState.None; } else { State = ComponentState.Hover; } } foreach (GUIComponent child in Children) { child.State = State; } if (Pulse) { pulseTimer += deltaTime; if (pulseTimer > 1.0f) { if (!flashed) { flashed = true; Frame.Flash(Color.White * 0.2f, 0.8f, true); } pulseExpand += deltaTime; if (pulseExpand > 1.0f) { pulseTimer = 0.0f; pulseExpand = 0.0f; flashed = false; } } } }