mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
Add draggable mod selector width.
This commit is contained in:
parent
6ad0b4299a
commit
480942339f
3 changed files with 32 additions and 21 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using Dalamud.Interface.ImGuiNotification;
|
||||
using Newtonsoft.Json;
|
||||
using OtterGui.Classes;
|
||||
using OtterGui.FileSystem.Selector;
|
||||
using OtterGui.Services;
|
||||
using Penumbra.Api.Enums;
|
||||
using Penumbra.Communication;
|
||||
|
|
@ -23,6 +24,10 @@ public class EphemeralConfig : ISavable, IDisposable, IService
|
|||
[JsonIgnore]
|
||||
private readonly ModPathChanged _modPathChanged;
|
||||
|
||||
public float CurrentModSelectorWidth { get; set; } = 200f;
|
||||
public float ModSelectorMinimumScale { get; set; } = 0.1f;
|
||||
public float ModSelectorMaximumScale { get; set; } = 0.5f;
|
||||
|
||||
public int Version { get; set; } = Configuration.Constants.CurrentVersion;
|
||||
public int LastSeenVersion { get; set; } = PenumbraChangelog.LastChangelogVersion;
|
||||
public bool DebugSeparateWindow { get; set; } = false;
|
||||
|
|
|
|||
|
|
@ -131,18 +131,41 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
|
|||
".7z",
|
||||
];
|
||||
|
||||
public new void Draw(float width)
|
||||
public new void Draw()
|
||||
{
|
||||
_dragDrop.CreateImGuiSource("ModDragDrop", m => m.Extensions.Any(e => ValidModExtensions.Contains(e.ToLowerInvariant())), m =>
|
||||
{
|
||||
ImUtf8.Text($"Dragging mods for import:\n\t{string.Join("\n\t", m.Files.Select(Path.GetFileName))}");
|
||||
return true;
|
||||
});
|
||||
base.Draw(width);
|
||||
base.Draw();
|
||||
if (_dragDrop.CreateImGuiTarget("ModDragDrop", out var files, out _))
|
||||
_modImportManager.AddUnpack(files.Where(f => ValidModExtensions.Contains(Path.GetExtension(f.ToLowerInvariant()))));
|
||||
}
|
||||
|
||||
protected override float CurrentWidth
|
||||
=> _config.Ephemeral.CurrentModSelectorWidth * ImUtf8.GlobalScale;
|
||||
|
||||
protected override float MinimumAbsoluteRemainder
|
||||
=> 550 * ImUtf8.GlobalScale;
|
||||
|
||||
protected override float MinimumScaling
|
||||
=> _config.Ephemeral.ModSelectorMinimumScale;
|
||||
|
||||
protected override float MaximumScaling
|
||||
=> _config.Ephemeral.ModSelectorMaximumScale;
|
||||
|
||||
protected override void SetSize(Vector2 size)
|
||||
{
|
||||
base.SetSize(size);
|
||||
var adaptedSize = MathF.Round(size.X / ImUtf8.GlobalScale);
|
||||
if (adaptedSize == _config.Ephemeral.CurrentModSelectorWidth)
|
||||
return;
|
||||
|
||||
_config.Ephemeral.CurrentModSelectorWidth = adaptedSize;
|
||||
_config.Ephemeral.Save();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
|
|
@ -651,14 +674,10 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
|
|||
if (!_stateFilter.HasFlag(ModFilter.Temporary) || !_stateFilter.HasFlag(ModFilter.NotTemporary))
|
||||
{
|
||||
if (settings == null && _stateFilter.HasFlag(ModFilter.Temporary))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (settings != null && settings.IsTemporary() != _stateFilter.HasFlag(ModFilter.Temporary))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Inheritance
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class ModsTab(
|
|||
{
|
||||
try
|
||||
{
|
||||
selector.Draw(GetModSelectorSize(config));
|
||||
selector.Draw();
|
||||
ImGui.SameLine();
|
||||
ImGui.SetCursorPosX(MathF.Round(ImGui.GetCursorPosX()));
|
||||
using var group = ImRaii.Group();
|
||||
|
|
@ -86,19 +86,6 @@ public class ModsTab(
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary> Get the correct size for the mod selector based on current config. </summary>
|
||||
public static float GetModSelectorSize(Configuration config)
|
||||
{
|
||||
var absoluteSize = Math.Clamp(config.ModSelectorAbsoluteSize, Configuration.Constants.MinAbsoluteSize,
|
||||
Math.Min(Configuration.Constants.MaxAbsoluteSize, ImGui.GetContentRegionAvail().X - 100));
|
||||
var relativeSize = config.ScaleModSelector
|
||||
? Math.Clamp(config.ModSelectorScaledSize, Configuration.Constants.MinScaledSize, Configuration.Constants.MaxScaledSize)
|
||||
: 0;
|
||||
return MathF.Round(config.ScaleModSelector
|
||||
? Math.Max(absoluteSize, relativeSize * ImGui.GetContentRegionAvail().X / 100)
|
||||
: absoluteSize);
|
||||
}
|
||||
|
||||
private void DrawRedrawLine()
|
||||
{
|
||||
if (config.HideRedrawBar)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue