bayuMIR/client/dev/GUILayout/game/tongyong/HuiShouOBJ.lua
2026-06-12 02:32:15 +08:00

378 lines
12 KiB
Lua

HuiShouOBJ = Up_BaseClassOBJ:new()
HuiShouOBJ.__cname = "HuiShouOBJ"
-- 配置文件
HuiShouOBJ.cfg = {}
-- UI文件
HuiShouOBJ.UIfile = "game/Tongyong/HuiShouUI"
local function getLocalStr()
local data = {}
local jsonStr = SL:GetLocalString("HuiShou")
if jsonStr and string.len(jsonStr) > 0 then
local jsonData = SL:JsonDecode(jsonStr)
if jsonData then
for k, v in pairs(jsonData or {}) do
data[tonumber(k) and tonumber(k) or k] = v
end
end
end
return data
end
HuiShouOBJ.LocalStr = getLocalStr()
function HuiShouOBJ:updata()
GUI:ListView_removeAllItems(self.ui.btn_list)
for i, v in ipairs(self.cfg or {}) do
if v[1].ClassName ~= "经验货币" then
local list_btn = string.format("list_btn_%d", i)
self.ui[list_btn] = GUI:Button_Create(self.ui.btn_list, list_btn, 0, 0,
string.format("res/custom/30/btn_%d.png", self.id == i and 2 or 3))
GUI:Button_setTitleText(self.ui[list_btn], v[1].ClassName)
GUI:Button_setTitleColor(self.ui[list_btn], "#d9d1b6")
GUI:Button_setTitleFontSize(self.ui[list_btn], 16)
GUI:Button_titleEnableOutline(self.ui[list_btn], "#000000", 2)
---* 切换按钮
GUI:addOnClickEvent(self.ui[list_btn], function()
GUI:Button_loadTextureNormal(self.ui[string.format("list_btn_%d", self.id)], "res/custom/30/btn_3.png")
self.id = i
GUI:Button_loadTextureNormal(self.ui[list_btn], "res/custom/30/btn_2.png")
self:getlist()
end)
if self.LocalStr[i] and table.nums(self.LocalStr[i]) > 0 then
local list_btn_star = string.format("list_btn_star_%d", i)
self.ui[list_btn_star] = GUI:Image_Create(self.ui[list_btn], list_btn_star, 4, 4,
"res/custom/30/star.png")
end
end
end
---* 更新金币回收倍率
local _beilv = SL:Get_CUR_ABIL_BY_ID(200) + 100
GUI:Text_setString(self.ui.Text_beilv, _beilv .. "%")
---* 一键全选控件
GUI:addOnClickEvent(self.ui.up_btn_2, function()
self:SetAll(true)
end)
---* 一键取消控件
GUI:addOnClickEvent(self.ui.up_btn_1, function()
self:SetAll(false)
end)
GUI:CheckBox_setSelected(self.ui.CheckBox_4, HuiShouOBJ.LocalStr.money and true or false)
---* 设置自动货币
GUI:CheckBox_addOnEvent(self.ui.CheckBox_4, function(CheckBox, editbox)
HuiShouOBJ.LocalStr.money = editbox == 0 and 1 or nil
SL:SetLocalString("HuiShou", SL:JsonEncode(HuiShouOBJ.LocalStr))
end)
GUI:CheckBox_setSelected(self.ui.CheckBox_3, HuiShouOBJ.LocalStr.auto and true or false)
---* 设置自动回收
GUI:CheckBox_addOnEvent(self.ui.CheckBox_3, function(CheckBox, editbox)
HuiShouOBJ.LocalStr.auto = editbox == 0 and 1 or nil
SL:SetLocalString("HuiShou", SL:JsonEncode(HuiShouOBJ.LocalStr))
end)
---* 一键回收
GUI:addOnClickEvent(self.ui.up_btn, function()
self:recycling()
end)
self:getlist()
end
---* 执行回收
function HuiShouOBJ:recycling()
---* 还原列表
if not self.item then
self.item = {}
for i, v in ipairs(self.cfg or {}) do
for zid, v in ipairs(v) do
self.item[v.Name] = v
self.item[v.Name].zid = zid
end
end
end
local cfg = self.LocalStr
local item = {}
local BAG_DATA = SL:GetMetaValue("BAG_DATA")
local bag_name_list = {}
for k, v in pairs(BAG_DATA or {}) do
local name = v.Name and v.Name or SL:GetMetaValue("ITEM_DATA_BY_MAKEINDEX", k, false).Name
local itemInfo = self.item[name]
if itemInfo then
if itemInfo.ClassName ~= "经验货币" then
if cfg[itemInfo.clssID] and cfg[itemInfo.clssID][tostring(itemInfo.zid)] then
table.insert(bag_name_list, k)
end
elseif self.LocalStr.money then
table.insert(bag_name_list, k)
end
end
end
if #bag_name_list > 0 then
ssrMessage:SubLink(self.__cname .. "_auto", bag_name_list)
end
end
SL:Schedule(function()
---* 执行自动回收
if HuiShouOBJ.LocalStr and HuiShouOBJ.LocalStr.auto then
local Bag_Count = SL:GetMetaValue("BAG_REMAIN_COUNT")
if Bag_Count < 20 then
HuiShouOBJ:recycling()
end
end
end, 1)
function HuiShouOBJ:getlist()
if not self.id then
return
end
GUI:ListView_removeAllItems(self.ui.item_list)
for i, v in ipairs(self.cfg[self.id] or {}) do
local item_list = string.format("item_list_%d", i)
self.ui[item_list] = GUI:Image_Create(self.ui.item_list, item_list, 0, 0, "res/public/bg_bti_07.png")
GUI:Image_setScale9Slice(self.ui[item_list], 5, 5, 5, 5)
GUI:setContentSize(self.ui[item_list], 568, 40)
--* 装备名
local Item_Name_Layout = string.format("Item_Name_Layout_%d", i)
self.ui[Item_Name_Layout] = GUI:Layout_Create(self.ui[item_list], Item_Name_Layout, 0, 0, 150, 40, false)
---* 背包数量
local index = 1
local bag_item_num = SL:GetMetaValue("ITEM_COUNT", v.Name)
if bag_item_num > 0 then
local bag_falg = string.format("bag_falg_%d", i)
self.ui[bag_falg] = GUI:Image_Create(self.ui[Item_Name_Layout], bag_falg, 0, 0, "res/public/1900000657.png")
GUI:setContentSize(self.ui[bag_falg], 30, 30)
GUI:Win_SetParam(self.ui[bag_falg], index)
index = index + 1
end
if v.check and v.check == 1 then
local huishou_falg = string.format("huishou_falg_%d", i)
self.ui[huishou_falg] = GUI:Image_Create(self.ui[Item_Name_Layout], huishou_falg, 0, 0,
"res/public/1900000658.png")
GUI:setContentSize(self.ui[huishou_falg], 30, 30)
GUI:Win_SetParam(self.ui[huishou_falg], index)
index = index + 1
end
local Item_bg_Layout = string.format("Item_bg_Layout_%d", i)
self.ui[Item_bg_Layout] = GUI:Layout_Create(self.ui[Item_Name_Layout], Item_bg_Layout, 0, 0,
string.len(v.Name) * 1, 40, false)
GUI:Win_SetParam(self.ui[Item_bg_Layout], index)
index = index + 1
local Item_Name = string.format("Item_Name_%d", i)
self.ui[Item_Name] = GUI:RichTextFCOLOR_Create(self.ui[Item_bg_Layout], Item_Name, 0, 20, v.Name, 180, 16,
"#9c9583", 5, nil, nil, { outlineSize = 2, SL:ConvertColorFromHexString("#FFFFFF") })
GUI:setAnchorPoint(self.ui[Item_Name], 0.00, 0.50)
GUI:UserUILayout(self.ui[Item_Name_Layout], {
dir = 2,
addDir = 2,
interval = 1,
-- gap = { x = -10 },
sortfunc = function(lists)
table.sort(lists, function(a, b)
return GUI:Win_GetParam(a) > GUI:Win_GetParam(b)
end)
end
})
---* 回收奖励
local gives = {}
for _, givs in ipairs(v.Gives or {}) do
table.insert(gives, string.format("%sx%d", givs[1], givs[2]))
end
local give_str = table.concat(gives, "")
if v.RandomGivesName then
local _str = {}
for _, givs in ipairs(v.RandomGivesName or {}) do
table.insert(_str, string.format("%sx%d", givs[1], givs[2]))
end
give_str = table.concat(_str, "")
end
if v.GivesRandomNum then
local _str = {}
for _, givs in ipairs(v.GivesRandomNum or {}) do
table.insert(_str, string.format("%sx(%d-%d随机)", givs[1], givs[2], givs[3]))
end
give_str = table.concat(_str, "")
end
local list_gives = string.format("list_gives_%d", i)
self.ui[list_gives] = GUI:RichTextFCOLOR_Create(self.ui[item_list], list_gives, 326, 20, give_str, 220, 16,
"#9c9583", 5, nil, nil, { outlineSize = 2, SL:ConvertColorFromHexString("#FFFFFF") })
GUI:setAnchorPoint(self.ui[list_gives], 0.50, 0.50)
---* 勾选
local list_checkbox = string.format("list_checkbox_%d", i)
self.ui[list_checkbox] = GUI:CheckBox_Create(self.ui[item_list], list_checkbox, 522, 20, "res/custom/30/1.png",
"res/custom/30/2.png")
GUI:setAnchorPoint(self.ui[list_checkbox], 0.50, 0.50)
local _bool = self:GetItemInfo(i)
GUI:CheckBox_setSelected(self.ui[list_checkbox], _bool)
GUI:CheckBox_addOnEvent(self.ui[list_checkbox], function(CheckBox, editbox)
self:SetItemInfo(i, editbox)
end)
end
end
---* 获取item是否勾选
---HuiShouOBJ.LocalStr
function HuiShouOBJ:GetItemInfo(id)
if not HuiShouOBJ.LocalStr[self.id] then
return false
end
if not HuiShouOBJ.LocalStr[self.id][tostring(id)] then
return false
else
return true
end
end
HuiShouOBJ.setcheck = {
[1] = function()
if (tonumber(SL:GetMetaValue("SERVER_VALUE", "{2}")) or 0) == 0 then
hk.sendmsg("此物品需要#251|开通王者特权#215|才可回收!")
return false
else
return true
end
end
}
---* 设置单物品勾选
function HuiShouOBJ:SetItemInfo(id, editbox)
if not HuiShouOBJ.LocalStr[self.id] then
HuiShouOBJ.LocalStr[self.id] = {}
end
if editbox == 0 then
local cfg = self.cfg[self.id][id]
if cfg.check then
local func = self.setcheck[cfg.check]
if func then
local _bool = func()
if not _bool then
local list_checkbox = string.format("list_checkbox_%d", id)
GUI:CheckBox_setSelected(self.ui[list_checkbox], false)
return
end
end
end
if not HuiShouOBJ.LocalStr[self.id][tostring(id)] then
HuiShouOBJ.LocalStr[self.id][tostring(id)] = {}
end
HuiShouOBJ.LocalStr[self.id][tostring(id)] = 1
if table.nums(HuiShouOBJ.LocalStr[self.id]) > 0 then
local list_btn_star = string.format("list_btn_star_%d", self.id)
if GUI:Win_IsNull(self.ui[list_btn_star]) then
local list_btn = string.format("list_btn_%d", self.id)
self.ui[list_btn_star] = GUI:Image_Create(self.ui[list_btn], list_btn_star, 4, 4,
"res/custom/30/star.png")
end
end
elseif editbox == 1 then
HuiShouOBJ.LocalStr[self.id][tostring(id)] = nil
if not HuiShouOBJ.LocalStr[self.id] or table.nums(HuiShouOBJ.LocalStr[self.id]) == 0 then
local list_btn_star = string.format("list_btn_star_%d", self.id)
if GUI:Win_IsNotNull(self.ui[list_btn_star]) then
GUI:removeFromParent(self.ui[list_btn_star])
end
end
end
end
---* 设置一键全选/取消
function HuiShouOBJ:SetAll(bool)
for i, v in ipairs(self.cfg[self.id] or {}) do
local list_checkbox = string.format("list_checkbox_%d", i)
GUI:CheckBox_setSelected(self.ui[list_checkbox], bool)
self:SetItemInfo(i, bool and 0 or 1)
end
end
---* 注册事件
function HuiShouOBJ:EventBind()
local function HuiShouOBJ_Var_Change(data)
if GUI:Win_IsNotNull(self._parent) then
if data.key == "HUMAN(STR_九秘等级)" then
self:GetInfo()
end
if data.key == "HUMAN(STR_九秘BUFF)" then
self:GetBuff()
end
end
end
SL:RegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname, HuiShouOBJ_Var_Change, self._parent)
--关闭窗口
SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname, function(widgetName)
self:OnClose(widgetName)
end)
end
--关闭窗口
function HuiShouOBJ:OnClose(widgetName)
if widgetName == self.__cname then
self:UnRegisterEvent()
end
end
function HuiShouOBJ:UnRegisterEvent()
SL:SetLocalString("HuiShou", SL:JsonEncode(HuiShouOBJ.LocalStr))
SL:UnRegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname)
SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname)
end
return HuiShouOBJ