Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Bottleneck.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Bottleneck</AssemblyName>
<Description>Production bottleneck finder</Description>
<Version>1.0.15</Version>
<Version>1.0.16</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
Expand All @@ -18,7 +18,6 @@
<PackageReference Include="BepInEx.Core" Version="5.*" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-*" />
<PackageReference Include="DysonSphereProgram.Modding.CommonAPI" Version="*-*" />
<PackageReference Include="DysonSphereProgram.Modding.NebulaMultiplayerModApi" Version="1.2.0" />
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" IncludeAssets="compile" />
</ItemGroup>
Expand Down
32 changes: 13 additions & 19 deletions BottleneckPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using Bottleneck.Stats;
using Bottleneck.UI;
using Bottleneck.Util;
using CommonAPI;
using CommonAPI.Systems;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;
Expand All @@ -16,8 +14,7 @@ namespace Bottleneck
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
[BepInDependency("dsp.nebula-multiplayer-api", BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency(CommonAPIPlugin.GUID)]
[CommonAPISubmoduleDependency(nameof(ProtoRegistry))]

public class BottleneckPlugin : BaseUnityPlugin
{
public static BottleneckPlugin Instance => _instance;
Expand Down Expand Up @@ -53,12 +50,9 @@ private void Awake()
{
Log.logger = Logger;
_instance = this;
using (ProtoRegistry.StartModLoad(PluginInfo.PLUGIN_GUID))
{
Strings.Init();
}
_harmony = new Harmony(PluginInfo.PLUGIN_GUID);
_harmony.PatchAll(typeof(BottleneckPlugin));
_harmony.PatchAll(typeof(Strings));
PluginConfig.InitConfig(Config);
Log.Info($"Plugin {PluginInfo.PLUGIN_GUID} {PluginInfo.PLUGIN_VERSION} is loaded!");

Expand Down Expand Up @@ -270,9 +264,9 @@ public static void UIStatisticsWindow__ValueToAstroBox_Postfix(UIStatisticsWindo
if (!__instance.isDysonTab && __instance.gameData.localPlanet != null && instanceAstroBox.Items.Count > 2)
{
int starId = __instance.gameData.localStar.id;
if (instanceAstroBox.Items[2] != "localSystemLabel".Translate(PluginConfig.GetLanguage()))
if (instanceAstroBox.Items[2] != Strings.LocalSystemLabel)
{
instanceAstroBox.Items.Insert(2, "localSystemLabel".Translate(PluginConfig.GetLanguage()));
instanceAstroBox.Items.Insert(2, Strings.LocalSystemLabel);
instanceAstroBox.ItemsData.Insert(2, starId * 100);
}
}
Expand All @@ -297,7 +291,7 @@ public static void UIStatisticsWindow__ValueToAstroBox_Postfix(UIStatisticsWindo
// hide star systems, unless we get a hit for one of stars in system
currentSystemId = astroId;
var starName = UIRoot.instance.uiGame.statWindow.gameData.galaxy.StarById(astroId / 100).displayName;
currentSystemName = starName + "空格行星系".Translate(PluginConfig.GetLanguage());
currentSystemName = starName + "空格行星系".Translate();
}
else
{
Expand Down Expand Up @@ -492,7 +486,7 @@ public BottleneckProductEntryElement GetEnhanceElement(UIProductEntry productEnt

public void GetPrecursorButtonTip(int productId, out string tipTitle, out string tipText)
{
tipTitle = "prodDetailsLabel".Translate(PluginConfig.GetLanguage());
tipTitle = Strings.ProdDetailsLabel;
tipText = "";

if (NebulaCompat.IsClient)
Expand All @@ -503,13 +497,13 @@ public void GetPrecursorButtonTip(int productId, out string tipTitle, out string
}

if (ItemUtil.HasPrecursors(productId))
tipTitle += "clickPrecursorText".Translate(PluginConfig.GetLanguage());
tipTitle += Strings.ClickPrecursorText;
if (_productionLocations.ContainsKey(productId))
{
if (_enableMadeOn)
{
var parensMessage = ItemUtil.HasPrecursors(productId) ? "controlClickLacking".Translate(PluginConfig.GetLanguage()) : "";
var producedOnText = "producedOnLabel".Translate(PluginConfig.GetLanguage());
var parensMessage = ItemUtil.HasPrecursors(productId) ? Strings.ControlClickLacking : "";
var producedOnText = Strings.ProducedOnLabel;
tipText = $"{parensMessage}<b>{producedOnText}</b>\r\n" + _productionLocations[productId].GetProducerSummary();
if (_productionLocations[productId].PlanetCount() > PluginConfig.productionPlanetCount.Value)
tipTitle += $" (top {PluginConfig.productionPlanetCount.Value} / {_productionLocations[productId].PlanetCount()} planets)";
Expand All @@ -527,7 +521,7 @@ public void GetPrecursorButtonTip(int productId, out string tipTitle, out string

public void GetSuccessorButtonTip(int productId, out string tipTitle, out string tipText)
{
tipTitle = "conDetailsLabel".Translate(PluginConfig.GetLanguage());
tipTitle = Strings.ConDetailsLabel;
tipText = "";

if (NebulaCompat.IsClient)
Expand All @@ -538,10 +532,10 @@ public void GetSuccessorButtonTip(int productId, out string tipTitle, out string
}

if (ItemUtil.HasConsumers(productId))
tipTitle += "clickConsumingText".Translate(PluginConfig.GetLanguage());
tipTitle += Strings.ClickConsumingText;
if (_productionLocations.ContainsKey(productId) && _enableMadeOn)
{
var consumedOnText = "consumedOnLabel".Translate(PluginConfig.GetLanguage());
var consumedOnText = Strings.ConsumedOnLabel;

tipText = $"<b>{consumedOnText}</b>\r\n" + _productionLocations[productId].GetConsumerSummary();
if (_productionLocations[productId].ConsumerPlanetCount() > PluginConfig.productionPlanetCount.Value)
Expand Down Expand Up @@ -753,7 +747,7 @@ private void AddEnablePrecursorFilterButton(UIStatisticsWindow uiStatisticsWindo
rectTxt.anchoredPosition = new Vector2(20, 0);
objsToDestroy.Add(rectTxt.gameObject);
Text text = rectTxt.gameObject.AddComponent<Text>();
text.text = "clearFilterLabel".Translate(PluginConfig.GetLanguage());
text.text = Strings.ClearFilterLabel;
text.fontStyle = FontStyle.Normal;
text.fontSize = 12;
text.verticalOverflow = VerticalWrapMode.Overflow;
Expand Down
7 changes: 4 additions & 3 deletions PlanetaryProductionSummary.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Bottleneck.UI;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -140,7 +141,7 @@ public string GetProducerSummary()
return _prodSummary;
}

var producersLabel = "producersLabel".Translate(PluginConfig.GetLanguage()).ToLowerInvariant();
var producersLabel = Strings.ProducersLabel;
var includedElements = _productions.GetRange(0, Math.Min(PluginConfig.productionPlanetCount.Value, _productions.Count))
.Select(prod => $"{prod.PlanetName}: {producersLabel}={prod.Producers}");
_prodSummary = string.Join("\n", includedElements);
Expand All @@ -154,7 +155,7 @@ public string GetConsumerSummary()
{
return _consumerSummary;
}
var consLabel = "consumersLabel".Translate(PluginConfig.GetLanguage()).ToLowerInvariant();
var consLabel = Strings.ConsumersLabel;
var includedElements = _consumers.GetRange(0, Math.Min(PluginConfig.productionPlanetCount.Value, _consumers.Count))
.Select(cons => $"{cons.PlanetName}: {consLabel}={cons.Consumers}");
_consumerSummary = string.Join("\n", includedElements);
Expand Down
25 changes: 1 addition & 24 deletions PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public static class PluginConfig
public static ConfigEntry<bool> systemFilter;
public static ConfigEntry<bool> includeSecondLevelConsumerProducer;
public static ConfigEntry<bool> disableItemHoverTip;
private static ConfigEntry<string> testOverrideLanguage;


public static void InitConfig(ConfigFile confFile)
Expand Down Expand Up @@ -49,28 +48,6 @@ public static void InitConfig(ConfigFile confFile)
"Tells mod to ignore unlocked tech for stacking items on belts. By default uses same 'Tech Limit' value as stations use");
statsOnly = confFile.Bind("Stats", "Disable Bottleneck", false,
"Disable Bottleneck functionality, use only BetterStats features");
var languages = Enum.GetNames(typeof(Language)).ToList().FindAll(l => l.ToString().Length == 4);
languages.Add("");
testOverrideLanguage = confFile.Bind("Internal", "TEST override language", "",
new ConfigDescription("Force an alt language to be used (for some text)",
new AcceptableValueList<string>(
languages.ToArray()
)));
// force this setting to empty so that it has to be set at runtime and can't be left on by accident
testOverrideLanguage.Value = "";
}

public static Language GetLanguage()
{
if (testOverrideLanguage.Value.Length > 0)
{
if (Enum.TryParse(testOverrideLanguage.Value, true, out Language newLang))
{
return newLang;
}

}
return Localization.language;
}
}
}
}
6 changes: 3 additions & 3 deletions ProductionDeficit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static ProductionDeficitItem FromItem(int itemId, AssemblerComponent asse
for (int i = 0; i < value.neededCount; i++)
{
var requiredItem = LDB.items.Select(assemblerComponent.requires[i]);
value.inputItemNames[i] = requiredItem.Name.Translate(PluginConfig.GetLanguage());
value.inputItemNames[i] = requiredItem.Name.Translate();
value.inputItemId[i] = requiredItem.ID;
value.inputItemIndex[assemblerComponent.requires[i]] = i;
}
Expand All @@ -183,12 +183,12 @@ public static ProductionDeficitItem FromItem(int itemId, LabComponent assemblerC
value = new ProductionDeficitItem
{
neededCount = assemblerComponent.requires.Length,
recipeName = LDB.recipes.Select(recipeId).Name.Translate(PluginConfig.GetLanguage())
recipeName = LDB.recipes.Select(recipeId).Name.Translate()
};
for (int i = 0; i < value.neededCount; i++)
{
var requiredItem = LDB.items.Select(assemblerComponent.requires[i]);
value.inputItemNames[i] = requiredItem.Name.Translate(PluginConfig.GetLanguage());
value.inputItemNames[i] = requiredItem.Name.Translate();
value.inputItemId[i] = requiredItem.ID;
value.inputItemIndex[assemblerComponent.requires[i]] = i;
}
Expand Down
56 changes: 15 additions & 41 deletions Stats/BetterStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Globalization;
using BepInEx.Logging;
using Bottleneck.Nebula;
using Bottleneck.UI;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
Expand Down Expand Up @@ -199,33 +200,6 @@ private static string FormatMetric(float value)
return value.ToString();
}

private static float ReverseFormat(string value)
{
string[] parts = value.Split(' ');
float multiplier;
string numericValue;

if (parts.Length > 1)
{
multiplier = parts[1] == "k" ? 1000 : (parts[1] == "M" ? 1000000 : (parts[1] == "G" ? 1000000000 : 1));
numericValue = parts[0];
}
else
{
multiplier = 1;
numericValue = parts[0].Replace(",", ".");
}

try
{
return float.Parse(numericValue, CultureInfo.InvariantCulture) * multiplier;
}
catch (FormatException ex)
{
throw new ArgumentException("Invalid format String : '" + value + "' (parsed as " + numericValue + " * " + multiplier + ")", nameof(value), ex);
}
}

private static EnhancedUIProductEntryElements EnhanceUIProductEntry(UIProductEntry __instance)
{
var parent = __instance.itemIcon.transform.parent;
Expand Down Expand Up @@ -297,29 +271,29 @@ private static EnhancedUIProductEntryElements EnhanceUIProductEntry(UIProductEnt
__instance.consumeUnitLabel.GetComponent<RectTransform>().anchoredPosition = new Vector2(initialXOffset + valuesWidth + 4, -4);

var maxProductionLabel = CopyText(__instance.productLabel, new Vector2(maxOffset, 0));
maxProductionLabel.text = "theoreticalMaxLabel".Translate(PluginConfig.GetLanguage());
maxProductionLabel.text = Strings.TheoreticalMaxLabel;
var maxProductionValue = CopyText(__instance.productText, new Vector2(maxOffset, 0));
maxProductionValue.text = "0";
var maxProductionUnit = CopyText(__instance.productUnitLabel, new Vector2(maxOffset, 0));
maxProductionUnit.text = "perMinLabel".Translate(PluginConfig.GetLanguage());
maxProductionUnit.text = Strings.PerMinLabel;

var maxConsumptionLabel = CopyText(__instance.consumeLabel, new Vector2(maxOffset, 0));
maxConsumptionLabel.text = "theoreticalMaxLabel".Translate(PluginConfig.GetLanguage());
maxConsumptionLabel.text = Strings.TheoreticalMaxLabel;
var maxConsumptionValue = CopyText(__instance.consumeText, new Vector2(maxOffset, 0));
maxConsumptionValue.text = "0";
var maxConsumptionUnit = CopyText(__instance.consumeUnitLabel, new Vector2(maxOffset, 0));
maxConsumptionUnit.text = "perMinLabel";
maxConsumptionUnit.text = Strings.PerMinLabel;

var counterProductionLabel = CopyText(__instance.productLabel, new Vector2(-initialXOffset, 0));
counterProductionLabel.GetComponent<RectTransform>().sizeDelta = new Vector2(60, 40);
counterProductionLabel.text = "producersLabel".Translate(PluginConfig.GetLanguage());
counterProductionLabel.text = Strings.ProducersLabel;
var counterProductionValue = CopyText(__instance.productText, new Vector2(-initialXOffset, 0));
counterProductionValue.GetComponent<RectTransform>().sizeDelta = new Vector2(60, 40);
counterProductionValue.text = "0";

var counterConsumptionLabel = CopyText(__instance.consumeLabel, new Vector2(-initialXOffset, 0));
counterConsumptionLabel.GetComponent<RectTransform>().sizeDelta = new Vector2(60, 40);
counterConsumptionLabel.text = "consumersLabel".Translate(PluginConfig.GetLanguage());
counterConsumptionLabel.text = Strings.ConsumersLabel;
var counterConsumptionValue = CopyText(__instance.consumeText, new Vector2(-initialXOffset, 0));
counterConsumptionValue.GetComponent<RectTransform>().sizeDelta = new Vector2(60, 40);
counterConsumptionValue.text = "0";
Expand Down Expand Up @@ -419,7 +393,7 @@ public static void UIStatisticsWindow__OnOpen_Postfix(UIStatisticsWindow __insta
rectTxt.anchoredPosition = new Vector2(20, 0);

Text text = rectTxt.gameObject.AddComponent<Text>();
text.text = "dispPerSecLabel".Translate(PluginConfig.GetLanguage());
text.text = Strings.DispPerSecLabel;
text.fontStyle = FontStyle.Normal;
text.fontSize = 14;
text.verticalOverflow = VerticalWrapMode.Overflow;
Expand Down Expand Up @@ -468,7 +442,7 @@ public static void UIStatisticsWindow__OnOpen_Postfix(UIStatisticsWindow __insta
_placeholder.alignment = TextAnchor.MiddleLeft;
_placeholder.supportRichText = false;
_placeholder.horizontalOverflow = HorizontalWrapMode.Overflow;
_placeholder.text = "filterLabel".Translate(PluginConfig.GetLanguage());
_placeholder.text = Strings.FilterLabel;
(_placeholder.transform as RectTransform).sizeDelta = new Vector2(90, 30);
(_placeholder.transform as RectTransform).anchoredPosition = new Vector2(5, 0);

Expand Down Expand Up @@ -548,16 +522,16 @@ public static void UIProductEntry__OnUpdate_Postfix(UIProductEntry __instance)
string originalProductText = __instance.productText.text.Trim();
string originalConsumeText = __instance.consumeText.text.Trim();


float originalProductValue = ReverseFormat(originalProductText);
float originalConsumeValue = ReverseFormat(originalConsumeText);
float lvDivisor = isTotalTimeWindow ? 1f : (float)__instance.lvDivisors[__instance.productionStatWindow.timeLevel];
float originalProductValue = __instance.entryData.production / lvDivisor;
float originalConsumeValue = __instance.entryData.consumption / lvDivisor;

string producers = "0";
string consumers = "0";
string maxProduction = "0";
string maxConsumption = "0";
string unitRate = PluginConfig.displayPerSecond.Value ? "perSecLabel".Translate(PluginConfig.GetLanguage()) : "perMinLabel".Translate(PluginConfig.GetLanguage());
string unit = isTotalTimeWindow ? "" : "perMinLabel".Translate(PluginConfig.GetLanguage());
string unitRate = PluginConfig.displayPerSecond.Value ? Strings.PerSecLabel : Strings.PerMinLabel;
string unit = isTotalTimeWindow ? "" : Strings.PerMinLabel;
int divider = 1;
bool alertOnLackOfProduction = false;
bool warnOnHighMaxConsumption = false;
Expand All @@ -566,7 +540,7 @@ public static void UIProductEntry__OnUpdate_Postfix(UIProductEntry __instance)
if (PluginConfig.displayPerSecond.Value)
{
divider = 60;
unit = !isTotalTimeWindow ? "perSecLabel".Translate(PluginConfig.GetLanguage()) : unit;
unit = !isTotalTimeWindow ? Strings.PerSecLabel : unit;

if (!isTotalTimeWindow)
{
Expand Down
2 changes: 1 addition & 1 deletion UI/BottleneckProductEntryElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static UIButton CopyButton(UIProductEntry uiProductEntry, UIButton button

private static string GetItemName(int itemId)
{
return LDB.items.Select(itemId).Name.Translate(PluginConfig.GetLanguage());
return LDB.items.Select(itemId).Name.Translate();
}
}
}
Loading