besteon / Ironmon-Tracker

A Lua script for the Bizhawk/mGBA emulator compatible with Pokemon Fire Red, Leaf Green, Ruby, Sapphire, and Emerald that tracks relevant data for the IronMon challenge.
MIT License
122 stars 44 forks source link

Better External UI framework #462

Closed UTDZac closed 2 months ago

UTDZac commented 2 months ago

This PR adds a long overdue wrapper for many of the native Bizhawk Lua functions for dealing with forms. Functionally speaking, nothing should change for the user outside of some form texts now actually being visible for non-English languages.

The main purpose behind this was to make it easier to create and manage form popup windows, including the individual Control elements associated with that form. The most notably change here is being able to easily apply a universal change to the creation of a given form Control, such as adding the property "AutoSize"=true on every Label used in all forms everywhere; great for translated text.

I did my best to document this new enhancement, update any old deprecated functions to use the new stuff, and test as many form popups as I could find on Bizhawk 2.8 and Bizhawk 2.9. Feel free to double-check me on any of these.

I'm also open to renaming the new ExternalUI.lua class to something shorter, if possible, since usage tends to get lengthy in some places. Note: This class has potential to be used for non-Bizhawk form things as well, as soon as we have a need for it.

UTDZac commented 2 months ago

Oh, the other reason I have been wanting to make this wrapper was because of the stupid inconsistency when using Bizhawk's Lua form function for creating a textbox. It is the only function that puts the width & height params before the x & y params. 😠

Fellshadow commented 2 months ago

Taking a look but want to comment on this part first:

I'm also open to renaming the new ExternalUI.lua class to something shorter, if possible, since usage tends to get lengthy in some places.

I think ExternalUI is a fine name as it's clear what it is, however instead of seeking a shorter name why not introduce a variable within the file to refer to ExternalUI.BizForms or whatever is being used in that file and use that instead to shorten the lengthy parts?

e.g. something like

local UI = ExternalUI.BizForms

and then anywhere you want to use ExternalUI.BizForms you do something like:

local form = UI.createForm(title, self.width, self.height, self.xPos, self.yPos, tryClose)

(obviously what variable names you use are up to you, and whether the UI variable should be local or not depends, but this is the way i'd try shortening things)