示例#1
0
        private GUIComponent CreateEditingHUD(bool inGame = false)
        {
            int width = 450;
            int height = 150;
            int x = GameMain.GraphicsWidth / 2 - width / 2, y = 30;

            editingHUD          = new GUIListBox(new Rectangle(x, y, width, height), "");
            editingHUD.UserData = this;
            GUIListBox listBox = (GUIListBox)editingHUD;

            listBox.Spacing = 5;

            var itemEditor = new SerializableEntityEditor(this, inGame, editingHUD, true);

            if (!inGame && Linkable)
            {
                itemEditor.AddCustomContent(new GUITextBlock(new Rectangle(0, 0, 0, 20), "Hold space to link to another item", "", null, GUI.SmallFont), 1);
            }

            foreach (ItemComponent ic in components)
            {
                if (ic.requiredItems.Count == 0)
                {
                    if (inGame)
                    {
                        if (SerializableProperty.GetProperties <InGameEditable>(ic).Count == 0)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (SerializableProperty.GetProperties <Editable>(ic).Count == 0)
                        {
                            continue;
                        }
                    }
                }

                var componentEditor = new SerializableEntityEditor(ic, inGame, editingHUD, !inGame);

                if (inGame)
                {
                    continue;
                }

                foreach (RelatedItem relatedItem in ic.requiredItems)
                {
                    var textBlock = new GUITextBlock(new Rectangle(0, 0, 0, 20), relatedItem.Type.ToString() + " required", "", Alignment.TopLeft, Alignment.CenterLeft, null, false, GUI.SmallFont);
                    textBlock.Padding = new Vector4(10.0f, 0.0f, 10.0f, 0.0f);
                    componentEditor.AddCustomContent(textBlock, 1);

                    GUITextBox namesBox = new GUITextBox(new Rectangle(0, 0, 180, 20), Alignment.Right, "", textBlock);
                    namesBox.Font = GUI.SmallFont;
                    namesBox.Text = relatedItem.JoinedNames;

                    namesBox.OnDeselected += (textBox, key) =>
                    {
                        relatedItem.JoinedNames = textBox.Text;
                        textBox.Text            = relatedItem.JoinedNames;
                    };

                    namesBox.OnEnterPressed += (textBox, text) =>
                    {
                        relatedItem.JoinedNames = text;
                        textBox.Text            = relatedItem.JoinedNames;
                        return(true);
                    };

                    y += 20;
                }
            }

            int contentHeight = (int)(editingHUD.children.Sum(c => c.Rect.Height) + (listBox.children.Count - 1) * listBox.Spacing + listBox.Padding.Y + listBox.Padding.W);

            editingHUD.SetDimensions(new Point(editingHUD.Rect.Width, MathHelper.Clamp(contentHeight, 50, editingHUD.Rect.Height)));

            return(editingHUD);
        }
示例#2
0
        public Limb(Ragdoll ragdoll, Character character, LimbParams limbParams)
        {
            this.ragdoll   = ragdoll;
            this.character = character;
            this.Params    = limbParams;
            wearingItems   = new List <WearableSprite>();
            dir            = Direction.Right;
            body           = new PhysicsBody(limbParams);
            type           = limbParams.Type;
            if (limbParams.IgnoreCollisions)
            {
                body.CollisionCategories = Category.None;
                body.CollidesWith        = Category.None;
                ignoreCollisions         = true;
            }
            else
            {
                //limbs don't collide with each other
                body.CollisionCategories = Physics.CollisionCharacter;
                body.CollidesWith        = Physics.CollisionAll & ~Physics.CollisionCharacter & ~Physics.CollisionItem & ~Physics.CollisionItemBlocking;
            }
            body.UserData = this;
            pullJoint     = new FixedMouseJoint(body.FarseerBody, ConvertUnits.ToSimUnits(limbParams.PullPos * Scale))
            {
                Enabled = false,
                //MaxForce = ((type == LimbType.LeftHand || type == LimbType.RightHand) ? 400.0f : 150.0f) * body.Mass
                // 150 or even 400 is too low if the joint is used for moving the character position from the mainlimb towards the collider position
                MaxForce = 1000 * Mass
            };

            GameMain.World.AddJoint(pullJoint);

            var element = limbParams.Element;

            body.BodyType = BodyType.Dynamic;

            damageModifiers = new List <DamageModifier>();

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "attack":
                    attack = new Attack(subElement, (character == null ? "null" : character.Name) + ", limb " + type);
                    if (attack.DamageRange <= 0)
                    {
                        switch (body.BodyShape)
                        {
                        case PhysicsBody.Shape.Circle:
                            attack.DamageRange = body.radius;
                            break;

                        case PhysicsBody.Shape.Capsule:
                            attack.DamageRange = body.height / 2 + body.radius;
                            break;

                        case PhysicsBody.Shape.Rectangle:
                            attack.DamageRange = new Vector2(body.width / 2.0f, body.height / 2.0f).Length();
                            break;
                        }
                        attack.DamageRange = ConvertUnits.ToDisplayUnits(attack.DamageRange);
                    }
                    break;

                case "damagemodifier":
                    damageModifiers.Add(new DamageModifier(subElement, character.Name));
                    break;
                }
            }

            SerializableProperties = SerializableProperty.GetProperties(this);

            InitProjSpecific(element);
        }
