local UICountryDiary = UIViewClass() local EverydayID = 1 function UICountryDiary:OnOpened(context) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_CountryEvent) local options = { UIUtils.GetLocalizedTxt(Const_IDS.IDS_GuildEvent_All) } for i, v in DataSheetManager.CountryEventType:GetEnumerator() do table.insert(options, UIUtils.GetLocalizedTxt(Const_IDS[v.EventType])) end UIUtils.DropdownAddOptions(self.Dropdown, options) MDL.Country.CountryGetDynamicInfoReq() self:RegistSystemEvent(EventID.UI_Country_DiaryRefresh, self.OnDiaryRefresh) end local function TableSort(a, b) return a.time > b.time end function UICountryDiary:OnDiaryRefresh(list) table.sort(list, TableSort) self.dataList = list for i, v in ipairs(list) do self.LoopScroll_Diary:AddData(v, 0) end end function UICountryDiary:ShowDiaryList(index) local list = {} if index == 0 then list = self.dataList else for i, v in ipairs(self.dataList) do local excelData = DataSheetManager.CountryEvent:GetDataByID(v.eventId) if excelData.EventType == index then table.insert(list, v) end end end self.LoopScroll_Diary:ClearCells() for i, v in ipairs(list) do self.LoopScroll_Diary:AddData(v, 0) end end function UICountryDiary:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UICountryDiary:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() end end function UICountryDiary:OnValueChanged(comp, value) if comp == self.Dropdown then self:ShowDiaryList(value) end end function UICountryDiary:OnCellInit(scrollRect, index, cellTable, data) if GameAppInfo.IsVietnamPackage() then cellTable.txt_Team.text = os.date(UTL.Time.FormatDateEnum.YMD, data.createTime) cellTable.txt_Date.text = os.date(UTL.Time.FormatDateEnum.HM, data.createTime) else cellTable.txt_Date.text = os.date(UTL.Time.FormatDateEnum.YMD, data.createTime) cellTable.txt_Team.text = os.date(UTL.Time.FormatDateEnum.HM, data.createTime) end local excelData = DataSheetManager.CountryEvent:GetDataByID(data.eventId) if data.eventId == EverydayID then cellTable.txt_Diary.text = self:GetDiaryStr(excelData.EventText, data.params) cellTable.img_Choose.gameObject:SetActive(true) else local strs = {} for i, v in ipairs(data.params) do if string.match(v, "^IDS") and Const_IDS[v] then table.insert(strs, UIUtils.GetLocalizedTxt(Const_IDS[v])) else table.insert(strs, v) end end cellTable.txt_Diary.text = string.FormatByIdsId(Const_IDS[excelData.EventText], unpack(strs)) cellTable.img_Choose.gameObject:SetActive(false) end if index % 2 == 0 then cellTable.img_Bg.gameObject:SetActive(false) cellTable.img_Bg01.gameObject:SetActive(true) else cellTable.img_Bg.gameObject:SetActive(true) cellTable.img_Bg01.gameObject:SetActive(false) end end function UICountryDiary:GetDiaryStr(ids, params) return string.FormatByIdsId(Const_IDS[ids], params[1], params[2], self:GetColorStr(params[3])) end function UICountryDiary:GetColorStr(param) local value = tonumber(param) if value >= 0 then return UTL.Color.FormatGreenColor("+" .. value) else return UTL.Color.FormatRedColor(value) end end return UICountryDiary