Skip to content

Commit

Permalink
Merged 'dev' into 'master'.
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-Apps committed Jul 14, 2018
2 parents ed6ddad + 3e9d7ee commit 3942c79
Show file tree
Hide file tree
Showing 50 changed files with 655 additions and 141 deletions.
21 changes: 14 additions & 7 deletions ParallelRoadTool/Detours/NetManagerDetour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public static int NetworksCount
{
set
{
// TODO: allow users to enable/disable this kind of snapping?
// We don't reset nodes arrays if size didn't change, this allows us to snap to previous nodes even after changing offsets.
if (_endNodeId != null && _endNodeId.Length == value) return;
_endNodeId = new ushort?[value];
_clonedEndNodeId = new ushort?[value];
_startNodeId = new ushort?[value];
Expand Down Expand Up @@ -94,17 +97,21 @@ private static NetNode CreateNode(out ushort newNodeId, ref Randomizer randomize
/// <param name="info"></param>
/// <param name="newNodePosition"></param>
/// <returns></returns>
private static ushort NodeAtPositionOrNew(ref Randomizer randomizer, NetInfo info, Vector3 newNodePosition)
private static ushort NodeAtPositionOrNew(ref Randomizer randomizer, NetInfo info, Vector3 newNodePosition, float verticalOffset)
{
var netManager = Singleton<NetManager>.instance;

// This should be the best possible value for snapping
var maxDistance = info.m_halfWidth;

DebugUtils.Log($"Trying to find an existing node at position {newNodePosition} with maxDistance = {maxDistance}");
DebugUtils.Log($"Trying to find an existing node at position {newNodePosition} (+- {verticalOffset}) with maxDistance = {maxDistance}");

if (ParallelRoadTool.Instance.IsSnappingEnabled &&
PathManager.FindPathPosition(newNodePosition, info.m_class.m_service, info.m_class.m_service, NetInfo.LaneType.All, VehicleInfo.VehicleType.All, VehicleInfo.VehicleType.All, true, false, maxDistance, out var posA, out var posB, out var sqrDistA, out var sqrDistB))
(PathManager.FindPathPosition(newNodePosition, info.m_class.m_service, info.m_class.m_service, NetInfo.LaneType.All, VehicleInfo.VehicleType.All, VehicleInfo.VehicleType.All, true, false, maxDistance, out var posA, out var posB, out var sqrDistA, out var sqrDistB) ||
PathManager.FindPathPosition(new Vector3(newNodePosition.x, newNodePosition.y - verticalOffset, newNodePosition.z), info.m_class.m_service, info.m_class.m_service, NetInfo.LaneType.All, VehicleInfo.VehicleType.All, VehicleInfo.VehicleType.All, true, false, maxDistance, out posA, out posB, out sqrDistA, out sqrDistB) ||
PathManager.FindPathPosition(new Vector3(newNodePosition.x, newNodePosition.y + verticalOffset, newNodePosition.z), info.m_class.m_service, info.m_class.m_service, NetInfo.LaneType.All, VehicleInfo.VehicleType.All, VehicleInfo.VehicleType.All, true, false, maxDistance, out posA, out posB, out sqrDistA, out sqrDistB)
)
)
{

DebugUtils.Log($"FindPathPosition worked with posA.segment = {posA.m_segment} and posB.segment = {posB.m_segment}");
Expand Down Expand Up @@ -254,7 +261,7 @@ private bool CreateSegment(out ushort segment, ref Randomizer randomizer, NetInf
// Get original nodes to clone them
var startNetNode = NetManager.instance.m_nodes.m_buffer[startNode];
var endNetNode = NetManager.instance.m_nodes.m_buffer[endNode];

// Create two clone nodes by offsetting the original ones.
// If we're not in "invert" mode (aka final part of a curve) and we already have an ending node with the same id of our starting node, we need to use that so that the segments can be connected.
// If the previous segment was in "invert" mode and the current startNode is the same as the previous one, we need to connect them.
Expand All @@ -266,7 +273,7 @@ private bool CreateSegment(out ushort segment, ref Randomizer randomizer, NetInf
$"[START] Using old node from previous iteration {_clonedEndNodeId[i].Value} instead of the given one {startNode}");
newStartNodeId = _clonedEndNodeId[i].Value;
DebugUtils.Log(
$"[START] Start node{startNetNode.m_position} becomes {NetManager.instance.m_nodes.m_buffer[newStartNodeId].m_position}");
$"[START] Start node {startNetNode.m_position} becomes {NetManager.instance.m_nodes.m_buffer[newStartNodeId].m_position}");
}
else if (!invert && _isPreviousInvert && _startNodeId[i].HasValue &&
_startNodeId[i].Value == startNode)
Expand All @@ -283,7 +290,7 @@ private bool CreateSegment(out ushort segment, ref Randomizer randomizer, NetInf
verticalOffset, invert);

DebugUtils.Log($"[START] {startNetNode.m_position} --> {newStartPosition} | isLeftHand = {ParallelRoadTool.Instance.IsLeftHandTraffic} | invert = {invert} | isSlope = {isSlope}");
newStartNodeId = NodeAtPositionOrNew(ref randomizer, info, newStartPosition);
newStartNodeId = NodeAtPositionOrNew(ref randomizer, info, newStartPosition, verticalOffset);
}

// Same thing as startNode, but this time we don't clone if we're in "invert" mode as we may need to connect this ending node with the previous ending one.
Expand All @@ -301,7 +308,7 @@ private bool CreateSegment(out ushort segment, ref Randomizer randomizer, NetInf
var newEndPosition = endNetNode.m_position.Offset(endDirection, horizontalOffset, verticalOffset, !(invert && isSlope && isEnteringSlope));

DebugUtils.Log($"[END] {endNetNode.m_position} --> {newEndPosition} | isEnteringSlope = {isEnteringSlope} | invert = {invert} | isSlope = {isSlope}");
newEndNodeId = NodeAtPositionOrNew(ref randomizer, info, newEndPosition);
newEndNodeId = NodeAtPositionOrNew(ref randomizer, info, newEndPosition, verticalOffset);
}

// Store current end nodes in case we may need to connect the following segment to them
Expand Down
101 changes: 101 additions & 0 deletions ParallelRoadTool/Extensions/LocaleManagerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using ColossalFramework.Globalization;
using ParallelRoadTool;
using ParallelRoadTool.Extensions.LocaleModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace ParallelRoadTool.Extensions
{
/// <summary>
/// <see cref="https://github.com/markusmitbrille/cities-skylines-custom-namelists/blob/master/CSLCNL/CSLCNL/LocaleManagerExtensions.cs"/>
/// </summary>
static class LocaleManagerExtensions
{
const string localeFieldName = "m_Locale";
const string localizedStringsFieldName = "m_LocalizedStrings";
const string localizedStringsCountFieldName = "m_LocalizedStringsCount";

static FieldInfo localeField = typeof(LocaleManager).GetField(localeFieldName, BindingFlags.Instance | BindingFlags.NonPublic);
static FieldInfo localizedStringsField = typeof(Locale).GetField(localizedStringsFieldName, BindingFlags.Instance | BindingFlags.NonPublic);
static FieldInfo localizedStringsCountField = typeof(Locale).GetField(localizedStringsCountFieldName, BindingFlags.Instance | BindingFlags.NonPublic);

public static Locale GetLocale(this LocaleManager localeManager)
{
return (Locale)localeField.GetValue(localeManager);
}

public static Dictionary<Locale.Key, string> GetLocalizedStrings(this Locale locale)
{
return (Dictionary<Locale.Key, string>)localizedStringsField.GetValue(locale);
}

public static Dictionary<Locale.Key, int> GetLocalizedStringsCount(this Locale locale)
{
return (Dictionary<Locale.Key, int>)localizedStringsCountField.GetValue(locale);
}

public static void RemoveRange(this LocaleManager localeManager, Locale.Key id)
{
Locale locale = localeManager.GetLocale();

// Set index to 0 so we can check for the string count
id.m_Index = 0;

if (!locale.Exists(id))
{
DebugUtils.Log($"Could not remove locale range {id}; localized string {id} does not exist!");
return;
}

Dictionary<Locale.Key, string> localizedStrings = locale.GetLocalizedStrings();
Dictionary<Locale.Key, int> localizedStringsCount = locale.GetLocalizedStringsCount();

for (int index = 0, lastIndex = locale.CountUnchecked(id); index <= lastIndex; index++, id.m_Index = index)
{
localizedStrings.Remove(id);
localizedStringsCount.Remove(id);
}

DebugUtils.Log($"Removed locale range {id.m_Identifier}[{id.m_Key}].");
}

public static void AddString(this LocaleManager localeManager, LocalizedString localizedString)
{
Locale locale = localeManager.GetLocale();

// Construct 0-index id for the localized string from argument
Locale.Key id;
id.m_Identifier = localizedString.Identifier;
id.m_Key = localizedString.Key;
id.m_Index = 0;

// Check if the id already exists; if so find next index
if (locale.Exists(id))
{
// Log message lags game on large namelists
// Log($"Localized string {localizedString.Identifier}[{localizedString.Key}] already exists, adding it with next available index.");
id.m_Index = locale.CountUnchecked(id);
}

// Add the localized string
locale.AddLocalizedString(id, localizedString.Value);

// Set the string counts accordingly
Dictionary<Locale.Key, int> localizedStringCounts = locale.GetLocalizedStringsCount();

// The count at the exact index appears to always be 0
localizedStringCounts[id] = 0;

// index = 0 appears to be a special case and indicates the count of localized strings with the same identifier and key
Locale.Key zeroIndexID = id;
zeroIndexID.m_Index = 0;
localizedStringCounts[zeroIndexID] = id.m_Index + 1;

// Log message lags game on large namelists
// Log($"Added localized string {id} = '{localizedString.Value}', count = {localizedStringCounts[zeroIndexID]}.");
}
}
}
21 changes: 21 additions & 0 deletions ParallelRoadTool/Extensions/LocaleModels/LocalizedString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace ParallelRoadTool.Extensions.LocaleModels
{
/// <summary>
/// <see cref="https://github.com/markusmitbrille/cities-skylines-custom-namelists/blob/master/CSLCNL/CSLCNL/LocalizedString.cs"/>
/// </summary>
public struct LocalizedString
{
[XmlAttribute(AttributeName = "identifier")]
public string Identifier;
[XmlAttribute(AttributeName = "key")]
public string Key;
[XmlText]
public string Value;
}
}
19 changes: 19 additions & 0 deletions ParallelRoadTool/Extensions/LocaleModels/LocalizedStringKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace ParallelRoadTool.Extensions.LocaleModels
{
/// <summary>
/// <see cref="https://github.com/markusmitbrille/cities-skylines-custom-namelists/blob/master/CSLCNL/CSLCNL/LocalizedStringKey.cs"/>
/// </summary>
public struct LocalizedStringKey
{
[XmlAttribute(AttributeName = "identifier")]
public string Identifier;
[XmlAttribute(AttributeName = "key")]
public string Key;
}
}
32 changes: 32 additions & 0 deletions ParallelRoadTool/Extensions/LocaleModels/NameList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using ColossalFramework;
using ColossalFramework.Globalization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace ParallelRoadTool.Extensions.LocaleModels
{
/// <summary>
/// <see cref="https://github.com/markusmitbrille/cities-skylines-custom-namelists/blob/master/CSLCNL/CSLCNL/NameList.cs"/>
/// </summary>
public class NameList
{
[XmlAttribute(AttributeName = "name")]
public string Name;
[XmlArray(ElementName = "strings")]
public LocalizedString[] LocalizedStrings;

public void Apply()
{
LocaleManager localeManager = SingletonLite<LocaleManager>.instance;
foreach (LocalizedString localizedString in LocalizedStrings)
{
localeManager.AddString(localizedString);
}

DebugUtils.Log($"Namelist {Name} applied.");
}
}
}
Binary file removed ParallelRoadTool/Icons/Anarchy.png
Binary file not shown.
Binary file removed ParallelRoadTool/Icons/AnarchyDisabled.png
Binary file not shown.
Binary file removed ParallelRoadTool/Icons/AnarchyFocused.png
Binary file not shown.
Binary file removed ParallelRoadTool/Icons/AnarchyHovered.png
Binary file not shown.
Binary file removed ParallelRoadTool/Icons/AnarchyPressed.png
Binary file not shown.
Binary file removed ParallelRoadTool/Icons/Bending.png
Binary file not shown.
Binary file removed ParallelRoadTool/Icons/BendingDisabled.png
Binary file not shown.
Binary file removed ParallelRoadTool/Icons/BendingFocused.png
Binary file not shown.
Binary file removed ParallelRoadTool/Icons/BendingHovered.png
Binary file not shown.
Binary file removed ParallelRoadTool/Icons/BendingPressed.png
Binary file not shown.
Binary file added ParallelRoadTool/Icons/Tutorial.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions ParallelRoadTool/Localization/en.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<NameList
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="PRT_en">
<strings>
<LocalizedString identifier="PRT_TOOLTIPS" key="SnappingToggleButton">Toggle snapping for existing nodes</LocalizedString>
<LocalizedString identifier="PRT_TOOLTIPS" key="ToolToggleButton">Toggle Parallel Road Tool</LocalizedString>
<LocalizedString identifier="PRT_TOOLTIPS" key="TutorialToggleButton">Toggle tutorial screen</LocalizedString>
<LocalizedString identifier="PRT_TOOLTIPS" key="ReverseToggleButton">Toggle reverse direction for this road</LocalizedString>
<LocalizedString identifier="PRT_TOOLTIPS" key="RemoveNetworkButton">Remove network</LocalizedString>
<LocalizedString identifier="PRT_TOOLTIPS" key="AddNetworkButton">Add network</LocalizedString>

<LocalizedString identifier="PRT_TEXTS" key="SameAsSelectedLabel">Same as selected</LocalizedString>
<LocalizedString identifier="PRT_TEXTS" key="DecreaseHorizontalOffsetOption">Decrease horizontal offset of parallel networks</LocalizedString>
<LocalizedString identifier="PRT_TEXTS" key="IncreaseHorizontalOffsetOption">Increase horizontal offset of parallel networks</LocalizedString>
<LocalizedString identifier="PRT_TEXTS" key="DecreaseVerticalOffsetOption">Decrease vertical offset of parallel networks</LocalizedString>
<LocalizedString identifier="PRT_TEXTS" key="IncreaseVerticalOffsetOption">Increase vertical offset of parallel networks</LocalizedString>

<LocalizedString identifier="TUTORIAL_ADVISER_TITLE" key="ParallelRoadTool">Parallel Road Tool</LocalizedString>
<LocalizedString identifier="TUTORIAL_ADVISER" key="ParallelRoadTool">
(if you don't see the image above, please close and reopen the tutorial)
1) Adds the currently selected network to your list
2) Allows you to change the selected network to another one
3) Reverses the direction for the network
4) Horizontal distance between the network and the first one
5) Vertical distance between the network and the first one
6) Removes the network from the list
7) Toggles snapping to all existing nodes.
Off: snaps only to the last segments drawn when the mod was on.
On : will try to snap to the closer segment available.

