Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions VFXEditor/Formats/PhybFormat/Simulator/Chain/PhybChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using VfxEditor.PhybFormat.Simulator.CollisionData;
using VfxEditor.PhybFormat.Utils;
using VfxEditor.Ui.Components.SplitViews;
using VfxEditor.FileBrowser;

namespace VfxEditor.PhybFormat.Simulator.Chain {
public enum ChainType {
Expand Down Expand Up @@ -121,5 +122,14 @@ public void AddPhysicsObjects( MeshBuilders meshes, Dictionary<string, Bone> bon
foreach( var item in Collisions ) item.AddPhysicsObjects( meshes, boneMatrixes );
foreach( var item in Nodes ) item.AddPhysicsObjects( meshes, boneMatrixes );
}

private byte[] ToBytes() {
return [];
}

public void SaveDialog() =>
FileBrowserManager.SaveFileDialog( "Select a Save Location", ".phybchain,.*", "ExportedPhybChain", "phybchain", ( bool ok, string res ) => {
if( ok ) System.IO.File.WriteAllBytes( res, ToBytes() );
} );
}
}
5 changes: 2 additions & 3 deletions VFXEditor/Formats/PhybFormat/Simulator/PhybSimulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class PhybSimulation : IPhysicsObject {

public readonly List<PhybSimulator> Simulators = [];

private readonly CommandDropdown<PhybSimulator> SimulatorDropdown;
private readonly CommandSaveDropdown<PhybSimulator> SimulatorDropdown;

public PhybSimulation( PhybFile file, BinaryReader reader, bool isEmpty ) {
File = file;
Expand All @@ -23,8 +23,7 @@ public PhybSimulation( PhybFile file, BinaryReader reader, bool isEmpty ) {
for( var i = 0; i < numSimulators; i++ ) Simulators.Add( new PhybSimulator( file, reader, startPos ) );
}

SimulatorDropdown = new( "Simulator", Simulators,
null, () => new PhybSimulator( File ) );
SimulatorDropdown = new( "Simulator", Simulators, null, () => new PhybSimulator( File ) );
}

public void Write( SimulationWriter writer ) {
Expand Down
15 changes: 12 additions & 3 deletions VFXEditor/Formats/PhybFormat/Simulator/PhybSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using VfxEditor.Ui.Components;
using VfxEditor.Ui.Components.SplitViews;
using VfxEditor.Ui.Interfaces;
using VfxEditor.FileBrowser;

namespace VfxEditor.PhybFormat.Simulator {
public class PhybSimulator : IUiItem, IPhysicsObject {
Expand All @@ -35,7 +36,7 @@ public class PhybSimulator : IUiItem, IPhysicsObject {

private readonly CommandSplitView<PhybCollisionData> CollisionSplitView;
private readonly CommandSplitView<PhybCollisionData> CollisionConnectorSplitView;
private readonly CommandDropdown<PhybChain> ChainDropdown;
private readonly CommandSaveDropdown<PhybChain> ChainDropdown;
private readonly CommandSplitView<PhybConnector> ConnectorSplitView;
private readonly CommandSplitView<PhybAttract> AttractSplitView;
private readonly CommandSplitView<PhybPin> PinSplitView;
Expand All @@ -52,8 +53,7 @@ public PhybSimulator( PhybFile file ) {
CollisionConnectorSplitView = new( "Collision Connector", CollisionConnectors, false,
( PhybCollisionData item, int idx ) => item.CollisionName.Value, () => new( File, this ), ( PhybCollisionData _, bool _ ) => File.OnChange() );

ChainDropdown = new( "Chain", Chains,
null, () => new( File, this ), ( PhybChain _, bool _ ) => File.OnChange() );
ChainDropdown = new( "Chain", Chains, null, () => new( File, this ), ( PhybChain _, bool _ ) => File.OnChange() );

ConnectorSplitView = new( "Connector", Connectors, false,
null, () => new( File, this ), ( PhybConnector _, bool _ ) => File.OnChange() );
Expand Down Expand Up @@ -252,5 +252,14 @@ public bool GetNode( int chainId, int nodeId, Dictionary<string, Bone> boneMatri

return true;
}

private byte[] ToBytes() {
return [];
}

public void SaveDialog() =>
FileBrowserManager.SaveFileDialog( "Select a Save Location", ".phybsimulator,.*", "ExportedPhybSimulator", "phybsimulator", ( bool ok, string res ) => {
if( ok ) System.IO.File.WriteAllBytes( res, ToBytes() );
} );
}
}
60 changes: 60 additions & 0 deletions VFXEditor/Formats/PhybFormat/Utils/CommandSaveDropdown.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using Dalamud.Interface;
using Dalamud.Interface.Utility.Raii;
using System.Collections.Generic;
using VfxEditor.Ui.Interfaces;
using VfxEditor.Utils;
using VfxEditor.PhybFormat.Simulator;
using VfxEditor.PhybFormat.Simulator.Chain;
using ImGuiNET;

namespace VfxEditor.Ui.Components {
public class CommandSaveDropdown<T> : CommandDropdown<T> where T : class, IUiItem {

public CommandSaveDropdown(
string id,
List<T> items,
Func<T, int, string> getTextAction,
Func<T> newAction,
Action<T, bool> onChangeAction = null
) : base( id, items, getTextAction, newAction, onChangeAction ) {

}

protected override void DrawNewDeleteControls( Action onNew, Action<T> onDelete ) {
if( onNew != null ) {
using var font = ImRaii.PushFont( UiBuilder.IconFont );
ImGui.SameLine();
if( ImGui.Button( FontAwesomeIcon.Plus.ToIconString() ) ) onNew();
}

using var disabled = ImRaii.Disabled( Selected == null );

if( typeof(T) == typeof(PhybSimulator) || typeof(T) == typeof(PhybChain) ) {
// coerce selected to export type
// TODO add onto IPhysicsObject instead?
using var font = ImRaii.PushFont( UiBuilder.IconFont );
ImGui.SameLine();
if( ImGui.Button( FontAwesomeIcon.Save.ToIconString() ) && Items.Contains( Selected ) ) {
var coerced = Selected as PhybSimulator;
if (coerced != null) {
coerced.SaveDialog();
} else {
var coerced_chain = Selected as PhybChain;
coerced_chain.SaveDialog();
}
}
}

if( onDelete != null ) {
using var font = ImRaii.PushFont( UiBuilder.IconFont );
ImGui.SameLine();
ImGui.SetCursorPosX( ImGui.GetCursorPosX() - 4 );
if( UiUtils.RemoveButton( FontAwesomeIcon.Trash.ToIconString() ) && Items.Contains( Selected ) ) {
onDelete( Selected );
Selected = null;
}
}
}
}
}
6 changes: 3 additions & 3 deletions VFXEditor/Ui/Components/Dropdowns/CommandDropdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

namespace VfxEditor.Ui.Components {
public class CommandDropdown<T> : UiDropdown<T> where T : class, IUiItem {
private readonly Func<T, int, string> GetTextAction;
private readonly Func<T> NewAction;
private readonly Action<T, bool> OnChangeAction;
protected readonly Func<T, int, string> GetTextAction;
protected readonly Func<T> NewAction;
protected readonly Action<T, bool> OnChangeAction;

public CommandDropdown( string id, List<T> items, Func<T, int, string> getTextAction, Func<T> newAction, Action<T, bool> onChangeAction = null ) : base( id, items ) {
GetTextAction = getTextAction;
Expand Down
2 changes: 1 addition & 1 deletion VFXEditor/Ui/Components/Dropdowns/Dropdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void DrawCombo() {

// ===========

protected void DrawNewDeleteControls( Action onNew, Action<T> onDelete ) {
protected virtual void DrawNewDeleteControls( Action onNew, Action<T> onDelete ) {
if( onNew != null ) {
using var font = ImRaii.PushFont( UiBuilder.IconFont );
ImGui.SameLine();
Expand Down