Add user configurable tooltip offset

This commit is contained in:
Infi
2024-04-07 19:01:41 +02:00
parent a3bf0cabf5
commit d9114aeb0e
6 changed files with 126 additions and 88 deletions
+71 -69
View File
@@ -45,6 +45,7 @@ internal class Configuration : IPluginConfiguration {
public string GlobalFont = Fonts.GlobalFonts[0].Name;
public string JapaneseFont = Fonts.JapaneseFonts[0].Item1;
public float TooltipOffset = 10f;
public float WindowAlpha = 100f;
public Dictionary<ChatType, uint> ChatColours = new();
public List<Tab> Tabs = new();
@@ -52,50 +53,51 @@ internal class Configuration : IPluginConfiguration {
public uint DatabaseMigration = LatestDbVersion;
internal void UpdateFrom(Configuration other) {
this.HideChat = other.HideChat;
this.HideDuringCutscenes = other.HideDuringCutscenes;
this.HideWhenNotLoggedIn = other.HideWhenNotLoggedIn;
this.HideWhenUiHidden = other.HideWhenUiHidden;
this.NativeItemTooltips = other.NativeItemTooltips;
this.PrettierTimestamps = other.PrettierTimestamps;
this.MoreCompactPretty = other.MoreCompactPretty;
this.HideSameTimestamps = other.HideSameTimestamps;
this.ShowNoviceNetwork = other.ShowNoviceNetwork;
this.SidebarTabView = other.SidebarTabView;
this.CommandHelpSide = other.CommandHelpSide;
this.KeybindMode = other.KeybindMode;
this.LanguageOverride = other.LanguageOverride;
this.CanMove = other.CanMove;
this.CanResize = other.CanResize;
this.ShowTitleBar = other.ShowTitleBar;
this.ShowPopOutTitleBar = other.ShowPopOutTitleBar;
this.DatabaseBattleMessages = other.DatabaseBattleMessages;
this.LoadPreviousSession = other.LoadPreviousSession;
this.FilterIncludePreviousSessions = other.FilterIncludePreviousSessions;
this.SharedMode = other.SharedMode;
this.SortAutoTranslate = other.SortAutoTranslate;
this.CollapseDuplicateMessages = other.CollapseDuplicateMessages;
this.FontsEnabled = other.FontsEnabled;
this.ExtraGlyphRanges = other.ExtraGlyphRanges;
this.FontSize = other.FontSize;
this.JapaneseFontSize = other.JapaneseFontSize;
this.SymbolsFontSize = other.SymbolsFontSize;
this.GlobalFont = other.GlobalFont;
this.JapaneseFont = other.JapaneseFont;
this.WindowAlpha = other.WindowAlpha;
this.ChatColours = other.ChatColours.ToDictionary(entry => entry.Key, entry => entry.Value);
this.Tabs = other.Tabs.Select(t => t.Clone()).ToList();
this.DatabaseMigration = other.DatabaseMigration;
HideChat = other.HideChat;
HideDuringCutscenes = other.HideDuringCutscenes;
HideWhenNotLoggedIn = other.HideWhenNotLoggedIn;
HideWhenUiHidden = other.HideWhenUiHidden;
NativeItemTooltips = other.NativeItemTooltips;
PrettierTimestamps = other.PrettierTimestamps;
MoreCompactPretty = other.MoreCompactPretty;
HideSameTimestamps = other.HideSameTimestamps;
ShowNoviceNetwork = other.ShowNoviceNetwork;
SidebarTabView = other.SidebarTabView;
CommandHelpSide = other.CommandHelpSide;
KeybindMode = other.KeybindMode;
LanguageOverride = other.LanguageOverride;
CanMove = other.CanMove;
CanResize = other.CanResize;
ShowTitleBar = other.ShowTitleBar;
ShowPopOutTitleBar = other.ShowPopOutTitleBar;
DatabaseBattleMessages = other.DatabaseBattleMessages;
LoadPreviousSession = other.LoadPreviousSession;
FilterIncludePreviousSessions = other.FilterIncludePreviousSessions;
SharedMode = other.SharedMode;
SortAutoTranslate = other.SortAutoTranslate;
CollapseDuplicateMessages = other.CollapseDuplicateMessages;
FontsEnabled = other.FontsEnabled;
ExtraGlyphRanges = other.ExtraGlyphRanges;
FontSize = other.FontSize;
JapaneseFontSize = other.JapaneseFontSize;
SymbolsFontSize = other.SymbolsFontSize;
GlobalFont = other.GlobalFont;
JapaneseFont = other.JapaneseFont;
TooltipOffset = other.TooltipOffset;
WindowAlpha = other.WindowAlpha;
ChatColours = other.ChatColours.ToDictionary(entry => entry.Key, entry => entry.Value);
Tabs = other.Tabs.Select(t => t.Clone()).ToList();
DatabaseMigration = other.DatabaseMigration;
}
public void Migrate() {
var loop = true;
while (loop && this.Version < LatestVersion) {
switch (this.Version) {
while (loop && Version < LatestVersion) {
switch (Version) {
case 1: {
this.Version = 2;
Version = 2;
foreach (var tab in this.Tabs) {
foreach (var tab in Tabs) {
#pragma warning disable CS0618
tab.UnreadMode = tab.DisplayUnread ? UnreadMode.Unseen : UnreadMode.None;
#pragma warning restore CS0618
@@ -104,26 +106,26 @@ internal class Configuration : IPluginConfiguration {
break;
}
case 2:
this.Version = 3;
Version = 3;
this.JapaneseFontSize = this.FontSize;
this.SymbolsFontSize = this.FontSize;
JapaneseFontSize = FontSize;
SymbolsFontSize = FontSize;
break;
case 3:
this.Version = 4;
Version = 4;
this.WindowAlpha *= 100f;
WindowAlpha *= 100f;
break;
case 4:
this.Version = 5;
Version = 5;
foreach (var tab in this.Tabs) {
foreach (var tab in Tabs) {
tab.ExtraChatAll = true;
}
break;
default:
Plugin.Log.Warning($"Couldn't migrate config version {this.Version}");
Plugin.Log.Warning($"Couldn't migrate config version {Version}");
loop = false;
break;
}
@@ -181,53 +183,53 @@ internal class Tab {
public List<Message> Messages = new();
~Tab() {
this.MessagesMutex.Dispose();
MessagesMutex.Dispose();
}
internal bool Matches(Message message) {
if (message.ExtraChatChannel != Guid.Empty) {
return this.ExtraChatAll || this.ExtraChatChannels.Contains(message.ExtraChatChannel);
return ExtraChatAll || ExtraChatChannels.Contains(message.ExtraChatChannel);
}
return message.Code.Type.IsGm()
|| this.ChatCodes.TryGetValue(message.Code.Type, out var sources) && (message.Code.Source is 0 or (ChatSource) 1 || sources.HasFlag(message.Code.Source));
|| ChatCodes.TryGetValue(message.Code.Type, out var sources) && (message.Code.Source is 0 or (ChatSource) 1 || sources.HasFlag(message.Code.Source));
}
internal void AddMessage(Message message, bool unread = true) {
this.MessagesMutex.Wait();
this.Messages.Add(message);
while (this.Messages.Count > Store.MessagesLimit) {
this.Messages.RemoveAt(0);
MessagesMutex.Wait();
Messages.Add(message);
while (Messages.Count > Store.MessagesLimit) {
Messages.RemoveAt(0);
}
this.MessagesMutex.Release();
MessagesMutex.Release();
if (unread) {
this.Unread += 1;
Unread += 1;
}
}
internal void Clear() {
this.MessagesMutex.Wait();
this.Messages.Clear();
this.MessagesMutex.Release();
MessagesMutex.Wait();
Messages.Clear();
MessagesMutex.Release();
}
internal Tab Clone() {
return new Tab {
Name = this.Name,
ChatCodes = this.ChatCodes.ToDictionary(entry => entry.Key, entry => entry.Value),
ExtraChatAll = this.ExtraChatAll,
ExtraChatChannels = this.ExtraChatChannels.ToHashSet(),
Name = Name,
ChatCodes = ChatCodes.ToDictionary(entry => entry.Key, entry => entry.Value),
ExtraChatAll = ExtraChatAll,
ExtraChatChannels = ExtraChatChannels.ToHashSet(),
#pragma warning disable CS0618
DisplayUnread = this.DisplayUnread,
DisplayUnread = DisplayUnread,
#pragma warning restore CS0618
UnreadMode = this.UnreadMode,
DisplayTimestamp = this.DisplayTimestamp,
Channel = this.Channel,
PopOut = this.PopOut,
IndependentOpacity = this.IndependentOpacity,
Opacity = this.Opacity,
UnreadMode = UnreadMode,
DisplayTimestamp = DisplayTimestamp,
Channel = Channel,
PopOut = PopOut,
IndependentOpacity = IndependentOpacity,
Opacity = Opacity,
};
}
}
+1 -1
View File
@@ -250,7 +250,7 @@ public sealed class PayloadHandler {
var x = isLeft ? window.X : LogWindow.LastWindowPos.X - atkSize.X;
var y = Math.Clamp(window.Y - atkSize.Y, 0, float.MaxValue);
y -= isTop ? 0 : 10; // small offset to prevent cut-off on the bottom
y -= isTop ? 0 : LogWindow.Plugin.Config.TooltipOffset; // offset to prevent cut-off on the bottom
atk->SetPosition((short) x, (short) y);
}
+18
View File
@@ -2165,6 +2165,24 @@ namespace ChatTwo.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Use this option if you experience cut-off tooltips..
/// </summary>
internal static string Options_TooltipOffset_Desc {
get {
return ResourceManager.GetString("Options_TooltipOffset_Desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Tooltip offset .
/// </summary>
internal static string Options_TooltipOffset_Name {
get {
return ResourceManager.GetString("Options_TooltipOffset_Name", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Window opacity.
/// </summary>
+6
View File
@@ -865,4 +865,10 @@
<data name="Context_AdventurerPlateError" xml:space="preserve">
<value>Unable to open adventurer plate at this moment</value>
</data>
<data name="Options_TooltipOffset_Name" xml:space="preserve">
<value>Tooltip offset </value>
</data>
<data name="Options_TooltipOffset_Desc" xml:space="preserve">
<value>Use this option if you experience cut-off tooltips.</value>
</data>
</root>
+21 -18
View File
@@ -10,80 +10,83 @@ internal sealed class Display : ISettingsTab {
public string Name => Language.Options_Display_Tab + "###tabs-display";
internal Display(Configuration mutable) {
this.Mutable = mutable;
Mutable = mutable;
}
public void Draw(bool changed) {
ImGui.PushTextWrapPos();
ImGuiUtil.OptionCheckbox(ref this.Mutable.HideChat, Language.Options_HideChat_Name, Language.Options_HideChat_Description);
ImGuiUtil.OptionCheckbox(ref Mutable.HideChat, Language.Options_HideChat_Name, Language.Options_HideChat_Description);
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(
ref this.Mutable.HideDuringCutscenes,
ref Mutable.HideDuringCutscenes,
Language.Options_HideDuringCutscenes_Name,
string.Format(Language.Options_HideDuringCutscenes_Description, Plugin.PluginName)
);
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(
ref this.Mutable.HideWhenNotLoggedIn,
ref Mutable.HideWhenNotLoggedIn,
Language.Options_HideWhenNotLoggedIn_Name,
string.Format(Language.Options_HideWhenNotLoggedIn_Description, Plugin.PluginName)
);
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(
ref this.Mutable.HideWhenUiHidden,
ref Mutable.HideWhenUiHidden,
Language.Options_HideWhenUiHidden_Name,
string.Format(Language.Options_HideWhenUiHidden_Description, Plugin.PluginName)
);
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(
ref this.Mutable.NativeItemTooltips,
ref Mutable.NativeItemTooltips,
Language.Options_NativeItemTooltips_Name,
string.Format(Language.Options_NativeItemTooltips_Description, Plugin.PluginName)
);
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(
ref this.Mutable.SidebarTabView,
ref Mutable.SidebarTabView,
Language.Options_SidebarTabView_Name,
string.Format(Language.Options_SidebarTabView_Description, Plugin.PluginName)
);
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(ref this.Mutable.PrettierTimestamps, Language.Options_PrettierTimestamps_Name, Language.Options_PrettierTimestamps_Description);
ImGuiUtil.OptionCheckbox(ref Mutable.PrettierTimestamps, Language.Options_PrettierTimestamps_Name, Language.Options_PrettierTimestamps_Description);
if (this.Mutable.PrettierTimestamps) {
if (Mutable.PrettierTimestamps) {
ImGui.TreePush();
ImGuiUtil.OptionCheckbox(ref this.Mutable.MoreCompactPretty, Language.Options_MoreCompactPretty_Name, Language.Options_MoreCompactPretty_Description);
ImGuiUtil.OptionCheckbox(ref this.Mutable.HideSameTimestamps, Language.Options_HideSameTimestamps_Name, Language.Options_HideSameTimestamps_Description);
ImGuiUtil.OptionCheckbox(ref Mutable.MoreCompactPretty, Language.Options_MoreCompactPretty_Name, Language.Options_MoreCompactPretty_Description);
ImGuiUtil.OptionCheckbox(ref Mutable.HideSameTimestamps, Language.Options_HideSameTimestamps_Name, Language.Options_HideSameTimestamps_Description);
ImGui.TreePop();
}
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(ref this.Mutable.CollapseDuplicateMessages, Language.Options_CollapseDuplicateMessages_Name, Language.Options_CollapseDuplicateMessages_Description);
ImGuiUtil.OptionCheckbox(ref Mutable.CollapseDuplicateMessages, Language.Options_CollapseDuplicateMessages_Name, Language.Options_CollapseDuplicateMessages_Description);
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(ref this.Mutable.ShowNoviceNetwork, Language.Options_ShowNoviceNetwork_Name, Language.Options_ShowNoviceNetwork_Description);
ImGuiUtil.OptionCheckbox(ref Mutable.ShowNoviceNetwork, Language.Options_ShowNoviceNetwork_Name, Language.Options_ShowNoviceNetwork_Description);
ImGui.Spacing();
ImGuiUtil.DragFloatVertical(Language.Options_WindowOpacity_Name, ref this.Mutable.WindowAlpha, .25f, 0f, 100f, $"{this.Mutable.WindowAlpha:N2}%%", ImGuiSliderFlags.AlwaysClamp);
ImGuiUtil.DragFloatVertical(Language.Options_TooltipOffset_Name, Language.Options_TooltipOffset_Desc, ref Mutable.TooltipOffset, 1, 0f, 400f, $"{Mutable.TooltipOffset:N0}px", ImGuiSliderFlags.AlwaysClamp);
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(ref this.Mutable.CanMove, Language.Options_CanMove_Name);
ImGuiUtil.DragFloatVertical(Language.Options_WindowOpacity_Name, ref Mutable.WindowAlpha, .25f, 0f, 100f, $"{Mutable.WindowAlpha:N2}%%", ImGuiSliderFlags.AlwaysClamp);
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(ref this.Mutable.CanResize, Language.Options_CanResize_Name);
ImGuiUtil.OptionCheckbox(ref Mutable.CanMove, Language.Options_CanMove_Name);
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(ref this.Mutable.ShowTitleBar, Language.Options_ShowTitleBar_Name);
ImGuiUtil.OptionCheckbox(ref Mutable.CanResize, Language.Options_CanResize_Name);
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(ref this.Mutable.ShowPopOutTitleBar, Language.Options_ShowPopOutTitleBar_Name);
ImGuiUtil.OptionCheckbox(ref Mutable.ShowTitleBar, Language.Options_ShowTitleBar_Name);
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(ref Mutable.ShowPopOutTitleBar, Language.Options_ShowPopOutTitleBar_Name);
ImGui.Spacing();
ImGui.PopTextWrapPos();
+9
View File
@@ -225,6 +225,15 @@ internal static class ImGuiUtil {
return ImGui.DragFloat($"##{label}", ref value, vSpeed, vMin, vMax, format, flags);
}
internal static bool DragFloatVertical(string label, string description, ref float value, float vSpeed = 1.0f, float vMin = float.MinValue, float vMax = float.MaxValue, string? format = null, ImGuiSliderFlags flags = ImGuiSliderFlags.None) {
ImGui.TextUnformatted(label);
ImGui.SetNextItemWidth(-1);
var r = ImGui.DragFloat($"##{label}", ref value, vSpeed, vMin, vMax, format, flags);
HelpText(description);
return r;
}
internal static bool TryToImGui(this VirtualKey key, out ImGuiKey result) {
result = key switch {
VirtualKey.NO_KEY => ImGuiKey.None,