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

Commit

Permalink
fix: styled the job configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 13, 2023
1 parent 6bcccf1 commit b19c496
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public interface IRotationConfig
/// </summary>
string DisplayName { get; }

/// <summary>
/// Default Value for this configuration.
/// </summary>
string DefaultValue { get; }

/// <summary>
/// Get the value of this.
/// </summary>
Expand Down
13 changes: 10 additions & 3 deletions RotationSolver/Commands/RSCommands_OtherCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,35 @@ private static void DoOtherCommand(OtherCommandType otherType, string str)
private static void DoSettingCommand(string str)
{
var job = RotationUpdater.Job;
var value = str.Split(' ').LastOrDefault();
var strs = str.Split(' ');
var value = strs.LastOrDefault();
if(TryGetOneEnum<PluginConfigBool>(str, out var b))
{
var v = !Service.ConfigNew.GetValue(b);
Service.ConfigNew.SetValue(b, v);
value = v.ToString();
value = Service.ConfigNew.GetValue(b).ToString();
}
else if (TryGetOneEnum<PluginConfigFloat>(str, out var f) && float.TryParse(value, out var f1))
{
Service.ConfigNew.SetValue(f, f1);
value = Service.ConfigNew.GetValue(f).ToString();
}
else if (TryGetOneEnum<PluginConfigInt>(str, out var i) && int.TryParse(value, out var i1))
{
Service.ConfigNew.SetValue(i, i1);
value = Service.ConfigNew.GetValue(i).ToString();

}
else if (TryGetOneEnum<JobConfigFloat>(str, out var f2) && float.TryParse(value, out f1))
{
Service.ConfigNew.SetValue(job, f2, f1);
value = Service.ConfigNew.GetValue(job, f2).ToString();

}
else if (TryGetOneEnum<JobConfigInt>(str, out var i2) && int.TryParse(value, out i1))
{
Service.ConfigNew.SetValue(job, i2, i1);
value = Service.ConfigNew.GetValue(job, i2).ToString();
}
else
{
Expand All @@ -70,7 +77,7 @@ private static void DoSettingCommand(string str)

//Say out.
Svc.Chat.Print(string.Format(LocalizationManager.RightLang.Commands_ChangeSettingsValue,
str, value));
strs.FirstOrDefault(), value));
}

private static void ToggleActionCommand(string str)
Expand Down
16 changes: 10 additions & 6 deletions RotationSolver/Localization/ConfigTranslation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,17 @@ internal static class ConfigTranslation
_ => string.Empty,
};

public static string ToCommand(this JobConfigInt config) => ToCommandStr(config);
public static string ToCommand(this JobConfigFloat config) => ToCommandStr(config);
public static string ToCommand(this PluginConfigInt config) => ToCommandStr(config);
public static string ToCommand(this JobConfigInt config) => ToCommandStr(config, "1");
public static string ToCommand(this JobConfigFloat config) => ToCommandStr(config, "0");
public static string ToCommand(this PluginConfigInt config) => ToCommandStr(config, "1");
public static string ToCommand(this PluginConfigBool config) => ToCommandStr(config);
public static string ToCommand(this PluginConfigFloat config) => ToCommandStr(config);
private static string ToCommandStr(object obj)
=> Service.Command + " " + OtherCommandType.Settings.ToString() + " " + obj.ToString();
public static string ToCommand(this PluginConfigFloat config) => ToCommandStr(config, "0");
private static string ToCommandStr(object obj, string extra = "")
{
var result = Service.Command + " " + OtherCommandType.Settings.ToString() + " " + obj.ToString();
if(!string.IsNullOrEmpty(extra)) result += " " + extra;
return result;
}

public static LinkDescription[] ToAction(this JobConfigInt config) => config switch
{
Expand Down
96 changes: 89 additions & 7 deletions RotationSolver/UI/RotationConfigWindowNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
using ECommons.ExcelServices;
using ECommons.GameHelpers;
using ECommons.ImGuiMethods;
using FFXIVClientStructs.FFXIV.Client.Game.UI;
using ImGuiScene;
using Lumina.Excel.GeneratedSheets;
using Newtonsoft.Json.Linq;
using RotationSolver.ActionSequencer;
using RotationSolver.Basic.Configuration;
using RotationSolver.Data;
using RotationSolver.Helpers;
using RotationSolver.Localization;
using RotationSolver.TextureItems;
using RotationSolver.UI.SearchableConfigs;
using RotationSolver.UI.SearchableSettings;
using RotationSolver.Updaters;
using System.Diagnostics;
Expand Down Expand Up @@ -331,10 +334,9 @@ private static void DrawItemMiddle(System.Action drawAction, float wholeWidth, f
drawAction();
}

private static float BodyMargin => 8 * _scale;
private void DrawBody()
{
var margin = BodyMargin;
var margin = 8 * _scale;
ImGui.SetCursorPos(ImGui.GetCursorPos() + Vector2.One * margin);
if (ImGui.BeginChild("Rotation Solver Body", Vector2.One * -margin))
{
Expand Down Expand Up @@ -418,7 +420,7 @@ private static void DrawAbout()
ImGui.PopStyleColor();

var width = ImGui.GetWindowWidth();
if (IconSet.GetTexture("https://discordapp.com/api/guilds/1064448004498653245/embed.png?style=banner2", out var icon) && TextureButton(icon, width, width))
if (IconSet.GetTexture("https://discordapp.com/api/guilds/1064448004498653245/embed.png?style=banner4", out var icon) && TextureButton(icon, width, width))
{
Util.OpenLink("https://discord.gg/4fECHunam9");
}
Expand Down Expand Up @@ -726,13 +728,93 @@ private static void DrawRotationStatus()
RotationUpdater.RightNowRotation?.DisplayStatus();
}

private static string ToCommandStr(string str, string extra = "")
{
var result = Service.Command + " " + OtherCommandType.Rotations.ToString() + " " + str;
if (!string.IsNullOrEmpty(extra)) result += " " + extra;
return result;
}
private static void DrawRotationConfiguration()
{
var rotation = RotationUpdater.RightNowRotation;
if (rotation == null) return;

rotation.Configs.Draw(Player.Available
&& rotation.Jobs.Contains((Job)Player.Object.ClassJob.Id));
var set = rotation.Configs;
foreach (var config in set.Configs)
{
var key = config.Name;
var name = $"##{config.GetHashCode()}_{config.Name}";
string command = ToCommandStr(config.Name, config.DefaultValue);
void Reset() => set.SetValue(config.Name, config.DefaultValue);

Searchable.PrepareGroup(key, command, Reset);

if (config is RotationConfigCombo c)
{
var val = set.GetCombo(c.Name);
ImGui.SetNextItemWidth(ImGui.CalcTextSize(c.Items[val]).X + 50 * _scale);
var openCombo = ImGui.BeginCombo(name, c.Items[val]);
if (ImGui.IsItemHovered()) Searchable.ReactPopup(key, command, Reset);
if (openCombo)
{
for (int comboIndex = 0; comboIndex < c.Items.Length; comboIndex++)
{
if (ImGui.Selectable(c.Items[comboIndex]))
{
set.SetValue(config.Name, comboIndex.ToString());
}
}
ImGui.EndCombo();
}
}
else if (config is RotationConfigBoolean b)
{
bool val = set.GetBool(config.Name);

if (ImGui.Checkbox(name, ref val))
{
set.SetValue(config.Name, val.ToString());
}
if (ImGui.IsItemHovered()) Searchable.ReactPopup(key, command, Reset);
}
else if (config is RotationConfigFloat f)
{
float val = set.GetFloat(config.Name);
ImGui.SetNextItemWidth(_scale * Searchable.DRAG_WIDTH);
if (ImGui.DragFloat(name, ref val, f.Speed, f.Min, f.Max))
{
set.SetValue(config.Name, val.ToString());
}
if (ImGui.IsItemHovered()) Searchable.ReactPopup(key, command, Reset);
}
else if (config is RotationConfigString s)
{
string val = set.GetString(config.Name);

ImGui.SetNextItemWidth(ImGui.GetWindowWidth());
if (ImGui.InputTextWithHint(name, config.DisplayName, ref val, 128))
{
set.SetValue(config.Name, val.ToString());
}
if (ImGui.IsItemHovered()) Searchable.ReactPopup(key, command, Reset);
continue;
}
else if (config is RotationConfigInt i)
{
int val = set.GetInt(config.Name);
ImGui.SetNextItemWidth(_scale * Searchable.DRAG_WIDTH);
if (ImGui.DragInt(name, ref val, i.Speed, i.Min, i.Max))
{
set.SetValue(config.Name, val.ToString());
}
if (ImGui.IsItemHovered()) Searchable.ReactPopup(key, command, Reset);
}
else continue;

ImGui.SameLine();
ImGui.TextWrapped(config.DisplayName);
if (ImGui.IsItemHovered()) Searchable.ReactPopup(key, command, Reset, false);
}
}

private static void DrawRotationInformation()
Expand Down Expand Up @@ -1044,7 +1126,7 @@ private static void DrawRotationsGitHub()

var changed = false;

var width = ImGui.GetWindowWidth() - ImGuiEx.CalcIconSize(FontAwesomeIcon.Ban).X - ImGui.GetStyle().ItemSpacing.X * 3 - BodyMargin;
var width = ImGui.GetWindowWidth() - ImGuiEx.CalcIconSize(FontAwesomeIcon.Ban).X - ImGui.GetStyle().ItemSpacing.X * 3 - 10 * _scale;
width /= 3;

ImGui.SetNextItemWidth(width);
Expand Down Expand Up @@ -1086,7 +1168,7 @@ private static void DrawRotationsLibraries()

ImGui.Spacing();

var width = ImGui.GetWindowWidth() - ImGuiEx.CalcIconSize(FontAwesomeIcon.Ban).X - ImGui.GetStyle().ItemSpacing.X - BodyMargin;
var width = ImGui.GetWindowWidth() - ImGuiEx.CalcIconSize(FontAwesomeIcon.Ban).X - ImGui.GetStyle().ItemSpacing.X - 10 * _scale;

int removeIndex = -1;
for (int i = 0; i < Service.ConfigNew.GlobalConfig.OtherLibs.Length; i++)
Expand Down
49 changes: 29 additions & 20 deletions RotationSolver/UI/SearchableConfigs/Searchable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace RotationSolver.UI.SearchableConfigs;

internal abstract class Searchable : ISearchable
{
protected const float DRAG_WIDTH = 150;
public const float DRAG_WIDTH = 150;
protected static float Scale => ImGuiHelpers.GlobalScale;
public CheckBoxSearch Parent { get; set; }

Expand All @@ -28,17 +28,22 @@ public void Draw(Job job)

DrawMain(job);

if (ImGui.BeginPopup(Popup_Key))
PrepareGroup(Popup_Key, Command, () => ResetToDefault(job));
}

public static void PrepareGroup(string key, string command, Action reset)
{
if (ImGui.BeginPopup(key))
{
if(ImGui.BeginTable(Popup_Key, 2, ImGuiTableFlags.BordersOuter))
if (ImGui.BeginTable(key, 2, ImGuiTableFlags.BordersOuter))
{
DrawHotKeys("Reset to Default Value.", () => ResetToDefault(job), "Backspace");
if (reset != null) DrawHotKeys("Reset to Default Value.", reset, "Backspace");

if (!string.IsNullOrEmpty(Command))
if (!string.IsNullOrEmpty(command))
{
DrawHotKeys($"Execute \"{Command}\"", ExecuteCommand, "Alt");
DrawHotKeys($"Execute \"{command}\"", () => ExecuteCommand(command), "Alt");

DrawHotKeys($"Copy \"{Command}\"", CopyCommand, "Ctrl");
DrawHotKeys($"Copy \"{command}\"", () => CopyCommand(command), "Ctrl");
}
ImGui.EndTable();
}
Expand Down Expand Up @@ -75,30 +80,34 @@ protected void ShowTooltip(Job job, bool showHand = true)
});
}

if(showHand) ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
ReactPopup(Popup_Key, Command, () => ResetToDefault(job));
}

