/// <summary>
        /// Saves the current RICO settings to file and then applies them live in-game.
        /// </summary>
        private void SaveAndApply()
        {
            // Find current prefab instance.
            BuildingData currentBuildingData = Loading.xmlManager.prefabHash[currentSelection.prefab];

            // Save first.
            Save();

            // Get the currently applied RICO settings (local, author, mod).
            RICOBuilding currentData = RICOUtils.CurrentRICOSetting(currentSelection);

            if (currentData != null)
            {
                // Convert the 'live' prefab (instance in PrefabCollection) and update household count and builidng level for all current instances.
                Loading.convertPrefabs.ConvertPrefab(currentData, PrefabCollection <BuildingInfo> .FindLoaded(currentBuildingData.prefab.name));
                CitizenUnitUtils.UpdateCitizenUnits(currentBuildingData.prefab.name);
            }
            else
            {
                Logging.Message("no current RICO settings to apply to prefab ", currentBuildingData.prefab.name);
            }

            // Force an update of all panels with current values.
            SettingsPanel.Panel.UpdateSelectedBuilding(currentSelection);
        }
        /// <summary>
        /// Saves the current RICO settings to file and then applies them live in-game.
        /// </summary>
        private void SaveAndApply()
        {
            // Find current prefab instance.
            BuildingData currentBuildingData = Loading.xmlManager.prefabHash[currentSelection.prefab];

            // Save first.
            Save();

            // If we're converting a residential building to something else, then we first should clear out all households.
            if (currentBuildingData.prefab.GetService() == ItemClass.Service.Residential && !IsCurrentResidential())
            {
                // removeAll argument to true to remove all households.
                UpdateHouseholds(currentBuildingData.prefab.name, removeAll: true);
            }

            // Get the currently applied RICO settings (local, author, mod).
            RICOBuilding currentData = RICOUtils.CurrentRICOSetting(currentSelection);

            if (currentData != null)
            {
                // Convert the 'live' prefab (instance in PrefabCollection) and update household count and builidng level for all current instances.
                Loading.convertPrefabs.ConvertPrefab(currentData, PrefabCollection <BuildingInfo> .FindLoaded(currentBuildingData.prefab.name));
                UpdateHouseholds(currentBuildingData.prefab.name, currentData.level);
            }
            else
            {
                Debugging.Message("no current RICO settings to apply to prefab " + currentBuildingData);
            }

            // Force an update of all panels with current values.
            SettingsPanel.Panel.UpdateSelectedBuilding(currentSelection);
        }
        /// <summary>
        /// Handles click events for Ploppable Tool panel tabs.
        /// </summary>
        /// <param name="panel">The Ploppable Tool panel for the selected tab</param>
        /// <param name="sprite">The sprite icon for the selected tab</param>
        public void TabClicked(int uiCategory, UISprite sprite)
        {
            // Clear the scroll panel.
            scrollPanel.Clear();

            // List of buildings in this category.
            List <BuildingData> buildingList = new List <BuildingData>();

            // Iterate through each prefab in our collection and see if it has RICO settings with a matching UI category.
            foreach (BuildingData buildingData in Loading.xmlManager.prefabHash.Values)
            {
                // Get the currently active RICO setting (if any) for this building.
                RICOBuilding ricoSetting = RICOUtils.CurrentRICOSetting(buildingData);

                // See if there's a valid RICO setting.
                if (ricoSetting != null)
                {
                    // Valid setting - if the UI category matches this one, add it to the list.
                    if (UICategoryIndex(ricoSetting.UiCategory) == uiCategory)
                    {
                        buildingList.Add(buildingData);
                    }
                }
            }

            // Set display FastList using our list of selected buildings, sorted alphabetically.
            scrollPanel.itemsData.m_buffer = buildingList.OrderBy(x => x.DisplayName).ToArray();
            scrollPanel.itemsData.m_size   = buildingList.Count;

            // Display the scroll panel.
            scrollPanel.DisplayAt(0);

            // Redraw all tab sprites in their base state (unfocused).
            for (int i = 0; i <= NumTypes; i++)
            {
                if (i <= 5)
                {
                    TabSprites[i].spriteName = "Zoning" + Names[i];
                }
                else
                {
                    TabSprites[i].spriteName = "IconPolicy" + Names[i];
                }
            }

            // Focus this sprite (no focused versions for AD or GC sprites so exclude those).
            if (sprite.spriteName != "IconPolicyLeisure" && sprite.spriteName != "IconPolicyTourist" && sprite.spriteName != "IconPolicyHightech" && sprite.spriteName != "IconPolicyOrganic" && sprite.spriteName != "IconPolicySelfsufficient")
            {
                sprite.spriteName += "Focused";
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Called by other mods to determine whether or not Ploppable RICO Revisited is controlling the population of this prefab.
        /// </summary>
        /// <param name="prefab">Prefab reference</param>
        /// <returns>True if Ploppable RICO is controlling the population of this prefab, false otherwise.</returns>
        public static bool IsRICOPopManaged(BuildingInfo prefab)
        {
            // First, do we have a setting at all?
            if (prefab != null && Loading.xmlManager.prefabHash.ContainsKey(prefab))
            {
                // Get active RICO settings.
                RICOBuilding building = RICOUtils.CurrentRICOSetting(Loading.xmlManager.prefabHash[prefab]);

                // Check that it's enabled and isn't using reality.
                if (building != null && building.ricoEnabled && !building.UseReality)
                {
                    return(true);
                }
            }

            // If we got here, we don't have an active setting.
            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Event handler for demolish warning checkbox.
        /// </summary>
        /// <param name="control">Calling UIComponent</param>
        /// <param name="isChecked">New isChecked state</param>
        private void DemolishWarnCheckChanged(UIComponent control, bool isChecked)
        {
            // Update mod settings.
            ModSettings.warnBulldoze = isChecked;

            // If we're in-game (dictionary has been initialized), iterate through dictionary, looking for RICO ploppable buildings and updating their auto-remove flags.
            if (Loading.xmlManager?.prefabHash != null)
            {
                foreach (BuildingInfo prefab in Loading.xmlManager.prefabHash.Keys)
                {
                    // Get active RICO settings.
                    RICOBuilding building = RICOUtils.CurrentRICOSetting(Loading.xmlManager.prefabHash[prefab]);

                    // Check that it's enabled and isn't growable.
                    if (building != null && building.ricoEnabled && !building.growable)
                    {
                        // Apply flag.
                        prefab.m_autoRemove = !isChecked;
                    }
                }
            }
        }