forked from lokinmodar/Echoglossian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UiScenarioTreeHandler.cs
113 lines (98 loc) · 3.49 KB
/
UiScenarioTreeHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// <copyright file="UiScenarioTreeHandler.cs" company="lokinmodar">
// Copyright (c) lokinmodar. All rights reserved.
// Licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License license.
// </copyright>
using System;
using Dalamud.Game.Addon.Lifecycle;
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
using Dalamud.Memory;
using Echoglossian.EFCoreSqlite.Models.Journal;
using FFXIVClientStructs.FFXIV.Component.GUI;
using Humanizer;
namespace Echoglossian
{
public partial class Echoglossian
{
private unsafe void TranslateQuestOnScenarioTree(AtkValue* setupAtkValues, int valueIndex)
{
if (setupAtkValues[valueIndex].Type != FFXIVClientStructs.FFXIV.Component.GUI.ValueType.String || setupAtkValues[valueIndex].String == null)
{
return;
}
var questNameText = MemoryHelper.ReadSeStringAsString(out _, (nint)setupAtkValues[valueIndex].String);
if (questNameText == null || questNameText.Length == 0)
{
return;
}
QuestPlate questPlate = this.FormatQuestPlate(questNameText, string.Empty);
QuestPlate foundQuestPlate = this.FindQuestPlateByName(questPlate);
if (foundQuestPlate != null)
{
#if DEBUG
PluginLog.Debug($"Name from database: {questNameText} -> {foundQuestPlate.TranslatedQuestName}");
#endif
var translatedQuestName = foundQuestPlate.TranslatedQuestName;
if (this.configuration.RemoveDiacriticsWhenUsingReplacementQuest)
{
translatedQuestName = this.RemoveDiacritics(translatedQuestName, this.SpecialCharsSupportedByGameFont);
}
setupAtkValues[valueIndex].SetManagedString(translatedQuestName);
}
else
{
var translatedNameText = this.Translate(questNameText);
#if DEBUG
PluginLog.Debug($"Name translated: {questNameText} -> {translatedNameText}");
#endif
QuestPlate translatedQuestPlate = new(
questNameText,
string.Empty,
ClientStateInterface.ClientLanguage.Humanize(),
translatedNameText,
string.Empty,
string.Empty,
langDict[languageInt].Code,
this.configuration.ChosenTransEngine,
DateTime.Now,
DateTime.Now);
string result = this.InsertQuestPlate(translatedQuestPlate);
#if DEBUG
PluginLog.Debug($"Using QuestPlate Replace - QuestPlate DB Insert operation result: {result}");
#endif
if (this.configuration.RemoveDiacriticsWhenUsingReplacementQuest)
{
translatedNameText = this.RemoveDiacritics(translatedNameText, this.SpecialCharsSupportedByGameFont);
}
setupAtkValues[valueIndex].SetManagedString(translatedNameText);
}
}
private unsafe void UiScenarioTreeHandler(AddonEvent type, AddonArgs args)
{
// PluginLog.Debug($"UiScenarioTreeHandler AddonEvent: {type} {args.AddonName}");
if (!this.configuration.TranslateJournal)
{
return;
}
if (args is not AddonRefreshArgs setupArgs)
{
return;
}
var setupAtkValues = (AtkValue*)setupArgs.AtkValues;
if (setupAtkValues == null)
{
return;
}
try
{
// Translate MSQ
this.TranslateQuestOnScenarioTree(setupAtkValues, 7);
// Translate SubQuest
this.TranslateQuestOnScenarioTree(setupAtkValues, 2);
}
catch (Exception e)
{
PluginLog.Error("Exception at UiScenarioTreeHandler: " + e.StackTrace);
}
}
}
}