progressbar and dialogue update
added props to progressbar fixed dialogue for nesting
This commit is contained in:
1 parent
58782dfcd0
commit
f8d46b9f7b
7 files changed
+85
-121
No files matched your search
@@ -1,17 +1,32 @@
|
|||||||
|
|
||||||
|
local promises = {}
|
||||||
|
|
||||||
|
function CloseDialogue(name)
|
||||||
|
SendNUIMessage({
|
||||||
|
type = "close",
|
||||||
|
name = name
|
||||||
|
})
|
||||||
|
promises[name] = nil
|
||||||
|
end
|
||||||
|
|
||||||
--- Open a dialogue with the player
|
--- Open a dialogue with the player
|
||||||
--- @param name string
|
--- @param name string
|
||||||
--- @param dialogue string
|
--- @param dialogue string
|
||||||
--- @param options table example = {{ id = string, label = string}}
|
--- @param options table example = {{ id = string, label = string}}
|
||||||
function OpenDialogue(name, dialogue, options)
|
function OpenDialogue(name, dialogue, options, onSelected, onCancelled)
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
type = "open",
|
type = "open",
|
||||||
text = dialogue,
|
text = dialogue,
|
||||||
name = name,
|
name = name,
|
||||||
options = options
|
options = options
|
||||||
})
|
})
|
||||||
|
SetNuiFocus(true, true)
|
||||||
|
local wrappedFunction = function(selected)
|
||||||
|
SetNuiFocus(false, false)
|
||||||
|
CloseDialogue(name)
|
||||||
|
onSelected(selected)
|
||||||
|
end
|
||||||
|
promises[name] = wrappedFunction
|
||||||
end
|
end
|
||||||
|
|
||||||
RegisterCommand("dialogue", function()
|
RegisterCommand("dialogue", function()
|
||||||
@@ -23,11 +38,35 @@ RegisterCommand("dialogue", function()
|
|||||||
{
|
{
|
||||||
label = "Goodbye",
|
label = "Goodbye",
|
||||||
id = 'someotherthing',
|
id = 'someotherthing',
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
|
function(selectedId)
|
||||||
|
if selectedId == 'something' then
|
||||||
|
OpenDialogue( "Akmed" , "Thank you for wanting to purchase me lucky charms", {
|
||||||
|
{
|
||||||
|
label = "fuck russia",
|
||||||
|
id = 'something',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label = "Goodbye",
|
||||||
|
id = 'someotherthing',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
function(selectedId)
|
||||||
|
print("fuck russia:", selectedId)
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
RegisterNuiCallback("dialogue:SelectOption", function(data)
|
||||||
|
print("Selected option: " .. data.name)
|
||||||
|
local promis = promises[data.name]
|
||||||
|
if not promis then return end
|
||||||
|
promis(data.id)
|
||||||
|
end)
|
||||||
|
|
||||||
-- { label: 'Hello there! this is some long text that i am Dialogueing', id: '1' },
|
-- { label: 'Hello there! this is some long text that i am Dialogueing', id: '1' },
|
||||||
-- { label: 'Trade with me', id: '2' },
|
-- { label: 'Trade with me', id: '2' },
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
if GetResourceState('ox_lib') ~= 'started' or (BridgeClientConfig.ProgressBarSystem ~= "ox" and BridgeClientConfig.InputSystem ~= "auto") then return end
|
|
||||||
ProgressBar = ProgressBar or {}
|
|
||||||
|
|
||||||
local function convertFromQB(options)
|
|
||||||
if not options then return options end
|
|
||||||
|
|
||||||
return {
|
|
||||||
duration = options.duration,
|
|
||||||
label = options.label,
|
|
||||||
position = 'bottom',
|
|
||||||
useWhileDead = options.useWhileDead,
|
|
||||||
canCancel = options.canCancel,
|
|
||||||
disable = {
|
|
||||||
move = options.controlDisables?.disableMovement,
|
|
||||||
car = options.controlDisables?.disableCarMovement,
|
|
||||||
combat = options.controlDisables?.disableCombat,
|
|
||||||
mouse = options.controlDisables?.disableMouse
|
|
||||||
},
|
|
||||||
anim = {
|
|
||||||
dict = options.animation?.animDict,
|
|
||||||
clip = options.animation?.anim
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProgressBar.Open(options, cb, isQBInput)
|
|
||||||
if isQBInput then
|
|
||||||
options = convertFromQB(options)
|
|
||||||
end
|
|
||||||
|
|
||||||
local style = options.style or 'bar'
|
|
||||||
local success = style == 'circle' and exports.ox_lib:progressCircle(options) or exports.ox_lib:progressBar(options)
|
|
||||||
|
|
||||||
if cb then cb(not success) end
|
|
||||||
return success
|
|
||||||
end
|
|
||||||
|
|
||||||
RegisterCommand("progressbar", function()
|
|
||||||
ProgressBar.Open({
|
|
||||||
duration = 5000,
|
|
||||||
label = "Searching",
|
|
||||||
disable = {
|
|
||||||
move = true,
|
|
||||||
combat = true
|
|
||||||
},
|
|
||||||
anim = {
|
|
||||||
dict = "anim@amb@clubhouse@tutorial@bkr_tut_ig3@",
|
|
||||||
clip = "machinic_loop_mechandplayer"
|
|
||||||
}
|
|
||||||
}, function(cancelled)
|
|
||||||
print(cancelled and "Cancelled" or "Complete")
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
@@ -43,6 +43,23 @@ ProgressBar = ProgressBar or {}
|
|||||||
|
|
||||||
local function convertFromQB(options)
|
local function convertFromQB(options)
|
||||||
if not options then return options end
|
if not options then return options end
|
||||||
|
local prop1 = options.prop or {}
|
||||||
|
local prop2 = options.propTwo or {}
|
||||||
|
local props = {
|
||||||
|
{
|
||||||
|
model = prop1.model,
|
||||||
|
bone = prop1.bone,
|
||||||
|
pos = prop1.coords,
|
||||||
|
rot = prop1.rotation,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model = prop2.model,
|
||||||
|
bone = prop2.bone,
|
||||||
|
pos = prop2.coords,
|
||||||
|
rot = prop2.rotation,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
duration = options.duration,
|
duration = options.duration,
|
||||||
@@ -59,7 +76,8 @@ local function convertFromQB(options)
|
|||||||
anim = {
|
anim = {
|
||||||
dict = options.animation?.animDict,
|
dict = options.animation?.animDict,
|
||||||
clip = options.animation?.anim
|
clip = options.animation?.anim
|
||||||
}
|
},
|
||||||
|
prop = props,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
if GetResourceState('progressbar') ~= 'started' or (BridgeClientConfig.ProgressBarSystem ~= "qb" and BridgeClientConfig.ProgressBarSystem ~= "auto") then return end
|
|
||||||
ProgressBar = ProgressBar or {}
|
|
||||||
|
|
||||||
local function convertFromOx(options)
|
|
||||||
if not options then return options end
|
|
||||||
|
|
||||||
return {
|
|
||||||
name = options.label,
|
|
||||||
duration = options.duration,
|
|
||||||
label = options.label,
|
|
||||||
useWhileDead = options.useWhileDead,
|
|
||||||
canCancel = options.canCancel,
|
|
||||||
controlDisables = {
|
|
||||||
disableMovement = options.disable?.move,
|
|
||||||
disableCarMovement = options.disable?.car,
|
|
||||||
disableMouse = options.disable?.mouse,
|
|
||||||
disableCombat = options.disable?.combat
|
|
||||||
},
|
|
||||||
animation = {
|
|
||||||
animDict = options.anim?.dict,
|
|
||||||
anim = options.anim?.clip
|
|
||||||
},
|
|
||||||
prop = {},
|
|
||||||
propTwo = {}
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProgressBar.Open(options, cb, qbFormat)
|
|
||||||
if not exports['progressbar'] then return false end
|
|
||||||
|
|
||||||
if not qbFormat then
|
|
||||||
options = convertFromOx(options)
|
|
||||||
end
|
|
||||||
|
|
||||||
exports['progressbar']:Progress(options, cb)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Example usage:
|
|
||||||
RegisterCommand("progressbar", function()
|
|
||||||
ProgressBar.Open({
|
|
||||||
duration = 5000,
|
|
||||||
label = "Searching",
|
|
||||||
disable = {
|
|
||||||
move = true,
|
|
||||||
combat = true
|
|
||||||
},
|
|
||||||
anim = {
|
|
||||||
dict = "anim@amb@clubhouse@tutorial@bkr_tut_ig3@",
|
|
||||||
clip = "machinic_loop_mechandplayer"
|
|
||||||
}
|
|
||||||
}, function(cancelled)
|
|
||||||
print(cancelled and "Cancelled" or "Complete")
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
@@ -65,7 +65,8 @@ ProgressBar = ProgressBar or {}
|
|||||||
|
|
||||||
local function convertFromOx(options)
|
local function convertFromOx(options)
|
||||||
if not options then return options end
|
if not options then return options end
|
||||||
|
local prop1 = options.prop[1] or options.prop or {}
|
||||||
|
local prop2 = options.prop[2] or {}
|
||||||
return {
|
return {
|
||||||
name = options.label,
|
name = options.label,
|
||||||
duration = options.duration,
|
duration = options.duration,
|
||||||
@@ -82,8 +83,18 @@ local function convertFromOx(options)
|
|||||||
animDict = options.anim?.dict,
|
animDict = options.anim?.dict,
|
||||||
anim = options.anim?.clip
|
anim = options.anim?.clip
|
||||||
},
|
},
|
||||||
prop = {},
|
prop = {
|
||||||
propTwo = {}
|
model = prop1.model,
|
||||||
|
bone = prop1.bone,
|
||||||
|
coords = prop1.pos,
|
||||||
|
rotation = prop1.rot
|
||||||
|
},
|
||||||
|
propTwo = {
|
||||||
|
model = prop2.model,
|
||||||
|
bone = prop2.bone,
|
||||||
|
coords = prop2.pos,
|
||||||
|
rotation = prop2.rot
|
||||||
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -110,7 +121,12 @@ RegisterCommand("progressbar", function()
|
|||||||
anim = {
|
anim = {
|
||||||
dict = "anim@amb@clubhouse@tutorial@bkr_tut_ig3@",
|
dict = "anim@amb@clubhouse@tutorial@bkr_tut_ig3@",
|
||||||
clip = "machinic_loop_mechandplayer"
|
clip = "machinic_loop_mechandplayer"
|
||||||
}
|
},
|
||||||
|
prop = {
|
||||||
|
model = "prop_ar_arrow_3",
|
||||||
|
pos = vector3(0.0, 0.0, 0.0),
|
||||||
|
rot = vector3(0.0, 0.0, 0.0)
|
||||||
|
},
|
||||||
}, function(cancelled)
|
}, function(cancelled)
|
||||||
print(cancelled and "Cancelled" or "Complete")
|
print(cancelled and "Cancelled" or "Complete")
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
.dialogue-container {
|
.dialogue-container {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 30px;
|
bottom: 30px;
|
||||||
width: 66.666%;
|
width: 50%;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
padding: 25px;
|
padding: 25px;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
import { fetchNui } from './fetch'
|
||||||
import './dialogue.css'
|
import './dialogue.css'
|
||||||
|
|
||||||
function Dialogue() {
|
function Dialogue() {
|
||||||
console.log("Dialogue component loaded")
|
|
||||||
const [count, setCount] = useState(0)
|
const [count, setCount] = useState(0)
|
||||||
const [dialogueOptions, setDialogueOption] = useState([])
|
const [dialogueOptions, setDialogueOption] = useState([])
|
||||||
const [currentText, setCurrentText] = useState("Welcome traveler! How can I help you today?")
|
const [currentText, setCurrentText] = useState("Welcome traveler! How can I help you today?")
|
||||||
@@ -11,11 +11,10 @@ function Dialogue() {
|
|||||||
const handleMessage = (event) => {
|
const handleMessage = (event) => {
|
||||||
var data = event.data;
|
var data = event.data;
|
||||||
|
|
||||||
if (data !== undefined && data.type === "hide") {
|
if (data !== undefined && data.type === "close") {
|
||||||
document.getElementById('root').classList.add("hidden");
|
document.getElementById('root').classList.add("hidden");
|
||||||
}
|
}
|
||||||
if (data !== undefined && data.type === "open") {
|
if (data !== undefined && data.type === "open") {
|
||||||
console.log("Received data: ", data.text)
|
|
||||||
setDialogueOption(data.options);
|
setDialogueOption(data.options);
|
||||||
setCurrentText(data.text);
|
setCurrentText(data.text);
|
||||||
setSpeakerName(data.name);
|
setSpeakerName(data.name);
|
||||||
@@ -39,7 +38,7 @@ function Dialogue() {
|
|||||||
{dialogueOptions.map((option) => (
|
{dialogueOptions.map((option) => (
|
||||||
<button
|
<button
|
||||||
key={option.id}
|
key={option.id}
|
||||||
onClick={() => console.log(`Selected: ${option.label}`)}
|
onClick={() => fetchNui("dialogue:SelectOption", { name: speakerName, id: option.id })}
|
||||||
className="dialogue-button"
|
className="dialogue-button"
|
||||||
>
|
>
|
||||||
{option.label}
|
{option.label}
|
||||||
|
|||||||
Reference in new issue
Block a user