|
|
- --<*
- -- @Author: Saber
- -- @Description: 申请社团界面
- --*>
- GuildApplyView = GuildApplyView or BaseClass(BaseItem)
- local GuildApplyView = GuildApplyView
-
- function GuildApplyView:__init(parent_wnd,prefab_asset,layer_name)
- self.base_file = "guild"
- self.layout_file = "GuildApplyView"
- self.parent_wnd = parent_wnd
- self.layer_name = layer_name
-
- self.guild_list_data = {} -- 社团列表
- self.sroll_end_req_evt = false -- 滑动到底时请求协议
- self.cur_page = 1 -- 当前加载了多少页的社团数据
- self.total_page = 0 -- 总页数
- self.page_size = 15 --向服务器发送一页的个数
- self.search_name = "" -- 当前搜索的社团名称
- self.search_filter = 0 -- 搜索过滤已满社团 1:使用过滤
- self.cur_select_leader_id = nil -- 当前选中的社团会长id
- self.cur_select_guild_id = nil -- 当前选中的社团id
- self.selected_item_index = 0 -- 当前选中的社团item的index
- self.is_in_guide = false --当前是否在引导
- self.model = GuildModel:getInstance()
- self:Load()
- end
-
- function GuildApplyView:Load_callback()
- local nodes = {
- -- 左侧选中社团信息
- "left/guild_icon:img", "left/leader_chat_btn:obj", "left/guild_name:tmp", "left/an_scroll/Viewport/an_con",
- "left/an_scroll/Viewport/an_con/guild_announce:tmp", "left/auto_pass:obj",
- "left/guild_condi_lv:tmp", "left/guild_condi_power:tmp", "left/apply_btn:obj:imgex",
- -- 右侧社团列表
- "right/guild_scroll", "right/guild_scroll/Viewport/guild_con",
- "right/create_btn:obj","right/search_btn:obj",
- "right/auto_apply_btn:obj:imgex",
- "right/guildname_input:input", "right/empty_girl:obj:raw", "right/empty_girl/empty_flag:tmp",
- "right/guild_scroll/Viewport/guild_con/badge_tip_con:obj",
- "right/guild_scroll/Viewport/guild_con/badge_tip_con/badge_tip:tmp",
- "right/guild_scroll/Viewport/guild_con/guildDiscountCon:obj", "right/guild_scroll/Viewport/guild_con/guildDiscountCon/discountCreateBtn:obj",
- "right/guild_scroll/Viewport/guild_con/guildDiscountCon/discountBg:img", "right/guild_scroll/Viewport/guild_con/guildDiscountCon/discountSlogan:img",
- }
- self:GetChildren(nodes)
- lua_resM:setOutsideRawImage(self, self.empty_girl_raw, GameResPath.GetRoleBg("com_empty_dialogueGirl1_590x560"), false)
-
- lua_resM:setOutsideImageSprite(self, self.discountBg_img, GameResPath.GetGuildImage("guild_create_discount_bg"))
- lua_resM:setOutsideImageSprite(self, self.discountSlogan_img, GameResPath.GetGuildImage("guild_create_discount_slogan"))
-
- self:AddEvents()
- -- 请求默认第一页的数据
- self.model:Fire(GuildModel.RequestGuildListEvt, self.search_name, self.search_filter, self.page_size, self.cur_page)
-
- self:AddToStageHandler()
- end
-
- function GuildApplyView:AddEvents( )
- local function click_event(target)
- if target == self.leader_chat_btn_obj then -- 私聊团长
- SocialityModel:getInstance():Fire(SocialityModel.CHAT_WITH_ROLEID, self.cur_select_leader_id)
- elseif target == self.apply_btn_obj then -- 申请加入该社团
- if self.cur_select_guild_id then
- self.model:Fire(GuildModel.ApplyJoinGuildEvt, self.cur_select_guild_id) --申请加入社团
- else
- Message.show("请先选中社团", "fault")
- end
- elseif target == self.create_btn_obj then -- 创建社团
- GlobalEventSystem:Fire(EventName.OPEN_GUILD_CREATE_VIEW, true)
- -- elseif target == self.search_btn_obj then -- 搜索社团
- -- self:OnSearchBtnClick()
- elseif target == self.auto_apply_btn_obj then -- 一键加入社团
- self.model:Fire(GuildModel.RequestMultiJoinGuildEvt)
- elseif target == self.discountCreateBtn_obj then -- 创建社团
- self.model.handle_40071_flag = 1--为1时处理列表界面的创建社团折扣提醒
- self.model:Fire(GuildModel.REQUEST_CCMD_EVENT, 40071)--查询判断历史社团最大数再去做社团创建
- end
- end
- AddClickEvent(self.leader_chat_btn_obj, click_event, LuaSoundManager.SOUND_UI.NONE)
- AddClickEvent(self.apply_btn_obj, click_event)
- AddClickEvent(self.create_btn_obj, click_event, LuaSoundManager.SOUND_UI.NONE)
- -- AddClickEvent(self.search_btn_obj, click_event) -- 暂时屏蔽搜索社团功能
- AddClickEvent(self.auto_apply_btn_obj, click_event)
- AddClickEvent(self.discountCreateBtn_obj, click_event)
-
- -- 更新社团列表数据
- local function update_guildlist_data(vo)
- self:SetGuildListData(vo)
- end
- self:BindEvent(self.model, GuildModel.RefreshGuildListEvt, update_guildlist_data)
-
- local function onGuideTrigger()
- self:AddToStageHandler()
- end
- self:BindEvent(GlobalEventSystem, EventName.TRIGGER_GUIDE_TYPE, onGuideTrigger)
-
-
- local function do_create_guild()
- if self.model.handle_40071_flag and self.model.handle_40071_flag == 1 then
- local is_in_discount = self.model:IsInCreateGuildDiscount()
- if not is_in_discount then
- local function ok( ... )
- GlobalEventSystem:Fire(EventName.OPEN_GUILD_CREATE_VIEW, true)
- end
- local ask_str = "手慢了喔~当前折扣创建名额不足,是否以原价创建?"
- Alert.show(ask_str,Alert.Type.Two,ok,nil,"确定","取消")
- else
- GlobalEventSystem:Fire(EventName.OPEN_GUILD_CREATE_VIEW, true)
- end
- end
- end
- self:BindEvent(self.model, GuildModel.AFTER_GET_HISTORY_GUILD_COUNT, do_create_guild)
-
- end
-
- function GuildApplyView:SetGuildListData(vo)
- self.total_page = vo.page_total
- self.cur_page = vo.page_no
- self:UpdateGuildList(vo.guild_list)
- end
- -- 更新社团列表 new_list:协议返回的社团列表,如果为空则代表这是首次运行,清空界面内的缓存数据
- function GuildApplyView:UpdateGuildList(new_list)
- -- 新列表需要自动定位至第一条数据
- local need_auto_select = TableSize(self.guild_list_data) == 0
-
- if new_list and #new_list > 0 then
- for k, data in pairs(new_list) do
- self.model:SortGuildBadge(data.badges)
- self.guild_list_data[#self.guild_list_data+1] = data
- end
- self.sroll_end_req_evt = false
- end
- -- 设置空表现
- local is_empty = TableSize(self.guild_list_data) == 0
- self.empty_girl_obj:SetActive(is_empty)
- self.apply_btn_imgex.gray = is_empty
- self.auto_apply_btn_imgex.gray = is_empty
-
- -- 点击item回调
- local function select_callback(index)
- self.selected_item_index = index
- self.guild_item_creator:IterateItems(function( item, i )
- item:SetSelected(i == index)
- end)
- self:UpdateSelectedGuildData(self.guild_list_data[index])
- end
-
- local function badge_select_callback(y, index, badge_id)
- self:UpdateBadgeTipConData(y, index, badge_id)
- end
-
- local can_create_guild_discount = self.model:IsInCreateGuildDiscount()
- local extra_space_y = 0
- if can_create_guild_discount then
- extra_space_y = 125
- self.guildDiscountCon_obj:SetActive(not is_empty)
- self.empty_flag_tmp.text = "<color=#2CF86F>前五名</color>创建社团,可享<color=#feffb3>五折优惠</color>!\n快点击右下“<color=#2CF86F>创建社团</color>”吧~"
- else
- self.guildDiscountCon_obj:SetActive(false)
- self.empty_flag_tmp.text = "暂无社团~点击右下“<color=#feffb3>创建社团</color>”\n 创建第一个社团吧~"
- end
-
- self.guild_item_creator = self.guild_item_creator or self:AddUIComponent(UI.ItemListCreator)
- local info = {
- data_list = self.guild_list_data,
- item_con = self.guild_con,
- scroll_view = self.guild_scroll,
- item_class = GuildApplyItem,
- item_height = 103,
- start_x = 0.5,
- start_y = 0-extra_space_y,
- space_y = 2,
- create_frequency = 0.01,
- alignment = UnityEngine.TextAnchor.UpperLeft,
- reuse_item_num = 7,
- -- final_callback = function()
- -- self.badge_tip_con:SetAsLastSibling()
- -- end,
- on_update_item = function(item, i, v)
- if i == #self.guild_list_data - 1 and not self.sroll_end_req_evt and self.cur_page < self.total_page then
- -- 调整标志量,请求协议
- self.sroll_end_req_evt = true
- self.model:Fire(GuildModel.RequestGuildListEvt, self.search_name, self.search_filter, self.page_size, self.cur_page + 1)
- end
- item:SetData(i, v, select_callback, badge_select_callback)
- item:SetSelected(i == self.selected_item_index)
- end,
- }
- self.guild_item_creator:UpdateItems(info)
- -- 默认选中第一个社团
- if need_auto_select then
- select_callback(1)
- end
- end
-
- function GuildApplyView:UpdateBadgeTipConData(y, index, badge_id)
- if self.last_badge_tips_y and self.last_badge_tips_y == y
- and self.last_badge_index and self.last_badge_index == index
- and self.badge_tip_con_obj.activeSelf then -- 重复点击,关闭tips
- self.badge_tip_con_obj:SetActive(false)
- else
- local badge_cfg = Config.Guildbadge[badge_id]
- self.badge_tip_tmp.text = Trim(badge_cfg.note)
- SetSizeDelta(self.badge_tip_con, 12 + (self.badge_tip_tmp.preferredWidth > 180 and 180 or self.badge_tip_tmp.preferredWidth), self.badge_tip_tmp.preferredHeight + 23)
- local pos_x = 520 + (index - 1) * 84
- local pos_y = y - self.badge_tip_con.sizeDelta.y - 10
- SetAnchoredPosition(self.badge_tip_con, pos_x, pos_y)
- if not self.badge_tip_con_obj.activeSelf then
- self.badge_tip_con:SetAsLastSibling()
- self.badge_tip_con_obj:SetActive(true)
- end
- self.last_badge_tips_y = y
- self.last_badge_index = index
- end
- end
-
- function GuildApplyView:UpdateSelectedGuildData(data)
- -- local asset_name = "guild_asset"
- -- local res_name = data and data.flag_style and "guild_icon" .. data.flag_style or "com_empty"
- -- lua_resM:setImageSprite(self, self.guild_icon_img, asset_name, res_name)
- if data then
- lua_resM:setImageSprite(self, self.guild_icon_img, "guildIcon_asset", "guild_icon"..(data.guild_flag), true)
- -- lua_resM:setOutsideImageSprite(self, self.guild_icon_img, GameResPath.GetGuildIcon(data.guild_flag), true)
- else
- lua_resM:setImageSprite(self, self.guild_icon_img, "common_asset", "com_empty")
- end
- self.guild_name_tmp.text = data and data.guild_name or ""
- self.guild_announce_tmp.text = data and data.announce or ""
- SetSizeDeltaY(self.an_con, 10 + self.guild_announce_tmp.preferredHeight)
- SetAnchoredPositionY(self.an_con, 0)
- -- 申请条件
- local req_lv = data and data.require_lv or 0
- local req_pow = data and data.require_pow or 0
- local role_lv = RoleManager.Instance.mainRoleInfo.level
- local power = RoleManager.Instance.mainRoleInfo.fighting
- self.guild_condi_lv_tmp.text = string.format("等级要求:<color=%s>%s</color>",
- role_lv >= req_lv and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK, req_lv > 0 and (req_lv .. "级以上") or "无")
- self.guild_condi_power_tmp.text = string.format("战力要求:<color=%s>%s</color>",
- power >= req_pow and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK, req_pow > 0 and (req_pow .. "以上") or "无")
-
- self.cur_select_leader_id = data and data.role_id or false
- self.leader_chat_btn_obj:SetActive(self.cur_select_leader_id and true)
- self.apply_btn_obj:SetActive(data and true or false)
- self.cur_select_guild_id = data and data.guild_id or nil
- self.auto_pass_obj:SetActive(data and data.app_type == 0 or false)
- end
-
- -- 更新点击搜索按钮事件
- function GuildApplyView:OnSearchBtnClick( )
- local name = self.guildname_input_input.text
- local _, title_filter = LanguageFilter.FilterMsg(name)
- if title_filter == false then
- Message.show("内容有敏感词")
- return
- end
-
- --相同搜索--
- if name and name~="" and name == self.search_name then
- return
- end
-
- self.search_name = name
- self.model:Fire(GuildModel.RequestGuildListEvt, self.search_name, self.search_filter, self.page_size, 1)
- -- 手动搜索时清空先前的缓存数据
- self.guild_list_data = {}
- -- 搜索后清空文本内容
- -- self.guildname_input_input.text = ""
- end
-
- function GuildApplyView:__delete( )
- if self.tabWindowComponent then
- self.tabWindowComponent:DeleteMe()
- end
- self.tabWindowComponent = nil
-
- Runner.Instance:RemoveRunObj(self)
- end
-
- --检测点击屏幕
- function GuildApplyView:Update()
- if self.is_in_guide then
- local is_click = false
- if Input.touchCount > 0 then
- is_click = true
- else
- if Input.GetMouseButtonDown(0) then
- is_click = true
- end
- end
- if is_click then
- self.is_in_guide = false
- Runner.Instance:RemoveRunObj(self)
- self:CloseGuide()
- end
- end
- end
-
- function GuildApplyView:AddToStageHandler()
- local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_GUILD,3)
- if not helpVo then return end
- local help_type = helpVo.help_type
- if (help_type == HelpType.TYPE_GUILD) then
- local step = helpVo.step
- local button = false
- if (help_type == HelpType.TYPE_GUILD) and step == 3 then
- button = self.auto_apply_btn_obj
- end
- if button then
- local function call_back()
-
- end
- GlobalEventSystem:Fire(EventName.OPEN_GUIDE_PROMPT_VIEW, button.transform, button.transform.parent.transform, call_back, helpVo, self.layout_file)
-
-
- self.is_in_guide = true
- Runner.Instance:AddRunObj(self, 1)
- end
- else
- GlobalEventSystem:Fire(EventName.CLOSE_GUIDE_PROMPT_VIEW)
- end
- end
-
- function GuildApplyView:CloseGuide()
- local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_GUILD,3)
- if helpVo then
- GlobalEventSystem:Fire(EventName.FINISH_CURRENT_HELP_STEP,helpVo)
- end
- end
|