This commit is contained in:
goat 2021-04-10 03:00:24 +02:00
commit 1a42ffefea
No known key found for this signature in database
GPG key ID: F18F057873895461
11 changed files with 265 additions and 24 deletions

View file

@ -72,6 +72,8 @@ resharper_align_multiline_for_stmt = true
resharper_align_multline_type_parameter_constrains = true resharper_align_multline_type_parameter_constrains = true
resharper_align_multline_type_parameter_list = true resharper_align_multline_type_parameter_list = true
resharper_apply_on_completion = true resharper_apply_on_completion = true
resharper_auto_property_can_be_made_get_only_global_highlighting = none
resharper_auto_property_can_be_made_get_only_local_highlighting = none
resharper_autodetect_indent_settings = true resharper_autodetect_indent_settings = true
resharper_braces_for_ifelse = required_for_multiline resharper_braces_for_ifelse = required_for_multiline
resharper_can_use_global_alias = false resharper_can_use_global_alias = false
@ -82,6 +84,8 @@ resharper_csharp_int_align_comments = true
resharper_csharp_new_line_before_while = true resharper_csharp_new_line_before_while = true
resharper_csharp_wrap_after_declaration_lpar = true resharper_csharp_wrap_after_declaration_lpar = true
resharper_enforce_line_ending_style = true resharper_enforce_line_ending_style = true
resharper_member_can_be_private_global_highlighting = none
resharper_member_can_be_private_local_highlighting = none
resharper_new_line_before_finally = false resharper_new_line_before_finally = false
resharper_place_accessorholder_attribute_on_same_line = false resharper_place_accessorholder_attribute_on_same_line = false
resharper_place_field_attribute_on_same_line = false resharper_place_field_attribute_on_same_line = false

View file

