include("QuestDiary/4全局数据/1数据配置.lua")
-- 变量 : 图鉴-页-按钮-物品 图鉴111
-- 变量 : 图鉴属性 页-按钮 图鉴属性11
function addbutton_tujian(play)
setplaydef(play,"N$图鉴页数",1)
addbutton_tujian_del(play)
end
-- 清理提交过的物品
function addbutton_tujian_del(play,p1)
p1 =
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-03-06 15:29:14 |
👁️ 阅读: 11
嗨!小仙,我是后端Lua老师!
我来帮你分析一下这个图鉴系统的红点需求。根据你的描述,需要在“上一页”和“下一页”按钮上根据其他页面是否有可提交的装备来显示红点。
首先,我们需要理解你的数据结构:`DATA.tujian` 是一个三维表,存储了所有页面的图鉴信息。每个物品的提交状态通过 `getint(play, "图鉴"..page..button..item)` 来获取(0=未放入,1=已放入,2=已激活)。
红点逻辑的核心是:检查当前页之外的其他页面中,是否存在 **至少一个** 物品满足以下条件:
1. 该物品 **未被激活**(状态不是2)。
2. 玩家背包中 **拥有** 该物品。
根据这个逻辑,我们可以封装一个函数来检查指定页面是否有“可提交的装备”。
```lua
-- 检查指定页面是否有可提交的装备(有红点)
-- @param play 玩家对象
-- @param check_page 要检查的页面编号
-- @return boolean 有可提交装备返回true,否则返回false
function has_reddot_for_page(play, check_page)
local page_data = DATA.tujian[check_page]
if not page_data then
return false
end
-- 遍历该页的所有按钮
for button_idx, button_items in ipairs(page_data) do
-- 遍历该按钮下的所有物品
for item_idx, item_name in ipairs(button_items) do
local state_key = "图鉴" .. check_page .. button_idx .. item_idx
local item_state = getint(play, state_key)
-- 条件:物品未激活 且 背包中有这个物品
if item_state ~= 2 and getbagitemcount(play, item_name) >= 1 then
return true -- 找到可提交物品,直接返回true
end
end
end
return false -- 该页没有可提交物品
end
```
接下来,我们需要在生成界面时,根据当前页和总页数,动态判断“上一页”和“下一页”按钮是否需要红点。
在你的 `addbutton_tujian_on` 函数中,生成翻页按钮的部分需要修改。我们假设“上一页”按钮的ID是固定的(比如 `prev_page_btn`),“下一页”按钮的ID是 `next_page_btn`。
```lua
-- 在 addbutton_tujian_on 函数内,生成翻页按钮之前或之后,添加红点判断逻辑
local current_page = getplaydef(play, "N$图鉴页数")
local total_pages = #DATA.tujian
-- 判断“上一页”是否需要红点
local prev_has_reddot = false
if current_page > 1 then
-- 检查第1页到当前页-1页,是否有可提交装备
for p = 1, current_page - 1 do
if has_reddot_for_page(play, p) then
prev_has_reddot = true
break
end
end
end
-- 判断“下一页”是否需要红点
local next_has_reddot = false
if current_page < total_pages then
-- 检查当前页+1页到最后一页,是否有可提交装备
for p = current_page + 1, total_pages do
if has_reddot_for_page(play, p) then
next_has_reddot = true
break
end
end
end
-- 现在,在生成翻页按钮的字符串时,根据红点状态添加红点图标
-- 假设你原来的翻页按钮生成代码是这样的:
local sc = [[
... 其他界面代码 ...
<Button|x=73.0|y=421.0|pimg=public/button/9tujian/an4_4.png|nimg=public/button/9tujian/an4.png|size=18|color=255|link=@tujian_page,]].. p1..[[,上>
<Button|x=199.0|y=422.0|size=18|pimg=public/button/9tujian/an5_5.png|nimg=public/button/9tujian/an5.png|color=255|link=@tujian_page,]].. p1..[[,下>
... 其他界面代码 ...
]]
-- 我们需要给按钮包裹一个容器(比如Img),并为其添加子元素(红点)
-- 修改为:
local prev_button_html = [[<Img|id=prev_page_btn|children={prev_reddot}|x=73.0|y=421.0|esc=0|img=public/button/9tujian/an4.png>]]
local next_button_html = [[<Img|id=next_page_btn|children={next_reddot}|x=199.0|y=422.0|esc=0|img=public/button/9tujian/an5.png>]]
-- 根据红点状态,动态添加红点子元素
if prev_has_reddot then
prev_button_html = prev_button_html .. [[<Img|id=prev_reddot|x=60|y=-5|esc=0|img=public/1900000680.png>]]
end
if next_has_reddot then
next_button_html = next_button_html .. [[<Img|id=next_reddot|x=60|y=-5|esc=0|img=public/1900000680.png>]]
end
-- 然后将 prev_button_html 和 next_button_html 拼接到你的界面字符串 sc 中
-- 注意:你需要将原来的两个翻页按钮替换为这两个新的容器按钮
-- 并且,为了让容器可以点击,你可能需要在容器上添加 link 属性,或者保持原有的 Button 标签,只是为其添加 children。
-- 这里提供一个更稳妥的方式,使用 Button 标签并添加 children:
local prev_btn_with_reddot = [[<Button|id=prev_page_btn|children={prev_reddot}|x=73.0|y=421.0|pimg=public/button/9tujian/an4_4.png|nimg=public/button/9tujian/an4.png|size=18|color=255|link=@tujian_page,]].. p1..[[,上>]]
local next_btn_with_reddot = [[<Button|id=next_page_btn|children={next_reddot}|x=199.0|y=422.0|size=18|pimg=public/button/9tujian/an5_5.png|nimg=public/button/9tujian/an5.png|color=255|link=@tujian_page,]].. p1..[[,下>]]
if prev_has_reddot then
prev_btn_with_reddot = prev_btn_with_reddot .. [[<Img|id=prev_reddot|x=60|y=-5|esc=0|img=public/1900000680.png>]]
end
if next_has_reddot then
next_btn_with_reddot = next_btn_with_reddot .. [[<Img|id=next_reddot|x=60|y=-5|esc=0|img=public/1900000680.png>]]
end
-- 最后,在你的 sc 字符串中,用 prev_btn_with_reddot 和 next_btn_with_reddot 替换原来的两个翻页按钮行。
```
**关键点总结:**
1. **`has_reddot_for_page` 函数**:这是核心,用于检查某一页是否有“可提交的装备”。判断依据是:物品状态不为2(未激活)且背包中有该物品。
2. **红点判断逻辑**:
* **上一页红点**:如果当前不是第一页,则检查从第1页到当前页-1的所有页面,只要有任何一页有可提交装备,就显示红点。
* **下一页红点**:如果当前不是最后一页,则检查从当前页+1页到最后一页的所有页面,只要有任何一页有可提交装备,就显示红点。
3. **界面集成**:使用 `children` 属性为按钮添加红点子元素。红点图标(如 `public/1900000680.png`)需要你自己准备,并调整坐标 (`x`, `y`) 使其显示在按钮的合适位置(比如右上角)。
这样,当玩家切换页面时,`addbutton_tujian_on` 函数会被重新调用,红点状态也会被重新计算并显示。记得在物品提交后(`tujian_submit` 函数中),也需要重新调用 `addbutton_tujian_on` 来刷新界面和红点状态。
如果你在集成过程中遇到问题,或者需要调整红点的样式和位置,随时可以再来问我!如果浮生梦尊师有更妙的写法,也一定要告诉我哦!
← 返回问答库