menuNavigation.tscript 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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.getPageCount() != 0 &&
  69. %this.pageStack.getIndexFromKey(%newPage) != -1)
  70. return;
  71. %canChange = true;
  72. if(%newPage.isMethod("canOpen"))
  73. %canChange = %newPage.call("canOpen");
  74. if(!%canChange)
  75. return;
  76. %currentPage = %this.getCurrentPage();
  77. if(isObject(%currentPage))
  78. {
  79. if(%currentPage.isMethod("canClose"))
  80. %canChange = %currentPage.call("canClose");
  81. if(!%canChange)
  82. return;
  83. if(%currentPage.isMethod("onClose"))
  84. %currentPage.call("onClose");
  85. }
  86. %this.pageStack.push_back(%newPage);
  87. %this.add(%newPage);
  88. if(%this.resizePages)
  89. {
  90. %newPage.resize(%this.position.x, %this.position.y,
  91. %this.extent.x, %this.extent.y);
  92. }
  93. if(%newPage.isMethod("onOpen"))
  94. %newPage.call("onOpen");
  95. %newPage.navigation = %this;
  96. if(%callback !$= "")
  97. eval(%callback);
  98. }
  99. //==============================================================================
  100. /// Summary:
  101. /// This function pops the topmost page off the given UINavigation-classed GUIContainer's stack
  102. /// The order of operations is thus:
  103. /// 1) check to see if the top page being popped says it can close via the canClose() function.
  104. /// If this method is not defined, it defaults to true, as there's no impediment to continuing
  105. /// If this check returns false, the popPage event cancels.
  106. /// 2) check to see if the previous page on the stack says it can open. Similar to
  107. /// the canClose() check on the new page, we default to true
  108. /// If this check returns false, the popPage event cancels.
  109. /// 3) Call - if defined - onClose() on the current top page of the stack
  110. /// 4) Remove the top page
  111. /// 5) Call - if defined - onOpen() on the now topmost page
  112. /// 6) Finally, if we defined a callback, call that.
  113. /// With this all run, the previous top page has done any cleanup work it needed to
  114. /// and the new top page has been opened successfully.
  115. ///
  116. /// \param %callback[optional] (Evaluable string) A evalable statement to invoke when the pop has been completed
  117. function UINavigation::popPage(%this, %callback)
  118. {
  119. if(%this.pageStack.count() == 0)
  120. return;
  121. %currentPage = %this.getCurrentPage();
  122. if(isObject(%currentPage))
  123. {
  124. %canChange = true;
  125. if(%currentPage.isMethod("canClose"))
  126. %canChange = %currentPage.call("canClose");
  127. if(!%canChange)
  128. return;
  129. }
  130. %prevPage = %this.getPreviousPage();
  131. if(isObject(%prevPage))
  132. {
  133. %canChange = true;
  134. if(%prevPage.isMethod("canOpen"))
  135. %canChange = %prevPage.call("canOpen");
  136. if(!%canChange)
  137. return;
  138. }
  139. if(isObject(%currentPage))
  140. {
  141. if(%currentPage.isMethod("onClose"))
  142. {
  143. %currentPage.call("onClose");
  144. }
  145. %this.pageStack.pop_back();
  146. %this.remove(%currentPage);
  147. %currentPage.navigation = "";
  148. }
  149. %newTopPage = %this.getCurrentPage();
  150. if(isObject(%newTopPage))
  151. {
  152. if(%newTopPage.isMethod("onOpen"))
  153. %newTopPage.call("onOpen");
  154. }
  155. if(%callback !$= "")
  156. eval(%callback);
  157. }
  158. //==============================================================================
  159. /// Summary:
  160. /// In order tops the topmost page in a loop until it has closed the entire stack,
  161. /// leaving only the root page
  162. ///
  163. /// \param %callback[optional] (Evaluable String) A evalable statement to invoke when the pop has been completed
  164. function UINavigation::popToRoot(%this, %callback)
  165. {
  166. %pageChanged = false;
  167. while(%this.getPageCount() != 0)
  168. {
  169. %currentPage = %this.getCurrentPage();
  170. if(isObject(%currentPage))
  171. {
  172. if(%currentPage.isMethod("canClose"))
  173. %canChange = %currentPage.call("canClose");
  174. if(!%canChange)
  175. return;
  176. }
  177. %prevPage = %this.getPreviousPage();
  178. if(isObject(%prevPage))
  179. {
  180. if(%prevPage.isMethod("canOpen"))
  181. %canChange = %prevPage.call("canOpen");
  182. if(!%canChange)
  183. return;
  184. }
  185. if(isObject(%currentPage))
  186. {
  187. if(%currentPage.isMethod("onClose"))
  188. {
  189. %currentPage.call("onClose");
  190. }
  191. %this.pageStack.pop_back();
  192. %this.remove(%currentPage);
  193. %currentPage.navigation = "";
  194. }
  195. %newTopPage = %this.getCurrentPage();
  196. if(%newTopPage.isMethod("onOpen"))
  197. %newTopPage.call("onOpen");
  198. %pageChanged = true;
  199. }
  200. if(%pageChanged && %callback !$= "")
  201. eval(%callback);
  202. }
  203. //==============================================================================
  204. /// Summary:
  205. /// Gets the current, topmost page on the stack. If no non-root pages are on the stack
  206. /// the root page is returned
  207. function UINavigation::getCurrentPage(%this)
  208. {
  209. if(isObject(%this.pageStack) && %this.pageStack.count() != 0)
  210. {
  211. return %this.pageStack.getKey(%this.pageStack.count()-1);
  212. }
  213. else
  214. {
  215. if(isObject(%this.rootPage))
  216. return %this.rootPage;
  217. }
  218. return 0;
  219. }
  220. //==============================================================================
  221. /// Summary:
  222. /// Gets the page just under the topmost page in the stack. If there is no previous page
  223. /// then the root page is returned
  224. function UINavigation::getPreviousPage(%this)
  225. {
  226. if(isObject(%this.pageStack) && %this.pageStack.count() > 1)
  227. {
  228. return %this.pageStack.getKey(%this.pageStack.count()-2);
  229. }
  230. else
  231. {
  232. if(isObject(%this.rootPage))
  233. return %this.rootPage;
  234. }
  235. return 0;
  236. }
  237. //==============================================================================
  238. /// Summary:
  239. /// Gets the number of pages on the stack.
  240. function UINavigation::getPageCount(%this)
  241. {
  242. %count = 0;
  243. if(isObject(%this.pageStack))
  244. %count = %this.pageStack.count();
  245. if(isObject(%this.rootPage))
  246. %count++;
  247. return %count;
  248. }
  249. //==============================================================================
  250. /// Summary:
  251. /// Force the page to reprocess to ensure it's status is up to date
  252. function UINavigation::refreshPage(%this)
  253. {
  254. %page = %this.getCurrentPage();
  255. if(!isObject(%page))
  256. return;
  257. if(%page.isMethod("onOpen"))
  258. %page.call("onOpen");
  259. }