| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- cc.Class({
- extends: cc.Component,
- properties: {
- GameStates: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameConfig: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameTalent: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameMakeUp: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameEloquence: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameFashion: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameDance: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- },
- OnActive()
- {
- //Game Logic
- this.GameConfigScript = this.GameConfig.getComponent('GameConfig');
- this.GameStatesScript = this.GameStates.getComponent('GameStates');
- //Talent
- this.TalentStartCourseBtn = this.GameTalent.getChildByName('UnlockBtn').getChildByName('StartCourseBtn');
- this.TalentFinishBtn = this.GameTalent.getChildByName('UnlockBtn').getChildByName('FinishBtn');
- this.TalentTotalTimeLabel = this.GameTalent.getChildByName('Panel').getChildByName('TotalTimeLabel');
- this.TalentTotalTimeScript = this.GameTalent.getChildByName('Panel').getChildByName('TotalTimeLabel').getComponent('ChangeTimeAndProgressBar');
- this.TalentTotalTimeLabel.getComponent(cc.Label).string = this.CastSecondsToHours(this.GameConfigScript.TalentTotalTime);
- this.TalentProgressBar = this.GameTalent.getChildByName('Panel').getChildByName('ProgressBar');
- this.TalentFinishCourseFrame = this.GameTalent.getChildByName('Panel').getChildByName('GameFinishCourseFrame');
- //MakeUp
- this.MakeUpStartCourseBtn = this.GameMakeUp.getChildByName('UnlockBtn').getChildByName('StartCourseBtn');
- this.MakeUpFinishBtn = this.GameMakeUp.getChildByName('UnlockBtn').getChildByName('FinishBtn');
- this.MakeUpTotalTimeLabel = this.GameMakeUp.getChildByName('Panel').getChildByName('TotalTimeLabel');
- this.MakeUpTotalTimeScript = this.GameMakeUp.getChildByName('Panel').getChildByName('TotalTimeLabel').getComponent('ChangeTimeAndProgressBar');
- this.MakeUpTotalTimeLabel.getComponent(cc.Label).string = this.CastSecondsToHours(this.GameConfigScript.MakeUpTotalTime);
- this.MakeUpProgressBar = this.GameMakeUp.getChildByName('Panel').getChildByName('ProgressBar');
- this.MakeUpFinishCourseFrame = this.GameMakeUp.getChildByName('Panel').getChildByName('GameFinishCourseFrame');
- //GameEloquence
- this.EloquenceStartCourseBtn = this.GameEloquence.getChildByName('UnlockBtn').getChildByName('StartCourseBtn');
- this.EloquenceFinishBtn = this.GameEloquence.getChildByName('UnlockBtn').getChildByName('FinishBtn');
- this.EloquenceTotalTimeLabel = this.GameEloquence.getChildByName('Panel').getChildByName('TotalTimeLabel');
- this.EloquenceTotalTimeScript = this.GameEloquence.getChildByName('Panel').getChildByName('TotalTimeLabel').getComponent('ChangeTimeAndProgressBar');
- this.EloquenceTotalTimeLabel.getComponent(cc.Label).string = this.CastSecondsToHours(this.GameConfigScript.EloquenceTotalTime);
- this.EloquenceProgressBar = this.GameEloquence.getChildByName('Panel').getChildByName('ProgressBar');
- this.EloquenceFinishCourseFrame = this.GameEloquence.getChildByName('Panel').getChildByName('GameFinishCourseFrame');
- // Fashion
- this.FashionStartCourseBtn = this.GameFashion.getChildByName('UnlockBtn').getChildByName('StartCourseBtn');
- this.FashionFinishBtn = this.GameFashion.getChildByName('UnlockBtn').getChildByName('FinishBtn');
- this.FashionTotalTimeLabel = this.GameFashion.getChildByName('Panel').getChildByName('TotalTimeLabel');
- this.FashionTotalTimeScript = this.GameFashion.getChildByName('Panel').getChildByName('TotalTimeLabel').getComponent('ChangeTimeAndProgressBar');
- this.FashionTotalTimeLabel.getComponent(cc.Label).string = this.CastSecondsToHours(this.GameConfigScript.FashionTotalTime);
- this.FashionProgressBar = this.GameFashion.getChildByName('Panel').getChildByName('ProgressBar');
- this.FashionFinishCourseFrame = this.GameFashion.getChildByName('Panel').getChildByName('GameFinishCourseFrame');
- // Dance
- this.DanceStartCourseBtn = this.GameDance.getChildByName('UnlockBtn').getChildByName('StartCourseBtn');
- this.DanceFinishBtn = this.GameDance.getChildByName('UnlockBtn').getChildByName('FinishBtn');
- this.DanceTotalTimeLabel = this.GameDance.getChildByName('Panel').getChildByName('TotalTimeLabel');
- this.DanceTotalTimeScript = this.GameDance.getChildByName('Panel').getChildByName('TotalTimeLabel').getComponent('ChangeTimeAndProgressBar');
- this.DanceTotalTimeLabel.getComponent(cc.Label).string = this.CastSecondsToHours(this.GameConfigScript.DanceTotalTime);
- this.DanceProgressBar = this.GameDance.getChildByName('Panel').getChildByName('ProgressBar');
- this.DanceFinishCourseFrame = this.GameDance.getChildByName('Panel').getChildByName('GameFinishCourseFrame');
- this.GetRemainTime(function () {
- // Talent
- if( this.GameStatesScript.TalentRemainTime>0)
- {
- this.TalentFinishBtn.active=true;
- this.TalentFinishBtn.getComponent(cc.Button).interactable = false;
- this.TalentStartCourseBtn.active = false;
- this.ShowProgressBar('Talent');
- }
- else
- {
- if(this.GameStatesScript.BTalentFinished)
- {
- this.TalentFinishBtn.active=false;
- this.TalentStartCourseBtn.active = true;
- }
- else {
- this.TalentFinishBtn.active=true;
- this.TalentFinishBtn.getComponent(cc.Button).interactable = true;
- this.TalentStartCourseBtn.active = false;
- this.TalentFinishCourseFrame.active=true;
- }
- }
- // MakeUp
- if( this.GameStatesScript.MakeUpRemainTime>0)
- {
- this.MakeUpFinishBtn.active=true;
- this.MakeUpFinishBtn.getComponent(cc.Button).interactable = false;
- this.MakeUpStartCourseBtn.active = false;
- this.ShowProgressBar('MakeUp');
- }
- else
- {
- if(this.GameStatesScript.BMakeUpFinished)
- {
- this.MakeUpFinishBtn.active=false;
- this.MakeUpStartCourseBtn.active = true;
- }
- else {
- this.MakeUpFinishBtn.active=true;
- this.MakeUpFinishBtn.getComponent(cc.Button).interactable = true;
- this.MakeUpStartCourseBtn.active = false;
- this.MakeUpFinishCourseFrame.active=true;
- }
- }
- // Eloquence
- if( this.GameStatesScript.EloquenceRemainTime>0)
- {
- this.EloquenceFinishBtn.active=true;
- this.EloquenceFinishBtn.getComponent(cc.Button).interactable = false;
- this.EloquenceStartCourseBtn.active = false;
- this.ShowProgressBar('Eloquence');
- }
- else
- {
- if(this.GameStatesScript.BEloquenceFinished)
- {
- this.EloquenceFinishBtn.active=false;
- this.EloquenceStartCourseBtn.active = true;
- }
- else {
- this.EloquenceFinishBtn.active=true;
- this.EloquenceFinishBtn.getComponent(cc.Button).interactable = true;
- this.EloquenceStartCourseBtn.active = false;
- this.EloquenceFinishCourseFrame.active=true;
- }
- }
- // Fashion
- if( this.GameStatesScript.FashionRemainTime>0)
- {
- this.FashionFinishBtn.active=true;
- this.FashionFinishBtn.getComponent(cc.Button).interactable = false;
- this.FashionStartCourseBtn.active = false;
- this.ShowProgressBar('Fashion');
- }
- else
- {
- if(this.GameStatesScript.BFashionFinished)
- {
- this.FashionFinishBtn.active=false;
- this.FashionStartCourseBtn.active = true;
- }
- else {
- this.FashionFinishBtn.active=true;
- this.FashionFinishBtn.getComponent(cc.Button).interactable = true;
- this.FashionStartCourseBtn.active = false;
- this.FashionFinishCourseFrame.active=true;
- }
- }
- // Dance
- if( this.GameStatesScript.DanceRemainTime>0)
- {
- this.EloquenceFinishBtn.active=true;
- this.EloquenceFinishBtn.getComponent(cc.Button).interactable = false;
- this.EloquenceStartCourseBtn.active = false;
- this.ShowProgressBar('Eloquence');
- }
- else
- {
- if(this.GameStatesScript.BEloquenceFinished)
- {
- this.EloquenceFinishBtn.active=false;
- this.EloquenceStartCourseBtn.active = true;
- }
- else {
- this.EloquenceFinishBtn.active=true;
- this.EloquenceFinishBtn.getComponent(cc.Button).interactable = true;
- this.EloquenceStartCourseBtn.active = false;
- this.EloquenceFinishCourseFrame.active=true;
- }
- }
- // Fashion
- // Dance
- }.bind(this));
- },
- GetRemainTime(CallBack)
- {
- let URL = this.GameConfigScript.Host+'GameCourse/GetCourseRemainTime?Openid='+ cc.sys.localStorage.getItem('Openid');
- let XHR = new XMLHttpRequest();
- XHR.onreadystatechange = function () {
- if (XHR.readyState == 4 && (XHR.status >= 200 && XHR.status < 400)) {
- let response = XHR.responseText;
- // console.log(response);
- let ResultJson = JSON.parse(response);
- this.GameStatesScript.TalentRemainTime = ResultJson.TalentRemainTime;
- this.GameStatesScript.BTalentFinished = ResultJson.BTalentFinished;
- this.GameStatesScript.MakeUpRemainTime = ResultJson.MakeUpRemainTime;
- this.GameStatesScript.BMakeUpFinished = ResultJson.BMakeUpFinished;
- this.GameStatesScript.EloquenceRemainTime = ResultJson.EloquenceRemainTime;
- this.GameStatesScript.BEloquenceFinished = ResultJson.BEloquenceFinished;
- // Fashion
- this.GameStatesScript.FashionRemainTime = ResultJson.FashionRemainTime;
- this.GameStatesScript.BFashionFinished = ResultJson.BFashionFinished;
- // Dance
- this.GameStatesScript.DanceRemainTime = ResultJson.DanceRemainTime;
- this.GameStatesScript.BDanceFinished = ResultJson.BDanceFinished;
- CallBack();
- }
- }.bind(this);
- XHR.open("GET", URL, true);
- XHR.setRequestHeader("Content-Type" , "application/json");
- XHR.send();
- },
- OnStarCourse(event, customEventData)
- {
- let CourseName = customEventData;
- let Data = 'Openid='+ cc.sys.localStorage.getItem('Openid');
- let URL = this.GameConfigScript.Host+'GameCourse/Start'+CourseName+'Course/';
- let XHR = new XMLHttpRequest();
- XHR.onreadystatechange = function ()
- {
- if (XHR.readyState == 4 && (XHR.status >= 200 && XHR.status < 400))
- {
- let response = XHR.responseText;
- console.log(response);
- if(CourseName == 'Talent')
- {
- this.TalentStartCourseBtn.active = false;
- this.TalentFinishBtn.active = true;
- }
- else if(CourseName == 'MakeUp')
- {
- this.MakeUpStartCourseBtn.active = false;
- this.MakeUpFinishBtn.active = true;
- }
- else if(CourseName == 'Eloquence')
- {
- this.EloquenceStartCourseBtn.active = false;
- this.EloquenceFinishBtn.active = true;
- }
- else if(CourseName == 'Fashion')
- {
- this.FashionStartCourseBtn.active = false;
- this.FashionFinishBtn.active = true;
- }
- else if(CourseName == 'Dance')
- {
- this.DanceStartCourseBtn.active = false;
- this.DanceFinishBtn.active = true;
- }
- this.UpdateGameStates(response);
- this.GetRemainTime(function () {
- this.ShowProgressBar(CourseName);
- }.bind(this));
- }
- }.bind(this);
- XHR.open("POST", URL, false);
- XHR.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
- XHR.send(Data);
- },
- ShowProgressBar(CourseName)
- {
- let CourseScript = null;
- let TotalTime = 0;
- let RemainTime = 0;
- if(CourseName=='Talent')
- {
- this.TalentProgressBar.active = true;
- CourseScript = this.TalentTotalTimeScript;
- TotalTime= this.GameConfigScript.TalentTotalTime;
- RemainTime = this.GameStatesScript.TalentRemainTime;
- }
- else if(CourseName=='MakeUp')
- {
- this.MakeUpProgressBar.active = true;
- CourseScript = this.MakeUpTotalTimeScript;
- TotalTime= this.GameConfigScript.MakeUpTotalTime;
- RemainTime = this.GameStatesScript.MakeUpRemainTime;
- }
- else if(CourseName=='Eloquence')
- {
- this.EloquenceProgressBar.active = true;
- CourseScript = this.EloquenceTotalTimeScript;
- TotalTime= this.GameConfigScript.EloquenceTotalTime;
- RemainTime = this.GameStatesScript.EloquenceRemainTime;
- }
- else if(CourseName=='Fashion')
- {
- this.FashionProgressBar.active = true;
- CourseScript = this.FashionTotalTimeScript;
- TotalTime= this.GameConfigScript.FashionTotalTime;
- RemainTime = this.GameStatesScript.FashionRemainTime;
- }
- else if(CourseName=='Dance')
- {
- this.DanceProgressBar.active = true;
- CourseScript = this.DanceTotalTimeScript;
- TotalTime= this.GameConfigScript.DanceTotalTime;
- RemainTime = this.GameStatesScript.DanceRemainTime;
- }
- // 重复次数
- let Repeat = cc.REPEAT_FOREVER;
- // 以秒为单位的时间间隔
- let Interval = 1;
- // 开始延时
- let Delay = 0.01;
- let Index = Math.floor(RemainTime);
- let StartCourseSchedule = function()
- {
- Index--;
- CourseScript.SetProgressBar(Index,TotalTime);
- if(0==Index)
- {
- this.FinishCourse(CourseName);
- this.unschedule(StartCourseSchedule);
- }
- }.bind(this);
- this.schedule(StartCourseSchedule, Interval, Repeat-1, Delay);
- },
- FinishCourse(CourseName)
- {
- // console.log(CourseName)
- if(CourseName=='Talent')
- {
- this.TalentFinishBtn.getComponent(cc.Button).interactable = true;
- this.TalentProgressBar.active = false;
- this.TalentTotalTimeLabel.getComponent(cc.Label).string = this.CastSecondsToHours(this.GameConfigScript.TalentTotalTime);
- this.TalentFinishCourseFrame.active=true;
- }
- else if(CourseName=='MakeUp')
- {
- this.MakeUpFinishBtn.getComponent(cc.Button).interactable = true;
- this.MakeUpProgressBar.active = false;
- this.MakeUpTotalTimeLabel.getComponent(cc.Label).string = this.CastSecondsToHours(this.GameConfigScript.MakeUpTotalTime);
- this.MakeUpFinishCourseFrame.active=true;
- }
- else if(CourseName=='Eloquence')
- {
- this.EloquenceFinishBtn.getComponent(cc.Button).interactable = true;
- this.EloquenceProgressBar.active = false;
- this.EloquenceTotalTimeLabel.getComponent(cc.Label).string = this.CastSecondsToHours(this.GameConfigScript.EloquenceTotalTime);
- this.EloquenceFinishCourseFrame.active=true;
- }
- else if(CourseName=='Fashion')
- {
- this.FashionFinishBtn.getComponent(cc.Button).interactable = true;
- this.FashionProgressBar.active = false;
- this.FashionTotalTimeLabel.getComponent(cc.Label).string = this.CastSecondsToHours(this.GameConfigScript.FashionTotalTime);
- this.FashionFinishCourseFrame.active=true;
- }
- else if(CourseName=='Dance')
- {
- this.DanceFinishBtn.getComponent(cc.Button).interactable = true;
- this.DanceProgressBar.active = false;
- this.DanceTotalTimeLabel.getComponent(cc.Label).string = this.CastSecondsToHours(this.GameConfigScript.DanceTotalTime);
- this.DanceFinishCourseFrame.active=true;
- }
- },
- OnCourseFinished(event, customEventData)
- {
- let CourseName = customEventData;
- if(CourseName=='Talent')
- {
- this.TalentFinishBtn.getComponent(cc.Button).interactable = false;
- this.TalentFinishBtn.active = false;
- this.TalentStartCourseBtn.active = true;
- this.TalentFinishCourseFrame.active=false;
- }
- else if(CourseName=='MakeUp')
- {
- this.MakeUpFinishBtn.getComponent(cc.Button).interactable = false;
- this.MakeUpFinishBtn.active = false;
- this.MakeUpStartCourseBtn.active = true;
- this.MakeUpFinishCourseFrame.active=false;
- }
- else if(CourseName=='Eloquence')
- {
- this.EloquenceFinishBtn.getComponent(cc.Button).interactable = false;
- this.EloquenceFinishBtn.active = false;
- this.EloquenceStartCourseBtn.active = true;
- this.EloquenceFinishCourseFrame.active=false;
- }
- else if(CourseName=='Fashion')
- {
- this.FashionFinishBtn.getComponent(cc.Button).interactable = false;
- this.FashionFinishBtn.active = false;
- this.FashionStartCourseBtn.active = true;
- this.FashionFinishCourseFrame.active=false;
- }
- else if(CourseName=='Dance')
- {
- this.DanceFinishBtn.getComponent(cc.Button).interactable = false;
- this.DanceFinishBtn.active = false;
- this.DanceStartCourseBtn.active = true;
- this.DanceFinishCourseFrame.active=false;
- }
- let Data = 'Openid='+ cc.sys.localStorage.getItem('Openid');
- let URL = this.GameConfigScript.Host+'GameCourse/Finish'+CourseName+'/';
- // console.log(URL)
- let XHR = new XMLHttpRequest();
- XHR.onreadystatechange = function ()
- {
- if (XHR.readyState == 4 && (XHR.status >= 200 && XHR.status < 400))
- {
- let response = XHR.responseText;
- this.UpdateGameStates(response);
- }
- }.bind(this);
- XHR.open("POST", URL, false);
- XHR.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
- XHR.send(Data);
- },
- UpdateGameStates(response)
- {
- let GameStates = JSON.parse(response);
- // console.log(ResultJson);
- // Game
- // let GameStates = ResultJson.GameConfig;
- // console.log(GameConfig);
- this.GameStatesScript.PlusActionPower(GameStates.ActionPower,false);
- this.GameStatesScript.PlusCoin(GameStates.Coin);
- this.GameStatesScript.PlusDiamond(GameStates.Diamond);
- this.GameStatesScript.PlusFans(GameStates.Fans);
- this.GameStatesScript.PlusFavorableImpression(GameStates.FavorableImpression);
- },
- CastSecondsToHours(Time)
- {
- if(Time<60) return Time+'秒';
- if(Time<3600 && Time >=60)
- {
- return Math.floor(Time/60)+'分'+Time%60+'秒';
- }
- if(Time>=3600)
- {
- let Hour = Math.floor(Time/3600);
- let s = Time%3600;
- let Min = Math.floor(s/60);
- return Hour+'小时'+Min+'分';
- }
- return Math.floor(Time/3600);
- }
- });
|