Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few code optimization. #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions easyDialog.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Created by Emmet on Friday, January 24, 2014.

Updated by Southclaws 2017-10-13 to add include guard.
Updated by Akshay Mohan "ParK_iY" on 2017-05-15 with few code optimization.
*/

#if defined _easyDialog_included
Expand All @@ -31,9 +32,13 @@
#define Dialog_Opened(%0) \
(CallRemoteFunction("Dialog_IsOpened", "i", (%0)))

#if !defined EASYDIALOG_SANITIZE_INPUT
#define EASYDIALOG_SANITIZE_INPUT 1
#endif

static
s_DialogName[MAX_PLAYERS][32 char],
s_DialogOpened[MAX_PLAYERS]
bool:s_DialogOpened[MAX_PLAYERS]
;

forward OnDialogPerformed(playerid, dialog[], response, success);
Expand All @@ -45,13 +50,13 @@ forward @dialog_format(); @dialog_format() {
forward Dialog_IsOpened(playerid);
public Dialog_IsOpened(playerid)
{
return (s_DialogOpened[playerid]);
return !!(s_DialogOpened[playerid]);
}

stock Dialog_Close(playerid)
{
s_DialogName[playerid]{0} = 0;
s_DialogOpened[playerid] = 0;
s_DialogOpened[playerid] = false;

return ShowPlayerDialog(playerid, -1, DIALOG_STYLE_MSGBOX, " ", " ", " ", "");
}
Expand All @@ -63,7 +68,7 @@ stock Dialog_Open(playerid, function[], style, caption[], info[], button1[], but
args
;

if (!strlen(info))
if (info[0] == '\0')
{
return 0;
}
Expand Down Expand Up @@ -98,7 +103,7 @@ stock Dialog_Open(playerid, function[], style, caption[], info[], button1[], but
{
ShowPlayerDialog(playerid, 32700, style, caption, info, button1, button2);
}
s_DialogOpened[playerid] = 1;
s_DialogOpened[playerid] = true;

strpack(s_DialogName[playerid], function, 32 char);

Expand All @@ -114,7 +119,7 @@ public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
s_Public = funcidx("OnDialogPerformed");
}

#if EASYDIALOG_SANITIZE_INPUT == 1
// Sanitize inputs.
for (new i = 0, l = strlen(inputtext); i < l; i ++)
{
Expand All @@ -123,12 +128,12 @@ public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
inputtext[i] = '#';
}
}
if (dialogid == 32700 && strlen(s_DialogName[playerid]) > 0)
#endif
if (dialogid == 32700 && s_DialogName[playerid]{0} != '\0')
{
new
string[40];
string[40] = "dialog_";

strcat(string, "dialog_");
strcat(string, s_DialogName[playerid]);

Dialog_Close(playerid);
Expand Down