/// <summary> /// create patch for OutsideConnectionsInfoViewPanel.UpdatePanel /// </summary> public static void CreateUpdatePanelPatch() { // get the OutsideConnectionsInfoViewPanel panel (displayed when the user clicks on the Outside Connections info view button) OutsideConnectionsInfoViewPanel ocPanel = UIView.library.Get <OutsideConnectionsInfoViewPanel>(typeof(OutsideConnectionsInfoViewPanel).Name); if (ocPanel == null) { Debug.LogError("Unable to find [OutsideConnectionsInfoViewPanel]."); return; } // find import total label string componentName = "ImportTotal"; _importTotalLabel = ocPanel.Find <UILabel>(componentName); if (_importTotalLabel == null) { Debug.LogError($"Unable to find label [{componentName}] on [OutsideConnectionsInfoViewPanel]."); return; } // find export total label componentName = "ExportTotal"; _exportTotalLabel = ocPanel.Find <UILabel>(componentName); if (_exportTotalLabel == null) { Debug.LogError($"Unable to find label [{componentName}] on [OutsideConnectionsInfoViewPanel]."); return; } // find import chart componentName = "ImportChart"; _importChart = ocPanel.Find <UIRadialChart>(componentName); if (_importChart == null) { Debug.LogError($"Unable to find chart [{componentName}] on [OutsideConnectionsInfoViewPanel]."); return; } // find export chart componentName = "ExportChart"; _exportChart = ocPanel.Find <UIRadialChart>(componentName); if (_exportChart == null) { Debug.LogError($"Unable to find chart [{componentName}] on [OutsideConnectionsInfoViewPanel]."); return; } // get the original UpdatePanel method MethodInfo original = typeof(OutsideConnectionsInfoViewPanel).GetMethod("UpdatePanel", BindingFlags.Instance | BindingFlags.NonPublic); if (original == null) { Debug.LogError($"Unable to find OutsideConnectionsInfoViewPanel.UpdatePanel method."); return; } // find the Prefix method MethodInfo prefix = typeof(OutsideConnectionsInfoViewPanelPatch).GetMethod("Prefix", BindingFlags.Static | BindingFlags.Public); if (prefix == null) { Debug.LogError($"Unable to find OutsideConnectionsInfoViewPanelPatch.Prefix method."); return; } // create the patch ExcludeMail.harmony.Patch(original, new HarmonyMethod(prefix), null, null); }
public override void OnLevelLoaded(LoadMode mode) { // do base processing base.OnLevelLoaded(mode); try { // initialize only if user has Industries DLC if (SteamHelper.IsDLCOwned(SteamHelper.DLC.IndustryDLC)) { // check for new or loaded game if (mode == LoadMode.NewGame || mode == LoadMode.NewGameFromScenario || mode == LoadMode.LoadGame) { // initialize Harmony ExcludeMail.harmony = HarmonyInstance.Create("com.github.rcav8tr.ExcludeMail"); if (ExcludeMail.harmony == null) { Debug.LogError("Unable to create Harmony instance."); return; } // find Ingame atlas UITextureAtlas ingameAtlas = null; UITextureAtlas[] atlases = Resources.FindObjectsOfTypeAll(typeof(UITextureAtlas)) as UITextureAtlas[]; for (int i = 0; i < atlases.Length; i++) { if (atlases[i] != null) { if (atlases[i].name == "Ingame") { ingameAtlas = atlases[i]; break; } } } if (ingameAtlas == null) { Debug.LogError("Unable to find atlas [Ingame]."); return; } // get the OutsideConnectionsInfoViewPanel panel (displayed when the user clicks on the Outside Connections info view button) OutsideConnectionsInfoViewPanel ocPanel = UIView.library.Get <OutsideConnectionsInfoViewPanel>(typeof(OutsideConnectionsInfoViewPanel).Name); if (ocPanel == null) { Debug.LogError("Unable to find [OutsideConnectionsInfoViewPanel]."); return; } // find the import and export legend mail panels UIPanel importLegendMailPanel = ocPanel.Find <UIPanel>("ResourceLegendMail"); if (importLegendMailPanel == null) { Debug.LogError($"Unable to find panel [ResourceLegendMail] on [OutsideConnectionsInfoViewPanel]"); return; } UIPanel exportLegendMailPanel = ocPanel.Find <UIPanel>("ResourceLegendMail2"); if (exportLegendMailPanel == null) { Debug.LogError($"Unable to find panel [ResourceLegendMail2] on [OutsideConnectionsInfoViewPanel]"); return; } // find the import and export legend mail boxes _importLegendMailBox = importLegendMailPanel.Find <UISprite>("MailColor"); if (_importLegendMailBox == null) { Debug.LogError($"Unable to find import sprite [MailColor] on [ResourceLegendMail] on [OutsideConnectionsInfoViewPanel]"); return; } _exportLegendMailBox = exportLegendMailPanel.Find <UISprite>("MailColor"); if (_exportLegendMailBox == null) { Debug.LogError($"Unable to find export sprite [MailColor] on [ResourceLegendMail2] on [OutsideConnectionsInfoViewPanel]"); return; } // find the import and export legend mail labels _importLegendMailLabel = importLegendMailPanel.Find <UILabel>("Type"); if (_importLegendMailLabel == null) { Debug.LogError($"Unable to find import label [Type] on [ResourceLegendMail] on [OutsideConnectionsInfoViewPanel]"); return; } _exportLegendMailLabel = exportLegendMailPanel.Find <UILabel>("Type"); if (_exportLegendMailLabel == null) { Debug.LogError($"Unable to find export label [Type] on [ResourceLegendMail2] on [OutsideConnectionsInfoViewPanel]"); return; } // find import total label UILabel totalLabel = ocPanel.Find <UILabel>("ImportTotal"); if (totalLabel == null) { Debug.LogError("Unable to find label [ImportTotal] on [OutsideConnectionsInfoViewPanel]."); return; } // create the check box (i.e. a sprite) _includeMailCheckBox = ocPanel.component.AddUIComponent <UISprite>(); if (_includeMailCheckBox == null) { Debug.LogError("Unable to create check box sprite on [OutsideConnectionsInfoViewPanel]."); return; } _includeMailCheckBox.name = "IncludeMailCheckBox"; _includeMailCheckBox.autoSize = false; _includeMailCheckBox.size = new Vector2(totalLabel.size.y, totalLabel.size.y); // width is same as height _includeMailCheckBox.relativePosition = new Vector3(8f, 82f); _includeMailCheckBox.atlas = ingameAtlas; SetCheckBox(_includeMailCheckBox, true); _includeMailCheckBox.isVisible = true; _includeMailCheckBox.BringToFront(); _includeMailCheckBox.eventClicked += CheckBox_eventClicked; // create the label and right align it to the info view _includeMailLabel = ocPanel.component.AddUIComponent <UILabel>(); if (_includeMailLabel == null) { Debug.LogError("Unable to create label on [OutsideConnectionsInfoViewPanel]."); return; } _includeMailLabel.name = "IncludeMailLabel"; _includeMailLabel.text = "Include Mail"; _includeMailLabel.textAlignment = UIHorizontalAlignment.Left; _includeMailLabel.verticalAlignment = UIVerticalAlignment.Top; _includeMailLabel.font = totalLabel.font; _includeMailLabel.textScale = totalLabel.textScale; _includeMailLabel.textColor = totalLabel.textColor; _includeMailLabel.autoSize = true; _includeMailLabel.relativePosition = new Vector3(_includeMailCheckBox.relativePosition.x + _includeMailCheckBox.size.x + 5f, _includeMailCheckBox.relativePosition.y + 2.5f); _includeMailLabel.isVisible = true; _includeMailLabel.BringToFront(); _includeMailLabel.eventClicked += Label_eventClicked; // create the patches PostOfficeAIPatch.CreateGetColorPatch(); PostVanAIPatch.CreateGetColorPatch(); OutsideConnectionsInfoViewPanelPatch.CreateUpdatePanelPatch(); // legend colors are not initialized _legendColorsInitialized = false; } } else { // show a nice message ExceptionPanel panel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel", true); panel.SetMessage( "Exclude Mail Mod", "Industries DLC is not installed. Having the Exclude Mail mod enabled without Industries DLC will not cause an error in the mod, but the functionality of the mod will not be available.", false); } } catch (Exception ex) { Debug.LogException(ex); } }