Skip to content

Commit

Permalink
Many changes for v9
Browse files Browse the repository at this point in the history
  • Loading branch information
slotthhy committed Oct 2, 2023
1 parent e687538 commit 3d980c8
Show file tree
Hide file tree
Showing 20 changed files with 211 additions and 127 deletions.
2 changes: 1 addition & 1 deletion Orchestrion/Audio/BGMManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Orchestrion.BGMSystem;
using Orchestrion.Ipc;
using Orchestrion.Persistence;
using Orchestrion.Struct;
using Orchestrion.Types;

namespace Orchestrion.Audio;

Expand Down
2 changes: 1 addition & 1 deletion Orchestrion/Audio/PlaylistManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Dalamud.Logging;
using Dalamud.Plugin.Services;
using Orchestrion.Persistence;
using Orchestrion.Struct;
using Orchestrion.Types;

namespace Orchestrion.Audio;

Expand Down
16 changes: 0 additions & 16 deletions Orchestrion/Icons.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Orchestrion/Ipc/OrchestrionIpcManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Dalamud.Plugin.Ipc;
using Orchestrion.Audio;
using Orchestrion.Persistence;
using Orchestrion.Struct;
using Orchestrion.Types;

namespace Orchestrion.Ipc;

Expand Down
50 changes: 24 additions & 26 deletions Orchestrion/OrchestrionPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
using Dalamud.Interface.GameFonts;
using Dalamud.Interface.Utility;

Check failure on line 11 in Orchestrion/OrchestrionPlugin.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Utility' does not exist in the namespace 'Dalamud.Interface' (are you missing an assembly reference?)
using Dalamud.Interface.Windowing;
using Dalamud.IoC;
using Dalamud.Logging;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Component.GUI;
using ImGuiNET;
Expand Down Expand Up @@ -81,7 +79,7 @@ public OrchestrionPlugin(DalamudPluginInterface pi)
DalamudApi.PluginInterface.LanguageChanged += LanguageChanged;
}

