Skip to content

Add inline inflation-adjusted cost editor for objects#223

Merged
LeftofZen merged 9 commits intomasterfrom
copilot/show-effective-cost-for-objects
Dec 28, 2025
Merged

Add inline inflation-adjusted cost editor for objects#223
LeftofZen merged 9 commits intomasterfrom
copilot/show-effective-cost-for-objects

Conversation

Copy link
Contributor

Copilot AI commented Dec 27, 2025

The editor now displays real in-game costs for objects accounting for inflation at a specified year, using a custom PropertyGrid cell editor that shows both the raw cost factor and calculated effective cost inline with an adjustable year stepper.

Changes

Core Economy Implementation

  • Common/Economy.cs: Inflation calculation engine
    • CalculateCurrencyMultiplicationFactors(year): Computes inflation factors for 32 cost indices using OpenLoco's inflation table
    • GetInflationAdjustedCost(costFactor, costIndex, year, divisor): Applies formula (costFactor * inflationFactor) / (1 << divisor)
    • Year range: 1900-2030 (values outside clamped)

Settings

  • EditorSettings: Added InflationYear property (default: 1950)
  • GlobalSettings: Static accessor for ViewModels to read current settings
  • Settings UI exposes inflation year control in Misc category

Custom PropertyGrid Cell Editor

  • CurrencyAttribute: Custom attribute to mark cost factor properties for custom editing
  • CurrencyEditorViewModel: ViewModel managing cost factor, year, and calculated effective cost
  • CurrencyView: Avalonia UI control displaying in a single row:
    • Cost Factor input (editable NumericUpDown)
    • Year stepper (editable NumericUpDown, 1800-2030)
    • Effective Cost display (calculated, £ formatted, read-only)
  • CurrencyCellEditFactory: Factory integrated into ExtendedPropertyGrid that creates custom editors for [Currency]-marked properties

ViewModel Updates

Applied [Currency] attribute to all cost factor properties across 13 object types:

  • Track, Road, Bridge: BuildCostFactor, SellCostFactor, TunnelCostFactor
  • Bridge: BaseCostFactor, HeightCostFactor
  • Tree: ClearCostFactor
  • Vehicle: CostFactor, RunCostFactor
  • Airport, Dock, Stations, Signals, Industry, Extras

Example from TrackViewModel:

[Category("Cost"), Currency]
public int16_t BuildCostFactor
{
    get => Model.BuildCostFactor;
    set => Model.BuildCostFactor = value;
}

Tests

  • EconomyTests: 9 tests validating inflation calculation mechanics

Usage

When editing objects in the PropertyGrid, cost factor properties display an inline editor showing:

  1. The editable cost factor value
  2. A year stepper (updates global inflation year setting)
  3. The calculated effective cost based on the selected year

This provides immediate visual feedback of how cost factors translate to in-game costs at different time periods, all within a single compact row per cost property.

Original prompt

This section details on the original issue you should resolve

<issue_title>Show effective cost for objects given a certain year</issue_title>
<issue_description>It could be useful to show in the editor the 'real' cost of building that object, given a certain year in the game. This would be shown on the UI as a real cost calculated from cost index and cost factor, and would need some kind of input for the in-game date, which would then set the inflation table which is also required for the calculation.

see: https://github.com/OpenLoco/OpenLoco/blob/master/src/OpenLoco/src/Economy/Economy.cpp#L130-L136</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Dec 27, 2025
Copilot AI and others added 4 commits December 27, 2025 13:59
Co-authored-by: LeftofZen <7483209+LeftofZen@users.noreply.github.com>
…ridge objects

Co-authored-by: LeftofZen <7483209+LeftofZen@users.noreply.github.com>
Co-authored-by: LeftofZen <7483209+LeftofZen@users.noreply.github.com>
Co-authored-by: LeftofZen <7483209+LeftofZen@users.noreply.github.com>
Copilot AI changed the title [WIP] Add effective cost display for objects by year Add inflation-adjusted cost display for objects Dec 27, 2025
Copilot AI requested a review from LeftofZen December 27, 2025 14:15
@LeftofZen
Copy link
Collaborator

@copilot this method for displaying the values in the UI does work, but since it is displayed in the UI in a PropertyGrid (from bodong.PropertyGrid repo) I would prefer if I could mark specific 'currency' properties with an attribute and then properties with that attribute use a custom cell editor and factory, which displays the underlying value as well as the inflation-adjusted value, as well as a stepper containing a year value that the user can edit.

…h inline inflation adjustment

- Created CurrencyAttribute to mark cost factor properties
- Created CurrencyEditorViewModel and CurrencyView for inline editing
- Created CurrencyCellEditFactory in ExtendedPropertyGrid
- Updated all 13 object ViewModels to use Currency attribute
- Removed separate read-only effective cost properties
- Cost properties now show: Factor input, Year stepper, and calculated effective cost inline

