源战役客户端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

130 rader
3.8 KiB

1 månad sedan
  1. LightTabItem = LightTabItem or BaseClass(BaseItem)
  2. local LightTabItem = LightTabItem
  3. LightTabItem.Width = 121
  4. LightTabItem.Height = 125
  5. function LightTabItem:__init(parent_wnd,prefab_asset,layer_name)
  6. self.base_file = "light"
  7. self.layout_file = "LightTabItem"
  8. self.layer_name = layer_name
  9. self.model = LightModel:GetInstance()
  10. self:Load()
  11. end
  12. function LightTabItem:Load_callback()
  13. self.nodes = {
  14. "di_can:obj", "lock:obj", "lb_lock_des:tmp", "icon:img", "di:img:obj", "red_dot:obj",
  15. "mask:obj", "light:obj", "di_name:obj",
  16. }
  17. self:GetChildren(self.nodes)
  18. self:AddEvents()
  19. if self.need_refreshData then
  20. self:UpdateView()
  21. end
  22. end
  23. function LightTabItem:AddEvents( )
  24. local function call_back( target )
  25. if self.call_back then
  26. self.call_back(self.data.id)
  27. end
  28. if self.index == 1 then
  29. --完成引导
  30. local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_LIGHT,3)
  31. if helpVo and helpVo.step == 3 then
  32. GlobalEventSystem:Fire(EventName.FINISH_CURRENT_HELP_STEP,helpVo)
  33. end
  34. end
  35. end
  36. AddClickEvent(self.di_obj,call_back,false)
  37. local function onGuideTrigger()
  38. self:AddToStageHandler()
  39. end
  40. self.guide_trigger_id = GlobalEventSystem:Bind(EventName.TRIGGER_GUIDE_TYPE,onGuideTrigger)
  41. end
  42. function LightTabItem:UpdateView( )
  43. if not self.data then
  44. return
  45. end
  46. local can_active = self.model:CanLightActive( false,self.data.id )
  47. local is_active = self.model:GetLightIsActive( self.data.id )
  48. local conf = self.model:GetLightConfOne(self.data.id)
  49. local cur_is_me = self.data.id == self.cur_select_id
  50. self.lock_obj:SetActive(not is_active)
  51. self.di_can_obj:SetActive(can_active)
  52. self.di_name_obj:SetActive(not is_active)
  53. self.lb_lock_des_tmp.text = (is_active or can_active) and "" or Trim(self.data.desc)
  54. -- lua_resM:setImageSprite(self, self.di_img, "light_asset", cur_is_me and "light_di_19" or "light_di_20",true)
  55. lua_resM:setImageSprite(self, self.di_img, "light_asset", "light_di_19" .. "_" .. conf.color,true)
  56. local function call_back( )
  57. local x,y = GetSizeDeltaXY(self.icon.transform)
  58. local scale = 1
  59. if x > y then
  60. if x > 104 then
  61. scale = 104/x
  62. end
  63. else
  64. if y > 104 then
  65. scale = 104/y
  66. end
  67. end
  68. SetLocalScale(self.icon.transform, scale,scale,scale)
  69. end
  70. lua_resM:setOutsideImageSprite(self,self.icon_img,"/client/assets/icon/light/light_head_" .. self.data.id .. ".png",true,call_back)
  71. self.mask_obj:SetActive( not is_active )
  72. self.light_obj:SetActive(cur_is_me)
  73. self:UpdateRed()
  74. end
  75. function LightTabItem:UpdateRed( )
  76. if not self.is_loaded then return end
  77. if not self.data then
  78. return
  79. end
  80. local can_active = self.model:CanLightActive( false,self.data.id )
  81. self.red_dot_obj:SetActive(can_active or self.model:CanLightUpGrade( false,self.data.id ))
  82. self:AddToStageHandler()
  83. end
  84. function LightTabItem:SetData( index, data, call_back, cur_select_id )
  85. self.index = index
  86. self.data = data
  87. self.call_back = call_back
  88. self.cur_select_id = cur_select_id
  89. if self.is_loaded then
  90. self.need_refreshData = false
  91. self:UpdateView()
  92. else
  93. self.need_refreshData = true
  94. end
  95. end
  96. function LightTabItem:__delete( )
  97. if self.guide_trigger_id then
  98. GlobalEventSystem:UnBind(self.guide_trigger_id)
  99. self.guide_trigger_id = nil
  100. end
  101. end
  102. function LightTabItem:AddToStageHandler()
  103. if self.index ~= 1 then return end
  104. local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_LIGHT,3)
  105. if not helpVo then return end
  106. local help_type = helpVo.help_type
  107. local step = helpVo.step
  108. local button = false
  109. if help_type == HelpType.TYPE_LIGHT and step == 3 then
  110. button = self.di_obj
  111. end
  112. if button then
  113. GlobalEventSystem:Fire(EventName.OPEN_GUIDE_PROMPT_VIEW, button.transform, self.transform, call_back, helpVo, self.layout_file)
  114. end
  115. end