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

125 lines
4.2 KiB

  1. ChildHandbookItem = ChildHandbookItem or BaseClass(BaseItem)
  2. function ChildHandbookItem:__init()
  3. self.base_file = "child"
  4. self.layout_file = "ChildHandbookItem"
  5. self.is_delay_callback = true
  6. -- self.use_local_view = true
  7. self.model = ChildModel:GetInstance()
  8. self:Load()
  9. end
  10. function ChildHandbookItem:Load_callback()
  11. self.nodes = {
  12. "bg/name_txt:tmp",
  13. "bg:obj:img","bg/chosen_con:obj","bg/lock_con:obj","bg/active_con:obj","bg/red_dot:obj",
  14. "bg/icon:img", "bg/fight_num:txt",
  15. }
  16. self:GetChildren(self.nodes)
  17. self:InitEvent()
  18. -- lua_resM:setOutsideImageSprite(self, self.bg_img, GameResPath.GetChildIcon("child_hand_book_bg2"), false)
  19. if self.need_refreshData then
  20. self:UpdateView( )
  21. self:SetChosen(self.isChosen)
  22. self:SetRedDot(self.isRedDot)
  23. end
  24. end
  25. function ChildHandbookItem:InitEvent()
  26. local function onBtnClickHandler(target, x, y)
  27. if target == self.bg_obj then
  28. --self.callback(self)
  29. if self.type == ChildConst.ChildHandbookItemType.CanActive then
  30. self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16536,self.data.suit_type,self.data.toy_id) -- 激活
  31. else
  32. UIToolTipMgr:getInstance():AppendGoodsTips(self.data.toy_id,nil, nil,nil,nil,nil,false,false)
  33. end
  34. end
  35. end
  36. AddClickEvent(self.bg_obj, onBtnClickHandler)
  37. end
  38. function ChildHandbookItem:SetData(data, check_effect)
  39. self.data = data or self.data
  40. self.last_type = self.type
  41. self.type = nil
  42. self.check_effect = check_effect
  43. local num = GoodsModel:getInstance():GetTypeGoodsNum(data.toy_id)
  44. if not data.isActive and num > 0 then --可激活
  45. self.type = ChildConst.ChildHandbookItemType.CanActive
  46. elseif not data.isActive and num <= 0 then ---不可激活,锁
  47. self.type = ChildConst.ChildHandbookItemType.Lock
  48. else
  49. self.type = ChildConst.ChildHandbookItemType.IsActive -- 已经激活
  50. end
  51. if self.is_loaded then
  52. self:UpdateView( )
  53. else
  54. self.need_refreshData = true
  55. end
  56. end
  57. function ChildHandbookItem:UpdateView( )
  58. self.fight_num_txt.text = "f"..GetFighting(stringtotable(self.data.attr_list))
  59. lua_resM:setOutsideImageSprite(self, self.icon_img, GameResPath.GetChildHandbookIcon(self.data.toy_id), true)
  60. local data = self.data
  61. if self.check_effect then
  62. self.check_effect = false
  63. if (not self.is_in_effect) and self.last_type ~= ChildConst.ChildHandbookItemType.IsActive and
  64. self.type == ChildConst.ChildHandbookItemType.IsActive then -- 可激活到激活
  65. self.is_in_effect = true
  66. local function call_back( )
  67. self.is_in_effect = false
  68. end
  69. self:ClearUIEffect(self.icon)
  70. self:AddUIEffect("ui_hunliqiudianliang", self.icon, "Activity", Vector3(0, 60 ,0), 4, false, 0.6, nil, call_back)
  71. end
  72. end
  73. self.chosen_con_obj:SetActive(false)
  74. self.lock_con_obj:SetActive(false)
  75. self.active_con_obj:SetActive(false)
  76. self.icon_img.color = Color(1,1,1)
  77. self.icon_img.gray = false
  78. -- self.fight_bg_img.gray = false
  79. -- local num = GoodsModel:getInstance():GetTypeGoodsNum(data.fashion_id)
  80. ---激活
  81. if self.type == ChildConst.ChildHandbookItemType.CanActive then --可激活
  82. self.active_con_obj:SetActive(true)
  83. self.icon_img.color = Color(114/255,111/255,111/255)
  84. elseif self.type == ChildConst.ChildHandbookItemType.Lock then --不可激活,锁
  85. self.lock_con_obj:SetActive(true)
  86. self.icon_img.gray = true
  87. -- self.fight_bg_img.gray = true
  88. else
  89. end
  90. self.name_txt_tmp.text = data.toy_name or ""
  91. end
  92. function ChildHandbookItem:SetChosen(bool)
  93. self.isChosen = bool
  94. if self.is_loaded then
  95. if bool then
  96. self.chosen_con_obj:SetActive(true)
  97. else
  98. self.chosen_con_obj:SetActive(false)
  99. end
  100. else
  101. self.need_refreshData = true
  102. end
  103. end
  104. function ChildHandbookItem:SetRedDot(bool)
  105. self.isRedDot = bool
  106. if self.is_loaded then
  107. --print("============>>> YiRan:ChildHandbookItem [start:83] vehicle_id :",vehicle_id,"self.isRedDot:",self.isRedDot)
  108. self.red_dot_obj:SetActive(self.isRedDot)
  109. else
  110. self.need_refreshData = true
  111. end
  112. end