Merge branch 'main' into 3dSkinRenderer

This commit is contained in:
miku-666
2024-06-22 22:20:27 +02:00
10 changed files with 362 additions and 3190 deletions

View File

@@ -1,215 +0,0 @@
namespace PckStudio.Forms.Additional_Popups.Animation
{
partial class ChangeTile
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ChangeTile));
this.acceptBtn = new System.Windows.Forms.Button();
this.CancelBtn = new System.Windows.Forms.Button();
this.treeViewBlocks = new System.Windows.Forms.TreeView();
this.treeViewItems = new System.Windows.Forms.TreeView();
this.metroLabel2 = new MetroFramework.Controls.MetroLabel();
this.metroTextBox1 = new MetroFramework.Controls.MetroTextBox();
this.metroTabControl1 = new MetroFramework.Controls.MetroTabControl();
this.Blocks = new System.Windows.Forms.TabPage();
this.Items = new System.Windows.Forms.TabPage();
this.metroTabControl1.SuspendLayout();
this.Blocks.SuspendLayout();
this.Items.SuspendLayout();
this.SuspendLayout();
//
// acceptBtn
//
this.acceptBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.acceptBtn.ForeColor = System.Drawing.Color.White;
this.acceptBtn.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.acceptBtn.Location = new System.Drawing.Point(92, 196);
this.acceptBtn.Name = "acceptBtn";
this.acceptBtn.Size = new System.Drawing.Size(75, 23);
this.acceptBtn.TabIndex = 7;
this.acceptBtn.Text = "Save";
this.acceptBtn.UseVisualStyleBackColor = true;
this.acceptBtn.Click += new System.EventHandler(this.AcceptBtn_Click);
//
// CancelBtn
//
this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.CancelBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.CancelBtn.ForeColor = System.Drawing.Color.White;
this.CancelBtn.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.CancelBtn.Location = new System.Drawing.Point(172, 196);
this.CancelBtn.Name = "CancelBtn";
this.CancelBtn.Size = new System.Drawing.Size(75, 23);
this.CancelBtn.TabIndex = 13;
this.CancelBtn.Text = "Cancel";
this.CancelBtn.UseVisualStyleBackColor = true;
this.CancelBtn.Click += new System.EventHandler(this.CancelBtn_Click);
//
// treeViewBlocks
//
this.treeViewBlocks.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.treeViewBlocks.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeViewBlocks.ForeColor = System.Drawing.Color.White;
this.treeViewBlocks.Location = new System.Drawing.Point(0, 0);
this.treeViewBlocks.Name = "treeViewBlocks";
this.treeViewBlocks.Size = new System.Drawing.Size(318, 142);
this.treeViewBlocks.TabIndex = 14;
this.treeViewBlocks.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViews_AfterSelect);
//
// treeViewItems
//
this.treeViewItems.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.treeViewItems.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeViewItems.ForeColor = System.Drawing.Color.White;
this.treeViewItems.Location = new System.Drawing.Point(0, 0);
this.treeViewItems.Name = "treeViewItems";
this.treeViewItems.Size = new System.Drawing.Size(318, 142);
this.treeViewItems.TabIndex = 14;
this.treeViewItems.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViews_AfterSelect);
//
// metroLabel2
//
this.metroLabel2.AutoSize = true;
this.metroLabel2.Location = new System.Drawing.Point(133, 19);
this.metroLabel2.Name = "metroLabel2";
this.metroLabel2.Size = new System.Drawing.Size(46, 19);
this.metroLabel2.TabIndex = 16;
this.metroLabel2.Text = "Filter: ";
this.metroLabel2.Theme = MetroFramework.MetroThemeStyle.Dark;
//
// metroTextBox1
//
//
//
//
this.metroTextBox1.CustomButton.Image = null;
this.metroTextBox1.CustomButton.Location = new System.Drawing.Point(134, 1);
this.metroTextBox1.CustomButton.Name = "";
this.metroTextBox1.CustomButton.Size = new System.Drawing.Size(21, 21);
this.metroTextBox1.CustomButton.Style = MetroFramework.MetroColorStyle.Blue;
this.metroTextBox1.CustomButton.TabIndex = 1;
this.metroTextBox1.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light;
this.metroTextBox1.CustomButton.UseSelectable = true;
this.metroTextBox1.CustomButton.Visible = false;
this.metroTextBox1.Lines = new string[0];
this.metroTextBox1.Location = new System.Drawing.Point(173, 18);
this.metroTextBox1.MaxLength = 32767;
this.metroTextBox1.Name = "metroTextBox1";
this.metroTextBox1.PasswordChar = '\0';
this.metroTextBox1.ScrollBars = System.Windows.Forms.ScrollBars.None;
this.metroTextBox1.SelectedText = "";
this.metroTextBox1.SelectionLength = 0;
this.metroTextBox1.SelectionStart = 0;
this.metroTextBox1.ShortcutsEnabled = true;
this.metroTextBox1.Size = new System.Drawing.Size(156, 23);
this.metroTextBox1.TabIndex = 17;
this.metroTextBox1.Theme = MetroFramework.MetroThemeStyle.Dark;
this.metroTextBox1.UseSelectable = true;
this.metroTextBox1.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109)))));
this.metroTextBox1.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel);
this.metroTextBox1.TextChanged += new System.EventHandler(this.filter_TextChanged);
//
// metroTabControl1
//
this.metroTabControl1.Controls.Add(this.Blocks);
this.metroTabControl1.Controls.Add(this.Items);
this.metroTabControl1.Location = new System.Drawing.Point(6, 8);
this.metroTabControl1.Name = "metroTabControl1";
this.metroTabControl1.SelectedIndex = 0;
this.metroTabControl1.Size = new System.Drawing.Size(326, 184);
this.metroTabControl1.Style = MetroFramework.MetroColorStyle.White;
this.metroTabControl1.TabIndex = 18;
this.metroTabControl1.Theme = MetroFramework.MetroThemeStyle.Dark;
this.metroTabControl1.UseSelectable = true;
//
// Blocks
//
this.Blocks.BackColor = System.Drawing.SystemColors.WindowFrame;
this.Blocks.Controls.Add(this.treeViewBlocks);
this.Blocks.Location = new System.Drawing.Point(4, 38);
this.Blocks.Name = "Blocks";
this.Blocks.Size = new System.Drawing.Size(318, 142);
this.Blocks.TabIndex = 0;
this.Blocks.Text = "Blocks";
//
// Items
//
this.Items.BackColor = System.Drawing.SystemColors.WindowFrame;
this.Items.Controls.Add(this.treeViewItems);
this.Items.Location = new System.Drawing.Point(4, 38);
this.Items.Name = "Items";
this.Items.Size = new System.Drawing.Size(318, 142);
this.Items.TabIndex = 0;
this.Items.Text = "Items";
//
// ChangeTile
//
this.AcceptButton = this.acceptBtn;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.CancelBtn;
this.ClientSize = new System.Drawing.Size(338, 228);
this.ControlBox = false;
this.Controls.Add(this.metroTextBox1);
this.Controls.Add(this.metroLabel2);
this.Controls.Add(this.metroTabControl1);
this.Controls.Add(this.CancelBtn);
this.Controls.Add(this.acceptBtn);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ChangeTile";
this.Resizable = false;
this.Style = MetroFramework.MetroColorStyle.Silver;
this.Theme = MetroFramework.MetroThemeStyle.Dark;
this.metroTabControl1.ResumeLayout(false);
this.Blocks.ResumeLayout(false);
this.Items.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
private void MetroTextBox1_TextChanged(object sender, System.EventArgs e)
{
throw new System.NotImplementedException();
}
#endregion
private System.Windows.Forms.Button acceptBtn;
private System.Windows.Forms.Button CancelBtn;
private System.Windows.Forms.TreeView treeViewBlocks;
private System.Windows.Forms.TreeView treeViewItems;
private MetroFramework.Controls.MetroLabel metroLabel2;
private MetroFramework.Controls.MetroTextBox metroTextBox1;
private MetroFramework.Controls.MetroTabControl metroTabControl1;
private System.Windows.Forms.TabPage Blocks;
private System.Windows.Forms.TabPage Items;
}
}

View File

@@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using MetroFramework.Controls;
using System.Xml.Linq;
using MetroFramework.Forms;
using PckStudio.Extensions;
using PckStudio.Internal;
@@ -10,7 +12,8 @@ using PckStudio.Internal.Json;
namespace PckStudio.Forms.Additional_Popups.Animation
{
internal partial class ChangeTile : MetroForm
/// Wrapper class kept for simplicity
internal class ChangeTile : IDisposable
{
private JsonTileInfo selectedTile;
private ResourceCategory category = ResourceCategory.BlockAnimation;
@@ -18,121 +21,69 @@ namespace PckStudio.Forms.Additional_Popups.Animation
public JsonTileInfo SelectedTile => selectedTile;
public ResourceCategory Category => category;
List<TreeNode> treeViewBlockCache = new List<TreeNode>();
List<TreeNode> treeViewItemCache = new List<TreeNode>();
private FilterPrompt filterPrompt;
public ChangeTile()
{
InitializeComponent();
treeViewBlocks.ImageList = Tiles.BlockImageList;
treeViewItems.ImageList = Tiles.ItemImageList;
filterPrompt = new FilterPrompt();
filterPrompt.OnSelectedItemChanged += filterPrompt_OnSelectedItemChanged;
InitializeTreeviews();
}
private void InitializeTreeviews()
{
Profiler.Start();
GetTileDataToView(ResourceCategory.BlockAnimation, treeViewBlocks.Nodes, treeViewBlockCache.Add);
GetTileDataToView(ResourceCategory.ItemAnimation, treeViewItems.Nodes, treeViewItemCache.Add);
GetTileDataToView(ResourceCategory.BlockAnimation);
GetTileDataToView(ResourceCategory.ItemAnimation);
Profiler.Stop();
}
private void treeViews_AfterSelect(object sender, TreeViewEventArgs e)
public DialogResult ShowDialog(IWin32Window owner)
{
if (e.Node.Tag is JsonTileInfo tileData)
return filterPrompt.ShowDialog(owner);
}
private void filterPrompt_OnSelectedItemChanged(object sender, EventArgs e)
{
if (filterPrompt.SelectedItem is JsonTileInfo tileData)
{
selectedTile = tileData;
category = e.Node.TreeView == treeViewItems
? ResourceCategory.ItemAnimation
: ResourceCategory.BlockAnimation;
category = filterPrompt.SelectedTabIndex == 0 ? ResourceCategory.BlockAnimation : ResourceCategory.ItemAnimation;
}
}
private void GetTileDataToView(ResourceCategory key, TreeNodeCollection collection, Action<TreeNode> additionalAction)
private void GetTileDataToView(ResourceCategory key)
{
List<JsonTileInfo> textureInfos = key switch
(List<JsonTileInfo> textureInfos, ImageList imgList, string name) = key switch
{
ResourceCategory.BlockAnimation => Tiles.BlockTileInfos,
ResourceCategory.ItemAnimation => Tiles.ItemTileInfos,
ResourceCategory.BlockAnimation => (Tiles.BlockTileInfos, Tiles.BlockImageList, "Blocks"),
ResourceCategory.ItemAnimation => (Tiles.ItemTileInfos, Tiles.ItemImageList, "Items"),
_ => throw new InvalidOperationException(nameof(key))
};
Profiler.Start();
if (textureInfos is not null)
{
foreach ((int i, var tileData) in textureInfos.enumerate())
var view = filterPrompt.AddFilterPage(name, null, filterPredicate);
view.ImageList = imgList;
foreach ((int i, var tileData) in textureInfos?.enumerate())
{
if (string.IsNullOrEmpty(tileData.InternalName) || view.Nodes.ContainsKey(tileData.InternalName))
continue;
TreeNode tileNode = new TreeNode(tileData.DisplayName, i, i)
{
if (string.IsNullOrEmpty(tileData.InternalName) || collection.ContainsKey(tileData.InternalName))
continue;
TreeNode tileNode = new TreeNode(tileData.DisplayName, i, i)
{
Name = tileData.InternalName,
Tag = tileData
};
collection.Add(tileNode);
additionalAction(tileNode);
}
}
Profiler.Stop();
Name = tileData.InternalName,
Tag = tileData
};
view.Nodes.Add(tileNode);
(view.Tag as List<TreeNode>).Add(tileNode);
}
}
void filter_TextChanged(object sender, EventArgs e)
{
// Some code in this function is modified code from this StackOverflow answer - MattNL
//https://stackoverflow.com/questions/8260322/filter-a-treeview-with-a-textbox-in-a-c-sharp-winforms-app
private bool filterPredicate(string filterText, object nodeTag)
{
return nodeTag is JsonTileInfo tileInfo && tileInfo.InternalName.ToLower().Contains(filterText.ToLower());
}
//blocks repainting tree until all objects loaded
treeViewBlocks.BeginUpdate();
treeViewBlocks.Nodes.Clear();
treeViewItems.BeginUpdate();
treeViewItems.Nodes.Clear();
if (!string.IsNullOrEmpty(metroTextBox1.Text))
{
foreach (TreeNode _node in treeViewBlockCache)
{
if (_node.Text.ToLower().Contains(metroTextBox1.Text.ToLower()) ||
(_node.Tag as JsonTileInfo).InternalName.ToLower().Contains(metroTextBox1.Text.ToLower()))
{
treeViewBlocks.Nodes.Add((TreeNode)_node.Clone());
}
}
foreach (TreeNode _node in treeViewItemCache)
{
if (_node.Text.ToLower().Contains(metroTextBox1.Text.ToLower()) ||
(_node.Tag as JsonTileInfo).InternalName.ToLower().Contains(metroTextBox1.Text.ToLower()))
{
treeViewItems.Nodes.Add((TreeNode)_node.Clone());
}
}
}
else
{
foreach (TreeNode _node in treeViewBlockCache)
{
treeViewBlocks.Nodes.Add((TreeNode)_node.Clone());
}
foreach (TreeNode _node in treeViewItemCache)
{
treeViewItems.Nodes.Add((TreeNode)_node.Clone());
}
}
//enables redrawing tree after all objects have been added
treeViewBlocks.EndUpdate();
treeViewItems.EndUpdate();
}
private void CancelBtn_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void AcceptBtn_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(selectedTile.InternalName))
{
DialogResult = DialogResult.Cancel;
return;
}
DialogResult = DialogResult.OK;
}
}
public void Dispose()
{
filterPrompt.Dispose();
}
}
}

