-
Notifications
You must be signed in to change notification settings - Fork 64
/
editor-emmet.pwn
1349 lines (1169 loc) · 37.7 KB
/
editor-emmet.pwn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Progress bar editor by Emmet_
* Made for Southclaw's Progress Bars v2.
*
* Features:
* - Ability to adjust all settings, including direction, color, and size.
* - Uses SQLite for better organization.
* - Supports multiple progress bars.
*/
#include <a_samp>
#include <progress2>
#include <zcmd>
#define COLOR_INFO (0xFFDD00FF)
#define COLOR_ERROR (0xFF5030FF)
#define PROJECT_DB_PATH "projects.db" // Path of the file that stores all of the project names.
#define PROJECT_EXPORT_PATH "%s.pwn" // Path of the export file location.
#define ADMIN_RESTRICTION false // Restrict the progress bar editor to RCON admins only?
#define MAX_PROJECT_NAME 24 // Maximum amount of characters in a project name.
#define DIALOG_MAIN_MENU 18300
#define DIALOG_LOAD_PROJECT 18301
#define DIALOG_LOAD_CUSTOM 18302
#define DIALOG_DELETE_PROJECT 18303
#define DIALOG_DELETE_CUSTOM 18304
#define DIALOG_DELETE_CONFIRM 18305
#define DIALOG_CREATE_PROJECT 18306
#define DIALOG_PROJECT_MENU 18307
#define DIALOG_BAR_MENU 18308
#define DIALOG_COLOR_INPUT 18309
#define DIALOG_DIRECTION_LIST 18310
#define DIALOG_MAX_VALUE 18311
#define LIST_TYPE_LOAD 1
#define LIST_TYPE_DELETE 2
#define UPDATE_BAR_POSITION 1
#define UPDATE_BAR_SIZE 2
#define UPDATE_BAR_DIRECTION 3
#define UPDATE_BAR_MAX_VALUE 4
#define UPDATE_BAR_COLOR 5
#define EDIT_TYPE_POSITION 1
#define EDIT_TYPE_SIZE 2
enum e_ProjectData
{
// Indicates if a project is active.
e_ProjectActive,
// Name of the project.
e_ProjectName[MAX_PROJECT_NAME],
// Name of the project to delete.
e_ProjectToDelete[MAX_PROJECT_NAME],
// Editing type. (1) Position (2) Size
e_EditType,
// Index of the selected progress bar, relative to "ProjectBars"
e_SelectedBar
};
new Project[MAX_PLAYERS][e_ProjectData];
enum e_ProjectBars
{
// Database ID of the progress bar's record.
e_DatabaseID,
// ID of the progress bar.
PlayerBar:e_ProgressBarID
};
new ProjectBars[MAX_PLAYERS][MAX_PLAYER_BARS][e_ProjectBars];
new DB:g_iDatabase;
new DBResult:g_iDatabaseResult;
public OnFilterScriptInit()
{
for (new i = 0; i < MAX_PLAYERS; i ++)
{
if (IsPlayerConnected(i)) ResetProjectData(i);
}
g_iDatabase = db_open(PROJECT_DB_PATH);
db_query(g_iDatabase, "CREATE TABLE IF NOT EXISTS `projects` (name VARCHAR("#MAX_PROJECT_NAME"), creator VARCHAR(24))");
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))");
print("\nProgress Bar Editor loaded!");
print("Use the /bar command to begin editing.\n");
return 1;
}
public OnFilterScriptExit()
{
for (new i = 0; i < MAX_PLAYERS; i ++)
{
if (Project[i][e_ProjectActive])
{
Project_Close(i);
ShowPlayerDialog(i, -1, DIALOG_STYLE_LIST, " ", " ", " ", "");
}
}
db_close(g_iDatabase);
print("Progress Bar Editor unloaded!");
return 1;
}
public OnPlayerConnect(playerid)
{
ResetProjectData(playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if (Project[playerid][e_ProjectActive])
{
Project_Close(playerid);
}
return 1;
}
public OnPlayerSpawn(playerid)
{
#if ADMIN_RESTRICTION == true
if (IsPlayerAdmin(playerid)) SendClientMessage(playerid, COLOR_INFO, "Use the /bar command to begin editing!");
#elseif ADMIN_RESTRICTION == false
SendClientMessage(playerid, COLOR_INFO, "Use the /bar command to begin editing!");
#endif
return 1;
}
public OnPlayerUpdate(playerid)
{
new
keys,
ud,
lr;
if (Project[playerid][e_ProjectActive] && Project[playerid][e_SelectedBar] != -1)
{
new
PlayerBar:barid = ProjectBars[playerid][Project[playerid][e_SelectedBar]][e_ProgressBarID],
string[128],
Float:x,
Float:y;
GetPlayerKeys(playerid, keys, ud, lr);
GetPlayerProgressBarPos(playerid, barid, x, y);
if (keys & KEY_SECONDARY_ATTACK)
{
switch (Project[playerid][e_EditType])
{
case EDIT_TYPE_POSITION:
{
UpdateProgressBarData(playerid, Project[playerid][e_SelectedBar], UPDATE_BAR_POSITION);
SetTimerEx("ShowProgressBarMenu", 300, false, "dd", playerid, _:barid);
format(string, sizeof(string), "You have set the position of bar #%d.", Project[playerid][e_SelectedBar]);
SendClientMessage(playerid, COLOR_INFO, string);
}
case EDIT_TYPE_SIZE:
{
UpdateProgressBarData(playerid, Project[playerid][e_SelectedBar], UPDATE_BAR_SIZE);
SetTimerEx("ShowProgressBarMenu", 300, false, "dd", playerid, _:barid);
format(string, sizeof(string), "You have set the size of bar #%d.", Project[playerid][e_SelectedBar]);
SendClientMessage(playerid, COLOR_INFO, string);
}
}
TogglePlayerControllable(playerid, 1);
SetPlayerProgressBarValue(playerid, barid, 50.0);
Project[playerid][e_EditType] = 0;
}
if (ud == KEY_UP)
{
if (Project[playerid][e_EditType] == EDIT_TYPE_POSITION)
{
if (keys == KEY_SPRINT)
SetPlayerProgressBarPos(playerid, barid, x, y - 5.0);
else
SetPlayerProgressBarPos(playerid, barid, x, y - 1.0);
}
else if (Project[playerid][e_EditType] == EDIT_TYPE_SIZE)
{
if (keys == KEY_SPRINT)
SetPlayerProgressBarHeight(playerid, barid, GetPlayerProgressBarHeight(playerid, barid) - 1.0);
else
SetPlayerProgressBarHeight(playerid, barid, GetPlayerProgressBarHeight(playerid, barid) - 0.5);
}
}
if (ud == KEY_DOWN)
{
if (Project[playerid][e_EditType] == EDIT_TYPE_POSITION)
{
if (keys == KEY_SPRINT)
SetPlayerProgressBarPos(playerid, barid, x, y + 5.0);
else
SetPlayerProgressBarPos(playerid, barid, x, y + 1.0);
}
else if (Project[playerid][e_EditType] == EDIT_TYPE_SIZE)
{
if (keys == KEY_SPRINT)
SetPlayerProgressBarHeight(playerid, barid, GetPlayerProgressBarHeight(playerid, barid) + 1.0);
else
SetPlayerProgressBarHeight(playerid, barid, GetPlayerProgressBarHeight(playerid, barid) + 0.5);
}
}
if (lr == KEY_LEFT)
{
if (Project[playerid][e_EditType] == EDIT_TYPE_POSITION)
{
if (keys == KEY_SPRINT)
SetPlayerProgressBarPos(playerid, barid, x - 5.0, y);
else
SetPlayerProgressBarPos(playerid, barid, x - 1.0, y);
}
else if (Project[playerid][e_EditType] == EDIT_TYPE_SIZE)
{
if (keys == KEY_SPRINT)
SetPlayerProgressBarWidth(playerid, barid, GetPlayerProgressBarWidth(playerid, barid) - 1.0);
else
SetPlayerProgressBarWidth(playerid, barid, GetPlayerProgressBarWidth(playerid, barid) - 0.5);
}
}
if (lr == KEY_RIGHT)
{
if (Project[playerid][e_EditType] == EDIT_TYPE_POSITION)
{
if (keys == KEY_SPRINT)
SetPlayerProgressBarPos(playerid, barid, x + 5.0, y);
else
SetPlayerProgressBarPos(playerid, barid, x + 1.0, y);
}
else if (Project[playerid][e_EditType] == EDIT_TYPE_SIZE)
{
if (keys == KEY_SPRINT)
SetPlayerProgressBarWidth(playerid, barid, GetPlayerProgressBarWidth(playerid, barid) + 1.0);
else
SetPlayerProgressBarWidth(playerid, barid, GetPlayerProgressBarWidth(playerid, barid) + 0.5);
}
}
}
return 1;
}
/*
Function:
ResetProjectData
Parameters:
playerid - The player to reset the data for.
Returns:
No significant value.
*/
stock ResetProjectData(playerid)
{
for (new i = 0; i < MAX_PLAYER_BARS; i ++)
{
ProjectBars[playerid][i][e_DatabaseID] = 0;
ProjectBars[playerid][i][e_ProgressBarID] = INVALID_PLAYER_BAR_ID;
}
Project[playerid][e_ProjectActive] = 0;
Project[playerid][e_ProjectName] = 0;
Project[playerid][e_EditType] = 0;
Project[playerid][e_SelectedBar] = -1;
}
/*
Function:
Project_ExportPath
Parameters:
name[] - Name of the project.
Returns:
The export file path for the specified project name.
*/
stock Project_ExportPath(name[])
{
new
path[MAX_PROJECT_NAME + 14];
format(path, sizeof(path), PROJECT_EXPORT_PATH, name);
return path;
}
/*
Function:
Project_Exists
Parameters:
name[] - Name of the project.
Returns:
Returns 1 if the project file exists.
*/
stock Project_Exists(name[])
{
new
string[128],
rows;
format(string, sizeof(string), "SELECT `name` FROM `projects` WHERE `name` = '%s'", name);
g_iDatabaseResult = db_query(g_iDatabase, string);
rows = db_num_rows(g_iDatabaseResult);
db_free_result(g_iDatabaseResult);
return (rows > 0);
}
/*
Function:
Project_Remove
Parameters:
name[] - Name of the project.
Returns:
Returns 1 if the project was removed.
*/
stock Project_Remove(name[])
{
if (Project_Exists(name))
{
new
string[128];
format(string, sizeof(string), "DELETE FROM projects WHERE name = '%s'", name);
db_query(g_iDatabase, string);
format(string, sizeof(string), "DELETE FROM bars WHERE project = '%s'", name);
db_query(g_iDatabase, string);
return 1;
}
return 0;
}
/*
Function:
Project_IsOpen
Parameters:
name[] - Name of the project.
Returns:
Returns 1 if the project is opened by another player.
*/
stock Project_IsOpen(name[])
{
for (new i = 0; i < MAX_PLAYERS; i ++)
{
if (!IsPlayerConnected(i)) continue;
if (Project[i][e_ProjectActive] && !strcmp(Project[i][e_ProjectName], name, true))
{
return 1;
}
}
return 0;
}
/*
Function:
Project_Open
Parameters:
playerid - The player that is editing the project.
name[] - Name of the project.
Returns:
1: if the project was successfully opened.
0: if another player is already editing that project.
*/
stock Project_Open(playerid, name[])
{
new
str[128],
rows
;
if (!Project_Exists(name))
{
// If it doesn't exist in the database, then add it in there.
GetPlayerName(playerid, str, sizeof(str));
format(str, sizeof(str), "INSERT INTO projects (name, creator) VALUES('%s', '%s')", name, str);
db_query(g_iDatabase, str);
}
else if (Project_IsOpen(name)) // Another player is already editing this project.
{
return 0;
}
new
Float:x,
Float:y,
Float:width,
Float:height,
Float:maxvalue,
color,
direction
;
format(str, sizeof(str), "SELECT * FROM `bars` WHERE `project` = '%s'", name);
g_iDatabaseResult = db_query(g_iDatabase, str);
rows = db_num_rows(g_iDatabaseResult);
for (new i = 0; i < rows; i ++)
{
if (i >= MAX_PLAYER_BARS)
{
printf("Warning: Project \"%s\" contains %d bars; limit is %d.", name, rows, MAX_PLAYER_BARS);
break;
}
db_get_field_assoc(g_iDatabaseResult, "bar_id", str, sizeof(str));
ProjectBars[playerid][i][e_DatabaseID] = strval(str);
db_get_field_assoc(g_iDatabaseResult, "x_pos", str, sizeof(str));
x = floatstr(str);
db_get_field_assoc(g_iDatabaseResult, "y_pos", str, sizeof(str));
y = floatstr(str);
db_get_field_assoc(g_iDatabaseResult, "width", str, sizeof(str));
width = floatstr(str);
db_get_field_assoc(g_iDatabaseResult, "height", str, sizeof(str));
height = floatstr(str);
db_get_field_assoc(g_iDatabaseResult, "max_value", str, sizeof(str));
maxvalue = floatstr(str);
db_get_field_assoc(g_iDatabaseResult, "color", str, sizeof(str));
color = strval(str);
db_get_field_assoc(g_iDatabaseResult, "direction", str, sizeof(str));
direction = strval(str);
ProjectBars[playerid][i][e_ProgressBarID] = CreatePlayerProgressBar(playerid, x, y, width, height, color, maxvalue, direction);
SetPlayerProgressBarValue(playerid, ProjectBars[playerid][i][e_ProgressBarID], 50.0);
ShowPlayerProgressBar(playerid, ProjectBars[playerid][i][e_ProgressBarID]);
db_next_row(g_iDatabaseResult);
}
db_free_result(g_iDatabaseResult);
Project[playerid][e_ProjectActive] = 1;
return strcat(Project[playerid][e_ProjectName], name, MAX_PROJECT_NAME);
}
/*
Function:
ShowProjectMainMenu
Parameters:
playerid - The player to show the main menu for.
Returns:
1: if the menu was successfully shown.
0: if the player is not editing any projects.
*/
stock ShowProjectMainMenu(playerid)
{
if (Project[playerid][e_ProjectActive])
{
ShowProjectMenu(playerid);
}
else
{
ShowPlayerDialog(playerid, DIALOG_MAIN_MENU, DIALOG_STYLE_LIST, "Main Menu", "Create project...\nLoad project...\nDelete project...", "Select", "Cancel");
}
return 1;
}
/*
Function:
ShowProjectMenu
Parameters:
playerid - The player to show the menu for.
Returns:
1: if the menu was successfully shown.
0: if the player is not editing any projects.
*/
forward ShowProjectMenu(playerid);
public ShowProjectMenu(playerid)
{
if (Project[playerid][e_ProjectActive])
{
new
string[1024];
format(string, sizeof(string), "Create progress bar...\nExport project...\nClose project...");
for (new i = 0; i < MAX_PLAYER_BARS; i ++)
{
if (ProjectBars[playerid][i][e_ProgressBarID] == INVALID_PLAYER_BAR_ID)
continue;
switch (GetPlayerProgressBarDirection(playerid, ProjectBars[playerid][i][e_ProgressBarID]))
{
case BAR_DIRECTION_LEFT:
format(string, sizeof(string), "%s\n- Bar #%d - Direction: Left", string, i);
case BAR_DIRECTION_RIGHT:
format(string, sizeof(string), "%s\n- Bar #%d - Direction: Right", string, i);
case BAR_DIRECTION_UP:
format(string, sizeof(string), "%s\n- Bar #%d - Direction: Up", string, i);
case BAR_DIRECTION_DOWN:
format(string, sizeof(string), "%s\n- Bar #%d - Direction: Down", string, i);
}
}
ShowPlayerDialog(playerid, DIALOG_PROJECT_MENU, DIALOG_STYLE_LIST, "Project Menu", string, "Select", "Cancel");
return 1;
}
return 0;
}
/*
Function:
Project_ShowList
Parameters:
playerid - The player to show the list to.
type - The type of the list.
Returns:
1: if the list was successfully shown.
0: if there wasn't anything to display.
*/
stock Project_ShowList(playerid, type)
{
new
string[MAX_PROJECT_NAME + 3],
buffer[1024],
rows;
strcat(buffer, "Custom name...\n");
g_iDatabaseResult = db_query(g_iDatabase, "SELECT `name` FROM projects");
rows = db_num_rows(g_iDatabaseResult);
for (new i = 0; i < rows; i ++)
{
db_get_field(g_iDatabaseResult, 0, string, sizeof(string));
db_next_row(g_iDatabaseResult);
strcat(buffer, string);
strcat(buffer, "\n");
}
db_free_result(g_iDatabaseResult);
if (isnull(buffer))
{
return 0;
}
switch (type)
{
case LIST_TYPE_LOAD:
{
ShowPlayerDialog(playerid, DIALOG_LOAD_PROJECT, DIALOG_STYLE_LIST, "Load project...", buffer, "Load", "Cancel");
}
case LIST_TYPE_DELETE:
{
ShowPlayerDialog(playerid, DIALOG_DELETE_PROJECT, DIALOG_STYLE_LIST, "Delete project...", buffer, "Delete", "Cancel");
}
}
return 1;
}
/*
Function:
Project_Close
Parameters:
playerid - The player to close the project for.
Returns:
1: if the project was closed.
0: if there wasn't any project loaded.
*/
stock Project_Close(playerid)
{
if (Project[playerid][e_ProjectActive])
{
if (Project[playerid][e_EditType] > 0)
{
TogglePlayerControllable(playerid, 1);
}
for (new i = 0; i < MAX_PLAYER_BARS; i ++)
{
if (ProjectBars[playerid][i][e_ProgressBarID] != INVALID_PLAYER_BAR_ID)
{
HidePlayerProgressBar(playerid, ProjectBars[playerid][i][e_ProgressBarID]);
DestroyPlayerProgressBar(playerid, ProjectBars[playerid][i][e_ProgressBarID]);
}
}
ResetProjectData(playerid);
return 1;
}
return 0;
}
/*
Function:
ShowProgressBarMenu
Parameters:
playerid - The player to show the menu to.
PlayerBar:barid - The ID of the player bar.
Returns:
1: if the menu was shown.
0: if the player bar doesn't exist.
*/
forward ShowProgressBarMenu(playerid, PlayerBar:barid);
public ShowProgressBarMenu(playerid, PlayerBar:barid)
{
if (Project[playerid][e_ProjectActive])
{
new
string[512],
title[24];
Project[playerid][e_SelectedBar] = GetProgressBarInternalID(playerid, barid);
format(title, sizeof(title), "Bar #%d", Project[playerid][e_SelectedBar]);
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));
ShowPlayerDialog(playerid, DIALOG_BAR_MENU, DIALOG_STYLE_LIST, title, string, "Select", "Back");
}
return 1;
}
/*
Function:
GetProgressBarInternalID
Parameters:
playerid - The player ID of the progress bar.
PlayerBar:barid - The ID of the progress bar.
Returns:
The index of "ProjectBars" that contains the progress bar ID.
*/
stock GetProgressBarInternalID(playerid, PlayerBar:barid)
{
for (new i = 0; i < MAX_PLAYER_BARS; i ++)
{
if (ProjectBars[playerid][i][e_ProgressBarID] == barid)
{
return i;
}
}
return -1;
}
/*
Function:
DuplicateProgresssBar
Parameters:
playerid - The player ID to duplicate the progress bar for.
index - The index of the bar, relative to "ProjectBars".
Returns:
The index relative to "ProjectBars" that contains the new progress bar ID.
*/
stock DuplicateProgressBar(playerid, index)
{
if (Project[playerid][e_ProjectActive])
{
new
PlayerBar:barid = ProjectBars[playerid][index][e_ProgressBarID],
Float:x,
Float:y;
GetPlayerProgressBarPos(playerid, barid, x, y);
return AddBarToProject(playerid, x, y, GetPlayerProgressBarWidth(playerid, barid), GetPlayerProgressBarHeight(playerid, barid), GetPlayerProgressBarMaxValue(playerid, barid), GetPlayerProgressBarColour(playerid, barid), GetPlayerProgressBarDirection(playerid, barid));
}
return -1;
}
/*
Function:
AddBarToProject
Parameters:
playerid - The player ID to add the bar for.
... - Parameters. Check "CreatePlayerProgressBar" for more details.
Returns:
The index relative to "ProjectBars" that contains the new progress bar ID.
*/
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)
{
new
string[160];
if (!Project[playerid][e_ProjectActive])
{
return -1;
}
for (new i = 0; i < MAX_PLAYER_BARS; i ++)
{
if (ProjectBars[playerid][i][e_ProgressBarID] != INVALID_PLAYER_BAR_ID) continue;
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);
db_query(g_iDatabase, string);
ProjectBars[playerid][i][e_ProgressBarID] = CreatePlayerProgressBar(playerid, x, y, width, height, color, max_value, direction);
ProjectBars[playerid][i][e_DatabaseID] = db_last_insert_id(g_iDatabase, "bars");
SetPlayerProgressBarValue(playerid, ProjectBars[playerid][i][e_ProgressBarID], 50.0);
ShowPlayerProgressBar(playerid, ProjectBars[playerid][i][e_ProgressBarID]);
return i;
}
return -1;
}
/*
Function:
UpdateProgressBarData
Parameters:
playerid - The player ID to add the bar for.
index - Index of the progress bar, relative to "ProjectBars".
type - Type of data to update in the database.
Returns:
Returns 1 if the data was successfully updated.
*/
stock UpdateProgressBarData(playerid, index, type)
{
new
PlayerBar:barid = ProjectBars[playerid][index][e_ProgressBarID],
string[128];
if (IsValidPlayerProgressBar(playerid, barid))
{
switch (type)
{
case UPDATE_BAR_POSITION:
{
new
Float:x,
Float:y;
GetPlayerProgressBarPos(playerid, barid, x, y);
format(string, sizeof(string), "UPDATE `bars` SET `x_pos` = %.6f, `y_pos` = %.6f WHERE `bar_id` = %d", x, y, ProjectBars[playerid][index][e_DatabaseID]);
db_query(g_iDatabase, string);
}
case UPDATE_BAR_SIZE:
{
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]);
db_query(g_iDatabase, string);
}
case UPDATE_BAR_DIRECTION:
{
format(string, sizeof(string), "UPDATE `bars` SET `direction` = %d WHERE `bar_id` = %d", GetPlayerProgressBarDirection(playerid, barid), ProjectBars[playerid][index][e_DatabaseID]);
db_query(g_iDatabase, string);
}
case UPDATE_BAR_MAX_VALUE:
{
format(string, sizeof(string), "UPDATE `bars` SET `max_value` = %.6f WHERE `bar_id` = %d", GetPlayerProgressBarMaxValue(playerid, barid), ProjectBars[playerid][index][e_DatabaseID]);
db_query(g_iDatabase, string);
}
case UPDATE_BAR_COLOR:
{
format(string, sizeof(string), "UPDATE `bars` SET `color` = %d WHERE `bar_id` = %d", GetPlayerProgressBarColour(playerid, barid), ProjectBars[playerid][index][e_DatabaseID]);
db_query(g_iDatabase, string);
}
}
return 1;
}
return 0;
}
stock GetDirectionFromType(direction)
{
new
str[6];
if (direction == BAR_DIRECTION_LEFT)
str = "Left";
else if (direction == BAR_DIRECTION_RIGHT)
str = "Right";
else if (direction == BAR_DIRECTION_UP)
str = "Up";
else if (direction == BAR_DIRECTION_DOWN)
str = "Down";
return str;
}
stock StrToHex(str[])
{
// Credits to Y_Less.
new
i,
value;
if (str[0] == '0' && (str [1] == 'x' || str [1] == 'X'))
i = 2;
while (str[i])
{
value <<= 4;
switch (str[i])
{
case '0'..'9':
value |= str [i] - '0';
case 'A'..'F':
value |= str [i] - 'A' + 10;
case 'a'..'f':
value |= str [i] - 'a' + 10;
default:
return 0;
}
++ i;
}
return value;
}
stock db_last_insert_id(DB:database, const table[])
{
new
DBResult:result,
string[64];
format(string, sizeof(string), "SELECT last_insert_rowid() FROM %s", table);
result = db_query(database, string);
db_get_field(result, 0, string, sizeof(string));
db_free_result(result);
return strval(string);
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
new
string[255],
PlayerBar:barid,
index = -1;
if (Project[playerid][e_ProjectActive] && (index = Project[playerid][e_SelectedBar]) != -1)
{
barid = ProjectBars[playerid][Project[playerid][e_SelectedBar]][e_ProgressBarID];
}
switch (dialogid)
{
case DIALOG_MAIN_MENU:
{
if (response)
{
switch (listitem)
{
case 0: // Create new project
{
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");
}
case 1: // Load existing project
{
Project_ShowList(playerid, LIST_TYPE_LOAD);
}
case 2: // Delete project
{
new
success = Project_ShowList(playerid, LIST_TYPE_DELETE);
if (!success) return SendClientMessage(playerid, COLOR_ERROR, "There are no projects to delete.");
}
}
}
}
case DIALOG_CREATE_PROJECT:
{
if (response)
{
if (isnull(inputtext))
{
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");
}
else if (strlen(inputtext) > 32)
{
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");
}
else if (Project_Exists(inputtext))
{
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");
}
else
{
for (new i = 0, l = strlen(inputtext); i < l; i ++)
{
switch (inputtext[i])
{
case '\\', '/', ':', '*', '"', '?', '<', '>', '|', '\'':
{
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");
}
}
}
format(string, sizeof(string), "You have created project \"%s\".", inputtext);
SendClientMessage(playerid, COLOR_INFO, string);
Project_Open(playerid, inputtext);
ShowProjectMenu(playerid);
}
}
else
{
ShowProjectMainMenu(playerid);
}
}
case DIALOG_LOAD_PROJECT:
{
if (response)
{
if (!listitem) // Custom name...
{
ShowPlayerDialog(playerid, DIALOG_LOAD_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "Please enter the name of the project you wish to load:", "Submit", "Back");
}
else
{
new
pos = -1;
// strip extra characters
if ((pos = strfind(inputtext, "\r")) != -1) strdel(inputtext, pos, pos + 1);
if ((pos = strfind(inputtext, "\n")) != -1) strdel(inputtext, pos, pos + 1);
format(string, sizeof(string), "You have loaded project \"%s\".", inputtext);
SendClientMessage(playerid, COLOR_INFO, string);
Project_Open(playerid, inputtext);
ShowProjectMenu(playerid);
}
}
else
{
ShowProjectMainMenu(playerid);
}
}
case DIALOG_LOAD_CUSTOM:
{
if (response)
{
if (isnull(inputtext) || strlen(inputtext) > 32)
{
ShowPlayerDialog(playerid, DIALOG_LOAD_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "Please enter the name of the project you wish to load:", "Submit", "Back");
}
else if (!Project_Exists(inputtext))
{
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");
}
else if (Project_IsOpen(inputtext))
{
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");
}
else
{
format(string, sizeof(string), "You have loaded project \"%s\".", inputtext);
SendClientMessage(playerid, COLOR_INFO, string);
Project_Open(playerid, inputtext);
ShowProjectMenu(playerid);
}
}
else
{
Project_ShowList(playerid, LIST_TYPE_LOAD);
}
}
case DIALOG_DELETE_PROJECT:
{
if (response)
{
if (!listitem) // Custom name...
{
ShowPlayerDialog(playerid, DIALOG_DELETE_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "Please enter the name of the project you wish to delete:", "Submit", "Back");
}
else
{
new