Quantx / CC2-UI-Enhancer

UI Enhancer mod for Carrier Command 2
58 stars 17 forks source link

Adding load bar to the inventory screen #31

Closed Rcomian closed 2 years ago

Rcomian commented 2 years ago

Adds a bar chart to the inventory screen so we can see how loaded our carrier is.

The bar consists of 3 parts:

The effect is this:

At the start of the game, the bar is just white. The default loadout gives you 27.3% of your capacity, so the bar is quite short. When you order your initial items, the bar extends with a dark grey section. This shows how far your white bar will go once the order has been fulfilled. When a barge picks up the order, the part of the order picked up by the barge turns light grey. If the barge leaves anything behind, that portion will be left as dark grey. When the barge delivers the order, as each item is put on the barge, the corresponding light-grey turns to white.

If ever the total orders go over the capacity of the barge, the border of the box turns red.

Implementation wise, render_inventory_stats has had a call to render_carrier_load_graph inserted between the two text rendering calls. This calculates the various load categories and the required lengths of the bars.

The extra functions: update_ui_bar, get_ordered_weight, get_barge_weight support this. They're mainly there to break the main function up.

Some effort has been made to prevent the bar "jittering". due to the nature of integer math and roundings, it's normal for the entire bar length to shift by up to 3 pixels. This is avoided by determining the required length before rounding the individual parts and then adding padding in a consistent way to ensure we hit the various lengths required.

I'm sure there's a better way to do that padding.

Quantx commented 2 years ago

Looks good! I'll probably do some minor tweaks, but overall I think this is a great way to communicate the carrier's current cargo capacity to the player.