Advertisement
Untonyst

u_dialog.inc

Aug 30th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.19 KB | None | 0 0
  1. /*
  2.  *  Fast and simple dialog processor.
  3.  *  
  4.  *  Copyright (c) 2016 Anton Styazhkin (Untonyst).
  5.  *  
  6.  *  This software is provided 'as-is', without any express or implied warranty.
  7.  *  In no event will the authors be held liable for any damages arising
  8.  *  from the use of this software.
  9.  *  
  10.  *  Permission is granted to anyone to use this software for
  11.  *  any purpose, including commercial applications, and to alter it and
  12.  *  redistribute it freely, subject to the following restrictions:
  13.  *  
  14.  *  1.  The origin of this software must not be misrepresented; you must not
  15.  *      claim that you wrote the original software. If you use this software in
  16.  *      a product, an acknowledgment in the product documentation would be
  17.  *      appreciated but is not required.
  18.  *  2.  Altered source versions must be plainly marked as such, and must not be
  19.  *      misrepresented as being the original software.
  20.  *  3.  This notice may not be removed or altered from any source distribution.
  21.  */
  22.  
  23. #if !defined _samp_included
  24.     #error Please include <a_npc> or <a_samp> first.
  25. #endif
  26.  
  27. #if defined _u_dialog_included
  28.     #error Include <u_dialog> already included.
  29. #endif
  30. #define _u_dialog_included
  31.  
  32. #if !defined MAX_FUNC_NAME
  33.     #define MAX_FUNC_NAME                       (31)
  34. #endif
  35. #if !defined PRIVATE_DIALOG_ID
  36.     #define PRIVATE_DIALOG_ID                   (32767)
  37. #endif
  38. #if !defined MAX_DIALOG_NAME
  39.     #define MAX_DIALOG_NAME                     (MAX_FUNC_NAME)
  40. #endif
  41.  
  42. #if !defined isnull
  43.     #define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
  44. #endif
  45.  
  46. #define DialogResponse:%0(%1,%2,%3,%4)\
  47.         forward %0(%1,%2,%3,%4);\
  48.         public %0(%1,%2,%3,%4)
  49.  
  50. static func_dlg[MAX_PLAYERS][MAX_DIALOG_NAME + 1 char];
  51.  
  52. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  53. {
  54.     #if defined OnDialogPerformed
  55.         if (OnDialogPerformed(playerid, func_dlg[playerid],
  56.                 response, funcidx(func_dlg[playerid])) == 0)
  57.         {
  58.             return 0;
  59.         }
  60.     #endif
  61.    
  62.     if (dialogid == PRIVATE_DIALOG_ID)
  63.     {
  64.         if (inputtext[0] == '\0')
  65.         {
  66.             inputtext[0] = '\1';
  67.         }
  68.         else
  69.         {
  70.             new i, c;
  71.             while ((c = inputtext[i]) != '\0')
  72.             {
  73.                 if (c == '%')
  74.                 {
  75.                     inputtext[i] = '#';
  76.                 }
  77.                 i++;
  78.             }
  79.         }
  80.         CallLocalFunction(func_dlg[playerid], "ddds",
  81.             playerid, response, listitem, inputtext);
  82.         return 1;
  83.     }
  84.    
  85.     #if defined u_dlg__OnDialogResponse
  86.         return u_dlg__OnDialogResponse(playerid, dialogid,
  87.                     response, listitem, inputtext);
  88.     #else
  89.         return 0;
  90.     #endif
  91. }
  92. #if defined _ALS_OnDialogResponse
  93.     #undef OnDialogResponse
  94. #else
  95.     #define _ALS_OnDialogResponse
  96. #endif
  97. #define OnDialogResponse u_dlg__OnDialogResponse
  98. #if defined u_dlg__OnDialogResponse
  99. forward u_dlg__OnDialogResponse(playerid, dialogid,
  100.             response, listitem, inputtext[]);
  101. #endif
  102.  
  103. stock
  104.     DialogShowForPlayer(playerid, function[],
  105.         style, caption[], info[], button1[], button2[])
  106. {
  107.     if (IsPlayerConnected(playerid) == 0)
  108.         return 0;  
  109.     strpack(func_dlg[playerid], function);
  110.     ShowPlayerDialog(playerid, PRIVATE_DIALOG_ID,
  111.         style, caption, info, button1, button2);
  112.     return 1;
  113. }
  114. #define ShowPlayerDialogEx DialogShowForPlayer
  115.  
  116. #if defined OnDialogPerformed
  117. forward OnDialogPerformed(playerid, function[], response, success);
  118. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement