diff --git a/ServerGridEditor.exe b/ServerGridEditor.exe index a63b328..569b589 100644 Binary files a/ServerGridEditor.exe and b/ServerGridEditor.exe differ diff --git a/Src/ServerGridEditor/Code/Island.cs b/Src/ServerGridEditor/Code/Island.cs index 3c4fadc..134bda7 100644 --- a/Src/ServerGridEditor/Code/Island.cs +++ b/Src/ServerGridEditor/Code/Island.cs @@ -42,6 +42,9 @@ namespace ServerGridEditor [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] public string islandTreasureBottleSupplyCrateOverrides = ""; + [JsonIgnore] + public string modDir = null; + Image cachedImg = null; Image cachedOptimizedImg = null; diff --git a/Src/ServerGridEditor/Forms/CreateIslandForm.Designer.cs b/Src/ServerGridEditor/Forms/CreateIslandForm.Designer.cs index ff3c63d..5e6da58 100644 --- a/Src/ServerGridEditor/Forms/CreateIslandForm.Designer.cs +++ b/Src/ServerGridEditor/Forms/CreateIslandForm.Designer.cs @@ -62,6 +62,8 @@ this.label11 = new System.Windows.Forms.Label(); this.label12 = new System.Windows.Forms.Label(); this.instancesListBox = new System.Windows.Forms.ListBox(); + this.label13 = new System.Windows.Forms.Label(); + this.modNameTxtBox = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.spawnerOverridesGrid)).BeginInit(); this.SuspendLayout(); @@ -188,7 +190,6 @@ // // addSublevels // - this.addSublevels.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.addSublevels.Location = new System.Drawing.Point(96, 295); this.addSublevels.Name = "addSublevels"; this.addSublevels.Size = new System.Drawing.Size(90, 24); @@ -365,6 +366,22 @@ this.instancesListBox.Size = new System.Drawing.Size(194, 95); this.instancesListBox.TabIndex = 39; // + // label13 + // + this.label13.AutoSize = true; + this.label13.Location = new System.Drawing.Point(20, 18); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(114, 13); + this.label13.TabIndex = 40; + this.label13.Text = "Unique Mod Extension"; + // + // modNameTxtBox + // + this.modNameTxtBox.Location = new System.Drawing.Point(140, 15); + this.modNameTxtBox.Name = "modNameTxtBox"; + this.modNameTxtBox.Size = new System.Drawing.Size(109, 20); + this.modNameTxtBox.TabIndex = 41; + // // CreateIslandForm // this.AcceptButton = this.createBtn; @@ -372,6 +389,8 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.cancelBtn; this.ClientSize = new System.Drawing.Size(609, 619); + this.Controls.Add(this.modNameTxtBox); + this.Controls.Add(this.label13); this.Controls.Add(this.instancesListBox); this.Controls.Add(this.label12); this.Controls.Add(this.label11); @@ -454,5 +473,7 @@ private System.Windows.Forms.Label label11; private System.Windows.Forms.Label label12; private System.Windows.Forms.ListBox instancesListBox; + private System.Windows.Forms.Label label13; + private System.Windows.Forms.TextBox modNameTxtBox; } } \ No newline at end of file diff --git a/Src/ServerGridEditor/Forms/CreateIslandForm.cs b/Src/ServerGridEditor/Forms/CreateIslandForm.cs index e6beb14..9ad0f23 100644 --- a/Src/ServerGridEditor/Forms/CreateIslandForm.cs +++ b/Src/ServerGridEditor/Forms/CreateIslandForm.cs @@ -73,6 +73,8 @@ namespace ServerGridEditor if (s != null) instancesListBox.Items.Add(string.Format("({0}, {1})", s.gridX, s.gridY)); } + + modNameTxtBox.Text = editedIsland.modDir; } } @@ -169,6 +171,7 @@ namespace ServerGridEditor float.TryParse(minTreasureQualityTxtBox.Text, out minTreasureQuality); float.TryParse(maxTreasureQualityTxtBox.Text, out maxTreasureQuality); + string islandRemovedFromMod = null; if (editedIsland != null) { if (islandNameTxtBox.Text != editedIsland.name) //name changed @@ -201,7 +204,8 @@ namespace ServerGridEditor mainForm.islands.Add(editedIsland.name, editedIsland); //rename image - string newImgPath = MainForm.imgsDir + "/" + editedIsland.name + "_img.jpg"; + string originalDirectory = Path.GetDirectoryName(editedIsland.imagePath); + string newImgPath = originalDirectory + "/" + editedIsland.name + "_img.jpg"; editedIsland.InvalidateImage(); File.Move(editedIsland.imagePath, newImgPath); @@ -211,6 +215,52 @@ namespace ServerGridEditor editedIsland.imagePath = newImgPath; } + if (modNameTxtBox.Text != editedIsland.modDir) + { + //Mod dir changed + if (!string.IsNullOrWhiteSpace(modNameTxtBox.Text)) + { + modNameTxtBox.Text.Trim(); + + string modDir = null; + modDir = MainForm.islandModsDir + "/" + modNameTxtBox.Text; + + if (!Directory.Exists(modDir)) + Directory.CreateDirectory(modDir); + if (!Directory.Exists(modDir + MainForm.modImgsDir)) + Directory.CreateDirectory(modDir + MainForm.modImgsDir); + + editedIsland.InvalidateImage(); + + string newImgPath = modDir + MainForm.modImgsDir + editedIsland.name + "_img.jpg"; + File.Move(editedIsland.imagePath, newImgPath); + + islandRemovedFromMod = editedIsland.modDir; + editedIsland.modDir = modNameTxtBox.Text; + + if (pictureBox1.ImageLocation == editedIsland.imagePath) + pictureBox1.ImageLocation = newImgPath; + + editedIsland.imagePath = newImgPath; + } + else + { + editedIsland.InvalidateImage(); + string newImgPath = MainForm.imgsDir + "/" + editedIsland.name + "_img.jpg"; + if (File.Exists(newImgPath)) + File.Delete(newImgPath); + File.Move(editedIsland.imagePath, newImgPath); + + islandRemovedFromMod = editedIsland.modDir; + editedIsland.modDir = null; + + if (pictureBox1.ImageLocation == editedIsland.imagePath) + pictureBox1.ImageLocation = newImgPath; + + editedIsland.imagePath = newImgPath; + } + } + editedIsland.x = x; editedIsland.y = y; @@ -250,7 +300,7 @@ namespace ServerGridEditor NewEntries.RemoveAll(item => { return string.IsNullOrWhiteSpace(item); }); editedIsland.extraSublevels = NewEntries; - mainForm.SaveIslands(); + mainForm.SaveIslands(islandRemovedFromMod); DialogResult = DialogResult.OK; Close(); } @@ -279,8 +329,19 @@ namespace ServerGridEditor spawnerOverrides.Add(name, template); } + string modDir = null; + if (!string.IsNullOrWhiteSpace(modNameTxtBox.Text)) + { + modDir = MainForm.islandModsDir + "/" + modNameTxtBox.Text; + if (!Directory.Exists(modDir)) + Directory.CreateDirectory(modDir); + if(!Directory.Exists(modDir + MainForm.modImgsDir)) + Directory.CreateDirectory(modDir + MainForm.modImgsDir); + } + //Copy the image to our local imgs directory - string newImgPath = MainForm.imgsDir + "/" + Name + "_img.jpg"; + string newImgPath = (modDir != null) ? (modDir + MainForm.modImgsDir) : MainForm.imgsDir; + newImgPath += "/" + Name + "_img.jpg"; File.Copy(ImgLocation, newImgPath, true); @@ -288,6 +349,8 @@ namespace ServerGridEditor minTreasureQuality, maxTreasureQuality, useNpcVolumesForTreasuresChkBox.Checked, useLevelBoundsForTreasuresChkBox.Checked, prioritizeVolumesForTreasuresChkBox.Checked, IslandTreasureBottleSupplyCrateOverridesTxtBox.Text, new List(extraSublevelsTxtBox.Lines))); + mainForm.islands.Last().Value.modDir = modNameTxtBox.Text.Trim(); + mainForm.RefreshIslandList(); mainForm.SaveIslands(); diff --git a/Src/ServerGridEditor/Forms/MainForm.cs b/Src/ServerGridEditor/Forms/MainForm.cs index 3c90cd8..4bda336 100644 --- a/Src/ServerGridEditor/Forms/MainForm.cs +++ b/Src/ServerGridEditor/Forms/MainForm.cs @@ -26,12 +26,15 @@ namespace ServerGridEditor public partial class MainForm : Form { public static string imgsDir = "./IslandImages"; + public static string modImgsDir = "/Images/"; public static string waterTilesDir = "./WaterTiles"; public static string foregroundTilesDir = "./Foregrounds"; public static string dataDir = "./Data"; public static string exportDir = "./Export"; + public static string islandModsDir = "./IslandExtensions"; public static string configSaveFile = dataDir + "/config.json"; - public static string islandsSaveFile = dataDir + "/islands.json"; + public static string islandsJson = "/islands.json"; + public static string islandsSaveFile = dataDir + islandsJson; public static string spawnersSaveFile = dataDir + "/spawners.json"; public static string islandsSaveFileBackup = dataDir + "/islands-backup.json"; @@ -132,6 +135,8 @@ namespace ServerGridEditor Directory.CreateDirectory(waterTilesDir); if (!Directory.Exists(foregroundTilesDir)) Directory.CreateDirectory(foregroundTilesDir); + if (!Directory.Exists(islandModsDir)) + Directory.CreateDirectory(islandModsDir); //if (!Directory.Exists(exportDir)) // Directory.CreateDirectory(exportDir); @@ -511,7 +516,7 @@ namespace ServerGridEditor foreach (Server s in currentProject.servers) { PointF serverCenter = new PointF(s.gridX * cellSize + cellSize / 2f, s.gridY * cellSize + cellSize / 2f); - serverCenter.Y -= cellSize * 0.15f; + serverCenter.Y -= cellSize * 0.17f; //Draw locks if (!forExport) { @@ -579,6 +584,10 @@ namespace ServerGridEditor continue; } + string easyName = string.Format("{0}{1}", (char)(((int)'A') + s.gridX), s.gridY + 1); + g.DrawString(easyName, font, Brushes.Black, new PointF(serverCenter.X + dynamicOutlineShift, serverCenter.Y + dynamicOutlineShift), centeredStringFormat); + g.DrawString(easyName, font, Brushes.White, serverCenter, centeredStringFormat); + serverCenter.Y += stringSize.Height * 1.1f; if (!string.IsNullOrWhiteSpace(s.MachineIdTag)) { @@ -1107,14 +1116,55 @@ namespace ServerGridEditor mapPanel.Invalidate(); } - public void SaveIslands() + public void SaveIslands(string islandRemovedFromMod = null) { //Take backup if (File.Exists(islandsSaveFile)) File.Copy(islandsSaveFile, islandsSaveFileBackup, true); - string json = JsonConvert.SerializeObject(islands, Formatting.Indented); + //Separate mod islands to be saved in their respective files + Dictionary> modsDict = new Dictionary>(); + + List allIslands = islands.Values.ToList(); + Dictionary originalIslands = new Dictionary(); + + foreach (Island island in allIslands) + if (island.modDir != null) + { + //This is a mod island group it to be saved + Dictionary modIslandsDict = null; + if (!modsDict.TryGetValue(island.modDir, out modIslandsDict)) + { + modIslandsDict = new Dictionary(); + modsDict.Add(island.modDir, modIslandsDict); + } + + modIslandsDict.Add(island.name, island); + } + else + { + originalIslands.Add(island.name, island); + } + + //Serialize Main island file + string json = JsonConvert.SerializeObject(originalIslands, Formatting.Indented); File.WriteAllText(islandsSaveFile, json); + + //Serialize mod island files + foreach (KeyValuePair> kvp in modsDict) + { + string islandDataJson = islandModsDir + "/" + kvp.Key + islandsJson; + json = JsonConvert.SerializeObject(kvp.Value, Formatting.Indented); + File.WriteAllText(islandDataJson, json); + } + + //Delete mod files if there are no more islands in it + if (islandRemovedFromMod != null && !modsDict.ContainsKey(islandRemovedFromMod)) + { + string modDirPath = islandModsDir + "/" + islandRemovedFromMod; + if (Directory.Exists(modDirPath)) + Directory.Delete(modDirPath, true); + } } public void LoadIslands() @@ -1122,15 +1172,39 @@ namespace ServerGridEditor if (File.Exists(islandsSaveFile)) { islands = JsonConvert.DeserializeObject>(File.ReadAllText(islandsSaveFile)); + + string[] modDirs = Directory.GetDirectories(islandModsDir); + + foreach (string islandModDir in modDirs) + { + string dataFile = islandModDir + islandsJson; + if (File.Exists(dataFile)) + { + Dictionary ModIslands = JsonConvert.DeserializeObject>(File.ReadAllText(dataFile)); + if(ModIslands != null) + foreach(KeyValuePair kvp in ModIslands) + { + if (islands.ContainsKey(kvp.Key)) + { + MessageBox.Show(string.Format("File {0} contains duplicate island named {1}, this island will not be imported", Path.GetFileName(dataFile), kvp.Key), + "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + continue; + } + + if (kvp.Value != null) + kvp.Value.modDir = Path.GetFileName(islandModDir); + + islands.Add(kvp.Key, kvp.Value); + } + } + } RefreshIslandList(); } } public void SaveProject() { - JsonSerializerSettings settings = new JsonSerializerSettings(); - string json = JsonConvert.SerializeObject(islands, Formatting.Indented); - File.WriteAllText(islandsSaveFile, json); + SaveIslands(); } /// @@ -1775,10 +1849,12 @@ namespace ServerGridEditor } } + string islandRemovedFromMod = null; foreach (string islandToRemove in islandsToRemove) { //delete the image islands[islandToRemove].InvalidateImage(); + islandRemovedFromMod = islands[islandToRemove].modDir; File.Delete(islands[islandToRemove].imagePath); islands.Remove(islandToRemove); @@ -1786,7 +1862,7 @@ namespace ServerGridEditor RefreshIslandList(); mapPanel.Invalidate(); - SaveIslands(); + SaveIslands(islandRemovedFromMod); } private void showServerInfoCheckbox_CheckedChanged(object sender, EventArgs e)