Skip to content

Game.UI.InGame.LoanUISystem

Assembly:
Game

Namespace:
Game.UI.InGame

Type:
public class

Base:
UISystemBase

Summary:
LoanUISystem is a UI-facing system that exposes loan-related data and actions to the UI layer via Colossal.UI binding types. It retrieves the in-game loan system (ILoanSystem) from the world, creates value bindings for the player's loan limit (creditworthiness), the current loan, and a proposed loan offer. It also handles UI-triggered actions to request, accept, or reset loan offers. A nested LoanWriter class is provided to serialize LoanInfo objects to JSON for the bindings.


Fields

  • private const string kGroup
    The binding group key used for all loan-related bindings ("loan"). Used to namespace the bindings so the UI can reference them.

  • private GetterValueBinding<int> m_LoanLimitBinding
    Getter binding that exposes the player's loan limit (creditworthiness) to the UI. It is populated from m_LoanSystem.Creditworthiness.

  • private GetterValueBinding<LoanInfo> m_CurrentLoanBinding
    Getter binding that exposes the current LoanInfo (the player's active loan) to the UI. It uses LoanWriter to serialize LoanInfo into JSON.

  • private GetterValueBinding<LoanInfo> m_LoanOfferBinding
    Getter binding that exposes a proposed loan offer (LoanInfo) to the UI. It calls m_LoanSystem.RequestLoanOffer with the current loan amount plus any requested offer difference; uses LoanWriter for serialization.

  • private ILoanSystem m_LoanSystem
    Reference to the game's loan system. Acquired via base.World.GetOrCreateSystemManaged() in OnCreate.

  • private int m_RequestedOfferDifference
    Tracks the difference between the currently proposed loan offer amount and the current loan amount. Used to remember a pending offer until the player accepts or resets it.

  • Nested type: public class LoanWriter : IWriter<LoanInfo>
    Serializer used by the GetterValueBinding bindings to write LoanInfo instances into JSON properties that the UI consumes. See Methods section for details.

Properties

  • None.
    This system exposes data via bindings rather than public properties.

Constructors

  • public LoanUISystem()
    Default constructor. Marked with [Preserve] attribute in the source to prevent stripping. The constructor itself performs no initialization beyond default; actual setup is done in OnCreate.

Methods

  • public void LoanWriter.Write(IJsonWriter writer, LoanInfo value)
    Serializes a LoanInfo instance into the writer. Writes a type begin marker ("loan.Loan") and the following properties: amount, dailyInterestRate, dailyPayment. Used by the GetterValueBinding instances to produce JSON for the UI.

  • protected override void OnCreate()
    Initializes the system: obtains the ILoanSystem from the world, creates and registers bindings:

  • m_LoanLimitBinding: group "loan", name "loanLimit", getter -> m_LoanSystem.Creditworthiness
  • m_CurrentLoanBinding: group "loan", name "currentLoan", getter -> m_LoanSystem.CurrentLoan (uses LoanWriter)
  • m_LoanOfferBinding: group "loan", name "loanOffer", getter -> m_LoanSystem.RequestLoanOffer(m_LoanSystem.CurrentLoan.m_Amount + m_RequestedOfferDifference) (uses LoanWriter)
  • Trigger bindings: "requestLoanOffer" -> RequestLoanOffer(int), "acceptLoanOffer" -> AcceptLoanOffer(), "resetLoanOffer" -> ResetLoanOffer() This method is annotated with [Preserve] in the source.

  • protected override void OnGameLoaded(Context serializationContext)
    Called when the game (or save) loads. Resets m_RequestedOfferDifference to 0 to ensure no stale pending offers remain after load.

  • protected override void OnUpdate()
    Called every update tick. Updates the three GetterValueBinding instances so the UI sees current values.

  • private void RequestLoanOffer(int amount)
    Called by the "requestLoanOffer" trigger. Requests a loan offer for the specified amount from m_LoanSystem.RequestLoanOffer(amount) and sets m_RequestedOfferDifference to the difference between the offered amount and the current loan amount. This difference is used when the player later accepts the offer.

  • private void AcceptLoanOffer()
    Called by the "acceptLoanOffer" trigger. Applies the pending offer by calling m_LoanSystem.ChangeLoan(currentAmount + m_RequestedOfferDifference) and then resets m_RequestedOfferDifference to 0.

  • private void ResetLoanOffer()
    Called by the "resetLoanOffer" trigger. Clears any pending offer by setting m_RequestedOfferDifference to 0.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Acquire the game loan system and set up bindings (example taken from the mod source).
    m_LoanSystem = base.World.GetOrCreateSystemManaged<LoanSystem>();

    AddBinding(m_LoanLimitBinding = new GetterValueBinding<int>("loan", "loanLimit", () => m_LoanSystem.Creditworthiness));
    AddBinding(m_CurrentLoanBinding = new GetterValueBinding<LoanInfo>("loan", "currentLoan", () => m_LoanSystem.CurrentLoan, new LoanWriter()));
    AddBinding(m_LoanOfferBinding = new GetterValueBinding<LoanInfo>("loan", "loanOffer", () => m_LoanSystem.RequestLoanOffer(m_LoanSystem.CurrentLoan.m_Amount + m_RequestedOfferDifference), new LoanWriter()));

    AddBinding(new TriggerBinding<int>("loan", "requestLoanOffer", RequestLoanOffer));
    AddBinding(new TriggerBinding("loan", "acceptLoanOffer", AcceptLoanOffer));
    AddBinding(new TriggerBinding("loan", "resetLoanOffer", ResetLoanOffer));
}

Notes and tips: - Bindings expose data to the UI layer (group "loan") which the game's UI components can listen to. - LoanWriter serializes only the fields amount, dailyInterestRate and dailyPayment from LoanInfo; extend if additional LoanInfo fields need to be exposed. - The pattern uses m_RequestedOfferDifference to avoid immediately changing the player's loan until they explicitly accept an offer. Make sure to reset this value when appropriate (e.g., on load or cancel).