Skip to content

Commit

Permalink
Merge pull request #86 from ST-Apps/dev
Browse files Browse the repository at this point in the history
Release 2.0.1
  • Loading branch information
ST-Apps authored Apr 28, 2020
2 parents 4750b76 + 1bfa4be commit 0271fac
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 26 deletions.
11 changes: 3 additions & 8 deletions Docs/workshop/Beta/description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
13 changes: 5 additions & 8 deletions Docs/workshop/Stable/description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
11 changes: 11 additions & 0 deletions ParallelRoadTool/Detours/NetManagerDetour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParallelRoadTool>.instance.IsMouseLongPress
&& ToolsModifierControl.GetTool<NetTool>().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;

Expand Down
2 changes: 1 addition & 1 deletion ParallelRoadTool/ModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down
6 changes: 6 additions & 0 deletions ParallelRoadTool/ParallelRoadTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public class ParallelRoadTool : MonoBehaviour
/// </summary>
public bool IsLeftHandTraffic { get; private set; }

/// <summary>
/// True if we detect a mouse long press, needed to prevent multiple updates when Anarchy is on.
/// HACK - [ISSUE-84]
/// </summary>
public bool IsMouseLongPress { get; set; }

/// <summary>
/// True only if <see cref="AppMode" /> is <see cref="AppMode.Game" />.
/// </summary>
Expand Down
59 changes: 50 additions & 9 deletions ParallelRoadTool/UI/UIMainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class UIMainWindow : UIPanel
private UITextField _dropdownFilterField;
private UIButton _loadPresetsButton;
private UIButton _savePresetsButton;
private UIButton _closeButton;

#endregion

Expand Down Expand Up @@ -91,6 +92,8 @@ private void UnsubscribeFromUIEvents()

_loadPresetsButton.eventClicked -= LoadPresetsButtonOnClicked;
_savePresetsButton.eventClicked -= SavePresetsButtonOnClicked;

_closeButton.eventClicked -= CloseButtonOneventClicked;
}

private void SubscribeToUIEvents()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -308,18 +326,28 @@ public override void Start()
bg.autoLayoutDirection = LayoutDirection.Vertical;
bg.autoFitChildrenVertically = true;

var label = bg.AddUIComponent<UILabel>();
var topPanel = bg.AddUIComponent<UIPanel>();
topPanel.size = new Vector2(500, 28);
topPanel.padding = new RectOffset(8, 8, 8, 8);

var label = topPanel.AddUIComponent<UILabel>();
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<UIDragHandle>();
_closeButton = topPanel.AddUIComponent<UIButton>();
_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<UIDragHandle>();
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;
Expand Down Expand Up @@ -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<ParallelRoadTool>.instance.IsMouseLongPress = e.type switch
{
EventType.MouseDown => true,
EventType.MouseUp => false,
_ => Singleton<ParallelRoadTool>.instance.IsMouseLongPress
};

Log._Debug($"[{nameof(UIMainWindow)}.{nameof(OnGUI)}] Settings {nameof(Singleton<ParallelRoadTool>.instance.IsMouseLongPress)} to {Singleton<ParallelRoadTool>.instance.IsMouseLongPress}");
}

// Checking key presses
if (OptionsKeymapping.ToggleParallelRoads.IsPressed(e)) ToggleToolCheckbox();

Expand Down

0 comments on commit 0271fac

Please sign in to comment.