Skip to content

Commit f689902

Browse files
Merge pull request #2667 from Daneel53/AddUseOfGrammarProcessors
Add the use of grammar processors
2 parents 81b351e + b6438ff commit f689902

19 files changed

Lines changed: 136 additions & 23 deletions

Assets/Scripts/Game/PlayerActivate.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using DaggerfallWorkshop.Game.Utility;
2727
using DaggerfallWorkshop.Game.Formulas;
2828
using DaggerfallWorkshop.Game.Utility.ModSupport;
29+
using DaggerfallWorkshop.Localization;
2930

3031
namespace DaggerfallWorkshop.Game
3132
{
@@ -468,7 +469,7 @@ void ActivateBuilding(
468469
if (GameManager.Instance.PlayerGPS.GetDiscoveredBuilding(building.buildingKey, out db))
469470
{
470471
// Check against quest system for an overriding quest-assigned display name for this building
471-
DaggerfallUI.AddHUDText(db.displayName);
472+
DaggerfallUI.AddHUDText(GrammarManager.grammarProcessor.ProcessGrammar(db.displayName));
472473

473474
if (!buildingUnlocked && buildingType < DFLocation.BuildingTypes.Temple
474475
&& buildingType != DFLocation.BuildingTypes.HouseForSale)

Assets/Scripts/Game/Questing/Person.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using FullSerializer;
2222
using DaggerfallWorkshop.Game.MagicAndEffects.MagicEffects;
2323
using DaggerfallWorkshop.Game.Guilds;
24+
using DaggerfallWorkshop.Localization;
2425

2526
namespace DaggerfallWorkshop.Game.Questing
2627
{
@@ -229,7 +230,7 @@ public override void SetResource(string line)
229230
if (careerAllianceGroup.Success)
230231
careerAllianceName = careerAllianceGroup.Value;
231232

232-
// Gender
233+
// GenderNums
233234
Group genderGroup = option.Groups["gender"];
234235
if (genderGroup.Success)
235236
genderName = genderGroup.Value;
@@ -293,6 +294,9 @@ public override bool ExpandMacro(MacroTypes macro, out string textOut)
293294
// This will be used for subsequent pronoun macros, etc.
294295
ParentQuest.LastResourceReferenced = this;
295296

297+
// Send the person's gender to the grammar processor
298+
GrammarManager.grammarProcessor.SetNPCGenderGetter(() => ParentQuest.LastResourceReferenced?.Gender ?? Genders.Male);
299+
296300
Place dialogPlace = GetDialogPlace();
297301
if (dialogPlace != null)
298302
{

Assets/Scripts/Game/TextManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,9 @@ public string GetLocalizedText(string key, TextCollections collection = TextColl
357357
{
358358
string localizedText;
359359
if (TryGetLocalizedText(GetRuntimeCollectionName(collection), key, out localizedText))
360+
{
360361
return localizedText;
362+
}
361363
else if (TryGetLocalizedText(GetDefaultCollectionName(collection), key, out localizedText))
362364
return localizedText;
363365
else

Assets/Scripts/Game/UserInterface/MultiFormatTextLabel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Text;
1616
using System.IO;
1717
using DaggerfallConnect.Arena2;
18+
using DaggerfallWorkshop.Localization;
1819

1920
namespace DaggerfallWorkshop.Game.UserInterface
2021
{
@@ -226,7 +227,7 @@ public TextLabel AddTextLabel(string text, DaggerfallFont font, Color color)
226227
// Use max width if it has been specified
227228
if (maxTextWidth > 0)
228229
textLabel.MaxWidth = maxTextWidth;
229-
textLabel.Text = text;
230+
textLabel.Text = GrammarManager.grammarProcessor.ProcessGrammar(text);
230231
textLabel.TextColor = color;
231232
textLabel.ShadowColor = ShadowColor;
232233
textLabel.ShadowPosition = ShadowPosition;

Assets/Scripts/Game/UserInterface/PopupText.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Project: Daggerfall Unity
1+
// Project: Daggerfall Unity
22
// Copyright: Copyright (C) 2009-2023 Daggerfall Workshop
33
// Web Site: http://www.dfworkshop.net
44
// License: MIT License (http://www.opensource.org/licenses/mit-license.php)
@@ -14,6 +14,7 @@
1414
using System.Collections.Generic;
1515
using UnityEngine;
1616
using DaggerfallConnect.Arena2;
17+
using DaggerfallWorkshop.Localization;
1718

1819
namespace DaggerfallWorkshop.Game.UserInterface
1920
{
@@ -113,11 +114,13 @@ public void AddText(string text, float delayInSeconds = popDelay)
113114
else
114115
// set next no-scroll delay
115116
nextPopDelay = Mathf.Max(nextPopDelay, delayInSeconds);
116-
TextLabel label = DaggerfallUI.AddTextLabel(DaggerfallUI.DefaultFont, Vector2.zero, text);
117+
// Apply grammar processor before display
118+
string pgText = GrammarManager.grammarProcessor.ProcessGrammar(text);
119+
TextLabel label = DaggerfallUI.AddTextLabel(DaggerfallUI.DefaultFont, Vector2.zero, pgText);
117120
label.HorizontalAlignment = HorizontalAlignment.Center;
118121
label.Parent = Parent;
119122
textRows.AddLast(label);
120-
GameManager.Instance.PlayerEntity.Notebook.AddMessage(text);
123+
GameManager.Instance.PlayerEntity.Notebook.AddMessage(pgText);
121124
}
122125

123126
/// <summary>

Assets/Scripts/Game/UserInterface/ToolTip.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Collections.Generic;
1515
using System.Text;
1616
using System.IO;
17+
using DaggerfallWorkshop.Localization;
1718

1819
namespace DaggerfallWorkshop.Game.UserInterface
1920
{
@@ -195,7 +196,7 @@ public override void Draw()
195196
// Draw tooltip text
196197
for (int i = 0; i < textRows.Length; i++)
197198
{
198-
font.DrawText(textRows[i], textPos, LocalScale, textColor);
199+
font.DrawText(GrammarManager.grammarProcessor.ProcessGrammar(textRows[i]), textPos, LocalScale, textColor);
199200
textPos.y += font.GlyphHeight * LocalScale.y;
200201
}
201202

Assets/Scripts/Game/UserInterfaceWindows/CreateCharClassSelect.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using DaggerfallWorkshop;
2020
using DaggerfallWorkshop.Game.UserInterface;
2121
using DaggerfallWorkshop.Game.Player;
22+
using DaggerfallWorkshop.Localization;
2223

2324
namespace DaggerfallWorkshop.Game.UserInterfaceWindows
2425
{
@@ -45,6 +46,7 @@ public CreateCharClassSelect(IUserInterfaceManager uiManager, DaggerfallBaseWind
4546

4647
protected override void Setup()
4748
{
49+
string careerName;
4850
base.Setup();
4951

5052
// Read all CLASS*.CFG files and add to listbox
@@ -55,7 +57,8 @@ protected override void Setup()
5557
{
5658
ClassFile classFile = new ClassFile(files[i]);
5759
classList.Add(classFile.Career);
58-
listBox.AddItem(TextManager.Instance.GetLocalizedText(classFile.Career.Name));
60+
careerName = TextManager.Instance.GetLocalizedText(classFile.Career.Name);
61+
listBox.AddItem(GrammarManager.grammarProcessor.ProcessGrammar(careerName));
5962
}
6063
}
6164
// Last option is for creating custom classes

Assets/Scripts/Game/UserInterfaceWindows/CreateCharGenderSelect.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Project: Daggerfall Unity
1+
// Project: Daggerfall Unity
22
// Copyright: Copyright (C) 2009-2023 Daggerfall Workshop
33
// Web Site: http://www.dfworkshop.net
44
// License: MIT License (http://www.opensource.org/licenses/mit-license.php)
@@ -20,6 +20,7 @@
2020
using DaggerfallWorkshop.Game.UserInterface;
2121
using DaggerfallWorkshop.Game.Entity;
2222
using DaggerfallWorkshop.Game.Player;
23+
using DaggerfallWorkshop.Localization;
2324

2425
namespace DaggerfallWorkshop.Game.UserInterfaceWindows
2526
{
@@ -59,12 +60,14 @@ protected override void Setup()
5960
void MaleButton_OnMouseClick(BaseScreenComponent sender, Vector2 position)
6061
{
6162
SelectedGender = Genders.Male;
63+
GrammarManager.grammarProcessor.SetHeroGenderGetter(() => Genders.Male);
6264
CloseWindow();
6365
}
6466

6567
void FemaleButton_OnMouseClick(BaseScreenComponent sender, Vector2 position)
6668
{
6769
SelectedGender = Genders.Female;
70+
GrammarManager.grammarProcessor.SetHeroGenderGetter(() => Genders.Female);
6871
CloseWindow();
6972
}
7073

Assets/Scripts/Game/UserInterfaceWindows/DaggerfallCharacterSheetWindow.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using DaggerfallWorkshop.Game.Entity;
1919
using DaggerfallWorkshop.Game.Formulas;
2020
using DaggerfallWorkshop.Game.Guilds;
21+
using DaggerfallWorkshop.Localization;
2122

2223
namespace DaggerfallWorkshop.Game.UserInterfaceWindows
2324
{
@@ -394,7 +395,7 @@ void UpdatePlayerValues()
394395

395396
// Update main labels
396397
nameLabel.Text = PlayerEntity.Name;
397-
raceLabel.Text = PlayerEntity.RaceTemplate.Name;
398+
raceLabel.Text = GrammarManager.grammarProcessor.ProcessGrammar(PlayerEntity.RaceTemplate.Name);
398399
classLabel.Text = PlayerEntity.Career.Name;
399400
levelLabel.Text = PlayerEntity.Level.ToString();
400401
goldLabel.Text = PlayerEntity.GetGoldAmount().ToString();

Assets/Scripts/Game/UserInterfaceWindows/DaggerfallCourtWindow.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using DaggerfallConnect.Arena2;
2020
using DaggerfallWorkshop.Game.Utility;
2121
using DaggerfallWorkshop.Game.Guilds;
22+
using DaggerfallWorkshop.Localization;
2223

2324
namespace DaggerfallWorkshop.Game.UserInterfaceWindows
2425
{
@@ -465,7 +466,7 @@ public void UpdatePrisonScreen()
465466
{
466467
daysInPrisonLeft--;
467468
daysUntilFreedomLabel.Text = TextManager.Instance.GetLocalizedText("daysUntilFreedom");
468-
daysUntilFreedomLabel.Text = daysUntilFreedomLabel.Text.Replace("%d", daysInPrisonLeft.ToString());
469+
daysUntilFreedomLabel.Text = GrammarManager.grammarProcessor.ProcessGrammar(daysUntilFreedomLabel.Text.Replace("%d", daysInPrisonLeft.ToString()));
469470

470471
if (daysInPrisonLeft == 0)
471472
{
@@ -519,7 +520,7 @@ protected virtual void SwitchToPrisonScreen()
519520
courtPanel.BackgroundTexture = nativeTexture;
520521

521522
daysUntilFreedomLabel.Text = TextManager.Instance.GetLocalizedText("daysUntilFreedom");
522-
daysUntilFreedomLabel.Text = daysUntilFreedomLabel.Text.Replace("%d", daysInPrison.ToString());
523+
daysUntilFreedomLabel.Text = GrammarManager.grammarProcessor.ProcessGrammar(daysUntilFreedomLabel.Text.Replace("%d", daysInPrison.ToString()));
523524
}
524525
}
525526
}

0 commit comments

Comments
 (0)