|
|
- --<*
- -- @Author: Saber
- -- @Description: 创建社团界面
- --*>
-
- GuildCreateView = GuildCreateView or BaseClass(BaseView)
- local GuildCreateView = GuildCreateView
-
- function GuildCreateView:__init()
- self.base_file = "guild"
- self.layout_file = "GuildCreateView"
- self.layer_name = "Activity"
- self.destroy_imm = true
- self.hide_maincancas = true
- self.use_background = true
- self.blur_activity_bg = true
- self.use_show_anim = true
- self.use_hide_anim = true
- self.type_tab_list = {} -- 社团tab列表
- self.icon_list = {} -- 图标列表
- self.color_list = {} -- 颜色列表
- self.cur_icon_flag = 1
- self.cur_icon_color = 1
- self.change_scene_close = true --是否切换场景时关闭(弹出界面使用)
- --self.append_to_ctl_queue = false --是否要添加进界面堆栈
- self.tab_index = 3 -- 默认选中3级社团
- self.no_guild_name_str = "<color=#D5D7DF>(未命名)</color>"
- self.tip_time = Status.NowTime
- self.name_limit = 6 -- 社团名称字数限制
- self.cur_tab_cost_cfg = nil -- 当前选中的扣费配置
- self.cur_tab_guild_lv = 0 -- 当前选中的社团等级
-
- self.model = GuildModel:getInstance()
-
- self.is_in_create_discount = self.model:IsInCreateGuildDiscount()
-
- self.load_callback = function ()
- self:LoadSuccess()
- self:AddEvent()
- end
- self.open_callback = function ( )
- self:OpenSuccess()
- end
- self.destroy_callback = function ( )
- self:DestroySuccess()
- end
- end
-
- function GuildCreateView:Open( )
- --self.data = data
- BaseView.Open(self)
- end
-
- function GuildCreateView:LoadSuccess()
- local nodes = {
- "content",
- "content/tab_con",
- "content/name_input:tmpInput", "content/color_con", "content/icon_con", "content/cur_icon:img",
- "content/createBtn:obj",
- "content/cost_node", "content/cost_node/create_cost_icon:img",
- "content/cost_node/create_costval:tmp", "content/cost_node/create_cost_title:tmp",
- "content/create_cond:tmp", "content/final_name:tmp",
- "content/cost_node/create_costval_discount:tmp", "content/cost_node/create_costval_line:obj",
- }
- self:GetChildren(nodes)
- self.final_name_tmp.text = self.no_guild_name_str
- -- self.name_input_tmpInput.characterLimit = self.name_limit
-
- 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_create_bg")
- end
-
- function GuildCreateView:AddEvent()
- local function click_event(target)
- if target == self.createBtn_obj then
- if self.is_in_create_discount then--如果界面打开时已经是折扣状态了,那创建社团需要发协议检测下还能否折扣
- self.model.handle_40071_flag = 2--为2时处理创建界面的创建社团折扣提醒
- self.model:Fire(GuildModel.REQUEST_CCMD_EVENT, 40071)--查询判断历史社团最大数再去做社团创建
- else
- self:OnCreateBtnClick()
- end
- end
- end
- AddClickEvent(self.createBtn_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
- end)
-
- local function do_create_guild()
- if self.model.handle_40071_flag and self.model.handle_40071_flag == 2 then
- local is_in_discount = self.model:IsInCreateGuildDiscount()
- if not is_in_discount then
- local function ok( ... )
- self:OnCreateBtnClick()
- end
- local ask_str = "手慢了喔~当前折扣创建名额不足,是否继续以原价创建?"
- Alert.show(ask_str,Alert.Type.Two,ok,nil,"确定","取消")
- else
- self:OnCreateBtnClick()
- end
- end
- end
- self:BindEvent(self.model, GuildModel.AFTER_GET_HISTORY_GUILD_COUNT, do_create_guild)
- end
-
- function GuildCreateView:OpenSuccess()
- if self.tabWindowComponent then
- self.tabWindowComponent:ChangeShowFlag("smallWindow2")
- end
- self:UpdateView()
- end
-
- function GuildCreateView:UpdateView()
- self:UpdateGuildTypeTab()
- -- self:SwitchTabindex(self.tab_index)
- self:UpdateGuildIconAndColor()
- end
-
- function GuildCreateView:UpdateGuildTypeTab( )
- local tab_list = {}
- for k, v in pairs(Config.Guildcreate) do
- tab_list[#tab_list+1] = v
- end
- local sort_func = function ( a, b )
- return a.cfg_id > b.cfg_id
- end
- table.sort(tab_list, sort_func)
- -- guild_type == tab_index
- local function tab_callback(guild_type, index)
- for k, item in pairs(self.type_tab_list) do
- item:SetSelected(guild_type)
- end
- self:SwitchTabindex(guild_type, tab_list[index])
- end
-
- local item
- for k, v in ipairs(tab_list) do
- item = self.type_tab_list[k]
- if not item then
- item = GuildCreateTabItem.New(self.tab_con)
- self.type_tab_list[k] = item
- end
- item:SetAnchoredPosition(3 + (k-1) * 172, -3)
- item:SetData(v, k, tab_callback)
- end
- -- 自动选中第三级
- self.tab_index = tab_list[1].cfg_id
- tab_callback(self.tab_index, 1)
- end
-
- function GuildCreateView:SwitchTabindex( index, create_cfg )
- self.tab_index = index
- -- 加载条件
- local cond = stringtotable(create_cfg.condition)
- local condi_str = ""
- for k, v in pairs(cond) do
- if v[1] == "lv" then
- condi_str = condi_str .. string.format("<color=#ffffff><size=20> Lv.%s </size></color>", v[2])
- elseif v[1] == "vip" then
- condi_str = condi_str .. string.format("<color=#fdffc2><size=20> VIP%s </size></color>", v[2])
- end
- if k < #cond then
- condi_str = condi_str .. "或"
- end
- end
- self.create_cond_tmp.text = "创建需求 " .. condi_str
- -- 加载不同创建类型下的消费
- local cost_cfg = stringtotable(create_cfg.cost)[1]
- self.cur_tab_cost_cfg = cost_cfg
- self.cur_tab_guild_lv = create_cfg.guild_lv
- local icon_asset, icon_name = WordManager:GetCommonMoneyIcon(cost_cfg[1])
- lua_resM:setImageSprite(self, self.create_cost_icon_img, icon_asset, icon_name)
- self.create_costval_tmp.text = cost_cfg[3]
- -- 对齐消耗节点位置
- local offset_x = (self.cost_node.sizeDelta.x - self.create_costval_tmp.preferredWidth - self.create_cost_title_tmp.preferredWidth - 42) / 2
- SetAnchoredPositionX(self.create_cost_title, offset_x)
- SetAnchoredPositionX(self.create_cost_icon, offset_x + self.create_cost_title_tmp.preferredWidth + 5)
- SetAnchoredPositionX(self.create_costval, self.create_cost_icon.anchoredPosition.x + 37)
-
- --是否处于社团创建折扣期
- local is_in_discount = self.model:IsInCreateGuildDiscount()
- if is_in_discount then
- self.create_costval_line_obj:SetActive(true)
- local discount = stringtotable(self.model:GetGuildKvByKey("create_guild_discount").val)[2]
- self.create_costval_discount_tmp.text = cost_cfg[3]*discount
- SetAnchoredPositionX(self.create_costval_line, self.create_cost_icon.anchoredPosition.x + 34)
- SetAnchoredPositionX(self.create_costval_discount, self.create_costval.anchoredPosition.x + self.create_costval_tmp.preferredWidth + 10)
- SetAnchoredPositionX(self.cost_node,238)
- else
- self.create_costval_line_obj:SetActive(false)
- self.create_costval_discount_tmp.text = ""
- SetAnchoredPositionX(self.cost_node,255)
- end
- end
-
- function GuildCreateView:OnCreateBtnClick( )
- if self.name_input_tmpInput.text == "" then
- Message.show("请输入社团名称")
- return
- end
-
- if HasLimitChar(self.name_input_tmpInput.text) then
- Message.show("社团名称名存在非法字符,请重新输入")
- return
- end
-
- local _, title_filter = LanguageFilter.FilterMsg(self.name_input_tmpInput.text)
- if title_filter == false then
- Message.show("社团名称有敏感词")
- return
- end
-
- local is_in_discount = self.model:IsInCreateGuildDiscount()
- local discount = 1
- if is_in_discount then
- discount = stringtotable(self.model:GetGuildKvByKey("create_guild_discount").val)[2]
- end
-
- local pay = self.tab_index
- local function create_func( )
- self.name_input_tmpInput.text = Util.SetNonBreakSpaceText(self.name_input_tmpInput.text)
- self.model:Fire(GuildModel.RequestCreateGuildEvt, pay, self.name_input_tmpInput.text, self.cur_icon_flag * 10000 + self.cur_icon_color)
- end
- local priceText = string.format("<color=%s>%s</color> 创建%s级社团?", ColorUtil.YELLOW_DARK, self.cur_tab_cost_cfg[3]*discount, self.cur_tab_guild_lv)
- local function use_function( toggle_tip_data, call_fun_sum )
- if self.cur_tab_cost_cfg[3]*discount ~= 0 then
- GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
- else
- call_fun_sum()
- end
- end
-
-
- local data = {
- gold_type = tonumber(self.cur_tab_cost_cfg[1]),
- cost_price = tonumber(self.cur_tab_cost_cfg[3])*discount,
- ok_callback = create_func,
- togglePriceStr = priceText,
- use_function = use_function,
- recharge_open_call_back = function()
- self:Close()
- end,
- no_need_toggle = true,
- }
- CustomActivityModel:getInstance():BuyTips(data)
- end
-
- function GuildCreateView: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
-
- function GuildCreateView:ChangePreviewIcon( )
- lua_resM:setImageSprite(self, self.cur_icon_img, "guildIcon_asset", "guild_icon" .. (self.cur_icon_flag * 10000 + self.cur_icon_color))
- end
-
- function GuildCreateView:DestroySuccess( )
- for k, v in pairs(self.type_tab_list) do
- v:DeleteMe()
- v = nil
- end
- 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
|