Game Development Community

BUG in the Gui Editor(Switch of resolution error) + FIX proposition

by Jean-louis Amadi · in Torque 3D Professional · 04/11/2012 (8:07 am) · 4 replies

In the file "game/tools/guiEditor/scripts/guiEditor.ed.cs"
The resolutions "1440 900" and "1600 900" are mutually excluded due to the use of the same index "900" in the popup list of resolution. If you work in "1440 900" and typing "F10" for enter in the Gui Editor, the resolution of the view will pass automatically in "1600 900". You risk to position your gui with a "1440 900" in mind but it will not be correct.
For FIX, I propose to just use another index for "1600 900" as 16900 instead of 900.


//=============================================================================================
//    Resolution List.
//=============================================================================================

//---------------------------------------------------------------------------------------------

function GuiEditorResList::init( %this )
{
   %this.clear();
   
   // Non-widescreen formats.
   
   %this.add( "640x480 (VGA, 4:3)", 640 );
   %this.add( "800x600 (SVGA, 4:3)", 800 );
   %this.add( "1024x768 (XGA, 4:3)", 1024 );
   %this.add( "1280x1024 (SXGA, 4:3)", 1280 );
   %this.add( "1600x1200 (UXGA, 4:3)", 1600 );
   
   // Widescreen formats.
   
   %this.add( "1280x720 (WXGA, 16:9)", 720 );
   ////[GameAlchemyPack--Begin]
   //Fix use another index
   //%this.add( "1600x900 (16:9)", 900 );
   %this.add( "1600x900 (16:9)", 16900 );
   //[GameAlchemyPack--End]
   %this.add( "1920x1080 (16:9)", 1080 );
   %this.add( "1440x900 (WXGA+, 16:10)", 900 );
   %this.add( "1680x1050 (WSXGA+, 16:10)", 1050 );
   %this.add( "1920x1200 (WUXGA, 16:10)", 1200 );   
}

//---------------------------------------------------------------------------------------------

function GuiEditorResList::selectFormat( %this, %format )
{
   %width = getWord( %format, 0 );
   %height = getWord( %format, 1 );
   
   switch( %height )
   {
      case 720:
         %this.setSelected( 720 );
         
      case 900:
      //[GameAlchemyPack--Begin]
      //Fix Take account "1440 X 900" OR "1600 X 900"
      if(%width == 1440)
         %this.setSelected( 900 );
      if(%width == 1600)
         %this.setSelected( 16900 );
      //[GameAlchemyPack--End]
         
      case 1050:
         %this.setSelected( 1050 );
         
      case 1080:
         %this.setSelected( 1080 );
         
      default:
      
         switch( %width )
         {
            case 640:
               %this.setSelected( 640 );
               
            case 800:
               %this.setSelected( 800 );
               
            case 1024:
               %this.setSelected( 1024 );
               
            case 1280:
               %this.setSelected( 1280 );
               
            case 1600:
            //[GameAlchemyPack--Begin]
            //Fix Take account "1600 X 900" OR "1600 X 1200"
               //%this.setSelected( 1600 );
               if(%height == 900)
                %this.setSelected( 16900 );//1600 X 900
                
               if(%height == 1200)
                %this.setSelected( 1600 );//1600 X 1200
            //[GameAlchemyPack--End]
               
            default:
               %this.setSelected( 1200 );
         }
   }
}

//---------------------------------------------------------------------------------------------

function GuiEditorResList::onSelect( %this, %id )
{
   switch( %id )
   {
      case 640:
         GuiEditor.setPreviewResolution( 640, 480 );
         
      case 800:
         GuiEditor.setPreviewResolution( 800, 600 );
         
      case 1024:
         GuiEditor.setPreviewResolution( 1024, 768 );
         
      case 1280:
         GuiEditor.setPreviewResolution( 1280, 1024 );
         
      case 1600:
         GuiEditor.setPreviewResolution( 1600, 1200 );
         
      //[GameAlchemyPack--Begin]
      //Fix
      case 16900:
         GuiEditor.setPreviewResolution( 1600, 900 );
      //[GameAlchemyPack--End]
         
      case 720:
         GuiEditor.setPreviewResolution( 1280, 720 );
         
      case 900:
         GuiEditor.setPreviewResolution( 1440, 900 );
         
      case 1050:
         GuiEditor.setPreviewResolution( 1680, 1050 );
         
      case 1080:
         GuiEditor.setPreviewResolution( 1920, 1080 );
         
      case 1200:
         GuiEditor.setPreviewResolution( 1920, 1200 );
   }
}

#1
04/11/2012 (11:28 am)
I was so disgusted with the way that the resolutions are managed in that script I rewrote that entire section just now and here it is. Enjoy!

//=============================================================================================
//    Resolution List.
//=============================================================================================

//---------------------------------------------------------------------------------------------

