Skip to content

Commit

Permalink
more scd ui tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
0ceal0t committed Feb 25, 2024
1 parent 7150319 commit 66bb8f7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 55 deletions.
2 changes: 1 addition & 1 deletion VFXEditor/Formats/ScdFormat/Sound/ScdSoundEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public override void Read( BinaryReader reader ) {
}

public override void Write( BinaryWriter writer ) {
writer.Write( ( byte )( RandomTracksEnabled ? RandomTracks.Tracks.Count : Tracks.Entries.Count ) );
writer.Write( ( byte )( RandomTracksEnabled ? RandomTracks.Entries.Count : Tracks.Entries.Count ) );
BusNumber.Write( writer );
Priority.Write( writer );
Type.Write( writer );
Expand Down
49 changes: 23 additions & 26 deletions VFXEditor/Formats/ScdFormat/Sound/SoundRandomTracks.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
using ImGuiNET;
using Dalamud.Interface.Utility.Raii;
using ImGuiNET;
using System.Collections.Generic;
using System.IO;
using VfxEditor.Data.Command.ListCommands;
using VfxEditor.Parsing;
using VfxEditor.Parsing.Int;
using VfxEditor.Utils;
using VfxEditor.Ui.Components.Tables;
using VfxEditor.Ui.Interfaces;

namespace VfxEditor.ScdFormat {
public class SoundRandomTracks {
public List<RandomTrackInfo> Tracks = new();
public readonly List<RandomTrackInfo> Entries = new();
private readonly CommandTable<RandomTrackInfo> EntryTable;

public readonly ParsedInt CycleInterval = new( "Cycle Interval" );
public readonly ParsedShort CycleNumPlayTrack = new( "Cycle Play Track" );
public readonly ParsedShort CycleRange = new( "Cycle Range" );

public SoundRandomTracks() {
EntryTable = new( "Entries", true, false, Entries, new() {
( "Track Index", ImGuiTableColumnFlags.None, -1 ),
( "Audio Index", ImGuiTableColumnFlags.None, -1 ),
( "Limit", ImGuiTableColumnFlags.None, -1 ),
},
() => new() );
}

public void Read( BinaryReader reader, SoundType type, byte trackCount ) {
for( var i = 0; i < trackCount; i++ ) {
var newTrack = new RandomTrackInfo();
newTrack.Read( reader );
Tracks.Add( newTrack );
Entries.Add( newTrack );
}

if( type == SoundType.Cycle ) {
Expand All @@ -29,7 +40,7 @@ public void Read( BinaryReader reader, SoundType type, byte trackCount ) {
}

public void Write( BinaryWriter writer, SoundType type ) {
Tracks.ForEach( x => x.Write( writer ) );
Entries.ForEach( x => x.Write( writer ) );

if( type == SoundType.Cycle ) {
CycleInterval.Write( writer );
Expand All @@ -49,30 +60,13 @@ public void Draw( SoundType type ) {

ImGui.SetCursorPosY( ImGui.GetCursorPosY() + 3 );

for( var idx = 0; idx < Tracks.Count; idx++ ) {
if( ImGui.CollapsingHeader( $"Track #{idx}", ImGuiTreeNodeFlags.DefaultOpen ) ) {
using var __ = ImRaii.PushId( idx );
using var indent = ImRaii.PushIndent();

if( UiUtils.RemoveButton( "Delete", true ) ) { // REMOVE
CommandManager.Add( new ListRemoveCommand<RandomTrackInfo>( Tracks, Tracks[idx] ) );
break;
}

Tracks[idx].Draw();
ImGui.SetCursorPosY( ImGui.GetCursorPosY() + 3 );
}
}

if( ImGui.Button( "+ New" ) ) { // NEW
CommandManager.Add( new ListAddCommand<RandomTrackInfo>( Tracks, new RandomTrackInfo() ) );
}
EntryTable.Draw();
}
}

public class RandomTrackInfo {
public class RandomTrackInfo : IUiItem {
public readonly SoundTrackInfo Track = new();
public readonly ParsedShort2 Limit = new( "Limit" );
public readonly ParsedShort2 Limit = new( "##Limit" );

public void Read( BinaryReader reader ) {
Track.Read( reader );
Expand All @@ -86,6 +80,9 @@ public void Write( BinaryWriter writer ) {

public void Draw() {
Track.Draw();

ImGui.TableNextColumn();
ImGui.SetNextItemWidth( 150 );
Limit.Draw();
}
}
Expand Down
49 changes: 21 additions & 28 deletions VFXEditor/Formats/ScdFormat/Sound/SoundTracks.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
using Dalamud.Interface.Utility.Raii;
using ImGuiNET;
using System.Collections.Generic;
using System.IO;
using VfxEditor.Data.Command.ListCommands;
using VfxEditor.Parsing;
using VfxEditor.Utils;
using VfxEditor.Ui.Components.Tables;
using VfxEditor.Ui.Interfaces;

namespace VfxEditor.ScdFormat {
public class SoundTracks {
public List<SoundTrackInfo> Entries = new();
public readonly List<SoundTrackInfo> Entries = new();
private readonly CommandTable<SoundTrackInfo> EntryTable;

public SoundTracks() {
EntryTable = new( "Entries", true, false, Entries, new() {
( "Track Index", ImGuiTableColumnFlags.None, -1 ),
( "Audio Index", ImGuiTableColumnFlags.None, -1 ),
},
() => new() );
}

public void Read( BinaryReader reader, byte entryCount ) {
for( var i = 0; i < entryCount; i++ ) {
Expand All @@ -23,33 +31,13 @@ public void Write( BinaryWriter writer ) {
}

public void Draw() {
using var _ = ImRaii.PushId( "Entries" );

ImGui.SetCursorPosY( ImGui.GetCursorPosY() + 3 );

for( var idx = 0; idx < Entries.Count; idx++ ) {
if( ImGui.CollapsingHeader( $"Entry #{idx}", ImGuiTreeNodeFlags.DefaultOpen ) ) {
using var __ = ImRaii.PushId( idx );
using var indent = ImRaii.PushIndent();

if( UiUtils.RemoveButton( "Delete", true ) ) { // REMOVE
CommandManager.Add( new ListRemoveCommand<SoundTrackInfo>( Entries, Entries[idx] ) );
}

Entries[idx].Draw();
ImGui.SetCursorPosY( ImGui.GetCursorPosY() + 3 );
}
}

if( ImGui.Button( "+ New" ) ) { // NEW
CommandManager.Add( new ListAddCommand<SoundTrackInfo>( Entries, new SoundTrackInfo() ) );
}
EntryTable.Draw();
}
}

public class SoundTrackInfo {
public readonly ParsedShort TrackIdx = new( "Track Index" );
public readonly ParsedShort AudioIdx = new( "Audio Index" );
public class SoundTrackInfo : IUiItem {
public readonly ParsedShort TrackIdx = new( "##Track" );
public readonly ParsedShort AudioIdx = new( "##Audio" );

public void Read( BinaryReader reader ) {
TrackIdx.Read( reader );
Expand All @@ -62,7 +50,12 @@ public void Write( BinaryWriter writer ) {
}

public void Draw() {
ImGui.TableNextColumn();
ImGui.SetNextItemWidth( 100 );
TrackIdx.Draw();

ImGui.TableNextColumn();
ImGui.SetNextItemWidth( 100 );
AudioIdx.Draw();
}
}
Expand Down

0 comments on commit 66bb8f7

Please sign in to comment.