Negative values are allowed for both vertical and horizontal distances.
A negative horizontal distance will place the road on the opposite side.
A negative vertical distance will place the road below terrain level.
</LocalizedString>
</strings>
</NameList>
34 changes: 34 additions & 0 deletions ParallelRoadTool/Localization/ru.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<NameList
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="PRT_ru">
<strings>
<LocalizedString identifier="PRT_TOOLTIPS" key="SnappingToggleButton">Изменить привязку узлов</LocalizedString>
<LocalizedString identifier="PRT_TOOLTIPS" key="ToolToggleButton">Переключение Parallel Road Tool</LocalizedString>
<LocalizedString identifier="PRT_TOOLTIPS" key="TutorialToggleButton">Руководство</LocalizedString>
<LocalizedString identifier="PRT_TOOLTIPS" key="ReverseToggleButton">Реверс направления</LocalizedString>
<LocalizedString identifier="PRT_TOOLTIPS" key="RemoveNetworkButton">Удалить</LocalizedString>
<LocalizedString identifier="PRT_TOOLTIPS" key="AddNetworkButton">Добавить</LocalizedString>

<LocalizedString identifier="PRT_TEXTS" key="SameAsSelectedLabel">То же, что выбрано</LocalizedString>
<LocalizedString identifier="PRT_TEXTS" key="DecreaseHorizontalOffsetOption">Уменьшение расстояния по горизонтали между дорогами/конструкциями</LocalizedString>
<LocalizedString identifier="PRT_TEXTS" key="IncreaseHorizontalOffsetOption">Увеличение расстояния по горизонтали между дорогами/конструкциями</LocalizedString>
<LocalizedString identifier="PRT_TEXTS" key="DecreaseVerticalOffsetOption">Уменьшение расстояния по вертикали между дорогами/конструкциями</LocalizedString>
<LocalizedString identifier="PRT_TEXTS" key="IncreaseVerticalOffsetOption">Увеличение расстояния по вертикали между дорогами/конструкциями</LocalizedString>

