源战役客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

327 linhas
13 KiB

  1. --<*
  2. -- @Author: Saber
  3. -- @Description: 申请社团界面
  4. --*>
  5. GuildApplyView = GuildApplyView or BaseClass(BaseItem)
  6. local GuildApplyView = GuildApplyView
  7. function GuildApplyView:__init(parent_wnd,prefab_asset,layer_name)
  8. self.base_file = "guild"
  9. self.layout_file = "GuildApplyView"
  10. self.parent_wnd = parent_wnd
  11. self.layer_name = layer_name
  12. self.guild_list_data = {} -- 社团列表
  13. self.sroll_end_req_evt = false -- 滑动到底时请求协议
  14. self.cur_page = 1 -- 当前加载了多少页的社团数据
  15. self.total_page = 0 -- 总页数
  16. self.page_size = 15 --向服务器发送一页的个数
  17. self.search_name = "" -- 当前搜索的社团名称
  18. self.search_filter = 0 -- 搜索过滤已满社团 1:使用过滤
  19. self.cur_select_leader_id = nil -- 当前选中的社团会长id
  20. self.cur_select_guild_id = nil -- 当前选中的社团id
  21. self.selected_item_index = 0 -- 当前选中的社团item的index
  22. self.is_in_guide = false --当前是否在引导
  23. self.model = GuildModel:getInstance()
  24. self:Load()
  25. end
  26. function GuildApplyView:Load_callback()
  27. local nodes = {
  28. -- 左侧选中社团信息
  29. "left/guild_icon:img", "left/leader_chat_btn:obj", "left/guild_name:tmp", "left/an_scroll/Viewport/an_con",
  30. "left/an_scroll/Viewport/an_con/guild_announce:tmp", "left/auto_pass:obj",
  31. "left/guild_condi_lv:tmp", "left/guild_condi_power:tmp", "left/apply_btn:obj:imgex",
  32. -- 右侧社团列表
  33. "right/guild_scroll", "right/guild_scroll/Viewport/guild_con",
  34. "right/create_btn:obj","right/search_btn:obj",
  35. "right/auto_apply_btn:obj:imgex",
  36. "right/guildname_input:input", "right/empty_girl:obj:raw", "right/empty_girl/empty_flag:tmp",
  37. "right/guild_scroll/Viewport/guild_con/badge_tip_con:obj",
  38. "right/guild_scroll/Viewport/guild_con/badge_tip_con/badge_tip:tmp",
  39. "right/guild_scroll/Viewport/guild_con/guildDiscountCon:obj", "right/guild_scroll/Viewport/guild_con/guildDiscountCon/discountCreateBtn:obj",
  40. "right/guild_scroll/Viewport/guild_con/guildDiscountCon/discountBg:img", "right/guild_scroll/Viewport/guild_con/guildDiscountCon/discountSlogan:img",
  41. }
  42. self:GetChildren(nodes)
  43. lua_resM:setOutsideRawImage(self, self.empty_girl_raw, GameResPath.GetRoleBg("com_empty_dialogueGirl1_590x560"), false)
  44. lua_resM:setOutsideImageSprite(self, self.discountBg_img, GameResPath.GetGuildImage("guild_create_discount_bg"))
  45. lua_resM:setOutsideImageSprite(self, self.discountSlogan_img, GameResPath.GetGuildImage("guild_create_discount_slogan"))
  46. self:AddEvents()
  47. -- 请求默认第一页的数据
  48. self.model:Fire(GuildModel.RequestGuildListEvt, self.search_name, self.search_filter, self.page_size, self.cur_page)
  49. self:AddToStageHandler()
  50. end
  51. function GuildApplyView:AddEvents( )
  52. local function click_event(target)
  53. if target == self.leader_chat_btn_obj then -- 私聊团长
  54. SocialityModel:getInstance():Fire(SocialityModel.CHAT_WITH_ROLEID, self.cur_select_leader_id)
  55. elseif target == self.apply_btn_obj then -- 申请加入该社团
  56. if self.cur_select_guild_id then
  57. self.model:Fire(GuildModel.ApplyJoinGuildEvt, self.cur_select_guild_id) --申请加入社团
  58. else
  59. Message.show("请先选中社团", "fault")
  60. end
  61. elseif target == self.create_btn_obj then -- 创建社团
  62. GlobalEventSystem:Fire(EventName.OPEN_GUILD_CREATE_VIEW, true)
  63. -- elseif target == self.search_btn_obj then -- 搜索社团
  64. -- self:OnSearchBtnClick()
  65. elseif target == self.auto_apply_btn_obj then -- 一键加入社团
  66. self.model:Fire(GuildModel.RequestMultiJoinGuildEvt)
  67. elseif target == self.discountCreateBtn_obj then -- 创建社团
  68. self.model.handle_40071_flag = 1--为1时处理列表界面的创建社团折扣提醒
  69. self.model:Fire(GuildModel.REQUEST_CCMD_EVENT, 40071)--查询判断历史社团最大数再去做社团创建
  70. end
  71. end
  72. AddClickEvent(self.leader_chat_btn_obj, click_event, LuaSoundManager.SOUND_UI.NONE)
  73. AddClickEvent(self.apply_btn_obj, click_event)
  74. AddClickEvent(self.create_btn_obj, click_event, LuaSoundManager.SOUND_UI.NONE)
  75. -- AddClickEvent(self.search_btn_obj, click_event) -- 暂时屏蔽搜索社团功能
  76. AddClickEvent(self.auto_apply_btn_obj, click_event)
  77. AddClickEvent(self.discountCreateBtn_obj, click_event)
  78. -- 更新社团列表数据
  79. local function update_guildlist_data(vo)
  80. self:SetGuildListData(vo)
  81. end
  82. self:BindEvent(self.model, GuildModel.RefreshGuildListEvt, update_guildlist_data)
  83. local function onGuideTrigger()
  84. self:AddToStageHandler()
  85. end
  86. self:BindEvent(GlobalEventSystem, EventName.TRIGGER_GUIDE_TYPE, onGuideTrigger)
  87. local function do_create_guild()
  88. if self.model.handle_40071_flag and self.model.handle_40071_flag == 1 then
  89. local is_in_discount = self.model:IsInCreateGuildDiscount()
  90. if not is_in_discount then
  91. local function ok( ... )
  92. GlobalEventSystem:Fire(EventName.OPEN_GUILD_CREATE_VIEW, true)
  93. end
  94. local ask_str = "手慢了喔~当前折扣创建名额不足,是否以原价创建?"
  95. Alert.show(ask_str,Alert.Type.Two,ok,nil,"确定","取消")
  96. else
  97. GlobalEventSystem:Fire(EventName.OPEN_GUILD_CREATE_VIEW, true)
  98. end
  99. end
  100. end
  101. self:BindEvent(self.model, GuildModel.AFTER_GET_HISTORY_GUILD_COUNT, do_create_guild)
  102. end
  103. function GuildApplyView:SetGuildListData(vo)
  104. self.total_page = vo.page_total
  105. self.cur_page = vo.page_no
  106. self:UpdateGuildList(vo.guild_list)
  107. end
  108. -- 更新社团列表 new_list:协议返回的社团列表,如果为空则代表这是首次运行,清空界面内的缓存数据
  109. function GuildApplyView:UpdateGuildList(new_list)
  110. -- 新列表需要自动定位至第一条数据
  111. local need_auto_select = TableSize(self.guild_list_data) == 0
  112. if new_list and #new_list > 0 then
  113. for k, data in pairs(new_list) do
  114. self.model:SortGuildBadge(data.badges)
  115. self.guild_list_data[#self.guild_list_data+1] = data
  116. end
  117. self.sroll_end_req_evt = false
  118. end
  119. -- 设置空表现
  120. local is_empty = TableSize(self.guild_list_data) == 0
  121. self.empty_girl_obj:SetActive(is_empty)
  122. self.apply_btn_imgex.gray = is_empty
  123. self.auto_apply_btn_imgex.gray = is_empty
  124. -- 点击item回调
  125. local function select_callback(index)
  126. self.selected_item_index = index
  127. self.guild_item_creator:IterateItems(function( item, i )
  128. item:SetSelected(i == index)
  129. end)
  130. self:UpdateSelectedGuildData(self.guild_list_data[index])
  131. end
  132. local function badge_select_callback(y, index, badge_id)
  133. self:UpdateBadgeTipConData(y, index, badge_id)
  134. end
  135. local can_create_guild_discount = self.model:IsInCreateGuildDiscount()
  136. local extra_space_y = 0
  137. if can_create_guild_discount then
  138. extra_space_y = 125
  139. self.guildDiscountCon_obj:SetActive(not is_empty)
  140. self.empty_flag_tmp.text = "<color=#2CF86F>前五名</color>创建社团,可享<color=#feffb3>五折优惠</color>!\n快点击右下“<color=#2CF86F>创建社团</color>”吧~"
  141. else
  142. self.guildDiscountCon_obj:SetActive(false)
  143. self.empty_flag_tmp.text = "暂无社团~点击右下“<color=#feffb3>创建社团</color>”\n 创建第一个社团吧~"
  144. end
  145. self.guild_item_creator = self.guild_item_creator or self:AddUIComponent(UI.ItemListCreator)
  146. local info = {
  147. data_list = self.guild_list_data,
  148. item_con = self.guild_con,
  149. scroll_view = self.guild_scroll,
  150. item_class = GuildApplyItem,
  151. item_height = 103,
  152. start_x = 0.5,
  153. start_y = 0-extra_space_y,
  154. space_y = 2,
  155. create_frequency = 0.01,
  156. alignment = UnityEngine.TextAnchor.UpperLeft,
  157. reuse_item_num = 7,
  158. -- final_callback = function()
  159. -- self.badge_tip_con:SetAsLastSibling()
  160. -- end,
  161. on_update_item = function(item, i, v)
  162. if i == #self.guild_list_data - 1 and not self.sroll_end_req_evt and self.cur_page < self.total_page then
  163. -- 调整标志量,请求协议
  164. self.sroll_end_req_evt = true
  165. self.model:Fire(GuildModel.RequestGuildListEvt, self.search_name, self.search_filter, self.page_size, self.cur_page + 1)
  166. end
  167. item:SetData(i, v, select_callback, badge_select_callback)
  168. item:SetSelected(i == self.selected_item_index)
  169. end,
  170. }
  171. self.guild_item_creator:UpdateItems(info)
  172. -- 默认选中第一个社团
  173. if need_auto_select then
  174. select_callback(1)
  175. end
  176. end
  177. function GuildApplyView:UpdateBadgeTipConData(y, index, badge_id)
  178. if self.last_badge_tips_y and self.last_badge_tips_y == y
  179. and self.last_badge_index and self.last_badge_index == index
  180. and self.badge_tip_con_obj.activeSelf then -- 重复点击,关闭tips
  181. self.badge_tip_con_obj:SetActive(false)
  182. else
  183. local badge_cfg = Config.Guildbadge[badge_id]
  184. self.badge_tip_tmp.text = Trim(badge_cfg.note)
  185. 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)
  186. local pos_x = 520 + (index - 1) * 84
  187. local pos_y = y - self.badge_tip_con.sizeDelta.y - 10
  188. SetAnchoredPosition(self.badge_tip_con, pos_x, pos_y)
  189. if not self.badge_tip_con_obj.activeSelf then
  190. self.badge_tip_con:SetAsLastSibling()
  191. self.badge_tip_con_obj:SetActive(true)
  192. end
  193. self.last_badge_tips_y = y
  194. self.last_badge_index = index
  195. end
  196. end
  197. function GuildApplyView:UpdateSelectedGuildData(data)
  198. -- local asset_name = "guild_asset"
  199. -- local res_name = data and data.flag_style and "guild_icon" .. data.flag_style or "com_empty"
  200. -- lua_resM:setImageSprite(self, self.guild_icon_img, asset_name, res_name)
  201. if data then
  202. lua_resM:setImageSprite(self, self.guild_icon_img, "guildIcon_asset", "guild_icon"..(data.guild_flag), true)
  203. -- lua_resM:setOutsideImageSprite(self, self.guild_icon_img, GameResPath.GetGuildIcon(data.guild_flag), true)
  204. else
  205. lua_resM:setImageSprite(self, self.guild_icon_img, "common_asset", "com_empty")
  206. end
  207. self.guild_name_tmp.text = data and data.guild_name or ""
  208. self.guild_announce_tmp.text = data and data.announce or ""
  209. SetSizeDeltaY(self.an_con, 10 + self.guild_announce_tmp.preferredHeight)
  210. SetAnchoredPositionY(self.an_con, 0)
  211. -- 申请条件
  212. local req_lv = data and data.require_lv or 0
  213. local req_pow = data and data.require_pow or 0
  214. local role_lv = RoleManager.Instance.mainRoleInfo.level
  215. local power = RoleManager.Instance.mainRoleInfo.fighting
  216. self.guild_condi_lv_tmp.text = string.format("等级要求:<color=%s>%s</color>",
  217. role_lv >= req_lv and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK, req_lv > 0 and (req_lv .. "级以上") or "")
  218. self.guild_condi_power_tmp.text = string.format("战力要求:<color=%s>%s</color>",
  219. power >= req_pow and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK, req_pow > 0 and (req_pow .. "以上") or "")
  220. self.cur_select_leader_id = data and data.role_id or false
  221. self.leader_chat_btn_obj:SetActive(self.cur_select_leader_id and true)
  222. self.apply_btn_obj:SetActive(data and true or false)
  223. self.cur_select_guild_id = data and data.guild_id or nil
  224. self.auto_pass_obj:SetActive(data and data.app_type == 0 or false)
  225. end
  226. -- 更新点击搜索按钮事件
  227. function GuildApplyView:OnSearchBtnClick( )
  228. local name = self.guildname_input_input.text
  229. local _, title_filter = LanguageFilter.FilterMsg(name)
  230. if title_filter == false then
  231. Message.show("内容有敏感词")
  232. return
  233. end
  234. --相同搜索--
  235. if name and name~="" and name == self.search_name then
  236. return
  237. end
  238. self.search_name = name
  239. self.model:Fire(GuildModel.RequestGuildListEvt, self.search_name, self.search_filter, self.page_size, 1)
  240. -- 手动搜索时清空先前的缓存数据
  241. self.guild_list_data = {}
  242. -- 搜索后清空文本内容
  243. -- self.guildname_input_input.text = ""
  244. end
  245. function GuildApplyView:__delete( )
  246. if self.tabWindowComponent then
  247. self.tabWindowComponent:DeleteMe()
  248. end
  249. self.tabWindowComponent = nil
  250. Runner.Instance:RemoveRunObj(self)
  251. end
  252. --检测点击屏幕
  253. function GuildApplyView:Update()
  254. if self.is_in_guide then
  255. local is_click = false
  256. if Input.touchCount > 0 then
  257. is_click = true
  258. else
  259. if Input.GetMouseButtonDown(0) then
  260. is_click = true
  261. end
  262. end
  263. if is_click then
  264. self.is_in_guide = false
  265. Runner.Instance:RemoveRunObj(self)
  266. self:CloseGuide()
  267. end
  268. end
  269. end
  270. function GuildApplyView:AddToStageHandler()
  271. local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_GUILD,3)
  272. if not helpVo then return end
  273. local help_type = helpVo.help_type
  274. if (help_type == HelpType.TYPE_GUILD) then
  275. local step = helpVo.step
  276. local button = false
  277. if (help_type == HelpType.TYPE_GUILD) and step == 3 then
  278. button = self.auto_apply_btn_obj
  279. end
  280. if button then
  281. local function call_back()
  282. end
  283. GlobalEventSystem:Fire(EventName.OPEN_GUIDE_PROMPT_VIEW, button.transform, button.transform.parent.transform, call_back, helpVo, self.layout_file)
  284. self.is_in_guide = true
  285. Runner.Instance:AddRunObj(self, 1)
  286. end
  287. else
  288. GlobalEventSystem:Fire(EventName.CLOSE_GUIDE_PROMPT_VIEW)
  289. end
  290. end
  291. function GuildApplyView:CloseGuide()
  292. local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_GUILD,3)
  293. if helpVo then
  294. GlobalEventSystem:Fire(EventName.FINISH_CURRENT_HELP_STEP,helpVo)
  295. end
  296. end