Func <bool> InitPanel(Widget panel) { var gs = Game.Settings.Game; SettingsUtils.BindCheckboxPref(panel, "ALTERNATE_SCROLL_CHECKBOX", gs, "UseAlternateScrollButton"); SettingsUtils.BindCheckboxPref(panel, "EDGESCROLL_CHECKBOX", gs, "ViewportEdgeScroll"); SettingsUtils.BindCheckboxPref(panel, "LOCKMOUSE_CHECKBOX", gs, "LockMouseWindow"); SettingsUtils.BindSliderPref(panel, "ZOOMSPEED_SLIDER", gs, "ZoomSpeed"); SettingsUtils.BindSliderPref(panel, "SCROLLSPEED_SLIDER", gs, "ViewportEdgeScrollStep"); SettingsUtils.BindSliderPref(panel, "UI_SCROLLSPEED_SLIDER", gs, "UIScrollSpeed"); var mouseControlDropdown = panel.Get <DropDownButtonWidget>("MOUSE_CONTROL_DROPDOWN"); mouseControlDropdown.OnMouseDown = _ => ShowMouseControlDropdown(mouseControlDropdown, gs); mouseControlDropdown.GetText = () => gs.UseClassicMouseStyle ? "Classic" : "Modern"; var mouseScrollDropdown = panel.Get <DropDownButtonWidget>("MOUSE_SCROLL_TYPE_DROPDOWN"); mouseScrollDropdown.OnMouseDown = _ => ShowMouseScrollDropdown(mouseScrollDropdown, gs); mouseScrollDropdown.GetText = () => gs.MouseScroll.ToString(); var mouseControlDescClassic = panel.Get("MOUSE_CONTROL_DESC_CLASSIC"); mouseControlDescClassic.IsVisible = () => gs.UseClassicMouseStyle; var mouseControlDescModern = panel.Get("MOUSE_CONTROL_DESC_MODERN"); mouseControlDescModern.IsVisible = () => !gs.UseClassicMouseStyle; foreach (var container in new[] { mouseControlDescClassic, mouseControlDescModern }) { var classicScrollRight = container.Get("DESC_SCROLL_RIGHT"); classicScrollRight.IsVisible = () => gs.UseClassicMouseStyle ^ gs.UseAlternateScrollButton; var classicScrollMiddle = container.Get("DESC_SCROLL_MIDDLE"); classicScrollMiddle.IsVisible = () => !gs.UseClassicMouseStyle ^ gs.UseAlternateScrollButton; var zoomDesc = container.Get("DESC_ZOOM"); zoomDesc.IsVisible = () => gs.ZoomModifier == Modifiers.None; var zoomDescModifier = container.Get <LabelWidget>("DESC_ZOOM_MODIFIER"); zoomDescModifier.IsVisible = () => gs.ZoomModifier != Modifiers.None; var zoomDescModifierTemplate = zoomDescModifier.Text; var zoomDescModifierLabel = new CachedTransform <Modifiers, string>( mod => zoomDescModifierTemplate.Replace("MODIFIER", mod.ToString())); zoomDescModifier.GetText = () => zoomDescModifierLabel.Update(gs.ZoomModifier); var edgescrollDesc = container.Get <LabelWidget>("DESC_EDGESCROLL"); edgescrollDesc.IsVisible = () => gs.ViewportEdgeScroll; } // Apply mouse focus preferences immediately var lockMouseCheckbox = panel.Get <CheckboxWidget>("LOCKMOUSE_CHECKBOX"); var oldOnClick = lockMouseCheckbox.OnClick; lockMouseCheckbox.OnClick = () => { // Still perform the old behaviour for clicking the checkbox, before // applying the changes live. oldOnClick(); MakeMouseFocusSettingsLive(); }; var zoomModifierDropdown = panel.Get <DropDownButtonWidget>("ZOOM_MODIFIER"); zoomModifierDropdown.OnMouseDown = _ => ShowZoomModifierDropdown(zoomModifierDropdown, gs); zoomModifierDropdown.GetText = () => gs.ZoomModifier.ToString(); return(() => false); }
Func <bool> InitPanel(Widget panel) { var musicPlaylist = worldRenderer.World.WorldActor.Trait <MusicPlaylist>(); var ss = Game.Settings.Sound; var scrollPanel = panel.Get <ScrollPanelWidget>("SETTINGS_SCROLLPANEL"); SettingsUtils.BindCheckboxPref(panel, "CASH_TICKS", ss, "CashTicks"); SettingsUtils.BindCheckboxPref(panel, "MUTE_SOUND", ss, "Mute"); SettingsUtils.BindCheckboxPref(panel, "MUTE_BACKGROUND_MUSIC", ss, "MuteBackgroundMusic"); SettingsUtils.BindSliderPref(panel, "SOUND_VOLUME", ss, "SoundVolume"); SettingsUtils.BindSliderPref(panel, "MUSIC_VOLUME", ss, "MusicVolume"); SettingsUtils.BindSliderPref(panel, "VIDEO_VOLUME", ss, "VideoVolume"); var muteCheckbox = panel.Get <CheckboxWidget>("MUTE_SOUND"); var muteCheckboxOnClick = muteCheckbox.OnClick; var muteCheckboxIsChecked = muteCheckbox.IsChecked; muteCheckbox.IsChecked = () => muteCheckboxIsChecked() || Game.Sound.DummyEngine; muteCheckbox.IsDisabled = () => Game.Sound.DummyEngine; muteCheckbox.OnClick = () => { muteCheckboxOnClick(); if (ss.Mute) { Game.Sound.MuteAudio(); } else { Game.Sound.UnmuteAudio(); } }; var muteBackgroundMusicCheckbox = panel.Get <CheckboxWidget>("MUTE_BACKGROUND_MUSIC"); var muteBackgroundMusicCheckboxOnClick = muteBackgroundMusicCheckbox.OnClick; muteBackgroundMusicCheckbox.OnClick = () => { muteBackgroundMusicCheckboxOnClick(); if (!musicPlaylist.AllowMuteBackgroundMusic) { return; } if (musicPlaylist.CurrentSongIsBackground) { musicPlaylist.Stop(); } }; // Replace controls with a warning label if sound is disabled var noDeviceLabel = panel.GetOrNull("NO_AUDIO_DEVICE_CONTAINER"); if (noDeviceLabel != null) { noDeviceLabel.Visible = Game.Sound.DummyEngine; } panel.Get("CASH_TICKS_CONTAINER").Visible = !Game.Sound.DummyEngine; panel.Get("MUTE_SOUND_CONTAINER").Visible = !Game.Sound.DummyEngine; panel.Get("MUTE_BACKGROUND_MUSIC_CONTAINER").Visible = !Game.Sound.DummyEngine; panel.Get("SOUND_VOLUME_CONTAINER").Visible = !Game.Sound.DummyEngine; panel.Get("MUSIC_VOLUME_CONTAINER").Visible = !Game.Sound.DummyEngine; panel.Get("VIDEO_VOLUME_CONTAINER").Visible = !Game.Sound.DummyEngine; var soundVolumeSlider = panel.Get <SliderWidget>("SOUND_VOLUME"); soundVolumeSlider.OnChange += x => Game.Sound.SoundVolume = x; var musicVolumeSlider = panel.Get <SliderWidget>("MUSIC_VOLUME"); musicVolumeSlider.OnChange += x => Game.Sound.MusicVolume = x; var videoVolumeSlider = panel.Get <SliderWidget>("VIDEO_VOLUME"); videoVolumeSlider.OnChange += x => Game.Sound.VideoVolume = x; var devices = Game.Sound.AvailableDevices(); soundDevice = devices.FirstOrDefault(d => d.Device == ss.Device) ?? devices.First(); var audioDeviceDropdown = panel.Get <DropDownButtonWidget>("AUDIO_DEVICE"); audioDeviceDropdown.OnMouseDown = _ => ShowAudioDeviceDropdown(audioDeviceDropdown, devices, scrollPanel); var deviceFont = Game.Renderer.Fonts[audioDeviceDropdown.Font]; var deviceLabel = new CachedTransform <SoundDevice, string>( s => WidgetUtils.TruncateText(s.Label, audioDeviceDropdown.UsableWidth, deviceFont)); audioDeviceDropdown.GetText = () => deviceLabel.Update(soundDevice); var restartDesc = panel.Get("RESTART_REQUIRED_DESC"); restartDesc.IsVisible = () => soundDevice.Device != OriginalSoundDevice; SettingsUtils.AdjustSettingsScrollPanelLayout(scrollPanel); return(() => { ss.Device = soundDevice.Device; return ss.Device != OriginalSoundDevice; }); }