Dialog.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. VC:{
  5. default :null,
  6. type :cc.Node
  7. },
  8. DialogBG:{
  9. default :null,
  10. type :cc.Node
  11. },
  12. DialogName:{
  13. default :null,
  14. type :cc.Node
  15. },
  16. DialogConversation:{
  17. default :null,
  18. type :cc.Node
  19. },
  20. Conversations : {
  21. default :[],
  22. type : [cc.String]
  23. },
  24. //contract
  25. ContractBG: {
  26. default :null,
  27. type :cc.Node
  28. },
  29. ContractConfirmBTN: {
  30. default :null,
  31. type :cc.Node
  32. },
  33. ContractCancelBTN: {
  34. default :null,
  35. type :cc.Node
  36. },
  37. CompanyNameEditbox: {
  38. default :null,
  39. type :cc.Node
  40. },
  41. CEONameEditbox: {
  42. default :null,
  43. type :cc.Node
  44. },
  45. },
  46. onLoad() {
  47. this.EnableTouch = false;
  48. this.DialogIndex = 0;
  49. this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
  50. //cc.log("TOUCH_START event=", event.type);
  51. if(this.EnableTouch == false)return;
  52. this.EnableTouch = false;
  53. if(this.DialogIndex == this.Conversations.length)
  54. {
  55. this.ShowContact();
  56. return;
  57. }
  58. var DialogConversationLabel = this.DialogConversation.getComponent(cc.Label);
  59. this.TypingAni(DialogConversationLabel,this.Conversations[this.DialogIndex],this.TypingFinished);
  60. this.DialogIndex++;
  61. }.bind(this));
  62. },
  63. start () {
  64. return;
  65. this.ShowDialog();
  66. //start game animation
  67. this.ShakeCamera(function(){
  68. this.ShowVC();
  69. }.bind(this));
  70. },
  71. ShowDialog:function()
  72. {
  73. //Show UI
  74. this.DialogBG.active = true;
  75. this.DialogName.active = true;
  76. this.DialogConversation.active = true;
  77. //set Conversation
  78. var DialogConversationLabel = this.DialogConversation.getComponent(cc.Label);
  79. DialogConversationLabel.string = this.Conversations[this.DialogIndex];
  80. this.DialogIndex++;
  81. },
  82. ShakeCamera:function(ACallBack)
  83. {
  84. //shake camera animation
  85. var RotateToRight = cc.rotateTo(0.1,3);
  86. var RotateToLeft = cc.rotateTo(0.1,-3);
  87. var SequenceAnim = cc.sequence(RotateToRight,RotateToLeft);
  88. var RepeatAction = cc.repeat(SequenceAnim,6);
  89. //call functuion
  90. var CallF = cc.callFunc(function(){
  91. this.node.runAction(cc.rotateTo(0.1,0));
  92. this.EnableTouch = true;
  93. ACallBack();
  94. }.bind(this));
  95. //do animation
  96. var ShakeAnim = cc.sequence(RepeatAction,CallF);
  97. this.node.runAction(ShakeAnim);
  98. },
  99. ShowVC:function()
  100. {
  101. this.VC.active = true;
  102. this.VC.opacity = 0;
  103. var ShowVCAnim = cc.fadeIn(1);
  104. this.VC.runAction(ShowVCAnim);
  105. },
  106. TypingAni: function (Label, Text, Callback) {
  107. var CurrentText = '';
  108. var Arr = Text.split('');
  109. var Len = Arr.length;
  110. var Step = 0;
  111. this.Func = function () {
  112. CurrentText += Arr[Step];
  113. Label.string = CurrentText;
  114. Step++;
  115. if (Step == Len) {
  116. this.unschedule(this.Func);
  117. Callback(this);
  118. }
  119. };
  120. this.schedule(this.Func,0.05, cc.macro.REPEAT_FOREVER, 0)
  121. },
  122. TypingFinished(Self){
  123. //cc.log('TypingFinished');
  124. Self.EnableTouch = true;
  125. },
  126. ShowContact:function () {
  127. // hide others
  128. this.VC.active = false;
  129. this.DialogName.active = false;
  130. this.DialogConversation.active = false;
  131. // show contract
  132. this.ContractBG.active = true;
  133. this.ContractConfirmBTN.active = true;
  134. this.ContractCancelBTN.active = true;
  135. this.CompanyNameEditbox.active = true;
  136. this.CEONameEditbox.active = true;
  137. }
  138. });