CitiesSkylinesMods / TMPE

Cities: Skylines Traffic Manager: President Edition
https://steamcommunity.com/sharedfiles/filedetails/?id=1637663252
MIT License
563 stars 85 forks source link

Tristate toggle #1675

Closed kianzarrin closed 1 year ago

kianzarrin commented 1 year ago

latest-branch-build.zip

fixes: #1671 see issue for details.

you can review first 2 commits individually:
1st- added extension for UIHelper to ensure type safety and convenience.
2nd- Added interface to propagate option dependencies (E.g.: enter blocked junction depends on junction restrictions).
this used to only work with checkbox but now it also works with tristate checkbox.

other commits:
- Created tristate toggle option
- if user moves mouse over the tristate sprite, tooltip is `yes no N/A`. 
but if user moves mouse over the text label, the tooltip explain what the option does.

Test: I tested propagation of dependencies also work.

test code:

diff --git a/TLM/TLM/State/OptionsTabs/PoliciesTab_RoundaboutsGroup.cs b/TLM/TLM/State/OptionsTabs/PoliciesTab_RoundaboutsGroup.cs
index 387cc6a3..c11dc8ef 100644
--- a/TLM/TLM/State/OptionsTabs/PoliciesTab_RoundaboutsGroup.cs
+++ b/TLM/TLM/State/OptionsTabs/PoliciesTab_RoundaboutsGroup.cs
@@ -57,7 +57,12 @@ namespace TrafficManager.State {
             };

         public static CheckboxOption RoundAboutQuickFix_ParkingBanYieldR =
-            new (nameof(Options.RoundAboutQuickFix_ParkingBanYieldR), Options.PersistTo.Savegame) {
+            new (nameof(Options.RoundAboutQuickFix_ParkingBanYieldR), Options.PersistTo.Global) {
+                Label = "Roundabout.Option:Put parking ban on roundabout branches",
+            };
+
+        public static TriStateCheckboxOption RoundAboutQuickFix_ParkingBanYieldR2 =
+            new(nameof(Options.RoundAboutQuickFix_ParkingBanYieldR), Options.PersistTo.Global) {
                 Label = "Roundabout.Option:Put parking ban on roundabout branches",
             };

@@ -85,6 +90,8 @@ namespace TrafficManager.State {
                     .PropagateTrueTo(MaintenanceTab_FeaturesGroup.ParkingRestrictionsEnabled);
                 RoundAboutQuickFix_ParkingBanYieldR
                     .PropagateTrueTo(MaintenanceTab_FeaturesGroup.ParkingRestrictionsEnabled);
+                RoundAboutQuickFix_ParkingBanYieldR2
+                    .PropagateTrueTo(MaintenanceTab_FeaturesGroup.ParkingRestrictionsEnabled);
             }
             catch (Exception ex) {
                 ex.LogException();
@@ -105,6 +112,7 @@ namespace TrafficManager.State {
             RoundAboutQuickFix_RealisticSpeedLimits.AddUI(group);
             RoundAboutQuickFix_ParkingBanMainR.AddUI(group);
             RoundAboutQuickFix_ParkingBanYieldR.AddUI(group);
+            RoundAboutQuickFix_ParkingBanYieldR2.AddUI(group);
         }

         private static string T(string key) => Translation.Options.Get(key);
kvakvs commented 1 year ago

Is this used anywhere in the UI, how to test?

kianzarrin commented 1 year ago

Is this used anywhere in the UI, how to test?

You need to type test code like the one I gave you on discord. also attached a test code in the description of this PR

What do you want to test?

kianzarrin commented 1 year ago

should I squash these two commits to the second commit and force push? 43a119a 66f958f this way all commits relating to propagation can be reviewed as one commit.

kvakvs commented 1 year ago

Is this used anywhere in the UI, how to test?

You need to type test code like the one I gave you on discord. also attached a test code in the description of this PR What do you want to test?

I want to see where this is used. Are you merging unused code?

kianzarrin commented 1 year ago

Are you merging unused code?

yes. next step is cleanup roundabout/high priority polices but that would be too much for this PR.

kianzarrin commented 1 year ago

@krzychu124 fixed disabled color image