Skip to content

Commit

Permalink
Merge pull request #1657 from CitiesSkylinesMods/enhancement/dlc-indi…
Browse files Browse the repository at this point in the history
…cator-for-options

Show DLC icon if the effect of the option depends on DLC availability
  • Loading branch information
krzychu124 committed Oct 4, 2022
2 parents a61184a + 609a7ad commit e1a357a
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 16 deletions.
14 changes: 6 additions & 8 deletions TLM/TLM/State/OptionsTabs/GameplayTab_AIGroups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public static class GameplayTab_AIGroups {
Label = "Gameplay.Checkbox:No excessive transfers",
};

public static CheckboxOption AllowBusInOldTown =
new(nameof(GlobalConfig.Instance.PathFinding.AllowBusInOldTownDistricts), Options.PersistTo.Global) {
public static DLCRestrictedCheckboxOption AllowBusInOldTown =
new(nameof(GlobalConfig.Instance.PathFinding.AllowBusInOldTownDistricts), requiredDLC: SteamHelper.DLC.AfterDarkDLC, Options.PersistTo.Global) {
Label = "Gameplay.Checkbox:Allow Buses in Old Town districts",
Handler = OnAllowBusInOldTownChanged,
Validator = AfterDarkDlcValidator,
};

public static CheckboxOption AllowTaxiInOldTown =
new(nameof(GlobalConfig.Instance.PathFinding.AllowTaxiInOldTownDistricts), Options.PersistTo.Global) {
public static DLCRestrictedCheckboxOption AllowTaxiInOldTown =
new(nameof(GlobalConfig.Instance.PathFinding.AllowTaxiInOldTownDistricts), requiredDLC: SteamHelper.DLC.AfterDarkDLC, Options.PersistTo.Global) {
Label = "Gameplay.Checkbox:Allow Taxis in Old Town districts",
Handler = OnAllowTaxiInOldTownChanged,
Validator = AfterDarkDlcValidator,
Expand All @@ -72,10 +72,8 @@ public static class GameplayTab_AIGroups {

RealisticPublicTransport.AddUI(group);

if (HasAfterDarkDLC) {
AllowBusInOldTown.AddUI(group);
AllowTaxiInOldTown.AddUI(group);
}
AllowBusInOldTown.AddUI(group);
AllowTaxiInOldTown.AddUI(group);
}

private static string T(string key) => Translation.Options.Get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public static class GameplayTab_VehicleBehaviourGroup {
};

// Requires Snowfall DLC
public static CheckboxOption StrongerRoadConditionEffects =
new(nameof(Options.strongerRoadConditionEffects), Options.PersistTo.Savegame) {
public static DLCRestrictedCheckboxOption StrongerRoadConditionEffects =
new(nameof(Options.strongerRoadConditionEffects), requiredDLC: SteamHelper.DLC.SnowFallDLC, Options.PersistTo.Savegame) {
Label = "Gameplay.Checkbox:Increase road condition impact",
Validator = SnowfallDlcValidator,
};
Expand Down Expand Up @@ -46,8 +46,7 @@ public static class GameplayTab_VehicleBehaviourGroup {

IndividualDrivingStyle.AddUI(group);

if (HasSnowfallDLC)
StrongerRoadConditionEffects.AddUI(group);
StrongerRoadConditionEffects.AddUI(group);

DisableDespawning.AddUI(group);

Expand Down
6 changes: 2 additions & 4 deletions TLM/TLM/State/OptionsTabs/PoliciesTab_InEmergenciesGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace TrafficManager.State {

public static class PoliciesTab_InEmergenciesGroup {

public static CheckboxOption EvacBussesMayIgnoreRules =
new (nameof(Options.evacBussesMayIgnoreRules), Options.PersistTo.Savegame) {
public static DLCRestrictedCheckboxOption EvacBussesMayIgnoreRules =
new (nameof(Options.evacBussesMayIgnoreRules), SteamHelper.DLC.NaturalDisastersDLC, Options.PersistTo.Savegame) {
Label = "VR.Checkbox:Evacuation buses may ignore traffic rules",
Validator = NaturalDisastersDlcValidator,
};
Expand All @@ -15,8 +15,6 @@ private static bool HasNaturalDisastersDLC
=> SteamHelper.IsDLCOwned(SteamHelper.DLC.NaturalDisastersDLC);

internal static void AddUI(UIHelperBase tab) {
if (!HasNaturalDisastersDLC) return;

var group = tab.AddGroup(T("VR.Group:In case of emergency/disaster"));

EvacBussesMayIgnoreRules.AddUI(group);
Expand Down
1 change: 1 addition & 0 deletions TLM/TLM/TLM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
<Compile Include="UI\Helpers\ActionButton.cs" />
<Compile Include="UI\Helpers\GlobalConfigObserver.cs" />
<Compile Include="UI\Helpers\DropDownOption.cs" />
<Compile Include="UI\Helpers\DLCRestrictedCheckboxOption.cs" />
<Compile Include="UI\Helpers\SliderOption.cs" />
<Compile Include="UI\Helpers\OptionButtonBase.cs" />
<Compile Include="UI\Helpers\UrlButton.cs" />
Expand Down
59 changes: 59 additions & 0 deletions TLM/TLM/UI/Helpers/DLCRestrictedCheckboxOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
namespace TrafficManager.UI.Helpers;

using System;
using ColossalFramework.Globalization;
using ColossalFramework.UI;
using ICities;
using TrafficManager.State;
using UnityEngine;

public class DLCRestrictedCheckboxOption : CheckboxOption {
private SteamHelper.DLC _requiredDLC;

public DLCRestrictedCheckboxOption(string fieldName,
SteamHelper.DLC requiredDLC,
Options.PersistTo scope = Options.PersistTo.Savegame) : base(fieldName, scope) {
_requiredDLC = requiredDLC;
_readOnly = !SteamHelper.IsDLCOwned(_requiredDLC);
}

public override CheckboxOption AddUI(UIHelperBase container) {
UIPanel panel = ((UIPanel)((UIHelper)container).self).AddUIComponent<UIPanel>();
panel.autoLayout = false;
panel.size = new Vector2(720, 22);//default checkbox template size
panel.relativePosition = Vector3.zero;
UIPanel innerPanel = panel.AddUIComponent<UIPanel>();
UISprite icon = innerPanel.AddUIComponent<UISprite>();
icon.relativePosition = Vector3.zero;
icon.size = new Vector2(24, 24);
icon.spriteName = MapToSpriteIconName(_requiredDLC);

var option = base.AddUI(new UIHelper(innerPanel));
innerPanel.relativePosition = new Vector3(-icon.size.x, 0);
innerPanel.autoLayoutDirection = LayoutDirection.Horizontal;
innerPanel.autoFitChildrenHorizontally = true;
innerPanel.autoFitChildrenVertically = true;
innerPanel.autoLayout = true;

if (_readOnly) {
icon.tooltip = Locale.Get("CONTENT_REQUIRED", _requiredDLC.ToString());
_ui.tooltip = Translate("Checkbox:DLC is required to change this option and see effects in game");
}

return option;
}

private static string MapToSpriteIconName(SteamHelper.DLC dlc) {
switch (dlc) {
case SteamHelper.DLC.AfterDarkDLC:
return "ADIcon";
case SteamHelper.DLC.NaturalDisastersDLC:
return "NaturalDisastersIcon";
case SteamHelper.DLC.SnowFallDLC:
return "WWIcon";
default:
return string.Empty;
}
}

}

0 comments on commit e1a357a

Please sign in to comment.