[Include] DLDiag // Dynamic List Dialog (v1.0)
#1

[Description]
This simple include allows you to create more dynamic list-style dialogs, while keeping it just as simple to identify player chosen listitem under OnDialogResponse callback.
[Functions]
This include only has three functions. Which are:
Quote:
AddDListItem(playerid, Item[], ItemID = -1, , ItemParameter = -1);
playerid - ID of player to who the list item should be assigned.
Item[] - The item to add.
ItemID - Manually assigned ID to the added item. Pretty much the same as dialogid in
ItemParameter - With this you can easily pass extra parameters, such as player or vehicle IDs (Added in v1.1)
ShowPlayerDialog. -1 by default.
ShowPlayerDList(playerid, DialogID, Caption[], Button1[], Button2[]);
playerid The ID of the player to show the dialog to.
DialogID - An ID to assign this dialog to, so responses can be processed. Max dialogid is 32767. Using negative values will close any open dialog.
Caption[] - The title at the top of the dialog.
Button1[] - The text on the left button.
Button2[] - The text on the right button.
Clear_DList(playerid);(Added in v1.2)
playerid - ID of a player whos list variables you want to clear.
This function should not be needed. However, it does exist, so you can manually clean up the dynamic list variables of a player. You could use it under OnPlayerDialogResponse, or OnPlayerDisconnect etc. to remove bugs.
[OnDialogResponse]
How to use the item ID and item parameter?
Well, there are two extra variables, called DLItemID, and DLParam, which you can use like any other integer variable. Look at the Sample Usage.
[Installing]
Just add it as any include. Except..
pawn Код:
#define DLD_STRING_SIZE 256 // Optional. Change if your DLists can be longer as 256 characters total. If not defined defaults to 256
#define DLD_MAX_LIST_ITEMS 10 // Optional. Change if you need more than 10 list items. If not defined defaults to 10
#include <DLDiag>
[Sample Usage]
pawn Код:
enum
{
    DLITEM_PM,
    DLITEM_KICK,
    DLITEM_BAN,
    DLITEM_GIVEMONEY
}
// This enum is not required. ItemID can be regular integer, like 1 or 126.
// But this way you can keep things nicely organized :)

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    // I know this looks kinda messy, but I just wanted to show some possibilities.

    AddDListItem(playerid, "Personal Message", DLITEM_PM, clickedplayerid);

    if( IsPlayerAdmin(playerid) ) AddDListItem(playerid, "Kick", DLITEM_KICK, clickedplayerid);
    if( IsPlayerAdmin(playerid) ) Function2(playerid, clickedplayerid);

    AddDListItem(playerid, "Give Money", DLITEM_GIVEMONEY, clickedplayerid);
    AddDListItem(playerid, "Close");

    ShowPlayerDlist(playerid, 1, "Example of Dynamic List Dialog", "Cool", "Close");
    return true;
}
public Function2(playerid, ExtraParam)
{
    return AddDListItem(playerid, "Ban", DLITEM_BAN, ExtraParam);
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case 1:
        {
            switch( DLItemID )
            {
                case DLITEM_PM:
                {
                    // Do Stuff
                }
                case DLITEM_BAN: Ban(DLParam);
                case DLITEM_KICK: Kick(DLParam);
                case DLITEM_GIVEMONEY: // Do Oter Stuff
            }
        }
    }
}
[Include itself]
also known as.. DOWNLOAD!
Since it's really short include I will simply post it right here.
Still, if you find it easier to drag a file to your include folders from archive, instead of creating a new file, a and copy-pasting content to it, like me. I have also uploaded it.
[SolidFiles]

pawn Код:
/*
 _____  _      _____  _
|  __ \| |    |  __ \(_)
| |  | | |    | |  | |_  __ _  __ _
| |  | | |    | |  | | |/ _` |/ _` |
| |__| | |____| |__| | | (_| | (_| |
|_____/|______|_____/|_|\__,_|\__, |
   DynamicListDialog (v1.2)    __/ |
                   ByTheXIII  |___/
                                    */



