Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
- Add tooltips to tool panel.
- Add localization.
- Add proper licensing.
  • Loading branch information
algernon-A committed Dec 19, 2023
1 parent b76f5a7 commit fc4b7bc
Show file tree
Hide file tree
Showing 25 changed files with 533 additions and 34 deletions.
4 changes: 3 additions & 1 deletion BepInEx/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// <copyright file="Plugin.cs" company="algernon (K. Algernon A. Sheppard)">
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
// Licensed under the Apache Licence, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// See LICENSE.txt file in the project root for full license information.
// </copyright>

namespace LineTool
Expand All @@ -14,7 +16,7 @@ namespace LineTool
/// <summary>
/// BepInEx plugin to substitute for IMod support.
/// </summary>
[BepInPlugin(GUID, "Line Tool Lite", "1.1.2")]
[BepInPlugin(GUID, "Line Tool Lite", "1.2.0")]
[HarmonyPatch]
public class Plugin : BaseUnityPlugin
{
Expand Down
2 changes: 1 addition & 1 deletion BepInEx/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Line_Tool_Lite",
"version_number": "1.1.2",
"version_number": "1.2.0",
"website_url": "https://github.com/algernon-A/LineToolLite",
"description": "Place objects in lines, curves, or circles. A variety of options and controls are availalbe to specify and fine-tune results.",
"dependencies": [
Expand Down
5 changes: 5 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.2.0
- Add tooltips to tool panel.
- Add localization.
- Add proper licensing.

1.1.2
- Additional updates for Tree Controller integration.

Expand Down
2 changes: 2 additions & 0 deletions Code/LineModes/Circle.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// <copyright file="Circle.cs" company="algernon (K. Algernon A. Sheppard)">
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
// Licensed under the Apache Licence, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// See LICENSE.txt file in the project root for full license information.
// </copyright>

namespace LineTool
Expand Down
2 changes: 2 additions & 0 deletions Code/LineModes/LineBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// <copyright file="LineBase.cs" company="algernon (K. Algernon A. Sheppard)">
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
// Licensed under the Apache Licence, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// See LICENSE.txt file in the project root for full license information.
// </copyright>

namespace LineTool
Expand Down
2 changes: 2 additions & 0 deletions Code/LineModes/LineMode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// <copyright file="LineMode.cs" company="algernon (K. Algernon A. Sheppard)">
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
// Licensed under the Apache Licence, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// See LICENSE.txt file in the project root for full license information.
// </copyright>

namespace LineTool
Expand Down
2 changes: 2 additions & 0 deletions Code/LineModes/PointData.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// <copyright file="PointData.cs" company="algernon (K. Algernon A. Sheppard)">
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
// Licensed under the Apache Licence, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// See LICENSE.txt file in the project root for full license information.
// </copyright>

namespace LineTool
Expand Down
2 changes: 2 additions & 0 deletions Code/LineModes/SimpleCurve.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// <copyright file="SimpleCurve.cs" company="algernon (K. Algernon A. Sheppard)">
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
// Licensed under the Apache Licence, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// See LICENSE.txt file in the project root for full license information.
// </copyright>

namespace LineTool
Expand Down
2 changes: 2 additions & 0 deletions Code/LineModes/SpacingMode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// <copyright file="SpacingMode.cs" company="algernon (K. Algernon A. Sheppard)">
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
// Licensed under the Apache Licence, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// See LICENSE.txt file in the project root for full license information.
// </copyright>

namespace LineTool
Expand Down
2 changes: 2 additions & 0 deletions Code/LineModes/StraightLine.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// <copyright file="StraightLine.cs" company="algernon (K. Algernon A. Sheppard)">
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
// Licensed under the Apache Licence, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// See LICENSE.txt file in the project root for full license information.
// </copyright>

namespace LineTool
Expand Down
78 changes: 78 additions & 0 deletions Code/Localization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// <copyright file="Localization.cs" company="algernon (K. Algernon A. Sheppard)">
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
// Licensed under the Apache Licence, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// See LICENSE.txt file in the project root for full license information.
// </copyright>

namespace LineTool
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Colossal.Localization;
using Colossal.Logging;
using Game.SceneFlow;

/// <summary>
/// Translation handling.
/// </summary>
public static class Localization
{
/// <summary>
/// Loads settings translations from tab-separated l10n file.
/// </summary>
/// <param name="log">Log to use.</param>
public static void LoadTranslations(ILog log)
{
try
{
// Read embedded file.
using StreamReader reader = new (Assembly.GetExecutingAssembly().GetManifestResourceStream("LineToolLite.l10n.csv"));
{
List<string> lines = new ();
while (!reader.EndOfStream)
{
// Skip empty lines.
string line = reader.ReadLine();
if (!string.IsNullOrWhiteSpace(line))
{
lines.Add(line);
}
}

// Iterate through each game locale.
log.Info("parsing translation file");
IEnumerable<string[]> fileLines = lines.Select(x => x.Split('\t'));
foreach (string localeID in GameManager.instance.localizationManager.GetSupportedLocales())
{
try
{
// Find matching column in file.
int valueColumn = Array.IndexOf(fileLines.First(), localeID);

// Make sure a valid column has been found (column 0 is the binding context and column 1 is the translation key).
if (valueColumn > 1)
{
// Add translations to game locales.
log.Debug("found translation for " + localeID);
MemorySource language = new (fileLines.Skip(1).ToDictionary(x => x[0] + '.' + x[1], x => x.ElementAtOrDefault(valueColumn)));
GameManager.instance.localizationManager.AddSource(localeID, language);
}
}
catch (Exception e)
{
// Don't let a single failure stop us.
log.Error(e, $"exception reading localization for locale {localeID}");
}
}
}
}
catch (Exception e)
{
log.Error(e, "exception reading settings localization file");
}
}
}
}
8 changes: 7 additions & 1 deletion Code/Mod.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// <copyright file="Mod.cs" company="algernon (K. Algernon A. Sheppard)">
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
// Licensed under the Apache Licence, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// See LICENSE.txt file in the project root for full license information.
// </copyright>

namespace LineTool
{
using System.IO;
using System.Reflection;
using Colossal.Logging;
using Game;
using Game.Modding;
Expand Down Expand Up @@ -46,7 +49,7 @@ public void OnLoad()
Log.effectivenessLevel = Level.Debug;
#endif

Log.Info("loading");
Log.Info($"loading {ModName} version {Assembly.GetExecutingAssembly().GetName().Version}");
}

/// <summary>
Expand All @@ -57,6 +60,9 @@ public void OnCreateWorld(UpdateSystem updateSystem)
{
Log.Info("starting OnCreateWorld");

// Load translations.
Localization.LoadTranslations(Log);

// Activate systems.
updateSystem.UpdateAt<LineToolSystem>(SystemUpdatePhase.ToolUpdate);
updateSystem.UpdateAt<LineToolUISystem>(SystemUpdatePhase.UIUpdate);
Expand Down
3 changes: 3 additions & 0 deletions Code/Systems/LineToolSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// <copyright file="LineToolSystem.cs" company="algernon (K. Algernon A. Sheppard)">
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
// Licensed under the Apache Licence, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// See LICENSE.txt file in the project root for full license information.
// </copyright>

namespace LineTool
Expand Down Expand Up @@ -687,6 +689,7 @@ protected override void OnStopRunning()

// Clear tooltips.
_tooltips.Clear();
World.GetExistingSystemManaged<LineToolUISystem>().ClearTooltip();

// Disable apply action.
_applyAction.shouldBeEnabled = false;
Expand Down
2 changes: 2 additions & 0 deletions Code/Systems/LineToolTooltipSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// <copyright file="LineToolTooltipSystem.cs" company="algernon (K. Algernon A. Sheppard)">
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
// Licensed under the Apache Licence, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// See LICENSE.txt file in the project root for full license information.
// </copyright>

namespace LineTool
Expand Down
24 changes: 17 additions & 7 deletions Code/Systems/LineToolUISystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// <copyright file="LineToolUISystem.cs" company="algernon (K. Algernon A. Sheppard)">
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
// Licensed under the Apache Licence, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// See LICENSE.txt file in the project root for full license information.
// </copyright>

namespace LineTool
Expand Down Expand Up @@ -48,6 +50,14 @@ internal void UpdateSpacing()
ExecuteScript(_uiView, $"if (lineTool) {{ lineTool.spacing = {_lineToolSystem.Spacing * 10}; if (lineTool.refreshSpacing) lineTool.refreshSpacing();}}");
}

/// <summary>
/// Clears any displayed tooltip.
/// </summary>
internal void ClearTooltip()
{
ExecuteScript(_uiView, "if (lineTool) {{ lineTool.hideTooltip(); }}");
}

/// <summary>
/// Called when the system is created.
/// </summary>
Expand Down Expand Up @@ -210,11 +220,11 @@ private string ReadCSS(string fileName)
}
catch (Exception e)
{
_log.Error(e, "exception reading CSS file " + fileName);
_log.Error(e, $"exception reading CSS file {fileName}");
}

// If we got here, something went wrong.; return null.
_log.Error("failed to read embedded CSS file " + fileName);
_log.Error($"failed to read embedded CSS file {fileName}");
return null;
}

Expand All @@ -240,11 +250,11 @@ private string ReadHTML(string fileName, string injectionPostfix)
}
catch (Exception e)
{
_log.Error(e, "exception reading embedded HTML file " + fileName);
_log.Error(e, $"exception reading embedded HTML file {fileName}");
}

// If we got here, something went wrong.; return null.
_log.Error("failed to read embedded HTML file " + fileName);
_log.Error($"failed to read embedded HTML file {fileName}");
return null;
}

Expand All @@ -269,11 +279,11 @@ private string ReadJS(string fileName)
}
catch (Exception e)
{
_log.Error(e, "exception reading embedded JavaScript file " + fileName);
_log.Error(e, $"exception reading embedded JavaScript file {fileName}");
}

// If we got here, something went wrong; return null.
_log.Error("failed to read embedded JavaScript file " + fileName);
_log.Error($"failed to read embedded JavaScript file {fileName}");
return null;
}

Expand All @@ -295,7 +305,7 @@ private string ReadUIFile(string fileName)
}
catch (Exception e)
{
_log.Error(e, "exception reading embedded UI file " + fileName);
_log.Error(e, $"exception reading embedded UI file {fileName}");
}

return null;
Expand Down
3 changes: 3 additions & 0 deletions Config/References.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<Reference Include="Colossal.UI.Binding">
<Private>false</Private>
</Reference>
<Reference Include="Colossal.Localization">
<Private>false</Private>
</Reference>
<Reference Include="Colossal.Logging">
<Private>false</Private>
</Reference>
Expand Down
2 changes: 2 additions & 0 deletions GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// <copyright file="GlobalSuppressions.cs" company="algernon (K. Algernon A. Sheppard)">
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
// Licensed under the Apache Licence, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// See LICENSE.txt file in the project root for full license information.
// </copyright>

using System.Diagnostics.CodeAnalysis;
Expand Down
Loading

0 comments on commit fc4b7bc

Please sign in to comment.