Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
C# / Lua: Added MinimapOverlays class with examples.
  • Loading branch information
manups4e committed Aug 4, 2023
1 parent c3f21a8 commit e0b4518
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 1 deletion.
14 changes: 13 additions & 1 deletion MenuExample/MenuExample.cs
Expand Up @@ -1585,6 +1585,19 @@ public MenuExample()
if (Game.IsControlJustPressed(0, Control.SelectCharacterTrevor) && !MenuHandler.IsAnyMenuOpen && !MenuHandler.IsAnyPauseMenuOpen)
LobbyPauseMenuShowcase(null);
if (Game.IsControlJustPressed(0, Control.Detonate))
{
long _wallp = API.CreateDui("https://images8.alphacoders.com/131/1318148.png", 1952, 1120);
API.CreateRuntimeTextureFromDuiHandle(txd, "wallp", API.GetDuiHandle(_wallp));
int overlay1 = await MinimapOverlays.AddOverlayToMinimap("scaleformui", "bannerbackground", 365, -422);
World.CreateBlip(new Vector3(365, -422, 45));
int overlay2 = await MinimapOverlays.AddOverlayToMinimap("scaleformui", "wallp", 2000, 1000);
}
if (Game.IsControlJustPressed(0, (Control)170)) // F3
{
if (ScaleformUI.Main.JobMissionSelection.Enabled)
Expand Down Expand Up @@ -1680,7 +1693,6 @@ public MenuExample()
await Delay(1000);
ScaleformUI.Main.JobMissionSelection.ShowPlayerVote(2, "PlayerName", HudColor.HUD_COLOUR_GREEN, true, true);
}
if (Game.IsControlJustPressed(0, Control.DropWeapon)) // F9
{
feedOpen = !feedOpen;
Expand Down
66 changes: 66 additions & 0 deletions ScaleformUI_Csharp/Scaleforms/Minimap/Minimap.cs
@@ -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]);
}
}
}
1 change: 1 addition & 0 deletions ScaleformUI_Lua/src/ScaleformUI/mainScaleform.lua
Expand Up @@ -13,6 +13,7 @@ ScaleformUI.Scaleforms.RankbarHandler = RankbarHandler --[[@type RankbarHandler]
ScaleformUI.Scaleforms.CountdownHandler = CountdownHandler --[[@type CountdownHandler]] -- countdown
ScaleformUI.Notifications = Notifications
ScaleformUI.Scaleforms.BigFeed = BigFeedInstance
ScaleformUI.Scaleforms.MinimapOverlays = MinimapOverlays
ScaleformUI.WaitTime = 850

ScaleformUI.Scaleforms._pauseMenu = nil
Expand Down
56 changes: 56 additions & 0 deletions ScaleformUI_Lua/src/scaleforms/Minimap/MinimapOverlays.lua
@@ -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

0 comments on commit e0b4518

Please sign in to comment.