local UIDyeAppearancePrizeWheel = UIViewClass() local EventSystem = require('Event/EventSystem') local Anim_Rate_Normal = 0.05 local Anim_Rate_Slow = 0.5 local Anim_Loop_Circle = 3 local Anim_Slow_Count = 4 ---抽卡表现逻辑 ---从上一个抽中的色卡按正常速度[Anim_Rate_Normal]转[Anim_Loop_Circle]圈(走到该色卡前一个色卡认为是一圈) ---走到新色卡的前[Anim_Slow_Count]个色卡后按[Anim_Rate_Slow]走到抽中色卡 local function SortByQuality(cfg1, cfg2) return cfg1.Quality < cfg2.Quality end function UIDyeAppearancePrizeWheel:OnOpened(context) CTL.DyeAppearance.RemoveDrawCardRed() UIUtils.SetActive(self.mask, false) self:RegistSystemEvent(EventID.UI_DyeAppearance_OnDrawColorFinish, self.OnDrawExp) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_CollectionAP_Entrance) self.colorList = {} self.drawColorList = {} --剩余可抽奖的色卡列表 local appearanceCfg = DataSheetManager.CollectionAP:GetDataByID(self.context.appearanceId) local costCfg = DataSheetManager.CollectionAPJackpot:GetDataByCostID_Count(appearanceCfg.CostID, 1) UTL.Item.SetItemIcon(self.img_Icon_One, costCfg.ItemID) self.costItemId = costCfg.ItemID CTL.Bag.RegisteEventByItemId(self.costItemId, self.HandleDrawCost, self) self:InitPartToggle() self:HandleSuits() self.toggle_TopGroup:SelectIndex(0) end function UIDyeAppearancePrizeWheel:HandleSuits() if self.suitList == nil then local suitList = {} for i, v in DataSheetManager.CollectionAPSuit:GetEnumerator() do if v.Quality < CTL.DyeAppearance.SuitQuality_Middle and v.IsInit == false then table.insert(suitList, v) end end table.sort(suitList, SortByQuality) for i, v in ipairs(suitList) do if self.Content[i] == nil then self:InstantiateCollection(self.Content, self.Content[1].gameObject) end self:SetSuitItem(self.Content[i], v) end self.suitList = suitList else for i, v in ipairs(self.suitList) do self:SetSuitItem(self.Content[i], v) end end end function UIDyeAppearancePrizeWheel:SetSuitItem(comp, suitCfg) UIUtils.SetLabelText(comp.txt_SuitName, Const_IDS[suitCfg.Name]) if suitCfg.Quality == CTL.DyeAppearance.SuitQuality_Middle then comp.state_SuitName:SetState(0) elseif suitCfg.Quality == CTL.DyeAppearance.SuitQuality_Best then comp.state_SuitName:SetState(2) else comp.state_SuitName:SetState(0) end for i, v in ipairs(suitCfg.PartList) do self:SetColorItem(comp.group_item[i], v, i) end end function UIDyeAppearancePrizeWheel:SetColorItem(comp, colorId, partIndex) local colorCfg = DataSheetManager.CollectionAPPart:GetDataByColorID_PartID_ApperanceID(colorId, partIndex, self.context.appearanceId) local isActive = MDL.DyeAppearance.IsColorActive(self.context.appearanceId, partIndex, colorId) CTL.DyeAppearance.SetColorItemTemplate(comp, colorCfg, false, isActive, isActive == false, false) end function UIDyeAppearancePrizeWheel:InitPartToggle() 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_Grow", idsList) for i, v in ipairs(idsList) do self.toggle_TopGroup:SetToggleIDS(i, "txt_Grow2", v) end end function UIDyeAppearancePrizeWheel:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIDyeAppearancePrizeWheel:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then --有遮罩时不让返回键退出该界面 if self.mask.gameObject.activeSelf then return end self:CloseView() elseif comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, { id = LuaConst.NoteID.DyeDrawCard }) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_Draw then if self.isPartComplete then CTL.Tips.AddTipsMsg(Const_IDS["IDS_ERRORCODE_449821_InfoCode_CollectionAP_Unlock"]) else if self.leftCountToDraw <= 0 then MDL.Player.SetDelayGSExpFlag(true) MDL.DyeAppearance.DrawColorReq(self.context.appearanceId, self.toggleIndex + 1) else for _, v in MDL.OperationActivity.StoreGoodsData:GetEnumerator() do if v.ItemID == self.costItemId then UTL.ItemTips.OpenQuickPurchaseView(v.ID) EventSystem.Dispatch(EventID.UI_PayMall_SetCount, self.leftCountToDraw) break end end end end else for i, v in ipairs(self.Content) do for part, item in ipairs(v.group_item) do if item.event_Click == comp then self:OnClickColorItem(i, part) return end end end end end function UIDyeAppearancePrizeWheel:PlaySwitchAnim() for i, v in ipairs(self.group_ItemNode) do UIUtils.SetActive(v.gameObject, false) end self.effect_Wheel:PlayUIEffect() CTL.Sound.PlayGameSound("UI_upgrade_02") for i, v in ipairs(self.group_ItemNode) do UIUtils.SetActive(v.gameObject, true) end end function UIDyeAppearancePrizeWheel:OnClickColorItem(suitIndex, partIndex) local func = function() self:SwitchPartIndex(partIndex) self:PlaySwitchAnim() end UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_CollectionAP_Lottery1, func, nil) end function UIDyeAppearancePrizeWheel:SwitchPartIndex(partIndex) if partIndex == self.toggleIndex + 1 then self:OnSwitchPart(partIndex) else self.toggle_TopGroup:SelectIndex(partIndex - 1) end end function UIDyeAppearancePrizeWheel:OnValueChanged(comp, index) self.toggleIndex = index self:OnSwitchPart(index + 1) self:PlaySwitchAnim() end function UIDyeAppearancePrizeWheel:OnSwitchPart(partIndex) CTL.DyeAppearance.CollectPartColorList(self.colorList, self.context.appearanceId, partIndex, true) local isAllActive = true for i, v in ipairs(self.group_ItemNode) do local isActive = self:SetDrawColorItem(v.item, self.colorList[i]) if isActive == false then isAllActive = false end end self.lastDrawColorId = CTL.DyeAppearance.GetLastDrawColorId(self.context.appearanceId, partIndex) if isAllActive then self:ResetHighlightItem() else self:OnHighlightItem(self.lastDrawColorId) end self:HandleDrawCost() end function UIDyeAppearancePrizeWheel:SetDrawColorItem(comp, colorCfg) local isActive = MDL.DyeAppearance.IsColorActive(self.context.appearanceId, colorCfg.PartID, colorCfg.ColorID) CTL.DyeAppearance.SetColorItemTemplate(comp, colorCfg, false, isActive, isActive == false, true) return isActive end function UIDyeAppearancePrizeWheel:HandleDrawCost() self.isPartComplete = false self.leftCountToDraw = 0 local needCount local partIndex = self.toggleIndex + 1 local activeCount, isComplete = CTL.DyeAppearance.GetPartActiveCount(self.context.appearanceId, partIndex) if isComplete then self.btn_Draw:SetGray(true, true) self.txt_One.text = nil self.isPartComplete = true needCount = 0 else local appearanceCfg = DataSheetManager.CollectionAP:GetDataByID(self.context.appearanceId) local costCfg = DataSheetManager.CollectionAPJackpot:GetDataByCostID_Count(appearanceCfg.CostID, activeCount) self.btn_Draw:SetGray(false) needCount = costCfg.ItemNum local curCount = MDL.Bag.GetItemCount(costCfg.ItemID) or 0 self.leftCountToDraw = needCount - curCount end self.txt_One.text = needCount self.btn_Draw:SetRedPoint(CTL.DyeAppearance.CheckPartDrawCardRed(self.context.appearanceId, partIndex)) self:UpdateToggleRed() end function UIDyeAppearancePrizeWheel:UpdateDrawExpParam(drawColorId) table.clearArray(self.drawColorList) local index for i, v in ipairs(self.colorList) do if v.ColorID == self.lastDrawColorId then index = i break end end for i = index, #self.colorList do local colorId = self.colorList[i].ColorID if MDL.DyeAppearance.IsColorActive(self.context.appearanceId, self.colorList[i].PartID, colorId) == false then table.insert(self.drawColorList, colorId) end end if index > 1 then for i = 1, index - 1 do local colorId = self.colorList[i].ColorID if MDL.DyeAppearance.IsColorActive(self.context.appearanceId, self.colorList[i].PartID, colorId) == false then table.insert(self.drawColorList, colorId) end end end if #self.drawColorList == 1 then return false end local drawIndex for i, v in ipairs(self.drawColorList) do if v == drawColorId then drawIndex = i break end end local count = #self.drawColorList --如果正常速度走完规定圈数,距离抽中色卡的距离不足Anim_Slow_Count个,需要再循环一圈走到前Anim_Slow_Count的位置去减速 if drawIndex < Anim_Slow_Count then self.animTotalTimes = count * (Anim_Loop_Circle + 1) + drawIndex else self.animTotalTimes = count * Anim_Loop_Circle + drawIndex end return true end function UIDyeAppearancePrizeWheel:OnClosed() CTL.Bag.UnRegisteEventByItemId(self.costItemId, self.HandleDrawCost, self) MDL.Player.SetDelayGSExpFlag(false) EventSystem.Dispatch(EventID.UI_DyeAppearance_UpdateDrawCardRed) end function UIDyeAppearancePrizeWheel:OnDrawExpEnd() UIUtils.SetActive(self.mask, false) local partIndex = self.toggleIndex + 1 CTL.DyeAppearance.ShowColorRewardItem(self.animTargetColorId, partIndex, self.context.appearanceId) self:HandleSuits() self:SwitchPartIndex(partIndex) MDL.Player.DelayShowGSExp() MDL.Player.SetDelayGSExpFlag(false) end function UIDyeAppearancePrizeWheel:OnDrawExp(colorId) self.animTargetColorId = colorId UIUtils.SetActive(self.mask, true) local isExp = self:UpdateDrawExpParam(colorId) if isExp == false then self:StartRepeatFunc(self.OnDrawExpEnd, Anim_Rate_Slow, 1) else self.animUpdateTimes = 0 self:StartRepeatFunc(self.UpdateHighlightItem, Anim_Rate_Normal, 0) end end function UIDyeAppearancePrizeWheel:ResetHighlightItem() for i, v in ipairs(self.group_ItemNode) do UIUtils.SetActive(v.img_select, false) end end function UIDyeAppearancePrizeWheel:OnHighlightItem(colorId, isEnd) self:ResetHighlightItem() local index for i, v in ipairs(self.colorList) do if v.ColorID == colorId then index = i break end end UIUtils.SetActive(self.group_ItemNode[index].img_select, true) if isEnd then self.group_ItemNode[index].effect_item:PlayUIEffect() end end function UIDyeAppearancePrizeWheel:UpdateHighlightItem() self.animUpdateTimes = self.animUpdateTimes + 1 local colorId, isEnd, isSwitchSpeed = self:DecodeAnimParam(self.animUpdateTimes) self:OnHighlightItem(colorId, isEnd) CTL.Sound.PlayGameSound("UI_treasures_roll") if isEnd then self:StopRepeatFunc(self.UpdateHighlightItem) self:StartRepeatFunc(self.OnDrawExpEnd, Anim_Rate_Slow, 1) return end if isSwitchSpeed then self:StopRepeatFunc(self.UpdateHighlightItem) self:StartRepeatFunc(self.UpdateHighlightItem, Anim_Rate_Slow, 0) end end function UIDyeAppearancePrizeWheel:DecodeAnimParam(times) local colorId, isEnd, isSwitchSpeed local count = times % #self.drawColorList if count == 0 then count = #self.drawColorList end colorId = self.drawColorList[count] isEnd = self.animTotalTimes == times isSwitchSpeed = (self.animTotalTimes - Anim_Slow_Count) == times return colorId, isEnd, isSwitchSpeed end function UIDyeAppearancePrizeWheel:UpdateToggleRed() for i = 1, CTL.DyeAppearance.PartCount do self.toggle_TopGroup:SetRedPoint(i - 1, CTL.DyeAppearance.CheckPartDrawCardRed(self.context.appearanceId, i)) end end return UIDyeAppearancePrizeWheel