-
Notifications
You must be signed in to change notification settings - Fork 2
Text box UI component
Displays a text box at the bottom of the screen that prints out a given string.
All of the functionality is stored in MainGameTextDisplay
, which extends UIComponent
. When create
is called, the class creates an empty table but doesn't display any images or text. display
can then be called by an event listener, for when create_textbox
is triggered, with a single String argument. It then places a background image within the table from create
, before printing the text to the screen. The positioning was handled by subdividing the screen into columns and rows, which can be seen below.
This allows for the text box's position to be dynamic in regards to the size of the screen. If the size of the screen is changed during the game, subsequent text boxes will fit to the screen.
In order to display the textbox from within another class in the game, the following code can be used:
String string = "This string will be printed by the textbox";
((MainGameScreen) ServiceLocator.getGame().getScreen()).getMainGameEntity().getEvents().trigger("create_textbox", string);
If you want to display the text box from the 'MainGameScreen' entity, you can just do the following:
String string = "This string will be printed by the textbox";
entity.getEvents().trigger("create_textbox", string);
Due to difficulties with simulating the game screen within the testing interface, the unit tests do not have complete coverage.
- MainGameTextDisplay is created properly
- Test that the display is only created once
- Test that the display() works
- Test that update() can be called multiple times without an error
- Test that dispose() removes all of the assets
Entities and Components
Interaction System
Unit Testing
Input Handling
UI
Game Screens and Areas
Map Generation
Basic Interactable Objects Design