SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 06/04/2015, 06:34 AM   #1
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,739
Reputation: 790
Default PreviewModelDialog.inc - SAMP looking like dialog for preview models list


PreviewModelDialog.inc
v4.6 - Last Updated: 29 March, 2018

This include introduces you to a new dialog style: "DIALOG_STYLE_PREVIEW_MODEL". A SA-MP looking like dialog with both standard buttons but with preview models in a list form!

For preview of dialogs, skip down to examples for photos.

About/Functioning:
  • Define your own preview dialog size
    You can have as many listitems you want, just pre-define this constant before including this library, e.g.:
    PHP Code:
    #define MAX_DIALOG_PREVIEW_MODELS 15
    #include <PreviewModelDialog.inc> 
    Similar way you can also define each preview listitem text size:
    PHP Code:
    #define MAX_DIALOG_PREVIEW_MODELS 15
    #define MAX_DIALOG_PREVIEW_TEXTSIZE 32
    #include <PreviewModelDialog.inc> 
  • No pre-allocation of memory
    The include works with BigETI's pawn-memory plugin allowing dynamic memory management, so you won't get huge .amx sizes.
  • Big enough preview
    I had this complain about previous version dialog having very small preview models and text which was barely readable, now its not the case huh?!
  • Players rotate/zoom models in game
    Yes as you can see in this picture, those LEFT and RIGHT arrows let players to rotate their selected models to view it full.
    And UP and DOWN arrows later added in v4.5, lets you zoom in and out now!

    The number at bottom represents the rotation (Z angle).
    In v4.5, the middle right represents the zoom level.


  • Functions
    Support samp dialog function "ShowPlayerDialog". Check the examples for how to use.
    Anyways, those who like using array of data, there is also a function for passing arrays for showing a preview model dialog:
    PHP Code:
    ShowPreviewModelDialog(playeriddialogidcaption[], models[], labels[][], button1[], button2[], size sizeof models); 
  • Scripter can set each model rotation
    You can set each model rotation before even showing the dialog to player, just use this:
    PHP Code:
    SetDialogPreviewRotation(playeridlistitemFloat:rxFloat:ryFloat:rzFloat:zoom); 
    NOTE: if player changes the preview model rotation in game, the value is affected in your function too.
  • A perfect scroll bar
    Yep, i just discovered if you want to make scrollbars or even boxes with textdraws, always use Sprites. The textsize of sprites is comparable with positioning of textdraws, so you don't really need algorithms for comparison.
  • GameText codes in listitems
    Since the dialog is made with pure textdraws, you can use label codes (e.g. ~n~ - switch line or ~r~ - red color) in preview model's labeltext.

Example: ShowPlayerDialog

A simple skin selection dialog with all samp skins as listitems.



Source:
PHP Code:
CMD:skins(playerid) {
    const 
MAX_SKINS 312;
    static 
string[MAX_SKINS 16];
    
    if (
string[0] == EOS) {
        for (new 
iMAX_SKINSi++) {
            
format(stringsizeof string"%s%i\tID: %i\n"stringii);
        }
    }
    
    return 
ShowPlayerDialog(playerid0DIALOG_STYLE_PREVIEW_MODEL"Skin Selection Dialog"string"Select""Cancel");
}

