Added Base Project
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Firebird2D.SceneSystem.Actors
|
||||
{
|
||||
public enum ResizeMode
|
||||
{
|
||||
Resize,
|
||||
DontResize,
|
||||
CutImage
|
||||
}
|
||||
|
||||
public enum AnchorPoint
|
||||
{
|
||||
topLeft,
|
||||
topMiddle,
|
||||
topRight,
|
||||
bottomLeft,
|
||||
bottomMiddle,
|
||||
bottomRight,
|
||||
LeftMiddle,
|
||||
RightMiddle,
|
||||
Center
|
||||
}
|
||||
|
||||
public enum AnchorMode
|
||||
{
|
||||
stayInValue,
|
||||
stayInRatio,
|
||||
stayInPlace
|
||||
}
|
||||
|
||||
public struct Anchors
|
||||
{
|
||||
public bool top;
|
||||
public bool left;
|
||||
public bool right;
|
||||
public bool bottom;
|
||||
|
||||
AnchorPoint anchorPoint;
|
||||
|
||||
AnchorMode anchorMode;
|
||||
|
||||
|
||||
public Anchors() : this(true, true, false, false, AnchorPoint.Center, AnchorMode.stayInValue) { }
|
||||
|
||||
public Anchors(bool top, bool left, bool right, bool bottom) : this(top, left, right, bottom, AnchorPoint.Center, AnchorMode.stayInValue) { }
|
||||
|
||||
|
||||
public Anchors(bool top, bool left, bool right, bool bottom, AnchorPoint anchorPoint) : this(top, left, right, bottom, anchorPoint, AnchorMode.stayInValue) { }
|
||||
|
||||
public Anchors(bool top, bool left, bool right, bool bottom, AnchorPoint anchorPoint, AnchorMode anchorMode)
|
||||
{
|
||||
this.top = top;
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.bottom = bottom;
|
||||
this.anchorPoint = anchorPoint;
|
||||
this.anchorMode = anchorMode;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IRenderable
|
||||
{
|
||||
public void Render(RenderWindow window);
|
||||
}
|
||||
|
||||
public interface IUpdatable
|
||||
{
|
||||
void Tick(int timeDifference);
|
||||
}
|
||||
|
||||
public interface IResizable : IRenderable
|
||||
{
|
||||
void Resize(int width, int height);
|
||||
void OnWindowResize(int width, int height);
|
||||
}
|
||||
|
||||
public interface I_BaseActor : IRenderable, IUpdatable, IComparable
|
||||
{
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public ResizeMode resizeMode { get; set; }
|
||||
|
||||
public Anchors Anchors { get; set; }
|
||||
|
||||
public Vector2f Position { get; set; }
|
||||
|
||||
public Vector2f Size { get; set; }
|
||||
|
||||
public float Rotation { get; set; }
|
||||
|
||||
public int Z_Index { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Firebird2D.SceneSystem.Actors
|
||||
{
|
||||
public interface I_Clickable : I_BaseActor
|
||||
{
|
||||
public event EventHandler Click;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Firebird2D.SceneSystem.Actors
|
||||
{
|
||||
public interface I_HitboxActor
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Firebird2D.SceneSystem.Actors
|
||||
{
|
||||
public interface I_InteractableActor : I_BaseActor
|
||||
{
|
||||
public bool Interact(I_PlayerActor player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Firebird2D.SceneSystem.Actors
|
||||
{
|
||||
public interface I_PlayerActor : I_BaseActor
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Firebird2D.SceneSystem.Actors;
|
||||
using SFML.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Firebird2D.SceneSystem
|
||||
{
|
||||
public interface I_Scene
|
||||
{
|
||||
public string Name { get; }
|
||||
|
||||
public I_PlayerActor Player { get; }
|
||||
|
||||
public List<I_InteractableActor> Interactable { get; }
|
||||
|
||||
public List<I_HitboxActor> Hitbox { get; }
|
||||
|
||||
public List<I_Clickable> Clickables{ get; }
|
||||
|
||||
public I_Scene BuildScene();
|
||||
|
||||
public void DestroyScene();
|
||||
|
||||
public void TickScene(int TimeDifference);
|
||||
|
||||
public void RenderScene(RenderWindow window);
|
||||
|
||||
public void addActor(I_BaseActor Actor);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Firebird2D.SceneSystem.Actors;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Firebird2D.SceneSystem
|
||||
{
|
||||
public abstract class SceneGroup
|
||||
{
|
||||
public string? GroupName { get; protected set; }
|
||||
|
||||
public List<I_Scene>? Scenes { get; protected set; }
|
||||
|
||||
public abstract I_Scene SceneChangeAnimation { get; protected set; }
|
||||
|
||||
public abstract void InitializeGroup();
|
||||
|
||||
public abstract I_Scene getStartingScene();
|
||||
|
||||
public I_Scene? Get_Scene(Type type)
|
||||
{
|
||||
if (type != typeof(I_Scene) || Scenes == null) return null;
|
||||
|
||||
return Scenes.FirstOrDefault(instance => instance.GetType() == type);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using Firebird2D.Core;
|
||||
using Firebird2D.SceneSystem.Actors;
|
||||
using SFML.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Firebird2D.SceneSystem
|
||||
{
|
||||
public static class SceneManager
|
||||
{
|
||||
//static List<I_Scene> scenes = new List<I_Scene>();
|
||||
|
||||
static string scenesPath = "scenes.dll";
|
||||
|
||||
static Assembly sceneDll = null;
|
||||
|
||||
static MainWindow mainWindow = null;
|
||||
|
||||
static SceneGroup ActiveSceneGroup = null;
|
||||
|
||||
public static void LoadScenes(MainWindow renderWindow)
|
||||
{
|
||||
if (mainWindow == null) return; // todo wenn render window null
|
||||
mainWindow = renderWindow;
|
||||
|
||||
sceneDll = Assembly.Load(scenesPath);
|
||||
|
||||
if (sceneDll == null) return; //Todo wenn scenes nicht geladen werden fehler
|
||||
|
||||
Type? scenesConfig = sceneDll.GetType("Scenes.Config");
|
||||
|
||||
if (scenesConfig == null) return; //Todo wenn die scenes config nicht gefunden wird
|
||||
|
||||
FieldInfo? startSceneGroup = scenesConfig.GetField("startingGroup", BindingFlags.Public | BindingFlags.Static);
|
||||
|
||||
if (startSceneGroup == null) return;// Todo wenn die scenes config nicht gefunden wird
|
||||
|
||||
SceneGroup? startingGroup = startSceneGroup.GetValue(null) as SceneGroup;
|
||||
|
||||
if (startingGroup == null) return;//Todo wenn die scenes config nicht gefunden wird
|
||||
|
||||
LoadSceneGroup(startingGroup, null);
|
||||
|
||||
}
|
||||
|
||||
private static async void LoadSceneGroup(SceneGroup sceneGroup, List<I_BaseActor>? carryOverActors)
|
||||
{
|
||||
if (sceneGroup == null) return; //todoo wenn scene group null
|
||||
|
||||
ActiveSceneGroup = sceneGroup;
|
||||
|
||||
changeScene(sceneGroup.SceneChangeAnimation, carryOverActors);
|
||||
|
||||
// Asynchrone Initialisierung der Szene im Hintergrund
|
||||
await Task.Run(() => sceneGroup.InitializeGroup());
|
||||
}
|
||||
|
||||
public static void changeScene(Type type, List<I_BaseActor> carryOverActors)
|
||||
{
|
||||
if (type != typeof(I_Scene)) return;
|
||||
|
||||
I_Scene? scene = ActiveSceneGroup.Get_Scene(type);
|
||||
|
||||
changeScene(scene,carryOverActors);
|
||||
}
|
||||
|
||||
private static void changeScene(I_Scene? scene, List<I_BaseActor>? carryOverActors)
|
||||
{
|
||||
if (scene == null) return; //todo reaction
|
||||
|
||||
if (mainWindow.ActiveSecene != null)
|
||||
mainWindow.ActiveSecene.DestroyScene();
|
||||
|
||||
if (carryOverActors != null)
|
||||
foreach (I_BaseActor actor in carryOverActors)
|
||||
{
|
||||
scene.addActor(actor);
|
||||
}
|
||||
|
||||
mainWindow.ActiveSecene = scene.BuildScene();
|
||||
}
|
||||
|
||||
public static void changeGroup(SceneGroup nextSceneGroup, List<I_BaseActor> carryOverActors)
|
||||
{
|
||||
LoadSceneGroup(nextSceneGroup, carryOverActors);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user