How to add UI elements like comboboxes, lists, and buttons to Beyond All Reason widgets without rebuilding the rendering layer.
Tags: beyond all reason, modding, lua, widgets, graphical components
If you want comboboxes, buttons, or list elements in a BAR widget, you can use the existing order menu system. Comboboxes in the order menu get created dynamically when a new order is added. You do not need to manually render them through OpenGL.
The Spring engine provides a Lua UI layer that handles common interface elements. BAR widgets sit on top of that layer and can access the same building blocks.
A BAR widget is a Lua script placed in the luaui/widgets/ directory. Each widget registers callbacks the engine calls at specific times, like widget:Initialize(), widget:Update(), or widget:CommandNotify().
To add a graphical component, call the widget's Spring API functions. The Spring.GetWidgetConfig() and Spring.SetWidgetConfig() functions handle storing your UI state between sessions. For interactive elements, Spring.SendCommands() fires engine commands based on user input.
Define options in your widget configuration table. The engine renders them as a dropdown when the widget is active. Each selection maps back to a value your widget logic reads during its update cycle.
widget:GetConfig('myOption', 'default')
The order display system handles the visual rendering. Your code only needs to define what the options mean to the widget.
The best way to start is to open existing BAR widgets and see how they work. The game ships with dozens of functional widget scripts. Read the ones that have UI elements: the attack command widget, the build menu, and the economy display all include interactive components.
The BAR microblog also publishes dev notes with example snippets that are worth reviewing. If you hit a wall, post in the modding channels. Modders here are used to helping people past the first few frustrating hours of widget development.
Fair warning, most experienced modders will not write an entire widget for a small amount. If you need custom code, be prepared to learn the Lua yourself or budget appropriately for the work involved.
Drop the widget file into luaui/widgets/, launch a skirmish, and open the widget list with F11. Enable your widget and check for errors in infolog.txt. Lua errors in widgets surface quickly when the game loads the UI layer.
Test in a simple skirmish match first. Multiplayer adds variable latency and host state issues that cloud debugging. Once the widget behaves correctly in single-player, test it with other players to make sure it syncs properly.
Modding BAR takes patience. You will break things, read error logs, and restart frequently. Having a community where people share code examples and answer questions without judgment makes the learning curve manageable.
That same patience and respect for the learning process is what separates groups like Creed of Champions from typical gaming communities. When teammates treat mistakes as normal steps toward improvement, everyone gets better, faster.
[Crd] One of the few places where you can for sure coordinate with people in matches with a good supportive attitude. Everybody tends to be understanding and constructive.