using System.Collections.Generic; using OpenTK; using SM.Base.Contexts; namespace SM.Base.Scene { /// /// A generic scene, that imports functions for scene control. /// public abstract class GenericScene { /// /// This contains the background. /// protected IBackgroundItem _background; /// /// Draws this scene. /// public virtual void Draw(DrawContext context) { } /// /// Called, when the user activates the scene. /// internal void Activate() { OnActivating(); } /// /// Called, when the user activates the scene. /// protected virtual void OnActivating() { } } /// /// A generic scene that imports different functions. /// /// The type of cameras. /// The type of show items. /// The type for collections public abstract class GenericScene : GenericScene where TCamera : GenericCamera, new() where TCollection : GenericItemCollection, new() where TItem : IShowItem { /// /// The active camera, that is used if the context doesn't force the viewport camera. /// If none set, it automaticly uses the viewport camera. /// public TCamera Camera { get; set; } /// /// A camera to control the background. /// public TCamera BackgroundCamera { get; set; } = new TCamera(); /// /// A camera to control the HUD. /// public TCamera HUDCamera { get; set; } = new TCamera(); /// /// Objects inside the scene. /// public TCollection Objects { get; set; } = new TCollection(); /// /// This defines the HUD objects. /// public TCollection HUD { get; } = new TCollection(); /// /// A collection for cameras to switch easier to different cameras. /// public Dictionary Cameras = new Dictionary(); /// public override void Draw(DrawContext context) { if (!context.ForceViewport && Camera != null) context.View = Camera.CalculateViewMatrix(); DrawContext backgroundDrawContext = context; backgroundDrawContext.View = BackgroundCamera.CalculateViewMatrix(); _background?.Draw(backgroundDrawContext); Objects.Draw(context); context.View = HUDCamera.CalculateViewMatrix(); HUD.Draw(context); } } }