源战役客户端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

345 lignes
11 KiB

  1. SpecialTipView = SpecialTipView or BaseClass(BaseView)
  2. local SpecialTipView = SpecialTipView
  3. local TimeUtil = TimeUtil
  4. function SpecialTipView:__init(layout_file_type, layer_name)
  5. self.layout_file_type = layout_file_type
  6. self.base_file = "common"
  7. self.layout_file = "SpecialTipView"
  8. -- 计时器里面会跑到的model,都要在这里注册,减少对_G表的搜索
  9. self.scene_mgr = SceneManager:getInstance()
  10. self.dungeon_model = BaseDungeonModel:getInstance()
  11. self.layer_name = layer_name or "Main"
  12. self.destroy_imm = true
  13. self.use_background = false
  14. self.change_scene_close = true
  15. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  16. self.need_show_money = false --是否要显示顶部的金钱栏
  17. self.floor_anim_list = {}--楼层动作列表
  18. self.showing_main_tips = false -- 正在展示主横幅
  19. self.showing_sub_tips = false -- 正在展示副横幅
  20. self.load_callback = function ()
  21. self:LoadSuccess()
  22. self:AddEvent()
  23. end
  24. self.open_callback = function ( )
  25. self:UpdateView()
  26. end
  27. self.destroy_callback = function ( )
  28. self:DestroySuccess()
  29. end
  30. end
  31. -- data = {
  32. --[其他参数]
  33. -- module_id,--模块id
  34. -- id,--子模块,与module_id共同使用来寻找Config.Languageextra中的提示语
  35. -- [必须参数]
  36. -- type, -- 类型 默认1 1=显示文本定时关闭 2=持续显示倒计时类型1(必须写sepeical_str,且只带一个%s用来展示时间) 3=补充显示的小横幅,不覆盖主横幅的展示
  37. -- sepeical_str,--强制显示文本,传了次文本时,不找配置,直接显示文本内容
  38. -- show_time,--显示时长,时间过后会关闭tipview,nil或false时tipview需要发送事件手动关闭
  39. -- end_time_callback,时间结束回调
  40. -- }
  41. function SpecialTipView:InitMainTipData(data)
  42. self.module_id = data.module_id
  43. self.id = data.id
  44. self.sepeical_str = data.sepeical_str
  45. self.show_time = data.show_time
  46. self.main_type = data.type
  47. if self.end_time_callback then
  48. self.end_time_callback()
  49. end
  50. -- 清除掉所有主横幅计时器事件
  51. self:RemoveCloseTimeId()
  52. self:RemoveTimerTypeId()
  53. self.showing_main_tips = true
  54. end
  55. function SpecialTipView:InitSubTipData(data)
  56. self.st_module_id = data.module_id
  57. self.st_id = data.id
  58. self.st_sepeical_str = data.sepeical_str
  59. self.st_show_time = data.show_time
  60. self.st_type = data.type
  61. if self.st_end_time_callback then
  62. self.st_end_time_callback()
  63. end
  64. -- 清除掉所有副横幅计时器事件
  65. self:RemoveSubTipsCloseTimeId()
  66. self:RemoveSubTipsTimerTypeId()
  67. self.showing_sub_tips = true
  68. end
  69. function SpecialTipView:Open(data, layout_file_type, layer_name)
  70. if data.type ~= SpecialTipType.SubTip1 then -- 主tips,覆盖掉之前的主tips
  71. self:InitMainTipData(data)
  72. elseif data.type == SpecialTipType.SubTip1 then -- 副tips,覆盖副tips的横幅
  73. self:InitSubTipData(data)
  74. end
  75. BaseView.Open(self)
  76. end
  77. function SpecialTipView:LoadSuccess()
  78. self.nodes = {
  79. "diImg:raw", "descText:tmp",
  80. "diSubImg:raw", "descSubText:tmp",
  81. "descMiddleText:tmp",
  82. }
  83. self:GetChildren(self.nodes)
  84. self:InitMainTipsText(false)
  85. self:InitSubTipsText(false)
  86. lua_resM:setOutsideRawImage(self, self.diImg_raw, GameResPath.GetViewBigBg("special_tip_di_3"), false)
  87. lua_resM:setOutsideRawImage(self, self.diSubImg_raw, GameResPath.GetViewBigBg("special_tip_di_4"), true)
  88. --设置sceneView的自适应
  89. self.transform.sizeDelta = Vector2(ScreenWidth, ScreenHeight)
  90. SetAnchoredPosition(self.transform, 0, 0)
  91. end
  92. function SpecialTipView:AddEvent()
  93. end
  94. function SpecialTipView:UpdateView()
  95. self:UpdateMainTips()
  96. self:UpdateSubTips()
  97. self:UpdateTipsNodePosition()
  98. end
  99. function SpecialTipView:UpdateMainTips( )
  100. if not self.showing_main_tips then return end
  101. -- 初始化横幅文本
  102. self:InitMainTipsText(true)
  103. self:UpdateAutoClose()
  104. if self.main_type == SpecialTipType.Normal then
  105. self.descText_tmp.text = self.sepeical_str
  106. -- 动态拓展倒计时的类型,就放在这里面,原则上倒计时类型可使用同一个self.tip_type_timer_id来保存计时器id
  107. elseif self.main_type == SpecialTipType.Middle then
  108. self.descMiddleText_tmp.text = self.sepeical_str
  109. else
  110. self:ShowTimerType()
  111. end
  112. end
  113. -- 类型1展示(秒数)
  114. function SpecialTipView:ShowTimerType( )
  115. local end_time = self:GetTimerTypeEndTime()
  116. local druation_speed = self:GetTimerTypeDurationSpeed()
  117. local left_time
  118. -- 展开计时器
  119. local function tipTypeTimerFunc()
  120. if self.main_type == SpecialTipType.Timer1 then--秒数倒计时
  121. left_time = end_time - TimeUtil:getServerTime()
  122. elseif self.main_type == SpecialTipType.Timer2 then--豪秒数倒计时
  123. left_time = end_time - TimeUtil:getServerTimeMs() / 1000
  124. elseif self.main_type == SpecialTipType.Timer3 then
  125. left_time = end_time - TimeUtil:getServerTime()
  126. end
  127. left_time = left_time > 0 and left_time or 0
  128. ----------------这个是例子 一定要看
  129. --self.sepeical_str = 距离评级下降 %s
  130. --self:GetTimeStrFunc(left_time) = <size=130%><#ffffff>00:00.00</color></size>
  131. local str = string.format(self.sepeical_str,self:GetTimeStrFunc(left_time))
  132. self.descText_tmp.text = str or ""
  133. if left_time <= 0 then
  134. self.showing_main_tips = false
  135. if self.end_time_callback then
  136. self.end_time_callback()
  137. self.end_time_callback = nil
  138. end
  139. self:RemoveTimerTypeId()
  140. end
  141. end
  142. tipTypeTimerFunc()
  143. self.tip_type_timer_id = GlobalTimerQuest:AddPeriodQuest(tipTypeTimerFunc, druation_speed, -1)
  144. end
  145. --专属倒计时方法
  146. function SpecialTipView:GetTimeStrFunc( left_time )
  147. local time_str = ""
  148. if self.main_type == SpecialTipType.Timer1 then--秒数倒计时
  149. time_str = string.format("<size=130%%><#ffffff>%s</color></size>",left_time)
  150. elseif self.main_type == SpecialTipType.Timer2 then--豪秒数倒计时
  151. time_str = string.format("<size=130%%><#ffffff>%s</color></size>",TimeUtil:convertMillisecondTime(left_time))
  152. elseif self.main_type == SpecialTipType.Timer3 then--00:00倒计时
  153. time_str = string.format("<size=130%%><#ffffff>%s</color></size>",TimeUtil:timeConversion(left_time, "MM-ss"))
  154. end
  155. return time_str
  156. end
  157. -- 更新副横幅
  158. function SpecialTipView:UpdateSubTips( )
  159. if not self.showing_sub_tips then return end
  160. -- 初始化文本节点
  161. self:InitSubTipsText(true)
  162. self:UpdateSubTipAutoClose()
  163. self:ShowSubTimerType()
  164. end
  165. function SpecialTipView:ShowSubTimerType( )
  166. self.descSubText_tmp.text = self.st_sepeical_str
  167. end
  168. -------------------------------------------------------------------------------------------------
  169. -- 结束时间计算
  170. function SpecialTipView:GetTimerTypeEndTime()
  171. if self.main_type == SpecialTipType.Timer2 then
  172. return TimeUtil:getServerTime() + self.show_time
  173. else
  174. return TimeUtil:getServerTime() + self.show_time
  175. end
  176. end
  177. -- 计时器速度 (秒)
  178. function SpecialTipView:GetTimerTypeDurationSpeed( )
  179. if self.main_type == SpecialTipType.Timer2 then
  180. return 0.03
  181. else
  182. return 0.5
  183. end
  184. end
  185. -- 更新主横幅的倒计时
  186. function SpecialTipView:UpdateAutoClose( )
  187. --不设置显示时间时不会自动关闭界面
  188. if not self.show_time then return end
  189. local function clockFun()
  190. self.show_time = self.show_time or 0
  191. if self.show_time <= 0 then
  192. if self.end_time_callback then
  193. self.end_time_callback()
  194. self.end_time_callback = nil
  195. end
  196. self:InitMainTipsText(false)
  197. self.showing_main_tips = false
  198. self:CheckTipsClose()
  199. end
  200. self.show_time = self.show_time - 1
  201. end
  202. if not self.close_time_id then
  203. self.close_time_id = GlobalTimerQuest:AddPeriodQuest(clockFun, 1, -1)
  204. end
  205. end
  206. -- 检查副标题的主倒计时
  207. function SpecialTipView:UpdateSubTipAutoClose( )
  208. if not self.st_show_time then return end
  209. local function st_clockFun()
  210. self.st_show_time = self.st_show_time or 0
  211. if self.st_show_time <= 0 then
  212. if self.st_end_time_callback then
  213. self.st_end_time_callback()
  214. self.st_end_time_callback = nil
  215. end
  216. self:InitSubTipsText(false)
  217. self.showing_sub_tips = false
  218. self:CheckTipsClose()
  219. end
  220. self.st_show_time = self.st_show_time - 1
  221. end
  222. if not self.st_close_time_id then
  223. self.st_close_time_id = GlobalTimerQuest:AddPeriodQuest(st_clockFun, 1, -1)
  224. end
  225. end
  226. -- 检查是否关闭tips界面
  227. function SpecialTipView:CheckTipsClose( )
  228. -- 当主Tips和副Tips都不显示的时候,关闭界面
  229. if not self.showing_main_tips and not self.showing_sub_tips then
  230. self:Close()
  231. return
  232. end
  233. -- 调整节点位置
  234. self:UpdateTipsNodePosition()
  235. end
  236. -- 调整横幅节点之间的相对位置
  237. function SpecialTipView:UpdateTipsNodePosition( )
  238. if self.showing_main_tips and self.showing_sub_tips then -- 两个都显示时,需要上下均分位置
  239. SetAnchoredPositionY(self.diImg, 225 + 15)
  240. SetAnchoredPositionY(self.descText, 224 + 15)
  241. SetAnchoredPositionY(self.diSubImg, 225 - 25)
  242. SetAnchoredPositionY(self.descSubText, 226 - 25)
  243. SetAnchoredPositionY(self.descMiddleText, 221)
  244. elseif self.showing_main_tips then -- 只展示主tips节点
  245. SetAnchoredPositionY(self.diImg, 225)
  246. SetAnchoredPositionY(self.descMiddleText, 221)
  247. SetAnchoredPositionY(self.descText, 224)
  248. elseif self.showing_sub_tips then -- 只展示副tips节点
  249. SetAnchoredPositionY(self.diSubImg, 225)
  250. SetAnchoredPositionY(self.descSubText, 226)
  251. SetAnchoredPositionY(self.descMiddleText, 221)
  252. end
  253. end
  254. -------------------------------------------------------------------------------------------------
  255. -------------------------------------------------------------------------------------------------
  256. -- 当出现多个Tip同时发过来的时候做覆盖处理,最后一个发过来的作为当前显示
  257. function SpecialTipView:UpdateTips(data,layout_file_type, layer_name)
  258. if data.type ~= SpecialTipType.SubTip1 then -- 主tips,覆盖掉之前的主tips
  259. self:InitMainTipData(data)
  260. self:UpdateMainTips()
  261. elseif data.type == SpecialTipType.SubTip1 then -- 副tips,覆盖副tips的横幅
  262. self:InitSubTipData(data)
  263. self:UpdateSubTips()
  264. end
  265. self:UpdateTipsNodePosition()
  266. end
  267. -- 初始化所有的文本
  268. function SpecialTipView:InitMainTipsText(show)
  269. if self.is_loaded then
  270. show = show or false
  271. self.diImg_raw.enabled = show
  272. self.descText_tmp.text = ""
  273. self.descMiddleText_tmp.text = ""
  274. end
  275. end
  276. function SpecialTipView:InitSubTipsText(show)
  277. if self.is_loaded then
  278. show = show or false
  279. self.diSubImg_raw.enabled = show
  280. self.descSubText_tmp.text = ""
  281. end
  282. end
  283. function SpecialTipView:RemoveCloseTimeId( )
  284. if self.close_time_id then
  285. GlobalTimerQuest:CancelQuest(self.close_time_id)
  286. self.close_time_id = nil
  287. end
  288. end
  289. function SpecialTipView:RemoveTimerTypeId( )
  290. if self.tip_type_timer_id then
  291. GlobalTimerQuest:CancelQuest(self.tip_type_timer_id)
  292. self.tip_type_timer_id = nil
  293. end
  294. end
  295. function SpecialTipView:RemoveSubTipsCloseTimeId( )
  296. if self.st_close_time_id then
  297. GlobalTimerQuest:CancelQuest(self.st_close_time_id)
  298. self.st_close_time_id = nil
  299. end
  300. end
  301. function SpecialTipView:RemoveSubTipsTimerTypeId( )
  302. if self.st_tip_type_timer_id then
  303. GlobalTimerQuest:CancelQuest(self.st_tip_type_timer_id)
  304. self.st_tip_type_timer_id = nil
  305. end
  306. end
  307. function SpecialTipView:DestroySuccess( )
  308. self:RemoveCloseTimeId()
  309. self:RemoveTimerTypeId()
  310. self:RemoveSubTipsCloseTimeId()
  311. self:RemoveSubTipsTimerTypeId()
  312. end