private static void PopulateSpecificLocation(string path, params JsonConverter[] converters) { if (Path.GetExtension(path).ToLowerInvariant() != ".json") { Notification.Show($"~o~Warning~s~: Non JSON file found in the Locations Directory! ({Path.GetFileName(path)})"); return; } try { string contents = File.ReadAllText(path); Location location = JsonConvert.DeserializeObject <Location>(contents, converters); if (location.Interior.HasValue) { if (Function.Call <int>(Hash.GET_INTERIOR_AT_COORDS, location.Interior.Value.X, location.Interior.Value.Y, location.Interior.Value.Z) == 0) { Notification.Show($"~o~Warning~s~: Interior of {location.Name} is not available! Maybe you forgot to install it?"); return; } } if (!location.PedInfo.Model.IsPed) { Notification.Show($"~o~Warning~s~: Model {location.PedInfo.Model} for Location {location.Name} is not a Ped!"); return; } ScaledTexture texture = null; if (!string.IsNullOrWhiteSpace(location.BannerTXD) && !string.IsNullOrWhiteSpace(location.BannerTexture)) { texture = new ScaledTexture(PointF.Empty, new SizeF(0, 108), location.BannerTXD, location.BannerTexture); } Menu menu = new Menu(location, texture); FoodShops.Pool.Add(menu); location.Menu = menu; location.RecreatePed(); if (FoodShops.Config.ShowBlips) { location.Blip = World.CreateBlip(location.Trigger); location.Blip.Sprite = BlipSprite.Store; location.Blip.Color = BlipColor.NetPlayer3; location.Blip.Name = $"Food Shop: {location.Name}"; location.Blip.IsShortRange = true; } locations.Add(location); } catch (Exception ex) { Notification.Show($"~o~Warning~s~: Unable to load Location {Path.GetFileName(path)}:\n{ex.Message}"); } }
/// <summary> /// Creates a new item that can be sliden. /// </summary> /// <param name="title">The title of the Item.</param> /// <param name="subtitle">The subtitle of the Item.</param> public NativeSlidableItem(string title, string subtitle) : base(title, subtitle) { arrowLeft = new ScaledTexture(PointF.Empty, SizeF.Empty, "commonmenu", "arrowleft") { Color = NativeMenu.colorBlack }; arrowRight = new ScaledTexture(PointF.Empty, SizeF.Empty, "commonmenu", "arrowright") { Color = NativeMenu.colorBlack }; }
private static unsafe void SetDataPurge <T>( XTexture2D texture, XRectangle?rect, ReadOnlySpan <T> data, int startIndex, int elementCount, bool animated ) where T : unmanaged { TextureCache.Remove(texture); if (!ManagedSpriteInstance.Validate(texture, clean: true)) { return; } if (texture.Format.IsBlock()) { ManagedSpriteInstance.FullPurge(texture, animated: animated); return; } #if ASYNC_SETDATA var byteData = Cacheable(texture) ? GetByteArray(data, startIndex, elementCount, out int elementSize) : null; ThreadQueue.Queue((data) => Thread.CurrentThread.Priority = ThreadPriority.BelowNormal; ScaledTexture.Purge( reference: texture, bounds: rect, data: new DataRef <byte>( data: data, offset: startIndex * elementSize, length: elementCount * elementSize ) ), byteData); #else var byteData = Cacheable(texture) ? data : default; var span = byteData.IsEmpty ? default : byteData.Slice(startIndex, elementCount).AsBytes(); ManagedSpriteInstance.Purge( reference: texture, bounds: rect, data: new(span), animated: animated ); #endif }
public Menu(Location location, ScaledTexture banner) : base("", location.Name, "", banner) { Location = location; //NoItemsText = "This Shop does not has any food or drinks to be purchased."; foreach (ShopMenu menu in location.Menus) { foreach (Meal meal in menu.Meals) { Add(new Item(meal)); } } Shown += PurchaseMenu_Shown; Closing += PurchaseMenu_Closing; Closed += PurchaseMenu_Closed; }
private static void OnSetDataPost <T> (Texture2D __instance, int level, Rectangle?rect, T[] data, int startIndex, int elementCount) where T : unmanaged { if (__instance is ManagedTexture2D) { return; } if (!ScaledTexture.Validate(__instance)) { return; } var dataRef = DataRef <byte> .Null; if (__instance.LevelCount <= 1) { dataRef = new DataRef <byte>((byte[])new Span <T>(data).As <byte>().ToArray().Clone(), startIndex, elementCount); } ScaledTexture.Purge(__instance, rect, dataRef); }
private static void OnSetDataPost <T> (Texture2D __instance, T[] data) where T : unmanaged { if (__instance is ManagedTexture2D) { return; } if (!ScaledTexture.Validate(__instance)) { return; } var dataRef = DataRef <byte> .Null; if (__instance.LevelCount <= 1) { dataRef = (byte[])new Span <T>(data).As <byte>().ToArray().Clone(); } ScaledTexture.Purge(__instance, null, dataRef); }
private static void SetDataPurge <T>(Texture2D texture, Rectangle?rect, T[] data, int startIndex, int elementCount) where T : struct { if (texture is ManagedTexture2D) { return; } if (!ScaledTexture.Validate(texture)) { return; } int elementSize = 0; var byteData = Cacheable(texture) ? GetByteArray(data, out elementSize) : null; #if ASYNC_SETDATA ThreadQueue.Queue((data) => Thread.CurrentThread.Priority = ThreadPriority.BelowNormal; ScaledTexture.Purge( reference: texture, bounds: rect, data: new DataRef <byte>( data: data, offset: startIndex * elementSize, length: elementCount * elementSize ) ), byteData); #else ScaledTexture.Purge( reference: texture, bounds: rect, data: new DataRef <byte>( data: byteData, offset: startIndex * elementSize, length: elementCount * elementSize ) ); #endif }
internal static string SafeName(this ScaledTexture texture) { return(texture.Name.IsBlank() ? "Unknown" : texture.Name.Replace("\\", "/")); }