diff --git a/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs b/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs index 0ee4b4bdf..aaf8d1e3b 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs @@ -43,7 +43,7 @@ namespace Barotrauma { return text; } - text = TextManager.Get(textTag).Replace("[key]", keyBind); + text = TextManager.GetWithVariable(textTag, "[key]", keyBind); cachedHudTexts.Add(textTag + keyBind, text); return text; } diff --git a/Barotrauma/BarotraumaClient/Source/Characters/CharacterInfo.cs b/Barotrauma/BarotraumaClient/Source/Characters/CharacterInfo.cs index 9896272dd..f678e8b3a 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/CharacterInfo.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/CharacterInfo.cs @@ -119,11 +119,9 @@ namespace Barotrauma if ((int)newLevel > (int)prevLevel) { GUI.AddMessage( - TextManager.Get("SkillIncreased") - .Replace("[name]", Name) - .Replace("[skillname]", TextManager.Get("SkillName." + skillIdentifier)) - .Replace("[newlevel]", ((int)newLevel).ToString()), - Color.Green); + TextManager.GetWithVariables("SkillIncreased", new string[3] { "[name]", "[skillname]", "[newlevel]" }, + new string[3] { Name, TextManager.Get("SkillName." + skillIdentifier), ((int)newLevel).ToString() }, + new bool[3] { false, true, false }), Color.Green); } } diff --git a/Barotrauma/BarotraumaClient/Source/Characters/Health/AfflictionHusk.cs b/Barotrauma/BarotraumaClient/Source/Characters/Health/AfflictionHusk.cs index 727aea035..802016b71 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/Health/AfflictionHusk.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/Health/AfflictionHusk.cs @@ -26,7 +26,7 @@ namespace Barotrauma } else if (state != InfectionState.Active && Character.Controlled == character) { - GUI.AddMessage(TextManager.Get("HuskActivate").Replace("[Attack]", GameMain.Config.KeyBind(InputType.Attack).ToString()), + GUI.AddMessage(TextManager.GetWithVariable("HuskActivate", "[Attack]", GameMain.Config.KeyBind(InputType.Attack).ToString()), Color.Red); } } diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/MultiPlayerCampaign.cs b/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/MultiPlayerCampaign.cs index bb18197ea..6be3bacb1 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/MultiPlayerCampaign.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/MultiPlayerCampaign.cs @@ -113,8 +113,8 @@ namespace Barotrauma if (GameMain.Client != null && interactor == Character.Controlled) { - var msgBox = new GUIMessageBox("", TextManager.Get("CampaignEnterOutpostPrompt") - .Replace("[locationname]", Submarine.MainSub.AtStartPosition ? Map.CurrentLocation.Name : Map.SelectedLocation.Name), + var msgBox = new GUIMessageBox("", TextManager.GetWithVariable("CampaignEnterOutpostPrompt", "[locationname]", + Submarine.MainSub.AtStartPosition ? Map.CurrentLocation.Name : Map.SelectedLocation.Name), new string[] { TextManager.Get("Yes"), TextManager.Get("No") }) { UserData = "watchmanprompt" diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/Tutorials/CaptainTutorial.cs b/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/Tutorials/CaptainTutorial.cs index 1427c742c..f45ec0fc9 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/Tutorials/CaptainTutorial.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/Tutorials/CaptainTutorial.cs @@ -230,7 +230,7 @@ namespace Barotrauma.Tutorials } while (!Submarine.MainSub.AtEndPosition || Submarine.MainSub.DockedTo.Count == 0); RemoveCompletedObjective(segments[6]); yield return new WaitForSeconds(3f, false); - GameMain.GameSession?.CrewManager.AddSinglePlayerChatMessage(radioSpeakerName, TextManager.Get("Captain.Radio.Complete").Replace("[OUTPOSTNAME]", GameMain.GameSession.EndLocation.Name), ChatMessageType.Radio, null); + GameMain.GameSession?.CrewManager.AddSinglePlayerChatMessage(radioSpeakerName, TextManager.GetWithVariable("Captain.Radio.Complete", "[OUTPOSTNAME]", GameMain.GameSession.EndLocation.Name), ChatMessageType.Radio, null); SetHighlight(captain_navConsole.Item, false); SetHighlight(captain_sonar.Item, false); SetHighlight(captain_statusMonitor, false); diff --git a/Barotrauma/BarotraumaServer/Source/GameSession/GameModes/TraitorManager.cs b/Barotrauma/BarotraumaServer/Source/GameSession/GameModes/TraitorManager.cs index a96478b67..3c05f2ef0 100644 --- a/Barotrauma/BarotraumaServer/Source/GameSession/GameModes/TraitorManager.cs +++ b/Barotrauma/BarotraumaServer/Source/GameSession/GameModes/TraitorManager.cs @@ -16,10 +16,9 @@ namespace Barotrauma public void Greet(GameServer server, string codeWords, string codeResponse) { - string greetingMessage = TextManager.Get("TraitorStartMessage").Replace("[targetname]", TargetCharacter.Name); - string moreAgentsMessage = TextManager.Get("TraitorMoreAgentsMessage") - .Replace("[codewords]", codeWords) - .Replace("[coderesponse]", codeResponse); + string greetingMessage = TextManager.GetWithVariable("TraitorStartMessage", "[targetname]", TargetCharacter.Name); + string moreAgentsMessage = TextManager.GetWithVariables("TraitorMoreAgentsMessage", + new string[2] { "[codewords]", "[coderesponse]" }, new string[2] { codeWords, codeResponse }); var greetingChatMsg = ChatMessage.Create(null, greetingMessage, ChatMessageType.Server, null); var moreAgentsChatMsg = ChatMessage.Create(null, moreAgentsMessage, ChatMessageType.Server, null); @@ -38,7 +37,7 @@ namespace Barotrauma { var ownerMsg = ChatMessage.Create( null,//TextManager.Get("NewTraitor"), - TextManager.Get("TraitorStartMessageServer").Replace("[targetname]", TargetCharacter.Name).Replace("[traitorname]", Character.Name), + TextManager.GetWithVariables("TraitorStartMessageServer", new string[2] { "[targetname]", "[traitorname]" }, new string[2] { TargetCharacter.Name, Character.Name }), ChatMessageType.MessageBox, null ); @@ -168,9 +167,8 @@ namespace Barotrauma } } - endMessage += (TextManager.ReplaceGenderPronouns(TextManager.Get(messageTag), traitorCharacter.Info.Gender) + "\n") - .Replace("[traitorname]", traitorCharacter.Name) - .Replace("[targetname]", targetCharacter.Name); + endMessage += (TextManager.ReplaceGenderPronouns(TextManager.GetWithVariables(messageTag, new string[2] { "[traitorname]", "[targetname]" }, + new string[2] { traitorCharacter.Name, targetCharacter.Name }), traitorCharacter.Info.Gender) + "\n"); } return endMessage; diff --git a/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs b/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs index 48dfceef2..1dbc815cb 100644 --- a/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs @@ -415,7 +415,7 @@ namespace Barotrauma.Networking { if (endRoundTimer <= 0.0f) { - SendChatMessage(TextManager.Get("CrewDeadNoRespawns").Replace("[time]", "60"), ChatMessageType.Server); + SendChatMessage(TextManager.GetWithVariable("CrewDeadNoRespawns", "[time]", "60"), ChatMessageType.Server); } endRoundTimer += deltaTime; } @@ -728,7 +728,7 @@ namespace Barotrauma.Networking if (matchingSub == null) { SendDirectChatMessage( - TextManager.Get("CampaignStartFailedSubNotFound").Replace("[subname]", subName), + TextManager.GetWithVariable("CampaignStartFailedSubNotFound", "[subname]", subName), connectedClient, ChatMessageType.MessageBox); } else diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/HumanAIController.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/HumanAIController.cs index dbf996ddf..2f176e100 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/HumanAIController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/HumanAIController.cs @@ -381,8 +381,8 @@ namespace Barotrauma } if (Character.PressureTimer > 50.0f && Character.CurrentHull != null) - { - Character.Speak(TextManager.Get("DialogPressure").Replace("[roomname]", Character.CurrentHull.DisplayName), null, 0, "pressure", 30.0f); + { + Character.Speak(TextManager.GetWithVariable("DialogPressure", "[roomname]", Character.CurrentHull.DisplayName, true), null, 0, "pressure", 30.0f); } } diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveExtinguishFire.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveExtinguishFire.cs index d60f7926b..b2bccbe4d 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveExtinguishFire.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveExtinguishFire.cs @@ -110,8 +110,8 @@ namespace Barotrauma move = false; extinguisher.Use(deltaTime, character); if (!targetHull.FireSources.Contains(fs)) - { - character.Speak(TextManager.Get("DialogPutOutFire").Replace("[roomname]", targetHull.Name), null, 0, "putoutfire", 10.0f); + { + character.Speak(TextManager.GetWithVariable("DialogPutOutFire", "[roomname]", targetHull.Name, true), null, 0, "putoutfire", 10.0f); } } } diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveOperateItem.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveOperateItem.cs index d77c798c3..3da532975 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveOperateItem.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveOperateItem.cs @@ -60,7 +60,7 @@ namespace Barotrauma ItemComponent target = useController ? controller : component; if (useController && controller == null) { - character.Speak(TextManager.Get("DialogCantFindController").Replace("[item]", component.Item.Name), null, 2.0f, "cantfindcontroller", 30.0f); + character.Speak(TextManager.GetWithVariable("DialogCantFindController", "[item]", component.Item.Name, true), null, 2.0f, "cantfindcontroller", 30.0f); abandon = true; return; } diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRepairItem.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRepairItem.cs index a3574b29d..8ddb26d26 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRepairItem.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRepairItem.cs @@ -44,8 +44,8 @@ namespace Barotrauma { bool isCompleted = Item.IsFullCondition; if (isCompleted) - { - character?.Speak(TextManager.Get("DialogItemRepaired").Replace("[itemname]", Item.Name), null, 0.0f, "itemrepaired", 10.0f); + { + character?.Speak(TextManager.GetWithVariable("DialogItemRepaired", "[itemname]", Item.Name, true), null, 0.0f, "itemrepaired", 10.0f); } return isCompleted; } @@ -140,7 +140,7 @@ namespace Barotrauma { // If the current condition is less than the previous condition, we can't complete the task, so let's abandon it. The item is probably deteriorating at a greater speed than we can repair it. abandon = true; - character?.Speak(TextManager.Get("DialogCannotRepair").Replace("[itemname]", Item.Name), null, 0.0f, "cannotrepair", 10.0f); + character?.Speak(TextManager.GetWithVariable("DialogCannotRepair", "[itemname]", Item.Name, true), null, 0.0f, "cannotrepair", 10.0f); } } repairable.CurrentFixer = abandon && repairable.CurrentFixer == character ? null : character; @@ -161,8 +161,8 @@ namespace Barotrauma objective.CloseEnough = repairTool.Range * 0.75f; } return objective; - }, - onAbandon: () => character.Speak(TextManager.Get("DialogCannotRepair").Replace("[itemname]", Item.Name), null, 0.0f, "cannotrepair", 10.0f)); + }, + onAbandon: () => character.Speak(TextManager.GetWithVariable("DialogCannotRepair", "[itemname]", Item.Name, true), null, 0.0f, "cannotrepair", 10.0f)); } } diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRescue.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRescue.cs index 65c43a1d9..3eff46f3a 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRescue.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRescue.cs @@ -57,11 +57,10 @@ namespace Barotrauma if (targetCharacter.IsUnconscious && HumanAIController.GetHullSafety(targetCharacter.CurrentHull, targetCharacter) < HumanAIController.HULL_SAFETY_THRESHOLD) { if (character.SelectedCharacter != targetCharacter) - { - character.Speak(TextManager.Get("DialogFoundUnconsciousTarget") - .Replace("[targetname]", targetCharacter.Name).Replace("[roomname]", targetCharacter.CurrentHull.DisplayName), - null, 1.0f, - "foundunconscioustarget" + targetCharacter.Name, 60.0f); + { + character.Speak(TextManager.GetWithVariables("DialogFoundUnconsciousTarget", new string[2] { "[targetname]", "[roomname]" }, + new string[2] { targetCharacter.Name, targetCharacter.CurrentHull.DisplayName }, new bool[2] { false, true }), + null, 1.0f, "foundunconscioustarget" + targetCharacter.Name, 60.0f); // Go to the target and select it if (!character.CanInteractWith(targetCharacter)) @@ -113,11 +112,10 @@ namespace Barotrauma { // We can start applying treatment if (character.SelectedCharacter != targetCharacter) - { - character.Speak(TextManager.Get("DialogFoundWoundedTarget") - .Replace("[targetname]", targetCharacter.Name).Replace("[roomname]", targetCharacter.CurrentHull.DisplayName), - null, 1.0f, - "foundwoundedtarget" + targetCharacter.Name, 60.0f); + { + character.Speak(TextManager.GetWithVariables("DialogFoundWoundedTarget", new string[2] { "[targetname]", "[roomname]" }, + new string[2] { targetCharacter.Name, targetCharacter.CurrentHull.DisplayName }, new bool[2] { false, true }), + null, 1.0f, "foundwoundedtarget" + targetCharacter.Name, 60.0f); character.SelectCharacter(targetCharacter); } @@ -191,9 +189,10 @@ namespace Barotrauma { itemListStr = string.Join(" or ", string.Join(", ", itemNameList.Take(itemNameList.Count - 1)), itemNameList.Last()); } - character.Speak(TextManager.Get("DialogListRequiredTreatments") - .Replace("[targetname]", targetCharacter.Name) - .Replace("[treatmentlist]", itemListStr), + + + character.Speak(TextManager.GetWithVariables("DialogListRequiredTreatments", new string[2] { "[targetname]", "[treatmentlist]" }, + new string[2] { targetCharacter.Name, itemListStr }, new bool[2] { false, true }), null, 2.0f, "listrequiredtreatments" + targetCharacter.Name, 60.0f); } character.DeselectCharacter(); @@ -235,8 +234,8 @@ namespace Barotrauma bool isCompleted = targetCharacter.Bleeding <= 0 && targetCharacter.Vitality / targetCharacter.MaxVitality > AIObjectiveRescueAll.GetVitalityThreshold(objectiveManager); if (isCompleted) - { - character.Speak(TextManager.Get("DialogTargetHealed").Replace("[targetname]", targetCharacter.Name), + { + character.Speak(TextManager.GetWithVariable("DialogTargetHealed", "[targetname]", targetCharacter.Name), null, 1.0f, "targethealed" + targetCharacter.Name, 60.0f); } return isCompleted || targetCharacter.IsDead; diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/Order.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/Order.cs index 6391147f5..db26adb82 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/Order.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/Order.cs @@ -171,12 +171,12 @@ namespace Barotrauma string messageTag = (givingOrderToSelf && !TargetAllCharacters ? "OrderDialogSelf." : "OrderDialog.") + AITag; if (!string.IsNullOrEmpty(orderOption)) messageTag += "." + orderOption; - string msg = TextManager.Get(messageTag, true); + if (targetCharacterName == null) targetCharacterName = ""; + if (targetRoomName == null) targetRoomName = ""; + string msg = TextManager.GetWithVariables(messageTag, new string[2] { "[name]", "[roomname]" }, new string[2] { targetCharacterName, targetRoomName }, true); if (msg == null) return ""; - if (targetCharacterName == null) targetCharacterName = ""; - if (targetRoomName == null) targetRoomName = ""; - return msg.Replace("[name]", targetCharacterName).Replace("[roomname]", targetRoomName); + return msg; } } diff --git a/Barotrauma/BarotraumaShared/Source/GameSession/CargoManager.cs b/Barotrauma/BarotraumaShared/Source/GameSession/CargoManager.cs index 271dd6dc1..03c92e52e 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSession/CargoManager.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSession/CargoManager.cs @@ -108,7 +108,7 @@ namespace Barotrauma } #if CLIENT - new GUIMessageBox("", TextManager.Get("CargoSpawnNotification").Replace("[roomname]", cargoRoom.DisplayName)); + new GUIMessageBox("", TextManager.GetWithVariable("CargoSpawnNotification", "[roomname]", cargoRoom.DisplayName, true)); #endif Dictionary availableContainers = new Dictionary(); diff --git a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/CampaignMode.cs b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/CampaignMode.cs index d0cd28725..3ddd11311 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/CampaignMode.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/CampaignMode.cs @@ -193,7 +193,7 @@ namespace Barotrauma character.TeamID = Character.TeamType.FriendlyNPC; character.SetCustomInteract( WatchmanInteract, - hudText: TextManager.Get("TalkHint").Replace("[key]", GameMain.Config.KeyBind(InputType.Select).ToString())); + hudText: TextManager.GetWithVariable("TalkHint", "[key]", GameMain.Config.KeyBind(InputType.Select).ToString())); } protected abstract void WatchmanInteract(Character watchman, Character interactor); diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs index a61ce2b23..681f74534 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs @@ -396,11 +396,12 @@ namespace Barotrauma.Items.Components sinTime = 0; if (!leak.FlowTargetHull.ConnectedGaps.Any(g => !g.IsRoomToRoom && g.Open > 0.0f)) { - character.Speak(TextManager.Get("DialogLeaksFixed").Replace("[roomname]", leak.FlowTargetHull.DisplayName), null, 0.0f, "leaksfixed", 10.0f); + + character.Speak(TextManager.GetWithVariable("DialogLeaksFixed", "[roomname]", leak.FlowTargetHull.DisplayName, true), null, 0.0f, "leaksfixed", 10.0f); } else { - character.Speak(TextManager.Get("DialogLeakFixed").Replace("[roomname]", leak.FlowTargetHull.DisplayName), null, 0.0f, "leakfixed", 10.0f); + character.Speak(TextManager.GetWithVariable("DialogLeakFixed", "[roomname]", leak.FlowTargetHull.DisplayName, true), null, 0.0f, "leakfixed", 10.0f); } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Sonar.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Sonar.cs index c18e1ad02..539ba0aac 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Sonar.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Sonar.cs @@ -219,8 +219,10 @@ namespace Barotrauma.Items.Components { dialogTag = "DialogSonarTargetLarge"; } - character.Speak(TextManager.Get(dialogTag).Replace("[direction]", targetGroup.Key).Replace("[count]", targetGroup.Value.Count.ToString()), - null, 0, "sonartarget" + targetGroup.Value[0].ID, 30); + + character.Speak(TextManager.GetWithVariables(dialogTag, new string[2] { "[direction]", "[count]" }, + new string[2] { targetGroup.Key.ToString(), targetGroup.Value.Count.ToString() }, + new bool[2] { true, false }), null, 0, "sonartarget" + targetGroup.Value[0].ID, 30); //prevent the character from reporting other targets in the group for (int i = 1; i < targetGroup.Value.Count; i++) @@ -239,7 +241,7 @@ namespace Barotrauma.Items.Components int clockDir = (int)Math.Round((angle / MathHelper.TwoPi) * 12); if (clockDir == 0) clockDir = 12; - return TextManager.Get("roomname.subdiroclock").Replace("[dir]", clockDir.ToString()); + return TextManager.GetWithVariable("roomname.subdiroclock", "[dir]", clockDir.ToString()); } private Vector2 GetTransducerPos() diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerContainer.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerContainer.cs index f411cf341..f74e81242 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerContainer.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerContainer.cs @@ -244,9 +244,10 @@ namespace Barotrauma.Items.Components #if CLIENT rechargeSpeedSlider.BarScroll = RechargeSpeed / Math.Max(maxRechargeSpeed, 1.0f); #endif - character.Speak(TextManager.Get("DialogChargeBatteries") - .Replace("[itemname]", item.Name) - .Replace("[rate]", ((int)(rechargeSpeed / maxRechargeSpeed * 100.0f)).ToString()), null, 1.0f, "chargebattery", 10.0f); + + character.Speak(TextManager.GetWithVariables("DialogChargeBatteries", new string[2] { "[itemname]", "[rate]" }, + new string[2] { item.Name, ((int)(rechargeSpeed / maxRechargeSpeed * 100.0f)).ToString() }, + new bool[2] { true, false }), null, 1.0f, "chargebattery", 10.0f); } } else @@ -260,9 +261,9 @@ namespace Barotrauma.Items.Components #if CLIENT rechargeSpeedSlider.BarScroll = RechargeSpeed / Math.Max(maxRechargeSpeed, 1.0f); #endif - character.Speak(TextManager.Get("DialogStopChargingBatteries") - .Replace("[itemname]", item.Name) - .Replace("[rate]", ((int)(rechargeSpeed / maxRechargeSpeed * 100.0f)).ToString()), null, 1.0f, "chargebattery", 10.0f); + character.Speak(TextManager.GetWithVariables("DialogStopChargingBatteries", new string[2] { "[itemname]", "[rate]" }, + new string[2] { item.Name, ((int)(rechargeSpeed / maxRechargeSpeed * 100.0f)).ToString() }, + new bool[2] { true, false }), null, 1.0f, "chargebattery", 10.0f); } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs index b8b1ce152..e839e8c8b 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs @@ -459,7 +459,7 @@ namespace Barotrauma.Items.Components } var containShellObjective = new AIObjectiveContainItem(character, container.ContainableItems[0].Identifiers[0], container, objective.objectiveManager); - character?.Speak(TextManager.Get("DialogLoadTurret").Replace("[itemname]", item.Name), null, 0.0f, "loadturret", 30.0f); + character?.Speak(TextManager.GetWithVariable("DialogLoadTurret", "[itemname]", item.Name, true), null, 0.0f, "loadturret", 30.0f); containShellObjective.targetItemCount = usableProjectileCount + 1; containShellObjective.ignoredContainerIdentifiers = new string[] { containerItem.prefab.Identifier }; objective.AddSubObjective(containShellObjective); @@ -506,7 +506,7 @@ namespace Barotrauma.Items.Components if (objective.Option.ToLowerInvariant() == "fireatwill") { - character?.Speak(TextManager.Get("DialogFireTurret").Replace("[itemname]", item.Name), null, 0.0f, "fireturret", 5.0f); + character?.Speak(TextManager.GetWithVariable("DialogFireTurret", "[itemname]", item.Name, true), null, 0.0f, "fireturret", 5.0f); character.SetInput(InputType.Shoot, true, true); } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index e60801429..752d3df85 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -1539,9 +1539,8 @@ namespace Barotrauma { if (requiredSkill != null) { - GUI.AddMessage(TextManager.Get("InsufficientSkills") - .Replace("[requiredskill]", TextManager.Get("SkillName." + requiredSkill.Identifier)) - .Replace("[requiredlevel]", ((int)requiredSkill.Level).ToString()), Color.Red); + GUI.AddMessage(TextManager.GetWithVariables("InsufficientSkills", new string[2] { "[requiredskill]", "[requiredlevel]" }, + new string[2] { TextManager.Get("SkillName." + requiredSkill.Identifier), ((int)requiredSkill.Level).ToString() }, new bool[2] { true, false }), Color.Red); } } #endif diff --git a/Barotrauma/BarotraumaShared/Source/TextManager.cs b/Barotrauma/BarotraumaShared/Source/TextManager.cs index 60ff00a43..3e0daac38 100644 --- a/Barotrauma/BarotraumaShared/Source/TextManager.cs +++ b/Barotrauma/BarotraumaShared/Source/TextManager.cs @@ -176,6 +176,107 @@ namespace Barotrauma } } + public static string GetWithVariables(string textTag, string[] variableTags, string[] variableValues, bool[] formatCapitals = null, bool returnNull = false, string fallBackTag = null) + { + string text = Get(textTag, returnNull, fallBackTag); + + if (text == null || text.Length == 0 || variableTags.Length != variableValues.Length) + { +#if DEBUG + if (variableTags.Length != variableValues.Length) + { + DebugConsole.ThrowError("variableTags.Length and variableValues.Length do not match for \"" + textTag + "\"."); + } + + if (formatCapitals != null && formatCapitals.Length != variableTags.Length) + { + DebugConsole.ThrowError("variableTags.Length and formatCapitals.Length do not match for \"" + textTag + "\"."); + } +#endif + if (returnNull) + { + return null; + } + else + { + return textTag; + } + } + + if (formatCapitals != null && !GameMain.Config.Language.Contains("Chinese")) + { + for (int i = 0; i < variableTags.Length; i++) + { + if (formatCapitals[i]) + { + variableValues[i] = HandleCapitalization(text, variableTags[i], variableValues[i]); + } + } + } + + for (int i = 0; i < variableTags.Length; i++) + { + text = text.Replace(variableTags[i], variableValues[i]); + } + + return text; + } + + public static string GetWithVariable(string textTag, string variableTag, string variableValue, bool formatCapitals = false, bool returnNull = false, string fallBackTag = null) + { + string text = Get(textTag, returnNull, fallBackTag); + + if (text == null || text.Length == 0) + { + if (returnNull) + { + return null; + } + else + { + return textTag; + } + } + + if (formatCapitals && !GameMain.Config.Language.Contains("Chinese")) + { + variableValue = HandleCapitalization(text, variableTag, variableValue); + } + + return text.Replace(variableTag, variableValue); + } + + private static string HandleCapitalization(string text, string variableTag, string variableValue) + { + int index = text.IndexOf(variableTag) - 1; + if (index == -1) + { + return variableValue; + } + + for (int i = index; i >= 0; i--) + { + if (text[i] == ' ') + { + continue; + } + else + { + if (text[i] != '.') + { + variableValue = variableValue.ToLower(); + } + else + { + variableValue = variableValue.First().ToString().ToUpper() + variableValue.Substring(1); + break; + } + } + } + + return variableValue; + } + public static string ParseInputTypes(string text) { foreach (InputType inputType in Enum.GetValues(typeof(InputType)))