Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add check box in new UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 3, 2023
1 parent 32dcafc commit a38744f
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 7 deletions.
1 change: 1 addition & 0 deletions RotationSolver.Basic/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal static unsafe bool CanMove
}

public static float CountDownTime => Countdown.TimeRemaining;
public static PluginConfig ConfigNew { get; set; } = new PluginConfig();

public static PluginConfiguration Config { get; set; }
public static PluginConfiguration Default { get; } = new PluginConfiguration();
Expand Down
76 changes: 76 additions & 0 deletions RotationSolver/Localization/ConfigTranslation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using RotationSolver.Basic.Configuration;

namespace RotationSolver.Localization;

internal static class ConfigTranslation
{
public static string ToName(this JobConfigString config) => config switch
{
_ => string.Empty,
};

public static string ToName(this JobConfigInt config) => config switch
{
_ => string.Empty,
};

public static string ToName(this JobConfigFloat config) => config switch
{
_ => string.Empty,
};

public static string ToName(this PluginConfigInt config) => config switch
{
_ => string.Empty,
};

public static string ToName(this PluginConfigBool config) => config switch
{
_ => string.Empty,
};

public static string ToName(this PluginConfigFloat config) => config switch
{
_ => string.Empty,
};

public static string ToName(this PluginConfigVector4 config) => config switch
{
_ => string.Empty,
};

public static string ToDescription(this JobConfigString config) => config switch
{
_ => string.Empty,
};

public static string ToDescription(this JobConfigInt config) => config switch
{
_ => string.Empty,
};

public static string ToDescription(this JobConfigFloat config) => config switch
{
_ => string.Empty,
};

public static string ToDescription(this PluginConfigInt config) => config switch
{
_ => string.Empty,
};

public static string ToDescription(this PluginConfigBool config) => config switch
{
_ => string.Empty,
};

public static string ToDescription(this PluginConfigFloat config) => config switch
{
_ => string.Empty,
};

public static string ToDescription(this PluginConfigVector4 config) => config switch
{
_ => string.Empty,
};
}
79 changes: 73 additions & 6 deletions RotationSolver/UI/SearchableConfigs/CheckBoxSearch.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,81 @@
namespace RotationSolver.UI.SearchableSettings;
using ECommons.ExcelServices;
using RotationSolver.Basic.Configuration;
using RotationSolver.Localization;
using RotationSolver.UI.SearchableConfigs;

internal class CheckBoxSearch : ISearchable
namespace RotationSolver.UI.SearchableSettings;

internal class CheckBoxSearchPlugin : CheckBoxSearch
{
private PluginConfigBool _config;
public override string ID => _config.ToString();

public override string Name => _config.ToName();

public override string Description => _config.ToDescription();

public CheckBoxSearchPlugin(PluginConfigBool config, params ISearchable[] children)
{
_config = config;
Children = children;
}

protected override bool GetValue(Job job)
{
return Service.ConfigNew.GetValue(_config);
}

protected override void SetValue(Job job, bool value)
{
Service.ConfigNew.SetValue(_config, value);
}
}

internal abstract class CheckBoxSearch : Searchable
{
public string SearchingKey => throw new NotImplementedException();
public abstract string ID { get; }

public ISearchable[] Children { get; protected set; }

public string Name { get; set; }
public string Description { get; set; } = string.Empty;
protected abstract bool GetValue(Job job);
protected abstract void SetValue(Job job, bool value);

public void Draw()
public override void Draw(Job job)
{
var enable = GetValue(job);
if (ImGui.Checkbox($"##{ID}", ref enable))
{
SetValue(job, enable);
}
if(ImGui.IsItemHovered()) ShowTooltip();

var name = $"{Name}##Config_{ID}";
if (enable)
{
var x = ImGui.GetCursorPosX();
var drawBody = ImGui.TreeNode(name) && Children != null && Children.Length > 0;
if (ImGui.IsItemHovered()) ShowTooltip();

if (drawBody)
{
ImGui.SetCursorPosX(x);
ImGui.BeginGroup();
foreach (var child in Children)
{
child.Draw(job);
}
ImGui.EndGroup();
ImGui.TreePop();
}
}
else
{
ImGui.PushStyleColor(ImGuiCol.HeaderHovered, 0x0);
ImGui.PushStyleColor(ImGuiCol.HeaderActive, 0x0);
ImGui.TreeNodeEx(name, ImGuiTreeNodeFlags.Leaf | ImGuiTreeNodeFlags.NoTreePushOnOpen);
if (ImGui.IsItemHovered()) ShowTooltip();

ImGui.PopStyleColor(2);
}
}
}
6 changes: 5 additions & 1 deletion RotationSolver/UI/SearchableConfigs/ISearchable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
namespace RotationSolver.UI.SearchableSettings;
using ECommons.ExcelServices;

namespace RotationSolver.UI.SearchableSettings;

public interface ISearchable
{
string SearchingKey { get; }

void Draw(Job job);
}
31 changes: 31 additions & 0 deletions RotationSolver/UI/SearchableConfigs/Searchable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using ECommons.ExcelServices;
using RotationSolver.UI.SearchableSettings;

namespace RotationSolver.UI.SearchableConfigs;

internal abstract class Searchable : ISearchable
{
public string SearchingKey => Name + " : " + Description;
public abstract string Name { get; }
public abstract string Description { get; }
public Action DrawTooltip { get; set; }

public abstract void Draw(Job job);

protected void ShowTooltip()
{
ImguiTooltips.ShowTooltip(() =>
{
var showDesc = !string.IsNullOrEmpty(Description);
if (showDesc)
{
ImGui.TextWrapped(Description);
}
if(showDesc && DrawTooltip != null)
{
ImGui.Separator();
}
DrawTooltip?.Invoke();
});
}
}

0 comments on commit a38744f

Please sign in to comment.