private static void Postfix(UIButton __result, GeneratedScrollPanel __instance, string name, string tooltip, string baseIconName, int index, UITextureAtlas atlas, UIComponent tooltipBox, bool enabled) { if (Settings.hideExtraUIonVP) { return; } __result.eventVisibilityChanged += new PropertyChangedEventHandler <bool>(Init); GeneratedScrollPanel panel = __instance; SimulationManager.instance.AddAction(() => { if (__result.objectUserData is PrefabInfo prefab) { string key = Asset.GetName(prefab); if (AssetTagList.instance.assets.ContainsKey(key)) { if (AssetTagList.instance.assets[key].onButtonClicked == null) { MethodInfo onButtonClicked = panel.GetType().GetMethod("OnButtonClicked", BindingFlags.NonPublic | BindingFlags.Instance); AssetTagList.instance.assets[key].onButtonClicked = Delegate.CreateDelegate(typeof(Asset.OnButtonClicked), panel, onButtonClicked, false) as Asset.OnButtonClicked; } } } }); }
private void ShowNetwork(string name, string desc, GeneratedScrollPanel panel, int constructionCost, int maintenanceCost, string prefixIcon) { UIButton button = panel.Find <UIButton>(name); if (button != null && button.name == name) { GameObject.DestroyImmediate(button); } NetInfo netInfo = PrefabCollection <NetInfo> .FindLoaded(name); if (netInfo == null) { DebugUtils.Warning("Couldn't find NetInfo named '" + name + "'"); return; } //DebugUtils.Log("NetInfo named '" + name + "' found."); PlayerNetAI netAI = netInfo.m_netAI as PlayerNetAI; // Adding cost netAI.m_constructionCost = constructionCost; netAI.m_maintenanceCost = maintenanceCost; // Making the prefab valid netInfo.m_availableIn = ItemClass.Availability.All; netInfo.m_placementStyle = ItemClass.Placement.Manual; typeof(NetInfo).GetField("m_UICategory", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(netInfo, "PublicTransportPlane"); // Adding icons netInfo.m_Atlas = m_atlas; netInfo.m_Thumbnail = prefixIcon; // Adding missing locale Locale locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(SingletonLite <LocaleManager> .instance); Locale.Key key = new Locale.Key() { m_Identifier = "NET_TITLE", m_Key = name }; if (!locale.Exists(key)) { locale.AddLocalizedString(key, name); } key = new Locale.Key() { m_Identifier = "NET_DESC", m_Key = name }; if (!locale.Exists(key)) { locale.AddLocalizedString(key, desc); } typeof(GeneratedScrollPanel).GetMethod("CreateAssetItem", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(panel, new object[] { netInfo }); }
private bool internalRefreshPanel(bool refreshCustoms) { Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.CustomRefreshPanel"); if (Interlocked.CompareExchange(ref this.refreshing, 1, 0) == 1) { Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.CustomRefreshPanel -- Can't refresh, already refreshing"); return(true); } // Refresh the Custom Panels only when specified -- Can't refresh these panels before completing the init process if (refreshCustoms) { try { // Refresh the Education Panel UIComponent healthcareDefault = this.m_Strip.Find(EDUCATION_COMPONENT_NAME); GeneratedScrollPanel healthcarePanel = this.m_Strip.GetComponentInContainer(healthcareDefault, typeof(CustomEducationPanel)) as GeneratedScrollPanel; if (healthcarePanel != null) { Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.CustomRefreshPanel -- Refreshing the Education Panel"); healthcarePanel.RefreshPanel(); } // Refresh the Dormitory Panel UIComponent dormitoryDefault = this.m_Strip.Find(DORMITORY_COMPONENT_NAME); GeneratedScrollPanel dormitoryPanel = this.m_Strip.GetComponentInContainer(dormitoryDefault, typeof(DormitoryPanel)) as GeneratedScrollPanel; if (dormitoryPanel != null) { Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.CustomRefreshPanel -- Refreshing the Dormitory Panel"); dormitoryPanel.RefreshPanel(); } } catch (Exception e) { Logger.logError(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.CustomRefreshPanel -- Exception refreshing the Custom Panels: {0} -- {1}", e, e.StackTrace); this.refreshing = 0; return(true); } } // Proceed with the existing logic if (this.groupFilter != GeneratedGroupPanel.GroupFilter.None) { this.PopulateGroups(this.groupFilter, this.sortingMethod); } else if (!string.IsNullOrEmpty(this.serviceName)) { this.DefaultGroup(this.serviceName); } else { this.DefaultGroup(EnumExtensions.Name <ItemClass.Service>(this.service)); } this.refreshing = 0; return(true); }
public static bool Prefix(GeneratedScrollPanel __instance) { // Get Private field m_scrollablePanel BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance; FieldInfo fi_name = typeof(GeneratedScrollPanel).GetField("m_ScrollablePanel", flags); UIScrollablePanel m_ScrollablePanel = (UIScrollablePanel)fi_name.GetValue(__instance); // Get Private Method ShouldAssetBeVisible(Object obj) MethodInfo md_name = typeof(GeneratedScrollPanel).GetMethod("ShouldAssetBeVisible", flags); foreach (UIComponent component in m_ScrollablePanel.components) { UIButton button = component as UIButton; if (!(button != null) || button.objectUserData == null) { continue; } // Don't show icons that we want to hide ModConfig.IconInfo firstMatch = ModConfig.hiddenIcons.FirstOrDefault(i => i.Name == button.name); if (firstMatch != null) { // Double check the button has a grandparent before accessing if (button.parent.parent != null) { // Only skip showing a button if it belongs to the panel specified in the config if (firstMatch.Grandparent == button.parent.parent.name) { continue; } } } bool shouldBeVisible = (bool)typeof(GeneratedScrollPanel).GetMethod("ShouldAssetBeVisible", flags).Invoke(__instance, new object[] { button.objectUserData }); if (!shouldBeVisible || button.isVisible) { continue; } button.isVisible = true; ValueAnimator.Animate(delegate(float val) { if (button != null) { button.opacity = val; } }, new AnimatedFloat((!shouldBeVisible) ? 1f : 0f, (!shouldBeVisible) ? 0f : 1f, 0.2f), delegate { button.isVisible = shouldBeVisible; }); } // Skip return(false); }
public void InitMod() { GeneratedScrollPanel panel = panelGameObject.GetComponent <GeneratedScrollPanel>(); ShowNetwork("Airplane Runway", "Runway", panel, 7000, 600, "Runway"); ShowNetwork("Airplane Taxiway", "Taxiway", panel, 4000, 200, "Taxiway"); OptionPanelBase optionPanel = (OptionPanelBase)typeof(GeneratedScrollPanel).GetMethod("CreateOptionPanel", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(panel, new object[] { "RoadsOptionPanel" }); optionPanel.HidePanel(); typeof(GeneratedScrollPanel).GetField("m_QuaysOptionPanel", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(panel, optionPanel); }
private UIButton AddButton(Type type, UITabstrip strip, string category, string[] editorCategories, string tooltip, bool enabled) { if (GameObject.Find(String.Format("{0}Panel", category)) != null) { return(null); } GameObject subbarButtonTemplate = UITemplateManager.GetAsGameObject("SubbarButtonTemplate"); GameObject subbarPanelTemplate = UITemplateManager.GetAsGameObject("SubbarPanelTemplate"); UIButton button = (UIButton)strip.AddTab(category, subbarButtonTemplate, subbarPanelTemplate, type); button.isEnabled = enabled; GeneratedScrollPanel generatedScrollPanel = (GeneratedScrollPanel)strip.GetComponentInContainer(button, type); if (generatedScrollPanel != null) { generatedScrollPanel.component.isInteractive = true; generatedScrollPanel.m_OptionsBar = ToolsModifierControl.mainToolbar.m_OptionsBar; generatedScrollPanel.m_DefaultInfoTooltipAtlas = ToolsModifierControl.mainToolbar.m_DefaultInfoTooltipAtlas; if (generatedScrollPanel is EditorPropsPanel) { ((EditorPropsPanel)generatedScrollPanel).m_editorCategories = editorCategories; ((EditorPropsPanel)generatedScrollPanel).category = category; } if (enabled) { generatedScrollPanel.RefreshPanel(); } } button.tooltip = tooltip; return(button); }
#pragma warning disable 108,114 protected UIButton SpawnButtonEntry(UITabstrip strip, string name, string category, bool isDefaultCategory, #pragma warning restore 108,114 string localeID, string unlockText, string spriteBase, bool enabled, bool forceFillContainer) { int objectIndex = (int)typeof(GeneratedGroupPanel).GetField("m_ObjectIndex", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this); // TAM Edit Start Type type = typeof(GeneratedScrollPanel) .Assembly .GetTypes() .FirstOrDefault(t => string.Equals(t.Name, name + "Panel", StringComparison.InvariantCultureIgnoreCase)); // TAM Edit End if (type != null && !type.IsSubclassOf(typeof(GeneratedScrollPanel))) { type = null; } UIButton uIButton; if (strip.childCount > objectIndex) { uIButton = (strip.components[objectIndex] as UIButton); } else { GameObject asGameObject = UITemplateManager.GetAsGameObject(kSubbarButtonTemplate); GameObject asGameObject2 = UITemplateManager.GetAsGameObject(kSubbarPanelTemplate); uIButton = (strip.AddTab(category, asGameObject, asGameObject2, type) as UIButton); } uIButton.isEnabled = enabled; uIButton.gameObject.GetComponent <TutorialUITag>().tutorialTag = category; GeneratedScrollPanel generatedScrollPanel = strip.GetComponentInContainer(uIButton, type) as GeneratedScrollPanel; if (generatedScrollPanel != null) { generatedScrollPanel.component.isInteractive = true; generatedScrollPanel.m_OptionsBar = this.m_OptionsBar; generatedScrollPanel.m_DefaultInfoTooltipAtlas = this.m_DefaultInfoTooltipAtlas; if (forceFillContainer || enabled) { generatedScrollPanel.category = ((!isDefaultCategory) ? category : string.Empty); generatedScrollPanel.RefreshPanel(); } } // TAM Edit Start var customAtlas = AtlasManager.instance.GetAtlas(category); if (customAtlas != null) { uIButton.atlas = customAtlas; } // TAM Edit End string text = spriteBase + category; uIButton.normalFgSprite = text; uIButton.focusedFgSprite = text + "Focused"; uIButton.hoveredFgSprite = text + "Hovered"; uIButton.pressedFgSprite = text + "Pressed"; uIButton.disabledFgSprite = text + "Disabled"; if (!string.IsNullOrEmpty(localeID) && !string.IsNullOrEmpty(unlockText)) { uIButton.tooltip = Locale.Get(localeID, category) + " - " + unlockText; } else if (!string.IsNullOrEmpty(localeID)) { uIButton.tooltip = Locale.Get(localeID, category); } typeof(GeneratedGroupPanel).GetField("m_ObjectIndex", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this, objectIndex + 1); return(uIButton); }
new protected UIButton CreateButton(string name, string tooltip, string baseIconName, int index, UITextureAtlas atlas, UIComponent tooltipBox, bool enabled) { UIScrollablePanel m_ScrollablePanel = (UIScrollablePanel)typeof(GeneratedScrollPanel).GetField("m_ScrollablePanel", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this); FieldInfo m_ObjectIndexField = typeof(GeneratedScrollPanel).GetField("m_ObjectIndex", BindingFlags.Instance | BindingFlags.NonPublic); int m_ObjectIndex = (int)m_ObjectIndexField.GetValue(this); UIButton uIButton; if (m_ScrollablePanel.childCount > m_ObjectIndex) { uIButton = (m_ScrollablePanel.components[m_ObjectIndex] as UIButton); } else { GameObject asGameObject = UITemplateManager.GetAsGameObject("PlaceableItemTemplate"); uIButton = (m_ScrollablePanel.AttachUIComponent(asGameObject) as UIButton); } uIButton.gameObject.GetComponent <TutorialUITag>().tutorialTag = name; uIButton.text = string.Empty; uIButton.name = name; uIButton.tooltipAnchor = UITooltipAnchor.Anchored; uIButton.tabStrip = true; uIButton.horizontalAlignment = UIHorizontalAlignment.Center; uIButton.verticalAlignment = UIVerticalAlignment.Middle; uIButton.pivot = UIPivotPoint.TopCenter; if (atlas != null) { uIButton.atlas = atlas; } if (index != -1) { uIButton.zOrder = index; } uIButton.verticalAlignment = this.buttonsAlignment; uIButton.foregroundSpriteMode = UIForegroundSpriteMode.Fill; uIButton.normalFgSprite = baseIconName; uIButton.focusedFgSprite = baseIconName + "Focused"; uIButton.hoveredFgSprite = baseIconName + "Hovered"; uIButton.pressedFgSprite = baseIconName + "Pressed"; uIButton.disabledFgSprite = baseIconName + "Disabled"; UIComponent uIComponent = (uIButton.childCount <= 0) ? null : uIButton.components[0]; if (uIComponent != null) { uIComponent.isVisible = false; } uIButton.isEnabled = enabled; uIButton.tooltip = tooltip; uIButton.tooltipBox = tooltipBox; uIButton.group = base.component; m_ObjectIndexField.SetValue(this, m_ObjectIndex + 1); // Start mod uIButton.eventVisibilityChanged += new PropertyChangedEventHandler <bool>(Init); GeneratedScrollPanel panel = this; SimulationManager.instance.AddAction(() => { if (uIButton.objectUserData is PrefabInfo prefab) { string key = Asset.GetName(prefab); if (AssetTagList.instance.assets.ContainsKey(key)) { if (AssetTagList.instance.assets[key].onButtonClicked == null) { MethodInfo onButtonClicked = panel.GetType().GetMethod("OnButtonClicked", BindingFlags.NonPublic | BindingFlags.Instance); AssetTagList.instance.assets[key].onButtonClicked = Delegate.CreateDelegate(typeof(Asset.OnButtonClicked), panel, onButtonClicked, false) as Asset.OnButtonClicked; } } } }); // End mod return(uIButton); }
public bool initDormitories() { Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.initDormitories"); /* * Multi-step initilization process, perform each step one at a time and wait for it to completely finish before moving on. * If an object isn't allowed to initilize complete, interacting with it can crash the game. */ // First refresh the default panels before starting if (!this.hasStartedInit) { this.internalRefreshPanel(false); this.hasStartedInit = true; } // 1) Check the Education Component and replace the Panel with a custom one that will exclude Dormitories UIComponent educationComponent = this.m_Strip.Find(EDUCATION_COMPONENT_NAME); GeneratedScrollPanel educationPanel = this.m_Strip.GetComponentInContainer(educationComponent, typeof(GeneratedScrollPanel)) as GeneratedScrollPanel; if (!(educationPanel is CustomEducationPanel)) { // Check to make sure this step is only done once, if attempting more than once, then just bail to give the process more time to finish if (this.replacedEducationPanel) { Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.initDormitories -- Waiting for replacement of the Education Panel to complete"); return(false); } // Destroy the existing component Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.initDormitories -- Destroying existing Education Panel: {0}", educationPanel); Destroy(educationPanel); // Set the new component Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.initDormitories -- Creating new Custom Education Panel"); UIComponent healthcarePanelContainer = this.m_Strip.tabPages.components[educationComponent.zOrder]; healthcarePanelContainer.gameObject.AddComponent <CustomEducationPanel>(); // Mark this step as complete and bail to ensure this step is allowed to finish Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.initDormitories -- Bailing after finishing setting the Custom Education Panel"); this.replacedEducationPanel = true; return(false); } // 2) Check the Dormitory Component and create it if it's not present UIComponent dormitoryComponent = this.m_Strip.Find(DORMITORY_COMPONENT_NAME); if (dormitoryComponent == null) { // Check to make sure this step is only done once, if attempting more than once, then just bail to give the process more time to finish if (this.replacedDormitoryComponent) { Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.initDormitories -- Waiting for replacement of the Dormitory Component to complete"); return(false); } // Create the new tab for the Dormitory Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.initDormitories -- Creating new Dormitory Tab"); this.SpawnButtonEntry(this.m_Strip, DORMITORY_NAME, DORMITORY_COMPONENT_NAME, true, null, SPRITE_BASE, true, false); // Mark this step as complete and bail to ensure this step is allowed to finish Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.initDormitories -- Bailing after finished creating new Dormitory tab"); this.replacedDormitoryComponent = true; return(false); } // 3) Check the Dormitory Panel and create it if it's not present GeneratedScrollPanel dormitoryPanel = this.m_Strip.GetComponentInContainer(dormitoryComponent, typeof(DormitoryPanel)) as GeneratedScrollPanel; if (dormitoryPanel == null) { // Check to make sure this step is only done once, if attempting more than once, then just bail to give the process more time to finish if (this.replacedDormitoryPanel) { Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.initDormitories -- Waiting for replacement of the Dormitory Panel to complete"); return(false); } // Create the new Dormitory Panel UIComponent dormitoryPanelContainer = this.m_Strip.tabPages.components[dormitoryComponent.zOrder]; Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.initDormitories -- Setting Panel for: {0}", dormitoryPanelContainer); dormitoryPanelContainer.gameObject.AddComponent <DormitoryPanel>(); // Mark this step as complete and bail to ensure this step is allowed to finish Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.initDormitories -- Bailing after setting Nusing Home Panel"); this.replacedDormitoryPanel = true; return(false); } // Ensure there are 2 tabs present now if (this.m_Strip.childCount != 2) { Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.initDormitories -- Bailing because the number of tabs was expected to be 2 but was {0} -- Components detected:", this.m_Strip.childCount); foreach (UIComponent comp in this.m_Strip.components) { Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.initDormitories -- Child Component: {0}", comp); } return(false); } // Remove all children from the Education Panel so it can be repopulated by the new panel logic -- Note: May take more than one iteration to remove them all if (educationPanel.childComponents.Count > 0) { ((CustomEducationPanel)educationPanel).removeAllChildren(); return(false); } // Before finishing, refresh the panel this.RefreshPanel(); Logger.logInfo(PanelHelper.LOG_CUSTOM_PANELS, "CustomEducationGroupPanel.initDormitories -- Done Initing"); return(true); }