Esempio n. 1
0
        public void UpdateRoom(Room room)
        {
            DrawableRoom dr    = GetRoom(room);
            int          index = Rooms.IndexOf(dr);

            dr.Target.Dispose();
            Rooms[index] = new DrawableRoom(room, TargetUsage);
            Editor.Camera.Update();
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the currently selected room.
        /// </summary>
        public void SetSelected(Room room)
        {
            DrawableRoom old = null;

            if (SelectedRoom != null)
            {
                Overlay.Dispose();
                old = SelectedRoom;
            }

            SelectedRoom       = GetRoom(room);
            SelectedRoom.Dirty = true;
            if (old != null)
            {
                old.Dirty = true;
            }

            Overlay = new RenderTarget2D(Engine.Instance.GraphicsDevice, room.Width, room.Height, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);
        }
Esempio n. 3
0
        /// <summary>
        /// Renders a room.
        /// </summary>
        /// <param name="room">The room to render.</param>
        /// <param name="flags">The render flags.</param>
        public void RenderRoom(DrawableRoom room, RenderFlags flags = RenderFlags.All)
        {
            // Generate decals
            room.BGDecals = CreateDecalTextureList(room.Room.BackgroundDecals);
            room.FGDecals = CreateDecalTextureList(room.Room.ForegroundDecals);

            // Generate tiles
            if (room.TilesDirty)
            {
                room.BGTiles = Editor.BGAutotiler.GenerateTextureMap(room.Room.BackgroundTiles, true);
                room.FGTiles = Editor.FGAutotiler.GenerateTextureMap(room.Room.ForegroundTiles, true);

                for (int i = 0; i < room.Room.ObjectTiles.Map.Length; i++)
                {
                    if (room.Room.ObjectTiles.Map[i] != TileGrid.OBJ_AIR)
                    {
                        room.OBTiles.Add(
                            new StaticTexture(GFX.Scenery[room.Room.ObjectTiles.Map[i]])
                        {
                            Position = new Vector2(i % room.Room.ObjectTiles.Width * 8, i / room.Room.ObjectTiles.Width * 8)
                        }
                            );
                    }
                }

                room.TilesDirty = false;
            }

            Engine.Instance.GraphicsDevice.SetRenderTarget(room.Target);
            if (SelectedRoom == room)
            {
                Engine.Instance.GraphicsDevice.Clear(Settings.SelectedRoomColor);
            }
            else
            {
                Engine.Instance.GraphicsDevice.Clear(Settings.RoomColor);
            }

            Engine.Batch.Begin(
                SpriteSortMode.Deferred,
                BlendState.AlphaBlend,
                SamplerState.PointClamp,
                DepthStencilState.None,
                RasterizerState.CullNone,
                null
                );

            // Background tiles
            if (flags.HasFlag(RenderFlags.BGTiles))
            {
                room.BGTiles.Draw();
            }

            // Background decals
            if (flags.HasFlag(RenderFlags.BGDecals))
            {
                foreach (StaticTexture t in room.BGDecals)
                {
                    t.DrawCentered();
                }
            }

            // Object tiles
            if (flags.HasFlag(RenderFlags.OBTiles))
            {
                foreach (StaticTexture t in room.OBTiles)
                {
                    t.Draw();
                }
            }

            // Entities
            if (flags.HasFlag(RenderFlags.Entities))
            {
                foreach (Entity e in room.Room.Entities)
                {
                    e.Render();
                }
            }

            // Foreground tiles
            if (flags.HasFlag(RenderFlags.FGTiles))
            {
                room.FGTiles.Draw();
            }

            // Foreground decals
            if (flags.HasFlag(RenderFlags.FGDecals))
            {
                foreach (StaticTexture t in room.FGDecals)
                {
                    t.DrawCentered();
                }
            }

            // Triggers
            if (flags.HasFlag(RenderFlags.Triggers))
            {
                foreach (Entity t in room.Room.Triggers)
                {
                    Rectangle tr = new Rectangle((int)t.Position.X, (int)t.Position.Y, (int)t.Attributes["width"], (int)t.Attributes["height"]);
                    GFX.Draw.BorderedRectangle(tr, Settings.TriggerColor * 0.4f, Settings.TriggerColor);
                    GFX.Draw.TextCentered(MiscHelper.CleanCamelCase(t.Name), tr, Color.White);
                }
            }

            Engine.Batch.End();

            room.Dirty = false;
        }