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

269 regels
9.2 KiB

4 weken geleden
  1. FuliAIView = FuliAIView or BaseClass(BaseItem)
  2. local FuliAIView = FuliAIView
  3. function FuliAIView:__init()
  4. self.use_local_view = true
  5. self.base_file = "fuli"
  6. self.layout_file = "FuliAIView"
  7. self.model = FuliModel:GetInstance()
  8. self.item_list = {}
  9. self.hand_anim_list = {}
  10. self.do_not_set_progress = false
  11. self.is_hide_delete_effect = false
  12. self:Load()
  13. end
  14. function FuliAIView:Load_callback()
  15. self.nodes = {
  16. "item_con","time_text:tmp","effect","role_con",
  17. }
  18. self:GetChildren(self.nodes)
  19. self:AddEvents()
  20. if self.need_refreshData then
  21. self:SetData()
  22. end
  23. self:AddUIEffect("ui_zaixianlibao", self.effect, "UI", Vector3(-126,48,0), 1, true, -1, nil, call_back,nil,nil, 14)
  24. end
  25. function FuliAIView:AddEvents( )
  26. local function on_update_view( )
  27. self:UpdateView()
  28. end
  29. self.on_update_view_id = self.model:Bind(FuliConst.UPDATE_FULI_AI_INFO, on_update_view)
  30. end
  31. function FuliAIView:UpdateView( )
  32. -- if self.model:IsFuliAINeedRed() then
  33. -- self:PlayHandEffect()
  34. -- else
  35. -- self:StopHandEffect()
  36. -- end
  37. self.data = self.model:GetFuliAIInfo()
  38. local cfg = self.model:GetFuliAICFG(self.data.type)
  39. local pos = {
  40. -- {20,-252},{266,-392},{668,-377},{899,-205},{724,-21}
  41. -- {53.8,-128.7},{244.3,-9.5},{448.6,-124.7},{450,-331},{244,-446},{15,-321.8}
  42. {-61,-162.5},{197,-26.5},{393.5,-164},{405,-348},{184,-474},{-44.5,-340}
  43. }
  44. for i,v in ipairs(cfg) do
  45. local item = self.item_list[i]
  46. if not item then
  47. item = FuliAIItem.New(self.item_con)
  48. item:SetPosition(pos[i][1], pos[i][2])
  49. self.item_list[i] = item
  50. end
  51. item:SetData(i,v,self.data)
  52. end
  53. self:UpdateOnlineTime()
  54. -- self:UpdateProgressBar()
  55. end
  56. function FuliAIView:timeConvert(time)
  57. local hoursStr = math.floor(time / 60 / 60) % 24
  58. local minutesStr = math.floor(time / 60) % 60
  59. local secondStr = time % 60
  60. if tonumber(hoursStr) < 10 then hoursStr = 0 .. hoursStr end
  61. if tonumber(minutesStr) < 10 then minutesStr = 0 .. minutesStr end
  62. if tonumber(secondStr) < 10 then secondStr = 0 .. secondStr end
  63. return hoursStr .. HtmlColorTxt("", "#ffffff", 0.8) .. minutesStr .. HtmlColorTxt("", "#ffffff", 0.8) .. secondStr .. HtmlColorTxt("", "#ffffff", 0.8)
  64. end
  65. function FuliAIView:UpdateProgressBar( )
  66. local server_data = self.model:GetFuliAIInfo()
  67. local cfg = self.model:GetFuliAICFG(server_data.type)
  68. local progress_data = {
  69. [1] = {left = 0, right = 0.055,min = 0 , max = 0, minus = 0},
  70. [2] = {left = 0.055, right = 0.271,min = 0 , max = 0, minus = 0},
  71. [3] = {left = 0.33, right = 0.58,min = 0 , max = 0, minus = 0},
  72. [4] = {left = 0.655, right = 0.945,min = 0 , max = 0, minus = 0},
  73. }
  74. for i,v in ipairs(cfg) do
  75. if i == 1 then
  76. progress_data[i].min = 0
  77. progress_data[i].max = v.duration
  78. progress_data[i].minus = progress_data[i].max - progress_data[i].min
  79. progress_data[i].offset = progress_data[i].right - progress_data[i].left
  80. else
  81. progress_data[i].min = cfg[i-1].duration
  82. progress_data[i].max = v.duration
  83. progress_data[i].minus = progress_data[i].max - progress_data[i].min
  84. progress_data[i].offset = progress_data[i].right - progress_data[i].left
  85. end
  86. end
  87. local find = false
  88. if self.do_not_set_progress then--已经填满了就不用再设置了
  89. for i,v in ipairs(progress_data) do
  90. if server_data.duration_time <= v.max and server_data.duration_time >= v.min then
  91. self.progress_image_img.fillAmount = v.left + (server_data.duration_time - v.min)/v.minus * v.offset
  92. find = true
  93. break
  94. end
  95. end
  96. end
  97. if not find and not self.do_not_set_progress then--没找到代表着已经填充完了
  98. self.progress_image_img.fillAmount = 1
  99. self.do_not_set_progress = true
  100. end
  101. local function callback( ... )
  102. self.time_text_tmp.text = self:timeConvert(server_data.duration_time or 0)
  103. local find = false
  104. if self.do_not_set_progress then--已经填满了就不用再设置了
  105. for i,v in ipairs(progress_data) do
  106. if server_data.duration_time <= v.max and server_data.duration_time >= v.min then
  107. self.progress_image_img.fillAmount = v.left + (server_data.duration_time - v.min)/v.minus * v.offset
  108. find = true
  109. break
  110. end
  111. end
  112. end
  113. if not find and not self.do_not_set_progress then--没找到代表着已经填充完了
  114. self.progress_image_img.fillAmount = 1
  115. self.do_not_set_progress = true
  116. end
  117. end
  118. self.model:SetFuncCallBack(callback, "FuliAIView:UpdateProgressBar")
  119. end
  120. function FuliAIView:UpdateOnlineTime( )
  121. local server_data = self.model:GetFuliAIInfo()
  122. local function callback( ... )
  123. self.time_text_tmp.text = self:timeConvert(server_data.duration_time or 0)
  124. end
  125. self.model:SetFuncCallBack(callback, "FuliAIView:UpdateOnlineTime")
  126. end
  127. function FuliAIView:UpdateRoleModel( )
  128. local res_data = {
  129. father_node = self,
  130. transform = self.role_con,
  131. fashion_type = FuncOpenModel.TypeId.FJarvis,
  132. figure_id = 1019,
  133. position = Vector3(-30,-70,0),
  134. scale = 330,
  135. ui_model_type = UIModelCommon.ModelType.BackModel,
  136. action_name_list = {"show"},
  137. rotate = -25,
  138. }
  139. FuncOpenModel:getInstance():SetModelRes(res_data)
  140. end
  141. function FuliAIView:SetData( data )
  142. self.data = data
  143. if self.is_loaded then
  144. self.need_refreshData = false
  145. self.model:Fire(FuliConst.AI_TALK_SHOW, FuliConst.AI_TALK_TYPE.ENTER)
  146. self:UpdateView()
  147. self:UpdateRoleModel()
  148. else
  149. self.need_refreshData = true
  150. end
  151. end
  152. function FuliAIView:PlayHandEffect()
  153. do return end --2020527废弃 防止策划吃书 先留着
  154. if self.is_play_hand_effect then
  155. return
  156. end
  157. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.hand_image_obj)
  158. self.hand_image_obj:SetActive(true)
  159. if not self.hand_image_canvas then
  160. self.hand_image_canvas = self.hand_image:GetComponent("CanvasGroup")
  161. end
  162. self.hand_image_canvas.alpha = 0
  163. local function delayfun()
  164. local id = TweenLite.to(self, self.hand_image_canvas,TweenLite.UiAnimationType.ALPHA, 1, 0.5)
  165. table.insert(self.hand_anim_list, id)
  166. end
  167. local callfun1 = cc.CallFunc.New(delayfun)
  168. local function delayfun2()
  169. self.dot_image_obj:SetActive(true)
  170. self.left_arrow_obj:SetActive(true)
  171. self.right_arrow_obj:SetActive(true)
  172. local time = 1.5
  173. local id = TweenLite.to(self, self.dot_image,TweenLite.UiAnimationType.SCALE, Vector3(1.2,1.2,1.2), time,nil,nil,true)
  174. table.insert(self.hand_anim_list, id)
  175. id = TweenLite.to(self, self.left_arrow, TweenLite.UiAnimationType.ANCHORED_POSX, -204.5, time,nil,nil,true)
  176. table.insert(self.hand_anim_list, id)
  177. id = TweenLite.to(self, self.right_arrow, TweenLite.UiAnimationType.ANCHORED_POSX, 71, time,nil,nil,true)
  178. table.insert(self.hand_anim_list, id)
  179. end
  180. local callfun2 = cc.CallFunc.New(delayfun2)
  181. --再显示出来
  182. local function delayfun3()
  183. end
  184. local callfun3 = cc.CallFunc.New(delayfun3)
  185. local action = cc.Sequence.New(cc.DelayTime.New(0.5),callfun1,cc.DelayTime.New(1), callfun2, cc.DelayTime.New(0.5), callfun3)
  186. cc.ActionManager:getInstance():addAction(action, self.hand_image_obj)
  187. self.is_play_hand_effect = true
  188. end
  189. function FuliAIView:StopHandEffect( )
  190. self.is_play_hand_effect = false
  191. -- if self.hand_image_obj then
  192. -- self.hand_image_obj:SetActive(false)
  193. -- end
  194. if self.dot_image_obj then
  195. self.dot_image_obj:SetActive(false)
  196. end
  197. if self.left_arrow_obj then
  198. self.left_arrow_obj:SetActive(false)
  199. end
  200. if self.right_arrow_obj then
  201. self.right_arrow_obj:SetActive(false)
  202. end
  203. -- cc.ActionManager:getInstance():removeAllActionsFromTarget(self.hand_image_obj)
  204. for i,v in ipairs(self.hand_anim_list) do
  205. TweenLite.Stop(v)
  206. end
  207. self.hand_anim_list = {}
  208. end
  209. -- function FuliAIView:ShowTalkText( type )
  210. -- local cfg = self.model:GetFuliAITalkCFG(type)
  211. -- local max = #cfg
  212. -- local random_num = math.random(1, max)
  213. -- self.talk_text_tmp.text = Trim(cfg[random_num].content)
  214. -- local pos_num = math.random(1,2)
  215. -- if pos_num == 1 then
  216. -- SetAnchoredPosition(self.talk_con, -266, 67)--位置都固定摆的
  217. -- SetAnchoredPosition(self.talk_text, -7, 0)--位置都固定摆的
  218. -- lua_resM:setImageSprite(self, self.talk_con_img, "fuli_asset", "fuli_item27")
  219. -- -- self.talk_arrow.localRotation = Quaternion.Euler(0,0,180)
  220. -- elseif pos_num == 2 then
  221. -- SetAnchoredPosition(self.talk_con, 106, 47)--位置都固定摆的
  222. -- SetAnchoredPosition(self.talk_text, 6, 0)--位置都固定摆的
  223. -- lua_resM:setImageSprite(self, self.talk_con_img, "fuli_asset", "fuli_item26")
  224. -- -- self.talk_arrow.localRotation = Quaternion.Euler(0,0,270)
  225. -- -- elseif pos_num == 3 then
  226. -- -- SetAnchoredPosition(self.talk_con, -413.1, 39)--位置都固定摆的
  227. -- -- SetAnchoredPosition(self.talk_arrow, 194.1, 11.2)--位置都固定摆的
  228. -- -- self.talk_arrow.localRotation = Quaternion.Euler(0,0,0)
  229. -- end
  230. -- self.talk_con_obj:SetActive(true)
  231. -- end
  232. function FuliAIView:__delete( )
  233. -- self.model:DeleteFuncCallBack("FuliAIView:UpdateProgressBar")
  234. self.model:DeleteFuncCallBack("FuliAIView:UpdateOnlineTime")
  235. self:ClearUIEffect(self.effect)
  236. -- self:StopHandEffect()
  237. for i,v in ipairs(self.item_list) do
  238. v:DeleteMe()
  239. v = nil
  240. end
  241. self.item_list = {}
  242. if self.on_update_view_id then
  243. self.model:UnBind(self.on_update_view_id)
  244. self.on_update_view_id = nil
  245. end
  246. if self.on_action_id then
  247. self.model:UnBind(self.on_action_id)
  248. self.on_action_id = nil
  249. end
  250. if self.show_talk_text_id then
  251. self.model:UnBind(self.show_talk_text_id)
  252. self.show_talk_text_id = nil
  253. end
  254. end