Skip to content

Commit

Permalink
changes to the config window
Browse files Browse the repository at this point in the history
  • Loading branch information
perappu committed Jul 28, 2023
1 parent a9e3f5c commit e562ad6
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 36 deletions.
2 changes: 1 addition & 1 deletion WhoSaidWhatNow/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public class Configuration : IPluginConfiguration
{ XivChatType.CrossLinkShell8, true}
};

//TODO: Custom chat color values, ideally using ingame colors
//Default chat color values
public IDictionary<XivChatType, Vector4> ChatColors = new Dictionary<XivChatType, Vector4>()
{
Expand Down Expand Up @@ -128,6 +127,7 @@ public class Configuration : IPluginConfiguration
{ XivChatType.CrossLinkShell8, new Tuple < string, string >("[CWLS8]<","> {0}")}
};

//Formats for log export
public readonly IDictionary<XivChatType, string> Formats = new Dictionary<XivChatType, string>()
{
{ XivChatType.Say, "{0}: {1}" },
Expand Down
28 changes: 11 additions & 17 deletions WhoSaidWhatNow/Objects/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,9 @@ public class Player
public string Server { get; init; }
public bool RemoveDisabled { get; set; }
public DateTime TimeAdded { get; set; }

public Vector4 NameColor { get; set; }

private void SetNameColor(string name)
{
int nameHash = name.GetHashCode();
float val1 = (float)(((nameHash >> (nameHash.ToString()[1] * 8)) & 0xFF) / 255.0) + 0.4f;
float val2 = (float)(((nameHash >> (nameHash.ToString()[2] * 8)) & 0xFF) / 255.0) + 0.4f;
float val3 = (float)(((nameHash >> (nameHash.ToString()[3] * 8)) & 0xFF) / 255.0) + 0.4f;

//Random rand = new Random(nameHash);
//float val1 = (float)rand.NextDouble() + 0.2f;
//float val2 = (float)rand.NextDouble() + 0.2f;
//float val3 = (float)rand.NextDouble() + 0.2f;

Vector4 newColor = new Vector4(val1, val2, val3, 1f);
NameColor = newColor;
}

// constructors
public Player(uint id, string name, string server, bool removeDisabled = false)
{
ID = id;
Expand Down Expand Up @@ -98,6 +82,16 @@ public Player(PlayerCharacter playerCharacter, bool removeDisabled = false)
SetNameColor(Name);
}

//setters and getters i guess
private void SetNameColor(string name)
{
Vector4 nameColor = ConfigurationUtils.GenerateRgba((uint)name.GetHashCode());
nameColor.X += 0.2f;
nameColor.Y += 0.2f;
nameColor.Z += 0.2f;
NameColor = nameColor;
}

public string GetNameTag()
{
return Name + "" + Server;
Expand Down
6 changes: 3 additions & 3 deletions WhoSaidWhatNow/Utils/ConfigurationUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void reset()
PlayerUtils.CheckTrackedPlayers();
}

public static void GetConfigColors()
public static void SetConfigColors()
{
foreach (KeyValuePair<XivChatType,Vector4> chatColor in Plugin.Config.ChatColors)
{
Expand All @@ -39,13 +39,13 @@ public static void GetConfigColors()
}
}

private static Vector4 GenerateRgba(uint color)
public static Vector4 GenerateRgba(uint color)
{
Color c = Color.FromArgb(0xFF, Color.FromArgb((int)color));
return new Vector4(c.R / 255f, c.G / 255f, c.B / 255f, 1f);
}

private static UiConfigOption ChatTypeToConfigColor(XivChatType chatType)
public static UiConfigOption ChatTypeToConfigColor(XivChatType chatType)
{
switch (chatType)
{
Expand Down
52 changes: 37 additions & 15 deletions WhoSaidWhatNow/Windows/ConfigWindow.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.DrunkenToad;
using Dalamud.Interface.Windowing;
using ImGuiNET;
using Lumina.Excel.GeneratedSheets;
using System;
using System.Collections.Generic;
using System.Numerics;
Expand Down Expand Up @@ -29,33 +30,39 @@ public void Dispose() { }

public override void Draw()
{
// can't ref a property, so use a local copy for config variables

// design philosophy for us right now is we save automatically
// if we have more options we may change later, but honestly I think some larger plugins also do this so we're fine

ImGui.BeginTabBar("###WhoSaidWhatNowConfig_Tab_Bar");

//GENERAL SETTINGS TAB
if (ImGui.BeginTabItem("General"))
{
// replace the existing panels by using the same IDs.
ImGui.BeginChild(ConfigWindow.ID_PANEL_LEFT, new Vector2(0,0), true);
ImGui.BeginChild(ConfigWindow.ID_PANEL_LEFT, new Vector2(0, 0), true);

//plugin on/off
bool enabled = Plugin.Config.Enabled;
if (ImGui.Checkbox("Plugin On/Off", ref enabled))
{
Plugin.Config.Enabled = enabled;
Plugin.Config.Save();
}

//plugin autoscroll
bool autoscroll = Plugin.Config.AutoscrollOnOpen;
if (ImGui.Checkbox("Autoscroll to bottom when opening log (may or may not be functional)", ref autoscroll))
{
Plugin.Config.AutoscrollOnOpen = autoscroll;
Plugin.Config.Save();
}
ImGui.Separator();

//plugin set config colors
ImGui.TextWrapped("This button will match WhoWhat's colors to Character Configuration > Log Window Settings.");
if (ImGui.Button("Set Colors to Character Log Text Colors")) {
ConfigurationUtils.GetConfigColors();
if (ImGui.Button("Set Colors to Character Log Text Colors"))
{
ConfigurationUtils.SetConfigColors();
Plugin.Config.Save();
}

Expand All @@ -64,7 +71,8 @@ public override void Draw()

}

if (ImGui.BeginTabItem("Always Tracked Players"))
// ALWAYS TRACKED TAB
if (ImGui.BeginTabItem("Favorite Players"))
{
ImGui.BeginChild(ConfigWindow.ID_PANEL_LEFT, new Vector2(0, 0), true);

Expand All @@ -84,17 +92,25 @@ public override void Draw()

List<Tuple<string, string>> templist = new List<Tuple<string, string>>(Plugin.Config.AlwaysTrackedPlayers);
//build table of existing data
foreach (var player in templist)
foreach (var playerName in templist)
{
var player = Plugin.Players.Find(x => x.Name == playerName.Item1);
if(player != null) {
ImGui.PushStyleColor(ImGuiCol.Text, player.NameColor);
}
ImGui.TableNextColumn();
ImGui.TableNextColumn();
ImGui.Text(player.Item1);
ImGui.Text(playerName.Item1);
ImGui.TableNextColumn();
ImGui.Text(player.Item2);
ImGui.Text(playerName.Item2);
ImGui.TableNextColumn();
if (ImGui.Button("Remove##" + player.Item1))
if (player != null)
{
PlayerUtils.RemoveTrackedPlayer(player);
ImGui.PopStyleColor();
}
if (ImGui.Button("Remove##" + playerName.Item1))
{
PlayerUtils.RemoveTrackedPlayer(playerName);
PlayerUtils.CheckTrackedPlayers();
}
ImGui.TableNextColumn();
Expand All @@ -115,7 +131,7 @@ public override void Draw()
{
if (newName.IsValidCharacterName() && !newServer.Equals(""))
{
PlayerUtils.AddTrackedPlayer(new Tuple<string,string>(newName, worldNames[newServer]));
PlayerUtils.AddTrackedPlayer(new Tuple<string, string>(newName, worldNames[newServer]));
newName = string.Empty;
newServer = 0;
}
Expand All @@ -126,21 +142,27 @@ public override void Draw()
ImGui.EndTabItem();
}

//ENABLED CHANNELS TAB
if (ImGui.BeginTabItem("Channels"))
{
ImGui.BeginChild(ConfigWindow.ID_PANEL_LEFT, new Vector2(0, 0), true);

foreach (var chan in Plugin.Config.ChannelToggles)
//generate checkbox for each chat channel
foreach (var chan in Plugin.Config.ChannelToggles)
{
bool val = chan.Value;
ImGui.PushStyleColor(ImGuiCol.Text, Plugin.Config.ChatColors[chan.Key]);
if (ImGui.Checkbox(chan.Key.ToString(), ref val))
{

Plugin.Config.ChannelToggles[chan.Key] = val;

Plugin.Config.Save();

}
ImGui.PopStyleColor();
}



ImGui.EndChild();
ImGui.EndTabItem();
}
Expand Down
17 changes: 17 additions & 0 deletions WhoSaidWhatNow/Windows/TabIndividual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ public TabIndividual(MainWindow mainWindow, Plugin plugin)
{
ImGui.SetTooltip("Save log to .txt file");
}

//push font to make our menus with FA icons

ImGui.BeginGroup();
ImGui.BeginDisabled(Plugin.SelectedPlayer == null || Plugin.SelectedPlayer.RemoveDisabled);
ImGui.PushFont(UiBuilder.IconFont);
if (ImGui.MenuItem(FontAwesomeIcon.UserCheck.ToIconString()))
{
PlayerUtils.AddTrackedPlayer(new Tuple<string,string>(Plugin.SelectedPlayer.Name, Plugin.SelectedPlayer.Server));
}
ImGui.PopFont();
ImGui.EndDisabled();
ImGui.EndGroup();
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip("Add player to favorites");
}
ImGui.EndMenuBar();
}
ImGui.EndChild();
Expand Down

0 comments on commit e562ad6

Please sign in to comment.