switch to SetTooltip

This commit is contained in:
Infi
2024-04-11 15:55:54 +02:00
parent 4c8bde1f9f
commit db73c59d40
+32 -45
View File
@@ -5,44 +5,45 @@ using ImGuiNET;
namespace ChatTwo.Ui.SettingsTabs; namespace ChatTwo.Ui.SettingsTabs;
internal sealed class Database : ISettingsTab { internal sealed class Database : ISettingsTab
{
private Configuration Mutable { get; } private Configuration Mutable { get; }
private Plugin Plugin { get; } private Plugin Plugin { get; }
public string Name => Language.Options_Database_Tab + "###tabs-database"; public string Name => Language.Options_Database_Tab + "###tabs-database";
internal Database(Configuration mutable, Plugin plugin) { internal Database(Configuration mutable, Plugin plugin)
{
Plugin = plugin; Plugin = plugin;
Mutable = mutable; Mutable = mutable;
} }
private bool _showAdvanced; private bool ShowAdvanced;
private long _databaseLastRefreshTicks; private long DatabaseLastRefreshTicks;
private long _databaseSize; private long DatabaseSize;
private long _databaseLogSize; private long DatabaseLogSize;
private int _databaseMessageCount; private int DatabaseMessageCount;
public void Draw(bool changed) { public void Draw(bool changed) {
if (changed) { if (changed)
_showAdvanced = ImGui.GetIO().KeyShift; ShowAdvanced = ImGui.GetIO().KeyShift;
}
ImGuiUtil.OptionCheckbox(ref Mutable.DatabaseBattleMessages, Language.Options_DatabaseBattleMessages_Name, Language.Options_DatabaseBattleMessages_Description); ImGuiUtil.OptionCheckbox(ref Mutable.DatabaseBattleMessages, Language.Options_DatabaseBattleMessages_Name, Language.Options_DatabaseBattleMessages_Description);
ImGui.Spacing(); ImGui.Spacing();
if (ImGuiUtil.OptionCheckbox(ref Mutable.LoadPreviousSession, Language.Options_LoadPreviousSession_Name, Language.Options_LoadPreviousSession_Description)) { if (ImGuiUtil.OptionCheckbox(ref Mutable.LoadPreviousSession, Language.Options_LoadPreviousSession_Name, Language.Options_LoadPreviousSession_Description))
if (Mutable.LoadPreviousSession) { {
if (Mutable.LoadPreviousSession)
Mutable.FilterIncludePreviousSessions = true; Mutable.FilterIncludePreviousSessions = true;
}
} }
ImGui.Spacing(); ImGui.Spacing();
if (ImGuiUtil.OptionCheckbox(ref Mutable.FilterIncludePreviousSessions, Language.Options_FilterIncludePreviousSessions_Name, Language.Options_FilterIncludePreviousSessions_Description)) { if (ImGuiUtil.OptionCheckbox(ref Mutable.FilterIncludePreviousSessions, Language.Options_FilterIncludePreviousSessions_Name, Language.Options_FilterIncludePreviousSessions_Description))
if (!Mutable.FilterIncludePreviousSessions) { {
if (!Mutable.FilterIncludePreviousSessions)
Mutable.LoadPreviousSession = false; Mutable.LoadPreviousSession = false;
}
} }
ImGuiUtil.OptionCheckbox( ImGuiUtil.OptionCheckbox(
@@ -62,12 +63,12 @@ internal sealed class Database : ISettingsTab {
// Refresh the database size and message count every 5 seconds to avoid // Refresh the database size and message count every 5 seconds to avoid
// constant stat calls and spamming the database. // constant stat calls and spamming the database.
if (_databaseLastRefreshTicks + 5 * 1000 < Environment.TickCount64) if (DatabaseLastRefreshTicks + 5 * 1000 < Environment.TickCount64)
{ {
_databaseSize = Store.DatabaseSize(); DatabaseSize = Store.DatabaseSize();
_databaseLogSize = Store.DatabaseLogSize(); DatabaseLogSize = Store.DatabaseLogSize();
_databaseMessageCount = Plugin.Store.MessageCount(); DatabaseMessageCount = Plugin.Store.MessageCount();
_databaseLastRefreshTicks = Environment.TickCount64; DatabaseLastRefreshTicks = Environment.TickCount64;
} }
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Path, Store.DatabasePath())); ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Path, Store.DatabasePath()));
@@ -79,62 +80,48 @@ internal sealed class Database : ISettingsTab {
ImGui.SetClipboardText(path); ImGui.SetClipboardText(path);
WrapperUtil.AddNotification(Language.Options_Database_Metadata_CopyConfigPathNotification, NotificationType.Info); WrapperUtil.AddNotification(Language.Options_Database_Metadata_CopyConfigPathNotification, NotificationType.Info);
} }
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
{ {
ImGui.SetMouseCursor(ImGuiMouseCursor.Hand); ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
ImGui.BeginTooltip(); ImGui.SetTooltip(Language.Options_Database_Metadata_CopyConfigPath);
ImGui.Text(Language.Options_Database_Metadata_CopyConfigPath);
ImGui.EndTooltip();
} }
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Size, StringUtil.BytesToString(_databaseSize))); ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Size, StringUtil.BytesToString(DatabaseSize)));
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
{ ImGui.SetTooltip(DatabaseSize.ToString("N0") + "B");
ImGui.BeginTooltip();
ImGui.Text(_databaseSize.ToString("N0") + "B");
ImGui.EndTooltip();
}
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_LogSize, StringUtil.BytesToString(_databaseLogSize))); ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_LogSize, StringUtil.BytesToString(DatabaseLogSize)));
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
{ ImGui.SetTooltip(DatabaseLogSize.ToString("N0") + "B");
ImGui.BeginTooltip();
ImGui.Text(_databaseLogSize.ToString("N0") + "B");
ImGui.EndTooltip();
}
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_MessageCount, _databaseMessageCount, Store.MessagesLimit)); ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_MessageCount, DatabaseMessageCount, Store.MessagesLimit));
if (ImGuiUtil.CtrlShiftButton(Language.Options_ClearDatabase_Button, Language.Options_ClearDatabase_Tooltip)) if (ImGuiUtil.CtrlShiftButton(Language.Options_ClearDatabase_Button, Language.Options_ClearDatabase_Tooltip))
{ {
Plugin.Log.Warning("Clearing database"); Plugin.Log.Warning("Clearing database");
Plugin.Store.ClearDatabase(); Plugin.Store.ClearDatabase();
foreach (var tab in Plugin.Config.Tabs) foreach (var tab in Plugin.Config.Tabs)
{
tab.Clear(); tab.Clear();
}
// Refresh on next draw // Refresh on next draw
_databaseLastRefreshTicks = 0; DatabaseLastRefreshTicks = 0;
WrapperUtil.AddNotification(Language.Options_ClearDatabase_Success, NotificationType.Info); WrapperUtil.AddNotification(Language.Options_ClearDatabase_Success, NotificationType.Info);
} }
ImGui.Unindent(style.IndentSpacing); ImGui.Unindent(style.IndentSpacing);
ImGui.Spacing(); ImGui.Spacing();
if (_showAdvanced && ImGui.TreeNodeEx(Language.Options_Database_Advanced)) if (ShowAdvanced && ImGui.TreeNodeEx(Language.Options_Database_Advanced))
{ {
ImGui.PushTextWrapPos(); ImGui.PushTextWrapPos();
ImGuiUtil.WarningText(Language.Options_Database_Advanced_Warning); ImGuiUtil.WarningText(Language.Options_Database_Advanced_Warning);
if (ImGuiUtil.CtrlShiftButton("Checkpoint", "Ctrl+Shift: Database.Checkpoint()")) if (ImGuiUtil.CtrlShiftButton("Checkpoint", "Ctrl+Shift: Database.Checkpoint()"))
{
Plugin.Store.Database.Checkpoint(); Plugin.Store.Database.Checkpoint();
}
if (ImGuiUtil.CtrlShiftButton("Rebuild", "Ctrl+Shift: Database.Rebuild()")) if (ImGuiUtil.CtrlShiftButton("Rebuild", "Ctrl+Shift: Database.Rebuild()"))
{
Plugin.Store.Database.Rebuild(); Plugin.Store.Database.Rebuild();
}
ImGui.PopTextWrapPos(); ImGui.PopTextWrapPos();
ImGui.TreePop(); ImGui.TreePop();