CustomPage.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. cc.Class({
  2. extends: cc.BaseControl,
  3. properties: {
  4. m_HOOK: cc.Component,
  5. m_ResponseNode: cc.Node,
  6. m_ResponseComName: cc.String,
  7. m_WoShiFenGeXian: cc.String,
  8. ////////////////////////////////////////////
  9. m_LabCustom: [cc.Label],
  10. m_Label: cc.Label,
  11. m_EditBox: cc.EditBox,
  12. m_WoShiFenGeXian1: cc.String,
  13. ////////////////////////////////////////////
  14. m_btClose: cc.Button,
  15. m_btOK: cc.Button,
  16. m_btNO: cc.Button,
  17. m_btNoClick: cc.Button,
  18. m_WoShiFenGeXian2: cc.String,
  19. ////////////////////////////////////////////
  20. m_SwitchToggleNode: cc.Node,
  21. m_SwitchToggleArray: [cc.Toggle],
  22. m_SwitchButtonNode: cc.Node,
  23. m_SwitchButtonArray: [cc.Button],
  24. m_SwitchPageNode: cc.Node,
  25. m_PageArray: [cc.Node],
  26. },
  27. ctor: function () {},
  28. onLoad: function () {
  29. },
  30. start: function () {
  31. var cbIndex = 0;
  32. if (this.m_SwitchToggleNode) {
  33. this.m_SwitchToggleArray = new Array();
  34. this.TraverseNode({
  35. ContentArray: this.m_SwitchToggleArray,
  36. SouceNode: this.m_SwitchToggleNode,
  37. SearchCom: cc.Toggle,
  38. HandlerComponet: null,
  39. HandlerFunc: null,
  40. CustomData: null,
  41. });
  42. }
  43. for (var i = 0; i < this.m_SwitchToggleArray.length; ++i) {
  44. this.AddClickHandler(this.m_SwitchToggleArray[i], this.node, 'CustomPage', 'OnButtonClickedSwitchPage', cbIndex);
  45. ++cbIndex;
  46. }
  47. if (this.m_SwitchButtonNode) {
  48. this.m_SwitchButtonArray = new Array();
  49. this.TraverseNode({
  50. ContentArray: this.m_SwitchButtonArray,
  51. SouceNode: this.m_SwitchButtonNode,
  52. SearchCom: cc.Button,
  53. HandlerComponet: null,
  54. HandlerFunc: null,
  55. CustomData: null,
  56. });
  57. }
  58. for (var i = 0; i < this.m_SwitchButtonArray.length; ++i) {
  59. this.AddClickHandler(this.m_SwitchButtonArray[i], this.node, 'CustomPage', 'OnButtonClickedSwitchPage', cbIndex);
  60. ++cbIndex;
  61. }
  62. if (this.m_SwitchPageNode) {
  63. this.m_PageArray = new Array();
  64. for (var i = 0; i < this.m_SwitchPageNode.childrenCount; ++i) {
  65. this.m_PageArray[i] = this.m_SwitchPageNode.getChildByName('' + i);
  66. }
  67. }
  68. if (this.m_SwitchToggleArray.length > 0) this.UpdateSwitchPage(0, 0);
  69. if (this.m_SwitchButtonArray.length > 0) this.UpdateSwitchPage(0, 0);
  70. },
  71. SetAttribute2: function () {
  72. // SetOK: {
  73. // _active: true,
  74. // _enable: true,
  75. // _valid: true,
  76. // _hook: this,
  77. // _callback: null,
  78. // _event: {
  79. // _target: null,
  80. // _component: null,
  81. // _handler: null,
  82. // _CustomData: null
  83. // }
  84. // },
  85. if (this.m_btClose) {
  86. if (this.m_Attribute.SetClose) {
  87. this.AddClickHandler(this.m_btClose, this.node, 'CustomPage', 'OnButtonClickedClose');
  88. if (this.m_Attribute.SetClose._event && this.m_Attribute.SetClose._event._target &&
  89. this.m_Attribute.SetClose._event._component && this.m_Attribute.SetClose._event._handler) {
  90. this.AddClickHandler(this.m_btClose, this.m_Attribute.SetClose._event._target,
  91. this.m_Attribute.SetClose._event._component, this.m_Attribute.SetClose._event._handler);
  92. }
  93. if (this.m_Attribute.SetClose._active) this.m_btClose.node.active = true;
  94. else this.m_btClose.node.active = false;
  95. } else {}
  96. }
  97. if (this.m_btOK) {
  98. if (this.m_Attribute.SetOK) {
  99. this.AddClickHandler(this.m_btOK, this.node, 'CustomPage', 'OnButtonClickedOK');
  100. if (this.m_Attribute.SetOK._event && this.m_Attribute.SetOK._event._target &&
  101. this.m_Attribute.SetOK._event._component && this.m_Attribute.SetOK._event._handler) {
  102. this.AddClickHandler(this.m_btOK, this.m_Attribute.SetOK._event._target,
  103. this.m_Attribute.SetOK._event._component, this.m_Attribute.SetOK._event._handler,
  104. this.m_Attribute.SetOK._event._customData
  105. );
  106. }
  107. if (this.m_Attribute.SetOK._active) this.m_btOK.node.active = true;
  108. else
  109. this.m_btOK.node.active = false;
  110. } else {}
  111. }
  112. if (this.m_btNO) {
  113. if (this.m_Attribute.SetNO) {
  114. this.AddClickHandler(this.m_btNO, this.node, 'CustomPage', 'OnButtonClickedNO');
  115. if (this.m_Attribute.SetNO._event && this.m_Attribute.SetNO._event._target &&
  116. this.m_Attribute.SetNO._event._component && this.m_Attribute.SetNO._event._handler) {
  117. this.AddClickHandler(this.m_btNO, this.m_Attribute.SetNO._event._target,
  118. this.m_Attribute.SetNO._event._component, this.m_Attribute.SetNO._event._handler);
  119. }
  120. if (this.m_Attribute.SetNO._active) this.m_btNO.node.active = true;
  121. else this.m_btNO.node.active = false;
  122. } else {}
  123. }
  124. if (this.m_btNoClick) {
  125. if (this.m_Attribute.SetBGClose) {
  126. this.m_btNoClick.node.active = true;
  127. this.AddClickHandler(this.m_btNoClick, this.node, 'CustomPage', 'OnButtonClickedBG');
  128. if (this.m_Attribute.SetBGClose._event && this.m_Attribute.SetBGClose._event._target &&
  129. this.m_Attribute.SetBGClose._event._component && this.m_Attribute.SetBGClose._event._handler) {
  130. this.AddClickHandler(this.m_btNoClick, this.m_Attribute.SetBGClose._event._target,
  131. this.m_Attribute.SetBGClose._event._component, this.m_Attribute.SetNO._event._handler);
  132. }
  133. if (this.m_Attribute.SetBGClose._active) this.m_btNoClick.node.active = true;
  134. else this.m_btNoClick.node.active = false;
  135. } else {
  136. }
  137. }
  138. },
  139. SetString: function (szText) {
  140. console.log(szText);
  141. this.m_Label.string = szText;
  142. },
  143. GetEditBoxString: function () {
  144. if (this.m_EditBox) return this.m_EditBox.string;
  145. return '';
  146. },
  147. OnButtonClickedClose: function () {
  148. this.HidePage();
  149. },
  150. OnButtonClickedOK: function () {
  151. if(this.m_Attribute.SetOK._valid) this.HidePage();
  152. if (this.m_HOOK && this.m_HOOK.OnOKCallback) {
  153. this.m_HOOK.OnOKCallback(this);
  154. }
  155. if (this.m_Attribute.SetOK._hook && this.m_Attribute.SetOK._hook[this.m_Attribute.SetOK._callback]) {
  156. this.m_Attribute.SetOK._hook[this.m_Attribute.SetOK._callback](this);
  157. }
  158. },
  159. OnButtonClickedNO: function () {
  160. this.HidePage();
  161. },
  162. OnButtonClickedBG: function (event, customData) {
  163. if (customData == 1 || this.m_Attribute.SetBGClose._valid) {
  164. this.HidePage();
  165. }
  166. },
  167. HidePage: function () {
  168. if (this.m_ResponseNode instanceof cc.Node) {
  169. var pCom = this.$('@' + this.m_ResponseComName, this.m_ResponseNode);
  170. if(pCom && pCom.HideView) pCom.HideView();
  171. else this.m_ResponseNode.active = false;
  172. } else {
  173. this.node.active = false;
  174. }
  175. },
  176. ///////////////////////////////////////////////////
  177. SetCustomText: function (szText, ColorArray, ActiveArray) {
  178. if (!this.m_LabCustom) return;
  179. for (var i = 0; i < this.m_LabCustom.length; ++i) {
  180. this.m_LabCustom[i].string = ''
  181. if (Array.isArray(szText)) this.m_LabCustom[i].string = szText[i];
  182. else this.m_LabCustom[i].string = szText;
  183. if (ColorArray && ColorArray[i]) {
  184. this.m_LabCustom[i].node.color = ColorArray[i];
  185. }
  186. if (ActiveArray) {
  187. this.m_LabCustom[i].node.active = ActiveArray[i];
  188. }
  189. }
  190. },
  191. ///////////////////////////////////////////////////
  192. OnButtonClickedSwitchPage: function (event, customData) {
  193. this.UpdateSwitchPage(event, customData);
  194. },
  195. UpdateSwitchPage: function (event, customData) {
  196. if (!this.m_PageArray || !Array.isArray(this.m_PageArray)) return;
  197. for (var i = 0; i < this.m_PageArray.length; ++i) {
  198. if (this.m_PageArray[i]) {
  199. if (customData == i) {
  200. this.m_PageArray[i].active = true;
  201. this.ButtonCheck(event.target, true);
  202. if(this.m_HOOK && this.m_HOOK.OnChangePage) this.m_HOOK.OnChangePage(i, this.m_PageArray[i]);
  203. } else {
  204. this.m_PageArray[i].active = false;
  205. this.ButtonCheck(event.target, false);
  206. }
  207. }
  208. }
  209. },
  210. ButtonCheck: function(target, bCheck) {
  211. for(var i in this.m_SwitchButtonArray) {
  212. if (this.m_SwitchButtonArray[i] && this.m_SwitchButtonArray[i].node == target) {
  213. var pCheck = this.m_SwitchButtonArray[i].node.getChildByName('check');
  214. if (pCheck) pCheck.active = bCheck;
  215. }
  216. }
  217. },
  218. ///////////////////////////////////////////////////
  219. });