MODULE: UI Scale v0.4

Started by Snarky, Mon 17/06/2024 18:44:54

Previous topic - Next topic

Snarky

Have you ever started a project from a template, changed the resolution, and discovered that even though you said yes to "Would you like AGS to automatically resize all your GUIs to the new resolution?" the UI looks completely broken? That's because while AGS resizes the dimensions of the GUIs and GUI elements, it doesn't scale the sprite graphics accordingly, so after the resize they no longer fit.

This module deals with that problem. By adding a single line to game_start() all the UI graphics are rescaled to the specified dimensions:

Code: ags
// In GlobalScript.asc
function game_start()
{
  UiScale.Rescale(2.0); // Scale the UI graphics to double the resolution
}

You can also have different horizontal and vertical scaling factors, and configure it to include or exclude GUIs and GUI Controls, Inventory Items, and Mouse Cursor Modes – in general or on an individual basis (for example if you change the graphics for part of the UI and don't want to scale those any longer):

Code: ags
function game_start()
{
  // Inventory items will not be scaled, except for iKey
  UiScale.IncludeInventoryItems = false;
  iKey.SetIncludedInScaling(true);

  // gMyNewGui (and all its controls) will be excluded from scaling
  gMyNewGui.SetIncludedInScaling(false);

  // This button will be excluded from scaling (even if the rest of its owning GUI is scaled)
  btnAlreadyEdited.SetIncludedInScaling(false);

  // Mouse Cursors are not scaled by default, but we set eModeLookat to be scaled 
  SetCursorModeIncludedInScaling(eModeLookat, true);

  // Scale by 3 horizontally and 2 vertically
  UiScale.Rescale(3.0, 2.0); 
  // If math is not your thing, you could also just put new_resolution/old_resolution, e.g.:
  // UiScale(1024.0/320.0, 600.0/200.0);  // Upscaled from 320x200 to 1024x600; works out to (3.2, 3.0)
}

Finally, you can get a report on how many scaled sprites the module creates, and a list of the sprites that have been scaled (useful to see which sprites you still need to replace):

Code: ags
function game_start()
{
  UiScale.Rescale(2.5); // You don't need to scale by whole numbers
  System.Log(eLogDebug, "UI Scale resized %d sprites:", UiScale.Count);
  String spriteList[] = UiScale.ListScaledSprites();
  for(int i=0; i<UiScale.Count; i++)
    System.Log(eLogDebug, spriteList[i]);
}

Note that this module creates scaled copies of all the UI sprites and stores them in memory (as DynamicSprites), so it will increase the memory requirements of your game—potentially by a lot (especially with high game resolutions). It should only be used as a temporary solution until you can replace the sprites, or for small/test projects.

Bugs and limitations:
-No known bugs (please report any you find)
-The module does not scale fonts, so text formatting may look strange after scaling
-There is no way in AGS to retrieve mouse cursor hotspot coordinates, so if the hotspot is not at (0,0), scaling cursors will not appropriately adjust the hotspot position; this must then be done manually using Mouse.ChangeModeHotspot(). For this reason, mouse cursor scaling is off by default
-Animated mouse cursors are not scaled. (But this could be added in future)
-The verb coin template assumes a circular verb coin, so scaling by different horizontal and vertical factors may have non-optimal results; also note that to work with the Verb Coin template, UiScale should be placed below the VerbCoin module in the script list
-The module only applies scaling to sprites that are set as UI graphics when it is called (normally on startup); if set to some other sprite later on (as another module might potentially do), that sprite will not be scaled

Version history:
-v0.4: Initial release

Download:
UiScale v0.4

ArachnidTea

:> thank you snarky! I shall include you in my game credit kkkkk  :-D

The basic UiScale.Rescale works wonderfully but including all the other part results in compilation errors:
GlobalScript.asc(92): Error (line 92): Type mismatch: cannot convert 'String[]' to 'String'

which is line 5 of your 3rd code

But for now I am happy with the result and would just use the basic scaling function until i replaced all the GUIs with something prettier :>>

Crimson Wizard

Quote from: ArachnidTea on Sun 30/06/2024 10:27:47including all the other part results in compilation errors:
GlobalScript.asc(92): Error (line 92): Type mismatch: cannot convert 'String[]' to 'String'

which is line 5 of your 3rd code

"String[] spriteList" is a C# syntax.
In AGS it has to be "String spriteList[]".

DiegoHolt

Hi, Snarky!

I think this is what I was looking for, but I can't make it work. Just copied the module in the AGS folder but it isn't showing in my plugins' section. I have restarted AGS but still nothing.

What am I missing here?

eri0o

@DiegoHolt this is not a plugin, it is an exported Script Module. A Script Module is a pair of Header and Script files that can be imported in your AGS game project through AGS Editor.

In your project explorer, you click in the Script entry there that should contain all your script modules, including the GlobalScript and right-click it and select import module, then click on the SCM file from here whenever you downloaded it.

There's an entry on this in the manual here but it's very minimal, feel free to suggest improvements

https://adventuregamestudio.github.io/ags-manual/ScriptModules.html#managing-modules

DiegoHolt

Thanks, man! You're the best!

Anyway, now that I've tried it I've realized it's not what I needed. This upscales the graphics but not the dialog text in the box. I guess I'll have to keep searching here and there.

Either way, thank you for always being there to help!  :-D

eri0o

@DiegoHolt in ags4 you can just set the GUI to the scale you want - but we haven't yet made a manual for it... Ags4 is still in development though and it will have breaking changes between versions.

I think in ags3 the easiest approach is to just make your GUIs at the proper size.

About text you can create a new font and make it a different scale - I don't remember the details of the font panel because I don't use very much. I think it's Size Multiplier: https://adventuregamestudio.github.io/ags-manual/EditorFont.html

Anyway, then you go to your GUI and set the labels and buttons to use this new font you created there.

DiegoHolt

@eri0o I hope that's how you tag someone hehe

My problem is not the font size, but the place the text occupies in the dialog box. It's hard for me to explain since English is not my native language.

Here, this should explain the issue:



I'm sure that I'm doing something wrong, since I'm fairly new to AGS and scripting in general.

SMF spam blocked by CleanTalk