View File

@@ -1,187 +0,0 @@
namespace PckStudio.Forms.Additional_Popups.EntityForms
{
partial class AddEntry
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AddEntry));
this.acceptBtn = new System.Windows.Forms.Button();
this.CancelBtn = new System.Windows.Forms.Button();
this.treeViewEntity = new System.Windows.Forms.TreeView();
this.metroLabel2 = new MetroFramework.Controls.MetroLabel();
this.metroTextBox1 = new MetroFramework.Controls.MetroTextBox();
this.metroTabControl1 = new MetroFramework.Controls.MetroTabControl();
this.Blocks = new System.Windows.Forms.TabPage();
this.metroTabControl1.SuspendLayout();
this.Blocks.SuspendLayout();
this.SuspendLayout();
//
// acceptBtn
//
this.acceptBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.acceptBtn.ForeColor = System.Drawing.Color.White;
this.acceptBtn.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.acceptBtn.Location = new System.Drawing.Point(92, 196);
this.acceptBtn.Name = "acceptBtn";
this.acceptBtn.Size = new System.Drawing.Size(75, 23);
this.acceptBtn.TabIndex = 7;
this.acceptBtn.Text = "Add";
this.acceptBtn.UseVisualStyleBackColor = true;
this.acceptBtn.Click += new System.EventHandler(this.AcceptBtn_Click);
//
// CancelBtn
//
this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.CancelBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.CancelBtn.ForeColor = System.Drawing.Color.White;
this.CancelBtn.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.CancelBtn.Location = new System.Drawing.Point(172, 196);
this.CancelBtn.Name = "CancelBtn";
this.CancelBtn.Size = new System.Drawing.Size(75, 23);
this.CancelBtn.TabIndex = 13;
this.CancelBtn.Text = "Cancel";
this.CancelBtn.UseVisualStyleBackColor = true;
this.CancelBtn.Click += new System.EventHandler(this.CancelBtn_Click);
//
// treeViewEntity
//
this.treeViewEntity.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.treeViewEntity.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeViewEntity.ForeColor = System.Drawing.Color.White;
this.treeViewEntity.Location = new System.Drawing.Point(0, 0);
this.treeViewEntity.Name = "treeViewEntity";
this.treeViewEntity.Size = new System.Drawing.Size(318, 142);
this.treeViewEntity.TabIndex = 14;
this.treeViewEntity.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViews_AfterSelect);
//
// metroLabel2
//
this.metroLabel2.AutoSize = true;
this.metroLabel2.Location = new System.Drawing.Point(133, 19);
this.metroLabel2.Name = "metroLabel2";
this.metroLabel2.Size = new System.Drawing.Size(46, 19);
this.metroLabel2.TabIndex = 16;
this.metroLabel2.Text = "Filter: ";
this.metroLabel2.Theme = MetroFramework.MetroThemeStyle.Dark;
//
// metroTextBox1
//
//
//
//
this.metroTextBox1.CustomButton.Image = null;
this.metroTextBox1.CustomButton.Location = new System.Drawing.Point(134, 1);
this.metroTextBox1.CustomButton.Name = "";
this.metroTextBox1.CustomButton.Size = new System.Drawing.Size(21, 21);
this.metroTextBox1.CustomButton.Style = MetroFramework.MetroColorStyle.Blue;
this.metroTextBox1.CustomButton.TabIndex = 1;
this.metroTextBox1.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light;
this.metroTextBox1.CustomButton.UseSelectable = true;
this.metroTextBox1.CustomButton.Visible = false;
this.metroTextBox1.Lines = new string[0];
this.metroTextBox1.Location = new System.Drawing.Point(173, 18);
this.metroTextBox1.MaxLength = 32767;
this.metroTextBox1.Name = "metroTextBox1";
this.metroTextBox1.PasswordChar = '\0';
this.metroTextBox1.ScrollBars = System.Windows.Forms.ScrollBars.None;
this.metroTextBox1.SelectedText = "";
this.metroTextBox1.SelectionLength = 0;
this.metroTextBox1.SelectionStart = 0;
this.metroTextBox1.ShortcutsEnabled = true;
this.metroTextBox1.Size = new System.Drawing.Size(156, 23);
this.metroTextBox1.TabIndex = 17;
this.metroTextBox1.Theme = MetroFramework.MetroThemeStyle.Dark;
this.metroTextBox1.UseSelectable = true;
this.metroTextBox1.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109)))));
this.metroTextBox1.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel);
this.metroTextBox1.TextChanged += new System.EventHandler(this.filter_TextChanged);
//
// metroTabControl1
//
this.metroTabControl1.Controls.Add(this.Blocks);
this.metroTabControl1.Location = new System.Drawing.Point(6, 8);
this.metroTabControl1.Name = "metroTabControl1";
this.metroTabControl1.SelectedIndex = 0;
this.metroTabControl1.Size = new System.Drawing.Size(326, 184);
this.metroTabControl1.Style = MetroFramework.MetroColorStyle.White;
this.metroTabControl1.TabIndex = 18;
this.metroTabControl1.Theme = MetroFramework.MetroThemeStyle.Dark;
this.metroTabControl1.UseSelectable = true;
//
// Blocks
//
this.Blocks.BackColor = System.Drawing.SystemColors.WindowFrame;
this.Blocks.Controls.Add(this.treeViewEntity);
this.Blocks.Location = new System.Drawing.Point(4, 38);
this.Blocks.Name = "Blocks";
this.Blocks.Size = new System.Drawing.Size(318, 142);
this.Blocks.TabIndex = 0;
this.Blocks.Text = "Entities";
//
// AddEntry
//
this.AcceptButton = this.acceptBtn;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.CancelBtn;
this.ClientSize = new System.Drawing.Size(338, 228);
this.ControlBox = false;
this.Controls.Add(this.metroTextBox1);
this.Controls.Add(this.metroLabel2);
this.Controls.Add(this.metroTabControl1);
this.Controls.Add(this.CancelBtn);
this.Controls.Add(this.acceptBtn);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "AddEntry";
this.Resizable = false;
this.Style = MetroFramework.MetroColorStyle.Silver;
this.Theme = MetroFramework.MetroThemeStyle.Dark;
this.metroTabControl1.ResumeLayout(false);
this.Blocks.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
private void MetroTextBox1_TextChanged(object sender, System.EventArgs e)
{
throw new System.NotImplementedException();
}
#endregion
private System.Windows.Forms.Button CancelBtn;
private System.Windows.Forms.TreeView treeViewEntity;
private MetroFramework.Controls.MetroLabel metroLabel2;
private MetroFramework.Controls.MetroTextBox metroTextBox1;
private MetroFramework.Controls.MetroTabControl metroTabControl1;
private System.Windows.Forms.TabPage Blocks;
public System.Windows.Forms.Button acceptBtn;
}
}

