DisplayAsGUI Module

Started by Gal Shemesh, Wed 03/09/2025 22:43:47

Previous topic - Next topic

Gal Shemesh

About:
Made in AGS Editor .NET 32-bit (Build 3.6.2.12)

This module is used for displaying text to the screen, the same way the built-in Display() function does, with the exception that this one is using a GUI label to displaying the text, which can be manipulated after being drawn to the screen, such as adding a 'text typing effect' and adjusting the entire text box yBase position. This is very handy if you wish to have the text box bottom edge at a specific Y coordinate and to have it extend upwards when it contains more lines.

*** Make sure to read the limitations section at the end of this file. ***




Installation:
1. Import the DisplayAsGUI.scm script to your AGS scripts section.
2. Import the gDisplayAsGUI.guf GUI to your AGS GUI section (import this FIRST if you don't have any GUI in your game yet).
3. If you already have a custom text window GUI in your game (which is used for the text window borders and fill), skip this step. Otherwise, import the gTextWindow.guf GUI to your AGS GUI section.

Setup:
1. Under 'Text output' in the 'General Settings', set 'Custom text-window GUI' to your text window GUI (this GUI MUST have a higher ID number than 0, or else it won't show up in the list!)
2. Open the DisplayAsGUI.scm script and adjust the variables under '// initial variables that are allowed to be changed' section at the top of the script to your settings:

- int CustomTextWindowGUI = ID; // point to the text window GUI ID
- int CustomDisplayAsGUI = ID; // point to the gDisplayAsGUI ID
- int font = ID; // point to font ID of your choice
- int delay = int; // set the amount of game loops to wait when appending each char (for the letter-by-letter typing effect)
- int ZOrderBordersAndFill = 1; // if all of your other GUIs are set to ZOrder 0, keep this as 1. Otherwise, make it 1 number higher (this will make sure that the text box will be drawn above any other GUI)

How to use:
Call the DisplayAsGUI(String text, bool typeEffect, int yBase) function. In it, provide a string that you wish to show to the screen, an optional typeEffect bool (true for ON or false for OFF), and an optional yBase coordinate for sticking the text box bottom edge to; if you wish to use the optional yBase parameter but don't want a typeEffect, you must pass 'false' in its place.

The DisplayAsGUI() function relays on the custom text window GUI settings; any change you make to your text window GUI appearance, such as modifying the border sprites, padding or changing background fill and text colors will affect it. It was built that way so you won't need to adjust anything in the module code apart from the initial parameters mentioned above.


Example 1:
Code: ags
DisplayAsGUI("The quick brown fox jumps over the lazy dog.");
The above will display the message at the middle of the screen, the same as it will look like if you used the built-in Display() function.

Example 2:
Code: ags
DisplayAsGUI("The quick brown fox jumps over the lazy dog.", true);

Same as example 1, but the text will be drawn from start to finish in a char-by-char manner (typing effect), within a pre-defined text box size.

Example 3:
Code: ags
DisplayAsGUI("The quick brown fox jumps over the lazy dog.", false, Screen.Height);

Same as example 1 (no typing effect), but the text box will be drawn at the very bottom of the screen. In case of a higher or lower yBase value than the screen height, the text box will be nudged towards the center of the screen until that the text window borders are fully visible.

*You may skip the typing effect by interrupting with either Escape, Enter, Space or Left/Right mouse button.


Limitations:
1. When the text window border sprites are being drawn in this custom function, the Top, Bottom, Left and Right border sprites get stretched (not tiled) from one corner sprite to the parallel one. Hence, the Top and Bottom sprites must have a width of 1px and the Left and Right sprites must have a height of 1px. Anything bigger than that and the their sprites would look wrong.

2. The inner fill cannot be an image but a single color number, set in the BackgroundColourNumber property of the Text Window GUI. After that the border sprites are drawn, an empty dynamic sprite gets drawn over with a rectangle in that color, which fills the area between all of the corner sprites, including the extra padding that you may set in the Text Window GUI properties.


You may download the module from my personal Dropbox.


Changelog
=========
Version 1.0.1
Released: 4th September 2025
- Module name changed from DisplayNew() to DisplayAsGUI().
- README file updated.

Version 1.0.0
Released: 4th September 2025
Notes: Initial release

SMF spam blocked by CleanTalk