local UIGuildArchitecture = UIViewClass() local lvStr = "%s/%s" function UIGuildArchitecture:OnOpened(context) MDL.Guild.GetGuildInfoReq() self:RegistSystemEvent(EventID.UI_Guild_GuildBuildRefresh, self.UpdateBuildInfo) self:RegistSystemEvent(EventID.UI_Guild_GuildInfoRefresh, self.UpdateBuildInfo) self:RegistSystemEvent(EventID.UI_Guild_SelfInfoRefresh, self.UpdateCost) self.guildBuildingCfgData = {} for i,v in DataSheetManager.GuildBuildingBase:GetEnumerator() do self.guildBuildingCfgData[i] = v end self.curSelectId = 0 if self.loc_Btn.CurState == 0 then self.btns = self.btn_Group else self.btns = self.btn_Group_Loc end self:UpdateBuildInfo() self:OnButtonClicked(self.btns[1].btn) end function UIGuildArchitecture:UpdateBuildInfo() for i, btn in ipairs(self.btns) do self:RefreshBtn(btn, self.guildBuildingCfgData[i]) end if self.curSelectId > 0 then self:ShowBuildInfo() end end function UIGuildArchitecture:OnButtonClicked(comp) if comp == self.btn_LevelUp then self:ClickLevelUp() elseif comp == self.btn_Apply then self:ClickAccelerate() elseif comp == self.btn_Info then UIUtils.SetActive(self.Btn_CloseClick, true) UIUtils.SetActive(self.group_TipsPanel, true) elseif comp == self.Btn_CloseClick then UIUtils.SetActive(self.Btn_CloseClick, false) UIUtils.SetActive(self.group_TipsPanel, false) else for i, v in ipairs(self.btns) do if comp == v.btn then local data = self.guildBuildingCfgData[i] if CTL.Guild.UnOpenGuildActivity[data.ID] then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS["IDS_NowNotOpen"]) else v.UIState_Select:SetState(1) CTL.Sound.PlayGameSound("UI_zhangjie") self.curSelectId = data.ID self:ShowBuildInfo() UIUtils.SetLabelText(self.txt_title1,Const_IDS[data.BuildingName]) UIUtils.SetImageByAssetBundle(self.img_TopBg, data.BannerImageName) end else v.UIState_Select:SetState(0) end end end end function UIGuildArchitecture:ShowBuildInfo() self.lockDesc = nil local buildInfo = MDL.Guild.GetBuildInfo(self.curSelectId) local buildingData = DataSheetManager.GuildBuilding:GetDataByBuildingType_Level(self.curSelectId,buildInfo.level) local maxLevel = DataSheetManager.GuildBuilding:GetDataLengthByBuildingType_Level(self.curSelectId) self.txt_LevelNum.text = string.format(lvStr, buildInfo.level, maxLevel) local isMax = buildInfo.level == maxLevel self.txt_Info1.text = self:GetEffectStr(buildingData.Effect_Table) if not isMax then local nextBuildingData = DataSheetManager.GuildBuilding:GetDataByBuildingType_Level(self.curSelectId,buildInfo.level+1) self.txt_Info2.text = self:GetEffectStr(nextBuildingData.Effect_Table) local str = nil for i,v in ipairs(buildingData.LevelUpTrigger_Table) do local _, tmpContent="" if v.LevelUpTriggerID == LuaConst.UnlockConditionType.GuildLevel then _, tmpContent = MDL.Unlock.IsComplete(v.LevelUpTriggerID, v.LevelUpTriggerParams, "IDS_GuildActivity_ReptUnlock") elseif v.LevelUpTriggerID == LuaConst.UnlockConditionType.GuildBuildLevelByType then _, tmpContent = MDL.Unlock.IsComplete(v.LevelUpTriggerID, v.LevelUpTriggerParams, "IDS_GuildBuildingTriggerDesc") end if not _ then self.lockDesc = tmpContent end if str then str = str.."\n" .. tmpContent else str = tmpContent end end local dayStr = UIUtils.GetLocalizedTxt(Const_IDS.IDS_GuildBuilding_BuildTime2) local hourStr = UIUtils.GetLocalizedTxt(Const_IDS.IDS_GuildBuilding_BuildTime1) str = str .."\n" .. UTL.Time.FormatTimeForDay(buildingData.Time, dayStr ,hourStr) self.txt_Info3.text = str end if not isMax and not buildInfo.isBuilding then --升级按钮 self:SetLevelUpCost() self.group_Up.gameObject:SetActive(true) self:StopRepeatFunc(self.OnUpdateFun) elseif buildInfo.isBuilding then self.state:SetState(1) self:OnUpdateFun() self:StartRepeatFunc(self.OnUpdateFun, 1) local time = buildInfo.buildingEndTime - UTL.Time.GetServerTimestamp() self.txt_TimeNum:ResetAndBeginCustomTimer(false,time,0,"{0:00}:{1:00}:{2:00}",1) local speedTime = buildingData.BoostTime * (buildingData.BoostTimeLimit - #buildInfo.speedUpAcids) if not self:IsSpeedUp(buildInfo.speedUpAcids) then UIUtils.SetLabelText(self.lab_Apply,Const_IDS.IDS_GuildBuilding_SpeedUp) self.btn_Apply:SetGray(false) else UIUtils.SetLabelText(self.lab_Apply,Const_IDS.IDS_GuildBuilding_AreadySpeedUp) self.btn_Apply:SetGray(true) end if speedTime > 0 then local str = UIUtils.GetLocalizedTxt(Const_IDS.IDS_GuildBuilding_Time) self.txt_SurTimeNum.text = UTL.Time.FormatTimeClockBySeconds(speedTime,str) else UIUtils.SetLabelText(self.txt_SurTimeNum,Const_IDS.IDS_ERRORCODE_1360_InfoCode_Guild_BoostTimeLimit) end self:OnUpdateFun() self.group_Up.gameObject:SetActive(true) elseif isMax then -- 满级 self.state:SetState(2) self:StopRepeatFunc(self.OnUpdateFun) self.group_Up.gameObject:SetActive(false) end self.curSelectLevel = buildInfo.level end function UIGuildArchitecture:IsSpeedUp(speedUpAcids) for i,v in ipairs(speedUpAcids) do if v == BattleDataGetter.GetAcID() then return true end end return false end function UIGuildArchitecture:OnUpdateFun(deltaTime, timeSinceUpdate) local buildInfo = MDL.Guild.GetBuildInfo(self.curSelectId) if buildInfo.isBuilding then local buildingData = DataSheetManager.GuildBuilding:GetDataByBuildingType_Level(self.curSelectId,buildInfo.level) local time = buildInfo.buildingEndTime - UTL.Time.GetServerTimestamp() self.slider_XP.value = 1- time/buildingData.Time if time <= 0 then MDL.Guild.GetGuildInfoReq() self:StopRepeatFunc(self.OnUpdateFun) end end end function UIGuildArchitecture:SetLevelUpCost() local buildInfo = MDL.Guild.GetBuildInfo(self.curSelectId) local maxLevel = DataSheetManager.GuildBuilding:GetDataLengthByBuildingType_Level(self.curSelectId) local isMax = buildInfo.level == maxLevel if not isMax and not buildInfo.isBuilding then local buildingData = DataSheetManager.GuildBuilding:GetDataByBuildingType_Level(self.curSelectId,buildInfo.level) if MDL.Guild.JobHasPermission(MDL.Guild.GetMyGuildInfo().jobTitle,MDL.Guild.AuthorityEnum.GuildBuilding) then self.state:SetState(3) self.txt_UpCost.text = buildingData.CostValue local count = MDL.Currency.GetMoneyCount(MDL.Currency.CurrencyType.GuildWuZi) self.costEnough = (count >= buildingData.CostValue) self.costName = UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.ItemData:GetDataByID(MDL.Currency.CurrencyType.GuildWuZi).Name]) if count < buildingData.CostValue then self.txt_UpCost.text = UTL.Color.FormatRedColor(buildingData.CostValue) self.costEnough = false else self.txt_UpCost.text = buildingData.CostValue self.costEnough = true end else self.state:SetState(0) end end end function UIGuildArchitecture:UpdateCost() self:SetLevelUpCost() end function UIGuildArchitecture:ClickLevelUp() if not MDL.Guild.JobHasPermission(MDL.Guild.GetMyGuildInfo().jobTitle,MDL.Guild.AuthorityEnum.GuildBuilding) then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_Guild_CommonFail4) elseif self.lockDesc then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(self.lockDesc,self.costName) elseif not self.costEnough then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_Guild_CommonFail1,self.costName) else local str = string.FormatByIdsId(Const_IDS.IDS_GuildBuildingConstruct_Confirm, tonumber(self.txt_UpCost.text), self.txt_title1.text) UTL.MessageBox.ShowOKCancelBox(nil, str, function() MDL.Guild.GuildBuildingLevelUpReq(self.curSelectId,self.curSelectLevel ) end) end end function UIGuildArchitecture:ClickAccelerate() MDL.Guild.GuildBuildingSpeedUpReq(self.curSelectId, self.curSelectLevel) end function UIGuildArchitecture:GetEffectStr(effectTable) local str = nil for i,v in ipairs(effectTable) do local effectData = DataSheetManager.GuildBuildingEffect:GetDataByID(v.EffectTime) if str then str = str.."\n" .. string.FormatByIdsId(Const_IDS[effectData.EffectDesc],v.EffectValue) else str = string.FormatByIdsId(Const_IDS[effectData.EffectDesc],v.EffectValue) end end return str end function UIGuildArchitecture:RefreshBtn(btn, data) UIUtils.SetLabelText(btn.labLocal_Title,Const_IDS[data.BuildingName]) if self.curSelectId and self.curSelectId == data.ID then UIUtils.SetActive(btn.Checkmark01, true) btn.UIState_Select:SetState(1) else UIUtils.SetActive(btn.Checkmark01, false) btn.UIState_Select:SetState(0) end --暂未开放,显示敬请期待 if CTL.Guild.UnOpenGuildActivity[data.ID] then btn.state:SetState(1) return end local buildInfo = MDL.Guild.GetBuildInfo(data.ID) local buildingData = DataSheetManager.GuildBuilding:GetDataByBuildingType_Level(data.ID,buildInfo.level) btn.labLocal_Level.text = buildInfo.level if not buildInfo.isBuilding then --可升级 btn.effect:StopUIEffect() btn.state:SetState(2) local maxLevel = DataSheetManager.GuildBuilding:GetDataLengthByBuildingType_Level(data.ID) local isMax = buildInfo.level == maxLevel btn.group_Arrow.gameObject:SetActive(self:IsUnLock(buildingData) and not isMax) elseif buildInfo.isBuilding then --正在升级 btn.effect:PlayUIEffect() btn.state:SetState(0) local time = buildInfo.buildingEndTime - UTL.Time.GetServerTimestamp() btn.txt_TimeNum:ResetAndBeginCustomTimer(true, buildingData.Time - time, buildingData.Time, nil) else btn.effect:StopUIEffect() btn.state:SetState(1) end end function UIGuildArchitecture:IsUnLock(buildingData) local isUnLock = true for i,v in ipairs(buildingData.LevelUpTrigger_Table) do local _, tmpContent = MDL.Unlock.IsComplete(v.LevelUpTriggerID, v.LevelUpTriggerParams) isUnLock = isUnLock and _ end local count = MDL.Currency.GetMoneyCount(MDL.Currency.CurrencyType.GuildWuZi) isUnLock = isUnLock and (count >= buildingData.CostValue) return isUnLock end return UIGuildArchitecture