Co-authored-by: LeftofZen <7483209+LeftofZen@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 28, 2025

@copilot this method for displaying the values in the UI does work, but since it is displayed in the UI in a PropertyGrid (from bodong.PropertyGrid repo) I would prefer if I could mark specific 'curre...

I've implemented the custom PropertyGrid cell editor approach you requested. Changes in commit b9f4c65:

Implementation:

  • Created [Currency] attribute to mark cost factor properties
  • Built custom CurrencyCellEditFactory that creates inline editors for marked properties
  • Each currency property now displays in a single row with:
    • Factor input (editable)
    • Year stepper (editable, 1800-2030)
    • Calculated effective cost (£ formatted, read-only)

Applied to all 13 object types: Track, Road, Bridge, Airport, Dock, Stations (Track/Road), Extras (Track/Road), Tree, Signal, Industry, Vehicle

The year stepper updates the global inflation year setting, so changing it in one editor affects all currency displays. The UI is much more compact than the previous approach with separate read-only properties.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • av-build-tel-api-v1.avaloniaui.net
    • Triggering command: /usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.1/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.1/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll dong s /home/REDACTED/.local/bin/grep dong rtMovementNodeFl-l cal/bin/grep grep -l dong gionObjectLoader.cs ndor/bin/grep dong ionSound.cs rep grep (dns block)
    • Triggering command: /usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.1/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.1/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll dong ildingObjectLoader.cs /snap/bin/grep dong priteFlags.cs /opt/pipx_bin/grPropertyGrid\|ExtendedPropertyGrid grep -l dong wnNamesObjectLoader.cs p/bin/grep dong SpriteSlopeType.--norc grep grep (dns block)
    • Triggering command: /usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.2/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.2/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll dong cs /snap/bin/grep dong erAnimation.cs /opt/pipx_bin/grPropertyGrid\|ExtendedPropertyGrid grep -l dong rrencyObjectLoader.cs p/bin/grep dong nyColourType.cs grep grep (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add inflation-adjusted cost display for objects Add inline inflation-adjusted cost editor for objects Dec 28, 2025
@LeftofZen LeftofZen force-pushed the copilot/show-effective-cost-for-objects branch from 0f9e9bf to 5cec6f0 Compare December 28, 2025 05:42
@LeftofZen LeftofZen marked this pull request as ready for review December 28, 2025 05:42
Copilot AI review requested due to automatic review settings December 28, 2025 05:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an inline inflation-adjusted cost editor for objects in the ObjectEditor GUI, displaying real in-game costs based on specified year and inflation calculations derived from OpenLoco's economy system.

Key Changes:

  • Implemented core inflation calculation engine matching OpenLoco's formula (1900-2030 year range)
  • Created custom PropertyGrid cell editor with inline cost factor input, year stepper, and calculated effective cost display
  • Applied [InflatableCurrency] attribute to cost factor properties across 13 object ViewModel types

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
Definitions/Economy.cs Core inflation calculation engine with year-based currency multiplication factors
Tests/EconomyTests.cs Test suite validating inflation calculations and edge cases
Gui/Views/InflatableCurrencyView.axaml XAML layout for inline cost editor with factor input, year stepper, and result display
Gui/Views/InflatableCurrencyView.cs TemplatedControl backing class for currency view
Gui/ViewModels/InflatableCurrencyViewModel.cs ReactiveUI ViewModel managing cost calculations and property change notifications
Gui/Attributes/InflatableCurrencyAttribute.cs Custom attribute marking properties for inflation-adjusted editing
Gui/Views/ExtendedPropertyGrid.cs Factory implementation integrating custom currency editor into PropertyGrid
Gui/ViewModels/LocoTypes/Objects/*.cs Applied InflatableCurrency attributes and CostIndex property change notifications across 13 object types
Gui/Gui.csproj Added build configuration for CurrencyView component
Gui/App.axaml Registered InflatableCurrencyView style resources
Gui/Views/Pos3View.axaml Minor cleanup: removed ReSharper comments, improved comment formatting
Gui/ViewModels/EditorSettingsWindowViewModel.cs Added InflationYear setting property

@LeftofZen LeftofZen force-pushed the copilot/show-effective-cost-for-objects branch from 9717520 to 698d236 Compare December 28, 2025 11:38
@LeftofZen LeftofZen added this to the 5.7.0 milestone Dec 28, 2025
@LeftofZen LeftofZen added the ui label Dec 28, 2025
@LeftofZen LeftofZen merged commit 3bc3ff7 into master Dec 28, 2025
@LeftofZen LeftofZen deleted the copilot/show-effective-cost-for-objects branch December 28, 2025 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show effective cost for objects given a certain year

2 participants