function GuiEditorResList::init( %this )
{
   %this.clear();
   
   // Note: Text values must stay in the "<dispX>x<DispY> (<name>, <ratio>)" format!
   
   // Non-widescreen formats.
   %this.add( "640x480 (VGA, 4:3)" );
   %this.add( "800x600 (SVGA, 4:3)" );
   %this.add( "1024x768 (XGA, 4:3)" );
   %this.add( "1280x768 (WXGA, 5:3)" );
   %this.add( "1280x960 (UVGA, 4:3)" );
   %this.add( "1280x1024 (SXGA, 5:4)" );
   %this.add( "1600x1200 (UXGA, 4:3)" );
   
   // Widescreen formats.
   %this.add( "1280x720 (WXGA, 16:9)" );
   %this.add( "1280x800 (WXGA, 16:10" );
   %this.add( "1440x900 (WXGA+, 16:10)" );
   %this.add( "1600x900 (HD+, 16:9)" );
   %this.add( "1680x1050 (WSXGA+, 16:10)" );
   %this.add( "1920x1080 (HD 1080, 16:9)" );
   %this.add( "1920x1200 (WUXGA, 16:10)" );
   %this.add( "2560x1440 (WQHD, 16:9)" );
   
}

//---------------------------------------------------------------------------------------------

function GuiEditorResList::GetItemResolution(%this, %id)
{	
	// get requested item's text
	%text = %this.getTextById(%id);
	
	// find the x in <dispX>x<DispY> (<name>, <ratio>)
	%x = strpos(%text, "x");
	
	// and replace the x with a space
	%text = getSubStr(%text, 0, %x) SPC getSubStr(%text, %x +1);

	// remove the unnecessary chars around resolution name and ratio
	%text = stripChars(%text, "(),");
	
	// the returned format is "<dispX> <dispY> <name> <ratio>"
	return %text;
}

function GuiEditorResList::selectFormat( %this, %format )
{
	// get requested resolution
	%width = getWord(%format, 0);
	%height = getWord(%format, 1);

	// set default to invalid and get number of items available	
	%pick  = -1;
	%alt   = 0;
	%count = %this.size();
	
	// find the best possible match if not exact
	for(%i=0; %i<%count; %i++)
	{
		// get resultion details
		%res = %this.GetItemResolution(%i);
		%w   = getWord(%res, 0);
		%h   = getWord(%res, 1);
		
		// test for exact match
		if(%w == %width && %h == %height)
		{
			// success, exact match found
			%pick = %i;
			break;
		}
		
		// test for possible alternative
		if(	(%w <= %width) &&	// width is exact or less than requested
			(%h <= %height))	// height is exact or less than requested
		{
			// remember this alternative
			%alt = %i;
		}
	}
	
	// determine if an exact match was found
	if(%pick != -1)
	{
		// an exact match was found, use it
		%this.setSelected(%pick);
	} else
	{
		// use the alternative
		%this.setSelected(%alt);
	}

}

//---------------------------------------------------------------------------------------------

function GuiEditorResList::onSelect( %this, %id )
{
	// get item resolution
	%res = %this.GetItemResolution(%id);
	
	// set the requested resolution
	GuiEditor.setPreviewResolution(getWord(%res, 0), getWord(%res, 1));
	
}

#2
05/08/2012 (8:32 am)

ERRATUM : TAKE NOT ACCOUNT THE "RESOLUTION ROTATED"

In the method : GetItemResolution

line 44-45
i had to change
%text = getSubStr(%text, 0, %x) SPC getSubStr(%text, %x +1);
with
%text = getSubStr(%text, 0, %x) SPC getSubStr(%text, %x+1,%x);

work fine after ;)

#3
05/08/2012 (9:36 am)
I don't understand why you had to change that line since it is working as intended for me as tested on Torque 3D 1.1 final and 1.2. Your change truncates the text after the found 'x' position at the length of which the 'x' character was found.

With your change this is the logical results:
%text = "1024x768 (XGA, 4:3)";

// find the x in <dispX>x<DispY> (<name>, <ratio>)  
%x = strpos(%text, "x");  
      
// and replace the x with a space  
%text = %text = getSubStr(%text, 0, %x) SPC getSubStr(%text, %x+1,%x);

//----

// the result will be
%text = "1024 768 ";

// instead of this expected result
%text = "1024 768 (XGA, 4:3)";

With that in mind your change also breaks if there is an odd resolution such as "900x1600 (Rotated, 9:16)" entered into the list for a monitor rotated 90 degrees (rare, but it can happen) when somebody wants to support it. In that case the result of your change will be "900 160".

So, I cannot figure out why you had to make that change at all.
#4
05/08/2012 (1:37 pm)
This was because "getSubStr" don't accept 2 parameters for me but 3 mandatory...

Also i had not think about the rotation of resolution even rare.

In C++ "getSubStr" seems accept 2 parameters and fills the last with -1(if not given) for go to the end of the string but for an unknown reason, the script for me, don't carry out this task.

In conclusion, your original solution still the better, i will investigate my script, and my c++ for the problem with "getSubStr" ;)