Advertisement
Guest User

SAMP Car color dialog

a guest
Nov 3rd, 2014
1,402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.37 KB | None | 0 0
  1. /*
  2.                   _____           _     _      
  3.                  |  __ \         | |   (_)      
  4.                  | |  | |_ __ ___| |__  _ _ __  
  5.                  | |  | | '__/ _ \ '_ \| | '_ \
  6.                  | |__| | | |  __/ |_) | | | | |
  7.                  |_____/|_|  \___|_.__/|_|_| |_|
  8.                             Β©Drebin 2013-2014
  9.                             Thanks to AIped for helping!
  10.         http://forum.sa-mp.com/showthread.php?p=2518564#post2518564
  11. */
  12.  
  13. #include <a_samp>
  14.  
  15. new PlayerText:ptd_box[MAX_PLAYERS];
  16. new PlayerText:ptd_panel[MAX_PLAYERS][8][8];
  17. new PlayerText:ptd_indicator[MAX_PLAYERS];
  18. new ptd_shown[MAX_PLAYERS] = -1;
  19. new ptd_posX[MAX_PLAYERS];
  20. new ptd_posY[MAX_PLAYERS];
  21.  
  22. new panelcolors[16][8]= {
  23.  //new sa-mp 0.3x HEX Values car colors to set each textdraw's color, sorted by row and column
  24. {0x177517FF, 0x210606FF, 0x125478FF, 0x452A0DFF, 0x571E1EFF, 0x010701FF, 0x25225AFF, 0x2C89AAFF},
  25. {0x8A4DBDFF, 0x35963AFF,0xB7B7B7FF, 0x464C8DFF, 0x84888CFF, 0x817867FF, 0x817A26FF, 0x6A506FFF},
  26. {0x583E6FFF, 0x8CB972FF, 0x824F78FF, 0x6D276AFF,0x1E1D13FF, 0x1E1306FF, 0x1F2518FF, 0x2C4531FF},
  27. {0x1E4C99FF, 0x2E5F43FF, 0x1E9948FF, 0x1E9999FF, 0x999976FF, 0x7C8499FF,0x992E1EFF, 0x2C1E08FF},
  28. {0x142407FF, 0x993E4DFF, 0x1E4C99FF, 0x198181FF, 0x1A292AFF, 0x16616FFF, 0x1B6687FF, 0x6C3F99FF},
  29. {0x481A0EFF, 0x7A7399FF, 0x746D99FF, 0x53387EFF, 0x222407FF, 0x3E190CFF, 0x46210EFF, 0x991E1EFF},
  30. {0x8D4C8DFF, 0x805B80FF,0x7B3E7EFF, 0x3C1737FF, 0x733517FF, 0x781818FF, 0x83341AFF, 0x8E2F1CFF},
  31. {0x7E3E53FF, 0x7C6D7CFF, 0x020C02FF, 0x072407FF,0x163012FF, 0x16301BFF, 0x642B4FFF, 0x368452FF},
  32. {0x999590FF, 0x818D96FF, 0x99991EFF, 0x7F994CFF, 0x839292FF, 0x788222FF,0x2B3C99FF, 0x3A3A0BFF},
  33. {0x8A794EFF, 0x0E1F49FF, 0x15371CFF, 0x15273AFF, 0x375775FF, 0x060820FF, 0x071326FF, 0x20394BFF},
  34. {0x2C5089FF, 0x15426CFF, 0x103250FF, 0x241663FF, 0x692015FF, 0x8C8D94FF, 0x516013FF, 0x090F02FF},
  35. {0x8C573AFF, 0x52888EFF, 0x995C52FF, 0x99581EFF, 0x993A63FF, 0x998F4EFF, 0x99311EFF, 0x0D1842FF},
  36. {0x521E1EFF, 0x42420DFF, 0x4C991EFF, 0x082A1DFF,0x96821DFF, 0x197F19FF, 0x3B141FFF, 0x745217FF},
  37. {0x893F8DFF, 0x7E1A6CFF, 0x0B370BFF, 0x27450DFF, 0x071F24FF, 0x784573FF, 0x8A653AFF, 0x732617FF},
  38. {0x319490FF, 0x56941DFF, 0x59163DFF, 0x1B8A2FFF, 0x38160BFF, 0x041804FF, 0x355D8EFF, 0x2E3F5BFF},
  39. {0x561A28FF, 0x4E0E27FF, 0x706C67FF, 0x3B3E42FF, 0x2E2D33FF, 0x7B7E7DFF, 0x4A4442FF, 0x28344EFF}
  40. };
  41.  
  42. new carcolids[16][8] = { //Vehicle color IDs shown in the dialog sorted by row and column
  43. {128,   129,    130,    131,    132,    133,    134,    135},
  44. {136,   137,    138,    139,    140,    141,    142,    143},
  45. {144,   145,    146,    147,    148,    149,    150,    151},
  46. {152,   153,    154,    155,    156,    157,    158,    159},
  47. {160,   161,    162,    163,    164,    165,    166,    167},
  48. {168,   169,    170,    171,    172,    173,    174,    175},
  49. {176,   177,    178,    179,    180,    181,    182,    183},
  50. {184,   185,    186,    187,    188,    189,    190,    191},  
  51. {192,   193,    194,    195,    196,    197,    198,    199},  
  52. {200,   201,    202,    203,    204,    205,    206,    207},  
  53. {208,   209,    210,    211,    212,    213,    214,    215},  
  54. {216,   217,    218,    219,    220,    221,    222,    223},  
  55. {224,   225,    226,    227,    228,    229,    230,    231},  
  56. {232,   233,    234,    235,    236,    237,    238,    239},  
  57. {240,   241,    242,    243,    244,    245,    246,    247},  
  58. {248,   249,    250,    251,    252,    253,    254,    255}        
  59. };
  60.  
  61. //Offsets used to calculate the spacing between each of the colors used in the dialog + offsets for cursor movements
  62. #define OFFSET_COL_X        25.6 //The distance from "2" to "1" on the X axis. Y axis level doesn't change (they have an identical X axis value)
  63. #define OFFSET_ROW_Y        24.0 //The distance from "3" to "1" on the Y axis. X axis level doesn't change (they have an identical Y axis value)
  64. #define OFFSET_INDICATOR_X  25.6 //The X value the dialog cursor has to be moved on the X axis to get to the next color (Y value doesn't change when moving horizontally)
  65. #define OFFSET_INDICATOR_Y  24.0 //The Y value the dialog cursor has to be moved on the Y axis to get to the next color (X value doesn't change when moving vertically)
  66. //     OFFSETS
  67. //  1  2  -  -  -  -  -  -
  68. //  3  -  -  -  -  -  -  -
  69. //  -  -  -  -  -  -  -  -
  70. //  -  -  -  -  -  -  -  -
  71. //  -  -  -  -  -  -  -  -
  72. //  -  -  -  -  -  -  -  -
  73. //  -  -  -  -  -  -  -  -
  74. //  -  -  -  -  -  -  -  -
  75.  
  76. #define CURSOR_MOVE_UP      0
  77. #define CURSOR_MOVE_DOWN    1
  78. #define CURSOR_MOVE_LEFT    2
  79. #define CURSOR_MOVE_RIGHT   3
  80.  
  81. #define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  82.  
  83. forward OnPlayerChangeSelectedColor(playerid, column, row);
  84. forward OnPlayerSelectColor(playerid, column, row);
  85.  
  86. forward ShowPlayerColorSelectDialog(playerid);
  87. forward HidePlayerColorSelectDialog(playerid);
  88. forward MoveColorDialogCursor(playerid, direction);
  89. forward SelectCurrentColor(playerid);
  90. forward CreateColorSelectionDialog(playerid);
  91. forward DestroyColorSelectionDialog(playerid);
  92. forward GetColorFromPosition(column, row);
  93.  
  94. public ShowPlayerColorSelectDialog(playerid)
  95. {
  96.     PlayerTextDrawShow(playerid, ptd_box[playerid]);
  97.     PlayerTextDrawShow(playerid, ptd_indicator[playerid]);
  98.     for(new i = 0; i < 8; i++) //Loop through every row
  99.     {
  100.         for(new k = 0; k < 8; k++) //Loop through every column
  101.             PlayerTextDrawShow(playerid, ptd_panel[playerid][i][k]); //Show the textdraw
  102.     }
  103.     ptd_posX[playerid] = 0;
  104.     ptd_posY[playerid] = 0;
  105.     ptd_shown[playerid] = 1;
  106.     return 1;
  107. }
  108.  
  109. public HidePlayerColorSelectDialog(playerid)
  110. {
  111.     SetPaintTDIndicatorPos(playerid, 0, 0); //Reset the cursor to the top left corner of the dialog for next use
  112.     PlayerTextDrawHide(playerid, ptd_box[playerid]);
  113.     PlayerTextDrawHide(playerid, ptd_indicator[playerid]);
  114.     for(new i = 0; i < 8; i++) //Loop through every row
  115.     {
  116.         for(new k = 0; k < 8; k++) //Loop through every column
  117.             PlayerTextDrawHide(playerid, ptd_panel[playerid][i][k]); //Hide the textdraw
  118.     }
  119.     ptd_posX[playerid] = -1;
  120.     ptd_posY[playerid] = -1;
  121.     ptd_shown[playerid] = 0;
  122.     return 1;
  123. }
  124.  
  125. public MoveColorDialogCursor(playerid, direction)
  126. {
  127.     if(!ptd_shown[playerid]) return 0;
  128.     new Keys,ud,lr;
  129.     GetPlayerKeys(playerid,Keys,ud,lr);
  130.     switch(direction)
  131.     {
  132.         case CURSOR_MOVE_UP: //Cursor should be moved up
  133.         {
  134.             if(ptd_posY[playerid] != 0) //Cursor's current position is not in the top row (if it was it couldn't move up any further)
  135.             {
  136.                 SetPaintTDIndicatorPos(playerid, ptd_posX[playerid], ptd_posY[playerid] - 1); //Move the cursor up one row (Y axis)
  137.                 OnPlayerChangeSelectedColor(playerid, ptd_posX[playerid], ptd_posY[playerid]);
  138.             }
  139.         }
  140.         case CURSOR_MOVE_DOWN: //Cursor should be moved down
  141.         {
  142.             if(ptd_posY[playerid] != 7) //Cursor's current position is not in the bottom row (if it was it couldn't move down any further)
  143.             {
  144.                 SetPaintTDIndicatorPos(playerid, ptd_posX[playerid], ptd_posY[playerid] + 1); //Move the cursor down one row (Y axis)
  145.                 OnPlayerChangeSelectedColor(playerid, ptd_posX[playerid], ptd_posY[playerid]);
  146.             }
  147.         }
  148.         case CURSOR_MOVE_LEFT: //Cursor should be moved left
  149.         {
  150.             if(ptd_posX[playerid] == 0) //Cursor is in the very left column
  151.             {
  152.                 if(ptd_posY[playerid] != 0) //Cursor is also not in the top row (if it was, it couldn't move up or left)
  153.                 {
  154.                     SetPaintTDIndicatorPos(playerid, 7, ptd_posY[playerid] - 1); //Move cursor up one row and set it to into the very right column
  155.                     OnPlayerChangeSelectedColor(playerid, ptd_posX[playerid], ptd_posY[playerid]);
  156.                 }
  157.             }
  158.             else //Cursor is not in the very left column
  159.             {
  160.                 SetPaintTDIndicatorPos(playerid, ptd_posX[playerid] - 1, ptd_posY[playerid]); //Move cursor left one column
  161.                 OnPlayerChangeSelectedColor(playerid, ptd_posX[playerid], ptd_posY[playerid]);
  162.             }
  163.         }
  164.         case CURSOR_MOVE_RIGHT: //Cursor should be moved right
  165.         {
  166.             if(ptd_posX[playerid] == 7) //Cursor is in the very right column
  167.             {
  168.                 if(ptd_posY[playerid] != 7) //Cursor is also not in the bottom row (if it was, it couldn't move down or right)
  169.                 {
  170.                     SetPaintTDIndicatorPos(playerid, 0, ptd_posY[playerid] + 1); //Move cursor down one row and set it to into the very left column
  171.                     OnPlayerChangeSelectedColor(playerid, ptd_posX[playerid], ptd_posY[playerid]);
  172.                 }
  173.             }
  174.             else
  175.             {
  176.                 SetPaintTDIndicatorPos(playerid, ptd_posX[playerid] + 1, ptd_posY[playerid]); //Move cursor right one column
  177.                 OnPlayerChangeSelectedColor(playerid, ptd_posX[playerid], ptd_posY[playerid]);
  178.             }
  179.         }
  180.     }
  181.     return 1;
  182. }
  183.  
  184. public SelectCurrentColor(playerid) //Select the color the cursor has currently selected
  185. {
  186.     if(ptd_shown[playerid])
  187.         OnPlayerSelectColor(playerid, ptd_posX[playerid], ptd_posY[playerid]);
  188. }
  189.  
  190. public CreateColorSelectionDialog(playerid) //Create the color dialog
  191. {
  192.     ptd_box[playerid] = CreatePlayerTextDraw(playerid, 132.0, 147.0, "_");
  193.     PlayerTextDrawAlignment(playerid, ptd_box[playerid], 2);
  194.     PlayerTextDrawLetterSize(playerid, ptd_box[playerid], 0.5, 20.900007);
  195.     PlayerTextDrawSetProportional(playerid, ptd_box[playerid], 1);
  196.     PlayerTextDrawUseBox(playerid, ptd_box[playerid], 1);
  197.     PlayerTextDrawBoxColor(playerid, ptd_box[playerid], 0x00000078);
  198.     PlayerTextDrawTextSize(playerid, ptd_box[playerid], 2.0, 201.0);
  199.    
  200.     ptd_indicator[playerid] = CreatePlayerTextDraw(playerid, 42.000000, 147.000000, "_");
  201.     PlayerTextDrawAlignment(playerid, ptd_indicator[playerid], 2);
  202.     PlayerTextDrawLetterSize(playerid, ptd_indicator[playerid], 0.500000, 2.199999);
  203.     PlayerTextDrawSetProportional(playerid, ptd_indicator[playerid], 1);
  204.     PlayerTextDrawUseBox(playerid, ptd_indicator[playerid], 1);
  205.     PlayerTextDrawBoxColor(playerid, ptd_indicator[playerid], 0xFFFFFFFF);
  206.     PlayerTextDrawTextSize(playerid, ptd_indicator[playerid], 0.000000, 21.000000);
  207.    
  208.     for(new row = 0; row < 8; row++)
  209.     {
  210.         for(new col = 0; col < 8; col++)
  211.         {
  212.             ptd_panel[playerid][row][col] = CreatePlayerTextDraw(playerid, 42.0 + (col * OFFSET_COL_X), 150.0 + (row * OFFSET_ROW_Y), "_");
  213.             PlayerTextDrawAlignment(playerid, ptd_panel[playerid][row][col], 2);
  214.             PlayerTextDrawLetterSize(playerid, ptd_panel[playerid][row][col], 0.5, 1.5);
  215.             PlayerTextDrawSetProportional(playerid, ptd_panel[playerid][row][col], 1);
  216.             PlayerTextDrawUseBox(playerid, ptd_panel[playerid][row][col], 1);
  217.             PlayerTextDrawBoxColor(playerid, ptd_panel[playerid][row][col], panelcolors[row][col]);
  218.             PlayerTextDrawTextSize(playerid, ptd_panel[playerid][row][col], 0.00, 15.0);
  219.         }
  220.     }
  221.     return 1;
  222. }
  223.  
  224. public DestroyColorSelectionDialog(playerid) //Destroy the dialog
  225. {
  226.     PlayerTextDrawDestroy(playerid, ptd_box[playerid]);
  227.     PlayerTextDrawDestroy(playerid, ptd_indicator[playerid]);
  228.     for(new i = 0; i < 8; i++)
  229.     {
  230.         for(new k = 0; k < 8; k++)
  231.             PlayerTextDrawDestroy(playerid, ptd_panel[playerid][i][k]);
  232.     }
  233.     return 1;
  234. }
  235.  
  236. public GetColorFromPosition(column, row) //Get the color ID from the column and row the cursor is in
  237.     return carcolids[row][column];
  238.    
  239.    
  240. //Internal function
  241. stock SetPaintTDIndicatorPos(playerid, column, row) //Set the exact position of the cursor
  242. {
  243.     PlayerTextDrawDestroy(playerid, ptd_indicator[playerid]);
  244.     ptd_indicator[playerid] = CreatePlayerTextDraw(playerid, 42.000000 + (column * OFFSET_INDICATOR_X), 147.000000 + (row * OFFSET_INDICATOR_Y), "_");
  245.     PlayerTextDrawAlignment(playerid, ptd_indicator[playerid], 2);
  246.     PlayerTextDrawLetterSize(playerid, ptd_indicator[playerid], 0.500000, 2.199999);
  247.     PlayerTextDrawSetProportional(playerid, ptd_indicator[playerid], 1);
  248.     PlayerTextDrawUseBox(playerid, ptd_indicator[playerid], 1);
  249.     PlayerTextDrawBoxColor(playerid, ptd_indicator[playerid], 0xFFFFFFFF);
  250.     PlayerTextDrawTextSize(playerid, ptd_indicator[playerid], 0.000000, 21.000000);
  251.    
  252.     PlayerTextDrawDestroy(playerid, ptd_panel[playerid][row][column]);
  253.     ptd_panel[playerid][row][column] = CreatePlayerTextDraw(playerid, 42.0 + (column * OFFSET_COL_X), 150.0 + (row * OFFSET_ROW_Y), "_");
  254.     PlayerTextDrawAlignment(playerid, ptd_panel[playerid][row][column], 2);
  255.     PlayerTextDrawLetterSize(playerid, ptd_panel[playerid][row][column], 0.5, 1.5);
  256.     PlayerTextDrawSetProportional(playerid, ptd_panel[playerid][row][column], 1);
  257.     PlayerTextDrawUseBox(playerid, ptd_panel[playerid][row][column], 1);
  258.     PlayerTextDrawBoxColor(playerid, ptd_panel[playerid][row][column], panelcolors[row][column]);
  259.     PlayerTextDrawTextSize(playerid, ptd_panel[playerid][row][column], 0.00, 15.0);
  260.    
  261.     PlayerTextDrawShow(playerid, ptd_indicator[playerid]);
  262.     PlayerTextDrawShow(playerid, ptd_panel[playerid][row][column]);
  263.    
  264.     ptd_posX[playerid] = column;
  265.     ptd_posY[playerid] = row;
  266.     return 1;
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement