AssetBrowser redesigned

- Load multiple entries (while selected).
- fix resize issue.
This commit is contained in:
Razmoth
2023-05-08 21:29:19 +04:00
parent 2376a8669e
commit 6b060f734c
4 changed files with 110 additions and 78 deletions

View File

@@ -6,7 +6,7 @@ namespace AssetStudio
{ {
public static class ResourceMap public static class ResourceMap
{ {
private static AssetMap Instance; private static AssetMap Instance = new() { GameType = GameType.Normal, AssetEntries = Array.Empty<AssetEntry>() };
public static AssetEntry[] GetEntries() => Instance.AssetEntries; public static AssetEntry[] GetEntries() => Instance.AssetEntries;
public static void FromFile(string path) public static void FromFile(string path)
{ {
@@ -31,7 +31,7 @@ namespace AssetStudio
public static void Clear() public static void Clear()
{ {
Instance.GameType = GameType.Normal; Instance.GameType = GameType.Normal;
Instance.AssetEntries = null; Instance.AssetEntries = Array.Empty<AssetEntry>();
} }
} }
} }

View File

@@ -1,4 +1,6 @@
namespace AssetStudioGUI using System.Windows.Forms;
namespace AssetStudioGUI
{ {
partial class AssetBrowser partial class AssetBrowser
{ {
@@ -28,90 +30,132 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
assetListView = new System.Windows.Forms.DataGridView(); assetListView = new DataGridView();
fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); tableLayoutPanel1 = new TableLayoutPanel();
loadAssetMapToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); tableLayoutPanel2 = new TableLayoutPanel();
clearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); loadAssetMap = new Button();
searchTextBox = new System.Windows.Forms.ToolStripTextBox(); searchTextBox = new TextBox();
menuStrip1 = new System.Windows.Forms.MenuStrip(); loadSelected = new Button();
clear = new Button();
((System.ComponentModel.ISupportInitialize)assetListView).BeginInit(); ((System.ComponentModel.ISupportInitialize)assetListView).BeginInit();
menuStrip1.SuspendLayout(); tableLayoutPanel1.SuspendLayout();
tableLayoutPanel2.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// assetListView // assetListView
// //
assetListView.AllowUserToAddRows = false; assetListView.AllowUserToAddRows = false;
assetListView.AllowUserToDeleteRows = false; assetListView.AllowUserToDeleteRows = false;
assetListView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; assetListView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
assetListView.Location = new System.Drawing.Point(12, 27); assetListView.Dock = DockStyle.Fill;
assetListView.Location = new System.Drawing.Point(3, 38);
assetListView.Name = "assetListView"; assetListView.Name = "assetListView";
assetListView.ReadOnly = true; assetListView.ReadOnly = true;
assetListView.RowTemplate.Height = 25; assetListView.RowTemplate.Height = 25;
assetListView.Size = new System.Drawing.Size(524, 268); assetListView.Size = new System.Drawing.Size(518, 250);
assetListView.RowHeadersVisible = false;
assetListView.TabIndex = 2; assetListView.TabIndex = 2;
assetListView.RowHeaderMouseDoubleClick += assetListView_RowHeaderMouseDoubleClick;
// //
// fileToolStripMenuItem // tableLayoutPanel1
// //
fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { loadAssetMapToolStripMenuItem, clearToolStripMenuItem }); tableLayoutPanel1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
fileToolStripMenuItem.Name = "fileToolStripMenuItem"; tableLayoutPanel1.ColumnCount = 1;
fileToolStripMenuItem.Size = new System.Drawing.Size(37, 23); tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
fileToolStripMenuItem.Text = "File"; tableLayoutPanel1.Controls.Add(assetListView, 0, 1);
tableLayoutPanel1.Controls.Add(tableLayoutPanel2, 0, 0);
tableLayoutPanel1.Location = new System.Drawing.Point(12, 12);
tableLayoutPanel1.Name = "tableLayoutPanel1";
tableLayoutPanel1.RowCount = 2;
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 35F));
tableLayoutPanel1.RowStyles.Add(new RowStyle());
tableLayoutPanel1.Size = new System.Drawing.Size(524, 283);
tableLayoutPanel1.TabIndex = 3;
// //
// loadAssetMapToolStripMenuItem // tableLayoutPanel2
// //
loadAssetMapToolStripMenuItem.Name = "loadAssetMapToolStripMenuItem"; tableLayoutPanel2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
loadAssetMapToolStripMenuItem.Size = new System.Drawing.Size(180, 22); tableLayoutPanel2.ColumnCount = 4;
loadAssetMapToolStripMenuItem.Text = "Load AssetMap"; tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 120F));
loadAssetMapToolStripMenuItem.Click += loadAssetMapToolStripMenuItem_Click; tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 60F));
tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 100F));
tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle());
tableLayoutPanel2.Controls.Add(loadAssetMap, 0, 0);
tableLayoutPanel2.Controls.Add(clear, 1, 0);
tableLayoutPanel2.Controls.Add(loadSelected, 2, 0);
tableLayoutPanel2.Controls.Add(searchTextBox, 3, 0);
tableLayoutPanel2.Location = new System.Drawing.Point(3, 3);
tableLayoutPanel2.Name = "tableLayoutPanel2";
tableLayoutPanel2.RowCount = 1;
tableLayoutPanel2.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
tableLayoutPanel2.Size = new System.Drawing.Size(518, 29);
tableLayoutPanel2.TabIndex = 3;
// //
// clearToolStripMenuItem // loadAssetMap
// //
clearToolStripMenuItem.Name = "clearToolStripMenuItem"; loadAssetMap.Location = new System.Drawing.Point(3, 3);
clearToolStripMenuItem.Size = new System.Drawing.Size(180, 22); loadAssetMap.Name = "loadAssetMap";
clearToolStripMenuItem.Text = "Clear"; loadAssetMap.Size = new System.Drawing.Size(94, 23);
clearToolStripMenuItem.Click += clearToolStripMenuItem_Click; loadAssetMap.TabIndex = 0;
loadAssetMap.Text = "Load AssetMap";
loadAssetMap.UseVisualStyleBackColor = true;
loadAssetMap.Click += loadAssetMap_Click;
loadAssetMap.Dock = DockStyle.Fill;
// //
// searchTextBox // searchTextBox
// //
searchTextBox.Location = new System.Drawing.Point(103, 3);
searchTextBox.Name = "searchTextBox"; searchTextBox.Name = "searchTextBox";
searchTextBox.Size = new System.Drawing.Size(500, 23); searchTextBox.Size = new System.Drawing.Size(227, 23);
searchTextBox.KeyPress += toolStripTextBox1_KeyPress; searchTextBox.TabIndex = 3;
searchTextBox.KeyPress += searchTextBox_KeyPress;
searchTextBox.Dock = DockStyle.Fill;
// //
// menuStrip1 // loadSelected
// //
menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { fileToolStripMenuItem, searchTextBox }); loadSelected.Location = new System.Drawing.Point(336, 3);
menuStrip1.Location = new System.Drawing.Point(0, 0); loadSelected.Name = "loadSelected";
menuStrip1.Name = "menuStrip1"; loadSelected.Size = new System.Drawing.Size(94, 23);
menuStrip1.Size = new System.Drawing.Size(548, 27); loadSelected.TabIndex = 2;
menuStrip1.TabIndex = 1; loadSelected.Text = "Load Selected";
menuStrip1.Text = "menuStrip1"; loadSelected.UseVisualStyleBackColor = true;
loadSelected.Click += loadSelected_Click;
loadSelected.Dock = DockStyle.Fill;
//
// clear
//
clear.Location = new System.Drawing.Point(436, 3);
clear.Name = "clear";
clear.Size = new System.Drawing.Size(73, 23);
clear.TabIndex = 1;
clear.Text = "Clear";
clear.UseVisualStyleBackColor = true;
clear.Click += clear_Click;
clear.Dock = DockStyle.Fill;
// //
// AssetBrowser // AssetBrowser
// //
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(548, 307); ClientSize = new System.Drawing.Size(548, 307);
Controls.Add(assetListView); Controls.Add(tableLayoutPanel1);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
Name = "AssetBrowser"; Name = "AssetBrowser";
ShowIcon = false; ShowIcon = false;
StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; StartPosition = FormStartPosition.CenterScreen;
Text = "Asset Browser"; Text = "Asset Browser";
((System.ComponentModel.ISupportInitialize)assetListView).EndInit(); ((System.ComponentModel.ISupportInitialize)assetListView).EndInit();
menuStrip1.ResumeLayout(false); tableLayoutPanel1.ResumeLayout(false);
menuStrip1.PerformLayout(); tableLayoutPanel2.ResumeLayout(false);
tableLayoutPanel2.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
PerformLayout();
} }
#endregion #endregion
private System.Windows.Forms.DataGridView assetListView; private System.Windows.Forms.DataGridView assetListView;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; private TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.ToolStripMenuItem loadAssetMapToolStripMenuItem; private TableLayoutPanel tableLayoutPanel2;
private System.Windows.Forms.ToolStripMenuItem clearToolStripMenuItem; private Button loadAssetMap;
private System.Windows.Forms.ToolStripTextBox searchTextBox; private Button clear;
private System.Windows.Forms.MenuStrip menuStrip1; private Button loadSelected;
private TextBox searchTextBox;
} }
} }

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@@ -16,62 +17,52 @@ namespace AssetStudioGUI
_parent = form; _parent = form;
} }
private async void loadAssetMapToolStripMenuItem_Click(object sender, EventArgs e) private async void loadAssetMap_Click(object sender, EventArgs e)
{ {
fileToolStripMenuItem.DropDown.Visible = false; loadAssetMap.Enabled = false;
var openFileDialog = new OpenFileDialog() { Multiselect = false, Filter = "AssetMap File|*.map" }; var openFileDialog = new OpenFileDialog() { Multiselect = false, Filter = "AssetMap File|*.map" };
if (openFileDialog.ShowDialog(this) == DialogResult.OK) if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{ {
var path = openFileDialog.FileName; var path = openFileDialog.FileName;
Logger.Info($"Loading AssetMap..."); Logger.Info($"Loading AssetMap...");
InvokeUpdate(loadAssetMapToolStripMenuItem, false);
await Task.Run(() => ResourceMap.FromFile(path)); await Task.Run(() => ResourceMap.FromFile(path));
assetListView.DataSource = ResourceMap.GetEntries(); assetListView.DataSource = ResourceMap.GetEntries();
InvokeUpdate(loadAssetMapToolStripMenuItem, true); assetListView.Columns.GetLastColumn(DataGridViewElementStates.None, DataGridViewElementStates.None).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
} }
loadAssetMap.Enabled = true;
} }
private void clearToolStripMenuItem_Click(object sender, EventArgs e) private void clear_Click(object sender, EventArgs e)
{ {
ResourceMap.Clear(); ResourceMap.Clear();
assetListView.DataSource = null; assetListView.DataSource = null;
Logger.Info($"Cleared !!"); Logger.Info($"Cleared !!");
} }
private async void assetListView_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) private async void loadSelected_Click(object sender, EventArgs e)
{ {
var entry = assetListView.CurrentRow.DataBoundItem as AssetEntry; var files = assetListView.SelectedRows.Cast<DataGridViewRow>().Select(x => x.DataBoundItem as AssetEntry).Select(x => x.Source).ToHashSet();
if (!string.IsNullOrEmpty(entry.Source)) if (files.Count != 0 && !files.Any(x => string.IsNullOrEmpty(x)))
{ {
Logger.Info("Loading..."); Logger.Info("Loading...");
_parent.Invoke(() => _parent.LoadPaths(entry.Source)); _parent.Invoke(() => _parent.LoadPaths(files.ToArray()));
}
}
private void InvokeUpdate(ToolStripItem item, bool value)
{
if (InvokeRequired)
{
BeginInvoke(new Action(() => { item.Enabled = value; }));
}
else
{
item.Enabled = value;
} }
} }
private void toolStripTextBox1_KeyPress(object sender, KeyPressEventArgs e) private void searchTextBox_KeyPress(object sender, KeyPressEventArgs e)
{ {
if (e.KeyChar == (char)Keys.Enter) if (e.KeyChar == (char)Keys.Enter)
{ {
var value = searchTextBox.Text; var value = searchTextBox.Text;
if (!string.IsNullOrEmpty(value)) var assets = ResourceMap.GetEntries();
if (assets.Length != 0 && !string.IsNullOrEmpty(value))
{ {
var regex = new Regex(value); var regex = new Regex(value);
assetListView.DataSource = Array.FindAll(ResourceMap.GetEntries(), x => x.Matches(regex)); assetListView.DataSource = Array.FindAll(assets, x => x.Matches(regex));
} }
else else
{ {
assetListView.DataSource = ResourceMap.GetEntries(); assetListView.DataSource = assets;
} }
} }
} }

View File

@@ -57,7 +57,4 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>142, 17</value>
</metadata>
</root> </root>