Skip to content

Technical Coding Tips

Benjamin Sutas edited this page Apr 8, 2022 · 9 revisions

Error Messages

Titles are meant to be the first line of the error message and are set by the caller. The message is meant to be set by the game command and should be your specific issue. For example, in your caller, do something like:

// set title
GameCommands::setErrorTitle(StringIds::cant_build_pop_5_string_id);

// call game command, handle failure
if (GameCommands::do_5(item, EntityId(*_buildTargetVehicle)) == GameCommands::FAILURE)
{
    return;
}

and in the game command, do something like this (on failure of the command):

// set error message details
GameCommands::setErrorText(StringIds::vehicle_is_locked);

// return failure
return GameCommands::FAILURE;

Game Commands

  • When updating a company, use CompanyManager::getUpdatingCompany()

Palettes

Google Sheets palette colour lookup

UI

Widget states

I don't have a perfect explanation of what 'enabled' state is really for, but:

  • enabled - whether or not the widget is enabled to render/accept input
  • disabled - disables user input to the widget and greys out its text/label
  • activated - for checkboxes, this is the true/false of the checkbox

Examples: Activated buttonWithImage: image

Widget sizing/spacing

  • Border size between window and widget: 3px
  • Distance between subsequent group boxes: 5px
  • Distance to indent an item off a checkbox: 15px
  • Distance to vertically space single-line widgets, eg text/buttons/labels: 14px

How to remove a static loco_global

In short, you want to provide getter and setter functions for that loco_global so that it doesn't need to be referenced in the file you're in; the getter/setters can be used instead. Here is a refactor by Duncan that removes a loco_global: https://github.com/OpenLoco/OpenLoco/pull/1381/files

Where should setter/getter go?

  • First check if the variable should be accessed through gamestate or s5::options
  • Anything from 0x009C8714 to 0x009C8714+0x431A is in s5:: options
  • 0x00525E18 to (0x00987C5C+0x3E80) is game state
  • Outside of those ranges it will just have to be based on where makes sense

GameState

There are two GameState structs, one in GameState.h and one in S5.h, what is the reason for this?

  • S5.h is the 'original' game state struct and will not change as it represents the original and thus will stay tied with the S5 format. The one in GameState.h is allowed to change as required when we add more options after new save format is introduced.

Tooltips

All string_ids that are for tooltips should have the "{SMALLFONT}{COLOUR BLACK}your_tooltip_here" formatting in en_GB.yml.

Clone this wiki locally