示例#1
0
        protected void setBudget(int newBudget)
        {
            if (newBudget == -1)
            {
                return;
            }

            SimulationManager sm = Singleton <SimulationManager> .instance;

            // Set the budget sliders
            if (BudgetControlsManager.IsBudgetPanelVisible())
            {
                UISlider slider = BudgetControlsManager.GetBudgetSlider(GetEconomyPanelContainerName(), GetBudgetItemName(), sm.m_isNightTime);
                if (slider != null)
                {
                    if (slider.value != newBudget)
                    {
                        slider.value = newBudget;
                    }
                }
            }

            // Set the budget directly
            Singleton <EconomyManager> .instance.SetBudget(GetService(), GetSubService(), newBudget, sm.m_isNightTime);
        }
示例#2
0
 public override void OnLevelLoaded(LoadMode mode)
 {
     if (mode == LoadMode.NewGame || mode == LoadMode.LoadGame || mode == LoadMode.NewGameFromScenario)
     {
         BudgetControlsManager.Init();
     }
 }
示例#3
0
        public override void OnLevelUnloading()
        {
            Singleton <AutobudgetManager> .instance.ReadValuesFromFile();

            Mod.UpdateUI();
            BudgetControlsManager.ResetUI();
        }
示例#4
0
        public void SetAutobudget()
        {
            if (!Enabled)
            {
                return;
            }

            if (!Singleton <DistrictManager> .exists || !Singleton <EconomyManager> .exists || !Singleton <SimulationManager> .exists)
            {
                return;
            }

            EconomyManager em          = Singleton <EconomyManager> .instance;
            int            budgetDay   = em.GetBudget(GetService(), GetSubService(), false);
            int            budgetNight = em.GetBudget(GetService(), GetSubService(), true);

            // If not the beginning
            if (prevBudgetDay != 0 && prevBudgetNight != 0)
            {
                // Probably somebody changed budget manually -> disable autobudget
                if (prevBudgetDay != budgetDay || budgetNight != prevBudgetNight)
                {
                    Enabled         = false;
                    prevBudgetDay   = 0;
                    prevBudgetNight = 0;
                    Mod.UpdateUI();
                    BudgetControlsManager.UpdateControls();
                }
            }

            prevBudgetDay   = budgetDay;
            prevBudgetNight = budgetNight;

            if (counter-- <= 0)
            {
                counter = refreshCount;
                setAutobudget();
                prevBudgetDay   = 0;
                prevBudgetNight = 0;
            }
        }
            public override void Awake()
            {
                base.Awake();

                this.position = new Vector3(45, -4);
                this.size     = new Vector2(30f, 40f);

                // Enable/disable checkbox
                checkBox          = this.AddUIComponent <UICheckBox>();
                checkBox.position = new Vector3(6, 0);
                checkBox.size     = new Vector2(30, 20);

                UISprite sprite = checkBox.AddUIComponent <UISprite>();

                sprite.spriteName       = "ToggleBase";
                sprite.size             = new Vector2(16f, 16f);
                sprite.relativePosition = new Vector3(2f, 2f);

                checkBox.checkedBoxObject = sprite.AddUIComponent <UISprite>();
                ((UISprite)checkBox.checkedBoxObject).spriteName = "ToggleBaseFocused";
                checkBox.checkedBoxObject.size             = new Vector2(16f, 16f);
                checkBox.checkedBoxObject.relativePosition = Vector3.zero;

                // Options button
                btn                 = this.AddUIComponent <UIButton>();
                btn.position        = new Vector3(0, -20);
                btn.size            = new Vector2(30, 16);
                btn.text            = "...";
                btn.textColor       = Color.white;
                btn.normalBgSprite  = "ButtonMenu";
                btn.hoveredBgSprite = "ButtonMenuHovered";
                btn.eventClick     += delegate(UIComponent component, UIMouseEventParameter eventParam)
                {
                    if (!string.IsNullOrEmpty(budgetItemName))
                    {
                        BudgetControlsManager.showOptionsPanel(budgetItemName);
                    }
                };
            }
