-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1657 from CitiesSkylinesMods/enhancement/dlc-indi…
…cator-for-options Show DLC icon if the effect of the option depends on DLC availability
- Loading branch information
Showing
5 changed files
with
71 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |