源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

334 lines
11 KiB

  1. --<*
  2. -- @Author: Saber
  3. -- @Description: 创建社团界面
  4. --*>
  5. GuildCreateView = GuildCreateView or BaseClass(BaseView)
  6. local GuildCreateView = GuildCreateView
  7. function GuildCreateView:__init()
  8. self.base_file = "guild"
  9. self.layout_file = "GuildCreateView"
  10. self.layer_name = "Activity"
  11. self.destroy_imm = true
  12. self.hide_maincancas = true
  13. self.use_background = true
  14. self.blur_activity_bg = true
  15. self.use_show_anim = true
  16. self.use_hide_anim = true
  17. self.type_tab_list = {} -- 社团tab列表
  18. self.icon_list = {} -- 图标列表
  19. self.color_list = {} -- 颜色列表
  20. self.cur_icon_flag = 1
  21. self.cur_icon_color = 1
  22. self.change_scene_close = true --是否切换场景时关闭(弹出界面使用)
  23. --self.append_to_ctl_queue = false --是否要添加进界面堆栈
  24. self.tab_index = 3 -- 默认选中3级社团
  25. self.no_guild_name_str = "<color=#D5D7DF>(未命名)</color>"
  26. self.tip_time = Status.NowTime
  27. self.name_limit = 6 -- 社团名称字数限制
  28. self.cur_tab_cost_cfg = nil -- 当前选中的扣费配置
  29. self.cur_tab_guild_lv = 0 -- 当前选中的社团等级
  30. self.model = GuildModel:getInstance()
  31. self.is_in_create_discount = self.model:IsInCreateGuildDiscount()
  32. self.load_callback = function ()
  33. self:LoadSuccess()
  34. self:AddEvent()
  35. end
  36. self.open_callback = function ( )
  37. self:OpenSuccess()
  38. end
  39. self.destroy_callback = function ( )
  40. self:DestroySuccess()
  41. end
  42. end
  43. function GuildCreateView:Open( )
  44. --self.data = data
  45. BaseView.Open(self)
  46. end
  47. function GuildCreateView:LoadSuccess()
  48. local nodes = {
  49. "content",
  50. "content/tab_con",
  51. "content/name_input:tmpInput", "content/color_con", "content/icon_con", "content/cur_icon:img",
  52. "content/createBtn:obj",
  53. "content/cost_node", "content/cost_node/create_cost_icon:img",
  54. "content/cost_node/create_costval:tmp", "content/cost_node/create_cost_title:tmp",
  55. "content/create_cond:tmp", "content/final_name:tmp",
  56. "content/cost_node/create_costval_discount:tmp", "content/cost_node/create_costval_line:obj",
  57. }
  58. self:GetChildren(nodes)
  59. self.final_name_tmp.text = self.no_guild_name_str
  60. -- self.name_input_tmpInput.characterLimit = self.name_limit
  61. local function close_callback()
  62. self:Close()
  63. end
  64. self.tabWindowComponent = UITabWindow.New(self.transform, {}, nil, close_callback, self.background_wnd, self.content, UITabWindow.SizeSmallNoTab, nil, nil, true)
  65. self.tabWindowComponent:SetTitleText("创建社团")
  66. self.tabWindowComponent:SetBackgroundRes("guild_create_bg")
  67. end
  68. function GuildCreateView:AddEvent()
  69. local function click_event(target)
  70. if target == self.createBtn_obj then
  71. if self.is_in_create_discount then--如果界面打开时已经是折扣状态了,那创建社团需要发协议检测下还能否折扣
  72. self.model.handle_40071_flag = 2--为2时处理创建界面的创建社团折扣提醒
  73. self.model:Fire(GuildModel.REQUEST_CCMD_EVENT, 40071)--查询判断历史社团最大数再去做社团创建
  74. else
  75. self:OnCreateBtnClick()
  76. end
  77. end
  78. end
  79. AddClickEvent(self.createBtn_obj, click_event)
  80. -- 输入监听
  81. self.name_input_tmpInput.onValueChanged:AddListener(function()
  82. local len = utf8len(self.name_input_tmpInput.text)
  83. if len > self.name_limit then
  84. self.name_input_tmpInput.text = GetInputLimitResultStr(self.name_input_tmpInput.text, self.name_limit) --减去多出来的字符
  85. self.tip_time = self.tip_time or 0
  86. if Status.NowTime - self.tip_time > 0.2 then
  87. Message.show(string.format("最多可输入%s个字符", self.name_limit), "fault")
  88. self.tip_time = Status.NowTime
  89. end
  90. end
  91. -- 右侧同步玩家输入的社团名称
  92. self.final_name_tmp.text = self.name_input_tmpInput.text == "" and self.no_guild_name_str or self.name_input_tmpInput.text
  93. end)
  94. local function do_create_guild()
  95. if self.model.handle_40071_flag and self.model.handle_40071_flag == 2 then
  96. local is_in_discount = self.model:IsInCreateGuildDiscount()
  97. if not is_in_discount then
  98. local function ok( ... )
  99. self:OnCreateBtnClick()
  100. end
  101. local ask_str = "手慢了喔~当前折扣创建名额不足,是否继续以原价创建?"
  102. Alert.show(ask_str,Alert.Type.Two,ok,nil,"确定","取消")
  103. else
  104. self:OnCreateBtnClick()
  105. end
  106. end
  107. end
  108. self:BindEvent(self.model, GuildModel.AFTER_GET_HISTORY_GUILD_COUNT, do_create_guild)
  109. end
  110. function GuildCreateView:OpenSuccess()
  111. if self.tabWindowComponent then
  112. self.tabWindowComponent:ChangeShowFlag("smallWindow2")
  113. end
  114. self:UpdateView()
  115. end
  116. function GuildCreateView:UpdateView()
  117. self:UpdateGuildTypeTab()
  118. -- self:SwitchTabindex(self.tab_index)
  119. self:UpdateGuildIconAndColor()
  120. end
  121. function GuildCreateView:UpdateGuildTypeTab( )
  122. local tab_list = {}
  123. for k, v in pairs(Config.Guildcreate) do
  124. tab_list[#tab_list+1] = v
  125. end
  126. local sort_func = function ( a, b )
  127. return a.cfg_id > b.cfg_id
  128. end
  129. table.sort(tab_list, sort_func)
  130. -- guild_type == tab_index
  131. local function tab_callback(guild_type, index)
  132. for k, item in pairs(self.type_tab_list) do
  133. item:SetSelected(guild_type)
  134. end
  135. self:SwitchTabindex(guild_type, tab_list[index])
  136. end
  137. local item
  138. for k, v in ipairs(tab_list) do
  139. item = self.type_tab_list[k]
  140. if not item then
  141. item = GuildCreateTabItem.New(self.tab_con)
  142. self.type_tab_list[k] = item
  143. end
  144. item:SetAnchoredPosition(3 + (k-1) * 172, -3)
  145. item:SetData(v, k, tab_callback)
  146. end
  147. -- 自动选中第三级
  148. self.tab_index = tab_list[1].cfg_id
  149. tab_callback(self.tab_index, 1)
  150. end
  151. function GuildCreateView:SwitchTabindex( index, create_cfg )
  152. self.tab_index = index
  153. -- 加载条件
  154. local cond = stringtotable(create_cfg.condition)
  155. local condi_str = ""
  156. for k, v in pairs(cond) do
  157. if v[1] == "lv" then
  158. condi_str = condi_str .. string.format("<color=#ffffff><size=20> Lv.%s </size></color>", v[2])
  159. elseif v[1] == "vip" then
  160. condi_str = condi_str .. string.format("<color=#fdffc2><size=20> VIP%s </size></color>", v[2])
  161. end
  162. if k < #cond then
  163. condi_str = condi_str .. ""
  164. end
  165. end
  166. self.create_cond_tmp.text = "创建需求 " .. condi_str
  167. -- 加载不同创建类型下的消费
  168. local cost_cfg = stringtotable(create_cfg.cost)[1]
  169. self.cur_tab_cost_cfg = cost_cfg
  170. self.cur_tab_guild_lv = create_cfg.guild_lv
  171. local icon_asset, icon_name = WordManager:GetCommonMoneyIcon(cost_cfg[1])
  172. lua_resM:setImageSprite(self, self.create_cost_icon_img, icon_asset, icon_name)
  173. self.create_costval_tmp.text = cost_cfg[3]
  174. -- 对齐消耗节点位置
  175. local offset_x = (self.cost_node.sizeDelta.x - self.create_costval_tmp.preferredWidth - self.create_cost_title_tmp.preferredWidth - 42) / 2
  176. SetAnchoredPositionX(self.create_cost_title, offset_x)
  177. SetAnchoredPositionX(self.create_cost_icon, offset_x + self.create_cost_title_tmp.preferredWidth + 5)
  178. SetAnchoredPositionX(self.create_costval, self.create_cost_icon.anchoredPosition.x + 37)
  179. --是否处于社团创建折扣期
  180. local is_in_discount = self.model:IsInCreateGuildDiscount()
  181. if is_in_discount then
  182. self.create_costval_line_obj:SetActive(true)
  183. local discount = stringtotable(self.model:GetGuildKvByKey("create_guild_discount").val)[2]
  184. self.create_costval_discount_tmp.text = cost_cfg[3]*discount
  185. SetAnchoredPositionX(self.create_costval_line, self.create_cost_icon.anchoredPosition.x + 34)
  186. SetAnchoredPositionX(self.create_costval_discount, self.create_costval.anchoredPosition.x + self.create_costval_tmp.preferredWidth + 10)
  187. SetAnchoredPositionX(self.cost_node,238)
  188. else
  189. self.create_costval_line_obj:SetActive(false)
  190. self.create_costval_discount_tmp.text = ""
  191. SetAnchoredPositionX(self.cost_node,255)
  192. end
  193. end
  194. function GuildCreateView:OnCreateBtnClick( )
  195. if self.name_input_tmpInput.text == "" then
  196. Message.show("请输入社团名称")
  197. return
  198. end
  199. if HasLimitChar(self.name_input_tmpInput.text) then
  200. Message.show("社团名称名存在非法字符,请重新输入")
  201. return
  202. end
  203. local _, title_filter = LanguageFilter.FilterMsg(self.name_input_tmpInput.text)
  204. if title_filter == false then
  205. Message.show("社团名称有敏感词")
  206. return
  207. end
  208. local is_in_discount = self.model:IsInCreateGuildDiscount()
  209. local discount = 1
  210. if is_in_discount then
  211. discount = stringtotable(self.model:GetGuildKvByKey("create_guild_discount").val)[2]
  212. end
  213. local pay = self.tab_index
  214. local function create_func( )
  215. self.name_input_tmpInput.text = Util.SetNonBreakSpaceText(self.name_input_tmpInput.text)
  216. self.model:Fire(GuildModel.RequestCreateGuildEvt, pay, self.name_input_tmpInput.text, self.cur_icon_flag * 10000 + self.cur_icon_color)
  217. end
  218. local priceText = string.format("<color=%s>%s</color> 创建%s级社团?", ColorUtil.YELLOW_DARK, self.cur_tab_cost_cfg[3]*discount, self.cur_tab_guild_lv)
  219. local function use_function( toggle_tip_data, call_fun_sum )
  220. if self.cur_tab_cost_cfg[3]*discount ~= 0 then
  221. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  222. else
  223. call_fun_sum()
  224. end
  225. end
  226. local data = {
  227. gold_type = tonumber(self.cur_tab_cost_cfg[1]),
  228. cost_price = tonumber(self.cur_tab_cost_cfg[3])*discount,
  229. ok_callback = create_func,
  230. togglePriceStr = priceText,
  231. use_function = use_function,
  232. recharge_open_call_back = function()
  233. self:Close()
  234. end,
  235. no_need_toggle = true,
  236. }
  237. CustomActivityModel:getInstance():BuyTips(data)
  238. end
  239. function GuildCreateView:UpdateGuildIconAndColor( )
  240. local function icon_call_back(index)
  241. for k, v in ipairs(self.icon_list) do
  242. if v.index then
  243. v:SetSelect(v.index == index)
  244. end
  245. end
  246. self.cur_icon_flag = index
  247. self:ChangePreviewIcon()
  248. end
  249. local offset_x = (self.icon_con.sizeDelta.x - 4 * 86) / 2 + 10
  250. for i = 1, 4 do
  251. local item = self.icon_list[i]
  252. if not item then
  253. item = GuildCreateIconItem.New(self.icon_con, nil, self.layer_name)
  254. self.icon_list[i] = item
  255. end
  256. local pos = Vector2((i-1) * 86 + offset_x, -13)
  257. item:SetData(i, pos, icon_call_back)
  258. item:SetSelect(i == self.cur_icon_flag)
  259. end
  260. local function color_callback(index)
  261. for k, v in ipairs(self.color_list) do
  262. if v.index then
  263. v:SetSelect(v.index == index)
  264. end
  265. end
  266. self.cur_icon_color = index
  267. self:ChangePreviewIcon()
  268. end
  269. offset_x = (self.color_con.sizeDelta.x - 8 * 50) / 2 + 6
  270. for i = 1, 8 do
  271. local item = self.color_list[i]
  272. if not item then
  273. item = GuildCreateColorItem.New(self.color_con, nil, self.layer_name)
  274. self.color_list[i] = item
  275. end
  276. local pos = Vector2((i-1) * 50 + offset_x, 0)
  277. item:SetData(i, pos, color_callback)
  278. item:SetSelect(i == self.cur_icon_color)
  279. end
  280. -- color_callback(1)
  281. self:ChangePreviewIcon()
  282. end
  283. function GuildCreateView:ChangePreviewIcon( )
  284. lua_resM:setImageSprite(self, self.cur_icon_img, "guildIcon_asset", "guild_icon" .. (self.cur_icon_flag * 10000 + self.cur_icon_color))
  285. end
  286. function GuildCreateView:DestroySuccess( )
  287. for k, v in pairs(self.type_tab_list) do
  288. v:DeleteMe()
  289. v = nil
  290. end
  291. for k, v in pairs(self.icon_list) do
  292. v:DeleteMe()
  293. v = nil
  294. end
  295. for k, v in pairs(self.color_list) do
  296. v:DeleteMe()
  297. v = nil
  298. end
  299. if self.tabWindowComponent then
  300. self.tabWindowComponent:DeleteMe()
  301. self.tabWindowComponent = nil
  302. end
  303. end