示例#6
0
        public void OnLoadData()
        {
            try
            {
                byte[] data = serializedData.LoadData(DataID);

                if (data == null)
                {
                    Debug.Log(Mod.LogMsgPrefix + "No saved data ");
                    return;
                }

                using (var stream = new MemoryStream(data))
                {
                    DataSerializer.Deserialize <AutobudgetElectricity.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <AutobudgetWater.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <AutobudgetGarbage.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <AutobudgetHealthcare.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <AutobudgetEducation.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <AutobudgetPolice.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <AutobudgetFire.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <AutobudgetRoad.Data>(stream, DataSerializer.Mode.Memory);
                    if (LastReadDataVersion >= 4)
                    {
                        DataSerializer.Deserialize <AutobudgetPost.Data>(stream, DataSerializer.Mode.Memory);
                    }
                    DataSerializer.Deserialize <AutobudgetTaxi.Data>(stream, DataSerializer.Mode.Memory);
                }
            }
            catch (Exception ex)
            {
                Debug.Log(Mod.LogMsgPrefix + "load error: " + ex.Message);
            }

            Mod.UpdateUI();
            BudgetControlsManager.UpdateControls();
        }
        public void OnSettingsUI(UIHelperBase helper)
        {
            AutobudgetManager am = Singleton <AutobudgetManager> .instance;

            #region Electricity

            UIHelperBase electricityGroup = helper.AddGroup("Electricity");

            UI_Electricity_Enabled = (UICheckBox)electricityGroup.AddCheckbox("Enable", am.container.AutobudgetElectricity.Enabled, delegate(bool isChecked)
            {
                if (freezeUI)
                {
                    return;
                }
                am.container.AutobudgetElectricity.Enabled = isChecked;
                BudgetControlsManager.UpdateControls();
            });

            addLabelToSlider(UI_Electricity_Buffer = (UISlider)electricityGroup.AddSlider("Buffer", 0, 100, 1, am.container.AutobudgetElectricity.AutobudgetBuffer, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetElectricity.AutobudgetBuffer = (int)val;
                }
            }), "%");
            UI_Electricity_Buffer.tooltip = "Set how much production should exceed consumption";

            addLabelToSlider(UI_Electricity_MaxBudget = (UISlider)electricityGroup.AddSlider("Maximum budget", 50, 150, 1, am.container.AutobudgetElectricity.BudgetMaxValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetElectricity.BudgetMaxValue = (int)val;
                }
            }), "%");
            UI_Electricity_MaxBudget.tooltip = "Budget will not be raised higher then this value";

            UI_Electricity_AutoPause = (UICheckBox)electricityGroup.AddCheckbox("Autopause when budget is too high", am.container.AutobudgetElectricity.PauseWhenBudgetTooHigh, delegate(bool isChecked)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetElectricity.PauseWhenBudgetTooHigh = isChecked;
                }
            });
            UI_Electricity_AutoPause.tooltip = "Pause and switch to the electricity info view mode when the autobudget raises up to the maximum value";

            helper.AddSpace(20);

            #endregion


            #region Water, sewage, and heating

            UIHelperBase waterGroup = helper.AddGroup("Water, sewage, and heating");

            UI_Water_Enabled = (UICheckBox)waterGroup.AddCheckbox("Enable", am.container.AutobudgetWater.Enabled, delegate(bool isChecked)
            {
                if (freezeUI)
                {
                    return;
                }
                am.container.AutobudgetWater.Enabled = isChecked;
                BudgetControlsManager.UpdateControls();
            });

            addLabelToSlider(UI_Water_Buffer = (UISlider)waterGroup.AddSlider("Buffer", 0, 100, 1, am.container.AutobudgetWater.AutobudgetBuffer, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetWater.AutobudgetBuffer = (int)val;
                }
            }), "%");
            UI_Water_Buffer.tooltip = "Set how much production should exceed consumption";

            addLabelToSlider(UI_Water_MaxBudget = (UISlider)waterGroup.AddSlider("Maximum budget", 50, 150, 1, am.container.AutobudgetWater.BudgetMaxValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetWater.BudgetMaxValue = (int)val;
                }
            }), "%");
            UI_Water_MaxBudget.tooltip = "Budget will not be raised higher then this value";

            UI_Water_AutoPause = (UICheckBox)waterGroup.AddCheckbox("Autopause when budget is too high", am.container.AutobudgetWater.PauseWhenBudgetTooHigh, delegate(bool isChecked)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetWater.PauseWhenBudgetTooHigh = isChecked;
                }
            });
            UI_Water_AutoPause.tooltip = "Pause and switch to the water and sewage info view mode when the autobudget raises up to the maximum value";

            addLabelToSlider(UI_Water_StorageAmount = (UISlider)waterGroup.AddSlider("Target water storage", 0, 100, 1, am.container.AutobudgetWater.TargetWaterStorageRatio, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetWater.TargetWaterStorageRatio = (int)val;
                }
            }), "%");
            UI_Water_StorageAmount.tooltip = "When water storage tanks are filled more than this value, water consumption will not influence the budget";

            UI_Water_UseHeating = (UICheckBox)waterGroup.AddCheckbox("Increase budget if not enough heating", am.container.AutobudgetWater.UseHeatingAutobudget, delegate(bool isChecked)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetWater.UseHeatingAutobudget = isChecked;
                }
            });
            UI_Water_UseHeating.tooltip = "The budget increases when some of your buildings have heating problems";

            addLabelToSlider(UI_Water_MaxHeatingBudget = (UISlider)waterGroup.AddSlider("Max heating budget", 50, 150, 1, am.container.AutobudgetWater.HeatingBudgetMaxValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetWater.HeatingBudgetMaxValue = (int)val;
                }
            }), "%");
            UI_Water_MaxHeatingBudget.tooltip = "Budget rising due to heating problems will never exceed this value";

            helper.AddSpace(20);

            #endregion


            #region Garbage disposal

            UIHelperBase garbageGroup = helper.AddGroup("Garbage disposal");

            UI_Garbage_Enabled = (UICheckBox)garbageGroup.AddCheckbox("Enable", am.container.AutobudgetGarbage.Enabled, delegate(bool isChecked)
            {
                if (freezeUI)
                {
                    return;
                }
                am.container.AutobudgetGarbage.Enabled = isChecked;
                BudgetControlsManager.UpdateControls();
            });

            addLabelToSlider(UI_Garbage_MaxBudget = (UISlider)garbageGroup.AddSlider("Maximum budget", 50, 150, 1, am.container.AutobudgetGarbage.BudgetMaxValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetGarbage.BudgetMaxValue = (int)val;
                }
            }), "%");
            UI_Garbage_MaxBudget.tooltip = "Budget will not be raised higher then this value";

            addLabelToSlider(UI_Garbage_MaxAmount = (UISlider)garbageGroup.AddSlider("Max garbage amount", 0, 100, 1, am.container.AutobudgetGarbage.MaximumGarbageAmount, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetGarbage.MaximumGarbageAmount = (int)val;
                }
            }), "%");
            UI_Garbage_MaxAmount.tooltip = "When at least one of the recycling centers or incineration plants is piled with garbage more than this value, the budget will be raised to the maximum";

            helper.AddSpace(20);

            #endregion


            #region Healthcare

            UIHelperBase healthcareGroup = helper.AddGroup("Healthcare and Deathcare");

            UI_Healthcare_Enabled = (UICheckBox)healthcareGroup.AddCheckbox("Enable", am.container.AutobudgetHealthcare.Enabled, delegate(bool isChecked)
            {
                if (freezeUI)
                {
                    return;
                }
                am.container.AutobudgetHealthcare.Enabled = isChecked;
                BudgetControlsManager.UpdateControls();
            });

            addLabelToSlider(UI_Healthcare_MinBudget = (UISlider)healthcareGroup.AddSlider("Minimum budget", 50, 150, 1, am.container.AutobudgetHealthcare.BudgetMinValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetHealthcare.BudgetMinValue = (int)val;
                }
            }), "%");
            UI_Healthcare_MinBudget.tooltip = "Budget will not be lowered below this value";

            addLabelToSlider(UI_Healthcare_MaxBudget = (UISlider)healthcareGroup.AddSlider("Maximum budget", 50, 150, 1, am.container.AutobudgetHealthcare.BudgetMaxValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetHealthcare.BudgetMaxValue = (int)val;
                }
            }), "%");
            UI_Healthcare_MaxBudget.tooltip = "Budget will not be raised higher then this value";

            helper.AddSpace(20);

            #endregion


            #region Education

            UIHelperBase educationGroup = helper.AddGroup("Education");

            UI_Education_Enabled = (UICheckBox)educationGroup.AddCheckbox("Enable", am.container.AutobudgetEducation.Enabled, delegate(bool isChecked)
            {
                if (freezeUI)
                {
                    return;
                }
                am.container.AutobudgetEducation.Enabled = isChecked;
                BudgetControlsManager.UpdateControls();
            });

            UI_Education_ElementaryRate = (UISlider)educationGroup.AddSlider("Elementary education", 10, 100, 5, am.container.AutobudgetEducation.ElementaryEducationTargetRate, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetEducation.ElementaryEducationTargetRate = (int)val;
                }
            });
            addLabelToSlider(UI_Education_ElementaryRate, "%");
            UI_Education_ElementaryRate.tooltip = "Target elementary education rate";

            UI_Education_HighRate = (UISlider)educationGroup.AddSlider("High school education", 10, 100, 5, am.container.AutobudgetEducation.HighEducationTargetRate, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetEducation.HighEducationTargetRate = (int)val;
                }
            });
            addLabelToSlider(UI_Education_HighRate, "%");
            UI_Education_HighRate.tooltip = "Target high school education rate";

            UI_Education_MaxBudget = (UISlider)educationGroup.AddSlider("Maximum budget", 50, 150, 1, am.container.AutobudgetEducation.BudgetMaxValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetEducation.BudgetMaxValue = (int)val;
                }
            });
            addLabelToSlider(UI_Education_MaxBudget, "%");
            UI_Education_MaxBudget.tooltip = "Budget will not be raised higher then this value";

            helper.AddSpace(20);

            #endregion


            #region Police

            UIHelperBase policeGroup = helper.AddGroup("Police");

            UI_Police_Enabled = (UICheckBox)policeGroup.AddCheckbox("Enable", am.container.AutobudgetPolice.Enabled, delegate(bool isChecked)
            {
                if (freezeUI)
                {
                    return;
                }
                am.container.AutobudgetPolice.Enabled = isChecked;
                BudgetControlsManager.UpdateControls();
            });

            addLabelToSlider(UI_Police_MinBudget = (UISlider)policeGroup.AddSlider("Minimum budget", 50, 150, 1, am.container.AutobudgetPolice.BudgetMinValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetPolice.BudgetMinValue = (int)val;
                }
            }), "%");
            UI_Police_MinBudget.tooltip = "Budget will not be lowered below this value";

            addLabelToSlider(UI_Police_MaxBudget = (UISlider)policeGroup.AddSlider("Maximum budget", 50, 150, 1, am.container.AutobudgetPolice.BudgetMaxValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetPolice.BudgetMaxValue = (int)val;
                }
            }), "%");
            UI_Police_MaxBudget.tooltip = "Budget will not be raised higher then this value";

            helper.AddSpace(20);

            #endregion


            #region Fire

            UIHelperBase fireGroup = helper.AddGroup("Fire service");

            UI_Fire_Enabled = (UICheckBox)fireGroup.AddCheckbox("Enable", am.container.AutobudgetFire.Enabled, delegate(bool isChecked)
            {
                if (freezeUI)
                {
                    return;
                }
                am.container.AutobudgetFire.Enabled = isChecked;
                BudgetControlsManager.UpdateControls();
            });

            addLabelToSlider(UI_Fire_MinBudget = (UISlider)fireGroup.AddSlider("Minimum budget", 50, 150, 1, am.container.AutobudgetFire.BudgetMinValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetFire.BudgetMinValue = (int)val;
                }
            }), "%");
            UI_Fire_MinBudget.tooltip = "Budget will not be lowered below this value";

            addLabelToSlider(UI_Fire_MaxBudget = (UISlider)fireGroup.AddSlider("Maximum budget", 50, 150, 1, am.container.AutobudgetFire.BudgetMaxValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetFire.BudgetMaxValue = (int)val;
                }
            }), "%");
            UI_Fire_MaxBudget.tooltip = "Budget will not be raised higher then this value";

            addLabelToSlider(UI_Fire_TrucksExcessNum = (UISlider)fireGroup.AddSlider("Minimum trucks waiting", 1, 5, 1, am.container.AutobudgetFire.FireTrucksExcessNum, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetFire.FireTrucksExcessNum = (int)val;
                }
            }), " trucks");
            UI_Fire_TrucksExcessNum.tooltip = "Minimum number of trucks waiting in each of the fire stations";

            helper.AddSpace(20);

            #endregion


            #region Roads

            UIHelperBase roadGroup = helper.AddGroup("Road maintenance and snow dumps");

            UI_Road_Enabled = (UICheckBox)roadGroup.AddCheckbox("Enable", am.container.AutobudgetRoad.Enabled, delegate(bool isChecked)
            {
                if (freezeUI)
                {
                    return;
                }
                am.container.AutobudgetRoad.Enabled = isChecked;
                BudgetControlsManager.UpdateControls();
            });

            addLabelToSlider(UI_Road_MinBudget = (UISlider)roadGroup.AddSlider("Minimum budget", 50, 150, 1, am.container.AutobudgetRoad.BudgetMinValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetRoad.BudgetMinValue = (int)val;
                }
            }), "%");
            UI_Road_MinBudget.tooltip = "Budget will not be lowered below this value";

            addLabelToSlider(UI_Road_MaxBudget = (UISlider)roadGroup.AddSlider("Maximum budget", 50, 150, 1, am.container.AutobudgetRoad.BudgetMaxValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetRoad.BudgetMaxValue = (int)val;
                }
            }), "%");
            UI_Road_MaxBudget.tooltip = "Budget will not be raised higher then this value";

            helper.AddSpace(20);

            #endregion


            #region Post

            UIHelperBase postGroup = helper.AddGroup("Post offices");

            UI_Post_Enabled = (UICheckBox)postGroup.AddCheckbox("Enable", am.container.AutobudgetPost.Enabled, delegate(bool isChecked)
            {
                if (freezeUI)
                {
                    return;
                }
                am.container.AutobudgetPost.Enabled = isChecked;
                BudgetControlsManager.UpdateControls();
            });

            addLabelToSlider(UI_Post_MaxBudget = (UISlider)postGroup.AddSlider("Maximum budget", 50, 150, 1, am.container.AutobudgetPost.BudgetMaxValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetPost.BudgetMaxValue = (int)val;
                }
            }), "%");
            UI_Post_MaxBudget.tooltip = "Budget will not be raised higher then this value";

            helper.AddSpace(20);

            #endregion


            #region Taxi

            UIHelperBase taxiGroup = helper.AddGroup("Taxi");

            UI_Taxi_Enabled = (UICheckBox)taxiGroup.AddCheckbox("Enable", am.container.AutobudgetTaxi.Enabled, delegate(bool isChecked)
            {
                if (freezeUI)
                {
                    return;
                }
                am.container.AutobudgetTaxi.Enabled = isChecked;
                BudgetControlsManager.UpdateControls();
            });

            addLabelToSlider(UI_Taxi_MaxBudget = (UISlider)taxiGroup.AddSlider("Maximum budget", 50, 150, 1, am.container.AutobudgetTaxi.BudgetMaxValue, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetTaxi.BudgetMaxValue = (int)val;
                }
            }), "%");
            UI_Taxi_MaxBudget.tooltip = "Budget will not be raised higher then this value";

            addLabelToSlider(UI_Taxi_DepotVehiclesExcessNum = (UISlider)taxiGroup.AddSlider("Taxis waiting at depots", 1, 5, 1, am.container.AutobudgetTaxi.TargetNumberOfVehiclesWaitingAtDepot, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetTaxi.TargetNumberOfVehiclesWaitingAtDepot = (int)val;
                }
            }), " taxis");
            UI_Taxi_DepotVehiclesExcessNum.tooltip = "Target number of taxis waiting in depots";

            addLabelToSlider(UI_Taxi_StandVehiclesExcessNum = (UISlider)taxiGroup.AddSlider("Taxis waiting at stands", 1, 5, 1, am.container.AutobudgetTaxi.TargetNumberOfVehiclesWaitingAtStand, delegate(float val)
            {
                if (!freezeUI)
                {
                    am.container.AutobudgetTaxi.TargetNumberOfVehiclesWaitingAtStand = (int)val;
                }
            }), " taxis");
            UI_Taxi_StandVehiclesExcessNum.tooltip = "Target number of taxis waiting at taxi stands";

            helper.AddSpace(20);

            #endregion


            helper.AddCheckbox("Create controls on the budget panel", am.container.IsCreateControlsOnBudgetPanel, delegate(bool isChecked)
            {
                if (freezeUI)
                {
                    return;
                }
                am.container.IsCreateControlsOnBudgetPanel = isChecked;
            });
            helper.AddSpace(20);


            // Save buttons
            helper.AddButton("Save as default for new games", delegate()
            {
                am.container.Save();
            });
            helper.AddButton("Reset to the last saved values", delegate()
            {
                am.ReadValuesFromFile();
                TotalAutobudgetOptionsUpdateUI();
            });
            helper.AddButton("Reset to the mod default values", delegate()
            {
                am.ResetToDefaultValues();
                TotalAutobudgetOptionsUpdateUI();
            });
            helper.AddSpace(20);
        }