Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- e_dialog by Eduardo AC © 2022
- OnOpenPlayerDialog(playerid, response_callback[])
- OnClosePlayerDialog(playerid, response_callback[], delay)
- ShowPlayerDialog(playerid, const response_callback[], style, const caption[], const info[], const button1[], const button2[])
- ShowDialogForPlayer(playerid, style, const caption[], const info[], const button1[], const button2[], const response_callback[])
- HasPlayerOpenDialog(playerid)
- GetPlayerDialogResponseName(playerid)
- GetLastPlayerDialogResponseName(playerid)
- ClosePlayerDialog(playerid, bool:blank_dialog = false)
- OpenLastPlayerDialog(playerid)
- */
- #if defined _e_dialog_included
- #endinput
- #endif
- #define _e_dialog_included
- #pragma library e_dialog
- #define E_DIALOG_HOOK false
- #define E_DIALOG_ID 32760
- #define E_DIALOG_CLOSE_CHECK 1500
- static __playerDialogResponse[MAX_PLAYERS][32];
- static __playerTimerCheckDialogClose[MAX_PLAYERS] = {-1, ...};
- // Last dialog
- static __playerLastDialogStyle[MAX_PLAYERS] = {-1, ...};
- static __playerLastDialogCaption[MAX_PLAYERS][128];
- static __playerLastDialogInfo[MAX_PLAYERS][4096];
- static __playerLastDialogButton1[MAX_PLAYERS][20];
- static __playerLastDialogButton2[MAX_PLAYERS][20];
- static __playerLastDialogResponse[MAX_PLAYERS][32];
- forward OnOpenPlayerDialog(playerid, response_callback[]);
- forward OnClosePlayerDialog(playerid, response_callback[], delay);
- public OnPlayerDisconnect(playerid, reason)
- {
- KillTimer(__playerTimerCheckDialogClose[playerid]);
- __playerTimerCheckDialogClose[playerid] = -1;
- __playerDialogResponse[playerid][0] = '\0';
- __playerLastDialogStyle[playerid] = -1;
- __playerLastDialogCaption[playerid][0] = '\0';
- __playerLastDialogInfo[playerid][0] = '\0';
- __playerLastDialogButton1[playerid][0] = '\0';
- __playerLastDialogButton2[playerid][0] = '\0';
- __playerLastDialogResponse[playerid][0] = '\0';
- #if defined e_dialog_OnPlayerDisconnect
- e_dialog_OnPlayerDisconnect(playerid, reason);
- #endif
- return true;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == E_DIALOG_ID)
- {
- if(__playerDialogResponse[playerid][0] != '\0')
- {
- new response_callback[32];
- strcat(response_callback, __playerDialogResponse[playerid]);
- __playerDialogResponse[playerid][0] = '\0';
- if(inputtext[0] != '\0')
- {
- for(new i = 0, len = strlen(inputtext); i < len; i ++)
- {
- if(inputtext[i] == '%')
- inputtext[i] = '#';
- }
- CallLocalFunction(response_callback, "iiis", playerid, response, listitem, inputtext);
- }
- else
- CallLocalFunction(response_callback, "iii", playerid, response, listitem);
- }
- return false;
- }
- #if defined e_dialog_OnDialogResponse
- e_dialog_OnDialogResponse(playerid, dialogid, response, listitem, inputtext);
- #endif
- return true;
- }
- forward Timer_CheckDialogClose(playerid, response_callback[], tick);
- public Timer_CheckDialogClose(playerid, response_callback[], tick)
- {
- if(__playerDialogResponse[playerid][0] == '\0')
- {
- KillTimer(__playerTimerCheckDialogClose[playerid]);
- __playerTimerCheckDialogClose[playerid] = -1;
- CallLocalFunction("OnClosePlayerDialog", "isi", playerid, response_callback, (gettime() - tick));
- }
- return true;
- }
- /// <summary>
- /// Função interna para abrir uma caixa de diálogo.
- /// </summary>
- /// <param name="playerid">ID do jogador</param>
- /// <param name="style">ID do estilo de caixa</param>
- /// <param name="caption">Título da caixa</param>
- /// <param name="info">Informação da caixa</param>
- /// <param name="button1">Texto do botão 1</param>
- /// <param name="button2">Texto do botão 2</param>
- /// <param name="response_callback">Callback de resposta dos botões</param>
- /// <returns>True para sucesso ou False para erro</returns>
- static stock __dialogContent(playerid, style, const caption[], const info[], const button1[], const button2[], const response_callback[])
- {
- if(!IsPlayerConnected(playerid))
- return false;
- __playerLastDialogStyle[playerid] = style;
- format(__playerLastDialogCaption[playerid], 128, "%s", caption);
- format(__playerLastDialogInfo[playerid], 4096, "%s", info);
- format(__playerLastDialogButton1[playerid], 20, "%s", button1);
- format(__playerLastDialogButton2[playerid], 20, "%s", button2);
- format(__playerLastDialogResponse[playerid], 32, "%s", response_callback);
- if(response_callback[0] != '\0')
- {
- strcat((__playerDialogResponse[playerid][0] = '\0', __playerDialogResponse[playerid]), response_callback);
- KillTimer(__playerTimerCheckDialogClose[playerid]);
- __playerTimerCheckDialogClose[playerid] = SetTimerEx("Timer_CheckDialogClose", E_DIALOG_CLOSE_CHECK, true, "isi", playerid, response_callback, gettime());
- }
- ShowPlayerDialog(playerid, E_DIALOG_ID, style, caption, info, button1, button2);
- CallLocalFunction("OnOpenPlayerDialog", "is", playerid, !strlen(response_callback) ? ("<null>") : response_callback);
- return true;
- }
- #if E_DIALOG_HOOK
- stock e_dialog_ShowPlayerDialog(playerid, const response_callback[], style, const caption[], const info[], const button1[], const button2[])
- {
- return __dialogContent(playerid, style, caption, info, button1, button2, response_callback);
- }
- #if defined _ALS_ShowPlayerDialog
- #undef ShowPlayerDialog
- #else
- #define _ALS_ShowPlayerDialog
- #endif
- #define ShowPlayerDialog e_dialog_ShowPlayerDialog
- #endif
- stock ShowDialogForPlayer(playerid, style, const caption[], const info[], const button1[], const button2[], const response_callback[])
- {
- return __dialogContent(playerid, style, caption, info, button1, button2, response_callback);
- }
- /// <summary>
- /// Retorna se o jogador possui uma caixa de diálogo (e_dialog) aberta.
- /// </summary>
- /// <param name="playerid">ID do jogador</param>
- /// <returns>True para aberta ou False para fechada</returns>
- stock HasPlayerOpenDialog(playerid)
- {
- if(!IsPlayerConnected(playerid))
- return false;
- return __playerTimerCheckDialogClose[playerid] > -1;
- }
- /// <summary>
- /// Retorna o nome da callback de resposta que está ativa na tela do jogador.
- /// </summary>
- /// <param name="playerid">ID do jogador</param>
- /// <returns>Nome da callback de resposta</returns>
- stock GetPlayerDialogResponseName(playerid)
- {
- new dname[32];
- if(!IsPlayerConnected(playerid))
- return dname;
- if(__playerTimerCheckDialogClose[playerid] == -1)
- return dname;
- strcat(dname, __playerLastDialogResponse[playerid]);
- return dname;
- }
- /// <summary>
- /// Retorna o nome da última callback de resposta chamada para o jogador (ativa ou não).
- /// </summary>
- /// <param name="playerid">ID do jogador</param>
- /// <returns>Nome da última callback de resposta</returns>
- stock GetLastPlayerDialogResponseName(playerid)
- {
- new dname[32];
- if(!IsPlayerConnected(playerid))
- return dname;
- strcat(dname, __playerLastDialogResponse[playerid]);
- return dname;
- }
- /// <summary>
- /// Força a chamada da função "OnClosePlayerDialog" e remove o suporte a respostas da caixa de diálogo aberta.
- /// </summary>
- /// <param name="playerid">ID do jogador</param>
- /// <param name="blank_dialog">Quando verdadeiro abre uma caixa de diálogo vazia no lugar da anterior.</param>
- /// <returns>True para sucesso ou False para erro</returns>
- stock ClosePlayerDialog(playerid, bool:blank_dialog = false)
- {
- if(!IsPlayerConnected(playerid))
- return false;
- __playerDialogResponse[playerid][0] = '\0';
- if(blank_dialog && __playerTimerCheckDialogClose[playerid] > -1)
- __dialogContent(playerid, DIALOG_STYLE_MSGBOX, " ", " ", " ", "", "");
- return true;
- }
- /// <summary>
- /// Abre a última caixa de diálogo fechada.
- /// </summary>
- /// <param name="playerid">ID do jogador</param>
- /// <returns>True para sucesso ou False para erro</returns>
- stock OpenLastPlayerDialog(playerid)
- {
- if(!IsPlayerConnected(playerid))
- return false;
- __dialogContent(playerid,
- __playerLastDialogStyle[playerid],
- __playerLastDialogCaption[playerid],
- __playerLastDialogInfo[playerid],
- __playerLastDialogButton1[playerid],
- __playerLastDialogButton2[playerid],
- __playerLastDialogResponse[playerid]);
- return true;
- }
- // ---------------- HOOK ----------------
- #if defined _ALS_OnPlayerDisconnect
- #undef OnPlayerDisconnect
- #else
- #define _ALS_OnPlayerDisconnect
- #endif
- #define OnPlayerDisconnect e_dialog_OnPlayerDisconnect
- #if defined e_dialog_OnPlayerDisconnect
- forward e_dialog_OnPlayerDisconnect(playerid, reason);
- #endif
- #if defined _ALS_OnDialogResponse
- #undef OnDialogResponse
- #else
- #define _ALS_OnDialogResponse
- #endif
- #define OnDialogResponse e_dialog_OnDialogResponse
- #if defined e_dialog_OnDialogResponse
- forward e_dialog_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement