Glamourer/Glamourer/Gui/Tabs/DesignTab/DesignDetailTab.cs

214 lines
8.8 KiB
C#

using Dalamud.Interface.ImGuiNotification;
using Glamourer.Configuration;
using Glamourer.Designs;
using Glamourer.Services;
using ImSharp;
using Luna;
namespace Glamourer.Gui.Tabs.DesignTab;
public class DesignDetailTab
{
private readonly SaveService _saveService;
private readonly Configuration.Configuration _config;
private readonly DesignFileSystemSelector _selector;
private readonly DesignFileSystem _fileSystem;
private readonly DesignManager _manager;
private readonly DesignColors _colors;
private readonly DesignColorCombo _colorCombo;
private bool _editDescriptionMode;
public DesignDetailTab(SaveService saveService, DesignFileSystemSelector selector, DesignManager manager, DesignFileSystem fileSystem,
DesignColors colors, Configuration.Configuration config)
{
_saveService = saveService;
_selector = selector;
_manager = manager;
_fileSystem = fileSystem;
_colors = colors;
_config = config;
_colorCombo = new DesignColorCombo(_colors, false);
}
public void Draw()
{
using var h = DesignPanelFlag.DesignDetails.Header(_config);
if (!h)
return;
DrawDesignInfoTable();
DrawDescription();
Im.Line.New();
}
private void DrawDesignInfoTable()
{
using var style = ImStyleDouble.ButtonTextAlign.Push(new Vector2(0, 0.5f));
using var table = Im.Table.Begin("Details"u8, 2);
if (!table)
return;
table.SetupColumn("Type"u8, TableColumnFlags.WidthFixed, Im.Font.CalculateSize("Reset Temporary Settings"u8).X);
table.SetupColumn("Data"u8, TableColumnFlags.WidthStretch);
table.DrawFrameColumn("Design Name"u8);
table.NextColumn();
var width = Im.ContentRegion.Available with { Y = 0 };
Im.Item.SetNextWidth(width.X);
if (ImEx.InputOnDeactivation.Text("##Name"u8, _selector.Selected!.Name.Text, out string newName))
_manager.Rename(_selector.Selected!, newName);
var identifier = _selector.Selected!.Identifier.ToString();
table.DrawFrameColumn("Unique Identifier"u8);
table.NextColumn();
var fileName = _saveService.FileNames.DesignFile(_selector.Selected!);
using (Im.Font.PushMono())
{
if (Im.Button(identifier, width))
try
{
Process.Start(new ProcessStartInfo(fileName) { UseShellExecute = true });
}
catch (Exception ex)
{
Glamourer.Messager.NotificationMessage(ex, $"Could not open file {fileName}.", $"Could not open file {fileName}",
NotificationType.Warning);
}
if (Im.Item.RightClicked())
Im.Clipboard.Set(identifier);
}
Im.Tooltip.OnHover(
$"Open the file\n\t{fileName}\ncontaining this design in the .json-editor of your choice.\n\nRight-Click to copy identifier to clipboard.");
table.DrawFrameColumn("Full Selector Path"u8);
table.NextColumn();
Im.Item.SetNextWidth(width.X);
if (ImEx.InputOnDeactivation.Text("##Path"u8, _selector.SelectedLeaf!.FullName(), out string newPath))
try
{
_fileSystem.RenameAndMove(_selector.SelectedLeaf, newPath);
}
catch (Exception ex)
{
Glamourer.Messager.NotificationMessage(ex, ex.Message, "Could not rename or move design", NotificationType.Error);
}
table.DrawFrameColumn("Quick Design Bar"u8);
table.NextColumn();
if (Im.RadioButton("Display##qdb"u8, _selector.Selected.QuickDesign))
_manager.SetQuickDesign(_selector.Selected!, true);
var hovered = Im.Item.Hovered();
Im.Line.SameInner();
if (Im.RadioButton("Hide##qdb"u8, !_selector.Selected.QuickDesign))
_manager.SetQuickDesign(_selector.Selected!, false);
if (hovered || Im.Item.Hovered())
Im.Tooltip.Set("Display or hide this design in your quick design bar."u8);
var forceRedraw = _selector.Selected!.ForcedRedraw;
table.DrawFrameColumn("Force Redrawing"u8);
table.NextColumn();
if (Im.Checkbox("##ForceRedraw"u8, ref forceRedraw))
_manager.ChangeForcedRedraw(_selector.Selected!, forceRedraw);
Im.Tooltip.OnHover("Set this design to always force a redraw when it is applied through any means."u8);
var resetAdvancedDyes = _selector.Selected!.ResetAdvancedDyes;
table.DrawFrameColumn("Reset Advanced Dyes"u8);
table.NextColumn();
if (Im.Checkbox("##ResetAdvancedDyes"u8, ref resetAdvancedDyes))
_manager.ChangeResetAdvancedDyes(_selector.Selected!, resetAdvancedDyes);
Im.Tooltip.OnHover("Set this design to reset any previously applied advanced dyes when it is applied through any means."u8);
var resetTemporarySettings = _selector.Selected!.ResetTemporarySettings;
table.DrawFrameColumn("Reset Temporary Settings"u8);
table.NextColumn();
if (Im.Checkbox("##ResetTemporarySettings"u8, ref resetTemporarySettings))
_manager.ChangeResetTemporarySettings(_selector.Selected!, resetTemporarySettings);
Im.Tooltip.OnHover(
"Set this design to reset any temporary settings previously applied to the associated collection when it is applied through any means."u8);
table.DrawFrameColumn("Color"u8);
table.NextColumn();
if (_colorCombo.Draw("##colorCombo"u8, _selector.Selected!.Color.Length is 0 ? DesignColors.AutomaticName : _selector.Selected!.Color,
"Associate a color with this design.\n"u8
+ "Right-Click to revert to automatic coloring.\n"u8
+ "Hold Control and scroll the mousewheel to scroll."u8,
width.X - Im.Style.ItemSpacing.X - Im.Style.FrameHeight, out var newColorName))
_manager.ChangeColor(_selector.Selected!, newColorName == DesignColors.AutomaticName ? string.Empty : newColorName);
if (Im.Item.RightClicked())
_manager.ChangeColor(_selector.Selected!, string.Empty);
if (_colors.TryGetValue(_selector.Selected!.Color, out var currentColor))
{
Im.Line.Same();
if (DesignColorUi.DrawColorButton($"Color associated with {_selector.Selected!.Color}", currentColor, out var newColor))
_colors.SetColor(_selector.Selected!.Color, newColor);
}
else if (_selector.Selected!.Color.Length != 0)
{
Im.Line.Same();
ImEx.Icon.Draw(LunaStyle.WarningIcon, _colors.MissingColor);
Im.Tooltip.OnHover("The color associated with this design does not exist."u8);
}
table.DrawFrameColumn("Creation Date"u8);
table.NextColumn();
ImEx.TextFramed($"{_selector.Selected!.CreationDate.LocalDateTime:F}", width, 0);
table.DrawFrameColumn("Last Update Date"u8);
table.NextColumn();
ImEx.TextFramed($"{_selector.Selected!.LastEdit.LocalDateTime:F}", width, 0);
table.DrawFrameColumn("Tags"u8);
table.NextColumn();
DrawTags();
}
private void DrawTags()
{
var idx = TagButtons.Draw(StringU8.Empty, StringU8.Empty, _selector.Selected!.Tags, out var editedTag);
if (idx < 0)
return;
if (idx < _selector.Selected!.Tags.Length)
{
if (editedTag.Length is 0)
_manager.RemoveTag(_selector.Selected!, idx);
else
_manager.RenameTag(_selector.Selected!, idx, editedTag);
}
else
{
_manager.AddTag(_selector.Selected!, editedTag);
}
}
private void DrawDescription()
{
var desc = _selector.Selected!.Description;
var size = Im.ContentRegion.Available with { Y = 12 * Im.Style.TextHeightWithSpacing };
if (!_editDescriptionMode)
{
using (var textBox = Im.ListBox.Begin("##desc"u8, size))
{
if (textBox)
Im.TextWrapped(desc);
}
if (Im.Button("Edit Description"u8))
_editDescriptionMode = true;
}
else
{
if (ImEx.InputOnDeactivation.MultiLine("##desc"u8, desc, out string newDescription, size))
_manager.ChangeDescription(_selector.Selected!, newDescription);
if (Im.Button("Stop Editing"u8))
_editDescriptionMode = false;
}
}
}