Skip to content

Commit

Permalink
refactor(client): display text prompt on markers
Browse files Browse the repository at this point in the history
Text prompts for evidence, stashes, shops, crafting.
Resolves #1700.
  • Loading branch information
thelindat committed May 20, 2024
1 parent 3f298a1 commit bb8f029
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 115 deletions.
4 changes: 2 additions & 2 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ RegisterNetEvent('ox_inventory:setPlayerInventory', function(currentDrops, inven
createDrop(dropId, data)
end

local hasTextUi = false
local hasTextUi
local uiOptions = { icon = 'fa-id-card' }

---@param point CPoint
Expand All @@ -1254,7 +1254,7 @@ RegisterNetEvent('ox_inventory:setPlayerInventory', function(currentDrops, inven

if point.isClosest and point.currentDistance < 1.2 then
if not hasTextUi then
hasTextUi = point
hasTextUi = nil
lib.showTextUI(point.message, uiOptions)
end

Expand Down
20 changes: 9 additions & 11 deletions modules/crafting/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ if not lib then return end
local CraftingBenches = {}
local Items = require 'modules.items.client'
local createBlip = require 'modules.utils.client'.CreateBlip
local Utils = require 'modules.utils.client'
local markerColour = { 150, 150, 30 }
local prompt = {
options = { icon = 'fa-wrench' },
message = ('**%s** \n%s'):format(locale('open_crafting_bench'), locale('interact_prompt', GetControlInstructionalButton(0, 38, true):sub(3)))
}

---@param id number
---@param data table
Expand Down Expand Up @@ -64,16 +70,6 @@ local function createCraftingBench(id, data)
elseif data.points then
data.zones = nil

---@param point CPoint
local function nearbyBench(point)
---@diagnostic disable-next-line: param-type-mismatch
DrawMarker(2, point.coords.x, point.coords.y, point.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.15, 150, 150, 30, 222, false, false, 0, true, false, false, false)

if point.isClosest and point.currentDistance < 1.2 and IsControlJustReleased(0, 38) then
client.openInventory('crafting', { id = point.benchid, index = point.index })
end
end

for i = 1, #data.points do
local coords = data.points[i]

Expand All @@ -83,7 +79,9 @@ local function createCraftingBench(id, data)
benchid = id,
index = i,
inv = 'crafting',
nearby = nearbyBench
prompt = prompt,
marker = markerColour,
nearby = Utils.nearbyMarker
})

if blip then
Expand Down
33 changes: 17 additions & 16 deletions modules/inventory/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,17 @@ local function openEvidence()
client.openInventory('policeevidence')
end

---@param point CPoint
local function nearbyEvidence(point)
---@diagnostic disable-next-line: param-type-mismatch
DrawMarker(2, point.coords.x, point.coords.y, point.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.15, 30, 30, 150, 222, false, false, 0, true, false, false, false)

if point.isClosest and point.currentDistance < 1.2 and IsControlJustReleased(0, 38) then
openEvidence()
end
end
local markerColour = { 30, 30, 150 }
local textPrompts = {
evidence = {
options = { icon = 'fa-box-archive' },
message = ('**%s** \n%s'):format(locale('open_police_evidence'), locale('interact_prompt', GetControlInstructionalButton(0, 38, true):sub(3)))
},
stash = {
options = { icon = 'fa-warehouse' },
message = ('**%s** \n%s'):format(locale('open_stash'), locale('interact_prompt', GetControlInstructionalButton(0, 38, true):sub(3)))
}
}

Inventory.Evidence = setmetatable(lib.load('data.evidence'), {
__call = function(self)
Expand Down Expand Up @@ -318,19 +320,16 @@ Inventory.Evidence = setmetatable(lib.load('data.evidence'), {
coords = evidence.coords,
distance = 16,
inv = 'policeevidence',
nearby = nearbyEvidence
marker = markerColour,
prompt = textPrompts.evidence,
nearby = Utils.nearbyMarker
})
end
end
end
end
})

local function nearbyStash(self)
---@diagnostic disable-next-line: param-type-mismatch
DrawMarker(2, self.coords.x, self.coords.y, self.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.15, 30, 30, 150, 222, false, false, 0, true, false, false, false)
end

Inventory.Stashes = setmetatable(lib.load('data.stashes'), {
__call = function(self)
for id, stash in pairs(self) do
Expand Down Expand Up @@ -365,7 +364,9 @@ Inventory.Stashes = setmetatable(lib.load('data.stashes'), {
distance = 16,
inv = 'stash',
invId = stash.name,
nearby = nearbyStash
marker = markerColour,
prompt = textPrompts.stash,
nearby = Utils.nearbyMarker
})
end
end
Expand Down
20 changes: 9 additions & 11 deletions modules/shops/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ for shopType, shopData in pairs(lib.load('data.shops') --[[@as table<string, OxS
end
end

---@param point CPoint
local function nearbyShop(point)
---@diagnostic disable-next-line: param-type-mismatch
DrawMarker(2, point.coords.x, point.coords.y, point.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.15, 30, 150, 30, 222, false, false, 0, true, false, false, false)

if point.isClosest and point.currentDistance < 1.2 and IsControlJustReleased(0, 38) then
client.openInventory('shop', { id = point.invId, type = point.type })
end
end

---@param point CPoint
local function onEnterShop(point)
if not point.entity then
Expand Down Expand Up @@ -112,6 +102,8 @@ local function wipeShops()
table.wipe(shops)
end

local markerColour = { 30, 150, 30 }

local function refreshShops()
wipeShops()

Expand Down Expand Up @@ -190,6 +182,7 @@ local function refreshShops()
end
elseif shop.locations then
if not hasShopAccess(shop) then goto skipLoop end
local shopPrompt = { icon = 'fas fa-shopping-basket' }

for i = 1, #shop.locations do
local coords = shop.locations[i]
Expand All @@ -201,7 +194,12 @@ local function refreshShops()
inv = 'shop',
invId = i,
type = type,
nearby = nearbyShop,
marker = markerColour,
prompt = {
options = shop.icon and { icon = shop.icon } or shopPrompt,
message = ('**%s** \n%s'):format(label, locale('interact_prompt', GetControlInstructionalButton(0, 38, true):sub(3)))
},
nearby = Utils.nearbyMarker,
blip = blip and createBlip(blip, coords)
})
end
Expand Down
Loading

0 comments on commit bb8f029

Please sign in to comment.