public override void UpdateOnceBeforeFrame()
        {
            base.UpdateOnceBeforeFrame();
            IsCountingDown = false;
            if (Sync.IsServer)
            {
                for (int i = 0; i < Toolbar.ItemCount; ++i)
                {
                    Toolbar.UpdateItem(i);
                    Toolbar.ActivateItemAtIndex(i);
                }

                //Visual scripting action
                if (CubeGrid.Physics != null && MyVisualScriptLogicProvider.TimerBlockTriggered != null)
                {
                    MyVisualScriptLogicProvider.TimerBlockTriggered(CustomName.ToString());
                }
                if (CubeGrid.Physics != null && !string.IsNullOrEmpty(Name) && MyVisualScriptLogicProvider.TimerBlockTriggeredEntityName != null)
                {
                    MyVisualScriptLogicProvider.TimerBlockTriggeredEntityName(Name);
                }
            }
            UpdateEmissivity();
            DetailedInfo.Clear();
            RaisePropertiesChanged();
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            var ob = (MyObjectBuilder_TerminalBlock)objectBuilder;

            if (ob.CustomName != null)
            {
                CustomName.Clear().Append(ob.CustomName);
                DisplayNameText = ob.CustomName;
            }
            else
            {
                CustomName.Clear();
                GetTerminalName(CustomName);
            }

            if (Sync.IsServer && Sync.Clients != null)
            {
                Sync.Clients.ClientRemoved += ClientRemoved;
            }

            ShowOnHUD           = ob.ShowOnHUD;
            ShowInTerminal      = ob.ShowInTerminal;
            ShowInInventory     = ob.ShowInInventory;
            ShowInToolbarConfig = ob.ShowInToolbarConfig;
            AddDebugRenderComponent(new MyDebugRenderComponentTerminal(this));
        }
Example #3
0
    public void AddNewCustomNameComponent1(CustomName newValue)
    {
        var component = CreateComponent <NewCustomNameComponent1Component>(TestComponentsLookup.NewCustomNameComponent1);

        component.value = newValue;
        AddComponent(TestComponentsLookup.NewCustomNameComponent1, component);
    }
Example #4
0
 //
 // Constructors
 //
 public Name(CustomName name)
 {
     s  = name.FullSingular;
     p  = name.FullPlural;
     a  = name.AbbreviatedSingular;
     ap = name.AbbreviatedPlural;
 }
Example #5
0
        public string GetPersonName(TDBasePersonData person)
        {
            string ret       = "";
            string splite    = "";
            string firstName = "";

            if (!BaseLanguageMgr.Space.IsInv())
            {
                splite = BaseLanguageMgr.Space;
            }
            else
            {
                splite = Splite;
            }

            if (CustomName.IsInv())
            {
                firstName = person.FirstName.GetName();
            }
            else
            {
                firstName = CustomName;
            }

            ret = person.LastName.GetName() + splite + firstName;
            return(ret);
        }
Example #6
0
    public void ReplaceNewCustomNameComponent2(CustomName newValue)
    {
        var component = CreateComponent <NewCustomNameComponent2Component>(TestComponentsLookup.NewCustomNameComponent2);

        component.value = newValue;
        ReplaceComponent(TestComponentsLookup.NewCustomNameComponent2, component);
    }
Example #7
0
        public void Write(WorldPacket data)
        {
            data.WriteUInt64(DbID);
            data.WriteUInt32(GarrFollowerID);
            data.WriteUInt32(Quality);
            data.WriteUInt32(FollowerLevel);
            data.WriteUInt32(ItemLevelWeapon);
            data.WriteUInt32(ItemLevelArmor);
            data.WriteUInt32(Xp);
            data.WriteUInt32(Durability);
            data.WriteUInt32(CurrentBuildingID);
            data.WriteUInt32(CurrentMissionID);
            data.WriteInt32(AbilityID.Count);
            data.WriteUInt32(ZoneSupportSpellID);
            data.WriteUInt32(FollowerStatus);
            data.WriteInt32(Health);
            data.WriteInt8(BoardIndex);
            data.WriteInt32(HealingTimestamp);

            AbilityID.ForEach(ability => data.WriteUInt32(ability.Id));

            data.WriteBits(CustomName.GetByteCount(), 7);
            data.FlushBits();
            data.WriteString(CustomName);
        }
 internal ObjectInteraction(string id, InteractionType type, CustomName name, bool original)
 {
     Id               = id;
     Type             = type;
     ButtonName       = name;
     FromOriginalGame = original;
 }
