Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Lane Arrows Buttons #387

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added TLM/TLM/Resources/TurnSigns/ButtonF.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TLM/TLM/Resources/TurnSigns/ButtonFGray.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TLM/TLM/Resources/TurnSigns/ButtonL.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TLM/TLM/Resources/TurnSigns/ButtonLGray.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TLM/TLM/Resources/TurnSigns/ButtonR.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TLM/TLM/Resources/TurnSigns/ButtonRGray.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions TLM/TLM/TLM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,16 @@
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.2\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" />
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.2\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\TurnSigns\ButtonF.png" />
<EmbeddedResource Include="Resources\TurnSigns\ButtonL.png" />
<EmbeddedResource Include="Resources\TurnSigns\ButtonR.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\TurnSigns\ButtonFGray.png" />
<EmbeddedResource Include="Resources\TurnSigns\ButtonLGray.png" />
<EmbeddedResource Include="Resources\TurnSigns\ButtonRGray.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>mkdir "$(LOCALAPPDATA)\Colossal Order\Cities_Skylines\Addons\Mods\$(TargetName)"
Expand Down
103 changes: 78 additions & 25 deletions TLM/TLM/UI/SubTools/LaneArrowTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@

namespace TrafficManager.UI.SubTools {
public class LaneArrowTool : SubTool {
/// <summary>
/// Arrow sign bits are combined together to find index in turn arrow textures
/// located in TextureResources.TurnSignTextures.
/// </summary>
public const int SIGN_BIT_LEFT = 1;
public const int SIGN_BIT_FORWARD = 2;
public const int SIGN_BIT_RIGHT = 4;

/// <summary>Size for white turn sign in the GUI</summary>
private const float BUTTON_GUI_SCALE = 50f;

/// <summary>
/// Sum of widths of GUI elements for 1 lane.
/// NOTE this also adds spacing between lane columns.
/// </summary>
private const float LANE_GUI_WIDTH = BUTTON_GUI_SCALE * 1.33f + LANE_LABEL_OFFSET_X;
private const float GUI_HEIGHT = 24f + BUTTON_GUI_SCALE * 1.66f; // label size + buttons

/// <summary>The horizontal offset for "Lane #" text in each column</summary>
private const float LANE_LABEL_OFFSET_X = 36f;

private bool _cursorInSecondaryPanel;

public LaneArrowTool(TrafficManagerTool mainTool) : base(mainTool) {
Expand All @@ -30,15 +51,20 @@ public class LaneArrowTool : SubTool {
}

public override void OnPrimaryClickOverlay() {
if (HoveredNodeId == 0 || HoveredSegmentId == 0) return;
if (HoveredNodeId == 0 || HoveredSegmentId == 0) {
return;
}

var netFlags = Singleton<NetManager>.instance.m_nodes.m_buffer[HoveredNodeId].m_flags;
if ((netFlags & NetNode.Flags.Junction) == NetNode.Flags.None) {
return;
}

if ((netFlags & NetNode.Flags.Junction) == NetNode.Flags.None) return;

if (Singleton<NetManager>.instance.m_segments.m_buffer[HoveredSegmentId].m_startNode != HoveredNodeId &&
Singleton<NetManager>.instance.m_segments.m_buffer[HoveredSegmentId].m_endNode != HoveredNodeId)
var hoveredSegment = Singleton<NetManager>.instance.m_segments.m_buffer[HoveredSegmentId];
if (hoveredSegment.m_startNode != HoveredNodeId &&
hoveredSegment.m_endNode != HoveredNodeId) {
return;
}

SelectedSegmentId = HoveredSegmentId;
SelectedNodeId = HoveredNodeId;
Expand Down Expand Up @@ -79,16 +105,19 @@ public class LaneArrowTool : SubTool {
if (diff.magnitude > TrafficManagerTool.MaxOverlayDistance)
return; // do not draw if too distant

int width = numLanes * 128;
var windowRect3 = new Rect(screenPos.x - width / 2, screenPos.y - 70, width, 50);
GUILayout.Window(250, windowRect3, _guiLaneChangeWindow, "", BorderlessStyle);
_cursorInSecondaryPanel = windowRect3.Contains(Event.current.mousePosition);
int width = numLanes * (int)LANE_GUI_WIDTH;
var proposedWindowRect = new Rect(screenPos.x - width / 2, screenPos.y - 70, width, GUI_HEIGHT);
var actualWindowRect = GUILayout.Window(250, proposedWindowRect, _guiLaneChangeWindow, "", BorderlessStyle);
_cursorInSecondaryPanel = actualWindowRect.Contains(Event.current.mousePosition);
}

public override void RenderOverlay(RenderManager.CameraInfo cameraInfo) {
NetManager netManager = Singleton<NetManager>.instance;
//Log._Debug($"LaneArrow Overlay: {HoveredNodeId} {HoveredSegmentId} {SelectedNodeId} {SelectedSegmentId}");
if (!_cursorInSecondaryPanel && HoveredSegmentId != 0 && HoveredNodeId != 0 && (HoveredSegmentId != SelectedSegmentId || HoveredNodeId != SelectedNodeId)) {
if (!_cursorInSecondaryPanel
&& HoveredSegmentId != 0
&& HoveredNodeId != 0
&& (HoveredSegmentId != SelectedSegmentId || HoveredNodeId != SelectedNodeId)) {
var nodeFlags = netManager.m_nodes.m_buffer[HoveredNodeId].m_flags;

if ((netManager.m_segments.m_buffer[HoveredSegmentId].m_startNode == HoveredNodeId || netManager.m_segments.m_buffer[HoveredSegmentId].m_endNode == HoveredNodeId) && (nodeFlags & NetNode.Flags.Junction) != NetNode.Flags.None) {
Expand Down Expand Up @@ -118,42 +147,67 @@ public class LaneArrowTool : SubTool {
for (var i = 0; i < laneList.Count; i++) {
var flags = (NetLane.Flags)Singleton<NetManager>.instance.m_lanes.m_buffer[laneList[i].laneId].m_flags;

var style1 = new GUIStyle("button");
var style2 = new GUIStyle("button") {
normal = { textColor = new Color32(255, 0, 0, 255) },
hover = { textColor = new Color32(255, 0, 0, 255) },
focused = { textColor = new Color32(255, 0, 0, 255) }
};

var laneStyle = new GUIStyle { contentOffset = new Vector2(12f, 0f) };

var laneTitleStyle = new GUIStyle {
contentOffset = new Vector2(36f, 2f),
contentOffset = new Vector2(LANE_LABEL_OFFSET_X, 2f),
normal = { textColor = new Color(1f, 1f, 1f) }
};

GUILayout.BeginVertical(laneStyle);
GUILayout.Label(Translation.GetString("Lane") + " " + (i + 1), laneTitleStyle);

//----------------------
// Button group
//----------------------
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (!Flags.applyLaneArrowFlags(laneList[i].laneId)) {
Flags.removeLaneArrowFlags(laneList[i].laneId);
}
Flags.LaneArrowChangeResult res = Flags.LaneArrowChangeResult.Invalid;

bool buttonClicked = false;
if (GUILayout.Button("←", ((flags & NetLane.Flags.Left) == NetLane.Flags.Left ? style1 : style2), GUILayout.Width(35), GUILayout.Height(25))) {
var isLeft = (flags & NetLane.Flags.Left) == NetLane.Flags.Left;
var isForward = (flags & NetLane.Flags.Forward) == NetLane.Flags.Forward;
var isRight = (flags & NetLane.Flags.Right) == NetLane.Flags.Right;

if (GUILayout.Button(isForward ? TextureResources.TurnButtonForward : TextureResources.TurnButtonForwardGray,
GUILayout.Width(BUTTON_GUI_SCALE * 1.33f),
GUILayout.Height(BUTTON_GUI_SCALE * 0.66f))) {
buttonClicked = true;
LaneArrowManager.Instance.ToggleLaneArrows(laneList[i].laneId, startNode, Flags.LaneArrows.Left, out res);
LaneArrowManager.Instance.ToggleLaneArrows(laneList[i].laneId, startNode,
Flags.LaneArrows.Forward, out res);
}
if (GUILayout.Button("↑", ((flags & NetLane.Flags.Forward) == NetLane.Flags.Forward ? style1 : style2), GUILayout.Width(25), GUILayout.Height(35))) {
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();

//----------------------
// Arrow sign row
//----------------------
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button(isLeft ? TextureResources.TurnButtonLeft : TextureResources.TurnButtonLeftGray,
GUILayout.Width(BUTTON_GUI_SCALE * 0.66f),
GUILayout.Height(BUTTON_GUI_SCALE))) {
buttonClicked = true;
LaneArrowManager.Instance.ToggleLaneArrows(laneList[i].laneId, startNode, Flags.LaneArrows.Forward, out res);
LaneArrowManager.Instance.ToggleLaneArrows(laneList[i].laneId, startNode,
Flags.LaneArrows.Left, out res);
}
if (GUILayout.Button("→", ((flags & NetLane.Flags.Right) == NetLane.Flags.Right ? style1 : style2), GUILayout.Width(35), GUILayout.Height(25))) {
if (GUILayout.Button(isRight ? TextureResources.TurnButtonRight : TextureResources.TurnButtonRightGray,
GUILayout.Width(BUTTON_GUI_SCALE * 0.66f),
GUILayout.Height(BUTTON_GUI_SCALE))) {
buttonClicked = true;
LaneArrowManager.Instance.ToggleLaneArrows(laneList[i].laneId, startNode, Flags.LaneArrows.Right, out res);
LaneArrowManager.Instance.ToggleLaneArrows(laneList[i].laneId, startNode,
Flags.LaneArrows.Right, out res);
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();

//----------------------
// Button click handling
//----------------------
if (buttonClicked) {
switch (res) {
case Flags.LaneArrowChangeResult.Invalid:
Expand All @@ -169,7 +223,6 @@ public class LaneArrowTool : SubTool {
}
}

GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUILayout.EndVertical();
}
Expand Down
20 changes: 18 additions & 2 deletions TLM/TLM/UI/TextureResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using TrafficManager.Manager.Impl;
using TrafficManager.Traffic;
using TrafficManager.UI;
using TrafficManager.UI.SubTools;
using TrafficManager.Util;
using UnityEngine;
using static TrafficManager.Traffic.Data.PrioritySegment;
Expand Down Expand Up @@ -42,6 +43,14 @@ public class TextureResources
public static readonly Texture2D PedestrianModeAutomaticTexture2D;
public static readonly Texture2D PedestrianModeManualTexture2D;
public static readonly IDictionary<PriorityType, Texture2D> PrioritySignTextures;
originalfoo marked this conversation as resolved.
Show resolved Hide resolved

public static readonly Texture2D TurnButtonLeft;
public static readonly Texture2D TurnButtonRight;
public static readonly Texture2D TurnButtonForward;
public static readonly Texture2D TurnButtonLeftGray;
public static readonly Texture2D TurnButtonRightGray;
public static readonly Texture2D TurnButtonForwardGray;

public static readonly Texture2D SignRemoveTexture2D;
public static readonly Texture2D ClockPlayTexture2D;
public static readonly Texture2D ClockPauseTexture2D;
Expand Down Expand Up @@ -123,7 +132,14 @@ static TextureResources()
PrioritySignTextures[PriorityType.Main] = LoadDllResource("sign_priority.png", 200, 200);
PrioritySignTextures[PriorityType.Stop] = LoadDllResource("sign_stop.png", 200, 200);
PrioritySignTextures[PriorityType.Yield] = LoadDllResource("sign_yield.png", 200, 200);


TurnButtonLeft = LoadDllResource("TurnSigns.ButtonL.png", 80, 127);
TurnButtonRight = LoadDllResource("TurnSigns.ButtonR.png", 80, 127);
TurnButtonForward = LoadDllResource("TurnSigns.ButtonF.png", 62, 62);
TurnButtonLeftGray = LoadDllResource("TurnSigns.ButtonLGray.png", 80, 127);
TurnButtonRightGray = LoadDllResource("TurnSigns.ButtonRGray.png", 80, 127);
TurnButtonForwardGray = LoadDllResource("TurnSigns.ButtonFGray.png", 62, 62);

// delete priority sign
SignRemoveTexture2D = LoadDllResource("remove_signs.png", 256, 256);

Expand Down Expand Up @@ -264,5 +280,5 @@ static byte[] ReadToEnd(Stream stream)
stream.Position = originalPosition;
}
}
}
}
}