A simple .NET Framework to make 2D games quick and easy.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Inspector Rework

+215 -52
+1 -1
src/Debug/Debug.cs
··· 60 60 public static class Debug { 61 61 62 62 public static List<DebugLog> Logs = new List<DebugLog>(); 63 - internal static DebugLog lastTopMessage; 63 + 64 64 65 65 public static Dictionary<string, Action<object[]>> commands = new Dictionary<string, Action<object[]>>(); 66 66
+24 -51
src/Debug/InspectorScene.cs
··· 10 10 public class InspectorScene : Scene 11 11 { 12 12 float yOffset = 0; 13 + public string SelectedScene = ""; 13 14 14 15 public InspectorScene(int width, int height, string id) : base(width, height, id) 15 16 { 16 17 SetClearColor(UiStyles.Background); 17 - SetUpdateOnlyIfActive(true); 18 + // SetUpdateOnlyIfActive(true); 18 19 } 19 20 20 21 public override void Update() 21 22 { 23 + if(SelectedScene == "") 24 + { 25 + SelectedScene = SceneHandler.Scenes.First(e => e.Key != "Inspector" && e.Key != "Console" && e.Key != "Performance").Key; 26 + } 27 + 22 28 if(MouseInsideScene) 23 29 { 24 30 if(Mouse.Pressed(MB.ScrollDown)) { ··· 30 36 } 31 37 32 38 new UiBuilder(new Vector4(0, yOffset, (int)(Game.Window.Width * 0.2), (int)Game.Window.Height), Mouse.Position) 33 - .Title("Inspector") 34 - .Container( 35 - "Scenes", 39 + .Title($"Inspector for {SelectedScene}") 40 + .ForEach(SceneHandler.Get(SelectedScene).Entities, (e) => 36 41 new UiBuilder() 37 - .ForEach(SceneHandler.Scenes.ToList(), (val, idx) => 38 - { 42 + .Title(e.name == null ? e.ToString()! : e.name) 43 + .ForEach(e.Components, (c) => { 44 + 39 45 var list = new UiBuilder() 40 - .Title(val.Key) 41 - .ButtonGroup( 42 - new UiButton("Load", () => SceneHandler.Load(val.Key)), 43 - new UiButton("Unload", () => SceneHandler.Unload(val.Key)), 44 - new UiButton("Remake", () => SceneHandler.Remake(val.Key)) 45 - ) 46 - .Button("Apply Aspect Ratio", () => val.Value.ApplyOriginalAspectRatio()) 47 - .Checkbox("Allow window resize", val.Value.AllowWindowResize, () => val.Value.SetAllowWindowResize(!val.Value.AllowWindowResize)) 48 - .Checkbox("Always at back", val.Value.AlwaysAtBack, () => val.Value.SetAlwaysAtBack(!val.Value.AlwaysAtBack)) 49 - .Checkbox("Always rebuild texture", val.Value.AlwaysRebuildTexture, () => val.Value.SetAlwaysRebuildTexture(!val.Value.AlwaysRebuildTexture)) 46 + .Title(c.ToString()) 50 47 .Build(); 51 48 52 - FieldInfo[] infos = val.Value.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); 49 + FieldInfo[] infos = c.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); 53 50 54 51 List<object> exports = new() { 55 52 ··· 58 55 foreach(var fi in infos) { 59 56 if (fi.IsDefined(typeof(Export), true)) 60 57 { 61 - var fival = fi.GetValue(val.Value); 58 + var fival = fi.GetValue(c); 62 59 if(fival is not null) 63 60 { 64 61 exports.Add(new UiText(fi.Name)); ··· 66 63 { 67 64 exports.Add(new UiTextField(fi.Name, fival.ToString()!, (result) => 68 65 { 69 - fi.SetValue(val.Value, result); 66 + fi.SetValue(c, result); 70 67 }, (result) => { })); 71 68 } 72 69 else if (fival.GetType() == typeof(bool)) ··· 74 71 exports.RemoveAt(exports.Count - 1); 75 72 exports.Add(new UiCheckbox(fi.Name, (bool)fival, () => 76 73 { 77 - fi.SetValue(val.Value, !(bool)fival); 74 + fi.SetValue(c, !(bool)fival); 78 75 })); 79 76 } 80 77 else if (fival.GetType() == typeof(float)) ··· 88 85 89 86 exports.Add(new UiSlider(a.sliderMin, a.sliderMax, (float)fival, (result) => 90 87 { 91 - fi.SetValue(val.Value, result); 88 + fi.SetValue(c, result); 92 89 })); 93 90 } 94 91 } else if(fival.GetType() == typeof(int)) { ··· 100 97 Export a = (Export)expor; 101 98 102 99 exports.Add(new UiSlider(a.sliderMin, a.sliderMax, (int)fival, (result) => { 103 - fi.SetValue(val.Value, (int)result); 100 + fi.SetValue(c, (int)result); 104 101 })); 105 102 } 106 103 } else { ··· 113 110 114 111 if (exports.Count > 0) 115 112 { 116 - list.Add(new UiTitle($"Exports")); 117 - list.Add(exports); 113 + list.AddRange(exports); 114 + return list; 118 115 } 119 116 120 - if (idx != SceneHandler.Scenes.ToList().Count - 1) 121 - { 122 - list.Add(new UiSpacer()); 123 - } 124 - 125 - return list; 126 - }) 127 - .Build() 128 - ) 129 - .Container( 130 - "Loaded Scenes", 131 - new UiBuilder() 132 - .ForEach(SceneHandler.LoadedScenes, (scene, idx) => 133 - { 134 - var list = new List<object>() 135 - { 136 - new UiTitle(scene), 137 - new UiButton("Unload", () => SceneHandler.Unload(scene)) 138 - }; 139 - 140 - if (idx != SceneHandler.LoadedScenes.Count - 1) 141 - { 142 - list.Add(new UiSpacer()); 143 - } 144 - 145 - return list; 117 + return new UiBuilder() 118 + .Build(); 146 119 }) 147 120 .Build() 148 121 ) ··· 151 124 if(MouseInsideScene) 152 125 { 153 126 if(uiHeight > WindowSize.Y) { 154 - if(-yOffset < 0) { 127 + if(-yOffset < 0) { 155 128 yOffset = 0; 156 129 } 157 130 if(-yOffset > uiHeight - WindowSize.Y + 50) {
+167
src/Debug/OldInspectorScene.cs
··· 1 + using System.Numerics; 2 + using System.Reflection; 3 + using Fjord.Input; 4 + using Fjord.Ui; 5 + using Fjord.Graphics; 6 + using static SDL2.SDL; 7 + 8 + namespace Fjord.Scenes; 9 + 10 + public class OldInspectorScene : Scene 11 + { 12 + float yOffset = 0; 13 + 14 + public OldInspectorScene(int width, int height, string id) : base(width, height, id) 15 + { 16 + SetClearColor(UiStyles.Background); 17 + SetUpdateOnlyIfActive(true); 18 + } 19 + 20 + public override void Update() 21 + { 22 + if(MouseInsideScene) 23 + { 24 + if(Mouse.Pressed(MB.ScrollDown)) { 25 + yOffset -= 10; 26 + } 27 + if(Mouse.Pressed(MB.ScrollUp)) { 28 + yOffset += 10; 29 + } 30 + } 31 + 32 + new UiBuilder(new Vector4(0, yOffset, (int)(Game.Window.Width * 0.2), (int)Game.Window.Height), Mouse.Position) 33 + .Title("Inspector") 34 + .Container( 35 + "Scenes", 36 + new UiBuilder() 37 + .ForEach(SceneHandler.Scenes.ToList(), (val, idx) => 38 + { 39 + var list = new UiBuilder() 40 + .Title(val.Key) 41 + .ButtonGroup( 42 + new UiButton("Load", () => SceneHandler.Load(val.Key)), 43 + new UiButton("Unload", () => SceneHandler.Unload(val.Key)), 44 + new UiButton("Remake", () => SceneHandler.Remake(val.Key)) 45 + ) 46 + .Button("Apply Aspect Ratio", () => val.Value.ApplyOriginalAspectRatio()) 47 + .Checkbox("Allow window resize", val.Value.AllowWindowResize, () => val.Value.SetAllowWindowResize(!val.Value.AllowWindowResize)) 48 + .Checkbox("Always at back", val.Value.AlwaysAtBack, () => val.Value.SetAlwaysAtBack(!val.Value.AlwaysAtBack)) 49 + .Checkbox("Always rebuild texture", val.Value.AlwaysRebuildTexture, () => val.Value.SetAlwaysRebuildTexture(!val.Value.AlwaysRebuildTexture)) 50 + .Build(); 51 + 52 + FieldInfo[] infos = val.Value.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); 53 + 54 + List<object> exports = new() { 55 + 56 + }; 57 + 58 + foreach(var fi in infos) { 59 + if (fi.IsDefined(typeof(Export), true)) 60 + { 61 + var fival = fi.GetValue(val.Value); 62 + if(fival is not null) 63 + { 64 + exports.Add(new UiText(fi.Name)); 65 + if (fival.GetType() == typeof(string)) 66 + { 67 + exports.Add(new UiTextField(fi.Name, fival.ToString()!, (result) => 68 + { 69 + fi.SetValue(val.Value, result); 70 + }, (result) => { })); 71 + } 72 + else if (fival.GetType() == typeof(bool)) 73 + { 74 + exports.RemoveAt(exports.Count - 1); 75 + exports.Add(new UiCheckbox(fi.Name, (bool)fival, () => 76 + { 77 + fi.SetValue(val.Value, !(bool)fival); 78 + })); 79 + } 80 + else if (fival.GetType() == typeof(float)) 81 + { 82 + exports.RemoveAt(exports.Count - 1); 83 + exports.Add(new UiText($"{fi.Name} ({(float)fival})")); 84 + var expor = fi.GetCustomAttribute(typeof(Export)); 85 + if (expor is not null) 86 + { 87 + Export a = (Export)expor; 88 + 89 + exports.Add(new UiSlider(a.sliderMin, a.sliderMax, (float)fival, (result) => 90 + { 91 + fi.SetValue(val.Value, result); 92 + })); 93 + } 94 + } else if(fival.GetType() == typeof(int)) { 95 + exports.RemoveAt(exports.Count - 1); 96 + exports.Add(new UiText($"{fi.Name} ({(int)fival})")); 97 + var expor = fi.GetCustomAttribute(typeof(Export)); 98 + if (expor is not null) 99 + { 100 + Export a = (Export)expor; 101 + 102 + exports.Add(new UiSlider(a.sliderMin, a.sliderMax, (int)fival, (result) => { 103 + fi.SetValue(val.Value, (int)result); 104 + })); 105 + } 106 + } else { 107 + exports.RemoveAt(exports.Count - 1); 108 + exports.Add(new UiText($"{fi.Name} has an unsupported type: {fival.GetType()}!")); 109 + } 110 + } 111 + } 112 + } 113 + 114 + if (exports.Count > 0) 115 + { 116 + list.Add(new UiTitle($"Exports")); 117 + list.Add(exports); 118 + } 119 + 120 + if (idx != SceneHandler.Scenes.ToList().Count - 1) 121 + { 122 + list.Add(new UiSpacer()); 123 + } 124 + 125 + return list; 126 + }) 127 + .Build() 128 + ) 129 + .Container( 130 + "Loaded Scenes", 131 + new UiBuilder() 132 + .ForEach(SceneHandler.LoadedScenes, (scene, idx) => 133 + { 134 + var list = new List<object>() 135 + { 136 + new UiTitle(scene), 137 + new UiButton("Unload", () => SceneHandler.Unload(scene)) 138 + }; 139 + 140 + if (idx != SceneHandler.LoadedScenes.Count - 1) 141 + { 142 + list.Add(new UiSpacer()); 143 + } 144 + 145 + return list; 146 + }) 147 + .Build() 148 + ) 149 + .Render(out int uiHeight); 150 + 151 + if(MouseInsideScene) 152 + { 153 + if(uiHeight > WindowSize.Y) { 154 + if(-yOffset < 0) { 155 + yOffset = 0; 156 + } 157 + if(-yOffset > uiHeight - WindowSize.Y + 50) { 158 + yOffset = -uiHeight + WindowSize.Y - 50; 159 + } 160 + } else { 161 + yOffset = 0; 162 + } 163 + } 164 + } 165 + } 166 + 167 +
+16
src/Entity/Component.cs
··· 59 59 60 60 public class Transform : Component 61 61 { 62 + [Export] 62 63 public Vector2 Position; 64 + 65 + [Export(0, 360)] 63 66 public float Angle; 67 + 68 + public override void Update() 69 + { 70 + if(Angle > 360) 71 + { 72 + Angle = 0; 73 + } 74 + 75 + if(Angle < 0) 76 + { 77 + Angle = 360; 78 + } 79 + } 64 80 }
+7
src/Entity/Entity.cs
··· 5 5 internal SceneKeyboard Keyboard; 6 6 internal SceneMouse Mouse; 7 7 internal Scene Parent; 8 + internal string? name; 8 9 9 10 internal List<Component> Components = new(); 10 11 ··· 15 16 this.Mouse = parent.Mouse; 16 17 17 18 this.Components.Add(new Transform()); 19 + } 20 + 21 + public Entity Name(string name) 22 + { 23 + this.name = name; 24 + return this; 18 25 } 19 26 20 27 public Entity Add(Component component)