From 86818197d848a9d718176dc182e55482ecbcf900 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Mon, 4 Mar 2024 03:19:37 +0800 Subject: [PATCH] UXAssist v1.0.14 & bugfix --- UXAssist/FactoryPatch.cs | 45 ++++++++++++++++++++++++++++++---- UXAssist/PlanetFunctions.cs | 9 +++++++ UXAssist/README.md | 8 +++++- UXAssist/UXAssist.csproj | 2 +- UXAssist/package/manifest.json | 2 +- 5 files changed, 58 insertions(+), 8 deletions(-) diff --git a/UXAssist/FactoryPatch.cs b/UXAssist/FactoryPatch.cs index acebd26..fadf03a 100644 --- a/UXAssist/FactoryPatch.cs +++ b/UXAssist/FactoryPatch.cs @@ -547,7 +547,17 @@ public static class FactoryPatch _patch = null; } - private static void CalculateGridOffset(PlanetData planet, Vector3 pos, out float x, out float y) + private static bool _initialized; + [HarmonyPostfix, HarmonyPatch(typeof(UIRoot), "_OnOpen")] + public static void UIRoot__OnOpen_Postfix() + { + if (_initialized) return; + UIGeneralTips.instance.buildCursorTextComp.supportRichText = true; + UIGeneralTips.instance.entityBriefInfo.entityNameText.supportRichText = true; + _initialized = true; + } + + private static void CalculateGridOffset(PlanetData planet, Vector3 pos, out float x, out float y, out float z) { var npos = pos.normalized; var segment = planet.aux.activeGrid?.segment ?? 200; @@ -558,8 +568,19 @@ public static class FactoryPatch var longitudeRad = BlueprintUtils.GetLongitudeRad(npos); x = longitudeRad / longitudeRadPerGrid; y = latitudeRad / latitudeRadPerGrid; + z = (pos.magnitude - planet.realRadius - 0.2f) / 1.3333333f; } + private static string FixedPoint(float f) + { + var s = Mathf.RoundToInt(f * 10000); + return $"{s / 10000}.{Math.Abs(s % 10000)}".TrimEnd('0').TrimEnd('.'); + } + + private static PlanetData _lastPlanet; + private static Vector3 _lastPos; + private static string _lastOffsetText; + [HarmonyPostfix] [HarmonyPriority(Priority.Last), HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click.CheckBuildConditions))] private static void BuildTool_Click_CheckBuildConditions_Postfix(BuildTool_Click __instance) @@ -567,8 +588,15 @@ public static class FactoryPatch if (__instance.buildPreviews.Count != 1) return; var preview = __instance.buildPreviews[0]; if (preview.desc.isInserter) return; - CalculateGridOffset(__instance.planet, preview.lpos, out var x, out var y); - __instance.actionBuild.model.cursorText = $"({x},{y})\n" + __instance.actionBuild.model.cursorText; + var planet = __instance.planet; + if (_lastPlanet != planet || _lastPos != preview.lpos) + { + CalculateGridOffset(__instance.planet, preview.lpos, out var x, out var y, out var z); + _lastPlanet = planet; + _lastPos = preview.lpos; + _lastOffsetText = $"{FixedPoint(x)},{FixedPoint(y)},{FixedPoint(z)}"; + } + __instance.actionBuild.model.cursorText = $"({_lastOffsetText})\n" + __instance.actionBuild.model.cursorText; } [HarmonyTranspiler] @@ -587,8 +615,15 @@ public static class FactoryPatch { var entity = entityBriefInfo.factory.entityPool[entityBriefInfo.entityId]; if (entity.inserterId > 0) return; - CalculateGridOffset(entityBriefInfo.factory.planet, entity.pos, out var x, out var y); - entityBriefInfo.entityNameText.text += $" ({x},{y})"; + var planet = entityBriefInfo.factory.planet; + if (_lastPlanet != planet || _lastPos != entity.pos) + { + CalculateGridOffset(planet, entity.pos, out var x, out var y, out var z); + _lastPlanet = planet; + _lastPos = entity.pos; + _lastOffsetText = $"{FixedPoint(x)},{FixedPoint(y)},{FixedPoint(z)}"; + } + entityBriefInfo.entityNameText.text += $" ({_lastOffsetText})"; } ) ); diff --git a/UXAssist/PlanetFunctions.cs b/UXAssist/PlanetFunctions.cs index 03c9d40..be852fc 100644 --- a/UXAssist/PlanetFunctions.cs +++ b/UXAssist/PlanetFunctions.cs @@ -51,6 +51,13 @@ public static class PlanetFunctions var planet = GameMain.localPlanet; var factory = planet?.factory; if (factory == null) return; + var uiGame = UIRoot.instance.uiGame; + if (uiGame) + { + uiGame.ShutAllFunctionWindow(); + uiGame.ShutAllFullScreens(); + } + GameMain.data.mainPlayer?.controller.actionBuild.Close(); //planet.data = new PlanetRawData(planet.precision); //planet.data.CalcVerts(); for (var id = factory.entityCursor - 1; id > 0; id--) @@ -152,6 +159,8 @@ public static class PlanetFunctions factory.enemyRecycleCursor = 0; factory.enemyCapacity = 0; factory.SetEnemyCapacity(isCombatMode ? 1024 : 32); + factory.hashSystemDynamic = new HashSystem(); + factory.hashSystemStatic = new HashSystem(); factory.cargoContainer = new CargoContainer(); factory.cargoTraffic = new CargoTraffic(planet); factory.blockContainer = new MiniBlockContainer(); diff --git a/UXAssist/README.md b/UXAssist/README.md index fcf5dd1..e0819d7 100644 --- a/UXAssist/README.md +++ b/UXAssist/README.md @@ -4,8 +4,11 @@ #### 一些提升用户体验的功能和补丁 ## Changlog +* 1.0.14 + + Fix crash in `Re-initialize planet` again + + `Off-grid building and stepped rotation`: Add Z coordinate to display, and adjust the precision to 4 decimal after point * 1.0.13 - + `Off-grid building and stepped rotation`: show building coorinates(relative to grids) on building preview and building info panel now + + `Off-grid building and stepped rotation`: show building coordinates(relative to grids) on building preview and building info panel now + Increase maximum count of Metadata Instantiations to 20000 (from 2000) + Increase capacity of player order queue to 128 (from 16) + Fix issue caused by game updates @@ -101,6 +104,9 @@ * [OffGridConstruction](https://github.com/Velociraptor115-DSPModding/OffGridConstruction): Off-grid building & stepped rotation implementations ## 更新日志 +* 1.0.14 + + 再次尝试修复`初始化本行星`导致的崩溃问题 + + `脱离网格建造和小角度旋转`:现在显示建筑Z坐标,并将精度调整为小数点后4位 * 1.0.13 + `脱离网格建造和小角度旋转`:现在在建造预览和建筑信息面板上显示建筑坐标(相对于网格) + 将元数据提取的最大数量增加到20000(原来为2000) diff --git a/UXAssist/UXAssist.csproj b/UXAssist/UXAssist.csproj index 274eb26..34934e5 100644 --- a/UXAssist/UXAssist.csproj +++ b/UXAssist/UXAssist.csproj @@ -4,7 +4,7 @@ net472 org.soardev.uxassist DSP MOD - UXAssist - 1.0.13 + 1.0.14 true latest UXAssist diff --git a/UXAssist/package/manifest.json b/UXAssist/package/manifest.json index 1c59e4f..53970e3 100644 --- a/UXAssist/package/manifest.json +++ b/UXAssist/package/manifest.json @@ -1,6 +1,6 @@ { "name": "UXAssist", - "version_number": "1.0.13", + "version_number": "1.0.14", "website_url": "https://github.com/soarqin/DSP_Mods/tree/master/UXAssist", "description": "Some functions and patches for better user experience / 一些提升用户体验的功能和补丁", "dependencies": [