From 208d6d1f7cd27bacb9ddba6dcbfd8401fa79a01b Mon Sep 17 00:00:00 2001 From: lastbattle <4586194+lastbattle@users.noreply.github.com> Date: Thu, 26 Sep 2024 12:40:26 +0800 Subject: [PATCH] [HaCreator] add map 'obj' image from editor panel by selecting from files --- .../GUI/EditorPanels/ObjPanel.Designer.cs | 287 ++++++++++-------- HaCreator/GUI/EditorPanels/ObjPanel.cs | 184 ++++++++++- HaCreator/GUI/EditorPanels/ObjPanel.resx | 54 ++-- MapleLib | 2 +- 4 files changed, 364 insertions(+), 163 deletions(-) diff --git a/HaCreator/GUI/EditorPanels/ObjPanel.Designer.cs b/HaCreator/GUI/EditorPanels/ObjPanel.Designer.cs index 84a01ba5..3b7c3c31 100644 --- a/HaCreator/GUI/EditorPanels/ObjPanel.Designer.cs +++ b/HaCreator/GUI/EditorPanels/ObjPanel.Designer.cs @@ -30,155 +30,200 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.splitContainer3 = new System.Windows.Forms.SplitContainer(); - this.splitContainer4 = new System.Windows.Forms.SplitContainer(); - this.objSetListBox = new System.Windows.Forms.ListBox(); - this.objL0ListBox = new System.Windows.Forms.ListBox(); - this.splitContainer5 = new System.Windows.Forms.SplitContainer(); - this.objL1ListBox = new System.Windows.Forms.ListBox(); - this.objImagesContainer = new ThumbnailFlowLayoutPanel(); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).BeginInit(); - this.splitContainer3.Panel1.SuspendLayout(); - this.splitContainer3.Panel2.SuspendLayout(); - this.splitContainer3.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer4)).BeginInit(); - this.splitContainer4.Panel1.SuspendLayout(); - this.splitContainer4.Panel2.SuspendLayout(); - this.splitContainer4.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer5)).BeginInit(); - this.splitContainer5.Panel1.SuspendLayout(); - this.splitContainer5.Panel2.SuspendLayout(); - this.splitContainer5.SuspendLayout(); - this.SuspendLayout(); - // - // splitContainer3 - // - this.splitContainer3.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer3.Location = new System.Drawing.Point(0, 0); - this.splitContainer3.Name = "splitContainer3"; - this.splitContainer3.Orientation = System.Windows.Forms.Orientation.Horizontal; - // - // splitContainer3.Panel1 - // - this.splitContainer3.Panel1.Controls.Add(this.splitContainer4); - // - // splitContainer3.Panel2 - // - this.splitContainer3.Panel2.Controls.Add(this.splitContainer5); - this.splitContainer3.Size = new System.Drawing.Size(284, 658); - this.splitContainer3.SplitterDistance = 189; - this.splitContainer3.TabIndex = 2; - // - // splitContainer4 - // - this.splitContainer4.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer4.Location = new System.Drawing.Point(0, 0); - this.splitContainer4.Name = "splitContainer4"; - this.splitContainer4.Orientation = System.Windows.Forms.Orientation.Horizontal; - // - // splitContainer4.Panel1 - // - this.splitContainer4.Panel1.Controls.Add(this.objSetListBox); - // - // splitContainer4.Panel2 - // - this.splitContainer4.Panel2.Controls.Add(this.objL0ListBox); - this.splitContainer4.Size = new System.Drawing.Size(284, 189); - this.splitContainer4.SplitterDistance = 113; - this.splitContainer4.TabIndex = 0; + splitContainer_all = new System.Windows.Forms.SplitContainer(); + splitContainer_topPanel = new System.Windows.Forms.SplitContainer(); + objSetListBox = new System.Windows.Forms.ListBox(); + objL0ListBox = new System.Windows.Forms.ListBox(); + splitContainer_bottomPanel = new System.Windows.Forms.SplitContainer(); + objL1ListBox = new System.Windows.Forms.ListBox(); + objImagesContainer = new ThumbnailFlowLayoutPanel(); + button_addImage = new System.Windows.Forms.Button(); + splitContainer_whole = new System.Windows.Forms.SplitContainer(); + ((System.ComponentModel.ISupportInitialize)splitContainer_all).BeginInit(); + splitContainer_all.Panel1.SuspendLayout(); + splitContainer_all.Panel2.SuspendLayout(); + splitContainer_all.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)splitContainer_topPanel).BeginInit(); + splitContainer_topPanel.Panel1.SuspendLayout(); + splitContainer_topPanel.Panel2.SuspendLayout(); + splitContainer_topPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)splitContainer_bottomPanel).BeginInit(); + splitContainer_bottomPanel.Panel1.SuspendLayout(); + splitContainer_bottomPanel.Panel2.SuspendLayout(); + splitContainer_bottomPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)splitContainer_whole).BeginInit(); + splitContainer_whole.Panel1.SuspendLayout(); + splitContainer_whole.Panel2.SuspendLayout(); + splitContainer_whole.SuspendLayout(); + SuspendLayout(); + // + // splitContainer_all + // + splitContainer_all.Dock = System.Windows.Forms.DockStyle.Fill; + splitContainer_all.Location = new System.Drawing.Point(0, 0); + splitContainer_all.Name = "splitContainer_all"; + splitContainer_all.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer_all.Panel1 + // + splitContainer_all.Panel1.Controls.Add(splitContainer_topPanel); + // + // splitContainer_all.Panel2 + // + splitContainer_all.Panel2.Controls.Add(splitContainer_bottomPanel); + splitContainer_all.Size = new System.Drawing.Size(284, 629); + splitContainer_all.SplitterDistance = 180; + splitContainer_all.TabIndex = 2; + // + // splitContainer_topPanel + // + splitContainer_topPanel.Dock = System.Windows.Forms.DockStyle.Fill; + splitContainer_topPanel.Location = new System.Drawing.Point(0, 0); + splitContainer_topPanel.Name = "splitContainer_topPanel"; + splitContainer_topPanel.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer_topPanel.Panel1 + // + splitContainer_topPanel.Panel1.Controls.Add(objSetListBox); + // + // splitContainer_topPanel.Panel2 + // + splitContainer_topPanel.Panel2.Controls.Add(objL0ListBox); + splitContainer_topPanel.Size = new System.Drawing.Size(284, 180); + splitContainer_topPanel.SplitterDistance = 107; + splitContainer_topPanel.TabIndex = 0; // // objSetListBox // - this.objSetListBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.objSetListBox.FormattingEnabled = true; - this.objSetListBox.Location = new System.Drawing.Point(0, 0); - this.objSetListBox.Name = "objSetListBox"; - this.objSetListBox.Size = new System.Drawing.Size(284, 113); - this.objSetListBox.TabIndex = 0; - this.objSetListBox.SelectedIndexChanged += new System.EventHandler(this.objSetListBox_SelectedIndexChanged); + objSetListBox.Dock = System.Windows.Forms.DockStyle.Fill; + objSetListBox.FormattingEnabled = true; + objSetListBox.ItemHeight = 13; + objSetListBox.Location = new System.Drawing.Point(0, 0); + objSetListBox.Name = "objSetListBox"; + objSetListBox.Size = new System.Drawing.Size(284, 107); + objSetListBox.TabIndex = 0; + objSetListBox.SelectedIndexChanged += objSetListBox_SelectedIndexChanged; // // objL0ListBox // - this.objL0ListBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.objL0ListBox.FormattingEnabled = true; - this.objL0ListBox.Location = new System.Drawing.Point(0, 0); - this.objL0ListBox.Name = "objL0ListBox"; - this.objL0ListBox.Size = new System.Drawing.Size(284, 72); - this.objL0ListBox.TabIndex = 0; - this.objL0ListBox.SelectedIndexChanged += new System.EventHandler(this.objL0ListBox_SelectedIndexChanged); + objL0ListBox.Dock = System.Windows.Forms.DockStyle.Fill; + objL0ListBox.FormattingEnabled = true; + objL0ListBox.ItemHeight = 13; + objL0ListBox.Location = new System.Drawing.Point(0, 0); + objL0ListBox.Name = "objL0ListBox"; + objL0ListBox.Size = new System.Drawing.Size(284, 69); + objL0ListBox.TabIndex = 0; + objL0ListBox.SelectedIndexChanged += objL0ListBox_SelectedIndexChanged; // - // splitContainer5 + // splitContainer_bottomPanel // - this.splitContainer5.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer5.Location = new System.Drawing.Point(0, 0); - this.splitContainer5.Name = "splitContainer5"; - this.splitContainer5.Orientation = System.Windows.Forms.Orientation.Horizontal; + splitContainer_bottomPanel.Dock = System.Windows.Forms.DockStyle.Fill; + splitContainer_bottomPanel.Location = new System.Drawing.Point(0, 0); + splitContainer_bottomPanel.Name = "splitContainer_bottomPanel"; + splitContainer_bottomPanel.Orientation = System.Windows.Forms.Orientation.Horizontal; // - // splitContainer5.Panel1 + // splitContainer_bottomPanel.Panel1 // - this.splitContainer5.Panel1.Controls.Add(this.objL1ListBox); + splitContainer_bottomPanel.Panel1.Controls.Add(objL1ListBox); // - // splitContainer5.Panel2 + // splitContainer_bottomPanel.Panel2 // - this.splitContainer5.Panel2.Controls.Add(this.objImagesContainer); - this.splitContainer5.Size = new System.Drawing.Size(284, 465); - this.splitContainer5.SplitterDistance = 67; - this.splitContainer5.TabIndex = 0; + splitContainer_bottomPanel.Panel2.Controls.Add(objImagesContainer); + splitContainer_bottomPanel.Size = new System.Drawing.Size(284, 445); + splitContainer_bottomPanel.SplitterDistance = 64; + splitContainer_bottomPanel.TabIndex = 0; // // objL1ListBox // - this.objL1ListBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.objL1ListBox.FormattingEnabled = true; - this.objL1ListBox.Location = new System.Drawing.Point(0, 0); - this.objL1ListBox.Name = "objL1ListBox"; - this.objL1ListBox.Size = new System.Drawing.Size(284, 67); - this.objL1ListBox.TabIndex = 0; - this.objL1ListBox.SelectedIndexChanged += new System.EventHandler(this.objL1ListBox_SelectedIndexChanged); + objL1ListBox.Dock = System.Windows.Forms.DockStyle.Fill; + objL1ListBox.FormattingEnabled = true; + objL1ListBox.ItemHeight = 13; + objL1ListBox.Location = new System.Drawing.Point(0, 0); + objL1ListBox.Name = "objL1ListBox"; + objL1ListBox.Size = new System.Drawing.Size(284, 64); + objL1ListBox.TabIndex = 0; + objL1ListBox.SelectedIndexChanged += objL1ListBox_SelectedIndexChanged; // // objImagesContainer // - this.objImagesContainer.AutoScroll = true; - this.objImagesContainer.BackColor = System.Drawing.Color.White; - this.objImagesContainer.Dock = System.Windows.Forms.DockStyle.Fill; - this.objImagesContainer.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; - this.objImagesContainer.Location = new System.Drawing.Point(0, 0); - this.objImagesContainer.Name = "objImagesContainer"; - this.objImagesContainer.Size = new System.Drawing.Size(284, 394); - this.objImagesContainer.TabIndex = 0; - this.objImagesContainer.WrapContents = false; + objImagesContainer.AutoScroll = true; + objImagesContainer.BackColor = System.Drawing.Color.White; + objImagesContainer.Dock = System.Windows.Forms.DockStyle.Fill; + objImagesContainer.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; + objImagesContainer.Font = new System.Drawing.Font("Segoe UI", 8.25F); + objImagesContainer.Location = new System.Drawing.Point(0, 0); + objImagesContainer.Name = "objImagesContainer"; + objImagesContainer.Size = new System.Drawing.Size(284, 377); + objImagesContainer.TabIndex = 0; + objImagesContainer.WrapContents = false; + // + // button_addImage + // + button_addImage.Dock = System.Windows.Forms.DockStyle.Fill; + button_addImage.Enabled = false; + button_addImage.Location = new System.Drawing.Point(0, 0); + button_addImage.Name = "button_addImage"; + button_addImage.Size = new System.Drawing.Size(284, 25); + button_addImage.TabIndex = 0; + button_addImage.Text = "Add Image"; + button_addImage.UseVisualStyleBackColor = true; + button_addImage.Click += button_addImage_Click; + // + // splitContainer_whole + // + splitContainer_whole.Dock = System.Windows.Forms.DockStyle.Fill; + splitContainer_whole.Location = new System.Drawing.Point(0, 0); + splitContainer_whole.Name = "splitContainer_whole"; + splitContainer_whole.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer_whole.Panel1 + // + splitContainer_whole.Panel1.Controls.Add(splitContainer_all); + // + // splitContainer_whole.Panel2 + // + splitContainer_whole.Panel2.Controls.Add(button_addImage); + splitContainer_whole.Size = new System.Drawing.Size(284, 658); + splitContainer_whole.SplitterDistance = 629; + splitContainer_whole.TabIndex = 1; // // ObjPanel // - this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; - this.Controls.Add(this.splitContainer3); - this.Font = new System.Drawing.Font("Segoe UI", 8.25F); - this.Name = "ObjPanel"; - this.Size = new System.Drawing.Size(284, 658); - this.splitContainer3.Panel1.ResumeLayout(false); - this.splitContainer3.Panel2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).EndInit(); - this.splitContainer3.ResumeLayout(false); - this.splitContainer4.Panel1.ResumeLayout(false); - this.splitContainer4.Panel2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer4)).EndInit(); - this.splitContainer4.ResumeLayout(false); - this.splitContainer5.Panel1.ResumeLayout(false); - this.splitContainer5.Panel2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer5)).EndInit(); - this.splitContainer5.ResumeLayout(false); - this.ResumeLayout(false); - + AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + Controls.Add(splitContainer_whole); + Font = new System.Drawing.Font("Segoe UI", 8.25F); + Name = "ObjPanel"; + Size = new System.Drawing.Size(284, 658); + splitContainer_all.Panel1.ResumeLayout(false); + splitContainer_all.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer_all).EndInit(); + splitContainer_all.ResumeLayout(false); + splitContainer_topPanel.Panel1.ResumeLayout(false); + splitContainer_topPanel.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer_topPanel).EndInit(); + splitContainer_topPanel.ResumeLayout(false); + splitContainer_bottomPanel.Panel1.ResumeLayout(false); + splitContainer_bottomPanel.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer_bottomPanel).EndInit(); + splitContainer_bottomPanel.ResumeLayout(false); + splitContainer_whole.Panel1.ResumeLayout(false); + splitContainer_whole.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer_whole).EndInit(); + splitContainer_whole.ResumeLayout(false); + ResumeLayout(false); } #endregion - private System.Windows.Forms.SplitContainer splitContainer3; - private System.Windows.Forms.SplitContainer splitContainer4; + private System.Windows.Forms.SplitContainer splitContainer_all; + private System.Windows.Forms.SplitContainer splitContainer_topPanel; private System.Windows.Forms.ListBox objSetListBox; private System.Windows.Forms.ListBox objL0ListBox; - private System.Windows.Forms.SplitContainer splitContainer5; + private System.Windows.Forms.SplitContainer splitContainer_bottomPanel; private System.Windows.Forms.ListBox objL1ListBox; private ThumbnailFlowLayoutPanel objImagesContainer; + private System.Windows.Forms.Button button_addImage; + private System.Windows.Forms.SplitContainer splitContainer_whole; } } \ No newline at end of file diff --git a/HaCreator/GUI/EditorPanels/ObjPanel.cs b/HaCreator/GUI/EditorPanels/ObjPanel.cs index fc329bb1..0c5b8129 100644 --- a/HaCreator/GUI/EditorPanels/ObjPanel.cs +++ b/HaCreator/GUI/EditorPanels/ObjPanel.cs @@ -11,16 +11,10 @@ using MapleLib.WzLib.WzProperties; using MapleLib.WzLib.WzStructure.Data; using System; -using System.Collections; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; -using WeifenLuo.WinFormsUI.Docking; namespace HaCreator.GUI.EditorPanels { @@ -28,11 +22,18 @@ public partial class ObjPanel : UserControl { private HaCreatorStateManager hcsm; + /// + /// Constructor + /// public ObjPanel() { InitializeComponent(); } + /// + /// Init + /// + /// public void Initialize(HaCreatorStateManager hcsm) { this.hcsm = hcsm; @@ -40,12 +41,21 @@ public void Initialize(HaCreatorStateManager hcsm) List sortedObjSets = new List(); foreach (KeyValuePair oS in Program.InfoManager.ObjectSets) + { sortedObjSets.Add(oS.Key); + } sortedObjSets.Sort(); foreach (string oS in sortedObjSets) + { objSetListBox.Items.Add(oS); + } } + /// + /// On obj selection changed + /// + /// + /// private void objSetListBox_SelectedIndexChanged(object sender, EventArgs e) { if (objSetListBox.SelectedItem == null) @@ -70,6 +80,11 @@ private void objSetListBox_SelectedIndexChanged(object sender, EventArgs e) } } + /// + /// On L0 selection changed + /// + /// + /// private void objL0ListBox_SelectedIndexChanged(object sender, EventArgs e) { if (objL0ListBox.SelectedItem == null) @@ -89,31 +104,43 @@ private void objL0ListBox_SelectedIndexChanged(object sender, EventArgs e) } } + /// + /// On L1 selection changed + /// + /// + /// private void objL1ListBox_SelectedIndexChanged(object sender, EventArgs e) { lock (hcsm.MultiBoard) { - if (objL1ListBox.SelectedItem == null) return; + if (objL1ListBox.SelectedItem == null) + return; + objImagesContainer.Controls.Clear(); WzImageProperty l1Prop = Program.InfoManager.ObjectSets[(string)objSetListBox.SelectedItem][(string)objL0ListBox.SelectedItem][(string)objL1ListBox.SelectedItem]; - try + + foreach (WzSubProperty l2Prop in l1Prop.WzProperties) { - foreach (WzSubProperty l2Prop in l1Prop.WzProperties) + try { ObjectInfo info = ObjectInfo.Get((string)objSetListBox.SelectedItem, (string)objL0ListBox.SelectedItem, (string)objL1ListBox.SelectedItem, l2Prop.Name); - ImageViewer item = objImagesContainer.Add(info.Image, l2Prop.Name, true); + Bitmap image = info.Image; + ImageViewer item = objImagesContainer.Add(image, l2Prop.Name, true); + item.Tag = info; item.MouseDown += new MouseEventHandler(objItem_Click); item.MouseUp += new MouseEventHandler(ImageViewer.item_MouseUp); item.MaxHeight = UserSettings.ImageViewerHeight; item.MaxWidth = UserSettings.ImageViewerWidth; } - } - catch(InvalidCastException) - { - return; + catch (InvalidCastException) + { + return; + } } } + // Enable add image button after a L1 is selected + button_addImage.Enabled = true; } public void OnL1Changed(string l1) @@ -136,5 +163,134 @@ private void objItem_Click(object sender, MouseEventArgs e) ((ImageViewer)sender).IsActive = true; } } + + /// + /// Adds an image to the obj + /// + /// + /// + private void button_addImage_Click(object sender, EventArgs e) + { + if (objSetListBox.SelectedItem == null || objL0ListBox.SelectedItem == null || objL1ListBox.SelectedItem == null) + { + MessageBox.Show("Please select an object set, L0, and L1 category before adding an image.", "Selection Required", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + + using (OpenFileDialog openFileDialog = new OpenFileDialog()) + { + //openFileDialog.Filter = "Image Files (*.png;*.jpg;*.jpeg;*.gif;*.bmp)|*.png;*.jpg;*.jpeg;*.gif;*.bmp"; + openFileDialog.Filter = "Image Files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg"; + openFileDialog.Title = "Select an image to add"; + + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + try + { + Bitmap newImage = new(openFileDialog.FileName); + string imageName = System.IO.Path.GetFileNameWithoutExtension(openFileDialog.FileName); + + string objSetName = (string)objSetListBox.SelectedItem; + string l0Name = (string)objL0ListBox.SelectedItem; + string l1Name = (string)objL1ListBox.SelectedItem; + + // Get the L1 property + WzImageProperty l1Prop = Program.InfoManager.ObjectSets[objSetName][l0Name][l1Name]; + + // Generate a unique name for the new object + string newObjL2Name = GenerateUniqueObjectName(objSetName, l0Name, l1Name); + + ObjectInfo newObjectInfo; + WzImageProperty newL2Prop_; + + bool bAnimated = false; + if (bAnimated) // if its canvas property, its 1 frame, otherwise its animated + { + // Create a new WzSubProperty for the L2 object + WzCanvasProperty newL2Prop = new WzCanvasProperty("0", l1Prop); + newL2Prop.PngProperty = new WzPngProperty(); + newL2Prop.PngProperty.PNG = newImage; + newL2Prop_ = newL2Prop; + + // Add the new L2 property to the L1 property + l1Prop.WzProperties.Add(newL2Prop); + + // there's no fixed place or consistency in the WZ + // sometimes its at the top-center + // sometimes bottom-left or bottom-right + // it depends on nexon-devs, better off making this automatic for the user. + Point point = new Point(newImage.Width / 2, newImage.Height); // set at bottom-center + + // Create a new ObjectInfo + newObjectInfo = new ObjectInfo(newImage, point, objSetName, l0Name, l1Name, newObjL2Name, newL2Prop); + } + else + { + // Create a new WzSubProperty for the L2 object + WzSubProperty newL2Prop = new WzSubProperty(newObjL2Name); + + // Add necessary properties to the new L2 object + newL2Prop["z"] = new WzIntProperty("z", 0); // Default z-index + WzCanvasProperty canvasProp = new WzCanvasProperty("0"); + canvasProp.PngProperty = new WzPngProperty(); + canvasProp.PngProperty.PNG = newImage; + newL2Prop["0"] = canvasProp; + + newL2Prop_ = newL2Prop; + + // Add the new L2 property to the L1 property + l1Prop.WzProperties.Add(newL2Prop); + + // there's no fixed place or consistency in the WZ + // sometimes its at the top-center + // sometimes bottom-left or bottom-right + // it depends on nexon-devs, better off making this automatic for the user. + Point point = new Point(newImage.Width / 2, newImage.Height); // set at bottom-center + + // Create a new ObjectInfo + newObjectInfo = new ObjectInfo(newImage, point, objSetName, l0Name, l1Name, newObjL2Name, newL2Prop); + } + + // Add the new image to the objImagesContainer + ImageViewer newItem = objImagesContainer.Add(newImage, newObjL2Name, true); + newItem.Tag = newObjectInfo; + newItem.MouseDown += new MouseEventHandler(objItem_Click); + newItem.MouseUp += new MouseEventHandler(ImageViewer.item_MouseUp); + newItem.MaxHeight = UserSettings.ImageViewerHeight; + newItem.MaxWidth = UserSettings.ImageViewerWidth; + + // flag WZ files changed to save it + WzObject topMostWzDir = l1Prop.GetTopMostWzDirectory(); + WzObject topMostWzImg = l1Prop.GetTopMostWzImage(); + Program.WzManager.SetWzFileUpdated(topMostWzDir.Name, topMostWzImg as WzImage); + + MessageBox.Show($"Image '{newObjL2Name}' added successfully.", "Image Added", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show($"Error adding image: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + /// + /// Generates a new object name for the image + /// 0,1,2,3,4,5,6 ... + /// + /// + /// + /// + /// + private string GenerateUniqueObjectName(string objSetName, string l0Name, string l1Name) + { + int counter = 1; + WzImageProperty l1Prop = Program.InfoManager.ObjectSets[objSetName][l0Name][l1Name]; + while (l1Prop.WzProperties.Any(p => p.Name == counter.ToString())) + { + counter++; + } + return counter.ToString(); + } } } diff --git a/HaCreator/GUI/EditorPanels/ObjPanel.resx b/HaCreator/GUI/EditorPanels/ObjPanel.resx index 1af7de15..8b2ff64a 100644 --- a/HaCreator/GUI/EditorPanels/ObjPanel.resx +++ b/HaCreator/GUI/EditorPanels/ObjPanel.resx @@ -1,17 +1,17 @@  - diff --git a/MapleLib b/MapleLib index 6b439789..484b5744 160000 --- a/MapleLib +++ b/MapleLib @@ -1 +1 @@ -Subproject commit 6b4397892cb76a53872e15c57090562c26b5b3f6 +Subproject commit 484b5744fd170f94c9382722e1e644558e777ea2