mirror of
https://github.com/thegeneralist01/Scene-Manager-DevRepo
synced 2026-01-11 07:30:40 +01:00
Refactored to implement RNUIMouseInputHandler class.
This commit is contained in:
parent
f0af9b6207
commit
467ca54c39
7 changed files with 431 additions and 1031 deletions
|
|
@ -1,7 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using Rage;
|
||||
using RAGENativeUI;
|
||||
using RAGENativeUI.Elements;
|
||||
|
|
@ -10,13 +9,18 @@ namespace SceneManager
|
|||
{
|
||||
class BarrierMenu
|
||||
{
|
||||
private static List<TrafficLight> trafficLightList = new List<TrafficLight>() { TrafficLight.Green, TrafficLight.Red, TrafficLight.Yellow, TrafficLight.None };
|
||||
internal static UIMenu barrierMenu = new UIMenu("Scene Manager", "~o~Barrier Management");
|
||||
internal static List<Barrier> barriers = new List<Barrier>();
|
||||
private static UIMenuListScrollerItem<string> barrierList = new UIMenuListScrollerItem<string>("Spawn Barrier", "", Settings.barrierKeys);
|
||||
private static UIMenuNumericScrollerItem<int> rotateBarrier = new UIMenuNumericScrollerItem<int>("Rotate Barrier", "", 0, 350, 10);
|
||||
private static UIMenuCheckboxItem invincible = new UIMenuCheckboxItem("Indestructible", false);
|
||||
private static UIMenuNumericScrollerItem<int> barrierTexture = new UIMenuNumericScrollerItem<int>("Change Texture", "", 0, 15, 1);
|
||||
private static UIMenuCheckboxItem setBarrierLights = new UIMenuCheckboxItem("Enable Barrier Lights", false);
|
||||
private static UIMenuListScrollerItem<TrafficLight> setBarrierTrafficLight = new UIMenuListScrollerItem<TrafficLight>("Set Barrier Traffic Light", "", trafficLightList);
|
||||
private static UIMenuListScrollerItem<string> removeBarrierOptions = new UIMenuListScrollerItem<string>("Remove Barrier", "", new[] { "Last Barrier", "Nearest Barrier", "All Barriers" });
|
||||
private static UIMenuItem resetBarriers = new UIMenuItem("Reset Barriers", "Reset all spawned barriers to their original position and rotation");
|
||||
internal static Rage.Object shadowBarrier;
|
||||
internal static Object shadowBarrier;
|
||||
|
||||
internal static void InstantiateMenu()
|
||||
{
|
||||
|
|
@ -24,80 +28,125 @@ namespace SceneManager
|
|||
MenuManager.menuPool.Add(barrierMenu);
|
||||
|
||||
barrierMenu.OnItemSelect += BarrierMenu_OnItemSelected;
|
||||
barrierMenu.OnScrollerChange += BarrierMenu_OnScrollerChange;
|
||||
barrierMenu.OnMenuOpen += BarrierMenu_OnMouseDown;
|
||||
barrierMenu.OnScrollerChange += BarrierMenu_OnScrollerChanged;
|
||||
barrierMenu.OnCheckboxChange += BarrierMenu_OnCheckboxChanged;
|
||||
barrierMenu.OnMenuOpen += BarrierMenu_OnMenuOpen;
|
||||
}
|
||||
|
||||
internal static void BuildBarrierMenu()
|
||||
{
|
||||
barrierMenu.AddItem(resetBarriers);
|
||||
resetBarriers.ForeColor = Color.Gold;
|
||||
resetBarriers.Enabled = false;
|
||||
barrierMenu.AddItem(barrierList);
|
||||
barrierList.ForeColor = Color.Gold;
|
||||
|
||||
barrierMenu.AddItem(removeBarrierOptions, 0);
|
||||
barrierMenu.AddItem(rotateBarrier);
|
||||
|
||||
barrierMenu.AddItem(invincible);
|
||||
|
||||
if (Settings.EnableAdvancedBarricadeOptions)
|
||||
{
|
||||
barrierMenu.AddItem(barrierTexture);
|
||||
barrierTexture.Index = 0;
|
||||
|
||||
barrierMenu.AddItem(setBarrierLights);
|
||||
|
||||
barrierMenu.AddItem(setBarrierTrafficLight);
|
||||
setBarrierTrafficLight.Index = 3;
|
||||
}
|
||||
|
||||
barrierMenu.AddItem(removeBarrierOptions);
|
||||
removeBarrierOptions.ForeColor = Color.Gold;
|
||||
removeBarrierOptions.Enabled = false;
|
||||
|
||||
barrierMenu.AddItem(rotateBarrier, 0);
|
||||
|
||||
barrierMenu.AddItem(barrierList, 0);
|
||||
barrierList.ForeColor = Color.Gold;
|
||||
barrierMenu.AddItem(resetBarriers);
|
||||
resetBarriers.ForeColor = Color.Gold;
|
||||
resetBarriers.Enabled = false;
|
||||
}
|
||||
|
||||
internal static void CreateShadowBarrier(UIMenu barrierMenu)
|
||||
internal static void CreateShadowBarrier()
|
||||
{
|
||||
Hints.Display($"~o~Scene Manager ~y~[Hint]\n~w~The shadow cone will disappear if you aim too far away.");
|
||||
|
||||
if (shadowBarrier)
|
||||
{
|
||||
shadowBarrier.Delete();
|
||||
}
|
||||
|
||||
shadowBarrier = new Object(Settings.barrierValues[barrierList.Index], GetMousePositionInWorld(), rotateBarrier.Value);
|
||||
shadowBarrier = new Object(Settings.barrierValues[barrierList.Index], MousePositionInWorld.GetPosition, rotateBarrier.Value);
|
||||
if (!shadowBarrier)
|
||||
{
|
||||
barrierMenu.Close();
|
||||
Game.DisplayNotification($"~o~Scene Manager ~r~[Error]\n~w~Something went wrong creating the shadow barrier. Please try again.");
|
||||
return;
|
||||
}
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_TRAFFICLIGHT_OVERRIDE(shadowBarrier, setBarrierTrafficLight.Index);
|
||||
Rage.Native.NativeFunction.Natives.PLACE_OBJECT_ON_GROUND_PROPERLY(shadowBarrier);
|
||||
shadowBarrier.IsGravityDisabled = true;
|
||||
shadowBarrier.IsCollisionEnabled = false;
|
||||
shadowBarrier.Opacity = 0.7f;
|
||||
|
||||
GameFiber ShadowConeLoopFiber = new GameFiber(() => LoopToDisplayShadowBarrier());
|
||||
ShadowConeLoopFiber.Start();
|
||||
// Start with lights off for Parks's objects
|
||||
if (Settings.EnableAdvancedBarricadeOptions)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.x971DA0055324D033(shadowBarrier, barrierTexture.Value);
|
||||
SetBarrierLights();
|
||||
}
|
||||
}
|
||||
|
||||
void LoopToDisplayShadowBarrier()
|
||||
private static void LoopToDisplayShadowBarrier()
|
||||
{
|
||||
while (barrierMenu.Visible && shadowBarrier)
|
||||
while (barrierMenu.Visible)
|
||||
{
|
||||
if (barrierList.Selected || rotateBarrier.Selected)
|
||||
if (barrierList.Selected || rotateBarrier.Selected || invincible.Selected || barrierTexture.Selected || setBarrierLights.Selected || setBarrierTrafficLight.Selected)
|
||||
{
|
||||
if (shadowBarrier)
|
||||
{
|
||||
shadowBarrier.IsVisible = true;
|
||||
UpdateShadowBarrierPosition();
|
||||
}
|
||||
else if(MousePositionInWorld.GetPositionForBarrier.DistanceTo2D(Game.LocalPlayer.Character.Position) <= Settings.BarrierPlacementDistance)
|
||||
{
|
||||
CreateShadowBarrier();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
shadowBarrier.IsVisible = false;
|
||||
if (shadowBarrier)
|
||||
{
|
||||
shadowBarrier.Delete();
|
||||
}
|
||||
}
|
||||
GameFiber.Yield();
|
||||
}
|
||||
|
||||
if (shadowBarrier)
|
||||
{
|
||||
shadowBarrier.Delete();
|
||||
}
|
||||
|
||||
void UpdateShadowBarrierPosition()
|
||||
{
|
||||
DisableBarrierMenuOptionsIfShadowConeTooFar();
|
||||
shadowBarrier.SetPositionWithSnap(GetMousePositionInWorld());
|
||||
if (shadowBarrier)
|
||||
{
|
||||
shadowBarrier.Delete();
|
||||
CreateShadowBarrier();
|
||||
//shadowBarrier.Heading = rotateBarrier.Value;
|
||||
//shadowBarrier.Position = MousePositionInWorld.GetPositionForBarrier;
|
||||
//Rage.Native.NativeFunction.Natives.PLACE_OBJECT_ON_GROUND_PROPERLY(shadowBarrier);
|
||||
//Rage.Native.NativeFunction.Natives.SET_ENTITY_TRAFFICLIGHT_OVERRIDE(shadowBarrier, setBarrierTrafficLight.Index);
|
||||
}
|
||||
|
||||
void DisableBarrierMenuOptionsIfShadowConeTooFar()
|
||||
{
|
||||
if (shadowBarrier.Position.DistanceTo2D(Game.LocalPlayer.Character.Position) > Settings.BarrierPlacementDistance)
|
||||
if (!shadowBarrier && MousePositionInWorld.GetPositionForBarrier.DistanceTo2D(Game.LocalPlayer.Character.Position) <= Settings.BarrierPlacementDistance)
|
||||
{
|
||||
CreateShadowBarrier();
|
||||
|
||||
}
|
||||
else if (shadowBarrier && shadowBarrier.Position.DistanceTo2D(Game.LocalPlayer.Character.Position) > Settings.BarrierPlacementDistance)
|
||||
{
|
||||
barrierList.Enabled = false;
|
||||
rotateBarrier.Enabled = false;
|
||||
shadowBarrier.Delete();
|
||||
}
|
||||
else if (shadowBarrier.Position.DistanceTo2D(Game.LocalPlayer.Character.Position) <= Settings.BarrierPlacementDistance && barrierList.SelectedItem == "Flare")
|
||||
else if (shadowBarrier && shadowBarrier.Position.DistanceTo2D(Game.LocalPlayer.Character.Position) <= Settings.BarrierPlacementDistance && barrierList.SelectedItem == "Flare")
|
||||
{
|
||||
barrierList.Enabled = true;
|
||||
rotateBarrier.Enabled = false;
|
||||
|
|
@ -110,26 +159,57 @@ namespace SceneManager
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void SpawnBarrier()
|
||||
{
|
||||
var barrier = new Rage.Object(shadowBarrier.Model, shadowBarrier.Position, rotateBarrier.Value);
|
||||
if(barrierList.SelectedItem == "Flare")
|
||||
{
|
||||
SpawnFlare();
|
||||
}
|
||||
else
|
||||
{
|
||||
var barrier = new Object(shadowBarrier.Model, shadowBarrier.Position, rotateBarrier.Value);
|
||||
barrier.SetPositionWithSnap(shadowBarrier.Position);
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_DYNAMIC(barrier, true);
|
||||
barrier.IsPositionFrozen = false;
|
||||
if (invincible.Checked)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_DISABLE_FRAG_DAMAGE(barrier, true);
|
||||
if(barrier.Model.Name != "prop_barrier_wat_03a")
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_DISABLE_BREAKING(barrier, true);
|
||||
}
|
||||
}
|
||||
if (Settings.EnableAdvancedBarricadeOptions)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.x971DA0055324D033(barrier, barrierTexture.Value);
|
||||
if (setBarrierLights.Checked)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_LIGHTS(barrier, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_LIGHTS(barrier, true);
|
||||
}
|
||||
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_TRAFFICLIGHT_OVERRIDE(barrier, setBarrierTrafficLight.Index);
|
||||
barrier.IsPositionFrozen = true;
|
||||
GameFiber.Sleep(50);
|
||||
if (barrier)
|
||||
{
|
||||
barrier.IsPositionFrozen = false;
|
||||
}
|
||||
}
|
||||
barriers.Add(new Barrier(barrier, barrier.Position, barrier.Heading));
|
||||
removeBarrierOptions.Enabled = true;
|
||||
resetBarriers.Enabled = true;
|
||||
}
|
||||
|
||||
private static void SpawnFlare()
|
||||
void SpawnFlare()
|
||||
{
|
||||
var flare = new Weapon("weapon_flare", shadowBarrier.Position, 1);
|
||||
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_DYNAMIC(flare, true);
|
||||
GameFiber.Sleep(1);
|
||||
GameFiber.StartNew(() =>
|
||||
{
|
||||
while (flare && flare.HeightAboveGround > 0.05f)
|
||||
|
|
@ -146,6 +226,14 @@ namespace SceneManager
|
|||
barriers.Add(new Barrier(flare, flare.Position, flare.Heading));
|
||||
removeBarrierOptions.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RotateBarrier()
|
||||
{
|
||||
shadowBarrier.Heading = rotateBarrier.Value;
|
||||
shadowBarrier.Position = MousePositionInWorld.GetPositionForBarrier;
|
||||
Rage.Native.NativeFunction.Natives.PLACE_OBJECT_ON_GROUND_PROPERLY(shadowBarrier);
|
||||
}
|
||||
|
||||
private static void RemoveBarrier()
|
||||
{
|
||||
|
|
@ -189,6 +277,13 @@ namespace SceneManager
|
|||
Rage.Native.NativeFunction.Natives.SET_ENTITY_DYNAMIC(newBarrier, true);
|
||||
newBarrier.IsPositionFrozen = false;
|
||||
Rage.Native.NativeFunction.Natives.SET_DISABLE_FRAG_DAMAGE(newBarrier, true);
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_TRAFFICLIGHT_OVERRIDE(newBarrier, setBarrierTrafficLight.Index);
|
||||
newBarrier.IsPositionFrozen = true;
|
||||
GameFiber.Sleep(50);
|
||||
if (newBarrier)
|
||||
{
|
||||
newBarrier.IsPositionFrozen = false;
|
||||
}
|
||||
barriers.Add(new Barrier(newBarrier, newBarrier.Position, newBarrier.Heading));
|
||||
|
||||
|
||||
|
|
@ -201,11 +296,37 @@ namespace SceneManager
|
|||
currentBarriers.Clear();
|
||||
}
|
||||
|
||||
private static void BarrierMenu_OnScrollerChange(UIMenu sender, UIMenuScrollerItem scrollerItem, int oldIndex, int newIndex)
|
||||
private static void SetBarrierLights()
|
||||
{
|
||||
if (setBarrierLights.Checked)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_LIGHTS(shadowBarrier, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_LIGHTS(shadowBarrier, true);
|
||||
}
|
||||
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_TRAFFICLIGHT_OVERRIDE(shadowBarrier, setBarrierTrafficLight.Index);
|
||||
}
|
||||
|
||||
private static void BarrierMenu_OnCheckboxChanged(UIMenu sender, UIMenuCheckboxItem checkbox, bool @checked)
|
||||
{
|
||||
if(checkbox == setBarrierLights)
|
||||
{
|
||||
SetBarrierLights();
|
||||
}
|
||||
}
|
||||
|
||||
private static void BarrierMenu_OnScrollerChanged(UIMenu sender, UIMenuScrollerItem scrollerItem, int oldIndex, int newIndex)
|
||||
{
|
||||
if (scrollerItem == barrierList)
|
||||
{
|
||||
CreateShadowBarrier(barrierMenu);
|
||||
if (shadowBarrier)
|
||||
{
|
||||
shadowBarrier.Delete();
|
||||
}
|
||||
barrierTexture.Index = 0;
|
||||
|
||||
if(barrierList.SelectedItem == "Flare")
|
||||
{
|
||||
|
|
@ -219,29 +340,29 @@ namespace SceneManager
|
|||
barrierMenu.Width = SetMenuWidth();
|
||||
}
|
||||
|
||||
if (scrollerItem == barrierTexture)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.x971DA0055324D033(shadowBarrier, barrierTexture.Value);
|
||||
}
|
||||
|
||||
if (scrollerItem == setBarrierTrafficLight)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_TRAFFICLIGHT_OVERRIDE(shadowBarrier, setBarrierTrafficLight.Index);
|
||||
}
|
||||
|
||||
if (scrollerItem == rotateBarrier)
|
||||
{
|
||||
shadowBarrier.Heading = rotateBarrier.Value;
|
||||
RotateBarrier();
|
||||
}
|
||||
}
|
||||
|
||||
private static void BarrierMenu_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
|
||||
{
|
||||
if (selectedItem == barrierList)
|
||||
{
|
||||
// Attach some invisible object to the cone which the AI try to drive around
|
||||
// Barrier rotates with cone and becomes invisible similar to ASC when created
|
||||
if(barrierList.SelectedItem == "Flare")
|
||||
{
|
||||
SpawnFlare();
|
||||
}
|
||||
else
|
||||
{
|
||||
SpawnBarrier();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (selectedItem == removeBarrierOptions)
|
||||
{
|
||||
RemoveBarrier();
|
||||
|
|
@ -253,166 +374,27 @@ namespace SceneManager
|
|||
}
|
||||
}
|
||||
|
||||
private static void BarrierMenu_OnMouseDown(UIMenu menu)
|
||||
private static void BarrierMenu_OnMenuOpen(UIMenu menu)
|
||||
{
|
||||
GameFiber.StartNew(() =>
|
||||
var scrollerItems = new List<UIMenuScrollerItem> { barrierList, barrierTexture, setBarrierTrafficLight, rotateBarrier, removeBarrierOptions };
|
||||
var checkboxItems = new Dictionary<UIMenuCheckboxItem, RNUIMouseInputHandler.Function>() { { invincible, null }, {setBarrierLights, SetBarrierLights} };
|
||||
var selectItems = new Dictionary<UIMenuItem, RNUIMouseInputHandler.Function>()
|
||||
{
|
||||
while (menu.Visible)
|
||||
{
|
||||
var selectedScroller = menu.MenuItems.Where(x => (x == barrierList || x == rotateBarrier || x == removeBarrierOptions) && x.Selected).FirstOrDefault();
|
||||
if (selectedScroller != null)
|
||||
{
|
||||
HandleScrollerItemsWithMouseWheel(selectedScroller);
|
||||
{ barrierList, SpawnBarrier },
|
||||
{ removeBarrierOptions, RemoveBarrier },
|
||||
{ resetBarriers, ResetBarriers },
|
||||
};
|
||||
|
||||
Hints.Display($"~o~Scene Manager ~y~[Hint]\n~w~The shadow barrier will disappear if you aim too far away.");
|
||||
CreateShadowBarrier();
|
||||
|
||||
GameFiber ShadowConeLoopFiber = new GameFiber(() => LoopToDisplayShadowBarrier());
|
||||
ShadowConeLoopFiber.Start();
|
||||
|
||||
RNUIMouseInputHandler.Initialize(menu, scrollerItems, checkboxItems, selectItems);
|
||||
}
|
||||
|
||||
// Add waypoint if menu item is selected and user left clicks
|
||||
if (Game.IsKeyDown(Keys.LButton))
|
||||
{
|
||||
OnMenuItemClicked();
|
||||
}
|
||||
GameFiber.Yield();
|
||||
}
|
||||
});
|
||||
|
||||
void OnMenuItemClicked()
|
||||
{
|
||||
if (barrierList.Selected)
|
||||
{
|
||||
if (barrierList.SelectedItem == "Flare")
|
||||
{
|
||||
SpawnFlare();
|
||||
}
|
||||
else
|
||||
{
|
||||
SpawnBarrier();
|
||||
}
|
||||
}
|
||||
else if (removeBarrierOptions.Selected)
|
||||
{
|
||||
RemoveBarrier();
|
||||
}
|
||||
else if (resetBarriers.Selected)
|
||||
{
|
||||
ResetBarriers();
|
||||
}
|
||||
}
|
||||
|
||||
void HandleScrollerItemsWithMouseWheel(UIMenuItem selectedScroller)
|
||||
{
|
||||
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();
|
||||
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)
|
||||
{
|
||||
if (selectedScroller == barrierList)
|
||||
{
|
||||
barrierList.ScrollToNextOption();
|
||||
CreateShadowBarrier(barrierMenu);
|
||||
|
||||
if (barrierList.SelectedItem == "Flare")
|
||||
{
|
||||
rotateBarrier.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
rotateBarrier.Enabled = true;
|
||||
}
|
||||
|
||||
barrierMenu.Width = SetMenuWidth();
|
||||
}
|
||||
else if (selectedScroller == rotateBarrier)
|
||||
{
|
||||
rotateBarrier.ScrollToNextOption();
|
||||
shadowBarrier.Heading = rotateBarrier.Value;
|
||||
}
|
||||
else if (selectedScroller == removeBarrierOptions)
|
||||
{
|
||||
removeBarrierOptions.ScrollToNextOption();
|
||||
}
|
||||
}
|
||||
else if (Game.GetMouseWheelDelta() < 0)
|
||||
{
|
||||
if (selectedScroller == barrierList)
|
||||
{
|
||||
barrierList.ScrollToPreviousOption();
|
||||
CreateShadowBarrier(barrierMenu);
|
||||
|
||||
if (barrierList.SelectedItem == "Flare")
|
||||
{
|
||||
rotateBarrier.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
rotateBarrier.Enabled = true;
|
||||
}
|
||||
|
||||
barrierMenu.Width = SetMenuWidth();
|
||||
}
|
||||
else if (selectedScroller == rotateBarrier)
|
||||
{
|
||||
rotateBarrier.ScrollToPreviousOption();
|
||||
shadowBarrier.Heading = rotateBarrier.Value;
|
||||
}
|
||||
else if(selectedScroller == removeBarrierOptions)
|
||||
{
|
||||
removeBarrierOptions.ScrollToPreviousOption();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Vector3 GetMousePositionInWorld()
|
||||
{
|
||||
HitResult TracePlayerView(float maxTraceDistance = 30f, 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(Settings.BarrierPlacementDistance, TraceFlags.IntersectWorld).HitPosition;
|
||||
}
|
||||
|
||||
private static float SetMenuWidth()
|
||||
internal static float SetMenuWidth()
|
||||
{
|
||||
float defaultWidth = UIMenu.DefaultWidth;
|
||||
float width = barrierMenu.Width;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Drawing;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using Rage;
|
||||
|
|
@ -19,7 +20,7 @@ namespace SceneManager
|
|||
MenuManager.menuPool.Add(editPathMenu);
|
||||
editPathMenu.OnItemSelect += EditPath_OnItemSelected;
|
||||
editPathMenu.OnCheckboxChange += EditPath_OnCheckboxChange;
|
||||
editPathMenu.OnMenuOpen += EditPath_OnMouseDown;
|
||||
editPathMenu.OnMenuOpen += EditPath_OnMenuOpen;
|
||||
}
|
||||
|
||||
internal static void BuildEditPathMenu()
|
||||
|
|
@ -84,42 +85,17 @@ namespace SceneManager
|
|||
}
|
||||
}
|
||||
|
||||
private static void EditPath_OnMouseDown(UIMenu menu)
|
||||
private static void EditPath_OnMenuOpen(UIMenu menu)
|
||||
{
|
||||
GameFiber.StartNew(() =>
|
||||
var scrollerItems = new List<UIMenuScrollerItem> { };
|
||||
var checkboxItems = new Dictionary<UIMenuCheckboxItem, RNUIMouseInputHandler.Function>() { { disablePath, DisablePath } };
|
||||
var selectItems = new Dictionary<UIMenuItem, RNUIMouseInputHandler.Function>()
|
||||
{
|
||||
while (menu.Visible)
|
||||
{
|
||||
// Add waypoint if menu item is selected and user left clicks
|
||||
if (Game.IsKeyDown(Keys.LButton))
|
||||
{
|
||||
OnCheckboxItemClicked();
|
||||
OnMenuItemClicked();
|
||||
}
|
||||
GameFiber.Yield();
|
||||
}
|
||||
});
|
||||
{ editPathWaypoints, EditPathWaypoints },
|
||||
{ deletePath, DeletePath }
|
||||
};
|
||||
|
||||
void OnCheckboxItemClicked()
|
||||
{
|
||||
if (disablePath.Selected && disablePath.Enabled)
|
||||
{
|
||||
disablePath.Checked = !disablePath.Checked;
|
||||
DisablePath();
|
||||
}
|
||||
}
|
||||
|
||||
void OnMenuItemClicked()
|
||||
{
|
||||
if (editPathWaypoints.Selected)
|
||||
{
|
||||
EditPathWaypoints();
|
||||
}
|
||||
else if (deletePath.Selected)
|
||||
{
|
||||
DeletePath();
|
||||
}
|
||||
}
|
||||
RNUIMouseInputHandler.Initialize(menu, scrollerItems, checkboxItems, selectItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using Rage;
|
||||
using RAGENativeUI;
|
||||
using RAGENativeUI.Elements;
|
||||
|
|
@ -10,8 +9,6 @@ namespace SceneManager
|
|||
{
|
||||
class EditWaypointMenu
|
||||
{
|
||||
private static VehicleDrivingFlags[] drivingFlags = new VehicleDrivingFlags[] { VehicleDrivingFlags.Normal, VehicleDrivingFlags.IgnorePathFinding, VehicleDrivingFlags.StopAtDestination };
|
||||
private static string[] waypointTypes = new string[] { "Drive To (Normal)", "Drive To (Direct)", "Stop" };
|
||||
internal static UIMenu editWaypointMenu = new UIMenu("Scene Manager", "~o~Edit Waypoint");
|
||||
internal static UIMenuItem updateWaypoint = new UIMenuItem("Update Waypoint");
|
||||
internal static UIMenuItem removeWaypoint = new UIMenuItem("Remove Waypoint");
|
||||
|
|
@ -33,13 +30,12 @@ namespace SceneManager
|
|||
editWaypointMenu.OnScrollerChange += EditWaypoint_OnScrollerChanged;
|
||||
editWaypointMenu.OnCheckboxChange += EditWaypoint_OnCheckboxChanged;
|
||||
editWaypointMenu.OnItemSelect += EditWaypoint_OnItemSelected;
|
||||
editWaypointMenu.OnMenuOpen += EditWaypoint_OnMouseDown;
|
||||
editWaypointMenu.OnMenuOpen += EditWaypoint_OnMenuOpen;
|
||||
}
|
||||
|
||||
internal static void BuildEditWaypointMenu()
|
||||
{
|
||||
var currentPath = PathMainMenu.paths[PathMainMenu.editPath.Value-1];
|
||||
//Logger.Log($"Current path: {currentPath.Number}");
|
||||
|
||||
editWaypoint = new UIMenuNumericScrollerItem<int>("Edit Waypoint", "", currentPath.Waypoints.First().Number, currentPath.Waypoints.Last().Number, 1);
|
||||
editWaypointMenu.Clear();
|
||||
|
|
@ -47,7 +43,6 @@ namespace SceneManager
|
|||
editWaypoint.Index = 0;
|
||||
|
||||
var currentWaypoint = currentPath.Waypoints.Where(wp => wp.Number == editWaypoint.Value).FirstOrDefault();
|
||||
//Logger.Log($"Current waypoint: {currentWaypoint.Number}, Driving flag: {currentWaypoint.DrivingFlag.ToString()}");
|
||||
if(currentWaypoint != null)
|
||||
{
|
||||
editWaypointMenu.AddItem(collectorWaypoint = new UIMenuCheckboxItem("Collector", currentWaypoint.IsCollector, "If this waypoint will collect vehicles to follow the path"));
|
||||
|
|
@ -89,15 +84,33 @@ namespace SceneManager
|
|||
}
|
||||
}
|
||||
|
||||
private static void UpdateWaypoint(Path currentPath, Waypoint currentWaypoint, DrivingFlagType drivingFlag)
|
||||
private static void UpdateCollectorMenuOptionsStatus()
|
||||
{
|
||||
if (currentPath.Waypoints.Count == 1)
|
||||
if (collectorWaypoint.Checked)
|
||||
{
|
||||
currentWaypoint.UpdateWaypoint(currentWaypoint, GetMousePositionInWorld(), drivingFlag, stopWaypointType.Checked, SetDriveSpeedForWaypoint(), true, changeCollectorRadius.Value, changeSpeedZoneRadius.Value, updateWaypointPosition.Checked);
|
||||
changeCollectorRadius.Enabled = true;
|
||||
changeSpeedZoneRadius.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentWaypoint.UpdateWaypoint(currentWaypoint, GetMousePositionInWorld(), drivingFlag, stopWaypointType.Checked, SetDriveSpeedForWaypoint(), collectorWaypoint.Checked, changeCollectorRadius.Value, changeSpeedZoneRadius.Value, updateWaypointPosition.Checked);
|
||||
changeCollectorRadius.Enabled = false;
|
||||
changeSpeedZoneRadius.Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateWaypoint()
|
||||
{
|
||||
var currentPath = PathMainMenu.paths[PathMainMenu.editPath.Index];
|
||||
var currentWaypoint = currentPath.Waypoints[editWaypoint.Index];
|
||||
DrivingFlagType drivingFlag = directWaypointBehavior.Checked ? DrivingFlagType.Direct : DrivingFlagType.Normal;
|
||||
|
||||
if (currentPath.Waypoints.Count == 1)
|
||||
{
|
||||
currentWaypoint.UpdateWaypoint(currentWaypoint, MousePositionInWorld.GetPosition, drivingFlag, stopWaypointType.Checked, SetDriveSpeedForWaypoint(), true, changeCollectorRadius.Value, changeSpeedZoneRadius.Value, updateWaypointPosition.Checked);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentWaypoint.UpdateWaypoint(currentWaypoint, MousePositionInWorld.GetPosition, drivingFlag, stopWaypointType.Checked, SetDriveSpeedForWaypoint(), collectorWaypoint.Checked, changeCollectorRadius.Value, changeSpeedZoneRadius.Value, updateWaypointPosition.Checked);
|
||||
}
|
||||
|
||||
Game.LogTrivial($"Path {currentPath.Number} Waypoint {currentWaypoint.Number} updated [Driving style: {drivingFlag} | Stop waypoint: {stopWaypointType.Checked} | Speed: {changeWaypointSpeed.Value} | Collector: {currentWaypoint.IsCollector}]");
|
||||
|
|
@ -106,8 +119,12 @@ namespace SceneManager
|
|||
Game.DisplayNotification($"~o~Scene Manager ~g~[Success]~w~\nWaypoint {currentWaypoint.Number} updated.");
|
||||
}
|
||||
|
||||
private static void RemoveWaypoint(Path currentPath, Waypoint currentWaypoint, DrivingFlagType drivingFlag)
|
||||
private static void RemoveWaypoint()
|
||||
{
|
||||
var currentPath = PathMainMenu.paths[PathMainMenu.editPath.Index];
|
||||
var currentWaypoint = currentPath.Waypoints[editWaypoint.Index];
|
||||
DrivingFlagType drivingFlag = directWaypointBehavior.Checked ? DrivingFlagType.Direct : DrivingFlagType.Normal;
|
||||
|
||||
if (currentPath.Waypoints.Count == 1)
|
||||
{
|
||||
Game.LogTrivial($"Deleting the last waypoint from the path.");
|
||||
|
|
@ -134,7 +151,7 @@ namespace SceneManager
|
|||
{
|
||||
Hints.Display($"~o~Scene Manager ~y~[Hint]~w~\nYour path's first waypoint ~b~must~w~ be a collector. If it's not, it will automatically be made into one.");
|
||||
Game.LogTrivial($"The path only has 1 waypoint left, this waypoint must be a collector.");
|
||||
currentPath.Waypoints[0].UpdateWaypoint(currentWaypoint, GetMousePositionInWorld(), drivingFlag, stopWaypointType.Checked, SetDriveSpeedForWaypoint(), true, changeCollectorRadius.Value, changeSpeedZoneRadius.Value, updateWaypointPosition.Checked);
|
||||
currentPath.Waypoints[0].UpdateWaypoint(currentWaypoint, MousePositionInWorld.GetPosition, drivingFlag, stopWaypointType.Checked, SetDriveSpeedForWaypoint(), true, changeCollectorRadius.Value, changeSpeedZoneRadius.Value, updateWaypointPosition.Checked);
|
||||
collectorWaypoint.Checked = true;
|
||||
changeCollectorRadius.Enabled = true;
|
||||
changeSpeedZoneRadius.Enabled = true;
|
||||
|
|
@ -142,8 +159,11 @@ namespace SceneManager
|
|||
}
|
||||
}
|
||||
|
||||
private static void AddAsNewWaypoint(Path currentPath, DrivingFlagType drivingFlag)
|
||||
private static void AddAsNewWaypoint()
|
||||
{
|
||||
var currentPath = PathMainMenu.paths[PathMainMenu.editPath.Index];
|
||||
DrivingFlagType drivingFlag = directWaypointBehavior.Checked ? DrivingFlagType.Direct : DrivingFlagType.Normal;
|
||||
|
||||
var pathIndex = PathMainMenu.paths.IndexOf(currentPath);
|
||||
var newWaypointBlip = CreateNewWaypointBlip();
|
||||
if (!currentPath.IsEnabled)
|
||||
|
|
@ -153,11 +173,11 @@ namespace SceneManager
|
|||
|
||||
if (collectorWaypoint.Checked)
|
||||
{
|
||||
currentPath.Waypoints.Add(new Waypoint(currentPath, currentPath.Waypoints.Last().Number + 1, GetMousePositionInWorld(), SetDriveSpeedForWaypoint(), drivingFlag, stopWaypointType.Checked, newWaypointBlip, true, changeCollectorRadius.Value, changeSpeedZoneRadius.Value));
|
||||
currentPath.Waypoints.Add(new Waypoint(currentPath, currentPath.Waypoints.Last().Number + 1, MousePositionInWorld.GetPosition, SetDriveSpeedForWaypoint(), drivingFlag, stopWaypointType.Checked, newWaypointBlip, true, changeCollectorRadius.Value, changeSpeedZoneRadius.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
currentPath.Waypoints.Add(new Waypoint(currentPath, currentPath.Waypoints.Last().Number + 1, GetMousePositionInWorld(), SetDriveSpeedForWaypoint(), drivingFlag, stopWaypointType.Checked, newWaypointBlip));
|
||||
currentPath.Waypoints.Add(new Waypoint(currentPath, currentPath.Waypoints.Last().Number + 1, MousePositionInWorld.GetPosition, SetDriveSpeedForWaypoint(), drivingFlag, stopWaypointType.Checked, newWaypointBlip));
|
||||
}
|
||||
|
||||
editWaypointMenu.RemoveItemAt(0);
|
||||
|
|
@ -171,7 +191,7 @@ namespace SceneManager
|
|||
Blip CreateNewWaypointBlip()
|
||||
{
|
||||
var spriteNumericalEnum = pathIndex + 17; // 17 because the numerical value of these sprites are always 17 more than the path index
|
||||
var blip = new Blip(GetMousePositionInWorld())
|
||||
var blip = new Blip(MousePositionInWorld.GetPosition)
|
||||
{
|
||||
Scale = 0.5f,
|
||||
Sprite = (BlipSprite)spriteNumericalEnum
|
||||
|
|
@ -254,251 +274,38 @@ namespace SceneManager
|
|||
|
||||
if (selectedItem == updateWaypoint)
|
||||
{
|
||||
UpdateWaypoint(currentPath, currentWaypoint, drivingFlag);
|
||||
UpdateWaypoint();
|
||||
}
|
||||
|
||||
if (selectedItem == addAsNewWaypoint)
|
||||
{
|
||||
AddAsNewWaypoint(currentPath, drivingFlag);
|
||||
AddAsNewWaypoint();
|
||||
}
|
||||
|
||||
if (selectedItem == removeWaypoint)
|
||||
{
|
||||
RemoveWaypoint(currentPath, currentWaypoint, drivingFlag);
|
||||
RemoveWaypoint();
|
||||
}
|
||||
}
|
||||
|
||||
private static void EditWaypoint_OnMouseDown(UIMenu menu)
|
||||
private static void EditWaypoint_OnMenuOpen(UIMenu menu)
|
||||
{
|
||||
GameFiber.StartNew(() =>
|
||||
var scrollerItems = new List<UIMenuScrollerItem> { editWaypoint, changeWaypointSpeed, changeCollectorRadius, changeSpeedZoneRadius };
|
||||
var checkboxItems = new Dictionary<UIMenuCheckboxItem, RNUIMouseInputHandler.Function>()
|
||||
{
|
||||
while (menu.Visible)
|
||||
{ collectorWaypoint, UpdateCollectorMenuOptionsStatus },
|
||||
{ stopWaypointType, null },
|
||||
{ directWaypointBehavior, null },
|
||||
{ updateWaypointPosition, null }
|
||||
};
|
||||
var selectItems = new Dictionary<UIMenuItem, RNUIMouseInputHandler.Function>()
|
||||
{
|
||||
var selectedScroller = menu.MenuItems.Where(x => (x == editWaypoint || x == changeWaypointSpeed || x == changeCollectorRadius || x == changeSpeedZoneRadius) && x.Selected).FirstOrDefault();
|
||||
if (selectedScroller != null)
|
||||
{
|
||||
HandleScrollerItemsWithMouseWheel(selectedScroller);
|
||||
}
|
||||
{ updateWaypoint, UpdateWaypoint },
|
||||
{ removeWaypoint, RemoveWaypoint },
|
||||
{ addAsNewWaypoint, AddAsNewWaypoint }
|
||||
};
|
||||
|
||||
if (Game.IsKeyDown(Keys.LButton))
|
||||
{
|
||||
OnCheckboxItemClicked();
|
||||
OnMenuItemClicked();
|
||||
}
|
||||
GameFiber.Yield();
|
||||
}
|
||||
});
|
||||
|
||||
void OnCheckboxItemClicked()
|
||||
{
|
||||
if (collectorWaypoint.Selected && collectorWaypoint.Enabled)
|
||||
{
|
||||
collectorWaypoint.Checked = !collectorWaypoint.Checked;
|
||||
if (collectorWaypoint.Checked)
|
||||
{
|
||||
changeCollectorRadius.Enabled = true;
|
||||
changeSpeedZoneRadius.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
changeCollectorRadius.Enabled = false;
|
||||
changeSpeedZoneRadius.Enabled = false;
|
||||
}
|
||||
}
|
||||
else if (stopWaypointType.Selected)
|
||||
{
|
||||
stopWaypointType.Checked = !stopWaypointType.Checked;
|
||||
}
|
||||
else if (directWaypointBehavior.Selected)
|
||||
{
|
||||
directWaypointBehavior.Checked = !directWaypointBehavior.Checked;
|
||||
}
|
||||
else if (updateWaypointPosition.Selected)
|
||||
{
|
||||
updateWaypointPosition.Checked = !updateWaypointPosition.Checked;
|
||||
if (updateWaypointPosition.Checked)
|
||||
{
|
||||
DrawWaypointMarker(GetMousePositionInWorld());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void OnMenuItemClicked()
|
||||
{
|
||||
var currentPath = PathMainMenu.paths[PathMainMenu.editPath.Index];
|
||||
var currentWaypoint = currentPath.Waypoints[editWaypoint.Index];
|
||||
DrivingFlagType drivingFlag = directWaypointBehavior.Checked ? DrivingFlagType.Direct : DrivingFlagType.Normal;
|
||||
|
||||
if (updateWaypoint.Selected)
|
||||
{
|
||||
UpdateWaypoint(currentPath, currentWaypoint, drivingFlag);
|
||||
}
|
||||
else if (removeWaypoint.Selected)
|
||||
{
|
||||
RemoveWaypoint(currentPath, currentWaypoint, drivingFlag);
|
||||
}
|
||||
else if (addAsNewWaypoint.Selected)
|
||||
{
|
||||
AddAsNewWaypoint(currentPath, drivingFlag);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleScrollerItemsWithMouseWheel(UIMenuItem selectedScroller)
|
||||
{
|
||||
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();
|
||||
CompareScrollerValues();
|
||||
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)
|
||||
{
|
||||
if (selectedScroller == changeCollectorRadius)
|
||||
{
|
||||
changeCollectorRadius.ScrollToNextOption();
|
||||
}
|
||||
else if (selectedScroller == changeSpeedZoneRadius)
|
||||
{
|
||||
changeSpeedZoneRadius.ScrollToNextOption();
|
||||
}
|
||||
else if (selectedScroller == changeWaypointSpeed)
|
||||
{
|
||||
changeWaypointSpeed.ScrollToNextOption();
|
||||
}
|
||||
else if(selectedScroller == editWaypoint)
|
||||
{
|
||||
editWaypoint.ScrollToNextOption();
|
||||
|
||||
var currentPath = PathMainMenu.paths[PathMainMenu.editPath.Index];
|
||||
var currentWaypoint = currentPath.Waypoints[editWaypoint.Value - 1];
|
||||
changeWaypointSpeed.Value = (int)MathHelper.ConvertMetersPerSecondToMilesPerHour(currentWaypoint.Speed);
|
||||
stopWaypointType.Checked = currentWaypoint.IsStopWaypoint;
|
||||
directWaypointBehavior.Checked = currentWaypoint.DrivingFlagType == DrivingFlagType.Direct ? true : false;
|
||||
collectorWaypoint.Checked = currentWaypoint.IsCollector;
|
||||
changeCollectorRadius.Enabled = collectorWaypoint.Checked ? true : false;
|
||||
changeCollectorRadius.Value = (int)currentWaypoint.CollectorRadius;
|
||||
changeSpeedZoneRadius.Enabled = collectorWaypoint.Checked ? true : false;
|
||||
changeSpeedZoneRadius.Value = (int)currentWaypoint.SpeedZoneRadius;
|
||||
updateWaypointPosition.Checked = false;
|
||||
}
|
||||
}
|
||||
else if (Game.GetMouseWheelDelta() < 0)
|
||||
{
|
||||
if (selectedScroller == changeCollectorRadius)
|
||||
{
|
||||
changeCollectorRadius.ScrollToPreviousOption();
|
||||
}
|
||||
else if (selectedScroller == changeSpeedZoneRadius)
|
||||
{
|
||||
changeSpeedZoneRadius.ScrollToPreviousOption();
|
||||
}
|
||||
else if (selectedScroller == changeWaypointSpeed)
|
||||
{
|
||||
changeWaypointSpeed.ScrollToPreviousOption();
|
||||
}
|
||||
else if (selectedScroller == editWaypoint)
|
||||
{
|
||||
editWaypoint.ScrollToPreviousOption();
|
||||
|
||||
var currentPath = PathMainMenu.paths[PathMainMenu.editPath.Index];
|
||||
var currentWaypoint = currentPath.Waypoints[editWaypoint.Value - 1];
|
||||
changeWaypointSpeed.Value = (int)MathHelper.ConvertMetersPerSecondToMilesPerHour(currentWaypoint.Speed);
|
||||
stopWaypointType.Checked = currentWaypoint.IsStopWaypoint;
|
||||
directWaypointBehavior.Checked = currentWaypoint.DrivingFlagType == DrivingFlagType.Direct ? true : false;
|
||||
collectorWaypoint.Checked = currentWaypoint.IsCollector;
|
||||
changeCollectorRadius.Enabled = collectorWaypoint.Checked ? true : false;
|
||||
changeCollectorRadius.Value = (int)currentWaypoint.CollectorRadius;
|
||||
changeSpeedZoneRadius.Enabled = collectorWaypoint.Checked ? true : false;
|
||||
changeSpeedZoneRadius.Value = (int)currentWaypoint.SpeedZoneRadius;
|
||||
updateWaypointPosition.Checked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CompareScrollerValues()
|
||||
{
|
||||
if (selectedScroller == changeCollectorRadius && changeCollectorRadius.Value > changeSpeedZoneRadius.Value)
|
||||
{
|
||||
while (changeCollectorRadius.Value > changeSpeedZoneRadius.Value)
|
||||
{
|
||||
changeSpeedZoneRadius.ScrollToNextOption();
|
||||
}
|
||||
}
|
||||
if (selectedScroller == changeSpeedZoneRadius && changeSpeedZoneRadius.Value < changeCollectorRadius.Value)
|
||||
{
|
||||
changeCollectorRadius.Value = changeSpeedZoneRadius.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawWaypointMarker(Vector3 waypointPosition)
|
||||
{
|
||||
if (SettingsMenu.threeDWaypoints.Checked)
|
||||
{
|
||||
if (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 (stopWaypointType.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Vector3 GetMousePositionInWorld()
|
||||
{
|
||||
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(100f, TraceFlags.IntersectWorld).HitPosition;
|
||||
RNUIMouseInputHandler.Initialize(menu, scrollerItems, checkboxItems, selectItems);
|
||||
}
|
||||
|
||||
private static float SetDriveSpeedForWaypoint()
|
||||
|
|
@ -506,15 +313,11 @@ namespace SceneManager
|
|||
float convertedSpeed;
|
||||
if (SettingsMenu.speedUnits.SelectedItem == SpeedUnits.MPH)
|
||||
{
|
||||
//Logger.Log($"Original speed: {waypointSpeeds[waypointSpeed.Index]}{SettingsMenu.speedUnits.SelectedItem}");
|
||||
convertedSpeed = MathHelper.ConvertMilesPerHourToMetersPerSecond(changeWaypointSpeed.Value);
|
||||
//Logger.Log($"Converted speed: {convertedSpeed}m/s");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Logger.Log($"Original speed: {waypointSpeeds[waypointSpeed.Index]}{SettingsMenu.speedUnits.SelectedItem}");
|
||||
convertedSpeed = MathHelper.ConvertKilometersPerHourToMetersPerSecond(changeWaypointSpeed.Value);
|
||||
//Logger.Log($"Converted speed: {convertedSpeed}m/s");
|
||||
}
|
||||
|
||||
return convertedSpeed;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using Rage;
|
||||
using RAGENativeUI;
|
||||
using RAGENativeUI.Elements;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
|
@ -18,7 +19,7 @@ namespace SceneManager
|
|||
MenuManager.menuPool.Add(mainMenu);
|
||||
}
|
||||
|
||||
public static void BuildMainMenu()
|
||||
internal static void BuildMainMenu()
|
||||
{
|
||||
mainMenu.AddItem(navigateToPathMenu = new UIMenuItem("Path Menu"));
|
||||
navigateToPathMenu.ForeColor = Color.Gold;
|
||||
|
|
@ -31,49 +32,36 @@ namespace SceneManager
|
|||
mainMenu.BindMenuToItem(SettingsMenu.settingsMenu, navigateToSettingsMenu);
|
||||
|
||||
mainMenu.RefreshIndex();
|
||||
mainMenu.OnItemSelect += MainMenu_OnItemSelected;
|
||||
mainMenu.OnMenuOpen += MainMenu_OnMouseDown;
|
||||
mainMenu.OnMenuOpen += MainMenu_OnMenuOpen;
|
||||
}
|
||||
|
||||
private static void MainMenu_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
|
||||
{
|
||||
if (selectedItem == navigateToBarrierMenu)
|
||||
{
|
||||
BarrierMenu.CreateShadowBarrier(BarrierMenu.barrierMenu);
|
||||
}
|
||||
}
|
||||
|
||||
private static void MainMenu_OnMouseDown(UIMenu menu)
|
||||
{
|
||||
GameFiber.StartNew(() =>
|
||||
{
|
||||
while (menu.Visible)
|
||||
{
|
||||
if (Game.IsKeyDown(Keys.LButton))
|
||||
{
|
||||
menu.Visible = false;
|
||||
OnMenuItemClicked();
|
||||
}
|
||||
GameFiber.Yield();
|
||||
}
|
||||
});
|
||||
|
||||
void OnMenuItemClicked()
|
||||
{
|
||||
if (navigateToPathMenu.Selected)
|
||||
private static void ShowPathMainMenu()
|
||||
{
|
||||
PathMainMenu.pathMainMenu.Visible = true;
|
||||
}
|
||||
else if (navigateToBarrierMenu.Selected)
|
||||
|
||||
private static void ShowBarrierMenu()
|
||||
{
|
||||
BarrierMenu.barrierMenu.Visible = true;
|
||||
BarrierMenu.CreateShadowBarrier(BarrierMenu.barrierMenu);
|
||||
}
|
||||
else if (navigateToSettingsMenu.Selected)
|
||||
|
||||
private static void ShowSettingsMenu()
|
||||
{
|
||||
SettingsMenu.settingsMenu.Visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void MainMenu_OnMenuOpen(UIMenu menu)
|
||||
{
|
||||
var scrollerItems = new List<UIMenuScrollerItem> { };
|
||||
var checkboxItems = new Dictionary<UIMenuCheckboxItem, RNUIMouseInputHandler.Function>() { };
|
||||
var selectItems = new Dictionary<UIMenuItem, RNUIMouseInputHandler.Function>()
|
||||
{
|
||||
{ navigateToPathMenu, ShowPathMainMenu },
|
||||
{ navigateToBarrierMenu, ShowBarrierMenu },
|
||||
{ navigateToSettingsMenu, ShowSettingsMenu }
|
||||
};
|
||||
|
||||
RNUIMouseInputHandler.Initialize(menu, scrollerItems, checkboxItems, selectItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Net.Configuration;
|
||||
using System.Windows.Forms;
|
||||
using Rage;
|
||||
using RAGENativeUI;
|
||||
|
|
@ -28,7 +29,7 @@ namespace SceneManager
|
|||
pathCreationMenu.OnItemSelect += PathCreation_OnItemSelected;
|
||||
pathCreationMenu.OnCheckboxChange += PathCreation_OnCheckboxChanged;
|
||||
pathCreationMenu.OnScrollerChange += PathCreation_OnScrollerChanged;
|
||||
pathCreationMenu.OnMenuOpen += PathCreation_OnMouseDown;
|
||||
pathCreationMenu.OnMenuOpen += PathCreation_OnMenuOpen;
|
||||
}
|
||||
|
||||
internal static void BuildPathCreationMenu()
|
||||
|
|
@ -67,85 +68,8 @@ namespace SceneManager
|
|||
pathCreationMenu.RefreshIndex();
|
||||
}
|
||||
|
||||
private static void PathCreation_OnCheckboxChanged(UIMenu sender, UIMenuCheckboxItem checkboxItem, bool @checked)
|
||||
private static void UpdateCollectorMenuOptionsStatus()
|
||||
{
|
||||
if(checkboxItem == collectorWaypoint)
|
||||
{
|
||||
collectorRadius.Enabled = collectorWaypoint.Checked ? true : false;
|
||||
speedZoneRadius.Enabled = collectorWaypoint.Checked ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void PathCreation_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
|
||||
{
|
||||
if (selectedItem == trafficAddWaypoint)
|
||||
{
|
||||
AddNewWaypoint(GetMousePositionInWorld());
|
||||
}
|
||||
|
||||
if (selectedItem == trafficRemoveWaypoint)
|
||||
{
|
||||
RemoveWaypoint();
|
||||
}
|
||||
|
||||
if (selectedItem == trafficEndPath)
|
||||
{
|
||||
EndPath();
|
||||
}
|
||||
}
|
||||
|
||||
private static void PathCreation_OnScrollerChanged(UIMenu sender, UIMenuScrollerItem scrollerItem, int first, int last)
|
||||
{
|
||||
if (scrollerItem == collectorRadius)
|
||||
{
|
||||
if (collectorRadius.Value > speedZoneRadius.Value)
|
||||
{
|
||||
while (collectorRadius.Value > speedZoneRadius.Value)
|
||||
{
|
||||
speedZoneRadius.ScrollToNextOption();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scrollerItem == speedZoneRadius)
|
||||
{
|
||||
if (speedZoneRadius.Value < collectorRadius.Value)
|
||||
{
|
||||
collectorRadius.Value = speedZoneRadius.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void PathCreation_OnMouseDown(UIMenu menu)
|
||||
{
|
||||
GameFiber.StartNew(() =>
|
||||
{
|
||||
while (menu.Visible)
|
||||
{
|
||||
var selectedScroller = menu.MenuItems.Where(x => (x == collectorRadius || x == speedZoneRadius || x == waypointSpeed) && x.Selected).FirstOrDefault();
|
||||
if (selectedScroller != null)
|
||||
{
|
||||
HandleScrollerItemsWithMouseWheel(selectedScroller);
|
||||
}
|
||||
|
||||
// Draw marker at mouse position
|
||||
DrawWaypointMarker(GetMousePositionInWorld());
|
||||
|
||||
// Add waypoint if menu item is selected and user left clicks
|
||||
if (Game.IsKeyDown(Keys.LButton))
|
||||
{
|
||||
OnCheckboxItemClicked();
|
||||
OnMenuItemClicked();
|
||||
}
|
||||
GameFiber.Yield();
|
||||
}
|
||||
});
|
||||
|
||||
void OnCheckboxItemClicked()
|
||||
{
|
||||
if (collectorWaypoint.Selected && collectorWaypoint.Enabled)
|
||||
{
|
||||
collectorWaypoint.Checked = !collectorWaypoint.Checked;
|
||||
if (collectorWaypoint.Checked)
|
||||
{
|
||||
collectorRadius.Enabled = true;
|
||||
|
|
@ -157,110 +81,11 @@ namespace SceneManager
|
|||
speedZoneRadius.Enabled = false;
|
||||
}
|
||||
}
|
||||
else if (stopWaypointType.Selected)
|
||||
{
|
||||
stopWaypointType.Checked = !stopWaypointType.Checked;
|
||||
}
|
||||
else if (directWaypointBehavior.Selected)
|
||||
{
|
||||
directWaypointBehavior.Checked = !directWaypointBehavior.Checked;
|
||||
}
|
||||
}
|
||||
|
||||
void OnMenuItemClicked()
|
||||
{
|
||||
if (trafficAddWaypoint.Selected)
|
||||
{
|
||||
AddNewWaypoint(GetMousePositionInWorld());
|
||||
}
|
||||
else if (trafficRemoveWaypoint.Selected)
|
||||
{
|
||||
RemoveWaypoint();
|
||||
}
|
||||
else if (trafficEndPath.Selected)
|
||||
{
|
||||
EndPath();
|
||||
}
|
||||
}
|
||||
|
||||
void HandleScrollerItemsWithMouseWheel(UIMenuItem selectedScroller)
|
||||
{
|
||||
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();
|
||||
CompareScrollerValues();
|
||||
DrawWaypointMarker(GetMousePositionInWorld());
|
||||
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)
|
||||
{
|
||||
if (selectedScroller == collectorRadius)
|
||||
{
|
||||
collectorRadius.ScrollToNextOption();
|
||||
}
|
||||
else if (selectedScroller == speedZoneRadius)
|
||||
{
|
||||
speedZoneRadius.ScrollToNextOption();
|
||||
}
|
||||
else if (selectedScroller == waypointSpeed)
|
||||
{
|
||||
waypointSpeed.ScrollToNextOption();
|
||||
}
|
||||
}
|
||||
else if (Game.GetMouseWheelDelta() < 0)
|
||||
{
|
||||
if (selectedScroller == collectorRadius)
|
||||
{
|
||||
collectorRadius.ScrollToPreviousOption();
|
||||
}
|
||||
else if (selectedScroller == speedZoneRadius)
|
||||
{
|
||||
speedZoneRadius.ScrollToPreviousOption();
|
||||
}
|
||||
else if (selectedScroller == waypointSpeed)
|
||||
{
|
||||
waypointSpeed.ScrollToPreviousOption();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CompareScrollerValues()
|
||||
{
|
||||
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 AddNewWaypoint(Vector3 waypointPosition)
|
||||
private static void AddNewWaypoint()
|
||||
{
|
||||
var anyPathsExist = PathMainMenu.paths.Count > 0;
|
||||
var waypointPosition = MousePositionInWorld.GetPosition;
|
||||
|
||||
if (!anyPathsExist)
|
||||
{
|
||||
|
|
@ -426,7 +251,7 @@ namespace SceneManager
|
|||
}
|
||||
}
|
||||
|
||||
internal static void AddNewPathToPathsCollection(List<Path> paths, int pathIndex)
|
||||
private static void AddNewPathToPathsCollection(List<Path> paths, int pathIndex)
|
||||
{
|
||||
var pathNum = pathIndex + 1;
|
||||
Game.LogTrivial($"Creating path {pathNum}");
|
||||
|
|
@ -436,52 +261,72 @@ namespace SceneManager
|
|||
trafficEndPath.Enabled = false;
|
||||
}
|
||||
|
||||
private static void DrawWaypointMarker(Vector3 waypointPosition)
|
||||
private static void PathCreation_OnCheckboxChanged(UIMenu sender, UIMenuCheckboxItem checkboxItem, bool @checked)
|
||||
{
|
||||
if (SettingsMenu.threeDWaypoints.Checked && collectorWaypoint.Checked)
|
||||
if(checkboxItem == collectorWaypoint)
|
||||
{
|
||||
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 (stopWaypointType.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);
|
||||
collectorRadius.Enabled = collectorWaypoint.Checked ? true : false;
|
||||
speedZoneRadius.Enabled = collectorWaypoint.Checked ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
private static Vector3 GetMousePositionInWorld()
|
||||
private static void PathCreation_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
|
||||
{
|
||||
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)
|
||||
if (selectedItem == trafficAddWaypoint)
|
||||
{
|
||||
Vector3 direction = GetPlayerLookingDirection(out start);
|
||||
end = start + (maxTraceDistance * direction);
|
||||
return World.TraceLine(start, end, flags);
|
||||
AddNewWaypoint();
|
||||
}
|
||||
|
||||
Vector3 GetPlayerLookingDirection(out Vector3 camPosition)
|
||||
if (selectedItem == trafficRemoveWaypoint)
|
||||
{
|
||||
if (Camera.RenderingCamera)
|
||||
{
|
||||
camPosition = Camera.RenderingCamera.Position;
|
||||
return Camera.RenderingCamera.Direction;
|
||||
RemoveWaypoint();
|
||||
}
|
||||
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();
|
||||
if (selectedItem == trafficEndPath)
|
||||
{
|
||||
EndPath();
|
||||
}
|
||||
}
|
||||
|
||||
return TracePlayerView(100f, TraceFlags.IntersectWorld).HitPosition;
|
||||
private static void PathCreation_OnScrollerChanged(UIMenu sender, UIMenuScrollerItem scrollerItem, int first, int last)
|
||||
{
|
||||
if (scrollerItem == collectorRadius)
|
||||
{
|
||||
if (collectorRadius.Value > speedZoneRadius.Value)
|
||||
{
|
||||
while (collectorRadius.Value > speedZoneRadius.Value)
|
||||
{
|
||||
speedZoneRadius.ScrollToNextOption();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scrollerItem == speedZoneRadius)
|
||||
{
|
||||
if (speedZoneRadius.Value < collectorRadius.Value)
|
||||
{
|
||||
collectorRadius.Value = speedZoneRadius.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void PathCreation_OnMenuOpen(UIMenu menu)
|
||||
{
|
||||
var scrollerItems = new List<UIMenuScrollerItem> { collectorRadius, speedZoneRadius, waypointSpeed };
|
||||
var checkboxItems = new Dictionary<UIMenuCheckboxItem, RNUIMouseInputHandler.Function>()
|
||||
{
|
||||
{ collectorWaypoint, UpdateCollectorMenuOptionsStatus},
|
||||
{ stopWaypointType, null},
|
||||
{ directWaypointBehavior, null}
|
||||
};
|
||||
var selectItems = new Dictionary<UIMenuItem, RNUIMouseInputHandler.Function>()
|
||||
{
|
||||
{ trafficAddWaypoint, AddNewWaypoint },
|
||||
{ trafficRemoveWaypoint, RemoveWaypoint },
|
||||
{ trafficEndPath, EndPath }
|
||||
};
|
||||
|
||||
RNUIMouseInputHandler.Initialize(menu, scrollerItems, checkboxItems, selectItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ namespace SceneManager
|
|||
MenuManager.menuPool.Add(pathMainMenu);
|
||||
pathMainMenu.OnItemSelect += PathMenu_OnItemSelected;
|
||||
pathMainMenu.OnCheckboxChange += PathMenu_OnCheckboxChange;
|
||||
pathMainMenu.OnMenuOpen += PathMenu_OnMouseDown;
|
||||
pathMainMenu.OnMenuOpen += PathMenu_OnMenuOpen;
|
||||
}
|
||||
|
||||
internal static void BuildPathMenu()
|
||||
|
|
@ -90,6 +90,12 @@ namespace SceneManager
|
|||
}
|
||||
}
|
||||
|
||||
private static void GoToEditPathMenu()
|
||||
{
|
||||
pathMainMenu.Visible = false;
|
||||
EditPathMenu.editPathMenu.Visible = true;
|
||||
}
|
||||
|
||||
private static void GoToPathCreationMenu()
|
||||
{
|
||||
if (createNewPath.Text.Contains("Continue"))
|
||||
|
|
@ -103,7 +109,6 @@ namespace SceneManager
|
|||
PathCreationMenu.BuildPathCreationMenu();
|
||||
pathMainMenu.Visible = false;
|
||||
PathCreationMenu.pathCreationMenu.Visible = true;
|
||||
//Draw3DWaypointOnPlayer();
|
||||
|
||||
// For each element in paths, determine if the element exists but is not finished yet, or if it doesn't exist, create it.
|
||||
for (int i = 0; i <= paths.Count; i++)
|
||||
|
|
@ -413,157 +418,24 @@ namespace SceneManager
|
|||
}
|
||||
}
|
||||
|
||||
private static void PathMenu_OnMouseDown(UIMenu menu)
|
||||
private static void PathMenu_OnMenuOpen(UIMenu menu)
|
||||
{
|
||||
GameFiber.StartNew(() =>
|
||||
var scrollerItems = new List<UIMenuScrollerItem> { directOptions, directDriver, dismissDriver, editPath };
|
||||
var checkboxItems = new Dictionary<UIMenuCheckboxItem, RNUIMouseInputHandler.Function>()
|
||||
{
|
||||
while (menu.Visible)
|
||||
{
|
||||
var selectedScroller = menu.MenuItems.Where(x => (x == directOptions || x == directDriver || x == dismissDriver || x == editPath) && x.Selected).FirstOrDefault();
|
||||
if (selectedScroller != null)
|
||||
{
|
||||
HandleScrollerItemsWithMouseWheel(selectedScroller);
|
||||
}
|
||||
{ disableAllPaths, DisableAllPaths }
|
||||
};
|
||||
|
||||
// Add waypoint if menu item is selected and user left clicks
|
||||
if (Game.IsKeyDown(Keys.LButton))
|
||||
var selectItems = new Dictionary<UIMenuItem, RNUIMouseInputHandler.Function>()
|
||||
{
|
||||
OnCheckboxItemClicked();
|
||||
OnMenuItemClicked();
|
||||
}
|
||||
GameFiber.Yield();
|
||||
}
|
||||
});
|
||||
{ createNewPath, GoToPathCreationMenu },
|
||||
{ editPath, GoToEditPathMenu },
|
||||
{ deleteAllPaths, DeleteAllPaths },
|
||||
{ directDriver, DirectDriver },
|
||||
{ dismissDriver, DismissDriver }
|
||||
};
|
||||
|
||||
void OnCheckboxItemClicked()
|
||||
{
|
||||
if (disableAllPaths.Selected && disableAllPaths.Enabled)
|
||||
{
|
||||
disableAllPaths.Checked = !disableAllPaths.Checked;
|
||||
DisableAllPaths();
|
||||
}
|
||||
}
|
||||
|
||||
void OnMenuItemClicked()
|
||||
{
|
||||
if (createNewPath.Selected)
|
||||
{
|
||||
GoToPathCreationMenu();
|
||||
}
|
||||
else if (editPath.Selected)
|
||||
{
|
||||
menu.Visible = false;
|
||||
EditPathMenu.editPathMenu.Visible = true;
|
||||
}
|
||||
else if (deleteAllPaths.Selected)
|
||||
{
|
||||
DeleteAllPaths();
|
||||
}
|
||||
else if (directDriver.Selected)
|
||||
{
|
||||
DirectDriver();
|
||||
}
|
||||
else if (dismissDriver.Selected)
|
||||
{
|
||||
DismissDriver();
|
||||
}
|
||||
}
|
||||
|
||||
void HandleScrollerItemsWithMouseWheel(UIMenuItem selectedScroller)
|
||||
{
|
||||
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();
|
||||
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)
|
||||
{
|
||||
if (selectedScroller == editPath)
|
||||
{
|
||||
editPath.ScrollToNextOption();
|
||||
}
|
||||
else if (selectedScroller == directOptions)
|
||||
{
|
||||
directOptions.ScrollToNextOption();
|
||||
}
|
||||
else if (selectedScroller == directDriver)
|
||||
{
|
||||
directDriver.ScrollToNextOption();
|
||||
}
|
||||
else if (selectedScroller == dismissDriver)
|
||||
{
|
||||
dismissDriver.ScrollToNextOption();
|
||||
}
|
||||
}
|
||||
else if (Game.GetMouseWheelDelta() < 0)
|
||||
{
|
||||
if (selectedScroller == editPath)
|
||||
{
|
||||
editPath.ScrollToPreviousOption();
|
||||
}
|
||||
else if (selectedScroller == directOptions)
|
||||
{
|
||||
directOptions.ScrollToPreviousOption();
|
||||
}
|
||||
else if (selectedScroller == directDriver)
|
||||
{
|
||||
directDriver.ScrollToPreviousOption();
|
||||
}
|
||||
else if (selectedScroller == dismissDriver)
|
||||
{
|
||||
dismissDriver.ScrollToPreviousOption();
|
||||
RNUIMouseInputHandler.Initialize(menu, scrollerItems, checkboxItems, selectItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//private static void Draw3DWaypointOnPlayer()
|
||||
//{
|
||||
// GameFiber.StartNew(() =>
|
||||
// {
|
||||
// while (SettingsMenu.threeDWaypoints.Checked)
|
||||
// {
|
||||
// if (PathCreationMenu.pathCreationMenu.Visible)
|
||||
// {
|
||||
// if (PathCreationMenu.collectorWaypoint.Checked)
|
||||
// {
|
||||
// Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 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, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 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.stopWaypointType.Checked)
|
||||
// {
|
||||
// Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 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, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 65, 255, 65, 80, false, false, 2, false, 0, 0, false);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
// GameFiber.Yield();
|
||||
// }
|
||||
// });
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using RAGENativeUI;
|
||||
using RAGENativeUI.Elements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
|
@ -24,7 +25,7 @@ namespace SceneManager
|
|||
settingsMenu.OnCheckboxChange += SettingsMenu_OnCheckboxChange;
|
||||
settingsMenu.OnScrollerChange += SettingsMenu_OnScrollerChange;
|
||||
settingsMenu.OnItemSelect += SettingsMenu_OnItemSelected;
|
||||
settingsMenu.OnMenuOpen += SettingsMenu_OnMouseDown;
|
||||
settingsMenu.OnMenuOpen += SettingsMenu_OnMenuOpen;
|
||||
}
|
||||
|
||||
internal static void BuildSettingsMenu()
|
||||
|
|
@ -38,7 +39,7 @@ namespace SceneManager
|
|||
saveSettings.ForeColor = System.Drawing.Color.Gold;
|
||||
}
|
||||
|
||||
internal static void ToggleMapBlips()
|
||||
private static void ToggleMapBlips()
|
||||
{
|
||||
if (mapBlips.Checked)
|
||||
{
|
||||
|
|
@ -62,6 +63,17 @@ namespace SceneManager
|
|||
}
|
||||
}
|
||||
|
||||
private static void ToggleHints()
|
||||
{
|
||||
Hints.Enabled = hints.Checked ? true : false;
|
||||
}
|
||||
|
||||
private static void ToggleSettings()
|
||||
{
|
||||
Settings.UpdateSettings(threeDWaypoints.Checked, mapBlips.Checked, hints.Checked, speedUnits.SelectedItem);
|
||||
Game.DisplayHelp($"Scene Manager settings saved");
|
||||
}
|
||||
|
||||
private static void SettingsMenu_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
|
||||
{
|
||||
if(selectedItem == saveSettings)
|
||||
|
|
@ -94,99 +106,21 @@ namespace SceneManager
|
|||
}
|
||||
}
|
||||
|
||||
private static void SettingsMenu_OnMouseDown(UIMenu menu)
|
||||
private static void SettingsMenu_OnMenuOpen(UIMenu menu)
|
||||
{
|
||||
GameFiber.StartNew(() =>
|
||||
var scrollerItems = new List<UIMenuScrollerItem> { speedUnits };
|
||||
var checkboxItems = new Dictionary<UIMenuCheckboxItem, RNUIMouseInputHandler.Function>()
|
||||
{
|
||||
while (menu.Visible)
|
||||
{ threeDWaypoints, null},
|
||||
{ mapBlips, ToggleMapBlips},
|
||||
{ hints, ToggleHints}
|
||||
};
|
||||
var selectItems = new Dictionary<UIMenuItem, RNUIMouseInputHandler.Function>()
|
||||
{
|
||||
var selectedScroller = menu.MenuItems.Where(x => x == speedUnits && x.Selected).FirstOrDefault();
|
||||
if (selectedScroller != null)
|
||||
{
|
||||
HandleScrollerItemsWithMouseWheel(selectedScroller);
|
||||
}
|
||||
{ saveSettings, ToggleSettings }
|
||||
};
|
||||
|
||||
// Add waypoint if menu item is selected and user left clicks
|
||||
if (Game.IsKeyDown(Keys.LButton))
|
||||
{
|
||||
OnCheckboxItemClicked();
|
||||
OnMenuItemClicked();
|
||||
}
|
||||
GameFiber.Yield();
|
||||
}
|
||||
});
|
||||
|
||||
void OnCheckboxItemClicked()
|
||||
{
|
||||
if (threeDWaypoints.Selected && threeDWaypoints.Enabled)
|
||||
{
|
||||
threeDWaypoints.Checked = !threeDWaypoints.Checked;
|
||||
}
|
||||
else if (mapBlips.Selected)
|
||||
{
|
||||
mapBlips.Checked = !mapBlips.Checked;
|
||||
ToggleMapBlips();
|
||||
}
|
||||
else if (hints.Selected)
|
||||
{
|
||||
hints.Checked = !hints.Checked;
|
||||
Hints.Enabled = hints.Checked ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
void OnMenuItemClicked()
|
||||
{
|
||||
if (saveSettings.Selected)
|
||||
{
|
||||
Settings.UpdateSettings(threeDWaypoints.Checked, mapBlips.Checked, hints.Checked, speedUnits.SelectedItem);
|
||||
Game.DisplayHelp($"Scene Manager settings saved");
|
||||
}
|
||||
}
|
||||
|
||||
void HandleScrollerItemsWithMouseWheel(UIMenuItem selectedScroller)
|
||||
{
|
||||
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();
|
||||
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)
|
||||
{
|
||||
if (selectedScroller == speedUnits)
|
||||
{
|
||||
speedUnits.ScrollToNextOption();
|
||||
PathCreationMenu.pathCreationMenu.Clear();
|
||||
PathCreationMenu.BuildPathCreationMenu();
|
||||
}
|
||||
}
|
||||
else if (Game.GetMouseWheelDelta() < 0)
|
||||
{
|
||||
if (selectedScroller == speedUnits)
|
||||
{
|
||||
speedUnits.ScrollToPreviousOption();
|
||||
PathCreationMenu.pathCreationMenu.Clear();
|
||||
PathCreationMenu.BuildPathCreationMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
RNUIMouseInputHandler.Initialize(menu, scrollerItems, checkboxItems, selectItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue