diff --git a/Docs/workshop/Beta/description.txt b/Docs/workshop/Beta/description.txt index 623ea51..2451f70 100644 --- a/Docs/workshop/Beta/description.txt +++ b/Docs/workshop/Beta/description.txt @@ -15,15 +15,10 @@ Main features are: [/quote] [quote] -[h1]Current version: [b]2.0.0-dev[/b] [url=http://steamcommunity.com/sharedfiles/filedetails/changelog/1400711138]Changelog[/url], [url=https://github.com/ST-Apps/CS-ParallelRoadTool]Source code[/url][/h1] +[h1]Current version: [b]2.0.1-dev[/b] [url=http://steamcommunity.com/sharedfiles/filedetails/changelog/1400711138]Changelog[/url], [url=https://github.com/ST-Apps/CS-ParallelRoadTool]Source code[/url][/h1] [list] -[*] Enabled tool while in upgrade mode so that you can add parallel/stacked segments to already existing networks -[*] Added ability to save/load presets -[*] Added search feature -[*] [b]Networks can now be built only after being unlocked (You can still build them all from the beginning if you have the Unlock All Milestones mod active)[/b] -[*] [b]Added cost for parallel/stacked segments[/b] -[*] [b]Increased dropdown size for better readability[/b] -[*] Minor performances fixes +[*] Fixed an issue with Anarchy that caused multiple roads updates while keeping mouse pressed +[*] Added a panic X button to close mod's window when other methods do not work [/list] [/quote] diff --git a/Docs/workshop/Stable/description.txt b/Docs/workshop/Stable/description.txt index 9f9271f..daab5b0 100644 --- a/Docs/workshop/Stable/description.txt +++ b/Docs/workshop/Stable/description.txt @@ -6,21 +6,18 @@ Main features are: [*] [b]Visual overlay guidelines[/b] to help you visualizing what you're going to build before actually building [*] [b]One-way networks support[/b]: you can reverse the direction of any one-way network, so that [b]you can easily build highways without needing to manually upgrade direction later[/b] [*] Left-hand drive support +[*] [b]Upgrade mode: you can add parallel/stacked segments to already existing networks[/b] +[*] [b]Save/load presets[/b] [/list] [h1]For new features and/or debugging, you can subscribe to the [url=https://steamcommunity.com/sharedfiles/filedetails/?id=1400711138]beta version[/url][/h1] [b]Tested on C:S version 1.13.0-f8[/b] [quote] -[h1]Current version: [b]2.0.0[/b] [url=http://steamcommunity.com/sharedfiles/filedetails/changelog/1440928803]Changelog[/url], [url=https://github.com/ST-Apps/CS-ParallelRoadTool]Source code[/url][/h1] +[h1]Current version: [b]2.0.1[/b] [url=http://steamcommunity.com/sharedfiles/filedetails/changelog/1440928803]Changelog[/url], [url=https://github.com/ST-Apps/CS-ParallelRoadTool]Source code[/url][/h1] [list] -[*] Enabled tool while in upgrade mode so that you can add parallel/stacked segments to already existing networks -[*] Added ability to save/load presets -[*] Added search feature -[*] [b]Networks can now be built only after being unlocked (You can still build them all from the beginning if you have the Unlock All Milestones mod active)[/b] -[*] [b]Added cost for parallel/stacked segments[/b] -[*] [b]Increased dropdown size for better readability[/b] -[*] Minor performances fixes +[*] Fixed an issue with Anarchy that caused multiple roads updates while keeping mouse pressed +[*] Added a panic X button to close mod's window when other methods do not work [/list] [/quote] diff --git a/ParallelRoadTool/Detours/NetManagerDetour.cs b/ParallelRoadTool/Detours/NetManagerDetour.cs index 9556622..4f8f111 100644 --- a/ParallelRoadTool/Detours/NetManagerDetour.cs +++ b/ParallelRoadTool/Detours/NetManagerDetour.cs @@ -237,6 +237,17 @@ private bool CreateSegment(out ushort segment, var result = NetManager.instance.CreateSegment(out segment, ref randomizer, info, startNode, endNode, startDirection, endDirection, buildIndex, modifiedIndex, invert); + if (Singleton.instance.IsMouseLongPress + && ToolsModifierControl.GetTool().m_mode == NetTool.Mode.Upgrade + && startNode == _startNodeId[0] + && endNode == _endNodeId[0]) + { + // HACK - [ISSUE-84] Prevent executing multiple times when we have a long mouse press on the very same segment + Log._Debug($"[{nameof(NetManagerDetour)}.{nameof(CreateSegment)}] Skipping because mouse has not been released yet from the previous upgrade."); + + return result; + } + // HACK - [ISSUE-10] [ISSUE-18] Check if we've been called by an allowed caller, otherwise we can stop here if (!IsAllowedCaller(new StackTrace(false))) return result; diff --git a/ParallelRoadTool/ModInfo.cs b/ParallelRoadTool/ModInfo.cs index 69218eb..fad246e 100644 --- a/ParallelRoadTool/ModInfo.cs +++ b/ParallelRoadTool/ModInfo.cs @@ -10,7 +10,7 @@ namespace ParallelRoadTool { public class ModInfo : IUserMod { - private const string Version = "2.0.0"; + private const string Version = "2.0.1"; #if DEBUG private const string Branch = "dev"; public static readonly string ModName = $"[BETA] Parallel Road Tool {Version}-{Branch}"; diff --git a/ParallelRoadTool/ParallelRoadTool.cs b/ParallelRoadTool/ParallelRoadTool.cs index eda2f58..5e7a073 100644 --- a/ParallelRoadTool/ParallelRoadTool.cs +++ b/ParallelRoadTool/ParallelRoadTool.cs @@ -53,6 +53,12 @@ public class ParallelRoadTool : MonoBehaviour /// public bool IsLeftHandTraffic { get; private set; } + /// + /// True if we detect a mouse long press, needed to prevent multiple updates when Anarchy is on. + /// HACK - [ISSUE-84] + /// + public bool IsMouseLongPress { get; set; } + /// /// True only if is . /// diff --git a/ParallelRoadTool/UI/UIMainWindow.cs b/ParallelRoadTool/UI/UIMainWindow.cs index 48e3458..b0af4b3 100644 --- a/ParallelRoadTool/UI/UIMainWindow.cs +++ b/ParallelRoadTool/UI/UIMainWindow.cs @@ -59,6 +59,7 @@ public class UIMainWindow : UIPanel private UITextField _dropdownFilterField; private UIButton _loadPresetsButton; private UIButton _savePresetsButton; + private UIButton _closeButton; #endregion @@ -91,6 +92,8 @@ private void UnsubscribeFromUIEvents() _loadPresetsButton.eventClicked -= LoadPresetsButtonOnClicked; _savePresetsButton.eventClicked -= SavePresetsButtonOnClicked; + + _closeButton.eventClicked -= CloseButtonOneventClicked; } private void SubscribeToUIEvents() @@ -108,6 +111,13 @@ private void SubscribeToUIEvents() _loadPresetsButton.eventClicked += LoadPresetsButtonOnClicked; _savePresetsButton.eventClicked += SavePresetsButtonOnClicked; + + _closeButton.eventClicked += CloseButtonOneventClicked; + } + + private void CloseButtonOneventClicked(UIComponent component, UIMouseEventParameter eventparam) + { + ToggleToolCheckbox(true); } private void DropdownFilterFieldOnEventLostFocus(UIComponent component, UIFocusEventParameter eventparam) @@ -261,10 +271,18 @@ public void UpdateDropdowns() #region Utility - private void ToggleToolCheckbox() + private void ToggleToolCheckbox(bool forceClose = false) { - _toolToggleButton.isChecked = !_toolToggleButton.isChecked; - OnParallelToolToggled?.Invoke(_toolToggleButton, _toolToggleButton.isChecked); + if (forceClose) + { + _toolToggleButton.isChecked = false; + OnParallelToolToggled?.Invoke(_toolToggleButton, _toolToggleButton.isChecked); + } + else + { + _toolToggleButton.isChecked = !_toolToggleButton.isChecked; + OnParallelToolToggled?.Invoke(_toolToggleButton, _toolToggleButton.isChecked); + } } private void AdjustNetOffset(float step, bool isHorizontal = true) @@ -308,18 +326,28 @@ public override void Start() bg.autoLayoutDirection = LayoutDirection.Vertical; bg.autoFitChildrenVertically = true; - var label = bg.AddUIComponent(); + var topPanel = bg.AddUIComponent(); + topPanel.size = new Vector2(500, 28); + topPanel.padding = new RectOffset(8, 8, 8, 8); + + var label = topPanel.AddUIComponent(); label.name = $"{Configuration.ResourcePrefix}TitleLabel"; - label.textScale = 0.9f; label.text = ModInfo.ModName; - label.autoSize = false; - label.width = 500; + label.relativePosition = Vector2.zero; label.SendToBack(); - var dragHandle = label.AddUIComponent(); + _closeButton = topPanel.AddUIComponent(); + _closeButton.text = ""; + _closeButton.normalBgSprite = "buttonclose"; + _closeButton.hoveredBgSprite = "buttonclosehover"; + _closeButton.pressedBgSprite = "buttonclosepressed"; + _closeButton.size = new Vector2(32, 32); + _closeButton.relativePosition = new Vector3(width - 44, -8); + + var dragHandle = topPanel.AddUIComponent(); dragHandle.target = this; dragHandle.relativePosition = Vector3.zero; - dragHandle.size = label.size; + dragHandle.size = topPanel.size - new Vector2(60, 0); _mainPanel = bg.AddUIComponent(typeof(UIOptionsPanel)) as UIOptionsPanel; _netList = bg.AddUIComponent(typeof(UINetList)) as UINetList; @@ -436,6 +464,19 @@ public void OnGUI() var e = Event.current; + if (e.isMouse) + { + // HACK - [ISSUE-84] Report if we're currently having a long mouse press + Singleton.instance.IsMouseLongPress = e.type switch + { + EventType.MouseDown => true, + EventType.MouseUp => false, + _ => Singleton.instance.IsMouseLongPress + }; + + Log._Debug($"[{nameof(UIMainWindow)}.{nameof(OnGUI)}] Settings {nameof(Singleton.instance.IsMouseLongPress)} to {Singleton.instance.IsMouseLongPress}"); + } + // Checking key presses if (OptionsKeymapping.ToggleParallelRoads.IsPressed(e)) ToggleToolCheckbox();