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

90 lines
2.4 KiB

  1. CommonActivityIconTipView = CommonActivityIconTipView or BaseClass(BaseView)
  2. local CommonActivityIconTipView = CommonActivityIconTipView
  3. function CommonActivityIconTipView:__init()
  4. self.base_file = "common"
  5. self.layout_file = "CommonActivityIconTipView"
  6. self.layer_name = "Main"
  7. self.destroy_imm = true
  8. self.use_background = false
  9. self.append_to_ctl_queue = false
  10. self.str = ""
  11. self.pos_x = 0
  12. self.pos_y = 0
  13. self.time = 10
  14. self.load_callback = function ()
  15. self:LoadSuccess()
  16. self:UpdateView(self.str,self.pos_x,self.pos_y)
  17. end
  18. self.close_callback = function ()
  19. self:Remove()
  20. end
  21. end
  22. function CommonActivityIconTipView:Remove()
  23. if self.event_list_id then
  24. GlobalEventSystem:UnBind(self.event_list_id)
  25. self.event_list_id = nil
  26. end
  27. if self.timer_id then
  28. GlobalTimerQuest:CancelQuest(self.timer_id)
  29. self.timer_id = nil
  30. end
  31. end
  32. function CommonActivityIconTipView:Open( str,x,y )
  33. self.str = str or self.str
  34. self.pos_x = x or self.pos_x
  35. self.pos_y = y or self.pos_y
  36. print("huangcong:CommonActivityIconTipView [35]: ",str,x,y)
  37. BaseView.Open(self)
  38. end
  39. function CommonActivityIconTipView:LoadSuccess()
  40. local nodes = {
  41. "layout/bg","layout/text:txt","layout:obj"
  42. }
  43. self:GetChildren(nodes)
  44. self:InitEvent()
  45. end
  46. function CommonActivityIconTipView:InitEvent()
  47. local updateFunc2 = function ()
  48. self:Close()
  49. end
  50. self.event_list_id = GlobalEventSystem:Bind(EventName.CLOSE_ACTIVITY_ICON_TIP_VIEW, updateFunc2)
  51. end
  52. function CommonActivityIconTipView:UpdateView(str,x,y)
  53. self.str = str or self.str
  54. self.pos_x = x or self.pos_x
  55. self.pos_y = y or self.pos_y
  56. self.layout_obj:SetActive(false)
  57. -- local width = self.text_txt.preferredWidth
  58. -- width = width + 150
  59. -- self.bg.sizeDelta = Vector2(width,80)
  60. self.text_txt.text = self.str
  61. if self.pos_x and self.pos_y then
  62. -- local x,y = ScreenToViewportPoint(self.pos_x,self.pos_y)
  63. -- self.layout.sizeDelta = Vector2(307,self.curr_height)
  64. self.layout.anchoredPosition = Vector3(self.pos_x+313,self.pos_y+242,0)
  65. end
  66. self.layout_obj:SetActive(true)
  67. self:SetTimer()
  68. end
  69. function CommonActivityIconTipView:SetTimer()
  70. if self.timer_id then
  71. GlobalTimerQuest:CancelQuest(self.timer_id)
  72. self.timer_id = nil
  73. end
  74. local function onTimer()
  75. self.time = self.time - 1
  76. if self.time > 0 then
  77. else
  78. GlobalTimerQuest:CancelQuest(self.timer_id)
  79. self.timer_id = nil
  80. self:Close()
  81. end
  82. end
  83. self.timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 1, -1)
  84. end