public static void UpdateSliders()
        {
            UIPanel budgetPanel = getBudgetPanel();

            if (budgetPanel != null)
            {
                SimulationManager          sm = Singleton <SimulationManager> .instance;
                AutobudgetObjectsContainer c  = Singleton <AutobudgetManager> .instance.container;

                freezeUI = true;
                foreach (AutobudgetBase obj in c.AllAutobudgetObjects)
                {
                    UIComponent budgetItem = budgetPanel.Find(obj.GetBudgetItemName());
                    if (budgetItem != null)
                    {
                        UISlider slider       = budgetItem.Find <UISlider>(sm.m_isNightTime ? "NightSlider" : "DaySlider");
                        int      updatedValue = Singleton <EconomyManager> .instance.GetBudget(obj.GetService(), obj.GetSubService(), sm.m_isNightTime);

                        if (slider.value != updatedValue)
                        {
                            slider.value = updatedValue;
                        }
                    }
                }
                freezeUI = false;
            }
        }
        private static void removeControls()
        {
            UITabContainer economyContainer = ToolsModifierControl.economyPanel.component.Find <UITabContainer>("EconomyContainer");

            if (economyContainer != null)
            {
                UIPanel budgetPanel = economyContainer.Find <UIPanel>("Budget");
                if (budgetPanel != null)
                {
                    AutobudgetObjectsContainer c = Singleton <AutobudgetManager> .instance.container;

                    foreach (AutobudgetBase obj in c.AllAutobudgetObjects)
                    {
                        UIPanel container = budgetPanel.Find <UIPanel>(obj.GetEconomyPanelContainerName());
                        if (container != null)
                        {
                            UIPanel budgetItem = container.Find <UIPanel>(obj.GetBudgetItemName());
                            if (budgetItem != null)
                            {
                                string controlName = AutobudgetItemPanel.GetControlNameFromItemName(obj.GetBudgetItemName());
                                AutobudgetItemPanel autobudgetItemControl = budgetItem.Find <AutobudgetItemPanel>(controlName);
                                if (autobudgetItemControl != null)
                                {
                                    budgetItem.RemoveUIComponent(autobudgetItemControl);
                                    Component.Destroy(autobudgetItemControl);
                                }
                            }
                        }
                    }
                }
            }
        }
        public void ReadValuesFromFile()
        {
            container = AutobudgetObjectsContainer.CreateFromFile();
            if (container == null)
            {
                container = new AutobudgetObjectsContainer();
            }

            container.InitObjects();
        }
        protected override void setAutobudget()
        {
            DistrictManager dm = Singleton <DistrictManager> .instance;

            int capacity = dm.m_districts.m_buffer[0].GetElectricityCapacity();

            // No electricity
            if (capacity <= 0)
            {
                return;
            }

            int consumption = dm.m_districts.m_buffer[0].GetElectricityConsumption();

            // No changes from the previous state
            if (capacity == capacity_prev && consumption == consumption_prev)
            {
                return;
            }

            capacity_prev    = capacity;
            consumption_prev = consumption;

            int electricityFromGarbage = getGarbageElectricityProduction();
            //Debug.Log(string.Format("capacity = {0}, consumption = {1}, getGarbageElectricityProduction = {2}", capacity, consumption, getGarbageElectricityProduction()));

            AutobudgetObjectsContainer o  = Singleton <AutobudgetManager> .instance.container;
            EconomyManager             em = Singleton <EconomyManager> .instance;
            SimulationManager          sm = Singleton <SimulationManager> .instance;

            int budget    = em.GetBudget(ItemClass.Service.Electricity, ItemClass.SubService.None, sm.m_isNightTime);
            int newBudget = calculateNewBudget(capacity - electricityFromGarbage, consumption - electricityFromGarbage, budget, getBufferCoefficient(AutobudgetBuffer));

            newBudget = Math.Min(newBudget, BudgetMaxValue);

            if (newBudget == BudgetMaxValue && PauseWhenBudgetTooHigh && !isPausedRecently)
            {
                Helper.SetPause();
                isPausedRecently = true;
                Singleton <InfoManager> .instance.SetCurrentMode(InfoManager.InfoMode.Electricity, InfoManager.SubInfoMode.Default);
            }

            if (newBudget < BudgetMaxValue)
            {
                isPausedRecently = false;
            }

            setBudget(newBudget);
        }
        public static void UpdateControls()
        {
            UIPanel budgetPanel = getBudgetPanel();

            if (budgetPanel != null)
            {
                AutobudgetObjectsContainer c = Singleton <AutobudgetManager> .instance.container;

                freezeUI = true;
                foreach (AutobudgetBase obj in c.AllAutobudgetObjects)
                {
                    updateCheckBox(budgetPanel, obj.GetBudgetItemName(), obj.Enabled);
                }
                freezeUI = false;
            }
        }
        private static void updateControlsPositions()
        {
            UIPanel budgetPanel = getBudgetPanel();

            if (budgetPanel != null)
            {
                AutobudgetObjectsContainer c = Singleton <AutobudgetManager> .instance.container;

                foreach (AutobudgetBase obj in c.AllAutobudgetObjects)
                {
                    AutobudgetItemPanel autobudgetItem = budgetPanel.Find <AutobudgetItemPanel>(AutobudgetItemPanel.GetControlNameFromItemName(obj.GetBudgetItemName()));
                    if (autobudgetItem != null)
                    {
                        autobudgetItem.UpdatePosition();
                    }
                }
            }
        }
Пример #7
0
        public static AutobudgetObjectsContainer CreateFromFile()
        {
            string path = getOptionsFilePath();

            if (!File.Exists(path))
            {
                return(null);
            }

            try
            {
                XmlSerializer ser    = new XmlSerializer(typeof(AutobudgetObjectsContainer));
                TextReader    reader = new StreamReader(path);
                AutobudgetObjectsContainer instance = (AutobudgetObjectsContainer)ser.Deserialize(reader);
                reader.Close();

                return(instance);
            }
            catch
            {
                return(null);
            }
        }
        private static void createControls()
        {
            UITabContainer economyContainer = ToolsModifierControl.economyPanel.component.Find <UITabContainer>("EconomyContainer");

            if (economyContainer != null)
            {
                UIPanel budgetPanel = economyContainer.Find <UIPanel>("Budget");
                if (budgetPanel != null)
                {
                    AutobudgetObjectsContainer c = Singleton <AutobudgetManager> .instance.container;

                    foreach (AutobudgetBase obj in c.AllAutobudgetObjects)
                    {
                        UIPanel container = budgetPanel.Find <UIPanel>(obj.GetEconomyPanelContainerName());
                        if (container != null)
                        {
                            UIPanel budgetItem = container.Find <UIPanel>(obj.GetBudgetItemName());
                            if (budgetItem != null)
                            {
                                AutobudgetItemPanel autobudgetPanel = budgetItem.AddUIComponent <AutobudgetItemPanel>();
                                autobudgetPanel.SetName(obj.GetBudgetItemName());
                                autobudgetPanel.isChecked = obj.Enabled;
                                autobudgetPanel.SetCheckCallback(delegate(bool isChecked)
                                {
                                    if (!freezeUI)
                                    {
                                        obj.Enabled = isChecked;
                                        Mod.UpdateUI();
                                    }
                                });
                            }
                        }
                    }
                }
            }
        }
 public void ResetToDefaultValues()
 {
     container = new AutobudgetObjectsContainer();
     container.InitObjects();
 }