View File

@@ -1,23 +1,26 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using MetroFramework.Forms;
using Newtonsoft.Json.Linq;
using PckStudio.Forms.Additional_Popups.Animation;
using PckStudio.Internal.Json;
namespace PckStudio.Forms.Additional_Popups.EntityForms
{
public partial class AddEntry : MetroForm
/// Wrapper class kept for simplicity
public class AddEntry
{
string selectedEntity = "";
public string SelectedEntity => selectedEntity;
List<TreeNode> treeViewEntityCache = new List<TreeNode>();
private FilterPrompt filterPrompt;
public AddEntry(string dataType, System.Drawing.Image[] entityImages)
{
InitializeComponent();
ImageList entities = new ImageList();
filterPrompt = new FilterPrompt();
filterPrompt.OnSelectedItemChanged += FilterPrompt_OnSelectedItemChanged;
var treeViewEntity = filterPrompt.AddFilterPage("Entities", null, filterPredicate);
ImageList entities = new ImageList();
entities.ColorDepth = ColorDepth.Depth32Bit;
entities.ImageSize = new System.Drawing.Size(32, 32);
entities.Images.AddRange(entityImages);
@@ -42,16 +45,26 @@ namespace PckStudio.Forms.Additional_Popups.EntityForms
SelectedImageIndex = i,
};
i++;
if (!String.IsNullOrEmpty(entity.InternalName))
if (!string.IsNullOrEmpty(entity.InternalName))
{
treeViewEntity.Nodes.Add(entityNode);
treeViewEntityCache.Add(entityNode);
(treeViewEntity.Tag as List<TreeNode>).Add(entityNode);
}
}
treeViewEntity.Sort();
}
private void FilterPrompt_OnSelectedItemChanged(object sender, EventArgs e)
{
selectedEntity = filterPrompt.SelectedItem.ToString();
}
public DialogResult ShowDialog(IWin32Window owner)
{
return filterPrompt.ShowDialog(owner);
}
private void treeViews_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Node.Tag is string entityData)
@@ -60,47 +73,9 @@ namespace PckStudio.Forms.Additional_Popups.EntityForms
}
}
void filter_TextChanged(object sender, EventArgs e)
private bool filterPredicate(string filterText, object nodeTag)
{
// Some code in this function is modified code from this StackOverflow answer - MattNL
//https://stackoverflow.com/questions/8260322/filter-a-treeview-with-a-textbox-in-a-c-sharp-winforms-app
//blocks repainting tree until all objects loaded
treeViewEntity.BeginUpdate();
treeViewEntity.Nodes.Clear();
if (!string.IsNullOrEmpty(metroTextBox1.Text))
{
foreach (TreeNode _node in treeViewEntityCache)
{
if (_node.Text.ToLower().Contains(metroTextBox1.Text.ToLower()) ||
(_node.Tag as string).ToLower().Contains(metroTextBox1.Text.ToLower()))
{
treeViewEntity.Nodes.Add((TreeNode)_node.Clone());
}
}
}
else
{
foreach (TreeNode _node in treeViewEntityCache)
{
treeViewEntity.Nodes.Add((TreeNode)_node.Clone());
}
}
//enables redrawing tree after all objects have been added
treeViewEntity.EndUpdate();
}
private void CancelBtn_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void AcceptBtn_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(selectedEntity)) CancelBtn_Click(sender, e);
DialogResult = DialogResult.OK;
Close();
}
return nodeTag is string a && a.ToLower().Contains(filterText.ToLower());
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,157 @@
namespace PckStudio.Forms.Additional_Popups.Animation
{
partial class FilterPrompt
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
MetroFramework.Controls.MetroLabel metroLabel2;
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FilterPrompt));
this.acceptButton = new System.Windows.Forms.Button();
this.cancelButton = new System.Windows.Forms.Button();
this.filterTextBox = new MetroFramework.Controls.MetroTextBox();
this.tabController = new MetroFramework.Controls.MetroTabControl();
metroLabel2 = new MetroFramework.Controls.MetroLabel();
this.SuspendLayout();
//
// metroLabel2
//
metroLabel2.AutoSize = true;
metroLabel2.Location = new System.Drawing.Point(133, 19);
metroLabel2.Name = "metroLabel2";
metroLabel2.Size = new System.Drawing.Size(46, 19);
metroLabel2.TabIndex = 16;
metroLabel2.Text = "Filter: ";
metroLabel2.Theme = MetroFramework.MetroThemeStyle.Dark;
//
// acceptButton
//
this.acceptButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.acceptButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.acceptButton.ForeColor = System.Drawing.Color.White;
this.acceptButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.acceptButton.Location = new System.Drawing.Point(92, 196);
this.acceptButton.Name = "acceptButton";
this.acceptButton.Size = new System.Drawing.Size(75, 23);
this.acceptButton.TabIndex = 7;
this.acceptButton.Text = "Save";
this.acceptButton.UseVisualStyleBackColor = true;
this.acceptButton.Click += new System.EventHandler(this.AcceptBtn_Click);
//
// cancelButton
//
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.cancelButton.ForeColor = System.Drawing.Color.White;
this.cancelButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.cancelButton.Location = new System.Drawing.Point(172, 196);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 13;
this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Click += new System.EventHandler(this.CancelBtn_Click);
//
// filterTextBox
//
//
//
//
this.filterTextBox.CustomButton.Image = null;
this.filterTextBox.CustomButton.Location = new System.Drawing.Point(134, 1);
this.filterTextBox.CustomButton.Name = "";
this.filterTextBox.CustomButton.Size = new System.Drawing.Size(21, 21);
this.filterTextBox.CustomButton.Style = MetroFramework.MetroColorStyle.Blue;
this.filterTextBox.CustomButton.TabIndex = 1;
this.filterTextBox.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light;
this.filterTextBox.CustomButton.UseSelectable = true;
this.filterTextBox.CustomButton.Visible = false;
this.filterTextBox.Lines = new string[0];
this.filterTextBox.Location = new System.Drawing.Point(173, 18);
this.filterTextBox.MaxLength = 32767;
this.filterTextBox.Name = "filterTextBox";
this.filterTextBox.PasswordChar = '\0';
this.filterTextBox.ScrollBars = System.Windows.Forms.ScrollBars.None;
this.filterTextBox.SelectedText = "";
this.filterTextBox.SelectionLength = 0;
this.filterTextBox.SelectionStart = 0;
this.filterTextBox.ShortcutsEnabled = true;
this.filterTextBox.Size = new System.Drawing.Size(156, 23);
this.filterTextBox.TabIndex = 17;
this.filterTextBox.Theme = MetroFramework.MetroThemeStyle.Dark;
this.filterTextBox.UseSelectable = true;
this.filterTextBox.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109)))));
this.filterTextBox.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel);
this.filterTextBox.TextChanged += new System.EventHandler(this.filter_TextChanged);
//
// tabController
//
this.tabController.Location = new System.Drawing.Point(6, 8);
this.tabController.Name = "tabController";
this.tabController.Size = new System.Drawing.Size(326, 184);
this.tabController.Style = MetroFramework.MetroColorStyle.White;
this.tabController.TabIndex = 18;
this.tabController.Theme = MetroFramework.MetroThemeStyle.Dark;
this.tabController.UseSelectable = true;
//
// FilterPromtp
//
this.AcceptButton = this.acceptButton;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(338, 228);
this.ControlBox = false;
this.Controls.Add(this.filterTextBox);
this.Controls.Add(metroLabel2);
this.Controls.Add(this.tabController);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.acceptButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FilterPromtp";
this.Resizable = false;
this.Style = MetroFramework.MetroColorStyle.Silver;
this.Theme = MetroFramework.MetroThemeStyle.Dark;
this.ResumeLayout(false);
this.PerformLayout();
}
private void MetroTextBox1_TextChanged(object sender, System.EventArgs e)
{
throw new System.NotImplementedException();
}
#endregion
private System.Windows.Forms.Button acceptButton;
private System.Windows.Forms.Button cancelButton;
private MetroFramework.Controls.MetroTextBox filterTextBox;
private MetroFramework.Controls.MetroTabControl tabController;
}
}

