Skip to content

Commit

Permalink
Option to only show relevant settings
Browse files Browse the repository at this point in the history
  • Loading branch information
n00mkrad committed Nov 26, 2024
1 parent a09b290 commit 6e4cc8d
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 58 deletions.
1 change: 0 additions & 1 deletion CodeLegacy/Data/Implementations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public static AiInfo GetAi(string aiName)
return NetworksAll[0];
}

// New: Use enums
public static AiInfo GetAi(Ai ai)
{
if (AiLookup.TryGetValue(ai, out AiInfo aiObj))
Expand Down
3 changes: 3 additions & 0 deletions CodeLegacy/Extensions/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public static bool GetBool(this string str)
{
try
{
if (str.IsEmpty())
return false;

return bool.Parse(str);
}
catch
Expand Down
18 changes: 18 additions & 0 deletions CodeLegacy/Forms/CustomForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,30 @@ namespace Flowframes.Forms
public class CustomForm : Form
{
public Control FocusedControl { get { return this.GetControls().Where(c => c.Focused).FirstOrDefault(); } }
public List<Control> AllControls => GetAllControls(this);

public bool AllowTextboxTab { get; set; } = true;
public bool AllowEscClose { get; set; } = true;

private List<Control> _tabOrderedControls;

private static List<Control> GetAllControls(Control parent)
{
var controls = new List<Control>();

foreach (Control ctrl in parent.Controls)
{
controls.Add(ctrl);

if (ctrl.HasChildren)
{
controls.AddRange(GetAllControls(ctrl));
}
}

return controls;
}

public void TabOrderInit(List<Control> tabOrderedControls, int defaultFocusIndex = 0)
{
_tabOrderedControls = tabOrderedControls;
Expand Down
4 changes: 2 additions & 2 deletions CodeLegacy/Forms/Main/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public Form1()
}
}

private async void Form1_Load(object sender, EventArgs e)
private void Form1_Load(object sender, EventArgs e)
{
CheckForIllegalCrossThreadCalls = false;
CheckForIllegalCrossThreadCalls = Debugger.IsAttached;
AutoScaleMode = AutoScaleMode.None;
}

Expand Down
83 changes: 56 additions & 27 deletions CodeLegacy/Forms/SettingsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 26 additions & 28 deletions CodeLegacy/Forms/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,32 @@

namespace Flowframes.Forms
{
public partial class SettingsForm : Form
public partial class SettingsForm : CustomForm
{
bool initialized = false;
private bool _initialized = false;
private AiInfo _currentAi = null;

public SettingsForm(int index = 0)
public SettingsForm(int tabIndex = 0, AiInfo currentAi = null)
{
AutoScaleMode = AutoScaleMode.None;
InitializeComponent();
settingsTabList.SelectedIndex = index;

_currentAi = currentAi == null ? Program.mainForm.GetAi() : currentAi;
settingsTabList.SelectedIndex = tabIndex;
}

private void SettingsForm_Load(object sender, EventArgs e)
{
MinimumSize = new Size(Width, Height);
MaximumSize = new Size(Width, (Height * 1.5f).RoundToInt());
mpdecimateMode.FillFromEnum<Enums.Interpolation.MpDecimateSens>(useKeyNames: true);
onlyShowRelevantSettings.Click += (s, ea) => SetVisibility();

InitGpus();
InitServers();
LoadSettings();
AddTooltipClickFunction();
initialized = true;
_initialized = true;
Task.Run(() => CheckModelCacheSize());
}

Expand Down Expand Up @@ -105,6 +109,7 @@ void SaveSettings()
ncnnGpus.Text = ncnnGpus.Text.Replace(" ", "");

// General
ConfigParser.SaveGuiElement(onlyShowRelevantSettings);
ConfigParser.SaveComboxIndex(processingMode);
ConfigParser.SaveGuiElement(maxVidHeight, ConfigParser.StringMode.Int);
ConfigParser.SaveComboxIndex(tempFolderLoc);
Expand Down Expand Up @@ -150,6 +155,7 @@ void SaveSettings()

void LoadSettings()
{
ConfigParser.LoadGuiElement(onlyShowRelevantSettings);
// General
ConfigParser.LoadComboxIndex(processingMode);
ConfigParser.LoadGuiElement(maxVidHeight);
Expand Down Expand Up @@ -196,6 +202,8 @@ void LoadSettings()

private void SetVisibility()
{
bool onlyRelevant = onlyShowRelevantSettings.Checked;

// Dev options
List<Control> devOptions = new List<Control> { panKeepTempFolder, };
devOptions.ForEach(c => c.SetVisible(Program.Debug));
Expand All @@ -205,37 +213,27 @@ private void SetVisibility()
legacyUntestedOptions.ForEach(c => c.SetVisible(Program.Debug));

// AutoEnc options
bool autoEncEnabled = autoEncMode.SelectedIndex != 0;
bool autoEncPossible = !_currentAi.Piped;
autoEncMode.Visible = !(onlyRelevant && !autoEncPossible);
bool autoEncEnabled = autoEncMode.Visible && autoEncMode.SelectedIndex != 0;
List<Control> autoEncOptions = new List<Control> { panAutoEncBackups, panAutoEncLowSpaceMode };
autoEncOptions.ForEach(c => c.SetVisible(autoEncEnabled));
panAutoEncInSbsMode.SetVisible(autoEncEnabled && panProcessingStyle.Visible);

var availAis = Implementations.NetworksAvailable;
panTorchGpus.SetVisible(NvApi.NvGpus.Count > 0 && Python.IsPytorchReady());
panNcnnGpus.SetVisible(VulkanUtils.VkDevices.Count > 0);
panRifeCudaHalfPrec.SetVisible(NvApi.NvGpus.Count > 0 && availAis.Contains(Implementations.rifeCuda));
}

private static List<Control> GetAllControls(Control parent)
{
var controls = new List<Control>();

foreach (Control ctrl in parent.Controls)
{
controls.Add(ctrl);

if (ctrl.HasChildren)
{
controls.AddRange(GetAllControls(ctrl));
}
}

return controls;
bool showTorchSettings = !(onlyRelevant && _currentAi.Backend != AiInfo.AiBackend.Pytorch);
panTorchGpus.SetVisible(showTorchSettings && NvApi.NvGpus.Count > 0 && Python.IsPytorchReady());
bool showNcnnSettings = !(onlyRelevant && _currentAi.Backend != AiInfo.AiBackend.Ncnn);
panNcnnGpus.SetVisible(showNcnnSettings && VulkanUtils.VkDevices.Count > 0);
bool showRifeCudaSettings = !(onlyRelevant && _currentAi != Implementations.rifeCuda);
panRifeCudaHalfPrec.SetVisible(showRifeCudaSettings && NvApi.NvGpus.Count > 0 && availAis.Contains(Implementations.rifeCuda));
bool showDainNcnnSettings = !(onlyRelevant && _currentAi != Implementations.dainNcnn);
new List<Control> { panTitleDainNcnn, panDainNcnnTileSize }.ForEach(c => c.SetVisible(showDainNcnnSettings && availAis.Contains(Implementations.dainNcnn)));
}

private void AddTooltipClickFunction()
{
foreach (Control control in GetAllControls(this))
foreach (Control control in AllControls)
{
if(!(control is PictureBox))
continue;
Expand Down Expand Up @@ -283,7 +281,7 @@ private void custOutDirBrowseBtn_Click(object sender, EventArgs e)

private void cmdDebugMode_SelectedIndexChanged(object sender, EventArgs e)
{
if (initialized && cmdDebugMode.SelectedIndex == 2)
if (_initialized && cmdDebugMode.SelectedIndex == 2)
UiUtils.ShowMessageBox("If you enable this, you need to close the CMD window manually after the process has finished, otherwise processing will be paused!", UiUtils.MessageType.Warning);
}

Expand Down
2 changes: 2 additions & 0 deletions CodeLegacy/IO/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ private static string WriteDefaultValIfExists(string keyStr, Type type)
return WriteDefault(keyStr, "");
}

if (key == Key.onlyShowRelevantSettings) return WriteDefault(key, true);
if (key == Key.disablePreview) return WriteDefault(key, true);
if (key == Key.maxVidHeight) return WriteDefault(key, "2160");
if (key == Key.clearLogOnInput) return WriteDefault(key, true);
Expand Down Expand Up @@ -368,6 +369,7 @@ public enum Key
mpdecimateMode,
ncnnGpus,
ncnnThreads,
onlyShowRelevantSettings,
opusBitrate,
processingMode,
rifeCudaBufferSize,
Expand Down

0 comments on commit 6e4cc8d

Please sign in to comment.