Layout : Add support for adding fonts/textures from the tree

This commit is contained in:
KillzXGaming 2022-02-28 18:31:05 -05:00
parent 6137bddb0d
commit a3a1b71474
2 changed files with 52 additions and 24 deletions

View file

@ -2263,7 +2263,7 @@ namespace LayoutBXLYT
public virtual List<string> Textures { get; }
[Browsable(false)]
public virtual List<string> Fonts { get; }
public virtual List<string> Fonts { get; set; }
[Browsable(false)]
public virtual List<BxlytMaterial> Materials { get;}

View file

@ -172,31 +172,34 @@ namespace LayoutBXLYT
{
ActiveLayout.TextureFolder = new TreeNode("Textures");
treeView1.Nodes.Add(ActiveLayout.TextureFolder);
for (int i = 0; i < textures.Count; i++)
ActiveLayout.TextureFolder.ContextMenuStrip = new ContextMenuStrip();
ActiveLayout.TextureFolder.ContextMenuStrip.Items.Add(new STToolStipMenuItem("Add", null, (o, e) =>
{
TreeNode matNode = new TreeNode(textures[i]);
matNode.Tag = i;
ActiveLayout.Textures.Add("NewTexture");
AddTextureNode("NewTexture", ActiveLayout.Textures.Count - 1);
}));
for (int i = 0; i < textures.Count; i++)
AddTextureNode(textures[i], i);
}
private void AddTextureNode(string tex, int i)
{
TreeNode matNode = new TreeNode(tex);
matNode.ContextMenuStrip = new ContextMenuStrip();
var menu = new STToolStipMenuItem("Rename");
menu.Click += RenameTextureAction;
matNode.ContextMenuStrip.Items.Add(menu);
matNode.ContextMenuStrip.Items.Add(new STToolStipMenuItem("Rename", null, (o, e) =>
{
RenameTextureAction(matNode, i);
}));
matNode.ImageKey = "texture";
matNode.SelectedImageKey = "texture";
ActiveLayout.TextureFolder.Nodes.Add(matNode);
}
}
private void RenameTextureAction(object sender, EventArgs e)
private void RenameTextureAction(TreeNode selectedNode, int index)
{
var selectedNode = treeView1.SelectedNode;
if (selectedNode == null) return;
int index = (int)selectedNode.Tag;
string activeTex = ActiveLayout.Textures[index];
RenameDialog dlg = new RenameDialog();
dlg.SetString(activeTex);
dlg.SetString(selectedNode.Text);
if (dlg.ShowDialog() == DialogResult.OK)
{
ActiveLayout.Textures[index] = dlg.textBox1.Text;
@ -207,14 +210,39 @@ namespace LayoutBXLYT
private void LoadFonts(List<string> fonts)
{
ActiveLayout.FontFolder = new TreeNode("Fonts");
ActiveLayout.FontFolder.ContextMenuStrip = new ContextMenuStrip();
ActiveLayout.FontFolder.ContextMenuStrip.Items.Add(new STToolStipMenuItem("Add", null, (o, e) =>
{
ActiveLayout.Fonts.Add("NewFont");
AddFontNode("NewFont", ActiveLayout.Fonts.Count - 1);
}));
treeView1.Nodes.Add(ActiveLayout.FontFolder);
for (int i = 0; i < fonts.Count; i++)
AddFontNode(fonts[i], i);
}
private void AddFontNode(string font, int i)
{
TreeNode matNode = new TreeNode(fonts[i]);
TreeNode matNode = new TreeNode(font);
matNode.ContextMenuStrip = new ContextMenuStrip();
matNode.ContextMenuStrip.Items.Add(new STToolStipMenuItem("Rename", null, (o, e) =>
{
RenameFont(matNode, i);
}));
matNode.ImageKey = "font";
matNode.SelectedImageKey = "font";
ActiveLayout.FontFolder.Nodes.Add(matNode);
}
private void RenameFont(TreeNode selectedNode, int index)
{
RenameDialog dlg = new RenameDialog();
dlg.SetString(selectedNode.Text);
if (dlg.ShowDialog() == DialogResult.OK) {
ActiveLayout.Fonts[index] = dlg.textBox1.Text;
selectedNode.Text = dlg.textBox1.Text;
}
}
private void LoadMaterials(List<BxlytMaterial> materials)