Пример #10
0
        public void TotalAutobudgetOptionsUpdateUI()
        {
            if (UI_Electricity_Enabled == null)
            {
                return;
            }

            AutobudgetObjectsContainer c = Singleton <AutobudgetManager> .instance.container;

            freezeUI = true;

            UI_Electricity_Enabled.isChecked   = c.AutobudgetElectricity.Enabled;
            UI_Electricity_Buffer.value        = c.AutobudgetElectricity.AutobudgetBuffer;
            UI_Electricity_MaxBudget.value     = c.AutobudgetElectricity.BudgetMaxValue;
            UI_Electricity_AutoPause.isChecked = c.AutobudgetElectricity.PauseWhenBudgetTooHigh;

            UI_Water_Enabled.isChecked     = c.AutobudgetWater.Enabled;
            UI_Water_Buffer.value          = c.AutobudgetWater.AutobudgetBuffer;
            UI_Water_MaxBudget.value       = c.AutobudgetWater.BudgetMaxValue;
            UI_Water_AutoPause.isChecked   = c.AutobudgetWater.PauseWhenBudgetTooHigh;
            UI_Water_StorageAmount.value   = c.AutobudgetWater.TargetWaterStorageRatio;
            UI_Heating_TurnOnOff.isChecked = c.AutobudgetHeating.Enabled;

            UI_Garbage_Enabled.isChecked = c.AutobudgetGarbage.Enabled;
            UI_Garbage_MaxBudget.value   = c.AutobudgetGarbage.BudgetMaxValue;
            UI_Garbage_MaxAmount.value   = c.AutobudgetGarbage.MaximumGarbageAmount;

            UI_Healthcare_Enabled.isChecked = c.AutobudgetHealthcare.Enabled;
            UI_Healthcare_MinBudget.value   = c.AutobudgetHealthcare.BudgetMinValue;
            UI_Healthcare_MaxBudget.value   = c.AutobudgetHealthcare.BudgetMaxValue;

            UI_Education_Enabled.isChecked    = c.AutobudgetEducation.Enabled;
            UI_Education_ElementaryRate.value = c.AutobudgetEducation.ElementaryEducationTargetRate;
            UI_Education_HighRate.value       = c.AutobudgetEducation.HighEducationTargetRate;
            UI_Education_MaxBudget.value      = c.AutobudgetEducation.BudgetMaxValue;

            UI_Police_Enabled.isChecked = c.AutobudgetPolice.Enabled;
            UI_Police_MinBudget.value   = c.AutobudgetPolice.BudgetMinValue;
            UI_Police_MaxBudget.value   = c.AutobudgetPolice.BudgetMaxValue;

            UI_Fire_Enabled.isChecked     = c.AutobudgetFire.Enabled;
            UI_Fire_MinBudget.value       = c.AutobudgetFire.BudgetMinValue;
            UI_Fire_MaxBudget.value       = c.AutobudgetFire.BudgetMaxValue;
            UI_Fire_TrucksExcessNum.value = c.AutobudgetFire.FireTrucksExcessNum;

            UI_Industry_Enabled.isChecked = c.AutobudgetIndustry.Enabled;
            UI_Industry_MinBudget.value   = c.AutobudgetIndustry.BudgetMinValue;
            UI_Industry_MaxBudget.value   = c.AutobudgetIndustry.BudgetMaxValue;

            UI_Road_Enabled.isChecked = c.AutobudgetRoad.Enabled;
            UI_Road_MinBudget.value   = c.AutobudgetRoad.BudgetMinValue;
            UI_Road_MaxBudget.value   = c.AutobudgetRoad.BudgetMaxValue;

            UI_Post_Enabled.isChecked = c.AutobudgetPost.Enabled;
            UI_Post_MaxBudget.value   = c.AutobudgetPost.BudgetMaxValue;

            UI_Taxi_Enabled.isChecked            = c.AutobudgetTaxi.Enabled;
            UI_Taxi_MaxBudget.value              = c.AutobudgetTaxi.BudgetMaxValue;
            UI_Taxi_DepotVehiclesExcessNum.value = c.AutobudgetTaxi.TargetNumberOfVehiclesWaitingAtDepot;
            UI_Taxi_StandVehiclesExcessNum.value = c.AutobudgetTaxi.TargetNumberOfVehiclesWaitingAtStand;

            freezeUI = false;
        }