hreesang/samp-pagination-dialog
A library that breaks SA:MP or open.mp's dialog list items into pages
Este repositorio no tiene archivo de licencia. Se puede leer, pero eso por sí solo no da permiso para reutilizarlo.
Instalar con sampctl
sampctl package install hreesang/samp-pagination-dialog
Ejecútalo en la carpeta de tu proyecto. sampctl descarga el paquete y sus dependencias.
README.md
samp-pagination-dialog
SA:MP or open.mp's dialog list, currently, limits the items that you want to show to your players by the capped string size which is 4096. Yet, this library breaks that limit. If the items string size in total is more than 4096, the items will be broken into pages. It's also possible for you to specify how many items you want to show per page, not always depending on the 4096 string size limit. If the size of items you want to show per page is more than 4096 string size, yet it will still be capped into 4096 string size per page.
Installation
Download the library or simply use sampctl to do so:
sampctl package install Hreesang/samp-pagination-dialog
Include in your code and begin using the library:
#include <PawnPlus>
#include <pagination_dialog>
To be noted that you need PawnPlus to make this library works, so include it before including this library.
Usage
static const dialogItems[][] = {
"Hi, I'm Hreesang. Who are you?",
"Old unsatiable our now but considered travelling impression.",
"Offices parties lasting outward nothing age few resolve.",
"Impression to discretion understood to we interested he excellence.",
"Woody equal ask saw sir weeks aware decay.",
"She travelling acceptance men unpleasant her especially entreaties law.",
"Behaviour we improving at something to.",
"Evil true high lady roof men had open.",
"Far concluded not his something extremity."
};
@cmd() dialog(const playerid, const params[], const help)
{
#pragma unused help
new totalItems, maxItems;
if (sscanf(params, "iI(-1)", totalItems, maxItems)) {
return SendClientMessage(playerid, -1, "Usage: /dialog [total items] [opt: max items per page]");
}
if (totalItems < 0) {
return SendClientMessage(playerid, -1, "Total items should be one or more.");
}
if (maxItems != DEFAULT_PAGINATION_DIALOG_ITEMS && !(1 <= totalItems)) {
return SendClientMessage(playerid, -1, "Max items should be one or more.");
}
new List:items = list_new();
for (new i = 0; i < totalItems; i++) {
new idx = random(sizeof dialogItems);
AddPaginationDialogItem(items, dialogItems[idx]);
}
ShowPaginationDialog(playerid, random(1000), PAGE_DIALOG_STYLE_LIST, "Dialog ({page}/{maxPages})", items, "Asu", .maxItems = maxItems);
return 1;
}
public OnPaginationDialogResponse(playerid, dialogid, bool:response, listitem)
{
new string[144];
format(string, sizeof string, "[OnPaginationDialogResponse] playerid: %i, dialogid: %i, response: %s, listitem: %i", playerid, dialogid, response ? "true" : "false", listitem);
SendClientMessage(playerid, -1, string);
return 1;
}
Have a look at test.pwn for more detailed usage information.
Testing
To test, simply build and run the package:
sampctl build
sampctl run
Declarations
| Declaration | Value | Editable? | Description |
|---|---|---|---|
| PAGINATION_DIALOG_ID | 1847 | Yes | Index used to reference the native's dialog. |
| PAGINATION_DIALOG_PP_ID | 0x502B | Yes | Reserved dialog ID for the asynchronous feature. |
| DEFAULT_PAGINATION_DIALOG_ITEMS | -1 | Yes | Page breaks depends on 4096 string size if the max items value is using this value. |
| MAX_PAGINATION_DIALOG_ITEMS | DEFAULT_PAGINATION_DIALOG_ITEMS | Yes | Max items to be shown per page, depending on 4096 string size is the default. |
| MAX_PAGINATION_DIALOG_CAPTION | 64 | Yes | Max string size for the dialog caption. |
| MAX_PAGINATION_DIALOG_BUTTON | 64 | Yes | Max string size for the dialog buttons. |
| PAGE_DIALOG_STYLE_LIST | DIALOG_STYLE_LIST | No | Pagination dialog style |
| PAGE_DIALOG_STYLE_TABLIST | DIALOG_STYLE_TABLIST | No | Pagination dialog style |
| PAGE_DIALOG_STYLE_TABLIST_HDRS | DIALOG_STYLE_TABLIST_HDRS | No | Pagination dialog style |
APIs
pagination_dialog.inc
public OnPaginationDialogResponse(playerid, dialogid, bool:response, listitem)
Parameters:
playeridPlayer who received the dialog response.dialogidIndex of pagination dialog that's triggered by the player.bool:responseBoolean response of the dialog:trueandfalse. It will befalseif player closes the dialog on next or previous button/item.listitemIndex of item the player selected.-1if player closed the dialog on next or previous button.
Return Values:
any numberNothing happens.
stock bool:ShowPaginationDialog(playerid, dialogid, PAGE_DIALOG_STYLE:style, const caption[], List:items, const button1[], const button2[] = "", const nextButton[] = ">>>", const prevButton[] = "<<<", page = 0, maxItems = MAX_PAGINATION_DIALOG_ITEMS)
Shows a pagination dialog to specified player.
Parameters:
playeridPlayer who will be shown the dialog.dialogidIndex of pagination dialog that will be triggered by the player.stylePagination dialog style.captionCaption for the pagination dialog. Use{page}to display the current page and{maxPages}for the max pages, see test.pwn.List:itemsItems of the dialog that's added byAddPaginationDialogItem(Str).const button1[]Left button of the dialog response.const button2[]Right button of the dialog response.const nextButton[]Button to move to the next page, default is>>>.const prevButton[]Button to move to the previous page, default is<<<.pagePage number to be opened at first, default is0.maxItemsMax items per page, default isMAX_PAGINATION_DIALOG_ITEMS.
Return Values:
trueif success.falseif not success: player not connected or invalid items.
stock AddPaginationDialogItem(List:items, const string[])
stock AddPaginationDialogItemStr(List:items, ConstStringTag:str)
Adds an item to the list of items for a pagination dialog.
Parameters:
List:itemsList of the items created bylist_new.stringorConstStringTag:strItem string to be put into the list. It supports both plain and PawnPlus' string.
stock bool:OpenPaginationDialogPage(playerid, page)
Navigates to a page from the specified player's current opened pagination dialog.
Parameters:
playeridPlayer that will do the navigation.pagePage number to navigate. It's zero-indexed.
Return Values:
trueif success.falseif player doesn't have any active pagination dialog.
stock bool:ClosePaginationDialog(playerid)
Closes the specified player's current opened pagination dialog.
Parameters:
playeridPlayer that will close the dialog.
Return Values:
trueif successfalseif player doesn't have any active pagination dialog.
pagination_dialog_async.inc
Check the examples_async.pwn file for some basic examples.
stock Task:ShowPaginationDialogAsync(playerid, PAGE_DIALOG_STYLE:style, const caption[], List:items, const button1[], const button2[] = "", const nextButton[] = ">>>", const prevButton[] = "<<<", page = 0, maxItems = MAX_PAGINATION_DIALOG_ITEMS)
main()
{
...
new Task:t = ShowPaginationDialogAsync(playerid, PAGE_DIALOG_STYLE_TABLIST_HDRS, "Async Dialog ({page}/{maxPages})", items, "Asu", .maxItems = maxItems);
new response[E_ASYNC_PAGE_DIALOG];
yield(1);
await_arr(t, response);
new string[144];
format(string, sizeof string, "[Pagination Dialog Async] response: %s, listitem: %i", response[E_ASYNC_PAGE_DIALOG_RESPONSE] ? "true" : "false", response[E_ASYNC_PAGE_DIALOG_LISTITEM]);
SendClientMessage(playerid, -1, string);
}
Shows a pagination dialog to specified player, but this one has PawnPlus' task support.
Parameters:
playeridPlayer who will be shown the dialog.stylePagination dialog style.captionCaption for the pagination dialog. Use{page}to display the current page and{maxPages}for the max pages, see test.pwn.List:itemsItems of the dialog that's added byAddPaginationDialogItem(Str).const button1[]Left button of the dialog response.const button2[]Right button of the dialog response.const nextButton[]Button to move to the next page, default is>>>.const prevButton[]Button to move to the previous page, default is<<<.pagePage number to be opened at first, default is0.maxItemsMax items per page, default isMAX_PAGINATION_DIALOG_ITEMS.
Return Values:
Task:taskA task where the result will be E_ASYNC_PAGE_DIALOG,
Credits
- Hreesang for making the library.
Esta página se genera con lo que GitHub publica sobre el repositorio. samp.directory no aloja el código. Informar de un problema con esta ficha