-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTDialog.inc
190 lines (157 loc) · 5.18 KB
/
TDialog.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
TDialog - v.2.0
Make dialog easier & efficient.
Functions:
TDialog_Show(playerid, dialogid, dialog_type, button0[], button1[]) - This will execute dialog to a player.
TDialog_SetHeader(dialogid, header[], {Float,_}:....) - Thiss will set the header of a dialog.
TDialog_SetInfo(dialogid, info[], {Float,_}:....);
Replacements:
DIALOG_STYLE_MSGBOX --> TDIALOG_MSG
DIALOG_STYLE_LIST --> TDIALOG_LIST
DIALOG_STYLE_TABLIST --> TDIALOG_TABLIST
DIALOG_STYLE_TABLIST_HEADERS --> TDIALOG_TABLIST_HEAD
DIALOG_STYLE_INPUT --> TDIALOG_INPUT
DIALOG_STYLE_PASSWORD --> TDIALOG_PASS
Special Thanks:
- Emmet for #emit stuff
*/
#define TDialogCall:%0(%1) \
forward tdialog_%0(%1); public tdialog_%0(%1)
#define TDialog_Show(%0,%1, \
TDialog_Open(%0, #%1,
#define TDialog_SetHeader(%0, \
TDialog_SH(#%0,
#define TDialog_SetInfo(%0, \
TDialog_SI(#%0,
#define TDIALOG_CAPTION_LENGTH (32 * 2)
#define TDIALOG_INFO_LENGTH (4086)
#define TDIALOG_CALLBACK_LENGTH (24)
enum
{
TDIALOG_MSG,
TDIALOG_LIST,
TDIALOG_TABLIST,
TDIALOG_TABLIST_HEAD,
TDIALOG_INPUT,
TDIALOG_PASS
};
enum E_TDIALOG
{
E_TDIALOG_HEADER[TDIALOG_CAPTION_LENGTH],
E_TDIALOG_INFO[TDIALOG_INFO_LENGTH],
E_TDIALOG_CALL[TDIALOG_CALLBACK_LENGTH]
};
static E_TDDATA[E_TDIALOG];
static TDialogFunction[32 char];
stock TDialog_Open(playerid, const function[], dialog_type, button0[], button1[])
{
switch(dialog_type) {
case TDIALOG_MSG: ShowPlayerDialog(playerid, 57200, DIALOG_STYLE_MSGBOX, E_TDDATA[E_TDIALOG_HEADER], E_TDDATA[E_TDIALOG_INFO], button0, button1);
case TDIALOG_LIST: ShowPlayerDialog(playerid, 57200, DIALOG_STYLE_LIST, E_TDDATA[E_TDIALOG_HEADER], E_TDDATA[E_TDIALOG_INFO], button0, button1);
case TDIALOG_TABLIST: ShowPlayerDialog(playerid, 57200, DIALOG_STYLE_TABLIST, E_TDDATA[E_TDIALOG_HEADER], E_TDDATA[E_TDIALOG_INFO], button0, button1);
case TDIALOG_TABLIST_HEAD: ShowPlayerDialog(playerid, 57200, DIALOG_STYLE_TABLIST_HEADERS, E_TDDATA[E_TDIALOG_HEADER], E_TDDATA[E_TDIALOG_INFO], button0, button1);
case TDIALOG_INPUT: ShowPlayerDialog(playerid, 57200, DIALOG_STYLE_INPUT, E_TDDATA[E_TDIALOG_HEADER], E_TDDATA[E_TDIALOG_INFO], button0, button1);
case TDIALOG_PASS: ShowPlayerDialog(playerid, 57200, DIALOG_STYLE_PASSWORD, E_TDDATA[E_TDIALOG_HEADER], E_TDDATA[E_TDIALOG_INFO], button0, button1);
}
E_TDDATA[E_TDIALOG_HEADER][0] = EOS;
E_TDDATA[E_TDIALOG_INFO][0] = EOS;
strpack(TDialogFunction, function, 32 char);
return 1;
}
stock TDialog_SH(function[], const header[], {Float,_}:...)
{
static
string[64],
args;
if(!strcmp(function, TDialogFunction, true)) {
if ((args = numargs()) > 2)
{
while(--args >= 2)
{
#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 header
#emit PUSH.C 64
#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
format(E_TDDATA[E_TDIALOG_HEADER], 64, string);
#emit RETN
}
else format(E_TDDATA[E_TDIALOG_HEADER], 64, header);
}
else print("[TDialog]: Unknown Dialog Function.");
return 1;
}
stock TDialog_SI(const function[], const info[], {Float,_}:...)
{
static
string[4096],
args;
if(!strcmp(function, TDialogFunction, true)) {
if((args = numargs()) > 2)
{
while(--args >= 2)
{
#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
format(E_TDDATA[E_TDIALOG_INFO], 4096, string);
#emit RETN
}
else format(E_TDDATA[E_TDIALOG_INFO], 4096, info);
}
else print("[TDialog]: Unknown Dialog Function.");
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if (dialogid == 57200 && strlen(TDialogFunction) > 0)
{
new
func[40];
strcat(func, "tdialog_");
strcat(func, TDialogFunction);
CallLocalFunction(func, "ddds", playerid, response, listitem, (!inputtext[0]) ? ("\1") : (inputtext));
}
#if defined TD_OnDialogResponse
TD_OnDialogResponse(playerid, dialogid, response, listitem, inputtext);
#else
return 0;
#endif
}
#if defined _ALS_OnDialogResponse
#undef OnDialogResponse
#else
#define _ALS_OnDialogResponse
#endif
#define OnDialogResponse TD_OnDialogResponse
#if defined TD_OnDialogResponse
forward TD_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
#endif