[Include] progress3D - Create progress bars in 3D space
#1

progress3D.inc



After the 2D textdraw-based version of progress bars, here now comes the 3D version. This library lets you create progress bars in 3D space. It's basically just two overlapping 3D text labels, one being moved slightly to the right to fill in those gaps between the characters. Have fun with it!

Repository



Functions
  • Bar3D:CreateProgressBar3D(Float:x, Float:y, Float:z, layout, fill_color, background_color, Float:max_value, Float:init_value, Float:drawdistance, attachedplayer = INVALID_PLAYER_ID, attachedvehicle = INVALID_VEHICLE_ID, testlos = 0, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = STREAMER_3D_TEXT_LABEL_SD, areaid = -1, priority = 0)
    • Creates a 3D progress bar.
  • DestroyProgressBar3D(Bar3D:barid)
    • Destroys a 3D progress bar.
  • GetProgressBar3DValue(Bar3D:barid)
    • Returns the current progress value.
  • SetProgressBar3DValue(Bar3D:barid, Float:value)
    • Updates the value of the specified 3D progress bar.
  • GetProgressBar3DFillColor(Bar3D:barid)
    • Returns the fill color of the specified 3D progress bar.
  • SetProgressBar3DFillColor(Bar3D:barid, fill_color)
    • Updates the fill color of the specified 3D progress bar.
  • GetProgressBar3DBackgroundColor(Bar3D:barid)
    • Returns the background color of the specified 3D progress bar.
  • SetProgressBar3DBackgroundColor(Bar3D:barid, background_color)
    • Updates the background color of the specified 3D progress bar.
  • GetProgressBar3DMaxValue(Bar3D:barid)
    • Returns the maximum value of the specified 3D progress bar.
  • SetProgressBar3DMaxValue(Bar3D:barid, Float:max_value)
    • Updates the maximum value of the specified 3D progress bar.
  • GetProgressBar3DLayout(Bar3D:barid)
    • Returns the layout of the specified 3D progress bar.
  • SetProgressBar3DLayout(Bar3D:barid, layout)
    • Updates the layout of the specified 3D progress bar.
  • IsValidProgressBar3D(Bar3D:barid)
    • Returns true, if the specified 3D progress bar ID is valid and exists.
Changelog

v2.0
  • Update to YSI 5
  • Added compatibility for streamer version 2.9.4
  • Fixed a bug in SetProgressBar3DLayout(...) which caused the wrong layout to be applied
  • Minor code refactoring
v1.3.1
  • Moved the position parameters x, y, z to the front of Bar3D:CreateProgressBar3D(...)
  • Slightly improved code readability
v1.3
  • Added a new parameter layout with three new bar layout options
    • BAR_3D_LAYOUT_THIN
    • BAR_3D_LAYOUT_NORMAL
    • BAR_3D_LAYOUT_THICK
  • Added GetProgressBar3DLayout(Bar3D:barid) and SetProgressBar3DLayout(Bar3D:barid, layout)
v1.2.1
  • Fixed getter functions (forgot to add "_:" to the returned value)
v1.2
  • Added the parameter Float:max_value to Bar3D:CreateProgressBar3D(...)
  • Added GetProgressBar3DMaxValue(Bar3D:barid)
  • Added SetProgressBar3DMaxValue(Bar3D:barid, Float:max_value)
  • Updated the testing script
v1.1
  • Code optimizations
  • Internal check if value ranges from 0 to 100.
v1.0
  • Initial release
Reply
#2

Код:
static Bar3D:Bars3D[MAX_3D_BARS][BAR_3D_DATA],
       Text3D:Bars1[MAX_3D_BARS],
       Text3D:Bars2[MAX_3D_BARS];

new Iterator:Bars3D_Index<MAX_3D_BARS>,
    Iterator:Bars1_Index<MAX_3D_BARS>,
    Iterator:Bars2_Index<MAX_3D_BARS>;
Create one iterator, one variable and one enum instead of this disaster.
Reply
#3

It looks interesting but it improves the code please.

Good release
Reply
#4

I'm taking this!

Nice work.
Reply
#5

First of all, thank you for the constructive feedback!

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
Another thing I noticed was a lot of copy-paste code, bar1/bar2 could be globally allocated as `static const` to remove the need to allocate on the stack. And the code that calculates and manipulates the label text could be delegated to a separate function because currently it's copied into three places, if you had to fix a bug you'd have to fix it three times, which increases the chances of typos introducing more bugs!

Aside from that, the code is pretty good. There might be some string manipulation optimisations to be done but it's probably unnecessary. Good work!
In the first pass, I usually prioritize functional over optimized code - the latter is something I bother about in the second pass, so delegating the progress calculation to a separate function is definitely something I'll do, thanks!

About the stack allocation: So, you're saying that I should just do this?
PHP код:
static const bar1[] = "IIIIIIIIIIIIIIIIIIIIIIIII",
             
bar2[] = " IIIIIIIIIIIIIIIIIIIIIIIII"
Reply
#6

So if for example i have a timer of 20 seconds, how i can set the progress bar to fill completely in 20 seconds?
Reply
#7

For now, the progress is calculated in percent, so 0.0 is the minimum and 100.0 is the maximum value.
So, if 20 seconds are 100%, then 1 seconds equals 100/20 = 5%. So, each second, you would have to increase the value by 5.0.

I realize, this might be a bit inconvenient to use. I might add "min_value" and "max_value" parameters and let the function do the calculations for you in the near future.
Reply
#8

Nice release.
Reply
#9

Good release
Reply
#10

Quote:
Originally Posted by Manyula
Посмотреть сообщение
For now, the progress is calculated in percent, so 0.0 is the minimum and 100.0 is the maximum value.
I've now added a 'max_value' parameter and three new layout options for bar thickness. Thanks for the feedback!
Reply
#11

I don't see the download link...
Reply
#12

Quote:
Originally Posted by Unrea1
Посмотреть сообщение
I don't see the download link...
https://github.com/TheManyula/progress3D/releases

(It's currently missing from the main post for some reason)
Reply
#13

Please update this for support streamer plugin v2.9.4, i've found many error for streamer v.2.9.4
Reply
#14

The test pwn is just crashing my pawncc. cant compile it :B 0.3.7
Reply
#15

Quote:
Originally Posted by tonmgdamamg3
Посмотреть сообщение
Please update this for support streamer plugin v2.9.4, i've found many error for streamer v.2.9.4
The errors are caused by the 2.9.4 version of the streamer plugin.

EDIT: The issue was a tag that got removed in the new streamer version. progress3D version 2.0 is now compatible with streamer version 2.9.4.

Quote:
Originally Posted by RenanMsV
Посмотреть сообщение
The test pwn is just crashing my pawncc. cant compile it :B 0.3.7
Are you using sampctl? Which compiler version are you using?
Reply
#16

Awesome, no border?
Reply
#17

Quote:
Originally Posted by Kar
Посмотреть сообщение
Awesome, no border?
Unfortunately no border. Adding outlines to the characters themselves also adds their outlines to the center of the progress bar.
In order to add a border that only surrounds the bar would require four entirely black bars covering all four edges, so eight additional 3D text labels. I don't think that's worth it.
Quite some time ago, I suggested adding variable font sizes and letter spacing to 3D text labels which would drastically reduce the amount of labels required. Since that hasn't happened, there's nothing I can do.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)