From a8222e429ff8384d1f45dc05b70931e49c5cc30f Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Thu, 28 Mar 2019 12:36:11 +0200 Subject: [PATCH] (edb24c37f) Fixed ItemComponents overwriting the Msg-tags ("ItemMsgPressSelect" etc) with the text fetched from the text xml, preventing the texts from being translated after the sub has been saved. --- .../Source/Items/Components/ItemComponent.cs | 6 +++- .../Items/Components/Holdable/Holdable.cs | 10 +++---- .../Source/Items/Components/ItemComponent.cs | 28 +++++++++++++------ .../BarotraumaShared/Source/Items/Item.cs | 4 +-- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs index d9927245e..cc9829018 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs @@ -496,7 +496,11 @@ namespace Barotrauma.Items.Components { msg = msg.Replace("[" + inputType.ToString().ToLowerInvariant() + "]", GameMain.Config.KeyBind(inputType).ToString()); } - Msg = msg; + DisplayMsg = msg; + } + else + { + DisplayMsg = Msg; } } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Holdable.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Holdable.cs index 5d3f4dcfc..8258fae90 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Holdable.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Holdable.cs @@ -158,7 +158,7 @@ namespace Barotrauma.Items.Components if (attachable) { - prevMsg = Msg; + prevMsg = DisplayMsg; prevPickKey = PickKey; prevRequiredItems = new Dictionary>(requiredItems); @@ -191,7 +191,7 @@ namespace Barotrauma.Items.Components base.Load(componentElement); if (attachable) { - prevMsg = Msg; + prevMsg = DisplayMsg; prevPickKey = PickKey; prevRequiredItems = new Dictionary>(requiredItems); } @@ -404,8 +404,8 @@ namespace Barotrauma.Items.Components body.Enabled = false; item.body = null; - - Msg = prevMsg; + + DisplayMsg = prevMsg; PickKey = prevPickKey; requiredItems = new Dictionary>(prevRequiredItems); @@ -420,7 +420,7 @@ namespace Barotrauma.Items.Components //make the item pickable with the default pick key and with no specific tools/items when it's deattached requiredItems.Clear(); - Msg = ""; + DisplayMsg = ""; PickKey = InputType.Select; } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs index 4e4c77c66..5c0fb03b4 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs @@ -56,9 +56,7 @@ namespace Barotrauma.Items.Components protected const float CorrectionDelay = 1.0f; protected CoroutineHandle delayedCorrectionCoroutine; protected float correctionTimer; - - private string msg; - + [Editable, Serialize(0.0f, false)] public float PickingTime { @@ -191,13 +189,24 @@ namespace Barotrauma.Items.Components { get { return name; } } - - //TODO: this shouldn't be saved as-is, causes tags ("ItemMsgPressSelect" etc) to be converted into actual texts when saving the subs + [Editable, Serialize("", true)] public string Msg { - get { return msg; } - set { msg = value; } + get; + set; + } + + public string DisplayMsg + { + get; + set; + } + + public AITarget AITarget + { + get; + private set; } public AITarget AITarget @@ -238,13 +247,13 @@ namespace Barotrauma.Items.Components { string pickKeyStr = element.GetAttributeString("pickkey", "Select"); pickKeyStr = ToolBox.ConvertInputType(pickKeyStr); - PickKey = (InputType)Enum.Parse(typeof(InputType),pickKeyStr, true); + PickKey = (InputType)Enum.Parse(typeof(InputType), pickKeyStr, true); } catch (Exception e) { DebugConsole.ThrowError("Invalid pick key in " + element + "!", e); } - + SerializableProperties = SerializableProperty.DeserializeProperties(this, element); ParseMsg(); @@ -535,6 +544,7 @@ namespace Barotrauma.Items.Components GameAnalyticsManager.AddErrorEventOnce("ItemComponent.DegreeOfSuccess:CharacterNull", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg); return 0.0f; } + float average = skillSuccessSum / requiredSkills.Count; float skillSuccessSum = 0.0f; for (int i = 0; i < requiredSkills.Count; i++) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 11c413b9b..12141e208 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -1551,14 +1551,14 @@ namespace Barotrauma foreach (ItemComponent ic in components) { - if (string.IsNullOrEmpty(ic.Msg)) continue; + if (string.IsNullOrEmpty(ic.DisplayMsg)) continue; if (!ic.CanBePicked && !ic.CanBeSelected) continue; if (ic is Holdable holdable && !holdable.CanBeDeattached()) continue; Color color = Color.Red; if (ic.HasRequiredSkills(character) && ic.HasRequiredItems(character, false)) color = Color.Orange; - texts.Add(new ColoredText(ic.Msg, color, false)); + texts.Add(new ColoredText(ic.DisplayMsg, color, false)); } return texts;