GameMgr.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import {
  2. _decorator,
  3. sp,
  4. Color,
  5. Component,
  6. director,
  7. find,
  8. Font,
  9. Label,
  10. log,
  11. Node,
  12. Sprite,
  13. SpriteFrame,
  14. TangentWeightMode,
  15. tween,
  16. UIOpacity,
  17. v2,
  18. v3,
  19. Vec2,
  20. Vec3,
  21. Prefab,
  22. instantiate,
  23. math,
  24. Button,
  25. assetManager,
  26. error,
  27. UITransform,
  28. EditBox,
  29. JsonAsset
  30. } from 'cc';
  31. import {LoadUtils} from './utils/LoadUtils';
  32. import {ArrUtils} from './utils/ArrUtils';
  33. import {AudioManage} from './AudioManage';
  34. import {StayData} from './StayData';
  35. import {BgMusicMgr} from './BgMusicMgr';
  36. import {NumUtils} from './utils/NumUtils';
  37. import {NodeUtils} from './utils/NodeUtils';
  38. import {HttpUtils} from './utils/HttpUtils';
  39. import {UserInfo} from './UserInfo';
  40. const {ccclass, property} = _decorator;
  41. @ccclass('GameMgr')
  42. export class GameMgr extends Component {
  43. // @property(JsonAsset)
  44. // private configFile: JsonAsset = null
  45. // private configData:any = null
  46. private progressWidth: number = 0
  47. protected onLoad(): void {
  48. // this.configData = this.configFile.json;
  49. // console.log(this.configData.gameSettings.playerSpeed);
  50. this.progressWidth = this.node.getChildByName("progress").getChildByName("PMask").getComponent(UITransform).width
  51. this.node.getChildByName("progress").getChildByName("PMask").getComponent(UITransform).width = 0
  52. this.node.getChildByName("progress").active = false
  53. // this.node.getChildByName("tipBg").active = false
  54. // this.node.getChildByName("tipBg").getComponent(UIOpacity).opacity = 0
  55. // this.node.getChildByName("tipBg").getChildByName("EditBox1").getComponent(EditBox).placeholder = ""
  56. // this.node.getChildByName("tipBg").getChildByName("btnStart").off("click")
  57. // this.node.getChildByName("tipBg").getChildByName("btnStart").on("click", (event) => {
  58. // // this.loadTest()
  59. // this.checkUserInput()
  60. // }, this)
  61. // director.addPersistRootNode(this.node.getChildByName("staticNode"))
  62. }
  63. start() {
  64. this.initGame()
  65. }
  66. //初始化游戏
  67. private initGame() {
  68. const sourceCode = this.getParameterByName("view")
  69. const phone = this.getParameterByName("phone")
  70. const hospitalId = this.getParameterByName("hospitalId")
  71. const hospitalName = this.getParameterByName("hospitalName")
  72. UserInfo.phone = phone
  73. UserInfo.sourceCode = sourceCode
  74. UserInfo.hospitalId = hospitalId
  75. UserInfo.hospitalName = hospitalName
  76. // console.log("url param: "+JSON.stringify(UserInfo.phone));
  77. this.loadTest()
  78. }
  79. private async aloadBundle(name: string): Promise<void> {
  80. return new Promise((resolve, reject) => {
  81. assetManager.loadBundle("name", (error, bundle) => {
  82. if (error) {
  83. reject(error)
  84. } else {
  85. resolve()
  86. }
  87. })
  88. })
  89. }
  90. /**
  91. * async await Promise应用的例子
  92. */
  93. private async checkUserInput() {
  94. const nameStr = this.node.getChildByName("tipBg").getChildByName("EditBox1").getComponent(EditBox).string
  95. const phoneStr = this.node.getChildByName("tipBg").getChildByName("EditBox2").getComponent(EditBox).string
  96. let f1: boolean = true
  97. let f2: boolean = true
  98. if (null == nameStr || "" == nameStr) {
  99. this.node.getChildByName("tipBg").getChildByName("EditBox1").getComponent(EditBox).placeholder = "姓名不能为空"
  100. NodeUtils.shakeNode(this.node.getChildByName("tipBg").getChildByName("EditBox1"), () => {
  101. }, 0.1)
  102. f1 = false
  103. }
  104. if (null == phoneStr || "" == phoneStr) {
  105. this.node.getChildByName("tipBg").getChildByName("EditBox2").getComponent(EditBox).placeholder = "手机号码不能为空"
  106. NodeUtils.shakeNode(this.node.getChildByName("tipBg").getChildByName("EditBox2"), () => {
  107. }, 0.1)
  108. f2 = false
  109. } else if (phoneStr.length != 11) {
  110. this.node.getChildByName("tipBg").getChildByName("EditBox2").getComponent(EditBox).string = ""
  111. this.node.getChildByName("tipBg").getChildByName("EditBox2").getComponent(EditBox).placeholder = "手机号码不正确"
  112. NodeUtils.shakeNode(this.node.getChildByName("tipBg").getChildByName("EditBox2"), () => {
  113. }, 0.1)
  114. f2 = false
  115. }
  116. if (f1 && f2) {
  117. //HttpUtils.sendHttpReq()返回一个Promise,使用await解开pormiss获取里面的数据
  118. // const aa = await HttpUtils.sendHttpReq()
  119. }
  120. }
  121. /**
  122. * 加载测试
  123. */
  124. private loadTest() {
  125. // this.node.getChildByName("tipBg").active = false
  126. this.node.getChildByName("progress").active = true
  127. assetManager.loadBundle("distance", (error, bundle) => {
  128. // bundle.loadDir("/", (completed: number, total: number) => {
  129. // // console.log("0000000= " + (completed / total));
  130. // this.node.getChildByName("progress").getChildByName("PMask").getComponent(UITransform).width = this.progressWidth * (completed / total)
  131. // }, (error) => {
  132. // if (!error) {
  133. this.node.getChildByName("progress").getChildByName("PMask").getComponent(UITransform).width = 1200
  134. this.scheduleOnce(function () {
  135. director.loadScene("sc_distance")
  136. }, 0.3);
  137. // }
  138. // })
  139. })
  140. }
  141. private cardAnimi(cardNo: number = 0) {
  142. this.node.getChildByName("progress").active = true
  143. assetManager.loadBundle("distance", (error, bundle) => {
  144. bundle.loadDir("/", (completed: number, total: number) => {
  145. }, (error) => {
  146. })
  147. })
  148. }
  149. update(deltaTime: number) {
  150. }
  151. /**
  152. * 读取浏览器地址栏数据
  153. */
  154. private loadGame() {
  155. }
  156. //得到url参数值
  157. getParameterByName(name) {
  158. let param: string = window.location.href.substring(window.location.href.indexOf("?"), window.location.href.length)
  159. param = decodeURIComponent(param)
  160. let url = window.location.href.substring(0, window.location.href.indexOf("?")) + param;
  161. // console.log("00000000000= " + url);
  162. // let url = window.location.href
  163. name = name.replace(/[\[\]]/g, '\\$&');
  164. let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
  165. results = regex.exec(url);
  166. if (!results) return null;
  167. if (!results[2]) return '';
  168. return decodeURIComponent(results[2].replace(/\+/g, ' '));
  169. }
  170. }