public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[]) {
    if (
dialogid == 0) {
        if (
response) {
            
SetPlayerSkin(playeridlistitem);
            
GameTextForPlayer(playerid"~g~Skin Changed!"30003);
        }
    }
    return 
1;

Example: ShowPreviewModelDialog

A simple weapon selection dialog made using array method. This way is slightly faster than using strings in ShowPlayerDialog and it more readable but it hardly matters here!



Source:
PHP Code:
new WEAPON_MODELS[] = {
    
342343344359360361363366
};

new 
WEAPON_NAMES[][] = {
    
"Grenade""Tear Gas""Moltov""RPG""HS Rocket""Flamethrower""Satchel""Fire Extinguisher"
};

new 
WEAPON_IDS[] = {
    
WEAPON_GRENADEWEAPON_TEARGASWEAPON_MOLTOVWEAPON_ROCKETLAUNCHERWEAPON_HEATSEEKERWEAPON_FLAMETHROWERWEAPON_SATCHELWEAPON_FIREEXTINGUISHER
};

CMD:weapons(playerid) {
    return 
ShowPreviewModelDialog(playerid0"Weapon Selection Dialog"WEAPON_MODELSWEAPON_NAMES"Select""Cancel");
}

public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[]) {
    if (
dialogid == 0) {
        if (
response) {
            
GivePlayerWeapon(playeridWEAPON_IDS[listitem], 100);
            
GameTextForPlayer(playerid"~g~Weapon spawned!"30003);
        }
    }
    return 
1;

Download:
https://github.com/Agneese-Saini/SA-...odelDialog.inc

Dependencies:
pawn-memory (Plugin) - http://forum.sa-mp.com/showthread.php?t=645166

Convert From mSelection:
- Coming soon -

Last edited by Gammix; 30/03/2018 at 04:00 AM.
Gammix is online now   Reply With Quote
Old 06/04/2015, 06:48 AM   #2
RaeF
Huge Clucker
 
Join Date: Dec 2014
Location: Indonesia
Posts: 265
Reputation: 27
Default Re: Dialogs Include (new dialog functions and DIALOG_STYLE_PREVMODEL)

Great job man!
RaeF is offline   Reply With Quote
Old 06/04/2015, 10:08 AM   #3
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,739
Reputation: 790
Default Re: Dialogs Include (new dialog functions and DIALOG_STYLE_PREVMODEL)

Thanks^

UPDATE R2 - 6th April, 2015
  • Fixed NEXT and PREVIOUS buttons
  • Fixed Selecting bug
  • Fixed Buttons configurations
  • STABLE Version released!
__________________
Gammix is online now   Reply With Quote
Old 06/04/2015, 10:11 AM   #4
Kapersky™
Gangsta
 
Kapersky™'s Avatar
 
Join Date: Jul 2014
Location: !ncredible India.
Posts: 751
Reputation: 344
Default Re: Dialogs Include (new dialog functions and DIALOG_STYLE_PREVMODEL)

Nice work! Looks sick! *appreciated*.
Kapersky™ is offline   Reply With Quote
Old 06/04/2015, 10:14 AM   #5
R0
Big Clucker
 
R0's Avatar
 
Join Date: May 2014
Location: Nowhere,But still you can find me anytime you want
Posts: 144
Reputation: 33
Default Re: Dialogs Include (new dialog functions and DIALOG_STYLE_PREVMODEL)

Nice,btw i was working on an include like this to release too.
R0 is offline   Reply With Quote
Old 08/04/2015, 01:19 AM   #6
Pottus
Godfather
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 5,416
Reputation: 1224
Default Re: Dialogs Include (new dialog functions and DIALOG_STYLE_PREVMODEL)

Code:
public OnPlayerConnect(playerid)
{
        Dialog_Reset(playerid);

Why bother? It's done in OnPlayerDisconnect().

Line 189:
Code:
format(gPlayerList[playerid][i][E_desc], 28, "");
// Do this
gPlayerList[playerid][i][E_desc][0] = '\0';

You for got to clean up playerdraws in OnGameModeExit() / OnFilterScriptExit()
Pottus is offline   Reply With Quote
Old 08/04/2015, 01:27 AM   #7
RaeF
Huge Clucker
 
Join Date: Dec 2014
Location: Indonesia
Posts: 265
Reputation: 27
Default Re: Dialogs Include (new dialog functions and DIALOG_STYLE_PREVMODEL)

Sorry, but it's look neat
RaeF is offline   Reply With Quote
Old 08/04/2015, 11:13 AM   #8
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,739
Reputation: 790
Default Re: Dialogs Include (new dialog functions and DIALOG_STYLE_PREVMODEL)

Quote:
Originally Posted by Pottus View Post
Code:
public OnPlayerConnect(playerid)
{
        Dialog_Reset(playerid);

Why bother? It's done in OnPlayerDisconnect().
Maybe because my dialog functions don't check if player is connected!

Quote:
Originally Posted by Pottus View Post
Line 189:
Code:
format(gPlayerList[playerid][i][E_desc], 28, "");
// Do this
gPlayerList[playerid][i][E_desc][0] = '\0';

You for got to clean up playerdraws in OnGameModeExit() / OnFilterScriptExit()
Player textdraws must be cleaned up when player disconnects.

R3 - 8th April, 2015
  • Fixed header disappearing
  • Converted 3D array system to 2D array, really affect the file's output size
  • Reduced lines, short code!
  • NEW DESIGN

Please download the latest version.
__________________

Last edited by Gammix; 08/04/2015 at 11:56 AM.
Gammix is online now   Reply With Quote
Old 08/04/2015, 12:09 PM   #9
Excel™
Gangsta
 
Excel™'s Avatar
 
Join Date: Jul 2012
Posts: 560
Reputation: 95
Default Re: Dialogs Include (new dialog functions and DIALOG_STYLE_PREVMODEL)

Nice job buddy. I will use it!

When will this come out:
__________________
NO MORE CODING SAMP :V
JUST PLAYING...
Excel™ is offline   Reply With Quote
Old 10/04/2015, 06:33 AM   #10
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,739
Reputation: 790
Default Re: Dialogs Include (new dialog functions and DIALOG_STYLE_PREVMODEL)

Quote:
Originally Posted by Y_Less View Post
They should! Currently most of those will crash as they don't even check if the player is VALID, let alone connected:

Code:
GetPlayerDialogID(-1); // Crash
Dialog_TotalPages(INVALID_PLAYER_ID); // Crash
// etc...
Why would anyone even perform that function on id -1.
AND, i personally think people have habit to perform such checks like IsPlayerConnected, or maybe a range check... So i didn't bothered to add that! Though now it is done in R4.

All the functions having Dialog_ as prefix are internal functions, i don't recommend people to use them!

Quote:
Originally Posted by Y_Less View Post
Code:
stock Dialog_TotalPages(playerid)
{
        if((gPlayerTotalModels[playerid] >= MODELS_PER_PAGE) && (gPlayerTotalModels[playerid] % MODELS_PER_PAGE) == 0)
        {
                return (gPlayerTotalModels[playerid] / MODELS_PER_PAGE);
        }
        else return (gPlayerTotalModels[playerid] / MODELS_PER_PAGE) + 1;
}

That is much more simply expressed as:

Code:
stock Dialog_TotalPages(playerid)
{
        return ceildiv(gPlayerTotalModels[playerid], MODELS_PER_PAGE);
}

ceildiv

Obviously with adequate connection checks.
Thats nice & short.

Quote:
Originally Posted by Y_Less View Post
Why are "Dialog_CreateGlobalTD()" and "Dialog_CreateGlobalButtonsTD()" stock and global? They shouldn't be stock because they are always used (they aren't API functions), and they shouldn't be global because they are purely internal (again, they aren't API functions).
Ok, that can be an alternative.
Why they shouldn't be global, i don't think so you need player textdraws for just a static display.

Quote:
Originally Posted by Y_Less View Post
Also, there are much better ways to hook the init functions now - both in terms of being script type agnostic, and using more modern ALS methods (applicable for your other callbacks too).
I don't know those new methods, And their benifits?


R4 - 10th April, 2015
  • Add player connection check within the external functions
  • Add double click feature for selecting models directly
  • More shorter code!

Please download the latest version.
__________________
Gammix is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] Items spawner dialogs (zcmd & dialogs include) Q_Lite Filterscripts 17 16/10/2016 11:09 AM
[FilterScript] [FS]Fighting Styles,5 most usable styles Like in SP By Don_(GH) HAYTXA Filterscripts 10 28/03/2013 06:39 AM
Making an OnFilterScriptInit in an include without adding anything in the .pwn exepct the #include r3k1lLz_ Help Archive 6 06/01/2011 06:49 AM
[FilterScript] [FS]Trans World Airlines v0.2 [TWA] - Bug Fixed - Adding Dialogs Soon. Toni Filterscripts 16 13/06/2010 02:57 PM
[FilterScript] [FS] Fighting Styles (0.3a) - |Save styles in Dini| MoBiL[e] Filterscripts 23 24/04/2010 11:12 AM


All times are GMT. The time now is 01:08 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.