Configurable position for the preview
This commit is contained in:
@@ -25,6 +25,7 @@ internal class Configuration : IPluginConfiguration
|
|||||||
public bool HideSameTimestamps;
|
public bool HideSameTimestamps;
|
||||||
public bool ShowNoviceNetwork;
|
public bool ShowNoviceNetwork;
|
||||||
public bool SidebarTabView;
|
public bool SidebarTabView;
|
||||||
|
public PreviewPosition PreviewPosition = PreviewPosition.Inside;
|
||||||
public CommandHelpSide CommandHelpSide = CommandHelpSide.None;
|
public CommandHelpSide CommandHelpSide = CommandHelpSide.None;
|
||||||
public KeybindMode KeybindMode = KeybindMode.Strict;
|
public KeybindMode KeybindMode = KeybindMode.Strict;
|
||||||
public LanguageOverride LanguageOverride = LanguageOverride.None;
|
public LanguageOverride LanguageOverride = LanguageOverride.None;
|
||||||
@@ -78,6 +79,7 @@ internal class Configuration : IPluginConfiguration
|
|||||||
HideSameTimestamps = other.HideSameTimestamps;
|
HideSameTimestamps = other.HideSameTimestamps;
|
||||||
ShowNoviceNetwork = other.ShowNoviceNetwork;
|
ShowNoviceNetwork = other.ShowNoviceNetwork;
|
||||||
SidebarTabView = other.SidebarTabView;
|
SidebarTabView = other.SidebarTabView;
|
||||||
|
PreviewPosition = other.PreviewPosition;
|
||||||
CommandHelpSide = other.CommandHelpSide;
|
CommandHelpSide = other.CommandHelpSide;
|
||||||
KeybindMode = other.KeybindMode;
|
KeybindMode = other.KeybindMode;
|
||||||
LanguageOverride = other.LanguageOverride;
|
LanguageOverride = other.LanguageOverride;
|
||||||
@@ -238,6 +240,27 @@ internal class Tab
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
internal enum PreviewPosition
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Inside,
|
||||||
|
Top,
|
||||||
|
Bottom,
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static class PreviewPositionExt
|
||||||
|
{
|
||||||
|
internal static string Name(this PreviewPosition position) => position switch
|
||||||
|
{
|
||||||
|
PreviewPosition.None => Language.Options_Preview_None,
|
||||||
|
PreviewPosition.Inside => Language.Options_Preview_Inside,
|
||||||
|
PreviewPosition.Top => Language.Options_Preview_Top,
|
||||||
|
PreviewPosition.Bottom => Language.Options_Preview_Bottom,
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(position), position, null),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
internal enum CommandHelpSide
|
internal enum CommandHelpSide
|
||||||
{
|
{
|
||||||
|
|||||||
Generated
+63
@@ -2390,6 +2390,69 @@ namespace ChatTwo.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Bottom.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Options_Preview_Bottom {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Options_Preview_Bottom", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to A preview wih all emote, auto-translate encoded as they appear in chat.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Options_Preview_Description {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Options_Preview_Description", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Text Preview:.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Options_Preview_Header {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Options_Preview_Header", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Inside.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Options_Preview_Inside {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Options_Preview_Inside", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Input preview.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Options_Preview_Name {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Options_Preview_Name", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to None.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Options_Preview_None {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Options_Preview_None", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Top.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Options_Preview_Top {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Options_Preview_Top", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Replaces words with their emote version, currently supports BetterTTV.
|
/// Looks up a localized string similar to Replaces words with their emote version, currently supports BetterTTV.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1051,4 +1051,25 @@
|
|||||||
<data name="Options_Emote_Loaded" xml:space="preserve">
|
<data name="Options_Emote_Loaded" xml:space="preserve">
|
||||||
<value>Emotes available:</value>
|
<value>Emotes available:</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Options_Preview_Description" xml:space="preserve">
|
||||||
|
<value>A preview wih all emote, auto-translate encoded as they appear in chat</value>
|
||||||
|
</data>
|
||||||
|
<data name="Options_Preview_Name" xml:space="preserve">
|
||||||
|
<value>Input preview</value>
|
||||||
|
</data>
|
||||||
|
<data name="Options_Preview_None" xml:space="preserve">
|
||||||
|
<value>None</value>
|
||||||
|
</data>
|
||||||
|
<data name="Options_Preview_Inside" xml:space="preserve">
|
||||||
|
<value>Inside</value>
|
||||||
|
</data>
|
||||||
|
<data name="Options_Preview_Top" xml:space="preserve">
|
||||||
|
<value>Top</value>
|
||||||
|
</data>
|
||||||
|
<data name="Options_Preview_Bottom" xml:space="preserve">
|
||||||
|
<value>Bottom</value>
|
||||||
|
</data>
|
||||||
|
<data name="Options_Preview_Header" xml:space="preserve">
|
||||||
|
<value>Text Preview:</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|||||||
@@ -521,7 +521,7 @@ public sealed class ChatLogWindow : Window
|
|||||||
// TODO: I hate this predraw thing
|
// TODO: I hate this predraw thing
|
||||||
PreviewHeight = 0;
|
PreviewHeight = 0;
|
||||||
Message? predrawnMessage = null;
|
Message? predrawnMessage = null;
|
||||||
if (!string.IsNullOrEmpty(Chat))
|
if (Plugin.Config.PreviewPosition is PreviewPosition.Inside && !string.IsNullOrEmpty(Chat))
|
||||||
{
|
{
|
||||||
var bytes = Encoding.UTF8.GetBytes(Chat.Trim());
|
var bytes = Encoding.UTF8.GetBytes(Chat.Trim());
|
||||||
AutoTranslate.ReplaceWithPayload(Plugin.DataManager, ref bytes);
|
AutoTranslate.ReplaceWithPayload(Plugin.DataManager, ref bytes);
|
||||||
@@ -534,7 +534,7 @@ public sealed class ChatLogWindow : Window
|
|||||||
var before = ImGui.GetCursorPosY();
|
var before = ImGui.GetCursorPosY();
|
||||||
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
|
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
|
||||||
{
|
{
|
||||||
ImGui.TextUnformatted("Text Preview:");
|
ImGui.TextUnformatted(Language.Options_Preview_Header);
|
||||||
DrawChunks(predrawnMessage.Content);
|
DrawChunks(predrawnMessage.Content);
|
||||||
}
|
}
|
||||||
var after = ImGui.GetCursorPosY();
|
var after = ImGui.GetCursorPosY();
|
||||||
|
|||||||
+11
-13
@@ -1,4 +1,3 @@
|
|||||||
using System.Numerics;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using ChatTwo.Code;
|
using ChatTwo.Code;
|
||||||
using ChatTwo.Util;
|
using ChatTwo.Util;
|
||||||
@@ -14,7 +13,6 @@ public class InputPreview : Window
|
|||||||
private ChatLogWindow LogWindow { get; }
|
private ChatLogWindow LogWindow { get; }
|
||||||
|
|
||||||
private float Height;
|
private float Height;
|
||||||
private float AppliedHeight;
|
|
||||||
|
|
||||||
internal InputPreview(ChatLogWindow logWindow) : base("##chat2-inputpreview")
|
internal InputPreview(ChatLogWindow logWindow) : base("##chat2-inputpreview")
|
||||||
{
|
{
|
||||||
@@ -31,25 +29,25 @@ public class InputPreview : Window
|
|||||||
|
|
||||||
public override void PreDraw()
|
public override void PreDraw()
|
||||||
{
|
{
|
||||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
|
||||||
// Sizes don't use much precision
|
|
||||||
if (AppliedHeight == Height)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AppliedHeight = Height;
|
|
||||||
|
|
||||||
var width = LogWindow.LastWindowSize.X;
|
|
||||||
var pos = LogWindow.LastWindowPos;
|
var pos = LogWindow.LastWindowPos;
|
||||||
|
var size = LogWindow.LastWindowSize;
|
||||||
|
|
||||||
Size = new Vector2(width, Height);
|
Size = size with { Y = Height };
|
||||||
|
|
||||||
Position = pos with { Y = pos.Y - Height };
|
var y = Plugin.Config.PreviewPosition switch
|
||||||
|
{
|
||||||
|
PreviewPosition.Top => pos.Y - Height,
|
||||||
|
PreviewPosition.Bottom => pos.Y + size.Y,
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(Plugin.Config.PreviewPosition), Plugin.Config.PreviewPosition, null)
|
||||||
|
};
|
||||||
|
|
||||||
|
Position = pos with { Y = y };
|
||||||
PositionCondition = ImGuiCond.Always;
|
PositionCondition = ImGuiCond.Always;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool DrawConditions()
|
public override bool DrawConditions()
|
||||||
{
|
{
|
||||||
return !string.IsNullOrEmpty(LogWindow.Chat);
|
return Plugin.Config.PreviewPosition is PreviewPosition.Top or PreviewPosition.Bottom && !string.IsNullOrEmpty(LogWindow.Chat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
|
|||||||
@@ -24,6 +24,19 @@ internal sealed class Miscellaneous(Configuration mutable) : ISettingsTab
|
|||||||
ImGuiUtil.HelpText(string.Format(Language.Options_Language_Description, Plugin.PluginName));
|
ImGuiUtil.HelpText(string.Format(Language.Options_Language_Description, Plugin.PluginName));
|
||||||
ImGui.Spacing();
|
ImGui.Spacing();
|
||||||
|
|
||||||
|
using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_Preview_Name, Mutable.PreviewPosition.Name()))
|
||||||
|
{
|
||||||
|
if (combo)
|
||||||
|
{
|
||||||
|
foreach (var position in Enum.GetValues<PreviewPosition>())
|
||||||
|
if (ImGui.Selectable(position.Name(), Mutable.PreviewPosition == position))
|
||||||
|
Mutable.PreviewPosition = position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGuiUtil.HelpText(Language.Options_Preview_Description);
|
||||||
|
ImGui.Spacing();
|
||||||
|
|
||||||
using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_CommandHelpSide_Name, Mutable.CommandHelpSide.Name()))
|
using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_CommandHelpSide_Name, Mutable.CommandHelpSide.Name()))
|
||||||
{
|
{
|
||||||
if (combo)
|
if (combo)
|
||||||
|
|||||||
Reference in New Issue
Block a user