Jump to content
HazJ

A3 Displays and SafeZone

Recommended Posts

Hi all,
I am trying to reverse a control's X axis of an A3 display, I am having trouble understanding this specific way of safeZone. I know how to move it manually but doing it this way, it isn't exactly perfect. :P

_test ctrlSetPosition [(1 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2)) / 2)), (1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2)) / 2)), (12 * (((safezoneW / safezoneH) min 1.2) / 40)), (23 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25))];

http://s26.postimg.org/dwtoug8qf/20170320220747_1.jpg

Share this post


Link to post
Share on other sites

Hi HazJ, can you be a bit more descriptive about what your trying to do?

A control cannot be reversed, it must always be TL (top left) to BR (bottom right), having a minus width will cause the control not to display.

You picture does not help explain what we are meant to be looking at.

Creating a quick RscButton using ctrlCreate with the dimensions from your post gives me something the size and position of the Ground box from the Inventory display.

Not sure if my crystal balls a little fuzzy or I have just not had enough coffee this morning :)

Share this post


Link to post
Share on other sites

Yeah, I want to create one on the other side of the screen. The same distance from the center Inventory container if possible.

Share this post


Link to post
Share on other sites

These are the values for the main player inventory background.

x="14.6 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2)";
y="2 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)";
w="24.4 * (((safezoneW / safezoneH) min 1.2) / 40)";
h="22 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)";

Ignoring the values at the begining ( 14.6, 2, 24.4 and 22 )lets break down BIs equations so we can make more sense out of them.

h = [] spawn {
	disableSerialization;
	
	_screenRatio = safeZoneW / safeZoneH;
	_screenSafeWidth = _screenRatio min 1.2;
	_screenSafeHeight = ( _screenRatio min 1.2 ) / 1.2;
	_screenWidthTotalGutter = safeZoneW - _screenSafeWidth;
	_screenHeightTotalGutter = safeZoneH - _screenSafeHeight;
	_screenSafeX_0 = safeZoneX + ( _screenWidthTotalGutter / 2 );
	_screenSafeY_0 = safeZoneY + ( _screenHeightTotalGutter / 2 );
	_screenSafeWidthGridSize = _screenSafeWidth / 40;
	_screenSafeHeightGridSize = _screenSafeHeight / 25;
	
	_ctrl = findDisplay 46 ctrlCreate [ "RscText", 20000 ];
	_ctrl ctrlSetPosition[
		_screenSafeX_0,
		_screenSafeY_0,
		_screenSafeWidth,
		_screenSafeHeight
	];
	_ctrl ctrlSetBackgroundColor [ 0, 1, 0, 0.2 ];
	_ctrl ctrlCommit 0;
	
	_ctrl = findDisplay 46 ctrlCreate [ "RscText", 20001 ];
	_ctrl ctrlSetPosition[
		0,
		0,
		_screenSafeWidthGridSize,
		_screenSafeHeightGridSize
	];
	_ctrl ctrlSetBackgroundColor [ 0, 0, 1, 1 ];
	_ctrl ctrlCommit 0;
	
	{
		_ctrl = findDisplay 46 ctrlCreate [ "RscLine", 20002 + _forEachIndex ];
		_ctrl ctrlSetPosition _x;
		_ctrl ctrlSetTextColor [ 1, 0, 0, 1 ];
		_ctrl ctrlCommit 0;
	}forEach [
		[ 0, 0, 1, 0 ],
		[ 1, 0, 0, 1 ],
		[ 0, 1, 1, 0 ],
		[ 0, 0, 0, 1 ]
	];
};

If you run this from the debug console whilst taking this picture into consideration (that shows an overview of what the safezone values mean) you will see three things..

  • The large green area is what BIs equation deams a safe screen area, being slightly bigger in the X (1.2 x) than the 4:3 UI Absolute Area.
  • The red lines represent the UI 4:3 safe area being from 0,0 to 1,1
  • The small blue area is BIs safe area broken down into a grid of ( 40 x 25 )

If you open the gui editor you will see that the red lines are an exact match for the grid displayed being the 4:3 UI Absolute Area and the blue area is nearly a match for the grid displayed in the gui editor ( blue area is actually 1.2x in the X the size of a gui editor grid space so as to break the green area down into the same number of grid spaces 40 x 25 ) . Press Ctrl+i and in the box type configfile >> "RscDisplayInventory". Notice the display starts one grid down, and if you mouse over the main background ( just below where it says Player Name ) you will see it starts 2 grids down.

Now knowing this we can take the numbers we ignored to begin with, where...

  • 14.6 is the number of grid positions across in X
  • 2 grids down in Y
  • 24.4 grids wide
  • 22 grids high

So if we compare this to the inventories Ground Container background...

Main background

x="14.6 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2)";
y="2 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)";
w="24.4 * (((safezoneW / safezoneH) min 1.2) / 40)";
h="22 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)";

Container background

