Skip to content

Commit

Permalink
v3.0.0r2
Browse files Browse the repository at this point in the history
Updated to latest KU
  • Loading branch information
klyte45 committed Nov 7, 2022
1 parent 241f894 commit 8a6eba6
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 172 deletions.
8 changes: 7 additions & 1 deletion ElectricRoadsKw.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32819.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EF00}") = "ElectricRoadsKw", "ElectricRoadsKw\ElectricRoadsKw.csproj", "{291D9EA9-6945-4EA3-8756-37464040F450}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectricRoadsKw", "ElectricRoadsKw\ElectricRoadsKw.csproj", "{291D9EA9-6945-4EA3-8756-37464040F450}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KwyttoUtilityER", "KwyttoUtilityER\KwyttoUtilityER.csproj", "{27C9AAF8-F40F-4D56-0601-9C9025ED0A0C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +17,10 @@ Global
{291D9EA9-6945-4EA3-8756-37464040F450}.Debug|Any CPU.Build.0 = Debug|Any CPU
{291D9EA9-6945-4EA3-8756-37464040F450}.Release|Any CPU.ActiveCfg = Release|Any CPU
{291D9EA9-6945-4EA3-8756-37464040F450}.Release|Any CPU.Build.0 = Release|Any CPU
{27C9AAF8-F40F-4D56-0601-9C9025ED0A0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27C9AAF8-F40F-4D56-0601-9C9025ED0A0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27C9AAF8-F40F-4D56-0601-9C9025ED0A0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27C9AAF8-F40F-4D56-0601-9C9025ED0A0C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
27 changes: 0 additions & 27 deletions ElectricRoadsKw/CommonProperties.cs

This file was deleted.

2 changes: 1 addition & 1 deletion ElectricRoadsKw/Data/ClassesData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ColossalFramework;
using ICities;
using Klyte.Localization;
using ElectricRoads.Localization;
using Kwytto.LiteUI;
using Kwytto.Utils;
using System;
Expand Down
11 changes: 5 additions & 6 deletions ElectricRoadsKw/Data/DataContainer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using ColossalFramework;
using ColossalFramework.Threading;
using ICities;
using Klyte.Localization;
using Kwytto;
using ElectricRoads.Localization;
using Kwytto.LiteUI;
using Kwytto.Utils;
using System;
Expand All @@ -29,7 +28,7 @@ public void OnLoadData()
{
LogUtils.DoLog($"LOADING DATA {GetType()}");
instance.Instances = new Dictionary<Type, IDataExtension>();
List<Type> instancesExt = ReflectionUtils.GetInterfaceImplementations(typeof(IDataExtension), GetType());
List<Type> instancesExt = ReflectionUtils.GetInterfaceImplementations(typeof(IDataExtension), new[] { GetType().Assembly });
LogUtils.DoLog($"SUBTYPE COUNT: {instancesExt.Count}");
foreach (Type type in instancesExt)
{
Expand Down Expand Up @@ -89,7 +88,7 @@ private void ProcessExtension(Type type)
try
{
instance.Instances[type] = basicInstance.Deserialize(type, storage) ?? basicInstance;
if (CommonProperties.DebugMode)
if (ModInstance.DebugMode)
{
string content = System.Text.Encoding.UTF8.GetString(storage);
LogUtils.DoLog($"{type} DATA {storage.Length}b => {content}");
Expand All @@ -113,7 +112,7 @@ private void ProcessExtension(Type type)
KwyttoDialog.ShowModal(new KwyttoDialog.BindProperties()
{
title = $"Error loading '{type}' data",
message = $"An error occurred while loading the data from <color yellow>{CommonProperties.ModName}</color>.{(CommonProperties.GitHubRepoPath.IsNullOrWhiteSpace() ? "" : "\nPlease open a issue in GitHub along with the game log attached and a printscreen of this window to get this checked by the mod developer. See the <color cyan>Report-a-bug Helper</color> button in the mod options menu to see details about how to get the game log.")}\nRaw data:",
message = $"An error occurred while loading the data from <color yellow>{ModInstance.Instance.SimpleName}</color>.{(ModInstance.Instance.GitHubRepoPath.IsNullOrWhiteSpace() ? "" : "\nPlease open a issue in GitHub along with the game log attached and a printscreen of this window to get this checked by the mod developer. See the <color cyan>Report-a-bug Helper</color> button in the mod options menu to see details about how to get the game log.")}\nRaw data:",
scrollText = content,
buttons = new[]
{
Expand Down Expand Up @@ -182,7 +181,7 @@ public void OnSaveData()


byte[] data = instance.Instances[type]?.Serialize();
if (CommonProperties.DebugMode)
if (ModInstance.DebugMode)
{
string content = System.Text.Encoding.UTF8.GetString(data);
LogUtils.DoLog($"{type} DATA (L = {data?.Length}) => {content}");
Expand Down
6 changes: 3 additions & 3 deletions ElectricRoadsKw/Data/DataExtensionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static U Instance
public IDataExtension Deserialize(Type type, byte[] data)
{
string content = data[0] == '<' ? Encoding.UTF8.GetString(data) : ZipUtils.Unzip(data);
if (CommonProperties.DebugMode)
if (ModInstance.DebugMode)
{
LogUtils.DoLog($"Deserializing {typeof(U)}:\n{content}");
}
Expand All @@ -47,8 +47,8 @@ public byte[] Serialize()
return null;
}
BeforeSerialize();
var xml = XmlUtils.DefaultXmlSerialize((U)this, CommonProperties.DebugMode);
if (CommonProperties.DebugMode)
var xml = XmlUtils.DefaultXmlSerialize((U)this, ModInstance.DebugMode);
if (ModInstance.DebugMode)
{
LogUtils.DoLog($"Serializing {typeof(U)}:\n{xml}");
}
Expand Down
26 changes: 12 additions & 14 deletions ElectricRoadsKw/ElectricRoadsKw.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ProjectGuid>{291D9EA9-6945-4EA3-8756-37464040F450}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Klyte</RootNamespace>
<RootNamespace>ElectricRoads</RootNamespace>
<AssemblyName>ElectricRoadsKw</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
Expand Down Expand Up @@ -66,7 +66,6 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CommonProperties.cs" />
<EmbeddedResource Include="Localization\Str.*.resx" />
<EmbeddedResource Include="Localization\Str.resx">
<LastGenOutput>Str.Designer.cs</LastGenOutput>
Expand All @@ -79,22 +78,15 @@
<DesignTime>True</DesignTime>
<DependentUpon>Str.resx</DependentUpon>
</Compile>
<Compile Include="Data\ClassesData.cs" />
<Compile Include="Data\DataContainer.cs" />
<Compile Include="Data\DataExtensionBase.cs" />
<Compile Include="Data\ExtensionInterfaceDictionaryStructValSimplImpl.cs" />
<Compile Include="Data\IDataExtension.cs" />
<Compile Include="MainController.cs" />
<Compile Include="ModInstance.cs" />
<Compile Include="Overrides\ElectricRoadsOverrides.cs" />
<Compile Include="Data\**\*.cs" />
<Compile Include="UI\LiteUI\MainWindow.cs" />
<Compile Include="_commons\**\*.cs" Exclude="_commons\Localization\KStr.Designer.cs" />
<Compile Include="_commons\Localization\KStr.Designer.cs">
<DependentUpon>KStr.resx</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="_commons\Localization\KStr.*.resx" />
<EmbeddedResource Include="_commons\Localization\KStr.resx">
<LastGenOutput>KStr.Designer.cs</LastGenOutput>
<Generator>ResXFileCodeGenerator</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand All @@ -115,6 +107,12 @@
<EmbeddedResource Include="UI\Images\Reload.png" />
<EmbeddedResource Include="UI\Images\Save.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KwyttoUtilityER\KwyttoUtilityER.csproj">
<Project>{27c9aaf8-f40f-4d56-0601-9c9025ed0a0c}</Project>
<Name>KwyttoUtilityER</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>set "ModDir=%25LOCALAPPDATA%25\Colossal Order\Cities_Skylines\Addons\Mods\$(SolutionName)\"
Expand Down
4 changes: 2 additions & 2 deletions ElectricRoadsKw/Localization/Str.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 21 additions & 39 deletions ElectricRoadsKw/ModInstance.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using ElectricRoads.UI;
using ICities;
using Klyte.Localization;
using ElectricRoads.Localization;
using Kwytto.Interfaces;
using Kwytto.Utils;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using UnifiedUI.Helpers;
using UnityEngine;

[assembly: AssemblyVersion("3.0.0.1")]
[assembly: AssemblyVersion("3.0.0.2")]
namespace ElectricRoads
{
public class ModInstance : BasicIUserMod<ModInstance, MainController>
Expand All @@ -25,49 +23,33 @@ public class ModInstance : BasicIUserMod<ModInstance, MainController>
[2862121823] = "81 Tiles 2"
};

public override string SafeName => "ElectricRoads";

public override string Acronym => "ER";

public override Color ModColor { get; } = ColorExtensions.FromRGB("a38b00");

public enum PatchFlags
{
RegularGame = 0x1,
Mod81TilesGame = 0x2
BP81TilesGame = 0x2
}
internal static PatchFlags m_currentPatched;

protected override void OnLevelLoadedInherit(LoadMode mode)
{
base.OnLevelLoadedInherit(mode);
Instance.RegisterMod();
}

private UUICustomButton m_modButton;
public void RegisterMod()
private IUUIButtonContainerPlaceholder[] cachedUUI;
public override IUUIButtonContainerPlaceholder[] UUIButtons => cachedUUI ?? (cachedUUI = new[]
{
m_modButton = UUIHelpers.RegisterCustomButton(
name: SimpleName,
groupName: "Klyte45",
tooltip: Name,
onToggle: (value) => { if (value) { Open(); } else { Close(); } },
onToolChanged: null,
icon: KResourceLoader.LoadTexture($"UI.Images.{IconName}.png"),
hotkeys: new UUIHotKeys { }

);
Close();
}
internal void Close()
{
m_modButton.IsPressed = false;
MainWindow.Instance.Visible = false;
m_modButton.Button?.Unfocus();
ApplyButtonColor();
}

internal void ApplyButtonColor() => m_modButton.Button.color = Color.Lerp(Color.gray, m_modButton.IsPressed ? Color.white : Color.black, 0.5f);
internal void Open()
new UUIWindowButtonContainerPlaceholder(
buttonName: Instance.SimpleName,
tooltip: Instance.GeneralName,
iconPath: "ModIcon",
windowGetter: ()=>MainWindow.Instance
)
});
protected override void DoOnLevelUnloading()
{
m_modButton.IsPressed = true;
MainWindow.Instance.Visible = true;
MainWindow.Instance.transform.position = new Vector3(25, 50);
ApplyButtonColor();
base.DoOnLevelUnloading();
cachedUUI = null;
}
}
}
2 changes: 1 addition & 1 deletion ElectricRoadsKw/Overrides/ElectricRoadsOverrides.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void Awake()
AddRedirect(typeof(PropInstance).GetMethod("RenderInstance", RedirectorUtils.allFlags, null, new Type[] { typeof(RenderManager.CameraInfo), typeof(PropInfo), typeof(InstanceID), typeof(Vector3), typeof(float), typeof(float), typeof(Color), typeof(Vector4), typeof(bool) }, null), null, null, GetType().GetMethod("LightsOnCheckDetour", RedirectorUtils.allFlags));
AddRedirect(typeof(LightEffect).GetMethod("PopulateGroupData", RedirectorUtils.allFlags), GetType().GetMethod("CheckElectrityNetForLight", RedirectorUtils.allFlags));

ModInstance.m_currentPatched &= ~ModInstance.PatchFlags.Mod81TilesGame;
ModInstance.m_currentPatched &= ~ModInstance.PatchFlags.BP81TilesGame;
ModInstance.m_currentPatched &= ~ModInstance.PatchFlags.RegularGame;


Expand Down
Binary file modified ElectricRoadsKw/UI/Images/ModIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed ElectricRoadsKw/UI/Images/ModIcon.psd
Binary file not shown.
Loading

0 comments on commit 8a6eba6

Please sign in to comment.