uimanager.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. class UIManager
  2. {
  3. //! Create & open menu with specific id (see \ref MenuID) and set its parent
  4. proto native UIScriptedMenu EnterScriptedMenu(int id, UIMenuPanel parent);
  5. proto native UIScriptedMenu CreateScriptedMenu(int id, UIMenuPanel parent);
  6. proto native void EnterServerBrowser(UIMenuPanel parentMenu);
  7. proto native UIScriptedMenu ShowScriptedMenu(UIScriptedMenu menu, UIMenuPanel parent);
  8. proto native void HideScriptedMenu(UIScriptedMenu menu);
  9. proto native Widget GetWidgetUnderCursor();
  10. proto native bool IsDialogVisible();
  11. //! Returns true for a single frame whenever a dialog is hidden.
  12. proto native bool IsDialogHiding();
  13. proto native bool IsModalVisible();
  14. proto native void CloseSpecificDialog(int id);
  15. proto native void CloseDialog();
  16. proto native void HideDialog();
  17. /**
  18. \brief Shows message dialog
  19. @param caption
  20. @param text
  21. @param id custom user id
  22. @param butts \ref DialogBoxType
  23. @param def \ref DialogBoxButton
  24. @param type \ref DialogMessageType
  25. @param handler
  26. \n usage :
  27. @code
  28. const int QUIT_DIALOG_ID = 76;
  29. GetGame().GetUIManager().ShowDialog("Quit", "Do You really want to quit?", QUIT_DIALOG_ID, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
  30. ...
  31. // after user pass dialog, callback on menu/event handler is called
  32. ScriptedWidgetEventHandler::OnModalResult( Widget w, int x, int y, int code, int result )
  33. {
  34. if (code == QUIT_DIALOG_ID && result == DBB_YES) // yes this is callback for dialog we show earlier and user press YES button
  35. {
  36. Quit();
  37. }
  38. }
  39. @endcode
  40. */
  41. proto native void ShowDialog(string caption, string text, int id, int butts /*DBT_*/, int def/*DBB_*/, int type /*DMT_*/, UIScriptedMenu handler);
  42. //! natively checks game focus on cursor hiding
  43. proto native bool ShowCursor(bool visible);
  44. proto native bool IsCursorVisible();
  45. proto native bool IsDialogQueued();
  46. proto native bool ShowQueuedDialog();
  47. proto native int GetLoginQueuePosition();
  48. proto native bool ScreenFadeVisible();
  49. proto native void ScreenFadeIn(float duration, string text, int backgroundColor, int textColor);
  50. proto native void ScreenFadeOut(float duration);
  51. proto native bool IsScaledMode();
  52. proto native void SetScaledMode(bool enabled);
  53. //! Returns most-top open menu
  54. proto native UIScriptedMenu GetMenu();
  55. //! Close top window on windows stack, returns true when any window is closed
  56. bool Back()
  57. {
  58. if (IsDialogVisible() == false)
  59. {
  60. UIMenuPanel menu = GetMenu();
  61. if (menu)
  62. {
  63. menu.Close();
  64. return true;
  65. }
  66. }
  67. return false;
  68. }
  69. //! Close all opened menus
  70. bool CloseAll()
  71. {
  72. UIMenuPanel menu = GetMenu();
  73. while (menu)
  74. {
  75. if (menu.GetParentMenu())
  76. {
  77. menu = menu.GetParentMenu();
  78. }
  79. else
  80. {
  81. menu.Close();
  82. return true;
  83. }
  84. }
  85. return false;
  86. }
  87. //! Close all opened menus except first menu
  88. bool CloseAllSubmenus()
  89. {
  90. UIMenuPanel menu = GetMenu();
  91. while (menu && menu.GetParentMenu() && menu.GetParentMenu().GetParentMenu())
  92. {
  93. menu = menu.GetParentMenu();
  94. }
  95. if (menu && menu.GetParentMenu())
  96. {
  97. menu.Close();
  98. return true;
  99. }
  100. return false;
  101. }
  102. //! Close menu with specific ID (see \ref MenuID)
  103. bool CloseMenu(int id)
  104. {
  105. UIMenuPanel menu = GetMenu();
  106. while (menu)
  107. {
  108. if (menu.GetID() == id)
  109. {
  110. menu.Close();
  111. return true;
  112. }
  113. menu = menu.GetParentMenu();
  114. }
  115. return false;
  116. }
  117. bool HideMenu(int id)
  118. {
  119. UIScriptedMenu menu = GetMenu();
  120. while (menu)
  121. {
  122. if (menu.GetID() == id)
  123. {
  124. HideScriptedMenu( menu );
  125. return true;
  126. }
  127. menu = UIScriptedMenu.Cast( menu.GetParentMenu() );
  128. }
  129. return false;
  130. }
  131. //! Returns true if menu with specific ID is opened (see \ref MenuID)
  132. bool IsMenuOpen(int id)
  133. {
  134. return FindMenu(id) != null;
  135. }
  136. //! Returns menu with specific ID if it is open (see \ref MenuID)
  137. UIScriptedMenu FindMenu(int id)
  138. {
  139. UIScriptedMenu menu = GetMenu();
  140. while (menu)
  141. {
  142. if (menu.GetID() == id)
  143. {
  144. return menu;
  145. }
  146. menu = UIScriptedMenu.Cast( menu.GetParentMenu() );
  147. }
  148. return NULL;
  149. }
  150. //Window management
  151. void OpenWindow( int id )
  152. {
  153. UIScriptedWindow window = UIScriptedWindow.GetWindow( id );
  154. //if window is already opened, close it
  155. if ( window )
  156. {
  157. CloseWindow( id );
  158. return;
  159. }
  160. //create new window
  161. switch( id )
  162. {
  163. case GUI_WINDOW_MISSION_LOADER:
  164. window = GetGame().GetMission().CreateScriptedWindow( id );
  165. break;
  166. default: {};
  167. }
  168. if ( window )
  169. {
  170. window.Init();
  171. //add to active windows
  172. UIScriptedWindow.AddToActiveWindows( id, window );
  173. }
  174. }
  175. void CloseWindow( int id )
  176. {
  177. UIScriptedWindow window = UIScriptedWindow.GetWindow( id );
  178. if ( window )
  179. {
  180. UIScriptedWindow.RemoveFromActiveWindows( id );
  181. window.HideWindow();
  182. //delete window;
  183. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(this.DeleteWindow, window );
  184. /*
  185. wtf? leak
  186. Timer delete_timer = new Timer ( CALL_CATEGORY_SYSTEM );
  187. Param1<UIScriptedWindow> params = new Param1<UIScriptedWindow>( window );
  188. delete_timer.Run( 0.5, this, "DeleteWindow", params, false );*/
  189. }
  190. }
  191. void DeleteWindow( UIScriptedWindow window )
  192. {
  193. delete window;
  194. }
  195. bool IsWindowOpened( int id )
  196. {
  197. if ( UIScriptedWindow.GetWindow( id ) )
  198. {
  199. return true;
  200. }
  201. return false;
  202. }
  203. void ShowUICursor( bool visible )
  204. {
  205. g_Game.SetMouseCursorDesiredVisibility(visible);
  206. }
  207. };
  208. //! Returns random loading background texture path
  209. string GetRandomLoadingBackground()
  210. {
  211. const string images[] = {"{655A1BF79F5B291}Gui/textures/loading_screens/loading_screen_1_co.edds", "{84BE5F7442BD4B}Gui/textures/loading_screens/loading_screen_2_co.edds"};
  212. Math.Randomize(-1);
  213. int index = Math.RandomInt(0, 100) % 2;
  214. return images[index];
  215. }