Advertisement
Guest User

Simple Dialog

a guest
Aug 10th, 2022
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.38 KB | None | 0 0
  1. /*
  2.  * Simple Dialog Library
  3.  *
  4.  * Copyright (c) 2022 VVWVV
  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 from the
  8.  * 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.  *
  19.  * 2.   Altered source versions must be plainly marked as such, and must not be
  20.  *  misrepresented as being the original software.
  21.  *
  22.  * 3.   This notice may not be removed or altered from any source distribution.
  23.  */
  24.  
  25. #if !defined BYTES_PER_CELL
  26. const BYTES_PER_CELL = cellbits / charbits;
  27. #endif
  28.  
  29. #if !defined DIALOG_ID
  30.     #define DIALOG_ID (32767)
  31. #endif
  32.  
  33. #define DIALOG:%1(%2) \
  34.     @D_(%2) <dialogState_:%1>
  35.  
  36. #define Dialog_Show(%1,%2,%3,%4,%5,%6,%7) \
  37.     state ( \
  38.         ShowPlayerDialog((%1), DIALOG_ID, (%3), (%4), (%5), (%6), (%7)), \
  39.         ( \
  40.             Dialog_State_[(%1)] = __emit( \
  41.                 LCTRL 6, \
  42.                 MOVE.alt, \
  43.                 LCTRL 0, \
  44.                 ADD, \
  45.                 MOVE.alt, \
  46.                 LCTRL 1, \
  47.                 XCHG, \
  48.                 SUB, \
  49.                 CONST.alt (21 * BYTES_PER_CELL), \
  50.                 ADD, \
  51.                 STOR.pri Dialog_Addr_, \
  52.                 LREF.pri Dialog_Addr_ \
  53.             ) \
  54.         ) \
  55.     ) dialogState_:%2
  56.  
  57. stock Dialog_State_[MAX_PLAYERS];
  58. stock Dialog_Addr_;
  59.  
  60. static stock Dialog_StateTableAddr_;
  61.  
  62. forward @D_(playerid, response, listitem, const inputtext[]);
  63.  
  64. DIALOG:INTERNAL_(playerid, response, listitem, const inputtext[])
  65. {
  66.     /* Nothing here.  This dialog for internal use. */
  67.     return;
  68. }
  69.  
  70. stock Dialog_Init()
  71. {
  72.     const OFFSET_TO_STATE = -4 * BYTES_PER_CELL;
  73.     new addr;
  74.     state dialogState_:INTERNAL_;
  75.     Dialog_StateTableAddr_ = __emit(
  76.         LCTRL 6,
  77.         MOVE.alt,
  78.         LCTRL 0,
  79.         ADD,
  80.         MOVE.alt,
  81.         LCTRL 1,
  82.         XCHG,
  83.         SUB,
  84.         CONST.alt OFFSET_TO_STATE,
  85.         ADD,
  86.         STOR.S.pri addr,
  87.         LREF.S.pri addr
  88.     );
  89. }
  90.  
  91. stock Dialog_Close(playerid)
  92. {
  93.     static const s = !" ";
  94.     ShowPlayerDialog(player, -1, DIALOG_STYLE_MSGBOX, s, s, s, s);
  95. }
  96.  
  97. public OnDialogResponse(playerid, dialogid, response, listitem,
  98.     inputtext[])
  99. {
  100.     if (DIALOG_ID != dialogid)
  101.         goto skip_dialog;
  102.     new playerState = Dialog_State_[playerid];
  103.     __emit(
  104.         LOAD.S.pri playerState,
  105.         SREF.pri Dialog_StateTableAddr_
  106.     );
  107.     @D_(playerid, response, listitem, inputtext);
  108. skip_dialog:
  109. #if defined Dialog_OnDialogResponse
  110.     return Dialog_OnDialogResponse(playerid, dialogid, response, listitem,
  111.         inputtext);
  112. #else
  113.     return 0;
  114. #endif
  115. }
  116.  
  117. #if defined _ALS_OnDialogResponse
  118.     #undef OnDialogResponse
  119. #else
  120.     #define _ALS_OnDialogResponse
  121. #endif
  122. #define OnDialogResponse Dialog_OnDialogResponse
  123.  
  124. #if defined Dialog_OnDialogResponse
  125. forward Dialog_OnDialogResponse(playerid, dialogid, response, listitem,
  126.     inputtext[]);
  127. #endif
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement