Jump to content
Lorenz94

Displaying text on fuel bar

Recommended Posts

Hello, I'm trying to add a text line showing a real time percentage over the fuel bar.

What I'm facing is a problem in centering the text on the full lenght of the bar, based on how many numbers do have the text (eg: 1%, 10%, 100%).

 

Can someone more confident with default dialogs please help? What I have is as follows, and works, but not centered:

Spoiler

_rscUnitInfo = uiNamespace getVariable "RscUnitInfo";
_ctrlPos = ctrlPosition (_rscUnitInfo displayCtrl 113);

_ctrlPos params ["_x", "_y", "_w", "_h"];

_ctrl = findDisplay 46 ctrlCreate ["ctrlStructuredText", 200401];
_ctrl ctrlSetFont "PuristaSemibold";
_ctrl ctrlSetText format ["%1%2", ((fuel objectParent player)*100) toFixed 0, "%"];
_ctrl ctrlSetPosition [_x +0.125, _y - _h, _w, _h +0.1];
_ctrl ctrlCommit 0;

 

Thank you!

Share this post


Link to post
Share on other sites
_rscUnitInfo = uiNamespace getVariable "RscUnitInfo";
_ctrlPos = ctrlPosition (_rscUnitInfo displayCtrl 113);

_ctrlPos params ["_xP", "_yP", "_wP", "_hP"];

_ctrl = _rscUnitInfo ctrlCreate ["RscStructuredText", 200401];
_ctrl ctrlSetTextColor [0,0,0,1];
_ctrl ctrlSetStructuredText parseText format  ["<t align='center' size='0.45' shadow='0'>%1%2</t>", ((fuel vehicle player)*100) toFixed 0, "%"];
_ctrl ctrlSetPosition [_xP, _yP - _hP/2, _wP, 2 * _hP];
_ctrl ctrlCommit 0;

 

The magic here is the Structured Text. The attribute "center" aligns the text.

Some other notes:

  1. You can use the display itself to display the value. When exiting the vehicle it is reset and doesn't show up anymore.
  2. Use the RscStructuredText base class. When chaning the ui size it scales the text size correctly.
  3. ctrlSetTextColor for more contrast on white background
  4. You can play around with the 'size' parameter to find something that suits you
  5. vehicle command instead of objectParent seems a bit more intuitive but doesnt matter
  6. GUI positions are a bit complicated. You were using absolute values which will stay the same while the ui changes depending on UI size, screen size, ...

 

The only problem that remains is that RscUnitInfo closes as soon as you leave the vehicle. Calling it everytime the player enters a vehicle is a possible solutin with a getin EH.

  • Like 2

Share this post


Link to post
Share on other sites
7 hours ago, 7erra said:

_rscUnitInfo = uiNamespace getVariable "RscUnitInfo";
_ctrlPos = ctrlPosition (_rscUnitInfo displayCtrl 113);

_ctrlPos params ["_xP", "_yP", "_wP", "_hP"];

_ctrl = _rscUnitInfo ctrlCreate ["RscStructuredText", 200401];
_ctrl ctrlSetTextColor [0,0,0,1];
_ctrl ctrlSetStructuredText parseText format  ["<t align='center' size='0.45' shadow='0'>%1%2</t>", ((fuel vehicle player)*100) toFixed 0, "%"];
_ctrl ctrlSetPosition [_xP, _yP - _hP/2, _wP, 2 * _hP];
_ctrl ctrlCommit 0;

 

The magic here is the Structured Text. The attribute "center" aligns the text.

Some other notes:

  1. You can use the display itself to display the value. When exiting the vehicle it is reset and doesn't show up anymore.
  2. Use the RscStructuredText base class. When chaning the ui size it scales the text size correctly.
  3. ctrlSetTextColor for more contrast on white background
  4. You can play around with the 'size' parameter to find something that suits you
  5. vehicle command instead of objectParent seems a bit more intuitive but doesnt matter
  6. GUI positions are a bit complicated. You were using absolute values which will stay the same while the ui changes depending on UI size, screen size, ...

 

The only problem that remains is that RscUnitInfo closes as soon as you leave the vehicle. Calling it everytime the player enters a vehicle is a possible solutin with a getin EH.

Thank you 7erra, this works as I intended. I can't see the difference between my coordinates and yours, where can understand you're not using  absolute values? Thank you!

Share this post


Link to post
Share on other sites
15 hours ago, Lorenz94 said:

I can't see the difference between my coordinates and yours, where can understand you're not using  absolute values?

When talking about GUI coordinates then absolute values mean 0, 0.5, 0.6345, etc.. This coordinate system was used for 4:3 screens and is out of date. Instead BI introduced safeZone coordinates. Based upon these BI develeoped a newer coordinate system called GUI_GRID. This is used in nearly all dialogs ingame because it guarentees the visibility of controls even with different settings (UI size, monitor size, screen ration, etc.). When dealing with UI elements it is always good practice to set your UI settings to the extreme options, like UI scale: Very Large. You might notice that your text won't stay where it is while the RscUnitInfo will move somwhere else on the screen.

15 hours ago, Lorenz94 said:

_ctrl ctrlSetPosition [_xP, _yP - _hP/2, _wP, 2 * _hP];

These positions are not absoulte because they use the original positions which are GUI_GRID, so simple math with a complicated background.

This is the config for the Fuelbar (a3\ui_f\config.bin: RscIngameUI >> RscUnitInfo) :

class CA_ValueFuel: RscProgress
{
	idc=113;
	texture="#(argb,8,8,3)color(1,1,1,1)";
	text="#(argb,8,8,3)color(1,1,1,1)";
	x="0 * 					(			((safezoneW / safezoneH) min 1.2) / 40) + 		(profilenamespace getvariable [""IGUI_GRID_VEHICLE_X"",		(safezoneX + 0.5 * 			(			((safezoneW / safezoneH) min 1.2) / 40))])";
	y="1 * 					(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + 		(profilenamespace getvariable [""IGUI_GRID_VEHICLE_Y"",		(safezoneY + 0.5 * 			(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25))])";
	w="10 * 					(			((safezoneW / safezoneH) min 1.2) / 40)";
	h="0.2 * 					(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25)";
};

Or translated to the GUI_GRID defines:

class CA_ValueFuel: RscProgress
{
	idc=113;
	texture="#(argb,8,8,3)color(1,1,1,1)";
	text="#(argb,8,8,3)color(1,1,1,1)";
	x="0 * GUI_GRID_W + (profilenamespace getvariable [""IGUI_GRID_VEHICLE_X"", (safezoneX + 0.5 * GUI_GRID_W)])";
	y="1 * GUI_GRID_H + (profilenamespace getvariable [""IGUI_GRID_VEHICLE_Y"", (safezoneY + 0.5 * GUI_GRID_H)])";
	w="10 * GUI_GRID_W";
	h="0.2 * GUI_GRID_H";
};

So using 5 times the control's height (ctrlPosition _ctrl select 3) is the same as using 1 * GUI_GRID_H.

 

Btw the newest gui coordinate system is the pixelGrid but this is another story.

Edited by 7erra
Goddamn emoji
  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×