Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcintyre committed Mar 13, 2024
1 parent 8f94036 commit 3c82512
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 49 deletions.
69 changes: 24 additions & 45 deletions Orchestrion/OrchestrionPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Collections.Generic;
using System.IO;
using Dalamud.Game.Command;
using Dalamud.Game.Text;
using Dalamud.Plugin;
Expand Down Expand Up @@ -77,37 +78,22 @@ public OrchestrionPlugin(DalamudPluginInterface pi)

DalamudApi.Framework.Update += OrchestrionUpdate;
DalamudApi.ClientState.Logout += ClientStateOnLogout;

DalamudApi.PluginInterface.UiBuilder.BuildFonts += BuildFonts;
DalamudApi.PluginInterface.UiBuilder.RebuildFonts();


DalamudApi.PluginInterface.LanguageChanged += LanguageChanged;
}

public static void LanguageChanged(string code)
{
var stream =
Assembly.GetExecutingAssembly().GetManifestResourceStream($"Orchestrion.Loc.{code}.json")
?? Assembly.GetExecutingAssembly().GetManifestResourceStream($"Orchestrion.Loc.en.json");
if (stream == null) return; // we can't recover
var content = new StreamReader(stream).ReadToEnd();
Loc.Setup(content);
}

private void BuildFonts()
{

var atlas = DalamudApi.PluginInterface.UiBuilder.FontAtlas;
CnFont = atlas.NewDelegateFontHandle(e => e.OnPreBuild(tk => {
var config = new SafeFontConfig
{
SizePx = UiBuilder.DefaultFontSizePx,
GlyphRanges = ImGuiHelpers.CreateImGuiRangesFrom(
UnicodeRanges.CjkUnifiedIdeographs,
UnicodeRanges.CjkUnifiedIdeographsExtensionA,
UnicodeRanges.BasicLatin),
GlyphRanges = SongList.Instance
.GetSongs()
.Values
.SelectMany(x => x.Strings.GetValueOrDefault("zh", default).Name ?? string.Empty)
.Concat(Enumerable.Range(1, 127).Select(x => (char)x))
.ToGlyphRange(),
};
// tk.Font = tk.AddDalamudAssetFont(DalamudAsset.NotoSansJpMedium, config);
tk.Font = tk.AddFontFromFile(@"c:/windows/fonts/msyh.ttc", config);
tk.Font = tk.AddDalamudAssetFont(DalamudAsset.NotoSansJpMedium, config);
}));
if (CnFont.LoadException != null)
{
Expand All @@ -116,37 +102,30 @@ private void BuildFonts()
}

LargeFont = atlas.NewGameFontHandle(new GameFontStyle(GameFontFamily.Axis, 24 * ImGuiHelpers.GlobalScale));
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
DalamudApi.PluginLog.Debug($"fonts built");
}

public static void LanguageChanged(string code)
{
var stream =
Assembly.GetExecutingAssembly().GetManifestResourceStream($"Orchestrion.Loc.{code}.json")
?? Assembly.GetExecutingAssembly().GetManifestResourceStream($"Orchestrion.Loc.en.json");
if (stream == null) return; // we can't recover
var content = new StreamReader(stream).ReadToEnd();
Loc.Setup(content);
}

public void Dispose()
{
_mainWindow.Dispose();
DalamudApi.Framework.Update -= OrchestrionUpdate;
DalamudApi.PluginInterface.UiBuilder.Draw -= _windowSystem.Draw;
DalamudApi.PluginInterface.UiBuilder.BuildFonts -= BuildFonts;
// DalamudApi.PluginInterface.UiBuilder.BuildFonts -= BuildFonts;
DalamudApi.CommandManager.RemoveHandler(CommandName);
_dtrEntry?.Dispose();
PlaylistManager.Dispose();
BGMManager.Dispose();
LargeFont?.Dispose();
CnFont?.Dispose();
}

private void OrchestrionUpdate(IFramework ignored)
Expand Down
6 changes: 3 additions & 3 deletions Orchestrion/UI/Components/BgmTooltip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ public static void DrawBgmTooltip(Song bgm)
{
var code = Configuration.Instance.AltTitleLanguageCode;
var altLangTitle = bgm.Strings[code].Name;
OrchestrionPlugin.CnFont.Push();
DalamudApi.PluginLog.Debug($"alt lang is {altLangTitle} for {code}, thing is, CnFont loadexception null?: {OrchestrionPlugin.CnFont.LoadException == null}");
if (bgm.Name != altLangTitle && !string.IsNullOrEmpty(altLangTitle))
{
var label = Loc.Localize("TitleColon", "Title: ");
label = $"[{code}] {label}";
ImGui.TextColored(ImGuiColors.DalamudGrey, label);
ImGui.SameLine();
using var _ = code == "zh" ? OrchestrionPlugin.CnFont.Push() : null;
ImGui.TextWrapped(altLangTitle);
}
OrchestrionPlugin.CnFont.Pop();
}

if (!string.IsNullOrEmpty(bgm.AlternateName))
Expand All @@ -61,6 +59,7 @@ public static void DrawBgmTooltip(Song bgm)
label = $"[{code}] {label}";
ImGui.TextColored(ImGuiColors.DalamudGrey, label);
ImGui.SameLine();
using var _ = code == "zh" ? OrchestrionPlugin.CnFont.Push() : null;
ImGui.TextWrapped(altLangAltTitle);
}
}
Expand All @@ -82,6 +81,7 @@ public static void DrawBgmTooltip(Song bgm)
label = $"[{code}] {label}";
ImGui.TextColored(ImGuiColors.DalamudGrey, label);
ImGui.SameLine();
using var _ = code == "zh" ? OrchestrionPlugin.CnFont.Push() : null;
ImGui.TextWrapped(altLangSpecialModeName);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Orchestrion/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ public static bool SearchMatches(string searchText, Song song)

public static string Lang()
{
return DalamudApi.PluginInterface.UiLanguage;
return Configuration.Instance.UserInterfaceLanguageCode;
}
}

0 comments on commit 3c82512

Please sign in to comment.