mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-10-13 23:10:23 +03:00
improvements
This commit is contained in:
@@ -1,23 +1,43 @@
|
||||
using ImGuiNET;
|
||||
using CpDatLib;
|
||||
using ImGuiNET;
|
||||
using MissionTmaLib.Parsing;
|
||||
using NResLib;
|
||||
using NResUI.Abstractions;
|
||||
using NResUI.Models;
|
||||
using ScrLib;
|
||||
using TexmLib;
|
||||
using VarsetLib;
|
||||
|
||||
namespace NResUI.ImGuiUI;
|
||||
|
||||
public class NResExplorerPanel : IImGuiPanel
|
||||
{
|
||||
private readonly NResExplorerViewModel _viewModel;
|
||||
private readonly TexmExplorerViewModel _texmExplorerViewModel;
|
||||
private readonly VarsetViewModel _varsetViewModel;
|
||||
private readonly CpDatSchemeViewModel _cpDatSchemeViewModel;
|
||||
private readonly MissionTmaViewModel _missionTmaViewModel;
|
||||
private readonly ScrViewModel _scrViewModel;
|
||||
|
||||
public NResExplorerPanel(NResExplorerViewModel viewModel)
|
||||
public NResExplorerPanel(NResExplorerViewModel viewModel, TexmExplorerViewModel texmExplorerViewModel,
|
||||
VarsetViewModel varsetViewModel, CpDatSchemeViewModel cpDatSchemeViewModel, MissionTmaViewModel missionTmaViewModel, ScrViewModel scrViewModel)
|
||||
{
|
||||
_viewModel = viewModel;
|
||||
_texmExplorerViewModel = texmExplorerViewModel;
|
||||
_varsetViewModel = varsetViewModel;
|
||||
_cpDatSchemeViewModel = cpDatSchemeViewModel;
|
||||
_missionTmaViewModel = missionTmaViewModel;
|
||||
_scrViewModel = scrViewModel;
|
||||
}
|
||||
|
||||
int contextMenuRow = -1;
|
||||
|
||||
public void OnImGuiRender()
|
||||
{
|
||||
if (ImGui.Begin("NRes Explorer"))
|
||||
{
|
||||
ImGui.Text("NRes - это файл-архив. Они имеют разные расширения. Примеры - Textures.lib, weapon.rlb, object.dlb, behpsp.res");
|
||||
ImGui.Text(
|
||||
"NRes - это файл-архив. Они имеют разные расширения. Примеры - Textures.lib, weapon.rlb, object.dlb, behpsp.res");
|
||||
ImGui.Separator();
|
||||
|
||||
if (!_viewModel.HasFile)
|
||||
@@ -34,7 +54,7 @@ public class NResExplorerPanel : IImGuiPanel
|
||||
if (_viewModel.Archive is not null)
|
||||
{
|
||||
ImGui.Text(_viewModel.Path);
|
||||
|
||||
|
||||
ImGui.Text("Header: ");
|
||||
ImGui.SameLine();
|
||||
ImGui.Text(_viewModel.Archive.Header.NRes);
|
||||
@@ -48,8 +68,8 @@ public class NResExplorerPanel : IImGuiPanel
|
||||
ImGui.SameLine();
|
||||
ImGui.Text(_viewModel.Archive.Header.TotalFileLengthBytes.ToString());
|
||||
|
||||
|
||||
if (ImGui.BeginTable("content", 12, ImGuiTableFlags.Borders | ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.NoHostExtendX))
|
||||
if (ImGui.BeginTable("content", 12,
|
||||
ImGuiTableFlags.Borders | ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.NoHostExtendX))
|
||||
{
|
||||
ImGui.TableSetupColumn("Тип файла");
|
||||
ImGui.TableSetupColumn("Кол-во элементов");
|
||||
@@ -70,6 +90,17 @@ public class NResExplorerPanel : IImGuiPanel
|
||||
{
|
||||
ImGui.TableNextRow();
|
||||
ImGui.TableNextColumn();
|
||||
|
||||
ImGui.Selectable("##row_select" + i, false, ImGuiSelectableFlags.SpanAllColumns);
|
||||
if (ImGui.IsItemHovered() && ImGui.IsMouseClicked(ImGuiMouseButton.Right))
|
||||
{
|
||||
Console.WriteLine("Context menu for row " + i);
|
||||
contextMenuRow = i;
|
||||
ImGui.OpenPopup("row_context_menu");
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
|
||||
ImGui.Text(_viewModel.Archive.Files[i].FileType);
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.Text(_viewModel.Archive.Files[i].ElementCount.ToString());
|
||||
@@ -122,6 +153,130 @@ public class NResExplorerPanel : IImGuiPanel
|
||||
);
|
||||
}
|
||||
|
||||
if (ImGui.BeginPopup("row_context_menu"))
|
||||
{
|
||||
if (contextMenuRow == -1 || contextMenuRow > _viewModel.Archive.Files.Count)
|
||||
{
|
||||
ImGui.Text("Broken context menu :(. Reopen");
|
||||
}
|
||||
else
|
||||
{
|
||||
var file = _viewModel.Archive.Files[contextMenuRow];
|
||||
ImGui.Text("Actions for file " + file.FileName);
|
||||
ImGui.TextDisabled("Program has no understading of file format(");
|
||||
ImGui.Separator();
|
||||
if (ImGui.MenuItem("Open as Texture TEXM"))
|
||||
{
|
||||
using var fs = new FileStream(_viewModel.Path!, FileMode.Open, FileAccess.Read,
|
||||
FileShare.Read);
|
||||
fs.Seek(file.OffsetInFile, SeekOrigin.Begin);
|
||||
|
||||
var buffer = new byte[file.FileLength];
|
||||
|
||||
fs.ReadExactly(buffer, 0, file.FileLength);
|
||||
|
||||
using var ms = new MemoryStream(buffer);
|
||||
|
||||
var parseResult = TexmParser.ReadFromStream(ms, file.FileName);
|
||||
|
||||
_texmExplorerViewModel.SetParseResult(parseResult, Path.Combine(_viewModel.Path!, file.FileName));
|
||||
Console.WriteLine("Read TEXM from context menu");
|
||||
}
|
||||
|
||||
if (ImGui.MenuItem("Open as Archive NRes"))
|
||||
{
|
||||
using var fs = new FileStream(_viewModel.Path!, FileMode.Open, FileAccess.Read,
|
||||
FileShare.Read);
|
||||
fs.Seek(file.OffsetInFile, SeekOrigin.Begin);
|
||||
|
||||
var buffer = new byte[file.FileLength];
|
||||
|
||||
fs.ReadExactly(buffer, 0, file.FileLength);
|
||||
|
||||
using var ms = new MemoryStream(buffer);
|
||||
|
||||
var parseResult = NResParser.ReadFile(ms);
|
||||
|
||||
_viewModel.SetParseResult(parseResult, Path.Combine(_viewModel.Path!, file.FileName));
|
||||
Console.WriteLine("Read NRes from context menu");
|
||||
}
|
||||
|
||||
if (ImGui.MenuItem("Open as Varset .var"))
|
||||
{
|
||||
using var fs = new FileStream(_viewModel.Path!, FileMode.Open, FileAccess.Read,
|
||||
FileShare.Read);
|
||||
fs.Seek(file.OffsetInFile, SeekOrigin.Begin);
|
||||
|
||||
var buffer = new byte[file.FileLength];
|
||||
|
||||
fs.ReadExactly(buffer, 0, file.FileLength);
|
||||
|
||||
using var ms = new MemoryStream(buffer);
|
||||
|
||||
var parseResult = VarsetParser.Parse(ms);
|
||||
|
||||
_varsetViewModel.Items = parseResult;
|
||||
Console.WriteLine("Read Varset from context menu");
|
||||
}
|
||||
|
||||
if (ImGui.MenuItem("Open as Scheme cp.dat"))
|
||||
{
|
||||
using var fs = new FileStream(_viewModel.Path!, FileMode.Open, FileAccess.Read,
|
||||
FileShare.Read);
|
||||
fs.Seek(file.OffsetInFile, SeekOrigin.Begin);
|
||||
|
||||
var buffer = new byte[file.FileLength];
|
||||
|
||||
fs.ReadExactly(buffer, 0, file.FileLength);
|
||||
|
||||
using var ms = new MemoryStream(buffer);
|
||||
|
||||
var parseResult = CpDatParser.Parse(ms);
|
||||
|
||||
_cpDatSchemeViewModel.SetParseResult(parseResult, file.FileName);
|
||||
Console.WriteLine("Read cp.dat from context menu");
|
||||
}
|
||||
|
||||
if (ImGui.MenuItem("Open as Mission .tma"))
|
||||
{
|
||||
using var fs = new FileStream(_viewModel.Path!, FileMode.Open, FileAccess.Read,
|
||||
FileShare.Read);
|
||||
fs.Seek(file.OffsetInFile, SeekOrigin.Begin);
|
||||
|
||||
var buffer = new byte[file.FileLength];
|
||||
|
||||
fs.ReadExactly(buffer, 0, file.FileLength);
|
||||
|
||||
using var ms = new MemoryStream(buffer);
|
||||
|
||||
var parseResult = MissionTmaParser.ReadFile(ms);
|
||||
|
||||
_missionTmaViewModel.SetParseResult(parseResult, Path.Combine(_viewModel.Path!, file.FileName));
|
||||
Console.WriteLine("Read .tma from context menu");
|
||||
}
|
||||
|
||||
if (ImGui.MenuItem("Open as Scripts .scr"))
|
||||
{
|
||||
using var fs = new FileStream(_viewModel.Path!, FileMode.Open, FileAccess.Read,
|
||||
FileShare.Read);
|
||||
fs.Seek(file.OffsetInFile, SeekOrigin.Begin);
|
||||
|
||||
var buffer = new byte[file.FileLength];
|
||||
|
||||
fs.ReadExactly(buffer, 0, file.FileLength);
|
||||
|
||||
using var ms = new MemoryStream(buffer);
|
||||
|
||||
var parseResult = ScrParser.ReadFile(ms);
|
||||
|
||||
_scrViewModel.SetParseResult(parseResult, Path.Combine(_viewModel.Path!, file.FileName));
|
||||
Console.WriteLine("Read .scr from context menu");
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
|
||||
ImGui.EndTable();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user