File size: 3,237 Bytes
72629ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#if defined _easyDialog_included
	#endinput
#endif
#define _easyDialog_included
#if !defined isnull
	#define isnull(%1) \
		((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
#if !defined HidePlayerDialog
	#define HidePlayerDialog(%1) \
		ShowPlayerDialog(%1, -1, 0, " ", " ", " ", " ")
#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)))
#if !defined _INC_open_mp
	#if !defined DIALOG_STYLE
		#define DIALOG_STYLE: _:
	#endif
#endif
static
	s_DialogName[MAX_PLAYERS][32 char],
	bool: s_DialogOpened[MAX_PLAYERS]
;
forward OnDialogPerformed(playerid, const dialog[], response, success);
forward @dialog_format(); @dialog_format() {
	new emptyString[] = '\1';
	format(emptyString, sizeof(emptyString), emptyString);
}
forward Dialog_IsOpened(playerid);
public Dialog_IsOpened(playerid) {
	return (s_DialogOpened[playerid]);
}
stock Dialog_Close(playerid) {
	s_DialogName[playerid]{0} = 0;
	s_DialogOpened[playerid] = false;
	return HidePlayerDialog(playerid);
}
stock Dialog_Open(playerid, const function[], DIALOG_STYLE:style, const caption[], const info[], const button1[], const 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, 32700, style, caption, string, button1, button2);
	}
	else {
		ShowPlayerDialog(playerid, 32700, style, caption, info, button1, button2);
	}
	s_DialogOpened[playerid] = true;
	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");
	}
	for (new i = 0, l = strlen(inputtext); i < l; i ++) {
		if (inputtext[i] == '%') {
			inputtext[i] = '#';
		}
	}
	if (dialogid == 32700 && strlen(s_DialogName[playerid]) > 0) {
		new
			string[40];
		strcat(string, "dialog_");
		strcat(string, s_DialogName[playerid]);
		Dialog_Close(playerid);
		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