UiController.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. // Learn cc.Class:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/class.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. //const StatesManage = require("StatesManage");
  8. cc.Class({
  9. extends: require("BaseUiConstroller"),
  10. properties: {
  11. interfacaArr: { //界面列表
  12. default: [],
  13. type: cc.Node,
  14. },
  15. passArr: { //
  16. type: cc.Prefab,
  17. default: [],
  18. },
  19. audioArr: { //音频
  20. type: cc.AudioClip,
  21. default: [],
  22. },
  23. Column_Right_Grid: cc.Node,
  24. },
  25. // LIFE-CYCLE CALLBACKS:
  26. onLoad() {
  27. this.bg1 = cc.find("Canvas/Panel_Botton/Btn_Activity/Bg_1");
  28. this.bg2 = cc.find("Canvas/Panel_Botton/Btn_Game/Bg_2");
  29. this.bg3 = cc.find("Canvas/Panel_Botton/Btn_Role/Bg_3");
  30. this.Btn_Activity = cc.find("Canvas/Panel_Botton/Btn_Activity");
  31. this.Btn_Game = cc.find("Canvas/Panel_Botton/Btn_Game");
  32. this.Btn_Role = cc.find("Canvas/Panel_Botton/Btn_Role");
  33. this.game = cc.find("Canvas/Game");
  34. this.Interface_Node = cc.find("Canvas/Interface_Node");
  35. this.Panel_Botton = cc.find("Canvas/Panel_Botton");
  36. this.back_btn = cc.find("Canvas/UiController/Btn_Back");
  37. this.Interface_PassArr = cc.find("Canvas/Interface_PassArr");
  38. this.role_headArr = cc.find("Canvas/Interface_Against/Panel_Middle/Bg/PassNode").children;
  39. var self = this;
  40. cc.loader.loadRes("prefab/Items/Grid", (err, prefab) => {
  41. for (let i = 0; i < 30; i++) {
  42. self.Column_Right_Grid.addChild(cc.instantiate(prefab));
  43. }
  44. });
  45. },
  46. start() {
  47. this.init();
  48. this.Role_Head_Event();
  49. this.interface_info = cc.find("Canvas/Interface_Info").getComponent('Interface_Info');
  50. },
  51. Role_Head_Event() {
  52. this.role_headArr.forEach(element => {
  53. element.on(cc.Node.EventType.TOUCH_START, () => {
  54. cc.audioEngine.playEffect(this.audioArr[0]);
  55. console.log("触摸头像");
  56. //打开全部关卡界面
  57. this.Interface_PassArr.active = true;
  58. });
  59. });
  60. },
  61. update(dt) {
  62. this.role_headArr.forEach(element => {
  63. element.active = false;
  64. });
  65. this.role_headArr[this.GameState._currPass].active = true;
  66. },
  67. Bottonbtn_Touch(event) {
  68. cc.audioEngine.playEffect(this.audioArr[0]);
  69. this.Interface_Node.removeAllChildren();
  70. if (event.target.name == "Btn_Activity") {
  71. this.bg1.active = true;
  72. this.bg2.active = false;
  73. this.bg3.active = false;
  74. this.Btn_Activity.setScale(1);
  75. this.Btn_Game.setScale(0.8);
  76. this.Btn_Role.setScale(0.8);
  77. this.interfacaArr[0].active = false;
  78. this.interfacaArr[1].active = false;
  79. cc.resources.load("prefab/Interface/Interface_Activitys", (err, prefab) => {
  80. var interfaceactivity = cc.instantiate(prefab);
  81. this.Interface_Node.addChild(interfaceactivity);
  82. });
  83. }
  84. if (event.target.name == "Btn_Game") {
  85. this.bg1.active = false;
  86. this.bg2.active = true;
  87. this.bg3.active = false;
  88. this.Btn_Activity.setScale(0.8);
  89. this.Btn_Game.setScale(1);
  90. this.Btn_Role.setScale(0.8);
  91. this.change_interface(this.interfacaArr, 0);
  92. this.game.removeAllChildren();
  93. this.Interface_Node.removeAllChildren();
  94. }
  95. if (event.target.name == "Btn_Role") {
  96. this.bg1.active = false;
  97. this.bg2.active = false;
  98. this.bg3.active = true;
  99. this.Btn_Activity.setScale(0.8);
  100. this.Btn_Game.setScale(0.8);
  101. this.Btn_Role.setScale(1);
  102. this.change_interface(this.interfacaArr, 1);
  103. this.Interface_Node.removeAllChildren();
  104. }
  105. if (event.target.name == "Btn_Back") {
  106. this.game.removeAllChildren();
  107. this.Panel_Botton.active = true;
  108. this.change_interface(this.interfacaArr, 0);
  109. this.back_btn.active = false;
  110. this.GameMode._gamestart = false;
  111. }
  112. if (event.target.name == "Btn_Back_Pass") {
  113. this.change_interface(this.interfacaArr, 0);
  114. this.Interface_PassArr.active = false;
  115. }
  116. },
  117. //触发按钮 关卡
  118. btn_Touch(event) {
  119. cc.audioEngine.playEffect(this.audioArr[0]);
  120. this.game.removeAllChildren();
  121. this.Interface_Node.removeAllChildren();
  122. this.interfacaArr[0].active = false;
  123. this.interfacaArr[1].active = false;
  124. if (event.target.name == "Btn_Against") {
  125. this.Panel_Botton.active = false;
  126. //this.GameState._currPass = 0;
  127. this.game.addChild(cc.instantiate(this.passArr[this.GameState._currPass]));
  128. // var self = this;
  129. // cc.resources.loadDir("prefab/Pass", (err, prefabs) => {
  130. // var interfacegame = cc.instantiate(prefabs[]);
  131. // self.game.addChild(interfacegame);
  132. // });
  133. }
  134. // this.game.addChild(StatesManage.Game_Pass[this.GameState._currPass]);
  135. //var self = this;
  136. //
  137. // cc.loader.loadRes("prefab/Pass", (err, prefabs) => {
  138. // console.log("关卡:", self.GameState._currPass);
  139. // var interfacegame = cc.instantiate(prefabs[self.GameState._currPass]);
  140. // self.game.addChild(interfacegame);
  141. // });
  142. },
  143. init() {
  144. //角色脚本
  145. this.GameState = cc.find("GameStates").getComponent("GameStates");
  146. this.GameMode = cc.find("GameMode").getComponent("GameMode");
  147. // this.controScp = this.playerController.getComponent('PlayerController');
  148. // this.charactortroScp = this.Charactor.getComponent('Charactor');
  149. this.font_Arr = cc.find("Canvas/UiController/Ui_caution").children;
  150. this.change_interface(this.interfacaArr, 0);
  151. this.bg2.active = true;
  152. this.Btn_Activity.setScale(0.8);
  153. this.Btn_Game.setScale(1);
  154. this.Btn_Role.setScale(0.8);
  155. },
  156. actions() {
  157. let action1 = cc.scaleTo(0.8, 0.8, 0.8);
  158. let action2 = cc.scaleTo(1, 2, 2);
  159. this.ui_countdown(action1, action2);
  160. },
  161. ui_countdown(action, action2) {
  162. for (let i = 0; i < 3; i++) {
  163. this.scheduleOnce(function() {
  164. cc.audioEngine.playEffect(this.audioArr[6]);
  165. this.font_Arr[i].active = true;
  166. this.font_Arr[i].runAction(action);
  167. this.scheduleOnce(function() {
  168. this.font_Arr[i].active = false;
  169. this.font_Arr[i].setScale(2);
  170. }, 0.6);
  171. }, i + 1);
  172. }
  173. this.scheduleOnce(function() {
  174. this.font_Arr[3].active = true;
  175. this.font_Arr[3].runAction(action2);
  176. this.scheduleOnce(function() {
  177. this.font_Arr[3].active = false;
  178. this.back_btn.active = true;
  179. }, 0.8);
  180. cc.audioEngine.playEffect(this.audioArr[5]);
  181. this.GameMode._gamestart = true;
  182. }, 4);
  183. },
  184. Ui_Shake(node_index) {
  185. if (node_index == 1) { //左
  186. this.font_Arr[4].active = true;
  187. this.Shake(this.font_Arr[4], 2);
  188. cc.audioEngine.playEffect(this.audioArr[6]);
  189. this.scheduleOnce(function() {
  190. this.font_Arr[4].active = false;
  191. }, 0.5);
  192. }
  193. if (node_index == 2) { //右
  194. this.font_Arr[5].active = true;
  195. this.Shake(this.font_Arr[5], 2);
  196. cc.audioEngine.playEffect(this.audioArr[6]);
  197. this.scheduleOnce(function() {
  198. this.font_Arr[5].active = false;
  199. }, 0.5);
  200. }
  201. if (node_index == 3) { //红屏
  202. this.font_Arr[8].active = true;
  203. this.scheduleOnce(function() {
  204. this.font_Arr[8].active = false;
  205. }, 0.5);
  206. }
  207. if (node_index == 4) { //血量不足
  208. this.font_Arr[7].active = true;
  209. this.scheduleOnce(function() {
  210. this.font_Arr[7].active = false;
  211. }, 0.5);
  212. }
  213. if (node_index == 5) { //能量不足
  214. this.font_Arr[6].active = true;
  215. this.scheduleOnce(function() {
  216. this.font_Arr[6].active = false;
  217. }, 0.5);
  218. }
  219. },
  220. Shake(node_shake, index) {
  221. let x = node_shake.x;
  222. let y = node_shake.y;
  223. let offset = 10;
  224. if (index == 0) {
  225. let action = cc.repeatForever(
  226. cc.sequence(
  227. // cc.moveTo(0.018, cc.v2(x + (5 + offset), y + (offset + 7))),
  228. // cc.moveTo(0.018, cc.v2(x - (6 + offset), y + (offset + 7))),
  229. // cc.moveTo(0.018, cc.v2(x - (13 + offset), y + (offset + 3))),
  230. // cc.moveTo(0.018, cc.v2(x + (3 + offset), y - (6 + offset))),
  231. // cc.moveTo(0.018, cc.v2(x - (5 + offset), y + (offset + 5))),
  232. cc.moveTo(0.018, cc.v2(x + (2 + offset), y - (8 + offset))),
  233. cc.moveTo(0.018, cc.v2(x - (8 + offset), y - (10 + offset))),
  234. cc.moveTo(0.018, cc.v2(x + (3 + offset), y + (offset + 10))),
  235. cc.moveTo(0.018, cc.v2(x + (0 + offset), y + (offset + 0)))
  236. )
  237. )
  238. node_shake.runAction(action);
  239. setTimeout(() => {
  240. node_shake.stopAction(action);
  241. node_shake.x = x;
  242. node_shake.y = y;
  243. }, 1000);
  244. } else if (index == 1) {
  245. let action = cc.repeatForever(
  246. cc.sequence(
  247. cc.moveTo(0.018, cc.v2(x + (5 + offset), y + (offset + 7))),
  248. cc.moveTo(0.018, cc.v2(x - (6 + offset), y + (offset + 7))),
  249. cc.moveTo(0.018, cc.v2(x - (13 + offset), y + (offset + 3))),
  250. cc.moveTo(0.018, cc.v2(x + (3 + offset), y - (6 + offset))),
  251. )
  252. )
  253. node_shake.runAction(action);
  254. setTimeout(() => {
  255. node_shake.stopAction(action);
  256. node_shake.x = x;
  257. node_shake.y = y;
  258. }, 1000);
  259. } else if (index == 2) {
  260. let action = cc.repeatForever(
  261. cc.sequence(
  262. cc.moveTo(0.018, cc.v2(x + offset, y + offset)),
  263. cc.moveTo(0.018, cc.v2(x - offset, y + offset)),
  264. cc.moveTo(0.018, cc.v2(x - offset, y + offset)),
  265. cc.moveTo(0.018, cc.v2(x + offset, y - offset)),
  266. cc.moveTo(0.018, cc.v2(x - offset, y + offset)),
  267. )
  268. )
  269. node_shake.runAction(action);
  270. setTimeout(() => {
  271. node_shake.stopAction(action);
  272. node_shake.x = x;
  273. node_shake.y = y;
  274. }, 1000);
  275. }
  276. },
  277. });