Exemple #1
0
        public AmbientObjectListItem(AmbientObjectType ambientObjectType)
        {
            this.AmbientObjectType = ambientObjectType;
            this.displayString     = ambientObjectType.Name + " (" + ambientObjectType.ID + ")";
            this.stringBounds      = Button.ButtonFont.MeasureString(displayString);

            Bounds = new Rect(Point.Zero, ambientObjectType.SpriteBounds);
        }
Exemple #2
0
        public static bool ReplaceTypeFromString(PlacementType placementType, string objectText)
        {
            try
            {
                InputDialog dialog;

                switch (placementType)
                {
                case PlacementType.BlockPlacement:
                    BlockType newBlockType = JsonConvert.DeserializeObject <BlockType>(objectText, SerializationUtils.SerializerSettings);
                    BlockType.lookup[newBlockType.ID] = newBlockType;
                    break;

                case PlacementType.AmbientObjectPlacement:
                    AmbientObjectType newAmbientObjectType = JsonConvert.DeserializeObject <AmbientObjectType>(objectText, SerializationUtils.SerializerSettings);
                    AmbientObjectType.lookup[newAmbientObjectType.ID] = newAmbientObjectType;
                    break;

                case PlacementType.AmbientHitableObjectPlacement:
                    AmbientHitableObjectType newAmbientHitableObjectType = JsonConvert.DeserializeObject <AmbientHitableObjectType>(objectText, SerializationUtils.SerializerSettings);
                    AmbientHitableObjectType.lookup[newAmbientHitableObjectType.ID] = newAmbientHitableObjectType;
                    break;

                case PlacementType.LivingEntityPlacement:
                    dialog = new InputDialog("Create LivingEntity", objectText);

                    if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        LivingEntityType newLivingEntityType = JsonConvert.DeserializeObject <LivingEntityType>(dialog.ResultText, SerializationUtils.SerializerSettings);
                        LivingEntityType.lookup[newLivingEntityType.ID] = newLivingEntityType;

                        return(true);
                    }

                    return(false);
                }

                return(true);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Error while replacing type: " + e.Message);

                return(false);
            }
        }
Exemple #3
0
        public static void CreateObjectAtMousePosition(MetaDataType metaDataType)
        {
            var realPosition = SimulationGame.RealWorldMousePosition;

            if (metaDataType is BlockType)
            {
                var blockPosition = GeometryUtils.GetBlockFromReal((int)realPosition.X, (int)realPosition.Y);
                var blockType     = (BlockType)metaDataType;

                SimulationGame.World.SetBlockType(blockPosition.X, blockPosition.Y, SimulationGame.Player.InteriorID, blockType.ID);
            }
            else
            {
                if (!SimulationGame.KeyboardState.IsKeyDown(Keys.LeftControl) && !SimulationGame.KeyboardState.IsKeyDown(Keys.RightControl))
                {
                    var blockPosition = GeometryUtils.GetChunkPosition((int)realPosition.X, (int)realPosition.Y, 16, 16);

                    realPosition = new Vector2(blockPosition.X * 16, blockPosition.Y * 16);
                }

                var        newWorldPosition = new WorldPosition(realPosition.X, realPosition.Y, SimulationGame.Player.InteriorID);
                GameObject gameObject       = null;

                if (metaDataType is AmbientObjectType)
                {
                    gameObject = AmbientObjectType.Create(newWorldPosition, (AmbientObjectType)metaDataType);
                }
                else if (metaDataType is AmbientHitableObjectType)
                {
                    gameObject = AmbientHitableObjectType.Create(newWorldPosition, (AmbientHitableObjectType)metaDataType);
                }
                else if (metaDataType is LivingEntityType)
                {
                    gameObject = LivingEntityType.Create(newWorldPosition, (LivingEntityType)metaDataType);
                }

                gameObject.ConnectToWorld();
            }
        }
        public static void Draw(SpriteBatch spriteBatch, GameTime gameTime, AmbientObject ambientObject)
        {
            var ambientObjectType = AmbientObjectType.lookup[ambientObject.AmbientObjectType];

            if (ambientObjectType != null)
            {
                var depth = GeometryUtils.GetLayerDepthFromReservedLayer(ReservedDepthLayers.BlockDecoration);

                if (ambientObjectType.InForeground == true)
                {
                    depth = 1.0f;
                }
                else if (ambientObjectType.HasDepth == true)
                {
                    depth = GeometryUtils.GetLayerDepthFromPosition(ambientObject.Position.X, ambientObject.Position.Y + ambientObject.YPositionDepthOffset);
                }

                if (ambientObjectType.SpritePositions.Length > 1)
                {
                    if (ambientObject.ObjectAnimation == null)
                    {
                        ambientObject.ObjectAnimation = AmbientObjectType.CreateAnimation(ambientObject);
                        ambientObject.ObjectAnimation.Start(Repeat.Mode.Loop);
                    }

                    ambientObject.ObjectAnimation.Update(gameTime);
                    spriteBatch.Draw(ambientObject.ObjectAnimation, ambientObject.Position.ToVector(), color: Color.White, layerDepth: depth);
                }
                else
                {
                    spriteBatch.Draw(SimulationGame.ContentManager.Load <Texture2D>(ambientObjectType.SpritePath), ambientObject.Position.ToVector(), new Rectangle(ambientObjectType.SpritePositions[0], ambientObjectType.SpriteBounds), Color.White, 0.0f, ambientObjectType.SpriteOrigin, 1.0f, SpriteEffects.None, depth);
                }

                if (ambientObjectType.Lightning != null)
                {
                    LightningRenderer.AddLightning(ambientObject.Position.ToVector(), ambientObjectType.Lightning);
                }
            }
        }
 public static AmbientObject createSmallRocks(WorldPosition position)
 {
     return(AmbientObjectType.Create(new WorldPosition(position.X - 12.5f + WorldGrid.BlockSize.X / 2, position.Y + 10 + WorldGrid.BlockSize.Y / 2, position.InteriorID), AmbientObjectType.lookup[random.Next(0, 2)]));
 }
