local UICountryRenamePanel = UIViewClass() function UICountryRenamePanel:OnOpened(context) UIUtils.SetLabelText(self.txt_Tips, Const_IDS.IDS_CountrySetting_ChangeReignIntro) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_CountrySetting_ChangeReign) UIUtils.SetLabelText(self.Placeholder, Const_IDS.IDS_Guild_InputCommon) local costType = DataSheetManager.ConstData:GetDataByID("CountryReignCostType").IntValue local costCount = DataSheetManager.ConstData:GetDataByID("CountryReignCostIValue").IntValue local coinData = DataSheetManager.ItemData:GetDataByID(costType) UTL.Item.SetAtlasSprite(self.img_Icon, "UI_Common", coinData.Icon) local count = MDL.Currency.GetMoneyCount(costType) if count < costCount then self.txt_Count.text = UTL.Color.FormatRedColor(costCount) self.isEnough = false else self.txt_Count.text = costCount self.isEnough = true end self.changeNameCDTime = DataSheetManager.ConstData:GetDataByID("CountryReignCD").IntValue self:SetChangeNamePanel() self.event_Random.gameObject:SetActive(false) self:RegistSystemEvent(EventID.UI_RefreshCurrency, self.RefreshCost) end function UICountryRenamePanel:RefreshCost() local costType = DataSheetManager.ConstData:GetDataByID("CountryReignCostType").IntValue local costCount = DataSheetManager.ConstData:GetDataByID("CountryReignCostIValue").IntValue local count = MDL.Currency.GetMoneyCount(costType) if count < costCount then self.txt_Count.text = UTL.Color.FormatRedColor(costCount) self.isEnough = false else self.txt_Count.text = costCount self.isEnough = true end end function UICountryRenamePanel:SetChangeNamePanel() UIUtils.SetActive(self.group_NameChange.gameObject, true) UIUtils.SetActive(self.group_Cost, true) UIUtils.SetActive(self.txt_LevelHint, false) local changeCount = MDL.Country.GetMyCountryInfo().titleChangeTimes if changeCount == 0 then UIUtils.SetLabelText(self.txt_First, Const_IDS.IDS_CountrySetting_FirstTimeFree) UIUtils.SetActive(self.group_NameChange, false) self.isEnough = true else UIUtils.SetActive(self.group_NameChange, true) local lastTime = MDL.Country.GetMyCountryInfo().nextTitleChangeTime if lastTime and lastTime > 0 then local cdTime = os.difftime(lastTime, UTL.Time.GetServerTimestamp()) self.isInCD = cdTime > 0 if self.isInCD then self:StartRepeatFunc(self.SetChangeNamePanel, cdTime + 1, 1) CTL.Country.SetCdTime(self.txt_CDTips, cdTime, Const_IDS.IDS_Country_ChangeReignCDIntro) end end end end function UICountryRenamePanel:OnValueChanged(comp, value) if comp == self.obj_input then local length = DataSheetManager.ConstData:GetDataByID("CountryReignNumlimit").IntValue self.obj_input.text = UTL.String.CutStrByLength(self.obj_input.text, length) end end function UICountryRenamePanel:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UICountryRenamePanel:OnButtonClicked(comp) if comp == self.btn_Sure then if string.isNilOrEmpty(self.obj_input.text) then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_Country_ReignTitleEmpty) return end if self.isInCD then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(self.txt_CDTips.CDText.text) return end local info = MDL.Country.GetMyCountryInfo() if self.obj_input.text == MDL.Country.GetCountryTitle(info.reignTitle, info.countryID) then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_GuildRepeatedName) return end if self.isEnough then local value = DataSheetManager.ConstData:GetDataByID("CountryReignCD").IntValue local day = math.floor(value / UTL.Time.TotalSecondsOneDay) local result = string.FormatByIdsId(Const_IDS.IDS_Item_Time_Day, day) local content = string.FormatByIdsId(Const_IDS.IDS_CountrySetting_ChangeReignConfirm, result, self.obj_input.text) UTL.MessageBox.ShowOKCancelBox(nil, content, function() MDL.Country.CountrySetReignTitleReq(self.obj_input.text) self:CloseView() end) else CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_Guild_CommonFail5) end elseif comp == self.UICommonPopUp.btn_Close then self:CloseView() end end function UICountryRenamePanel:GetCountryLengthDesc() local length = DataSheetManager.ConstData:GetDataByID("CountryReignNumlimit").IntValue if Localization.IsAllChinese() then length = length / 2 end return string.FormatByIdsId(Const_IDS.IDS_Guild_InputCommon, length) end return UICountryRenamePanel