mirror of
https://github.com/thegeneralist01/Scene-Manager-DevRepo
synced 2026-01-11 15:40:29 +01:00
Initial commit
This commit is contained in:
parent
296206f5b9
commit
fd12e1bea2
9 changed files with 1031 additions and 0 deletions
229
SceneManager/Utils/UserInput.cs
Normal file
229
SceneManager/Utils/UserInput.cs
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
using InputManager;
|
||||
using Rage;
|
||||
using Rage.Native;
|
||||
using RAGENativeUI;
|
||||
using RAGENativeUI.Elements;
|
||||
using SceneManager.Menus;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SceneManager.Utils
|
||||
{
|
||||
// The only reason this class should change is to modify how user input is handled
|
||||
class UserInput
|
||||
{
|
||||
internal static void HandleKeyPress()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
bool isTextEntryOpen = (Rage.Native.NativeFunction.Natives.UPDATE_ONSCREEN_KEYBOARD<int>() == 0);
|
||||
if (!isTextEntryOpen && MenuKeysPressed())
|
||||
{
|
||||
Menus.MainMenu.DisplayMenu();
|
||||
GameFiber.StartNew(() => MenuManager.Update(), "Menu Processing Fiber");
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
if (MenuManager.MenuPool.IsAnyMenuOpen())
|
||||
{
|
||||
Game.DisplaySubtitle($"You are using a test build of Scene Manager. Please report any bugs/crashes in the Discord server.");
|
||||
}
|
||||
#endif
|
||||
GameFiber.Yield();
|
||||
}
|
||||
}
|
||||
|
||||
private static bool MenuKeysPressed()
|
||||
{
|
||||
if (MenuKeysPressed())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
bool MenuKeysPressed()
|
||||
{
|
||||
if (MenuManager.AreMenusClosed() &&
|
||||
((Settings.ModifierKey == Keys.None && Game.IsKeyDown(Settings.ToggleKey)) ||
|
||||
(Game.IsKeyDownRightNow(Settings.ModifierKey) && Game.IsKeyDown(Settings.ToggleKey)) ||
|
||||
(Settings.ModifierButton == ControllerButtons.None && Game.IsControllerButtonDown(Settings.ToggleButton)) ||
|
||||
(Game.IsControllerButtonDownRightNow(Settings.ModifierButton) && Game.IsControllerButtonDown(Settings.ToggleButton))))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Vector3 GetMousePosition { get { return GetMousePositionInWorld(); } }
|
||||
|
||||
internal static Vector3 GetMousePositionForBarrier { get { return GetMousePositionInWorld(Settings.BarrierPlacementDistance); } }
|
||||
|
||||
private static Vector3 GetMousePositionInWorld(float maxDistance = 100f)
|
||||
{
|
||||
HitResult TracePlayerView(float maxTraceDistance = 100f, TraceFlags flags = TraceFlags.IntersectWorld) => TracePlayerView2(out Vector3 v1, out Vector3 v2, maxTraceDistance, flags);
|
||||
|
||||
HitResult TracePlayerView2(out Vector3 start, out Vector3 end, float maxTraceDistance, TraceFlags flags)
|
||||
{
|
||||
Vector3 direction = GetPlayerLookingDirection(out start);
|
||||
end = start + (maxTraceDistance * direction);
|
||||
return World.TraceLine(start, end, flags);
|
||||
}
|
||||
|
||||
Vector3 GetPlayerLookingDirection(out Vector3 camPosition)
|
||||
{
|
||||
if (Camera.RenderingCamera)
|
||||
{
|
||||
camPosition = Camera.RenderingCamera.Position;
|
||||
return Camera.RenderingCamera.Direction;
|
||||
}
|
||||
else
|
||||
{
|
||||
float pitch = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_RELATIVE_PITCH<float>();
|
||||
float heading = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_RELATIVE_HEADING<float>();
|
||||
|
||||
camPosition = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_COORD<Vector3>();
|
||||
return (Game.LocalPlayer.Character.Rotation + new Rotator(pitch, 0, heading)).ToVector().ToNormalized();
|
||||
}
|
||||
}
|
||||
|
||||
return TracePlayerView(maxDistance, TraceFlags.IntersectWorld).HitPosition;
|
||||
}
|
||||
|
||||
internal static void InitializeMenuMouseControl(UIMenu menu, List<UIMenuScrollerItem> scrollerItems)
|
||||
{
|
||||
while (menu.Visible)
|
||||
{
|
||||
var selectedScroller = menu.MenuItems.Where(x => scrollerItems.Contains(x) && x.Selected && x.Enabled).FirstOrDefault();
|
||||
if (selectedScroller != null)
|
||||
{
|
||||
OnWheelScroll(menu, selectedScroller, scrollerItems);
|
||||
}
|
||||
|
||||
if (Game.IsKeyDown(Keys.LButton) && Rage.Native.NativeFunction.Natives.UPDATE_ONSCREEN_KEYBOARD<int>() != 0)
|
||||
{
|
||||
Keyboard.KeyDown(Keys.Enter);
|
||||
GameFiber.Wait(1);
|
||||
Keyboard.KeyUp(Keys.Enter);
|
||||
}
|
||||
|
||||
if (menu.SubtitleText.Contains("Path Creation Menu"))
|
||||
{
|
||||
DrawWaypointMarker();
|
||||
}
|
||||
GameFiber.Yield();
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnWheelScroll(UIMenu menu, UIMenuItem selectedScroller, List<UIMenuScrollerItem> scrollerItems)
|
||||
{
|
||||
var menuScrollingDisabled = false;
|
||||
var menuItems = menu.MenuItems.Where(x => x != selectedScroller);
|
||||
|
||||
while (Game.IsShiftKeyDownRightNow)
|
||||
{
|
||||
menu.ResetKey(Common.MenuControls.Up);
|
||||
menu.ResetKey(Common.MenuControls.Down);
|
||||
menuScrollingDisabled = true;
|
||||
ScrollMenuItem();
|
||||
if (menu.SubtitleText.Contains("Path Creation Menu") || menu.SubtitleText.Contains("Edit Waypoint"))
|
||||
{
|
||||
CompareScrollerValues();
|
||||
}
|
||||
if (menu.SubtitleText.Contains("Path Creation Menu"))
|
||||
{
|
||||
DrawWaypointMarker();
|
||||
}
|
||||
GameFiber.Yield();
|
||||
}
|
||||
|
||||
if (menuScrollingDisabled)
|
||||
{
|
||||
menuScrollingDisabled = false;
|
||||
menu.SetKey(Common.MenuControls.Up, GameControl.CursorScrollUp);
|
||||
menu.SetKey(Common.MenuControls.Up, GameControl.CellphoneUp);
|
||||
menu.SetKey(Common.MenuControls.Down, GameControl.CursorScrollDown);
|
||||
menu.SetKey(Common.MenuControls.Down, GameControl.CellphoneDown);
|
||||
}
|
||||
|
||||
void ScrollMenuItem()
|
||||
{
|
||||
if (Game.GetMouseWheelDelta() > 0)
|
||||
{
|
||||
Keyboard.KeyDown(Keys.Right);
|
||||
GameFiber.Wait(1);
|
||||
Keyboard.KeyUp(Keys.Right);
|
||||
}
|
||||
else if (Game.GetMouseWheelDelta() < 0)
|
||||
{
|
||||
Keyboard.KeyDown(Keys.Left);
|
||||
GameFiber.Wait(1);
|
||||
Keyboard.KeyUp(Keys.Left);
|
||||
}
|
||||
}
|
||||
|
||||
void CompareScrollerValues()
|
||||
{
|
||||
var collectorRadius = (UIMenuNumericScrollerItem<int>)scrollerItems.Where(x => x.Text == "Collection Radius").FirstOrDefault();
|
||||
var speedZoneRadius = (UIMenuNumericScrollerItem<int>)scrollerItems.Where(x => x.Text == "Speed Zone Radius").FirstOrDefault();
|
||||
|
||||
if (selectedScroller.Text == "Collection Radius" || selectedScroller.Text == "Speed Zone Radius")
|
||||
{
|
||||
if (selectedScroller == collectorRadius && collectorRadius.Value > speedZoneRadius.Value)
|
||||
{
|
||||
while (collectorRadius.Value > speedZoneRadius.Value)
|
||||
{
|
||||
speedZoneRadius.ScrollToNextOption();
|
||||
}
|
||||
}
|
||||
if (selectedScroller == speedZoneRadius && speedZoneRadius.Value < collectorRadius.Value)
|
||||
{
|
||||
collectorRadius.Value = speedZoneRadius.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawWaypointMarker()
|
||||
{
|
||||
var waypointPosition = GetMousePosition;
|
||||
if (SettingsMenu.ThreeDWaypoints.Checked && PathCreationMenu.CollectorWaypoint.Checked)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, waypointPosition, 0, 0, 0, 0, 0, 0, (float)PathCreationMenu.CollectorRadius.Value * 2, (float)PathCreationMenu.CollectorRadius.Value * 2, 1f, 80, 130, 255, 80, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, waypointPosition, 0, 0, 0, 0, 0, 0, (float)PathCreationMenu.SpeedZoneRadius.Value * 2, (float)PathCreationMenu.SpeedZoneRadius.Value * 2, 1f, 255, 185, 80, 80, false, false, 2, false, 0, 0, false);
|
||||
}
|
||||
else if (PathCreationMenu.StopWaypoint.Checked)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, waypointPosition, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 255, 65, 65, 80, false, false, 2, false, 0, 0, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, waypointPosition, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 65, 255, 65, 80, false, false, 2, false, 0, 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetFileName(string windowTitle, string defaultText, int maxLength)
|
||||
{
|
||||
NativeFunction.Natives.DISABLE_ALL_CONTROL_ACTIONS(2);
|
||||
|
||||
NativeFunction.Natives.DISPLAY_ONSCREEN_KEYBOARD(true, windowTitle, 0, defaultText, 0, 0, 0, maxLength);
|
||||
Game.DisplayHelp("Enter the filename you would like to save your path as\n~INPUT_FRONTEND_ACCEPT~ Export path\n~INPUT_FRONTEND_CANCEL~ Cancel", true);
|
||||
Game.DisplaySubtitle(windowTitle, 100000);
|
||||
|
||||
while (NativeFunction.Natives.UPDATE_ONSCREEN_KEYBOARD<int>() == 0)
|
||||
{
|
||||
GameFiber.Yield();
|
||||
}
|
||||
|
||||
NativeFunction.Natives.ENABLE_ALL_CONTROL_ACTIONS(2);
|
||||
Game.DisplaySubtitle("", 5);
|
||||
Game.HideHelp();
|
||||
|
||||
return NativeFunction.Natives.GET_ONSCREEN_KEYBOARD_RESULT<string>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue