源战役客户端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

203 wiersze
4.9 KiB

4 tygodni temu
  1. AdventureBookItem = AdventureBookItem or BaseClass(BaseItem)
  2. local AdventureBookItem = AdventureBookItem
  3. local math_abs = math.abs
  4. AdventureBookItem.ITEM_OFFSET = 380
  5. function AdventureBookItem:__init()
  6. self.base_file = "adventureBook"
  7. self.layout_file = "AdventureBookItem"
  8. self.is_delay_callback = true
  9. self.model = AdventureBookModel:getInstance()
  10. self.need_refreshData = false
  11. self.real_index = -1
  12. self.is_lock = false
  13. self.cur_scale = -1
  14. self.drag_begin_x = 0
  15. self.max_book_index = 10
  16. self.curr_pos_x = 0
  17. self:Load()
  18. end
  19. function AdventureBookItem:Load_callback()
  20. self:LoadSuccess()
  21. self:InitEvent()
  22. if self.need_refreshData then
  23. self:SetData(self.data)
  24. end
  25. end
  26. function AdventureBookItem:LoadSuccess()
  27. self.icon_img,
  28. self.chapt_img,
  29. self.state_img = self:GetChildImages({
  30. "icon",
  31. "chapt",
  32. "state",
  33. })
  34. self.state_object,
  35. self.lock_object,
  36. self.select_object = self:GetChildGameObjects(
  37. {
  38. "state",
  39. "lock",
  40. "select",
  41. })
  42. self.lock_txt,
  43. self.content_txt = self:GetChildTexts({
  44. "lock/text",
  45. "content",
  46. })
  47. end
  48. function AdventureBookItem:InitEvent()
  49. end
  50. function AdventureBookItem:OnClickItem()
  51. if not self.is_loaded then
  52. return
  53. end
  54. if self.is_lock then
  55. Message.show("暂未解锁本书")
  56. else
  57. self.model:Fire(AdventureBookModel.UPDATE_ADVENTURE_BOOK_DETAIL_VIEW, self.data.type, self.data.subtype)
  58. end
  59. end
  60. function AdventureBookItem:SetData(data)
  61. self.data = data
  62. if not self.data then return end
  63. if self.is_loaded then
  64. local info = self.model:GetBookInfo(self.data.type, self.data.subtype)
  65. if info then
  66. self:SetLockState(false)
  67. self.state_object:SetActive(true)
  68. if info.status == 0 then --进行中
  69. lua_resM:setImageSprite(self,self.state_img,"adventureBook_asset", "tyui_jxz")
  70. elseif info.status == 1 then --可激活
  71. lua_resM:setImageSprite(self,self.state_img,"adventureBook_asset", "tyui_kjh")
  72. elseif info.status == 2 then --已完成
  73. lua_resM:setImageSprite(self,self.state_img,"adventureBook_asset", "tyui_ywc")
  74. end
  75. self.content_txt.text = "获得" ..Trim(self.data.reward_name)
  76. else
  77. self:SetLockState(true)
  78. self.state_object:SetActive(false)
  79. self.content_txt.text = ""
  80. end
  81. local show_index = self.model:GetBookShowIndex(self.data.type)
  82. if show_index == self.data.subtype then
  83. self:SetItemScale(1)
  84. self.select_object:SetActive(true)
  85. else
  86. self:SetItemScale(0.8)
  87. self.select_object:SetActive(false)
  88. end
  89. self.max_book_index = TableSize(Config.Adventurebook)
  90. lua_resM:setImageSprite(self,self.chapt_img,"adventureBook_asset", "zjui_title_" .. self.data.subtype,true)
  91. lua_resM:setOutsideImageSprite(self, self.icon_img, GameResPath.GetImage("adventureBook","zjui_bg1_"..self.data.subtype),true)
  92. else
  93. self.need_refreshData = true
  94. end
  95. end
  96. function AdventureBookItem:SetLockState(bool)
  97. self.is_lock = bool
  98. self.lock_object:SetActive(bool)
  99. if bool then
  100. self.icon_img.gray = true
  101. local unlock = ErlangParser:GetInstance():Parse(self.data.unlock_condition)
  102. if unlock and unlock[1] then
  103. if unlock[1][1] == "book" then
  104. local last_data = Config.Adventurebook[unlock[1][2].."@"..unlock[1][3]]
  105. if last_data then
  106. self.lock_txt.text = "激活"..Trim(last_data.name).."后解锁"
  107. end
  108. end
  109. end
  110. else
  111. self.icon_img.gray = false
  112. end
  113. end
  114. function AdventureBookItem:__delete()
  115. end
  116. function AdventureBookItem:SetItemScale(scale)
  117. scale = scale > 0.8 and scale or 0.8
  118. if self.cur_scale ~= scale then
  119. self.cur_scale = scale
  120. self:SetScale(scale)
  121. end
  122. end
  123. function AdventureBookItem:DragBegin()
  124. self:SetDragBeginX()
  125. end
  126. function AdventureBookItem:Drag(x,y)
  127. if not self.is_loaded then
  128. return
  129. end
  130. self:SetAnchoredPosition(self.drag_begin_x + x,0)
  131. self.curr_pos_x = self.transform.anchoredPosition.x
  132. if self.curr_pos_x < - AdventureBookItem.ITEM_OFFSET * 2 then
  133. local new_pos_x = self.curr_pos_x + AdventureBookItem.ITEM_OFFSET * 4
  134. self:SetAnchoredPosition(new_pos_x,0)
  135. self:SetDragBeginX(new_pos_x - x)
  136. local subtype = self.data.subtype + 4
  137. if subtype > self.max_book_index then
  138. subtype = subtype - self.max_book_index
  139. end
  140. local data = Config.Adventurebook[self.data.type .. "@" .. subtype]
  141. if data then
  142. self:SetData(data)
  143. end
  144. elseif self.curr_pos_x > AdventureBookItem.ITEM_OFFSET * 2 then
  145. local new_pos_x = self.curr_pos_x - AdventureBookItem.ITEM_OFFSET * 4
  146. self:SetAnchoredPosition(new_pos_x,0)
  147. self:SetDragBeginX(new_pos_x - x)
  148. local subtype = self.data.subtype - 4
  149. if subtype < 1 then
  150. subtype = subtype + self.max_book_index
  151. end
  152. local data = Config.Adventurebook[self.data.type .. "@" .. subtype]
  153. if data then
  154. self:SetData(data)
  155. end
  156. end
  157. self:SetItemScale(1 - 0.2 * math_abs(self.curr_pos_x) / AdventureBookItem.ITEM_OFFSET)
  158. end
  159. function AdventureBookItem:DragEnd()
  160. self:SetDragBeginX()
  161. end
  162. function AdventureBookItem:SetDragBeginX(x)
  163. if not self.is_loaded then
  164. return
  165. end
  166. self.drag_begin_x = x or self.transform.anchoredPosition.x
  167. end