示例#3
0
 public Emitter()
 {
     SerializableProperties = SerializableProperty.GetProperties(this);
 }
示例#4
0
        public Structure(Rectangle rectangle, StructurePrefab sp, Submarine submarine)
            : base(sp, submarine)
        {
            if (rectangle.Width == 0 || rectangle.Height == 0)
            {
                return;
            }
            System.Diagnostics.Debug.Assert(rectangle.Width > 0 && rectangle.Height > 0);

            rect   = rectangle;
            prefab = sp;

            spriteColor = prefab.SpriteColor;
            if (ResizeHorizontal && !ResizeVertical)
            {
                isHorizontal = true;
            }
            else if (ResizeVertical && !ResizeHorizontal)
            {
                isHorizontal = false;
            }
            else
            {
                isHorizontal = (rect.Width > rect.Height);
            }

            StairDirection = prefab.StairDirection;

            SerializableProperties = SerializableProperty.GetProperties(this);

            if (prefab.Body)
            {
                bodies = new List <Body>();
                //gaps = new List<Gap>();

                Body newBody = BodyFactory.CreateRectangle(GameMain.World,
                                                           ConvertUnits.ToSimUnits(rect.Width),
                                                           ConvertUnits.ToSimUnits(rect.Height),
                                                           1.5f);
                newBody.BodyType            = BodyType.Static;
                newBody.Position            = ConvertUnits.ToSimUnits(new Vector2(rect.X + rect.Width / 2.0f, rect.Y - rect.Height / 2.0f));
                newBody.Friction            = 0.5f;
                newBody.OnCollision        += OnWallCollision;
                newBody.UserData            = this;
                newBody.CollisionCategories = (prefab.Platform) ? Physics.CollisionPlatform : Physics.CollisionWall;

                bodies.Add(newBody);

                WallList.Add(this);

                CreateSections();
            }
            else
            {
                sections    = new WallSection[1];
                sections[0] = new WallSection(rect);

                if (StairDirection != Direction.None)
                {
                    CreateStairBodies();
                }
            }

#if CLIENT
            if (prefab.CastShadow)
            {
                GenerateConvexHull();
            }
#endif

            InsertToList();
        }
示例#5
0
        public Structure(Rectangle rectangle, StructurePrefab sp, Submarine submarine)
            : base(sp, submarine)
        {
            System.Diagnostics.Debug.Assert(rectangle.Width > 0 && rectangle.Height > 0);
            if (rectangle.Width == 0 || rectangle.Height == 0)
            {
                return;
            }
            defaultRect = rectangle;

            rect = rectangle;
#if CLIENT
            TextureScale = sp.TextureScale;
#endif
            spriteColor = prefab.SpriteColor;
            if (ResizeHorizontal && !ResizeVertical)
            {
                IsHorizontal = true;
            }
            else if (ResizeVertical && !ResizeHorizontal)
            {
                IsHorizontal = false;
            }
            else
            {
                if (BodyWidth > 0.0f && BodyHeight > 0.0f)
                {
                    IsHorizontal = BodyWidth > BodyHeight;
                }
                else
                {
                    IsHorizontal = (rect.Width > rect.Height);
                }
            }

            StairDirection         = Prefab.StairDirection;
            SerializableProperties = SerializableProperty.GetProperties(this);

            InitProjSpecific();

            if (Prefab.Body)
            {
                Bodies = new List <Body>();
                WallList.Add(this);

                CreateSections();
                UpdateSections();
            }
            else
            {
                Sections    = new WallSection[1];
                Sections[0] = new WallSection(rect);

                if (StairDirection != Direction.None)
                {
                    CreateStairBodies();
                }
            }

            // Only add ai targets automatically to submarine/outpost walls
            if (aiTarget == null && HasBody && Tags.Contains("wall") && submarine != null)
            {
                aiTarget = new AITarget(this);
            }

            InsertToList();
        }
