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

Junction Lane Arrows Editor rework with preview #391

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
beb0abe
WIP experimental world space canvas
kvakvs Jun 23, 2019
5104c2f
UI creation in world space
kvakvs Jun 24, 2019
d136b7e
Buttons are now clickable, but no animations and no texture updates
kvakvs Jun 24, 2019
fd433a9
Fixed 'cursor in secondary panel' for nicer behaviour
kvakvs Jun 24, 2019
4f1ef13
Lane control buttons one per lane in the ground plane
kvakvs Jun 25, 2019
c1a1f87
Lane arrows look better and work
kvakvs Jun 26, 2019
c30a19e
For a single lane, open arrow buttons right away
kvakvs Jun 26, 2019
a3bdc6f
Calculate possible turn directions, and disable the lane arrow buttons
kvakvs Jun 26, 2019
186ea33
Better graphics for lane arrow buttons; Sprite handling improved; Ren…
kvakvs Jun 26, 2019
6a08ac7
Load and set shader (WIP)
kvakvs Jun 26, 2019
2e0f57b
Speed Limits textures into their own sub-struct in TextureResources
kvakvs Jun 27, 2019
99b4716
ESC hides the UI correctly
kvakvs Jun 27, 2019
026a041
Outgoing lanes are displayed in bright green
kvakvs Jun 28, 2019
5e2395f
Darker off arrows in lane arrows GUI
kvakvs Jul 2, 2019
5711587
Untabify, place texture loader and lane arrow tool into their own dirs
kvakvs Jul 2, 2019
3e0bdc5
Mass untabify for UI modules
kvakvs Jul 2, 2019
3069fb3
Detect inverted tangents and correct them for UI orientation
kvakvs Jul 2, 2019
f538338
Lane arrows now edit the whole junction
kvakvs Jul 4, 2019
07f7805
Lane Arrows tool has a state machine now and no buttons, click on the…
kvakvs Jul 6, 2019
7e59acb
Lane clicking works in Lane Arrows mode
kvakvs Jul 6, 2019
e25a66e
Accept other node click in Outgoing mode; Allow only segments which b…
kvakvs Jul 6, 2019
16c7e8f
Hovering a lane in incoming select mode, will show allowed turns as c…
kvakvs Jul 7, 2019
ce56049
Lane can be hovered only within 50m from its end; Correct unhovering
kvakvs Jul 7, 2019
8271c42
Moved SpeedLimits texture accessors into their texture class
kvakvs Jul 7, 2019
3610f0a
Using lane curves to display turns
kvakvs Jul 7, 2019
ba6228a
Use World helper more
kvakvs Jul 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion TLM/TLM/UI/IncompatibleModsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,11 @@ private void TryPopModal()

if (blurEffect != null && UIView.ModalInputCount() == 0)
{
ValueAnimator.Animate("ModalEffect", delegate (float val) { blurEffect.opacity = val; }, new AnimatedFloat(1f, 0f, 0.7f, EasingType.CubicEaseOut), delegate () { blurEffect.Hide(); });
ValueAnimator.Animate(
originalfoo marked this conversation as resolved.
Show resolved Hide resolved
"ModalEffect",
val => blurEffect.opacity = val,
new AnimatedFloat(1f, 0f, 0.7f, EasingType.CubicEaseOut),
() => blurEffect.Hide());
}
}
}
Expand Down
23 changes: 5 additions & 18 deletions TLM/TLM/UI/SubTools/LaneArrows/LaneArrowTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,6 @@ private void OnEnterState_OutgoingDirections() {
if (!Flags.applyLaneArrowFlags(SelectedLaneId)) {
Flags.removeLaneArrowFlags(SelectedLaneId);
}

// var segmentBuffer = Singleton<NetManager>.instance.m_segments.m_buffer;
// var segment = segmentBuffer[SelectedSegmentId];
// var otherNodeId = SelectedNodeId == segment.m_startNode
// ? segment.m_endNode : segment.m_startNode;
//
// outgoingLanes_ = new HashSet<uint>();
// foreach (var ln in GetIncomingLaneList(SelectedSegmentId, otherNodeId)) {
// outgoingLanes_.Add(ln.laneId);
// }
}

/// <summary>
Expand Down Expand Up @@ -200,11 +190,10 @@ private void Deselect() {
}

internal static IList<LanePos> GetIncomingLaneList(ushort segmentId, ushort nodeId) {
var segmentsBuffer = Singleton<NetManager>.instance.m_segments.m_buffer;
return Constants.ServiceFactory.NetService.GetSortedLanes(
segmentId,
ref segmentsBuffer[segmentId],
segmentsBuffer[segmentId].m_startNode == nodeId,
ref World.SegmentRef(segmentId),
World.Segment(segmentId).m_startNode == nodeId,
LaneArrowManager.LANE_TYPES,
LaneArrowManager.VEHICLE_TYPES,
true);
Expand All @@ -227,9 +216,8 @@ private OutgoingTurnsCollection GetOutgoingTurns(ushort nodeId, ushort ignoreSeg
return result;
}

var nodesBuffer = Singleton<NetManager>.instance.m_nodes.m_buffer;
var node = nodesBuffer[nodeId];
var incomingSegment = Singleton<NetManager>.instance.m_segments.m_buffer[ignoreSegmentId];
var node = World.Node(nodeId);
var incomingSegment = World.Segment(ignoreSegmentId);
var isStartNode = nodeId == incomingSegment.m_startNode;

for (var i = 0; i < MAX_NODE_SEGMENTS; ++i) {
Expand All @@ -256,8 +244,7 @@ private OutgoingTurnsCollection GetOutgoingTurns(ushort nodeId, ushort ignoreSeg
private HashSet<uint> GetAllIncomingLanes(ushort nodeId) {
var result = new HashSet<uint>();

var nodeBuffer = Singleton<NetManager>.instance.m_nodes.m_buffer;
var node = nodeBuffer[nodeId];
var node = World.Node(nodeId);

for (var i = 0; i < MAX_NODE_SEGMENTS; ++i) {
var connectedSegId = node.GetSegment(i);
Expand Down
3 changes: 1 addition & 2 deletions TLM/TLM/UI/SubTools/LaneArrows/LaneArrowTool_Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,12 @@ public override void RenderOverlay(RenderManager.CameraInfo cameraInfo) {
/// </summary>
/// <param name="cameraInfo">The camera</param>
private void RenderOverlay_NodeSelect(RenderManager.CameraInfo cameraInfo) {
var nodeBuffer = Singleton<NetManager>.instance.m_nodes.m_buffer;
RenderHoveredNode(cameraInfo);

// Draw the selected node
if (SelectedNodeId != 0) {
RenderNodeOverlay(cameraInfo,
ref nodeBuffer[SelectedNodeId],
ref World.NodeRef(SelectedNodeId),
PALETTE_SELECTED);
}
}
Expand Down
26 changes: 13 additions & 13 deletions TLM/TLM/UI/SubTools/SpeedLimitsTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,30 +114,29 @@ private void ShowSigns(bool viewOnly) {
Quaternion camRot = Camera.main.transform.rotation;
Vector3 camPos = Camera.main.transform.position;

NetManager netManager = Singleton<NetManager>.instance;
SpeedLimitManager speedLimitManager = SpeedLimitManager.Instance;

if (lastCamPos == null || lastCamRot == null || !lastCamRot.Equals(camRot) || !lastCamPos.Equals(camPos)) {
// cache visible segments
currentlyVisibleSegmentIds.Clear();

for (uint segmentId = 1; segmentId < NetManager.MAX_SEGMENT_COUNT; ++segmentId) {
if (!Constants.ServiceFactory.NetService.IsSegmentValid((ushort)segmentId)) {
for (ushort segmentId = 1; segmentId < NetManager.MAX_SEGMENT_COUNT; ++segmentId) {
if (!Constants.ServiceFactory.NetService.IsSegmentValid(segmentId)) {
continue;
}
/*if ((netManager.m_segments.m_buffer[segmentId].m_flags & NetSegment.Flags.Untouchable) != NetSegment.Flags.None)
continue;*/

if ((netManager.m_segments.m_buffer[segmentId].m_bounds.center - camPos).magnitude > TrafficManagerTool.MAX_OVERLAY_DISTANCE)
if ((World.Segment((ushort)segmentId).m_bounds.center - camPos).magnitude > TrafficManagerTool.MAX_OVERLAY_DISTANCE)
continue; // do not draw if too distant

Vector3 screenPos;
bool visible = MainTool.WorldToScreenPoint(netManager.m_segments.m_buffer[segmentId].m_bounds.center, out screenPos);
bool visible = MainTool.WorldToScreenPoint(World.Segment((ushort)segmentId).m_bounds.center, out screenPos);

if (! visible)
continue;

if (!speedLimitManager.MayHaveCustomSpeedLimits((ushort)segmentId, ref netManager.m_segments.m_buffer[segmentId]))
if (!speedLimitManager.MayHaveCustomSpeedLimits((ushort)segmentId, ref World.SegmentRef((ushort)segmentId)))
continue;

currentlyVisibleSegmentIds.Add((ushort)segmentId);
Expand All @@ -150,19 +149,21 @@ private void ShowSigns(bool viewOnly) {
bool handleHovered = false;
foreach (ushort segmentId in currentlyVisibleSegmentIds) {
Vector3 screenPos;
bool visible = MainTool.WorldToScreenPoint(netManager.m_segments.m_buffer[segmentId].m_bounds.center, out screenPos);
bool visible = MainTool.WorldToScreenPoint(World.Segment(segmentId).m_bounds.center, out screenPos);

if (!visible)
continue;

NetInfo segmentInfo = netManager.m_segments.m_buffer[segmentId].Info;
NetInfo segmentInfo = World.Segment(segmentId).Info;

// draw speed limits
if (MainTool.GetToolMode() != ToolMode.VehicleRestrictions || segmentId != SelectedSegmentId) { // no speed limit overlay on selected segment when in vehicle restrictions mode
if (drawSpeedLimitHandles((ushort)segmentId, ref netManager.m_segments.m_buffer[segmentId], viewOnly, ref camPos))
if (drawSpeedLimitHandles(segmentId, ref World.SegmentRef(segmentId), viewOnly, ref camPos)) {
handleHovered = true;
}
}
}

overlayHandleHovered = handleHovered;
}

Expand Down Expand Up @@ -462,7 +463,6 @@ private bool drawSpeedLimitHandles(ushort segmentId, ref NetSegment segment, boo
}

var center = segment.m_bounds.center;
var netManager = Singleton<NetManager>.instance;

var hovered = false;
var speedLimitToSet = viewOnly ? -1f : currentPaletteSpeedLimit;
Expand Down Expand Up @@ -611,7 +611,7 @@ private bool drawSpeedLimitHandles(ushort segmentId, ref NetSegment segment, boo
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) {

NetInfo.Direction normDir = e.Key;
if ((netManager.m_segments.m_buffer[segmentId].m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None) {
if ((World.Segment(segmentId).m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None) {
normDir = NetInfo.InvertDirection(normDir);
}

Expand All @@ -622,13 +622,13 @@ private bool drawSpeedLimitHandles(ushort segmentId, ref NetSegment segment, boo
bool reverse = data.segVisitData.viaStartNode == data.segVisitData.viaInitialStartNode;

ushort otherSegmentId = data.segVisitData.curGeo.SegmentId;
NetInfo otherSegmentInfo = netManager.m_segments.m_buffer[otherSegmentId].Info;
NetInfo otherSegmentInfo = World.Segment(otherSegmentId).Info;
uint laneId = data.curLanePos.laneId;
byte laneIndex = data.curLanePos.laneIndex;
NetInfo.Lane laneInfo = otherSegmentInfo.m_lanes[laneIndex];

NetInfo.Direction otherNormDir = laneInfo.m_finalDirection;
if ((netManager.m_segments.m_buffer[otherSegmentId].m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None ^
if ((World.Segment(otherSegmentId).m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None ^
reverse) {
otherNormDir = NetInfo.InvertDirection(otherNormDir);
}
Expand Down
14 changes: 6 additions & 8 deletions TLM/TLM/Util/GenericFsm.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace TrafficManager.Util {
using System;
using System.Collections.Generic;
using CSUtil.Commons;

/// <summary>
/// A finite state machine
Expand All @@ -18,7 +17,7 @@ public GenericFsm(TState state) {
transitions_ = new Dictionary<TState, Dictionary<TTrigger, TState>>();
enterStateEvents_ = new Dictionary<TState, Action>();
State = state;
Log._Debug($"FSM: Created with state {state}");
// Log._Debug($"FSM: Created with state {state}");
}

/// <summary>
Expand Down Expand Up @@ -85,20 +84,19 @@ public Configurator Configure(TState state) {
/// <returns>Whether state change succeeded</returns>
public bool SendTrigger(TTrigger trigger) {
if (!transitions_.ContainsKey(State)) {
Log._Debug($"FSM: Can't leave state {State} with {trigger} - " +
"no transitions defined for it");
// Log._Debug($"FSM: Can't leave state {State} with {trigger} - " +
// "no transitions defined for it");
return false;
}

var outTransitions = transitions_[State];
if (!outTransitions.ContainsKey(trigger)) {
Log._Debug($"FSM: Can't leave state {State} with {trigger} - " +
"the trigger is not accepted in this state");
// Log._Debug($"FSM: Can't leave state {State} with {trigger} - " +
// "the trigger is not accepted in this state");
return false;
}

// TODO: Callback on leave state
Log._Debug($"FSM: State changed {State} -> ({trigger}) -> {outTransitions[trigger]}");
// Log._Debug($"FSM: State changed {State} -> ({trigger}) -> {outTransitions[trigger]}");
State = outTransitions[trigger];

// Callback on enter state
Expand Down
12 changes: 12 additions & 0 deletions TLM/TLM/Util/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ public static NetSegment Segment(ushort index) {
return segmentBuffer_[index];
}

/// <summary>
/// Returns ref to world segment, use where `ref segments[index]` is needed.
/// </summary>
/// <param name="index">Segment index</param>
/// <returns>Reference to the segment</returns>
public static ref NetSegment SegmentRef(ushort index) {
#if DEBUG
Debug.Assert(Constants.ServiceFactory.NetService.IsSegmentValid(index));
#endif
return ref segmentBuffer_[index];
}

public static NetNode Node(ushort index) {
#if DEBUG
Debug.Assert(Constants.ServiceFactory.NetService.IsNodeValid(index));
Expand Down