forked from Awsomedude/easyDialog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easyDialog.inc
160 lines (128 loc) · 3.35 KB
/
easyDialog.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
easyDialog.inc - Dialogs made easier!
With this useful include, scripters can easily create
dialogs and show them to players.
This include will prevent dialog spoofing, ID collision
and a lot more.
Created by Emmet on Friday, January 24, 2014.
Updated by Southclaws 2017-10-13 to add include guard.
*/
#if defined _easyDialog_included
#endinput
#endif
#define _easyDialog_included
#if !defined isnull
#define isnull(%1) \
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
#define Dialog:%0(%1) \
forward dialog_%0(%1); public dialog_%0(%1)
#define Dialog_Show(%0,%1, \
Dialog_Open(%0, #%1,
#define Dialog_Opened(%0) \
(CallRemoteFunction("Dialog_IsOpened", "i", (%0)))
static
s_DialogName[MAX_PLAYERS][32 char],
s_DialogOpened[MAX_PLAYERS]
;
forward OnDialogPerformed(playerid, dialog[], response, success);
forward @dialog_format(); @dialog_format() {
format("", 0, "");
}
forward Dialog_IsOpened(playerid);
public Dialog_IsOpened(playerid)
{
return (s_DialogOpened[playerid]);
}
stock Dialog_Close(playerid)
{
s_DialogName[playerid]{0} = 0;
s_DialogOpened[playerid] = 0;
return ShowPlayerDialog(playerid, -1, DIALOG_STYLE_MSGBOX, " ", " ", " ", "");
}
stock Dialog_Open(playerid, function[], style, caption[], info[], button1[], button2[], {Float,_}:...)
{
static
string[4096],
args
;
if (!strlen(info))
{
return 0;
}
if ((args = numargs()) > 7)
{
while (--args >= 7)
{
#emit LCTRL 5
#emit LOAD.alt args
#emit SHL.C.alt 2
#emit ADD.C 12
#emit ADD
#emit LOAD.I
#emit PUSH.pri
}
#emit PUSH.S info
#emit PUSH.C 4096
#emit PUSH.C string
#emit LOAD.S.pri 8
#emit CONST.alt 16
#emit SUB
#emit PUSH.pri
#emit SYSREQ.C format
#emit LCTRL 5
#emit SCTRL 4
ShowPlayerDialog(playerid, 32000, style, caption, string, button1, button2);
}
else
{
ShowPlayerDialog(playerid, 32000, style, caption, info, button1, button2);
}
s_DialogOpened[playerid] = 1;
strpack(s_DialogName[playerid], function, 32 char);
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
static
s_Public = cellmax;
if (s_Public == cellmax)
{
s_Public = funcidx("OnDialogPerformed");
}
// Sanitize inputs.
for (new i = 0, l = strlen(inputtext); i < l; i ++)
{
if (inputtext[i] == '%' || inputtext[i] == '{')
{
inputtext[i] = '#';
}
}
if (dialogid == 32000 && strlen(s_DialogName[playerid]) > 0)
{
new
string[40];
strcat(string, "dialog_");
strcat(string, s_DialogName[playerid]);
s_DialogName[playerid]{0} = 0;
s_DialogOpened[playerid] = 0;
if ((s_Public == -1) || (CallLocalFunction("OnDialogPerformed", "dsdd", playerid, string[7], response, funcidx(string) != -1)))
{
CallLocalFunction(string, "ddds", playerid, response, listitem, (!inputtext[0]) ? ("\1") : (inputtext));
}
}
#if defined DR_OnDialogResponse
return DR_OnDialogResponse(playerid, dialogid, response, listitem, inputtext);
#else
return 0;
#endif
}
#if defined _ALS_OnDialogResponse
#undef OnDialogResponse
#else
#define _ALS_OnDialogResponse
#endif
#define OnDialogResponse DR_OnDialogResponse
#if defined DR_OnDialogResponse
forward DR_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
#endif