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

Commit

Permalink
fix: changed the way to reset value.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jul 6, 2023
1 parent 7b4e78a commit 3a27f99
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 53 deletions.
2 changes: 1 addition & 1 deletion RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ internal partial class Strings
public string ConfigWindow_Param_HostileDesc { get; set; } = "You can set the logic of hostile target selection to allow flexibility in switching the logic of selecting hostile in battle.";
public string ConfigWindow_Param_AddOne { get; set; } = "Add One";
public string ConfigWindow_Param_HostileCondition { get; set; } = "Hostile target selection condition";
public string ConfigWindow_Param_ResetToDefault { get; set; } = "Press left ctrl + shift and press right mouse button to reset this value";
public string ConfigWindow_Param_ResetToDefault { get; set; } = "Press left ctrl and press left mouse button to reset this value";

public string ConfigWindow_Action_ShowOnCDWindow { get; set; } = "Show on CD window";

Expand Down
73 changes: 50 additions & 23 deletions RotationSolver/UI/ImGuiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using RotationSolver.Localization;
using RotationSolver.Updaters;
using System.ComponentModel;
using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;

namespace RotationSolver.UI;

Expand Down Expand Up @@ -127,20 +125,49 @@ public static bool IconButton(FontAwesomeIcon icon, string name, string descript
return result;
}

public static Vector2 IconButtonSize(FontAwesomeIcon icon, string name)
public static void UndoValue<T>(string name, ref T value, T @default, Action otherThing = null)
{
ImGui.PushFont(UiBuilder.IconFont);
var result = ImGui.CalcTextSize($"{icon.ToIconString()}##{name}");
ImGui.PopFont();
return result;
ImGui.SameLine();

if (IconButton(FontAwesomeIcon.Undo, $"#{name}: Undo",
LocalizationManager.RightLang.ConfigWindow_Param_ResetToDefault)
&& ImGui.IsKeyPressed(ImGuiKey.LeftCtrl))
{
otherThing?.Invoke();
value = @default;
Service.Config.Save();
}
}

public static void UndoValue<T>(string name, ref T value1, T default1, ref T value2, T default2, Action otherThing = null)
{
ImGui.SameLine();

if (IconButton(FontAwesomeIcon.Undo, $"#{name}: Undo",
LocalizationManager.RightLang.ConfigWindow_Param_ResetToDefault)
&& ImGui.IsKeyPressed(ImGuiKey.LeftCtrl))
{
otherThing?.Invoke();
value1 = default1;
value2 = default2;
Service.Config.Save();
}
}

//public static Vector2 IconButtonSize(FontAwesomeIcon icon, string name)
//{
// ImGui.PushFont(UiBuilder.IconFont);
// var result = ImGui.CalcTextSize($"{icon.ToIconString()}##{name}");
// ImGui.PopFont();
// return result;
//}


public static void HoveredString(string text, Action selected = null)
{
if (ImGui.IsItemHovered())
{
ImGuiHelper.ShowTooltip(text);
ShowTooltip(text);

if (ImGui.IsMouseClicked(ImGuiMouseButton.Left))
{
Expand All @@ -155,21 +182,21 @@ public static void ShowTooltip(string text)
if (!string.IsNullOrEmpty(text)) ImGui.SetTooltip(text);
}

public static bool HoveredStringReset(string text)
{
if (ImGui.IsItemHovered())
{
text = string.IsNullOrEmpty(text)? LocalizationManager.RightLang.ConfigWindow_Param_ResetToDefault
: text + "\n \n" + LocalizationManager.RightLang.ConfigWindow_Param_ResetToDefault;

ImGuiHelper.ShowTooltip(text);

return ImGui.IsMouseDown(ImGuiMouseButton.Right)
&& ImGui.IsKeyPressed(ImGuiKey.LeftShift)
&& ImGui.IsKeyPressed(ImGuiKey.LeftCtrl);
}
return false;
}
//public static bool HoveredStringReset(string text)
//{
// if (ImGui.IsItemHovered())
// {
// text = string.IsNullOrEmpty(text)? LocalizationManager.RightLang.ConfigWindow_Param_ResetToDefault
// : text + "\n \n" + LocalizationManager.RightLang.ConfigWindow_Param_ResetToDefault;

// ShowTooltip(text);

// return ImGui.IsMouseDown(ImGuiMouseButton.Right)
// && ImGui.IsKeyPressed(ImGuiKey.LeftShift)
// && ImGui.IsKeyPressed(ImGuiKey.LeftCtrl);
// }
// return false;
//}

internal unsafe static bool DrawEditorList<T>(List<T> items, Action<T> draw)
{
Expand Down
8 changes: 5 additions & 3 deletions RotationSolver/UI/RotationConfigWindow_Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ private static void DrawColor4(string name, ref Vector4 value, Vector4 @default,
otherthing?.Invoke();
Service.Config.Save();
}
if (ImGuiHelper.HoveredStringReset(description) && value != @default)

ImGuiHelper.HoveredString(description);

if (value != @default)
{
value = @default;
Service.Config.Save();
ImGuiHelper.UndoValue(name, ref value, @default);
}
}
}
56 changes: 33 additions & 23 deletions RotationSolver/UI/RotationConfigWindow_Major.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dalamud.Interface.Windowing;
using Dalamud.Logging;
using Newtonsoft.Json.Linq;
using RotationSolver.Localization;

namespace RotationSolver.UI;
Expand Down Expand Up @@ -91,26 +92,30 @@ internal static void DrawCheckBox(string name, ref bool value, bool @default, st
otherThing?.Invoke();
Service.Config.Save();
}
if (ImGuiHelper.HoveredStringReset(description) && value != @default)

ImGuiHelper.HoveredString(description);

if(value != @default)
{
otherThing?.Invoke();
value = @default;
Service.Config.Save();
ImGuiHelper.UndoValue(name, ref value, @default, otherThing);
}
}



