Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Simple Dialog Library
- *
- * Copyright (c) 2022 VVWVV
- *
- * This software is provided 'as-is', without any express or implied warranty.
- * In no event will the authors be held liable for any damages arising from the
- * use of this software.
- *
- * Permission is granted to anyone to use this software for
- * any purpose, including commercial applications, and to alter it and
- * redistribute it freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software in
- * a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- *
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- *
- * 3. This notice may not be removed or altered from any source distribution.
- */
- #if !defined BYTES_PER_CELL
- const BYTES_PER_CELL = cellbits / charbits;
- #endif
- #if !defined DIALOG_ID
- #define DIALOG_ID (32767)
- #endif
- #define DIALOG:%1(%2) \
- @D_(%2) <dialogState_:%1>
- #define Dialog_Show(%1,%2,%3,%4,%5,%6,%7) \
- state ( \
- ShowPlayerDialog((%1), DIALOG_ID, (%3), (%4), (%5), (%6), (%7)), \
- ( \
- Dialog_State_[(%1)] = __emit( \
- LCTRL 6, \
- MOVE.alt, \
- LCTRL 0, \
- ADD, \
- MOVE.alt, \
- LCTRL 1, \
- XCHG, \
- SUB, \
- CONST.alt (21 * BYTES_PER_CELL), \
- ADD, \
- STOR.pri Dialog_Addr_, \
- LREF.pri Dialog_Addr_ \
- ) \
- ) \
- ) dialogState_:%2
- stock Dialog_State_[MAX_PLAYERS];
- stock Dialog_Addr_;
- static stock Dialog_StateTableAddr_;
- forward @D_(playerid, response, listitem, const inputtext[]);
- DIALOG:INTERNAL_(playerid, response, listitem, const inputtext[])
- {
- /* Nothing here. This dialog for internal use. */
- return;
- }
- stock Dialog_Init()
- {
- const OFFSET_TO_STATE = -4 * BYTES_PER_CELL;
- new addr;
- state dialogState_:INTERNAL_;
- Dialog_StateTableAddr_ = __emit(
- LCTRL 6,
- MOVE.alt,
- LCTRL 0,
- ADD,
- MOVE.alt,
- LCTRL 1,
- XCHG,
- SUB,
- CONST.alt OFFSET_TO_STATE,
- ADD,
- STOR.S.pri addr,
- LREF.S.pri addr
- );
- }
- stock Dialog_Close(playerid)
- {
- static const s = !" ";
- ShowPlayerDialog(player, -1, DIALOG_STYLE_MSGBOX, s, s, s, s);
- }
- public OnDialogResponse(playerid, dialogid, response, listitem,
- inputtext[])
- {
- if (DIALOG_ID != dialogid)
- goto skip_dialog;
- new playerState = Dialog_State_[playerid];
- __emit(
- LOAD.S.pri playerState,
- SREF.pri Dialog_StateTableAddr_
- );
- @D_(playerid, response, listitem, inputtext);
- skip_dialog:
- #if defined Dialog_OnDialogResponse
- return Dialog_OnDialogResponse(playerid, dialogid, response, listitem,
- inputtext);
- #else
- return 0;
- #endif
- }
- #if defined _ALS_OnDialogResponse
- #undef OnDialogResponse
- #else
- #define _ALS_OnDialogResponse
- #endif
- #define OnDialogResponse Dialog_OnDialogResponse
- #if defined Dialog_OnDialogResponse
- forward Dialog_OnDialogResponse(playerid, dialogid, response, listitem,
- inputtext[]);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement