messageBoxes.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. // Cleanup Dialog created by 'core'
  23. if( isObject( MessageBoxYesNoDlg ) )
  24. MessageBoxYesNoDlg.delete();
  25. if( isObject( MessageBoxOKDlg ) )
  26. MessageBoxOKDlg.delete();
  27. // Load Editor Dialogs
  28. exec("./guis/messageBoxOk.gui");
  29. exec("./guis/messageBoxYesNo.gui");
  30. // --------------------------------------------------------------------
  31. // Message Sound
  32. // --------------------------------------------------------------------
  33. /*new SFXDescription(MessageBoxAudioDescription)
  34. {
  35. volume = 1.0;
  36. isLooping = false;
  37. is3D = false;
  38. channel = $GuiAudioType;
  39. };
  40. new SFXProfile(messageBoxBeep)
  41. {
  42. filename = "./messageBoxSound";
  43. description = MessageBoxAudioDescription;
  44. preload = true;
  45. };*/
  46. //---------------------------------------------------------------------------------------------
  47. // messageCallback
  48. // Calls a callback passed to a message box.
  49. //---------------------------------------------------------------------------------------------
  50. function messageCallback(%dlg, %callback)
  51. {
  52. Canvas.popDialog(%dlg);
  53. eval(%callback);
  54. }
  55. //The # in the function passed replaced with the output
  56. //of the preset menu.
  57. function IOCallback(%dlg, %callback)
  58. {
  59. %id = IODropdownMenu.getSelected();
  60. %text = IODropdownMenu.getTextById(%id);
  61. %callback = strreplace(%callback, "#", %text);
  62. eval(%callback);
  63. Canvas.popDialog(%dlg);
  64. }
  65. //---------------------------------------------------------------------------------------------
  66. // MBSetText
  67. // Sets the text of a message box and resizes it to accomodate the new string.
  68. //---------------------------------------------------------------------------------------------
  69. function MBSetText(%text, %frame, %msg)
  70. {
  71. // Get the extent of the text box.
  72. %ext = %text.getExtent();
  73. // Set the text in the center of the text box.
  74. %text.setText("<just:center>" @ %msg);
  75. // Force the textbox to resize itself vertically.
  76. %text.forceReflow();
  77. // Grab the new extent of the text box.
  78. %newExtent = %text.getExtent();
  79. // Get the vertical change in extent.
  80. %deltaY = getWord(%newExtent, 1) - getWord(%ext, 1);
  81. // Resize the window housing the text box.
  82. %windowPos = %frame.getPosition();
  83. %windowExt = %frame.getExtent();
  84. %frame.resize(getWord(%windowPos, 0), getWord(%windowPos, 1) - (%deltaY / 2),
  85. getWord(%windowExt, 0), getWord(%windowExt, 1) + %deltaY);
  86. %frame.canMove = "0";
  87. //%frame.canClose = "0";
  88. %frame.resizeWidth = "0";
  89. %frame.resizeHeight = "0";
  90. %frame.canMinimize = "0";
  91. %frame.canMaximize = "0";
  92. //sfxPlayOnce( messageBoxBeep );
  93. }
  94. //---------------------------------------------------------------------------------------------
  95. // Various message box display functions. Each one takes a window title, a message, and a
  96. // callback for each button.
  97. //---------------------------------------------------------------------------------------------
  98. function MessageBoxOK(%title, %message, %callback)
  99. {
  100. MBOKFrame.text = %title;
  101. Canvas.pushDialog(MessageBoxOKDlg);
  102. MBSetText(MBOKText, MBOKFrame, %message);
  103. MessageBoxOKDlg.callback = %callback;
  104. }
  105. function MessageBoxOKDlg::onSleep( %this )
  106. {
  107. %this.callback = "";
  108. }
  109. function MessageBoxOKCancel(%title, %message, %callback, %cancelCallback)
  110. {
  111. MBOKCancelFrame.text = %title;
  112. Canvas.pushDialog(MessageBoxOKCancelDlg);
  113. MBSetText(MBOKCancelText, MBOKCancelFrame, %message);
  114. MessageBoxOKCancelDlg.callback = %callback;
  115. MessageBoxOKCancelDlg.cancelCallback = %cancelCallback;
  116. }
  117. function MessageBoxOKCancelDlg::onSleep( %this )
  118. {
  119. %this.callback = "";
  120. }
  121. function MessageBoxOKCancelDetails(%title, %message, %details, %callback, %cancelCallback)
  122. {
  123. if(%details $= "")
  124. {
  125. MBOKCancelDetailsButton.setVisible(false);
  126. }
  127. MBOKCancelDetailsScroll.setVisible(false);
  128. MBOKCancelDetailsFrame.setText( %title );
  129. Canvas.pushDialog(MessageBoxOKCancelDetailsDlg);
  130. MBSetText(MBOKCancelDetailsText, MBOKCancelDetailsFrame, %message);
  131. MBOKCancelDetailsInfoText.setText(%details);
  132. %textExtent = MBOKCancelDetailsText.getExtent();
  133. %textExtentY = getWord(%textExtent, 1);
  134. %textPos = MBOKCancelDetailsText.getPosition();
  135. %textPosY = getWord(%textPos, 1);
  136. %extentY = %textPosY + %textExtentY + 65;
  137. MBOKCancelDetailsInfoText.setExtent(285, 128);
  138. MBOKCancelDetailsFrame.setExtent(300, %extentY);
  139. MessageBoxOKCancelDetailsDlg.callback = %callback;
  140. MessageBoxOKCancelDetailsDlg.cancelCallback = %cancelCallback;
  141. MBOKCancelDetailsFrame.defaultExtent = MBOKCancelDetailsFrame.getExtent();
  142. }
  143. function MBOKCancelDetailsToggleInfoFrame()
  144. {
  145. if(!MBOKCancelDetailsScroll.isVisible())
  146. {
  147. MBOKCancelDetailsScroll.setVisible(true);
  148. MBOKCancelDetailsText.forceReflow();
  149. %textExtent = MBOKCancelDetailsText.getExtent();
  150. %textExtentY = getWord(%textExtent, 1);
  151. %textPos = MBOKCancelDetailsText.getPosition();
  152. %textPosY = getWord(%textPos, 1);
  153. %verticalStretch = %textExtentY;
  154. if((%verticalStretch > 260) || (%verticalStretch < 0))
  155. %verticalStretch = 260;
  156. %extent = MBOKCancelDetailsFrame.defaultExtent;
  157. %height = getWord(%extent, 1);
  158. %posY = %textPosY + %textExtentY + 10;
  159. %posX = getWord(MBOKCancelDetailsScroll.getPosition(), 0);
  160. MBOKCancelDetailsScroll.setPosition(%posX, %posY);
  161. MBOKCancelDetailsScroll.setExtent(getWord(MBOKCancelDetailsScroll.getExtent(), 0), %verticalStretch);
  162. MBOKCancelDetailsFrame.setExtent(300, %height + %verticalStretch + 10);
  163. } else
  164. {
  165. %extent = MBOKCancelDetailsFrame.defaultExtent;
  166. %width = getWord(%extent, 0);
  167. %height = getWord(%extent, 1);
  168. MBOKCancelDetailsFrame.setExtent(%width, %height);
  169. MBOKCancelDetailsScroll.setVisible(false);
  170. }
  171. }
  172. function MessageBoxOKCancelDetailsDlg::onSleep( %this )
  173. {
  174. %this.callback = "";
  175. }
  176. function MessageBoxYesNo(%title, %message, %yesCallback, %noCallback)
  177. {
  178. MBYesNoFrame.text = %title;
  179. Canvas.pushDialog(MessageBoxYesNoDlg);
  180. MBSetText(MBYesNoText, MBYesNoFrame, %message);
  181. MessageBoxYesNoDlg.yesCallBack = %yesCallback;
  182. MessageBoxYesNoDlg.noCallback = %noCallBack;
  183. }
  184. function MessageBoxYesNoCancel(%title, %message, %yesCallback, %noCallback, %cancelCallback)
  185. {
  186. MBYesNoCancelFrame.text = %title;
  187. MessageBoxYesNoDlg.profile = "GuiOverlayProfile";
  188. Canvas.pushDialog(MessageBoxYesNoCancelDlg);
  189. MBSetText(MBYesNoCancelText, MBYesNoCancelFrame, %message);
  190. MessageBoxYesNoCancelDlg.yesCallBack = %yesCallback;
  191. MessageBoxYesNoCancelDlg.noCallback = %noCallBack;
  192. MessageBoxYesNoCancelDlg.cancelCallback = %cancelCallback;
  193. }
  194. function MessageBoxYesNoDlg::onSleep( %this )
  195. {
  196. %this.yesCallback = "";
  197. %this.noCallback = "";
  198. }
  199. //---------------------------------------------------------------------------------------------
  200. // MessagePopup
  201. // Displays a message box with no buttons. Disappears after %delay milliseconds.
  202. //---------------------------------------------------------------------------------------------
  203. function MessagePopup(%title, %message, %delay)
  204. {
  205. // Currently two lines max.
  206. MessagePopFrame.setText(%title);
  207. Canvas.pushDialog(MessagePopupDlg);
  208. MBSetText(MessagePopText, MessagePopFrame, %message);
  209. if (%delay !$= "")
  210. schedule(%delay, 0, CloseMessagePopup);
  211. }
  212. //---------------------------------------------------------------------------------------------
  213. // IODropdown
  214. // By passing in a simgroup or simset, the user will be able to choose a child of that group
  215. // through a guiPopupMenuCtrl
  216. //---------------------------------------------------------------------------------------------
  217. function IODropdown(%title, %message, %simgroup, %callback, %cancelCallback)
  218. {
  219. IODropdownFrame.text = %title;
  220. Canvas.pushDialog(IODropdownDlg);
  221. MBSetText(IODropdownText, IODropdownFrame, %message);
  222. if(isObject(%simgroup))
  223. {
  224. for(%i = 0; %i < %simgroup.getCount(); %i++)
  225. IODropdownMenu.add(%simgroup.getObject(%i).getName());
  226. }
  227. IODropdownMenu.sort();
  228. IODropdownMenu.setFirstSelected(0);
  229. IODropdownDlg.callback = %callback;
  230. IODropdownDlg.cancelCallback = %cancelCallback;
  231. }
  232. function IODropdownDlg::onSleep( %this )
  233. {
  234. %this.callback = "";
  235. %this.cancelCallback = "";
  236. IODropdownMenu.clear();
  237. }
  238. function CloseMessagePopup()
  239. {
  240. Canvas.popDialog(MessagePopupDlg);
  241. }