(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).

This commit is contained in:
Joonas Rikkonen
2019-04-08 23:11:56 +03:00
parent 3877c18d0c
commit 71128c27e6
2 changed files with 34 additions and 6 deletions

View File

@@ -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
};

View File

@@ -14,11 +14,21 @@ namespace Barotrauma.Items.Components
public bool State;
public string Label, Connection, Signal;
public List<StatusEffect> StatusEffects = new List<StatusEffect>();
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);
}
}
}
}