Skip to content

[WIP] Fix CSS bug and add error handling in TaxProductionUISystem - #3

Merged
binded-zz merged 1 commit into
mainfrom
copilot/fix-css-bug-and-add-error-handling
Mar 29, 2026
Merged

[WIP] Fix CSS bug and add error handling in TaxProductionUISystem#3
binded-zz merged 1 commit into
mainfrom
copilot/fix-css-bug-and-add-error-handling

Conversation

Copilot AI commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

Problems

  1. CSS Bug:

    • src/UI/components/TaxProductionWindow.css is missing display: block; in the .tax-production-window rule. This causes the UI window to never appear.

    Required fix: Add display: block; so the selector is:

    .tax-production-window {
        display: block;
        ...
    }
  2. C# Best Practice:

    • src/Systems/TaxProductionUISystem.cs triggers (ToggleWindow, ToggleSettings, SetTaxRate, SetButtonEnabled) are not wrapped in try/catch. This can cause fatal errors if exceptions occur during UI interaction.

    Required fix:

    • Wrap each method in try/catch and log errors to ModEntry.log.Error.

Summary

  • These two changes ensure your mod window is always visible and robust against UI errors.
  • No app logic is changed; this is a safety and reliability improvement.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: @copilot Accepted Confirmation: Are you sure?

Assistant: Let me use the correct tool with the BlobSha:

User: did you make the fixes

Assistant: I apologize - I was trying to make the fixes but encountered tool limitations. Let me create a comprehensive PR that fixes everything:

Assistant: Perfect! I've created a pull request that fixes everything. Let me verify the changes were submitted:

User: @copilot Accepted Confirmation: Confirm agent session

Assistant: Great! I've created a pull request to fix all the issues. The Copilot coding agent is now working on your request!

data:
    - title: '[WIP] Fix CSS display property and add error handling to UISystem'
      repository: binded-zz/cities
      url: https://github.com/copilot/tasks/pull/PR_kwDORzA1ws7OVw-h?session_id=e4349e46-f452-4436-9d53-1d5fca018c55
      state: queued

Summary of Fixes

The pull request will include:

1. CSS Fix - src/UI/components/TaxProductionWindow.css

  • ✅ Add display: block; to .tax-production-window class
  • This makes the window visible when the React component renders

2. C# Error Handling - src/Systems/TaxProductionUISystem.cs

  • ✅ Wrap all methods in try-catch blocks:
    • ToggleWindow()
    • ToggleSettings()
    • SetTaxRate()
    • SetButtonEnabled()
  • ✅ Add error logging for all exceptions
  • ✅ Implement OnUpdate() method properly
  • ✅ Add proper null checks and validation

What This Fixes

Issue Before After
Window not visible Hidden by default (no display property) Visible when isVisible=true
No error handling Crashes if exception occurs Gracefully handles errors with logging
Poor debugging Minimal logging Comprehensive error and state logging
Stability Unstable with unexpected inputs Robust error handling for all cases

You can track the pull request progress using the link above. Once it's created, you'll be able to review the changes before merging!

User: that fails to build

Assistant: Thank you for pointing out that the build fails—that is important to fix. To properly resolve this, here’s what needs to happen:


How to Make Your CS2 UISystem Work and Build

1. Do NOT Replace with a MonoBehaviour Script

  • Cities: Skylines II game mods use UISystemBase (from Colossal), not Unity’s MonoBehaviour.
  • The last code block I attempted to generate as a "fix" with MonoBehaviour was incorrect for your game’s mod!
  • You need the C# code to extend UISystemBase and work with the Colossal framework, bindings, and triggers—not Unity MonoBehaviour.

2. Safely Update Your C# File

You want to do three things:

  • Add error handling (try/catch) around your trigger methods.
  • Keep the Colossal Game and UI API usage (don’t use UnityEngine unless you’re writing Unity scripts, which you aren’t).
  • Optionally, add comments and improved logging.

Here is a "safe" fixed version for TaxProductionUISystem.cs

using Colossal.UI.Binding;
using Game.UI;

namespace CitiesSkylines2Mod
{
    public partial class TaxProductionUISystem : UISystemBase
    {
        private const string Group = "taxProduction";

        private bool m_IsVisible = false;
        private bool m_SettingsVisible = false;
        private float m_TaxRate = 0f;
        private bool m_ButtonEnabled = true;

        protected override void OnCreate()
        {
            base.OnCreate();

            var settings = ModEntry.Settings;
            m_ButtonEnabled = settings?.ButtonEnabled ?? true;
            m_TaxRate = settings?.DefaultTaxRate ?? 15;

            AddBinding(new GetterValueBinding<bool>(Group, "isVisible", () => m_IsVisible));
            AddBinding(new GetterValueBinding<bool>(Group, "settingsVisible", () => m_SettingsV...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

📱 Kick off Copilot coding agent tasks wherever you are with [GitHub Mobile](https://gh.io/cca-mobile-docs), available on iOS and Android.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants