Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
C# / Lua: Added MinimapOverlays class with examples.
- Loading branch information
Showing
4 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| using CitizenFX.Core; | ||
| using static CitizenFX.Core.Native.API; | ||
|
|
||
| namespace ScaleformUI.Scaleforms | ||
| { | ||
| public static class MinimapOverlays | ||
| { | ||
| internal static Dictionary<int, KeyValuePair<string, string>> minimaps = new(); | ||
| internal static int overlay = 0; | ||
|
|
||
| private static async Task Load() | ||
| { | ||
| overlay = AddMinimapOverlay("MINIMAP_LOADER.gfx"); | ||
| while (!HasMinimapOverlayLoaded(overlay)) await BaseScript.Delay(0); | ||
| SetMinimapOverlayDisplay(overlay, 0f, 0f, 100f, 100f, 100f); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds a custom minimap in any place of the map specified | ||
| /// </summary> | ||
| /// <param name="textureDict">The texture dictionary</param> | ||
| /// <param name="textureName">The texture name</param> | ||
| /// <param name="x">X position</param> | ||
| /// <param name="y">Y Position</param> | ||
| /// <returns>The overlay ID in Dictionary</returns> | ||
| public static async Task<int> AddOverlayToMinimap(string textureDict, string textureName, float x, float y, float width = -1, float height = -1, int alpha = -1, bool centered = false) | ||
| { | ||
| if (overlay == 0) await Load(); | ||
|
|
||
| if (!HasStreamedTextureDictLoaded(textureDict)) | ||
| { | ||
| RequestStreamedTextureDict(textureDict, false); | ||
| while (!HasStreamedTextureDictLoaded(textureDict)) await BaseScript.Delay(0); | ||
| } | ||
|
|
||
| CallMinimapScaleformFunction(overlay, "ADD_OVERLAY"); | ||
| ScaleformMovieMethodAddParamTextureNameString(textureDict); | ||
| ScaleformMovieMethodAddParamTextureNameString(textureName); | ||
| ScaleformMovieMethodAddParamFloat(x); | ||
| ScaleformMovieMethodAddParamFloat(y); | ||
| ScaleformMovieMethodAddParamFloat(width); | ||
| ScaleformMovieMethodAddParamFloat(height); | ||
| ScaleformMovieMethodAddParamInt(alpha); | ||
| ScaleformMovieMethodAddParamBool(centered); | ||
| EndScaleformMovieMethod(); | ||
|
|
||
| SetStreamedTextureDictAsNoLongerNeeded(textureDict); | ||
|
|
||
| minimaps.Add(minimaps.Count + 1, new(textureDict, textureName)); | ||
| return minimaps.Count; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Remove an overlay from the ingame Map | ||
| /// </summary> | ||
| /// <param name="overlayId">Id of the overlay to remove</param> | ||
| public static async void RemoveOverlayFromMinimap(int overlayId) | ||
| { | ||
| if (overlay == 0) await Load(); | ||
| CallMinimapScaleformFunction(overlay, "REM_OVERLAY"); | ||
| ScaleformMovieMethodAddParamInt(overlayId); | ||
| EndScaleformMovieMethod(); | ||
| minimaps.Remove(minimaps.Keys.ToList()[overlayId]); | ||
| } | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
ScaleformUI_Lua/src/scaleforms/Minimap/MinimapOverlays.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| MinimapOverlays = setmetatable({ | ||
| overlay = 0, | ||
| minimaps = {}, | ||
| }, MinimapOverlays) | ||
| MinimapOverlays.__index = MinimapOverlays | ||
| MinimapOverlays.__call = function() | ||
| return "MinimapOverlays" | ||
| end | ||
|
|
||
| function MinimapOverlays:Load() | ||
| self.overlay = AddMinimapOverlay("MINIMAP_LOADER.gfx") | ||
| while not HasMinimapOverlayLoaded(self.overlay) do Citizen.Wait(0) end | ||
| SetMinimapOverlayDisplay(self.overlay, 0.0, 0.0, 100.0, 100.0, 100.0) | ||
| end | ||
|
|
||
| function MinimapOverlays:AddOverlayToMinimap(textureDict, textureName, x, y, width, height, alpha, centered) | ||
| if self.overlay == 0 then self:Load() end | ||
| if width == nil then width = -1 end | ||
| if height == nil then height = -1 end | ||
| if alpha == nil then alpha = -1 end | ||
| if centered == nil then centered = false end | ||
|
|
||
| if not HasStreamedTextureDictLoaded(textureDict) then | ||
| RequestStreamedTextureDict(textureDict, false) | ||
| while not HasStreamedTextureDictLoaded(textureDict) do Citizen.Wait(0) end | ||
| end | ||
|
|
||
| CallMinimapScaleformFunction(self.overlay, "ADD_OVERLAY") | ||
| ScaleformMovieMethodAddParamTextureNameString(textureDict) | ||
| ScaleformMovieMethodAddParamTextureNameString(textureName) | ||
| ScaleformMovieMethodAddParamFloat(x) | ||
| ScaleformMovieMethodAddParamFloat(y) | ||
| ScaleformMovieMethodAddParamFloat(width) | ||
| ScaleformMovieMethodAddParamFloat(height) | ||
| ScaleformMovieMethodAddParamInt(alpha) | ||
| ScaleformMovieMethodAddParamBool(centered) | ||
| EndScaleformMovieMethod() | ||
|
|
||
| SetStreamedTextureDictAsNoLongerNeeded(textureDict) | ||
|
|
||
| table.insert(self.minimaps, {id = #self.minimaps + 1, txd = textureDict, txn = textureName}) | ||
| return #self.minimaps | ||
| end | ||
|
|
||
| function MinimapOverlays:RemoveOverlayFromMinimap(overlayId) | ||
| if overlayId == nil then return end | ||
| if self.overlay == 0 then self:Load() end | ||
| CallMinimapScaleformFunction(self.overlay, "REM_OVERLAY"); | ||
| ScaleformMovieMethodAddParamInt(overlayId) | ||
| EndScaleformMovieMethod() | ||
| for k,v in pairs(self.minimaps) do | ||
| if k == overlayId then | ||
| table.remove(k) | ||
| end | ||
| end | ||
| end |