From 2f8ff668a995d5f65c66336bc3f9c221fce63cb7 Mon Sep 17 00:00:00 2001 From: A-tG Date: Sun, 1 May 2022 19:25:02 +0300 Subject: [PATCH] NeverShowElements implemented --- .../Core/OsdWindowManager.Visibility.cs | 20 ++++----- .../Factories/OsdContentFactory.cs | 23 +++++++--- .../Factories/StripButtonFactory.cs | 45 ++++++++++++++++--- .../Types/IOsdRootElement.cs | 1 + .../OSD/Strip/ButtonContainer.Voicemeeter.cs | 20 ++++++--- .../OSD/Strip/FaderContainer.Voicemeeter.cs | 15 +++++-- .../OSD/Strip/FaderContainer.xaml.cs | 2 + .../UiControls/OSD/Strip/StripControl.xaml.cs | 20 ++++++++- 8 files changed, 115 insertions(+), 31 deletions(-) diff --git a/VoicemeeterOsdProgram/Core/OsdWindowManager.Visibility.cs b/VoicemeeterOsdProgram/Core/OsdWindowManager.Visibility.cs index 2a0eda9..5350d33 100644 --- a/VoicemeeterOsdProgram/Core/OsdWindowManager.Visibility.cs +++ b/VoicemeeterOsdProgram/Core/OsdWindowManager.Visibility.cs @@ -11,28 +11,27 @@ private static bool UpdateOsdElementsVis() { m_wpfControl.AllowAutoUpdateSeparators = false; - bool hasAnyChildVisible = false; + bool hasAnyElementVisible = false; var children = m_wpfControl.MainContent.Children; var len = children.Count; for (int i = 0; i < len; i++) { var strip = (StripControl)children[i]; // 2 checks to imitate "lazy" evaluation - bool hasChanges = strip.HasChangesFlag; - if (!hasChanges) continue; + if (!strip.HasChangesFlag || !strip.HasAnyChildVisibleFlag) continue; bool isIgnore = OptionsStorage.Osd.IgnoreStripsIndexes.Contains((uint)i); if (isIgnore) continue; strip.Visibility = Visibility.Visible; UpdateAlwaysVisibleElements(strip); - hasAnyChildVisible = true; + hasAnyElementVisible = true; } m_wpfControl.UpdateSeparators(); m_wpfControl.AllowAutoUpdateSeparators = true; - return hasAnyChildVisible; + return hasAnyElementVisible; } private static void UpdateAlwaysVisibleElements(StripControl strip) @@ -40,20 +39,21 @@ private static void UpdateAlwaysVisibleElements(StripControl strip) var options = OptionsStorage.Osd; foreach (ButtonContainer btnCont in strip.BusBtnsContainer.Children) { - if (!options.AlwaysShowElements.Contains(StripElements.Buses)) break; - - btnCont.Visibility = Visibility.Visible; + if (btnCont.IsAlwaysVisible()) + { + btnCont.Visibility = Visibility.Visible; + } } foreach (ButtonContainer btnCont in strip.ControlBtnsContainer.Children) { - if (btnCont.IsAlwaysVisible?.Invoke() ?? false) + if (btnCont.IsAlwaysVisible()) { btnCont.Visibility = Visibility.Visible; } } - if (options.AlwaysShowElements.Contains(StripElements.Fader)) + if (strip.FaderCont.IsAlwaysVisible()) { strip.FaderCont.Visibility = Visibility.Visible; } diff --git a/VoicemeeterOsdProgram/Factories/OsdContentFactory.cs b/VoicemeeterOsdProgram/Factories/OsdContentFactory.cs index dfec93b..87bfb51 100644 --- a/VoicemeeterOsdProgram/Factories/OsdContentFactory.cs +++ b/VoicemeeterOsdProgram/Factories/OsdContentFactory.cs @@ -1,7 +1,8 @@ using AtgDev.Voicemeeter.Types; using System.Collections.Generic; -using VoicemeeterOsdProgram.Core; using VoicemeeterOsdProgram.Core.Types; +using VoicemeeterOsdProgram.Options; +using VoicemeeterOsdProgram.Types; using VoicemeeterOsdProgram.UiControls.OSD; using VoicemeeterOsdProgram.UiControls.OSD.Strip; @@ -56,7 +57,7 @@ private static void AddVirtualOutputs(OsdControl osd) strip.StripLabel.Text = name; MakeFaderParam(strip, stripIndex, StripType.Output); - strip.FaderCont.OsdParent = strip; + InitFader(strip); osd.MainContent.Children.Add(strip); } @@ -72,7 +73,7 @@ private static void AddPhysicalOutputs(OsdControl osd) MakeLabelParam(strip, i, name, StripType.Output); MakeFaderParam(strip, i, StripType.Output); - strip.FaderCont.OsdParent = strip; + InitFader(strip); osd.MainContent.Children.Add(strip); } @@ -88,7 +89,7 @@ private static void AddVirtualInputs(OsdControl osd) MakeLabelParam(strip, stripIndex, $"VirtIn{i + 1}", StripType.Input); MakeFaderParam(strip, stripIndex, StripType.Input); - strip.FaderCont.OsdParent = strip; + InitFader(strip); osd.MainContent.Children.Add(strip); } @@ -102,7 +103,7 @@ private static void AddHardwareInputs(OsdControl osd) MakeLabelParam(strip, i, $"HardIn{i + 1}", StripType.Input); MakeFaderParam(strip, i, StripType.Input); - strip.FaderCont.OsdParent = strip; + InitFader(strip); osd.MainContent.Children.Add(strip); } @@ -185,5 +186,17 @@ private static StripControl GetHardwareInputStrip(int stripIndex) strip.ControlBtnsContainer.Children.Insert(0, btn); return strip; } + + private static void InitFader(StripControl strip) + { + var f = strip.FaderCont; + f.OsdParent = strip; + f.IsAlwaysVisible = () => + { + return !f.IsNeverShow() && + OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Fader); + }; + f.IsNeverShow = () => OptionsStorage.Osd.NeverShowElements.Contains(StripElements.Fader); + } } } diff --git a/VoicemeeterOsdProgram/Factories/StripButtonFactory.cs b/VoicemeeterOsdProgram/Factories/StripButtonFactory.cs index 8a30acf..abe8a0c 100644 --- a/VoicemeeterOsdProgram/Factories/StripButtonFactory.cs +++ b/VoicemeeterOsdProgram/Factories/StripButtonFactory.cs @@ -11,8 +11,7 @@ public static class StripButtonFactory public static ButtonContainer GetMono(IOsdRootElement parent) { - var btnCont = GetCommonBtnCont(parent); - btnCont.IsAlwaysVisible = () => OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Mono); + var btnCont = GetCommonMono(parent); var btn = btnCont.Btn; btnCont.Btn.Style = (Style)btnCont.Resources["MonoBtnStyle"]; @@ -28,8 +27,7 @@ public static ButtonContainer GetMono(IOsdRootElement parent) public static ButtonContainer GetMonoWithReverse(IOsdRootElement parent) { - var btnCont = GetCommonBtnCont(parent); - btnCont.IsAlwaysVisible = () => OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Mono); + var btnCont = GetCommonMono(parent); var btn = btnCont.Btn; btn.Style = (Style)btnCont.Resources["MonoReverseBtnStyle"]; @@ -46,7 +44,12 @@ public static ButtonContainer GetMonoWithReverse(IOsdRootElement parent) public static ButtonContainer GetSolo(IOsdRootElement parent) { var btnCont = GetCommonBtnCont(parent); - btnCont.IsAlwaysVisible = () => OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Solo); + btnCont.IsAlwaysVisible = () => + { + return !btnCont.IsNeverShow() && + OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Solo); + }; + btnCont.IsNeverShow = () => OptionsStorage.Osd.NeverShowElements.Contains(StripElements.Solo); btnCont.Btn.Style = (Style)btnCont.Resources["SoloBtnStyle"]; return btnCont; } @@ -54,7 +57,12 @@ public static ButtonContainer GetSolo(IOsdRootElement parent) public static ButtonContainer GetMute(IOsdRootElement parent) { var btnCont = GetCommonBtnCont(parent); - btnCont.IsAlwaysVisible = () => OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Mute); + btnCont.IsAlwaysVisible = () => + { + return !btnCont.IsNeverShow() && + OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Mute); + }; + btnCont.IsNeverShow = () => OptionsStorage.Osd.NeverShowElements.Contains(StripElements.Mute); var btn = btnCont.Btn; btn.Style = (Style)btnCont.Resources["MuteBtnStyle"]; @@ -79,6 +87,12 @@ public static ButtonContainer GetSel(IOsdRootElement parent) public static ButtonContainer GetBusSelect(IOsdRootElement parent, string name) { var btnCont = GetCommonBtnCont(parent); + btnCont.IsAlwaysVisible = () => + { + return !btnCont.IsNeverShow() && + OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Buses); + }; + btnCont.IsNeverShow = () => OptionsStorage.Osd.NeverShowElements.Contains(StripElements.Buses); btnCont.Btn.Content = name; return btnCont; } @@ -86,7 +100,12 @@ public static ButtonContainer GetBusSelect(IOsdRootElement parent, string name) public static ButtonContainer GetEqOn(IOsdRootElement parent) { var btnCont = GetCommonBtnCont(parent); - btnCont.IsAlwaysVisible = () => OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.EQ); + btnCont.IsAlwaysVisible = () => + { + return !btnCont.IsNeverShow() && + OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.EQ); + }; + btnCont.IsNeverShow = () => OptionsStorage.Osd.NeverShowElements.Contains(StripElements.EQ); var btn = btnCont.Btn; btn.Content = "EQ"; btn.Style = (Style)btnCont.Resources["EqOnBtnStyle"]; @@ -99,5 +118,17 @@ private static ButtonContainer GetCommonBtnCont(IOsdRootElement parent) btnCont.OsdParent = parent; return btnCont; } + + private static ButtonContainer GetCommonMono(IOsdRootElement parent) + { + var btnCont = GetCommonBtnCont(parent); + btnCont.IsAlwaysVisible = () => + { + return !btnCont.IsNeverShow() && + OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Mono); + }; + btnCont.IsNeverShow = () => OptionsStorage.Osd.NeverShowElements.Contains(StripElements.Mono); + return btnCont; + } } } diff --git a/VoicemeeterOsdProgram/Types/IOsdRootElement.cs b/VoicemeeterOsdProgram/Types/IOsdRootElement.cs index 81c92ea..a054d77 100644 --- a/VoicemeeterOsdProgram/Types/IOsdRootElement.cs +++ b/VoicemeeterOsdProgram/Types/IOsdRootElement.cs @@ -3,5 +3,6 @@ public interface IOsdRootElement { public bool HasChangesFlag { get; set; } + public bool HasAnyChildVisibleFlag { get; set; } } } diff --git a/VoicemeeterOsdProgram/UiControls/OSD/Strip/ButtonContainer.Voicemeeter.cs b/VoicemeeterOsdProgram/UiControls/OSD/Strip/ButtonContainer.Voicemeeter.cs index 1a87666..11c133f 100644 --- a/VoicemeeterOsdProgram/UiControls/OSD/Strip/ButtonContainer.Voicemeeter.cs +++ b/VoicemeeterOsdProgram/UiControls/OSD/Strip/ButtonContainer.Voicemeeter.cs @@ -1,11 +1,13 @@ using System; using VoicemeeterOsdProgram.Core.Types; +using System.Windows; namespace VoicemeeterOsdProgram.UiControls.OSD.Strip { partial class ButtonContainer { public Func IsAlwaysVisible = () => false; + public Func IsNeverShow = () => false; private VoicemeeterNumParam m_vmParam; @@ -27,23 +29,31 @@ public VoicemeeterNumParam VmParameter m_vmParam = value; m_vmParam.ReadValueChanged += OnVmValueChanged; - Btn.Click += OnBtnClick; ; + Btn.Click += OnBtnClick; } } private void OnVmValueChanged(object sender, ValOldNew e) { - if (OsdParent is not null) + bool hasOsdParent = OsdParent is not null; + if (hasOsdParent) { OsdParent.HasChangesFlag = true; } - Highlight(); - Visibility = System.Windows.Visibility.Visible; + if (!IsNeverShow()) + { + Highlight(); + Visibility = Visibility.Visible; + if (hasOsdParent) + { + OsdParent.HasAnyChildVisibleFlag = true; + } + } Btn.State = (uint)e.newVal; } - private void OnBtnClick(object sender, System.Windows.RoutedEventArgs e) + private void OnBtnClick(object sender, RoutedEventArgs e) { if (sender is not OutlineTglBtn btn) return; diff --git a/VoicemeeterOsdProgram/UiControls/OSD/Strip/FaderContainer.Voicemeeter.cs b/VoicemeeterOsdProgram/UiControls/OSD/Strip/FaderContainer.Voicemeeter.cs index 57853d9..b215696 100644 --- a/VoicemeeterOsdProgram/UiControls/OSD/Strip/FaderContainer.Voicemeeter.cs +++ b/VoicemeeterOsdProgram/UiControls/OSD/Strip/FaderContainer.Voicemeeter.cs @@ -1,4 +1,5 @@ using VoicemeeterOsdProgram.Core.Types; +using System.Windows; namespace VoicemeeterOsdProgram.UiControls.OSD.Strip { @@ -30,13 +31,21 @@ public VoicemeeterNumParam VmParameter private void OnVmValueChanged(object sender, ValOldNew e) { - if (OsdParent is not null) + bool hasOsdParent = OsdParent is not null; + if (hasOsdParent) { OsdParent.HasChangesFlag = true; } - Visibility = System.Windows.Visibility.Visible; - Highlight(); + if (!IsNeverShow()) + { + Visibility = Visibility.Visible; + Highlight(); + if (hasOsdParent) + { + OsdParent.HasAnyChildVisibleFlag = true; + } + } // To prevent triggering OnFaderValueChanged Fader.isIgnoreValueChanged = true; diff --git a/VoicemeeterOsdProgram/UiControls/OSD/Strip/FaderContainer.xaml.cs b/VoicemeeterOsdProgram/UiControls/OSD/Strip/FaderContainer.xaml.cs index 6bf4cda..7e7ad7e 100644 --- a/VoicemeeterOsdProgram/UiControls/OSD/Strip/FaderContainer.xaml.cs +++ b/VoicemeeterOsdProgram/UiControls/OSD/Strip/FaderContainer.xaml.cs @@ -14,6 +14,8 @@ namespace VoicemeeterOsdProgram.UiControls.OSD.Strip public partial class FaderContainer : ContentControl { public IOsdRootElement OsdParent; + public Func IsAlwaysVisible = () => false; + public Func IsNeverShow = () => false; private DoubleAnimation m_highlightAnim = new() { diff --git a/VoicemeeterOsdProgram/UiControls/OSD/Strip/StripControl.xaml.cs b/VoicemeeterOsdProgram/UiControls/OSD/Strip/StripControl.xaml.cs index 8034f08..edaf230 100644 --- a/VoicemeeterOsdProgram/UiControls/OSD/Strip/StripControl.xaml.cs +++ b/VoicemeeterOsdProgram/UiControls/OSD/Strip/StripControl.xaml.cs @@ -12,6 +12,7 @@ namespace VoicemeeterOsdProgram.UiControls.OSD.Strip public partial class StripControl : UserControl, IOsdRootElement { private bool m_hasChanges = false; + private bool m_hasChildVis = false; private DoubleAnimation m_highlightAnim = new() { @@ -34,11 +35,28 @@ public bool HasChangesFlag m_hasChanges = false; return true; } - return m_hasChanges; + return false; } set => m_hasChanges = value; } + /// + /// Resets itself when read + /// + public bool HasAnyChildVisibleFlag + { + get + { + if (m_hasChildVis) + { + m_hasChildVis = false; + return true; + } + return false; + } + set => m_hasChildVis = value; + } + public StripControl() { InitializeComponent();