forked from ST-Apps/CS-ParallelRoadTool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
655 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
ParallelRoadTool/Extensions/LocaleModels/LocalizedString.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
ParallelRoadTool/Extensions/LocaleModels/LocalizedStringKey.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.