Example #9
0
    public void AddNewCustomNameComponent2(CustomName newValue)
    {
        var index     = TestComponentsLookup.NewCustomNameComponent2;
        var component = CreateComponent <NewCustomNameComponent2Component>(index);

        component.value = newValue;
        AddComponent(index, component);
    }
    public void AddNewCustomNameComponent1(CustomName newValue)
    {
        var index     = TestComponentsLookup.NewCustomNameComponent1;
        var component = (NewCustomNameComponent1Component)CreateComponent(index, typeof(NewCustomNameComponent1Component));

        component.value = newValue;
        AddComponent(index, component);
    }
Example #11
0
 public override int GetHashCode()
 {
     return(EntityTypes.Type1.GetHashCode() ^
            EntityTypes.Type2.GetHashCode() ^
            CustomName.GetHashCode() ^
            Level.GetHashCode() ^
            XP.GetHashCode());
 }
    public void ReplaceNewCustomNameComponent1(CustomName newValue)
    {
        var index     = TestComponentsLookup.NewCustomNameComponent1;
        var component = CreateComponent <NewCustomNameComponent1Component>(index);

        component.value = newValue;
        ReplaceComponent(index, component);
    }
Example #13
0
    public void ReplaceNewCustomNameComponent2(CustomName newValue)
    {
        var index     = TestComponentsLookup.NewCustomNameComponent2;
        var component = (NewCustomNameComponent2Component)CreateComponent(index, typeof(NewCustomNameComponent2Component));

        component.value = newValue;
        ReplaceComponent(index, component);
    }
Example #14
0
 public void UpdateCustomName(string text)
 {
     if (CustomName.CompareUpdate(text))
     {
         RaiseCustomNameChanged();
         RaiseShowOnHUDChanged();
         DisplayNameText = text;
     }
 }
Example #15
0
        /// <summary>
        /// Меод просто вызвывает делегаты, скорость выполнения измерять безсмысленно
        /// т.к они в одной сборке
        /// </summary>
        public void InvokeDelegate()
        {
            var del1 = new CustomName <List <int>, int>(Sum);

            del1.Invoke(this.List);
            var del2 = new Func <List <int>, int>(Sum);

            del2.Invoke(this.List);
        }
 private void CreateTextBox(bool isEditable, string description)
 {
     m_textBox = new MyGuiScreenTextPanel(CustomName.ToString(),
                                          currentObjectivePrefix: "",
                                          currentObjective: MyTexts.GetString(MySpaceTexts.Terminal_CustomData),
                                          description: description,
                                          editable: isEditable,
                                          resultCallback: OnClosedTextBox);
 }
Example #17
0
 public void UpdateCustomName(StringBuilder text)
 {
     if (CustomName.CompareUpdate(text))
     {
         RaiseCustomNameChanged();
         RaiseShowOnHUDChanged();
         DisplayNameText = text.ToString();
     }
 }
Example #18
0
 public string GetName()
 {
     if (CustomName == "")
     {
         return(MethodInfo.Name.ToLower());
     }
     else
     {
         return(CustomName.ToLower());
     }
 }
Example #19
0
 public string GetName()
 {
     if (CustomName == "")
     {
         return(GetObjectInfo().Name.ToLower());
     }
     else
     {
         return(CustomName.ToLower());
     }
 }
Example #20
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            var ob = (MyObjectBuilder_TerminalBlock)objectBuilder;

            if (ob.CustomName != null)
            {
                CustomName.Clear().Append(ob.CustomName);
                DisplayNameText = ob.CustomName;
            }
            else
            {
                CustomName.Clear();
                GetTerminalName(CustomName);
            }

            ShowOnHUD      = ob.ShowOnHUD;
            ShowInTerminal = ob.ShowInTerminal;
            AddDebugRenderComponent(new MyDebugRenderComponentTerminal(this));
        }
        internal static bool Prefix(Group __instance, IVisitor visitor)
        {
            if (!(visitor is Serializers.Serializer) && !(visitor is Serializers.Deserializer))
            {
                GameObject[] SubObjects = __instance.gameObject.GetChildren();

                if (SubObjects.Length == 0)
                {
                    visitor.VisualLabel("No child objects found!".Colorize(Color.white));
                    return(false);
                }

                if (SubObjects.Length > 0)
                {
                    visitor.VisualLabel("Group Hierarchy");

                    int Index = 1;

                    foreach (GameObject Children in SubObjects)
                    {
                        string Name = Children.name;

                        if (Children.HasComponent <CustomName>())
                        {
                            CustomName CustomNameComponent = Children.GetComponent <CustomName>();
                            Name = $"[b]{CustomNameComponent.CustomName_}[/b]".Colorize(Color.white);
                        }

                        visitor.VisitAction($"Inspect {Name} (#{Index})", () => EditorUtil.Inspect(Children), null);

                        ++Index;
                    }
                }
            }

            return(true);
        }
