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 void initialize(BetterBudget2 main, UIEmbeddedBudgetPanel panel, List <UIPanel> sliderList) { this._main = main; this._panel = panel; this.transform.parent = panel.parent.transform; relativePosition = new Vector3(panel.parent.width, 0); int containerHeight = (int)Math.Ceiling(_main._spriteDictionary.Count / 4.0) * 35 + 5; size = new Vector2(400, 155 + containerHeight); canFocus = true; isInteractive = true; isVisible = true; backgroundSprite = "MenuPanel2"; color = new Color32(255, 255, 255, 255); UILabel label = AddUIComponent <UILabel>(); label.text = "Budget Editor"; label.transform.parent = this.transform; label.relativePosition = new Vector3((width / 2) - ((label.text.Length / 2) * 8), 12); label.name = "Title"; // icon _icon = AddUIComponent <UISprite>(); _icon.relativePosition = new Vector3(2, 2); _icon.spriteName = "MoneyThumb"; _icon.name = "Icon"; _icon.size = new Vector2(40, 40); // Drag Handler UIDragHandle draghandler = AddUIComponent <UIDragHandle>(); draghandler.relativePosition = new Vector3(0, 0); draghandler.transform.parent = this.transform; draghandler.target = this; draghandler.name = "Drag Handler"; draghandler.size = new Vector2(this.width, 41); // Quit Button _quitButton = AddUIComponent <UIButton>(); _quitButton.name = "Quit Button"; _quitButton.normalBgSprite = "buttonclose"; _quitButton.pressedBgSprite = "buttonclosehover"; _quitButton.hoveredBgSprite = "buttonclosepressed"; _quitButton.focusedBgSprite = "buttonclosehover"; _quitButton.eventClick += closePanel; _quitButton.size = new Vector2(36, 36); _quitButton.relativePosition = new Vector3(width - 43, 2); // container Unselected _containerUnselected = AddUIComponent <UIPanel>(); _containerUnselected.name = "Slider Container Unselected"; _containerUnselected.backgroundSprite = "GenericPanel"; _containerUnselected.relativePosition = new Vector3(30, 60); _containerUnselected.size = new Vector2(145, containerHeight); _containerUnselected.autoLayout = true; _containerUnselected.autoSize = false; _containerUnselected.autoLayoutStart = LayoutStart.TopLeft; _containerUnselected.autoLayoutDirection = LayoutDirection.Horizontal; _containerUnselected.autoLayoutPadding = new RectOffset(5, 0, 5, 0); _containerUnselected.wrapLayout = true; // Arrow _spriteArrow = AddUIComponent <UISprite>(); _spriteArrow.name = "Arrow Sprite"; _spriteArrow.spriteName = "ArrowRight"; _spriteArrow.relativePosition = new Vector3(163, 100); _spriteArrow.size = new Vector3(64, 64); // container Selected _containerSelected = AddUIComponent <UIPanel>(); _containerSelected.name = "Slider Container Selected"; _containerSelected.backgroundSprite = "GenericPanel"; _containerSelected.relativePosition = new Vector3(225, 60); _containerSelected.size = new Vector2(145, containerHeight); _containerSelected.autoLayout = true; _containerSelected.autoSize = false; _containerSelected.autoLayoutStart = LayoutStart.TopLeft; _containerSelected.autoLayoutDirection = LayoutDirection.Horizontal; _containerSelected.autoLayoutPadding = new RectOffset(5, 0, 5, 0); _containerSelected.wrapLayout = true; // budget selected icons foreach (UIPanel sliderPanel in sliderList) { UISprite sprite = _containerSelected.AddUIComponent <UISprite>(); sprite.name = sliderPanel.name; sprite.spriteName = _main._spriteDictionary[sliderPanel.name]; sprite.size = new Vector2(30, 30); sprite.eventClick += toggleSprite; sprite.isInteractive = true; } // budget unselected icons foreach (KeyValuePair <String, String> entry in _main._spriteDictionary) { if (_containerSelected.Find <UISprite>(entry.Key) == null) { UISprite sprite = _containerUnselected.AddUIComponent <UISprite>(); sprite.name = entry.Key; sprite.spriteName = entry.Value; sprite.size = new Vector2(30, 30); sprite.eventClick += toggleSprite; sprite.isInteractive = true; } } // apply changes UIButton button = AddUIComponent <UIButton>(); button.name = "Apply Button"; button.size = new Vector2(340, 30); button.relativePosition = new Vector3(30, 75 + containerHeight); button.normalBgSprite = "ButtonMenu"; button.focusedBgSprite = "ButtonMenuFocused"; button.hoveredBgSprite = "ButtonMenuHovered"; button.pressedBgSprite = "ButtonMenuPressed"; button.text = "Apply"; button.textScale = 1.3f; button.eventClick += applyChanges; // apply changes UIButton button2 = AddUIComponent <UIButton>(); button2.name = "Create Custom Panel Button"; button2.size = new Vector2(340, 30); button2.relativePosition = new Vector3(30, 115 + containerHeight); button2.normalBgSprite = "ButtonMenu"; button2.focusedBgSprite = "ButtonMenuFocused"; button2.hoveredBgSprite = "ButtonMenuHovered"; button2.pressedBgSprite = "ButtonMenuPressed"; button2.text = "Create Custom Panel"; button2.textScale = 1.3f; button2.eventClick += createCustomPanel; }
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); } } }