r1sc / Open76

Interstate '76 engine reimplementation
GNU General Public License v3.0
52 stars 3 forks source link

Car Component UI Sprites (Weapons, Car Health, etc.) #20

Open JJJohan opened 5 years ago

JJJohan commented 5 years ago

The point of this issue isn't to get completely functional components, but to at least draw their UI elements on screen.

I've managed to decipher the ETBL blocks in the vehicles. These serve two purposes based on their flag. They are either reference images with one or more coordinates on the image to indicate where things go, or alternatively they are spritesheet images which are cut up into multiple sub-sections.

An example of a reference image - ZSY_.MAP (the lines and text were added for illustration purposes) reference

An example of a spritesheet - ZDUE.MAP: spritesheet

The ETBL structure

ETBL Offset Name Example Value Description
0 Map filename zrad.map The texture that holds all the goods
13 ETBL Type 0 0 = spritesheet, 1 = reference image
17 ETBL Length 2 Amount of sprites/positions in map

The ETBL item structure

Offset Name Example Value Description
0 Item Name range_pos Name of sprite / reference position
16 X Offset 139 X pixel offset in map texture
20 Y Offset 4 Y pixel offset in map texture
24 Width 0 Sprite width (always 0 for reference pos)
28 Height 0 Sprite height (always 0 for reference pos)

What I'd like to get working for this issue:

firstperson-reference

Stretch goal:

JJJohan commented 5 years ago

I've made a bit of progress on this.. image

Just emphasising that the weapon and systems panels are not static images here, they're displaying the correct digits and colours!

The good news is I managed to get a sprite manager set up that handles all the ETBL stuff and have a weapons panel class that deals with the weapon sprites, right down to the ammo count and the health level diodes (at least on the UI side of things)

Currently I've set sprites up to simply be a Color array with a Width and Height property. The image generation consists of inserting the pixel buffer into an existing texture. This way there is only 1 texture (per panel). It is quite fast to modify the texture this way, less straining on system resources and completely backwards compatible (at least as much as Unity will allow support for). Also it ensures the sprites are placed in the correct pixel coordinates rather than fiddling with world objects in texture space.

Sadly there's some bad news too..

I pointed my data folder back back over to my Interstate 76 Gold Edition - only to find that the VDFs don't have ETBL blocks at all! The sprites are located elsewhere. Garrr why did the data files change so much between game versions!

It's not impossible to work around, but a little surprising and a bit annoying. I think for the time being, I'll wrap up the weapons and vehicle component panels and then adjust the sprite manager so it can handle loading wherever the Gold Edition sprites are stored.

Update

Upon closer inspection of the data files in the patched version of the game, the data is moved from the VDF to a separate ELT file. This is a text-only file, but the layout of the data is identical to the ETBL data. Using this information, I determine from the VDF file revision whether we extract the ETBL data from the VDF itself or from an ELT file - the good news is there's no duplicate logic here and everything now works as intended in both versions of the game.

Video of UI in action:

<img src="https://img.youtube.com/vi/r7gUhUpr7TE/0.jpg" alt="Vehicle Sounds Video" border="10" />

Update 2

I got the compass completely working, yay. I should probably take a break soon so I don't lose interest 😛. Anyway quick update of what's done, and what's left before I'll throw up a pull request:

Done: Weapons panel Systems panel Compass Gear Panel Specials Panel

To Do (I might do these in a separate pull request): Radar "Interior view 2" i.e. car turned off but UI visible (whatever this camera mode is called)