public static GraphicsOptions Init(ConfigSection graphicsSection) { ConfigSection presets = graphicsSection.GetSection("Presets"); if (presets == null) { DashCMD.WriteError("[game.cfg - GraphicsOptions] Graphics.Presets was not found!"); return(null); } string usedPreset = graphicsSection.GetString("preset"); if (usedPreset == null) { DashCMD.WriteError("[game.cfg - GraphicsOptions] Graphics.preset was not found!"); return(null); } foreach (DictionaryEntry pair in presets.Children) { ConfigSection preset = pair.Value as ConfigSection; if (preset == null) { DashCMD.WriteWarning("[game.cfg - GraphicsOptions] Invalid token '{0}' in Graphics.Presets", pair.Key); continue; } bool fxaa = preset.GetBoolean("fxaa") ?? false; bool shadows = preset.GetBoolean("shadows") ?? false; int shadowRes = preset.GetInteger("shadowRes") ?? 1; int pcfSamples = preset.GetInteger("shadowPCF") ?? 1; FogQuality fogQuality = preset.GetEnum <FogQuality>("fogQuality") ?? FogQuality.Low; GraphicsOptions options = new GraphicsOptions() { ApplyFXAA = fxaa, RenderShadows = shadows, ShadowResolution = shadowRes, ShadowPCFSamples = pcfSamples, FogQuality = fogQuality }; allOptions.Add((string)pair.Key, options); } GraphicsOptions usedOptions; if (allOptions.TryGetValue(usedPreset, out usedOptions)) { DashCMD.WriteStandard("[game.cfg - GraphicsOptions] Using preset '{0}'", usedPreset); return(usedOptions); } else { DashCMD.WriteError("[game.cfg - GraphicsOptions] Specified preset '{0}' was not found!", usedPreset); return(null); } }
/// <summary> /// Set a GFX option and reflect setting on button /// </summary> /// <param name="dropDown"></param> /// <param name="button"></param> void SetGfxOption(GUIDropDown dropDown, GUIDropDownButton button) { if (button.Value == null) { return; //it should never be null but just in case... } if (button.Value.GetType() == typeof(int)) { var SubMenu = TopBarHelper.GetSubMenus(); foreach (KeyValuePair <string, GUIDropDownButton> btn in SubMenu["PCF Samples"]) { if (btn.Value.Toggled) { btn.Value.Toggled = false; //only toggle off if on break; //prevent more than whats needed } } renderer.GFXSettings.ShadowPCFSamples = (button.Value as int? != null ? (int)button.Value : 1); //we try to safe cast as int nullable; if we fail we hard set to 1 button.Toggled = true; } if (button.Value.GetType() == typeof(FogQuality)) { FogQuality myType = (FogQuality)button.Value; var SubMenu = TopBarHelper.GetSubMenus(); foreach (KeyValuePair <string, GUIDropDownButton> btn in SubMenu["Fog"]) { if (btn.Value.Toggled) { btn.Value.Toggled = false; //only toggle off if on break; //prevent more than whats needed } } switch (myType) { case FogQuality.Off: { bool currentSetting = renderer.FogEnabled; renderer.FogEnabled = !currentSetting; button.Toggled = currentSetting; //dont need to invert the bool, all buttons are false by default due to the foreach loop break; } case FogQuality.Low: { renderer.FogEnabled = true; renderer.GFXSettings.FogQuality = FogQuality.Low; button.Toggled = true; break; } case FogQuality.Medium: { renderer.FogEnabled = true; renderer.GFXSettings.FogQuality = FogQuality.Medium; button.Toggled = true; break; } case FogQuality.High: { renderer.FogEnabled = true; renderer.GFXSettings.FogQuality = FogQuality.High; button.Toggled = true; break; } } } if (button.Value.GetType() == typeof(gfxType)) { //check for enum gfxType gfxType myType = (gfxType)button.Value; // /should/ be safe to case as gfxType switch (myType) { case gfxType.fxaa: { bool currentSetting = renderer.GFXSettings.ApplyFXAA; //easier to read renderer.GFXSettings.ApplyFXAA = !currentSetting; button.Toggled = !currentSetting; break; } case gfxType.shadows: { bool currentSetting = renderer.GFXSettings.RenderShadows; //easier to read renderer.GFXSettings.RenderShadows = !currentSetting; button.Toggled = !currentSetting; break; } case gfxType.wireframe: { bool currentSetting = renderer.GlobalWireframe; //easier to read renderer.GlobalWireframe = !currentSetting; button.Toggled = !currentSetting; break; } } } }