Code commit

This commit is contained in:
RisaDev
2024-01-06 01:21:41 +03:00
parent a7d7297c59
commit a486dd2c96
90 changed files with 11576 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
using Dalamud.Interface.Utility;
using Dalamud.Interface;
using ImGuiNET;
using System.Numerics;
using CustomizePlus.Core.Services;
using CustomizePlus.Game.Services;
using CustomizePlus.Configuration.Data;
using CustomizePlus.UI.Windows.MainWindow.Tabs.Templates;
using CustomizePlus.Core.Helpers;
namespace CustomizePlus.UI.Windows.Controls;
public class PluginStateBlock
{
private readonly BoneEditorPanel _boneEditorPanel;
private readonly PluginConfiguration _configuration;
private readonly GameStateService _gameStateService;
private readonly FantasiaPlusDetectService _fantasiaPlusDetectService;
private static Vector4 normalColor = new Vector4(1, 1, 1, 1);
private static Vector4 warnColor = new Vector4(1, 0.5f, 0, 1);
private static Vector4 errorColor = new Vector4(1, 0, 0, 1);
public PluginStateBlock(
BoneEditorPanel boneEditorPanel,
PluginConfiguration configuration,
GameStateService gameStateService,
FantasiaPlusDetectService fantasiaPlusDetectService)
{
_boneEditorPanel = boneEditorPanel;
_configuration = configuration;
_gameStateService = gameStateService;
_fantasiaPlusDetectService = fantasiaPlusDetectService;
}
public void Draw(float yPos)
{
var severity = PluginStateSeverity.Normal;
string? message = null;
if (_fantasiaPlusDetectService.IsFantasiaPlusInstalled)
{
severity = PluginStateSeverity.Error;
message = $"Fantasia+ detected. The plugin is disabled until Fantasia+ is disabled and the game is restarted.";
}
else if (_gameStateService.GameInPosingMode())
{
severity = PluginStateSeverity.Warning;
message = $"GPose active. Most editor features are unavailable while you're in this mode.";
}
else if (!_configuration.PluginEnabled)
{
severity = PluginStateSeverity.Warning;
message = "Plugin is disabled, template bone editing is not available.";
}
else if (_boneEditorPanel.IsEditorActive)
{
if (!_boneEditorPanel.IsCharacterFound)
{
severity = PluginStateSeverity.Error;
message = $"Selected preview character was not found.";
}
else
{
if (_boneEditorPanel.HasChanges)
severity = PluginStateSeverity.Warning;
message = $"Editor is active.{(_boneEditorPanel.HasChanges ? " You have unsaved changes, finish template bone editing to open save/revert dialog." : "")}";
}
}
if (message != null)
{
ImGui.SetCursorPos(new Vector2(ImGui.GetWindowContentRegionMax().X - ImGui.CalcTextSize(message).X - 30, yPos - ImGuiHelpers.GlobalScale));
var icon = FontAwesomeIcon.InfoCircle;
var color = normalColor;
switch (severity)
{
case PluginStateSeverity.Warning:
icon = FontAwesomeIcon.ExclamationTriangle;
color = warnColor;
break;
case PluginStateSeverity.Error:
icon = FontAwesomeIcon.ExclamationTriangle;
color = errorColor;
break;
}
ImGui.PushStyleColor(ImGuiCol.Text, color);
CtrlHelper.LabelWithIcon(icon, message, false);
ImGui.PopStyleColor();
}
}
private enum PluginStateSeverity
{
Normal,
Warning,
Error
}
}

View File

@@ -0,0 +1,151 @@
using Dalamud.Interface.Utility;
using ImGuiNET;
using OtterGui.Classes;
using OtterGui.Log;
using OtterGui.Widgets;
using OtterGui;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using CustomizePlus.Templates;
using CustomizePlus.Configuration.Data;
using CustomizePlus.Profiles;
using CustomizePlus.Profiles.Data;
using CustomizePlus.Templates.Events;
using CustomizePlus.Templates.Data;
namespace CustomizePlus.UI.Windows.Controls;
public abstract class TemplateComboBase : FilterComboCache<Tuple<Template, string>>, IDisposable
{
private readonly PluginConfiguration _configuration;
private readonly TemplateChanged _templateChanged;
// protected readonly TabSelected TabSelected;
protected float InnerWidth;
protected TemplateComboBase(
Func<IReadOnlyList<Tuple<Template, string>>> generator,
Logger logger,
TemplateChanged templateChanged,
//TabSelected tabSelected,
PluginConfiguration configuration)
: base(generator, logger)
{
_templateChanged = templateChanged;
//TabSelected = tabSelected;
_configuration = configuration;
_templateChanged.Subscribe(OnTemplateChange, TemplateChanged.Priority.TemplateCombo);
}
public bool Incognito
=> _configuration.UISettings.IncognitoMode;
void IDisposable.Dispose()
=> _templateChanged.Unsubscribe(OnTemplateChange);
protected override bool DrawSelectable(int globalIdx, bool selected)
{
var ret = base.DrawSelectable(globalIdx, selected);
var (design, path) = Items[globalIdx];
if (path.Length > 0 && design.Name != path)
{
var start = ImGui.GetItemRectMin();
var pos = start.X + ImGui.CalcTextSize(design.Name).X;
var maxSize = ImGui.GetWindowPos().X + ImGui.GetWindowContentRegionMax().X;
var remainingSpace = maxSize - pos;
var requiredSize = ImGui.CalcTextSize(path).X + ImGui.GetStyle().ItemInnerSpacing.X;
var offset = remainingSpace - requiredSize;
if (ImGui.GetScrollMaxY() == 0)
offset -= ImGui.GetStyle().ItemInnerSpacing.X;
if (offset < ImGui.GetStyle().ItemSpacing.X)
ImGuiUtil.HoverTooltip(path);
else
ImGui.GetWindowDrawList().AddText(start with { X = pos + offset },
ImGui.GetColorU32(ImGuiCol.TextDisabled), path);
}
return ret;
}
protected bool Draw(Template? currentTemplate, string? label, float width)
{
InnerWidth = 400 * ImGuiHelpers.GlobalScale;
CurrentSelectionIdx = Math.Max(Items.IndexOf(p => currentTemplate == p.Item1), 0);
CurrentSelection = Items[CurrentSelectionIdx];
var name = label ?? "Select Template Here...";
var ret = Draw("##template", name, string.Empty, width, ImGui.GetTextLineHeightWithSpacing())
&& CurrentSelection != null;
return ret;
}
protected override string ToString(Tuple<Template, string> obj)
=> obj.Item1.Name.Text;
protected override float GetFilterWidth()
=> InnerWidth - 2 * ImGui.GetStyle().FramePadding.X;
protected override bool IsVisible(int globalIndex, LowerString filter)
{
var (design, path) = Items[globalIndex];
return filter.IsContained(path) || design.Name.Lower.Contains(filter.Lower);
}
private void OnTemplateChange(TemplateChanged.Type type, Template template, object? data = null)
{
switch (type)
{
case TemplateChanged.Type.Created:
case TemplateChanged.Type.Renamed:
Cleanup();
break;
case TemplateChanged.Type.Deleted:
Cleanup();
if (CurrentSelection?.Item1 == template)
{
CurrentSelectionIdx = -1;
CurrentSelection = null;
}
break;
}
}
}
public sealed class TemplateCombo : TemplateComboBase
{
private readonly ProfileManager _profileManager;
public TemplateCombo(
TemplateManager templateManager,
ProfileManager profileManager,
TemplateFileSystem fileSystem,
Logger logger,
TemplateChanged templateChanged,
//TabSelected tabSelected,
PluginConfiguration configuration)
: base(
() => templateManager.Templates
.Select(d => new Tuple<Template, string>(d, fileSystem.FindLeaf(d, out var l) ? l.FullName() : string.Empty))
.OrderBy(d => d.Item2)
.ToList(), logger, templateChanged,/* tabSelected, */configuration)
{
_profileManager = profileManager;
}
public Template? Template
=> CurrentSelection?.Item1;
public void Draw(Profile profile, Template? template, int templateIndex)
{
if (!Draw(template, Incognito ? template?.Incognito : template?.Name, ImGui.GetContentRegionAvail().X))
return;
if (templateIndex >= 0)
_profileManager.ChangeTemplate(profile, templateIndex, CurrentSelection!.Item1);
else
_profileManager.AddTemplate(profile, CurrentSelection!.Item1);
}
}