mirror of
				https://github.com/sampletext32/ParkanPlayground.git
				synced 2025-11-04 15:29:43 +03:00 
			
		
		
		
	Allow to view cp .dat in UI
This commit is contained in:
		@@ -56,6 +56,7 @@ public class App
 | 
			
		||||
            serviceCollection.AddSingleton(new BinaryExplorerViewModel());
 | 
			
		||||
            serviceCollection.AddSingleton(new ScrViewModel());
 | 
			
		||||
            serviceCollection.AddSingleton(new VarsetViewModel());
 | 
			
		||||
            serviceCollection.AddSingleton(new CpDatSchemeViewModel());
 | 
			
		||||
 | 
			
		||||
            var serviceProvider = serviceCollection.BuildServiceProvider();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										120
									
								
								NResUI/ImGuiUI/CpDatSchemeExplorer.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										120
									
								
								NResUI/ImGuiUI/CpDatSchemeExplorer.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,120 @@
 | 
			
		||||
using CpDatLib;
 | 
			
		||||
using ImGuiNET;
 | 
			
		||||
using NResUI.Abstractions;
 | 
			
		||||
using NResUI.Models;
 | 
			
		||||
using ScrLib;
 | 
			
		||||
 | 
			
		||||
namespace NResUI.ImGuiUI;
 | 
			
		||||
 | 
			
		||||
