源战役客户端
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.

518 lines
18 KiB

  1. EncourageTips = EncourageTips or BaseClass(BaseView)
  2. local EncourageTips = EncourageTips
  3. EncourageTips.ShowType = {
  4. Open = 1,
  5. Update = 2,
  6. Close = 3,
  7. }
  8. EncourageTips.EncourageType = { -- 鼓舞界面类型
  9. Default = 1, --默认类型,以幻魔鼓舞为标准默认类型
  10. GuildBoss = 2, --社团boss鼓舞
  11. }
  12. -------------------------
  13. --[[
  14. 使 self.data
  15. --encourageType,社团boss鼓舞传这个参数
  16. --]]
  17. -------------------------
  18. function EncourageTips:__init(encourageType)
  19. self.base_file = "encourage"
  20. --不同模块的鼓舞界面功能大体一致,界面布局不同,可以自己单独搞个预制体
  21. self.encourageType = encourageType
  22. if self.encourageType == EncourageTips.EncourageType.GuildBoss then
  23. self.is_guild_boss = true
  24. self.layout_file = "EncourageGuildBossTips"
  25. else
  26. self.layout_file = "EncourageTips"
  27. end
  28. self.layer_name = "Activity"
  29. self.destroy_imm = true
  30. self.change_scene_close = true
  31. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  32. self.need_show_money = true --是否要显示顶部的金钱栏
  33. self.is_set_zdepth = true
  34. self.click_bg_toClose = true
  35. self.blur_activity_bg = true
  36. ------------------------
  37. -- 一级全屏界面:
  38. self.hide_maincancas = false --隐藏主界面
  39. self.use_background = true --不一定显示遮罩
  40. -- 二级界面:
  41. -- self.hide_maincancas = false --是否需要隐藏主界面,看策划需求
  42. -- self.use_background = true --需要遮罩
  43. ------------------------
  44. --默认数据以及范例
  45. self.data = {
  46. [1] ={
  47. type_id = 2,-- 鼓舞类型(红钻)
  48. limit = 1,-- 鼓舞最大次数
  49. use_time = 0,-- 已鼓舞次数
  50. click_call = false,--点击回调
  51. first_free = false,--首次免费
  52. },
  53. [2] ={
  54. type_id = 1,-- 鼓舞类型(彩钻)
  55. limit = 1,-- 鼓舞最大次数
  56. use_time = 0,-- 已鼓舞次数
  57. click_call = false,--点击回调
  58. first_free = false,--首次免费
  59. }
  60. }
  61. self.load_callback = function ()
  62. self:LoadSuccess()
  63. self:AddEvent()
  64. end
  65. self.open_callback = function ( )
  66. self:UpdateView()
  67. end
  68. self.close_win_callback = function ( )
  69. self:Close()
  70. end
  71. self.destroy_callback = function ( )
  72. self:DestroySuccess()
  73. end
  74. end
  75. function EncourageTips:CheckData( data )
  76. if not data then return end
  77. self.data.title_name = data.title_name or self.data.title_name
  78. for i=1,2 do
  79. if data[i] then
  80. self.data[i].type_id = data[i].type_id or self.data[i].type_id
  81. self.data[i].limit = data[i].limit or self.data[i].limit
  82. self.data[i].use_time = data[i].use_time or self.data[i].use_time
  83. self.data[i].click_call = data[i].click_call or self.data[i].click_call
  84. self.data[i].first_free = data[i].first_free or self.data[i].first_free
  85. end
  86. end
  87. end
  88. function EncourageTips:Open( data )
  89. self:CheckData(data)
  90. BaseView.Open(self)
  91. end
  92. function EncourageTips:LoadSuccess()
  93. local nodes = {
  94. "Window:raw","lb_left_2:tmp","lb_left_1:tmp","btn_close:obj",
  95. "des_1:tmp","icon_money_1:img","lb_money_1:tmp","btn_1:obj:img",
  96. "des_2:tmp","icon_money_2:img","lb_money_2:tmp","btn_2:obj:img",
  97. "btn_1/lb_btn_1:tmp", "btn_2/lb_btn_2:tmp", "lb_buff_tip:tmp",
  98. "moneyCon",
  99. }
  100. self:GetChildren(nodes)
  101. -- 社团boss鼓舞界面新加节点
  102. if self.is_guild_boss then
  103. local nodes_guild_boss = {
  104. "encourage_award_money_1:img",
  105. "encourage_award_money_2:img",
  106. "encourage_award_1:tmp",
  107. "encourage_award_2:tmp",
  108. "des_1_num:tmp",
  109. "des_2_num:tmp",
  110. }
  111. self:GetChildren(nodes_guild_boss)
  112. end
  113. if self.is_guild_boss then
  114. lua_resM:setOutsideRawImage(self,self.Window_raw,GameResPath.GetViewBigBg("encourage_guild_boss_bg"),false)
  115. else
  116. lua_resM:setOutsideRawImage(self,self.Window_raw,GameResPath.GetViewBigBg("encourage_bg"),false)
  117. end
  118. if not self.money_view then
  119. self.money_view = UIMoneyView.New(self.moneyCon)
  120. end
  121. self.money_view:SetPosition(0,0)
  122. self.money_view:SetData()
  123. -- self.money_view:ChangeShowFlag("smallWindow2")
  124. end
  125. function EncourageTips:AddEvent()
  126. local function call_back( target )
  127. if target == self.btn_close_obj then
  128. self:Close()
  129. elseif target == self.btn_1_obj then
  130. local function ok_callback( ... )
  131. if self.data[1].click_call then
  132. self.data[1].click_call()
  133. else
  134. Message.show("鼓舞类型1")
  135. end
  136. end
  137. if self.cost_goods_can and self.cost_goods_can[1] then
  138. --道具足够啦,判断个毛线
  139. ok_callback()
  140. return
  141. end
  142. local function toggle_function( flag )
  143. BossModel:GetInstance().encourage_tip_toggle = flag
  144. end
  145. local function use_function( toggle_tip_data,call_fun_sum )
  146. if not BossModel:GetInstance().encourage_tip_toggle then
  147. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  148. else
  149. call_fun_sum()
  150. end
  151. end
  152. local need_num = self.cost_num_list[1] or 0
  153. if self.data[1].first_free and self.data[1].use_time == 0 then
  154. need_num = 0
  155. end
  156. local jin = RoleManager.Instance.mainRoleInfo.jin
  157. local jinLock = RoleManager.Instance.mainRoleInfo.jinLock
  158. if jinLock >= need_num and self.cost_type_list[1] == 2 then
  159. ok_callback()
  160. return
  161. end
  162. local buy_tip_data = {
  163. gold_type = self.cost_type_list[1],--货币类型
  164. cost_price = need_num,--消耗金额
  165. ok_callback = ok_callback,--成功
  166. toggle_function = toggle_function,--多选
  167. togglePriceStr = string.format("<color=#fdffc2>%s</color> 鼓舞",need_num),--提示语
  168. use_function = use_function,--最终调用
  169. }
  170. CustomActivityModel:getInstance():BuyTips(buy_tip_data)
  171. elseif target == self.btn_2_obj then
  172. local function ok_callback( ... )
  173. if self.data[2].click_call then
  174. self.data[2].click_call()
  175. else
  176. Message.show("鼓舞类型2")
  177. end
  178. end
  179. if self.cost_goods_can and self.cost_goods_can[2] then
  180. --道具足够啦,判断个毛线
  181. ok_callback()
  182. return
  183. end
  184. local function toggle_function( flag )
  185. BossModel:GetInstance().encourage_tip_toggle = flag
  186. end
  187. local function use_function( toggle_tip_data,call_fun_sum )
  188. if not BossModel:GetInstance().encourage_tip_toggle then
  189. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  190. else
  191. call_fun_sum()
  192. end
  193. end
  194. local need_num = self.cost_num_list[2] or 0
  195. if self.data[2].first_free and self.data[2].use_time == 0
  196. or (self.have_act_buff and self.data[2].use_time == 0) then
  197. need_num = 0
  198. end
  199. local jin = RoleManager.Instance.mainRoleInfo.jin
  200. local jinLock = RoleManager.Instance.mainRoleInfo.jinLock
  201. if jinLock >= need_num and self.cost_type_list[2] == 2 then
  202. ok_callback()
  203. return
  204. end
  205. local buy_tip_data = {
  206. gold_type = self.cost_type_list[2],--货币类型
  207. cost_price = need_num,--消耗金额
  208. ok_callback = ok_callback,--成功
  209. toggle_function = toggle_function,--多选
  210. togglePriceStr = string.format("<color=#fdffc2>%s</color> 鼓舞",need_num),--提示语
  211. use_function = use_function,--最终调用
  212. }
  213. CustomActivityModel:getInstance():BuyTips(buy_tip_data)
  214. end
  215. end
  216. AddClickEvent(self.btn_close_obj,call_back,false)
  217. AddClickEvent(self.btn_1_obj,call_back,false)
  218. AddClickEvent(self.btn_2_obj,call_back,false)
  219. local function updata_buff_state(id)
  220. if id == KfActivityModel.TabID.MaterialSubmit and self.is_loaded then
  221. self:UpdateViewDefault()
  222. end
  223. end
  224. self:BindEvent(KfActivityModel:getInstance(), KfActivityModel.ANS_UPDATE_VIEW, updata_buff_state)
  225. self:BindEvent(GlobalEventSystem, EventName.OPEN_VIP_VIEW, function ()
  226. self:Close()
  227. end)
  228. end
  229. function EncourageTips:UpdateTips(data,extra_param_list)
  230. self:CheckData(data)
  231. if extra_param_list then
  232. if extra_param_list.show_encourage_percentage then
  233. self:UpdateGuildBossEncouragePercentage(true)
  234. elseif extra_param_list.show_encourage_times then
  235. self:UpdateGuildBossEncourageTimes()
  236. else
  237. self:UpdateView()
  238. end
  239. else
  240. self:UpdateView()
  241. end
  242. end
  243. function EncourageTips:UpdateView()
  244. if self.is_guild_boss then
  245. self:UpdateViewGuildBoss()
  246. else
  247. self:UpdateViewDefault()
  248. end
  249. end
  250. -- 默认鼓舞类型的updateview
  251. function EncourageTips:UpdateViewDefault( )
  252. self.cost_goods_can = self.cost_goods_can or {}--道具足够
  253. self.cost_num_list = self.cost_num_list or {}
  254. self.cost_type_list = self.cost_type_list or {}
  255. for i=1,2 do
  256. local can_encourage = self.data[i].use_time < self.data[i].limit
  257. local show_time = can_encourage and self.data[i].use_time + 1 or self.data[i].limit
  258. local conf = Config.Encourageattr[self.data[i].type_id .. "@" .. show_time]
  259. local old_conf = Config.Encourageattr[self.data[i].type_id .. "@" .. (show_time-1)]
  260. if self.data[i].use_time == self.data[i].limit then
  261. --满级
  262. old_conf = Config.Encourageattr[self.data[i].type_id .. "@" .. self.data[i].limit]
  263. end
  264. if conf then
  265. --置灰按钮
  266. SetImageGray( self["btn_" .. i .. "_img"], not can_encourage )
  267. local tmp_btn_lb = self:GetChild("btn_" .. i .. "/lb_btn_"..i):GetComponent("TMPro.TextMeshProUGUI")
  268. if i==1 then
  269. SetTMPSharedMaterial(tmp_btn_lb,can_encourage and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkBlueBtn or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
  270. else
  271. SetTMPSharedMaterial(tmp_btn_lb,can_encourage and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
  272. end
  273. --鼓舞描述
  274. if can_encourage and self.data[i].use_time == 0 then
  275. self["des_" .. i .. "_tmp"].text = "PVE伤害"
  276. self:GetChild("des_" .. i .. "_num"):GetComponent("TMPro.TextMeshProUGUI").text = "+0%"
  277. else
  278. local show_content = Trim(old_conf.desc)
  279. local content_list = Split(show_content,[[\n]]) or {}
  280. self["des_" .. i .. "_tmp"].text = content_list[1] or ""
  281. self:GetChild("des_" .. i .. "_num"):GetComponent("TMPro.TextMeshProUGUI").text = content_list[2] or ""
  282. end
  283. -------------------------
  284. local price_info = stringtotable(conf.price)
  285. local goods_info = stringtotable(conf.goods)
  286. --消耗道具显示
  287. local use_goods = false
  288. local str_price = ""
  289. if TableSize(goods_info) > 0 then
  290. local goods_num = GoodsModel:getInstance():GetTypeGoodsNum( goods_info[1][2] )
  291. if goods_num >= goods_info[1][3] then
  292. --拥有足够的替代物
  293. str_price = goods_info[1][3]
  294. local goods_icon = GoodsModel:getInstance():GetGoodsBasicByTypeId( goods_info[1][2] ).goods_icon
  295. lua_resM:setOutsideImageSprite(self,self["icon_money_" .. i .. "_img"],GameResPath.GetGoodsIcon(goods_icon),false)
  296. use_goods = true
  297. self.cost_goods_can[i] = true
  298. end
  299. end
  300. if not use_goods then
  301. str_price = price_info[1][3]
  302. local asset, source = WordManager:GetCommonMoneyIcon(tonumber(price_info[1][1]))
  303. lua_resM:setImageSprite(self, self["icon_money_" .. i .. "_img"], asset, source, true)
  304. self.cost_type_list[i] = tonumber(price_info[1][1])
  305. self.cost_num_list[i] = tonumber(str_price)
  306. end
  307. if i == 2 then
  308. local buff_kind = OperateActivityModel.MaterialSubmitBuffKind.BOSS_HUT_ADD --是否存在活动加成buff
  309. local buff_cfg,buff_info = OperateActivityModel:getInstance():GetMaterialBuffInfoByKind(buff_kind)
  310. if buff_cfg and buff_info and self.data[i].use_time == 0 and self.encourageType ~= EncourageTips.EncourageType.GuildBoss then
  311. local sec = buff_info.etime - TimeUtil:getServerTime( )
  312. if sec > 0 then
  313. self["lb_money_" .. i .. "_tmp"].text = "免费"
  314. local sec = buff_info.etime - TimeUtil:getServerTime( )
  315. self.have_act_buff = true
  316. self:ActBuffTimeLate(sec)
  317. local buff_name = Config.Unitebuffkind[buff_kind] and Config.Unitebuffkind[buff_kind].name or ""
  318. self.lb_buff_tip_tmp.text = string.format("<color=%s><size=105%%>[%s]</size> 生效期间首次免费</color>",ColorUtil.TOPYELLOW,Trim(buff_name))
  319. else
  320. self["lb_money_" .. i .. "_tmp"].text = str_price
  321. self.lb_buff_tip_tmp.text = ""
  322. end
  323. else
  324. self["lb_money_" .. i .. "_tmp"].text = str_price
  325. self.lb_buff_tip_tmp.text = ""
  326. end
  327. else
  328. if self.data[i].first_free and self.data[i].use_time == 0 then
  329. self["lb_money_" .. i .. "_tmp"].text = "免费"
  330. else
  331. if use_goods then
  332. -- 鼓舞卷
  333. local goods_id = 102004
  334. local has_num = GoodsModel:getInstance():GetTypeGoodsNum(goods_id)
  335. local color = has_num >= str_price and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK
  336. self["lb_money_" .. i .. "_tmp"].text = string.format('%s/%s', HtmlColorTxt( has_num, color),str_price)
  337. else
  338. self["lb_money_" .. i .. "_tmp"].text = str_price
  339. end
  340. end
  341. end
  342. --显示剩余次数
  343. local left_time = self.data[i].limit - self.data[i].use_time
  344. self["lb_left_" .. i .. "_tmp"].text = string.format( "%s鼓舞:剩余%s次", WordManager:GetCommonMoneyStr(tonumber(price_info[1][1])),HtmlColorTxt( left_time , left_time > 0 and '#2cf89a' or '#ff203a'))
  345. end
  346. end
  347. end
  348. --活动BUFF时间倒计时
  349. function EncourageTips:ActBuffTimeLate( sec )
  350. if self.is_loaded then
  351. if self.act_sec == sec then
  352. return
  353. else
  354. self.act_sec = sec
  355. end
  356. if self.act_buff_timer_id then
  357. GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
  358. self.act_buff_timer_id = nil
  359. end
  360. local sec = sec or 0
  361. if sec > 0 then
  362. local function onTimer()
  363. sec = sec - 1
  364. if sec > 0 then
  365. else
  366. self.have_act_buff = false
  367. self:UpdateViewDefault()
  368. GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
  369. self.act_buff_timer_id = nil
  370. end
  371. end
  372. if not self.act_buff_timer_id then
  373. self.act_buff_timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 1, -1)
  374. end
  375. onTimer()
  376. else
  377. self.have_act_buff = false
  378. self:UpdateViewDefault()
  379. end
  380. end
  381. end
  382. -- 社团boss类型的updateviw
  383. function EncourageTips:UpdateViewGuildBoss()
  384. self.cost_goods_can = self.cost_goods_can or {}--道具足够
  385. self.cost_num_list = self.cost_num_list or {}
  386. self.cost_type_list = self.cost_type_list or {}
  387. for i=1,2 do
  388. self.cost_goods_can[i] = false--不走物品判断逻辑
  389. if i == 1 then--免费鼓舞
  390. self.cost_num_list[i] = 0
  391. self.cost_type_list[i] = 0
  392. else
  393. self.cost_num_list[i] = stringtotable(GuildModel:getInstance():GetGuildBossKV("bgold_encourage_cost"))[1]
  394. self.cost_type_list[i] = 2
  395. end
  396. end
  397. self:UpdateGuildBossEncourageTimes()
  398. self:UpdateGuildBossEncouragePercentage()
  399. end
  400. --社团boss界面鼓舞次数刷新
  401. function EncourageTips:UpdateGuildBossEncourageTimes( )
  402. local damage_percentage = GuildModel:getInstance():GetGuildBossKV("encourage_hurt")/100 --万分比伤害,这里除去100拿百分比伤害
  403. self.encourage_award_1_tmp.text = "+20"
  404. self.encourage_award_2_tmp.text = "+20"
  405. -- 设置红点
  406. local limit_free = GuildModel:getInstance():GetGuildBossKV("free_encourage")
  407. local free_time = GuildModel:getInstance():GetLeftFreeEncourageTimes()
  408. --self.free_encourage_red_obj:SetActive(limit_free - free_time > 0)
  409. for i=1,2 do
  410. local can_encourage = self.data[i].use_time < self.data[i].limit
  411. -- local show_time = can_encourage and self.data[i].use_time + 1 or self.data[i].limit
  412. --置灰
  413. SetImageGray( self["btn_" .. i .. "_img"], not can_encourage )
  414. SetTMPSharedMaterial(self["lb_btn_" .. i .. "_tmp"], not can_encourage and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn or (i == 1 and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkBlueBtn or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn))
  415. --价格
  416. self["lb_money_" .. i .. "_tmp"].text = i == 1 and "免费" or stringtotable(GuildModel:getInstance():GetGuildBossKV("bgold_encourage_cost"))[1]
  417. --鼓舞加成
  418. self["des_" .. i .. "_num_tmp"].text = "+" .. damage_percentage * self.data[i].use_time .. "%"
  419. --显示剩余次数
  420. local left_time = self.data[i].limit - self.data[i].use_time
  421. self["lb_left_" .. i .. "_tmp"].text = "剩余" .. WordManager:AddColorToString(left_time,left_time > 0 and '32ff62' or 'fa1022',false) .. ""
  422. end
  423. end
  424. --社团boss鼓舞加成系数刷新
  425. function EncourageTips:UpdateGuildBossEncouragePercentage(guild_boss_need_show_anim)
  426. local damage_percentage = GuildModel:getInstance():GetGuildBossKV("encourage_hurt")/100 --万分比伤害,这里除去100拿百分比伤害
  427. local damage = GuildModel:getInstance():GetEncourageGuildTimes()*damage_percentage
  428. -- self.des_1_title_tmp.text = "社团成员伤害"
  429. -- self.des_1_tmp.text = "+"..damage.."%"
  430. -- if guild_boss_need_show_anim then
  431. -- self:PlayGuildBossEncourageActionStart()
  432. -- end
  433. end
  434. -- --社团boss鼓舞界面的鼓舞加成
  435. -- function EncourageTips:PlayGuildBossEncourageActionStart( )
  436. -- self:StopTweenAction()
  437. -- SetLocalScale(self.des_1, 1,1,1)
  438. -- local function onComplete( ... )
  439. -- self:PlayGuildBossEncourageActionEnd()
  440. -- end
  441. -- self.scale_start_id = TweenLite.to(self, self.des_1, TweenLite.UiAnimationType.SCALE, Vector3(1.5,1.5,1.5) ,0.1, onComplete)
  442. -- end
  443. -- function EncourageTips:PlayGuildBossEncourageActionEnd( )
  444. -- local function onComplete( ... )
  445. -- SetLocalScale(self.des_1, 1,1,1)
  446. -- self:StopTweenAction()
  447. -- end
  448. -- self.scale_end_id = TweenLite.to(self, self.des_1, TweenLite.UiAnimationType.SCALE, Vector3(1,1,1) ,0.1, onComplete)
  449. -- end
  450. -- function EncourageTips:StopTweenAction( )
  451. -- if self.scale_start_id then
  452. -- TweenLite.Stop(self.scale_start_id)
  453. -- self.scale_start_id = nil
  454. -- end
  455. -- if self.scale_end_id then
  456. -- TweenLite.Stop(self.scale_end_id)
  457. -- self.scale_end_id = nil
  458. -- end
  459. -- end
  460. function EncourageTips:DestroySuccess( )
  461. --self:StopTweenAction()
  462. if self.act_buff_timer_id then
  463. GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
  464. self.act_buff_timer_id = nil
  465. end
  466. if self.money_view then
  467. self.money_view:DeleteMe()
  468. self.money_view = nil
  469. end
  470. end