mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-17 14:06:02 +01:00
Fix duplicate functions and typos
This commit is contained in:
@@ -1,171 +1,3 @@
|
||||
--[[
|
||||
Instructional Buttons & Debug Text Module
|
||||
-------------------------------------------
|
||||
This module provides functions for:
|
||||
• Displaying instructional buttons on-screen via a scaleform movie.
|
||||
• Drawing debug text with a background rectangle when debugMode is enabled.
|
||||
• Rendering 3D text in the world.
|
||||
• Displaying help messages and spinners.
|
||||
]]
|
||||
|
||||
-------------------------------------------------------------
|
||||
-- Instructional Buttons Functionality
|
||||
-------------------------------------------------------------
|
||||
|
||||
--- Loads and draws instructional buttons on-screen using a scaleform movie.
|
||||
---
|
||||
--- Requests the "instructional_buttons" scaleform, clears previous data, sets clear space,
|
||||
--- creates data slots for each button option provided in `info`, and then draws the scaleform fullscreen.
|
||||
---
|
||||
--- @param info table An array of tables, where each table represents a button option:
|
||||
--- - keys (table): An array of key codes (e.g., {38, 29}) to display.
|
||||
--- - text (string): The label for the button.
|
||||
---
|
||||
--- @usage
|
||||
--- ```lua
|
||||
---CreateThread(function()
|
||||
--- while true do
|
||||
--- makeInstructionalButtons({
|
||||
--- { keys = {38, 29}, text = "Open Menu" },
|
||||
--- { keys = {45}, text = "Close Menu" }
|
||||
--- })
|
||||
--- Wait(0)
|
||||
--- end
|
||||
---end)
|
||||
--- ```
|
||||
function makeInstructionalButtons(info)
|
||||
local build = RequestScaleformMovie("instructional_buttons")
|
||||
while not HasScaleformMovieLoaded(build) do Wait(0) end
|
||||
|
||||
-- Draw the scaleform fullscreen (initial draw).
|
||||
DrawScaleformMovieFullscreen(build, 255, 255, 255, 0, 0)
|
||||
|
||||
-- Clear previous instructions.
|
||||
BeginScaleformMovieMethod(build, "CLEAR_ALL")
|
||||
EndScaleformMovieMethod()
|
||||
|
||||
-- Set clear spacing between buttons.
|
||||
BeginScaleformMovieMethod(build, "SET_CLEAR_SPACE")
|
||||
ScaleformMovieMethodAddParamInt(200)
|
||||
EndScaleformMovieMethod()
|
||||
|
||||
-- Add each button option to the scaleform.
|
||||
for i = 1, #info do
|
||||
BeginScaleformMovieMethod(build, "SET_DATA_SLOT")
|
||||
ScaleformMovieMethodAddParamInt(i - 1)
|
||||
for k = 1, #info[i].keys do
|
||||
ScaleformMovieMethodAddParamPlayerNameString(GetControlInstructionalButton(2, info[i].keys[k], true))
|
||||
end
|
||||
BeginTextCommandScaleformString("STRING")
|
||||
AddTextComponentSubstringKeyboardDisplay(info[i].text)
|
||||
EndTextCommandScaleformString()
|
||||
EndScaleformMovieMethod()
|
||||
end
|
||||
|
||||
-- Draw the instructional buttons.
|
||||
BeginScaleformMovieMethod(build, "DRAW_INSTRUCTIONAL_BUTTONS")
|
||||
EndScaleformMovieMethod()
|
||||
|
||||
-- Set a translucent black background.
|
||||
BeginScaleformMovieMethod(build, "SET_BACKGROUND_COLOUR")
|
||||
ScaleformMovieMethodAddParamInt(0)
|
||||
ScaleformMovieMethodAddParamInt(0)
|
||||
ScaleformMovieMethodAddParamInt(0)
|
||||
ScaleformMovieMethodAddParamInt(80)
|
||||
EndScaleformMovieMethod()
|
||||
|
||||
-- Final full-screen draw with full opacity.
|
||||
DrawScaleformMovieFullscreen(build, 255, 255, 255, 255, 0)
|
||||
end
|
||||
|
||||
-- EXPERIMENTAL --
|
||||
-- RedM Button Prompts --
|
||||
-- Creates the promot, then shows it, this needs to be run in a loop
|
||||
local promptGroups = {}
|
||||
|
||||
function makeRedInstructionalButtons(info, title)
|
||||
if not promptGroups[title] then -- Create group if not exists
|
||||
promptGroups[title] = {
|
||||
title = CreateVarString(10, 'LITERAL_STRING', title),
|
||||
id = GetRandomIntInRange(0, 0xffffff),
|
||||
prompts = {},
|
||||
}
|
||||
for i = 1, #info do
|
||||
promptGroups[title].prompts[i] = {
|
||||
keys = info[i].keys,
|
||||
text = info[i].text,
|
||||
}
|
||||
local keyTitle = CreateVarString(10, 'LITERAL_STRING', info[i].text)
|
||||
-- Create one prompt per entry
|
||||
local promptSet = UiPromptRegisterBegin()
|
||||
-- Register all keys for this prompt
|
||||
for k = 1, #info[i].keys do
|
||||
PromptSetControlAction(promptSet, info[i].keys[k])
|
||||
end
|
||||
PromptSetText(promptSet, keyTitle)
|
||||
PromptSetEnabled(promptSet, true)
|
||||
PromptSetVisible(promptSet, true)
|
||||
PromptSetGroup(promptSet, promptGroups[title].id)
|
||||
PromptRegisterEnd(promptSet)
|
||||
end
|
||||
end
|
||||
PromptSetActiveGroupThisFrame(promptGroups[title].id, promptGroups[title].title)
|
||||
end
|
||||
|
||||
onResourceStop(function()
|
||||
for k, v in pairs(promptGroups) do
|
||||
print("^5GTAUI^7: ^2Removing Prompt Group^7: ^3" .. k .. "^7")
|
||||
PromptDelete(promptGroups[k].id, 1)
|
||||
end
|
||||
end, true)
|
||||
|
||||
-------------------------------------------------------------
|
||||
-- Debug Text Display Functionality
|
||||
-------------------------------------------------------------
|
||||
|
||||
--- Draws debug text on the screen if debugMode is enabled.
|
||||
---
|
||||
--- Calculates a background rectangle based on the number of text lines and renders each line on-screen.
|
||||
---
|
||||
--- @param textTable table An array of strings to display.
|
||||
--- @param loc vector2 (Optional) Top-left coordinate for the text box (default: vec2(0.05, 0.65)).
|
||||
---
|
||||
--- @usage
|
||||
--- ```lua
|
||||
---CreateThread(function()
|
||||
--- while true do
|
||||
--- debugScaleForm(
|
||||
--- {
|
||||
--- "Line 1: Debug info",
|
||||
--- "Line 2: More info"
|
||||
--- }
|
||||
--- )
|
||||
--- Wait(0)
|
||||
--- end
|
||||
---end)
|
||||
--- ```
|
||||
function debugScaleForm(textTable, loc)
|
||||
if debugMode then
|
||||
loc = loc or vec2(0.05, 0.65)
|
||||
|
||||
local lineHeight = 0.025 -- Height per line.
|
||||
local totalHeight = #textTable * lineHeight
|
||||
local boxPadding = 0.01 -- Padding around the text.
|
||||
local size = vec2(0.18, totalHeight + boxPadding * 2)
|
||||
|
||||
-- Draw background rectangle.
|
||||
DrawRect(loc.x + size.x / 2, loc.y + size.y / 2, size.x, size.y, 0, 0, 0, 255)
|
||||
|
||||
-- Render each line of text.
|
||||
for i = 1, #textTable do
|
||||
SetTextScale(0.30, 0.30)
|
||||
BeginTextCommandDisplayText("STRING")
|
||||
AddTextComponentSubstringKeyboardDisplay(textTable[i])
|
||||
EndTextCommandDisplayText(loc.x + 0.005, loc.y + (i - 1) * lineHeight + 0.01)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------
|
||||
-- 3D Text Rendering
|
||||
-------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user