local UIDyeAppearanceCurrent = UIViewClass() local EventSystem = require('Event/EventSystem') function UIDyeAppearanceCurrent:OnOpened(context) CTL.DyeAppearance.RecoverDyeRecord(self.context.appearanceId) self:RegistSystemEvent(EventID.UI_DyeAppearance_UpdateModelDye, self.OnUpdateModelDye) self:RegistSystemEvent(EventID.UI_DyeAppearance_UpdateInfo, self.OnUpdateModelDye) self:RegistSystemEvent(EventID.UI_DyeAppearance_UpdateDrawCardRed, self.UpdateToggleRed) self.colorList = {} self:InitParts() self:SetAttrs(CTL.DyeAppearance.GetTotalAttr(self.context.appearanceId), false) if context.selectPartIndex then self.toggle_TopGroup:SelectIndex(context.selectPartIndex - 1) else self.toggle_TopGroup:SelectIndex(0) end end function UIDyeAppearanceCurrent:InitParts() local idsList = { Const_IDS.IDS_CollectionAP_Part1, Const_IDS.IDS_CollectionAP_Part2, Const_IDS.IDS_CollectionAP_Part3, Const_IDS.IDS_CollectionAP_Part4 } UTL.Toggle.InitToggleGroupByIDS(self.toggle_TopGroup, "txt_Grow1", idsList) for i, v in ipairs(idsList) do self.toggle_TopGroup:SetToggleIDS(i, "txt_Grow2", v) end end function UIDyeAppearanceCurrent:UpdateToggleRed() for i = 1, CTL.DyeAppearance.PartCount do self.toggle_TopGroup:SetRedPoint(i - 1, CTL.DyeAppearance.CheckPartNoticeRed(self.context.appearanceId, i)) end self:UpdateBtnRed() end function UIDyeAppearanceCurrent:OnValueChanged(comp, index) if comp == self.toggle_TopGroup then self:OnSwitchPart(index + 1) self:UpdateToggleRed() end end function UIDyeAppearanceCurrent:OnSwitchPart(partIndex) self.selectPartIndex = partIndex self.ani_color:PlayAnim() CTL.DyeAppearance.CollectPartColorList(self.colorList, self.context.appearanceId, partIndex) local selectColor = CTL.DyeAppearance.GetPartRecordColor(partIndex) self:UpdateColorList() local index = self:GetColorCellIndex(selectColor) self:OnClickColorItem(index) end function UIDyeAppearanceCurrent:UpdateColorList() for i, v in ipairs(self.colorList) do local item = self.group_Colors[i] if item then self:SetColorItem(item, v) end end end function UIDyeAppearanceCurrent:SetColorItem(item, data) local selectColor = CTL.DyeAppearance.GetPartRecordColor(data.PartID) local isActive = MDL.DyeAppearance.IsColorActive(self.context.appearanceId, data.PartID, data.ColorID) local isDye = MDL.DyeAppearance.IsColorDye(self.context.appearanceId, data.PartID, data.ColorID) CTL.DyeAppearance.SetColorItemTemplate(item, data, isDye, false, isActive == false, false, data.ColorID == selectColor) local isRed = CTL.DyeAppearance.GetIsColorNoticeRed(data.ColorID, data.PartID, self.context.appearanceId) item.event_Click:SetRedPoint(isRed) end function UIDyeAppearanceCurrent:OnClickColorItem(index) local data = self.colorList[index] if data then EventSystem.Dispatch(EventID.UI_DyeAppearance_ChangeModelPartDye, data.PartID, data.ColorID) CTL.DyeAppearance.RemoveNoticeColor(self.context.appearanceId, data.PartID, data.ColorID) self:UpdateColorList() self:SetAttrs(data.Attr_Table, true) end end function UIDyeAppearanceCurrent:GetColorCellIndex(color) for i, v in ipairs(self.colorList) do if v.ColorID == color then return i end end return 1 end function UIDyeAppearanceCurrent:OnButtonClicked(comp) if comp == self.btn_Recover then UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_CollectionAP_Tip3, function() CTL.DyeAppearance.CollectInitColorList(CTL.DyeAppearance.GetRecordColorList(), self.context.appearanceId) MDL.DyeAppearance.SetCurColorReq(self.context.appearanceId, CTL.DyeAppearance.GetRecordColorList()) end, nil) elseif comp == self.btn_Check then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, { id = LuaConst.NoteID.DyeAppearanceColor, params = CTL.DyeAppearance.GetNoteParams(LuaConst.NoteID.DyeAppearanceColor) }) elseif comp == self.btn_Upgrade then if CTL.DyeAppearance.CheckIfUnSave(self.context.appearanceId) then local func1 = function() MDL.DyeAppearance.SetCurColorReq(self.context.appearanceId, CTL.DyeAppearance.GetRecordColorList()) CTL.DyeAppearance.TryGetDye(self.context.appearanceId) end local func2 = function() CTL.DyeAppearance.TryGetDye(self.context.appearanceId) end UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_CollectionAP_Tip4, func1, func2) else CTL.DyeAppearance.TryGetDye(self.context.appearanceId) end elseif comp == self.btn_Equip then local isAllActive = true for i, v in ipairs(CTL.DyeAppearance.GetRecordColorList()) do if MDL.DyeAppearance.IsColorActive(self.context.appearanceId, i, v) == false then isAllActive = false break end end if isAllActive == false then UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_CollectionAP_Tip5, function() MDL.DyeAppearance.SetCurColorReq(self.context.appearanceId, CTL.DyeAppearance.GetRecordColorList()) end, nil) else UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_CollectionAP_Tip2, function() MDL.DyeAppearance.SetCurColorReq(self.context.appearanceId, CTL.DyeAppearance.GetRecordColorList()) end, nil) end else for i, v in ipairs(self.group_Colors) do if v.event_Click == comp then self:OnClickColorItem(i) end end end end function UIDyeAppearanceCurrent:OnClosed() self.context.selectPartIndex = self.selectPartIndex end function UIDyeAppearanceCurrent:SetAttrs(attr, isExtra) if isExtra then self.cell_Hp.txt_extra.text = nil self.cell_Atk.txt_extra.text = nil self.cell_Defense.txt_extra.text = nil self.cell_shjc.txt_extra.text = nil end if isExtra == false then self.cell_shjc.txt_value.text = 0 end for i, v in pairs(attr) do if isExtra == false then if i == LuaConst.AttrTypeId.hplmt then self.cell_Hp.txt_value.text = v elseif i == LuaConst.AttrTypeId.atk then self.cell_Atk.txt_value.text = v elseif i == LuaConst.AttrTypeId.def then self.cell_Defense.txt_value.text = v else self.cell_shjc.txt_value.text = UTL.Attr.FormatNumberToPercentage(v, 0) end else if v.AttrType == LuaConst.AttrTypeId.hplmt then self.cell_Hp.txt_extra.text = v.AttrNum elseif v.AttrType == LuaConst.AttrTypeId.atk then self.cell_Atk.txt_extra.text = v.AttrNum elseif v.AttrType == LuaConst.AttrTypeId.def then self.cell_Defense.txt_extra.text = v.AttrNum else self.cell_shjc.txt_extra.text = UTL.Attr.FormatNumberToPercentage(v.AttrNum, 0) end end end end function UIDyeAppearanceCurrent:OnUpdateModelDye() self:SetAttrs(CTL.DyeAppearance.GetTotalAttr(self.context.appearanceId), false) self:OnSwitchPart(self.selectPartIndex) self:UpdateToggleRed() end function UIDyeAppearanceCurrent:UpdateBtnRed() self.btn_Upgrade:SetRedPoint(CTL.DyeAppearance.CheckDrawCardRed(self.context.appearanceId)) end return UIDyeAppearanceCurrent