View File

@@ -0,0 +1,118 @@
/* Copyright (c) 2024-present miku-666
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1.The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using MetroFramework.Forms;
namespace PckStudio.Forms.Additional_Popups.Animation
{
internal partial class FilterPrompt : MetroForm
{
public string AcceptButtonText { get => acceptButton.Text; set => acceptButton.Text = value; }
public string CancelButtonText { get => cancelButton.Text; set => cancelButton.Text = value; }
private object selectedItem;
public object SelectedItem => selectedItem;
public int SelectedTabIndex => tabController.SelectedIndex;
public delegate bool FilterPredicate(string filterText, object nodeTag);
public event EventHandler OnSelectedItemChanged
{
add => Events.AddHandler(nameof(OnSelectedItemChanged), value);
remove => Events.RemoveHandler(nameof(OnSelectedItemChanged), value);
}
public FilterPrompt()
{
InitializeComponent();
}
public TreeView AddFilterPage(string categoryName, string key, FilterPredicate filterPredicate)
{
_ = categoryName ?? throw new ArgumentNullException(nameof(categoryName));
TabPage page = new TabPage(categoryName);
page.Name = key ?? categoryName;
page.Tag = filterPredicate;
var pageView = new TreeView()
{
Dock = DockStyle.Fill,
BackColor = Color.FromArgb(64, 64, 64),
};
pageView.AfterSelect += (sender, e) =>
{
selectedItem = e.Node.Tag;
Events[nameof(OnSelectedItemChanged)]?.DynamicInvoke(this, EventArgs.Empty);
};
pageView.Tag = new List<TreeNode>(4);
page.Controls.Add(pageView);
tabController.TabPages.Add(page);
return pageView;
}
public TreeView GetByKey(string key)
{
return tabController.TabPages[key].Controls[0] is TreeView view ? view : null;
}
private void filter_TextChanged(object sender, EventArgs e)
{
// Some code in this function is modified code from this StackOverflow answer - MattNL
// https://stackoverflow.com/questions/8260322/filter-a-treeview-with-a-textbox-in-a-c-sharp-winforms-app
// block re-painting control until all objects are loaded
foreach (TabPage tabpage in tabController.TabPages)
{
if (tabpage.Tag is not FilterPredicate filerPredicate || tabpage.Controls[0] is not TreeView pageView || pageView.Tag is not List<TreeNode> pageCache)
continue;
if (string.IsNullOrEmpty(filterTextBox.Text))
{
pageView.Nodes.Clear();
pageView.Nodes.AddRange(pageCache.ToArray());
continue;
}
pageView.BeginUpdate();
pageView.Nodes.Clear();
foreach (TreeNode _node in pageCache)
{
if (_node.Text.ToLower().Contains(filterTextBox.Text.ToLower()) || filerPredicate(filterTextBox.Text, _node.Tag))
{
pageView.Nodes.Add((TreeNode)_node.Clone());
}
}
pageView.EndUpdate();
}
}
private void CancelBtn_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void AcceptBtn_Click(object sender, EventArgs e)
{
DialogResult = selectedItem is null ? DialogResult.Cancel : DialogResult.OK;
}
}
}

View File

@@ -117,6 +117,15 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="metroLabel2.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="metroLabel2.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="filterTextBox.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>

View File

@@ -151,7 +151,6 @@ namespace PckStudio.Forms.Editor
if (!(treeView1.SelectedNode.Tag is BehaviourFile.RiderPositionOverride entry)) return;
var diag = new AddEntry("behaviours", ApplicationScope.EntityImages);
diag.acceptBtn.Text = "Save";
if (diag.ShowDialog(this) == DialogResult.OK)
{

View File

@@ -135,6 +135,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions\MaterialContainerExtensions.cs" />
<Compile Include="Forms\Additional-Popups\FilterPrompt.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\Additional-Popups\FilterPrompt.Designer.cs">
<DependentUpon>FilterPrompt.cs</DependentUpon>
</Compile>
<Compile Include="Forms\ContributorsForm.cs">
<SubType>Form</SubType>
</Compile>
@@ -293,12 +299,7 @@
<Compile Include="Internal\IO\TGA\TGAHeader.cs" />
<Compile Include="Internal\IO\TGA\TGAReader.cs" />
<Compile Include="Internal\IO\TGA\TGAWriter.cs" />
<Compile Include="Forms\Additional-Popups\EntityForms\AddEntry.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\Additional-Popups\EntityForms\AddEntry.Designer.cs">
<DependentUpon>AddEntry.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Additional-Popups\EntityForms\AddEntry.cs" />
<Compile Include="Forms\Additional-Popups\Loc\AddLanguage.cs">
<SubType>Form</SubType>
</Compile>
@@ -357,12 +358,7 @@
<Compile Include="Forms\Editor\LOCEditor.Designer.cs">
<DependentUpon>LOCEditor.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Additional-Popups\Animation\ChangeTile.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\Additional-Popups\Animation\ChangeTile.Designer.cs">
<DependentUpon>ChangeTile.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Additional-Popups\Animation\ChangeTile.cs" />
<Compile Include="Forms\Additional-Popups\Animation\SetBulkSpeed.cs">
<SubType>Form</SubType>
</Compile>
@@ -463,16 +459,15 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Internal\IO\3DST\TextureCodec.cs" />
<EmbeddedResource Include="Forms\Additional-Popups\FilterPrompt.resx">
<DependentUpon>FilterPrompt.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\ContributorsForm.resx">
<DependentUpon>ContributorsForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Features\CemuPanel.resx">
<DependentUpon>CemuPanel.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Additional-Popups\EntityForms\AddEntry.resx">
<DependentUpon>AddEntry.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Additional-Popups\Loc\AddLanguage.resx">
<DependentUpon>AddLanguage.cs</DependentUpon>
</EmbeddedResource>
@@ -513,9 +508,6 @@
<EmbeddedResource Include="Forms\Editor\LOCEditor.resx">
<DependentUpon>LOCEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Additional-Popups\Animation\ChangeTile.resx">
<DependentUpon>ChangeTile.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Additional-Popups\Animation\SetBulkSpeed.resx">
<DependentUpon>SetBulkSpeed.cs</DependentUpon>
</EmbeddedResource>