Making custom cargo car and locomotive profile icons

Creating and Editing Rollingstock
User avatar
Gumboots
CEO
Posts: 1203
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

Making custom cargo car and locomotive profile icons Unread post

I've figured out a couple of things about profile icons (ie: locomotive and car side views for the train list). I have always hated doing these, because it was difficult to get them done well. I've finally figured out how to get them done to a high standard, quickly and easily.

The tricky part is the alpha channel for them. Unlike skins for cars, which have to have binary alpha almost everywhere, the profile icons have to be done with the full range of partial transparency to make them look good. Since the icons are made from scaled-down profile shots of cars, that are rendered out of their background before scaling, they naturally scale down to have partial transparency around the edges anyway. That bit is fine. The tricky bit was getting this onto the alpha channel so it looked smooth when saved as a DDS.

Turns out that the easy way is to do it goes like this:

1/ Have a normal white background layer as the basis of the image.

2/ Have the scaled-down, rendered, profile shot as the second layer.

3/ Put a black color overlay style, set to 100% opacity on normal blending mode, on the background layer. This is only used for getting the alpha channel, not for saving as DDS. It can be toggled on and off easily.

4/ Put a white color overlay style, set to 100% opacity on normal blending mode, on the icon layer. This can also be toggled on and off easily. In combination with the black overlay on the background layer, this automatically gives pure white (ie: full opacity on the alpha channel) for the solid parts of the icon and the correct shades of grey (ie: partial transparency on the alpha channel) around the edges.

5/ With the two color overlays toggled on, select the whole image and then "Copy Merged" to pick the lot up as one greyscale layer.

6/ Switch to the alpha channel and Ctrl+V onto it, and the merged copy will be transferred to the alpha channel. This will give the desired result without any hassle. !*th_up*!

7/ Now just switch back to the RBG channel, toggle off the black and white overlays, then flatten the image and save as DDS. Sorted. (0!!0)

----------------------------------------------------------
So this is all good. The only other tricky bit is the length of the icons. This is another RT3 thing. :roll:

If the icons are so long that the full consist would run off the screen, RT3 scales the whole thing for overall length. The catch (there has to be a catch) is that it won't scale the areas assigned to each car when you hover the cursor over the train list. If the icons are too long, when you are hovering your cursor over the fourth car the pop-up text will be telling you what cargo is in the second car. The cargo in the last car? Good luck finding that. It'll be off the right side of your train list. :-P

Obviously this is a PITA for usability, so there has to be a practical length limit set on cargo car icons. Turns out, from trial and error, that this length seems to be about 100 pixels. All cargo car profile icons have to be restricted to a maximum of 100 pixels, regardless of how long the car is.
Gumbootz Lokomotivfabrik und Bierkeller

LMR Samson 0-4-0 - Pennsy H3 Consolidation - Custom double tank cars set
User avatar
Gumboots
CEO
Posts: 1203
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

Re: Making custom cargo car and locomotive profile icons Unread post

Update: I've been doing some more testing of profile icon size, and it turns out the limits are tighter than 100px. The problem is that custom profile icons, that are not part of the default CarSideView_* images, do not scale properly for window width.

All the default cars and locos, which are on the CarSideView_* images, will always scale correctly for any window size. This includes the areas assigned to each car for displaying cargo type when the cursor is over the car's icon. No matter how long each car or locomotive icon is, the game will always shrink the train and the areas assigned to each car in such a way that the hover function works perfectly for every car.

With cars that use custom icons the situation is different. The car icons will scale to fit the whole train in the available space, but the hover area assigned to each car remains at a larger size. I haven't double checked, but I assume this would be the size in pixels, as defined in the profile .imb file. This is what screws up the hover functionality, and it screws it up pretty badly. If you had a consist of 8 boxcars it would be very difficult to tell what was in each one.

I tested with the game in windowed mode, which with the settings I'm running is 1600x1024, and I tested with the longest locomotive icon, which is the Big Boy. With that combination it looks like the car icons cannot be longer than about 85px, so I think that's the limit I'll have to use for any future work.

The other possibility would be to hijack parts of the CarSideView_*.dds for some custom cars. If that was done it would be possible to use larger icons without running into scaling problems. Since the existing custom cars do not reference the default images there are some slots available for use, so I'll probably look into that option too. Apart from anything else it should be marginally more efficient use of resources, since it would eliminate the need for some custom car icons.
Gumbootz Lokomotivfabrik und Bierkeller

LMR Samson 0-4-0 - Pennsy H3 Consolidation - Custom double tank cars set
User avatar
Gumboots
CEO
Posts: 1203
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

Re: Making custom cargo car and locomotive profile icons Unread post