x="1 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2)";
y="1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)";
w="12 * (((safezoneW / safezoneH) min 1.2) / 40)";
h="23 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)";

 

We know that the gap between the Ground container and the Main back ground is..

Main backgrounds X - ( Containers X + Containers Width )

14.6 - ( 1 + 12 ) = 1.6 grid spaces

So the starting position for the new control will be..

Main backgrounds X + Main backgrounds Width + the gap

14.6 + 24.4 + 1.6 = 40.6

and the Y and size of the control is just the same as the original Ground Containers.

 

Lets plug in the values and see if it looks right. Exit the gui editor and run this from the debug console..

player addEventHandler [ "InventoryOpened", {
	h = [] spawn {
		disableSerialization;
		waitUntil { !isNull findDisplay 602 };
		
		_invDisplay = findDisplay 602;
				
		_pos = [  
			40.6 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2), 
			1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2), 
			12 * (((safezoneW / safezoneH) min 1.2) / 40), 
			23 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)
		];
		
		_ctrl = findDisplay 46 ctrlCreate [ "RscText", 20000 ];
		_ctrl ctrlSetPosition _pos;
		_ctrl ctrlSetBackgroundColor [ 0, 0, 0, 1 ];
		_ctrl ctrlCommit 0;
		
	};
}];

Open the players inventory to show the controls position.

A lot to take in I know but thought it would be better to show where the numbers actually come from rather than just giving the solution.

  • Like 5

Share this post


Link to post
Share on other sites

That makes sense! Thank you, Larrow... You are a GOD. :grinning:

Share this post


Link to post
Share on other sites

Hi again, I added this bit of code to move everything over to the left but I would like to make it perfectly center if possible.

_inventoryDisplay = findDisplay 602;

{
	_position = ctrlPosition _x;
	_position set [0, ((ctrlPosition _x select 0) - 0.25)];
	_x ctrlSetPosition _position;
	_x ctrlCommit 0;
} forEach (allControls _inventoryDisplay);

What should 0.25 be? I know the whole width of screen so do I just / 2 or is there more to it? I guess not since it's moving from current position.

Share this post


Link to post
Share on other sites
On 22/03/2017 at 5:30 AM, HazJ said:

Hi again, I added this bit of code to move everything over to the left but I would like to make it perfectly center if possible.

Well as the original Inventory display is pretty much central to begin with, all you need to do is move every thing to the left by half the width of the elements you are adding ( gap + ground container width ).

player addEventHandler [ "InventoryOpened", {
	h = [] spawn {
		disableSerialization;
		waitUntil { !isNull findDisplay 602 };
		
		_invDisplay = findDisplay 602;
		
		ctrlPosition ( _invDisplay displayCtrl 1002 ) params[ "_mainX", "_mainY", "_mainW" ];
		ctrlPosition ( _invDisplay displayCtrl 1001 ) params[ "_contX", "_contY", "_contW", "_contH" ];
		
		_gap = _mainX - ( _contX + _contW );
		_halfWidth = ( _gap / 2 ) + ( _contW / 2 );

		_pos = [  
			_mainX + _mainW + _gap,
			_contY,
			_contW,
			_contH
		];
		
		_ctrl = _invDisplay ctrlCreate [ "RscText", 20000 ];
		_ctrl ctrlSetPosition _pos;
		_ctrl ctrlSetBackgroundColor [ 0, 0, 0, 1 ];
		_ctrl ctrlCommit 0;
		
		{
			_ctrl = _x;
			ctrlPosition _ctrl params[ "_posX", "_posY", "_width", "_height" ];
			
			_ctrl ctrlSetPosition[ _posX - _halfWidth, _posY, _width, _height ];
			_ctrl ctrlCommit 0;
		}forEach allControls _invDisplay;
		
	};
}];

 

  • Like 1

Share this post


Link to post
Share on other sites

Thank you again, Larrow! Another question... When I first open the Inventory menu, If I look closely then I notice it moves and adds the additional elements (that I made). It's not a big issue as it happens really fast but if it can be prevented then I would like to do that. When I use .hpp files I can set the default x/y/w/h values to off-screen and then set the correct ones with ctrlSetPosition which also allows me to do transitions for them but as this is all done with ctrlCreate and the .hpp is in the game files, I'm not sure how.

Share this post


Link to post
Share on other sites
On 25/03/2017 at 9:33 PM, HazJ said:

If I look closely then I notice it moves and adds the additional elements (that I made). It's not a big issue as it happens really fast but if it can be prevented then I would like to do that.

No particular way around this..

  • You could make it a mod, in doing so changing the BI inventory display to incorporate your new ctrls.
  • You could change the order of the script round to see if it will gain you any speed. Instead of creating the new ctrls and then moving everything, instead move all the existing ctrls and then create your new ones. If you still have everything inside the InventroyOpen EH it would be a good idea to move it to a function and only use the EH to just call the function.
  • Like 1

Share this post


Link to post
Share on other sites

Thanks.

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

×