if (ImGui.IsMouseClicked(ImGuiMouseButton.Right))
public static void ReactPopup(string key, string command, Action reset, bool showHand = true)
{
if (showHand) ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);

if (ImGui.IsMouseClicked(ImGuiMouseButton.Right))
{
if(!ImGui.IsPopupOpen(Popup_Key))
if (!ImGui.IsPopupOpen(key))
{
ImGui.OpenPopup(Popup_Key);
ImGui.OpenPopup(key);
}
}

ExecuteHotKeys(() => ResetToDefault(job), VirtualKey.BACK);
ExecuteHotKeys(ExecuteCommand, VirtualKey.MENU);
ExecuteHotKeys(CopyCommand, VirtualKey.CONTROL);
if (reset != null) ExecuteHotKeys(reset, VirtualKey.BACK);
ExecuteHotKeys(() => ExecuteCommand(command), VirtualKey.MENU);
ExecuteHotKeys(() => CopyCommand(command), VirtualKey.CONTROL);
}

private void ExecuteCommand()
private static void ExecuteCommand(string command)
{
Svc.Commands.ProcessCommand(Command);
Svc.Commands.ProcessCommand(command);
}

private void CopyCommand()
private static void CopyCommand(string command)
{
ImGui.SetClipboardText(Command);
Notify.Success($"\"{Command}\" copied to clipboard.");
ImGui.SetClipboardText(command);
Notify.Success($"\"{command}\" copied to clipboard.");
}

private static void DrawHotKeys(string name, Action action, params string[] keys)
Expand Down

0 comments on commit b19c496

Please sign in to comment.