FDialogNone.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. import FqLogin from "../../../login/FqLogin";
  2. import { AudioMgr } from "../../../main/ViewManage";
  3. import { HttpStateType, ReveData } from "../../../util/CHttp";
  4. import FF from "../FF";
  5. import FMap from "../map/FMap";
  6. import FSprite from "../object/FSprite";
  7. import BaseEvent from "./base/BaseEvent";
  8. import WOneByone from "./map1/WOneByone";
  9. /**
  10. * 闲聊脚本
  11. */
  12. const { ccclass, property } = cc._decorator;
  13. @ccclass
  14. export default class FDialogNone extends BaseEvent {
  15. @property({
  16. displayName: '地图元素编号'
  17. })
  18. public mapGoodId: string = '23';
  19. @property(cc.Prefab)
  20. mMapDialog: cc.Prefab = null;
  21. @property({
  22. displayName: '对话内容',
  23. type: [cc.String]
  24. })
  25. text: Array<string> = [];
  26. @property({
  27. displayName: '完成后的对话',
  28. type: [cc.String]
  29. })
  30. finish: Array<string> = [];//完成后的对话
  31. @property({
  32. displayName: '靠近的提示',
  33. type: cc.Node
  34. })
  35. icon: cc.Node = null;
  36. @property({
  37. displayName: '提示图标',
  38. type: cc.SpriteFrame
  39. })
  40. mTipsIcon: cc.SpriteFrame = null;
  41. /**
  42. * 控制的栅栏
  43. */
  44. @property([cc.Node])
  45. mFenceTrigger: Array<cc.Node> = [];
  46. onLoad() {
  47. super.onLoad()
  48. if (this.icon) {
  49. this.icon.active = false;
  50. }
  51. }
  52. onBegin(tag: number) {
  53. if (tag == 1) {
  54. this.showOpt(this.mTipsIcon, () => {
  55. this.startDialog()
  56. })
  57. } else if (tag == 2) {
  58. if (this.icon) {
  59. this.icon.active = true;
  60. }
  61. }
  62. }
  63. onEnd(tag: number) {
  64. if (tag == 1) {
  65. this.closeOpt()
  66. } else if (tag == 2) {
  67. if (this.icon) {
  68. this.icon.active = false;
  69. }
  70. }
  71. }
  72. public startDialog() {
  73. if (this.icon) {
  74. this.icon.active = false;
  75. }
  76. if (this.mapGoodId == '') {
  77. this.showDialog1();
  78. } else {
  79. let ff = this.ff;
  80. let stage = ff.main.player.stage;
  81. if (stage.element.indexOf(this.mapGoodId) > 0) {
  82. this.showDialog2();
  83. } else {
  84. this.showDialog1();
  85. }
  86. }
  87. }
  88. public closeButton() {
  89. if (this.icon) {
  90. this.icon.active = false;
  91. }
  92. this.closeOpt()
  93. }
  94. private showDialog2() {
  95. this.ff.pauseSprite(true);
  96. this.ff.mBlockInputEvents.active = true;
  97. let dialogs = this.finish;
  98. let node = cc.instantiate(this.mMapDialog);
  99. node.group = 'map'
  100. node.zIndex = 9999;
  101. node.x = this.node.x;
  102. node.y = this.node.y + this.node.height;
  103. node.parent = this.ff.mMap.mSprites;
  104. let obo = node.getComponent(WOneByone);
  105. obo.dialogs = dialogs;
  106. obo.setCallback(() => {
  107. this.closeButton();
  108. node.destroy();
  109. this.ff.setBlockInputCallback(null);
  110. this.ff.pauseSprite(false);
  111. this.ff.mBlockInputEvents.active = false;
  112. this.openmFenceTrigger()
  113. });
  114. this.ff.setBlockInputCallback(() => {
  115. obo.jump();
  116. });
  117. obo._start();
  118. }
  119. private showDialog1() {
  120. this.ff.pauseSprite(true);
  121. this.ff.mBlockInputEvents.active = true;
  122. let dialogs = this.text;
  123. let node = cc.instantiate(this.mMapDialog);
  124. node.group = 'map'
  125. node.zIndex = 9999;
  126. node.x = this.node.x;
  127. node.y = this.node.y + this.node.height;
  128. node.parent = this.ff.mMap.mSprites;
  129. let obo = node.getComponent(WOneByone);
  130. obo.dialogs = dialogs;
  131. obo.setCallback(() => {
  132. this.closeButton();
  133. node.destroy();
  134. this.ff.setBlockInputCallback(null);
  135. this.ff.pauseSprite(false);
  136. this.ff.mBlockInputEvents.active = false;
  137. if (this.mapGoodId != "") {
  138. this.getMapObject(this.mapGoodId);
  139. }
  140. if (!this.finish.length) {
  141. this.openmFenceTrigger()
  142. }
  143. });
  144. this.ff.setBlockInputCallback(() => {
  145. obo.jump();
  146. });
  147. obo._start();
  148. }
  149. /**
  150. * 捡起地图上的物品
  151. * @param objectId
  152. */
  153. public getMapObject(objectId: string) {
  154. let msg = {
  155. objectId: objectId
  156. }
  157. let ff = this.ff;
  158. ff.main.gameHttp.sendJson('stage/v1/stageObject', msg, (state, reve: ReveData) => {
  159. if (state == HttpStateType.SUCCESS) {
  160. if (reve.retCode == 0) {
  161. let player = ff.main.player;
  162. let stage = player.stage;
  163. stage.element.push(objectId);
  164. ff.main.showReward(reve, () => {
  165. this.openmFenceTrigger()
  166. });
  167. } else {
  168. ff.main.showTips(reve.message);
  169. }
  170. } else {
  171. ff.main.showTips('网络异常');
  172. }
  173. });
  174. }
  175. public openmFenceTrigger() {
  176. if (this.mFenceTrigger.length <= 0) {
  177. return
  178. }
  179. this.pause()
  180. this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  181. cc.tween(this.node).sequence(
  182. cc.callFunc(() => {
  183. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  184. const element = this.mFenceTrigger[i];
  185. this.showFence(element, 'close');
  186. }
  187. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  188. }),
  189. cc.delayTime(1),
  190. cc.callFunc(() => {
  191. this.resume()
  192. FqLogin.commitEvent(this.node.name, '', '');
  193. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  194. const element = this.mFenceTrigger[i];
  195. element.active = false;
  196. }
  197. })
  198. ).start();
  199. })
  200. }
  201. private showFence(element, action) {
  202. let nodes = element.children;
  203. for (let i = 0; i < nodes.length; i++) {
  204. const element = nodes[i];
  205. let spine = element.getComponent(sp.Skeleton);
  206. if (spine) {
  207. spine.setAnimation(0, action, false);
  208. }
  209. }
  210. }
  211. }