local UITreasureBowlPanel = UIViewClass() function UITreasureBowlPanel:OnOpened(context) self.activityId = context.activityId self.activityType = MDL.OperationActivity.ActivityType.TreasureBowl self:RegistSystemEvent(EventID.UI_TreasureBowl_SelfInfoUpdate, self.RefreshOwnInfo) self:RegistSystemEvent(EventID.UI_TreasureBowl_PlayerDrawInfoUpdate, self.RefreshPlayerInfo) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.CheckIfClose) self:RefreshOwnInfo() self.group_Time:SetDHMSStr(UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPrivilege_BuffShow), "{0}:{1}:{2}", "{0}:{1}", "{0}:{1}") self:RefreshLeftTime() MDL.TreasureBowl.GetTreasureBowlHistoryReq(self.activityId) end function UITreasureBowlPanel:RefreshOwnInfo() self.maxCount = MDL.OperationActivity.TreasureBowlReward:GetDataLengthByActivityID(self.activityId) self.drawCount = MDL.TreasureBowl.GetDrawCount(self.activityId) self.isReachMax = self.drawCount == self.maxCount UIUtils.SetActive(self.group_ChargeAmount, not self.isReachMax) self.btn_Collect:SetGray(self.isReachMax) self.state_Disabled:SetState(self.isReachMax and 1 or 0) if self.isReachMax then UIUtils.SetLabelText(self.txt_GetAmount, Const_IDS.IDS_TreasureBowl_NoTimes) self.state_Collect:SetState(1) else self.treasureBowlRewardData = MDL.OperationActivity.TreasureBowlReward:GetDataByActivityID_ID(self.activityId, self.drawCount + 1) self.txt_CostNum.text = self.treasureBowlRewardData.NeedCoinNum self.txt_GetAmount.text = string.FormatByIdsKey("IDS_TreasureBowl_MaxReward", self.treasureBowlRewardData.MaxGold) self.state_Collect:SetState(0) end local rechargeNum = MDL.TreasureBowl.GetRechargeNum(self.activityId) UIUtils.SetActive(self.txt_ChargeTarget, false) self.availableCount = self.maxCount for i, v in MDL.OperationActivity.TreasureBowlReward:GetEnumeratorByActivityID(self.activityId) do if rechargeNum < v.NeedRecharge then self.availableCount = i - 1 UIUtils.SetActive(self.txt_ChargeTarget, true) local temNum = MDL.Currency.GetPriceExchangeRate(v.NeedRecharge - rechargeNum, GameAppInfo.IsOverseaPackage()) self.txt_ChargeTarget.text = string.FormatByIdsKey("IDS_TreasureBowl_ObtainedTimes", MDL.Currency.FormatPriceNum(temNum)) break end end local remainCount = self.availableCount - self.drawCount self.txt_RemainTimes.text = string.FormatByIdsKey("IDS_TreasureBowl_RemainingTimes", remainCount == 0 and UTL.Color.FormatRedColor(0) or UTL.Color.FormatGreenColor(remainCount)) if GameAppInfo.IsJapanesePackage() then self.txt_GoldNum_JP.text = UTL.Item.GetItemStockCount(MDL.Currency.CurrencyType.GoldIngot) --日本地区调整UI适配 self:UILanguagesAdjustForJP() else self.txt_GoldNum.text = UTL.Item.GetItemStockCount(MDL.Currency.CurrencyType.GoldIngot) end end function UITreasureBowlPanel:RefreshPlayerInfo() self.loop_Info:ReloadAll(MDL.TreasureBowl.GetPlayerInfo(self.activityId)) end function UITreasureBowlPanel:RefreshLeftTime() local activityInfo = MDL.OperationActivity.GetOperationActivityInfo(self.activityType, self.activityId) local leftTimes = activityInfo.endTime - UTL.Time.GetServerTimestamp() self.group_Time:ResetAndBeginCustomTimer(false, leftTimes, 0, nil) if leftTimes <= UTL.Time.TotalSecondsOneDay then self:StartRepeatFunc(self.AutoCloseView, leftTimes, 1) end end function UITreasureBowlPanel:AutoCloseView(deltaTime, timeSinceUpdate) self:CloseView() end function UITreasureBowlPanel:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UITreasureBowlPanel:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() elseif comp == self.btn_Recharge then CTL.ItemSources.ExecuteSourceFunctionById(MDL.ItemSources.SourceType.Recharge) elseif comp == self.btn_Collect then if self.isReachMax then CTL.Tips.AddTipsMsg(Const_IDS.IDS_TreasureBowl_NoTimes) return end if self.availableCount > self.drawCount then if MDL.Currency.GetSoftTokenCountById(self.treasureBowlRewardData.NeedCoinType) >= self.treasureBowlRewardData.NeedCoinNum then MDL.TreasureBowl.TreasureBowlReq(self.activityId, self.drawCount + 1) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Guild_CommonFail5) end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_TreasureBowl_InsufficientTimes) end end end function UITreasureBowlPanel:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Info then if GameAppInfo.IsJapanesePackage() then --日本地区需要调整UI显示顺序,在不新增设置锚点的cs接口的情况下,去掉元宝图标 UIUtils.SetActive(cellTable.img_Gold, false) UIUtils.SetLocalPosition(cellTable.txt_Desc,0,0,0) cellTable.txt_Desc.text = string.FormatByIdsKey("IDS_TreasureBowl_Note_JP", data.playerName, data.itemNum) else UIUtils.SetActive(cellTable.img_Gold, true) cellTable.txt_Desc.text = string.FormatByIdsKey("IDS_TreasureBowl_Note", data.playerName, data.itemNum) end end end function UITreasureBowlPanel:CheckIfClose(funcId, state) if funcId == MDL.Unlock.FunctionType.TreasureBowl and not state then self:CloseView() end end --日本地区需要调整这个界面中所有的“数字”和“金元宝”的顺序 如果是单地区多语言需要重置其他语言的本地化逻辑 function UITreasureBowlPanel:UILanguagesAdjustForJP() --标题 UIUtils.SetActive(self.group_Recruit, false) UIUtils.SetActive(self.group_Recruit_JP, true) --按钮 UIUtils.SetActive(self.img_CurrencyIconOnBtn, false) UIUtils.SetActive(self.img_CurrencyIcon_JP, true) end return UITreasureBowlPanel