local UIChangAnSiegeBattleGround = UIViewClass() --UIManager.OpenView(Const_UI_Lua.UIEnum.UIChangAnSiegeBattleGround,{tableIndex = 2, slotIndex = 5}) function UIChangAnSiegeBattleGround:OnOpened(context) if context then self.toggles_Tab:SelectIndex(context.tableIndex) local slotItem = self.group_Info[context.tableIndex + 1][context.slotIndex] if slotItem then self:ClickItem(slotItem.btn_Icon) UIUtils.SetActive(slotItem.img_Chk, true) end else self.toggles_Tab:SelectIndex(0) end end function UIChangAnSiegeBattleGround:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIChangAnSiegeBattleGround:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() elseif comp == self.btn_Before then self:ShowBefore() elseif comp == self.btn_Next then self:ShowNext() else self:ClickItem(comp) end end function UIChangAnSiegeBattleGround:ShowNext() self.curSelectIndex = self.curSelectIndex + 1 self.toggles_Tab:SelectIndex(self.curSelectIndex) end function UIChangAnSiegeBattleGround:ShowBefore() self.curSelectIndex = self.curSelectIndex - 1 self.toggles_Tab:SelectIndex(self.curSelectIndex) end function UIChangAnSiegeBattleGround:ClickItem(comp) for i = 1, 3 do for k,v in ipairs(self.group_Info[i]) do if comp == v.btn_Icon then self:ShowFactorInfo(i, k) break end end end end function UIChangAnSiegeBattleGround:OnValueChanged(comp, index) if comp == self.toggles_Tab then self.curSelectIndex = index self:ShowDetail(index+1) self.btn_Before.gameObject:SetActive(self.curSelectIndex ~= 0) self.btn_Next.gameObject:SetActive(self.curSelectIndex ~= 2) if index == 0 and (BattleDataGetter.IsCityWarLevel() or BattleDataGetter.IsCityWarWaitingLevel()) then local slotItem = self.group_Info[1][self.context.slotIndex] if slotItem then self:ClickItem(slotItem.btn_Icon) UIUtils.SetActive(slotItem.img_Chk, true) end end end end function UIChangAnSiegeBattleGround:ShowDetail(index) for i=1,3 do UIUtils.SetActive(self.group_Info[i].gameObject, i == index) if i == index then if MDL.ChangAnSiege.IsDefendCountry() then self.group_Info[4][i]:SetState(0) else self.group_Info[4][i]:SetState(1) end end end if MDL.ChangAnSiege.IsDefendCountry() then if index == 1 then self:ShowFactorInfo(index, 1) elseif index == 2 then self:ShowFactorInfo(index, 4) elseif index == 3 then self:ShowFactorInfo(index, 8) end else if index == 1 then self:ShowFactorInfo(index, 2) elseif index == 2 then self:ShowFactorInfo(index, 7) elseif index == 3 then self:ShowFactorInfo(index, 13) end end for _, data in DataSheetManager.SiegeCityFieldIntro:GetDataByFieldID_FactorID(index) do UIUtils.SetLabelText(self.group_Info[index][data.FactorID].lab_Name, Const_IDS[data.FactorName]) end end function UIChangAnSiegeBattleGround:ShowFactorInfo(fieldID, factorID) local data = DataSheetManager.SiegeCityFieldIntro:GetDataByFieldID_FactorID(fieldID, factorID) UIUtils.SetLabelText(self.txt_Name, Const_IDS[data.FactorName]) UIUtils.SetLabel(self.txt_Info, self:GetDesc(data)) UIUtils.SetLabelText(self.txt_Target, Const_IDS[data.FactorTag]) UIUtils.SetImageByAssetBundle(self.img_Icon, data.IconID) for i,v in ipairs(self.group_Info[fieldID]) do UIUtils.SetActive(self.group_Info[fieldID][i].img_Chk.gameObject, i == factorID) end end function UIChangAnSiegeBattleGround:GetDesc(data) if #data.Variable_Table > 0 then local params = {} for i,v in ipairs(data.Variable_Table) do local excel = DataSheetManager[v.TableName] local key = tonumber(v.KeyId) or v.KeyId table.insert(params, excel["GetDataBy"..v.KeyName](excel, key)[v.ColumnName]) end return string.FormatByIdsKey(data.Intro, unpack(params)) else return UIUtils.GetLocalizedTxt(Const_IDS[data.FactorIntro]) end end return UIChangAnSiegeBattleGround