From 71128c27e694f603aaee8570b745d7465cfa1fbd Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 8 Apr 2019 23:11:56 +0300 Subject: [PATCH] (7764eef2d) CustomInterfaces can apply status effects when a button is pressed or depending on the state of a tickbox (OnUse when the tickbox is checked, OnSecondaryUse otherwise). --- .../Components/Signal/CustomInterface.cs | 11 ++++--- .../Components/Signal/CustomInterface.cs | 29 +++++++++++++++++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/CustomInterface.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/CustomInterface.cs index fa80285b3..a74b5d3b8 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/CustomInterface.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/CustomInterface.cs @@ -1,6 +1,7 @@ using Barotrauma.Networking; using Lidgren.Network; using Microsoft.Xna.Framework; +using System; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; @@ -15,14 +16,16 @@ namespace Barotrauma.Items.Components { uiElements.Clear(); - GUILayoutGroup paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.8f), GuiFrame.RectTransform, Anchor.Center)) - { RelativeSpacing = 0.05f, Stretch = true }; + GUILayoutGroup paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.8f), GuiFrame.RectTransform, Anchor.Center), + childAnchor: customInterfaceElementList.Count > 1 ? Anchor.TopCenter : Anchor.Center) + { RelativeSpacing = 0.05f }; + float elementSize = Math.Min(1.0f / customInterfaceElementList.Count, 0.5f); foreach (CustomInterfaceElement ciElement in customInterfaceElementList) { if (ciElement.ContinuousSignal) { - var tickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.1f), paddedFrame.RectTransform), ciElement.Label) + var tickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, elementSize), paddedFrame.RectTransform), ciElement.Label) { UserData = ciElement }; @@ -42,7 +45,7 @@ namespace Barotrauma.Items.Components } else { - var btn = new GUIButton(new RectTransform(new Vector2(1.0f, 0.1f), paddedFrame.RectTransform), ciElement.Label) + var btn = new GUIButton(new RectTransform(new Vector2(1.0f, elementSize), paddedFrame.RectTransform), ciElement.Label, style: "GUIButtonLarge") { UserData = ciElement }; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/CustomInterface.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/CustomInterface.cs index 798cf2fe0..1fd9ca9e6 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/CustomInterface.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/CustomInterface.cs @@ -14,11 +14,21 @@ namespace Barotrauma.Items.Components public bool State; public string Label, Connection, Signal; + public List StatusEffects = new List(); + public CustomInterfaceElement(XElement element) { Label = element.GetAttributeString("text", ""); Connection = element.GetAttributeString("connection", ""); Signal = element.GetAttributeString("signal", "1"); + + foreach (XElement subElement in element.Elements()) + { + if (subElement.Name.ToString().ToLowerInvariant() == "statuseffect") + { + StatusEffects.Add(StatusEffect.Load(subElement, parentDebugName: "custom interface element (label " + Label + ")")); + } + } } } @@ -119,7 +129,14 @@ namespace Barotrauma.Items.Components private void ButtonClicked(CustomInterfaceElement btnElement) { if (btnElement == null) return; - item.SendSignal(0, btnElement.Signal, btnElement.Connection, sender: null, source: item); + if (!string.IsNullOrEmpty(btnElement.Connection)) + { + item.SendSignal(0, btnElement.Signal, btnElement.Connection, sender: null, source: item); + } + foreach (StatusEffect effect in btnElement.StatusEffects) + { + item.ApplyStatusEffect(effect, ActionType.OnUse, 1.0f); + } } private void TickBoxToggled(CustomInterfaceElement tickBoxElement, bool state) @@ -134,7 +151,15 @@ namespace Barotrauma.Items.Components { if (!ciElement.ContinuousSignal) { continue; } //TODO: allow changing output when a tickbox is not selected - item.SendSignal(0, ciElement.State ? ciElement.Signal : "0", ciElement.Connection, sender: null, source: item); + if (!string.IsNullOrEmpty(ciElement.Signal)) + { + item.SendSignal(0, ciElement.State ? ciElement.Signal : "0", ciElement.Connection, sender: null, source: item); + } + + foreach (StatusEffect effect in ciElement.StatusEffects) + { + item.ApplyStatusEffect(effect, ciElement.State ? ActionType.OnUse : ActionType.OnSecondaryUse, 1.0f, null, null, true, false); + } } } }