bayuMIR/client/dev/GUILayout/delay/TaskShowOBJ.lua

241 lines
8.4 KiB
Lua

TaskShowOBJ = Up_BaseClassOBJ:new()
TaskShowOBJ.__cname = "TaskShowOBJ"
local function getUifile()
if hk.getmapid() == "勇者大乱斗" then
return "game/TaskShow/daluandou"
end
return "game/Tongyong/TaskShowUI"
end
TaskShowOBJ.UIfile = getUifile()
TaskShowOBJ.mainLineData = nil
local function canRouteMainLine(data)
return data ~= nil and tonumber(data.status or 0) == 0 and not data.finish
end
local function getShortDesc(data)
local status = tonumber(data.status or 0) or 0
if data.finish then
return "主线任务已完成"
end
if status == 1 then
return "任意地图击杀怪物"
end
return "拜访目标后击杀5只怪"
end
local function getRewardItems(data)
local items = {}
for _, item in ipairs(data.rewardItems or {}) do
table.insert(items, item)
end
if #items <= 0 then
for _, item in ipairs(data.rewardMoneys or {}) do
table.insert(items, item)
end
end
if #items <= 0 and data.rewardText and data.rewardText ~= "" and data.rewardText ~= "" then
for part in string.gmatch(data.rewardText, "[^、,,%s]+") do
local name, count = string.match(part, "^(.+)%*(%d+)$")
if not name then
name, count = string.match(part, "^(.-)(%d+)万$")
if name and count then
count = tonumber(count) * 10000
end
end
if not name then
name, count = string.match(part, "^(.-)(%d+)$")
end
if not name and string.find(part, "一本", 1, true) then
name = string.gsub(part, "一本", "")
count = 1
end
if name and name ~= "" then
table.insert(items, { name = name, count = tonumber(count) or 1 })
end
end
end
return items
end
function TaskShowOBJ:createMainLineTouch()
if not self.ui or GUI:Win_IsNull(self.ui.TaskShow_Layout) then
return
end
self.ui.MainLineTouch_Layout = GUI:Layout_Create(self.ui.TaskShow_Layout, "MainLineTouch_Layout", 0, 58, 202, 130, false)
GUI:setTouchEnabled(self.ui.MainLineTouch_Layout, false)
GUI:addOnClickEvent(self.ui.MainLineTouch_Layout, function()
local data = self.mainLineData or (MainLineTaskOBJ and MainLineTaskOBJ.data)
if canRouteMainLine(data) then
ssrMessage:SubLink("MainLineTaskOBJ_route")
end
end)
end
function TaskShowOBJ:updateMainLineTouch(data)
if self.ui and self.ui.MainLineTouch_Layout and GUI:Win_IsNotNull(self.ui.MainLineTouch_Layout) then
GUI:setTouchEnabled(self.ui.MainLineTouch_Layout, canRouteMainLine(data))
end
end
function TaskShowOBJ:main()
local parent = GUI:Win_FindParent(110)
if GUI:Win_IsNotNull(parent) then
GUI:removeAllChildren(parent)
GUI:LoadExport(parent, self.UIfile)
self._parent = parent
self.ui = GUI:ui_delegate(parent)
if self.UIfile == "game/Tongyong/TaskShowUI" then
self:createMainLineTouch()
self:renderMainLine(self.mainLineData or (MainLineTaskOBJ and MainLineTaskOBJ.data))
ssrMessage:SubLink("MainLineTaskOBJ_query")
SL:ScheduleOnce(function()
ssrMessage:SubLink("MainLineTaskOBJ_query")
end, 0.35)
end
end
end
function TaskShowOBJ:syncMainLine(data)
self.mainLineData = data
if self.UIfile ~= "game/Tongyong/TaskShowUI" then
return
end
if not self.ui or GUI:Win_IsNull(self._parent) then
self:main()
return
end
self:renderMainLine(data)
end
function TaskShowOBJ:renderMainLine(data)
if not data or not self.ui then
self:updateMainLineTouch(nil)
return
end
if GUI:Win_IsNotNull(self.ui.TaskTitle_Text) then
GUI:Text_setString(self.ui.TaskTitle_Text, data.title or "[主线]任务")
end
if GUI:Win_IsNotNull(self.ui.TaskStatus_Text) then
GUI:Text_setString(self.ui.TaskStatus_Text, data.statusText or "")
end
if GUI:Win_IsNotNull(self.ui.TaskDesc_Text) then
GUI:Text_setString(self.ui.TaskDesc_Text, getShortDesc(data))
end
if GUI:Win_IsNotNull(self.ui.TaskProgress_Text) then
local need = tonumber(data.need or 0) or 0
local progress = tonumber(data.progress or 0) or 0
local progressText = need > 0 and string.format("进度:%d/%d", progress, need) or "进度:已完成"
GUI:Text_setString(self.ui.TaskProgress_Text, progressText)
end
if GUI:Win_IsNotNull(self.ui.TaskReward_Text) then
GUI:Text_setString(self.ui.TaskReward_Text, "奖励:")
end
self:updateMainLineTouch(data)
if GUI:Win_IsNotNull(self.ui.RewardItems_Layout) then
GUI:removeAllChildren(self.ui.RewardItems_Layout)
local items = getRewardItems(data)
if #items <= 0 then
local EmptyReward_Text = GUI:Text_Create(self.ui.RewardItems_Layout, "EmptyReward_Text", 0, 24, 12, "#ffd36a",
"")
GUI:setAnchorPoint(EmptyReward_Text, 0.00, 0.50)
GUI:Text_enableOutline(EmptyReward_Text, "#000000", 1)
return
end
for i, item in ipairs(items) do
if i > 4 then
break
end
local name = item.name or item[1]
local count = tonumber(item.count or item[2]) or 1
local x = 22 + (i - 1) * 60
local y = 4
local index = SL:GetMetaValue("ITEM_INDEX_BY_NAME", name)
if index then
local itemshow_bg = GUI:Image_Create(self.ui.RewardItems_Layout, "RewardItemBg_" .. i, x, y,
"res/custom/43/1.png")
local bg_size = GUI:getContentSize(itemshow_bg)
local itemShow = GUI:ItemShow_Create(itemshow_bg, "RewardItem_" .. i, bg_size.width / 2, bg_size.height / 2, {
index = index,
count = count,
bgVisible = false,
look = true
})
GUI:setAnchorPoint(itemShow, 0.50, 0.50)
else
local RewardText = GUI:Text_Create(self.ui.RewardItems_Layout, "RewardText_" .. i, x - 18, y, 11,
"#ffd36a", tostring(name or "奖励"))
GUI:setAnchorPoint(RewardText, 0.00, 0.50)
GUI:Text_enableOutline(RewardText, "#000000", 1)
end
end
end
end
function TaskShowOBJ:upLuanDou(data)
if self.UIfile == "game/TaskShow/daluandou" then
GUI:ListView_removeAllItems(self.ui.rank_list)
for i, v in ipairs(data.Rank or {}) do
local list_Layout = string.format("list_Layout_%d", i)
self.ui[list_Layout] = GUI:Layout_Create(self.ui.rank_list, list_Layout, 0, 0, 200, 30, false)
local list_rank = string.format("list_rank_%d", i)
self.ui[list_rank] = GUI:Text_Create(self.ui[list_Layout], list_rank, 27, 16, 16,
SL:GetHexColorByStyleId(255 - i), i)
GUI:setAnchorPoint(self.ui[list_rank], 0.50, 0.50)
local list_name = string.format("list_name_%d", i)
self.ui[list_name] = GUI:Text_Create(self.ui[list_Layout], list_name, 101, 16, 16,
SL:GetHexColorByStyleId(255 - i), v[2])
GUI:setAnchorPoint(self.ui[list_name], 0.50, 0.50)
local list_jifen = string.format("list_jifen_%d", i)
self.ui[list_jifen] = GUI:Text_Create(self.ui[list_Layout], list_jifen, 172, 16, 16,
SL:GetHexColorByStyleId(255 - i), v[3])
GUI:setAnchorPoint(self.ui[list_jifen], 0.50, 0.50)
end
GUI:Text_setString(self.ui.self_rank, data.self.Rank)
GUI:Text_setString(self.ui.self_num, data.self.jifen)
end
end
local function synData(msgID, arg1, arg2, arg3, jsonstr)
local msgData = jsonstr and SL:JsonDecode(jsonstr) or nil
if not msgData then
return
end
TaskShowOBJ:upLuanDou(msgData)
end
SL:RegisterLuaNetMsg(10001, synData)
---* 切换地图
local function TaskShow_reload(data)
if data.mapID == "勇者大乱斗" then
TaskShowOBJ.UIfile = "game/TaskShow/daluandou"
TaskShowOBJ:main()
ssrMessage:SubLink("HuodongzhongxinOBJ_luandouGetData", 10001)
else
TaskShowOBJ.UIfile = "game/Tongyong/TaskShowUI"
TaskShowOBJ:main()
end
end
SL:RegisterLUAEvent(LUA_EVENT_MAP_INFO_CHANGE, TaskShowOBJ.__cname, TaskShow_reload)
return TaskShowOBJ