| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- cc.Class({
- extends: cc.Component,
- properties: {
- VC:{
- default :null,
- type :cc.Node
- },
- DialogBG:{
- default :null,
- type :cc.Node
- },
- DialogName:{
- default :null,
- type :cc.Node
- },
- DialogConversation:{
- default :null,
- type :cc.Node
- },
- Conversations : {
- default :[],
- type : [cc.String]
- },
- //contract
- ContractBG: {
- default :null,
- type :cc.Node
- },
- ContractConfirmBTN: {
- default :null,
- type :cc.Node
- },
- ContractCancelBTN: {
- default :null,
- type :cc.Node
- },
- CompanyNameEditbox: {
- default :null,
- type :cc.Node
- },
- CEONameEditbox: {
- default :null,
- type :cc.Node
- },
- },
- onLoad() {
- this.EnableTouch = false;
- this.DialogIndex = 0;
- this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
- //cc.log("TOUCH_START event=", event.type);
- if(this.EnableTouch == false)return;
- this.EnableTouch = false;
- if(this.DialogIndex == this.Conversations.length)
- {
- this.ShowContact();
- return;
- }
- var DialogConversationLabel = this.DialogConversation.getComponent(cc.Label);
- this.TypingAni(DialogConversationLabel,this.Conversations[this.DialogIndex],this.TypingFinished);
- this.DialogIndex++;
- }.bind(this));
- },
- start () {
- return;
- this.ShowDialog();
- //start game animation
- this.ShakeCamera(function(){
- this.ShowVC();
- }.bind(this));
- },
- ShowDialog:function()
- {
- //Show UI
- this.DialogBG.active = true;
- this.DialogName.active = true;
- this.DialogConversation.active = true;
- //set Conversation
- var DialogConversationLabel = this.DialogConversation.getComponent(cc.Label);
- DialogConversationLabel.string = this.Conversations[this.DialogIndex];
- this.DialogIndex++;
- },
- ShakeCamera:function(ACallBack)
- {
- //shake camera animation
- var RotateToRight = cc.rotateTo(0.1,3);
- var RotateToLeft = cc.rotateTo(0.1,-3);
- var SequenceAnim = cc.sequence(RotateToRight,RotateToLeft);
- var RepeatAction = cc.repeat(SequenceAnim,6);
- //call functuion
- var CallF = cc.callFunc(function(){
- this.node.runAction(cc.rotateTo(0.1,0));
- this.EnableTouch = true;
- ACallBack();
- }.bind(this));
- //do animation
- var ShakeAnim = cc.sequence(RepeatAction,CallF);
- this.node.runAction(ShakeAnim);
- },
- ShowVC:function()
- {
- this.VC.active = true;
- this.VC.opacity = 0;
- var ShowVCAnim = cc.fadeIn(1);
- this.VC.runAction(ShowVCAnim);
- },
- TypingAni: function (Label, Text, Callback) {
- var CurrentText = '';
- var Arr = Text.split('');
- var Len = Arr.length;
- var Step = 0;
- this.Func = function () {
- CurrentText += Arr[Step];
- Label.string = CurrentText;
- Step++;
- if (Step == Len) {
- this.unschedule(this.Func);
- Callback(this);
- }
- };
- this.schedule(this.Func,0.05, cc.macro.REPEAT_FOREVER, 0)
- },
- TypingFinished(Self){
- //cc.log('TypingFinished');
- Self.EnableTouch = true;
- },
- ShowContact:function () {
- // hide others
- this.VC.active = false;
- this.DialogName.active = false;
- this.DialogConversation.active = false;
- // show contract
- this.ContractBG.active = true;
- this.ContractConfirmBTN.active = true;
- this.ContractCancelBTN.active = true;
- this.CompanyNameEditbox.active = true;
- this.CEONameEditbox.active = true;
- }
- });
|