private void createCustomPanel(UIComponent component, UIMouseEventParameter eventParam) { UICustomBudgetPanel test = _main.AddUIComponent <UICustomBudgetPanel>(); test.initialize(_main, new BBCustomSaveFile()); deletePanel(); }
public override void Start() { //base.Start(); // load UI and attach the BetterBudget object to its origin (top left) view = UIView.GetAView(); this.transform.parent = view.transform; relativePosition = new Vector3(0, 0); size = new Vector2(0, 0); this.name = "BetterBudgetMod"; isVisible = true; isInteractive = false; //UIView.FullScreenContainer.EconomyPanel isVisible _expensePanel = view.FindUIComponent("FullScreenContainer").Find <UIPanel>("EconomyPanel"); // Create list for slider panels _sliderList = new Dictionary <String, UIPanel>(); _spriteDictionary = new Dictionary <String, String>(); // Find budget container with all slider panels _budgetPanel = view.FindUIComponent <UIPanel>("FullScreenContainer").Find <UIPanel>("EconomyPanel").Find <UITabContainer>("EconomyContainer").Find <UIPanel>("Budget"); // Get all slider panels out of the buget container foreach (UIPanel servicesContainer in _budgetPanel.components) { foreach (UIPanel sliderPanel in servicesContainer.components) { String spriteName; UISprite originalSprite = sliderPanel.Find <UISprite>("Icon"); if (originalSprite.spriteName.Contains("Disabled")) { spriteName = originalSprite.spriteName.Substring(0, originalSprite.spriteName.Length - 8); } else { spriteName = originalSprite.spriteName; } _spriteDictionary.Add(sliderPanel.name, spriteName); _sliderList.Add(sliderPanel.name, sliderPanel); sliderPanel.eventIsEnabledChanged += hitMilestone; } } List <UIPanel> infoViewPanelList = new List <UIPanel>(); _embeddedBudgetPanelList = new List <UIEmbeddedBudgetPanel>(); foreach (UIPanel panel in view.GetComponentsInChildren <UIPanel>()) { if (panel.name.Contains("(Library)") && panel.name.Contains("InfoViewPanel")) { infoViewPanelList.Add(panel); } } foreach (UIPanel infoViewPanel in infoViewPanelList) { UIEmbeddedBudgetPanel embeddedPanel = infoViewPanel.AddUIComponent <UIEmbeddedBudgetPanel>(); embeddedPanel.initialize(this, infoViewPanel); _embeddedBudgetPanelList.Add(embeddedPanel); } // load settings (pretty complex to be expansion viable) BBSettings settings = loadSettings(); if (settings.embeddedPanelSettings.Count > 0) { Dictionary <String, List <String> > map = new Dictionary <String, List <String> >(); foreach (BBEmbeddedSaveFile savefile in settings.embeddedPanelSettings) { map.Add(savefile.infoViewPanelName, savefile.budgetSliderNameList); } foreach (UIEmbeddedBudgetPanel panel in _embeddedBudgetPanelList) { String panelName = panel.getInfoViewPanel().name; if (map.ContainsKey(panelName)) { if (map[panelName].Count > 0) { panel.setSliderPanel(map[panelName].ToArray()); } panel.settings.budgetSliderNameList = map[panelName]; // required to save settings even tho sliders from expansion may be unavailable } } } _customBudgetPanelList = new List <UICustomBudgetPanel>(); if (settings.customPanelSettings.Count > 0) { foreach (BBCustomSaveFile savefile in settings.customPanelSettings) { UICustomBudgetPanel panel = AddUIComponent <UICustomBudgetPanel>(); panel.initialize(this, savefile); } } }
public override void Start() { //base.Start(); // load UI and attach the BetterBudget object to its origin (top left) view = UIView.GetAView(); this.transform.parent = view.transform; relativePosition = new Vector3(0, 0); size = new Vector2(0, 0); this.name = "BetterBudgetMod"; isVisible = true; isInteractive = false; //UIView.FullScreenContainer.EconomyPanel isVisible _expensePanel = view.FindUIComponent("FullScreenContainer").Find <UIPanel>("EconomyPanel"); _expensePanel.absolutePosition = new Vector3(_expensePanel.absolutePosition.x, 5000, _expensePanel.absolutePosition.y); // fix/workaround for economy budget window flickering // Create dictionaries _budgetItems = new Dictionary <String, BudgetItem>(); _originalBudgetPanels = new Dictionary <String, UIPanel>(); _spriteDictionary = new Dictionary <String, String>(); _serviceInfos = new Dictionary <String, ServiceInfo>(); _allBudgetPanels = new Dictionary <String, List <UIPanel> >(); // Find budget container with all slider panels _budgetPanel = view.FindUIComponent <UIPanel>("FullScreenContainer").Find <UIPanel>("EconomyPanel").Find <UITabContainer>("EconomyContainer").Find <UIPanel>("Budget"); // Get all slider panels out of the budget container foreach (UIComponent servicesContainer in _budgetPanel.components) { foreach (UIComponent sliderPanel in servicesContainer.components) { if (sliderPanel.GetComponents <BudgetItem>().Length == 0) { continue; } UISprite originalSprite = sliderPanel.Find <UISprite>("Icon"); // saves the service sprites for the customizer String spriteName; if (originalSprite.spriteName.Contains("Disabled")) { spriteName = originalSprite.spriteName.Substring(0, originalSprite.spriteName.Length - 8); } else { spriteName = originalSprite.spriteName; } // Add value changed event to update all other panels UISlider sliderDay = sliderPanel.Find <UISlider>("DaySlider"); UISlider sliderNight = sliderPanel.Find <UISlider>("NightSlider"); sliderDay.eventValueChanged += copySliderValuesDay; sliderNight.eventValueChanged += copySliderValuesNight; // Add event that unlocks the components sliderPanel.eventIsEnabledChanged += hitMilestone; // save service names and sprites as well as the budget panels (to later remove the milestone event) _spriteDictionary.Add(sliderPanel.name, spriteName); _originalBudgetPanels.Add(sliderPanel.name, (UIPanel)sliderPanel); // Add to budget panel list (to copy values on value changed from one another) if (!_allBudgetPanels.ContainsKey(sliderPanel.name)) { _allBudgetPanels.Add(sliderPanel.name, new List <UIPanel>()); } _allBudgetPanels[sliderPanel.name].Add((UIPanel)sliderPanel); // Add to original BudgetItem list to create copies of them BudgetItem budgetItem = sliderPanel.GetComponents <BudgetItem>()[0]; _budgetItems.Add(sliderPanel.name, budgetItem); // Copy data binding values from BudgetItem (to be later used to initialize the copies) BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; ItemClass.Service service = (ItemClass.Service)(budgetItem.GetType().GetField("m_Service", bindFlags).GetValue(budgetItem)); ItemClass.SubService subService = (ItemClass.SubService)(budgetItem.GetType().GetField("m_SubService", bindFlags).GetValue(budgetItem)); Int32 budgetExpensePollIndex = (Int32)(budgetItem.GetType().GetField("m_BudgetExpensePollIndex", bindFlags).GetValue(budgetItem)); //Debug.Log(sliderPanel.name + " " + service + " " + subService + " " + budgetExpensePollIndex); _serviceInfos.Add(sliderPanel.name, new ServiceInfo(sliderPanel.name, service, subService, budgetExpensePollIndex)); } } // Get all service panels (info views) List <UIPanel> infoViewPanelList = new List <UIPanel>(); _embeddedBudgetPanelList = new List <UIEmbeddedBudgetPanel>(); foreach (UIPanel panel in view.GetComponentsInChildren <UIPanel>()) { if (panel.name.Contains("(Library)") && panel.name.Contains("InfoViewPanel")) { infoViewPanelList.Add(panel); } } // create mod panels and add them to the service info view panels foreach (UIPanel infoViewPanel in infoViewPanelList) { UIEmbeddedBudgetPanel embeddedPanel = infoViewPanel.AddUIComponent <UIEmbeddedBudgetPanel>(); embeddedPanel.initialize(this, infoViewPanel); _embeddedBudgetPanelList.Add(embeddedPanel); } // load settings (complex to be expansion viable) BBSettings settings = loadSettings(); if (settings.embeddedPanelSettings.Count > 0) { Dictionary <String, List <String> > map = new Dictionary <String, List <String> >(); foreach (BBEmbeddedSaveFile savefile in settings.embeddedPanelSettings) { map.Add(savefile.infoViewPanelName, savefile.budgetSliderNameList); } foreach (UIEmbeddedBudgetPanel panel in _embeddedBudgetPanelList) { String panelName = panel.getInfoViewPanel().name; if (map.ContainsKey(panelName)) { if (map[panelName].Count > 0) { panel.setSliderPanel(map[panelName].ToArray()); } panel.settings.budgetSliderNameList = map[panelName]; // ensures that settings are saved across sessions even if some expansions and their budgets may be disabled } } } _customBudgetPanelList = new List <UICustomBudgetPanel>(); if (settings.customPanelSettings.Count > 0) { foreach (BBCustomSaveFile savefile in settings.customPanelSettings) { UICustomBudgetPanel panel = AddUIComponent <UICustomBudgetPanel>(); panel.initialize(this, savefile); } } }