public static ExtendedGameOptionsSerializable CreateFromFile() { ExtendedGameOptionsSerializable instance = null; string path = getOptionsFilePath(); if (!File.Exists(path)) { return(null); } try { XmlSerializer ser = new XmlSerializer(typeof(ExtendedGameOptionsSerializable)); TextReader reader = new StreamReader(path); instance = (ExtendedGameOptionsSerializable)ser.Deserialize(reader); reader.Close(); return(instance); } catch { Debug.Log("ExtendedGameOptionsMod: Error reading options file."); return(null); } }
private ExtendedGameOptionsManager() { values = ExtendedGameOptionsSerializable.CreateFromFile(); if (values == null) { values = new ExtendedGameOptionsSerializable(); } }
public override void OnAfterResourcesModified(int x, int z, NaturalResource type, int amount) { if ((type == NaturalResource.Oil || type == NaturalResource.Ore) && amount < 0) { ExtendedGameOptionsSerializable o = Singleton <ExtendedGameOptionsManager> .instance.values; if (type == NaturalResource.Oil) { // Vanilla original rate (100%) if (o.OilDepletionRate == 100) { return; } if (o.OilDepletionRate == 0) { // Vanilla original UnlimitedOilAndOre mod resourceManager.SetResource(x, z, type, (byte)(resourceManager.GetResource(x, z, type) - amount), false); } else { // 1% ~ 99% if (Singleton <SimulationManager> .instance.m_randomizer.Int32(100u) >= o.OilDepletionRate) { resourceManager.SetResource(x, z, type, (byte)(resourceManager.GetResource(x, z, type) - amount), false); } } } else if (type == NaturalResource.Ore) { // Vanilla original rate (100%) if (o.OreDepletionRate == 100) { return; } if (o.OreDepletionRate == 0) { // Vanilla original UnlimitedOilAndOre mod resourceManager.SetResource(x, z, type, (byte)(resourceManager.GetResource(x, z, type) - amount), false); } else { // 1% ~ 99% if (Singleton <SimulationManager> .instance.m_randomizer.Int32(100u) >= o.OreDepletionRate) { resourceManager.SetResource(x, z, type, (byte)(resourceManager.GetResource(x, z, type) - amount), false); } } } } }
public override void OnRefreshMilestones() { ExtendedGameOptionsSerializable o = Singleton <ExtendedGameOptionsManager> .instance.values; if (o.BasicRoadsAvailableBromStart) { milestonesManager.UnlockMilestone("Basic Road Created"); } if (o.TrainTrackUnlock) { milestonesManager.UnlockMilestone("Train Track Requirements"); } if (o.MetroTrackUnlock) { milestonesManager.UnlockMilestone("Metro Track Requirements"); } if (o.UnlockMilestone) { milestonesManager.UnlockMilestone("Milestone" + o.UnlockMilestoneIndex.ToString()); } }
public void OnSettingsUI(UIHelperBase helper) { ExtendedGameOptionsSerializable o = Singleton <ExtendedGameOptionsManager> .instance.values; //////////// General //////////// helper.AddCheckbox("Enable achievements", o.EnableAchievements, delegate(bool isChecked) { o.EnableAchievements = isChecked; modified = true; }); helper.AddCheckbox("Info View buttons are always enabled", o.InfoViewButtonsAlwaysEnabled, delegate(bool isChecked) { o.InfoViewButtonsAlwaysEnabled = isChecked; modified = true; }); helper.AddSpace(20); //////////// Unlocks //////////// UIHelperBase unlockGroup = helper.AddGroup("Unlocks (requires game reload)"); unlockGroup.AddCheckbox("Basic roads are available from the start", o.BasicRoadsAvailableBromStart, delegate(bool isChecked) { o.BasicRoadsAvailableBromStart = isChecked; modified = true; }); unlockGroup.AddCheckbox("Train tracks can be constructed without a train station", o.TrainTrackUnlock, delegate(bool isChecked) { o.TrainTrackUnlock = isChecked; modified = true; }); unlockGroup.AddCheckbox("Metro tunnels can be constructed without a metro station", o.MetroTrackUnlock, delegate(bool isChecked) { o.MetroTrackUnlock = isChecked; modified = true; }); unlockGroup.AddCheckbox("Unlock everything up to the following milestone", o.UnlockMilestone, delegate(bool isChecked) { o.UnlockMilestone = isChecked; modified = true; }); unlockGroup.AddDropdown(" (select Megalopolis to unlock all)", Milestones.MilestoneLocalizedNames, o.UnlockMilestoneIndex - 1, delegate(int sel) { o.UnlockMilestoneIndex = sel + 1; modified = true; }); //////////// Economy //////////// UIHelperBase economyGroup = helper.AddGroup("Economy"); economyGroup.AddTextfield("Initial money (set blank to not change)", o.InitialMoney < 0 ? "" : o.InitialMoney.ToString(), delegate(string text) { }, delegate(string text) { int value; if (int.TryParse(text, out value)) { value = Mathf.Clamp(value, 0, 10 * 1000 * 1000); o.InitialMoney = value; } else { o.InitialMoney = -1; } modified = true; }); economyGroup.AddCheckbox("Bulldozing structures built recently gives full refund", o.FullRefund, delegate(bool isChecked) { o.FullRefund = isChecked; modified = true; }); //////////// Others //////////// if (SteamHelper.IsDLCOwned(SteamHelper.DLC.NaturalDisastersDLC)) { helper.AddCheckbox("Enable random disasters for scenarios", o.EnableRandomDisastersForScenarios, delegate(bool isChecked) { o.EnableRandomDisastersForScenarios = isChecked; modified = true; }); } helper.AddCheckbox("Set number of purchasable areas (uncheck this if using 81 tiles mod)", o.EnableAreasMaxCountOption, delegate(bool isChecked) { Singleton <ExtendedGameOptionsManager> .instance.values.EnableAreasMaxCountOption = isChecked; if (isChecked) { Areas.Update(); } else { Areas.Reset(); } modified = true; }); UIDropDown areasMaxCountDropdown = (UIDropDown)helper.AddDropdown("Areas", Areas.GetAvailableValuesStr(), o.AreasMaxCount - 1, delegate(int sel) { o.AreasMaxCount = sel + 1; modified = true; if (Singleton <ExtendedGameOptionsManager> .instance.values.EnableAreasMaxCountOption) { Areas.Update(); } }); helper.AddSpace(20); //////////// Resources //////////// UIHelperBase resourcesHelper = helper.AddGroup("Resources depletion rate"); addLabelToResourceSlider(resourcesHelper.AddSlider("Oil depletion rate", 0, 100, 1, o.OilDepletionRate, delegate(float val) { o.OilDepletionRate = (int)val; modified = true; })); addLabelToResourceSlider(resourcesHelper.AddSlider("Ore depletion rate", 0, 100, 1, o.OreDepletionRate, delegate(float val) { o.OreDepletionRate = (int)val; modified = true; })); UIComponent optionPanel = areasMaxCountDropdown.parent.parent; optionPanel.eventVisibilityChanged += OptionPanel_eventVisibilityChanged; }