Exemple #6
0
        public static int CreateObject(PlacementType placementType, WorldBuilder.PlacementMode placementMode, TileSetSelectionView tileSetSelectionView, bool showDialog = false)
        {
            string spritePath     = null;
            Point  spritePosition = Point.Zero;
            Point  spriteBounds   = Point.Zero;

            if (placementMode == WorldBuilder.PlacementMode.CreateFromTileset)
            {
                spritePath     = tileSetSelectionView.SelectedSpritePath;
                spritePosition = tileSetSelectionView.SelectedSpritePosition ?? Point.Zero;
                spriteBounds   = tileSetSelectionView.SelectedSpriteBounds;
            }

            object selectedObject = null;
            int    newId          = GenerateNewId(placementType);

            switch (placementType)
            {
            case PlacementType.BlockPlacement:
                if (spriteBounds.X != WorldGrid.BlockSize.X || spriteBounds.Y != WorldGrid.BlockSize.Y)
                {
                    System.Windows.Forms.MessageBox.Show("Cannot create block with blocksize != 32,32");

                    return(-1);
                }

                selectedObject = new BlockType()
                {
                    ID             = newId,
                    Name           = "Block" + newId,
                    SpritePath     = spritePath,
                    SpritePosition = spritePosition,
                    SpriteBounds   = spriteBounds,
                };
                break;

            case PlacementType.AmbientObjectPlacement:
                selectedObject = new AmbientObjectType()
                {
                    ID              = newId,
                    Name            = "AmbientObj" + newId,
                    SpritePath      = spritePath,
                    SpritePositions = new Point[] { spritePosition },
                    SpriteBounds    = spriteBounds,
                    SpriteOrigin    = new Vector2(0, spriteBounds.Y)
                };
                break;

            case PlacementType.AmbientHitableObjectPlacement:
                selectedObject = new AmbientHitableObjectType()
                {
                    ID                        = newId,
                    Name                      = "HitableObj" + newId,
                    SpritePath                = spritePath,
                    SpritePositions           = new Point[] { spritePosition },
                    SpriteBounds              = spriteBounds,
                    SpriteOrigin              = new Vector2(0, spriteBounds.Y),
                    RelativeBlockingRectangle = new Rect(0, -spriteBounds.Y, spriteBounds.X, spriteBounds.Y),
                    RelativeHitboxRectangle   = new Rect(0, -spriteBounds.Y, spriteBounds.X, spriteBounds.Y)
                };
                break;

            case PlacementType.LivingEntityPlacement:
                selectedObject = new LivingEntityType()
                {
                    ID           = newId,
                    Name         = "LivingEntity" + newId,
                    SpriteOrigin = new Point(0, spriteBounds.Y)
                };
                break;
            }

            string selectedObjectString;

            if (showDialog)
            {
                var dialog = new InputDialog("Create Object", JToken.FromObject(selectedObject, SerializationUtils.Serializer).ToString(Formatting.Indented));

                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    selectedObjectString = dialog.ResultText;
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                selectedObjectString = JToken.FromObject(selectedObject, SerializationUtils.Serializer).ToString();
            }

            if (ReplaceTypeFromString(placementType, selectedObjectString) == false)
            {
                return(-1);
            }

            return(newId);
        }