Example #22
0
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();

            if (SafeConstraint != null)
            {
                if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_CONNECTORS_AND_MERGE_BLOCKS && CustomName.ToString() == "DEBUG")
                {
                    DebugDrawInfo(new Vector2(0.0f, 0.0f));
                    m_other.DebugDrawInfo(new Vector2(0.0f, 120.0f));

                    MyRenderProxy.DebugDrawLine3D(PositionComp.GetPosition(), PositionComp.GetPosition() + WorldMatrix.GetDirectionVector(m_right) * 10.0f, Color.Red, Color.Red, false);
                    MyRenderProxy.DebugDrawLine3D(m_other.PositionComp.GetPosition(), m_other.PositionComp.GetPosition() + m_other.WorldMatrix.GetDirectionVector(m_other.m_otherRight) * 10.0f, Color.Red, Color.Red, false);

                    MyRenderProxy.DebugDrawLine3D(PositionComp.GetPosition(), PositionComp.GetPosition() + WorldMatrix.GetDirectionVector(m_otherRight) * 5.0f, Color.Yellow, Color.Yellow, false);
                    MyRenderProxy.DebugDrawLine3D(m_other.PositionComp.GetPosition(), m_other.PositionComp.GetPosition() + m_other.WorldMatrix.GetDirectionVector(m_other.m_right) * 5.0f, Color.Yellow, Color.Yellow, false);
                }

                Vector3 thisVelocity     = CubeGrid.Physics.GetVelocityAtPoint(PositionComp.GetPosition());
                Vector3 otherVelocity    = m_other.CubeGrid.Physics.GetVelocityAtPoint(m_other.PositionComp.GetPosition());
                Vector3 relativeVelocity = otherVelocity - thisVelocity;

                // Damping to avoid too quick approach
                if (relativeVelocity.Length() > 0.5f)
                {
                    CubeGrid.Physics.LinearVelocity         += relativeVelocity * 0.05f;
                    m_other.CubeGrid.Physics.LinearVelocity -= relativeVelocity * 0.05f;
                }
            }
        }
