feat: add settings window, add way to change general chat type

This commit is contained in:
goat 2020-05-22 14:04:55 +02:00
parent aa58d9258b
commit 5843dc8775
4 changed files with 107 additions and 1 deletions

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using Dalamud.Configuration;
using Dalamud.DiscordBot;
using Dalamud.Game.Chat;
using Newtonsoft.Json;
namespace Dalamud
@ -31,6 +32,8 @@ namespace Dalamud
public string LastVersion { get; set; }
public XivChatType GeneralChatType { get; set; } = XivChatType.Debug;
[JsonIgnore]
public string ConfigPath;

View file

@ -202,10 +202,12 @@ namespace Dalamud {
private bool isImguiDrawDataWindow = false;
private bool isImguiDrawPluginWindow = false;
private bool isImguiDrawCreditsWindow = false;
private bool isImguiDrawSettingsWindow = false;
private DalamudLogWindow logWindow;
private DalamudDataWindow dataWindow;
private DalamudCreditsWindow creditsWindow;
private DalamudSettingsWindow settingsWindow;
private PluginInstallerWindow pluginWindow;
private void BuildDalamudUi()
@ -243,6 +245,10 @@ namespace Dalamud {
if (ImGui.MenuItem("Open Credits window")) {
OnOpenCreditsCommand(null, null);
}
if (ImGui.MenuItem("Open Settings window"))
{
OnOpenSettingsCommand(null, null);
}
ImGui.MenuItem("Draw ImGui demo", "", ref this.isImguiDrawDemoWindow);
if (ImGui.MenuItem("Dump ImGui info"))
OnDebugImInfoCommand(null, null);
@ -359,6 +365,11 @@ namespace Dalamud {
}
}
if (this.isImguiDrawSettingsWindow)
{
this.isImguiDrawSettingsWindow = this.settingsWindow != null && this.settingsWindow.Draw();
}
if (this.isImguiDrawDemoWindow)
ImGui.ShowDemoWindow();
}
@ -447,6 +458,12 @@ namespace Dalamud {
HelpMessage = Loc.Localize("DalamudLanguageHelp", "Set the language for the in-game addon and plugins that support it. Available languages: ") + Localization.ApplicableLangCodes.Aggregate("en", (current, code) => current + ", " + code)
});
this.CommandManager.AddHandler("/xlsettings", new CommandInfo(OnOpenSettingsCommand)
{
HelpMessage = Loc.Localize("DalamudSettingsHelp", "Change various In-Game-Addon settings like chat channels and the discord bot setup."),
ShowInHelp = false // Not quite ready yet
});
this.CommandManager.AddHandler("/imdebug", new CommandInfo(OnDebugImInfoCommand)
{
HelpMessage = "ImGui DEBUG",
@ -685,6 +702,12 @@ namespace Dalamud {
this.Configuration.Save();
}
private void OnOpenSettingsCommand(string command, string arguments)
{
this.settingsWindow = new DalamudSettingsWindow(this);
this.isImguiDrawSettingsWindow = true;
}
private int RouletteSlugToKey(string slug) => slug.ToLower() switch {
"leveling" => 1,
"506070" => 2,

View file

@ -201,7 +201,8 @@ namespace Dalamud.Game.Internal.Gui {
public void Print(string message) {
Log.Verbose("[CHATGUI PRINT]{0}", message);
PrintChat(new XivChatEntry {
MessageBytes = Encoding.UTF8.GetBytes(message)
MessageBytes = Encoding.UTF8.GetBytes(message),
Type = this.dalamud.Configuration.GeneralChatType
});
}

View file

@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Net.Mime;
using System.Numerics;
using CheapLoc;
using Dalamud.Game.Chat;
using Dalamud.Game.ClientState.Actors.Types;
using Dalamud.Game.ClientState.Actors.Types.NonPlayer;
using Dalamud.Plugin;
using ImGuiNET;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Serilog;
using SharpDX.Direct3D11;
namespace Dalamud.Interface
{
class DalamudSettingsWindow {
private readonly Dalamud dalamud;
public DalamudSettingsWindow(Dalamud dalamud) {
this.dalamud = dalamud;
this.chatTypes = Enum.GetValues(typeof(XivChatType)).Cast<XivChatType>().Select(x => x.ToString()).ToArray();
this.dalamudMessagesChatType = (int) this.dalamud.Configuration.GeneralChatType;
}
private string[] chatTypes;
private Vector4 hintTextColor = new Vector4(0.70f, 0.70f, 0.70f, 1.00f);
private int dalamudMessagesChatType;
public bool Draw() {
ImGui.SetNextWindowSize(new Vector2(500, 500), ImGuiCond.Always);
var isOpen = true;
if (!ImGui.Begin("XIVLauncher Settings", ref isOpen, ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize)) {
ImGui.End();
return false;
}
ImGui.BeginChild("scrolling", new Vector2(499, 430), false, ImGuiWindowFlags.HorizontalScrollbar);
if (ImGui.BeginTabBar("SetTabBar")) {
if (ImGui.BeginTabItem("General")) {
ImGui.Text("General Chat Channel");
ImGui.Combo("##XlChatTypeCombo", ref this.dalamudMessagesChatType, this.chatTypes,
this.chatTypes.Length);
ImGui.TextColored(this.hintTextColor, "Select the chat channel that is to be used for general XIVLauncher messages.");
}
}
ImGui.EndChild();
if (ImGui.Button("Save")) {
Save();
}
ImGui.SameLine();
if (ImGui.Button("Save and Close")) {
Save();
isOpen = false;
}
ImGui.End();
return isOpen;
}
private void Save() {
this.dalamud.Configuration.GeneralChatType = (XivChatType) this.dalamudMessagesChatType;
this.dalamud.Configuration.Save();
}
}
}