I just went through all the CarSideView*.imb files and tallied up the empty slots.

CarSideView1.imb has 52 dummy slots which are not being used, as well as 10 placeholder slots (they reference an actual visible part of the image, but are not used during play) and another 4 slots that hold icons for empty A, B C & D era flat cars (not used during play either). That's a total of 66 unused slots in that file.

CarSideView2.imb has 36 dummy slots which are not being used, and CarSideView3.imb has 33 dummy slots which are not being used (these two files do not have any placeholders or empty flats). That means these two files add another 69 unused slots.

So, if I can figure out how to get the empty slots working, and calling chunks of image that I want to call, then potentially there is scope to add another 135 custom cargo cars and still have all their icons called from images that will scale properly in the gameplay interface. This would solve all the problems nicely, since I don't need nearly that many custom cargo cars. About 90 slots would handle the entire 8 era cargo car set, which would leave about 45 spare ones for extra custom cargo cars and/or custom locos.

Last time I tried getting the empty slots working I couldn't figure it out. *!*!*! Hopefully it's possible. Will have to test it and try a few things.
Gumbootz Lokomotivfabrik und Bierkeller

LMR Samson 0-4-0 - Pennsy H3 Consolidation - Custom double tank cars set
User avatar
Gumboots
CEO
Posts: 1203
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

Re: Making custom cargo car and locomotive profile icons Unread post

!!party*!

Just ran some quick and rough tests. Turns out I can get the dummy slots working, and can get them to call any chunk of the image I like. This is cool. (0!!0)

