How hard TabNavigation could be?
“So, 7,5 hours passed, what did you do?”
“TabNavigation”
“what? like you implemented some advanced ui navigation system?”
“TabNavigation. I implemented TabNavigation. An empty page which has tabs at the top you can switch”
“WAT?”
No, I did more, but from the time counted here, getting the built-in into Hytale TabNavigation ui component literally took 5 or 6 hours.
Why you may ask?
Well, the tabs are supposed to be set up dynamically from the code based on json, and as it turns out there is no api in Hytale to do that. Hytale is mostly an undocumented project, which means that you discover how to do things by reading existing code of the game, and trial and error. I spent hours trying out different functions and parameters just to add few tabs to the TabNavigationui component provided by the game.<br>
Nothing worked, which drained my motivation, and the real life got busy which made me take a break from the project.<br>
Fortunetely, when I came back few weeks later, I found that some folks in the HytaleModding discord figured out a workaround, which involved calling a private method via Java reflection, and manually assembling the json to be sent to the client. (For context ui is controlled server side in Hytale, and changes to it are sent to the client as a list of commands (like add, append, delete) in json).<br>
After understanding how it works, I implemented my own solution, which instead of messing with json used java reflection to register a custom data class which I namedNavigationTabrepresenting the tab in the api. That made it possible to call the standardsetmethod with aList`, which were then serialized properly by the game and sent to the client, making the tabs finally work.
Icons have issues too
After that I encountered an another problem. I was hoping to use the textures of items and the game as icons as it is commonly done in Minecraft, but it seems that Hytale is unable to use any textures placed outside of the Common/UI folder in an asset pack for UI, and the icons are located in Common/Icons :(
So I will probably have to use some custom textures, or copy them over to the Common/UI directory.
Other changes
One more thing worth noting off is that I also refactored the code to make it compile on the latest Hytale pre-releases, which removed all Vector types like Vector3d and Vector3f (classes keeping x,y,z values, used for positions and rotations of everything), and replaced them with their counterparts from JOML (Java OpenGL Math Library).
That’s it for today, bye!
Log in to leave a comment