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

@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -16,62 +17,52 @@ namespace AssetStudioGUI
_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" };
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
var path = openFileDialog.FileName;
Logger.Info($"Loading AssetMap...");
InvokeUpdate(loadAssetMapToolStripMenuItem, false);
await Task.Run(() => ResourceMap.FromFile(path));
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();
assetListView.DataSource = null;
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...");
_parent.Invoke(() => _parent.LoadPaths(entry.Source));
}
}
private void InvokeUpdate(ToolStripItem item, bool value)
{
if (InvokeRequired)
{
BeginInvoke(new Action(() => { item.Enabled = value; }));
}
else
{
item.Enabled = value;
_parent.Invoke(() => _parent.LoadPaths(files.ToArray()));
}
}
private void toolStripTextBox1_KeyPress(object sender, KeyPressEventArgs e)
private void searchTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
var value = searchTextBox.Text;
if (!string.IsNullOrEmpty(value))
var assets = ResourceMap.GetEntries();
if (assets.Length != 0 && !string.IsNullOrEmpty(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
{
assetListView.DataSource = ResourceMap.GetEntries();
assetListView.DataSource = assets;
}
}
}