红点怎么加
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-07-06 14:48:30 |
👁️ 阅读: 3
根据浮生梦老师前端课程内容,红点功能可以通过以下方式实现:
## 1. 创建红点节点
```lua
-- 首先创建一个节点作为红点容器
local redNode = GUI:Node_Create(parentNode, "Node_redtips", x, y)
-- 使用SL:CreateRedPoint创建红点
SL:CreateRedPoint(redNode)
-- 初始设置为隐藏
GUI:setVisible(redNode, false)
```
## 2. 显示/隐藏红点
```lua
-- 根据条件显示红点
GUI:setVisible(redNode, true) -- 显示红点
GUI:setVisible(redNode, false) -- 隐藏红点
-- 示例:根据服务器变量控制红点显示
local hasBidding = SL:GetMetaValue("AUCTION_HAVE_MY_BIDDING")
GUI:setVisible(redNode, hasBidding)
```
## 3. 红点与动态变量绑定
```lua
-- 通过SL:CustomAttrWidgetAdd绑定动态变量
local variableValue = "&<REDKEY/redpoint_key>&" -- 红点变量格式
SL:CustomAttrWidgetAdd(variableValue, widget) -- 绑定到控件
-- 或者使用物品数量变量
local itemCountValue = "&<TITEMCOUNT/1001>&" -- 物品ID为1001
SL:CustomAttrWidgetAdd(itemCountValue, widget)
```
## 4. 完整示例
```lua
-- 创建按钮并添加红点
local button = GUI:Button_Create(parent, "btn_test", 100, 100, "res/public/1900000612.png")
GUI:Button_setTitleText(button, "有红点的按钮")
-- 创建红点节点
local redNode = GUI:Node_Create(button, "Node_redtips", 80, 20)
SL:CreateRedPoint(redNode)
GUI:setVisible(redNode, false)
-- 点击按钮时切换红点显示
GUI:addOnClickEvent(button, function()
local isVisible = not GUI:isVisible(redNode)
GUI:setVisible(redNode, isVisible)
SL:print("红点状态:" .. (isVisible and "显示" or "隐藏"))
end)
```
## 注意事项:
1. 红点变量需要服务端配置对应支持
2. 使用`&<REDKEY/key>&`格式绑定红点变量
3. 使用`&<TITEMCOUNT/itemID>&`格式绑定物品数量变量
4. 红点创建后默认隐藏,需要根据条件手动显示
这样你就可以在界面上添加红点提示功能了。如果还有不明白的地方,随时可以问我!
← 返回问答库