-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'Insert Special Character' right click action on macros
- Loading branch information
1 parent
9ab3379
commit dafb719
Showing
5 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
MacroMate/Extensions/Dalamud/Interface/CharPicker/CharPickerDialog.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Numerics; | ||
using Dalamud.Interface.Utility; | ||
using Dalamud.Interface.Windowing; | ||
using ImGuiNET; | ||
|
||
namespace MacroMate.Extensions.Dalamud.Interface.CharPicker; | ||
|
||
/// Class to pick a character from a list of possible characters | ||
public class CharPickerDialog : Window { | ||
public static readonly string NAME = "Char Picker"; | ||
|
||
private Action<char>? Callback { get; set; } | ||
private List<char> Choices { get; set; } = new(); | ||
|
||
/// <summary> | ||
/// Counts the number of inserts since this window gained focus. | ||
/// | ||
/// Resets when focus is lost or when the window is opened. | ||
/// </summary> | ||
public int ConsecutiveInserts { get; private set; } = 0; | ||
|
||
public CharPickerDialog() : base(NAME) { | ||
this.SizeConstraints = new WindowSizeConstraints { | ||
MinimumSize = new Vector2(375, 330), | ||
MaximumSize = new Vector2(float.MaxValue, float.MaxValue) | ||
}; | ||
} | ||
|
||
public void Open( | ||
List<char> choices, | ||
Action<char> callback | ||
) { | ||
Choices = choices; | ||
Callback = callback; | ||
ConsecutiveInserts = 0; | ||
if (!IsOpen) { | ||
IsOpen = true; | ||
} else { | ||
ImGui.SetWindowFocus(WindowName); | ||
} | ||
} | ||
|
||
public override void Draw() { | ||
var buttonSize = 36 * ImGuiHelpers.GlobalScale; | ||
var columns = (int)((ImGui.GetContentRegionAvail().X - ImGui.GetStyle().WindowPadding.X) / (buttonSize + ImGui.GetStyle().ItemSpacing.X)); | ||
|
||
if (!IsFocused) { ConsecutiveInserts = 0; } | ||
|
||
ImGuiClip.ClippedDraw(Choices, (choice) => { | ||
var text = (choice).ToString(); | ||
ImGui.SetWindowFontScale(1.3f); | ||
if (ImGui.Button(text, new Vector2(36 * ImGuiHelpers.GlobalScale))) { | ||
if (Callback != null) { | ||
Callback(choice); | ||
ConsecutiveInserts += 1; | ||
} | ||
} | ||
ImGui.SetWindowFontScale(1); | ||
}, columns, lineHeight: buttonSize); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters