Skip to content

Commit 24b5af6

Browse files
committed
Added image support
1 parent 103db80 commit 24b5af6

File tree

9 files changed

+129
-36
lines changed

9 files changed

+129
-36
lines changed

DSPTranslationPlugin/DSPTranslationPlugin.csproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,31 @@
5353
</Reference>
5454
<Reference Include="UnityEngine.TextRenderingModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
5555
<HintPath>D:\Games\SteamLibrary\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
56+
<Private>False</Private>
5657
</Reference>
5758
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
5859
<HintPath>D:\Games\SteamLibrary\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\UnityEngine.UI.dll</HintPath>
60+
<Private>False</Private>
61+
</Reference>
62+
<Reference Include="UnityEngine.UnityWebRequestAssetBundleModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
63+
<HintPath>D:\Games\SteamLibrary\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\UnityEngine.UnityWebRequestAssetBundleModule.dll</HintPath>
64+
<Private>False</Private>
65+
</Reference>
66+
<Reference Include="UnityEngine.UnityWebRequestAudioModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
67+
<HintPath>D:\Games\SteamLibrary\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\UnityEngine.UnityWebRequestAudioModule.dll</HintPath>
68+
<Private>False</Private>
69+
</Reference>
70+
<Reference Include="UnityEngine.UnityWebRequestModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
71+
<HintPath>D:\Games\SteamLibrary\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\UnityEngine.UnityWebRequestModule.dll</HintPath>
72+
<Private>False</Private>
73+
</Reference>
74+
<Reference Include="UnityEngine.UnityWebRequestTextureModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
75+
<HintPath>D:\Games\SteamLibrary\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\UnityEngine.UnityWebRequestTextureModule.dll</HintPath>
76+
<Private>False</Private>
77+
</Reference>
78+
<Reference Include="UnityEngine.UnityWebRequestWWWModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
79+
<HintPath>D:\Games\SteamLibrary\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\UnityEngine.UnityWebRequestWWWModule.dll</HintPath>
80+
<Private>False</Private>
5981
</Reference>
6082
</ItemGroup>
6183

DSPTranslationPlugin/GameHarmony/Localizer_Refresh_Harmony.cs

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
using HarmonyLib;
1+
using System;
2+
using System.Collections;
3+
using HarmonyLib;
24
using UnityEngine;
5+
using UnityEngine.Networking;
6+
using UnityEngine.UI;
37

48
namespace DSPTranslationPlugin.GameHarmony
59
{
@@ -9,12 +13,55 @@ namespace DSPTranslationPlugin.GameHarmony
913
[HarmonyPatch(typeof(Localizer), "Refresh")]
1014
public static class Localizer_Refresh_Harmony
1115
{
16+
[HarmonyPrefix]
17+
public static bool Prefix(Localizer __instance)
18+
{
19+
var maskableGraphics = __instance.GetComponents<MaskableGraphic>();
20+
__instance.translation = __instance.stringKey.Translate();
21+
foreach (var graphic in maskableGraphics)
22+
{
23+
if (graphic is Text text)
24+
{
25+
text.text = __instance.translation;
26+
}
27+
else if (graphic is Image image)
28+
{
29+
if (Uri.IsWellFormedUriString(__instance.translation, UriKind.RelativeOrAbsolute))
30+
{
31+
__instance.StartCoroutine(GetRequest(__instance.translation, image));
32+
}
33+
else
34+
{
35+
image.sprite = Resources.Load<Sprite>(__instance.translation);
36+
}
37+
}
38+
else if (graphic is RawImage rawImage)
39+
{
40+
if (Uri.IsWellFormedUriString(__instance.translation, UriKind.RelativeOrAbsolute))
41+
{
42+
__instance.StartCoroutine(GetRequest(__instance.translation, rawImage));
43+
}
44+
else
45+
{
46+
rawImage.texture = Resources.Load<Texture2D>(__instance.translation);
47+
}
48+
}
49+
}
50+
51+
return false;
52+
}
53+
1254
/// <summary>
1355
/// Expand in game credits box
1456
/// </summary>
1557
/// <param name="__instance"></param>
1658
[HarmonyPostfix]
1759
public static void Postfix(Localizer __instance)
60+
{
61+
ExpandGameCreditsBox(__instance);
62+
}
63+
64+
private static void ExpandGameCreditsBox(Localizer __instance)
1865
{
1966
if (__instance.name == "tip" && __instance.transform.parent.name == "language")
2067
{
@@ -25,5 +72,38 @@ public static void Postfix(Localizer __instance)
2572
rect.sizeDelta = sizeDelta;
2673
}
2774
}
75+
76+
private static IEnumerator GetRequest(string uri, RawImage image)
77+
{
78+
var www = UnityWebRequestTexture.GetTexture(uri);
79+
yield return www.SendWebRequest();
80+
81+
if (www.isNetworkError || www.isHttpError)
82+
{
83+
Debug.LogError(www.error);
84+
}
85+
else
86+
{
87+
var myTexture = ((DownloadHandlerTexture) www.downloadHandler).texture;
88+
image.texture = myTexture;
89+
}
90+
}
91+
92+
private static IEnumerator GetRequest(string uri, Image image)
93+
{
94+
var www = UnityWebRequestTexture.GetTexture(uri);
95+
yield return www.SendWebRequest();
96+
97+
if (www.isNetworkError || www.isHttpError)
98+
{
99+
Debug.LogError(www.error);
100+
}
101+
else
102+
{
103+
var myTexture = ((DownloadHandlerTexture) www.downloadHandler).texture;
104+
var sprite = Sprite.Create(myTexture, new Rect(0, 0, myTexture.width, myTexture.height), Vector2.zero);
105+
image.sprite = sprite;
106+
}
107+
}
28108
}
29109
}

DSPTranslationPlugin/GameHarmony/TranslationFix/UIReplicatorWindow_OnUpdate_Harmony.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
using System.Collections.Generic;
2-
using System.IO;
3-
using System.Linq;
4-
using HarmonyLib;
5-
using Mono.Cecil.Cil;
6-
using TranslationCommon;
7-
using TranslationCommon.Translation;
8-
using UnityEngine.UI;
9-
using OpCodes = System.Reflection.Emit.OpCodes;
1+
using HarmonyLib;
102

113
namespace DSPTranslationPlugin.GameHarmony.TranslationFix
124
{
@@ -19,14 +11,16 @@ public static class UIReplicatorWindow_OnUpdate_Prefix
1911
private static bool isPatched = false;
2012

2113
/// <summary>
22-
/// Load current language after pressing "Apply" button
14+
/// Fixed "Replicating Queue" text
2315
/// </summary>
16+
/// <param name="__instance"></param>
2417
[HarmonyPrefix]
2518
public static void Prefix(UIReplicatorWindow __instance)
2619
{
2720
if (!isPatched)
2821
{
2922
var _tmp_text0 = AccessTools.Field(typeof(UIReplicatorWindow), "_tmp_text0");
23+
// 制造队列 == "Replicating Queue"
3024
_tmp_text0.SetValue(__instance, "制造队列".Translate());
3125
isPatched = true;
3226
}

DSPTranslationPlugin/TranslationPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace DSPTranslationPlugin
1414
{
15-
[BepInPlugin("com.muchaszewski.dsp_translationPlugin", "DSP Community Translation", "0.2.0")]
15+
[BepInPlugin("com.muchaszewski.dsp_translationPlugin", "DSP Community Translation", "0.2.2")]
1616
public class TranslationPlugin : BaseUnityPlugin
1717
{
1818
public static MonoBehaviour StaticMonoBehaviour { get; private set; }

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
- Adds possibility to add custom languages (text only)
88
- Adds (currently hidden) French language
99
- Adds the possibility to change Font in game (WORK IN PROGRESS)
10-
10+
- Use custom logo for custom translation
1111

1212
# Roadmap
1313
- Refactor code and add documentation
14-
- Add support for in images that can be translated (and game logo)
1514
- Add support for adjusting content size of in game UI to fit new text
16-
- Add `*.po` file (in addition to json for easier translations)
1715

1816
## Installation via Mod manager
1917

@@ -87,6 +85,19 @@ You can find [translations at Crowdin](https://crowdin.com/translate/dyson-spher
8785
}
8886
```
8987

88+
### Custom images:
89+
Currently in the game there are 2 images that can be changed, they look like a path - `UI/Textures/dsp-logo-en`. You can use a valid path from resources or valid URL.
90+
URL needs to be a direct png file. Eg:
91+
```
92+
Internet URI -- "ImageLogo0": "https://wiki.factorio.com/images/thumb/Factorio-logo.png/461px-Factorio-logo.png",
93+
Local file URI -- "ImageLogo0": "file://C:/Users/Muchaszewski/Documents/Icon.png"
94+
```
95+
96+
####Specific images description:
97+
98+
- `ImageLogo0` and `ImageLogo1` needs to have aspect ratio that corresponds to 800x300 pixels, otherwise they will be stretched
99+
100+
90101
### Dump file:
91102
Simpler file structure where only Translation value is provided.
92103
Each new translation is separated by 5 dashes `-----` this can speed up the translation process.

TranslationCommon/Fonts/TextDefaultFont.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,5 @@ public void UseCustomFontImmediate(Font fontToUse)
8080
{
8181
Reference.font = fontToUse;
8282
}
83-
84-
/// <summary>
85-
/// Custom utils to get text path
86-
/// </summary>
87-
/// <param name="text"></param>
88-
/// <returns></returns>
89-
public static string GetTextPath(Text text)
90-
{
91-
List<string> path = new List<string>();
92-
path.Add(text.name);
93-
var parent = text.transform.parent;
94-
while (parent != null)
95-
{
96-
path.Add(parent.name);
97-
parent = parent.parent;
98-
}
99-
100-
path.Reverse();
101-
return String.Join(".", path.ToArray());
102-
}
10383
}
10484
}

TranslationCommon/Translation/TranslationManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ private static void SetupTranslationDictionary()
7272
TranslationDictionary = CurrentLanguage?.Translation.TranslationTable.ToDictionary(proto => proto.Name);
7373
}
7474

75+
/// <summary>
76+
/// Load custom language
77+
/// </summary>
7578
public static void LoadCurrentLanguage()
7679
{
7780
if (!IsInitialized)

TranslationCommon/TranslationCommon.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
3636
<HintPath>D:\Games\SteamLibrary\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\UnityEngine.UI.dll</HintPath>
3737
</Reference>
38+
<Reference Include="UnityEngine.UnityWebRequestWWWModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
39+
<HintPath>D:\Games\SteamLibrary\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\UnityEngine.UnityWebRequestWWWModule.dll</HintPath>
40+
</Reference>
3841
</ItemGroup>
3942

4043
</Project>

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "DSPTranslationPlugin",
3-
"version_number": "0.2.1",
3+
"version_number": "0.2.2",
44
"website_url": "https://github.com/Muchaszewski/DSP_TranslationMod",
55
"description": "Dyson sphere translation plugin! Translations download form crowdin https://crowdin.com/translate/dyson-sphere-program/14#",
66
"dependencies": [

0 commit comments

Comments
 (0)