示例#6
0
        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
            };
            GUIListBox listBox = new GUIListBox(new RectTransform(new Vector2(0.95f, 0.8f), editingHUD.RectTransform, Anchor.Center), style: null)
            {
                Spacing = 5
            };

            var itemEditor = new SerializableEntityEditor(listBox.Content.RectTransform, this, inGame, showName: true);

            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)
                {
                    Stretch         = true,
                    RelativeSpacing = 0.02f
                };
                new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("MirrorEntityX"))
                {
                    ToolTip   = TextManager.Get("MirrorEntityXToolTip"),
                    OnClicked = (button, data) =>
                    {
                        FlipX(relativeToSub: false);
                        return(true);
                    }
                };
                new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("MirrorEntityY"))
                {
                    ToolTip   = TextManager.Get("MirrorEntityYToolTip"),
                    OnClicked = (button, data) =>
                    {
                        FlipY(relativeToSub: false);
                        return(true);
                    }
                };
                if (Sprite != null)
                {
                    var reloadTextureButton = new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("ReloadSprite"));
                    reloadTextureButton.OnClicked += (button, data) =>
                    {
                        Sprite.ReloadXML();
                        Sprite.ReloadTexture();
                        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);
            }

            foreach (ItemComponent ic in components)
            {
                if (inGame)
                {
                    if (!ic.AllowInGameEditing)
                    {
                        continue;
                    }
                    if (SerializableProperty.GetProperties <InGameEditable>(ic).Count == 0)
                    {
                        continue;
                    }
                }
                else
                {
                    if (ic.requiredItems.Count == 0 && SerializableProperty.GetProperties <Editable>(ic).Count == 0)
                    {
                        continue;
                    }
                }

                var componentEditor = new SerializableEntityEditor(listBox.Content.RectTransform, ic, inGame, showName: !inGame);

                if (inGame)
                {
                    continue;
                }

                foreach (var kvp in ic.requiredItems)
                {
                    foreach (RelatedItem relatedItem in kvp.Value)
                    {
                        var textBlock = new GUITextBlock(new RectTransform(new Point(editingHUD.Rect.Width, 20)),
                                                         relatedItem.Type.ToString() + " required", font: GUI.SmallFont)
                        {
                            Padding = new Vector4(10.0f, 0.0f, 10.0f, 0.0f)
                        };
                        componentEditor.AddCustomContent(textBlock, 1);

                        GUITextBox namesBox = new GUITextBox(new RectTransform(new Vector2(0.5f, 1.0f), textBlock.RectTransform, Anchor.CenterRight))
                        {
                            Font = GUI.SmallFont,
                            Text = relatedItem.JoinedIdentifiers
                        };

                        namesBox.OnDeselected += (textBox, key) =>
                        {
                            relatedItem.JoinedIdentifiers = textBox.Text;
                            textBox.Text = relatedItem.JoinedIdentifiers;
                        };

                        namesBox.OnEnterPressed += (textBox, text) =>
                        {
                            relatedItem.JoinedIdentifiers = text;
                            textBox.Text = relatedItem.JoinedIdentifiers;
                            return(true);
                        };
                    }
                }
            }

            PositionEditingHUD();
            SetHUDLayout();

            return(editingHUD);
        }
示例#7
0
        //private GUIComponent editingHUD;

        public SerializableEntityEditor(ISerializableEntity entity, bool inGame, GUIComponent parent, bool showName) : base("")
        {
            List <SerializableProperty> editableProperties = inGame ?
                                                             SerializableProperty.GetProperties <InGameEditable>(entity) :
                                                             SerializableProperty.GetProperties <Editable>(entity);

            if (parent != null)
            {
                parent.AddChild(this);
            }

            if (showName)
            {
                new GUITextBlock(new Rectangle(0, 0, 100, 20), entity.Name, "",
                                 Alignment.TopLeft, Alignment.TopLeft, this, false, GUI.Font);
            }

            int y = showName ? 30 : 10, padding = 10;

            foreach (var property in editableProperties)
            {
                //int boxHeight = 18;
                //var editable = property.Attributes.OfType<Editable>().FirstOrDefault();
                //if (editable != null) boxHeight = (int)(Math.Ceiling(editable.MaxLength / 40.0f) * 18.0f);

                object value = property.GetValue();

                GUIComponent propertyField = null;
                if (value is bool)
                {
                    propertyField = CreateBoolField(entity, property, (bool)value, y, this);
                }
                else if (value.GetType().IsEnum)
                {
                    propertyField = CreateEnumField(entity, property, value, y, this);
                }
                else if (value is string)
                {
                    propertyField = CreateStringField(entity, property, (string)value, y, this);
                }
                else if (value is int)
                {
                    propertyField = CreateIntField(entity, property, (int)value, y, this);
                }
                else if (value is float)
                {
                    propertyField = CreateFloatField(entity, property, (float)value, y, this);
                }
                else if (value is Vector2)
                {
                    propertyField = CreateVector2Field(entity, property, (Vector2)value, y, this);
                }
                else if (value is Vector3)
                {
                    propertyField = CreateVector3Field(entity, property, (Vector3)value, y, this);
                }
                else if (value is Vector4)
                {
                    propertyField = CreateVector4Field(entity, property, (Vector4)value, y, this);
                }
                else if (value is Color)
                {
                    propertyField = CreateColorField(entity, property, (Color)value, y, this);
                }
                else if (value is Rectangle)
                {
                    propertyField = CreateRectangleField(entity, property, (Rectangle)value, y, this);
                }

                if (propertyField != null)
                {
                    y += propertyField.Rect.Height + padding;
                }
            }

            if (children.Count > 0)
            {
                SetDimensions(new Point(Rect.Width, children.Last().Rect.Bottom - Rect.Y + 10), false);
            }
            else
            {
                SetDimensions(new Point(Rect.Width, 0), false);
            }

            if (parent is GUIListBox)
            {
                ((GUIListBox)parent).UpdateScrollBarSize();
            }
        }