@ -78,6 +78,12 @@ namespace Dalamud
ShowInHelp = false, ShowInHelp = false,
}); });
this.dalamud.CommandManager.AddHandler("/xldata", new CommandInfo(this.OnDebugDrawDataMenu)
{
HelpMessage = Loc.Localize("DalamudDevDataMenuHelp", "Draw dev data menu DEBUG. Usage: /xldata [Data Dropdown Type]"),
ShowInHelp = false,
});
this.dalamud.CommandManager.AddHandler("/xllog", new CommandInfo(this.OnOpenLog) this.dalamud.CommandManager.AddHandler("/xllog", new CommandInfo(this.OnOpenLog)
{ {
HelpMessage = Loc.Localize("DalamudDevLogHelp", "Open dev log DEBUG"), HelpMessage = Loc.Localize("DalamudDevLogHelp", "Open dev log DEBUG"),
@ -223,6 +229,14 @@ namespace Dalamud
this.dalamud.DalamudUi.IsDevMenu = !this.dalamud.DalamudUi.IsDevMenu; this.dalamud.DalamudUi.IsDevMenu = !this.dalamud.DalamudUi.IsDevMenu;
} }
private void OnDebugDrawDataMenu(string command, string arguments)
{
if (string.IsNullOrEmpty(arguments))
this.dalamud.DalamudUi.ToggleData();
else
this.dalamud.DalamudUi.ToggleData(arguments);
}
private void OnOpenLog(string command, string arguments) private void OnOpenLog(string command, string arguments)
{ {
this.dalamud.DalamudUi.ToggleLog(); this.dalamud.DalamudUi.ToggleLog();

View file

@ -19,6 +19,8 @@ namespace Dalamud.Game.Internal.Gui {
public delegate void OnMessageDelegate(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled); public delegate void OnMessageDelegate(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled);
public delegate void OnMessageRawDelegate(XivChatType type, uint senderId, ref StdString sender, ref StdString message, ref bool isHandled); public delegate void OnMessageRawDelegate(XivChatType type, uint senderId, ref StdString sender, ref StdString message, ref bool isHandled);
public delegate void OnCheckMessageHandledDelegate(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled); public delegate void OnCheckMessageHandledDelegate(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled);
public delegate void OnMessageHandledDelegate(XivChatType type, uint senderId, SeString sender, SeString message);
public delegate void OnMessageUnhandledDelegate(XivChatType type, uint senderId, SeString sender, SeString message);
/// <summary> /// <summary>
/// Event that allows you to stop messages from appearing in chat by setting the isHandled parameter to true. /// Event that allows you to stop messages from appearing in chat by setting the isHandled parameter to true.
@ -30,6 +32,16 @@ namespace Dalamud.Game.Internal.Gui {
/// </summary> /// </summary>
public event OnMessageDelegate OnChatMessage; public event OnMessageDelegate OnChatMessage;
/// <summary>
/// Event that will be fired when a chat message is handled by Dalamud or a Plugin.
/// </summary>
public event OnMessageHandledDelegate OnChatMessageHandled;
/// <summary>
/// Event that will be fired when a chat message is not handled by Dalamud or a Plugin.
/// </summary>
public event OnMessageUnhandledDelegate OnChatMessageUnhandled;
/// <summary> /// <summary>
/// Event that will be fired when a chat message is sent by the game, containing raw, unparsed data. /// Event that will be fired when a chat message is sent by the game, containing raw, unparsed data.
/// </summary> /// </summary>
@ -167,8 +179,15 @@ namespace Dalamud.Game.Internal.Gui {
} }
// Print the original chat if it's handled. // Print the original chat if it's handled.
if (!isHandled) if (isHandled)
{
OnChatMessageHandled?.Invoke(chattype, senderid, parsedSender, parsedMessage);
}
else
{
retVal = this.printMessageHook.Original(manager, chattype, pSenderName, messagePtr, senderid, parameter); retVal = this.printMessageHook.Original(manager, chattype, pSenderName, messagePtr, senderid, parameter);
OnChatMessageUnhandled?.Invoke(chattype, senderid, parsedSender, parsedMessage);
}
if (this.baseAddress == IntPtr.Zero) if (this.baseAddress == IntPtr.Zero)
this.baseAddress = manager; this.baseAddress = manager;

View file

@ -149,7 +149,7 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads
} }
catch (Exception e) catch (Exception e)
{ {
Log.Error(e, $"AutoTranslatePayload - failed to resolve: {this}"); Log.Error(e, $"AutoTranslatePayload - failed to resolve: {this.Type} - Group: {this.group}, Key: {this.key}");
} }
} }

View file

@ -1,32 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using System.Numerics; using System.Numerics;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using ImGuiNET; using ImGuiNET;
namespace Dalamud.Interface.Components namespace Dalamud.Interface.Components
{ {
/// <summary>
/// Component Demo Window to view custom components.
/// </summary>
internal class ComponentDemoWindow : Window internal class ComponentDemoWindow : Window
{ {
private readonly IComponent[] components = private List<IComponent> components = new List<IComponent>();
{
new TestComponent(),
};
/// <summary>
/// Initializes a new instance of the <see cref="ComponentDemoWindow"/> class.
/// </summary>
public ComponentDemoWindow() public ComponentDemoWindow()
: base("Dalamud Components Demo") : base("Dalamud Components Demo")
{ {
this.Size = new Vector2(600, 500); this.Size = new Vector2(600, 500);
this.SizeCondition = ImGuiCond.FirstUseEver; this.SizeCondition = ImGuiCond.FirstUseEver;
this.AddComponents();
this.SortComponents();
} }
/// <inheritdoc/>
public override void Draw() public override void Draw()
{ {
ImGui.BeginChild("comp_scrolling", new Vector2(0, 0), false, ImGuiWindowFlags.AlwaysVerticalScrollbar | ImGuiWindowFlags.HorizontalScrollbar); ImGui.BeginChild("comp_scrolling", new Vector2(0, 0), false, ImGuiWindowFlags.AlwaysVerticalScrollbar | ImGuiWindowFlags.HorizontalScrollbar);
ImGui.Text("This is a collection of UI components you can use in your plugin."); ImGui.Text("This is a collection of UI components you can use in your plugin.");
for (var i = 0; i < this.components.Length; i++) for (var i = 0; i < this.components.Count; i++)
{ {
var thisComp = this.components[i]; var thisComp = this.components[i];
@ -38,5 +46,22 @@ namespace Dalamud.Interface.Components
ImGui.EndChild(); ImGui.EndChild();
} }
private void AddComponents()
{
this.components.Add(new TestComponent());
this.components.Add(new HelpMarkerComponent("help me!")
{
SameLine = false,
});
var iconButtonComponent = new IconButtonComponent(1, FontAwesomeIcon.Carrot);
iconButtonComponent.OnButtonClicked += id => PluginLog.Log("Button#{0} clicked!", id);
this.components.Add(iconButtonComponent);
}
private void SortComponents()
{
this.components = this.components.OrderBy(component => component.Name).ToList();
}
} }
} }

View file

@ -0,0 +1,61 @@
using ImGuiNET;
namespace Dalamud.Interface.Components
{
/// <summary>
/// HelpMarker component to add a help icon with text on hover.
/// </summary>
public class HelpMarkerComponent : IComponent
{
/// <summary>
/// Initializes a new instance of the <see cref="HelpMarkerComponent"/> class.
/// </summary>
/// <param name="helpText">The text to display on hover.</param>
public HelpMarkerComponent(string helpText)
{
this.HelpText = helpText;
}
/// <summary>
/// Gets component name.
/// </summary>
public string Name { get; } = "HelpMarker Component";
/// <summary>
/// Gets or sets a value indicating whether the help text should display on same line as previous element.
/// </summary>
public bool SameLine { get; set; } = true;
/// <summary>
/// Gets or sets the help text.
/// </summary>
public string HelpText { get; set; }
/// <summary>
/// Gets or sets the help marker icon.
/// </summary>
public FontAwesomeIcon HelpIcon { get; set; } = FontAwesomeIcon.InfoCircle;
/// <summary>
/// Gets or sets the help text size modifier.
/// </summary>
public float HelpTextModifier { get; set; } = 35.0f;
/// <summary>
/// Draw HelpMarker component.
/// </summary>
public void Draw()
{
if (this.SameLine) ImGui.SameLine();
ImGui.PushFont(UiBuilder.IconFont);
ImGui.TextDisabled(this.HelpIcon.ToIconString());
ImGui.PopFont();
if (!ImGui.IsItemHovered()) return;
ImGui.BeginTooltip();
ImGui.PushTextWrapPos(ImGui.GetFontSize() * this.HelpTextModifier);
ImGui.TextUnformatted(this.HelpText);
ImGui.PopTextWrapPos();
ImGui.EndTooltip();
}
}
}

View file

@ -6,7 +6,7 @@ namespace Dalamud.Interface.Components
public interface IComponent public interface IComponent
{ {
/// <summary> /// <summary>
/// Gets or sets the name of the component. /// Gets the name of the component.
/// </summary> /// </summary>
public string Name { get; } public string Name { get; }

View file

@ -0,0 +1,82 @@
using System.Numerics;
using ImGuiNET;
namespace Dalamud.Interface.Components
{
/// <summary>
/// IconButton component to use an icon as a button.
/// </summary>
public class IconButtonComponent : IComponent
{
/// <summary>
/// Initializes a new instance of the <see cref="IconButtonComponent"/> class.
/// </summary>
/// <param name="buttonId">The id for the button.</param>
/// <param name="buttonIcon">The icon for the button.</param>
public IconButtonComponent(int buttonId, FontAwesomeIcon buttonIcon)
{
this.ButtonId = buttonId;
this.ButtonIcon = buttonIcon;
}
/// <summary>
/// Delegate for the <see cref="IconButtonComponent.IsButtonClickedDelegate"/> event that occurs when the button is clicked.
/// </summary>
/// <param name="buttonId">The id of the button that was clicked.</param>
public delegate void IsButtonClickedDelegate(int buttonId);
/// <summary>
/// Event that occurs when the button is clicked.
/// </summary>
public event IsButtonClickedDelegate OnButtonClicked;
/// <summary>
/// Gets component name.
/// </summary>
public string Name { get; } = "IconButton Component";
/// <summary>
/// Gets or sets the id for the button.
/// </summary>
public int ButtonId { get; set; }
/// <summary>
/// Gets or sets the icon to use for the button.
/// </summary>
public FontAwesomeIcon ButtonIcon { get; set; }
/// <summary>
/// Gets or sets the button color.
/// </summary>
public Vector4 ButtonColor { get; set; } = Vector4.Zero;
/// <summary>
/// Gets or sets the active button color.
/// </summary>
public Vector4 ButtonColorActive { get; set; } = Vector4.Zero;
/// <summary>
/// Gets or sets the hovered button color.
/// </summary>
public Vector4 ButtonColorHovered { get; set; } = Vector4.Zero;
/// <summary>
/// Draw IconButton component.
/// </summary>
public void Draw()
{
ImGui.PushStyleColor(ImGuiCol.Button, this.ButtonColor);
ImGui.PushStyleColor(ImGuiCol.ButtonActive, this.ButtonColorActive);
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, this.ButtonColorHovered);
ImGui.PushFont(UiBuilder.IconFont);
if (ImGui.Button($"{this.ButtonIcon.ToIconString()}{this.ButtonId}"))
{
this.OnButtonClicked?.Invoke(this.ButtonId);
}
ImGui.PopFont();
ImGui.PopStyleColor(3);
}
}
}

View file

@ -1,16 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ImGuiNET; using ImGuiNET;
namespace Dalamud.Interface.Components namespace Dalamud.Interface.Components
{ {
class TestComponent : IComponent /// <summary>
/// Test component to demonstrate how ImGui components work.
/// </summary>
public class TestComponent : IComponent
{ {
/// <summary>
/// Gets component name.
/// </summary>
public string Name { get; } = "Test Component"; public string Name { get; } = "Test Component";
/// <summary>
/// Draw test component.
/// </summary>
public void Draw() public void Draw()
{ {
ImGui.Text("You are viewing the test component. The test was a success."); ImGui.Text("You are viewing the test component. The test was a success.");

View file

@ -31,6 +31,11 @@ namespace Dalamud.Interface
private string serverOpString; private string serverOpString;
private int currentKind; private int currentKind;
private string[] dataKinds = new[]
{
"ServerOpCode", "Address", "Actor Table", "Font Test", "Party List", "Plugin IPC", "Condition",
"Gauge", "Command", "Addon", "Addon Inspector", "StartInfo", "Target", "Toast",
};
private bool drawActors = false; private bool drawActors = false;
private float maxActorDrawDistance = 20; private float maxActorDrawDistance = 20;
@ -73,6 +78,31 @@ namespace Dalamud.Interface
this.Load(); this.Load();
} }
/// <summary>
/// Set the DataKind dropdown menu.
/// </summary>
/// <param name="dataKind">Data kind name, can be lower and/or without spaces.</param>
public void SetDataKind(string dataKind)
{
if (string.IsNullOrEmpty(dataKind))
return;
if (dataKind == "ai")
dataKind = "Addon Inspector";
int index;
dataKind = dataKind.Replace(" ", string.Empty).ToLower();
var dataKinds = this.dataKinds.Select(k => k.Replace(" ", string.Empty).ToLower()).ToList();
if ((index = dataKinds.IndexOf(dataKind)) != -1)
{
this.currentKind = index;
}
else
{
this.dalamud.Framework.Gui.Chat.PrintError("/xldata: Invalid Data Type");
}
}
/// <summary> /// <summary>
/// Draw the window via ImGui. /// Draw the window via ImGui.
/// </summary> /// </summary>
@ -87,15 +117,7 @@ namespace Dalamud.Interface
var copy = ImGui.Button("Copy all"); var copy = ImGui.Button("Copy all");
ImGui.SameLine(); ImGui.SameLine();
ImGui.Combo( ImGui.Combo("Data kind", ref this.currentKind, dataKinds, dataKinds.Length);
"Data kind",
ref this.currentKind,
new[]
{
"ServerOpCode", "Address", "Actor Table", "Font Test", "Party List", "Plugin IPC", "Condition",
"Gauge", "Command", "Addon", "Addon Inspector", "StartInfo", "Target", "Toast",
},
14);
ImGui.Checkbox("Resolve GameData", ref this.resolveGameData); ImGui.Checkbox("Resolve GameData", ref this.resolveGameData);

View file

@ -460,6 +460,16 @@ namespace Dalamud.Interface
this.dataWindow.IsOpen ^= true; this.dataWindow.IsOpen ^= true;
} }
/// <summary>
/// Toggle the data window and preset the dropdown.
/// </summary>
internal void ToggleData(string dataKind)
{
this.dataWindow.IsOpen ^= true;
if (this.dataWindow.IsOpen)
this.dataWindow.SetDataKind(dataKind);
}
/// <summary> /// <summary>
/// Toggle the credits window. /// Toggle the credits window.
/// </summary> /// </summary>