private void LanguageChanged(string code)
public static void LanguageChanged(string code)
{
var stream =
Assembly.GetExecutingAssembly().GetManifestResourceStream($"Orchestrion.Loc.{code}.json")
Expand Down Expand Up @@ -112,6 +110,7 @@ private void OrchestrionUpdate(IFramework ignored)
{
PerformEcho();
CheckDtr();
UpdateSettings();
}

private void PerformEcho()
Expand All @@ -131,6 +130,23 @@ private void CheckDtr()
{
_dtrEntry.Shown = Configuration.Instance.ShowSongInNative;
}

private void UpdateSettings()
{
var dalamudChatType = DalamudApi.PluginInterface.GeneralChatType;
if (Configuration.Instance.ChatChannelMatchDalamud && Configuration.Instance.ChatType != dalamudChatType)
{
Configuration.Instance.ChatType = dalamudChatType;
Configuration.Instance.Save();
}

var dalamudLang = DalamudApi.PluginInterface.UiLanguage;
if (Configuration.Instance.UserInterfaceLanguageMatchDalamud && Configuration.Instance.UserInterfaceLanguageCode != dalamudLang)
{
Configuration.Instance.UserInterfaceLanguageCode = dalamudLang;
Configuration.Instance.Save();
}
}

private void ClientStateOnLogout()
{
Expand Down Expand Up @@ -377,15 +393,9 @@ private void UpdateDtr(int songId, bool playedByOrch = false)
{
if (_dtrEntry == null) return;
if (!SongList.Instance.TryGetSong(songId, out var song)) return;
var songName = Configuration.Instance.UseClientLangInServerInfo
? song.Strings[Util.ClientLangCode()].Name
: song.Name;
var locations = Configuration.Instance.UseClientLangInServerInfo
? song.Strings[Util.ClientLangCode()].Locations
: song.Locations;
var info = Configuration.Instance.UseClientLangInServerInfo
? song.Strings[Util.ClientLangCode()].AdditionalInfo
: song.AdditionalInfo;
var songName = song.Strings[Configuration.Instance.ServerInfoLanguageCode].Name;
var locations = song.Strings[Configuration.Instance.ServerInfoLanguageCode].Locations;
var info = song.Strings[Configuration.Instance.ServerInfoLanguageCode].AdditionalInfo;
if (string.IsNullOrEmpty(songName)) return;

var suffix = "";
Expand Down Expand Up @@ -417,26 +427,14 @@ private void UpdateDtr(int songId, bool playedByOrch = false)
private void UpdateChat(int songId, bool playedByOrch = false)
{
if (!Configuration.Instance.ShowSongInChat) return;

var songName = GetClientSongName(songId);
if (!SongList.Instance.TryGetSong(songId, out var song)) return;
var songName = song.Strings[Configuration.Instance.ChatLanguageCode].Name;

// the actual echoing is done during framework update
if (!string.IsNullOrEmpty(songName))
_songEchoMsg = BuildChatMessageFormatted(Loc.Localize("NowPlayingEcho", "Now playing <i>{0}</i>."), songName, playedByOrch);
}

private string GetClientSongName(int songId)
{
if (!SongList.Instance.TryGetSong(songId, out var song))
return null;

var songName = Configuration.Instance.UseClientLangInServerInfo
? song.Strings[Util.ClientLangCode()].Name
: song.Name;

return songName;
}

private unsafe bool IsLoadingScreen()
{
var titleCard = (AtkUnitBase*)DalamudApi.GameGui.GetAddonByName("_LocationTitle");
Expand Down
20 changes: 13 additions & 7 deletions Orchestrion/Persistence/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using Dalamud.Configuration;
using Dalamud.Game.Text;
using Newtonsoft.Json;
using Orchestrion.Struct;
using Orchestrion.Types;

namespace Orchestrion.Persistence;

Expand All @@ -21,9 +22,17 @@ public class Configuration : IPluginConfiguration
public bool ShowMiniPlayer { get; set; } = false;
public bool MiniPlayerLock { get; set; } = false;
public float MiniPlayerOpacity { get; set; } = 1.0f;

public bool ChatChannelMatchDalamud { get; set; } = true;
public bool ShowAltLangTitles { get; set; } = false;
public bool UseClientLangInServerInfo { get; set; } = true;
public bool UseClientLangInChat { get; set; } = true;
public bool UserInterfaceLanguageMatchDalamud { get; set; } = true;
public string UserInterfaceLanguageCode { get; set; } = DalamudApi.PluginInterface.UiLanguage;
public string AltTitleLanguageCode { get; set; } = "ja";
public string ServerInfoLanguageCode { get; set; } = "en";
public string ChatLanguageCode { get; set; } = "en";
public XivChatType ChatType { get; set; } = DalamudApi.PluginInterface.GeneralChatType;

public string LastSelectedPlaylist { get; set; } = "Favorites";

public Dictionary<int, SongReplacementEntry> SongReplacements { get; private set; } = new();

Expand All @@ -32,10 +41,7 @@ public class Configuration : IPluginConfiguration

public Dictionary<string, Playlist> Playlists { get; set; } = new();

private Configuration()
{

}
private Configuration() { }

[JsonIgnore]
private static Configuration _instance;
Expand Down
20 changes: 11 additions & 9 deletions Orchestrion/Persistence/SongList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
using System.IO;
using System.Linq;
using System.Net.Http;
using Dalamud.Logging;
using Lumina.Excel.GeneratedSheets;
using Orchestrion.Struct;
using Orchestrion.Types;

namespace Orchestrion.Persistence;

Expand All @@ -31,6 +30,7 @@ private SongList()
LoadLangSheet(GetRemoteSheet("ja"), "ja");
LoadLangSheet(GetRemoteSheet("de"), "de");
LoadLangSheet(GetRemoteSheet("fr"), "fr");
LoadLangSheet(GetRemoteSheet("zh"), "zh");
}
catch (Exception e)
{
Expand All @@ -40,9 +40,10 @@ private SongList()
LoadLangSheet(GetLocalSheet("ja"), "ja");
LoadLangSheet(GetLocalSheet("de"), "de");
LoadLangSheet(GetLocalSheet("fr"), "fr");
LoadLangSheet(GetLocalSheet("zh"), "zh");
}
}

private string GetRemoteSheet(string code)
{
return _client.GetStringAsync(string.Format(SheetPath, code)).Result;
Expand Down Expand Up @@ -156,13 +157,14 @@ public bool TryGetSongByName(string name, out int songId)
songId = 0;
foreach (var song in _songs.Values)
{
if (string.Equals(song.Strings["en"].Name, name, StringComparison.InvariantCultureIgnoreCase)
|| string.Equals(song.Strings["en"].AlternateName, name, StringComparison.InvariantCultureIgnoreCase)
|| string.Equals(song.Strings["ja"].Name, name, StringComparison.InvariantCultureIgnoreCase)
|| string.Equals(song.Strings["ja"].AlternateName, name, StringComparison.InvariantCultureIgnoreCase))
foreach (var lang in Util.AvailableTitleLanguages)
{
songId = song.Id;
return true;
if (string.Equals(song.Strings[lang].Name, name, StringComparison.InvariantCultureIgnoreCase)
|| string.Equals(song.Strings[lang].AlternateName, name, StringComparison.InvariantCultureIgnoreCase))
{
songId = song.Id;
return true;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Linq;

namespace Orchestrion.Struct;
namespace Orchestrion.Types;

public class IndexableSongList
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Orchestrion.Struct;
namespace Orchestrion.Types;

public struct RenderableSongEntry
{
Expand Down
2 changes: 1 addition & 1 deletion Orchestrion/Struct/Song.cs → Orchestrion/Types/Song.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace Orchestrion.Struct;
namespace Orchestrion.Types;

public struct SongStrings
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Orchestrion.Struct;
namespace Orchestrion.Types;

public struct SongReplacementEntry
{
Expand Down
8 changes: 4 additions & 4 deletions Orchestrion/UI/Components/BgmTooltip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Dalamud.Interface.Utility;

Check failure on line 4 in Orchestrion/UI/Components/BgmTooltip.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Utility' does not exist in the namespace 'Dalamud.Interface' (are you missing an assembly reference?)
using ImGuiNET;
using Orchestrion.Persistence;
using Orchestrion.Struct;
using Orchestrion.Types;

namespace Orchestrion.UI.Components;

Expand All @@ -30,7 +30,7 @@ public static void DrawBgmTooltip(Song bgm)

if (Configuration.Instance.ShowAltLangTitles)
{
var code = Util.AltLang();
var code = Configuration.Instance.AltTitleLanguageCode;
var altLangTitle = bgm.Strings[code].Name;
if (bgm.Name != altLangTitle && !string.IsNullOrEmpty(altLangTitle))
{
Expand All @@ -50,7 +50,7 @@ public static void DrawBgmTooltip(Song bgm)

if (Configuration.Instance.ShowAltLangTitles)
{
var code = Util.AltLang();
var code = Configuration.Instance.AltTitleLanguageCode;
var altLangAltTitle = bgm.Strings[code].AlternateName;
if (bgm.AlternateName != altLangAltTitle && !string.IsNullOrEmpty(altLangAltTitle))
{
Expand All @@ -71,7 +71,7 @@ public static void DrawBgmTooltip(Song bgm)

if (Configuration.Instance.ShowAltLangTitles)
{
var code = Util.AltLang();
var code = Configuration.Instance.AltTitleLanguageCode;
var altLangSpecialModeName = bgm.Strings[code].SpecialModeName;
if (bgm.SpecialModeName != altLangSpecialModeName)
{
Expand Down
2 changes: 1 addition & 1 deletion Orchestrion/UI/Components/RenderableSongList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Dalamud.Logging;
using ImGuiNET;
using Orchestrion.Persistence;
using Orchestrion.Struct;
using Orchestrion.Types;
using Orchestrion.UI.Windows;

namespace Orchestrion.UI.Components;
Expand Down
2 changes: 1 addition & 1 deletion Orchestrion/UI/Components/SongListRenderStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using Orchestrion.Audio;
using Orchestrion.Struct;
using Orchestrion.Types;

namespace Orchestrion.UI.Components;

Expand Down
2 changes: 1 addition & 1 deletion Orchestrion/UI/Windows/MainWindow/MainWindow.History.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Dalamud.Logging;
using ImGuiNET;
using Orchestrion.Persistence;
using Orchestrion.Struct;
using Orchestrion.Types;
using Orchestrion.UI.Components;

namespace Orchestrion.UI.Windows.MainWindow;
Expand Down
4 changes: 3 additions & 1 deletion Orchestrion/UI/Windows/MainWindow/MainWindow.Playlist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using ImGuiNET;
using Orchestrion.Audio;
using Orchestrion.Persistence;
using Orchestrion.Struct;
using Orchestrion.Types;
using Orchestrion.UI.Components;

namespace Orchestrion.UI.Windows.MainWindow;
Expand Down Expand Up @@ -121,6 +121,8 @@ private void DrawPlaylistPane()
ImGuiHelpers.ScaledVector2(0f, drawHeight)
))
{
Configuration.Instance.LastSelectedPlaylist = pName;
Configuration.Instance.Save();
RefreshPlaylist(playlist);

if (ImGui.IsMouseDoubleClicked(ImGuiMouseButton.Left) && playlist.Songs.Count > 0)
Expand Down
13 changes: 8 additions & 5 deletions Orchestrion/UI/Windows/MainWindow/MainWindow.Replacement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using CheapLoc;
using ImGuiNET;
using Orchestrion.Persistence;
using Orchestrion.Struct;
using Orchestrion.Types;
using Orchestrion.UI.Components;

namespace Orchestrion.UI.Windows.MainWindow;
Expand All @@ -25,15 +25,18 @@ private void DrawReplacementList()
{
foreach (var replacement in Configuration.Instance.SongReplacements.Values)
{
if (!SongList.Instance.TryGetSong(replacement.TargetSongId, out var targetSong)) continue;
if (!SongList.Instance.TryGetSong(replacement.ReplacementId, out var replacementSong)) continue;
if (!Util.SearchMatches(_searchText, targetSong) && !Util.SearchMatches(_searchText, replacementSong)) continue;

ImGui.Spacing();
SongList.Instance.TryGetSong(replacement.TargetSongId, out var target);

var targetText = $"{replacement.TargetSongId} - {target.Name}";
var replText = replacement.ReplacementId == SongReplacementEntry.NoChangeId ? MainWindow._noChange : $"{replacement.ReplacementId} - {SongList.Instance.GetSong(replacement.ReplacementId).Name}";
var targetText = $"{replacement.TargetSongId} - {targetSong.Name}";
var replText = replacement.ReplacementId == SongReplacementEntry.NoChangeId ? _noChange : $"{replacement.ReplacementId} - {replacementSong.Name}";

ImGui.TextWrapped($"{targetText}");
if (ImGui.IsItemHovered())
BgmTooltip.DrawBgmTooltip(target);
BgmTooltip.DrawBgmTooltip(targetSong);

ImGui.Text(Loc.Localize("ReplaceWith", "will be replaced with"));
ImGui.TextWrapped($"{replText}");
Expand Down
3 changes: 2 additions & 1 deletion Orchestrion/UI/Windows/MainWindow/MainWindow.Root.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using ImGuiNET;
using Orchestrion.Audio;
using Orchestrion.Persistence;
using Orchestrion.Struct;
using Orchestrion.Types;
using Orchestrion.UI.Components;

namespace Orchestrion.UI.Windows.MainWindow;
Expand Down Expand Up @@ -42,6 +42,7 @@ private enum TabType
public MainWindow(OrchestrionPlugin orch) : base(BaseName, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)
{
_orch = orch;
_selectedPlaylist = Configuration.Instance.Playlists.Values.FirstOrDefault(p => p.Name == Configuration.Instance.LastSelectedPlaylist);

_mainSongList = new RenderableSongList(
SongList.Instance.GetSongs().Select(s => new RenderableSongEntry(s.Key)).ToList(),
Expand Down
Loading

0 comments on commit 3d980c8

Please sign in to comment.