y_dialog_impl.inc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. Legal:
  3. Version: MPL 1.1
  4. The contents of this file are subject to the Mozilla Public License Version
  5. 1.1 the "License"; you may not use this file except in compliance with
  6. the License. You may obtain a copy of the License at
  7. http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS IS" basis,
  9. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  10. for the specific language governing rights and limitations under the
  11. License.
  12. The Original Code is the YSI framework.
  13. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  14. Portions created by the Initial Developer are Copyright C 2011
  15. the Initial Developer. All Rights Reserved.
  16. Contributors:
  17. Y_Less
  18. koolk
  19. JoeBullet/Google63
  20. g_aSlice/Slice
  21. Misiur
  22. samphunter
  23. tianmeta
  24. maddinat0r
  25. spacemud
  26. Crayder
  27. Dayvison
  28. Ahmad45123
  29. Zeex
  30. irinel1996
  31. Yiin-
  32. Chaprnks
  33. Konstantinos
  34. Masterchen09
  35. Southclaws
  36. PatchwerkQWER
  37. m0k1
  38. paulommu
  39. udan111
  40. Thanks:
  41. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  42. ZeeX - Very productive conversations.
  43. koolk - IsPlayerinAreaEx code.
  44. TheAlpha - Danish translation.
  45. breadfish - German translation.
  46. Fireburn - Dutch translation.
  47. yom - French translation.
  48. 50p - Polish translation.
  49. Zamaroht - Spanish translation.
  50. Los - Portuguese translation.
  51. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  52. me to strive to better.
  53. Pixels^ - Running XScripters where the idea was born.
  54. Matite - Pestering me to release it and using it.
  55. Very special thanks to:
  56. Thiadmer - PAWN, whose limits continue to amaze me!
  57. Kye/Kalcor - SA:MP.
  58. SA:MP Team past, present and future - SA:MP.
  59. Optional plugins:
  60. Gamer_Z - GPS.
  61. Incognito - Streamer.
  62. Me - sscanf2, fixes2, Whirlpool.
  63. */
  64. #define YSI_DIALOG_ID _A<_yD@>
  65. static stock
  66. YSI_g_sPlayerDialog[MAX_PLAYERS] = {-1, ...},
  67. bool:YSI_g_sPlayerMaster[MAX_PLAYERS] = {false, ...},
  68. Func:YSI_g_sPlayerCallback[MAX_PLAYERS]<iiiis>;
  69. stock Dialog_Get(playerid)
  70. {
  71. return YSI_g_sPlayerDialog[playerid];
  72. }
  73. remotefunc void:Dialog_Set(playerid, dialogid)
  74. {
  75. // If they could already see a dialog shown by this script, get rid of the
  76. // data from that one.
  77. YSI_g_sPlayerDialog[playerid] = dialogid;
  78. if (YSI_g_sPlayerMaster[playerid])
  79. {
  80. Indirect_Release(YSI_g_sPlayerCallback[playerid]),
  81. YSI_g_sPlayerCallback[playerid] = Func:0<iiiis>,
  82. YSI_g_sPlayerMaster[playerid] = false;
  83. }
  84. }
  85. stock Dialog_ShowCallback(playerid, Func:callback<iiiis>, style, const string:title[], const string:caption[], const string:button1[], const string:button2[] = "")
  86. {
  87. new
  88. ret = Dialog_Show(playerid, style, title, caption, button1, button2);
  89. Indirect_Claim(callback);
  90. YSI_g_sPlayerCallback[playerid] = callback;
  91. return ret;
  92. }
  93. #pragma deprecated Use Dialog_ShowCallback
  94. stock Dialog_ShowCallbackData(playerid, callback[E_CALLBACK_DATA], style, const string:title[], const string:caption[], const string:button1[], const string:button2[] = "")
  95. {
  96. new
  97. ret = Dialog_Show(playerid, style, title, caption, button1, button2);
  98. Indirect_Claim(callback[0]);
  99. YSI_g_sPlayerCallback[playerid] = F@_@iiiis:callback[0];
  100. return ret;
  101. }
  102. native Dialog_ShowPlayerNative(playerid, dialogid, style, const caption[], const info[], const button1[], const button2[]) = ShowPlayerDialog;
  103. stock Dialog_Show(playerid, style, const string:title[], const string:caption[], const string:button1[], const string:button2[] = "")
  104. {
  105. broadcastfunc Dialog_Set(playerid, YSI_DIALOG_ID);
  106. YSI_g_sPlayerMaster[playerid] = true;
  107. return Dialog_ShowPlayerNative(playerid, YSI_DIALOG_ID, style, title, caption, button1, button2);
  108. }
  109. stock Dialog_Hide(playerid)
  110. {
  111. // This almost looks like a Windows API function call!
  112. broadcastfunc Dialog_Set(playerid, -1);
  113. return Dialog_ShowPlayerNative(playerid, -1, 0, NULL, NULL, NULL, NULL);
  114. }
  115. HOOK__ OnPlayerDisconnect(playerid, reason)
  116. {
  117. #pragma unused reason
  118. // If this is a filterscript that has the currently displayed dialog in it,
  119. // then we need all scripts to know that this is no longer the case. If
  120. // this script is not in charge of the current dialog then do not broadcast
  121. // the reset, just do it locally.
  122. if (YSI_g_sPlayerMaster[playerid])
  123. Dialog_Hide(playerid);
  124. else
  125. YSI_g_sPlayerDialog[playerid] = -1;
  126. return 1;
  127. }
  128. HOOK__ OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  129. {
  130. // Apparently there's a hack to alter this.
  131. dialogid = YSI_g_sPlayerDialog[playerid];
  132. P:1("Dialog_OnDialogResponse called: %d %d %d %d %s", playerid, dialogid, response, listitem, inputtext);
  133. if (dialogid == YSI_DIALOG_ID)
  134. {
  135. if (YSI_g_sPlayerMaster[playerid])
  136. {
  137. new
  138. Func:callback<iiiis> = YSI_g_sPlayerCallback[playerid];
  139. YSI_g_sPlayerCallback[playerid] = Func:0<iiiis>;
  140. // Totally blank the stored dialog information, after making a local
  141. // copy of it for the sake of calling the callback. This is so that
  142. // we don't free the memory for the callback prematurely.
  143. broadcastfunc Dialog_Set(playerid, -1);
  144. // Call the callback.
  145. @.callback(playerid, YSI_DIALOG_ID, response, listitem, isnull(inputtext) ? ("\1") : inputtext);
  146. // Free the data.
  147. Indirect_Release(callback);
  148. return Y_HOOKS_BREAK_RETURN_1;
  149. }
  150. return Y_HOOKS_BREAK_RETURN_0;
  151. }
  152. else
  153. return Y_HOOKS_CONTINUE_RETURN_0;
  154. }
  155. stock _ShowPlayerDialog(playerid, dialog, style, const string:title[], const string:caption[], const string:button1[], const string:button2[])
  156. {
  157. // Fail.
  158. if (dialog == YSI_DIALOG_ID)
  159. return 0;
  160. broadcastfunc Dialog_Set(playerid, dialog);
  161. YSI_g_sPlayerMaster[playerid] = true;
  162. return ShowPlayerDialog(playerid, dialog, style, title, caption, button1, button2);
  163. }
  164. #if defined _ALS_ShowPlayerDialog
  165. #undef ShowPlayerDialog
  166. #else
  167. #define _ALS_ShowPlayerDialog
  168. #endif
  169. #define ShowPlayerDialog _ShowPlayerDialog
  170. #define _ALS_HidePlayerDialog
  171. #define HidePlayerDialog Dialog_Hide