-- <* -- @Author: Saber -- @Description: 社团改名改标识界面 -- *> GuildRenameView = GuildRenameView or BaseClass(BaseView) local GuildRenameView = GuildRenameView function GuildRenameView:__init() self.base_file = "guild" self.layout_file = "GuildRenameView" self.layer_name = "Activity" self.destroy_imm = true self.use_background = true --全屏界面默认使用这个参数,非全屏界面自行设置 self.change_scene_close = true --是否切换场景时关闭(弹出界面使用) -- self.append_to_ctl_queue = true --是否要添加进界面堆栈 self.blur_activity_bg = true self.use_show_anim = true self.use_hide_anim = true self.model = GuildModel:getInstance() self.no_guild_name_str = "(未命名)" self.tip_time = Status.NowTime self.icon_list = {} -- 图标列表 self.color_list = {} -- 颜色列表 self.cur_flag = 10001 self.cur_icon_flag = 1 self.cur_icon_color = 1 self.name_limit = 6 -- 社团名称字数限制 self.load_callback = function () self:LoadSuccess() self:AddEvent() end self.open_callback = function ( ) self:OpenSuccess() end self.switch_callback = function(index) self:SwitchTab(index) end self.destroy_callback = function ( ) self:DestroySuccess() end end function GuildRenameView:Open( ) --self.data = data BaseView.Open(self) end function GuildRenameView:LoadSuccess() local nodes = { "content", "content/comfirm_btn:obj", "content/cur_icon:img", "content/name_input:tmpInput", "content/color_con", "content/icon_con", "content/rename_cond:tmp", "content/final_name:tmp", -- 改名花费 "content/rename_cost_icon:img", "content/rename_costval:tmp", -- 改标识花费 "content/flag_cost_icon:img", "content/flag_costval:tmp", -- 总花费 "content/total_cost_node", "content/total_cost_node/total_cost_icon:img", "content/total_cost_node/total_cost_title:tmp", "content/total_cost_node/total_costval:tmp", } self:GetChildren(nodes) self.final_name_tmp.text = self.no_guild_name_str local function close_callback() self:Close() end self.tabWindowComponent = UITabWindow.New(self.transform, {}, nil, close_callback, self.background_wnd, self.content, UITabWindow.SizeSmallNoTab, nil, nil, true) self.tabWindowComponent:SetTitleText("信息变更") self.tabWindowComponent:SetBackgroundRes("guild_rename_bg") end function GuildRenameView:AddEvent() local function click_event(target) if target == self.comfirm_btn_obj then -- 确认修改 self:OnComfirmBtnClick() end end AddClickEvent(self.comfirm_btn_obj, click_event) -- 输入监听 self.name_input_tmpInput.onValueChanged:AddListener(function() local len = utf8len(self.name_input_tmpInput.text) if len > self.name_limit then self.name_input_tmpInput.text = GetInputLimitResultStr(self.name_input_tmpInput.text, self.name_limit) --减去多出来的字符 self.tip_time = self.tip_time or 0 if Status.NowTime - self.tip_time > 0.2 then Message.show(string.format("最多可输入%s个字符", self.name_limit), "fault") self.tip_time = Status.NowTime end end -- 右侧同步玩家输入的社团名称 self.final_name_tmp.text = self.name_input_tmpInput.text == "" and self.no_guild_name_str or self.name_input_tmpInput.text self:UpdateTotalCost() end) end function GuildRenameView:OpenSuccess() if self.tabWindowComponent then self.tabWindowComponent:ChangeShowFlag("smallWindow2") end self:UpdateView() end function GuildRenameView:UpdateView() self:InitFlagDataAndChangeCost() self:UpdateGuildIconAndColor() end -- 获取当前的社团旗帜和扣费配置 function GuildRenameView:InitFlagDataAndChangeCost( ) local guild_info = self.model:GetGuildBaseInfo() local flag = guild_info and guild_info.guild_flag self.cur_flag = flag self.cur_icon_flag = flag and math.floor(flag / 10000) or 1 self.cur_icon_color = flag and flag % 10000 or 1 -- 扣费配置 self.changed_name_cfg = stringtotable(self.model:GetGuildKvByKey("rename_cost").val)[1] local cost_asset, cost_res = WordManager:GetCommonMoneyIcon(self.changed_name_cfg[1]) lua_resM:setImageSprite(self, self.rename_cost_icon_img, cost_asset, cost_res) self.change_flag_cfg = stringtotable(self.model:GetGuildKvByKey("logo_change_cost").val)[1] cost_asset, cost_res = WordManager:GetCommonMoneyIcon(self.change_flag_cfg[1]) lua_resM:setImageSprite(self, self.flag_cost_icon_img, cost_asset, cost_res) end function GuildRenameView:UpdateGuildIconAndColor( ) local function icon_call_back(index) for k, v in ipairs(self.icon_list) do if v.index then v:SetSelect(v.index == index) end end self.cur_icon_flag = index self:ChangePreviewIcon() end local offset_x = (self.icon_con.sizeDelta.x - 4 * 86) / 2 + 10 for i = 1, 4 do local item = self.icon_list[i] if not item then item = GuildCreateIconItem.New(self.icon_con, nil, self.layer_name) self.icon_list[i] = item end local pos = Vector2((i-1) * 86 + offset_x, -13) item:SetData(i, pos, icon_call_back) item:SetSelect(i == self.cur_icon_flag) end local function color_callback(index) for k, v in ipairs(self.color_list) do if v.index then v:SetSelect(v.index == index) end end self.cur_icon_color = index self:ChangePreviewIcon() end offset_x = (self.color_con.sizeDelta.x - 8 * 50) / 2 + 6 for i = 1, 8 do local item = self.color_list[i] if not item then item = GuildCreateColorItem.New(self.color_con, nil, self.layer_name) self.color_list[i] = item end local pos = Vector2((i-1) * 50 + offset_x, 0) item:SetData(i, pos, color_callback) item:SetSelect(i == self.cur_icon_color) end -- color_callback(1) self:ChangePreviewIcon() end -- 修改右侧已设置的社团icon样式和花费 function GuildRenameView:ChangePreviewIcon( ) lua_resM:setImageSprite(self, self.cur_icon_img, "guildIcon_asset", "guild_icon" .. (self.cur_icon_flag * 10000 + self.cur_icon_color), true) self:UpdateTotalCost() end -- 更新总花费 function GuildRenameView:UpdateTotalCost( ) local new_name = self.name_input_tmpInput.text -- 是否已经改了名字 local changed_name = new_name ~= "" and 1 or 0 -- 是否已经改了旗帜 local new_flag = self.cur_icon_flag * 10000 + self.cur_icon_color local changed_flag = new_flag ~= self.cur_flag local rename_cost = changed_name == 1 and self.changed_name_cfg[3] or 0 local flag_cost = changed_flag and self.change_flag_cfg[3] or 0 local total_cost = rename_cost + flag_cost self.rename_costval_tmp.text = rename_cost self.flag_costval_tmp.text = flag_cost self.total_costval_tmp.text = total_cost -- 对齐节点 local offset_x = (self.total_cost_node.sizeDelta.x - self.total_costval_tmp.preferredWidth - self.total_cost_title_tmp.preferredWidth - 42) / 2 SetAnchoredPositionX(self.total_cost_title, offset_x) SetAnchoredPositionX(self.total_cost_icon, offset_x + self.total_cost_title_tmp.preferredWidth + 5) SetAnchoredPositionX(self.total_costval, self.total_cost_icon.anchoredPosition.x + 37) end -- 点击确认按钮 function GuildRenameView:OnComfirmBtnClick( ) local total_cost = tonumber(self.total_costval_tmp.text) if total_cost ~= 0 then -- 有变动了就允许发协议 local new_name = self.name_input_tmpInput.text -- 是否已经改了名字 local changed_name = new_name ~= "" and 1 or 0 -- 新旗帜 local new_flag = self.cur_icon_flag * 10000 + self.cur_icon_color local function ok_callback() self.model:Fire(GuildModel.REQUEST_CCMD_EVENT, 40025, changed_name, new_name, new_flag) end local priceText = string.format("%s 修改社团信息?", ColorUtil.YELLOW_DARK, total_cost) local function use_function( toggle_tip_data, call_fun_sum ) if total_cost ~= 0 then GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data) else call_fun_sum() end end local data = { gold_type = 1, cost_price = total_cost, ok_callback = ok_callback, togglePriceStr = priceText, use_function = use_function, no_need_toggle = true, recharge_open_call_back = function() self:Close() end, } CustomActivityModel:getInstance():BuyTips(data) else Message.show("好像什么都没改动哦~", "fault") end end function GuildRenameView:DestroySuccess( ) for k, v in pairs(self.icon_list) do v:DeleteMe() v = nil end for k, v in pairs(self.color_list) do v:DeleteMe() v = nil end if self.tabWindowComponent then self.tabWindowComponent:DeleteMe() self.tabWindowComponent = nil end end