a75a560...814f6c9

commit 814f6c9dd4d48b3931e1d3bcb1918ff79324c1d4
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Wed Mar 20 19:33:18 2019 +0200

    Fixed multiplayer campaign setup UI showing the client's subs instead of the server's (see #1311)

commit 4a3e485dea85aa21037b13fd1b86af4a4ec1a5fd
Author: itchyOwl <lauri.harkanen@gmail.com>
Date:   Wed Mar 20 19:16:17 2019 +0200

    Move new texts in the end of the localization file.

commit 5a8af99afe5aad0b2f5343ca6f923d8c7eb19e68
Author: itchyOwl <lauri.harkanen@gmail.com>
Date:   Wed Mar 20 19:05:43 2019 +0200

    Recreate the editing gui window when resetting the entities with the "resetall" command.

commit 0048e6dcb9699e5b1e434ace867bc8f426cdae28
Author: itchyOwl <lauri.harkanen@gmail.com>
Date:   Wed Mar 20 19:04:42 2019 +0200

    Fix resetting to prefab.

commit 88be0923761f5ac2c895364c8ad0e11fe9a66576
Author: itchyOwl <lauri.harkanen@gmail.com>
Date:   Wed Mar 20 18:40:13 2019 +0200

    Fix item components not being loaded properly.

commit 6f970d54ed800eff25ae3643b03c0020336c8621
Author: itchyOwl <lauri.harkanen@gmail.com>
Date:   Wed Mar 20 18:21:25 2019 +0200

    Add a console command for resetting all items and structures to the prefabs.

commit bd561ef43391a2e4251bef18a8738b233f540961
Merge: e8843c30c a75a56088
Author: itchyOwl <lauri.harkanen@gmail.com>
Date:   Wed Mar 20 17:47:14 2019 +0200

    Merge branch 'dev' of https://github.com/Regalis11/Barotrauma-development into dev

commit e8843c30cdb966832236ec361494e4c886130590
Author: itchyOwl <lauri.harkanen@gmail.com>
Date:   Wed Mar 20 17:46:38 2019 +0200

    Implement item and structure instance resetting to prefab. Add buttons in the subeditor. Allow to save the msg text in the editor.
This commit is contained in:
Joonas Rikkonen
2019-03-20 19:34:53 +02:00
parent 579e7f9abc
commit c78546b5f4
14 changed files with 187 additions and 170 deletions
@@ -525,6 +525,28 @@ namespace Barotrauma
} }
}, isCheat: true)); }, isCheat: true));
commands.Add(new Command("resetall", "Reset all items and structures to prefabs. Only applicable in the subeditor.", args =>
{
if (Screen.Selected == GameMain.SubEditorScreen)
{
Item.ItemList.ForEach(i => i.Reset());
Structure.WallList.ForEach(s => s.Reset());
foreach (MapEntity entity in MapEntity.SelectedList)
{
if (entity is Item item)
{
item.CreateEditingHUD();
break;
}
else if (entity is Structure structure)
{
structure.CreateEditingHUD();
break;
}
}
}
}));
commands.Add(new Command("alpha", "Change the alpha (as bytes from 0 to 255) of the selected item/structure instances. Applied only in the subeditor.", (string[] args) => commands.Add(new Command("alpha", "Change the alpha (as bytes from 0 to 255) of the selected item/structure instances. Applied only in the subeditor.", (string[] args) =>
{ {
if (Screen.Selected == GameMain.SubEditorScreen) if (Screen.Selected == GameMain.SubEditorScreen)
@@ -12,7 +12,7 @@ namespace Barotrauma
{ {
private UInt16 startWatchmanID, endWatchmanID; private UInt16 startWatchmanID, endWatchmanID;
public static GUIComponent StartCampaignSetup(IEnumerable<string> saveFiles) public static GUIComponent StartCampaignSetup( IEnumerable<Submarine> submarines, IEnumerable<string> saveFiles)
{ {
GUIFrame background = new GUIFrame(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker"); GUIFrame background = new GUIFrame(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker");
@@ -35,7 +35,7 @@ namespace Barotrauma
var newCampaignContainer = new GUIFrame(new RectTransform(Vector2.One, campaignContainer.RectTransform, Anchor.BottomLeft), style: null); var newCampaignContainer = new GUIFrame(new RectTransform(Vector2.One, campaignContainer.RectTransform, Anchor.BottomLeft), style: null);
var loadCampaignContainer = new GUIFrame(new RectTransform(Vector2.One, campaignContainer.RectTransform, Anchor.BottomLeft), style: null); var loadCampaignContainer = new GUIFrame(new RectTransform(Vector2.One, campaignContainer.RectTransform, Anchor.BottomLeft), style: null);
var campaignSetupUI = new CampaignSetupUI(true, newCampaignContainer, loadCampaignContainer, saveFiles); var campaignSetupUI = new CampaignSetupUI(true, newCampaignContainer, loadCampaignContainer, submarines, saveFiles);
var newCampaignButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonContainer.RectTransform), var newCampaignButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonContainer.RectTransform),
TextManager.Get("NewCampaign")) TextManager.Get("NewCampaign"))
@@ -313,7 +313,7 @@ namespace Barotrauma.Items.Components
if (sound == null) { return 0.0f; } if (sound == null) { return 0.0f; }
if (sound.VolumeProperty == "") { return sound.VolumeMultiplier; } if (sound.VolumeProperty == "") { return sound.VolumeMultiplier; }
if (properties.TryGetValue(sound.VolumeProperty, out SerializableProperty property)) if (SerializableProperties.TryGetValue(sound.VolumeProperty, out SerializableProperty property))
{ {
float newVolume = 0.0f; float newVolume = 0.0f;
try try
@@ -486,5 +486,18 @@ namespace Barotrauma.Items.Components
yield return CoroutineStatus.Success; yield return CoroutineStatus.Success;
} }
partial void ParseMsg()
{
string msg = TextManager.Get(Msg, true);
if (msg != null)
{
foreach (InputType inputType in Enum.GetValues(typeof(InputType)))
{
msg = msg.Replace("[" + inputType.ToString().ToLowerInvariant() + "]", GameMain.Config.KeyBind(inputType).ToString());
}
Msg = msg;
}
}
} }
} }
@@ -448,7 +448,7 @@ namespace Barotrauma
} }
} }
private GUIComponent CreateEditingHUD(bool inGame = false) public GUIComponent CreateEditingHUD(bool inGame = false)
{ {
editingHUD = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.25f), GUI.Canvas, Anchor.CenterRight) { MinSize = new Point(400, 0) }) { UserData = this }; editingHUD = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.25f), GUI.Canvas, Anchor.CenterRight) { MinSize = new Point(400, 0) }) { UserData = this };
GUIListBox listBox = new GUIListBox(new RectTransform(new Vector2(0.95f, 0.8f), editingHUD.RectTransform, Anchor.Center), style: null) GUIListBox listBox = new GUIListBox(new RectTransform(new Vector2(0.95f, 0.8f), editingHUD.RectTransform, Anchor.Center), style: null)
@@ -457,40 +457,38 @@ namespace Barotrauma
}; };
var itemEditor = new SerializableEntityEditor(listBox.Content.RectTransform, this, inGame, showName: true); var itemEditor = new SerializableEntityEditor(listBox.Content.RectTransform, this, inGame, showName: true);
if (!inGame && Linkable)
{
var linkText = new GUITextBlock(new RectTransform(new Point(editingHUD.Rect.Width, 20)), TextManager.Get("HoldToLink"), font: GUI.SmallFont);
var itemsText = new GUITextBlock(new RectTransform(new Point(editingHUD.Rect.Width, 20)), TextManager.Get("AllowedLinks") + ": ", font: GUI.SmallFont);
if (AllowedLinks.None())
{
itemsText.Text += TextManager.Get("None");
}
else
{
for (int i = 0; i < AllowedLinks.Count; i++)
{
itemsText.Text += AllowedLinks[i];
if (i < AllowedLinks.Count - 1)
{
itemsText.Text += ", ";
}
}
}
itemEditor.AddCustomContent(linkText, 1);
itemEditor.AddCustomContent(itemsText, 2);
linkText.TextColor = Color.Yellow;
itemsText.TextColor = Color.Yellow;
}
if (!inGame) if (!inGame)
{ {
if (Linkable)
{
var linkText = new GUITextBlock(new RectTransform(new Point(editingHUD.Rect.Width, 20)), TextManager.Get("HoldToLink"), font: GUI.SmallFont);
var itemsText = new GUITextBlock(new RectTransform(new Point(editingHUD.Rect.Width, 20)), TextManager.Get("AllowedLinks") + ": ", font: GUI.SmallFont);
if (AllowedLinks.None())
{
itemsText.Text += TextManager.Get("None");
}
else
{
for (int i = 0; i < AllowedLinks.Count; i++)
{
itemsText.Text += AllowedLinks[i];
if (i < AllowedLinks.Count - 1)
{
itemsText.Text += ", ";
}
}
}
itemEditor.AddCustomContent(linkText, 1);
itemEditor.AddCustomContent(itemsText, 2);
linkText.TextColor = Color.Yellow;
itemsText.TextColor = Color.Yellow;
}
var buttonContainer = new GUILayoutGroup(new RectTransform(new Point(listBox.Content.Rect.Width, 20)), isHorizontal: true) var buttonContainer = new GUILayoutGroup(new RectTransform(new Point(listBox.Content.Rect.Width, 20)), isHorizontal: true)
{ {
Stretch = true, Stretch = true,
RelativeSpacing = 0.02f RelativeSpacing = 0.02f
}; };
new GUIButton(new RectTransform(new Vector2(0.25f, 1.0f), buttonContainer.RectTransform), TextManager.Get("MirrorEntityX")) new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("MirrorEntityX"))
{ {
ToolTip = TextManager.Get("MirrorEntityXToolTip"), ToolTip = TextManager.Get("MirrorEntityXToolTip"),
OnClicked = (button, data) => OnClicked = (button, data) =>
@@ -499,7 +497,7 @@ namespace Barotrauma
return true; return true;
} }
}; };
new GUIButton(new RectTransform(new Vector2(0.25f, 1.0f), buttonContainer.RectTransform), TextManager.Get("MirrorEntityY")) new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("MirrorEntityY"))
{ {
ToolTip = TextManager.Get("MirrorEntityYToolTip"), ToolTip = TextManager.Get("MirrorEntityYToolTip"),
OnClicked = (button, data) => OnClicked = (button, data) =>
@@ -510,7 +508,7 @@ namespace Barotrauma
}; };
if (Sprite != null) if (Sprite != null)
{ {
var reloadTextureButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonContainer.RectTransform), TextManager.Get("ReloadSprite")); var reloadTextureButton = new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("ReloadSprite"));
reloadTextureButton.OnClicked += (button, data) => reloadTextureButton.OnClicked += (button, data) =>
{ {
Sprite.ReloadXML(); Sprite.ReloadXML();
@@ -518,6 +516,15 @@ namespace Barotrauma
return true; return true;
}; };
} }
new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("ResetToPrefab"))
{
OnClicked = (button, data) =>
{
Reset();
CreateEditingHUD();
return true;
}
};
itemEditor.AddCustomContent(buttonContainer, itemEditor.ContentCount); itemEditor.AddCustomContent(buttonContainer, itemEditor.ContentCount);
} }
@@ -87,7 +87,7 @@ namespace Barotrauma
} }
} }
private GUIComponent CreateEditingHUD(bool inGame = false) public GUIComponent CreateEditingHUD(bool inGame = false)
{ {
editingHUD = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.25f), GUI.Canvas, Anchor.CenterRight) { MinSize = new Point(400, 0) }) { UserData = this }; editingHUD = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.25f), GUI.Canvas, Anchor.CenterRight) { MinSize = new Point(400, 0) }) { UserData = this };
GUIListBox listBox = new GUIListBox(new RectTransform(new Vector2(0.95f, 0.8f), editingHUD.RectTransform, Anchor.Center), style: null); GUIListBox listBox = new GUIListBox(new RectTransform(new Vector2(0.95f, 0.8f), editingHUD.RectTransform, Anchor.Center), style: null);
@@ -98,7 +98,7 @@ namespace Barotrauma
Stretch = true, Stretch = true,
RelativeSpacing = 0.02f RelativeSpacing = 0.02f
}; };
new GUIButton(new RectTransform(new Vector2(0.25f, 1.0f), buttonContainer.RectTransform), TextManager.Get("MirrorEntityX")) new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("MirrorEntityX"))
{ {
ToolTip = TextManager.Get("MirrorEntityXToolTip"), ToolTip = TextManager.Get("MirrorEntityXToolTip"),
OnClicked = (button, data) => OnClicked = (button, data) =>
@@ -107,7 +107,7 @@ namespace Barotrauma
return true; return true;
} }
}; };
new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonContainer.RectTransform), TextManager.Get("MirrorEntityY")) new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("MirrorEntityY"))
{ {
ToolTip = TextManager.Get("MirrorEntityYToolTip"), ToolTip = TextManager.Get("MirrorEntityYToolTip"),
OnClicked = (button, data) => OnClicked = (button, data) =>
@@ -116,7 +116,7 @@ namespace Barotrauma
return true; return true;
} }
}; };
var reloadTextureButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonContainer.RectTransform), TextManager.Get("ReloadSprite")) var reloadTextureButton = new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("ReloadSprite"))
{ {
OnClicked = (button, data) => OnClicked = (button, data) =>
{ {
@@ -125,6 +125,15 @@ namespace Barotrauma
return true; return true;
} }
}; };
new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("ResetToPrefab"))
{
OnClicked = (button, data) =>
{
Reset();
CreateEditingHUD();
return true;
}
};
editor.AddCustomContent(buttonContainer, editor.ContentCount); editor.AddCustomContent(buttonContainer, editor.ContentCount);
PositionEditingHUD(); PositionEditingHUD();
@@ -40,6 +40,8 @@ namespace Barotrauma.Networking
private List<Client> otherClients; private List<Client> otherClients;
private readonly List<Submarine> serverSubmarines = new List<Submarine>();
private string serverIP; private string serverIP;
private bool needAuth; private bool needAuth;
@@ -779,7 +781,7 @@ namespace Barotrauma.Networking
saveFiles.Add(inc.ReadString()); saveFiles.Add(inc.ReadString());
} }
GameMain.NetLobbyScreen.CampaignSetupUI = MultiPlayerCampaign.StartCampaignSetup(saveFiles); GameMain.NetLobbyScreen.CampaignSetupUI = MultiPlayerCampaign.StartCampaignSetup(serverSubmarines, saveFiles);
break; break;
case ServerPacketHeader.PERMISSIONS: case ServerPacketHeader.PERMISSIONS:
ReadPermissions(inc); ReadPermissions(inc);
@@ -1162,7 +1164,7 @@ namespace Barotrauma.Networking
VoipClient = new VoipClient(this, client); VoipClient = new VoipClient(this, client);
UInt16 subListCount = inc.ReadUInt16(); UInt16 subListCount = inc.ReadUInt16();
List<Submarine> submarines = new List<Submarine>(); serverSubmarines.Clear();
for (int i = 0; i < subListCount; i++) for (int i = 0; i < subListCount; i++)
{ {
string subName = inc.ReadString(); string subName = inc.ReadString();
@@ -1171,16 +1173,16 @@ namespace Barotrauma.Networking
var matchingSub = Submarine.SavedSubmarines.FirstOrDefault(s => s.Name == subName && s.MD5Hash.Hash == subHash); var matchingSub = Submarine.SavedSubmarines.FirstOrDefault(s => s.Name == subName && s.MD5Hash.Hash == subHash);
if (matchingSub != null) if (matchingSub != null)
{ {
submarines.Add(matchingSub); serverSubmarines.Add(matchingSub);
} }
else else
{ {
submarines.Add(new Submarine(Path.Combine(Submarine.SavePath, subName) + ".sub", subHash, false)); serverSubmarines.Add(new Submarine(Path.Combine(Submarine.SavePath, subName) + ".sub", subHash, false));
} }
} }
GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.SubList, submarines); GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.SubList, serverSubmarines);
GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.ShuttleList.ListBox, submarines); GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.ShuttleList.ListBox, serverSubmarines);
gameStarted = inc.ReadBoolean(); gameStarted = inc.ReadBoolean();
bool allowSpectating = inc.ReadBoolean(); bool allowSpectating = inc.ReadBoolean();
@@ -31,14 +31,14 @@ namespace Barotrauma
} }
} }
private bool isMultiplayer; private readonly bool isMultiplayer;
public CampaignSetupUI(bool isMultiplayer, GUIComponent newGameContainer, GUIComponent loadGameContainer, IEnumerable<string> saveFiles=null) public CampaignSetupUI(bool isMultiplayer, GUIComponent newGameContainer, GUIComponent loadGameContainer, IEnumerable<Submarine> submarines, IEnumerable<string> saveFiles = null)
{ {
this.isMultiplayer = isMultiplayer; this.isMultiplayer = isMultiplayer;
this.newGameContainer = newGameContainer; this.newGameContainer = newGameContainer;
this.loadGameContainer = loadGameContainer; this.loadGameContainer = loadGameContainer;
var columnContainer = new GUILayoutGroup(new RectTransform(Vector2.One, newGameContainer.RectTransform), isHorizontal: true) var columnContainer = new GUILayoutGroup(new RectTransform(Vector2.One, newGameContainer.RectTransform), isHorizontal: true)
{ {
Stretch = true, Stretch = true,
@@ -60,7 +60,7 @@ namespace Barotrauma
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), leftColumn.RectTransform), TextManager.Get("SelectedSub") + ":", textAlignment: Alignment.BottomLeft); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), leftColumn.RectTransform), TextManager.Get("SelectedSub") + ":", textAlignment: Alignment.BottomLeft);
subList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.65f), leftColumn.RectTransform)); subList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.65f), leftColumn.RectTransform));
UpdateSubList(); UpdateSubList(submarines);
// New game right side // New game right side
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), rightColumn.RectTransform), TextManager.Get("SaveName") + ":", textAlignment: Alignment.BottomLeft); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), rightColumn.RectTransform), TextManager.Get("SaveName") + ":", textAlignment: Alignment.BottomLeft);
@@ -87,9 +87,8 @@ namespace Barotrauma
return false; return false;
} }
Submarine selectedSub = subList.SelectedData as Submarine; if (!(subList.SelectedData is Submarine selectedSub)) { return false; }
if (selectedSub == null) return false;
if (string.IsNullOrEmpty(selectedSub.MD5Hash.Hash)) if (string.IsNullOrEmpty(selectedSub.MD5Hash.Hash))
{ {
((GUITextBlock)subList.SelectedComponent).TextColor = Color.DarkRed * 0.8f; ((GUITextBlock)subList.SelectedComponent).TextColor = Color.DarkRed * 0.8f;
@@ -193,12 +192,12 @@ namespace Barotrauma
saveNameBox.Text = Path.GetFileNameWithoutExtension(savePath); saveNameBox.Text = Path.GetFileNameWithoutExtension(savePath);
} }
public void UpdateSubList() public void UpdateSubList(IEnumerable<Submarine> submarines)
{ {
#if DEBUG #if DEBUG
var subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus)); var subsToShow = submarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus));
#else #else
var subsToShow = Submarine.SavedSubmarines; var subsToShow = submarines;
#endif #endif
subList.ClearChildren(); subList.ClearChildren();
@@ -282,7 +282,7 @@ namespace Barotrauma
menuTabs[(int)Tab.LoadGame] = new GUIFrame(new RectTransform(relativeSize, GUI.Canvas, anchor, pivot, minSize, maxSize)); menuTabs[(int)Tab.LoadGame] = new GUIFrame(new RectTransform(relativeSize, GUI.Canvas, anchor, pivot, minSize, maxSize));
var paddedLoadGame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), menuTabs[(int)Tab.LoadGame].RectTransform, Anchor.Center), style: null); var paddedLoadGame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), menuTabs[(int)Tab.LoadGame].RectTransform, Anchor.Center), style: null);
campaignSetupUI = new CampaignSetupUI(false, paddedNewGame, paddedLoadGame) campaignSetupUI = new CampaignSetupUI(false, paddedNewGame, paddedLoadGame, Submarine.SavedSubmarines)
{ {
LoadGame = LoadGame, LoadGame = LoadGame,
StartNewGame = StartGame StartNewGame = StartGame
@@ -336,7 +336,7 @@ namespace Barotrauma
UpdateTutorialList(); UpdateTutorialList();
campaignSetupUI.UpdateSubList(); campaignSetupUI.UpdateSubList(Submarine.SavedSubmarines);
ResetButtonStates(null); ResetButtonStates(null);
@@ -712,6 +712,7 @@ namespace Barotrauma
} }
Body closestBody = Submarine.CheckVisibility(rayStart, rayEnd); Body closestBody = Submarine.CheckVisibility(rayStart, rayEnd);
if (Submarine.LastPickedFraction == 1.0f || closestBody == null) if (Submarine.LastPickedFraction == 1.0f || closestBody == null)
{ {
return; return;
@@ -462,10 +462,7 @@ namespace Barotrauma.Items.Components
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f) public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f)
{ {
if (componentElement == null) return; if (isStuck) return;
base.Load(componentElement);
var prevRequiredItems = new Dictionary<RelatedItem.RelationType, List<RelatedItem>>(requiredItems);
bool overrideRequiredItems = false;
bool wasOpen = PredictedState == null ? isOpen : PredictedState.Value; bool wasOpen = PredictedState == null ? isOpen : PredictedState.Value;
@@ -51,6 +51,8 @@ namespace Barotrauma.Items.Components
public ItemComponent Parent; public ItemComponent Parent;
public readonly XElement originalElement;
protected const float CorrectionDelay = 1.0f; protected const float CorrectionDelay = 1.0f;
protected CoroutineHandle delayedCorrectionCoroutine; protected CoroutineHandle delayedCorrectionCoroutine;
protected float correctionTimer; protected float correctionTimer;
@@ -64,11 +66,7 @@ namespace Barotrauma.Items.Components
set; set;
} }
public readonly Dictionary<string, SerializableProperty> properties; public Dictionary<string, SerializableProperty> SerializableProperties { get; protected set; }
public Dictionary<string, SerializableProperty> SerializableProperties
{
get { return properties; }
}
public virtual bool IsActive public virtual bool IsActive
{ {
@@ -194,7 +192,7 @@ namespace Barotrauma.Items.Components
get { return name; } get { return name; }
} }
[Editable, Serialize("", false)] [Editable, Serialize("", true)]
public string Msg public string Msg
{ {
get { return msg; } get { return msg; }
@@ -210,8 +208,9 @@ namespace Barotrauma.Items.Components
public ItemComponent(Item item, XElement element) public ItemComponent(Item item, XElement element)
{ {
this.item = item; this.item = item;
originalElement = element;
name = element.Name.ToString(); name = element.Name.ToString();
properties = SerializableProperty.GetProperties(this); SerializableProperties = SerializableProperty.GetProperties(this);
requiredItems = new Dictionary<RelatedItem.RelationType, List<RelatedItem>>(); requiredItems = new Dictionary<RelatedItem.RelationType, List<RelatedItem>>();
requiredSkills = new List<Skill>(); requiredSkills = new List<Skill>();
@@ -245,18 +244,9 @@ namespace Barotrauma.Items.Components
DebugConsole.ThrowError("Invalid pick key in " + element + "!", e); DebugConsole.ThrowError("Invalid pick key in " + element + "!", e);
} }
properties = SerializableProperty.DeserializeProperties(this, element); SerializableProperties = SerializableProperty.DeserializeProperties(this, element);
#if CLIENT ParseMsg();
string msg = TextManager.Get(Msg, true);
if (msg != null)
{
foreach (InputType inputType in Enum.GetValues(typeof(InputType)))
{
msg = msg.Replace("[" + inputType.ToString().ToLowerInvariant() + "]", GameMain.Config.KeyBind(inputType).ToString());
}
Msg = msg;
}
#endif
foreach (XElement subElement in element.Elements()) foreach (XElement subElement in element.Elements())
{ {
switch (subElement.Name.ToString().ToLowerInvariant()) switch (subElement.Name.ToString().ToLowerInvariant())
@@ -318,7 +308,6 @@ namespace Barotrauma.Items.Components
item.AddComponent(ic); item.AddComponent(ic);
break; break;
} }
} }
} }
@@ -623,87 +612,13 @@ namespace Barotrauma.Items.Components
public virtual void Load(XElement componentElement) public virtual void Load(XElement componentElement)
{ {
if (componentElement == null) return; if (componentElement == null) return;
foreach (XAttribute attribute in componentElement.Attributes()) foreach (XAttribute attribute in componentElement.Attributes())
{ {
if (!properties.TryGetValue(attribute.Name.ToString().ToLowerInvariant(), out SerializableProperty property)) continue; if (!SerializableProperties.TryGetValue(attribute.Name.ToString().ToLowerInvariant(), out SerializableProperty property)) continue;
property.TrySetValue(this, attribute.Value); property.TrySetValue(this, attribute.Value);
} }
#if CLIENT ParseMsg();
string msg = TextManager.Get(Msg, true); OverrideRequiredItems(componentElement);
if (msg != null)
{
foreach (InputType inputType in Enum.GetValues(typeof(InputType)))
{
msg = msg.Replace("[" + inputType.ToString().ToLowerInvariant() + "]", GameMain.Config.KeyBind(inputType).ToString());
}
Msg = msg;
}
#endif
var prevRequiredItems = new Dictionary<RelatedItem.RelationType, List<RelatedItem>>(requiredItems);
bool overrideRequiredItems = false;
foreach (XElement subElement in componentElement.Elements())
{
foreach (InputType inputType in Enum.GetValues(typeof(InputType)))
{
case "requireditem":
if (!overrideRequiredItems) requiredItems.Clear();
overrideRequiredItems = true;
RelatedItem newRequiredItem = RelatedItem.Load(subElement, item.Name);
if (newRequiredItem == null) continue;
var prevRequiredItem = prevRequiredItems.ContainsKey(newRequiredItem.Type) ?
prevRequiredItems[newRequiredItem.Type].Find(ri => ri.JoinedIdentifiers == newRequiredItem.JoinedIdentifiers) : null;
if (prevRequiredItem != null)
{
newRequiredItem.statusEffects = prevRequiredItem.statusEffects;
newRequiredItem.Msg = prevRequiredItem.Msg;
}
if (!requiredItems.ContainsKey(newRequiredItem.Type))
{
requiredItems[newRequiredItem.Type] = new List<RelatedItem>();
}
requiredItems[newRequiredItem.Type].Add(newRequiredItem);
break;
}
Msg = msg;
}
#endif
// Only door override required items
//var prevRequiredItems = new Dictionary<RelatedItem.RelationType, List<RelatedItem>>(requiredItems);
//bool overrideRequiredItems = false;
//foreach (XElement subElement in componentElement.Elements())
//{
// switch (subElement.Name.ToString().ToLowerInvariant())
// {
// case "requireditem":
// if (!overrideRequiredItems) requiredItems.Clear();
// overrideRequiredItems = true;
// RelatedItem newRequiredItem = RelatedItem.Load(subElement, item.Name);
// if (newRequiredItem == null) continue;
// var prevRequiredItem = prevRequiredItems.ContainsKey(newRequiredItem.Type) ?
// prevRequiredItems[newRequiredItem.Type].Find(ri => ri.JoinedIdentifiers == newRequiredItem.JoinedIdentifiers) : null;
// if (prevRequiredItem != null)
// {
// newRequiredItem.statusEffects = prevRequiredItem.statusEffects;
// newRequiredItem.Msg = prevRequiredItem.Msg;
// }
// if (!requiredItems.ContainsKey(newRequiredItem.Type))
// {
// requiredItems[newRequiredItem.Type] = new List<RelatedItem>();
// }
// requiredItems[newRequiredItem.Type].Add(newRequiredItem);
// break;
// }
//}
} }
/// <summary> /// <summary>
@@ -794,5 +709,47 @@ namespace Barotrauma.Items.Components
parentElement.Add(componentElement); parentElement.Add(componentElement);
return componentElement; return componentElement;
} }
public virtual void Reset()
{
SerializableProperties = SerializableProperty.DeserializeProperties(this, originalElement);
ParseMsg();
OverrideRequiredItems(originalElement);
}
private void OverrideRequiredItems(XElement element)
{
var prevRequiredItems = new Dictionary<RelatedItem.RelationType, List<RelatedItem>>(requiredItems);
bool overrideRequiredItems = false;
foreach (XElement subElement in element.Elements())
{
switch (subElement.Name.ToString().ToLowerInvariant())
{
case "requireditem":
if (!overrideRequiredItems) requiredItems.Clear();
overrideRequiredItems = true;
RelatedItem newRequiredItem = RelatedItem.Load(subElement, item.Name);
if (newRequiredItem == null) continue;
var prevRequiredItem = prevRequiredItems.ContainsKey(newRequiredItem.Type) ?
prevRequiredItems[newRequiredItem.Type].Find(ri => ri.JoinedIdentifiers == newRequiredItem.JoinedIdentifiers) : null;
if (prevRequiredItem != null)
{
newRequiredItem.statusEffects = prevRequiredItem.statusEffects;
newRequiredItem.Msg = prevRequiredItem.Msg;
}
if (!requiredItems.ContainsKey(newRequiredItem.Type))
{
requiredItems[newRequiredItem.Type] = new List<RelatedItem>();
}
requiredItems[newRequiredItem.Type].Add(newRequiredItem);
break;
}
}
}
partial void ParseMsg();
} }
} }
@@ -76,11 +76,7 @@ namespace Barotrauma
//a dictionary containing lists of the status effects in all the components of the item //a dictionary containing lists of the status effects in all the components of the item
private Dictionary<ActionType, List<StatusEffect>> statusEffectLists; private Dictionary<ActionType, List<StatusEffect>> statusEffectLists;
public readonly Dictionary<string, SerializableProperty> properties; public Dictionary<string, SerializableProperty> SerializableProperties { get; protected set; }
public Dictionary<string, SerializableProperty> SerializableProperties
{
get { return properties; }
}
private bool? hasInGameEditableProperties; private bool? hasInGameEditableProperties;
bool HasInGameEditableProperties bool HasInGameEditableProperties
@@ -90,7 +86,7 @@ namespace Barotrauma
if (hasInGameEditableProperties == null) if (hasInGameEditableProperties == null)
{ {
hasInGameEditableProperties = false; hasInGameEditableProperties = false;
if (properties.Values.Any(p => p.Attributes.OfType<InGameEditable>().Any())) if (SerializableProperties.Values.Any(p => p.Attributes.OfType<InGameEditable>().Any()))
{ {
hasInGameEditableProperties = true; hasInGameEditableProperties = true;
} }
@@ -99,7 +95,7 @@ namespace Barotrauma
foreach (ItemComponent component in components) foreach (ItemComponent component in components)
{ {
if (!component.AllowInGameEditing) { continue; } if (!component.AllowInGameEditing) { continue; }
if (component.properties.Values.Any(p => p.Attributes.OfType<InGameEditable>().Any())) if (component.SerializableProperties.Values.Any(p => p.Attributes.OfType<InGameEditable>().Any()))
{ {
hasInGameEditableProperties = true; hasInGameEditableProperties = true;
break; break;
@@ -468,8 +464,8 @@ namespace Barotrauma
XElement element = itemPrefab.ConfigElement; XElement element = itemPrefab.ConfigElement;
if (element == null) return; if (element == null) return;
properties = SerializableProperty.DeserializeProperties(this, element); SerializableProperties = SerializableProperty.DeserializeProperties(this, element);
if (submarine == null || !submarine.Loading) FindHull(); if (submarine == null || !submarine.Loading) FindHull();
@@ -586,10 +582,10 @@ namespace Barotrauma
public override MapEntity Clone() public override MapEntity Clone()
{ {
Item clone = new Item(rect, Prefab, Submarine, callOnItemLoaded: false); Item clone = new Item(rect, Prefab, Submarine, callOnItemLoaded: false);
foreach (KeyValuePair<string, SerializableProperty> property in properties) foreach (KeyValuePair<string, SerializableProperty> property in SerializableProperties)
{ {
if (!property.Value.Attributes.OfType<Editable>().Any()) continue; if (!property.Value.Attributes.OfType<Editable>().Any()) continue;
clone.properties[property.Key].TrySetValue(clone, property.Value.GetValue(this)); clone.SerializableProperties[property.Key].TrySetValue(clone, property.Value.GetValue(this));
} }
if (components.Count != clone.components.Count) if (components.Count != clone.components.Count)
@@ -603,10 +599,10 @@ namespace Barotrauma
for (int i = 0; i < components.Count && i < clone.components.Count; i++) for (int i = 0; i < components.Count && i < clone.components.Count; i++)
{ {
foreach (KeyValuePair<string, SerializableProperty> property in components[i].properties) foreach (KeyValuePair<string, SerializableProperty> property in components[i].SerializableProperties)
{ {
if (!property.Value.Attributes.OfType<Editable>().Any()) continue; if (!property.Value.Attributes.OfType<Editable>().Any()) continue;
clone.components[i].properties[property.Key].TrySetValue(clone.components[i], property.Value.GetValue(components[i])); clone.components[i].SerializableProperties[property.Key].TrySetValue(clone.components[i], property.Value.GetValue(components[i]));
} }
//clone requireditem identifiers //clone requireditem identifiers
@@ -1881,7 +1877,7 @@ namespace Barotrauma
foreach (XAttribute attribute in element.Attributes()) foreach (XAttribute attribute in element.Attributes())
{ {
if (!item.properties.TryGetValue(attribute.Name.ToString(), out SerializableProperty property)) continue; if (!item.SerializableProperties.TryGetValue(attribute.Name.ToString(), out SerializableProperty property)) continue;
bool shouldBeLoaded = false; bool shouldBeLoaded = false;
foreach (var propertyAttribute in property.Attributes.OfType<Serialize>()) foreach (var propertyAttribute in property.Attributes.OfType<Serialize>())
{ {
@@ -1974,6 +1970,12 @@ namespace Barotrauma
return element; return element;
} }
public virtual void Reset()
{
SerializableProperties = SerializableProperty.DeserializeProperties(this, Prefab.ConfigElement);
components.ForEach(c => c.Reset());
}
public override void OnMapLoaded() public override void OnMapLoaded()
{ {
FindHull(); FindHull();
@@ -1193,5 +1193,10 @@ namespace Barotrauma
SetDamage(i, Sections[i].damage, createNetworkEvent: false); SetDamage(i, Sections[i].damage, createNetworkEvent: false);
} }
} }
public virtual void Reset()
{
SerializableProperties = SerializableProperty.DeserializeProperties(this, Prefab.ConfigElement);
}
} }
} }
@@ -8,6 +8,8 @@ namespace Barotrauma
{ {
partial class StructurePrefab : MapEntityPrefab partial class StructurePrefab : MapEntityPrefab
{ {
public XElement ConfigElement { get; private set; }
private bool canSpriteFlipX, canSpriteFlipY; private bool canSpriteFlipX, canSpriteFlipY;
private float health; private float health;
@@ -150,6 +152,7 @@ namespace Barotrauma
{ {
name = element.GetAttributeString("name", "") name = element.GetAttributeString("name", "")
}; };
sp.ConfigElement = element;
if (string.IsNullOrEmpty(sp.name)) sp.name = element.Name.ToString(); if (string.IsNullOrEmpty(sp.name)) sp.name = element.Name.ToString();
sp.identifier = element.GetAttributeString("identifier", ""); sp.identifier = element.GetAttributeString("identifier", "");