From ef38f7491e32283850ef26a9f3ff4558a328466c Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 01:43:44 -0300 Subject: [PATCH] Updated existing code to use the Tools namespace --- LemonUI/Elements/BaseElement.cs | 2 +- LemonUI/Elements/ScaledText.cs | 2 +- LemonUI/Menus/NativeGridPanel.cs | 15 +++++----- LemonUI/Menus/NativeItem.cs | 3 +- LemonUI/Menus/NativeMenu.cs | 38 ++++++++++--------------- LemonUI/TimerBars/TimerBarCollection.cs | 5 ++-- 6 files changed, 28 insertions(+), 37 deletions(-) diff --git a/LemonUI/Elements/BaseElement.cs b/LemonUI/Elements/BaseElement.cs index 55222526..208911b8 100644 --- a/LemonUI/Elements/BaseElement.cs +++ b/LemonUI/Elements/BaseElement.cs @@ -1,5 +1,5 @@ -using LemonUI.Extensions; using System.Drawing; +using LemonUI.Tools; namespace LemonUI.Elements { diff --git a/LemonUI/Elements/ScaledText.cs b/LemonUI/Elements/ScaledText.cs index 481c0e99..9c105a40 100644 --- a/LemonUI/Elements/ScaledText.cs +++ b/LemonUI/Elements/ScaledText.cs @@ -16,7 +16,7 @@ using System.Collections.Generic; using System.Drawing; using System.Text; -using LemonUI.Extensions; +using LemonUI.Tools; namespace LemonUI.Elements { diff --git a/LemonUI/Menus/NativeGridPanel.cs b/LemonUI/Menus/NativeGridPanel.cs index 4605b353..afc3a787 100644 --- a/LemonUI/Menus/NativeGridPanel.cs +++ b/LemonUI/Menus/NativeGridPanel.cs @@ -12,13 +12,12 @@ using Control = Rage.GameControl; #elif SHVDN3 || SHVDNC using GTA; -using GTA.Native; using GTA.UI; #endif using LemonUI.Elements; -using LemonUI.Extensions; using System; using System.Drawing; +using LemonUI.Tools; namespace LemonUI.Menus { @@ -290,16 +289,16 @@ public override void Process() if (!Controls.IsUsingController) { - if (Screen.IsCursorInArea(grid.Position, grid.Size) && Controls.IsPressed(Control.CursorAccept)) + if (GameScreen.IsCursorInArea(grid.Position, grid.Size) && Controls.IsPressed(Control.CursorAccept)) { - PointF cursor = Screen.CursorPositionRelative; - PointF pos = innerPosition.ToRelative(); + PointF cursor = GameScreen.Cursor; + PointF pos = innerPosition; PointF start = new PointF(cursor.X - pos.X, cursor.Y - pos.Y); - SizeF size = innerSize.ToRelative(); + SizeF size = innerSize; - x = start.X / size.Width; - y = start.Y / size.Height; + x = (start.X / size.Width).ToXRelative(); + y = (start.Y / size.Height).ToYRelative(); } else { diff --git a/LemonUI/Menus/NativeItem.cs b/LemonUI/Menus/NativeItem.cs index 61b7999a..a36969b7 100644 --- a/LemonUI/Menus/NativeItem.cs +++ b/LemonUI/Menus/NativeItem.cs @@ -11,6 +11,7 @@ using LemonUI.Elements; using System; using System.Drawing; +using LemonUI.Tools; namespace LemonUI.Menus { @@ -230,7 +231,7 @@ public ColorSet Colors /// /// If this item is being hovered. /// - public bool IsHovered => Screen.IsCursorInArea(background.Position, background.Size); + public bool IsHovered => GameScreen.IsCursorInArea(background.Position, background.Size); #endregion diff --git a/LemonUI/Menus/NativeMenu.cs b/LemonUI/Menus/NativeMenu.cs index f6837732..8a8edbb8 100644 --- a/LemonUI/Menus/NativeMenu.cs +++ b/LemonUI/Menus/NativeMenu.cs @@ -26,13 +26,13 @@ using Font = GTA.UI.Font; #endif using LemonUI.Elements; -using LemonUI.Extensions; using LemonUI.Scaleform; using System; using System.Collections; using System.Collections.Generic; using System.Drawing; using System.Linq; +using LemonUI.Tools; namespace LemonUI.Menus { @@ -950,11 +950,10 @@ public void ResetCursor() const float extraX = 35; const float extraY = 325; - // Get the correct desired position of the cursor as relative PointF pos = PointF.Empty; if (SafeZoneAware) { - Screen.SetElementAlignment(Alignment, GFXAlignment.Top); + SafeZone.SetAlignment(Alignment, GFXAlignment.Top); float x = 0; switch (Alignment) { @@ -965,8 +964,8 @@ public void ResetCursor() x = Offset.X - Width - extraX; break; } - pos = Screen.GetRealPosition(x, Offset.Y + extraY).ToRelative(); - Screen.ResetElementAlignment(); + pos = SafeZone.GetSafePosition(x, Offset.Y + extraY).ToRelative(); + SafeZone.ResetAlignment(); } else { @@ -1004,7 +1003,7 @@ private void UpdateItems() PointF pos; if (SafeZoneAware) { - Screen.SetElementAlignment(Alignment, GFXAlignment.Top); + SafeZone.SetAlignment(Alignment, GFXAlignment.Top); float x = 0; switch (Alignment) { @@ -1015,8 +1014,8 @@ private void UpdateItems() x = Offset.X - Width; break; } - pos = Screen.GetRealPosition(x, Offset.Y); - Screen.ResetElementAlignment(); + pos = SafeZone.GetSafePosition(x, Offset.Y); + SafeZone.ResetAlignment(); } else { @@ -1208,18 +1207,12 @@ private void ProcessControls() if (UseMouse && !Controls.IsUsingController) { // Enable the mouse cursor -#if FIVEM || SHVDN3 || SHVDNC || ALTV - Screen.ShowCursorThisFrame(); -#elif RAGEMP - Invoker.Invoke(Natives.ShowCursorThisFrame); -#elif RPH - NativeFunction.CallByHash(0xAAE7CE1D63167423); -#endif + GameScreen.ShowCursorThisFrame(); // If the camera should be rotated when the cursor is on the left and right sections of the screen, do so if (RotateCamera) { - if (Screen.IsCursorInArea(PointF.Empty, searchAreaSize)) + if (GameScreen.IsCursorInArea(PointF.Empty, searchAreaSize)) { #if FIVEM || SHVDN3 || SHVDNC GameplayCamera.RelativeHeading += 5; @@ -1233,7 +1226,7 @@ private void ProcessControls() Camera.RenderingCamera.Heading += 5; #endif } - else if (Screen.IsCursorInArea(searchAreaRight, searchAreaSize)) + else if (GameScreen.IsCursorInArea(searchAreaRight, searchAreaSize)) { #if FIVEM || SHVDN3 || SHVDNC GameplayCamera.RelativeHeading -= 5; @@ -1259,7 +1252,7 @@ private void ProcessControls() if (item == selectedItem && item is NativeSlidableItem slidable) { // If the right arrow was pressed, go to the right - if (Screen.IsCursorInArea(slidable.RightArrow.Position, slidable.RightArrow.Size)) + if (GameScreen.IsCursorInArea(slidable.RightArrow.Position, slidable.RightArrow.Size)) { if (item.Enabled) { @@ -1273,7 +1266,7 @@ private void ProcessControls() return; } // If the user pressed the left arrow, go to the right - else if (Screen.IsCursorInArea(slidable.LeftArrow.Position, slidable.LeftArrow.Size)) + else if (GameScreen.IsCursorInArea(slidable.LeftArrow.Position, slidable.LeftArrow.Size)) { if (item.Enabled) { @@ -1289,7 +1282,7 @@ private void ProcessControls() } // If the cursor is inside of the selection rectangle - if (Screen.IsCursorInArea(item.title.Position.X - itemOffsetX, item.title.Position.Y - itemOffsetY, Width, itemHeight)) + if (GameScreen.IsCursorInArea(item.title.Position.X - itemOffsetX, item.title.Position.Y - itemOffsetY, Width, itemHeight)) { // If the item is selected, activate it if (item == selectedItem) @@ -1688,9 +1681,8 @@ public virtual void Recalculate() x = Offset.X - Width; break; } - Screen.SetElementAlignment(Alignment, GFXAlignment.Top); - pos = Screen.GetRealPosition(x, Offset.Y); - Screen.ResetElementAlignment(); + + pos = SafeZone.GetPositionAt(new PointF(x, Offset.Y), Alignment, GFXAlignment.Top); } else { diff --git a/LemonUI/TimerBars/TimerBarCollection.cs b/LemonUI/TimerBars/TimerBarCollection.cs index e5b88107..cb7de5df 100644 --- a/LemonUI/TimerBars/TimerBarCollection.cs +++ b/LemonUI/TimerBars/TimerBarCollection.cs @@ -14,6 +14,7 @@ using System.Collections.Generic; using System.Drawing; using LemonUI.Elements; +using LemonUI.Tools; namespace LemonUI.TimerBars { @@ -139,9 +140,7 @@ public void Remove(Func func) /// public void Recalculate() { - Screen.SetElementAlignment(GFXAlignment.Right, GFXAlignment.Bottom); - PointF pos = Screen.GetRealPosition(PointF.Empty); - Screen.ResetElementAlignment(); + PointF pos = SafeZone.BottomRight; pos.X += offset.X; pos.Y += offset.Y;