17.02.2014, 10:32
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
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
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)
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]);