Jump to content
chronicsilence

Multi-line text with DrawIcon3D

Recommended Posts

I want to have icons and text above a player's head. I can do this with the drawIcon3D script command, which will draw an icon and a line of text below it. However, I need to draw several lines of text, and it doesn't seem to be able to handle that ('\n' and '<br />' have no effect). I have tried just drawing multiple icons, each with one line and slightly below the previous one, but they often overlap with eachother and generally just look horrible.

 

Does anyone have any suggestions of a good way to draw multiple lines of text over someone's head?

Share this post


Link to post
Share on other sites

If it's not complex work, you could simply add more empty icons with a slightly lower positional offset, to gain more lines of text.

 

Messy, but depending on what your needs are, it works.

 

{

      drawIcon3D [];

      drawIcon3D [];    // 2nd line of text, empty value for icon picture

      drawIcon3D [];    // 3rd line of text, empty value for icon picture

} count array

 

 

edit: didnt read OP, seen you already tried that.

Share this post


Link to post
Share on other sites

You could try creating a display control with structured text and find the relative position on the screen with worldToScreen.

 

_ctrl = (findDisplay 46) ctrlCreate ["RscStructuredText", 9999];

worldToScreen

ctrlSetStructuredText

ctrlSetPosition

 

You'll need more code than that, but basically these are the relevant commands.

Share this post


Link to post
Share on other sites

You could try creating a display control with structured text and find the relative position on the screen with worldToScreen.

 

_ctrl = (findDisplay 46) ctrlCreate ["RscStructuredText", 9999];

worldToScreen

ctrlSetStructuredText

ctrlSetPosition

 

You'll need more code than that, but basically these are the relevant commands.

:D I just spent the last hour or so experimenting with that very thing.

h = this spawn {
	sleep 1;
	
	disableSerialization;
	_display = findDisplay 46;
	_control = _display ctrlCreate [ "RscStructuredText", 999 ];
		
	[ "text", "onEachFrame", {
		_unit = _this;
	
		
		_display = findDisplay 46;
		_control = _display displayCtrl 999;
		
		_name = ( name _unit ) splitString " ";
		
		_control ctrlSetStructuredText parseText format[ "<t align='center'>%1<br />%2</t>", _name select 0,  _name select 1 ];

		_w = ( ctrlPosition _control  ) select 2;
		_h = ( ctrlPosition _control  ) select 3;
		
		_pos2D = worldToScreen ( ( getPosVisual _unit ) vectorAdd [ 0, 0, 2 ] );
	
		if ( count _pos2D > 0 ) then {
			
			_control ctrlSetPosition [
				(_pos2D select 0) - _w/2,
				(_pos2D select 1) - _h/2,
				0.1,
				0.1
			];
	
			_control ctrlSetFade 0;
			_control ctrlCommit 0;
		}else{
			_control ctrlSetFade 1;
			_control ctrlCommit 0;
		};
	
	}, _this ] call BIS_fnc_addStackedEventHandler;

};
Sort of half borrowed from BIS_fnc_3DCredits and used the new ctrlCreate instead of the cutRsc. Just place the code in a units init for testing.
  • Like 2

Share this post


Link to post
Share on other sites

Necro, but this keeps showing up in search results so I'll link (another) solution here.

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

×