<LocalizedString identifier="TUTORIAL_ADVISER_TITLE" key="ParallelRoadTool">Parallel Road Tool</LocalizedString>
<LocalizedString identifier="TUTORIAL_ADVISER" key="ParallelRoadTool">
(если вы не видите изображение выше, пожалуйста, закройте и снова откройте руководство)
1) Добавляет выбранное в ваш список
2) Открывает список для выбора
3) Меняет направление(для односторонних дорог)
4) Расстояние по горизонтали между выбранным и первым в списке
5) Расстояние по вертикали между выбранным и первым в списке
6) Удаляет из списка
7) Переключает привязку ко всем существующим узлам.
Off: привязывается только к последним сегментам, нарисованным при включённом моде.
On : попытается привязаться к более близкому сегменту.
</LocalizedString>
</strings>
</NameList>
8 changes: 4 additions & 4 deletions ParallelRoadTool/ModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ParallelRoadTool
{
public class ModInfo : IUserMod
{
public const string Version = "0.19.0";
public const string Version = "0.24.0";
public const string Branch = "dev";

public ModInfo()
Expand All @@ -25,13 +25,13 @@ public ModInfo()
}

#if DEBUG
public string Name => $"[BETA] Parallel Road Tool {Version} b-{Branch}";
public string Name => $"[BETA] Parallel Road Tool {Version}-{Branch}";
#else
public string Name => $"Parallel Road Tool {Version} b-{Branch}";
public string Name => $"Parallel Road Tool {Version}";
#endif

public string Description =>
"This mod allows players to easily draw parallel roads in Cities: Skylines. ";
"This mod allows players to easily draw parallel/stacked roads in Cities: Skylines.";

public void OnSettingsUI(UIHelperBase helper)
{
Expand Down
Loading

0 comments on commit 3942c79

Please sign in to comment.