public class CpDatSchemeExplorer : IImGuiPanel
 | 
			
		||||
{
 | 
			
		||||
    private readonly CpDatSchemeViewModel _viewModel;
 | 
			
		||||
 | 
			
		||||
    public CpDatSchemeExplorer(CpDatSchemeViewModel viewModel)
 | 
			
		||||
    {
 | 
			
		||||
        _viewModel = viewModel;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void OnImGuiRender()
 | 
			
		||||
    {
 | 
			
		||||
        if (ImGui.Begin("cp .dat Scheme Explorer"))
 | 
			
		||||
        {
 | 
			
		||||
            var cpDat = _viewModel.CpDatScheme;
 | 
			
		||||
            if (_viewModel.HasFile && cpDat is not null)
 | 
			
		||||
            {
 | 
			
		||||
                ImGui.Text("Тип объекта в схеме: ");
 | 
			
		||||
                ImGui.SameLine();
 | 
			
		||||
                ImGui.Text(cpDat.Type.ToString("G"));
 | 
			
		||||
 | 
			
		||||
                var root = cpDat.Root;
 | 
			
		||||
 | 
			
		||||
                DrawEntry(root, 0);
 | 
			
		||||
 | 
			
		||||
                ImGui.Separator();
 | 
			
		||||
 | 
			
		||||
                if (ImGui.BeginTable("content", 7,
 | 
			
		||||
                        ImGuiTableFlags.Borders | ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.NoHostExtendX))
 | 
			
		||||
                {
 | 
			
		||||
                    ImGui.TableSetupColumn("Уровень вложенности");
 | 
			
		||||
                    ImGui.TableSetupColumn("Архив");
 | 
			
		||||
                    ImGui.TableSetupColumn("Элемент");
 | 
			
		||||
                    ImGui.TableSetupColumn("Magic1");
 | 
			
		||||
                    ImGui.TableSetupColumn("Magic2");
 | 
			
		||||
                    ImGui.TableSetupColumn("Описание");
 | 
			
		||||
                    ImGui.TableSetupColumn("Magic3");
 | 
			
		||||
 | 
			
		||||
                    ImGui.TableHeadersRow();
 | 
			
		||||
 | 
			
		||||
                    for (int i = 0; i < _viewModel.FlatList.Count; i++)
 | 
			
		||||
                    {
 | 
			
		||||
                        ImGui.TableNextRow();
 | 
			
		||||
                        ImGui.TableNextColumn();
 | 
			
		||||
                        ImGui.Text(_viewModel.FlatList[i].Level.ToString());
 | 
			
		||||
                        ImGui.TableNextColumn();
 | 
			
		||||
                        ImGui.Text(_viewModel.FlatList[i].Entry.ArchiveFile);
 | 
			
		||||
                        ImGui.TableNextColumn();
 | 
			
		||||
                        ImGui.Text(_viewModel.FlatList[i].Entry.ArchiveEntryName);
 | 
			
		||||
                        ImGui.TableNextColumn();
 | 
			
		||||
                        ImGui.Text(_viewModel.FlatList[i].Entry.Magic1.ToString());
 | 
			
		||||
                        ImGui.TableNextColumn();
 | 
			
		||||
                        ImGui.Text(_viewModel.FlatList[i].Entry.Magic2.ToString());
 | 
			
		||||
                        ImGui.TableNextColumn();
 | 
			
		||||
                        ImGui.Text(_viewModel.FlatList[i].Entry.Description);
 | 
			
		||||
                        ImGui.TableNextColumn();
 | 
			
		||||
                        ImGui.Text(_viewModel.FlatList[i].Entry.Magic3.ToString());
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    ImGui.EndTable();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                void DrawEntry(CpDatEntry entry, int index)
 | 
			
		||||
                {
 | 
			
		||||
                    if (ImGui.TreeNodeEx(
 | 
			
		||||
                            $"Элемент: \"{entry.ArchiveFile}/{entry.ArchiveEntryName}\" - {entry.Description}##entry_{index}"))
 | 
			
		||||
                    {
 | 
			
		||||
                        ImGui.Text("Magic1: ");
 | 
			
		||||
                        ImGui.SameLine();
 | 
			
		||||
                        ImGui.Text(entry.Magic1.ToString());
 | 
			
		||||
 | 
			
		||||
                        ImGui.Text("Magic2: ");
 | 
			
		||||
                        ImGui.SameLine();
 | 
			
		||||
                        ImGui.Text(entry.Magic2.ToString());
 | 
			
		||||
 | 
			
		||||
                        ImGui.Text("Magic3: ");
 | 
			
		||||
                        ImGui.SameLine();
 | 
			
		||||
                        ImGui.Text(entry.Magic3.ToString());
 | 
			
		||||
 | 
			
		||||
                        ImGui.Text("Кол-во дочерних элементов: ");
 | 
			
		||||
                        ImGui.SameLine();
 | 
			
		||||
                        ImGui.Text(entry.ChildCount.ToString());
 | 
			
		||||
 | 
			
		||||
                        if (entry.Children.Count > 0)
 | 
			
		||||
                        {
 | 
			
		||||
                            if (ImGui.TreeNodeEx("Дочерние элементы"))
 | 
			
		||||
                            {
 | 
			
		||||
                                foreach (var child in entry.Children)
 | 
			
		||||
                                {
 | 
			
		||||
                                    DrawEntry(child, ++index);
 | 
			
		||||
                                }
 | 
			
		||||
 | 
			
		||||
                                ImGui.TreePop();
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        ImGui.TreePop();
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else if (_viewModel.Error is not null)
 | 
			
		||||
            {
 | 
			
		||||
                ImGui.Text(_viewModel.Error);
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                ImGui.Text("cp .dat не открыт");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            ImGui.End();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
using System.Numerics;
 | 
			
		||||
using CpDatLib;
 | 
			
		||||
using ImGuiNET;
 | 
			
		||||
using MissionTmaLib;
 | 
			
		||||
using MissionTmaLib.Parsing;
 | 
			
		||||
@@ -18,6 +19,7 @@ namespace NResUI.ImGuiUI
 | 
			
		||||
        ScrViewModel scrViewModel,
 | 
			
		||||
        MissionTmaViewModel missionTmaViewModel,
 | 
			
		||||
        VarsetViewModel varsetViewModel,
 | 
			
		||||
        CpDatSchemeViewModel cpDatSchemeViewModel,
 | 
			
		||||
        MessageBoxModalPanel messageBox)
 | 
			
		||||
        : IImGuiPanel
 | 
			
		||||
    {
 | 
			
		||||
@@ -121,6 +123,21 @@ namespace NResUI.ImGuiUI
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    if (ImGui.MenuItem("Open cp .dat Scheme File"))
 | 
			
		||||
                    {
 | 
			
		||||
                        var result = Dialog.FileOpen("dat");
 | 
			
		||||
 | 
			
		||||
                        if (result.IsOk)
 | 
			
		||||
                        {
 | 
			
		||||
                            var path = result.Path;
 | 
			
		||||
                            var parseResult = CpDatParser.Parse(path);
 | 
			
		||||
 | 
			
		||||
                            cpDatSchemeViewModel.SetParseResult(parseResult, path);
 | 
			
		||||
 | 
			
		||||
                            Console.WriteLine("Read cp .dat");
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    if (nResExplorerViewModel.HasFile)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (ImGui.MenuItem("Экспортировать NRes"))
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										40
									
								
								NResUI/Models/CpDatSchemeViewModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								NResUI/Models/CpDatSchemeViewModel.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
using CpDatLib;
 | 
			
		||||
using ScrLib;
 | 
			
		||||
 | 
			
		||||
namespace NResUI.Models;
 | 
			
		||||
 | 
			
		||||
public class CpDatSchemeViewModel
 | 
			
		||||
{
 | 
			
		||||
    public bool HasFile { get; set; }
 | 
			
		||||
    public string? Error { get; set; }
 | 
			
		||||
 | 
			
		||||
    public CpDatScheme? CpDatScheme { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    public List<(int Level, CpDatEntry Entry)> FlatList { get; set; }
 | 
			
		||||
 | 
			
		||||
    public string? Path { get; set; }
 | 
			
		||||
 | 
			
		||||
    public void SetParseResult(CpDatParseResult parseResult, string path)
 | 
			
		||||
    {
 | 
			
		||||
        CpDatScheme = parseResult.Scheme;
 | 
			
		||||
        Error = parseResult.Error;
 | 
			
		||||
        HasFile = true;
 | 
			
		||||
        Path = path;
 | 
			
		||||
 | 
			
		||||
        if (CpDatScheme is not null)
 | 
			
		||||
        {
 | 
			
		||||
            FlatList = [];
 | 
			
		||||
            
 | 
			
		||||
            CollectEntries(CpDatScheme.Root, 0);
 | 
			
		||||
            
 | 
			
		||||
            void CollectEntries(CpDatEntry entry, int level)
 | 
			
		||||
            {
 | 
			
		||||
                FlatList.Add((level, entry));
 | 
			
		||||
                foreach (var child in entry.Children)
 | 
			
		||||
                {
 | 
			
		||||
                    CollectEntries(child, level + 1);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
    </ItemGroup>
 | 
			
		||||
 | 
			
		||||
    <ItemGroup>
 | 
			
		||||
      <ProjectReference Include="..\CpDatLib\CpDatLib.csproj" />
 | 
			
		||||
      <ProjectReference Include="..\MissionTmaLib\MissionTmaLib.csproj" />
 | 
			
		||||
      <ProjectReference Include="..\NResLib\NResLib.csproj" />
 | 
			
		||||
      <ProjectReference Include="..\ScrLib\ScrLib.csproj" />
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user