Example #23
0
        public override string GenerateJson(bool topLevel)
        {
            var b = new StringBuilder(base.GenerateJson(topLevel));

            if (!string.IsNullOrWhiteSpace(CustomName))
            {
                b.AppendFormat("CustomName:\"{0}\",", CustomName.EscapeJsonString());
            }
            if (!string.IsNullOrWhiteSpace(CustomName) && CustomNameVisible)
            {
                b.Append("CustomNameVisible:1b,");
            }
            if (CanPickUpLoot)
            {
                b.Append("CanPickUpLoot:1b,");
            }
            if (PersistanceRequired)
            {
                b.Append("PersistanceRequired:1b,");
            }
            if (NoAi)
            {
                b.Append("NoAI:1b,");
            }

            var holding  = Holding.GenerateJson(false);
            var boots    = Boots.GenerateJson(false);
            var leggings = Leggings.GenerateJson(false);
            var chest    = Chestplate.GenerateJson(false);
            var helm     = Helmet.GenerateJson(false);

            if (holding != string.Empty)
            {
                holding = holding.Remove(holding.Length - 1, 1);
            }

            if (boots != string.Empty)
            {
                boots = boots.Remove(boots.Length - 1, 1);
            }

            if (leggings != string.Empty)
            {
                leggings = leggings.Remove(leggings.Length - 1, 1);
            }

            if (chest != string.Empty)
            {
                chest = chest.Remove(chest.Length - 1, 1);
            }

            if (helm != string.Empty)
            {
                helm = helm.Remove(helm.Length - 1, 1);
            }

            if (holding != string.Empty || boots != string.Empty || leggings != string.Empty || chest != string.Empty || helm != string.Empty)
            {
                b.AppendFormat("Equipment:[0:{{{0}}},1:{{{1}}},2:{{{2}}},3:{{{3}}},4:{{{4}}}],", holding, boots, leggings, chest, helm);
            }

            if (DefaultHealth.HasValue && Health != DefaultHealth)
            {
                b.AppendFormat("HealF:{0}f,", Health);
            }

            StringBuilder aBuilder;

            if (PotionEffects.Count > 0)
            {
                aBuilder = new StringBuilder();
                for (var i = 0; i < PotionEffects.Count; i++)
                {
                    var attribute = PotionEffects[i];

                    var generateJson = attribute.GenerateJson(false);
                    if (!string.IsNullOrWhiteSpace(generateJson))
                    {
                        aBuilder.AppendFormat("{0}:{{{1}}},", i, generateJson);
                    }
                }

                aBuilder.Remove(aBuilder.Length - 1, 1);

                if (aBuilder.Length > 0)
                {
                    b.AppendFormat("ActiveEffects:[{0}],", aBuilder);
                }
            }


            if (Attributes.Count > 0)
            {
                aBuilder = new StringBuilder();
                for (var i = 0; i < Attributes.Count; i++)
                {
                    var attribute = Attributes[i];

                    var generateJson = attribute.GenerateJson(false);
                    if (!string.IsNullOrWhiteSpace(generateJson))
                    {
                        aBuilder.AppendFormat("{0}:{{{1}}},", i, generateJson);
                    }
                }

                aBuilder.Remove(aBuilder.Length - 1, 1);

                if (aBuilder.Length > 0)
                {
                    b.AppendFormat("Attributes:[{0}],", aBuilder);
                }
            }


            if (Math.Abs(DropChanceFloats[0].Value) > 0.001 || Math.Abs(DropChanceFloats[1].Value) > 0.001 ||
                Math.Abs(DropChanceFloats[2].Value) > 0.001 || Math.Abs(DropChanceFloats[3].Value) > 0.001 ||
                Math.Abs(DropChanceFloats[4].Value) > 0.001)
            {
                b.AppendFormat("DropChances:[0:{0:0.##}f,1:{1:0.##}f,2:{2:0.##}f,3:{3:0.##}f,4:{4:0.##}f],",
                               DropChanceFloats[0].Value, DropChanceFloats[1].Value, DropChanceFloats[2].Value, DropChanceFloats[3].Value,
                               DropChanceFloats[4].Value);
            }

            return(b.ToString());
        }
Example #24
0
 public override string ToString() => (CustomName.IsNotNullOrEmpty()) ? CustomName
         : $"{ParentIDE.Machine} : {DefaultName} {Id}";
Example #25
0
 public override string ToString() => (CustomName.IsNotNullOrEmpty()) ? CustomName : DefaultName + ParentIDE.Id.ToString();
