1
Fork 0
mirror of https://github.com/thegeneralist01/Scene-Manager-DevRepo synced 2026-01-11 15:40:29 +01:00

Added GetTextWidth and GetSelectedItemTextWidth methods

This commit is contained in:
Rich Dunne 2021-07-07 07:28:58 -06:00
parent 1fe9a61d0e
commit bed387ae9a

View file

@ -1,4 +1,5 @@
using Rage; using Rage;
using RAGENativeUI.Elements;
using SceneManager.Managers; using SceneManager.Managers;
using SceneManager.Paths; using SceneManager.Paths;
using SceneManager.Waypoints; using SceneManager.Waypoints;
@ -163,16 +164,24 @@ namespace SceneManager.Utils
if (!vehicle.HasDriver) if (!vehicle.HasDriver)
{ {
vehicle.CreateRandomDriver(); vehicle.CreateRandomDriver();
while (vehicle && !vehicle.HasDriver) GameFiber.Yield();
{ //while (vehicle && !vehicle.HasDriver)
GameFiber.Yield(); //{
} // Game.LogTrivial($"Trying to create new driver");
if(!vehicle || !vehicle.Driver) // GameFiber.Yield();
//}
if(!vehicle)
{ {
return false; return false;
} }
if(!vehicle.Driver)
{
Game.LogTrivial($"Unable to create a new driver");
vehicle.Delete();
return false;
}
Game.LogTrivial($"Vehicle has a new driver"); Game.LogTrivial($"Vehicle has a new driver");
vehicle.Driver.IsPersistent = true; //vehicle.Driver.IsPersistent = true;
vehicle.Driver.BlockPermanentEvents = true; vehicle.Driver.BlockPermanentEvents = true;
} }
return true; return true;
@ -182,5 +191,28 @@ namespace SceneManager.Utils
return false; return false;
} }
} }
internal static float GetTextWidth(this UIMenuItem menuItem)
{
menuItem.TextStyle.Apply();
Rage.Native.NativeFunction.Natives.x54CE8AC98E120CAB("STRING"); // _BEGIN_TEXT_COMMAND_GET_WIDTH
Rage.Native.NativeFunction.Natives.ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(menuItem.Text);
return Rage.Native.NativeFunction.Natives.x85F061DA64ED2F67<float>(true); // _END_TEXT_COMMAND_GET_WIDTH
}
internal static float GetSelectedItemTextWidth(this UIMenuListScrollerItem<string> scrollerItem)
{
if (scrollerItem.OptionCount == 0)
{
return 0;
}
scrollerItem.GetTextWidth();
scrollerItem.TextStyle.Apply();
Rage.Native.NativeFunction.Natives.x54CE8AC98E120CAB("STRING"); // _BEGIN_TEXT_COMMAND_GET_WIDTH
Rage.Native.NativeFunction.Natives.ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(scrollerItem.SelectedItem);
return Rage.Native.NativeFunction.Natives.x85F061DA64ED2F67<float>(true); // _END_TEXT_COMMAND_GET_WIDTH
}
} }
} }