local UITurntableMain = UIViewClass() local Angle_Item = 45 --每隔45度一个道具 --每隔Rotate_Rate时长旋转角度Rotate_Angle_Offset local Rotate_Rate = 0.02 local Rotate_Angle_Offset = 15 --到达目标角度前多加的角度 local Exp_Angle_Attach = 360 local EMPTY_DATA = 0 function UITurntableMain:OnCreated() self.pointTf = self.img_Pointer.transform self.curAngle = 0 self.pointTf:SetLocalEulerAngles(nil, nil, 0) UIUtils.SetLabelText(self.group_1.lab_Start, Const_IDS.IDS_SuperGoldHeroActivity_Turntable_Button_1) self.group_10.lab_Start.text = string.FormatByIdsId(Const_IDS.IDS_SuperGoldHeroActivity_Turntable_Button_2, 10) self.group_50.lab_Start.text = string.FormatByIdsId(Const_IDS.IDS_SuperGoldHeroActivity_Turntable_Button_2, 50) end function UITurntableMain:OnOpened(context) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS["IDS_Turntable_Title"]) if not GameAppInfo.IsJapanesePackage() then UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) end self:RegistSystemEvent(EventID.UI_Turntable_UpdateDrawTimes, self.OnDrawTimesUpdate) self:RegistSystemEvent(EventID.UI_Turntable_UpdateTotalReward, self.OnDrawTimesUpdate) self:RegistSystemEvent(EventID.UI_DirectGift_GiftInfoUpdate, self.UpdateGiftRed) self.oaBackGroundData = MDL.OperationActivity.TurntableBackGround:GetDataByActivityID(MDL.Turntable.GetActivityId()) CTL.Bag.RegisteEventByItemId(self.oaBackGroundData.ItemID, self.OnCostItemUpdate, self) self.txt_MiningTimes.text = string.FormatByIdsId(Const_IDS.IDS_Turntable_CoinTips1, self.oaBackGroundData.PresentedItemNum) self:RegistSystemEvent(EventID.UI_Turntable_DrawItemList, self.OnDrawItemExp) self:InitMoneyIcon() self.lab_Title02.text = Localization.GetOperationActivityLabel(self.oaBackGroundData.CasinoTitle) self:RefreshLeftTime() --展示道具 self:InitRewardShow() --抽奖道具 for i, data in MDL.OperationActivity.TurntableItem:GetEnumeratorByActivityID(MDL.Turntable.GetActivityId()) do self:InitRewardItem(i, data) end self:OnCostItemUpdate() self:OnIntegralItemUpdate() self:OnDrawTimesUpdate() self:InitPointerPos() self:UpdateGiftRed() CTL.Currency.OpenCurrencyPanel(self.__viewClassPath, self.currency_Info, nil, { activityType = MDL.OperationActivity.ActivityType.Turntable, activityId = MDL.Turntable.GetActivityId() }) self.toggle_AutoFollow.isOn = CTL.Turntable.GetRecordSkipState() end function UITurntableMain:InitRewardShow() self.rewardShowDataList = {} local runeList = {} local itemList = {} local petList = {} for _, data in MDL.OperationActivity.TurntableRewardShow:GetEnumeratorByActivityID(MDL.Turntable.GetActivityId()) do if data.ShowType == 1 then table.insert(runeList, data) elseif data.ShowType == 2 then table.insert(petList, data) elseif data.ShowType == 3 then table.insert(itemList, data) end end self:FillRewardData(self.rewardShowDataList, runeList) self:FillRewardData(self.rewardShowDataList, itemList) self:FillRewardData(self.rewardShowDataList, petList) self.loopItem:ReloadAll(self.rewardShowDataList) end function UITurntableMain:FillRewardData(result, typeList) local max = math.ceil(#typeList / 4) * 4 for i = 1, max do if typeList[i] then table.insert(result, typeList[i]) else table.insert(result, EMPTY_DATA) end end end function UITurntableMain:InitPointerPos() local itemId = CTL.Turntable.GetRecordDrawItemId() local targetAngle = self:GetTargetAngle(itemId) self.pointTf:SetLocalEulerAngles(nil, nil, -targetAngle) self.curAngle = targetAngle % 360 end function UITurntableMain:OnFocusChanged(isFocus) self:OnIntegralItemUpdate() end function UITurntableMain:OnIntegralItemUpdate() local curCount = UTL.Item.GetItemStockCount(self.oaBackGroundData.IntegralID) or 0 self.txt_num.text = "x" .. curCount end function UITurntableMain:OnCostItemUpdate() local curCount = MDL.Bag.GetItemCount(self.oaBackGroundData.ItemID) or 0 self:SetCostItemNum(self.group_1, curCount, 1) self:SetCostItemNum(self.group_10, curCount, 10) if curCount >= 50 then UIUtils.SetActive(self.group_50.gameObject, true) self:SetCostItemNum(self.group_50, curCount, 50) else UIUtils.SetActive(self.group_50.gameObject, false) end end function UITurntableMain:SetCostItemNum(comp, curNum, tarNum) local str if curNum >= tarNum then str = string.format("%s/%s", UTL.Color.FormatGreenColor(curNum), tarNum) comp.btn_Draw:SetRedPoint(true) else str = string.format("%s/%s", UTL.Color.FormatRedColor(curNum), tarNum) comp.btn_Draw:SetRedPoint(false) end comp.txt_MiningTimes.text = str end function UITurntableMain:InitRewardItem(index, data) local item = self.group_Rewards[index] UIUtils.SetActive(item.group_GrandPrize, data.IsShowRare == 1) UTL.Color.SetQualityImageByType(item.img_Quality, DataSheetManager.ItemData:GetDataByID(data.RewardID).Color, UTL.Color.QualityType.Circle) UTL.Item.SetItemIcon(item.img_Item, data.RewardID) item.txt_Num.text = data.RewardNum end function UITurntableMain:InitMoneyIcon() UTL.Item.SetItemIcon(self.img_Icon1, self.oaBackGroundData.IntegralID) UTL.Item.SetItemIcon(self.img_Icon2, self.oaBackGroundData.IntegralID) UTL.Item.SetItemIcon(self.group_1.img_Icon, self.oaBackGroundData.ItemID) UTL.Item.SetItemIcon(self.group_10.img_Icon, self.oaBackGroundData.ItemID) UTL.Item.SetItemIcon(self.group_50.img_Icon, self.oaBackGroundData.ItemID) end function UITurntableMain:RefreshLeftTime() local activityInfo = MDL.OperationActivity.GetOperationActivityInfo(MDL.OperationActivity.ActivityType.Turntable, MDL.Turntable.GetActivityId()) local leftTime = activityInfo.endTime - UTL.Time.GetServerTimestamp() local time = 0 if leftTime >= UTL.Time.TotalSecondsOneDay then time = leftTime - UTL.Time.TotalSecondsOneDay self.txt_Time:SetCustomString(UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeroFund_Timer), 1, 1) else self.txt_Time:SetCustomString(UIUtils.GetLocalizedTxt(Const_IDS.IDS_GuildWar_Time1), 1, 2) end self.txt_Time:ResetAndBeginTimer(false, leftTime) if time > 0 then self:StartRepeatFunc(self.RefreshLeftTime, time, 1) end end function UITurntableMain:OnClosed() CTL.Bag.UnRegisteEventByItemId(self.oaBackGroundData.ItemID, self.OnCostItemUpdate, self) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) MDL.Reward.SetCloseNotExpTipShow(false) end function UITurntableMain:StartDrawTimes(times) if self.isRotating then return end local curCount = MDL.Bag.GetItemCount(self.oaBackGroundData.ItemID) or 0 if curCount < times then CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS["IDS_DrawCard_Tip_LackItem"], UTL.Item.GetItemDataSpliceByType(self.oaBackGroundData.ItemID).Name)) return end MDL.Reward.SetCloseNotExpTipShow(true) MDL.Turntable.PetCasinoStartDrawReq(MDL.Turntable.GetActivityId(), times) end function UITurntableMain:OnButtonClicked(comp) if self.UITemplateTitlePanel.btn_close == comp then if self.isRotating then return end self:CloseView() elseif comp == self.UITemplateTitlePanel.btn_Home then if self.isRotating then return end CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, { id = LuaConst.NoteID.TurnTableRateJP }) elseif comp == self.group_1.btn_Draw then self:StartDrawTimes(1) elseif comp == self.group_10.btn_Draw then self:StartDrawTimes(10) elseif comp == self.group_50.btn_Draw then self:StartDrawTimes(50) elseif comp == self.btn_Record then UIManager.OpenView(Const_UI_Lua.UIEnum.UITurntableRecord, nil, Const_UI_Lua.UIEnum.UIMonopolyRecords) elseif comp == self.btn_Go2 or comp == self.btn_Go or comp == self.btn_Shop then CTL.Turntable.OpenStore() elseif comp == self.btn_RewardInfo then UIManager.OpenView(Const_UI_Lua.UIEnum.UITurntableTotal, nil, Const_UI_Lua.UIEnum.UISuperGoldDrawCardReward) elseif comp == self.btn_Reward then local result, rewardId = MDL.Turntable.CanGetTotalReward() if result then MDL.Turntable.PetCasinoGetRewardReq(MDL.Turntable.GetActivityId(), rewardId) else local _, nextCfg = MDL.Turntable.GetPreviewTotalRewardCfg() local result = string.match(nextCfg.Display, "%[(%d*),(%d*)%]") if string.isNilOrEmpty(result) then UIUtils.SetActive(self.btn_PreviewBg, true) self:ShowTotalRewardPreview(true, nextCfg.Reward_Table) else UTL.ItemTips.ShowCommonTipsById(nextCfg.Reward_Table[1].RewardID) end end elseif comp == self.btn_PreviewBg then UIUtils.SetActive(self.btn_PreviewBg, false) self:ShowTotalRewardPreview(false) elseif comp == self.btn_Gift then if self.isRotating then return end UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.OperationActivity.UIOACommonDirectGiftPanel, { activityType = MDL.OperationActivity.ActivityType.Turntable, activityId = MDL.Turntable.GetActivityId() }) else for i, v in ipairs(self.group_Rewards) do if comp == v.btn_Reward then local data = self:GetDataByIndex(i) if data then UTL.ItemTips.ShowCommonTipsById(data.RewardID) end return end end for i, v in ipairs(self.group_Preview) do if comp == v.event_Click then if i == 1 then UTL.ItemTips.ShowCommonTipsById(self.previewItemId_1) else UTL.ItemTips.ShowCommonTipsById(self.previewItemId_2) end return end end end end function UITurntableMain:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loopItem then if data == EMPTY_DATA then UIUtils.SetActive(cellTable.group_Rune.gameObject, false) UIUtils.SetActive(cellTable.group_Pet.gameObject, false) UIUtils.SetActive(cellTable.item.gameObject, false) else if data.ShowType == 1 then --宠物符文 UIUtils.SetActive(cellTable.group_Rune.gameObject, true) UIUtils.SetActive(cellTable.group_Pet.gameObject, false) UIUtils.SetActive(cellTable.item.gameObject, false) local skill = DataSheetManager.PetRelation:GetDataByItemID(data.IndexID) local cfg = DataSheetManager.PetRelationSkill:GetDataByRelationSkillID(skill.Relation_Table[1].RelationSkill) UIUtils.SetImageByAssetBundle(cellTable.group_Rune.sprite_Skill, cfg.RuneIcon) UIUtils.SetLabelText(cellTable.group_Rune.txt_Level, CTL.Pet.RuneSkillLevelIDS[#CTL.Pet.RuneSkillLevelIDS]) elseif data.ShowType == 2 then --宠物 UIUtils.SetActive(cellTable.group_Rune.gameObject, false) UIUtils.SetActive(cellTable.group_Pet.gameObject, true) UIUtils.SetActive(cellTable.item.gameObject, false) local cfg = DataSheetManager.PetData:GetDataByID_Stage(data.IndexID, MDL.Pet.PetState.Ultimate) UIUtils.SetImageByAssetBundle(cellTable.group_Pet.img_Pet, cfg.PetIcon) elseif data.ShowType == 3 then --道具 UIUtils.SetActive(cellTable.group_Rune.gameObject, false) UIUtils.SetActive(cellTable.group_Pet.gameObject, false) UIUtils.SetActive(cellTable.item.gameObject, true) UTL.Item.SetItemCell(cellTable.item, data.IndexID) end end end end function UITurntableMain:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loopItem then if target == cellTable.group_Rune.btn_Skill then local skill = DataSheetManager.PetRelation:GetDataByItemID(data.IndexID) CTL.Pet.ShowRuneSkillTips(skill.Relation_Table[1].RelationSkill) elseif target == cellTable.group_Pet.btn_Click then CTL.Pet.OpenPetIllustratedHandbookUI(data.IndexID) elseif target == cellTable.item.event_Click then UTL.ItemTips.ShowCommonTipsById(data.IndexID) end end end function UITurntableMain:GetTargetAngle(itemId) local index = 0 for i, data in MDL.OperationActivity.TurntableItem:GetEnumeratorByActivityID(MDL.Turntable.GetActivityId()) do if itemId == data.ID then index = i break end end if index > 0 then return self:IndexToAngle(index) + Exp_Angle_Attach end return 0 end function UITurntableMain:OnDrawItemExp(itemList) self.isRotating = true local targetItem = itemList[1] local targetAngle = self:GetTargetAngle(targetItem) if self.toggle_AutoFollow.isOn then self:RotateToTarget(targetAngle, true) else self:RotateToTarget(targetAngle, false) end end function UITurntableMain:RotateToTarget(targetAngle, isStraight) for i, v in ipairs(self.group_Rewards) do UIUtils.SetActive(v.effect_SelectSenior, false) end self:StopRepeatFunc(self.UpdateRotateOffset) local offset = targetAngle - self.curAngle if isStraight == true then self:SetPointAngleByOffset(offset) self:OnRotateEnd() else if offset <= Exp_Angle_Attach then self.angleOffset = offset + Exp_Angle_Attach else self.angleOffset = offset end self:StartRepeatFunc(self.UpdateRotateOffset, Rotate_Rate, 0) end end function UITurntableMain:UpdateRotateOffset() if self.angleOffset > 0 then self.angleOffset = self.angleOffset - Rotate_Angle_Offset self:SetPointAngleByOffset(Rotate_Angle_Offset) else self:StopRepeatFunc(self.UpdateRotateOffset) self:OnRotateEnd() end end function UITurntableMain:SetPointAngleByOffset(offset) local _, _, angle = self.pointTf:GetLocalEulerAngles() self.pointTf:SetLocalEulerAngles(nil, nil, angle - offset) self.curAngle = (self.curAngle + offset) % 360 end function UITurntableMain:OnRotateEnd() local index = self:AngleToIndex(self.curAngle) UIUtils.SetActive(self.group_Rewards[index].effect_SelectSenior, true) local data = self:GetDataByIndex(index) if data then CTL.Turntable.RecordDrawItemId(data.ID) end CTL.Reward.ShowDelayReward() self.isRotating = false self:OnIntegralItemUpdate() end function UITurntableMain:GetDataByIndex(index) for i, data in MDL.OperationActivity.TurntableItem:GetEnumeratorByActivityID(MDL.Turntable.GetActivityId()) do if index == i then return data end end return nil end function UITurntableMain:AngleToIndex(angle) return math.floor(angle / Angle_Item) + 1 end function UITurntableMain:IndexToAngle(index) return (index - 1) * Angle_Item end function UITurntableMain:OnDrawTimesUpdate() local curNum = MDL.Turntable.GetDrawTimes() local _, nextCfg = MDL.Turntable.GetPreviewTotalRewardCfg() local leftValue = math.min(curNum, nextCfg.TotalTimes) self.lab_Score.text = string.format("%s(%s/%s)", UIUtils.GetLocalizedTxt(Const_IDS.IDS_Turntable_AddUpReward), leftValue, nextCfg.TotalTimes) self.slider_progress.value = curNum / nextCfg.TotalTimes local result = string.match(nextCfg.Display, "%[(%d*),(%d*)%]") if string.isNilOrEmpty(result) then UIUtils.SetActive(self.img_NumBg, false) UIUtils.SetImageByAssetBundle(self.img_Item, nextCfg.Display) self.txt_ItemNum.text = nil else UIUtils.SetActive(self.img_NumBg, true) UTL.Item.SetItemIcon(self.img_Item, nextCfg.Reward_Table[1].RewardID) self.txt_ItemNum.text = nextCfg.Reward_Table[1].RewardNum end self:UpdateRewardGetState() end function UITurntableMain:UpdateRewardGetState() if MDL.Turntable.CanGetTotalReward() then self.group_Available:PlayUIEffect() else self.group_Available:StopUIEffect() end end function UITurntableMain:ShowTotalRewardPreview(state, rewardTable) UIUtils.SetActive(self.group_Preview.gameObject, state) if state then self.previewItemId_1 = rewardTable[1].RewardID self.previewItemId_2 = rewardTable[2].RewardID UTL.Item.SetItemCell(self.group_Preview[1], rewardTable[1].RewardID, rewardTable[1].RewardNum) UTL.Item.SetItemCell(self.group_Preview[2], rewardTable[2].RewardID, rewardTable[2].RewardNum) end end function UITurntableMain:UpdateGiftRed() self.btn_Gift:SetRedPoint(CTL.OACommon.IsHasGiftRedPoint(MDL.Turntable.GetActivityId())) end function UITurntableMain:OnValueChanged(comp, value) if comp == self.toggle_AutoFollow then CTL.Turntable.SetRecordSkipState(value) end end return UITurntableMain