local UICheatPanel = UIViewClass() local CommandPrefixByte = string.byte('#') local CheatConfig = require("Modules/Cheat/CheatConfig"); local EventSystem = require('Event/EventSystem') local CMDExcuteFormation = "%s %s" function UICheatPanel:OnOpened() self:RegistSystemEvent(EventID.UI_LuaConsole_Refresh_Attr, self.UILuaConsoleRefresh) self:RegistSystemEvent(EventID.UI_CheatReplay_RefreshList, self.RefreshReplayList) self.text_desc.text = CheatConfig.DESC_CONTENT; self.env = {} self.env.print = function(...) self:NewPrint(...) end setmetatable(self.env, { __index = _G }) self.tgl_auto_close.isOn = false self.tabGroup:SelectIndex(1) end function UICheatPanel:OnValueChanged(comp, value) if self.tabGroup == comp then UIUtils.SetActive(self.group_show, false) UIUtils.SetActive(self.group_help, value == 0) UIUtils.SetActive(self.group_cheat, value == 1) UIUtils.SetActive(self.group_console, value == 2) UIUtils.SetActive(self.group_replay, value == 3) if value == 1 then self.obj_LeftScroll_cheat:ClearCells() self.obj_RightScroll_cheat:ClearCells() for __, v in pairs(CheatConfig.ViewGroupTypeIndex) do -- 判断登录状态 local data = CheatConfig.ViewGroupType[v] if not NetManager.IsLaunch() or not CheatConfig.ViewGroupTypeDependLogin[data] then self.obj_LeftScroll_cheat:AddData(data, 0) end end self.obj_LeftScroll_cheat:SelectIndex(0) elseif value == 2 then self.LoopOutPrint:ClearCells() elseif value == 3 then self.obj_LeftScroll_replay:ClearCells() self.obj_RightScroll_replay:ClearCells() for _, v in pairs(CheatConfig.ReplayGroupIndex) do local data = CheatConfig.ReplayGroupType[v] if not NetManager.IsLaunch() then self.obj_LeftScroll_replay:AddData({ v, data }, 0) end end self.obj_LeftScroll_replay:SelectIndex(3) end end end function UICheatPanel:NewPrint(...) local count = select('#', ...) local content = "" for i = 1, count do content = content .. tostring(select(i, ...)) end self.LoopOutPrint:AddData(content, 0) end function UICheatPanel:UILuaConsoleRefresh(type, data) self.obj_RightScroll_cheat:ClearCells() UIUtils.SetActive(self.group_show, true) self.text_show.text = nil if type == 1 then --buff local result = {} local curBuffObjectList = data local content = {} local str for i, buffObject in ipairs(curBuffObjectList) do local buffID = buffObject.BuffID local buffUpdateData = buffObject.BuffUpdateData local buffUpdateList = buffObject.BuffUpdateList if buffUpdateData and buffUpdateData.BuffLayer > 0 then table.insert(result, buffID) str = buffID .. '\n' .. 'Layer: ' .. buffUpdateData.BuffLayer .. '\n' str = str .. 'BuffTime: ' .. buffUpdateData.BuffTimer[1] .. '\n' if buffUpdateData.IsRecordSource and buffUpdateData.SourceEntity ~= nil then str = str .. 'EntityRevive: ' .. buffUpdateData.SourceEntity.Event_EntityRevive .. '\n' end end table.insert(content, str) if buffUpdateList then for i, updateData in ipairs(buffUpdateList) do if updateData.BuffLayer > 0 then table.insert(result, buffID) str = str .. buffID .. '\n' .. 'Layer: ' .. updateData.BuffLayer .. '\n' str = str .. 'BuffTime: ' .. updateData.BuffTimer .. '\n' table.insert(content, str) end end end end for i, v in ipairs(content) do self.text_show.text = self.text_show.text .. v end elseif type == 2 then --武将属性 local str = '' local index = 0 for i, v in pairs(data) do index = index + 1 str = str .. i .. '=' .. v .. ' ' if index % 2 == 0 then str = str .. '\n' end end self.text_show.text = str end end function UICheatPanel:InitMutilArgsCells(cellTable, data, argsData) data.cellIndex = 1 -- 内部滑动列表的cellIndex (不是对应参数,因为一个参数可能对应多个cell) data.contentCount = #cellTable.Content -- 当前content已有的cellObj数量 data.contentMaxIndex = 1 -- 当前已遍历的content的最大index data.contentDic = {} -- k是cellIndex,v是实际对应content的cellObj index for _, v in ipairs(cellTable.Content) do UIUtils.SetActive(v.gameObject, false) end for i,v in pairs(argsData) do if v.showType == CheatConfig.ShowType.InputField then self:InitCellArgInputField(cellTable, data) elseif v.showType == CheatConfig.ShowType.DropDown then self:InitCellArgDropDown(v, cellTable, data) end end end function UICheatPanel:InitCellArgInputField(cellTable, data) for i = data.contentMaxIndex, data.contentCount do if cellTable.Content[i].InputFieldValue then data.contentDic[data.cellIndex] = i data.contentMaxIndex = i+1 UIUtils.SetActive(cellTable.Content[i].gameObject, true) cellTable.Content[i].InputFieldValue.text = "" data.cellIndex = data.cellIndex + 1 return end end local inputFieldTmp = self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.Content, self.InputFieldTemp.gameObject) UIUtils.SetActive(inputFieldTmp.gameObject, true) data.contentDic[data.cellIndex] = #cellTable.Content data.cellIndex = data.cellIndex + 1 end function UICheatPanel:InitCellArgDropDown(argdata, cellTable, data) if not data.drowDownValueData then data.drowDownValueData = {} -- 列表显示的values(数据源) end if not data.drowDownValues then data.drowDownValues = {} -- 当前选中的显示value end if not data.dropDownDatas then data.dropDownDatas = {} -- 当前选中的data end if not data.drowDownNextNum then data.drowDownNextNum = {} -- dropdown组下级个数 end local cheatData = argdata.getDropDownValuesFunc() local dropdownCount = #cheatData local dropDown for i = 1, dropdownCount do data.drowDownValueData[data.cellIndex] = cheatData[i] local oldDropDown = false for j = data.contentMaxIndex, data.contentCount do if cellTable.Content[j].Dropdown then dropDown = cellTable.Content[j] data.contentDic[data.cellIndex] = j data.contentMaxIndex = j + 1 UIUtils.SetActive(dropDown.gameObject, true) oldDropDown = true break end end if not oldDropDown then dropDown = self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.Content, self.DropdownTemp.gameObject) UIUtils.SetActive(dropDown.gameObject, true) data.contentDic[data.cellIndex] = #cellTable.Content end if i == 1 then if cheatData[i].dropDownValue then data.drowDownValues[data.cellIndex] = cheatData[i].dropDownValue[1] data.dropDownDatas[data.cellIndex] = cheatData[i].dropDownData[1] UIUtils.DropdownAddOptions(dropDown.Dropdown, cheatData[i].dropDownValue) else data.drowDownValues[data.cellIndex] = cheatData[i][1] UIUtils.DropdownAddOptions(dropDown.Dropdown, cheatData[i]) end else local dropData = cheatData[i][data.drowDownValues[data.cellIndex-1]] if dropData.dropDownValue then data.drowDownValues[data.cellIndex] = dropData.dropDownValue[1] data.dropDownDatas[data.cellIndex] = dropData.dropDownData[1] UIUtils.DropdownAddOptions(dropDown.Dropdown, dropData.dropDownValue) else data.drowDownValues[data.cellIndex] = dropData[1] UIUtils.DropdownAddOptions(dropDown.Dropdown, dropData) end end data.drowDownNextNum[data.cellIndex] = dropdownCount-i; data.cellIndex = data.cellIndex + 1 end end function UICheatPanel:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.obj_LeftScroll_cheat then cellTable.label.text = data elseif scrollRect == self.LoopOutPrint then UIUtils.SetLabel(cellTable.outPrint:GetComponent(typeof(LocalizationText)), data) elseif scrollRect == self.obj_RightScroll_cheat then local argsData = CheatConfig.CheatCmdArgsData[data.commandName] if argsData then self:InitMutilArgsCells(cellTable, data, argsData) cellTable.InputFieldValue.text = '' else UIUtils.SetActive(cellTable.group_Input, #data.argTypes > 0) local defArg = "" if #data.argDefValues > 0 then local index = 0 for i = 1, #data.argDefValues do local tn = type(data.argDefValues[i]) if tn == 'number' or tn == 'string' then if index == 0 then defArg = data.argDefValues[i] else defArg = defArg .. " " .. data.argDefValues[i] end index = index + 1 end end end cellTable.InputFieldValue.text = defArg end cellTable.lab_CmdName.text = data.commandName; cellTable.lab_CmdDesc.text = CTL.Cheat.GetCommandCfgData(data.commandName).desc cellTable.lab_ArgDesc.text = table.concat(data.argDescriptions, ' '); elseif scrollRect == self.obj_LeftScroll_replay then cellTable.label.text = data[2] elseif scrollRect == self.obj_RightScroll_replay then cellTable.labDesc.text = string.format("第 %s 场,文件大小 %s byte", index + 1, data.size) cellTable.labNum.text = string.format("%s 人", data.playerNum) end end function UICheatPanel:OnCellValueChanged(scrollRect, index, cellTable, target, value) local data = scrollRect:GetCellDataByIndex(index) if scrollRect == self.obj_RightScroll_cheat then if target == cellTable.InputFieldValue then return end for i = 1, #cellTable.Content do if cellTable.Content[i].Dropdown == target then local cellIndex for index, cellObjIndex in ipairs(data.contentDic) do if i == cellObjIndex then cellIndex = index break end end --第一个dropDown if not data.drowDownNextNum[cellIndex-1] or data.drowDownNextNum[cellIndex-1] == 0 then local dropData = data.drowDownValueData[cellIndex] if dropData.dropDownValue then data.drowDownValues[cellIndex] = dropData.dropDownValue[value+1] data.dropDownDatas[cellIndex] = dropData.dropDownData[value+1] else data.drowDownValues[cellIndex] = dropData[value+1] end else local index = data.contentDic[cellIndex-1] local dropData = data.drowDownValueData[i][data.drowDownValues[index]] if dropData.dropDownValue then data.drowDownValues[cellIndex] = dropData.dropDownValue[value+1] data.dropDownDatas[cellIndex] = dropData.dropDownData[value+1] else data.drowDownValues[cellIndex] = dropData[value+1] end end self:CheckMultiDropDownChanged(data, cellIndex, cellTable) cellTable.InputFieldValue.text = self:JointCmdValue(cellTable, data) break elseif cellTable.Content[i].InputFieldValue == target then cellTable.InputFieldValue.text = self:JointCmdValue(cellTable, data) break end end end end -- 检查单参数多dropDown function UICheatPanel:CheckMultiDropDownChanged(data, cellIndex, cellTable) local count = data.drowDownNextNum[cellIndex] if count == 0 then return end for i = cellIndex + 1, cellIndex + count do local dropData = data.drowDownValueData[i][data.drowDownValues[i-1]] if dropData.dropDownValue then data.drowDownValues[i] = dropData.dropDownValue[1] data.dropDownDatas[i] = dropData.dropDownData[1] UIUtils.DropdownAddOptions(cellTable.Content[data.contentDic[i]].Dropdown, dropData.dropDownValue) else data.drowDownValues[i] = dropData[1] UIUtils.DropdownAddOptions(cellTable.Content[data.contentDic[i]].Dropdown, data) end end end function UICheatPanel:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.obj_LeftScroll_cheat then if data == CheatConfig.ViewGroupType.ViewAssets then self:CloseView() UIManager.OpenView(Const_UI_Lua.UIEnum.UIViewAssets) return end UIUtils.SetActive(self.group_show, false) UIUtils.SetActive(self.group_console, false) local list = CTL.Cheat.GetCommandsByGroup(data) self.obj_RightScroll_cheat:ClearCells() for i,v in ipairs(list) do local argsShowType = CheatConfig.CheatCmdArgsData[v.commandName] if argsShowType then self.obj_RightScroll_cheat:AddData(v, 1) else self.obj_RightScroll_cheat:AddData(v, 0) end end elseif scrollRect == self.obj_RightScroll_cheat then if target == cellTable.BtnGet then local excuteCmdStr if #data.argTypes == 0 then excuteCmdStr = data.commandName else if not string.isNilOrEmpty(cellTable.InputFieldValue.text) then excuteCmdStr = string.format(CMDExcuteFormation, data.commandName, cellTable.InputFieldValue.text) else excuteCmdStr = string.format(CMDExcuteFormation, data.commandName, self:JointCmdValue(cellTable, data)) end end MDL.Cheat.Send(excuteCmdStr) if self.tgl_auto_close.isOn then self:CloseView() end end elseif scrollRect == self.obj_LeftScroll_replay then UIUtils.SetActive(self.group_show, false) UIUtils.SetActive(self.group_console, false) self.type = MDL.Unlock.FunctionType[data[1]] MDL.Replay.NoticeC2GImportantBattle(self.type) --请求观战列表 elseif scrollRect == self.obj_RightScroll_replay then if target == cellTable.BtnGet then local diyReplayId = string.split(data.url, "/") diyReplayId = diyReplayId[#diyReplayId] -- 服务器没有对这里设置key的逻辑,先这么搞一个临时key,也能全局唯一 MDL.Replay.C2GFairPlayReplayReq(self.type, diyReplayId, data.url, true) CTL.Cheat.ResetFakeInfo() end end end --获得观战列表 function UICheatPanel:RefreshReplayList(list) self.obj_RightScroll_replay:ClearCells() if list and #list > 0 then for _, v in ipairs(list) do self.obj_RightScroll_replay:AddData(v, 0) end end end -- 拼接cmd值 function UICheatPanel:JointCmdValue(cellTable, data) local result = '' local argsData = CheatConfig.CheatCmdArgsData[data.commandName] if not argsData then return result end local index = 1 for _, argdata in pairs(argsData) do if argdata.showType == CheatConfig.ShowType.InputField then result = result .. " ".. cellTable.Content[data.contentDic[index]].InputFieldValue.text index = index + 1 elseif argdata.showType == CheatConfig.ShowType.DropDown then local cheatData = argdata.getDropDownValuesFunc() local dropdownCount = #cheatData local drowDownIndex = index + dropdownCount-1 result = result .. " ".. argdata.getArgCmdValueFunc(data.drowDownValues[drowDownIndex], data.dropDownDatas[drowDownIndex], drowDownIndex) index = index + dropdownCount end end return result end function UICheatPanel:ExecuteConsole() local luaChunk = self.InputField.text if string.byte(luaChunk) == CommandPrefixByte then local cmdStr = string.sub(luaChunk, 2) MDL.Cheat.Send(cmdStr) else local func, msg = load(luaChunk, nil, nil, self.env) if func == nil then self:NewPrint(msg) else func() end end end function UICheatPanel:OnButtonClicked(comp) if comp == self.bottom then self:CloseView() elseif comp == self.excute_button then self:ExecuteConsole() if self.tgl_auto_close.isOn then self:CloseView() end end end return UICheatPanel