diff --git a/ModKit/ModKit/LocalizationManager.cs b/ModKit/ModKit/LocalizationManager.cs index 248758c9e..706a223d7 100644 --- a/ModKit/ModKit/LocalizationManager.cs +++ b/ModKit/ModKit/LocalizationManager.cs @@ -39,23 +39,30 @@ public static class LocalizationManager { public static string FilePath { get; private set; } public static void Enable() { - isEnabled = true; - IsDefault = true; - _local = null; - _localDefault = null; - var separator = Path.DirectorySeparatorChar; - _localFolderPath = Mod.modEntry.Path + "Localization" + separator; - FilePath = _localFolderPath + "en"; - _localDefault = Import(); - if (_localDefault == null) { - _localDefault = new(); - _localDefault.Strings = new(); + try { + isEnabled = true; + IsDefault = true; + _local = null; + _localDefault = null; + var separator = Path.DirectorySeparatorChar; + _localFolderPath = Mod.modEntry.Path + "Localization" + separator; + FilePath = _localFolderPath + "en"; + _localDefault = Import(); + if (_localDefault == null) { + _localDefault = new(); + _localDefault.Strings = new(); + } + var chosenLangauge = Mod.ModKitSettings.uiCultureCode; + FilePath = _localFolderPath + chosenLangauge; + if (chosenLangauge != "en") { + _local = Import(); + IsDefault = _local == null; + } + } - var chosenLangauge = Mod.ModKitSettings.uiCultureCode; - FilePath = _localFolderPath + chosenLangauge; - if (chosenLangauge != "en") { - _local = Import(); - IsDefault = _local == null; + catch (Exception ex) { + Mod.Error("Could not load localization files!"); + Mod.Warn(ex.ToString()); } } public static void Update() { diff --git a/ModKit/ModKit/SettingsController.cs b/ModKit/ModKit/SettingsController.cs index 3f2cde926..110cca0b3 100644 --- a/ModKit/ModKit/SettingsController.cs +++ b/ModKit/ModKit/SettingsController.cs @@ -43,7 +43,7 @@ public static void SaveSettings(this ModEntry modEntry, string fileName, T se try { var userSettings = JsonConvert.DeserializeObject(reader.ReadToEnd()); if (userSettings is IUpdatableSettings updatableSettings) updatableSettings?.AddMissingKeys((IUpdatableSettings)settings); - settings = userSettings ?? new(); + settings = userSettings; } catch { Mod.Error("Failed to load user settings. Settings will be rebuilt."); @@ -55,6 +55,7 @@ public static void SaveSettings(this ModEntry modEntry, string fileName, T se } } } + settings ??= new(); File.WriteAllText(userPath, JsonConvert.SerializeObject(settings, Formatting.Indented)); } } diff --git a/ModKit/UI/UI+Browser.cs b/ModKit/UI/UI+Browser.cs index bfbfe160e..4a961996f 100644 --- a/ModKit/UI/UI+Browser.cs +++ b/ModKit/UI/UI+Browser.cs @@ -93,8 +93,8 @@ public void ResetSearch() { ReloadData(); } public bool needsReloadData = true; - private bool _needsRedoCollation = true; - private bool _collationFinished = false; + internal bool _needsRedoCollation = true; + internal bool _collationFinished = false; public void RedoCollation() { _needsRedoCollation = true; _collationFinished = false; diff --git a/ToyBox/Info.json b/ToyBox/Info.json index f85c3a7b0..e41bd70fa 100644 --- a/ToyBox/Info.json +++ b/ToyBox/Info.json @@ -2,11 +2,11 @@ "Id": "0ToyBox0", "DisplayName": "{ToyBox} is preparing to conquer the Imperium", "Author": "Narria", - "Version": "1.5.7a", + "Version": "1.5.9", "ManagerVersion": "0.23.0", "Requirements": [], "AssemblyName": "ToyBox.dll", "EntryMethod": "ToyBox.Main.Load", "HomePage": "https://www.nexusmods.com/pathfinderwrathoftherighteous/mods/8?tab=posts&BH=0", - "Repository": "https://raw.githubusercontent.com/cabarius/ToyBox/master/ToyBox/Repository.json" + "Repository": "https://raw.githubusercontent.com/xADDBx/ToyBox/main/ToyBox/Repository.json" } \ No newline at end of file diff --git a/ToyBox/Localization/Wrath/en.json b/ToyBox/Localization/Wrath/en.json index b8bd24870..ffb81930d 100644 --- a/ToyBox/Localization/Wrath/en.json +++ b/ToyBox/Localization/Wrath/en.json @@ -331,7 +331,7 @@ "Enable Loading with Blueprint Errors": "Enable Loading with Blueprint Errors", "Enable Mouse3 Dragging To Aim The Camera": "Enable Mouse3 Dragging To Aim The Camera", "Enable Rotate on all maps and cutscenes": "Enable Rotate on all maps and cutscenes", - "Enable Search as you type for Browsers (needs restart)": "Enable Search as you type for Browsers (needs restart)" + "Enable Search as you type for Browsers (needs restart)": "Enable Search as you type for Browsers (needs restart)", "Enable Teleport Keys": "Enable Teleport Keys", "Enable Zoom on all maps and cutscenes": "Enable Zoom on all maps and cutscenes", "Enabled Search Filters": "Enabled Search Filters", diff --git a/ToyBox/ReadMe.md b/ToyBox/ReadMe.md index c3043c413..efbe1e7cc 100644 --- a/ToyBox/ReadMe.md +++ b/ToyBox/ReadMe.md @@ -73,14 +73,21 @@ * **Quest Resolution**: this allows you to view your active quests and advance them as needed to work around bugs or skip quests you don't want to do. Be warned this may break your game progression if used carelessly. -### ToyBox Rogue - Ver 1.5.8 (Coming Soon) -**ToyBox Rogue - Ver 1.5.8 -** ***Sh0dan*** **Preview Version 1.5.7a** built for 0.2.1ah -* (***ADDB***) Fixed weird behaviour when changing stats using the Textfield. -### ToyBox Wrath - Ver 1.5.8 (Coming Soon) -**ToyBox Wrath - Ver 1.5.8 - Preview Version 1.5.7a** built for 2.1.5r +### ToyBox Wrath - Ver 1.5.9 (built for 2.2.3c) +**ToyBox Wrath - Ver 1.5.9 - Preview Version 1.5.8b** built for 2.2.0av +* (***evandixon***) Fix unusable map screen on console view (e.g. PC Controller User & Steam Deck) +* (***ADDB***) Fixed Search 'n Pick - missing key update if collation happens too fast. +* (***ADDB***) Recompiled against new binaries. +* (***ADDB***) Temporarily change repository link to my Fork until Narria's one is active again. + +### ToyBox Wrath - Ver 1.5.8 (built for 2.2.0as) * (***ADDB***) Ride everything now really allows riding everything. Looks ridiculous but still. * (***ADDB***) Fixed weird behaviour when changing stats using the Textfield. -* * (***ifarmpandas***) Added ActivatableAbilities to "Abilities" button in party editor. +* (***ADDB***) Prevent mod from being unable to load when localization files are missing. +* (***ADDB***) Improved detection and added auto-deletion of concurrently installed outdated ToyBox version. +* (***ifarmpandas***) Added ActivatableAbilities to "Abilities" button in party editor. +* (***ADDB***) Recompile for new version. +* (***ADDB***) Fixed some whoopsies (missing Localization files in Release; Wrong Repository Branch in Info file etc.). ### ToyBox Rogue - Ver 1.5.7 (built for 0.2.1ah) * (***ADDB***) Added all localization keys to allow full localization. ### ToyBox Wrath - Ver 1.5.7 (built for 2.1.5r) diff --git a/ToyBox/Repository.json b/ToyBox/Repository.json index c619e9d3e..b6951fd0c 100644 --- a/ToyBox/Repository.json +++ b/ToyBox/Repository.json @@ -1,8 +1,8 @@ { "Releases": [ { - "Id": "ToyBox", - "Version": "1.5.7a" + "Id": "0ToyBox0", + "Version": "1.5.9" } ] } \ No newline at end of file diff --git a/ToyBox/ToyBox.csproj b/ToyBox/ToyBox.csproj index 0f4fdae54..641d347a9 100644 --- a/ToyBox/ToyBox.csproj +++ b/ToyBox/ToyBox.csproj @@ -313,7 +313,8 @@ - + + Localization\%(Filename)%(Extension) Always diff --git a/ToyBox/ToyBoxRT.csproj b/ToyBox/ToyBoxRT.csproj index 7a094ceda..10de26869 100644 --- a/ToyBox/ToyBoxRT.csproj +++ b/ToyBox/ToyBoxRT.csproj @@ -45,6 +45,7 @@ + @@ -432,6 +433,18 @@ $(RoguePath)\WH40KRT_Data\Managed\Utility.UnityExtensions.dll False + + ..\lib\RT\RogueTrader.GameCore_public.dll + False + + + $(RoguePath)\WH40KRT_Data\Managed\RogueTrader.SharedTypes.dll + False + + + $(RoguePath)\WH40KRT_Data\Managed\RogueTrader.NetPlayer.dll + False + @@ -537,7 +550,8 @@ - + + Localization\%(Filename)%(Extension) Always diff --git a/ToyBox/classes/MainUI/Browser/SearchAndPick.cs b/ToyBox/classes/MainUI/Browser/SearchAndPick.cs index d5327c9be..5ad70930e 100644 --- a/ToyBox/classes/MainUI/Browser/SearchAndPick.cs +++ b/ToyBox/classes/MainUI/Browser/SearchAndPick.cs @@ -218,8 +218,8 @@ public static void RedoLayout() { } public static void OnGUI() { - if (Event.current.type == EventType.Layout && (SearchAndPickBrowser.isCollating || needsRedoKeys)) { - needsRedoKeys = SearchAndPickBrowser.isCollating; + if (Event.current.type == EventType.Layout && needsRedoKeys) { + needsRedoKeys = SearchAndPickBrowser.isCollating || SearchAndPickBrowser._needsRedoCollation; var count = SearchAndPickBrowser.collatedDefinitions.Keys.Count; var tmp = new string[(int)(1.1 * count) + 10]; SearchAndPickBrowser.collatedDefinitions.Keys.CopyTo(tmp, 0); @@ -529,11 +529,13 @@ where selectedTypeFilter.filter(bp) RedoLayout(); bpCount = bps.Count(); SearchAndPickBrowser.RedoCollation(); + needsRedoKeys = true; } public static void ResetGUI() { RedoLayout(); SearchAndPickBrowser.RedoCollation(); + needsRedoKeys = true; } } } \ No newline at end of file diff --git a/ToyBox/classes/MainUI/EnhancedUI/ItemRarity.cs b/ToyBox/classes/MainUI/EnhancedUI/ItemRarity.cs index cbd06b4f0..e12b3a117 100644 --- a/ToyBox/classes/MainUI/EnhancedUI/ItemRarity.cs +++ b/ToyBox/classes/MainUI/EnhancedUI/ItemRarity.cs @@ -80,6 +80,8 @@ public static RarityType Rarity(this int rating) { return rarity; } public static int Rating(this BlueprintItemEnchantment bp) { + // This is impossible, but appearently a user might've encountered this in issue #1061 + if (bp == null) return 0; #if Wrath int rating; diff --git a/ToyBox/classes/MainUI/Main.cs b/ToyBox/classes/MainUI/Main.cs index c371679d6..78027199a 100644 --- a/ToyBox/classes/MainUI/Main.cs +++ b/ToyBox/classes/MainUI/Main.cs @@ -22,6 +22,7 @@ using static ModKit.UI; using LocalizationManager = ModKit.LocalizationManager; using Kingmaker.UI.Common; +using Newtonsoft.Json; #if RT using Kingmaker.UI.Models.Log.CombatLog_ThreadSystem.LogThreads.LifeEvents; #endif @@ -156,20 +157,15 @@ private static bool OnUnload(UnityModManager.ModEntry modEntry) { private static void LoadSettings(UnityModManager.ModEntry modEntry) { var thisToyBoxPath = modEntry.Path; var thisSettingsPath = Path.Combine(thisToyBoxPath, "Settings.xml"); - if (!File.Exists(thisSettingsPath)) { - try { - Mod.Log("Settings file not found attempting to migrate from older ToyBox".yellow()); -#if Wrath - var otherToyBoxPath = Path.Combine(UnityModManager.modsPath, "ToyBox"); -#elif RT - var otherToyBoxPath = Path.Combine(UnityModManager.ModsPath, "ToyBox"); -#endif - Mod.Log($"Checking {otherToyBoxPath}"); - if (Directory.Exists(otherToyBoxPath)) { - Mod.Log($" Found older ToyBox at {otherToyBoxPath} migrating all settings"); - File.Copy(Path.Combine(otherToyBoxPath, "Settings.xml"), thisSettingsPath); + var oldToyBoxPath = CheckForOldToyBox(modEntry); + try { + if (!oldToyBoxPath.IsNullOrEmpty()) { + if (!File.Exists(thisSettingsPath)) { + Mod.Log("Settings file not found attempting to migrate from older ToyBox".yellow()); + Mod.Log($"Checking {oldToyBoxPath}"); + File.Copy(Path.Combine(oldToyBoxPath, "Settings.xml"), thisSettingsPath); var thisUserSettingsPath = Path.Combine(thisToyBoxPath, "UserSettings"); - var otherUserSettingsPath = Path.Combine(otherToyBoxPath, "UserSettings"); + var otherUserSettingsPath = Path.Combine(oldToyBoxPath, "UserSettings"); Directory.CreateDirectory(thisUserSettingsPath); var allFiles = Directory.GetFiles(otherUserSettingsPath, "*.*", SearchOption.AllDirectories); foreach (string otherPath in allFiles) { @@ -179,17 +175,59 @@ private static void LoadSettings(UnityModManager.ModEntry modEntry) { } Mod.Log("ToyBox settings migration => SUCCESS".green()); } - else { - Mod.Log("Other ToyBox not found... creating default settings".yellow()); - } + Mod.Warn("Removing old detected ToyBox version!"); + File.Delete(oldToyBoxPath + UnityModManager.Config.ModInfo); + File.Delete(oldToyBoxPath + "Repository.json"); + File.Delete(oldToyBoxPath + "ToyBox.dll"); + File.Delete(oldToyBoxPath + "ToyBox.pdb"); + // Directory.Delete(oldToyBoxPath, true); } - catch (Exception e) { - Mod.Error(e); + else { + if (!File.Exists(thisSettingsPath)) { + Mod.Log("No old ToyBox version found... creating default settings".yellow()); + } } } + catch (Exception e) { + Mod.Error(e); + } Settings = UnityModManager.ModSettings.Load(modEntry); } + private static string CheckForOldToyBox(UnityModManager.ModEntry modEntry) { + try { + var x = Directory.GetCurrentDirectory(); + var mods = Directory.GetDirectories(x + "/Mods"); + foreach (var mod in mods) { + foreach (var file in Directory.GetFiles(mod)) { + if (new FileInfo(file).Name == "ToyBox.dll" && (new DirectoryInfo(mod).FullName + @"\") != new DirectoryInfo(modEntry.Path).FullName) { + var modDir = mod + @"\"; + try { + using (StreamReader modInfoFile = File.OpenText(modDir + UnityModManager.Config.ModInfo)) { + var modInfo = JsonConvert.DeserializeObject(modInfoFile.ReadToEnd()); + if (UnityModManager.ParseVersion(modInfo.Version) > modEntry.Version) { + // The current Assembly is the old version? + return null; + } // The current Assembly is the new version! + else { + return modDir; + } + + } + } // Couldn't find/read info.json + catch (Exception e) { + Mod.Error(e); + } + return modDir; + } + } + } + } + catch (Exception e) { + Mod.Error(e); + } + return null; + } private static bool OnToggle(UnityModManager.ModEntry modEntry, bool value) { Enabled = value; return true; diff --git a/ToyBox/classes/MonkeyPatchin/EnhancedUI/LocalMap.cs b/ToyBox/classes/MonkeyPatchin/EnhancedUI/LocalMap.cs index 5d62682b5..c6dff6d0e 100644 --- a/ToyBox/classes/MonkeyPatchin/EnhancedUI/LocalMap.cs +++ b/ToyBox/classes/MonkeyPatchin/EnhancedUI/LocalMap.cs @@ -58,7 +58,7 @@ public static bool OnClick(LocalMapVM __instance, Vector2 localPos, bool state) if (false && !Settings.toggleZoomableLocalMaps) return true; var vector3 = LocalMapRenderer.Instance.ViewportToWorldPoint( new Vector2( - localPos.x / (__instance.DrawResult.Value.ColorRT.width), + localPos.x / (__instance.DrawResult.Value.ColorRT.width), localPos.y / (__instance.DrawResult.Value.ColorRT.height) ) ); @@ -87,13 +87,13 @@ private static bool SetMarkers(LocalMapVM __instance) { if (Game.Instance.Player.CapitalPartyMode) first = first.Concat(Game.Instance.Player.RemoteCompanions.Where(u => !u.IsCustomCompanion())); foreach (var unit in first) - if (unit.View != null - && unit.View.enabled + if (unit.View != null + && unit.View.enabled && !unit #if RT .LifeState #endif - .IsHiddenBecauseDead + .IsHiddenBecauseDead && LocalMapModel.IsInCurrentArea(unit.Position) ) { __instance.MarkersVm.Add(new LocalMapCharacterMarkerVM(unit)); @@ -152,74 +152,79 @@ public static bool SetDrawResult(LocalMapBaseView __instance, LocalMapRenderer.D __instance.SetupBPRVisible(); // Now ToyBox wants to rock your world. We grab various transforms - var contentGroup = UIHelpers.LocalMapScreen.Find("ContentGroup"); // Overall map view including the compass - var mapBlock = UIHelpers.LocalMapScreen.Find("ContentGroup/MapBlock"); // Container for map, border, markers and the frame - var map = mapBlock.Find("Map"); // Just the map - var frameBlock = mapBlock.Find("Map/FrameBlock"); // Camera viewport projected onto the map - var frame = frameBlock.Find("Frame"); // intermediate container for the FrameBlock - if (contentGroup is RectTransform contentGroupRect - && mapBlock is RectTransform mapBlockRect - && map is RectTransform mapRect - && frameBlock is RectTransform frameBlockRect - && frame is RectTransform frameRect - ) { - if (Settings.toggleZoomableLocalMaps) { - // Calculate a zoom factor based on info used previously to scale the Frame Block. In our new world we will center the Frame Block in middle of the ContentGroup and then pan the map behind it. TODO - make it rotate so that it matches exactly the view of the camera (Frame Block will always point up) - var worldWidth = (dr.WorldRect.z - dr.WorldRect.x); - var fovMultiplier = Settings.AdjustedFovMultiplier; - var worldZoom = worldWidth / (fovMultiplier * 47f); - Zoom = width / (worldZoom * sizeDelta.x); - //Mod.Log($"zoom: {Zoom} worldZoom: {worldZoom} sizeDelta: {sizeDelta} - screenRect:{dr.ScreenRect.z - dr.ScreenRect.x} worldRec:{dr.WorldRect.z - dr.WorldRect.x} proj:\n{dr.InverseViewProj}"); - // save off the frame rotation so we can fix the camera movement when the map is open - FrameRotation = frame.localEulerAngles; - var zoom = Zoom; - // LocalMapVM_Patch.offset = frameBlockRect.localPosition * LocalMapVM_Patch.zoom; - - // Now adjust the position of the mapBlock to keep the FrameBlock in a fixed position - Position = mapBlock.localPosition; - Position.x = -3 - frameBlockRect.localPosition.x * zoom - width / (2 * worldZoom); // ??? this is a weird correction (make better?) - Position.y = -22 - frameBlockRect.localPosition.y * zoom - width / (4 * worldZoom); // ??? this is a weird correction (make better?) - mapBlock.localPosition = Position; - // Now apply the zoom to MapBlock - var zoomVector = new Vector3(zoom, zoom, 1.0f); - mapBlock.localScale = zoomVector; - //frameBlockRect.localScale = new Vector3(1f,1f, 1.0f); - - // Fix the pivot to ensure we stay centered when we zoom - mapBlockRect.pivot = new Vector2(0.0f, 0.0f); - //Mod.Log($"zoom: {zoomVector}"); - //frameBlockRect.pivot = new Vector2(0.5f, 0.5f); - //mapRect.pivot = new Vector2(0.5f, 0.5f); - if (Math.Abs(zoom - prevZoom) > .001) { - // Now we don't need all the POI and other map markers to get really big when you zoom so we will shrink them to a reasonable size - var shrinkVector = new Vector3(1.5f / zoom, 1.5f / zoom, 1); - - foreach (var markPath in MarksPaths) { - var marks = map.Find(markPath).gameObject.getChildren(); - foreach (var mark in marks) { - if (!mark.transform.localScale.Equals(new Vector3(0, 0, 0))) { - mark.transform.localScale = shrinkVector; + try { + var contentGroup = UIHelpers.LocalMapScreen.Find("ContentGroup"); // Overall map view including the compass + var mapBlock = UIHelpers.LocalMapScreen.Find("ContentGroup/MapBlock"); // Container for map, border, markers and the frame + var map = mapBlock.Find("Map"); // Just the map + var frameBlock = mapBlock.Find("Map/FrameBlock"); // Camera viewport projected onto the map + var frame = frameBlock.Find("Frame"); // intermediate container for the FrameBlock + if (contentGroup is RectTransform contentGroupRect + && mapBlock is RectTransform mapBlockRect + && map is RectTransform mapRect + && frameBlock is RectTransform frameBlockRect + && frame is RectTransform frameRect + ) { + if (Settings.toggleZoomableLocalMaps) { + // Calculate a zoom factor based on info used previously to scale the Frame Block. In our new world we will center the Frame Block in middle of the ContentGroup and then pan the map behind it. TODO - make it rotate so that it matches exactly the view of the camera (Frame Block will always point up) + var worldWidth = (dr.WorldRect.z - dr.WorldRect.x); + var fovMultiplier = Settings.AdjustedFovMultiplier; + var worldZoom = worldWidth / (fovMultiplier * 47f); + Zoom = width / (worldZoom * sizeDelta.x); + //Mod.Log($"zoom: {Zoom} worldZoom: {worldZoom} sizeDelta: {sizeDelta} - screenRect:{dr.ScreenRect.z - dr.ScreenRect.x} worldRec:{dr.WorldRect.z - dr.WorldRect.x} proj:\n{dr.InverseViewProj}"); + // save off the frame rotation so we can fix the camera movement when the map is open + FrameRotation = frame.localEulerAngles; + var zoom = Zoom; + // LocalMapVM_Patch.offset = frameBlockRect.localPosition * LocalMapVM_Patch.zoom; + + // Now adjust the position of the mapBlock to keep the FrameBlock in a fixed position + Position = mapBlock.localPosition; + Position.x = -3 - frameBlockRect.localPosition.x * zoom - width / (2 * worldZoom); // ??? this is a weird correction (make better?) + Position.y = -22 - frameBlockRect.localPosition.y * zoom - width / (4 * worldZoom); // ??? this is a weird correction (make better?) + mapBlock.localPosition = Position; + // Now apply the zoom to MapBlock + var zoomVector = new Vector3(zoom, zoom, 1.0f); + mapBlock.localScale = zoomVector; + //frameBlockRect.localScale = new Vector3(1f,1f, 1.0f); + + // Fix the pivot to ensure we stay centered when we zoom + mapBlockRect.pivot = new Vector2(0.0f, 0.0f); + //Mod.Log($"zoom: {zoomVector}"); + //frameBlockRect.pivot = new Vector2(0.5f, 0.5f); + //mapRect.pivot = new Vector2(0.5f, 0.5f); + if (Math.Abs(zoom - prevZoom) > .001) { + // Now we don't need all the POI and other map markers to get really big when you zoom so we will shrink them to a reasonable size + var shrinkVector = new Vector3(1.5f / zoom, 1.5f / zoom, 1); + + foreach (var markPath in MarksPaths) { + var marks = map.Find(markPath).gameObject.getChildren(); + foreach (var mark in marks) { + if (!mark.transform.localScale.Equals(new Vector3(0, 0, 0))) { + mark.transform.localScale = shrinkVector; + } + var lootMarkerView = mark.GetComponent(); + lootMarkerView?.Hide(); } - var lootMarkerView = mark.GetComponent(); - lootMarkerView?.Hide(); } - } - // Finally we tweak the thickness of the Frame Block so it doesn't grow really small and thick. - if (frame.FindChild("Top")?.gameObject?.transform is Transform tt) tt.localScale = new Vector3(1, 1.5f / zoom, 1); - if (frame.FindChild("Bottom")?.gameObject?.transform is Transform tb) tb.localScale = new Vector3(1, 1.5f / zoom, 1); - if (frame.FindChild("Bottom/BottomEye")?.gameObject?.transform is Transform tbe) tbe.localScale = new Vector3(1.5f / zoom, 1f, 1); - if (frame.FindChild("Left")?.gameObject?.transform is Transform tl) tl.localScale = new Vector3(1.5f / zoom, 1, 1); - if (frame.FindChild("Right")?.gameObject?.transform is Transform tr) tr.localScale = new Vector3(1.5f / zoom, 1, 1); + // Finally we tweak the thickness of the Frame Block so it doesn't grow really small and thick. + if (frame.FindChild("Top")?.gameObject?.transform is Transform tt) tt.localScale = new Vector3(1, 1.5f / zoom, 1); + if (frame.FindChild("Bottom")?.gameObject?.transform is Transform tb) tb.localScale = new Vector3(1, 1.5f / zoom, 1); + if (frame.FindChild("Bottom/BottomEye")?.gameObject?.transform is Transform tbe) tbe.localScale = new Vector3(1.5f / zoom, 1f, 1); + if (frame.FindChild("Left")?.gameObject?.transform is Transform tl) tl.localScale = new Vector3(1.5f / zoom, 1, 1); + if (frame.FindChild("Right")?.gameObject?.transform is Transform tr) tr.localScale = new Vector3(1.5f / zoom, 1, 1); + } + } + else { + // TODO: Factor the above into a helper function and take zoom as a paremeter so we can call it to reset everything back to normal when we turn off Enhanced Map + var zoomVector = new Vector3(1, 1, 1.0f); + Zoom = 1.0f; + //LocalMapVM_Patch.offset = new Vector2(0.0f, 0.0f); + mapBlock.localScale = new Vector3(1, 1, 1); } } - else { - // TODO: Factor the above into a helper function and take zoom as a paremeter so we can call it to reset everything back to normal when we turn off Enhanced Map - var zoomVector = new Vector3(1, 1, 1.0f); - Zoom = 1.0f; - //LocalMapVM_Patch.offset = new Vector2(0.0f, 0.0f); - mapBlock.localScale = new Vector3(1, 1, 1); - } + } + catch (Exception ex) { + Mod.Log("Exception in LocalMapBaseViewPatch.SetDrawResult: " + ex.ToString()); } return false; } @@ -241,87 +246,87 @@ public static bool SetupBPRVisible(LocalMapBaseView __instance) { } } #if true - enum MouseEventState { - Off, - Short, - Long, - } + enum MouseEventState { + Off, + Short, + Long, + } - private static MouseEventState eventState = MouseEventState.Off; - private static long eventStartTime = 0; - private static Vector3 eventStartPosition = Vector3.zero; - - [HarmonyPatch(typeof(LocalMapPCView))] - public static class LocalMapPCViewPatch { - [HarmonyPatch(nameof(OnPointerClick))] - [HarmonyPrefix] - public static bool OnPointerClick(LocalMapPCView __instance, PointerEventData eventData) { - if (!Settings.toggleZoomableLocalMaps) return true; - if (eventData.button == PointerEventData.InputButton.Middle) - return false; - Vector2 adjustedPoint = eventStartPosition; - if (eventState != MouseEventState.Short) { - Vector2 localPoint; - RectTransformUtility.ScreenPointToLocalPointInRectangle( - __instance.m_Image.rectTransform, - eventData.position, - Game.Instance.UI.UICamera, - out localPoint - ); - adjustedPoint = localPoint - + Vector2.Scale( - __instance.m_Image.rectTransform.sizeDelta, - __instance.m_Image.rectTransform.pivot - ); - } - Mod.Debug($"Click - localPoint: {adjustedPoint} vs pos: {Position } zoom:{Zoom}"); - __instance.ViewModel.OnClick(adjustedPoint, eventData.button == PointerEventData.InputButton.Left); - return false; - } + private static MouseEventState eventState = MouseEventState.Off; + private static long eventStartTime = 0; + private static Vector3 eventStartPosition = Vector3.zero; - [HarmonyPatch(nameof(Update))] - [HarmonyPrefix] - private static bool Update(LocalMapPCView __instance) { - if (!Settings.toggleZoomableLocalMaps) return true; - if (!__instance.m_MouseDown) { - eventState = MouseEventState.Off; - return false; - } + [HarmonyPatch(typeof(LocalMapPCView))] + public static class LocalMapPCViewPatch { + [HarmonyPatch(nameof(OnPointerClick))] + [HarmonyPrefix] + public static bool OnPointerClick(LocalMapPCView __instance, PointerEventData eventData) { + if (!Settings.toggleZoomableLocalMaps) return true; + if (eventData.button == PointerEventData.InputButton.Middle) + return false; + Vector2 adjustedPoint = eventStartPosition; + if (eventState != MouseEventState.Short) { Vector2 localPoint; RectTransformUtility.ScreenPointToLocalPointInRectangle( - __instance.m_Image.rectTransform, - Input.mousePosition, - Game.Instance.UI.UICamera, out localPoint + __instance.m_Image.rectTransform, + eventData.position, + Game.Instance.UI.UICamera, + out localPoint ); - var adjustedPoint = localPoint + Vector2.Scale( - __instance.m_Image.rectTransform.sizeDelta * Zoom, + adjustedPoint = localPoint + + Vector2.Scale( + __instance.m_Image.rectTransform.sizeDelta, __instance.m_Image.rectTransform.pivot - ); - var time = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - bool forwardEvent = false; - if (eventState == MouseEventState.Off) { - eventStartTime = time; - eventState = MouseEventState.Short; - // save off start position for Click can use it if we get Click during the Short phase - eventStartPosition = adjustedPoint; - forwardEvent = true; // send first event - } - if (eventState == MouseEventState.Short && time - eventStartTime > 100) { - eventState = MouseEventState.Long; - } - else if (eventState == MouseEventState.Long) { - forwardEvent = true; // once we are in long click then start sending updates - eventStartPosition = adjustedPoint; // update start position so that Click will have the right value after a long drag - } - if (forwardEvent) { - Mod.Debug($"Update - localPoint: {localPoint} -> {adjustedPoint} vs pos: {Position} zoom:{Zoom}"); - __instance.ViewModel.OnClick(adjustedPoint, true); - } + ); + } + Mod.Debug($"Click - localPoint: {adjustedPoint} vs pos: {Position} zoom:{Zoom}"); + __instance.ViewModel.OnClick(adjustedPoint, eventData.button == PointerEventData.InputButton.Left); + return false; + } + + [HarmonyPatch(nameof(Update))] + [HarmonyPrefix] + private static bool Update(LocalMapPCView __instance) { + if (!Settings.toggleZoomableLocalMaps) return true; + if (!__instance.m_MouseDown) { + eventState = MouseEventState.Off; return false; } + Vector2 localPoint; + RectTransformUtility.ScreenPointToLocalPointInRectangle( + __instance.m_Image.rectTransform, + Input.mousePosition, + Game.Instance.UI.UICamera, out localPoint + ); + var adjustedPoint = localPoint + Vector2.Scale( + __instance.m_Image.rectTransform.sizeDelta * Zoom, + __instance.m_Image.rectTransform.pivot + ); + var time = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + bool forwardEvent = false; + if (eventState == MouseEventState.Off) { + eventStartTime = time; + eventState = MouseEventState.Short; + // save off start position for Click can use it if we get Click during the Short phase + eventStartPosition = adjustedPoint; + forwardEvent = true; // send first event + } + if (eventState == MouseEventState.Short && time - eventStartTime > 100) { + eventState = MouseEventState.Long; + } + else if (eventState == MouseEventState.Long) { + forwardEvent = true; // once we are in long click then start sending updates + eventStartPosition = adjustedPoint; // update start position so that Click will have the right value after a long drag + } + if (forwardEvent) { + Mod.Debug($"Update - localPoint: {localPoint} -> {adjustedPoint} vs pos: {Position} zoom:{Zoom}"); + __instance.ViewModel.OnClick(adjustedPoint, true); + } + return false; } - #endif - #endif + } +#endif +#endif [HarmonyPatch(typeof(LocalMapMarkerPCView), nameof(LocalMapMarkerPCView.BindViewImplementation))] @@ -370,7 +375,7 @@ private static void UpdateMarker(LocalMapMarkerPCView markerView, UnitEntityData markImage.color = new Color(1, 1f, 0); } else { -// attentionMark?.SetActive(false); + // attentionMark?.SetActive(false); markImage.color = new Color(1, 1, 1); } } @@ -415,7 +420,7 @@ public static void UpdateInternal(UnitOvertipView __instance) { #endif } } - #if false +#if false [HarmonyPatch(typeof(LocalMapMarkerPart))] public static class LocalMapMarkerPartPatch { [HarmonyPatch(nameof(LocalMapMarkerPart.OnTurnOn))] @@ -440,8 +445,8 @@ public static void Markers() { //Mod.Error($"Marker Add"); } } - #endif - #if false +#endif +#if false [HarmonyPatch(typeof(EntityVisibilityForPlayerController))] public static class AddLocalMapMarkerRuntimePatch { [HarmonyPatch(nameof(EntityVisibilityForPlayerController.IsVisible), new Type[] { typeof(UnitEntityData)})] @@ -462,11 +467,11 @@ private static bool IsMapObjectVisible(MapObjectEntityData mapObject, ref bool _ return true; } } - #endif +#endif #if false - #if false +#if false var mapBlockRotation = mapBlock.localEulerAngles; var frameRotation = frame.localEulerAngles; var frameBlockRotation = frameBlock.localEulerAngles; @@ -479,7 +484,7 @@ private static bool IsMapObjectVisible(MapObjectEntityData mapObject, ref bool _ //mapBlock.Rotate(new Vector3()); // mapBlock.localEulerAngles = mapBlockRotation; Mod.Log($"frameRotation: {mapBlockRotation}"); - #endif +#endif // some experimental code to implement map rotation ) {