Guide.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. import { _decorator, Component, Mask, Node, RichText, Size, Tween, tween, UIOpacity, UITransform, v3, Vec3 } from 'cc';
  2. import LocalizedLabel from '../i18n/LocalizedLabel';
  3. import { BlockController } from './Block/BlockController';
  4. import { BlocksAll, GridBoardData } from './Block/BlockData';
  5. import GlobalData from './GlobalData';
  6. import { GridBlockMgr } from './GridBlockMgr';
  7. import { LocalStorageMgr } from './LocalStorageMgr';
  8. import { TouchMgr } from './TouchMgr';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('Guide')
  11. export class Guide extends Component {
  12. /** 单例模式 */
  13. private static _ins: Guide;
  14. constructor() {
  15. super();
  16. Guide._ins = this;
  17. }
  18. public static get ins(): Guide {
  19. if (!Guide._ins) {
  20. Guide._ins = new Guide();
  21. }
  22. return Guide._ins;
  23. }
  24. newComerReward: any = null;
  25. @property(Mask)
  26. private mask: Mask = null;
  27. @property(Node)
  28. shade: Node = null;
  29. @property(UITransform)
  30. toucher: UITransform;
  31. @property(UITransform)
  32. private pointer: UITransform = null;
  33. @property(Node)
  34. block: Node = null;
  35. @property(Node)
  36. diolog: Node = null;
  37. @property(RichText)
  38. diologLabel: RichText = null
  39. guideindex1: number[] = [3, 3];
  40. guideindex2: number[] = [3, 3];
  41. guideindex3: number[] = [4, 3];
  42. @property(Node)
  43. guidenode: Node = null;
  44. guideTarPos: Vec3 = null;
  45. @property(Node)
  46. selecnode: Node = null;
  47. selecOriPos: Vec3 = null;
  48. // @property(Node)
  49. // uiGuideNode1: Node = null;
  50. // uiGuideNodePos1: Vec3 = null;
  51. // @property(Node)
  52. // uiGuideNode2: Node = null;
  53. // uiGuideNodePos2: Vec3 = null;
  54. // @property(Node)
  55. // uiGuideNode3: Node = null;
  56. // uiGuideNodePos3: Vec3 = null;
  57. @property(Node)
  58. PopPage: Node = null;
  59. boardeffectTimes: number = 1;
  60. protected start(): void {
  61. // log(GlobalData.isCommer)
  62. if (GlobalData.isCommer) {
  63. this.runGuide();
  64. }
  65. }
  66. runGuide() {
  67. if (!GlobalData.isCommer) {
  68. this.node.active = false;
  69. return;
  70. }
  71. TouchMgr.ins.resumePromptBlock();
  72. // Tween.stopAll();
  73. Tween.stopAllByTarget(this.toucher.node);
  74. Tween.stopAllByTarget(this.block);
  75. // tween(this.toucher.node).stop()
  76. // tween(this.block).stop()
  77. this.guideTarPos = TouchMgr.ins.getNodeAToNodeBPoint(this.guidenode, this.node);
  78. this.selecOriPos = TouchMgr.ins.getNodeAToNodeBPoint(this.selecnode, this.node);
  79. // this.uiGuideNodePos1 = TouchMgr.ins.getNodeAToNodeBPoint(this.uiGuideNode1, this.node);
  80. // console.log(LocalStorageMgr.getItem(LocalStorageMgr.isCommer_key, true));
  81. // console.log(LocalStorageMgr.getItem(LocalStorageMgr.guideRecord_key, 1));
  82. if (GlobalData.guideRecord == 1) {
  83. GridBlockMgr.ins.generateBoard(GridBoardData.customizeBoardData1);
  84. GridBlockMgr.ins.generareGuideSelectionBlock([BlocksAll[45], BlocksAll[45], BlocksAll[45]]);
  85. this.guide1();
  86. } else if (GlobalData.guideRecord == 2) {
  87. GridBlockMgr.ins.generateBoard(GridBoardData.customizeBoardData2);
  88. GridBlockMgr.ins.generareGuideSelectionBlock([BlocksAll[10], BlocksAll[10], BlocksAll[10]]);
  89. this.guide2();
  90. } else if (GlobalData.guideRecord == 3) {
  91. GridBlockMgr.ins.generateBoard(GridBoardData.customizeBoardData3);
  92. GridBlockMgr.ins.generareGuideSelectionBlock([BlocksAll[11], BlocksAll[11], BlocksAll[11]]);
  93. this.guide3();
  94. } else if (GlobalData.guideRecord == 4) {
  95. this.guide4();
  96. }
  97. }
  98. //第一步引导
  99. guide1() {
  100. this.toucher.node.active = true
  101. this.diolog.active = true;
  102. this.diolog.setPosition(v3(0, 500, 0));
  103. this.diologLabel.string = '<color=#855933>拖动方块,填满整行可进行消除</color>';
  104. // let localizedLabel = this.diologLabel.node.getComponent(LocalizedLabel);
  105. // localizedLabel.setTextKeyAndOption("guide_Rtext_1");
  106. this.block.active = true;
  107. this.block.setPosition(this.selecOriPos);
  108. this.toucher.node.setPosition(this.selecOriPos.add(v3(100, -60, 0)));
  109. this.block.getComponent(BlockController).updateBlockSet(false, BlocksAll[45], 150);
  110. this.block.getComponent(BlockController).addBlockOffset(2);
  111. this.pointer.node.setPosition(v3(0, 0, 0))
  112. tween(this.toucher.node)
  113. .delay(0.2)
  114. .by(1, { position: v3(0, this.guideTarPos.y - this.selecOriPos.y, 0) })
  115. .delay(0.2)
  116. .by(0.01, { position: v3(0, -(this.guideTarPos.y - this.selecOriPos.y), 0) })
  117. .union()
  118. .repeatForever()
  119. .start()
  120. tween(this.block)
  121. .delay(0.2)
  122. .by(1, { position: v3(0, this.guideTarPos.y - this.selecOriPos.y, 0) })
  123. .delay(0.2)
  124. .by(0.01, { position: v3(0, -(this.guideTarPos.y - this.selecOriPos.y), 0) })
  125. .union()
  126. .repeatForever()
  127. .start()
  128. }
  129. guide2() {
  130. //这只是展示手指移动
  131. this.toucher.node.active = true
  132. this.diolog.active = true;
  133. this.diolog.setPosition(v3(0, 500, 0));
  134. this.diologLabel.string = '<color=#855933>点击方块可旋转90°,不限次数哦</color>';
  135. this.block.active = true;
  136. this.block.setPosition(this.selecOriPos);
  137. this.toucher.node.setPosition(this.selecOriPos.add(v3(100, -60, 0)));
  138. this.block.getComponent(BlockController).updateBlockSet(false, BlocksAll[7], 150);
  139. this.block.getComponent(BlockController).addBlockOffset(2);
  140. this.pointer.node.setPosition(v3(0, 0, 0))
  141. // this.guideTarPos.add3f(0, -55, 0);
  142. tween(this.toucher.node)
  143. .delay(0.2)
  144. .by(1, { position: v3(0, this.guideTarPos.y - this.selecOriPos.y - 55, 0) })
  145. .delay(0.2)
  146. .by(0.01, { position: v3(0, -(this.guideTarPos.y - this.selecOriPos.y) + 55, 0) })
  147. .union()
  148. .repeatForever()
  149. .start()
  150. tween(this.block)
  151. .delay(0.2)
  152. .by(1, { position: v3(0, this.guideTarPos.y - this.selecOriPos.y - 55, 0) })
  153. .delay(0.2)
  154. .by(0.01, { position: v3(0, -(this.guideTarPos.y - this.selecOriPos.y) + 55, 0) })
  155. .union()
  156. .repeatForever()
  157. .start()
  158. }
  159. guide3() {
  160. this.toucher.node.active = true
  161. this.diolog.active = true;
  162. this.diolog.setPosition(v3(0, 500, 0));
  163. this.diologLabel.string = '<color=#855933>当行与列同时被砖块填满,会一起消除</color>';
  164. this.block.active = true;
  165. this.block.setPosition(this.selecOriPos);
  166. this.toucher.node.setPosition(this.selecOriPos.add(v3(100, -60, 0)));
  167. this.block.getComponent(BlockController).updateBlockSet(false, BlocksAll[11], 150);
  168. this.block.getComponent(BlockController).addBlockOffset(2);
  169. this.pointer.node.setPosition(v3(0, 0, 0))
  170. tween(this.toucher.node)
  171. .delay(0.2)
  172. .by(1, { position: v3(0, this.guideTarPos.y - this.selecOriPos.y - 55, 0) })
  173. .delay(0.2)
  174. .by(0.01, { position: v3(0, -(this.guideTarPos.y - this.selecOriPos.y) + 55, 0) })
  175. .union()
  176. .repeatForever()
  177. .start()
  178. tween(this.block)
  179. .delay(0.2)
  180. .by(1, { position: v3(0, this.guideTarPos.y - this.selecOriPos.y - 55, 0) })
  181. .delay(0.2)
  182. .by(0.01, { position: v3(0, -(this.guideTarPos.y - this.selecOriPos.y) + 55, 0) })
  183. .union()
  184. .repeatForever()
  185. .start()
  186. }
  187. async guide4() {
  188. GridBlockMgr.ins.generateBoard_effect(GridBoardData.customizeBoardData4);
  189. this.scheduleOnce(() => {
  190. GridBlockMgr.ins.generateSelectionBlock(false, [BlocksAll[15], BlocksAll[2], BlocksAll[15]])
  191. }, 1);
  192. this.node.active = true;
  193. this.block.active = false;
  194. this.toucher.node.active = false
  195. this.diolog.active = true;
  196. this.diolog.setPosition(v3(0, 0, 0));
  197. this.diolog.getComponent(UIOpacity).opacity = 0;
  198. tween(this.diolog.getComponent(UIOpacity))
  199. .to(0.5, { opacity: 255 })
  200. .delay(2)
  201. .to(0.5, { opacity: 0 })
  202. .call(() => {
  203. this.node.active = false;
  204. })
  205. .start()
  206. }
  207. completeCurGuide(record) {
  208. GlobalData.guideRecord = record;
  209. LocalStorageMgr.setItem(LocalStorageMgr.guideRecord_key, GlobalData.guideRecord);
  210. this.runGuide();
  211. if (GlobalData.guideRecord >= 5) {
  212. GlobalData.isCommer = false;
  213. LocalStorageMgr.setItem(LocalStorageMgr.isCommer_key, GlobalData.isCommer);
  214. }
  215. }
  216. }