BaseState.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. (function() {
  2. FZ.stateStatus = {};
  3. FZ.stateStatus.INIT = 0;
  4. FZ.stateStatus.NORMAL = 5;
  5. FZ.stateStatus.HIDENOTIFY = 15;
  6. FZ.stateStatus.HIDELOGIC = 20;
  7. FZ.stateStatus.DONOTHING = 30;
  8. FZ.BaseState = FZ.newClass( {
  9. StateName : "GameStateBase",
  10. m_status : FZ.stateStatus.NORMAL,
  11. m_timer : null,
  12. m_main_div : null,
  13. m_main_div_clone : null,
  14. // m_div_back : null,
  15. m_ui_list : null,
  16. m_btn_list : null,
  17. init:function() {
  18. // register the state into the GameBase
  19. FZ.GameBase.registerState(this.StateName, this);
  20. this.m_main_div = document.createElement("div");
  21. this.m_main_div_clone = document.createElement("div");
  22. // this.m_div_back = [];
  23. this.m_ui_list = [];
  24. this.m_btn_list = [];
  25. },
  26. pause : function() {
  27. },
  28. resume : function() {
  29. },
  30. createUIs : function(names) {
  31. var index = 0;
  32. var info = null;
  33. var div = null;
  34. for (index = 0; index < names.length; index++) {
  35. info = FZ.getImgInfo(names[index]);
  36. div = document.createElement("div");
  37. FZ.GameBase.setCss(div, info);
  38. this.m_ui_list.push(div);
  39. this.m_main_div.appendChild(div);
  40. }
  41. },
  42. createBtns : function(names, addToStage) {
  43. var index = 0;
  44. var info = null;
  45. var infoDown = null;
  46. for (index = 0; index < names.length; index++) {
  47. info = FZ.getImgInfo(names[index][0]);
  48. infoDown = FZ.getImgInfo(names[index][1]);
  49. btn = new FZ.UIButton(info.w, info.h, info.cols, info.fileURL, infoDown.fileURL);
  50. btn.setPos(info.x, info.y);
  51. btn.addMonitor(this);
  52. this.m_btn_list.push(btn);
  53. if(addToStage) {
  54. this.m_main_div.appendChild(btn.m_div);
  55. }
  56. }
  57. },
  58. resetTranslate : function(alpha) {
  59. this.m_remove_div = false;
  60. this.m_main_div.style.display = "inline";
  61. this.m_main_div.style.zIndex = 0;
  62. this.m_main_div.style.webkitTransitionDuration = "0s";
  63. this.m_main_div.style.opacity = alpha;
  64. this.m_main_div.style.webkitTransform = "translate(0px, 0px) rotate(0deg)";
  65. },
  66. fade_in : function(time, alpha) {
  67. var mySelf = this;
  68. this.m_remove_div = false;
  69. this.m_main_div.style.webkitTransitionDuration = time + "ms";
  70. this.m_main_div.style.opacity = alpha;
  71. this.m_main_div.style.webkitTransform = "translate(0px, 0px) rotate(0deg)";
  72. },
  73. fade_out : function(time, alpha, angle) {
  74. var mySelf = this;
  75. var offsetX = FZ.GameDefs.SCREEN_W;
  76. var offsetY = 0;
  77. this.m_remove_div = true;
  78. this.m_main_div.style.webkitTransitionDuration = time + "ms";
  79. setTimeout(function() {
  80. mySelf.m_main_div.style.opacity = alpha;
  81. mySelf.m_main_div.style.webkitTransform = "translate(" + offsetX + "px, " + offsetY + "0px) rotate(" + angle + "deg)";
  82. }, 1);
  83. setTimeout(function() {
  84. if(mySelf.m_remove_div) {
  85. mySelf.m_main_div.style.display = "none";
  86. }
  87. }, time);
  88. },
  89. preProcess : function() {
  90. },
  91. postProcess : function() {
  92. },
  93. AIUpdate : function(deltaTime) {
  94. },
  95. pushState : function(stateName) {
  96. this.__stateStack.push(this.__StateLib[stateName]);
  97. },
  98. popState : function() {
  99. // this.CurrentState = null;
  100. this.CurrentState = this.__stateStack.pop();
  101. if((undefined !== this.CurrentState) && (null !== this.CurrentState)) {
  102. if(this.CurrentState.resume){
  103. this.CurrentState.resume.apply(this.CurrentState, arguments);
  104. }
  105. }
  106. }
  107. });
  108. })();