/// <summary> /// 'Save and apply' button event handler. /// </summary> /// <param name="control">Calling component (unused)</param> /// <param name="mouseEvent">Mouse event (unused)</param> protected virtual void Apply(UIComponent control, UIMouseEventParameter mouseEvent) { // Iterate through each sub-service menu. for (int i = 0; i < SubServiceNames.Length; ++i) { // Get population pack menu selected index. int popIndex = PopMenus[i].selectedIndex; // Check to see if this is a change from the current default. if (!PopData.instance.CurrentDefaultPack(Services[i], SubServices[i]).name.Equals(AvailablePopPacks[i][popIndex].name)) { // Default has changed - update default population dictionary for this subservice. PopData.instance.ChangeDefault(Services[i], SubServices[i], AvailablePopPacks[i][popIndex]); } // Update floor data pack if we're not using legacy calculations. if (AvailablePopPacks[i][popIndex].version != (int)DataVersion.legacy) { // Check to see if this is a change from the current default. if (!FloorData.instance.CurrentDefaultPack(Services[i], SubServices[i]).name.Equals(AvailableFloorPacks[FloorMenus[i].selectedIndex])) { // Default has changed - update default floor dictionary for this subservice. FloorData.instance.ChangeDefault(Services[i], SubServices[i], AvailableFloorPacks[FloorMenus[i].selectedIndex]); } } } // Save settings. ConfigUtils.SaveSettings(); }
/// <summary> /// Applies current settings and saves the updated configuration to file. /// </summary> private void ApplySettings() { // Update building setting and save - multiplier first! Multipliers.instance.UpdateMultiplier(currentBuilding, currentMult); PopData.instance.UpdateBuildingPack(currentBuilding, currentPopPack); FloorData.instance.UpdateBuildingPack(currentBuilding, currentFloorPack); // Update multiplier. if (multCheck.isChecked) { // If the multiplier override checkbox is selected, update the multiplier with the slider value. Multipliers.instance.UpdateMultiplier(currentBuilding, currentMult); } else { // Otherwise, delete any multiplier override. Multipliers.instance.DeleteMultiplier(currentBuilding.name); } // Make sure SchoolData is called AFTER student count is settled via Pop and Floor packs, so it can work from updated data. SchoolData.instance.UpdateBuildingPack(currentBuilding, currentSchoolPack); ConfigUtils.SaveSettings(); // Refresh the selection list (to make sure settings checkboxes reflect new state). BuildingDetailsPanel.Panel.RefreshList(); }
/// <summary> /// 'Add new pack' button event handler. /// </summary> /// <param name="control">Calling component (unused)</param> /// <param name="mouseEvent">Mouse event (unused)</param> protected override void AddPack(UIComponent control, UIMouseEventParameter mouseEvent) { // Default new pack name. string basePackName = Translations.Translate("RPR_OPT_NPK"); string newPackName = basePackName; // Integer suffix for when the above name already exists (starts with 2). int packNum = 2; // Current service. ItemClass.Service currentService = services[serviceDropDown.selectedIndex]; // Starting with our default new pack name, check to see if we already have a pack with this name for the currently selected service. while (PopData.instance.calcPacks.Find(pack => ((PopDataPack)pack).service == currentService && pack.name.Equals(newPackName)) != null) { // We already have a match for this name; append the current integer suffix to the base name and try again, incementing the integer suffix for the next attempt (if required). newPackName = "New pack " + packNum++; } // We now have a unique name; set the textfield. PackNameField.text = newPackName; // Add new pack with basic values (deails will be populated later). VolumetricPopPack newPack = new VolumetricPopPack { version = (int)DataVersion.customOne, service = services[serviceDropDown.selectedIndex], levels = new LevelData[maxLevels[serviceDropDown.selectedIndex]] }; // Update pack with information from the panel. UpdatePack(newPack); // Add our new pack to our list of packs and update defaults panel menus. PopData.instance.AddCalculationPack(newPack); CalculationsPanel.Instance.UpdateDefaultMenus(); // Update pack menu. packDropDown.items = PackList(currentService); // Set pack selection by iterating through each pack in the menu and looking for a match. for (int i = 0; i < packDropDown.items.Length; ++i) { if (packDropDown.items[i].Equals(newPack.displayName)) { // Got a match; apply selected index and stop looping. packDropDown.selectedIndex = i; break; } } // Save configuration file. ConfigUtils.SaveSettings(); }
/// <summary> /// Updates the DataStore with the information from the text fields. /// </summary> protected override void ApplyFields() { // Apply each subservice. ApplySubService(DataStore.office, Office); ApplySubService(DataStore.officeHighTech, HighTech); // Clear cached values. PopData.instance.workplaceCache.Clear(); // Save new settings. ConfigUtils.SaveSettings(); // Refresh settings. PopulateFields(); }
/// <summary> /// Updates the DataStore with the information from the text fields. /// </summary> protected override void ApplyFields() { // Apply each subservice. ApplySubService(DataStore.residentialLow, LowRes); ApplySubService(DataStore.residentialHigh, HighRes); ApplySubService(DataStore.resEcoLow, LowEcoRes); ApplySubService(DataStore.resEcoHigh, HighEcoRes); // Clear cached values. PopData.instance.householdCache.Clear(); // Save new settings. ConfigUtils.SaveSettings(); // Refresh settings. PopulateFields(); }
/// <summary> /// Save button event handler. /// <param name="control">Calling component (unused)</param> /// <param name="mouseEvent">Mouse event (unused)</param> /// </summary> protected virtual void Save(UIComponent control, UIMouseEventParameter mouseEvent) { // Update currently selected pack with information from the panel. UpdatePack(packList[packDropDown.selectedIndex]); // Update selected menu item in case the name has changed. packDropDown.items[packDropDown.selectedIndex] = packList[packDropDown.selectedIndex].displayName ?? packList[packDropDown.selectedIndex].name; // Update defaults panel menus. CalculationsPanel.Instance.UpdateDefaultMenus(); // Save configuration file. ConfigUtils.SaveSettings(); // Apply update. FloorData.instance.CalcPackChanged(packList[packDropDown.selectedIndex]); }
/// <summary> /// Sets a custom floor override override for the given building prefab, and saves the updated configuration; and also UPDATES live prefab data. /// Used to add an entry in-game after prefabs have loaded. /// </summary> /// <param name="prefab">Building prefab/param> /// <param name="overridePack">Override floor pack to set</param> internal void SetOverride(BuildingInfo prefab, FloorDataPack overridePack) { // Apply changes. SetOverride(prefab.name, overridePack); // Apply school changes if this is a school. if (prefab.GetService() == ItemClass.Service.Education) { SchoolData.instance.UpdateSchoolPrefab(prefab); } // Save updated configuration file. ConfigUtils.SaveSettings(); // Refresh the prefab's population settings to reflect changes. RefreshPrefab(prefab); }
/// <summary> /// Updates the DataStore with the information from the text fields. /// </summary> protected override void ApplyFields() { // Apply each subservice. ApplySubService(DataStore.commercialLow, LowCom); ApplySubService(DataStore.commercialHigh, HighCom); ApplySubService(DataStore.commercialEco, EcoCom); ApplySubService(DataStore.commercialLeisure, Leisure); ApplySubService(DataStore.commercialTourist, Tourist); // Clear cached values. PopData.instance.workplaceCache.Clear(); // Save new settings. ConfigUtils.SaveSettings(); // Refresh settings. PopulateFields(); }
/// <summary> /// Updates the DataStore with the information from the text fields. /// </summary> protected override void ApplyFields() { // Apply each subservice. ApplySubService(DataStore.industry, Generic); ApplySubService(DataStore.industry_farm, Farming); ApplySubService(DataStore.industry_forest, Forestry); ApplySubService(DataStore.industry_oil, Oil); ApplySubService(DataStore.industry_ore, Ore); // Clear cached values. PopData.instance.workplaceCache.Clear(); // Save new settings. ConfigUtils.SaveSettings(); // Refresh settings. PopulateFields(); }
/// <summary> /// Removes any manual population override for the given building prefab, and saves the updated configuration if an override was actually removed (i.e. one actually existed). /// </summary> /// <param name="prefab">Building prefab/param> internal void DeleteOverride(BuildingInfo prefab) { // Remove prefab record from dictionary. if (overrides.Remove(prefab.name)) { // An entry was removed (i.e. dictionary contained an entry); apply changes to relevant school. if (prefab.GetService() == ItemClass.Service.Education) { SchoolData.instance.UpdateSchoolPrefab(prefab); } // Save the updated configuration file. ConfigUtils.SaveSettings(); // Refresh the prefab's population settings to reflect changes. RefreshPrefab(prefab); } }
/// <summary> /// 'Save and apply' button event handler. /// </summary> /// <param name="control">Calling component (unused)</param> /// <param name="mouseEvent">Mouse event (unused)</param> protected virtual void Apply(UIComponent control, UIMouseEventParameter mouseEvent) { // Save settings. ConfigUtils.SaveSettings(); }
/// <summary> /// Saves and applies settings - save button event handler. /// </summary> private void SaveAndApply() { // Hide message. messageLabel.isVisible = false; // Don't do anything with invalid entries. if (currentSelection == null || currentSelection.name == null) { return; } // Are we doing population overrides? if (popCheck.isChecked) { // Read total floor count textfield if possible; ignore zero values if (int.TryParse(homeJobsCount.textField.text, out int homesJobs) && homesJobs != 0) { // Minimum value of 1. if (homesJobs < 1) { // Print warning message in red. messageLabel.textColor = new Color32(255, 0, 0, 255); messageLabel.text = Translations.Translate("RPR_ERR_ZERO"); messageLabel.isVisible = true; } else { // Set overide. PopData.instance.SetOverride(currentSelection, homesJobs); // Update CitizenUnits for existing building instances. CitizenUnitUtils.UpdateCitizenUnits(currentSelection.name, ItemClass.Service.None, currentSelection.GetSubService(), false); // Repopulate field with parsed value. homeJobLabel.text = homesJobs.ToString(); } } else { // TryParse couldn't parse any data; print warning message in red. messageLabel.textColor = new Color32(255, 0, 0, 255); messageLabel.text = Translations.Translate("RPR_ERR_INV"); messageLabel.isVisible = true; } } else { // Population override checkbox wasn't checked; remove any custom settings. PopData.instance.DeleteOverride(currentSelection); // Remove any legacy file settings to avoid conflicts. OverrideUtils.RemoveResidential(currentSelection); OverrideUtils.RemoveWorker(currentSelection); } // Are we doing floor overrides? if (floorCheck.isChecked) { // Attempt to parse values into override floor pack. FloorDataPack overrideFloors = TryParseFloors(); // Were we successful?. if (overrideFloors != null) { // Successful parsing - add override. FloorData.instance.SetOverride(currentSelection, overrideFloors); // Save configuration. ConfigUtils.SaveSettings(); // Update panel override. BuildingDetailsPanel.Panel.OverrideFloors = overrideFloors; // Repopulate fields with parsed values. UpdateFloorTextFields(overrideFloors.firstFloorMin.ToString(), overrideFloors.floorHeight.ToString()); } else { // Couldn't parse values; print warning message in red. messageLabel.textColor = new Color32(255, 0, 0, 255); messageLabel.text = Translations.Translate("RPR_ERR_INV"); messageLabel.isVisible = true; } } else { // Floor override checkbox wasn't checked; remove any floor override. FloorData.instance.DeleteOverride(currentSelection); } // Refresh the display so that all panels reflect the updated settings. BuildingDetailsPanel.Panel.Refresh(); }