Example #26
0
        /// <summary>
        /// creates control user interface based on node type
        /// </summary>
        /// <param name="mainColor"></param>
        protected void InitializeControl(Type nodeType)
        {
            CustomNodeName.Visibility = Visibility.Collapsed;

            MainPanel.DataContext = NodeInstance;

            var ignoredProperties = nodeType.CustomAttributes
                                    .Where(a => a.AttributeType == typeof(IgnoredPropertyAttribute))
                                    .Select(ca => ca.NamedArguments.Single(na => na.MemberName == nameof(IgnoredPropertyAttribute.Name)).TypedValue.Value as string).ToArray();

            var inputProperties = nodeType.GetProperties()
                                  .Where(p => p.CustomAttributes.Any(a => a.AttributeType == typeof(InputAttribute)))
                                  .Where(pi => ignoredProperties == null || !ignoredProperties.Contains(pi.Name))
                                  .OrderBy(p => p.CustomAttributes.Single(a => a.AttributeType == typeof(InputAttribute)).NamedArguments.Single(a => a.MemberName == nameof(InputAttribute.Order)).TypedValue.Value);

            var outputProperties = nodeType.GetProperties()
                                   .Where(p => p.CustomAttributes.Any(a => a.AttributeType == typeof(OutputAttribute)))
                                   .Where(pi => ignoredProperties == null || !ignoredProperties.Contains(pi.Name));

            #region grid definition

            // add rows for all input properties
            for (var i = 0; i < inputProperties.Count(); i++)
            {
                MainPanel.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Auto
                });
            }

            // number of input rows that have free output side
            var inputAnchorsOnly = inputProperties.Count(ip => AttributeHelper.GetValue <InputAttribute, bool>(ip, nameof(InputAttribute.AnchorOnly)) && !AttributeHelper.GetValue <InputAttribute, bool>(ip, nameof(InputAttribute.OutputAnchor)));
            // number of outputs that could be moved up next to inputs
            var outputAnchorsOnly = outputProperties.Count(op => AttributeHelper.GetValue <OutputAttribute, bool>(op, nameof(OutputAttribute.AnchorOnly)));
            // outputs that needs to be at bottom
            var outputLeft = outputProperties.Count() - outputAnchorsOnly;
            // number of output rows that should be added under input rows
            var outputRowsToAdd = outputLeft + Math.Max(0, outputAnchorsOnly - inputAnchorsOnly);

            // add rows for some output properties
            for (var i = 0; i < outputRowsToAdd; i++)
            {
                MainPanel.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Auto
                });
            }

            MainPanel.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(AnchorSize / 2)
            });                                                                                                         // bottom

            #endregion

            #region header

            CustomName = AttributeHelper.GetValue <NodeInfoAttribute, string>(NodeInstance.GetType(), nameof(NodeInfoAttribute.DisplayName)) ?? NodeInstance.GetType().Name;
            var colorValues = BitConverter.GetBytes(CustomName.GetHashCode());
            CustomColor = Color.FromArgb(0xff, colorValues[1], colorValues[2], colorValues[3]);

            NodeHeader.Background = new LinearGradientBrush(CustomColor, Color.Multiply(CustomColor, (float)0.5), new Point(0, 1), new Point(1, 0));
            NodeTitle.Text        = CustomName;

            #endregion

            #region border

            var border = new Border
            {
                BorderBrush     = new SolidColorBrush(Colors.Black),
                BorderThickness = new Thickness(1, 0, 1, 1)
            };
            Grid.SetRow(border, 1);
            Grid.SetColumnSpan(border, MainPanel.ColumnDefinitions.Count);
            Grid.SetRowSpan(border, MainPanel.RowDefinitions.Count - 1);
            MainPanel.Children.Add(border);

            #endregion

            var firstRow   = 2;
            var inputRows  = new bool[MainPanel.RowDefinitions.Count - 3];
            var outputRows = new bool[MainPanel.RowDefinitions.Count - 3];

            foreach (var inputProperty in inputProperties)
            {
                var inputAttribute = inputProperty.CustomAttributes.Single(a => a.AttributeType == typeof(InputAttribute));

                var readOnly             = AttributeHelper.GetValue <InputAttribute, bool>(inputProperty, nameof(InputAttribute.ReadOnly));
                var anchorOnly           = AttributeHelper.GetValue <InputAttribute, bool>(inputProperty, nameof(InputAttribute.AnchorOnly));
                var inputAnchor          = AttributeHelper.GetValue <InputAttribute, bool>(inputProperty, nameof(InputAttribute.InputAnchor));
                var outputAnchor         = AttributeHelper.GetValue <InputAttribute, bool>(inputProperty, nameof(InputAttribute.OutputAnchor));
                var inputName            = AttributeHelper.GetValue <InputAttribute, string>(inputProperty, nameof(InputAttribute.InputName)) ?? inputProperty.Name;
                var inputDisplayName     = AttributeHelper.GetValue <InputAttribute, string>(inputProperty, nameof(InputAttribute.DisplayName)) ?? inputProperty.Name;
                var inputAnchorProperty  = AttributeHelper.GetValue <InputAttribute, string>(inputProperty, nameof(InputAttribute.InputAnchorProperty)) ?? inputProperty.Name;
                var outputAnchorProperty = AttributeHelper.GetValue <InputAttribute, string>(inputProperty, nameof(InputAttribute.OutputAnchorProperty)) ?? inputProperty.Name;

                // next free row
                var row = firstRow;
                for (var i = 0; i < outputRows.Length; i++)
                {
                    if (!inputRows[i])
                    {
                        row += i;
                        break;
                    }
                }

                if (inputAnchor)
                {
                    #region input anchor

                    var anchor = new Rectangle
                    {
                        Fill                = new SolidColorBrush(InputBackground),
                        Stroke              = new SolidColorBrush(Colors.Black),
                        VerticalAlignment   = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Left,
                        Margin              = new Thickness(-AnchorSize / 2, 0, 0, 0),
                        Width               = AnchorSize,
                        Height              = AnchorSize,
                        Name                = InputAnchorPrefix + inputAnchorProperty,
                        ToolTip             = inputProperty.PropertyType.Name,
                    };
                    anchor.MouseEnter += HilightInputAnchorOn;
                    anchor.MouseLeave += HilightInputAnchorOff;

                    Grid.SetRow(anchor, row);
                    Grid.SetColumn(anchor, 0);
                    MainPanel.Children.Add(anchor);

                    #endregion
                }

                #region label

                var label = new Label
                {
                    Foreground        = new SolidColorBrush(TextForeground),
                    VerticalAlignment = VerticalAlignment.Center,
                    Name       = LabelPrefix + inputAnchorProperty,
                    FontFamily = new FontFamily("Consolas"),
                    Effect     = LabelEffect,
                    Content    = inputDisplayName,
                };

                Grid.SetRow(label, row);
                Grid.SetColumn(label, 1);
                if (inputAnchor && anchorOnly && outputAnchor)
                {
                    label.HorizontalAlignment = HorizontalAlignment.Right;
                    Grid.SetColumnSpan(label, 3);
                }
                else
                {
                    label.HorizontalAlignment = HorizontalAlignment.Left;
                }
                MainPanel.Children.Add(label);

                #endregion

                if (!anchorOnly)
                {
                    #region input element

                    if (inputProperty.PropertyType == typeof(SolidColorBrush))
                    {
                        var colorElement = new TextBox
                        {
                            Background                 = new SolidColorBrush(Colors.Black),
                            Foreground                 = new SolidColorBrush(Colors.White),
                            BorderThickness            = new Thickness(1),
                            BorderBrush                = new SolidColorBrush(InputBorder),
                            Margin                     = new Thickness(0, 0, 0, 0),
                            Name                       = InputValuePrefix + inputName,
                            FontFamily                 = new FontFamily("Consolas"),
                            HorizontalContentAlignment = HorizontalAlignment.Center,
                            VerticalContentAlignment   = VerticalAlignment.Center,
                            VerticalAlignment          = VerticalAlignment.Stretch,
                            HorizontalAlignment        = HorizontalAlignment.Stretch,
                            IsReadOnly                 = true,
                            Width                      = 128,
                        };

                        var binding = new Binding(inputProperty.Name)
                        {
                            Mode = BindingMode.OneWay,
                        };
                        colorElement.SetBinding(TextBox.TextProperty, binding);
                        colorElement.SetBinding(TextBox.BackgroundProperty, binding);

                        Grid.SetRow(colorElement, row);
                        Grid.SetColumn(colorElement, 2);
                        MainPanel.Children.Add(colorElement);
                    }
                    // TODO UI INPUT CustomCheckBox
                    //else if (inputProperty.PropertyType == typeof(bool))
                    //{
                    //	var checkBox = new CheckBox
                    //	{
                    //		//Background = new SolidColorBrush(InputBackground),
                    //		//Foreground = new SolidColorBrush(TextForeground),
                    //		BorderThickness = new Thickness(1),
                    //		Name = InputValuePrefix + inputName,
                    //		FontFamily = new FontFamily("Consolas"),
                    //		HorizontalContentAlignment = HorizontalAlignment.Center,
                    //		VerticalContentAlignment = VerticalAlignment.Center,
                    //		VerticalAlignment = VerticalAlignment.Center,
                    //		HorizontalAlignment = HorizontalAlignment.Center,
                    //	};

                    //	var binding = new Binding(inputProperty.Name)
                    //	{
                    //		Mode = BindingMode.OneWay,
                    //	};
                    //	checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);

                    //	Grid.SetRow(checkBox, row);
                    //	Grid.SetColumn(checkBox, 2);
                    //	Grid.SetColumnSpan(checkBox, mainPanel.ColumnDefinitions.Count - 1);
                    //	mainPanel.Children.Add(checkBox);
                    //}
                    else
                    {
                        var textbox = new TextBox
                        {
                            Foreground        = new SolidColorBrush(TextForeground),
                            BorderBrush       = new SolidColorBrush(InputBorder),
                            Background        = new SolidColorBrush(InputBackground),
                            VerticalAlignment = VerticalAlignment.Center,
                            TextAlignment     = TextAlignment.Right,
                            Margin            = new Thickness(0, 0, 4, 0),
                            Name         = InputValuePrefix + inputName,
                            IsReadOnly   = readOnly,
                            FontFamily   = new FontFamily("Consolas"),
                            TextWrapping = TextWrapping.Wrap,
                            VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                            MaxHeight = 128,
                            MaxWidth  = 256,
                        };

                        var binding = new Binding(inputProperty.Name)
                        {
                            Mode = readOnly ? BindingMode.OneWay : BindingMode.TwoWay,
                            ValidatesOnExceptions = true
                        };

                        if (inputProperty.PropertyType == typeof(double))
                        {
                            textbox.MinWidth     = 64;
                            binding.StringFormat = "{0:F" + DecimalPrecision + "}";
                        }
                        else if (inputProperty.PropertyType == typeof(int))
                        {
                            textbox.MinWidth = 64;
                        }
                        else if (inputProperty.PropertyType == typeof(string))
                        {
                            textbox.MinWidth      = 128;
                            textbox.TextAlignment = TextAlignment.Left;
                            textbox.TextWrapping  = TextWrapping.NoWrap;
                        }

                        textbox.SetBinding(TextBox.TextProperty, binding);

                        Grid.SetRow(textbox, row);
                        Grid.SetColumn(textbox, 2);
                        MainPanel.Children.Add(textbox);
                    }

                    #endregion

                    outputRows[row - firstRow] = true;
                }

                if (outputAnchor)
                {
                    #region output anchor

                    var anchor = new Rectangle
                    {
                        Fill                = new SolidColorBrush(CustomColor),
                        Stroke              = new SolidColorBrush(Colors.Black),
                        VerticalAlignment   = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Right,
                        Margin              = new Thickness(0, 0, -AnchorSize / 2, 0),
                        Width               = AnchorSize,
                        Height              = AnchorSize,
                        Name                = OutputAnchorPrefix + outputAnchorProperty,
                        ToolTip             = inputProperty.PropertyType.Name,
                    };
                    anchor.MouseEnter += HilightOutputAnchorOn;
                    anchor.MouseLeave += HilightOutputAnchorOff;

                    Grid.SetRow(anchor, row);
                    Grid.SetColumn(anchor, MainPanel.ColumnDefinitions.Count - 1);
                    MainPanel.Children.Add(anchor);

                    #endregion

                    outputRows[row - firstRow] = true;
                }

                inputRows[row - firstRow] = true;
            }

            foreach (var outputProperty in outputProperties)
            {
                var outputAttribute = outputProperty.CustomAttributes.Single(a => a.AttributeType == typeof(OutputAttribute));

                var readOnly             = AttributeHelper.GetValue <OutputAttribute, bool>(outputProperty, nameof(OutputAttribute.ReadOnly));
                var anchorOnly           = AttributeHelper.GetValue <OutputAttribute, bool>(outputProperty, nameof(OutputAttribute.AnchorOnly));
                var noAnchor             = AttributeHelper.GetValue <OutputAttribute, bool>(outputProperty, nameof(OutputAttribute.NoAnchor));
                var outputDisplayName    = AttributeHelper.GetValue <OutputAttribute, string>(outputProperty, nameof(OutputAttribute.DisplayName)) ?? outputProperty.Name;
                var outputAnchorProperty = AttributeHelper.GetValue <OutputAttribute, string>(outputProperty, nameof(OutputAttribute.OutputAnchorProperty)) ?? outputProperty.Name;

                // next free row
                var row = firstRow;
                for (var i = 0; i < outputRows.Length; i++)
                {
                    if (!outputRows[i] && (anchorOnly || !inputRows[i]))
                    {
                        row += i;
                        break;
                    }
                }

                if (!anchorOnly)
                {
                    #region output element

                    if (outputProperty.PropertyType == typeof(BitmapSource))
                    {
                        var imageBorder = new Border
                        {
                            BorderThickness = new Thickness(1),
                            BorderBrush     = new SolidColorBrush(InputBorder),
                        };
                        var image = new Image();
                        imageBorder.Child = image;

                        image.SetBinding(Image.SourceProperty, new Binding(outputProperty.Name)
                        {
                            Mode = BindingMode.OneWay
                        });

                        var widthBinding  = AttributeHelper.GetValue <ImageBindingsAttribute, string>(outputProperty, nameof(ImageBindingsAttribute.Width));
                        var heightBinding = AttributeHelper.GetValue <ImageBindingsAttribute, string>(outputProperty, nameof(ImageBindingsAttribute.Height));
                        if (!string.IsNullOrEmpty(widthBinding) && !string.IsNullOrEmpty(heightBinding))
                        {
                            image.SetBinding(Image.WidthProperty, new Binding(widthBinding)
                            {
                                Mode = BindingMode.OneWay
                            });
                            image.SetBinding(Image.HeightProperty, new Binding(heightBinding)
                            {
                                Mode = BindingMode.OneWay
                            });
                        }

                        Grid.SetRow(imageBorder, row);
                        Grid.SetColumn(imageBorder, 1);
                        Grid.SetColumnSpan(imageBorder, MainPanel.ColumnDefinitions.Count - 2);
                        MainPanel.Children.Add(imageBorder);
                    }
                    else
                    {
                        var textbox = new TextBox
                        {
                            Foreground        = new SolidColorBrush(TextForeground),
                            BorderBrush       = new SolidColorBrush(InputBorder),
                            Background        = new SolidColorBrush(InputBackground),
                            VerticalAlignment = VerticalAlignment.Center,
                            TextAlignment     = outputProperty.PropertyType == typeof(string) ? TextAlignment.Left : TextAlignment.Right,
                            Margin            = new Thickness(0, 0, 4, 0),
                            Name       = OutputValuePrefix + outputAnchorProperty,
                            FontFamily = new FontFamily("Consolas"),
                            IsReadOnly = readOnly,

                            TextWrapping = TextWrapping.Wrap,
                            VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                            MaxHeight = 128,
                            MaxWidth  = 256,
                        };

                        var binding = new Binding(outputProperty.Name)
                        {
                            Mode = BindingMode.TwoWay,
                            ValidatesOnExceptions = true
                        };

                        if (outputProperty.PropertyType == typeof(double))
                        {
                            binding.StringFormat = "{0:F" + DecimalPrecision + "}";
                        }

                        textbox.SetBinding(TextBox.TextProperty, binding);

                        Grid.SetRow(textbox, row);
                        Grid.SetColumn(textbox, 2);
                        MainPanel.Children.Add(textbox);
                    }

                    #endregion
                }

                #region label

                var label = new Label
                {
                    Foreground          = new SolidColorBrush(TextForeground),
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Right,
                    Name       = LabelPrefix + outputAnchorProperty,
                    FontFamily = new FontFamily("Consolas"),
                    Effect     = LabelEffect,
                    Content    = outputDisplayName,
                };

                Grid.SetRow(label, row);
                if (anchorOnly)
                {
                    Grid.SetColumn(label, 0);
                    Grid.SetColumnSpan(label, MainPanel.ColumnDefinitions.Count - 1);
                }
                else
                {
                    Grid.SetColumn(label, MainPanel.ColumnDefinitions.Count - 2);
                }

                MainPanel.Children.Add(label);

                #endregion

                if (!noAnchor)
                {
                    #region output anchor

                    var anchor = new Rectangle
                    {
                        Fill                = new SolidColorBrush(CustomColor),
                        Stroke              = new SolidColorBrush(Colors.Black),
                        VerticalAlignment   = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Right,
                        Margin              = new Thickness(0, 0, -8, 0),
                        Width               = AnchorSize,
                        Height              = AnchorSize,
                        Name                = OutputAnchorPrefix + outputAnchorProperty,
                        ToolTip             = outputProperty.PropertyType.Name,
                    };
                    anchor.MouseEnter += HilightOutputAnchorOn;
                    anchor.MouseLeave += HilightOutputAnchorOff;

                    Grid.SetRow(anchor, row);
                    Grid.SetColumn(anchor, MainPanel.ColumnDefinitions.Count - 1);
                    MainPanel.Children.Add(anchor);

                    #endregion
                }

                outputRows[row - firstRow] = true;
            }

            //MainPanel.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30) });
            //var customDouble = new CustomFloatingInput();
            //Grid.SetRow(customDouble, MainPanel.RowDefinitions.Count - 1);
            //Grid.SetColumn(customDouble, 1);
            //Grid.SetColumnSpan(customDouble, 2);
            //MainPanel.Children.Add(customDouble);

            //MainPanel.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30) });
            //var customInteger = new CustomIntegerInput();
            //Grid.SetRow(customInteger, MainPanel.RowDefinitions.Count - 1);
            //Grid.SetColumn(customInteger, 1);
            //Grid.SetColumnSpan(customInteger, 2);
            //MainPanel.Children.Add(customInteger);

            //MainPanel.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto, MinHeight = 30 });
            //var customText = new CustomTextInput();
            //Grid.SetRow(customText, MainPanel.RowDefinitions.Count - 1);
            //Grid.SetColumn(customText, 1);
            //Grid.SetColumnSpan(customText, 2);
            //MainPanel.Children.Add(customText);
        }
Example #27
0
 public override void UpdateBeforeSimulation10()
 {
     base.UpdateBeforeSimulation10();
     CustomName.Clear();
     GetTerminalName(CustomName);
 }
 public override string ToString() => (CustomName.IsNotNullOrEmpty()) ? CustomName
                         : $"{DefaultName} id{Id}";