Advertisement
Sasino97

[NO LANG]Sasinosoft Dialogs

Jul 3rd, 2011
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.54 KB | None | 0 0
  1. /*         Sasi-Dialogs
  2.  *
  3.  *   Copyright 2011, [GF]Sasino97
  4.  *
  5. */
  6.  
  7. #if defined _sasi_dialogs_included
  8.     #endinput
  9. #endif
  10. #define _sasi_dialogs_included
  11.  
  12. #pragma library _sasi_dialogs
  13.  
  14. #define MAX_DIALOGS 1000
  15. #define DIALOG_STYLE_QUESTION 3
  16.  
  17. enum dInfo
  18. {
  19.   Dexists,
  20.   Dstyle,
  21.   Dcaption[256],
  22.   Dinfo[256],
  23.   Dbutton1[11],
  24.   Dbutton2[11]
  25. }
  26.  
  27. new DialogInfo[MAX_DIALOGS][dInfo];
  28. new count;
  29.  
  30. forward OnPlayerAcceptMessage(playerid, dialogid);
  31. forward OnPlayerInput(playerid, dialogid, inputtext[]);
  32. forward OnPlayerSelectListItem(playerid, dialogid, listitem);
  33. forward OnPlayerAnswerQuestion(playerid, dialogid, response);
  34.  
  35. stock CreateDialog(style, caption[], info[], button1[], button2[])
  36. {
  37.   count ++;
  38.   new dialogid = count;
  39.   DialogInfo[dialogid][Dexists] = true;
  40.   DialogInfo[dialogid][Dstyle] = style;
  41.   format(DialogInfo[dialogid][Dcaption], 256, caption);
  42.   format(DialogInfo[dialogid][Dinfo], 256, items);
  43.   format(DialogInfo[dialogid][Dbutton1], 256, button1);
  44.   format(DialogInfo[dialogid][Dbutton2], 256, button2);
  45.   return dialogid;
  46. }
  47.  
  48. stock CreateInputWindow(caption[], info[], button1[], button2[])
  49. {
  50.   count ++;
  51.   new dialogid = count;
  52.   DialogInfo[dialogid][Dexists] = true;
  53.   DialogInfo[dialogid][Dstyle] = DIALOG_STYLE_INPUT;
  54.   format(DialogInfo[dialogid][Dcaption], 256, caption);
  55.   format(DialogInfo[dialogid][Dinfo], 256, info);
  56.   format(DialogInfo[dialogid][Dbutton1], 256, button1);
  57.   format(DialogInfo[dialogid][Dbutton2], 256, button2);
  58.   return dialogid;
  59. }
  60.  
  61. stock CreateQuestion(caption[], question[])
  62. {
  63.   count ++;
  64.   new dialogid = count;
  65.   DialogInfo[dialogid][Dexists] = true;
  66.   DialogInfo[dialogid][Dstyle] = DIALOG_STYLE_QUESTION;
  67.   format(DialogInfo[dialogid][Dcaption], 256, caption);
  68.   format(DialogInfo[dialogid][Dinfo], 256, question);
  69.   format(DialogInfo[dialogid][Dbutton1], 256, "Yes");
  70.   format(DialogInfo[dialogid][Dbutton2], 256, "No");
  71.   return dialogid;
  72. }
  73.  
  74. stock CreateMessage(message[])
  75. {
  76.   count ++;
  77.   new dialogid = count;
  78.   DialogInfo[dialogid][Dexists] = true;
  79.   DialogInfo[dialogid][Dstyle] = DIALOG_STYLE_MSGBOX;
  80.   format(DialogInfo[dialogid][Dcaption], 256, "");
  81.   format(DialogInfo[dialogid][Dinfo], 256, message);
  82.   format(DialogInfo[dialogid][Dbutton1], 256, "OK");
  83.   format(DialogInfo[dialogid][Dbutton2], 256, "");
  84.   return dialogid;
  85. }
  86.  
  87. stock CreateList(caption[], items[], button1[], button2[])
  88. {
  89.   count ++;
  90.   new dialogid = count;
  91.   DialogInfo[dialogid][Dexists] = true;
  92.   DialogInfo[dialogid][Dstyle] = DIALOG_STYLE_LIST;
  93.   format(DialogInfo[dialogid][Dcaption], 256, caption);
  94.   format(DialogInfo[dialogid][Dinfo], 256, items);
  95.   format(DialogInfo[dialogid][Dbutton1], 256, button1);
  96.   format(DialogInfo[dialogid][Dbutton2], 256, button2);
  97.   return dialogid;
  98. }
  99.  
  100. stock DialogShowForPlayer(playerid, dialogid)
  101. {
  102.   if(DialogInfo[dialogid][Dstyle] == DIALOG_STYLE_QUESTION) return ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, DialogInfo[dialogid][Dcaption], DialogInfo[dialogid][Dinfo], DialogInfo[dialogid][Dbutton1], DialogInfo[dialogid][Dbutton2]);
  103.   ShowPlayerDialog(playerid, dialogid, DialogInfo[dialogid][Dstyle], DialogInfo[dialogid][Dcaption], DialogInfo[dialogid][Dinfo], DialogInfo[dialogid][Dbutton1], DialogInfo[dialogid][Dbutton2]);
  104.   return 1;
  105. }
  106.  
  107. stock DestroyDialog(dialogid)
  108. {
  109.   DialogInfo[dialogid][Dexists] = false;
  110.   DialogInfo[dialogid][Dstyle] = 4;
  111.   format(DialogInfo[dialogid][Dcaption], 256, "_");
  112.   format(DialogInfo[dialogid][Dinfo], 256, "_");
  113.   format(DialogInfo[dialogid][Dbutton1], 256, "_");
  114.   format(DialogInfo[dialogid][Dbutton2], 256, "_");
  115.   return 1;
  116. }
  117.  
  118. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  119. {
  120.   if(DialogInfo[dialogid][Dstyle] == DIALOG_STYLE_MSGBOX)
  121.   {
  122.     return CallLocalFunction("OnPlayerAcceptMessage", "ii", playerid, dialogid);
  123.   }
  124.   else if(DialogInfo[dialogid][Dstyle] == DIALOG_STYLE_INPUT)
  125.   {
  126.     return CallLocalFunction("OnPlayerInput", "iis", playerid, dialogid, inputtext);
  127.   }
  128.   else if(DialogInfo[dialogid][Dstyle] == DIALOG_STYLE_LIST)
  129.   {
  130.     return CallLocalFunction("OnPlayerSelectListItem", "iii", playerid, dialogid, listitem);
  131.   }
  132.   else if(DialogInfo[dialogid][Dstyle] == DIALOG_STYLE_QUESTION)
  133.   {
  134.     return CallLocalFunction("OnPlayerAnswerQuestion", "iii", playerid, dialogid, response);
  135.   }
  136.   return 0;
  137. }
  138.  
  139. #if defined _ALS_OnDialogResponse
  140.     #undef OnDialogResponse
  141. #else
  142.     #define _ALS_OnDialogResponse
  143. #endif
  144. #define OnDialogResponse SD_OnDialogResponse
  145.  
  146. forward SD_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement