junkdog / artemis-odb

A continuation of the popular Artemis ECS framework
BSD 2-Clause "Simplified" License
769 stars 109 forks source link

[Question] User interface: artemis and scene2d #621

Closed bryanbrunt closed 3 years ago

bryanbrunt commented 3 years ago

Has anyone used Artemis and the classes in libgdx scene2d?

Imagine an interface similar to the game Civilization. There's a central map, and the map is surrounded by various UI elements. Would it be possible to have artemis control the map, and scene2d for everything else (dialogs, other screens, etc)?

I like the power of artemis, but re-implementing GUI elements inside of artemis for something as simple displaying a label control would be a major headache and loss of productivity. I certainly don't want to re-implement all of scene2ds UI controls.

Some time ago, I created a prototype Screen class that inherited from WorldScreen. This is how I believe I had it set up: WorldScreen rendered first (rendering a simple hexagonal map using an artemis map system), and then in the render method of the Screen class, there was a scene2d stage that rendered on top of the WorldScreen.

Has anyone else experimented along these lines? Or seen other other games that do?

schosin commented 3 years ago

I've used Scene2d with singletons [1]. I basically have a singleton component holding my stage and skin, which is initialized by a ui system, that also calls act and draw in its processSystem. After that I have systems for different parts of my UI such as for tooltips, ability bars or windows. They all inject the singleton and use it to get access to the stage. The advantage of managing those in artemis systems is being able to use the artemis callbacks, such as when entities are inserted/removed.

Suppose you want a window that lists all units, you just listen to those entities and update the window by adding actors in inserted and removing them in removed.

[1] https://github.com/DaanVanYperen/artemis-odb-contrib/wiki/Singleton-Plugin

bryanbrunt commented 3 years ago

Nice! At least with a complex UI, this seems a preferable UI system to the Daan's methodology of re-creating scene2d objects.

Realistically, my UI skills are limited. I don't have the time or patience to re-implement a list view or tab control.

Could you share some of your code?

It might be nice to have an alternate artemis-odb-scene2d-quickstart that uses scene2d with your techniques. If you shared your code, I could probably easily publish that to github.

I wrote a relatively complex strategy game in libgdx, and I relied heavily on Skin Composer and Scene2d. This is a game that I literally couldn't have written without scene2d.

It seems like if we had an artemis-odb-scene2d-quickstart, it would open up the artemis-odb framework to wider use.

schosin commented 3 years ago

I don't have a proper project I can share, but I created this gist with two examples:

Greetings, Ken

bryanbrunt commented 3 years ago

Thank you for those examples.

I've actually found that while at first intimidating, designing the user interface with the artemis RenderBatchingSystem is leaps and bounds easier than all the work I have done with scene2d.

Yes, you have to handle marshaling all of the primitive graphical elements yourself. But once you have conquered that hill, the flexibility of the graphical capabilities in artemis-odb-contrib makes life so easy.

Designing my own tooltip was essentially a breeze.

Create ToolTipSystem. Check the HoverState of the components. Modify the contents of the tooltip text. Update the tooltip component Pos to match the mouse Pos. With some logic for screen edge detection. Make the tooltip visible.

This would have been a nightmare with the scene2d logic, and I have definitely have nightmares from having had to modify skin json files.