Skip to content

Commit

Permalink
Updated existing code to use the Tools namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
justalemon committed Dec 16, 2023
1 parent c560e24 commit ef38f74
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 37 deletions.
2 changes: 1 addition & 1 deletion LemonUI/Elements/BaseElement.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using LemonUI.Extensions;
using System.Drawing;
using LemonUI.Tools;

namespace LemonUI.Elements
{
Expand Down
2 changes: 1 addition & 1 deletion LemonUI/Elements/ScaledText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using LemonUI.Extensions;
using LemonUI.Tools;

namespace LemonUI.Elements
{
Expand Down
15 changes: 7 additions & 8 deletions LemonUI/Menus/NativeGridPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion LemonUI/Menus/NativeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using LemonUI.Elements;
using System;
using System.Drawing;
using LemonUI.Tools;

namespace LemonUI.Menus
{
Expand Down Expand Up @@ -230,7 +231,7 @@ public ColorSet Colors
/// <summary>
/// If this item is being hovered.
/// </summary>
public bool IsHovered => Screen.IsCursorInArea(background.Position, background.Size);
public bool IsHovered => GameScreen.IsCursorInArea(background.Position, background.Size);

#endregion

Expand Down
38 changes: 15 additions & 23 deletions LemonUI/Menus/NativeMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
{
Expand Down Expand Up @@ -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<int>(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;
Expand All @@ -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;
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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
{
Expand Down
5 changes: 2 additions & 3 deletions LemonUI/TimerBars/TimerBarCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Collections.Generic;
using System.Drawing;
using LemonUI.Elements;
using LemonUI.Tools;

namespace LemonUI.TimerBars
{
Expand Down Expand Up @@ -139,9 +140,7 @@ public void Remove(Func<TimerBar, bool> func)
/// </summary>
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;
Expand Down

0 comments on commit ef38f74

Please sign in to comment.