Skip to content

Commit

Permalink
Merge pull request #8 from ZantetsukenGT/master
Browse files Browse the repository at this point in the history
API Change to add support for inputtext to callbacks
  • Loading branch information
Nickk888SAMP authored Aug 23, 2022
2 parents c5f5c9c + 513035c commit e4dc657
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions ndialog-pages.inc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ stock ClearDialogListitems(playerid)
NDP_P[playerid][ndp_button2] = 0;
NDP_P[playerid][ndp_nextButton] = 0;
NDP_P[playerid][ndp_backButton] = 0;
NDP_P[playerid][ndp_dialogName] = 0;
NDP_P[playerid][ndp_dialogName][0] = EOS;
//Logger for Debug purpose
#if defined _logger_included
Logger_Log("ndialog-pages",
Expand Down Expand Up @@ -207,9 +207,14 @@ static stock NDP_DialogInvoke(playerid, type, const function[], dialogid, style,
NDP_P[playerid][ndp_amountPerPage] = items_per_page;
NDP_P[playerid][ndp_endIndex] = 0;
NDP_P[playerid][ndp_type] = type;
NDP_P[playerid][ndp_dialogName][0] = EOS;

// Packs the function name into ndp_dialogName
strpack(NDP_P[playerid][ndp_dialogName], function, 32 char);
new bool: functionIsPacked = ispacked(function);
if (functionIsPacked)
strunpack(NDP_P[playerid][ndp_dialogName], function);
else
strcat(NDP_P[playerid][ndp_dialogName], function);

// Saving all strings into the corresponding variables
format(NDP_P[playerid][ndp_button1], 64, button1);
Expand Down Expand Up @@ -387,7 +392,7 @@ static stock NDP_ProcessDialogResponse(playerid, dialogid, response, listitem, i
case NDP_DIALOG_TYPE_DIALOG: // Normal Dialog
{
dialogid = 32701;
new ndp_d_str[40], ndp_d_dnu[32];
new ndp_d_str[32], ndp_d_dnu[32];

// Sanitize inputs.
for (new i = 0, l = strlen(inputtext); i < l; i ++)
Expand All @@ -399,7 +404,7 @@ static stock NDP_ProcessDialogResponse(playerid, dialogid, response, listitem, i
}

// Create the function string
strunpack(ndp_d_dnu, NDP_P[playerid][ndp_dialogName], 32);
strcat(ndp_d_dnu, NDP_P[playerid][ndp_dialogName]);
strcat(ndp_d_str, "ndpD_");
strcat(ndp_d_str, ndp_d_dnu);

Expand All @@ -416,7 +421,7 @@ static stock NDP_ProcessDialogResponse(playerid, dialogid, response, listitem, i
if(listitem != INVALID_LISTITEM)
{
// Call the function
CallLocalFunction(ndp_d_str, "ddd", playerid, response, listitem);
CallLocalFunction(ndp_d_str, "ddds", playerid, response, listitem, inputtext);
#if defined _logger_included
Logger_Log("ndialog-pages",
Logger_S("callback", "OnDialogResponse - CallLocalFunction"));
Expand Down
4 changes: 2 additions & 2 deletions ndp_examples.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ CMD:ndptest3(playerid, params[]) // DIALOG_STYLE_TABLIST_HEADERS

/* Callback */

DialogPages:NDP_Test(playerid, response, listitem)
DialogPages:NDP_Test(playerid, response, listitem, inputtext[])
{
if(!response)
return 1;

format(ndp_e_str, sizeof ndp_e_str, "[NDialog-Pages] You have selected listitem ID: %i", listitem);
format(ndp_e_str, sizeof ndp_e_str, "[NDialog-Pages] You have selected listitem ID: {666666}%i{FFFFFF}, listitem's text: {666666}%s", listitem, inputtext);
SendClientMessage(playerid, -1, ndp_e_str);
print(ndp_e_str);
return 1;
Expand Down

0 comments on commit e4dc657

Please sign in to comment.