/// <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;

            // 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 (FloorData.instance.calcPacks.Find(pack => 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).
            FloorDataPack newPack = new FloorDataPack
            {
                version = (int)DataVersion.customOne
            };

            // Update pack with information from the panel.
            UpdatePack(newPack);

            // Add our new pack to our list of packs and update defaults panel menus.
            FloorData.instance.AddCalculationPack(newPack);
            CalculationsPanel.Instance.UpdateDefaultMenus();

            // Update pack menu.
            packDropDown.items = PackList();

            // 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();
        }
Exemple #2
0
        /// <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]);
        }
Exemple #5
0
        /// <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);
        }
Exemple #6
0
        /// <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();
        }
Exemple #8
0
        /// <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>
        /// Adds control buttons to the bottom of the panel.
        /// </summary>
        /// <param name="panel">UI panel instance</param>
        protected void AddButtons(UIPanel panel)
        {
            // Add extra space.
            currentY += Margin;

            // Reset button.
            UIButton resetButton = UIControls.AddButton(panel, Margin, currentY, Translations.Translate("RPR_OPT_RTD"), 150f);

            resetButton.eventClicked += (component, clickEvent) => ResetToDefaults();

            // Revert button.
            UIButton revertToSaveButton = UIControls.AddButton(panel, (Margin * 2) + 150f, currentY, Translations.Translate("RPR_OPT_RTS"), 150f);

            revertToSaveButton.eventClicked += (component, clickEvent) => { ConfigUtils.LoadSettings(); PopulateFields(); };

            // Save button.
            UIButton saveButton = UIControls.AddButton(panel, (Margin * 3) + 300f, currentY, Translations.Translate("RPR_OPT_SAA"), 150f);

            saveButton.eventClicked += (component, clickEvent) => ApplyFields();
        }
Exemple #10
0
 /// <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();
 }
Exemple #11
0
        /// <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();
        }