public static bool ApplyPatch(Harmony harmonyInstance) { try { Type ploppableToolType = Type.GetType("PloppableRICO.PloppableTool, ploppablerico", false); if (ploppableToolType != null) { var original = ploppableToolType.GetMethod("TabClicked"); if (original == null) { return(false); } var prefix = typeof(DrawPloppablePanelPatch).GetMethod("Prefix"); var postfix = typeof(DrawPloppablePanelPatch).GetMethod("Postfix"); harmonyInstance.Patch(original, new HarmonyMethod(prefix), new HarmonyMethod(postfix)); return(true); } else { Debugging.Message($"Found enabled mod: ploppablerico. Yet Another Toolbar scale patch failed"); return(false); } } catch (Exception ex) { Debugging.Message($"Found enabled mod: ploppablerico. Yet Another Toolbar scale patch failed. {ex.Message}"); return(false); } }
/// <summary> /// Returns the filepath of the mod assembly. /// </summary> /// <returns>Mod assembly filepath</returns> private string GetAssemblyPath() { // Get list of currently active plugins. IEnumerable <PluginManager.PluginInfo> plugins = PluginManager.instance.GetPluginsInfo(); // Iterate through list. foreach (PluginManager.PluginInfo plugin in plugins) { try { // Get all (if any) mod instances from this plugin. IUserMod[] mods = plugin.GetInstances <IUserMod>(); // Check to see if the primary instance is this mod. if (mods.FirstOrDefault() is ModInfo) { // Found it! Return path. return(plugin.modPath); } } catch { // Don't care. } } // If we got here, then we didn't find the assembly. Debugging.Message("assembly path not found"); throw new FileNotFoundException("Yet Another Toolbar: assembly path not found!"); }
/// <summary> /// Actions to update the UI on a language change go here. /// </summary> public void UpdateUILanguage() { Debugging.Message("setting language to " + (currentIndex < 0 ? "system" : languages.Values[currentIndex].uniqueName)); // UI update code goes here. // TOOO: Add dynamic UI update. }
public void Update() { if (YetAnotherToolbar.instance.InitializationCheck()) // return true if initialized { Debugging.Message($"Destroying InitializationWorker"); Destroy(instance.gameObject); InitializationWorker.instance = null; } }
public void OnEnabled() { // Apply Harmony patches via Cities Harmony. // Called here instead of OnCreated to allow the auto-downloader to do its work prior to launch. HarmonyHelper.DoOnHarmonyReady(() => Patcher.PatchAll()); Debugging.Message("Harmony patches applied"); // Load settings here. XMLUtils.LoadSettings(); Debugging.Message("XML Settings loaded"); }
public static void UnpatchAll() { // Only unapply if patches appplied. if (_patched) { Debugging.Message("reverting Harmony patches"); // Unapply patches, but only with our HarmonyID. Harmony harmonyInstance = new Harmony(harmonyID); harmonyInstance.UnpatchAll(harmonyID); _patched = false; } }
private void FindItLayoutPatch() { try { GameObject findItObject = GameObject.Find("FindItDefaultPanel"); if (findItObject == null) { return; } UIComponent finditDefaultPanel = findItObject.GetComponent <UIComponent>(); if (finditDefaultPanel != null) { UIComponent finditScrollablePanel = finditDefaultPanel.Find("ScrollablePanel").GetComponent <UIComponent>(); if (finditScrollablePanel != null) { UIScrollablePanel scrollablePanel = (UIScrollablePanel)finditScrollablePanel; scrollablePanel.wrapLayout = true; scrollablePanel.autoLayout = true; scrollablePanel.autoLayoutStart = LayoutStart.TopLeft; } UIComponent finditScrollbar = finditDefaultPanel.Find("UIScrollbar").GetComponent <UIComponent>(); if (finditScrollbar != null) { UIScrollbar scrollbar = (UIScrollbar)finditScrollbar; UIComponent finditSlicedSpriteTrack = finditScrollbar.Find("UISlicedSprite").GetComponent <UIComponent>(); if (finditSlicedSpriteTrack != null) { UISlicedSprite slicedSpriteTrack = (UISlicedSprite)finditSlicedSpriteTrack; slicedSpriteTrack.height = tsContainer.height; } } } } catch (Exception ex) { Debugging.Message("FindItLayoutPatch() - " + ex.Message); } }
/// <summary> /// Loads languages from XML files. /// </summary> private void LoadLanguages() { // Clear existing dictionary. languages.Clear(); // Get the current assembly path and append our locale directory name. string assemblyPath = GetAssemblyPath(); if (!assemblyPath.IsNullOrWhiteSpace()) { string localePath = Path.Combine(assemblyPath, "Translations"); // Ensure that the directory exists before proceeding. if (Directory.Exists(localePath)) { // Load each file in directory and attempt to deserialise as a translation file. string[] translationFiles = Directory.GetFiles(localePath); foreach (string translationFile in translationFiles) { using (StreamReader reader = new StreamReader(translationFile)) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(Language)); if (xmlSerializer.Deserialize(reader) is Language translation) { // Got one! add it to the list. languages.Add(translation.uniqueName, translation); } else { Debugging.Message("couldn't deserialize translation file '" + translationFile); } } } } else { Debugging.Message("translations directory not found"); } } else { Debugging.Message("assembly path was empty"); } }
private void PloppableRICOLayoutPatch(int numOfRows, int numOfCols) { try { UIComponent panel = GameObject.Find("PloppableBuildingPanel").GetComponent <UIComponent>(); if (panel != null) { UIPanel p = panel as UIPanel; UIScrollablePanel scrollablePanel; foreach (UIComponent comp in panel.components) { if (comp is UIScrollablePanel) { scrollablePanel = (UIScrollablePanel)comp; p.height = tsContainer.height; p.width = Mathf.Round(859f - 763f + 109f * numOfCols) + 1; scrollablePanel.height = tsContainer.height; scrollablePanel.width = Mathf.Round(109f * numOfCols) + 1; if (numOfRows > 1) { scrollablePanel.scrollWheelDirection = UIOrientation.Vertical; scrollablePanel.autoLayoutDirection = LayoutDirection.Horizontal; } else { scrollablePanel.autoLayoutDirection = LayoutDirection.Horizontal; scrollablePanel.scrollWheelDirection = UIOrientation.Horizontal; } } } } } catch (Exception ex) { Debugging.Message("PloppableRICOLayoutPatch() - " + ex.Message); } }
/// <summary> /// Apply all Harmony patches. /// </summary> public static void PatchAll() { // Don't do anything if already patched. if (!_patched) { // Ensure Harmony is ready before patching. if (HarmonyHelper.IsHarmonyInstalled) { Debugging.Message("deploying Harmony patches"); // Apply all annotated patches and update flag. harmonyInstance = new Harmony(harmonyID); harmonyInstance.PatchAll(); _patched = true; } else { Debugging.Message("Harmony not ready"); } } }
public void SetAdvisorButtonVisibility() { try { UIMultiStateButton advisorButton = UIView.Find("AdvisorButton") as UIMultiStateButton; if (advisorButton == null) { return; } if (Settings.hideAdvisorButton) { advisorButton.Hide(); } else { advisorButton.Show(); } } catch (Exception ex) { Debugging.Message("SetAdvisorButtonVisibility() - " + ex.Message); } }
public void Start() { try { if (mainButton == null) { tsContainer = GameObject.Find("TSContainer").GetComponent <UITabContainer>(); thumbnailBar = UIView.Find <UISlicedSprite>("ThumbnailBar"); mainTS = UIView.Find <UITabstrip>("MainToolstrip"); tsBar = UIView.Find <UISlicedSprite>("TSBar"); infoPanel = UIView.Find <UIPanel>("InfoPanel"); pauseOutline = GameObject.Find("PauseOutline")?.GetComponent <UIComponent>(); if (pauseOutline != null) { pauseOutlineOriginalSize = pauseOutline.size; } isFindItEnabled = IsAssemblyEnabled("findit"); if (isFindItEnabled) { Debugging.Message($"Found enabled mod: findit. Yet Another Toolbar layout patch will be applied"); } isRICOEnabled = IsAssemblyEnabled("ploppablerico"); if (isRICOEnabled) { Debugging.Message($"Found enabled mod: ploppablerico. Yet Another Toolbar layout patch will be applied"); bool result = DrawPloppablePanelPatch.ApplyPatch(Patcher.harmonyInstance); if (result) { Debugging.Message($"Found enabled mod: ploppablerico. Yet Another Toolbar scale patch applied"); } } originalTSPosX = mainTS.relativePosition.x; originalScreenSize = UIView.GetAView().GetScreenResolution(); //UIMultiStateButton advisorButton = view.FindUIComponent<UIMultiStateButton>("AdvisorButton"); // Set Advisor Button and filter panel visiblity SetAdvisorButtonVisibility(); // SetFilterPanelsVisibility(); // Create main button mainButton = CreatMainButton(); // check UUI isUUIEnabled = IsAssemblyEnabled("unifieduimod"); if (isUUIEnabled && Settings.integrateMainButtonUUI) { UUIIntegration.AttachMainButton(); Debugging.Message($"Found enabled mod: unifieduimod. Yet Another Toolbar main button UUI integration applied"); } } } catch (Exception ex) { Debugging.Message("Start() - " + ex.Message); } }
private void UpdateLayout(int numOfRows, int numCols) { CheckMenuVisibility(); try { int numOfCols = isAssetEditorMode ? 7 : numCols; UITabContainer gtsContainer; tsContainer.height = Mathf.Round(104f * numOfRows) + 1; tsContainer.width = Mathf.Round(859f - 763f + 109f * numOfCols) + 1; foreach (UIComponent toolPanel in tsContainer.components) { if (toolPanel is UIPanel) { gtsContainer = toolPanel.GetComponentInChildren <UITabContainer>(); if (gtsContainer != null) { foreach (UIComponent tabPanel in gtsContainer.components) { tabPanel.height = tsContainer.height; tabPanel.width = tsContainer.width; UIScrollablePanel scrollablePanel = tabPanel.GetComponentInChildren <UIScrollablePanel>(); if (scrollablePanel != null) { scrollablePanel.height = tsContainer.height; scrollablePanel.width = Mathf.Round(109f * numOfCols) + 1; } // don't mess further with Find It's panel if (tabPanel.name == "FindItDefaultPanel") { continue; } if (numOfRows > 1) { UIScrollbar horizontalScrollbar = tabPanel.GetComponentInChildren <UIScrollbar>(); if (horizontalScrollbar != null) { horizontalScrollbar.value = 0; } if (scrollablePanel != null) { scrollablePanel.autoLayout = true; scrollablePanel.autoLayoutStart = LayoutStart.TopLeft; scrollablePanel.wrapLayout = true; scrollablePanel.autoLayoutDirection = LayoutDirection.Horizontal; scrollablePanel.scrollWheelDirection = UIOrientation.Vertical; } UIScrollbar verticalScrollbar; if (dictVerticalScrollbars.ContainsKey((UIPanel)tabPanel)) { verticalScrollbar = dictVerticalScrollbars[(UIPanel)tabPanel]; AdjustVerticalScrollbar(verticalScrollbar, tabPanel, scrollablePanel); } else { verticalScrollbar = CreateVerticalScrollbar((UIPanel)tabPanel, scrollablePanel); dictVerticalScrollbars[(UIPanel)tabPanel] = verticalScrollbar; } verticalScrollbar.Show(); } else { if (scrollablePanel != null) { scrollablePanel.autoLayout = true; scrollablePanel.autoLayoutStart = LayoutStart.TopLeft; scrollablePanel.wrapLayout = false; scrollablePanel.autoLayoutDirection = LayoutDirection.Horizontal; scrollablePanel.scrollWheelDirection = UIOrientation.Horizontal; scrollablePanel.ScrollToLeft(); } UIScrollbar verticalScrollbar; if (dictVerticalScrollbars.ContainsKey((UIPanel)tabPanel)) { verticalScrollbar = dictVerticalScrollbars[(UIPanel)tabPanel]; AdjustVerticalScrollbar(verticalScrollbar, tabPanel, scrollablePanel); } else { verticalScrollbar = CreateVerticalScrollbar((UIPanel)tabPanel, scrollablePanel); dictVerticalScrollbars[(UIPanel)tabPanel] = verticalScrollbar; } dictVerticalScrollbars[(UIPanel)tabPanel].Hide(); UIScrollbar horizontalScrollbar = tabPanel.GetComponentInChildren <UIScrollbar>(); if (horizontalScrollbar != null) { if (horizontalScrollbar.decrementButton != null) { horizontalScrollbar.decrementButton.relativePosition = new Vector3(horizontalScrollbar.decrementButton.relativePosition.x, horizontalScrollbar.height / 2f - 16f); } if (horizontalScrollbar.incrementButton != null) { horizontalScrollbar.incrementButton.relativePosition = new Vector3(horizontalScrollbar.incrementButton.relativePosition.x, horizontalScrollbar.height / 2f - 16f); } } } } } } } if (isFindItEnabled) { FindItLayoutPatch(); } if (isRICOEnabled && (!isEditorMode)) { PloppableRICOLayoutPatch(numOfRows, numOfCols); } } catch (Exception ex) { Debugging.Message("UpdateLayout() - " + ex.Message); } }
public void Start() { instance = this; Debugging.Message($"InitializationWorker started"); }
public void OnSettingsUI(UIHelperBase helper) { try { UIHelper group = helper.AddGroup(Name) as UIHelper; UIPanel panel = group.self as UIPanel; // Integrate main button with UUI UICheckBox integrateMainButtonUUI = (UICheckBox)group.AddCheckbox(Translations.Translate("YAT_SET_UUI"), Settings.integrateMainButtonUUI, (b) => { Settings.integrateMainButtonUUI = b; XMLUtils.SaveSettings(); if (YetAnotherToolbar.instance?.mainButton != null) { if (Settings.integrateMainButtonUUI) { UUIIntegration.AttachMainButton(); } else { UUIIntegration.DetachMainButton(); } } }); group.AddSpace(10); // Hide main button UICheckBox hideMainButton = (UICheckBox)group.AddCheckbox(Translations.Translate("YAT_SET_HMB"), Settings.hideMainButton, (b) => { Settings.hideMainButton = b; XMLUtils.SaveSettings(); if (YetAnotherToolbar.instance?.mainButton != null) { YetAnotherToolbar.instance.mainButton.isVisible = !Settings.hideMainButton; } }); group.AddSpace(10); UIButton mainButtonPositionReset = (UIButton)group.AddButton(Translations.Translate("YAT_SET_HMBRST"), () => { Settings.mainButtonX = 538.0f; Settings.mainButtonY = 947.0f; XMLUtils.SaveSettings(); if (YetAnotherToolbar.instance?.mainButton != null) { UIView view = UIView.GetAView(); Vector2 screenResolution = view.GetScreenResolution(); YetAnotherToolbar.instance.mainButton.absolutePosition = new Vector3(Settings.mainButtonX * screenResolution.x / 1920f, Settings.mainButtonY * screenResolution.y / 1080f);// advisorButton.absolutePosition + new Vector3(advisorButton.width, 0); } }); group.AddSpace(10); // Hide Advisor Button UICheckBox hideAdvisorButton = (UICheckBox)group.AddCheckbox(Translations.Translate("YAT_SET_HAB"), Settings.hideAdvisorButton, (b) => { Settings.hideAdvisorButton = b; XMLUtils.SaveSettings(); if (YetAnotherToolbar.instance != null) { YetAnotherToolbar.instance.SetAdvisorButtonVisibility(); } }); group.AddSpace(10); /* * // Hide Filter Panels * UICheckBox hideFilterPanels = (UICheckBox)group.AddCheckbox(Translations.Translate("YAT_SET_HFP"), Settings.hideFilterPanels, (b) => * { * Settings.hideFilterPanels = b; * XMLUtils.SaveSettings(); * if (YetAnotherToolbar.instance != null) * { * YetAnotherToolbar.instance.hideFilterPanels = Settings.hideFilterPanels; * YetAnotherToolbar.instance.SetFilterPanelsVisibility(); * } * }); * group.AddSpace(10); */ // Disable update notice UICheckBox disableUpdateNotice = (UICheckBox)group.AddCheckbox(Translations.Translate("YAT_SET_DUN"), Settings.disableUpdateNotice, (b) => { Settings.disableUpdateNotice = b; XMLUtils.SaveSettings(); }); group.AddSpace(10); // languate settings UIDropDown languageDropDown = (UIDropDown)group.AddDropdown(Translations.Translate("TRN_CHOICE"), Translations.LanguageList, Translations.Index, (value) => { Translations.Index = value; XMLUtils.SaveSettings(); }); languageDropDown.width = 300; group.AddSpace(10); // show path to YetAnotherToolbarConfig.xml string path = Path.Combine(DataLocation.executableDirectory, "YetAnotherToolbarConfig.xml"); UITextField ConfigFilePath = (UITextField)group.AddTextfield($"{Translations.Translate("YAT_SET_CFP")} - YetAnotherToolbarConfig.xml", path, _ => { }, _ => { }); ConfigFilePath.width = panel.width - 30; group.AddButton(Translations.Translate("YAT_SET_OFE"), () => System.Diagnostics.Process.Start(DataLocation.executableDirectory)); // shortcut keys panel.gameObject.AddComponent <ModeToggleKeyMapping>(); panel.gameObject.AddComponent <QuickMenuKeyMapping>(); panel.gameObject.AddComponent <HideMenuKeyMapping>(); group.AddSpace(10); } catch (Exception e) { Debugging.Message("OnSettingsUI failed"); Debugging.LogException(e); } }