| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- import {
- _decorator,
- sp,
- Color,
- Component,
- director,
- find,
- Font,
- Label,
- log,
- Node,
- Sprite,
- SpriteFrame,
- TangentWeightMode,
- tween,
- UIOpacity,
- v2,
- v3,
- Vec2,
- Vec3,
- Prefab,
- instantiate,
- math,
- Button,
- assetManager,
- error,
- UITransform,
- EditBox,
- JsonAsset
- } from 'cc';
- import {LoadUtils} from './utils/LoadUtils';
- import {ArrUtils} from './utils/ArrUtils';
- import {AudioManage} from './AudioManage';
- import {StayData} from './StayData';
- import {BgMusicMgr} from './BgMusicMgr';
- import {NumUtils} from './utils/NumUtils';
- import {NodeUtils} from './utils/NodeUtils';
- import {HttpUtils} from './utils/HttpUtils';
- import {UserInfo} from './UserInfo';
- const {ccclass, property} = _decorator;
- @ccclass('GameMgr')
- export class GameMgr extends Component {
- // @property(JsonAsset)
- // private configFile: JsonAsset = null
- // private configData:any = null
- private progressWidth: number = 0
- protected onLoad(): void {
- // this.configData = this.configFile.json;
- // console.log(this.configData.gameSettings.playerSpeed);
- this.progressWidth = this.node.getChildByName("progress").getChildByName("PMask").getComponent(UITransform).width
- this.node.getChildByName("progress").getChildByName("PMask").getComponent(UITransform).width = 0
- this.node.getChildByName("progress").active = false
- // this.node.getChildByName("tipBg").active = false
- // this.node.getChildByName("tipBg").getComponent(UIOpacity).opacity = 0
- // this.node.getChildByName("tipBg").getChildByName("EditBox1").getComponent(EditBox).placeholder = ""
- // this.node.getChildByName("tipBg").getChildByName("btnStart").off("click")
- // this.node.getChildByName("tipBg").getChildByName("btnStart").on("click", (event) => {
- // // this.loadTest()
- // this.checkUserInput()
- // }, this)
- // director.addPersistRootNode(this.node.getChildByName("staticNode"))
- }
- start() {
- this.initGame()
- }
- //初始化游戏
- private initGame() {
- const sourceCode = this.getParameterByName("view")
- const phone = this.getParameterByName("phone")
- const hospitalId = this.getParameterByName("hospitalId")
- const hospitalName = this.getParameterByName("hospitalName")
- UserInfo.phone = phone
- UserInfo.sourceCode = sourceCode
- UserInfo.hospitalId = hospitalId
- UserInfo.hospitalName = hospitalName
- // console.log("url param: "+JSON.stringify(UserInfo.phone));
- this.loadTest()
- }
- private async aloadBundle(name: string): Promise<void> {
- return new Promise((resolve, reject) => {
- assetManager.loadBundle("name", (error, bundle) => {
- if (error) {
- reject(error)
- } else {
- resolve()
- }
- })
- })
- }
- /**
- * async await Promise应用的例子
- */
- private async checkUserInput() {
- const nameStr = this.node.getChildByName("tipBg").getChildByName("EditBox1").getComponent(EditBox).string
- const phoneStr = this.node.getChildByName("tipBg").getChildByName("EditBox2").getComponent(EditBox).string
- let f1: boolean = true
- let f2: boolean = true
- if (null == nameStr || "" == nameStr) {
- this.node.getChildByName("tipBg").getChildByName("EditBox1").getComponent(EditBox).placeholder = "姓名不能为空"
- NodeUtils.shakeNode(this.node.getChildByName("tipBg").getChildByName("EditBox1"), () => {
- }, 0.1)
- f1 = false
- }
- if (null == phoneStr || "" == phoneStr) {
- this.node.getChildByName("tipBg").getChildByName("EditBox2").getComponent(EditBox).placeholder = "手机号码不能为空"
- NodeUtils.shakeNode(this.node.getChildByName("tipBg").getChildByName("EditBox2"), () => {
- }, 0.1)
- f2 = false
- } else if (phoneStr.length != 11) {
- this.node.getChildByName("tipBg").getChildByName("EditBox2").getComponent(EditBox).string = ""
- this.node.getChildByName("tipBg").getChildByName("EditBox2").getComponent(EditBox).placeholder = "手机号码不正确"
- NodeUtils.shakeNode(this.node.getChildByName("tipBg").getChildByName("EditBox2"), () => {
- }, 0.1)
- f2 = false
- }
- if (f1 && f2) {
- //HttpUtils.sendHttpReq()返回一个Promise,使用await解开pormiss获取里面的数据
- // const aa = await HttpUtils.sendHttpReq()
- }
- }
- /**
- * 加载测试
- */
- private loadTest() {
- // this.node.getChildByName("tipBg").active = false
- this.node.getChildByName("progress").active = true
- assetManager.loadBundle("distance", (error, bundle) => {
- // bundle.loadDir("/", (completed: number, total: number) => {
- // // console.log("0000000= " + (completed / total));
- // this.node.getChildByName("progress").getChildByName("PMask").getComponent(UITransform).width = this.progressWidth * (completed / total)
- // }, (error) => {
- // if (!error) {
- this.node.getChildByName("progress").getChildByName("PMask").getComponent(UITransform).width = 1200
- this.scheduleOnce(function () {
- director.loadScene("sc_distance")
- }, 0.3);
- // }
- // })
- })
- }
- private cardAnimi(cardNo: number = 0) {
- this.node.getChildByName("progress").active = true
- assetManager.loadBundle("distance", (error, bundle) => {
- bundle.loadDir("/", (completed: number, total: number) => {
- }, (error) => {
- })
- })
- }
- update(deltaTime: number) {
- }
- /**
- * 读取浏览器地址栏数据
- */
- private loadGame() {
- }
- //得到url参数值
- getParameterByName(name) {
- let param: string = window.location.href.substring(window.location.href.indexOf("?"), window.location.href.length)
- param = decodeURIComponent(param)
- let url = window.location.href.substring(0, window.location.href.indexOf("?")) + param;
- // console.log("00000000000= " + url);
- // let url = window.location.href
- name = name.replace(/[\[\]]/g, '\\$&');
- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
- results = regex.exec(url);
- if (!results) return null;
- if (!results[2]) return '';
- return decodeURIComponent(results[2].replace(/\+/g, ' '));
- }
- }
|