Add Output Path Config Prototype

This commit is contained in:
copecone committed 2026-09-01 08:09:55 +09:00
1 parent 4097e14e7a
commit 43763b0b35
5 files changed
+478 -12

No files matched your search

+234 -10
View File
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using ADOFAIRenderer.Core;
using ADOFAIRenderer.Data;
using ADOFAIRenderer.Data.Input;
using ADOFAIRenderer.Util;
using ADOFAIRenderer.Util.FFmpeg;
using MelonLoader;
using UnityEngine;
@@ -26,7 +28,9 @@ internal class RenderConfigUIManager : MonoBehaviour
private Button _audioEncodingConfigButton = null!;
private VisualElement _audioEncodingConfigContainer = null!;
private Button _globalSettingsButton = null!;
private VisualElement? _globalConfigContainer;
private Button _advancedSettingsButton = null!;
private VisualElement? _advancedConfigContainer;
private Label _versionLabel = null!;
@@ -92,19 +96,38 @@ internal class RenderConfigUIManager : MonoBehaviour
Melon<RenderMod>.Logger.Error("Button 'PresetSettingsButton' not found.");
}
var bottomRow = CreateRow();
bottomRow.pickingMode = PickingMode.Ignore;
bottomRow.style.position = Position.Absolute;
bottomRow.style.right = 0f;
bottomRow.style.bottom = 0f;
bottomRow.style.justifyContent = Justify.FlexEnd;
var rightBottomContainer = new VisualElement
{
name = "RightBottomButtonContainer",
pickingMode = PickingMode.Ignore,
style =
{
position = Position.Absolute,
right = 0f,
bottom = 0f,
flexDirection = FlexDirection.Column,
alignItems = Align.FlexEnd
}
};
var globalRow = CreateRow();
globalRow.pickingMode = PickingMode.Ignore;
globalRow.style.justifyContent = Justify.FlexEnd;
_globalSettingsButton = new Button { name = "GlobalSettingsButton", text = "Global Settings..." };
globalRow.Add(_globalSettingsButton);
rightBottomContainer.Add(globalRow);
var advancedRow = CreateRow();
advancedRow.pickingMode = PickingMode.Ignore;
advancedRow.style.justifyContent = Justify.FlexEnd;
_advancedSettingsButton = new Button { name = "AdvancedSettingsButton", text = "Advanced Settings..." };
bottomRow.Add(_advancedSettingsButton);
advancedRow.Add(_advancedSettingsButton);
rightBottomContainer.Add(advancedRow);
(_root.childCount > 0 ? _root[0] : _root).Add(bottomRow);
Melon<RenderMod>.Logger.Msg("[UI] AdvancedSettingsButton dynamically created.");
(_root.childCount > 0 ? _root[0] : _root).Add(rightBottomContainer);
Melon<RenderMod>.Logger.Msg("[UI] GlobalSettingsButton and AdvancedSettingsButton dynamically created.");
_globalSettingsButton.RegisterCallback<ClickEvent>(_ => OpenGlobalConfig());
_advancedSettingsButton.RegisterCallback<ClickEvent>(_ => OpenAdvancedConfig());
var versionText =
@@ -143,6 +166,207 @@ internal class RenderConfigUIManager : MonoBehaviour
Melon<RenderMod>.Logger.Msg("[UI] VersionLabel dynamically created.");
}
private void OpenGlobalConfig()
{
var tempGlobal = new GlobalConfig
{
OutputDirectory = GlobalSettings.Current.OutputDirectory
};
if (_globalConfigContainer != null && _root.Contains(_globalConfigContainer))
{
_root.Remove(_globalConfigContainer);
}
_globalConfigContainer = new VisualElement
{
name = "GlobalSettingsContainer",
style =
{
position = Position.Absolute,
width = Length.Percent(100),
height = Length.Percent(100),
left = 0,
top = 0,
backgroundColor = new StyleColor(new Color(0.15f, 0.15f, 0.15f, 1.0f)),
justifyContent = Justify.Center,
alignItems = Align.Center
}
};
// 1. Title Row
var titleRow = CreateRow();
var titleLabel = new Label("Global Settings")
{
style =
{
fontSize = 24,
color = new StyleColor(Color.white)
}
};
titleRow.Add(titleLabel);
_globalConfigContainer.Add(titleRow);
// 2. Output Path Row
var pathRow = CreateRow();
var pathLabel = CreateFormLabel("Output Directory");
var defaultDir = GlobalSettings.DefaultOutputDirectory;
var currentDisplayDir = !string.IsNullOrWhiteSpace(tempGlobal.OutputDirectory)
? tempGlobal.OutputDirectory
: defaultDir;
var pathField = new TextField
{
name = "GlobalOutputDirectory",
label = "",
value = currentDisplayDir,
style =
{
width = 520f,
fontSize = 12f
}
};
var textInput = pathField.Q("unity-text-input");
if (textInput != null)
{
textInput.style.backgroundColor = new StyleColor(new Color(0.1f, 0.1f, 0.1f, 1.0f));
textInput.style.borderTopLeftRadius = 6f;
textInput.style.borderTopRightRadius = 6f;
textInput.style.borderBottomLeftRadius = 6f;
textInput.style.borderBottomRightRadius = 6f;
textInput.style.borderTopWidth = 1f;
textInput.style.borderBottomWidth = 1f;
textInput.style.borderLeftWidth = 1f;
textInput.style.borderRightWidth = 1f;
textInput.style.borderTopColor = new StyleColor(new Color(0.3f, 0.3f, 0.35f, 0.8f));
textInput.style.borderBottomColor = new StyleColor(new Color(0.3f, 0.3f, 0.35f, 0.8f));
textInput.style.borderLeftColor = new StyleColor(new Color(0.3f, 0.3f, 0.35f, 0.8f));
textInput.style.borderRightColor = new StyleColor(new Color(0.3f, 0.3f, 0.35f, 0.8f));
textInput.style.paddingLeft = 8f;
textInput.style.paddingRight = 8f;
textInput.style.fontSize = 12f;
textInput.style.unityTextAlign = TextAnchor.MiddleLeft;
textInput.style.color = new StyleColor(Color.white);
}
pathRow.Add(pathLabel);
pathRow.Add(pathField);
_globalConfigContainer.Add(pathRow);
// 3. Action Buttons Row (Browse & Reset)
var actionRow = CreateRow();
actionRow.style.height = StyleKeyword.Auto;
actionRow.style.maxHeight = StyleKeyword.Null;
actionRow.style.minHeight = StyleKeyword.Null;
actionRow.style.marginBottom = 15f;
var browseBtn = new Button { text = "Browse..." };
browseBtn.RegisterCallback<ClickEvent>(_ =>
{
var initial = string.IsNullOrWhiteSpace(pathField.value) ? defaultDir : pathField.value;
FolderDialogUtil.OpenFolderBrowser(initial, selected =>
{
if (!string.IsNullOrWhiteSpace(selected))
{
pathField.value = selected;
}
});
});
var resetBtn = new Button { text = "Reset to Default" };
resetBtn.RegisterCallback<ClickEvent>(_ =>
{
pathField.value = defaultDir;
});
actionRow.Add(browseBtn);
actionRow.Add(resetBtn);
_globalConfigContainer.Add(actionRow);
// 4. Info Row
var infoRow = CreateRow();
infoRow.style.height = StyleKeyword.Auto;
infoRow.style.maxHeight = StyleKeyword.Null;
infoRow.style.minHeight = StyleKeyword.Null;
infoRow.style.marginBottom = 10f;
var infoLabel = new Label("Global output directory applies to all renders unless overridden by API.")
{
style =
{
color = new StyleColor(new Color(0.7f, 0.7f, 0.7f)),
fontSize = 18,
unityTextAlign = TextAnchor.MiddleCenter
}
};
infoRow.Add(infoLabel);
_globalConfigContainer.Add(infoRow);
// 5. Control Button Row (Cancel / Save)
var buttonRow = CreateRow();
var cancelBtn = new Button { text = "Cancel" };
var saveBtn = new Button { text = "Save" };
buttonRow.Add(cancelBtn);
buttonRow.Add(saveBtn);
_globalConfigContainer.Add(buttonRow);
cancelBtn.RegisterCallback<ClickEvent>(_ =>
{
ToggleGlobalScreens(false);
_root.Remove(_globalConfigContainer);
_globalConfigContainer = null!;
});
saveBtn.RegisterCallback<ClickEvent>(_ =>
{
var input = pathField.value?.Trim() ?? string.Empty;
if (string.IsNullOrWhiteSpace(input) ||
string.Equals(Path.GetFullPath(input).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar),
Path.GetFullPath(defaultDir).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar),
StringComparison.OrdinalIgnoreCase))
{
GlobalSettings.Current.OutputDirectory = null;
}
else
{
try
{
var fullPath = Path.GetFullPath(input);
if (!Directory.Exists(fullPath))
{
Directory.CreateDirectory(fullPath);
}
GlobalSettings.Current.OutputDirectory = fullPath;
}
catch (Exception ex)
{
CommonWarningDialogUI.ShowDialog("Invalid Path", $"Directory path is invalid:\n{ex.Message}", new DialogButton("OK", () => { }));
return;
}
}
GlobalSettings.Save();
ToggleGlobalScreens(false);
_root.Remove(_globalConfigContainer);
_globalConfigContainer = null!;
});
_root.Add(_globalConfigContainer);
ToggleGlobalScreens(true);
void ToggleGlobalScreens(bool showGlobal)
{
if (_root.childCount > 0)
{
_root[0].style.display = showGlobal ? DisplayStyle.None : DisplayStyle.Flex;
}
_globalConfigContainer.style.display = showGlobal ? DisplayStyle.Flex : DisplayStyle.None;
}
}
private void OpenAdvancedConfig()
{
var config = RenderManager.Instance.Configuration;