用户界面绘制

此部分函数可用于在玩家游戏界面上绘制文本和图形。

每帧调用说明

部分函数需要在每一帧里都被调用一次,以下是示例:

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        -- 这里是绘制的代码
    end
end)

Hud.DrawLabel3D

函数作用:绘制 3D 的消息气泡,支持显示按键,需要每帧调用
基本构造:ZeroDream.Hud.DrawLabel3D( pos, text )
示例代码:

local playerPos = GetEntityCoords(PlayerPedId())
local text = "这是一个简单的气泡,你也可以按下 ~INPUT_CONTEXT~ 但是什么都不会发生"
ZeroDream.Hud.DrawLabel3D(playerPos, text)

Hud.DrawMarker

函数作用:绘制方形的光圈(样式可以参考中国车牌的上牌点),需要每帧调用
基本构造:ZeroDream.Hud.DrawMarker( pos, heading, long, width, color, markerId, dir, rot )
示例代码:

local pos = vec3(-349.67, -105.17, 38.53)
local heading = 245.0
local color = { r = 255, g = 0, b = 0, a = 150 }
local long = 3.0
local width = 3.0
ZeroDream.Hud.DrawMarker(pos, heading, long, width, color, 36)

Hud.DrawText2D

函数作用:在屏幕上绘制 2D 的文字,需要每帧调用
基本构造:ZeroDream.Hud.DrawText2D( text, x, y, size, config )
示例代码:

local text = "天王盖地虎"
local x = 0.5 -- 屏幕横向位置,最小 0.0 最大 1.0
local y = 0.5 -- 屏幕纵向位置,同上
local size = 0.5 -- 字体大小
local config = { -- 可选配置
    color = {255, 255, 255, 255}, -- 字体颜色 R G B A
    font = 0, -- 字体类型
    outline = true, -- 字体边线
    center = false, -- 是否相对坐标居中
    shadow = true, -- 是否绘制阴影
    edge = true, -- 是否绘制字体边缘
}
ZeroDream.Hud.DrawText2D(text, x, y, size, config)

Hud.DrawText3D

函数作用:在屏幕上绘制 3D 的文字,需要每帧调用。此函数经过优化,在转动视角时不会有延迟
基本构造:ZeroDream.Hud.DrawText3D( pos, text, config )
示例代码:

local text = "宇宙第一帅"
local pos = GetEntityCoords(PlayerPedId()) + vec3(0, 0, 0.5)
local config = { -- 可选配置
    color = {255, 255, 255, 255}, -- 字体颜色 R G B A
    font = 0, -- 字体类型
    outline = true, -- 字体边线
    center = false, -- 是否相对坐标居中
    shadow = true, -- 是否绘制阴影
    edge = true, -- 是否绘制字体边缘
}
ZeroDream.Hud.DrawText3D(pos, text, config)

Hud.DrawRect

函数作用:在界面上绘制一个方块,需要每帧调用
基本构造:ZeroDream.Hud.DrawRect( x, y, width, height, color )
示例代码:

local x = 0.01
local y = 0.72
local width = 0.32
local height = 0.1
local color = { r = 223, g = 178, b = 62, a = 255 }
ZeroDream.Hud.DrawRect(x, y, width, height, color)

Hud.DrawHelpElements

函数作用:在屏幕右下角显示帮助信息(以及按钮),不需要每帧调用
基本构造:ZeroDream.Hud.DrawHelpElements( elements )
示例代码:

local elements = {
    { button = "~INPUT_CONTEXT~", text = "开门" },
    { text = "剩余时间:10 秒" }
}
ZeroDream.Hud.DrawHelpElements(elements)
-- 取消显示
ZeroDream.Hud.DrawHelpElements()

Hud.SendNotification

函数作用:发送消息通知,不需要每帧调用
基本构造:ZeroDream.Hud.SendNotification( message, theme )
示例代码:

local message = "你成功执行了这段代码"
local theme = "success"
ZeroDream.Hud.SendNotification( message, theme )

不是所有的 Hud 资源都支持 theme,例如 ESX 默认 Hud 就仅支持默认主题,而 QB-Core 默认 Hud 是支持其他颜色主题的。
如果服务器安装了 bulletin 插件,则此函数会优先调用 bulletin 来发送通知。