Advertisement
Guest User

Progress bar editor by Emmet_

a guest
Mar 27th, 2016
3,386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 41.29 KB | None | 0 0
  1. /*
  2.  *  Progress bar editor by Emmet_
  3.  *  Made for Southclaw's Progress Bars v2.
  4.  *
  5.  *  Features:
  6.  *  - Ability to adjust all settings, including direction, color, and size.
  7.  *  - Uses SQLite for better organization.
  8.  *  - Supports multiple progress bars.
  9. */
  10.  
  11. #include <a_samp>
  12. #include <progress2>
  13. #include <zcmd>
  14.  
  15. #define COLOR_INFO  (0xFFDD00FF)
  16. #define COLOR_ERROR (0xFF5030FF)
  17.  
  18. #define PROJECT_DB_PATH     "projects.db" // Path of the file that stores all of the project names.
  19. #define PROJECT_EXPORT_PATH "%s.pwn" // Path of the export file location.
  20. #define ADMIN_RESTRICTION   false  // Restrict the progress bar editor to RCON admins only?
  21. #define MAX_PROJECT_NAME    24     // Maximum amount of characters in a project name.
  22.  
  23. #define DIALOG_MAIN_MENU        18300
  24. #define DIALOG_LOAD_PROJECT     18301
  25. #define DIALOG_LOAD_CUSTOM      18302
  26. #define DIALOG_DELETE_PROJECT   18303
  27. #define DIALOG_DELETE_CUSTOM    18304
  28. #define DIALOG_DELETE_CONFIRM   18305
  29. #define DIALOG_CREATE_PROJECT   18306
  30. #define DIALOG_PROJECT_MENU     18307
  31. #define DIALOG_BAR_MENU         18308
  32. #define DIALOG_COLOR_INPUT      18309
  33. #define DIALOG_DIRECTION_LIST   18310
  34. #define DIALOG_MAX_VALUE        18311
  35.  
  36. #define LIST_TYPE_LOAD     1
  37. #define LIST_TYPE_DELETE   2
  38.  
  39. #define UPDATE_BAR_POSITION   1
  40. #define UPDATE_BAR_SIZE       2
  41. #define UPDATE_BAR_DIRECTION  3
  42. #define UPDATE_BAR_MAX_VALUE  4
  43. #define UPDATE_BAR_COLOR      5
  44.  
  45. #define EDIT_TYPE_POSITION   1
  46. #define EDIT_TYPE_SIZE       2
  47.  
  48. enum e_ProjectData
  49. {
  50.     // Indicates if a project is active.
  51.     e_ProjectActive,
  52.  
  53.     // Name of the project.
  54.     e_ProjectName[MAX_PROJECT_NAME],
  55.  
  56.     // Name of the project to delete.
  57.     e_ProjectToDelete[MAX_PROJECT_NAME],
  58.  
  59.     // Editing type. (1) Position (2) Size
  60.     e_EditType,
  61.  
  62.     // Index of the selected progress bar, relative to "ProjectBars"
  63.     e_SelectedBar
  64. };
  65.  
  66. new Project[MAX_PLAYERS][e_ProjectData];
  67.  
  68. enum e_ProjectBars
  69. {
  70.     // Database ID of the progress bar's record.
  71.     e_DatabaseID,
  72.  
  73.     // ID of the progress bar.
  74.     PlayerBar:e_ProgressBarID
  75. };
  76.  
  77. new ProjectBars[MAX_PLAYERS][MAX_PLAYER_BARS][e_ProjectBars];
  78.  
  79. new DB:g_iDatabase;
  80.  
  81. new DBResult:g_iDatabaseResult;
  82.  
  83. public OnFilterScriptInit()
  84. {
  85.     for (new i = 0; i < MAX_PLAYERS; i ++)
  86.     {
  87.         if (IsPlayerConnected(i)) ResetProjectData(i);
  88.     }
  89.     g_iDatabase = db_open(PROJECT_DB_PATH);
  90.  
  91.     db_query(g_iDatabase, "CREATE TABLE IF NOT EXISTS `projects` (name VARCHAR("#MAX_PROJECT_NAME"), creator VARCHAR(24))");
  92.     db_query(g_iDatabase, "CREATE TABLE IF NOT EXISTS `bars` (bar_id INTEGER PRIMARY KEY AUTOINCREMENT, project VARCHAR("#MAX_PROJECT_NAME"), x_pos FLOAT, y_pos FLOAT, width FLOAT, height FLOAT, max_value FLOAT, color INTEGER, direction INTEGER, FOREIGN KEY (project) REFERENCES projects(name))");
  93.  
  94.     print("\nProgress Bar Editor loaded!");
  95.     print("Use the /bar command to begin editing.\n");
  96.     return 1;
  97. }
  98.  
  99. public OnFilterScriptExit()
  100. {
  101.     for (new i = 0; i < MAX_PLAYERS; i ++)
  102.     {
  103.         if (Project[i][e_ProjectActive])
  104.         {
  105.             Project_Close(i);
  106.             ShowPlayerDialog(i, -1, DIALOG_STYLE_LIST, " ", " ", " ", "");
  107.         }
  108.     }
  109.     db_close(g_iDatabase);
  110.  
  111.     print("Progress Bar Editor unloaded!");
  112.     return 1;
  113. }
  114.  
  115. public OnPlayerConnect(playerid)
  116. {
  117.     ResetProjectData(playerid);
  118.     return 1;
  119. }
  120.  
  121. public OnPlayerDisconnect(playerid, reason)
  122. {
  123.     if (Project[playerid][e_ProjectActive])
  124.     {
  125.         Project_Close(playerid);
  126.     }
  127.     return 1;
  128. }
  129.  
  130. public OnPlayerSpawn(playerid)
  131. {
  132.     #if ADMIN_RESTRICTION == true
  133.         if (IsPlayerAdmin(playerid)) SendClientMessage(playerid, COLOR_INFO, "Use the /bar command to begin editing!");
  134.     #elseif ADMIN_RESTRICTION == false
  135.         SendClientMessage(playerid, COLOR_INFO, "Use the /bar command to begin editing!");
  136.     #endif
  137.  
  138.     return 1;
  139. }
  140.  
  141. public OnPlayerUpdate(playerid)
  142. {
  143.     new
  144.         keys,
  145.         ud,
  146.         lr;
  147.  
  148.     if (Project[playerid][e_ProjectActive] && Project[playerid][e_SelectedBar] != -1)
  149.     {
  150.         new
  151.             PlayerBar:barid = ProjectBars[playerid][Project[playerid][e_SelectedBar]][e_ProgressBarID],
  152.             string[128],
  153.             Float:x,
  154.             Float:y;
  155.  
  156.         GetPlayerKeys(playerid, keys, ud, lr);
  157.  
  158.         GetPlayerProgressBarPos(playerid, barid, x, y);
  159.  
  160.         if (keys & KEY_SECONDARY_ATTACK)
  161.         {
  162.             switch (Project[playerid][e_EditType])
  163.             {
  164.                 case EDIT_TYPE_POSITION:
  165.                 {
  166.                     UpdateProgressBarData(playerid, Project[playerid][e_SelectedBar], UPDATE_BAR_POSITION);
  167.                     SetTimerEx("ShowProgressBarMenu", 300, false, "dd", playerid, _:barid);
  168.  
  169.                     format(string, sizeof(string), "You have set the position of bar #%d.", Project[playerid][e_SelectedBar]);
  170.                     SendClientMessage(playerid, COLOR_INFO, string);
  171.                 }
  172.                 case EDIT_TYPE_SIZE:
  173.                 {
  174.                     UpdateProgressBarData(playerid, Project[playerid][e_SelectedBar], UPDATE_BAR_SIZE);
  175.                     SetTimerEx("ShowProgressBarMenu", 300, false, "dd", playerid, _:barid);
  176.  
  177.                     format(string, sizeof(string), "You have set the size of bar #%d.", Project[playerid][e_SelectedBar]);
  178.                     SendClientMessage(playerid, COLOR_INFO, string);
  179.                 }
  180.             }
  181.             TogglePlayerControllable(playerid, 1);
  182.             SetPlayerProgressBarValue(playerid, barid, 50.0);
  183.  
  184.             Project[playerid][e_EditType] = 0;
  185.         }
  186.         if (ud == KEY_UP)
  187.         {
  188.             if (Project[playerid][e_EditType] == EDIT_TYPE_POSITION)
  189.             {
  190.                 if (keys == KEY_SPRINT)
  191.                     SetPlayerProgressBarPos(playerid, barid, x, y - 5.0);
  192.                 else
  193.                     SetPlayerProgressBarPos(playerid, barid, x, y - 1.0);
  194.             }
  195.             else if (Project[playerid][e_EditType] == EDIT_TYPE_SIZE)
  196.             {
  197.                 if (keys == KEY_SPRINT)
  198.                     SetPlayerProgressBarHeight(playerid, barid, GetPlayerProgressBarHeight(playerid, barid) - 1.0);
  199.                 else
  200.                     SetPlayerProgressBarHeight(playerid, barid, GetPlayerProgressBarHeight(playerid, barid) - 0.5);
  201.             }
  202.         }
  203.         if (ud == KEY_DOWN)
  204.         {
  205.             if (Project[playerid][e_EditType] == EDIT_TYPE_POSITION)
  206.             {
  207.                 if (keys == KEY_SPRINT)
  208.                     SetPlayerProgressBarPos(playerid, barid, x, y + 5.0);
  209.                 else
  210.                     SetPlayerProgressBarPos(playerid, barid, x, y + 1.0);
  211.             }
  212.             else if (Project[playerid][e_EditType] == EDIT_TYPE_SIZE)
  213.             {
  214.                 if (keys == KEY_SPRINT)
  215.                     SetPlayerProgressBarHeight(playerid, barid, GetPlayerProgressBarHeight(playerid, barid) + 1.0);
  216.                 else
  217.                     SetPlayerProgressBarHeight(playerid, barid, GetPlayerProgressBarHeight(playerid, barid) + 0.5);
  218.             }
  219.         }
  220.         if (lr == KEY_LEFT)
  221.         {
  222.             if (Project[playerid][e_EditType] == EDIT_TYPE_POSITION)
  223.             {
  224.                 if (keys == KEY_SPRINT)
  225.                     SetPlayerProgressBarPos(playerid, barid, x - 5.0, y);
  226.                 else
  227.                     SetPlayerProgressBarPos(playerid, barid, x - 1.0, y);
  228.             }
  229.             else if (Project[playerid][e_EditType] == EDIT_TYPE_SIZE)
  230.             {
  231.                 if (keys == KEY_SPRINT)
  232.                     SetPlayerProgressBarWidth(playerid, barid, GetPlayerProgressBarWidth(playerid, barid) - 1.0);
  233.                 else
  234.                     SetPlayerProgressBarWidth(playerid, barid, GetPlayerProgressBarWidth(playerid, barid) - 0.5);
  235.             }
  236.         }
  237.         if (lr == KEY_RIGHT)
  238.         {
  239.             if (Project[playerid][e_EditType] == EDIT_TYPE_POSITION)
  240.             {
  241.                 if (keys == KEY_SPRINT)
  242.                     SetPlayerProgressBarPos(playerid, barid, x + 5.0, y);
  243.                 else
  244.                     SetPlayerProgressBarPos(playerid, barid, x + 1.0, y);
  245.             }
  246.             else if (Project[playerid][e_EditType] == EDIT_TYPE_SIZE)
  247.             {
  248.                 if (keys == KEY_SPRINT)
  249.                     SetPlayerProgressBarWidth(playerid, barid, GetPlayerProgressBarWidth(playerid, barid) + 1.0);
  250.                 else
  251.                     SetPlayerProgressBarWidth(playerid, barid, GetPlayerProgressBarWidth(playerid, barid) + 0.5);
  252.             }
  253.         }
  254.     }
  255.     return 1;
  256. }
  257.  
  258. /*
  259.     Function:
  260.         ResetProjectData
  261.     Parameters:
  262.         playerid - The player to reset the data for.
  263.     Returns:
  264.         No significant value.
  265. */
  266.  
  267. stock ResetProjectData(playerid)
  268. {
  269.     for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  270.     {
  271.         ProjectBars[playerid][i][e_DatabaseID] = 0;
  272.         ProjectBars[playerid][i][e_ProgressBarID] = INVALID_PLAYER_BAR_ID;
  273.     }
  274.     Project[playerid][e_ProjectActive] = 0;
  275.     Project[playerid][e_ProjectName] = 0;
  276.     Project[playerid][e_EditType] = 0;
  277.     Project[playerid][e_SelectedBar] = -1;
  278. }
  279.  
  280. /*
  281.     Function:
  282.         Project_ExportPath
  283.     Parameters:
  284.         name[] - Name of the project.
  285.     Returns:
  286.         The export file path for the specified project name.
  287. */
  288.  
  289. stock Project_ExportPath(name[])
  290. {
  291.     new
  292.         path[MAX_PROJECT_NAME + 14];
  293.  
  294.     format(path, sizeof(path), PROJECT_EXPORT_PATH, name);
  295.     return path;
  296. }
  297.  
  298. /*
  299.     Function:
  300.         Project_Exists
  301.     Parameters:
  302.         name[] - Name of the project.
  303.     Returns:
  304.         Returns 1 if the project file exists.
  305. */
  306.  
  307. stock Project_Exists(name[])
  308. {
  309.     new
  310.         string[128],
  311.         rows;
  312.  
  313.     format(string, sizeof(string), "SELECT `name` FROM `projects` WHERE `name` = '%s'", name);
  314.  
  315.     g_iDatabaseResult = db_query(g_iDatabase, string);
  316.  
  317.     rows = db_num_rows(g_iDatabaseResult);
  318.  
  319.     db_free_result(g_iDatabaseResult);
  320.  
  321.     return (rows > 0);
  322. }
  323.  
  324. /*
  325.     Function:
  326.         Project_Remove
  327.     Parameters:
  328.         name[] - Name of the project.
  329.     Returns:
  330.         Returns 1 if the project was removed.
  331. */
  332.  
  333. stock Project_Remove(name[])
  334. {
  335.     if (Project_Exists(name))
  336.     {
  337.         new
  338.             string[128];
  339.  
  340.         format(string, sizeof(string), "DELETE FROM projects WHERE name = '%s'", name);
  341.         db_query(g_iDatabase, string);
  342.  
  343.         format(string, sizeof(string), "DELETE FROM bars WHERE project = '%s'", name);
  344.         db_query(g_iDatabase, string);
  345.  
  346.         return 1;
  347.     }
  348.     return 0;
  349. }
  350.  
  351. /*
  352.     Function:
  353.         Project_IsOpen
  354.     Parameters:
  355.         name[] - Name of the project.
  356.     Returns:
  357.         Returns 1 if the project is opened by another player.
  358. */
  359.  
  360. stock Project_IsOpen(name[])
  361. {
  362.     for (new i = 0; i < MAX_PLAYERS; i ++)
  363.     {
  364.         if (!IsPlayerConnected(i)) continue;
  365.  
  366.         if (Project[i][e_ProjectActive] && !strcmp(Project[i][e_ProjectName], name, true))
  367.         {
  368.             return 1;
  369.         }
  370.     }
  371.     return 0;
  372. }
  373.  
  374. /*
  375.     Function:
  376.         Project_Open
  377.     Parameters:
  378.         playerid - The player that is editing the project.
  379.         name[] - Name of the project.
  380.     Returns:
  381.         1: if the project was successfully opened.
  382.         0: if another player is already editing that project.
  383. */
  384.  
  385. stock Project_Open(playerid, name[])
  386. {
  387.     new
  388.         str[128],
  389.         rows
  390.     ;
  391.     if (!Project_Exists(name))
  392.     {
  393.         // If it doesn't exist in the database, then add it in there.
  394.         GetPlayerName(playerid, str, sizeof(str));
  395.  
  396.         format(str, sizeof(str), "INSERT INTO projects (name, creator) VALUES('%s', '%s')", name, str);
  397.         db_query(g_iDatabase, str);
  398.     }
  399.     else if (Project_IsOpen(name)) // Another player is already editing this project.
  400.     {
  401.         return 0;
  402.     }
  403.  
  404.     new
  405.         Float:x,
  406.         Float:y,
  407.         Float:width,
  408.         Float:height,
  409.         Float:maxvalue,
  410.         color,
  411.         direction
  412.     ;
  413.  
  414.     format(str, sizeof(str), "SELECT * FROM `bars` WHERE `project` = '%s'", name);
  415.  
  416.     g_iDatabaseResult = db_query(g_iDatabase, str);
  417.  
  418.     rows = db_num_rows(g_iDatabaseResult);
  419.  
  420.     for (new i = 0; i < rows; i ++)
  421.     {
  422.         if (i >= MAX_PLAYER_BARS)
  423.         {
  424.             printf("Warning: Project \"%s\" contains %d bars; limit is %d.", name, rows, MAX_PLAYER_BARS);
  425.             break;
  426.         }
  427.         db_get_field_assoc(g_iDatabaseResult, "bar_id", str, sizeof(str));
  428.         ProjectBars[playerid][i][e_DatabaseID] = strval(str);
  429.  
  430.         db_get_field_assoc(g_iDatabaseResult, "x_pos", str, sizeof(str));
  431.         x = floatstr(str);
  432.  
  433.         db_get_field_assoc(g_iDatabaseResult, "y_pos", str, sizeof(str));
  434.         y = floatstr(str);
  435.  
  436.         db_get_field_assoc(g_iDatabaseResult, "width", str, sizeof(str));
  437.         width = floatstr(str);
  438.  
  439.         db_get_field_assoc(g_iDatabaseResult, "height", str, sizeof(str));
  440.         height = floatstr(str);
  441.  
  442.         db_get_field_assoc(g_iDatabaseResult, "max_value", str, sizeof(str));
  443.         maxvalue = floatstr(str);
  444.  
  445.         db_get_field_assoc(g_iDatabaseResult, "color", str, sizeof(str));
  446.         color = strval(str);
  447.  
  448.         db_get_field_assoc(g_iDatabaseResult, "direction", str, sizeof(str));
  449.         direction = strval(str);
  450.  
  451.         ProjectBars[playerid][i][e_ProgressBarID] = CreatePlayerProgressBar(playerid, x, y, width, height, color, maxvalue, direction);
  452.  
  453.         SetPlayerProgressBarValue(playerid, ProjectBars[playerid][i][e_ProgressBarID], 50.0);
  454.         ShowPlayerProgressBar(playerid, ProjectBars[playerid][i][e_ProgressBarID]);
  455.  
  456.         db_next_row(g_iDatabaseResult);
  457.     }
  458.     db_free_result(g_iDatabaseResult);
  459.  
  460.     Project[playerid][e_ProjectActive] = 1;
  461.  
  462.     return strcat(Project[playerid][e_ProjectName], name, MAX_PROJECT_NAME);
  463. }
  464.  
  465. /*
  466.     Function:
  467.         ShowProjectMainMenu
  468.     Parameters:
  469.         playerid - The player to show the main menu for.
  470.     Returns:
  471.         1: if the menu was successfully shown.
  472.         0: if the player is not editing any projects.
  473. */
  474.  
  475. stock ShowProjectMainMenu(playerid)
  476. {
  477.     if (Project[playerid][e_ProjectActive])
  478.     {
  479.         ShowProjectMenu(playerid);
  480.     }
  481.     else
  482.     {
  483.         ShowPlayerDialog(playerid, DIALOG_MAIN_MENU, DIALOG_STYLE_LIST, "Main Menu", "Create project...\nLoad project...\nDelete project...", "Select", "Cancel");
  484.     }
  485.     return 1;
  486. }
  487.  
  488. /*
  489.     Function:
  490.         ShowProjectMenu
  491.     Parameters:
  492.         playerid - The player to show the menu for.
  493.     Returns:
  494.         1: if the menu was successfully shown.
  495.         0: if the player is not editing any projects.
  496. */
  497.  
  498. forward ShowProjectMenu(playerid);
  499. public ShowProjectMenu(playerid)
  500. {
  501.     if (Project[playerid][e_ProjectActive])
  502.     {
  503.         new
  504.             string[1024];
  505.  
  506.         format(string, sizeof(string), "Create progress bar...\nExport project...\nClose project...");
  507.  
  508.         for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  509.         {
  510.             if (ProjectBars[playerid][i][e_ProgressBarID] == INVALID_PLAYER_BAR_ID)
  511.                 continue;
  512.  
  513.             switch (GetPlayerProgressBarDirection(playerid, ProjectBars[playerid][i][e_ProgressBarID]))
  514.             {
  515.                 case BAR_DIRECTION_LEFT:
  516.                     format(string, sizeof(string), "%s\n- Bar #%d - Direction: Left", string, i);
  517.                 case BAR_DIRECTION_RIGHT:
  518.                     format(string, sizeof(string), "%s\n- Bar #%d - Direction: Right", string, i);
  519.                 case BAR_DIRECTION_UP:
  520.                     format(string, sizeof(string), "%s\n- Bar #%d - Direction: Up", string, i);
  521.                 case BAR_DIRECTION_DOWN:
  522.                     format(string, sizeof(string), "%s\n- Bar #%d - Direction: Down", string, i);
  523.             }
  524.         }
  525.         ShowPlayerDialog(playerid, DIALOG_PROJECT_MENU, DIALOG_STYLE_LIST, "Project Menu", string, "Select", "Cancel");
  526.         return 1;
  527.     }
  528.     return 0;
  529. }
  530.  
  531. /*
  532.     Function:
  533.         Project_ShowList
  534.     Parameters:
  535.         playerid - The player to show the list to.
  536.         type - The type of the list.
  537.     Returns:
  538.         1: if the list was successfully shown.
  539.         0: if there wasn't anything to display.
  540. */
  541.  
  542. stock Project_ShowList(playerid, type)
  543. {
  544.     new
  545.         string[MAX_PROJECT_NAME + 3],
  546.         buffer[1024],
  547.         rows;
  548.  
  549.     strcat(buffer, "Custom name...\n");
  550.  
  551.     g_iDatabaseResult = db_query(g_iDatabase, "SELECT `name` FROM projects");
  552.  
  553.     rows = db_num_rows(g_iDatabaseResult);
  554.  
  555.     for (new i = 0; i < rows; i ++)
  556.     {
  557.         db_get_field(g_iDatabaseResult, 0, string, sizeof(string));
  558.         db_next_row(g_iDatabaseResult);
  559.  
  560.         strcat(buffer, string);
  561.         strcat(buffer, "\n");
  562.     }
  563.     db_free_result(g_iDatabaseResult);
  564.  
  565.     if (isnull(buffer))
  566.     {
  567.         return 0;
  568.     }
  569.     switch (type)
  570.     {
  571.         case LIST_TYPE_LOAD:
  572.         {
  573.             ShowPlayerDialog(playerid, DIALOG_LOAD_PROJECT, DIALOG_STYLE_LIST, "Load project...", buffer, "Load", "Cancel");
  574.         }
  575.         case LIST_TYPE_DELETE:
  576.         {
  577.             ShowPlayerDialog(playerid, DIALOG_DELETE_PROJECT, DIALOG_STYLE_LIST, "Delete project...", buffer, "Delete", "Cancel");
  578.         }
  579.     }
  580.     return 1;
  581. }
  582.  
  583. /*
  584.     Function:
  585.         Project_Close
  586.     Parameters:
  587.         playerid - The player to close the project for.
  588.     Returns:
  589.         1: if the project was closed.
  590.         0: if there wasn't any project loaded.
  591. */
  592.  
  593. stock Project_Close(playerid)
  594. {
  595.     if (Project[playerid][e_ProjectActive])
  596.     {
  597.         if (Project[playerid][e_EditType] > 0)
  598.         {
  599.             TogglePlayerControllable(playerid, 1);
  600.         }
  601.         for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  602.         {
  603.             if (ProjectBars[playerid][i][e_ProgressBarID] != INVALID_PLAYER_BAR_ID)
  604.             {
  605.                 HidePlayerProgressBar(playerid, ProjectBars[playerid][i][e_ProgressBarID]);
  606.                 DestroyPlayerProgressBar(playerid, ProjectBars[playerid][i][e_ProgressBarID]);
  607.             }
  608.         }
  609.         ResetProjectData(playerid);
  610.         return 1;
  611.     }
  612.     return 0;
  613. }
  614.  
  615. /*
  616.     Function:
  617.         ShowProgressBarMenu
  618.     Parameters:
  619.         playerid - The player to show the menu to.
  620.         PlayerBar:barid - The ID of the player bar.
  621.     Returns:
  622.         1: if the menu was shown.
  623.         0: if the player bar doesn't exist.
  624. */
  625.  
  626. forward ShowProgressBarMenu(playerid, PlayerBar:barid);
  627. public ShowProgressBarMenu(playerid, PlayerBar:barid)
  628. {
  629.     if (Project[playerid][e_ProjectActive])
  630.     {
  631.         new
  632.             string[512],
  633.             title[24];
  634.  
  635.         Project[playerid][e_SelectedBar] = GetProgressBarInternalID(playerid, barid);
  636.         format(title, sizeof(title), "Bar #%d", Project[playerid][e_SelectedBar]);
  637.  
  638.         format(string, sizeof(string), "Change position\nChange size\nChange color\nChange direction (%s)\nChange max value (%.4f)\nDuplicate bar\nDelete this bar", GetDirectionFromType(GetPlayerProgressBarDirection(playerid, barid)), GetPlayerProgressBarMaxValue(playerid, barid));
  639.         ShowPlayerDialog(playerid, DIALOG_BAR_MENU, DIALOG_STYLE_LIST, title, string, "Select", "Back");
  640.     }
  641.     return 1;
  642. }
  643.  
  644. /*
  645.     Function:
  646.         GetProgressBarInternalID
  647.     Parameters:
  648.         playerid - The player ID of the progress bar.
  649.         PlayerBar:barid - The ID of the progress bar.
  650.     Returns:
  651.         The index of "ProjectBars" that contains the progress bar ID.
  652. */
  653.  
  654. stock GetProgressBarInternalID(playerid, PlayerBar:barid)
  655. {
  656.     for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  657.     {
  658.         if (ProjectBars[playerid][i][e_ProgressBarID] == barid)
  659.         {
  660.             return i;
  661.         }
  662.     }
  663.     return -1;
  664. }
  665.  
  666. /*
  667.     Function:
  668.         DuplicateProgresssBar
  669.     Parameters:
  670.         playerid - The player ID to duplicate the progress bar for.
  671.         index - The index of the bar, relative to "ProjectBars".
  672.     Returns:
  673.         The index relative to "ProjectBars" that contains the new progress bar ID.
  674. */
  675.  
  676. stock DuplicateProgressBar(playerid, index)
  677. {
  678.     if (Project[playerid][e_ProjectActive])
  679.     {
  680.         new
  681.             PlayerBar:barid = ProjectBars[playerid][index][e_ProgressBarID],
  682.             Float:x,
  683.             Float:y;
  684.  
  685.         GetPlayerProgressBarPos(playerid, barid, x, y);
  686.         return AddBarToProject(playerid, x, y, GetPlayerProgressBarWidth(playerid, barid), GetPlayerProgressBarHeight(playerid, barid), GetPlayerProgressBarMaxValue(playerid, barid), GetPlayerProgressBarColour(playerid, barid), GetPlayerProgressBarDirection(playerid, barid));
  687.     }
  688.     return -1;
  689. }
  690.  
  691. /*
  692.     Function:
  693.         AddBarToProject
  694.     Parameters:
  695.         playerid - The player ID to add the bar for.
  696.         ... - Parameters. Check "CreatePlayerProgressBar" for more details.
  697.     Returns:
  698.         The index relative to "ProjectBars" that contains the new progress bar ID.
  699. */
  700.  
  701. stock AddBarToProject(playerid, Float:x = 280.0, Float:y = 200.0, Float:width = 55.5, Float:height = 3.2, Float:max_value = 100.0, color = -1429936641, direction = BAR_DIRECTION_RIGHT)
  702. {
  703.     new
  704.         string[160];
  705.  
  706.     if (!Project[playerid][e_ProjectActive])
  707.     {
  708.         return -1;
  709.     }
  710.     for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  711.     {
  712.         if (ProjectBars[playerid][i][e_ProgressBarID] != INVALID_PLAYER_BAR_ID) continue;
  713.  
  714.         format(string, sizeof(string), "INSERT INTO `bars` VALUES(null, '%s', %.6f, %.6f, %.6f, %.6f, %.4f, %d, %d)", Project[playerid][e_ProjectName], x, y, width, height, max_value, color, direction);
  715.         db_query(g_iDatabase, string);
  716.  
  717.         ProjectBars[playerid][i][e_ProgressBarID] = CreatePlayerProgressBar(playerid, x, y, width, height, color, max_value, direction);
  718.         ProjectBars[playerid][i][e_DatabaseID] = db_last_insert_id(g_iDatabase, "bars");
  719.  
  720.         SetPlayerProgressBarValue(playerid, ProjectBars[playerid][i][e_ProgressBarID], 50.0);
  721.         ShowPlayerProgressBar(playerid, ProjectBars[playerid][i][e_ProgressBarID]);
  722.         return i;
  723.     }
  724.     return -1;
  725. }
  726.  
  727. /*
  728.     Function:
  729.         UpdateProgressBarData
  730.     Parameters:
  731.         playerid - The player ID to add the bar for.
  732.         index - Index of the progress bar, relative to "ProjectBars".
  733.         type - Type of data to update in the database.
  734.     Returns:
  735.         Returns 1 if the data was successfully updated.
  736. */
  737.  
  738. stock UpdateProgressBarData(playerid, index, type)
  739. {
  740.     new
  741.         PlayerBar:barid = ProjectBars[playerid][index][e_ProgressBarID],
  742.         string[128];
  743.  
  744.     if (IsValidPlayerProgressBar(playerid, barid))
  745.     {
  746.         switch (type)
  747.         {
  748.             case UPDATE_BAR_POSITION:
  749.             {
  750.                 new
  751.                     Float:x,
  752.                     Float:y;
  753.  
  754.                 GetPlayerProgressBarPos(playerid, barid, x, y);
  755.  
  756.                 format(string, sizeof(string), "UPDATE `bars` SET `x_pos` = %.6f, `y_pos` = %.6f WHERE `bar_id` = %d", x, y, ProjectBars[playerid][index][e_DatabaseID]);
  757.                 db_query(g_iDatabase, string);
  758.             }
  759.             case UPDATE_BAR_SIZE:
  760.             {
  761.                 format(string, sizeof(string), "UPDATE `bars` SET `width` = %.6f, `height` = %.6f WHERE `bar_id` = %d", GetPlayerProgressBarWidth(playerid, barid), GetPlayerProgressBarHeight(playerid, barid), ProjectBars[playerid][index][e_DatabaseID]);
  762.                 db_query(g_iDatabase, string);
  763.             }
  764.             case UPDATE_BAR_DIRECTION:
  765.             {
  766.                 format(string, sizeof(string), "UPDATE `bars` SET `direction` = %d WHERE `bar_id` = %d", GetPlayerProgressBarDirection(playerid, barid), ProjectBars[playerid][index][e_DatabaseID]);
  767.                 db_query(g_iDatabase, string);
  768.             }
  769.             case UPDATE_BAR_MAX_VALUE:
  770.             {
  771.                 format(string, sizeof(string), "UPDATE `bars` SET `max_value` = %.6f WHERE `bar_id` = %d", GetPlayerProgressBarMaxValue(playerid, barid), ProjectBars[playerid][index][e_DatabaseID]);
  772.                 db_query(g_iDatabase, string);
  773.             }
  774.             case UPDATE_BAR_COLOR:
  775.             {
  776.                 format(string, sizeof(string), "UPDATE `bars` SET `color` = %d WHERE `bar_id` = %d", GetPlayerProgressBarColour(playerid, barid), ProjectBars[playerid][index][e_DatabaseID]);
  777.                 db_query(g_iDatabase, string);
  778.             }
  779.         }
  780.         return 1;
  781.     }
  782.     return 0;
  783. }
  784.  
  785. stock GetDirectionFromType(direction)
  786. {
  787.     new
  788.         str[6];
  789.  
  790.     if (direction == BAR_DIRECTION_LEFT)
  791.         str = "Left";
  792.     else if (direction == BAR_DIRECTION_RIGHT)
  793.         str = "Right";
  794.     else if (direction == BAR_DIRECTION_UP)
  795.         str = "Up";
  796.     else if (direction == BAR_DIRECTION_DOWN)
  797.         str = "Down";
  798.  
  799.     return str;
  800. }
  801.  
  802. stock StrToHex(str[])
  803. {
  804.     // Credits to Y_Less.
  805.  
  806.     new
  807.         i,
  808.         value;
  809.  
  810.     if (str[0] == '0' && (str [1] == 'x' || str [1] == 'X'))
  811.         i = 2;
  812.  
  813.     while (str[i])
  814.     {
  815.         value <<= 4;
  816.  
  817.         switch (str[i])
  818.         {
  819.             case '0'..'9':
  820.                 value |= str [i] - '0';
  821.  
  822.             case 'A'..'F':
  823.                 value |= str [i] - 'A' + 10;
  824.  
  825.             case 'a'..'f':
  826.                 value |= str [i] - 'a' + 10;
  827.  
  828.             default:
  829.                 return 0;
  830.         }
  831.         ++ i;
  832.     }
  833.     return value;
  834. }
  835.  
  836. stock db_last_insert_id(DB:database, const table[])
  837. {
  838.     new
  839.         DBResult:result,
  840.         string[64];
  841.  
  842.     format(string, sizeof(string), "SELECT last_insert_rowid() FROM %s", table);
  843.  
  844.     result = db_query(database, string);
  845.  
  846.     db_get_field(result, 0, string, sizeof(string));
  847.  
  848.     db_free_result(result);
  849.  
  850.     return strval(string);
  851. }
  852.  
  853. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  854. {
  855.     new
  856.         string[255],
  857.         PlayerBar:barid,
  858.         index = -1;
  859.  
  860.     if (Project[playerid][e_ProjectActive] && (index = Project[playerid][e_SelectedBar]) != -1)
  861.     {
  862.         barid = ProjectBars[playerid][Project[playerid][e_SelectedBar]][e_ProgressBarID];
  863.     }
  864.  
  865.     switch (dialogid)
  866.     {
  867.         case DIALOG_MAIN_MENU:
  868.         {
  869.             if (response)
  870.             {
  871.                 switch (listitem)
  872.                 {
  873.                     case 0: // Create new project
  874.                     {
  875.                         ShowPlayerDialog(playerid, DIALOG_CREATE_PROJECT, DIALOG_STYLE_INPUT, "Create new project...", "Please enter the name of your new project below:\nThe name must contain only letters, numbers and spaces.", "Submit", "Back");
  876.                     }
  877.                     case 1: // Load existing project
  878.                     {
  879.                         Project_ShowList(playerid, LIST_TYPE_LOAD);
  880.                     }
  881.                     case 2: // Delete project
  882.                     {
  883.                         new
  884.                             success = Project_ShowList(playerid, LIST_TYPE_DELETE);
  885.  
  886.                         if (!success) return SendClientMessage(playerid, COLOR_ERROR, "There are no projects to delete.");
  887.                     }
  888.                 }
  889.             }
  890.         }
  891.         case DIALOG_CREATE_PROJECT:
  892.         {
  893.             if (response)
  894.             {
  895.                 if (isnull(inputtext))
  896.                 {
  897.                     return ShowPlayerDialog(playerid, DIALOG_CREATE_PROJECT, DIALOG_STYLE_INPUT, "Create new project...", "Please enter the name of your new project below:\nThe name must contain only letters, numbers and spaces.", "Submit", "Back");
  898.                 }
  899.                 else if (strlen(inputtext) > 32)
  900.                 {
  901.                     return ShowPlayerDialog(playerid, DIALOG_CREATE_PROJECT, DIALOG_STYLE_INPUT, "Create new project...", "Please enter the name of your new project below:\nThe name must contain only letters, numbers and spaces.", "Submit", "Back");
  902.                 }
  903.                 else if (Project_Exists(inputtext))
  904.                 {
  905.                     return ShowPlayerDialog(playerid, DIALOG_CREATE_PROJECT, DIALOG_STYLE_INPUT, "Create new project...", "The specified project name is already in use!\n\nPlease enter the name of your new project below:\nThe name must contain only letters, numbers and spaces.", "Submit", "Back");
  906.                 }
  907.                 else
  908.                 {
  909.                     for (new i = 0, l = strlen(inputtext); i < l; i ++)
  910.                     {
  911.                         switch (inputtext[i])
  912.                         {
  913.                             case '\\', '/', ':', '*', '"', '?', '<', '>', '|', '\'':
  914.                             {
  915.                                 return ShowPlayerDialog(playerid, DIALOG_CREATE_PROJECT, DIALOG_STYLE_INPUT, "Create new project...", "You have entered invalid characters. Please remove them and try again.\n\nPlease enter the name of your new project below:\nThe name must contain only letters, numbers and spaces.", "Submit", "Back");
  916.                             }
  917.                         }
  918.                     }
  919.                     format(string, sizeof(string), "You have created project \"%s\".", inputtext);
  920.                     SendClientMessage(playerid, COLOR_INFO, string);
  921.  
  922.                     Project_Open(playerid, inputtext);
  923.                     ShowProjectMenu(playerid);
  924.                 }
  925.             }
  926.             else
  927.             {
  928.                 ShowProjectMainMenu(playerid);
  929.             }
  930.         }
  931.         case DIALOG_LOAD_PROJECT:
  932.         {
  933.             if (response)
  934.             {
  935.                 if (!listitem) // Custom name...
  936.                 {
  937.                     ShowPlayerDialog(playerid, DIALOG_LOAD_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "Please enter the name of the project you wish to load:", "Submit", "Back");
  938.                 }
  939.                 else
  940.                 {
  941.                     new
  942.                         pos = -1;
  943.  
  944.                     // strip extra characters
  945.                     if ((pos = strfind(inputtext, "\r")) != -1) strdel(inputtext, pos, pos + 1);
  946.                     if ((pos = strfind(inputtext, "\n")) != -1) strdel(inputtext, pos, pos + 1);
  947.  
  948.                     format(string, sizeof(string), "You have loaded project \"%s\".", inputtext);
  949.                     SendClientMessage(playerid, COLOR_INFO, string);
  950.  
  951.                     Project_Open(playerid, inputtext);
  952.                     ShowProjectMenu(playerid);
  953.                 }
  954.             }
  955.             else
  956.             {
  957.                 ShowProjectMainMenu(playerid);
  958.             }
  959.         }
  960.         case DIALOG_LOAD_CUSTOM:
  961.         {
  962.             if (response)
  963.             {
  964.                 if (isnull(inputtext) || strlen(inputtext) > 32)
  965.                 {
  966.                     ShowPlayerDialog(playerid, DIALOG_LOAD_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "Please enter the name of the project you wish to load:", "Submit", "Back");
  967.                 }
  968.                 else if (!Project_Exists(inputtext))
  969.                 {
  970.                     ShowPlayerDialog(playerid, DIALOG_LOAD_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "The specified project name doesn't exist.\n\nPlease enter the name of the project you wish to load:", "Submit", "Back");
  971.                 }
  972.                 else if (Project_IsOpen(inputtext))
  973.                 {
  974.                     ShowPlayerDialog(playerid, DIALOG_LOAD_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "The specified project is being edited by another player.\n\nPlease enter the name of the project you wish to load:", "Submit", "Back");
  975.                 }
  976.                 else
  977.                 {
  978.                     format(string, sizeof(string), "You have loaded project \"%s\".", inputtext);
  979.                     SendClientMessage(playerid, COLOR_INFO, string);
  980.  
  981.                     Project_Open(playerid, inputtext);
  982.                     ShowProjectMenu(playerid);
  983.                 }
  984.             }
  985.             else
  986.             {
  987.                 Project_ShowList(playerid, LIST_TYPE_LOAD);
  988.             }
  989.         }
  990.         case DIALOG_DELETE_PROJECT:
  991.         {
  992.             if (response)
  993.             {
  994.                 if (!listitem) // Custom name...
  995.                 {
  996.                     ShowPlayerDialog(playerid, DIALOG_DELETE_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "Please enter the name of the project you wish to delete:", "Submit", "Back");
  997.                 }
  998.                 else
  999.                 {
  1000.                     new
  1001.                         pos = -1;
  1002.  
  1003.                     // strip extra characters
  1004.                     if ((pos = strfind(inputtext, "\r")) != -1) strdel(inputtext, pos, pos + 1);
  1005.                     if ((pos = strfind(inputtext, "\n")) != -1) strdel(inputtext, pos, pos + 1);
  1006.  
  1007.                     Project[playerid][e_ProjectToDelete] = 0;
  1008.                     strcat(Project[playerid][e_ProjectToDelete], inputtext, MAX_PROJECT_NAME);
  1009.  
  1010.                     format(string, sizeof(string), "You are about to delete project \"%s\"!\nYou cannot recover a project once it is deleted.", inputtext);
  1011.                     ShowPlayerDialog(playerid, DIALOG_DELETE_CONFIRM, DIALOG_STYLE_MSGBOX, "Delete project...", string, "Yes", "No");
  1012.                 }
  1013.             }
  1014.             else
  1015.             {
  1016.                 ShowProjectMainMenu(playerid);
  1017.             }
  1018.         }
  1019.         case DIALOG_DELETE_CUSTOM:
  1020.         {
  1021.             if (response)
  1022.             {
  1023.                 if (isnull(inputtext) || strlen(inputtext) > 32)
  1024.                 {
  1025.                     ShowPlayerDialog(playerid, DIALOG_DELETE_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "Please enter the name of the project you wish to delete:", "Submit", "Back");
  1026.                 }
  1027.                 else if (!Project_Exists(inputtext))
  1028.                 {
  1029.                     ShowPlayerDialog(playerid, DIALOG_DELETE_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "The specified project name doesn't exist.\n\nPlease enter the name of the project you wish to delete:", "Submit", "Back");
  1030.                 }
  1031.                 else if (Project_IsOpen(inputtext))
  1032.                 {
  1033.                     ShowPlayerDialog(playerid, DIALOG_DELETE_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "The specified project is being edited by another player.\n\nPlease enter the name of the project you wish to delete:", "Submit", "Back");
  1034.                 }
  1035.                 else
  1036.                 {
  1037.                     Project[playerid][e_ProjectToDelete] = 0;
  1038.                     strcat(Project[playerid][e_ProjectToDelete], inputtext, MAX_PROJECT_NAME);
  1039.  
  1040.                     format(string, sizeof(string), "You are about to delete project \"%s\"!\nYou cannot recover a project once it is deleted.", inputtext);
  1041.                     ShowPlayerDialog(playerid, DIALOG_DELETE_CONFIRM, DIALOG_STYLE_MSGBOX, "Delete project...", string, "Yes", "No");
  1042.                 }
  1043.             }
  1044.             else
  1045.             {
  1046.                 Project_ShowList(playerid, LIST_TYPE_LOAD);
  1047.             }
  1048.         }
  1049.         case DIALOG_DELETE_CONFIRM:
  1050.         {
  1051.             if (response)
  1052.             {
  1053.                 Project_Remove(Project[playerid][e_ProjectToDelete]);
  1054.  
  1055.                 format(string, sizeof(string), "You have deleted project \"%s\".", Project[playerid][e_ProjectToDelete]);
  1056.                 SendClientMessage(playerid, COLOR_INFO, string);
  1057.  
  1058.                 Project[playerid][e_ProjectToDelete] = 0;
  1059.             }
  1060.             else
  1061.             {
  1062.                 ShowProjectMainMenu(playerid);
  1063.             }
  1064.         }
  1065.         case DIALOG_PROJECT_MENU:
  1066.         {
  1067.             if (response)
  1068.             {
  1069.                 switch (listitem)
  1070.                 {
  1071.                     case 0: // Create progress bar...
  1072.                     {
  1073.                         new
  1074.                             id = AddBarToProject(playerid);
  1075.  
  1076.                         if (id != -1)
  1077.                         {
  1078.                             format(string, sizeof(string), "You have created progress bar #%d.", id);
  1079.                             SendClientMessage(playerid, COLOR_INFO, string);
  1080.  
  1081.                             ShowProjectMenu(playerid);
  1082.                             return 1;
  1083.                         }
  1084.                         else
  1085.                         {
  1086.                             SendClientMessage(playerid, COLOR_ERROR, "Please adjust the \"MAX_PLAYER_BARS\" setting in \"progress2.inc\" to add more progress bars.");
  1087.                             ShowProjectMenu(playerid);
  1088.                         }
  1089.                     }
  1090.                     case 1: // Export project...
  1091.                     {
  1092.                         new
  1093.                             File:file = fopen(Project_ExportPath(Project[playerid][e_ProjectName]), io_write),
  1094.                             Float:x,
  1095.                             Float:y,
  1096.                             date[6]
  1097.                         ;
  1098.  
  1099.                         if (file)
  1100.                         {
  1101.                             getdate(date[0], date[1], date[2]);
  1102.                             gettime(date[3], date[4], date[5]);
  1103.  
  1104.                             format(string, sizeof(string), "/*\r\n * Project Name: %s\r\n * Date: %02d/%02d/%d @ %02d:%02d:%02d\r\n\r\n * The code below is to be used with the Progress Bar V2 include.\r\n *\r\n*/\r\n\r\n", Project[playerid][e_ProjectName], date[2], date[1], date[0], date[3], date[4], date[5]);
  1105.                             fwrite(file, string);
  1106.  
  1107.                             fwrite(file, "#include <a_samp>\r\n#include <progress2>\r\n\r\n");
  1108.  
  1109.                             for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  1110.                             {
  1111.                                 if (ProjectBars[playerid][i][e_ProgressBarID] != INVALID_PLAYER_BAR_ID)
  1112.                                 {
  1113.                                     format(string, sizeof(string), "new PlayerBar:Bar%d[MAX_PLAYERS];\r\n", i);
  1114.                                     fwrite(file, string);
  1115.                                 }
  1116.                             }
  1117.                             fwrite(file, "\r\npublic OnPlayerConnect(playerid)\r\n{\r\n");
  1118.  
  1119.                             for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  1120.                             {
  1121.                                 if (ProjectBars[playerid][i][e_ProgressBarID] == INVALID_PLAYER_BAR_ID)
  1122.                                     continue;
  1123.  
  1124.                                 GetPlayerProgressBarPos(playerid, ProjectBars[playerid][i][e_ProgressBarID], x, y);
  1125.  
  1126.                                 format(string, sizeof(string), "    Bar%d[playerid] = CreatePlayerProgressBar(playerid, %.6f, %.6f, %.6f, %.6f, %d, %.4f, %d);\r\n",
  1127.                                     i,
  1128.                                     x,
  1129.                                     y,
  1130.                                     GetPlayerProgressBarWidth(playerid, ProjectBars[playerid][i][e_ProgressBarID]),
  1131.                                     GetPlayerProgressBarHeight(playerid, ProjectBars[playerid][i][e_ProgressBarID]),
  1132.                                     GetPlayerProgressBarColour(playerid, ProjectBars[playerid][i][e_ProgressBarID]),
  1133.                                     GetPlayerProgressBarMaxValue(playerid, ProjectBars[playerid][i][e_ProgressBarID]),
  1134.                                     GetPlayerProgressBarDirection(playerid, ProjectBars[playerid][i][e_ProgressBarID])
  1135.                                 );
  1136.  
  1137.                                 fwrite(file, string);
  1138.                             }
  1139.                             fwrite(file, "\r\n    return 1;\r\n}\r\n\r\npublic OnPlayerSpawn(playerid)\r\n{\r\n");
  1140.  
  1141.                             for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  1142.                             {
  1143.                                 if (ProjectBars[playerid][i][e_ProgressBarID] == INVALID_PLAYER_BAR_ID)
  1144.                                     continue;
  1145.  
  1146.                                 format(string, sizeof(string), "    ShowPlayerProgressBar(playerid, Bar%d[playerid]);\r\n", i);
  1147.                                 fwrite(file, string);
  1148.                             }
  1149.                             fwrite(file, "\r\n    return 1;\r\n}\r\n");
  1150.                             fclose(file);
  1151.  
  1152.                             format(string, sizeof(string), "Project has been exported to \"%s\".", Project_ExportPath(Project[playerid][e_ProjectName]));
  1153.                             SendClientMessage(playerid, COLOR_INFO, string);
  1154.  
  1155.                             ShowProjectMenu(playerid);
  1156.                         }
  1157.                     }
  1158.                     case 2: // Close project...
  1159.                     {
  1160.                         format(string, sizeof(string), "You have closed project \"%s\".", Project[playerid][e_ProjectName]);
  1161.                         SendClientMessage(playerid, COLOR_INFO, string);
  1162.  
  1163.                         Project_Close(playerid);
  1164.                         ShowProjectMainMenu(playerid);
  1165.                     }
  1166.                     default: // Player selected a bar
  1167.                     {
  1168.                         index = strval(inputtext[7]);
  1169.  
  1170.                         if (!IsValidPlayerProgressBar(playerid, ProjectBars[playerid][index][e_ProgressBarID]))
  1171.                         {
  1172.                             SendClientMessage(playerid, COLOR_ERROR, "Whoops! There seems to be a problem here... Please contact Emmet.");
  1173.                         }
  1174.                         else
  1175.                         {
  1176.                             ShowProgressBarMenu(playerid, ProjectBars[playerid][index][e_ProgressBarID]);
  1177.                         }
  1178.                     }
  1179.                 }
  1180.             }
  1181.         }
  1182.         case DIALOG_BAR_MENU:
  1183.         {
  1184.             if (response)
  1185.             {
  1186.                 switch (listitem)
  1187.                 {
  1188.                     case 0: // Change position
  1189.                     {
  1190.                         Project[playerid][e_EditType] = EDIT_TYPE_POSITION;
  1191.                         TogglePlayerControllable(playerid, 0);
  1192.  
  1193.                         format(string, sizeof(string), "You are changing bar #%d's position. Use the arrow keys to move the bar and press Enter when done.", index);
  1194.                         SendClientMessage(playerid, COLOR_INFO, string);
  1195.                     }
  1196.                     case 1: // Change size
  1197.                     {
  1198.                         Project[playerid][e_EditType] = EDIT_TYPE_SIZE;
  1199.                         TogglePlayerControllable(playerid, 0);
  1200.  
  1201.                         format(string, sizeof(string), "You are changing bar #%d's size. Use the arrow keys to adjust the size and press Enter when done.", index);
  1202.                         SendClientMessage(playerid, COLOR_INFO, string);
  1203.                     }
  1204.                     case 2: // Change color
  1205.                     {
  1206.                         ShowPlayerDialog(playerid, DIALOG_COLOR_INPUT, DIALOG_STYLE_INPUT, "Change color", "Please enter the new color for this progress bar below:\nYou must enter a hexadecimal value. The hex color for white is 0xFFFFFFFF.", "Submit", "Back");
  1207.                     }
  1208.                     case 3: // Change direction
  1209.                     {
  1210.                         ShowPlayerDialog(playerid, DIALOG_DIRECTION_LIST, DIALOG_STYLE_LIST, "Change direction", "Right\nLeft\nUp\nDown", "Select", "Back");
  1211.                     }
  1212.                     case 4: // Change max value
  1213.                     {
  1214.                         format(string, sizeof(string), "Please enter the new maximum value for this bar below (current: %.4f):", GetPlayerProgressBarMaxValue(playerid, barid));
  1215.                         ShowPlayerDialog(playerid, DIALOG_MAX_VALUE, DIALOG_STYLE_INPUT, "Change max value", string, "Submit", "Back");
  1216.                     }
  1217.                     case 5: // Duplicate bar
  1218.                     {
  1219.                         new
  1220.                             id = DuplicateProgressBar(playerid, index);
  1221.  
  1222.                         if (id != -1)
  1223.                         {
  1224.                             format(string, sizeof(string), "You have duplicated progress bar #%d (new ID: #%d).", index, id);
  1225.                             SendClientMessage(playerid, COLOR_INFO, string);
  1226.  
  1227.                             ShowProjectMenu(playerid);
  1228.                         }
  1229.                         else
  1230.                         {
  1231.                             SendClientMessage(playerid, COLOR_ERROR, "Please adjust the \"MAX_PLAYER_BARS\" setting in \"progress2.inc\" to add more progress bars.");
  1232.                             ShowProjectMenu(playerid);
  1233.                         }
  1234.                     }
  1235.                     case 6: // Delete this bar
  1236.                     {
  1237.                         format(string, sizeof(string), "DELETE FROM `bars` WHERE `bar_id` = %d", ProjectBars[playerid][index][e_DatabaseID]);
  1238.                         db_query(g_iDatabase, string);
  1239.  
  1240.                         HidePlayerProgressBar(playerid, barid);
  1241.                         DestroyPlayerProgressBar(playerid, barid);
  1242.  
  1243.                         format(string, sizeof(string), "You have deleted progress bar #%d.", index);
  1244.                         SendClientMessage(playerid, COLOR_INFO, string);
  1245.  
  1246.                         ProjectBars[playerid][index][e_ProgressBarID] = INVALID_PLAYER_BAR_ID;
  1247.                         ProjectBars[playerid][index][e_DatabaseID] = 0;
  1248.  
  1249.                         Project[playerid][e_SelectedBar] = -1;
  1250.  
  1251.                         return ShowProjectMenu(playerid);
  1252.                     }
  1253.                 }
  1254.             }
  1255.             else
  1256.             {
  1257.                 ShowProjectMenu(playerid);
  1258.             }
  1259.         }
  1260.         case DIALOG_COLOR_INPUT:
  1261.         {
  1262.             if (response)
  1263.             {
  1264.                 if (isnull(inputtext) || (strlen(inputtext) != 6 && strlen(inputtext) != 8))
  1265.                 {
  1266.                     ShowPlayerDialog(playerid, DIALOG_COLOR_INPUT, DIALOG_STYLE_INPUT, "Change color", "Please enter the new color for this progress bar below:\nYou must enter a hexadecimal value. The hex color for white is 0xFFFFFFFF.", "Submit", "Back");
  1267.                 }
  1268.                 else
  1269.                 {
  1270.                     new color = StrToHex(inputtext);
  1271.  
  1272.                     SetPlayerProgressBarColour(playerid, barid, color);
  1273.  
  1274.                     ShowPlayerProgressBar(playerid, barid);
  1275.                     UpdateProgressBarData(playerid, index, UPDATE_BAR_COLOR);
  1276.  
  1277.                     format(string, sizeof(string), "You have set bar #%d's color to {%06x}%s.", index, color >>> 8, inputtext);
  1278.                     SendClientMessage(playerid, COLOR_INFO, string);
  1279.  
  1280.                     ShowProgressBarMenu(playerid, barid);
  1281.                 }
  1282.             }
  1283.             else
  1284.             {
  1285.                 ShowProgressBarMenu(playerid, barid);
  1286.             }
  1287.         }
  1288.         case DIALOG_DIRECTION_LIST:
  1289.         {
  1290.             if (response)
  1291.             {
  1292.                 SetPlayerProgressBarDirection(playerid, barid, listitem);
  1293.                 UpdateProgressBarData(playerid, index, UPDATE_BAR_DIRECTION);
  1294.  
  1295.                 format(string, sizeof(string), "You have changed bar #%d's direction to %s.", index, GetDirectionFromType(listitem));
  1296.                 SendClientMessage(playerid, COLOR_INFO, string);
  1297.  
  1298.                 ShowProgressBarMenu(playerid, barid);
  1299.             }
  1300.             else
  1301.             {
  1302.                 ShowProgressBarMenu(playerid, barid);
  1303.             }
  1304.         }
  1305.         case DIALOG_MAX_VALUE:
  1306.         {
  1307.             if (response)
  1308.             {
  1309.                 if (isnull(inputtext))
  1310.                 {
  1311.                     format(string, sizeof(string), "Please enter the new maximum value for this bar below (current: %.4f):", GetPlayerProgressBarMaxValue(playerid, barid));
  1312.                     ShowPlayerDialog(playerid, DIALOG_MAX_VALUE, DIALOG_STYLE_INPUT, "Change max value", string, "Submit", "Back");
  1313.                 }
  1314.                 else
  1315.                 {
  1316.                     new
  1317.                         Float:max_value = floatstr(inputtext);
  1318.  
  1319.                     SetPlayerProgressBarMaxValue(playerid, barid, max_value);
  1320.                     UpdateProgressBarData(playerid, index, UPDATE_BAR_MAX_VALUE);
  1321.  
  1322.                     format(string, sizeof(string), "You have changed bar #%d's maximum value to %.4f.", index, max_value);
  1323.                     SendClientMessage(playerid, COLOR_INFO, string);
  1324.  
  1325.                     ShowProgressBarMenu(playerid, barid);
  1326.                 }
  1327.             }
  1328.             else
  1329.             {
  1330.                 ShowProgressBarMenu(playerid, barid);
  1331.             }
  1332.         }
  1333.     }
  1334.     return 0;
  1335. }
  1336.  
  1337. CMD:bar(playerid, params[])
  1338. {
  1339.     #if ADMIN_RESTRICTION == true
  1340.         if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_ERROR, "You must be an RCON admin to use the editor.");
  1341.     #endif
  1342.  
  1343.     if (Project[playerid][e_EditType] > 0)
  1344.     {
  1345.         return SendClientMessage(playerid, COLOR_ERROR, "You must finish editing before you can use this command.");
  1346.     }
  1347.     ShowProjectMainMenu(playerid);
  1348.     return 1;
  1349. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement