Proportion calculations for textdraw -
CuervO - 17.02.2014
Hey there, i'm making a dynamic inventory system (which I'll most likely release) and I've got stuck at some "complex" part. I've got the GUI and the containers and all running already in a very decent phase, however I can't get to think this proportional:
The system has a sidebar thingy, where the sidebar increases it's size by or shrinks depending the amount of pages. This works perfectly, but I can't get the formula to proportionally place the bar according the page between the coords.
Images:
Page 1: bar completely at the top
Page 2: bar at the exact half
Page 3: bar at somewhere around 75%
Page 4: bar near 90%
Page 5: bar near 95%
Here is the code
pawn Код:
new totalpages = objects;
SetPVarInt(playerid, "DisplayingPages", totalpages);
new Float:barsize = 34.2/float(totalpages); //34.2 is the max value it can have, it will take the whole bar.
if(barsize < 0.2)
barsize = 0.2;
PlayerTextDrawLetterSize(playerid, Inv[playerid][16], 0.509999, barsize);
PlayerTextDrawShow(playerid, Inv[playerid][16]);
Min Y value for the bar: 125
Max Y value for the bar: 425
Min Y letter size: 0.2
Max Y letter size: 34.2
pawn Код:
PlayerTextDrawDestroy(playerid, Inv[playerid][16]);
new Float:ypos = (300/GetPVarInt(playerid,"DisplayingPage")) - 425; //here's the actual calculation
ypos = floatabs(ypos);
Inv[playerid][16] = CreatePlayerTextDraw(playerid, 636.500000, ypos, "_");
PlayerTextDrawAlignment(playerid, Inv[playerid][16], 2);
PlayerTextDrawBackgroundColor(playerid, Inv[playerid][16], 255);
PlayerTextDrawFont(playerid, Inv[playerid][16], 1);
new Float:barsize = 34.2/float(GetPVarInt(playerid,"DisplayingPages"));
if(barsize < 0.2)
barsize = 0.2;
PlayerTextDrawLetterSize(playerid, Inv[playerid][16], 0.509999, barsize);
PlayerTextDrawColor(playerid, Inv[playerid][16], -1442840321);
PlayerTextDrawSetOutline(playerid, Inv[playerid][16], 0);
PlayerTextDrawSetProportional(playerid, Inv[playerid][16], 1);
PlayerTextDrawSetShadow(playerid, Inv[playerid][16], 1);
PlayerTextDrawUseBox(playerid, Inv[playerid][16], 1);
PlayerTextDrawBoxColor(playerid, Inv[playerid][16], -1157627734);
PlayerTextDrawTextSize(playerid, Inv[playerid][16], 0.000000, 4.000000);
PlayerTextDrawShow(playerid, Inv[playerid][16]);
As you can see, the number of pages can vary depending the amount of objects you've got, that's where it needs proportions which I suck at, or am too tired to think about them. (But i'll go with the first one)
Re: Proportion calculations for textdraw -
CuervO - 17.02.2014
Posting for future reference.
Solved - It was a simple three rule:
300 (Difference between Max Y and Min Y) - Total Pages (all of the pages)
X (unknown Y for each page) - Current Page
So you can calculate: ((300 * (Current Page-1))/Total Pages)+125 and you'll get the proportional Y coordinate.
-1 Is there so it can result 0 and go back to the start:: 0/0 = 0 (not really) + 125 = 125.
Re: Proportion calculations for textdraw -
Pottus - 17.02.2014
You really shouldn't be using PVars I wouldn't even think of using any system that has even one PVar they're very low standard.
Re: Proportion calculations for textdraw -
CuervO - 17.02.2014
Quote:
Originally Posted by [uL]Pottus
You really shouldn't be using PVars I wouldn't even think of using any system that has even one PVar they're very low standard.
|
They are pretty simple, their only deficency is that they are a bit slower than normal variables, plus allow beter managment of Id variables (such as timers, objects, textdraws, etc). That still, the script so far features four PVars: DisplayingPage, MinDisplay, DisplayingPages, RotZ. I found it easier to use PVars when doing fast stuff that always changes rather than defining the function, reset it every time I need to re-use it and blabla..
Anyways, that's your own opinion without fundaments, of course.
Re: Proportion calculations for textdraw -
Pottus - 17.02.2014
Quote:
Originally Posted by CuervO
They are pretty simple, their only deficency is that they are a bit slower than normal variables, plus allow beter managment of Id variables (such as timers, objects, textdraws, etc). That still, the script so far features four PVars: DisplayingPage, MinDisplay, DisplayingPages, RotZ. I found it easier to use PVars when doing fast stuff that always changes rather than defining the function, reset it every time I need to re-use it and blabla..
Anyways, that's your own opinion without fundaments, of course.
|
That is straight non-sense, I think what your explaining to me is how NOT to script how could anyone expect to make a good gamemode like that is beyond me my friend you are very lazy when you don't have to be and shouldn't be.
Re: Proportion calculations for textdraw -
CuervO - 17.02.2014
Quote:
Originally Posted by [uL]Pottus
That is straight non-sense, I think what your explaining to me is how NOT to script how could anyone expect to make a good gamemode like that is beyond me my friend you are very lazy when you don't have to be and shouldn't be.
|
Explain good gamemode;
Explain How not to script;
Then explain me how PVars make a person a nosenser. And counter example me with valid arguments. Go on, I'm waiting to learn something new.
Re: Proportion calculations for textdraw -
Pottus - 17.02.2014
Here is an example of a good gamemode
https://github.com/Southclaw/ScavengeSurvive
Here is an example of how not to script
https://sampforum.blast.hk/showthread.php?tid=140427
Here is all about PVars
https://sampforum.blast.hk/showthread.php?tid=268499
If you examine all of that you will realize the error of your ways
Re: Proportion calculations for textdraw -
CuervO - 17.02.2014
Quote:
Originally Posted by [uL]Pottus
|
Everyone has different methods and specializations - Like it or not, not everyone follows the unique way, because there isn't any.
P.S: I will continue to use PVars so you don't use the script, though.