diff --git a/PedestrianBridge/KianCommons b/PedestrianBridge/KianCommons index 717fb29..2e885d7 160000 --- a/PedestrianBridge/KianCommons +++ b/PedestrianBridge/KianCommons @@ -1 +1 @@ -Subproject commit 717fb29885a775370e40e88aec9b0b445f1c64c2 +Subproject commit 2e885d7ce71f6ec612bee0f79dc922f332ea987f diff --git a/PedestrianBridge/PedestrianBridge.csproj b/PedestrianBridge/PedestrianBridge.csproj index 528ed35..da3628b 100644 --- a/PedestrianBridge/PedestrianBridge.csproj +++ b/PedestrianBridge/PedestrianBridge.csproj @@ -93,6 +93,7 @@ + @@ -102,12 +103,16 @@ + + + + - - + + diff --git a/PedestrianBridge/Shapes/Netwrapper/NodeWrapper.cs b/PedestrianBridge/Shapes/Netwrapper/NodeWrapper.cs index 3a84885..92e5821 100644 --- a/PedestrianBridge/Shapes/Netwrapper/NodeWrapper.cs +++ b/PedestrianBridge/Shapes/Netwrapper/NodeWrapper.cs @@ -1,11 +1,9 @@ using KianCommons; using KianCommons.Math; -using PedestrianBridge.Util; using System; using UnityEngine; -using static KianCommons.HelpersExtensions; +using static KianCommons.Assertion; using static KianCommons.NetUtil; -using static PedestrianBridge.Util.PrefabUtil; namespace PedestrianBridge.Shapes { public class NodeWrapper { @@ -40,7 +38,7 @@ void _Create() { } static ushort CreateNode(Vector3 position, NetInfo info) { - HelpersExtensions.AssertNotNull(info, "info"); + AssertNotNull(info, "info"); Log.Info($"creating node for {info.name} at position {position.ToString("000.000")}"); bool res = netMan.CreateNode(node: out ushort nodeID, randomizer: ref simMan.m_randomizer, info: info, position: position, buildIndex: simMan.m_currentBuildIndex); diff --git a/PedestrianBridge/Shapes/Netwrapper/SegmentWrapper.cs b/PedestrianBridge/Shapes/Netwrapper/SegmentWrapper.cs index e81dabf..1937f57 100644 --- a/PedestrianBridge/Shapes/Netwrapper/SegmentWrapper.cs +++ b/PedestrianBridge/Shapes/Netwrapper/SegmentWrapper.cs @@ -3,6 +3,7 @@ using System; using UnityEngine; using static KianCommons.NetUtil; +using static KianCommons.Assertion; namespace PedestrianBridge.Shapes { public class SegmentWrapper { @@ -94,7 +95,7 @@ public static void LogSegmentDetails(ushort segmentID) { private NetInfo GetFinalNetInfo() { int e1 = StartNode.elevation; int e2 = EndNode.elevation; - HelpersExtensions.Assert(!(e1 == 0 && e2 < 0), "Underground road is oppostie way arround"); + Assert(!(e1 == 0 && e2 < 0), "Underground road is oppostie way arround"); int nElevated = 0; if (e1 != 0) nElevated++; if (e2 != 0) nElevated++; diff --git a/PedestrianBridge/Shapes/Roundabout/RaboutSlice.cs b/PedestrianBridge/Shapes/Roundabout/RaboutSlice.cs index 0f2af5a..3c38a3d 100644 --- a/PedestrianBridge/Shapes/Roundabout/RaboutSlice.cs +++ b/PedestrianBridge/Shapes/Roundabout/RaboutSlice.cs @@ -11,6 +11,7 @@ namespace PedestrianBridge.Shapes { using static KianCommons.Math.VectorUtil; using System.Collections.Generic; using System.Linq; + using static KianCommons.Assertion; public class RaboutSlice { public struct Corner { @@ -75,7 +76,7 @@ static bool IsIntersectionOnGround(ushort segmentID1, ushort segmentID2) { bool IsBetweenInOut( ushort segmentID1Main, ushort segmentID1Minor, ushort segmentID2Main, ushort segmentID2Minor) { - KianCommons.HelpersExtensions.AssertStack(); + AssertStack(); const float maxLen = 7 * MPU; bool bShort = (corner1.Point - corner2.Point).sqrMagnitude <= maxLen * maxLen; if (!bShort) { @@ -127,8 +128,8 @@ public static ushort GetClosestSegment(Vector2 point, IEnumerable segmen } public static Vector2 MirrorPoint(Vector2 point, IEnumerable segmentList) { - HelpersExtensions.AssertNotNull(segmentList, "segmentList"); - HelpersExtensions.Assert(segmentList.Count() > 0, "segmentList.Count()>0"); + AssertNotNull(segmentList, "segmentList"); + Assert(segmentList.Count() > 0, "segmentList.Count()>0"); ushort closestSegmentID = GetClosestSegment(point, segmentList, out Vector3 hitpos); if (closestSegmentID != 0) { var diff = hitpos.ToCS2D() - point; diff --git a/PedestrianBridge/UI/ControlPanel/ElevationSlider.cs b/PedestrianBridge/UI/ControlPanel/ElevationSlider.cs index 4dc4dba..706c0d1 100644 --- a/PedestrianBridge/UI/ControlPanel/ElevationSlider.cs +++ b/PedestrianBridge/UI/ControlPanel/ElevationSlider.cs @@ -1,9 +1,6 @@ using ColossalFramework.UI; -using ICities; -using KianCommons; using KianCommons.UI; using System; -using System.Reflection.Emit; using UnityEngine; namespace PedestrianBridge.UI.ControlPanel { @@ -25,7 +22,7 @@ public override void Start() { started_ = true; } - const int low = 9; + const int low = 3; const int high = 30; const int diff = high - low; public float LinearValue { diff --git a/PedestrianBridge/UI/ControlPanel/UnderpassCheckbox.cs b/PedestrianBridge/UI/ControlPanel/UnderpassCheckbox.cs index 79700df..2363d13 100644 --- a/PedestrianBridge/UI/ControlPanel/UnderpassCheckbox.cs +++ b/PedestrianBridge/UI/ControlPanel/UnderpassCheckbox.cs @@ -14,11 +14,10 @@ public override void Start() { isChecked = ControlCenter.Underground; } - protected override void OnCheckChanged() { + public override void OnCheckChanged(UIComponent component, bool value) { + base.OnCheckChanged(component, value); ControlCenter.Underground = isChecked; - Invalidate(); ElevationSlider.Instance.Refresh(); } - } } diff --git a/PedestrianBridge/UI/PedestrianBridgeButton.cs b/PedestrianBridge/UI/PedestrianBridgeButton.cs index 98340a0..c039003 100644 --- a/PedestrianBridge/UI/PedestrianBridgeButton.cs +++ b/PedestrianBridge/UI/PedestrianBridgeButton.cs @@ -1,11 +1,9 @@ using ColossalFramework.UI; +using KianCommons; using PedestrianBridge.Tool; -using PedestrianBridge.Util; using System; using UnityEngine; -using static KianCommons.HelpersExtensions; -using KianCommons.UI; -using KianCommons; +using static KianCommons.Assertion; /* A lot of copy-pasting from Crossings mod by Spectra and Roundabout Mod by Strad. The sprites are partly copied as well. */ @@ -55,19 +53,19 @@ public override void Start() { this.atlas = atlas; normalBgSprite = focusedBgSprite = disabledBgSprite = PedestrianBridgeButtonBg; - hoveredBgSprite = PedestrianBridgeButtonBgHovered; - pressedBgSprite = PedestrianBridgeButtonBgPressed; + hoveredBgSprite = PedestrianBridgeButtonBgHovered; + pressedBgSprite = PedestrianBridgeButtonBgPressed; normalFgSprite = disabledFgSprite = hoveredFgSprite = pressedFgSprite = PedestrianBridgeIcon; focusedFgSprite = PedestrianBridgeIconPressed; - relativePosition = new Vector3(33, 38); + relativePosition = new Vector3(33, 38); size = new Vector2(SIZE, SIZE); Show(); Log.Info("PedestrianBridgeButton button created sucessfully."); } - public static UIButton CreateButton() { + public static UIButton CreateButton() { Log.Info("PedestrianBridgeButton.CreateButton() called"); return GetPanel().AddUIComponent(); } diff --git a/PedestrianBridge/Util/PrefabUtil.cs b/PedestrianBridge/Util/PrefabUtil.cs index d1e3be6..ca5312e 100644 --- a/PedestrianBridge/Util/PrefabUtil.cs +++ b/PedestrianBridge/Util/PrefabUtil.cs @@ -87,7 +87,7 @@ public static NetInfo GetSlope(this NetInfo info) { public static int GetInfoPrioirty(NetInfo info, NetInfo baseInfo = null) { PedestrianPathAI baseAI = baseInfo?.m_netAI as PedestrianPathAI; - HelpersExtensions.AssertNotNull(baseAI, "baseAI"); + Assertion.AssertNotNull(baseAI, "baseAI"); if (info == baseAI.m_info) return 0; if (info == baseAI.m_elevatedInfo) return 1; if (info == baseAI.m_slopeInfo) return 1; diff --git a/PedestrianBridge/Util/RoundAboutUtil.cs b/PedestrianBridge/Util/RoundAboutUtil.cs index 5e800c5..5c47c74 100644 --- a/PedestrianBridge/Util/RoundAboutUtil.cs +++ b/PedestrianBridge/Util/RoundAboutUtil.cs @@ -1,5 +1,4 @@ namespace PedestrianBridge.Util { - using CSUtil.Commons; using System.Collections.Generic; using System; using System.Linq; @@ -10,6 +9,7 @@ namespace PedestrianBridge.Util { using static TMPEUtil; using ColossalFramework.Math; using Log = KianCommons.Log; + using KianCommons; public class RoundaboutUtil { public static RoundaboutUtil Instance_render = new RoundaboutUtil(); @@ -163,10 +163,18 @@ private bool TraverseAroundRecursive(ushort segmentId) { private static ushort GetNextSegment(ushort segmentID) { ushort headNodeId = GetHeadNode(segmentID); - ushort ret = GetCWSegList(headNodeId).Where( - nextSegmentID => IsPartofRoundabout(nextSegmentID, segmentID)). - FirstOrDefault(); - return ret; + for(int whatchdog=0; whatchdog < 8; ++ whatchdog) { + // get next inward segment: + ushort nextSegmentID = RHT + ? segmentID.ToSegment().GetLeftSegment(headNodeId) + : segmentID.ToSegment().GetRightSegment(headNodeId); + if (nextSegmentID == segmentID) + break; + if (IsPartofRoundabout(nextSegmentID, segmentID)) + return nextSegmentID; + } + + return 0; } ///