From 6b660d80842550cf00425bad9104386f5bc74a1d Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Wed, 14 May 2025 04:48:23 -0400 Subject: [PATCH 1/5] feat: GetPlayerJobData return { jobName = jobData.name, jobLabel = jobData.label, gradeName = jobData.grade_name, gradeLabel = jobData.grade_label, gradeRank = jobData.grade, boss = isBoss, onDuty = jobData.onduty, } --- modules/framework/es_extended/client.lua | 19 +++++++++++++++- modules/framework/es_extended/server.lua | 21 +++++++++++++++++- modules/framework/qb-core/client.lua | 18 ++++++++++++++- modules/framework/qb-core/server.lua | 28 +++++++++++++++++++----- modules/framework/qbx_core/client.lua | 21 ++++++++++++++++++ modules/framework/qbx_core/server.lua | 25 ++++++++++++++++++--- 6 files changed, 121 insertions(+), 11 deletions(-) diff --git a/modules/framework/es_extended/client.lua b/modules/framework/es_extended/client.lua index d57c230..e2838a9 100644 --- a/modules/framework/es_extended/client.lua +++ b/modules/framework/es_extended/client.lua @@ -76,7 +76,7 @@ Framework.GetPlayerName = function() return playerData.firstName, playerData.lastName end ----This will return the players job name, job label, job grade label and job grade level +---Depricated : This will return the players job name, job label, job grade label and job grade level ---@return string ---@return string ---@return string @@ -86,6 +86,23 @@ Framework.GetPlayerJob = function() return playerData.job.name, playerData.job.label, playerData.job.grade_label, playerData.job.grade end +---This will return the players job name, job label, job grade label job grade level, boss status, and duty status in a table +---@return table +Framework.GetPlayerJobData = function() + local playerData = Framework.GetPlayerData() + local jobData = playerData.job + local isBoss = (jobData.grade_name == "boss") + return { + jobName = jobData.name, + jobLabel = jobData.label, + gradeName = jobData.grade_name, + gradeLabel = jobData.grade_label, + gradeRank = jobData.grade, + boss = isBoss, + onDuty = jobData.onduty, + } +end + ---This will return a boolean if the player has the item in their inventory ---@param item string ---@return boolean diff --git a/modules/framework/es_extended/server.lua b/modules/framework/es_extended/server.lua index 83fee38..780b20f 100644 --- a/modules/framework/es_extended/server.lua +++ b/modules/framework/es_extended/server.lua @@ -198,7 +198,7 @@ Framework.GetPlayerPhone = function(src) end ----Returns the job name, label, grade name, and grade level of the player. +---Depricated: Returns the job name, label, grade name, and grade level of the player. ---@param src number ---@return string | nil ---@return string | nil @@ -211,6 +211,25 @@ Framework.GetPlayerJob = function(src) return job.name, job.label, job.grade_label, job.grade end +---This will return the players job name, job label, job grade label job grade level, boss status, and duty status in a table +---@param src number +---@return table | nil +Framework.GetPlayerJobData = function(src) + local xPlayer = Framework.GetPlayer(src) + if not xPlayer then return end + local job = xPlayer.getJob() + local isBoss = (job.grade_name == "boss") + return { + jobName = job.name, + jobLabel = job.label, + gradeName = job.grade_name, + gradeLabel = job.grade_label, + gradeRank = job.grade, + boss = isBoss, + onDuty = job.onduty, + } +end + ---Returns the players duty status. ---@param src number ---@return boolean diff --git a/modules/framework/qb-core/client.lua b/modules/framework/qb-core/client.lua index 1daa075..8686657 100644 --- a/modules/framework/qb-core/client.lua +++ b/modules/framework/qb-core/client.lua @@ -91,7 +91,7 @@ Framework.GetPlayerName = function() return playerData.charinfo.firstname, playerData.charinfo.lastname end ----This will return the players job name, job label, job grade name and job grade level. +---Depricated : This will return the players job name, job label, job grade label and job grade level ---@return string ---@return string ---@return string @@ -101,6 +101,22 @@ Framework.GetPlayerJob = function() return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level end +---This will return the players job name, job label, job grade label job grade level, boss status, and duty status in a table +---@return table +Framework.GetPlayerJobData = function() + local playerData = Framework.GetPlayerData() + local jobData = playerData.job + return { + jobName = jobData.name, + jobLabel = jobData.label, + gradeName = jobData.grade.name, + gradeLabel = jobData.grade.name, + gradeRank = jobData.grade.level, + boss = jobData.isboss, + onDuty = jobData.onduty, + } +end + Framework.HasItem = function(item) return QBCore.Functions.HasItem(item) end diff --git a/modules/framework/qb-core/server.lua b/modules/framework/qb-core/server.lua index 1a302da..9885980 100644 --- a/modules/framework/qb-core/server.lua +++ b/modules/framework/qb-core/server.lua @@ -326,12 +326,12 @@ Framework.GetPlayersByJob = function(job) return playerList end ----This will get the players job info +---Depricated: Returns the job name, label, grade name, and grade level of the player. ---@param src number ----@return string ----@return string ----@return string ----@return string +---@return string | string | string | number | nil +---@return string | string | string | number | nil +---@return string | string | string | number | nil +---@return string | string | string | number | nil Framework.GetPlayerJob = function(src) local player = Framework.GetPlayer(src) if not player then return end @@ -339,6 +339,24 @@ Framework.GetPlayerJob = function(src) return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level end +---This will return the players job name, job label, job grade label job grade level, boss status, and duty status in a table +---@return table | nil +Framework.GetPlayerJobData = function(src) + local player = Framework.GetPlayer(src) + if not player then return end + local playerData = player.PlayerData + local jobData = playerData.job + return { + jobName = jobData.name, + jobLabel = jobData.label, + gradeName = jobData.grade.name, + gradeLabel = jobData.grade.name, + gradeRank = jobData.grade.level, + boss = jobData.isboss, + onDuty = jobData.onduty, + } +end + ---Returns the players duty status. ---@param src number ---@return boolean | nil diff --git a/modules/framework/qbx_core/client.lua b/modules/framework/qbx_core/client.lua index bf1e9af..ad0b815 100644 --- a/modules/framework/qbx_core/client.lua +++ b/modules/framework/qbx_core/client.lua @@ -50,11 +50,32 @@ Framework.GetPlayerName = function() return playerData.charinfo.firstname, playerData.charinfo.lastname end +---Depricated : This will return the players job name, job label, job grade label and job grade level +---@return string +---@return string +---@return string +---@return string Framework.GetPlayerJob = function() local playerData = Framework.GetPlayerData() return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level end +---This will return the players job name, job label, job grade label job grade level, boss status, and duty status in a table +---@return table +Framework.GetPlayerJobData = function() + local playerData = Framework.GetPlayerData() + local jobData = playerData.job + return { + jobName = jobData.name, + jobLabel = jobData.label, + gradeName = jobData.grade.name, + gradeLabel = jobData.grade.name, + gradeRank = jobData.grade.level, + boss = jobData.isboss, + onDuty = jobData.onduty, + } +end + Framework.GetPlayerInventory = function() return Framework.GetPlayerData().items end diff --git a/modules/framework/qbx_core/server.lua b/modules/framework/qbx_core/server.lua index b981b50..a7064b7 100644 --- a/modules/framework/qbx_core/server.lua +++ b/modules/framework/qbx_core/server.lua @@ -285,16 +285,35 @@ Framework.GetPlayersByJob = function(job) return playerList end ----Returns the job name, label, grade name, and grade level of the player. +---Depricated: Returns the job name, label, grade name, and grade level of the player. ---@param src number ---@return string | string | string | number | nil ---@return string | string | string | number | nil ---@return string | string | string | number | nil ---@return string | string | string | number | nil Framework.GetPlayerJob = function(src) - local player = Framework.GetPlayer(src).PlayerData + local player = Framework.GetPlayer(src) if not player then return end - return player.job.name, player.job.label, player.job.grade.name, player.job.grade.level + local playerData = player.PlayerData + return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level +end + +---This will return the players job name, job label, job grade label job grade level, boss status, and duty status in a table +---@return table | nil +Framework.GetPlayerJobData = function(src) + local player = Framework.GetPlayer(src) + if not player then return end + local playerData = player.PlayerData + local jobData = playerData.job + return { + jobName = jobData.name, + jobLabel = jobData.label, + gradeName = jobData.grade.name, + gradeLabel = jobData.grade.name, + gradeRank = jobData.grade.level, + boss = jobData.isboss, + onDuty = jobData.onduty, + } end ---Sets the player's job to the specified name and grade. From d89b087e4d539494a10b8f751a767a6a9b5a4ac2 Mon Sep 17 00:00:00 2001 From: gononono64 <96976330+gononono64@users.noreply.github.com> Date: Thu, 15 May 2025 01:48:02 -0500 Subject: [PATCH 2/5] cache fixed --- lib/cache/client/cache.lua | 12 ++++++------ lib/cache/shared/cache.lua | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/cache/client/cache.lua b/lib/cache/client/cache.lua index df493c8..4b4b430 100644 --- a/lib/cache/client/cache.lua +++ b/lib/cache/client/cache.lua @@ -12,13 +12,13 @@ local PlayerId = PlayerId --- Get the player's ped ID ---@return integer -local function GetPed() +function GetPed() return PlayerPedId() end --- Get the vehicle the player is in, if any ---@return integer | nil -local function GetVehicle() +function GetVehicle() local ped = Cache.Get("Ped") -- Use cached ped for efficiency if not ped then return end -- Or handle error/default case return GetVehiclePedIsIn(ped, false) @@ -26,7 +26,7 @@ end --- Get the seat of the player in the vehicle if the vehicle is occupied ---@return integer | nil -local function GetVehicleSeat() +function GetVehicleSeat() local vehicle = Cache.Get("Vehicle") if not vehicle then return end local ped = Cache.Get("Ped") @@ -40,7 +40,7 @@ end ---Get The Server ID of the player ---@return integer | nil -local function GetServerId() +function GetServerId() local ped = PlayerId() if not ped then return end -- Return unarmed hash if no ped return GetPlayerServerId(ped) @@ -48,7 +48,7 @@ end --- Get the current weapon of the player --- @return integer | nil -local function GetWeapon() +function GetWeapon() local ped = Cache.Get("Ped") if not ped then return end -- Return unarmed hash if no ped return GetSelectedPedWeapon(ped) @@ -57,7 +57,7 @@ end Cache.Create("Ped", GetPed, 1000) -- Check ped every second (adjust as needed) Cache.Create("Vehicle", GetVehicle, 500) -- Check vehicle every 500ms Cache.Create("Seat", GetVehicleSeat, 500) -- Check if in vehicle every 500ms -Cache.Create("Weapon", GetWeapon, 250) -- Check weapon every 250ms +Cache.Create("Weapon", GetWeapon , 250) -- Check weapon every 250ms Cache.Create("ServerId", GetServerId, 1000) -- Check server ID every second return Cache diff --git a/lib/cache/shared/cache.lua b/lib/cache/shared/cache.lua index ed42a50..c48e7ab 100644 --- a/lib/cache/shared/cache.lua +++ b/lib/cache/shared/cache.lua @@ -57,7 +57,6 @@ end function Cache.Create(name, compare, waitTime) assert(name, "Cache name is required.") assert(compare, "Comparison function is required.") - assert(type(compare) == "function", "Comparison function must be a function.") local _name = tostring(name) -- Ensure name is a string local cache = Cache.Caches[_name] if cache and cache.Compare == compare then From 2aef4125ffe96b81c9b989ebe2f5346d90a081bd Mon Sep 17 00:00:00 2001 From: gononono64 <96976330+gononono64@users.noreply.github.com> Date: Thu, 15 May 2025 01:49:49 -0500 Subject: [PATCH 3/5] removed prints left in cache --- lib/cache/shared/cache.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/cache/shared/cache.lua b/lib/cache/shared/cache.lua index c48e7ab..d0a9fb7 100644 --- a/lib/cache/shared/cache.lua +++ b/lib/cache/shared/cache.lua @@ -74,7 +74,6 @@ function Cache.Create(name, compare, waitTime) Value = compare() } Cache.Caches[_name] = _cache - print(_name .. " created with initial value: " .. tostring(Cache.Caches[_name].Value)) for _, onChange in pairs(_cache.OnChange) do onChange(_cache.Value, nil) end @@ -108,7 +107,6 @@ function Cache.Remove(name) local cache = Cache.Caches[_name] if cache then Cache.Caches[_name] = nil - print(_name .. " removed from cache.") if next(Cache.Caches) == nil then Cache.LoopRunning = false -- Stop the loop if no caches are left end From 3652f2b1bd7b1e3e41de89c89162a4379c77dbdb Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Thu, 15 May 2025 11:16:37 -0400 Subject: [PATCH 4/5] small patch for qbx when config not set --- modules/framework/_default/client.lua | 3 +++ modules/framework/qbx_core/client.lua | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 modules/framework/_default/client.lua diff --git a/modules/framework/_default/client.lua b/modules/framework/_default/client.lua new file mode 100644 index 0000000..5d895be --- /dev/null +++ b/modules/framework/_default/client.lua @@ -0,0 +1,3 @@ +Framework = Framework or {} + +return Framework \ No newline at end of file diff --git a/modules/framework/qbx_core/client.lua b/modules/framework/qbx_core/client.lua index ad0b815..8add8d7 100644 --- a/modules/framework/qbx_core/client.lua +++ b/modules/framework/qbx_core/client.lua @@ -27,13 +27,14 @@ end ---@param _ unknown ---@return nil Framework.ShowHelpText = function(message, _) - return print("Community_bridge:WARN: ShowHelpText is not implemented for this framework, please set the helptext module to hide the help text.") + if _ == nil then _ = 'left-center' end + return exports.ox_lib:showTextUI(message, { position = _position }) end ---This will hide the help text message on the screen ---@return nil Framework.HideHelpText = function() - return print("Community_bridge:WARN: HideHelpText is not implemented for this framework, please set the helptext module to hide the help text.") + return exports.ox_lib:hideTextUI() end Framework.GetPlayerMetaData = function(metadata) @@ -41,6 +42,10 @@ Framework.GetPlayerMetaData = function(metadata) return playerData.metadata[metadata] end +Framework.Notify = function(message, type, time) + return QBox:Notify("Notification", type, time, message) +end + Framework.GetPlayerIdentifier = function() return Framework.GetPlayerData().citizenid end From 1c19fffb313e05e6359aa3f1b8e6f42ced59372e Mon Sep 17 00:00:00 2001 From: Johann Kraus <56100605+JericoFX@users.noreply.github.com> Date: Fri, 16 May 2025 01:45:50 -0300 Subject: [PATCH 5/5] Clean DUI until i found a better way to do it --- lib/dui/client/dui.lua | 546 ++++++++++++++++++++--------------------- lib/init.lua | 2 +- 2 files changed, 274 insertions(+), 274 deletions(-) diff --git a/lib/dui/client/dui.lua b/lib/dui/client/dui.lua index 7f0d7f0..1b9fd68 100644 --- a/lib/dui/client/dui.lua +++ b/lib/dui/client/dui.lua @@ -1,329 +1,329 @@ --- DUI (Direct User Interface) Manager for FiveM --- Basic table-based implementation with full mouse support +-- -- DUI (Direct User Interface) Manager for FiveM +-- -- Basic table-based implementation with full mouse support ----@class DUI -DUI = {} +-- ---@class DUI +-- DUI = {} --- Constants -local DEFAULT_WIDTH = 1280 -local DEFAULT_HEIGHT = 720 +-- -- Constants +-- local DEFAULT_WIDTH = 1280 +-- local DEFAULT_HEIGHT = 720 --- Store active DUI instances -local activeInstances = {} -local instanceCounter = 0 +-- -- Store active DUI instances +-- local activeInstances = {} +-- local instanceCounter = 0 --- Mouse tracking state -local mouseState = { - tracking = false, - activeId = nil, - lastX = 0, - lastY = 0, - isPressed = false, - currentButton = nil -} +-- -- Mouse tracking state +-- local mouseState = { +-- tracking = false, +-- activeId = nil, +-- lastX = 0, +-- lastY = 0, +-- isPressed = false, +-- currentButton = nil +-- } --- Mouse button constants -local MOUSE_BUTTONS = { - LEFT = "left", - MIDDLE = "middle", - RIGHT = "right" -} +-- -- Mouse button constants +-- local MOUSE_BUTTONS = { +-- LEFT = "left", +-- MIDDLE = "middle", +-- RIGHT = "right" +-- } ----@class DUIInstance ----@field id number Unique identifier for this DUI instance ----@field url string URL loaded in the DUI ----@field width number Width of the DUI ----@field height number Height of the DUI ----@field handle number DUI browser handle ----@field txd string Texture dictionary name ----@field txn string Texture name ----@field active boolean Whether the DUI is active ----@field trackMouse boolean Whether mouse tracking is enabled for this instance ----@field mouseScale table Scale factors for mouse coordinates +-- ---@class DUIInstance +-- ---@field id number Unique identifier for this DUI instance +-- ---@field url string URL loaded in the DUI +-- ---@field width number Width of the DUI +-- ---@field height number Height of the DUI +-- ---@field handle number DUI browser handle +-- ---@field txd string Texture dictionary name +-- ---@field txn string Texture name +-- ---@field active boolean Whether the DUI is active +-- ---@field trackMouse boolean Whether mouse tracking is enabled for this instance +-- ---@field mouseScale table Scale factors for mouse coordinates --- Create a new DUI instance ----@param url string URL to load ----@param width? number Width of the DUI (default: 1280) ----@param height? number Height of the DUI (default: 720) ----@return number|nil id The DUI instance ID if successful, nil if failed -function DUI.Create(url, width, height) - if not url or type(url) ~= "string" then - return print("DUI.Create: URL is required and must be a string") - end +-- -- Create a new DUI instance +-- ---@param url string URL to load +-- ---@param width? number Width of the DUI (default: 1280) +-- ---@param height? number Height of the DUI (default: 720) +-- ---@return number|nil id The DUI instance ID if successful, nil if failed +-- function DUI.Create(url, width, height) +-- if not url or type(url) ~= "string" then +-- return print("DUI.Create: URL is required and must be a string") +-- end - width = width or DEFAULT_WIDTH - height = height or DEFAULT_HEIGHT - instanceCounter = instanceCounter + 1 +-- width = width or DEFAULT_WIDTH +-- height = height or DEFAULT_HEIGHT +-- instanceCounter = instanceCounter + 1 - local id = instanceCounter - local handle = CreateDui(url, width, height) +-- local id = instanceCounter +-- local handle = CreateDui(url, width, height) - if not handle then - return print("DUI.Create: Failed to create DUI instance") - end +-- if not handle then +-- return print("DUI.Create: Failed to create DUI instance") +-- end - local instance = { - id = id, - url = url, - width = width, - height = height, - handle = handle, - txd = "dui_" .. id, - txn = "texture_" .. id, - active = true, - trackMouse = false, - mouseScale = { - x = 1.0, - y = 1.0 - } - } +-- local instance = { +-- id = id, +-- url = url, +-- width = width, +-- height = height, +-- handle = handle, +-- txd = "dui_" .. id, +-- txn = "texture_" .. id, +-- active = true, +-- trackMouse = false, +-- mouseScale = { +-- x = 1.0, +-- y = 1.0 +-- } +-- } - -- Create runtime texture - local duiHandle = GetDuiHandle(handle) - CreateRuntimeTextureFromDuiHandle(CreateRuntimeTxd(instance.txd), instance.txn, duiHandle) +-- -- Create runtime texture +-- local duiHandle = GetDuiHandle(handle) +-- CreateRuntimeTextureFromDuiHandle(CreateRuntimeTxd(instance.txd), instance.txn, duiHandle) - activeInstances[id] = instance - return id -end +-- activeInstances[id] = instance +-- return id +-- end --- Destroy a DUI instance ----@param id number DUI instance ID ----@return boolean success Whether the operation was successful -function DUI.Destroy(id) - local instance = activeInstances[id] - if not instance then return false end +-- -- Destroy a DUI instance +-- ---@param id number DUI instance ID +-- ---@return boolean success Whether the operation was successful +-- function DUI.Destroy(id) +-- local instance = activeInstances[id] +-- if not instance then return false end - if instance.handle then - DestroyDui(instance.handle) - end +-- if instance.handle then +-- DestroyDui(instance.handle) +-- end - activeInstances[id] = nil - return true -end +-- activeInstances[id] = nil +-- return true +-- end --- Set URL for a DUI instance ----@param id number DUI instance ID ----@param url string New URL to load ----@return boolean success Whether the operation was successful -function DUI.SetURL(id, url) - local instance = activeInstances[id] - if not instance then return false end +-- -- Set URL for a DUI instance +-- ---@param id number DUI instance ID +-- ---@param url string New URL to load +-- ---@return boolean success Whether the operation was successful +-- function DUI.SetURL(id, url) +-- local instance = activeInstances[id] +-- if not instance then return false end - SetDuiUrl(instance.handle, url) - instance.url = url - return true -end +-- SetDuiUrl(instance.handle, url) +-- instance.url = url +-- return true +-- end --- Send a message to the DUI ----@param id number DUI instance ID ----@param message table Message to send (will be JSON encoded) ----@return boolean success Whether the operation was successful -function DUI.SendMessage(id, message) - local instance = activeInstances[id] - if not instance then return false end +-- -- Send a message to the DUI +-- ---@param id number DUI instance ID +-- ---@param message table Message to send (will be JSON encoded) +-- ---@return boolean success Whether the operation was successful +-- function DUI.SendMessage(id, message) +-- local instance = activeInstances[id] +-- if not instance then return false end - SendDuiMessage(instance.handle, json.encode(message)) - return true -end +-- SendDuiMessage(instance.handle, json.encode(message)) +-- return true +-- end --- Mouse interaction functions +-- -- Mouse interaction functions --- Move mouse cursor on DUI ----@param id number DUI instance ID ----@param x number X coordinate ----@param y number Y coordinate ----@return boolean success Whether the operation was successful -function DUI.MoveMouse(id, x, y) - local instance = activeInstances[id] - if not instance then return false end +-- -- Move mouse cursor on DUI +-- ---@param id number DUI instance ID +-- ---@param x number X coordinate +-- ---@param y number Y coordinate +-- ---@return boolean success Whether the operation was successful +-- function DUI.MoveMouse(id, x, y) +-- local instance = activeInstances[id] +-- if not instance then return false end - SendDuiMouseMove(instance.handle, x, y) - return true -end +-- SendDuiMouseMove(instance.handle, x, y) +-- return true +-- end --- Simulate mouse button press ----@param id number DUI instance ID ----@param button "left"|"middle"|"right" Mouse button to simulate ----@return boolean success Whether the operation was successful -function DUI.MouseDown(id, button) - local instance = activeInstances[id] - if not instance then return false end +-- -- Simulate mouse button press +-- ---@param id number DUI instance ID +-- ---@param button "left"|"middle"|"right" Mouse button to simulate +-- ---@return boolean success Whether the operation was successful +-- function DUI.MouseDown(id, button) +-- local instance = activeInstances[id] +-- if not instance then return false end - if not MOUSE_BUTTONS[button:upper()] then - return print("DUI.MouseDown: Invalid button. Must be 'left', 'middle', or 'right'") - end +-- if not MOUSE_BUTTONS[button:upper()] then +-- return print("DUI.MouseDown: Invalid button. Must be 'left', 'middle', or 'right'") +-- end - -- Update mouse state - if instance.trackMouse then - mouseState.isPressed = true - mouseState.currentButton = button - end +-- -- Update mouse state +-- if instance.trackMouse then +-- mouseState.isPressed = true +-- mouseState.currentButton = button +-- end - SendDuiMouseDown(instance.handle, button) - return true -end +-- SendDuiMouseDown(instance.handle, button) +-- return true +-- end --- Simulate mouse button release ----@param id number DUI instance ID ----@param button "left"|"middle"|"right" Mouse button to simulate ----@return boolean success Whether the operation was successful -function DUI.MouseUp(id, button) - local instance = activeInstances[id] - if not instance then return false end +-- -- Simulate mouse button release +-- ---@param id number DUI instance ID +-- ---@param button "left"|"middle"|"right" Mouse button to simulate +-- ---@return boolean success Whether the operation was successful +-- function DUI.MouseUp(id, button) +-- local instance = activeInstances[id] +-- if not instance then return false end - if not MOUSE_BUTTONS[button:upper()] then - return print("DUI.MouseUp: Invalid button. Must be 'left', 'middle', or 'right'") - end +-- if not MOUSE_BUTTONS[button:upper()] then +-- return print("DUI.MouseUp: Invalid button. Must be 'left', 'middle', or 'right'") +-- end - -- Update mouse state - if instance.trackMouse then - mouseState.isPressed = false - mouseState.currentButton = nil - end +-- -- Update mouse state +-- if instance.trackMouse then +-- mouseState.isPressed = false +-- mouseState.currentButton = nil +-- end - SendDuiMouseUp(instance.handle, button) - return true -end +-- SendDuiMouseUp(instance.handle, button) +-- return true +-- end --- Simulate mouse wheel movement ----@param id number DUI instance ID ----@param deltaY number Vertical scroll amount ----@param deltaX number Horizontal scroll amount ----@return boolean success Whether the operation was successful -function DUI.MouseWheel(id, deltaY, deltaX) - local instance = activeInstances[id] - if not instance then return false end +-- -- Simulate mouse wheel movement +-- ---@param id number DUI instance ID +-- ---@param deltaY number Vertical scroll amount +-- ---@param deltaX number Horizontal scroll amount +-- ---@return boolean success Whether the operation was successful +-- function DUI.MouseWheel(id, deltaY, deltaX) +-- local instance = activeInstances[id] +-- if not instance then return false end - SendDuiMouseWheel(instance.handle, deltaY, deltaX) - return true -end +-- SendDuiMouseWheel(instance.handle, deltaY, deltaX) +-- return true +-- end --- Click helper function (combines MoveMouse, MouseDown, and MouseUp) ----@param id number DUI instance ID ----@param x number X coordinate ----@param y number Y coordinate ----@param button? "left"|"middle"|"right" Mouse button to click (default: "left") ----@return boolean success Whether the operation was successful -function DUI.Click(id, x, y, button) - button = button or "left" +-- -- Click helper function (combines MoveMouse, MouseDown, and MouseUp) +-- ---@param id number DUI instance ID +-- ---@param x number X coordinate +-- ---@param y number Y coordinate +-- ---@param button? "left"|"middle"|"right" Mouse button to click (default: "left") +-- ---@return boolean success Whether the operation was successful +-- function DUI.Click(id, x, y, button) +-- button = button or "left" - if not DUI.MoveMouse(id, x, y) then return false end - if not DUI.MouseDown(id, button) then return false end +-- if not DUI.MoveMouse(id, x, y) then return false end +-- if not DUI.MouseDown(id, button) then return false end - -- Small delay to simulate real click - Citizen.Wait(50) +-- -- Small delay to simulate real click +-- Citizen.Wait(50) - return DUI.MouseUp(id, button) -end +-- return DUI.MouseUp(id, button) +-- end --- Enable or disable mouse tracking for a DUI instance ----@param id number DUI instance ID ----@param enabled boolean Whether to enable mouse tracking ----@param scaleX? number Scale factor for X coordinates (default: 1.0) ----@param scaleY? number Scale factor for Y coordinates (default: 1.0) ----@return boolean success Whether the operation was successful -function DUI.TrackMouse(id, enabled, scaleX, scaleY) - local instance = activeInstances[id] - if not instance then return false end +-- -- Enable or disable mouse tracking for a DUI instance +-- ---@param id number DUI instance ID +-- ---@param enabled boolean Whether to enable mouse tracking +-- ---@param scaleX? number Scale factor for X coordinates (default: 1.0) +-- ---@param scaleY? number Scale factor for Y coordinates (default: 1.0) +-- ---@return boolean success Whether the operation was successful +-- function DUI.TrackMouse(id, enabled, scaleX, scaleY) +-- local instance = activeInstances[id] +-- if not instance then return false end - instance.trackMouse = enabled - instance.mouseScale.x = scaleX or 1.0 - instance.mouseScale.y = scaleY or 1.0 +-- instance.trackMouse = enabled +-- instance.mouseScale.x = scaleX or 1.0 +-- instance.mouseScale.y = scaleY or 1.0 - if enabled then - mouseState.tracking = true - mouseState.activeId = id - elseif mouseState.activeId == id then - mouseState.tracking = false - mouseState.activeId = nil - end +-- if enabled then +-- mouseState.tracking = true +-- mouseState.activeId = id +-- elseif mouseState.activeId == id then +-- mouseState.tracking = false +-- mouseState.activeId = nil +-- end - return true -end +-- return true +-- end --- Update mouse coordinates from screen position ----@param screenX number Screen X coordinate ----@param screenY number Screen Y coordinate ----@return boolean updated Whether coordinates were updated -local function UpdateMousePosition(screenX, screenY) - if not mouseState.tracking or not mouseState.activeId then return false end +-- -- Update mouse coordinates from screen position +-- ---@param screenX number Screen X coordinate +-- ---@param screenY number Screen Y coordinate +-- ---@return boolean updated Whether coordinates were updated +-- local function UpdateMousePosition(screenX, screenY) +-- if not mouseState.tracking or not mouseState.activeId then return false end - local instance = activeInstances[mouseState.activeId] - if not instance or not instance.trackMouse then return false end +-- local instance = activeInstances[mouseState.activeId] +-- if not instance or not instance.trackMouse then return false end - -- Scale coordinates based on DUI dimensions and scale factors - local scaledX = screenX * instance.mouseScale.x - local scaledY = screenY * instance.mouseScale.y +-- -- Scale coordinates based on DUI dimensions and scale factors +-- local scaledX = screenX * instance.mouseScale.x +-- local scaledY = screenY * instance.mouseScale.y - -- Only update if position changed - if scaledX ~= mouseState.lastX or scaledY ~= mouseState.lastY then - mouseState.lastX = scaledX - mouseState.lastY = scaledY - DUI.MoveMouse(mouseState.activeId, scaledX, scaledY) - return true - end +-- -- Only update if position changed +-- if scaledX ~= mouseState.lastX or scaledY ~= mouseState.lastY then +-- mouseState.lastX = scaledX +-- mouseState.lastY = scaledY +-- DUI.MoveMouse(mouseState.activeId, scaledX, scaledY) +-- return true +-- end - return false -end +-- return false +-- end --- Mouse tracking thread -Citizen.CreateThread(function() - while true do - if mouseState.tracking and mouseState.activeId then - local instance = activeInstances[mouseState.activeId] - if instance and instance.trackMouse then - -- Get current cursor position - local screenX, screenY = GetNuiCursorPosition() - UpdateMousePosition(screenX, screenY) +-- -- Mouse tracking thread +-- Citizen.CreateThread(function() +-- while true do +-- if mouseState.tracking and mouseState.activeId then +-- local instance = activeInstances[mouseState.activeId] +-- if instance and instance.trackMouse then +-- -- Get current cursor position +-- local screenX, screenY = GetNuiCursorPosition() +-- UpdateMousePosition(screenX, screenY) - -- Handle held mouse buttons - if mouseState.isPressed and mouseState.currentButton then - -- Keep the button pressed state - SendDuiMouseDown(instance.handle, mouseState.currentButton) - end - end - end - Citizen.Wait(0) - end -end) +-- -- Handle held mouse buttons +-- if mouseState.isPressed and mouseState.currentButton then +-- -- Keep the button pressed state +-- SendDuiMouseDown(instance.handle, mouseState.currentButton) +-- end +-- end +-- end +-- Citizen.Wait(0) +-- end +-- end) --- Utility functions +-- -- Utility functions --- Get textures for a DUI instance ----@param id number DUI instance ID ----@return string|nil txd, string|nil txn Texture dictionary and name, or nil if instance not found -function DUI.GetTextures(id) - local instance = activeInstances[id] - if not instance then return nil, nil end +-- -- Get textures for a DUI instance +-- ---@param id number DUI instance ID +-- ---@return string|nil txd, string|nil txn Texture dictionary and name, or nil if instance not found +-- function DUI.GetTextures(id) +-- local instance = activeInstances[id] +-- if not instance then return nil, nil end - return instance.txd, instance.txn -end +-- return instance.txd, instance.txn +-- end --- Check if a DUI instance exists ----@param id number DUI instance ID ----@return boolean exists Whether the instance exists and is active -function DUI.Exists(id) - local instance = activeInstances[id] - return instance ~= nil and instance.active -end +-- -- Check if a DUI instance exists +-- ---@param id number DUI instance ID +-- ---@return boolean exists Whether the instance exists and is active +-- function DUI.Exists(id) +-- local instance = activeInstances[id] +-- return instance ~= nil and instance.active +-- end --- Get all active DUI instances ----@return table instances Table of active DUI instances -function DUI.GetActiveInstances() - return activeInstances -end +-- -- Get all active DUI instances +-- ---@return table instances Table of active DUI instances +-- function DUI.GetActiveInstances() +-- return activeInstances +-- end --- Cleanup all DUI instances -function DUI.CleanupAll() - for id in pairs(activeInstances) do - DUI.Destroy(id) - end -end +-- -- Cleanup all DUI instances +-- function DUI.CleanupAll() +-- for id in pairs(activeInstances) do +-- DUI.Destroy(id) +-- end +-- end --- Automatic cleanup on resource stop -AddEventHandler('onResourceStop', function(resourceName) - if GetCurrentResourceName() ~= resourceName then return end - DUI.CleanupAll() -end) +-- -- Automatic cleanup on resource stop +-- AddEventHandler('onResourceStop', function(resourceName) +-- if GetCurrentResourceName() ~= resourceName then return end +-- DUI.CleanupAll() +-- end) -return DUI +-- return DUI diff --git a/lib/init.lua b/lib/init.lua index 7aa6a34..ef0d786 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -80,7 +80,7 @@ cLib.ClientStateBag = ClientStateBag or Require("lib/statebags/client/client.lua cLib.Marker = Marker or Require("lib/markers/client/markers.lua") cLib.Anim = Anim or Require("lib/anim/client/client.lua") cLib.Cutscene = Cutscene or Require("lib/cutscenes/client/cutscene.lua") -cLib.DUI = DUI or Require("lib/dui/client/dui.lua") +--cLib.DUI = DUI or Require("lib/dui/client/dui.lua") cLib.Particle = Particle or Require("lib/particles/client/particles.lua") return cLib