private static void DrawRangedFloat(string name, ref float minValue, ref float maxValue, float defaultMin, float defaultMax, float speed = 0.01f, float min = 0, float max = 3, string description = "")
{
ImGui.SetNextItemWidth(100);
if (ImGui.DragFloatRange2(name, ref minValue, ref maxValue, speed, min, max))
{
Service.Config.Save();
}
if (ImGuiHelper.HoveredStringReset(description) && (minValue != defaultMin || maxValue != defaultMax))

ImGuiHelper.HoveredString(description);

if (minValue != defaultMin || maxValue != defaultMax)
{
minValue = defaultMin;
maxValue = defaultMax;
Service.Config.Save();
ImGuiHelper.UndoValue(name, ref minValue, defaultMin, ref maxValue, defaultMax);
}
}

Expand All @@ -121,11 +126,12 @@ private static void DrawRangedInt(string name, ref int minValue, ref int maxValu
{
Service.Config.Save();
}
if (ImGuiHelper.HoveredStringReset(description) && (minValue != defaultMin || maxValue != defaultMax))

ImGuiHelper.HoveredString(description);

if (minValue != defaultMin || maxValue != defaultMax)
{
minValue = defaultMin;
maxValue = defaultMax;
Service.Config.Save();
ImGuiHelper.UndoValue(name, ref minValue, defaultMin, ref maxValue, defaultMax);
}
}

Expand All @@ -137,11 +143,12 @@ private static void DrawFloatNumber(string name, ref float value, float @default
Service.Config.Save();
otherThing?.Invoke();
}
if (ImGuiHelper.HoveredStringReset(description) && value != @default)

ImGuiHelper.HoveredString(description);

if (value != @default)
{
value = @default;
Service.Config.Save();
otherThing?.Invoke();
ImGuiHelper.UndoValue(name, ref value, @default, otherThing);
}
}

Expand All @@ -153,11 +160,12 @@ private static void DrawIntNumber(string name, ref int value, int @default, floa
Service.Config.Save();
otherThing?.Invoke();
}
if (ImGuiHelper.HoveredStringReset(description) && value != @default)

ImGuiHelper.HoveredString(description);

if (value != @default)
{
value = @default;
Service.Config.Save();
otherThing?.Invoke();
ImGuiHelper.UndoValue(name, ref value, @default, otherThing);
}
}

Expand All @@ -168,10 +176,12 @@ private static void DrawColor3(string name, ref Vector3 value, Vector3 @default,
{
Service.Config.Save();
}
if (ImGuiHelper.HoveredStringReset(description) && value != @default)

ImGuiHelper.HoveredString(description);

if (value != @default)
{
value = @default;
Service.Config.Save();
ImGuiHelper.UndoValue(name, ref value, @default);
}
}

Expand Down
4 changes: 1 addition & 3 deletions RotationSolver/UI/RotationConfigWindow_Param.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ECommons.ExcelServices;
using RotationSolver.Commands;
using RotationSolver.Commands;
using RotationSolver.Localization;

namespace RotationSolver.UI;
Expand Down Expand Up @@ -68,7 +67,6 @@ private void DrawParamBasic()

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_ToggleManual,
ref Service.Config.ToggleManual, Service.Default.ToggleManual);

}

private void DrawParamDelay()
Expand Down
Binary file modified RotationSolver/bin/Release/net7.0-windows/RotationSolver/latest.zip
Binary file not shown.

0 comments on commit 3a27f99

Please sign in to comment.