Fivem的可自定义通知。模仿本机GTAV通知,但允许更多自定义
css
覆盖添加到ui/css/custom.css
来自定义外观~r~
, ~b~
, ~h~
等) exports . bulletin : Send ( message , timeout , position , progress , theme , exitAnim , flash )
-- or
exports . bulletin : Send ({
message = ' Message ' ,
timeout = 5000 ,
theme = ' success '
...
})
exports . bulletin : SendAdvanced ( message , title , subject , icon , timeout , position , progress , theme , exitAnim , flash )
-- or
exports . bulletin : SendAdvanced ({
message = ' Some Message ' ,
title = ' Some Title ' ,
subject = ' Some Subtitle ' ,
icon = ' CHAR_BANK_MAZE ' ,
...
})
local pinID = exports . bulletin : SendPinned ({
type = ' advanced ' , -- or 'standard'
message = ' This is pinned! ' ,
title = ' Title ' ,
subject = ' Subject ' ,
icon = ' CHAR_BANK_MAZE '
})
-- unpin
exports . bulletin : Unpin ( pinID )
-- unpin multiple
exports . bulletin : Unpin ({ pinID1 , pinID2 , pinID3 , ... })
-- unpin all
exports . bulletin : Unpin ()
-- update content
exports . bulletin : UpdatePinned ( pinID , options )
这些是发送主题通知的速记方法。他们采用与Send()
方法相同的参数 /表:
-- Send standard success notification
exports . bulletin : SendSuccess ( ... )
-- Send standard info notification
exports . bulletin : SendInfo ( ... )
-- Send standard warning notification
exports . bulletin : SendWarning ( ... )
-- Send standard error notification
exports . bulletin : SendError ( ... )
所有方法都可以从客户端和服务器触发:
-- standard
TriggerClientEvent ( ' bulletin:send ' , source , ... )
-- advanced
TriggerClientEvent ( ' bulletin:sendAdvanced ' , source , ... )
这些被作为单个参数或表格传递:
参数 | 类型 | 默认 | 选项 | 选修的 | 描述 |
---|---|---|---|---|---|
message | string | 不 | 发送的消息。可以是字符串或有效的HTML | ||
timeout | integer | 5000 | 是的 | ms 中显示通知的持续时间 | |
position | string | "bottomleft" | "bottomleft" , "topleft" , "topright" "bottomright" , "bottom" , "top" | 是的 | 通知的帖子 |
progress | boolean | false | true , false | 是的 | 是否显示通知超时的进度 |
theme | string | "default" | "default" , "success" , "info" , "warning" , "error" | 是的 | 通知的主题 |
exitAnim | string | "fadeOut" | 请参阅animate.css 以获取选项 | 是的 | 用于隐藏通知的动画 |
flash | boolean | false | 是的 | 通知眨眼 | |
title | string | 不 | 通知的标题(仅高级) | ||
subject | string | 不 | 通知的主题 /字幕(仅高级) | ||
icon | string | 不 | 要使用的图片(仅高级) |
Config . Timeout = 5000 -- Overridden by the `timeout` param
Config . Position = " bottomleft " -- Overridden by the `position` param
Config . Progress = false -- Overridden by the `progress` param
Config . Theme = " default " -- Overridden by the `theme` param
Config . Queue = 5 -- No. of notifications to show before queueing
Config . Stacking = true
Config . ShowStackedCount = true
Config . AnimationOut = " fadeOut " -- Default exit animation - overriden by the `exitAnim` param
Config . AnimationTime = 500 -- Entry / exit animation interval
Config . FlashCount = 5 -- No. of times the notification blinks when `flash` param is used
Config . SoundFile = false -- Sound file stored in ui/audio used for notification sound. Leave as false to disable.
Config . SoundVolume = 0.4 -- 0.0 - 1.0
Config . Pictures = {
-- advanced notification icons
}
要添加您自己的自定义图片,请将64x64
jpg
映像上传到ui/images
Dimages目录,然后将自定义代码和文件名添加到Config.Pictures
表中的config.lua
中,
将my_custom_icon_image.jpg
上传到ui/images
目录,然后使用MY_CUSTOM_ICON_CODE
(no Space!)作为密钥。
Config . Pictures = {
...
MY_CUSTOM_ICON_CODE = " my_custom_icon_image.jpg " -- Add this
}
然后在“通知呼叫”中使用自定义代码:
exports . bulletin : SendAdvanced ( " Message " , " Title " , " Subject " , " MY_CUSTOM_ICON_CODE " )
您可以通过将自定义声音文件上传到ui/audio
目录并编辑配置来启用通知声音:
Config . SoundFile = ' my_notification_sound.mp3 '
Config . SoundVolume = 0.4
有效的音频文件: .mp3
, .ogg
, .wav
公告支持以下格式:
n = new line
~ r ~ = Red
~ b ~ = Blue
~ g ~ = Green
~ y ~ = Yellow
~ p ~ = Purple
~ o ~ = Orange
~ u ~ = Black
~ w ~ = White
~ h ~ = Bold Text
您也可以将HTML用于颜色:
exports . bulletin : Send ( " <span class='r'>I am red</span> and <span class='y'>I am yellow</span> " )
或您喜欢的任何HTML
exports . bulletin : Send ( " <h1>Some Title</h1><p class='paragraph'>Some text</p><footer>Some footer text</footer> " )
为了发送固定通知,您需要存储该通知的pin_id
以便稍后可以将其取消。
local pinID = exports . bulletin : SendPinned ({
type = ' advanced ' -- or 'standard'
message = ' This is pinned! '
})
然后,要取消它,只需将存储的值传递给Unpin()
方法:
exports . bulletin : Unpin ( pinID )
Unpin()
方法还接受引脚ID table
:
exports . bulletin : Unpin ({ pinned1 , pinned2 , pinned3 })
或省略参数以取消所有内容:
exports . bulletin : Unpin ()
您还可以更新固定通知的内容:
-- Send pinned notification
local pinID = exports . bulletin : SendPinned ({
type = ' advanced ' ,
message = ' This is pinned! ' ,
title = ' Title ' ,
subject = ' Subject ' ,
icon = ' CHAR_BANK_MAZE ' ,
theme = ' success '
})
-- Update it's content
exports . bulletin : UpdatePinned ( pinID , {
message = ' Updated message! ' ,
title = ' Updated title ' ,
subject = ' Updated subject ' ,
icon = ' CHAR_TREVOR ' ,
theme = ' error ' ,
flash = true
})
目前只能更新message
, title
, subject
, icon
, theme
和flash
选项。
固定通知未排队,因此,例如,如果将Config.Queue
设置为5
,并且有2
固定通知,则您将在任何时候都会获得最多7
通知。
如果您使用的是ESX
,则可以通过在es_extended/client/functions.lua
中编辑适当的函数来获取公告来覆盖bulletin
:
ESX . ShowNotification = function ( msg )
-- SetNotificationTextEntry('STRING')
-- AddTextComponentString(msg)
-- DrawNotification(0,1)
exports . bulletin : Send ( msg )
end
ESX . ShowAdvancedNotification = function ( sender , subject , msg , textureDict , iconType , flash , saveToBrief , hudColorIndex )
-- if saveToBrief == nil then saveToBrief = true end
-- AddTextEntry('esxAdvancedNotification', msg)
-- BeginTextCommandThefeedPost('esxAdvancedNotification')
-- if hudColorIndex then ThefeedNextPostBackgroundColor(hudColorIndex) end
-- EndTextCommandThefeedPostMessagetext(textureDict, textureDict, false, iconType, sender, subject)
-- EndTextCommandThefeedPostTicker(flash or false, saveToBrief)
exports . bulletin : SendAdvanced ( msg , sender , subject , textureDict )
end
公告 版权(c)2021 mobius1 该程序是免费的软件:您可以根据自由软件基金会发布的GNU通用公共许可证的条款对其进行重新分配和/或修改它,该版本是该许可证的版本3,或(按您的选项)任何以后的版本。 该程序的分布是希望它将有用的,但没有任何保修;即使没有对特定目的的适销性或适合性的隐含保证。有关更多详细信息,请参见GNU通用公共许可证。 您应该已经收到了GNU通用公共许可证的副本以及此计划。 |