-- 改名界面 local UIRenamePanel = UIViewClass() local ChangeNameCost = DataSheetManager.ConstData:GetDataByID("ChangeNameCost").IntListValue local ChangeNameItemId = ChangeNameCost[1] local ChangeNameCostNum = ChangeNameCost[2] local ChangeNameCDTime = DataSheetManager.ConstData:GetDataByID("ChangeNameCDTime").IntValue local ChangeNameFreeNum = DataSheetManager.ConstData:GetDataByID("ChangeNameFreeTimes").IntValue local ChangeNameLevelLimit = DataSheetManager.ConstData:GetDataByID("ChangeNameFreeMaxLevel").IntValue -------------------- function UIRenamePanel:OnOpened() self:RegistSystemEvent(EventID.UI_RefreshCurrency, self.SetChangeNamePanel) self:RegistSystemEvent(EventID.UI_RefreshRandomName, self.RefreshRandomName) UIUtils.SetLabelText(self.txt_Tips, Const_IDS.IDS_PlayName_ChangeName) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_PlayName_ReName) UIUtils.SetLabelText(self.Placeholder, Const_IDS.IDS_PlayName_Hint2) self.gender = MDL.Player.GetSelfGender() self.group_Gender:SelectIndex(self.gender - 1) self:SetChangeNamePanel() end function UIRenamePanel:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIRenamePanel:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.btn_Sure then self:OnBtnOKClick() elseif comp == self.event_Random then self:OnBtnRandomClick() end end function UIRenamePanel:OnValueChanged(comp, index) if index == 0 then self.gender = LuaConst.Gender.Male elseif index == 1 then self.gender = LuaConst.Gender.Female end end function UIRenamePanel:OnUpdateFun(deltaTime, timeSinceUpdate) self:SetChangeNamePanel() end -------------------- function UIRenamePanel:SetChangeNamePanel() local lastTime = MDL.Name.GetLastNamedTime() local cdTime = os.difftime(lastTime + ChangeNameCDTime, UTL.Time.GetServerTimestamp()) self.isInCD = cdTime > 0 if not self.isInCD then self.txt_CDTips:ActiveComponents(false) self:StopRepeatFunc(self.OnUpdateFun) else self.txt_CDTips:ResetAndBeginCustomTimer(false, cdTime, 0, UIUtils.GetLocalizedTxt(Const_IDS["IDS_PlayName_ChangeNameCDTime"]), 1) self:StartRepeatFunc(self.OnUpdateFun, cdTime) end UIUtils.SetActive(self.group_NameChange.gameObject, true) if self:IsHaveFreeNums() then UIUtils.SetActive(self.group_Cost, false) if MDL.HeroSelect.GetTeamLevel() < ChangeNameLevelLimit then -- %s级之前,首次改名免费 UIUtils.SetLabel(self.txt_LevelHint, string.FormatByIdsId(Const_IDS.IDS_PlayName_ChangeNameCostFreeLevel, ChangeNameLevelLimit)) else -- 合服后给玩家赠送新的改名机会 UIUtils.SetLabelText(self.txt_LevelHint, Const_IDS.IDS_GamexMerge_Rename) end UIUtils.SetActive(self.txt_LevelHint, true) else UIUtils.SetActive(self.group_Cost, true) UIUtils.SetActive(self.txt_LevelHint, false) if MDL.Currency.IsMoneyEnough(ChangeNameItemId, ChangeNameCostNum) then UIUtils.SetLabel(self.txt_Count, "x" .. ChangeNameCostNum) else UIUtils.SetLabel(self.txt_Count, UTL.Color.FormatRedColor("x" .. ChangeNameCostNum)) end UTL.Item.ItemIconWithoutBg(self.img_Icon, ChangeNameItemId) end end function UIRenamePanel:RefreshRandomName() self.obj_input.text = CTL.Name.GetRandomName() end function UIRenamePanel:IsHaveFreeNums() return MDL.Name.GetNamedFreeNums() > 0 end function UIRenamePanel:IsCanChangeName() if self:IsHaveFreeNums() or MDL.Currency.IsMoneyEnough(ChangeNameItemId, ChangeNameCostNum) then if not self.isInCD then return true else CTL.Tips.AddTipsMsg(Const_IDS.IDS_PlayName_NotInCDTime) end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Store_CoinExchange_NotEnough) end end function UIRenamePanel:OnBtnRandomClick() local randomName = CTL.Name.GetRandomName() if randomName ~= "" then self.obj_input.text = randomName end end function UIRenamePanel:OnBtnOKClick() local tempName = self.obj_input.text -- 发给服务器验证名字合法性 if CTL.Name.IsNameLegal(tempName) then if self.gender then if self:IsCanChangeName() then local content if tempName == BattleDataGetter.GetPlayerName() and self.gender ~= MDL.Player.GetSelfGender() then -- 名字相同,仅改变性别 content = string.FormatByIdsId(Const_IDS.IDS_ChangeName_GenderChange) else content = string.FormatByIdsId(Const_IDS.IDS_PlayName_ReNameConfirmText, tempName) end if GameAppInfo.IsJapanesePackage() and self:IsHaveFreeNums() == false then local costDragonSufix = "\n" .. UIUtils.GetLocalizedTxt(Const_IDS.IDS_JP_MoneyConsumption_Pay) .. "\n" .. UIUtils.GetLocalizedTxt(Const_IDS.IDS_JP_MoneyConsumption_Time) .. "\n" .. UIUtils.GetLocalizedTxt(Const_IDS.IDS_JP_MoneyConsumption_CannotCancel) UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_PlayName_ReNameConfirmTitle, content .. costDragonSufix, function() MDL.Name.SendAccountName(tempName, self.gender, true) end) else UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_PlayName_ReNameConfirmTitle, content, function() MDL.Name.SendAccountName(tempName, self.gender, true) end) end end else -- 提示需要选择性别 CTL.Tips.AddTipsMsg(Const_IDS.IDS_Gender_Choose) end end end return UIRenamePanel