From 7d5c72134dae737fff6146c4f5ea5f7418d00af2 Mon Sep 17 00:00:00 2001 From: algernon-A Date: Thu, 21 Sep 2023 22:50:09 +1000 Subject: [PATCH] Sundry cleanups. --- Code/AutoReplace/AutoReplaceXML.cs | 2 +- Code/Mod.cs | 2 +- Code/Patches/Escape.cs | 8 +++--- Code/Patches/ToolBasePatch.cs | 2 +- Code/Replacer.cs | 2 +- Code/Settings/ModSettings.cs | 10 +++---- Code/UI/BuiltStationPanel.cs | 2 +- Code/UI/RONTool.cs | 4 +-- Code/UI/ReplacerPanel.cs | 42 +++++++++++++++--------------- Code/UI/UIList/NetRow.cs | 2 +- Code/UI/UIList/NetRowItem.cs | 10 +++---- Code/Utils/PrefabUtils.cs | 7 +++-- 12 files changed, 46 insertions(+), 47 deletions(-) diff --git a/Code/AutoReplace/AutoReplaceXML.cs b/Code/AutoReplace/AutoReplaceXML.cs index d06eb1f..debaa9c 100644 --- a/Code/AutoReplace/AutoReplaceXML.cs +++ b/Code/AutoReplace/AutoReplaceXML.cs @@ -57,7 +57,7 @@ public enum Replacements : int MOM, /// - /// Number of replacment types. + /// Number of replacement types. /// NumReplacements, } diff --git a/Code/Mod.cs b/Code/Mod.cs index ce8deb3..c29ad0f 100644 --- a/Code/Mod.cs +++ b/Code/Mod.cs @@ -20,7 +20,7 @@ public class Mod : PatcherMod, IUserMod public override string BaseName => "RON - the network replacer"; /// - /// Gets the mod's unique Harmony identfier. + /// Gets the mod's unique Harmony identifier. /// public override string HarmonyID => "com.github.algernon-A.csl.ron"; diff --git a/Code/Patches/Escape.cs b/Code/Patches/Escape.cs index 3400cc7..3a8a480 100644 --- a/Code/Patches/Escape.cs +++ b/Code/Patches/Escape.cs @@ -17,13 +17,13 @@ public static class Escape /// /// Harmony prefix patch to cancel the RON tool when it's active and the escape key is pressed. /// - /// True (continue on to game method) if the zoning tool isn't already active, false (pre-empt game method) otherwise. + /// True (continue on to game method) if the zoning tool isn't already active, false (preempt game method) otherwise. public static bool Prefix() { // Is the RON tool active? if (RONTool.IsActiveTool) { - // Yes; toggle tool status and return false (pre-empt original method). + // Yes; toggle tool status and return false (preempt original method). RONTool.ToggleTool(); return false; } @@ -32,7 +32,7 @@ public static bool Prefix() // Is the station panel open? if (StandalonePanelManager.Panel is StationPanel stationPanel) { - // Yes; close panel and return false (pre-empt original method). + // Yes; close panel and return false (preempt original method). stationPanel.Close(); return false; } @@ -41,7 +41,7 @@ public static bool Prefix() // Is the built station panel open? if (StandalonePanelManager.Panel is BuiltStationPanel builtStationPanel) { - // Yes; close panel and return false (pre-empt original method). + // Yes; close panel and return false (preempt original method). builtStationPanel.Close(); return false; } diff --git a/Code/Patches/ToolBasePatch.cs b/Code/Patches/ToolBasePatch.cs index 6e8bea9..8e0be1c 100644 --- a/Code/Patches/ToolBasePatch.cs +++ b/Code/Patches/ToolBasePatch.cs @@ -15,7 +15,7 @@ namespace RON [HarmonyPatch(typeof(ToolBase))] public static class ToolBasePatch { - // Setment to highlight (0 for none). + // Segment to highlight (0 for none). private static ushort s_selectedSegment = 0; /// diff --git a/Code/Replacer.cs b/Code/Replacer.cs index b1ffa6d..aaacf55 100644 --- a/Code/Replacer.cs +++ b/Code/Replacer.cs @@ -79,7 +79,7 @@ internal static void ReplaceNets(NetInfo target, NetInfo replacement, List - /// Gets or sets a value indicating whether North Americal Rail tracks should be auto-replaced on load (true). + /// Gets or sets a value indicating whether North American Rail tracks should be auto-replaced on load (true). /// [XmlIgnore] private static bool s_replaceNAR = true; @@ -97,7 +97,7 @@ public bool XMLShowRailwayReplacer } /// - /// Gets or sets a value indicating whether Network Extensons 2 roads should be auto-replaced on load (true). + /// Gets or sets a value indicating whether Network Extensions 2 roads should be auto-replaced on load (true). /// [XmlElement("ReplaceNExt2")] public bool XMLReplaceNext @@ -117,7 +117,7 @@ public bool XMLReplaceMOM } /// - /// Gets or sets a value indicating whether North Americal Rail tracks should be auto-replaced on load (true). + /// Gets or sets a value indicating whether North American Rail tracks should be auto-replaced on load (true). /// [XmlElement("ReplaceNAR")] public bool XMLReplaceNAR @@ -149,7 +149,7 @@ public AutoReplaceXML.Replacements XMLReplaceNARmode internal static bool EnableAdvanced { get => s_enableAdvanced; set => s_enableAdvanced = value; } /// - /// Gets or sets a value indicating whether Network Extensons 2 roads should be auto-replaced on load (true). + /// Gets or sets a value indicating whether Network Extensions 2 roads should be auto-replaced on load (true). /// [XmlIgnore] internal static bool ReplaceNExt2 { get => s_replaceNExt2; set => s_replaceNExt2 = value; } @@ -161,7 +161,7 @@ public AutoReplaceXML.Replacements XMLReplaceNARmode internal static bool ReplaceMOM { get => s_replaceMOM; set => s_replaceMOM = value; } /// - /// Gets or sets a value indicating whether North Americal Rail tracks should be auto-replaced on load (true). + /// Gets or sets a value indicating whether North American Rail tracks should be auto-replaced on load (true). /// [XmlIgnore] internal static bool ReplaceNAR { get => s_replaceNAR; set => s_replaceNAR = value; } diff --git a/Code/UI/BuiltStationPanel.cs b/Code/UI/BuiltStationPanel.cs index 65b28b8..423d7f6 100644 --- a/Code/UI/BuiltStationPanel.cs +++ b/Code/UI/BuiltStationPanel.cs @@ -78,7 +78,7 @@ public override void Awake() } /// - /// Called by Unity every tick. Used here to track state of any in-progress replacments. + /// Called by Unity every tick. Used here to track state of any in-progress replacements. /// public override void Update() { diff --git a/Code/UI/RONTool.cs b/Code/UI/RONTool.cs index 64e642b..c23ec3e 100644 --- a/Code/UI/RONTool.cs +++ b/Code/UI/RONTool.cs @@ -44,7 +44,7 @@ public override NetSegment.Flags GetSegmentIgnoreFlags(out bool nameOnly) } /// - /// Sets vehicle ingore flags to ignore all vehicles. + /// Sets vehicle ignore flags to ignore all vehicles. /// /// Vehicle flags ignoring all vehicles. public override Vehicle.Flags GetVehicleIgnoreFlags() => @@ -259,7 +259,7 @@ protected override void OnEnable() // Make sure that game is loaded before activating tool. if (!OnLevelLoadedPatch.Loaded) { - // Loading not complete - deactivate tool by seting default tool. + // Loading not complete - deactivate tool by setting default tool. ToolsModifierControl.SetTool(); return; } diff --git a/Code/UI/ReplacerPanel.cs b/Code/UI/ReplacerPanel.cs index b245380..7515eb3 100644 --- a/Code/UI/ReplacerPanel.cs +++ b/Code/UI/ReplacerPanel.cs @@ -58,8 +58,8 @@ internal class ReplacerPanel : StandalonePanel private const float ReplaceWidth = 150f; private const float FilterX = (CalculatedPanelWidth - Margin) - 360f; private const float FilterWidth = 220; - private const float FilterMenuxX = FilterX + FilterWidth + Margin; - private const float FilterMenuWidth = CalculatedPanelWidth - FilterMenuxX - Margin; + private const float FilterMenuX = FilterX + FilterWidth + Margin; + private const float FilterMenuWidth = CalculatedPanelWidth - FilterMenuX - Margin; private const float ButtonWidth = 220f; private const float PrevX = Margin; private const float NextX = LeftWidth + Margin - ButtonWidth; @@ -214,13 +214,13 @@ internal class ReplacerPanel : StandalonePanel }; // Segment info record. - private Dictionary> _segmentDict = new Dictionary>(); + private readonly Dictionary> _segmentDict = new Dictionary>(); // Parent-child network relation dictionaries. - private Dictionary _slopeParents = new Dictionary(); - private Dictionary _elevatedParents = new Dictionary(); - private Dictionary _bridgeParents = new Dictionary(); - private Dictionary _tunnelParents = new Dictionary(); + private readonly Dictionary _slopeParents = new Dictionary(); + private readonly Dictionary _elevatedParents = new Dictionary(); + private readonly Dictionary _bridgeParents = new Dictionary(); + private readonly Dictionary _tunnelParents = new Dictionary(); // Panel components. private UIList _targetList; @@ -447,7 +447,7 @@ public override void Awake() nameFilter.eventTextSubmitted += (c, text) => LoadedList(); // Search by name/author dropdown. - _searchTypeMenu = UIDropDowns.AddDropDown(this, FilterMenuxX, ToolRow1Y, FilterMenuWidth); + _searchTypeMenu = UIDropDowns.AddDropDown(this, FilterMenuX, ToolRow1Y, FilterMenuWidth); _searchTypeMenu.items = new string[(int)SearchTypes.NumTypes] { Translations.Translate("RON_PNL_NET"), Translations.Translate("RON_PNL_CRE") }; _searchTypeMenu.selectedIndex = (int)SearchTypes.SearchNetwork; _searchTypeMenu.eventSelectedIndexChanged += (c, isChecked) => LoadedList(); @@ -587,7 +587,7 @@ internal void SetTarget(ushort segmentID) // Set target list position. _targetList.FindItem(x => x.Prefab == selectedNet); - // Set selected network segement. + // Set selected network segment. _currentSegment = segmentID; // Set selected segments. @@ -651,7 +651,7 @@ private void SetSelectedSegments() // Get district of selected segment. ushort districtID = districtManager.GetDistrict(segmentBuffer[_currentSegment].m_middlePosition); - // Iterate through each segment of this type in our dictionary, adding to our list of selected segments if both start and end nodes are in the same district as the initial segement. + // Iterate through each segment of this type in our dictionary, adding to our list of selected segments if both start and end nodes are in the same district as the initial segment. foreach (ushort districtSegment in _segmentDict[SelectedPrefab]) { if (districtManager.GetDistrict(nodeBuffer[segmentBuffer[districtSegment].m_startNode].m_position) == districtID && districtManager.GetDistrict(nodeBuffer[segmentBuffer[districtSegment].m_endNode].m_position) == districtID) @@ -764,7 +764,7 @@ private void Delete(UIComponent c, UIMouseEventParameter p) YesNoNotification warningNotification = NotificationBase.ShowNotification(); warningNotification.YesButton.eventClicked += (button, clickEvent) => DeleteNets(); - // Singlular or plural? + // Singular or plural? warningNotification.AddParas( Translations.Translate(_selectedSegments.Count > 1 ? "RON_WAR_DEL" : "RON_WAR_DES"), Translations.Translate("RON_WAR_UND")); @@ -815,7 +815,7 @@ private void NextSegment(UIComponent c, UIMouseEventParameter p) // Is the selected segment ahead of this? if (segmentID > _currentSegment) { - // 'Fresh' segment - update target to this and finish looping, since we've found our taget. + // 'Fresh' segment - update target to this and finish looping, since we've found our target. targetSegment = segmentID; break; } @@ -825,7 +825,7 @@ private void NextSegment(UIComponent c, UIMouseEventParameter p) // Did we find a valid target? if (targetSegment != 0) { - ViewSegement(targetSegment); + ViewSegment(targetSegment); } } @@ -855,7 +855,7 @@ private void PreviousSegment(UIComponent c, UIMouseEventParameter p) // Is the previously-shown segment counter ahead of this? if (segmentID < _currentSegment) { - // 'Fresh' segment - update target to this and finish looping, since we've found our taget. + // 'Fresh' segment - update target to this and finish looping, since we've found our target. targetSegment = segmentID; break; } @@ -865,7 +865,7 @@ private void PreviousSegment(UIComponent c, UIMouseEventParameter p) // Did we find a valid target? if (targetSegment != 0) { - ViewSegement(targetSegment); + ViewSegment(targetSegment); } } @@ -971,7 +971,7 @@ private void SortTargets(UIComponent c, UIMouseEventParameter p) /// Moves the camera to view the given segment. /// /// Segment ID of target segment. - private void ViewSegement(ushort segmentID) + private void ViewSegment(ushort segmentID) { // Yes - set camera position. Vector3 cameraPosition = NetManager.instance.m_segments.m_buffer[segmentID].m_middlePosition; @@ -1048,7 +1048,7 @@ private void TargetList() NetSegment[] segments = netManager.m_segments.m_buffer; for (ushort i = 0; i < segments.Length; ++i) { - // Skip any inleigible flags. + // Skip any ineligible flags. if ((segments[i].m_flags & NetSegment.Flags.Created) == 0) { continue; @@ -1089,7 +1089,7 @@ private void TargetList() } } - // Create new object list for fastlist, ordering as approprite. + // Create new object list for fastlist, ordering as appropriate. object[] objectArray; switch (_targetSearchStatus) { @@ -1186,7 +1186,7 @@ private void LoadedList() } } - // Create new object list for fastlist, ordering as approprite. + // Create new object list for fastlist, ordering as appropriate. object[] objectArray; switch (_loadedSearchStatus) { @@ -1276,7 +1276,7 @@ private void DisplayNetwork(NetInfo network, UISprite previewSprite) } /// - /// Retuns the type icon filename for the given network. + /// Returns the type icon filename for the given network. /// /// Network to get icon for. /// Type icon filename, or null if no type icon is available. @@ -1436,7 +1436,7 @@ private UISprite AddArrowSprite(UIComponent parent, float xPos, string spriteNam /// Adds an arrow button. /// /// Parent component. - /// Relative X postion. + /// Relative X position. /// Relative Y position. /// Button width (default 32). /// Button height (default 20). diff --git a/Code/UI/UIList/NetRow.cs b/Code/UI/UIList/NetRow.cs index efb1e56..c21e8ab 100644 --- a/Code/UI/UIList/NetRow.cs +++ b/Code/UI/UIList/NetRow.cs @@ -223,7 +223,7 @@ protected override void OnSizeChanged() _stationLabel.relativePosition = new Vector2(StationX, (RowHeight - LabelHeight) / 2f); _categoryLabel.relativePosition = new Vector2(CategoryX, (RowHeight - LabelHeight) / 2f); - // Set icon sprice position. + // Set icon sprite position. _typeIconSprite.relativePosition = new Vector2(TypeX, (RowHeight - SpriteSize) / 2f); } } diff --git a/Code/UI/UIList/NetRowItem.cs b/Code/UI/UIList/NetRowItem.cs index 93a430d..05e9175 100644 --- a/Code/UI/UIList/NetRowItem.cs +++ b/Code/UI/UIList/NetRowItem.cs @@ -11,10 +11,10 @@ namespace RON public class NetRowItem { // Private fields. - private NetInfo _prefab; + private readonly NetInfo _prefab; + private readonly string _creator; + private readonly bool _isStation = false; private string _displayName; - private string _creator; - private bool _isStation = false; // Network indicator flags - if this is a vanilla/NExt2/mod asset. private bool _isVanilla = false; @@ -92,7 +92,7 @@ private void GetDisplayName() // If no period, assume it's either vanilla or Mod. if (period < 0) { - // Check for NEext prefabs. NExt prefabs aren't as consistent as would be ideal.... + // Check for NExt prefabs. NExt prefabs aren't as consistent as would be ideal.... _isNExt2 = _prefab.m_class.name.StartsWith("NExt") || _prefab.m_class.name.StartsWith("NEXT") || @@ -102,7 +102,7 @@ private void GetDisplayName() _prefab.name.StartsWith("Highway2L2W") || _prefab.name.StartsWith("AsymHighwayL1R2"); - // Check for Extra Train Station Tracks, OneWayTrainTrack, and MOM prefabs; this overrides the NExt2 check due to some OneWayTrainTrack prefabs haveing 'NExtSingleStaitonTrack' ItemClass (and hence being picked up above as NExt2 items). + // Check for Extra Train Station Tracks, OneWayTrainTrack, and MOM prefabs; this overrides the NExt2 check due to some OneWayTrainTrack prefabs having 'NExtSingleStationTrack' ItemClass (and hence being picked up above as NExt2 items). _isMod = _prefab.name.StartsWith("Station") || _prefab.name.StartsWith("Train Station Track (") || _prefab.name.StartsWith("Rail1L") || diff --git a/Code/Utils/PrefabUtils.cs b/Code/Utils/PrefabUtils.cs index 1ea4e25..3eb3451 100644 --- a/Code/Utils/PrefabUtils.cs +++ b/Code/Utils/PrefabUtils.cs @@ -5,7 +5,6 @@ namespace RON { - using System; using System.Collections.Generic; using ColossalFramework; using ColossalFramework.Packaging; @@ -308,8 +307,8 @@ internal static string GetCreator(NetInfo network) /// /// Slope parent dictionary. /// Elevated parent dictionary. - /// Brige parent dictionary. - /// Tunnel arent dictionary. + /// Bridge parent dictionary. + /// Tunnel parent dictionary. internal static void GetParents(Dictionary slopeParents, Dictionary elevatedParents, Dictionary bridgeParents, Dictionary tunnelParents) { // Iterate through all loaded net prefabs. @@ -404,7 +403,7 @@ internal static string GetDisplayName(PrefabInfo prefab) /// Parent prefab. private static void RecordParent(Dictionary dictionary, NetInfo child, NetInfo parent) { - // Null checks - child is routine, but the othes shouldn't be. + // Null checks - child is routine, but the others shouldn't be. if (child == null || parent == null || dictionary == null) { return;