Jump to content

Dialogy - rychlo a efektivne


Recommended Posts

Ak rozdelujete mod do niekolkych suborov, urcite ste narazil problem na spracovanie dialogov. Dovolte mi predstavit jednoduchy sposob spracovavania dialogov prostrednictvom vlastnej funkcie ShowPlayerDialogEx.

 

Dialog handler:

#define DIALOG_HANDLER 5400

forward ShowPlayerDialogEx(playerid, style, caption[], info[], button1[], button2[], callback[]);
forward HandleDialog(playerid, dialogid, response, listitem, inputtext[]);

public ShowPlayerDialogEx(playerid, style, caption[], info[], button1[], button2[], callback[])
{
ShowPlayerDialog(playerid, DIALOG_HANDLER, style, caption, info, button1, button2);
	SetPVarString(playerid,"hDialogCallback",callback);
}

public HandleDialog(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_HANDLER)
{
	new callback[32];
	GetPVarString(playerid,"hDialogCallback",callback,32);

	if(strlen(callback)>0)
	{
		if(strlen(inputtext)>0)
		{
	    	CallLocalFunction(callback,"ddds",playerid, response, listitem, inputtext);
		}
		else
		{
		    CallLocalFunction(callback,"ddds",playerid, response, listitem, "NULL");
		}
  		return true;
	}
}
return false;
}

 

Pouzitie:

1. Pridat do OnDialogResponse:

if(HandleDialog(playerid, dialogid, response, listitem, inputtext))
    return 1;

2. Volanie funkcie:

ShowPlayerDialogEx(playerid, DIALOG_STYLE_LIST, "{FFFF22}Zoznam", "a\nb\nc", "Vybrat", "Zrusit", "callbackSelectDialog");

 

3. Funkcia ktora bude automaticky vyvolana po pouziti formularu:

public callbackSelectDialog(playerid, response, listitem, inputtext[])
{
  ...
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...