/// <summary> /// (Re-)loads the current config (per ConfigurationUtils.CurrentSavedConfigName). /// </summary> private void LoadConfig() { // Clear current replacements. ReplacementUtils.NukeSettings(); // Load config file. ConfigurationUtils.LoadConfig(); Logging.KeyMessage("reloaded global configuration"); // Update button states accordingly. UpdateButtonStates(); // Update dirty renders. BuildingData.Update(); NetData.Update(); }
/// <summary> /// 'Save and apply' button event handler. Should onl be called ingame. /// </summary> /// <param name="control">Calling component (unused)</param> /// <param name="mouseEvent">Mouse event (unused)</param> private void Apply(UIComponent control, UIMouseEventParameter mouseEvent) { // Safety check. if (!inGame) { return; } // Are we using custom settings for this savegame, and have a valid current selection? if (customCheck.isChecked && !string.IsNullOrEmpty(selectedConfig)) { // Yes - set current configuration file. ConfigurationUtils.currentConfig = selectedConfig; // Clear current replacements. ReplacementUtils.NukeSettings(); // Load config file. ConfigurationUtils.LoadConfig(); Logging.KeyMessage("current configuration set to ", ConfigurationUtils.currentConfig); } else { // No custom settings - did we have any previously? if (ConfigurationUtils.currentConfig != null) { // We had previous settings - reset. ConfigurationUtils.currentConfig = null; // Clear current replacements. ReplacementUtils.NukeSettings(); // Load config file. ConfigurationUtils.LoadConfig(); Logging.KeyMessage("current configuration set to default"); } } }
/// <summary> /// Adds configurations panel tab to tabstrip. /// </summary> /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> internal ConfigurationsPanel(UITabstrip tabStrip, int tabIndex) { // Set reference. instance = this; // Determine if we're in-game or not; use status of replacer managers to determine. inGame = BuildingReplacement.Instance != null && NetworkReplacement.Instance != null; // Add tab and helper. UIPanel panel = PanelUtils.AddTab(tabStrip, Translations.Translate("BOB_OPT_CFG"), tabIndex); UIHelper helper = new UIHelper(panel); panel.autoLayout = false; // Config list panel. UIPanel configListPanel = panel.AddUIComponent <UIPanel>(); configListPanel.width = ListWidth; configListPanel.height = ListHeight; configListPanel.relativePosition = new Vector2(Margin, ListY); // Config selection list. configList = UIFastList.Create <UIConfigRow>(configListPanel); configList.backgroundSprite = "UnlockingPanel"; configList.width = configListPanel.width; configList.height = configListPanel.height; configList.canSelect = true; configList.rowHeight = RowHeight; configList.autoHideScrollbar = true; configList.relativePosition = Vector2.zero; configList.rowsData = new FastList <object>(); // File name textfield. UILabel fileTextLabel = UIControls.AddLabel(panel, ControlPanelX, ListY, "New configuration name:"); fileNameField = UIControls.AddTextField(panel, ControlPanelX, ListY + fileTextLabel.height); fileNameField.eventTextChanged += (control, text) => UpdateButtonStates(); // Buttons. activeCopyButton = UIControls.AddButton(panel, ControlPanelX, ListY + 70f, Translations.Translate("BOB_CFG_SAC"), 300f, scale: 0.8f); activeCopyButton.eventClicked += NewCurrent; selectedCopyButton = UIControls.AddButton(panel, ControlPanelX, ListY + 105f, Translations.Translate("BOB_CFG_SSC"), 300f, scale: 0.8f); selectedCopyButton.eventClicked += CopySelected; newCleanButton = UIControls.AddButton(panel, ControlPanelX, ListY + 140f, Translations.Translate("BOB_CFG_SEC"), 300f, scale: 0.8f); newCleanButton.eventClicked += NewClean; deleteButton = UIControls.AddButton(panel, ControlPanelX, ListY + 210f, Translations.Translate("BOB_CFG_DEL"), 300f, scale: 0.8f); deleteButton.eventClicked += Delete; // Ingame buttons - 'use custom' check and apply and nuke buttons. if (inGame) { // Use custom check box. customCheck = UIControls.LabelledCheckBox(panel, Margin, ToolBarY, Translations.Translate("BOB_CFG_UCS")); customCheck.eventCheckChanged += (control, isChecked) => { // If we've got a valid selection, set the current config name to this. if (isChecked && !string.IsNullOrEmpty(selectedConfig)) { ConfigurationUtils.CurrentSavedConfigName = selectedConfig; } }; // Apply button. UIButton applyButton = UIControls.AddButton(panel, Margin, FooterY, Translations.Translate("BOB_CFG_LAA"), 400f, scale: 0.8f); applyButton.eventClicked += Apply; // Use global configuration button. UIButton globalButton = UIControls.AddButton(panel, Margin, FooterY + 50f, Translations.Translate("BOB_CFG_LGL"), 400f, scale: 0.8f); globalButton.eventClicked += UseGlobal; // Clean up config button. UIButton cleanUpButton = UIControls.AddButton(panel, Margin + 50f, FooterY + 150f, Translations.Translate("BOB_CFG_CLE"), 300f); cleanUpButton.tooltip = Translations.Translate("BOB_CFG_CLE_TIP"); cleanUpButton.eventClicked += (control, clickEvent) => ConfigurationUtils.Cleanup(); // Nuke all settings button. UIButton nukeButton = UIControls.AddButton(panel, Margin + 50f, FooterY + 200f, Translations.Translate("BOB_NUKE"), 300f); nukeButton.eventClicked += (control, clickEvent) => { // Revert all-building and building settings. ReplacementUtils.NukeSettings(); // Save clean configuration. //ConfigurationUtils.SaveConfig(ConfigurationUtils.CurrentSavedConfigName, true); }; } // Populate selection list and set initial button states. RefreshList(); // Select current pack if we've got one. if (customCheck != null && customCheck.isChecked) { // Try to select current config name. selectedConfig = configList.FindItem(ConfigurationUtils.CurrentSavedConfigName); // Did we find it? if (selectedConfig == null) { // Not found; uncheck the use custom check. customCheck.isChecked = false; } } // Set initial button states. UpdateButtonStates(); }