private void ButtonClicked(CustomInterfaceElement btnElement)
 {
     if (btnElement == null)
     {
         return;
     }
     item.SendSignal(0, btnElement.Signal, btnElement.Connection, sender: null, source: item);
 }
Exemple #2
0
 private void TickBoxToggled(CustomInterfaceElement tickBoxElement, bool state)
 {
     if (tickBoxElement == null)
     {
         return;
     }
     tickBoxElement.State = state;
 }
        public void ServerRead(ClientNetObject type, IReadMessage msg, Client c)
        {
            bool[]   elementStates = new bool[customInterfaceElementList.Count];
            string[] elementValues = new string[customInterfaceElementList.Count];
            for (int i = 0; i < customInterfaceElementList.Count; i++)
            {
                if (customInterfaceElementList[i].HasPropertyName)
                {
                    elementValues[i] = msg.ReadString();
                }
                else
                {
                    elementStates[i] = msg.ReadBoolean();
                }
            }

            CustomInterfaceElement clickedButton = null;

            if ((c.Character != null && DrawHudWhenEquipped && item.ParentInventory?.Owner == c.Character) || item.CanClientAccess(c))
            {
                for (int i = 0; i < customInterfaceElementList.Count; i++)
                {
                    if (customInterfaceElementList[i].HasPropertyName)
                    {
                        if (!customInterfaceElementList[i].IsIntegerInput)
                        {
                            TextChanged(customInterfaceElementList[i], elementValues[i]);
                        }
                        else
                        {
                            int.TryParse(elementValues[i], out int value);
                            ValueChanged(customInterfaceElementList[i], value);
                        }
                    }
                    else if (customInterfaceElementList[i].ContinuousSignal)
                    {
                        TickBoxToggled(customInterfaceElementList[i], elementStates[i]);
                    }
                    else if (elementStates[i])
                    {
                        clickedButton = customInterfaceElementList[i];
                        ButtonClicked(customInterfaceElementList[i]);
                    }
                }
            }

            //notify all clients of the new state
            GameMain.Server.CreateEntityEvent(item, new object[]
            {
                NetEntityEvent.Type.ComponentState,
                item.GetComponentIndex(this),
                clickedButton
            });

            item.CreateServerEvent(this);
        }
 private void TextChanged(CustomInterfaceElement textElement, string text)
 {
     textElement.Signal = text;
     foreach (ISerializableEntity e in item.AllPropertyObjects)
     {
         if (e.SerializableProperties.ContainsKey(textElement.PropertyName))
         {
             e.SerializableProperties[textElement.PropertyName].TrySetValue(e, text);
         }
     }
 }
Exemple #5
0
 private void ButtonClicked(CustomInterfaceElement btnElement)
 {
     if (btnElement == null)
     {
         return;
     }
     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);
     }
 }
Exemple #6
0
 private void ButtonClicked(CustomInterfaceElement btnElement)
 {
     if (btnElement == null)
     {
         return;
     }
     if (btnElement.Connection != null)
     {
         item.SendSignal(new Signal(btnElement.Signal, 0, null, item), btnElement.Connection);
     }
     foreach (StatusEffect effect in btnElement.StatusEffects)
     {
         item.ApplyStatusEffect(effect, ActionType.OnUse, 1.0f);
     }
 }
Exemple #7
0
        public void ServerRead(ClientNetObject type, IReadMessage msg, Client c)
        {
            bool[] elementStates = new bool[customInterfaceElementList.Count];
            string[] elementValues = new string[customInterfaceElementList.Count];
            for (int i = 0; i < customInterfaceElementList.Count; i++)
            {
                if (!string.IsNullOrEmpty(customInterfaceElementList[i].PropertyName))
                {
                    elementValues[i] = msg.ReadString();
                }
                else
                {
                    elementStates[i] = msg.ReadBoolean();
                }
            }

            CustomInterfaceElement clickedButton = null;
            if (item.CanClientAccess(c))
            {
                for (int i = 0; i < customInterfaceElementList.Count; i++)
                {
                    if (!string.IsNullOrEmpty(customInterfaceElementList[i].PropertyName))
                    {
                        TextChanged(customInterfaceElementList[i], elementValues[i]);
                    }
                    else if (customInterfaceElementList[i].ContinuousSignal)
                    {
                        TickBoxToggled(customInterfaceElementList[i], elementStates[i]);
                    }
                    else if (elementStates[i])
                    {
                        clickedButton = customInterfaceElementList[i];
                        ButtonClicked(customInterfaceElementList[i]);
                    }
                }
            }

            //notify all clients of the new state
            GameMain.Server.CreateEntityEvent(item, new object[]
            {
                NetEntityEvent.Type.ComponentState,
                item.GetComponentIndex(this),
                clickedButton
            });

            item.CreateServerEvent(this);
        }
        public CustomInterface(Item item, XElement element)
            : base(item, element)
        {
            int i = 0;

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "button":
                case "textbox":
                    var button = new CustomInterfaceElement(subElement)
                    {
                        ContinuousSignal = false
                    };
                    if (string.IsNullOrEmpty(button.Label))
                    {
                        button.Label = "Signal out " + customInterfaceElementList.Count(e => !e.ContinuousSignal);
                    }
                    customInterfaceElementList.Add(button);
                    break;

                case "tickbox":
                    var tickBox = new CustomInterfaceElement(subElement)
                    {
                        ContinuousSignal = true
                    };
                    if (string.IsNullOrEmpty(tickBox.Label))
                    {
                        tickBox.Label = "Signal out " + customInterfaceElementList.Count(e => e.ContinuousSignal);
                    }
                    customInterfaceElementList.Add(tickBox);
                    break;
                }
                i++;
            }
            IsActive = true;
            InitProjSpecific(element);
            Labels  = element.GetAttributeString("labels", "");
            Signals = element.GetAttributeString("signals", "");
        }
 private void ValueChanged(CustomInterfaceElement numberInputElement, int value)
 {
     if (numberInputElement == null)
     {
         return;
     }
     numberInputElement.Signal = value.ToString();
     if (!numberInputElement.TargetOnlyParentProperty)
     {
         foreach (ISerializableEntity e in item.AllPropertyObjects)
         {
             if (!e.SerializableProperties.ContainsKey(numberInputElement.PropertyName))
             {
                 continue;
             }
             e.SerializableProperties[numberInputElement.PropertyName].TrySetValue(e, value);
         }
     }
     else if (SerializableProperties.ContainsKey(numberInputElement.PropertyName))
     {
         SerializableProperties[numberInputElement.PropertyName].TrySetValue(this, value);
     }
 }
 private void TextChanged(CustomInterfaceElement textElement, string text)
 {
     if (textElement == null)
     {
         return;
     }
     textElement.Signal = text;
     if (!textElement.TargetOnlyParentProperty)
     {
         foreach (ISerializableEntity e in item.AllPropertyObjects)
         {
             if (!e.SerializableProperties.ContainsKey(textElement.PropertyName))
             {
                 continue;
             }
             e.SerializableProperties[textElement.PropertyName].TrySetValue(e, text);
         }
     }
     else if (SerializableProperties.ContainsKey(textElement.PropertyName))
     {
         SerializableProperties[textElement.PropertyName].TrySetValue(this, text);
     }
 }