menuNavigation.tscript 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. //==============================================================================
  2. /// Summary:
  3. /// This function sets the root page for the navigation stack. The root page is 'below'
  4. /// all other normal pages and cannot be popped like a normal page.
  5. /// When we set a new root page, we first check if we have an existing root page.
  6. /// If we do, we run the usual canClose() then onClose() function pair, then we
  7. /// set it and call the onOpen() for the new root page.
  8. ///
  9. /// \param %rootPage (guiControl) The new guiControl that is being set as the root page of the navigation stack
  10. function UINavigation::setRootPage(%this, %rootPage)
  11. {
  12. if(!isObject(%this.pageStack))
  13. {
  14. %this.pageStack = new ArrayObject();
  15. }
  16. if(%this.rootPage $= %rootPage)
  17. return;
  18. if(isObject(%this.rootPage))
  19. {
  20. %canClose = true;
  21. if(%this.rootPage.isMethod("canClose"))
  22. %canClose = %this.rootPage.call("canClose");
  23. if(!%canClose)
  24. return; //if we're not allowed to close, just bail out wholesale because clearly
  25. //something is blocking changes to pages
  26. %this.remove(%this.rootPage);
  27. if(%this.rootPage.isMethod("onClose"))
  28. %this.rootPage.call("onClose");
  29. %this.rootPage.navigation = "";
  30. }
  31. %this.rootPage = %rootPage;
  32. %this.add(%rootPage);
  33. if(%this.resizePages)
  34. {
  35. %rootPage.resize(%this.position.x, %this.position.y,
  36. %this.extent.x, %this.extent.y);
  37. }
  38. %rootPage.navigation = %this;
  39. if(%rootPage.isMethod("onOpen"))
  40. %rootPage.call("onOpen");
  41. }
  42. //==============================================================================
  43. /// Summary:
  44. /// This function pushes a page onto the given UINavigation-classed GUIContainer's stack
  45. /// The order of operations is thus:
  46. /// 1) check to see if the new page being pushed says it can open via the canOpen() function.
  47. /// If this method is not defined, it defaults to true, as there's no impediment to continuing
  48. /// If this check returns false, the pushPage event cancels.
  49. /// 2) check to see if the current page on the stack says it can close. Similar to
  50. /// the canOpen() check on the new page, we default to true
  51. /// If this check returns false, the pushPage event cancels.
  52. /// 3) Call - if defined - onClose() on the current top page of the stack
  53. /// 4) Add the new page onto the stack
  54. /// 5) Call - if defined - onOpen() on the new page
  55. /// 6) Finally, if we defined a callback, call that.
  56. /// With this all run, the previous top page has done any cleanup work it needed to
  57. /// and the new top page has been opened successfully.
  58. ///
  59. /// \param %newPage (guiControl) The new guiControl that is being added onto the page stack
  60. /// \param %callback[optional]: (Evaluable string) A evalable statement to invoke when the push has been completed
  61. function UINavigation::pushPage(%this, %newPage, %callback)
  62. {
  63. if(!isObject(%this.pageStack))
  64. {
  65. %this.pageStack = new ArrayObject();
  66. }
  67. //don't re-add pages
  68. if(%this.pageStack.getIndexFromKey(%newPage) != -1)
  69. return;
  70. %canChange = true;
  71. if(%newPage.isMethod("canOpen"))
  72. %canChange = %newPage.call("canOpen");
  73. if(!%canChange)
  74. return;
  75. %currentPage = %this.getCurrentPage();
  76. if(isObject(%currentPage))
  77. {
  78. if(%currentPage.isMethod("canClose"))
  79. %canChange = %currentPage.call("canClose");
  80. if(!%canChange)
  81. return;
  82. if(%currentPage.isMethod("onClose"))
  83. %currentPage.call("onClose");
  84. }
  85. %this.pageStack.push_back(%newPage);
  86. %this.add(%newPage);
  87. if(%this.resizePages)
  88. {
  89. %newPage.resize(%this.position.x, %this.position.y,
  90. %this.extent.x, %this.extent.y);
  91. }
  92. if(%newPage.isMethod("onOpen"))
  93. %newPage.call("onOpen");
  94. %newPage.navigation = %this;
  95. if(%callback !$= "")
  96. eval(%callback);
  97. }
  98. //==============================================================================
  99. /// Summary:
  100. /// This function pops the topmost page off the given UINavigation-classed GUIContainer's stack
  101. /// The order of operations is thus:
  102. /// 1) check to see if the top page being popped says it can close via the canClose() function.
  103. /// If this method is not defined, it defaults to true, as there's no impediment to continuing
  104. /// If this check returns false, the popPage event cancels.
  105. /// 2) check to see if the previous page on the stack says it can open. Similar to
  106. /// the canClose() check on the new page, we default to true
  107. /// If this check returns false, the popPage event cancels.
  108. /// 3) Call - if defined - onClose() on the current top page of the stack
  109. /// 4) Remove the top page
  110. /// 5) Call - if defined - onOpen() on the now topmost page
  111. /// 6) Finally, if we defined a callback, call that.
  112. /// With this all run, the previous top page has done any cleanup work it needed to
  113. /// and the new top page has been opened successfully.
  114. ///
  115. /// \param %callback[optional] (Evaluable string) A evalable statement to invoke when the pop has been completed
  116. function UINavigation::popPage(%this, %callback)
  117. {
  118. if(%this.pageStack.count() == 0)
  119. return;
  120. %currentPage = %this.getCurrentPage();
  121. if(isObject(%currentPage))
  122. {
  123. %canChange = true;
  124. if(%currentPage.isMethod("canClose"))
  125. %canChange = %currentPage.call("canClose");
  126. if(!%canChange)
  127. return;
  128. }
  129. %prevPage = %this.getPreviousPage();
  130. if(isObject(%prevPage))
  131. {
  132. %canChange = true;
  133. if(%prevPage.isMethod("canOpen"))
  134. %canChange = %prevPage.call("canOpen");
  135. if(!%canChange)
  136. return;
  137. }
  138. if(isObject(%currentPage))
  139. {
  140. if(%currentPage.isMethod("onClose"))
  141. {
  142. %currentPage.call("onClose");
  143. }
  144. %this.pageStack.pop_back();
  145. %this.remove(%currentPage);
  146. %currentPage.navigation = "";
  147. }
  148. %newTopPage = %this.getCurrentPage();
  149. if(%newTopPage.isMethod("onOpen"))
  150. %newTopPage.call("onOpen");
  151. if(%callback !$= "")
  152. eval(%callback);
  153. }
  154. //==============================================================================
  155. /// Summary:
  156. /// In order tops the topmost page in a loop until it has closed the entire stack,
  157. /// leaving only the root page
  158. ///
  159. /// \param %callback[optional] (Evaluable String) A evalable statement to invoke when the pop has been completed
  160. function UINavigation::popToRoot(%this, %callback)
  161. {
  162. %pageChanged = false;
  163. while(%this.getPageCount() != 0)
  164. {
  165. %currentPage = %this.getCurrentPage();
  166. if(isObject(%currentPage))
  167. {
  168. if(%currentPage.isMethod("canClose"))
  169. %canChange = %currentPage.call("canClose");
  170. if(!%canChange)
  171. return;
  172. }
  173. %prevPage = %this.getPreviousPage();
  174. if(isObject(%prevPage))
  175. {
  176. if(%prevPage.isMethod("canOpen"))
  177. %canChange = %prevPage.call("canOpen");
  178. if(!%canChange)
  179. return;
  180. }
  181. if(isObject(%currentPage))
  182. {
  183. if(%currentPage.isMethod("onClose"))
  184. {
  185. %currentPage.call("onClose");
  186. }
  187. %this.pageStack.pop_back();
  188. %this.remove(%currentPage);
  189. %currentPage.navigation = "";
  190. }
  191. %newTopPage = %this.getCurrentPage();
  192. if(%newTopPage.isMethod("onOpen"))
  193. %newTopPage.call("onOpen");
  194. %pageChanged = true;
  195. }
  196. if(%pageChanged && %callback !$= "")
  197. eval(%callback);
  198. }
  199. //==============================================================================
  200. /// Summary:
  201. /// Gets the current, topmost page on the stack. If no non-root pages are on the stack
  202. /// the root page is returned
  203. function UINavigation::getCurrentPage(%this)
  204. {
  205. if(isObject(%this.pageStack) && %this.pageStack.count() != 0)
  206. {
  207. return %this.pageStack.getKey(%this.pageStack.count()-1);
  208. }
  209. else
  210. {
  211. if(isObject(%this.rootPage))
  212. return %this.rootPage;
  213. }
  214. return 0;
  215. }
  216. //==============================================================================
  217. /// Summary:
  218. /// Gets the page just under the topmost page in the stack. If there is no previous page
  219. /// then the root page is returned
  220. function UINavigation::getPreviousPage(%this)
  221. {
  222. if(isObject(%this.pageStack) && %this.pageStack.count() > 1)
  223. {
  224. return %this.pageStack.getKey(%this.pageStack.count()-2);
  225. }
  226. else
  227. {
  228. if(isObject(%this.rootPage))
  229. return %this.rootPage;
  230. }
  231. return 0;
  232. }
  233. //==============================================================================
  234. /// Summary:
  235. /// Gets the number of pages on the stack.
  236. function UINavigation::getPageCount(%this)
  237. {
  238. %count = 0;
  239. if(isObject(%this.pageStack))
  240. %count = %this.pageStack.count();
  241. if(isObject(%this.rootPage))
  242. %count++;
  243. return %count;
  244. }