[Include] fxShowPlayerDialog
#1

Hello!

The is too much complex for me to create DIALOG_ID for each dialog in my mode. So I have wrapped Showplayedialog with some trick.

The main idea is that player can't view more than 1 dialog at the same time.
Just want to share. Comments are welcome:

prerequisite: isnull function should be added for future check if input is null:
PHP Code:
#if !defined isnull
    #define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif 
First declare fxShowPlayerDialog
PHP Code:
new PlayerDialogFunc[MAX_PLAYERS][90];
new 
PlayerDialogStyle[MAX_PLAYERS];
fxShowPlayerDialog(playeridcallback[], dialogStyleheader[], text[], button1[], button2[]) {
    new 
fxCallback[32];
    
format(fxCallbacksizeof(fxCallback), "%s"callback);
    
PlayerDialogFunc[playerid] = fxCallback;
    
PlayerDialogStyle[playerid] = dialogStyle;
    
ShowPlayerDialog(playeridplayeriddialogStyleheadertextbutton1button2);

Next implement OnDialogResponse
PHP Code:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[]) {
    switch (
PlayerDialogStyle[playerid]) {
        case 
DIALOG_STYLE_MSGBOX: {
            return 
CallLocalFunction(PlayerDialogFunc[playerid], "ii"playeridresponse);
        }
        case 
DIALOG_STYLE_INPUTDIALOG_STYLE_PASSWORD: {
            new 
formatedInput[256];
            
format(formatedInputsizeof(formatedInput), "%s"inputtext);
            if (
isnull(formatedInput)) {
                
printf("FormattedInput is null: |%s|"formatedInput);
                return 
CallLocalFunction(PlayerDialogFunc[playerid], "iis"playeridresponse"\1");
            }
            
printf("Input: |%s|"formatedInput);
            return 
CallLocalFunction(PlayerDialogFunc[playerid], "iis"playeridresponseformatedInput);
        }
        default: {
            return 
CallLocalFunction(PlayerDialogFunc[playerid], "iii"playeridresponselistitem);
        }
    }
    return 
0;

After that in some part of your code you may use fxShowPlayerDialog
PHP Code:
...
fxShowPlayerDialog(playerid"onDialog"DIALOG_STYLE_MSGBOX"Dialog title""Dialog text""Yes""No");
...
forward onDialog(playeridresponse);
public 
onDialog(playeridresponse) {
// your callback is here

Example with input dialog:
PHP Code:
...
fxShowPlayerDialog(playerid"onInputDialog"DIALOG_STYLE_INPUT"Title""Text""Yes""No");
...
forward onInputDialog(playeridresponseinputtext[]);
public 
onInputDialog(playeridresponseinputtext[]) {
    if (
isnull(inputtext)) {
// if input is null
        
} else {
// if normal input
        
}

So you don't need to create DIALOG_ID for each dialog. You don't need to add code into OnDialogResponse too.
Just call dialog and implement callback.
BTW:
For different styles of dialog you should implement different type of callbacks.
Hope it helps somebody.

P.S. I wish it will be done natively

Full include:

PHP Code:
#if !defined isnull
    #define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
new PlayerDialogFunc[MAX_PLAYERS][90];
new 
PlayerDialogStyle[MAX_PLAYERS];
fxShowPlayerDialog(playeridcallback[], dialogStyleheader[], text[], button1[], button2[]) {
    new 
fxCallback[32];
    
format(fxCallbacksizeof(fxCallback), "%s"callback);
    
PlayerDialogFunc[playerid] = fxCallback;
    
PlayerDialogStyle[playerid] = dialogStyle;
    
ShowPlayerDialog(playeridplayeriddialogStyleheadertextbutton1button2);
    return 
0;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[]) {
    switch (
PlayerDialogStyle[playerid]) {
        case 
DIALOG_STYLE_MSGBOX: {
            return 
CallLocalFunction(PlayerDialogFunc[playerid], "ii"playeridresponse);
        }
        case 
DIALOG_STYLE_INPUTDIALOG_STYLE_PASSWORD: {
            new 
formatedInput[256];
            
format(formatedInputsizeof(formatedInput), "%s"inputtext);
            if (
isnull(formatedInput)) {
                return 
CallLocalFunction(PlayerDialogFunc[playerid], "iis"playeridresponse"\1");
            }
            return 
CallLocalFunction(PlayerDialogFunc[playerid], "iis"playeridresponseformatedInput);
        }
        default: {
            return 
CallLocalFunction(PlayerDialogFunc[playerid], "iii"playeridresponselistitem);
        }
    }
    return 
0;

Reply
#2

https://sampforum.blast.hk/showthread.php?tid=475838

EasyDialog by Emmet_ does the same thing, is more optimised and can do some useful tricks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)