-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started to work on prefab asset editors...
- Loading branch information
1 parent
d92624f
commit 41b92c1
Showing
5 changed files
with
145 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
using ImGuiNET; | ||
using Murder.Assets.Graphics; | ||
using Murder.Components; | ||
using Murder.Core; | ||
using Murder.Core.Geometry; | ||
using Murder.Core.Graphics; | ||
using Murder.Diagnostics; | ||
using Murder.Editor.Attributes; | ||
using Murder.Editor.ImGuiExtended; | ||
using Murder.Editor.Stages; | ||
using Murder.Editor.Systems; | ||
using Murder.Utilities; | ||
using System.Numerics; | ||
|
||
namespace Murder.Editor.CustomEditors | ||
{ | ||
[CustomEditorOf(typeof(SpriteAsset))] | ||
internal class SpriteEditor : CustomEditor | ||
{ | ||
/// <summary> | ||
/// Tracks the dialog system editors across different guids. | ||
/// </summary> | ||
protected Dictionary<Guid, SpriteInformation> ActiveEditors { get; private set; } = new(); | ||
|
||
private SpriteAsset? _sprite = null; | ||
|
||
public override object Target => _sprite!; | ||
|
||
public override void OpenEditor(ImGuiRenderer imGuiRenderer, RenderContext renderContext, object target, bool overwrite) | ||
{ | ||
_sprite = (SpriteAsset)target; | ||
|
||
if (!ActiveEditors.ContainsKey(_sprite.Guid)) | ||
{ | ||
Stage stage = new(imGuiRenderer, renderContext); | ||
|
||
SpriteInformation info = new(stage); | ||
ActiveEditors[_sprite.Guid] = info; | ||
|
||
InitializeStage(stage, info); | ||
} | ||
} | ||
|
||
private void InitializeStage(Stage stage, SpriteInformation info) | ||
{ | ||
GameLogger.Verify(_sprite is not null); | ||
|
||
stage.ToggleSystem(typeof(EntitiesSelectorSystem), false); | ||
|
||
Portrait portrait = new(_sprite.Guid, _sprite.Animations.Count == 0 ? string.Empty : _sprite.Animations.First().Key); | ||
info.HelperId = stage.AddEntityWithoutAsset(new PositionComponent(), new SpriteComponent(portrait)); | ||
|
||
stage.ShowInfo = false; | ||
stage.EditorHook.DrawSelection = false; | ||
stage.EditorHook.CurrentZoomLevel = 5; | ||
} | ||
|
||
public override void DrawEditor() | ||
{ | ||
GameLogger.Verify(_sprite is not null); | ||
|
||
if (!ActiveEditors.TryGetValue(_sprite.Guid, out var info)) | ||
{ | ||
GameLogger.Warning("Unitialized stage for particle editor?"); | ||
return; | ||
} | ||
|
||
Vector2 windowSize = ImGui.GetContentRegionAvail(); | ||
|
||
using TableMultipleColumns table = new( | ||
$"sprite_stage_{_sprite.Guid}", ImGuiTableFlags.Resizable, Calculator.RoundToInt(windowSize.X / 5), -1, Calculator.RoundToInt(windowSize.X / 5)); | ||
|
||
ImGui.TableNextColumn(); | ||
|
||
DrawFistColumn(); | ||
|
||
ImGui.TableNextColumn(); | ||
|
||
Stage stage = info.Stage; | ||
|
||
if (ActiveEditors.ContainsKey(_sprite.Guid)) | ||
{ | ||
windowSize = ImGui.GetContentRegionAvail(); | ||
Vector2 origin = ImGui.GetItemRectMin(); | ||
float length = windowSize.X / 3f; | ||
|
||
stage.Draw(); | ||
} | ||
|
||
ImGui.TableNextRow(); | ||
ImGui.TableNextColumn(); | ||
} | ||
|
||
private void DrawFistColumn() | ||
{ | ||
GameLogger.Verify(_sprite is not null); | ||
|
||
|
||
Vector2 windowSize = ImGui.GetContentRegionAvail(); | ||
ImGui.PushID("somed"); | ||
ImGui.PushItemWidth(20); | ||
ImGui.TextColored(Game.Profile.Theme.Accent, $"\uf520 {_sprite.Name}"); | ||
ImGuiHelpers.PrettySelectableWithIcon( | ||
label: _sprite.Name, | ||
selectable: true); | ||
ImGui.PopItemWidth(); | ||
ImGui.PopID(); | ||
} | ||
|
||
public override void CloseEditor(Guid target) | ||
{ | ||
if (ActiveEditors.TryGetValue(target, out SpriteInformation? info)) | ||
{ | ||
info.Stage.Dispose(); | ||
} | ||
|
||
ActiveEditors.Remove(target); | ||
} | ||
|
||
protected record SpriteInformation(Stage Stage) | ||
{ | ||
/// <summary> | ||
/// This is the entity id in the world. | ||
/// </summary> | ||
public int HelperId = 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters