diff --git a/PCK-Studio/Forms/Additional-Popups/Behaviours/AddBehaviour.Designer.cs b/PCK-Studio/Forms/Additional-Popups/Behaviours/AddBehaviour.Designer.cs new file mode 100644 index 00000000..c64f207a --- /dev/null +++ b/PCK-Studio/Forms/Additional-Popups/Behaviours/AddBehaviour.Designer.cs @@ -0,0 +1,185 @@ +namespace PckStudio.Forms.Additional_Popups.Behaviours +{ + partial class AddBehaviour + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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); + // + // treeViewBlocks + // + 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 = "treeViewBlocks"; + 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"; + // + // AddBehaviour + // + 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.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "AddBehaviour"; + 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 acceptBtn; + 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; + } +} \ No newline at end of file diff --git a/PCK-Studio/Forms/Additional-Popups/Behaviours/AddBehaviour.cs b/PCK-Studio/Forms/Additional-Popups/Behaviours/AddBehaviour.cs new file mode 100644 index 00000000..68932bbc --- /dev/null +++ b/PCK-Studio/Forms/Additional-Popups/Behaviours/AddBehaviour.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using MetroFramework.Forms; +using Newtonsoft.Json.Linq; +using PckStudio.Forms.Utilities; + +namespace PckStudio.Forms.Additional_Popups.Behaviours +{ + public partial class AddBehaviour : MetroForm + { + string selectedEntity = ""; + + public string SelectedEntity => selectedEntity; + + List treeViewEntityCache = new List(); + + public AddBehaviour() + { + InitializeComponent(); + ImageList entities = new ImageList(); + entities.ColorDepth = ColorDepth.Depth32Bit; + entities.ImageSize = new System.Drawing.Size(32, 32); + entities.Images.AddRange(BehaviourUtil.entityImages); + treeViewEntity.ImageList = entities; + + try + { + int i = 0; + + if (BehaviourUtil.entityData["entities"] != null) + { + foreach (JObject content in BehaviourUtil.entityData["entities"].Children()) + { + foreach (JProperty prop in content.Properties()) + { + if (!string.IsNullOrEmpty((string)prop.Value)) + { + TreeNode entityNode = new TreeNode((string)prop.Value) + { + Tag = prop.Name, + ImageIndex = i, + SelectedImageIndex = i, + }; + treeViewEntity.Nodes.Add(entityNode); + treeViewEntityCache.Add(entityNode); + } + i++; + } + } + } + } + catch (Newtonsoft.Json.JsonException j_ex) + { + MessageBox.Show(j_ex.Message, "Error"); + return; + } + } + + private void treeViews_AfterSelect(object sender, TreeViewEventArgs e) + { + if (e.Node.Tag is string entityData) + { + selectedEntity = entityData; + Console.WriteLine(selectedEntity); + } + } + + 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 + + //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(); + } + } +} diff --git a/PCK-Studio/Forms/Additional-Popups/Behaviours/AddBehaviour.resx b/PCK-Studio/Forms/Additional-Popups/Behaviours/AddBehaviour.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/PCK-Studio/Forms/Additional-Popups/Behaviours/AddBehaviour.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PCK-Studio/Forms/Editor/BehaviourEditor.cs b/PCK-Studio/Forms/Editor/BehaviourEditor.cs index e2933188..ff2b91a3 100644 --- a/PCK-Studio/Forms/Editor/BehaviourEditor.cs +++ b/PCK-Studio/Forms/Editor/BehaviourEditor.cs @@ -12,10 +12,9 @@ namespace PckStudio.Forms.Editor { public partial class BehaviourEditor : MetroForm { - // Behaviours File Format research by Miku + // Behaviours File Format research by Miku and MattNL private readonly PCKFile.FileData _file; BehaviourFile behaviourFile; - bool _isLittleEndian = false; void SetUpTree() { @@ -48,6 +47,10 @@ namespace PckStudio.Forms.Editor behaviourFile = BehavioursReader.Read(stream); } + treeView1.ImageList = new ImageList(); + Utilities.BehaviourUtil.entityImages.ToList().ForEach(img => treeView1.ImageList.Images.Add(img)); + treeView1.ImageList.ImageSize = new Size(32, 32); + treeView1.ImageList.ColorDepth = ColorDepth.Depth32Bit; SetUpTree(); } @@ -163,15 +166,26 @@ namespace PckStudio.Forms.Editor private void addNewEntryToolStripMenuItem_Click(object sender, EventArgs e) { - BehaviourFile.RiderPositionOverride NewOverride = new BehaviourFile.RiderPositionOverride("NewRiderOverride"); + var diag = new Additional_Popups.Behaviours.AddBehaviour(); - TreeNode NewOverrideNode = new TreeNode(NewOverride.name); - NewOverrideNode.Tag = NewOverride; - treeView1.Nodes.Add(NewOverrideNode); + if(diag.ShowDialog() == DialogResult.OK) + { + if (String.IsNullOrEmpty(diag.SelectedEntity)) return; + if (behaviourFile.entries.FindAll(behaviour => behaviour.name == diag.SelectedEntity).Count() > 0) + { + MessageBox.Show(this, "You cannot have two entries for one entity. Please use the \"Add New Position Override\" tool to add multiple overrides for entities", "Error", MessageBoxButtons.OK); + return; + } + BehaviourFile.RiderPositionOverride NewOverride = new BehaviourFile.RiderPositionOverride(diag.SelectedEntity); - treeView1.SelectedNode = NewOverrideNode; + TreeNode NewOverrideNode = new TreeNode(NewOverride.name); + NewOverrideNode.Tag = NewOverride; + treeView1.Nodes.Add(NewOverrideNode); - addNewPositionOverrideToolStripMenuItem_Click(sender, e); // adds a Position Override to the new Override + treeView1.SelectedNode = NewOverrideNode; + + addNewPositionOverrideToolStripMenuItem_Click(sender, e); // adds a Position Override to the new Override + } } private void treeView1_KeyDown(object sender, KeyEventArgs e) diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj index 4dcb4ed1..4aad58c5 100644 --- a/PCK-Studio/PckStudio.csproj +++ b/PCK-Studio/PckStudio.csproj @@ -18,44 +18,41 @@ false true - - - - $(IntermediateOutputPath)gitver - - - - - - - - - - - - @(GitVersion) - - - - - - - $(IntermediateOutputPath)GitHashAssemblyInfo.cs - - - - - - - - - <_Parameter1>GitHash - <_Parameter2>$(BuildHash) - - - - - + + + + $(IntermediateOutputPath)gitver + + + + + + + + + + @(GitVersion) + + + + + + $(IntermediateOutputPath)GitHashAssemblyInfo.cs + + + + + + + + + <_Parameter1>GitHash + <_Parameter2>$(BuildHash) + + + + + Debug AnyCPU @@ -200,6 +197,7 @@ + @@ -242,6 +240,12 @@ + + Form + + + AddBehaviour.cs + Form @@ -362,6 +366,7 @@ pleaseWait.cs + Form @@ -491,6 +496,9 @@ + + AddBehaviour.cs + AddLanguage.cs @@ -689,6 +697,7 @@ + @@ -750,6 +759,7 @@ +