/*=====================================

native AddDListItem(playerid, Item[], ItemID = -1, ItemParam = -1);
native ShowPlayerDList(playerid, DialogID, Caption[], Button1[], Button2[]);
native Clear_DList(playerid);

=====================================*/


#if defined _DLDiag_included
    #endinput
#endif
#define _DLDiag_included

#if !defined _samp_included
    #error "<a_samp> must be included before <DLDiag>"
#endif

#if !defined DLD_STRING_SIZE
    #define DLD_STRING_SIZE 256
#endif

#if !defined DLD_MAX_LIST_ITEMS
    #define DLD_MAX_LIST_ITEMS 10
#endif
#define DLItemID DLDPlayerListItems[playerid][listitem]
#define DLParam DLDPlayerListParam[playerid][listitem]

new DLDString[DLD_STRING_SIZE];
new DLDPlayerListItems[MAX_PLAYERS][DLD_MAX_LIST_ITEMS];
new DLDPlayerListParam[MAX_PLAYERS][DLD_MAX_LIST_ITEMS];
new DLDLastIS;

stock AddDListItem(playerid, ItemStr[DLD_STRING_SIZE], ItemID = -1, ItemParam = -1)
{
    DLDPlayerListItems[playerid][DLDLastIS] = ItemID;
    DLDPlayerListParam[playerid][DLDLastIS] = ItemParam;
    if( !DLDLastIS ){DLDString = ""; format(DLDString, sizeof(DLDString), "%s", ItemStr);}
    else format(DLDString, sizeof(DLDString), "%s\r\n%s", DLDString, ItemStr);
    DLDLastIS++;
    return DLDLastIS -1;
}
stock ShowPlayerDList(playerid, DialogID, Caption[], Button1[], Button2[])
{
    DLDLastIS = 0;
    ShowPlayerDialog(playerid, DialogID, DIALOG_STYLE_LIST, Caption, DLDString, Button1, Button2);
    DLDString = "";
    return true;
}
stock Clear_DList(playerid)
{
    for( new i; i < DLD_MAX_LIST_ITEMS; i++ )
    {
        DLDPlayerListItems[playerid][i] = 0;
        DLDPlayerListParam[playerid][i] = 0;
    }
    return true;
}
[Changelog]
v1.0
Release.

v1.1
Added extra parameter.

v1.2
Added Clear_DList function. + automatic string clearing to avoid possible bugs.
Reply
#2

Nice, you took basically Textdraws, Menus, and Dialogs and pushed them into one, first I seen. Good job!
Reply
#3

Quote:
Originally Posted by willsuckformoney
Посмотреть сообщение
Nice, you took basically Textdraws, Menus, and Dialogs and pushed them into one, first I seen. Good job!
^^^^^
Very good job
Reply
#4

Quote:
Originally Posted by willsuckformoney
Посмотреть сообщение
Nice, you took basically Textdraws, Menus, and Dialogs and pushed them into one, first I seen. Good job!
I don't really understand what you mean? I didn't even touch TextDraws. It only uses dialogs, and even then only list-styled dialogs.

And yes, the reason I decided to release this was because I didn't find anything similar. Plus.. since I've become a little bit more active in these forums I simply wanted to release something, and since I needed this myself anyway.. why not


And thanks, to both of you


Oh.. almost forgot New version. Added extra parameter to AddDListItem.
Reply
#5

Thanks, i will use this but a little later..
Reply
#6

nice!!! good job man
Reply
#7

Thanks I'm also open for suggestions.
Reply
#8

screenshots?
Reply
#9

Quote:
Originally Posted by [H]265
Посмотреть сообщение
screenshots?
Of what? A dialog?
This include doesn't do anything visually. It just allows to build more dynamic dialogs. So you can easily build dialogs which change constantly, and still be able to easily make difference between list objects. You can also easily pass on extra parameter.
Reply
#10

Thank you very much!

pawn Код:
if( IsPlayerAdmin(playerid) ) Function2(playerid), clickedplayerid;
Should be
pawn Код:
if( IsPlayerAdmin(playerid) ) Function2(playerid, clickedplayerid);
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)