Skip to content

Commit

Permalink
use observablecollection for lists of opcodes, add basic rendering of…
Browse files Browse the repository at this point in the history
… opcodes
  • Loading branch information
krogenth committed Aug 20, 2023
1 parent 642ab0e commit 4e97f9c
Show file tree
Hide file tree
Showing 11 changed files with 392 additions and 122 deletions.
7 changes: 3 additions & 4 deletions src/G2DataGUI.Common/Data/Maps/MapDialogue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
using G2DataGUI.Common.Data.Maps.MapDialogueOpcodes;
using G2DataGUI.IO.Streams;
using System.Linq;
using System.Collections.ObjectModel;

namespace G2DataGUI.Common.Data.Maps;
public class MapDialogue
{
public MapDialogueHeader Header { get; set; }
public List<byte[]> DialogueSections { get; set; } = new();
public List<List<IMapDialogueOpcode>> DialogueSectionOpcodes { get; set; } = new();
public ObservableCollection<ObservableCollection<IMapDialogueOpcode>> DialogueSectionOpcodes { get; set; } = new();

public static MapDialogue ReadMapDialogue(Stream reader, uint dialogueSectionLength)
{
Expand All @@ -21,7 +22,7 @@ public static MapDialogue ReadMapDialogue(Stream reader, uint dialogueSectionLen
var dialogueStartPosition = reader.Position;
for (var index = 1; index < dialogue.Header.Offsets.Count; index++)
{
dialogue.DialogueSectionOpcodes.Add(new List<IMapDialogueOpcode>());
dialogue.DialogueSectionOpcodes.Add(new ObservableCollection<IMapDialogueOpcode>());
var length = (index == dialogue.Header.Offsets.Count - 1) ?
(dialogueSectionLength - dialogue.Header.HeaderLength - (dialogue.Header.Offsets[index - 1].Offset * 8)) :
(dialogue.Header.Offsets[index].Offset - dialogue.Header.Offsets[index - 1].Offset) * 8;
Expand All @@ -40,9 +41,7 @@ public static MapDialogue ReadMapDialogue(Stream reader, uint dialogueSectionLen
}
}

//var dialogueStartPosition = reader.Position;
reader.Seek(dialogueStartPosition, SeekOrigin.Begin);
//var dialogueStartPosition = reader.Position;
for (var index = 1; index < dialogue.Header.Offsets.Count; index++)
{
var length = (index == dialogue.Header.Offsets.Count - 1) ?
Expand Down
22 changes: 0 additions & 22 deletions src/G2DataGUI.Common/Data/Maps/MapDialogueOpcodes/PauseOpcode.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using G2DataGUI.Common.Extensions;
using G2DataGUI.IO.Streams;
Expand All @@ -15,7 +15,7 @@ public class CreateOptionsTextBoxOpcode : ITextBoxOpcode, IMapDialogueOpcode
public TextBoxOption Option { get; set; } = TextBoxOption.CreateOptionsTextBox;
public byte TextBoxLength { get; set; }
public byte TextBoxHeight { get; set; }
public IList<IMapDialogueOpcode> NestedOpcodes { get; set; } = new List<IMapDialogueOpcode>();
public ObservableCollection<IMapDialogueOpcode> NestedOpcodes { get; set; } = new();

public static IMapDialogueOpcode ReadOpcode(Stream reader)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using G2DataGUI.Common.Extensions;
using G2DataGUI.IO.Streams;
Expand All @@ -11,7 +11,7 @@ public class CreateOverworldTextBoxOpcode : ITextBoxOpcode, IMapDialogueOpcodeRe
public TextBoxOption Option { get; set; } = TextBoxOption.CreateOverworldTextBox;
public byte TextBoxLength { get; set; }
public byte TextBoxHeight { get; set; }
public IList<IMapDialogueOpcode> NestedOpcodes { get; set; } = new List<IMapDialogueOpcode>();
public ObservableCollection<IMapDialogueOpcode> NestedOpcodes { get; set; } = new();

public static IMapDialogueOpcode ReadOpcode(Stream reader)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using G2DataGUI.Common.Extensions;
using G2DataGUI.IO.Streams;
Expand All @@ -16,7 +16,7 @@ internal class CreateSubTextBoxOpcode : ITextBoxOpcode, IMapDialogueOpcode
public TextBoxOption Option { get; set; } = TextBoxOption.CreateSubTextBox;
public byte Unknown1 { get; set; }
public byte TextBoxHeight { get; set; }
public IList<IMapDialogueOpcode> NestedOpcodes { get; set; } = new List<IMapDialogueOpcode>();
public ObservableCollection<IMapDialogueOpcode> NestedOpcodes { get; set; } = new();

public static IMapDialogueOpcode ReadOpcode(Stream reader)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using G2DataGUI.Common.Extensions;
using G2DataGUI.IO.Streams;
Expand All @@ -9,7 +9,7 @@ public class CreateTextBoxOpcode : ITextBoxOpcode, IMapDialogueOpcodeReader
{
public DialogueOpcode Opcode { get; set; } = DialogueOpcode.TextBox;
public TextBoxOption Option { get; set; } = TextBoxOption.CreateTextBox;
public IList<IMapDialogueOpcode> NestedOpcodes { get; set; } = new List<IMapDialogueOpcode>();
public ObservableCollection<IMapDialogueOpcode> NestedOpcodes { get; set; } = new();

public static IMapDialogueOpcode ReadOpcode(Stream reader)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using G2DataGUI.Common.Extensions;
using G2DataGUI.IO.Streams;
Expand All @@ -8,7 +8,7 @@ namespace G2DataGUI.Common.Data.Maps.MapDialogueOpcodes.TextBox;
public interface ITextBoxOpcode : IMapDialogueOpcode, IMapDialogueOpcodeReader
{
TextBoxOption Option { get; set; }
public IList<IMapDialogueOpcode> NestedOpcodes { get; set; }
public ObservableCollection<IMapDialogueOpcode> NestedOpcodes { get; set; }

public static new IMapDialogueOpcode ReadOpcode(Stream reader)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;

namespace G2DataGUI.Common.Data.Maps.MapDialogueOpcodes.TextBox;
Expand All @@ -7,7 +7,7 @@ public class RemoveTextBoxOpcode : ITextBoxOpcode, IMapDialogueOpcodeReader
{
public DialogueOpcode Opcode { get; set; } = DialogueOpcode.TextBox;
public TextBoxOption Option { get; set; } = TextBoxOption.RemoveTextBox;
public IList<IMapDialogueOpcode> NestedOpcodes { get; set; } = new List<IMapDialogueOpcode>();
public ObservableCollection<IMapDialogueOpcode> NestedOpcodes { get; set; } = new();

public static IMapDialogueOpcode ReadOpcode(Stream reader)
{
Expand Down
17 changes: 16 additions & 1 deletion src/G2DataGUI/UI/Selectors/MapOpcodeSelector.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Markup.Xaml.Templates;
using Avalonia.Metadata;
using G2DataGUI.Common.Data.Maps.MapDialogueOpcodes;

namespace G2DataGUI.UI.Selectors;
public class MapOpcodeSelector : IDataTemplate

public class MapOpcodeSelector : ITreeDataTemplate
{
[Content]
public Dictionary<string, IDataTemplate> Templates { get; private set; } = new();

public InstancedBinding ItemsSelector(object item)
{
if (item is IMapDialogueOpcode opcode)
{
return ((TreeDataTemplate)Templates[opcode.GetType().Name]).ItemsSelector(item);
}
else
{
return null;
}
}

public IControl Build(object data) =>
Templates[data.GetType().Name].Build(data);

Expand Down
12 changes: 6 additions & 6 deletions src/G2DataGUI/UI/ViewModels/MapDialogueViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using G2DataGUI.Common.Data.Maps.MapDialogueOpcodes;
using G2DataGUI.UI.Common.ViewModels;

namespace G2DataGUI.UI.ViewModels;

public class MapDialogueViewModel : BaseViewModel
{
private List<List<IMapDialogueOpcode>> _selectedMapDialogueOpcodes = new();
private ObservableCollection<ObservableCollection<IMapDialogueOpcode>> _selectedMapDialogueOpcodes = new();
private int _selectedMapDialogueOpcodeIndex;
private List<IMapDialogueOpcode> _selectedMapDialogueOpcodeItem;
private ObservableCollection<IMapDialogueOpcode> _selectedMapDialogueOpcodeItem;

public static MapDialogueViewModel Instance { get; private set; } = new();

Expand All @@ -17,12 +17,12 @@ private MapDialogueViewModel()
SelectedMapDialogueOpcodeIndex = 0;
}

public List<List<IMapDialogueOpcode>> SelectedMapDialogueOpcodes
public ObservableCollection<ObservableCollection<IMapDialogueOpcode>> SelectedMapDialogueOpcodes
{
get => _selectedMapDialogueOpcodes;
set
{
_selectedMapDialogueOpcodes = value == null ? new List<List<IMapDialogueOpcode>>() : value;
_selectedMapDialogueOpcodes = value == null ? new ObservableCollection<ObservableCollection<IMapDialogueOpcode>>() : value;
SelectedMapDialogueOpcodeIndex = 0;
OnPropertyChanged(nameof(SelectedMapDialogueOpcodes));
OnPropertyChanged(nameof(HasDialogueOpcodes));
Expand Down Expand Up @@ -52,7 +52,7 @@ public int SelectedMapDialogueOpcodeIndex
}
}

public List<IMapDialogueOpcode> SelectedMapDialogueOpcodeItem
public ObservableCollection<IMapDialogueOpcode> SelectedMapDialogueOpcodeItem
{
get => _selectedMapDialogueOpcodeItem;
set
Expand Down
Loading

0 comments on commit 4e97f9c

Please sign in to comment.