コード例 #1
0
        /// <summary>
        /// Populates the textfields with data from the selected calculation pack.
        /// </summary>
        /// <param name="index">Index number of calculation pack</param>
        private void PopulateTextFields(int index)
        {
            // Get local reference.
            VolumetricPopPack volPack = (VolumetricPopPack)packList[index];

            // Set name field.
            PackNameField.text = volPack.displayName ?? volPack.name;

            // Set service selection menu by iterating through each service and looking for a match.
            for (int i = 0; i < services.Length; ++i)
            {
                if (services[i] == volPack.service)
                {
                    // Got a match; apply selected index and stop looping.
                    // This also applies text field visibility via the service menue event handler.
                    serviceDropDown.selectedIndex = i;
                    break;
                }
            }

            // Iterate through each level in the pack and populate the relevant row.
            for (int i = 0; i < volPack.levels.Length; ++i)
            {
                // Local reference.
                LevelData level = volPack.levels[i];

                // Populate controls.
                emptyAreaFields[i].text       = level.emptyArea.ToString();
                emptyPercentFields[i].text    = level.emptyPercent.ToString();
                fixedPopChecks[i].isChecked   = level.areaPer < 0;
                areaPerFields[i].text         = Math.Abs(level.areaPer).ToString();
                fixedPopFields[i].text        = Math.Abs(level.areaPer).ToString();
                multiFloorChecks[i].isChecked = level.multiFloorUnits;
            }
        }
コード例 #2
0
        /// <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();
        }
コード例 #3
0
        /// <summary>
        /// Load settings from XML file.
        /// </summary>
        internal static void LoadSettings()
        {
            try
            {
                // Check to see if configuration file exists.
                if (File.Exists(ConfigFileName))
                {
                    // Read it.
                    using (StreamReader reader = new StreamReader(ConfigFileName))
                    {
                        XmlSerializer xmlSerializer = new XmlSerializer(typeof(XMLConfigurationFile));

                        if (!(xmlSerializer.Deserialize(reader) is XMLConfigurationFile configFile))
                        {
                            Logging.Error("couldn't deserialize configuration file");
                        }
                        else
                        {
                            // Deserialise population calculation packs.
                            foreach (PopPackXML xmlPack in configFile.popPacks)
                            {
                                // Convert to volumetric pack.
                                VolumetricPopPack volPack = new VolumetricPopPack()
                                {
                                    name        = xmlPack.name,
                                    displayName = xmlPack.name,
                                    service     = xmlPack.service,
                                    version     = (int)DataVersion.customOne,
                                    levels      = new LevelData[xmlPack.calculationLevels.Count]
                                };

                                // Iterate through each level in the xml and add to our volumetric pack.
                                foreach (PopLevel calculationLevel in xmlPack.calculationLevels)
                                {
                                    volPack.levels[calculationLevel.level] = new LevelData()
                                    {
                                        //floorHeight = calculationLevel.floorHeight,
                                        emptyArea       = calculationLevel.emptyArea,
                                        emptyPercent    = calculationLevel.emptyPercent,
                                        areaPer         = calculationLevel.areaPer,
                                        multiFloorUnits = calculationLevel.multiLevel
                                    };
                                }

                                // Add new pack to our dictionary.
                                PopData.instance.AddCalculationPack(volPack);
                            }

                            // Deserialise floor calculation packs.
                            foreach (FloorPackXML xmlPack in configFile.floorPacks)
                            {
                                // Convert to floor pack.
                                FloorDataPack floorPack = new FloorDataPack()
                                {
                                    name            = xmlPack.name,
                                    displayName     = xmlPack.name,
                                    version         = (int)DataVersion.customOne,
                                    floorHeight     = xmlPack.floorHeight,
                                    firstFloorMin   = xmlPack.firstMin,
                                    firstFloorExtra = xmlPack.firstExtra,
                                    firstFloorEmpty = xmlPack.firstEmpty
                                };

                                // Add new pack to our dictionary.
                                FloorData.instance.AddCalculationPack(floorPack);
                            }


                            // Deserialise consumption records.
                            DataMapping mapper = new DataMapping();
                            foreach (ConsumptionRecord consumptionRecord in configFile.consumption)
                            {
                                // Get relevant DataStore array for this record.
                                int[][] dataArray = mapper.GetArray(consumptionRecord.service, consumptionRecord.subService);

                                // Iterate through each consumption line and populate relevant DataStore fields.
                                foreach (ConsumptionLine consumptionLine in consumptionRecord.levels)
                                {
                                    int level = (int)consumptionLine.level;
                                    dataArray[level][DataStore.POWER]            = consumptionLine.power;
                                    dataArray[level][DataStore.WATER]            = consumptionLine.water;
                                    dataArray[level][DataStore.SEWAGE]           = consumptionLine.sewage;
                                    dataArray[level][DataStore.GARBAGE]          = consumptionLine.garbage;
                                    dataArray[level][DataStore.GROUND_POLLUTION] = consumptionLine.pollution;
                                    dataArray[level][DataStore.NOISE_POLLUTION]  = consumptionLine.noise;
                                    dataArray[level][DataStore.MAIL]             = consumptionLine.mail;
                                    dataArray[level][DataStore.INCOME]           = consumptionLine.income;
                                }
                            }

                            // Deserialise default pack lists.
                            PopData.instance.DeserializeDefaults(configFile.popDefaults);
                            FloorData.instance.DeserializeDefaults(configFile.floorDefaults);

                            // Deserialise building pack lists.
                            PopData.instance.DeserializeBuildings(configFile.buildings);
                            FloorData.instance.DeserializeBuildings(configFile.buildings);
                            SchoolData.instance.DeserializeBuildings(configFile.buildings);
                            Multipliers.instance.DeserializeBuildings(configFile.buildings);

                            // Deserialise building population overrides.
                            PopData.instance.DeserializeOverrides(configFile.popOverrides);

                            // Deserialize floor overrides.
                            foreach (FloorCalcOverride floorOverride in configFile.floors)
                            {
                                FloorData.instance.SetOverride(floorOverride.prefab, new FloorDataPack
                                {
                                    firstFloorMin = floorOverride.firstHeight,
                                    floorHeight   = floorOverride.floorHeight
                                });
                            }

                            // Deserialise visit modes.
                            RealisticVisitplaceCount.DeserializeVisits(configFile.visitorModes);

                            // Deserialise commercial sales multipliers.
                            GoodsUtils.DeserializeSalesMults(configFile.salesMults);

                            // Deserialise office production multipliers.
                            RealisticOfficeProduction.DeserializeProdMults(configFile.offProdMults);

                            // Deserialize industrial production calculation modes.
                            RealisticIndustrialProduction.DeserializeProds(configFile.indProdModes);
                            RealisticExtractorProduction.DeserializeProds(configFile.extProdModes);

                            // Deserialise commercial inventory caps.
                            GoodsUtils.DeserializeInvCaps(configFile.comIndCaps);
                        }
                    }
                }