MainSkillLayout.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. local MainSkillLayout = class("MainSkillLayout", function()
  2. return cc.Node:create()
  3. end)
  4. local sformat = string.format
  5. function MainSkillLayout:ctor()
  6. self._path = global.MMO.PATH_RES_PRIVATE .. "main/"
  7. self._nodeCells = {}
  8. self._skillCells = {}
  9. self._heroSkillCell = nil
  10. self.HeroPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  11. end
  12. function MainSkillLayout.create()
  13. local layout = MainSkillLayout.new()
  14. if layout:Init() then
  15. return layout
  16. end
  17. return nil
  18. end
  19. function MainSkillLayout:Init()
  20. self.ui = ui_delegate(self)
  21. return true
  22. end
  23. function MainSkillLayout:InitGUI()
  24. SL:RequireFile(SLDefine.LUAFile.LUA_FILE_MAIN_SKILL)
  25. local meta = {}
  26. meta.ClickSkillEvent = handler(self, self.ClickSkillEvent)
  27. meta.click_HeroSkill = handler(self, self.click_HeroSkill)
  28. meta.JointHeroEffect = handler(self, self.HeroJointEffect)
  29. meta.ClickComboSkill = handler(self, self.ClickComboSkillEvent)
  30. meta.__index = meta
  31. setmetatable(MainSkill, meta)
  32. MainSkill.main()
  33. self:InitSkill()
  34. self:InitEditMode()
  35. self._layoutSkill = self.ui.Panel_skill
  36. self._layoutActive = self.ui.Panel_active
  37. return true
  38. end
  39. function MainSkillLayout:InitEditMode()
  40. for i = 1, 9 do
  41. local name = string.format("Node_cell_%s", i)
  42. if self.ui[name] then
  43. self.ui[name].editMode = 1
  44. end
  45. end
  46. local items = {
  47. "Panel_quick_find",
  48. "Image_player",
  49. "Image_monster",
  50. "Image_hero",
  51. "Button_attack",
  52. "Button_pick",
  53. "Button_change",
  54. "Button_Lock",
  55. "Node_hj_skill"
  56. }
  57. for _, widgetName in ipairs(items) do
  58. if self.ui[widgetName] then
  59. self.ui[widgetName].editMode = 1
  60. end
  61. end
  62. end
  63. function MainSkillLayout:UpdatePick()
  64. local AutoProxy = global.Facade:retrieveProxy( global.ProxyTable.Auto )
  65. if AutoProxy:IsPickState() then
  66. self.ui.Button_pick:setBright(false)
  67. else
  68. self.ui.Button_pick:setBright(true)
  69. end
  70. end
  71. function MainSkillLayout:UpdatePickupVisible(visible)
  72. self.ui.Button_pick:setVisible(visible)
  73. end
  74. function MainSkillLayout:InitSkill()
  75. for i = 1, 9 do
  76. local node = self.ui[sformat("Node_cell_%s", i)]
  77. table.insert(self._nodeCells, node)
  78. end
  79. -- attack
  80. self.ui.Button_attack:addTouchEventListener(function(_, eventType)
  81. if eventType == 0 then
  82. global.Facade:sendNotification(global.NoticeTable.LaunchAttackSkill)
  83. self.ui.Button_attack:stopAllActions()
  84. schedule(self.ui.Button_attack, function()
  85. global.Facade:sendNotification(global.NoticeTable.LaunchAttackSkill)
  86. end, 0.01)
  87. elseif eventType == 2 or eventType == 3 then
  88. self.ui.Button_attack:stopAllActions()
  89. end
  90. end)
  91. end
  92. function MainSkillLayout:AddSkill(data)
  93. local node = self._nodeCells[data.Key]
  94. -- skill
  95. local cell = self:CreateSkillCell(data)
  96. cell.layoutBG:removeFromParent()
  97. self._skillCells[data.MagicID] = cell
  98. node:addChild(cell.layoutBG)
  99. end
  100. function MainSkillLayout:RmvSkill(data, key)
  101. if not data.MagicID or not key then
  102. return false
  103. end
  104. local node = self._nodeCells[key]
  105. node:removeAllChildren()
  106. self._skillCells[data.MagicID] = nil
  107. -- cleanup select skill
  108. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  109. local selectSkill = SkillProxy:GetSelectSkill()
  110. if selectSkill and selectSkill == data.MagicID then
  111. SkillProxy:SelectSkill(nil)
  112. end
  113. end
  114. function MainSkillLayout:CleanupAllSkill()
  115. for _, v in pairs(self._nodeCells) do
  116. v:removeAllChildren()
  117. end
  118. self._skillCells = {}
  119. -- cleanup range skill
  120. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  121. SkillProxy:SelectSkill(nil)
  122. end
  123. function MainSkillLayout:CreateSkillCell(data)
  124. local root = cc.Node:create()
  125. if MainSkill and MainSkill.createSkillCell then
  126. local cell = MainSkill.createSkillCell(root,data)
  127. return cell
  128. end
  129. end
  130. function MainSkillLayout:CreateHeroSkillCell(parent,data)
  131. if MainSkill and MainSkill.createHeroSkillCell then
  132. local cell = MainSkill.createHeroSkillCell(parent, data)
  133. return cell
  134. end
  135. end
  136. function MainSkillLayout:OnHeroSkillInit()
  137. local HeroSkillProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroSkillProxy)
  138. local heroSkill = HeroSkillProxy:haveHeroSkill()
  139. if not heroSkill then
  140. return nil
  141. end
  142. local data = {}
  143. data.MagicID = heroSkill
  144. self:OnHeroSkillAdd(data)
  145. end
  146. function MainSkillLayout:OnHeroSkillAdd(data)
  147. local HeroSkillProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroSkillProxy)
  148. local isHeroSkill = HeroSkillProxy:isHeroSkill(data.MagicID)
  149. if not isHeroSkill then
  150. return nil
  151. end
  152. if self._heroSkillCell then
  153. return
  154. end
  155. -- skill
  156. local cell = self:CreateHeroSkillCell(self.ui.Node_hj_skill,data)
  157. self._heroSkillCell = cell
  158. end
  159. function MainSkillLayout:OnHeroSkillDel(data)
  160. local HeroSkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  161. self._heroSkillCell = nil
  162. self.ui.Node_hj_skill:removeAllChildren()
  163. end
  164. function MainSkillLayout:HeroJointEffect(canuse)
  165. if self._heroSkillCell then
  166. local HeroPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  167. self._heroSkillCell.nodeSFX:setVisible(canuse)
  168. if canuse then
  169. Shader_Normal(self._heroSkillCell.buttonIcon)
  170. else
  171. Shader_Grey(self._heroSkillCell.buttonIcon)
  172. end
  173. end
  174. end
  175. function MainSkillLayout:click_HeroSkill(tips)
  176. local HeroSkillProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroSkillProxy)
  177. local heroSkill = HeroSkillProxy:haveHeroSkill()
  178. if not heroSkill then
  179. if tips then
  180. ShowSystemTips("当前没有英雄技能")
  181. end
  182. return nil
  183. end
  184. local HeroPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  185. if HeroPropertyProxy:getShan() then--在闪的时候才能放合击
  186. HeroPropertyProxy:ReqJointAttack()--请求合击
  187. end
  188. end
  189. function MainSkillLayout:UpdateExtraVisible()
  190. local HeroSkillProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroSkillProxy)
  191. local HeroPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  192. if HeroPropertyProxy:HeroIsLogin() then
  193. self.ui.Node_hj_skill:setVisible(true)
  194. else
  195. self.ui.Node_hj_skill:setVisible(false)
  196. end
  197. end
  198. function MainSkillLayout:ClickSkillEvent(sender, skillID)
  199. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  200. -- 开关技能
  201. if SkillProxy:IsOnoffSkill(skillID) then
  202. SkillProxy:RequestSkillOnoff(skillID)
  203. return nil
  204. end
  205. -- 输入坐标技能
  206. if SkillProxy:IsInputDestSkill(skillID) then
  207. -- reset last select
  208. local lastSelect = SkillProxy:GetSelectSkill()
  209. if lastSelect then
  210. local cell = self._skillCells[lastSelect]
  211. if cell then
  212. cell.nodeSelect:removeAllChildren()
  213. end
  214. SkillProxy:SelectSkill(nil)
  215. if skillID == lastSelect then
  216. return nil
  217. end
  218. end
  219. -- select
  220. SkillProxy:SelectSkill(skillID)
  221. local cell = self._skillCells[skillID]
  222. if cell then
  223. local key = SkillProxy:GetSkillKey(skillID)
  224. local sfx = global.FrameAnimManager:CreateSFXAnim(4005)
  225. cell.nodeSelect:addChild(sfx)
  226. sfx:SetGlobalElapseEnable(true)
  227. sfx:Play(0, 0, true)
  228. sfx:setScale(key == 1 and 0.9 or 0.6)
  229. end
  230. return nil
  231. end
  232. -- 普通释放技能
  233. self:LaunchSkill({skillID = skillID})
  234. end
  235. function MainSkillLayout:LaunchSkill(data)
  236. local skillID = data.skillID
  237. if skillID == 0 and self._comboSkillID then
  238. skillID = self._comboSkillID
  239. self._comboSkillID = nil
  240. end
  241. local PlayerInputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  242. if skillID == 0 and PlayerInputProxy:CheckMiningAble() then
  243. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  244. local destPos = cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY())
  245. global.Facade:sendNotification(global.NoticeTable.UserInputMining, {dest=destPos})
  246. else
  247. global.Facade:sendNotification(global.NoticeTable.UserInputLaunch, {skillID = skillID, priority = global.MMO.LAUNCH_PRIORITY_USER})
  248. end
  249. end
  250. function MainSkillLayout:ClickComboSkillEvent(skillID)
  251. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  252. if skillID and skillID ~= 0 then
  253. -- 开关技能
  254. if SkillProxy:IsOnoffSkill(skillID) then
  255. SkillProxy:RequestSkillOnoff(skillID, true)
  256. self._comboSkillID = skillID
  257. return nil
  258. end
  259. -- 普通释放技能
  260. self:LaunchSkill({skillID = skillID})
  261. end
  262. end
  263. function MainSkillLayout:OnSkillAdd(data)
  264. -- 没有快捷键
  265. if (not data.Key) or (data.Key == 0) then
  266. return false
  267. end
  268. -- 已存在
  269. if self._skillCells[data.MagicID] then
  270. print("MAIN SKILL ADD ERROR: EXIST SKILL. ID: " .. data.MagicID)
  271. return false
  272. end
  273. self:AddSkill(data)
  274. end
  275. function MainSkillLayout:OnSkillDel(data)
  276. -- 没有快捷键
  277. if (not data.Key) or (data.Key == 0) then
  278. return false
  279. end
  280. -- 不存在
  281. if not self._skillCells[data.MagicID] then
  282. return false
  283. end
  284. self:RmvSkill(data, data.Key)
  285. end
  286. function MainSkillLayout:OnSkillSkillUpdate(data)
  287. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  288. -- 没有快捷键
  289. if (not data.Key) or (data.Key == 0) then
  290. return false
  291. end
  292. -- 不存在
  293. if not self._skillCells[data.MagicID] then
  294. return false
  295. end
  296. local skillCell = self._skillCells[data.MagicID]
  297. local iconPath = SkillProxy:GetIconPathByID(data.MagicID)
  298. skillCell.buttonIcon:loadTextureNormal(iconPath)
  299. end
  300. function MainSkillLayout:OnSkillChangeKey(data)
  301. local last = data.last
  302. local skill = data.skill
  303. -- remove
  304. self:OnSkillDel(last)
  305. -- add
  306. self:OnSkillAdd(skill)
  307. end
  308. function MainSkillLayout:OnSkillDeleteKey(data)
  309. -- 没有快捷键
  310. if (not data.delKey) or (data.delKey == 0) then
  311. return false
  312. end
  313. -- 不存在
  314. if not self._skillCells[data.skill.MagicID] then
  315. return false
  316. end
  317. self:RmvSkill(data.skill, data.delKey)
  318. end
  319. function MainSkillLayout:OnSkillCDTimeChange(data)
  320. local skillCell = self._skillCells[data.id]
  321. if skillCell then
  322. skillCell.progressCD:setVisible(data.percent ~= 0)
  323. skillCell.progressCD:setPercentage(data.percent)
  324. skillCell.CDTime:setString(data.percent ~= 0 and string.format("%.1f", data.time) or "")
  325. end
  326. end
  327. function MainSkillLayout:OnSkillOn(data)
  328. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  329. local cell = self._skillCells[data.skillID]
  330. if cell then
  331. local key = SkillProxy:GetSkillKey(data.skillID)
  332. local sfx = global.FrameAnimManager:CreateSFXAnim(4005)
  333. cell.nodeON:removeAllChildren()
  334. cell.nodeON:addChild(sfx)
  335. sfx:SetGlobalElapseEnable(true)
  336. sfx:Play(0, 0, true)
  337. sfx:setScale(key == 1 and 0.9 or 0.6)
  338. end
  339. end
  340. function MainSkillLayout:OnSkillOff(data)
  341. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  342. local cell = self._skillCells[data.skillID]
  343. if cell then
  344. cell.nodeON:removeAllChildren()
  345. end
  346. end
  347. function MainSkillLayout:OnClearSelectSkill(skillID)
  348. if not skillID then
  349. return false
  350. end
  351. local cell = self._skillCells[skillID]
  352. if cell then
  353. cell.nodeSelect:removeAllChildren()
  354. end
  355. end
  356. function MainSkillLayout:OnPlayerEquipChange()
  357. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  358. local skillData = SkillProxy:GetSkillByKey(1)
  359. local skillCell = self._skillCells[0]
  360. if skillCell and skillData then
  361. local buttonIcon = skillCell.buttonIcon
  362. local path = SkillProxy:GetIconPathByID(skillData.MagicID)
  363. buttonIcon:loadTextureNormal(path)
  364. end
  365. end
  366. function MainSkillLayout:OnGuideEnterTransition(data)
  367. if data.extent then
  368. MainSkill.ChangeShowIndex(MainSkill._showIndex == 1 and 2 or 1)
  369. else
  370. if data.name == "GUIDE_BEGIN_SKILL_BUTTON" then
  371. MainSkill.ChangeShowIndex(2)
  372. elseif data.name == "GUIDE_BEGIN_SKILL_CHANGE_BUTTON" then
  373. MainSkill.ChangeShowIndex(1)
  374. end
  375. end
  376. end
  377. function MainSkillLayout:IsSkillPanelShow( ... )
  378. return MainSkill._showIndex == 1
  379. end
  380. return MainSkillLayout