menuNavigation.tscript 8.7 KB

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