local UIGuildCultivationMain = UIViewClass() function UIGuildCultivationMain:OnOpened(context) self:RegistSystemEvent(EventID.UI_GuildCultivateInfoRefresh, self.SelectSkillAfterLevelUp) self:RegistSystemEvent(EventID.UI_GuildCultivateSkillLevelUp, self.PlayLevelUpEffect) self:RegistSystemEvent(EventID.UI_GuildBuildingInfoRefresh, self.SelectSkillAfterLevelUp) self:RegistSystemEvent(EventID.BagItem_Update, self.SelectSkillAfterLevelUp) self:RegistSystemEvent(EventID.UI_RefreshCurrency, self.SelectSkillAfterLevelUp) self:RegistSystemEvent(EventID.AcquireSystemRedAfterUnlock, self.SelectSkillAfterLevelUp) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS["IDS_GuildCultivation_Title"]) self:RefreshSkills() self:SelectSkillByIndex(1) end function UIGuildCultivationMain:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIGuildCultivationMain:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView() elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_AttrBrowse then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGuildCultivationAttrBrowse) elseif comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.GuildCultivation }) elseif comp == self.btn_Confirm then if not self.isEnough then CTL.Tips.AddTipsMsg(Const_IDS["IDS_GuildCultivation_LevelUpWrongHint2"]) return end if not self.isUnlock then CTL.Tips.AddTipsMsg(Const_IDS["IDS_GuildCultivation_LevelUpWrongHint3"]) return end MDL.GuildCultivation.GuildCultivateUpLevelReq(self.cultivateId) else for i, v in ipairs(self.group_SkillIcons) do if comp == v.btn_Skill then self:SelectSkillByIndex(i) return end end end end function UIGuildCultivationMain:PlayLevelUpEffect() CTL.Sound.PlayGameSound("UI_lifeup") self.effect_LevelUp:PlayUIEffect() end function UIGuildCultivationMain:RefreshSkills() for i, v in ipairs(DataSheetUtil.GetSortedGuildCultivationData()) do local skillComp = self.group_SkillIcons[i] self:RefreshSkillIcon(skillComp, v) end end function UIGuildCultivationMain:SelectSkillByIndex(index) self.effect_Selected.transform:SetParent(self.group_SkillIcons[index].img_SkillIcon.transform, false) self.effect_Selected.transform:SetLocalPosition(0, 0, 0) self.cultivateId = DataSheetUtil.GetSortedGuildCultivationData()[index].CultivationType self:RefreshSkillInfo(self.cultivateId) local cultivateSkillLevel = MDL.GuildCultivation.GetGuildCultivationInfoById(self.cultivateId) if cultivateSkillLevel < 0 then CTL.Sound.PlayGameSound("UI_invalid") end end function UIGuildCultivationMain:SelectSkillAfterLevelUp() self:RefreshSkills() self:RefreshSkillInfo(self.cultivateId) end function UIGuildCultivationMain:RefreshSkillIcon(skillComp, data) local cultivateId = data.CultivationType UIUtils.SetImageByAssetBundle(skillComp.img_SkillIcon, data.CultivationIcon) local cultivateSkillLevel = MDL.GuildCultivation.GetGuildCultivationInfoById(cultivateId) UIUtils.SetActive(skillComp.img_SkillLock, cultivateSkillLevel < 0) skillComp.txt_Level.text = cultivateSkillLevel < 0 and 0 or cultivateSkillLevel --这里界面左侧和右侧的skillIcon都会复用这同一段代码,但是组件略有却别,所以需要进行判断 if skillComp.txt_SkillName then UIUtils.SetLabelText(skillComp.txt_SkillName, Const_IDS[data.CultivationName]) skillComp.state_SkillName:SetState(cultivateSkillLevel < 0 and 0 or 1) end if skillComp.btn_Skill then skillComp.btn_Skill:SetRedPoint(CTL.GuildCultivation.IsSkillCanLevelUp(cultivateId, cultivateSkillLevel + 1)) end end function UIGuildCultivationMain:RefreshSkillInfo(cultivateId) local cultivateSkillLevel = MDL.GuildCultivation.GetGuildCultivationInfoById(cultivateId) local data = DataSheetManager.CultivationData:GetDataByCultivationType(cultivateId) --设置属性名称和描述 UIUtils.SetLabelText(self.txt_Title, Const_IDS[data.CultivationName]) UIUtils.SetLabelText(self.txt_Tip, Const_IDS[data.CultivationDes]) --设置属性图标和解锁状态 self:RefreshSkillIcon(self.group_Icon, data) local _, curAttrData = DataSheetManager.CultivationLevel:TryGetDataByCultivationType_Level(cultivateId, cultivateSkillLevel) local _, nextAttrData = DataSheetManager.CultivationLevel:TryGetDataByCultivationType_Level(cultivateId, cultivateSkillLevel + 1) if nextAttrData then --找到下一级数据 self.state_Level:SetState(1) local ifUnlock = cultivateSkillLevel >= 0 if ifUnlock then --是否处于解锁状态 self.state_Lock:SetState(1) UIUtils.SetLabelText(self.txt_LevelTip, Const_IDS.IDS_GuildCultivation_LevelUpHint) UIUtils.SetActive(self.group_NextAttr.gameObject, true) UTL.Attr.SetAttrItem({self.group_CurrentAttr.txt_Attr, self.group_CurrentAttr.txt_AttrNumber}, curAttrData.AttrType, curAttrData.AttrNum) UTL.Attr.SetAttrItem({self.group_NextAttr.txt_Attr, self.group_NextAttr.txt_AttrNumber}, nextAttrData.AttrType, nextAttrData.AttrNum) else self.state_Lock:SetState(0) UIUtils.SetLabelText(self.txt_LevelTip, Const_IDS.IDS_GuildCultivation_LockHint) UIUtils.SetActive(self.group_NextAttr.gameObject, false) UTL.Attr.SetAttrItem({self.group_CurrentAttr.txt_Attr, self.group_CurrentAttr.txt_AttrNumber}, nextAttrData.AttrType, nextAttrData.AttrNum) end self.isUnlock = true for i, v in ipairs(nextAttrData.LevelUpTrigger_Table) do --升级条件显示,找到下一级的升级条件的数据进行显示 local cell = self.group_LevelLimitation[i] if v.LevelUpTriggerID and v.LevelUpTriggerID > 0 then local isUnlock, unlockText = CTL.GuildCultivation.IsSkillUnlock(v.LevelUpTriggerID, v.LevelUpTriggerParams) UIUtils.SetActive(cell.gameObject, true) cell.txt_Limitation.text = unlockText self.isUnlock = self.isUnlock and isUnlock else UIUtils.SetActive(cell.gameObject, false) end end for i=#nextAttrData.LevelUpTrigger_Table + 1, #self.group_LevelLimitation do UIUtils.SetActive(self.group_LevelLimitation[i].gameObject, false) end self.isEnough = true for i, v in ipairs(nextAttrData.LevelUpItem_Table) do --消耗材料显示,找到下一级的消耗材料数据 local cell = self.group_Cost[i] local itemId = v.ItemID local itemNum = v.ItemNum local count if itemId and itemId > 0 then if MDL.Currency.IsMoneyTypeByItemID(itemId) then UTL.Item.MoneyIcon(cell.img_Icon, itemId) count = MDL.Currency.GetMoneyCount(itemId) else UTL.Item.ItemIconWithoutBg(cell.img_Icon, itemId) count = MDL.Bag.GetItemCount(itemId) end self.isEnough = self.isEnough and (count >= itemNum) count = count >= itemNum and itemNum or UTL.Color.FormatRedColor(itemNum) cell.txt_Cost.text = count else UIUtils.SetActive(cell.gameObject, false) end end self.btn_Confirm:SetRedPoint(self.isUnlock and self.isEnough) else --找不到数据说明满级了 UIUtils.SetActive(self.group_MaxCurrentAttr.gameObject, true) UTL.Attr.SetAttrItem({self.group_MaxCurrentAttr.txt_Attr, self.group_MaxCurrentAttr.txt_AttrNumber}, curAttrData.AttrType, curAttrData.AttrNum) self.state_Level:SetState(0) end end return UIGuildCultivationMain