The quick and rough tests were with my new G era Troop cars. I edited their .car file to call CarSideview1.imb, and then messed around with references to call different chunks of the image, testing both hijacking a non-dummy reference (#114 - D era Rubber flatcar) and editing custom coordinates into a dummy call (#175 - last in the file). It all looks bodgey, because it's not calling a proper xTroopsG icon, but it all works predictably. This is a good enough proof of concept. All custom cargo cars, except flatcars, can potentially be done as part of CarSideView1.imb. Presumably it will work just as well for CarSideView2.imb and CarSideView3.imb. The only possible glitch is whether or not the game will accept a non-default size of those images to give the necessary extra space (will test that soon too) and maybe flatcars.

Why flatcars? Read on. :-D

While doing this, I figured out why I had trouble the last time I tried it a couple of years ago. Back then I was trying to get flatcars working, but at that stage was calling the default flatcar type (FlatA.car to FlatD.car in EngineTypes). The .car files for the default flatcar type reference the call for the empty flatcar placeholders in CarSideView1.imb, but they don't shows those icons while you are playing. At the time it drove me nuts, but it now makes perfect sense.

Since all the default flatcar cargoes reference the same .cgo and .car files in a given era (FlatA, FlatB, etc) there is no way that one .car file can give the correct CarSideView1.imb references for all cargoes. Since the .car file only allows one value, this means that when calling the default flatcar type the CarSideView1.imb references have to be handled by extra code locked inside the .exe. Without that extra locked code, there is no way the flatcar icons could work.

So, since the default flatcar icons rely on code locked inside the .exe they cannot be customised outside it, and therefore editing CarSideView1.imb won't work for FlatA, FlatB, FlatC or FlatD. Which I knew, but now I know why. *!*!*!

However, if you shift a default flatcar cargo to a custom car type, as I did with Goods being moved to the xBoxcar type, then you can call custom icons for it without dramas. IOW, I can get custom flatcar icons as long as the cargoes are on a custom car type, and as long as I'm using separate icons that aren't part of CarSideView1.imb.

What I don't know yet is whether I can get them working as part of CarSideView1.imb, or whether the extra code locked into the .exe will override any custom references for cargoes which are usually on flatcars (and basically bork things with a large, rusty hammer).

So the next testing steps are: 1/ try a non-standard size for CarSideView1.dds, with the appropriate edit to the image size in the header of CarSideView1.imb (and hope it works) and 2/ try a cargo which is on-flat-by-default with a custom car type, and see if it will still behave for icons inside CarSideView1.imb (probably won't).



Ok, 1/ works. !*th_up*! I just tested it by taking the default CarSideView1.dds and extending it from 512 height to 1024 height (copy/past of RGB and alpha channels to new 512x1024 file, with blank alpha and RGB filling the bottom half). This works just fine, and doing it this way means no need to edit all the references for existing icons. All it needs is the height changed in CarSideView1.imb, and custom icons can be added after the defaults. Easy.

Testing 2/ will require setting up some extra custom trickery for car type, so I'll get onto that.



Just got through testing 2/. As I suspected, attempting to use custom references inside CarSideView_1.imb, for a cargo that is on a flatcar by default (like Goods) does not work. The code inside the .exe is obviously overriding the custom car type (xxGoodsA, in this case). The result is that the icons simply do not display, although everything else works normally.

However, if I put Coffee into the same custom car type the icons work as they should. This is with them calling the last dummy reference, which has been edited to call an icon at the bottom right corner of the extended 512x1024 image. So most cargoes cool, but default flatcar cargoes no good.

Now for the stupid part. *!*!*! While testing this stuff I noticed that the consists still weren't scaling properly for longer cars. Eventually my brain started working, and I went back to my vanilla 1.05 installation and tested an 8 car consist of 50/50 default PassD and default MailD cars.

Turns out they don't scale properly either. :mrgreen: It's been so long since I messed with the default cars, and way back then I never noticed that their behaviour is bugged anyway. So you can put all your custom icons in CarSideView_1 and _2 and _3 if you want to (except for default flatcar cargoes) but even if you do there's no advantage in it. They still won't scale properly if the cars are too long.

So the upshot of all this stuffaroundery is that to get consists to behave really really properly, you're still restricted to somewhere around 85px icon length for any cargo car. Once it gets over that length things will start going bodgey on hover (car icons won't match the hover text, and speedometer won't be accessible on hover).

RT3: an entomologists paradise. More bugs than you can count. :-P

Anyway, at least now we know for sure. Separate icons and .imb files are easier on the brain, especially for WIP stuff, so for the moment I'll go back to using those.

Edit: Got clever and nailed down the limits, by messing around with default cars and loco changes. The default MailD has an 83px icon. The default Northern 484 has a 170px icon. A Northern hauling 8 MailD cars is just, barely inside the limit where all the hovers still work properly in the train list. It's just starting to break down, with the hover areas of the consist extending very slightly past the last car's icon, but the speedo is still accessible and hovering over each car works properly.

So that's the final figure: the complete train, locomotive and all cars, should have the sum of all its icons adding up to 834px, or less.
Gumbootz Lokomotivfabrik und Bierkeller

LMR Samson 0-4-0 - Pennsy H3 Consolidation - Custom double tank cars set
User avatar
Gumboots
CEO
Posts: 1203
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

Re: Making custom cargo car and locomotive profile icons Unread post

Woohoo! Nailed a solution! :-D This will allow any loco icon and any cargo car consist to fit in the available space and work properly for hover.

The trick is to edit the "Target Screen Width" and "Target Screen Height" in the header of the .imb files. Screenshot below.

Target_screen_size_tweaks.jpg

The default values in all CarsideView and Profile .imb files are 1600 px for "Target Screen Width" and 1200 px for "Target Screen Height". With these values, late era consists and large locomotives give the overflow problems I've been banging on about. However, if you edit those values you can make the train shrink or expand to suit the available space.

Increasing the "Target Screen Width" will make the train smaller in width, and increasing the "Target Screen Height" will make the train smaller in height. The screenshot shows how it works. The Big Boy is the largest default locomotive icon, and a Big Boy is 132 feet long. At the same scale, the icon for an 89 foot flatcar (actually 91 feet between connector faces) would be 147 pixels long. This is the longest icon likely to be used, so a good test case. The Red Devil icon is 148 px long, so works as a quick test. I simply edited the default PassD.car to call the CarSideView_1 reference for the Red Devil icon, so the 8 Red Devils are actually 8 pax cars, but with icons sized for the test. !*th_up*!

This all works. With the "Target Screen Width" set to 2640px, the entire train shrinks in size to fit the available space perfectly. Hovering the cursor over the locomotive, or over any cargo car, will always give the correct hover text at any position, and the speedo is accessible too. All three trains are set at this screen width, but the first one has "Target Screen Height" set at 1320 px and the second one has it set at 1980px (the natural 4:3 monitor ratio the game engine is coded for, since 2640/1980 = 4/3). This makes the first trains icons chunkier, because they are stretched vertically compared to their length. They look a bit more toy-like, but on the other hand are a bit easier to recognise at a glance. Anyway, you can tune it to suit your preferences just by tweaking "Target Screen Height".

The third train shown in the shot is a Planet and 8x A era pax cars, with height still at 1320 px. Here's the trade-off, in that early trains are probably a bit too small for convenience. Not a drama, because you can run those with different .imb tweaks if you want to. It wouldn't be hard to set up several batches of .imb files, that could be dropped in for different eras, or to make all custom icons to the same scale but adjust "Target Screen Width" and "Target Screen Height" for early cars and locos. It's all tweakable to get it behaving the way you want it. (0!!0)
Gumbootz Lokomotivfabrik und Bierkeller

LMR Samson 0-4-0 - Pennsy H3 Consolidation - Custom double tank cars set
Post Reply