Help Request: Automatic Train Painter Custom UI

Place to get help with not working mods / modding interface.
Post Reply
yeahtoast
Inserter
Inserter
Posts: 21
Joined: Wed Feb 27, 2019 6:17 pm
Contact:

Help Request: Automatic Train Painter Custom UI

Post by yeahtoast »

Hello all, I am the developer of the Automatic Train Painter mod, and I’m coming to you for some much-needed help.

(Apologies if this is the wrong forum, it looked to be the most appropriate to me. If not, please point me in the right direction!)

It’s often been requested to implement a way to add custom colors into the mod. Its database contains over 8000 items and fluids, each with their own hardcoded colors. Some may disagree with colors I've chosen, while modded items not included in the database are simply left unsupported entirely. To remedy this, I’d been brainstorming a way to allow users to select their own colors for items as they wish.

Back in version 0.16, there was a mod called Railway Painter which basically did this. You would enter an item name, pick its color, and magically every train with that item would be painted accordingly (I don't remember exactly how or when this painting would occur since the mod hasn't been usable in years, but that's not super critical at this point). It allowed for multiple configuration profiles, and included both a color picker and a train preview window. So, the proof of concept is there, the issue is: I’m not much of a programmer, honestly. Any veteran modder who’s looked at the source code for Automatic Train Painter can tell. Looping through tables, navigating if statements, and doing math functions are easy. UIs are... something else. :oops:

Having been mentally stuck on this project for well over a year, I instead decided to create mockups in Photoshop, based on the UI from Chuomiko’s terrific Module Inserter mod, to convey my ideas for those who can help. That mod’s UI framework includes just about everything I want to accomplish with my own.

Here’s how I envision it working:

Open the main menu by clicking the button in the upper-left of the screen. On the left half of the main menu, you’d start with an item selection button. Clicking that opens up an object selection menu, which should include all placeable entities, items, and fluids. Basically, everything you can pick from a constant combinator except for virtual signals:
filters.png
filters.png (352.18 KiB) Viewed 718 times
Item selection window, with examples for completed Advanced Circuit and Processing Unit colors

Once an item is selected, a dropper appears alongside a colored box. Clicking the dropper opens up a window akin to the vanilla train UI. Selecting the RGB values for the train would update the appearance of the train and the colored box in real-time, exactly as it would in the vanilla train UI:
preview1.png
preview1.png (277.57 KiB) Viewed 718 times
Color selection window with train preview

If the selected item is a fluid prototype, the preview window would instead show a fluid wagon:
preview2.png
preview2.png (289.97 KiB) Viewed 718 times
Color selection window with train preview (fluid wagon version)

(Based on my limited understanding of how Railway Painter pulled off this visual train preview, I’m assuming this would require one or two additional surfaces to store the actual trains themselves.)

Last mockup is more of a nice-to-have than a necessity:
duplicate.png
duplicate.png (162.61 KiB) Viewed 718 times
Duplicate existing color to new row

Each row could also have a duplicate function, which simply copies its information to a new line. This could make it easier to copy colors for use with different items. Replacing the selected item should maintain the existing color selection. Each row can also be individually deleted -- unlike duplicate, that function is absolutely necessary.

Once the item colors are selected on the left window, pressing the green check box above will apply them. What I’m imagining is this will then tabulate each row of the custom palette into a local table* of values, in the same format as those hardcoded into the mod, ie:

Code: Select all

Active_color_palette={ 
['item-name1']={r=000, g=000, b=000, a=127}, 
['item-name2']={r=255, g=255, b=255, a=127}, 
} 
Automatic Train Painter would then prioritize this table when looking through for an item’s color and paint accordingly per the mod’s existing framework, bypassing the filters, exceptions, and hardcoded item database entirely -- none of those are necessary in this application.

*I am concerned that storing this table locally may cause issues when used in multiplayer sessions. If that is valid, please let me know if there are solutions, or if this functionality must simply be disabled for multiplayer.

Visual description of UI functions
descriptions.png
descriptions.png (217.29 KiB) Viewed 718 times
The additional functions on the right of the menu are also taken from Module Inserter. Each palette can be saved as a preset and/or switched for another. They can also be exported to blueprint for easy import into other games. This isn’t exactly a 1-for-1 with Module Inserter though, as that mod actually uses the blueprint as an Upgrade Planner for inserting modules -- its core functionality.

---

In a nutshell, manually pick a color from the menu -> the mod paints the train like it already does. Seems easy enough, right? I have no doubt this is all possible, maybe even trivial, but I have just had extremely little success implementing even the most basic UI, to say nothing of actually getting it to function as desired. If anyone has thoughts on the best approach here, I'd appreciate the feedback. If there are tutorials on Factorio UI modding , or even some basic UI-containing mods that I can use as a starting point for understanding them, that would also be helpful. (EDIT: just saw this on the Discord; I'll start there)

In the rare case someone fluent in Factorio UI and can quickly develop this themselves, I’d be forever grateful.

Thanks for reading, and I eagerly await your feedback!

Xorimuth
Filter Inserter
Filter Inserter
Posts: 623
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: Help Request: Automatic Train Painter Custom UI

Post by Xorimuth »

Personally I don't think this feature is worth the effort to implement. For me the whole point of your (excellent!) mod is that I don't have to think about the colours! I think that the amount of use this GUI will get would be very low.
Some may disagree with colors I've chosen
You're the mod author, you're in charge :P
modded items not included in the database are simply left unsupported entirely
Surely barely anyone's going to go through every resource in a new overhaul and add them all manually?

Seems like you could satisfy most of the 'need' by adding a string-setting in mod settings, that allows the user to define their own JSON override e.g. {"iron-ore": {0.5, 0.1, 0.1}, "copper-ore": {0.9, 0, 0}}. This would be so much easier to implement and still allow the user to have the same power to override your mod defaults.
My mods
Content: Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Remote Configuration | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Help Request: Automatic Train Painter Custom UI

Post by PFQNiet »

You could even add a remote interface for other modders to provide colours for their custom items! Not only would this allow players to make their own modded colours for vanilla if they really want to, but it would allow other mod authors such as myself to specify how to colour things without needing to rely on a submission process :)

Post Reply

Return to “Modding help”