UIUpgradePanel.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. import UIPage from "../Framework/UIPage";
  2. import { PanelName } from "../Framework/Constant";
  3. import { cocosz } from "../Framework/CocosZ";
  4. import { utils } from "../../common-plugin/Scripts/Utils";
  5. import TweenEffect from "../Framework/TweenEffect";
  6. import { SkillType, upgradeMgr } from "../Game/UpgradeMgr";
  7. import PlatUtils from "../../common-plugin/Scripts/PlatUtils";
  8. import { gameMgr } from "../Game/gameMgr";
  9. const { ccclass, property } = cc._decorator;
  10. /**
  11. * 皮肤试用面板
  12. */
  13. @ccclass
  14. export default class UIUpgradePanel extends UIPage {
  15. private _mask: cc.Node = null;
  16. private _panel: cc.Node = null;
  17. private _skill0: cc.Node = null;
  18. private _skill1: cc.Node = null;
  19. private _skill2: cc.Node = null;
  20. private _skill3: cc.Node = null;
  21. private _skill4: cc.Node = null;
  22. private _btnRefresh: cc.Node = null;
  23. private _betterArr: number[] = [];
  24. private _otherArr: number[] = [];// 可以获取的技能数组
  25. private _uiSkillIdArr: number[] = [];// 随机4个技能
  26. private _curIndex: number = -1;// 当前选中下标
  27. private _canClick: boolean = true;// 能否点击
  28. private _lockArr: boolean[] = [false, false, false, false, false];
  29. constructor() {
  30. super(PanelName.UIUpgradePanel);
  31. this.isValid() && this.onLoad();
  32. }
  33. protected onLoad() {
  34. this._mask = this._page.getChildByName("Mask");
  35. this._panel = this._page.getChildByName("Panel");
  36. let btnNames: string[] = ["skill0", "skill1", "skill2", "skill3", "skill4", "btnRefresh"];
  37. for (let i = 0; i < btnNames.length; i++) {
  38. let btn: cc.Node = cc.find(btnNames[i], this._panel);
  39. if (btn) {
  40. btn.on(cc.Node.EventType.TOUCH_END, this._onBtnClickedHandler, this);
  41. if (btn.name == "skill0") {
  42. this._skill0 = btn;
  43. } else if (btn.name == "skill1") {
  44. this._skill1 = btn;
  45. } else if (btn.name == "skill2") {
  46. this._skill2 = btn;
  47. } else if (btn.name == "skill3") {
  48. this._skill3 = btn;
  49. } else if (btn.name == "skill4") {
  50. this._skill4 = btn;
  51. } else if (btn.name == "btnRefresh") {
  52. this._btnRefresh = btn;
  53. btn.active = cocosz.isADON;
  54. }
  55. }
  56. }
  57. // 服务器锁的数量
  58. let serverValue = cocosz.getConfigByKey("skillLockNum");
  59. if (Number.isInteger(serverValue)) {
  60. for (let i = 0; i < 5; i++) {
  61. if (i + serverValue >= 5) {
  62. this._lockArr[i] = true;
  63. } else {
  64. this._lockArr[i] = false;
  65. }
  66. }
  67. }
  68. }
  69. protected onOpen() {
  70. utils.SendEvent("页面-技能");
  71. // 优先技能数组
  72. let better = [
  73. SkillType.双发, SkillType.子弹碎片, SkillType.枪林弹雨, SkillType.谢幕,
  74. SkillType.瞬斩, SkillType.冰霜精通, SkillType.火焰精通, SkillType.萃取,
  75. SkillType.再生, SkillType.护甲靴子, SkillType.疾走, SkillType.神圣守护,
  76. SkillType.通灵匕首, SkillType.飞轮, SkillType.闪电, SkillType.燃烧瓶
  77. ];
  78. // 可以获取的技能数组
  79. for (let i = 0; i <= 34; i++) {
  80. if ([SkillType.雷电精通, SkillType.龙卵, SkillType.通灵镰刀].includes(i)) {
  81. // 剔除的技能
  82. } else if (upgradeMgr && upgradeMgr.isValid && upgradeMgr.upgradeSkillArr[i] >= upgradeMgr.upgradeSkillMaxLevelArr[i]) {
  83. // 达到最大级
  84. } else if (better.includes(i)) {
  85. // 优先数组
  86. this._betterArr.push(i);
  87. } else {
  88. // 其它数组
  89. this._otherArr.push(i);
  90. }
  91. }
  92. this._initPanel();
  93. if (PlatUtils.IsWechat) {
  94. utils.adManager.hideCustomAd({ location: 3 });
  95. utils.adManager.hideCustomAd({ location: 4 });
  96. }
  97. }
  98. protected onClose(): void {
  99. cocosz.pauseCount--;
  100. if (PlatUtils.IsWechat) {
  101. utils.adManager.showCustomAd({ location: 3 });
  102. utils.adManager.showCustomAd({ location: 4 });
  103. }
  104. }
  105. private _initPanel() {
  106. TweenEffect.panel_mask_opacity(this._mask)
  107. TweenEffect.panel_open_moveY(this._panel);
  108. this._curIndex = -1;
  109. // 刷新技能
  110. this._skill_refresh();
  111. }
  112. /**
  113. * 所有按钮点击事件
  114. * @param event
  115. * @param data
  116. */
  117. private async _onBtnClickedHandler(event: cc.Event, data: any) {
  118. //播放按钮点击音效
  119. await cocosz.audioMgr.playBtnEffect().catch();
  120. if (!this._canClick) return;
  121. switch (event.target.name) {
  122. case "btnRefresh": {
  123. this._canClick = false;
  124. // 分享
  125. if (event.target.getChildByName("share") && event.target.getChildByName("share").active) {
  126. utils.SendEvent("分享-刷新技能")
  127. cocosz.share(() => {
  128. utils.SendEvent("分享-刷新技能-成功")
  129. this._skill_refresh();
  130. this._canClick = true;
  131. }, () => {
  132. utils.SendEvent("分享-刷新技能-失败")
  133. this._canClick = true;
  134. })
  135. }
  136. // 视频
  137. else if (event.target.getChildByName("video") && event.target.getChildByName("video").active) {
  138. utils.SendEvent("视频-技能刷新(地下城僵尸)-播放")
  139. cocosz.watchAD(() => {
  140. utils.SendEvent("视频-技能刷新(地下城僵尸)-成功")
  141. this._skill_refresh();
  142. this._canClick = true;
  143. }, () => {
  144. utils.SendEvent("视频-技能刷新(地下城僵尸)-失败")
  145. this._canClick = true;
  146. });
  147. }
  148. break;
  149. }
  150. case "skill0":
  151. case "skill1":
  152. case "skill2":
  153. case "skill3":
  154. case "skill4": {
  155. this._canClick = false;
  156. let callback = () => {
  157. if ("skill0" == event.target.name)
  158. this._curIndex = 0;
  159. else if ("skill1" == event.target.name)
  160. this._curIndex = 1;
  161. else if ("skill2" == event.target.name)
  162. this._curIndex = 2;
  163. else if ("skill3" == event.target.name)
  164. this._curIndex = 3;
  165. else if ("skill4" == event.target.name)
  166. this._curIndex = 4;
  167. // 刷新
  168. this.updateFrame();
  169. // 选中技能
  170. this._selectSkill();
  171. }
  172. let lockNode = event.target.getChildByName("lock");
  173. if (lockNode && lockNode.active) {
  174. // 分享
  175. if (lockNode.getChildByName("share") && lockNode.getChildByName("share").active) {
  176. utils.SendEvent("分享-技能解锁")
  177. cocosz.share(() => {
  178. utils.SendEvent("分享-技能解锁-成功")
  179. callback && callback();
  180. }, () => {
  181. utils.SendEvent("分享-技能解锁-失败")
  182. this._canClick = true;
  183. })
  184. }
  185. // 视频
  186. else if (lockNode.getChildByName("video") && lockNode.getChildByName("video").active) {
  187. utils.SendEvent("视频-技能解锁-播放")
  188. cocosz.watchAD(() => {
  189. utils.SendEvent("视频-技能解锁-成功")
  190. callback && callback();
  191. }, () => {
  192. utils.SendEvent("视频-技能解锁-失败")
  193. this._canClick = true;
  194. });
  195. } else {
  196. callback && callback();
  197. }
  198. } else {
  199. callback && callback();
  200. }
  201. break;
  202. }
  203. }
  204. }
  205. private _selectSkill() {
  206. this._canClick = false;
  207. // 获取技能
  208. if (this._uiSkillIdArr[this._curIndex]) {
  209. upgradeMgr && upgradeMgr.isValid && upgradeMgr.getSkill(this._uiSkillIdArr[this._curIndex]);
  210. }
  211. // 卡片效果
  212. let arr: cc.Node[] = [this._skill0, this._skill1, this._skill2, this._skill3, this._skill4];
  213. arr.forEach((v, i) => {
  214. if (i == this._curIndex) {
  215. this.card_click(v);
  216. } else {
  217. this.card_recycle(v);
  218. }
  219. })
  220. // 关闭弹窗
  221. cocosz.scheduleOnce(() => {
  222. cocosz.uiMgr.closePanel(PanelName.UIUpgradePanel);
  223. if (gameMgr && gameMgr.playerTs && gameMgr.playerTs.isValid) {
  224. gameMgr.playerTs.avoidInjury(2);
  225. }
  226. }, 1.5);
  227. }
  228. private _getSkillIDName(id: number) {
  229. return id + (upgradeMgr.upgradeSkillMaxLevelArr[id] > 1 ? "_" + (upgradeMgr.upgradeSkillArr[id] + 1) : "")
  230. }
  231. private _skill_load(card: cc.Node, id) {
  232. // 名字
  233. let node_name = card.getChildByName("name");
  234. if (node_name) {
  235. let spr_name = node_name.getComponent(cc.Sprite);
  236. if (spr_name) {
  237. cocosz.resMgr.loadAndCacheRes("i18n/tex_zombie/" + cocosz.curLanguage + "/zombieSkill_name_" + this._getSkillIDName(id), cc.SpriteFrame, null, (err, res) => {
  238. if (spr_name && spr_name.isValid) {
  239. spr_name.spriteFrame = res;
  240. }
  241. });
  242. }
  243. }
  244. // 图标
  245. let node_icon = card.getChildByName("icon");
  246. if (node_icon) {
  247. let spr_icon = node_icon.getComponent(cc.Sprite);
  248. if (spr_icon) {
  249. cocosz.resMgr.loadAndCacheRes("tex_zombie/zombieSkill_icon_" + this._getSkillIDName(id), cc.SpriteFrame, null, (err, res) => {
  250. if (spr_icon && spr_icon.isValid) {
  251. spr_icon.spriteFrame = res;
  252. }
  253. });
  254. }
  255. }
  256. // 介绍
  257. let node_introduce = card.getChildByName("introduce");
  258. if (node_introduce) {
  259. let spr_introduce = node_introduce.getComponent(cc.Sprite);
  260. if (spr_introduce) {
  261. cocosz.resMgr.loadAndCacheRes("i18n/tex_zombie/" + cocosz.curLanguage + "/zombieSkill_introduce_" + this._getSkillIDName(id), cc.SpriteFrame, null, (err, res) => {
  262. if (spr_introduce && spr_introduce.isValid) {
  263. spr_introduce.spriteFrame = res;
  264. }
  265. });
  266. }
  267. }
  268. }
  269. /** 技能刷新 */
  270. private _skill_refresh() {
  271. this._uiSkillIdArr.length = 0;
  272. // 从技能数组中获取5个技能
  273. if (this._betterArr.length) {
  274. for (let i = Math.min(5 - this._uiSkillIdArr.length, this._betterArr.length); i > 0; i--) {
  275. let index = Math.floor(Math.random() * this._betterArr.length);
  276. if (this._betterArr[index] >= 0) {
  277. this._uiSkillIdArr.push(this._betterArr[index]);
  278. this._betterArr.splice(index, 1);
  279. }
  280. }
  281. }
  282. if (this._otherArr.length) {
  283. for (let i = Math.min(5 - this._uiSkillIdArr.length, this._otherArr.length); i > 0; i--) {
  284. let index = Math.floor(Math.random() * this._otherArr.length);
  285. if (this._otherArr[index] >= 0) {
  286. this._uiSkillIdArr.push(this._otherArr[index]);
  287. this._otherArr.splice(index, 1);
  288. }
  289. }
  290. }
  291. // 排序
  292. for (let i = 0; i < this._uiSkillIdArr.length; i++) {
  293. // 3级技能(非视频位置)
  294. if (upgradeMgr.upgradeSkillArr[this._uiSkillIdArr[i]] == 2 && !this._lockArr[i]) {
  295. // 与视频位置交换
  296. for (let j = this._uiSkillIdArr.length - 1; j > i; j--) {
  297. if (this._lockArr[j] && upgradeMgr.upgradeSkillArr[this._uiSkillIdArr[j]] != 2) {
  298. // 交换
  299. [this._uiSkillIdArr[i], this._uiSkillIdArr[j]] = [this._uiSkillIdArr[j], this._uiSkillIdArr[i]]
  300. }
  301. }
  302. }
  303. }
  304. // 技能0 ///////////////////////////////////////////////////////////////////////////////////////////////
  305. if (this._uiSkillIdArr[0] >= 0) {
  306. this._skill0.active = true;
  307. let id = this._uiSkillIdArr[0];
  308. this._skill_load(this._skill0, id);
  309. } else {
  310. this._skill0.active = false;
  311. }
  312. // 技能1 ///////////////////////////////////////////////////////////////////////////////////////////////
  313. if (this._uiSkillIdArr[1] >= 0) {
  314. this._skill1.active = true;
  315. let id = this._uiSkillIdArr[1];
  316. this._skill_load(this._skill1, id);
  317. } else {
  318. this._skill1.active = false;
  319. }
  320. // 技能2 ///////////////////////////////////////////////////////////////////////////////////////////////
  321. if (this._uiSkillIdArr[2] >= 0) {
  322. this._skill2.active = true;
  323. let id = this._uiSkillIdArr[2];
  324. this._skill_load(this._skill2, id);
  325. } else {
  326. this._skill2.active = false;
  327. }
  328. // 技能3 ///////////////////////////////////////////////////////////////////////////////////////////////
  329. if (this._uiSkillIdArr[3] >= 0) {
  330. this._skill3.active = true;
  331. let id = this._uiSkillIdArr[3];
  332. this._skill_load(this._skill3, id);
  333. } else {
  334. this._skill3.active = false;
  335. }
  336. // 技能4 ///////////////////////////////////////////////////////////////////////////////////////////////
  337. if (this._uiSkillIdArr[4] >= 0) {
  338. this._skill4.active = true;
  339. let id = this._uiSkillIdArr[4];
  340. this._skill_load(this._skill4, id);
  341. } else {
  342. this._skill4.active = false;
  343. }
  344. // 视频按钮隐藏
  345. if (this._otherArr.length == 0 && this._btnRefresh && this._btnRefresh.active) {
  346. this._btnRefresh.active = false;
  347. }
  348. this.updateFrame();
  349. }
  350. // 更新外发光
  351. updateFrame() {
  352. // 选中框
  353. this._skill0.children[0].active = (this._curIndex == 0);
  354. this._skill1.children[0].active = (this._curIndex == 1);
  355. this._skill2.children[0].active = (this._curIndex == 2);
  356. this._skill3.children[0].active = (this._curIndex == 3);
  357. this._skill4.children[0].active = (this._curIndex == 4);
  358. // 解锁框
  359. this._skill0.children[5].active = this._lockArr[0] && this._curIndex != 0;
  360. this._skill1.children[5].active = this._lockArr[1] && this._curIndex != 1;
  361. this._skill2.children[5].active = this._lockArr[2] && this._curIndex != 2;
  362. this._skill3.children[5].active = this._lockArr[3] && this._curIndex != 3;
  363. this._skill4.children[5].active = this._lockArr[4] && this._curIndex != 4;
  364. }
  365. /** 卡牌选中特效 */
  366. card_click(card: cc.Node) {
  367. card.zIndex = cc.macro.MAX_ZINDEX;
  368. cc.tween(card)
  369. .to(0.5, { x: 0, y: 200 }, { easing: "sineIn" })
  370. .to(1, { scale: 2, opacity: 0 }, { easing: "fade" })
  371. .start();
  372. }
  373. /** 卡牌回收 */
  374. card_recycle(card: cc.Node) {
  375. let btnUnLock = card.getChildByName("btnUnLock")
  376. if (btnUnLock) btnUnLock.active = false;
  377. cc.tween(card)
  378. .to(0.5, { opacity: 0 }, { easing: "sineIn" })
  379. .start();
  380. }
  381. }