diff --git a/NHSE.Core/Structures/Building/StructureUtil.cs b/NHSE.Core/Structures/Building/StructureUtil.cs new file mode 100644 index 0000000..e293a7a --- /dev/null +++ b/NHSE.Core/Structures/Building/StructureUtil.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using System.Linq; + +namespace NHSE.Core +{ + public static class StructureUtil + { + public static Dictionary GetStructureHelpList() + { + var kvpa = new[] + { + EnumUtil.GetEnumList(), + + EnumUtil.GetEnumList(), + EnumUtil.GetEnumList(), + EnumUtil.GetEnumList(), + + EnumUtil.GetEnumList(), + EnumUtil.GetEnumList(), + EnumUtil.GetEnumList(), + }; + return kvpa.ToDictionary(x => x.Key, x => x.Value); + } + } +} diff --git a/NHSE.Core/Util/EnumUtil.cs b/NHSE.Core/Util/EnumUtil.cs new file mode 100644 index 0000000..925000f --- /dev/null +++ b/NHSE.Core/Util/EnumUtil.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; + +namespace NHSE.Core +{ + public static class EnumUtil + { + public static KeyValuePair GetEnumList() where T : Enum + { + var type = typeof(T); + var name = type.Name; + var values = GetTypeValues(type); + return new KeyValuePair(name, values); + } + + private static string[] GetTypeValues(Type type) where T : Enum + { + var arr = (T[])Enum.GetValues(type); + var result = new string[arr.Length]; + for (int i = 0; i < arr.Length; i++) + result[i] = GetSummary(arr[i]); + return result; + } + + private static string GetSummary(T z) where T : Enum + { + int x = Convert.ToInt32(z); + return $"{z} = {x}"; + } + } +} diff --git a/NHSE.Sprites/TerrainSprite.cs b/NHSE.Sprites/TerrainSprite.cs index e55b574..624091e 100644 --- a/NHSE.Sprites/TerrainSprite.cs +++ b/NHSE.Sprites/TerrainSprite.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using NHSE.Core; @@ -67,7 +68,7 @@ public static Bitmap CreateMap(TerrainManager mgr, int scale, int acreIndex = -1 var map = ImageUtil.ResizeImage(img, img.Width * scale, img.Height * scale); if (acreIndex < 0) - return img; + return map; var acre = mgr.Acres[acreIndex]; var x = acre.X * TerrainManager.GridWidth; @@ -86,5 +87,36 @@ private static Bitmap DrawReticle(Bitmap map, int x, int y, int scale) gfx.DrawRectangle(pen, x * scale, y * scale, w, h); return map; } + + public static Bitmap GetMapWithBuildings(TerrainManager mgr, IReadOnlyList buildings, Font f, int scale = 4, int index = -1) + { + // Although there is terrain in the Top Row and Left Column, no buildings can be placed there. + // Adjust the building coordinates down-right by an acre. + const int buildingShift = TerrainManager.GridWidth; + var map = CreateMap(mgr, scale); + using var gfx = Graphics.FromImage(map); + + var selected = Brushes.Red; + var others = Brushes.Yellow; + var text = Brushes.White; + var stringFormat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; + + for (int i = 0; i < buildings.Count; i++) + { + var b = buildings[i]; + if (b.BuildingType == 0) + continue; + var x = (int)(((b.X / 2f) - buildingShift) * scale); + var y = (int)(((b.Y / 2f) - buildingShift) * scale); + + var pen = index == i ? selected : others; + gfx.FillRectangle(pen, x - scale, y - scale, scale * 2, scale * 2); + + var name = b.BuildingType.ToString(); + gfx.DrawString(name, f, text, new PointF(x, y - (scale * 2)), stringFormat); + } + + return map; + } } } \ No newline at end of file diff --git a/NHSE.WinForms/Editor.cs b/NHSE.WinForms/Editor.cs index b6f2f75..b43dcb3 100644 --- a/NHSE.WinForms/Editor.cs +++ b/NHSE.WinForms/Editor.cs @@ -505,7 +505,7 @@ private void B_LoadDesign_Click(object sender, EventArgs e) private void B_EditBuildings_Click(object sender, EventArgs e) { var buildings = SAV.Main.Buildings; - using var editor = new PropertyEditor(buildings, Array.Empty()); + using var editor = new BuildingEditor(buildings, SAV.Main); if (editor.ShowDialog() == DialogResult.OK) SAV.Main.Buildings = buildings; } diff --git a/NHSE.WinForms/NHSE.WinForms.csproj b/NHSE.WinForms/NHSE.WinForms.csproj index 96dfe33..abee398 100644 --- a/NHSE.WinForms/NHSE.WinForms.csproj +++ b/NHSE.WinForms/NHSE.WinForms.csproj @@ -43,6 +43,9 @@ Form + + Form + Form diff --git a/NHSE.WinForms/Subforms/BuildingEditor.Designer.cs b/NHSE.WinForms/Subforms/BuildingEditor.Designer.cs new file mode 100644 index 0000000..f1aee50 --- /dev/null +++ b/NHSE.WinForms/Subforms/BuildingEditor.Designer.cs @@ -0,0 +1,400 @@ +namespace NHSE.WinForms +{ + partial class BuildingEditor + { + /// + /// 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.B_Save = new System.Windows.Forms.Button(); + this.B_Cancel = new System.Windows.Forms.Button(); + this.LB_Items = new System.Windows.Forms.ListBox(); + this.PB_Map = new System.Windows.Forms.PictureBox(); + this.L_BuildingType = new System.Windows.Forms.Label(); + this.NUD_BuildingType = new System.Windows.Forms.NumericUpDown(); + this.NUD_X = new System.Windows.Forms.NumericUpDown(); + this.L_BuildingX = new System.Windows.Forms.Label(); + this.NUD_Y = new System.Windows.Forms.NumericUpDown(); + this.L_BuildingY = new System.Windows.Forms.Label(); + this.NUD_Rot = new System.Windows.Forms.NumericUpDown(); + this.L_BuildingRotation = new System.Windows.Forms.Label(); + this.NUD_08 = new System.Windows.Forms.NumericUpDown(); + this.L_Building08 = new System.Windows.Forms.Label(); + this.NUD_0C = new System.Windows.Forms.NumericUpDown(); + this.L_Building0C = new System.Windows.Forms.Label(); + this.NUD_10 = new System.Windows.Forms.NumericUpDown(); + this.L_Building10 = new System.Windows.Forms.Label(); + this.GB_Building = new System.Windows.Forms.GroupBox(); + this.GB_Info = new System.Windows.Forms.GroupBox(); + this.CB_StructureType = new System.Windows.Forms.ComboBox(); + this.L_StructureType = new System.Windows.Forms.Label(); + this.L_StructureValues = new System.Windows.Forms.Label(); + this.CB_StructureValues = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.PB_Map)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_BuildingType)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_X)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_Y)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_Rot)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_08)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_0C)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_10)).BeginInit(); + this.GB_Building.SuspendLayout(); + this.GB_Info.SuspendLayout(); + this.SuspendLayout(); + // + // B_Save + // + this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.B_Save.Location = new System.Drawing.Point(597, 526); + this.B_Save.Name = "B_Save"; + this.B_Save.Size = new System.Drawing.Size(75, 23); + this.B_Save.TabIndex = 1; + this.B_Save.Text = "Save"; + this.B_Save.UseVisualStyleBackColor = true; + this.B_Save.Click += new System.EventHandler(this.B_Save_Click); + // + // B_Cancel + // + this.B_Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.B_Cancel.Location = new System.Drawing.Point(516, 526); + this.B_Cancel.Name = "B_Cancel"; + this.B_Cancel.Size = new System.Drawing.Size(75, 23); + this.B_Cancel.TabIndex = 2; + this.B_Cancel.Text = "Cancel"; + this.B_Cancel.UseVisualStyleBackColor = true; + this.B_Cancel.Click += new System.EventHandler(this.B_Cancel_Click); + // + // LB_Items + // + this.LB_Items.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.LB_Items.FormattingEnabled = true; + this.LB_Items.Location = new System.Drawing.Point(12, 12); + this.LB_Items.Name = "LB_Items"; + this.LB_Items.Size = new System.Drawing.Size(206, 537); + this.LB_Items.TabIndex = 3; + this.LB_Items.SelectedIndexChanged += new System.EventHandler(this.LB_Items_SelectedIndexChanged); + // + // PB_Map + // + this.PB_Map.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.PB_Map.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.PB_Map.Location = new System.Drawing.Point(224, 12); + this.PB_Map.Name = "PB_Map"; + this.PB_Map.Size = new System.Drawing.Size(450, 386); + this.PB_Map.TabIndex = 5; + this.PB_Map.TabStop = false; + // + // L_BuildingType + // + this.L_BuildingType.Location = new System.Drawing.Point(6, 12); + this.L_BuildingType.Name = "L_BuildingType"; + this.L_BuildingType.Size = new System.Drawing.Size(100, 18); + this.L_BuildingType.TabIndex = 6; + this.L_BuildingType.Text = "Building Type:"; + this.L_BuildingType.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // NUD_BuildingType + // + this.NUD_BuildingType.Location = new System.Drawing.Point(112, 13); + this.NUD_BuildingType.Name = "NUD_BuildingType"; + this.NUD_BuildingType.Size = new System.Drawing.Size(69, 20); + this.NUD_BuildingType.TabIndex = 7; + this.NUD_BuildingType.ValueChanged += new System.EventHandler(this.NUD_BuildingType_ValueChanged); + // + // NUD_X + // + this.NUD_X.Location = new System.Drawing.Point(61, 35); + this.NUD_X.Maximum = new decimal(new int[] { + 255, + 0, + 0, + 0}); + this.NUD_X.Name = "NUD_X"; + this.NUD_X.Size = new System.Drawing.Size(45, 20); + this.NUD_X.TabIndex = 9; + this.NUD_X.ValueChanged += new System.EventHandler(this.NUD_BuildingType_ValueChanged); + // + // L_BuildingX + // + this.L_BuildingX.Location = new System.Drawing.Point(35, 34); + this.L_BuildingX.Name = "L_BuildingX"; + this.L_BuildingX.Size = new System.Drawing.Size(20, 18); + this.L_BuildingX.TabIndex = 8; + this.L_BuildingX.Text = "X:"; + this.L_BuildingX.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // NUD_Y + // + this.NUD_Y.Location = new System.Drawing.Point(136, 35); + this.NUD_Y.Maximum = new decimal(new int[] { + 255, + 0, + 0, + 0}); + this.NUD_Y.Name = "NUD_Y"; + this.NUD_Y.Size = new System.Drawing.Size(45, 20); + this.NUD_Y.TabIndex = 11; + this.NUD_Y.ValueChanged += new System.EventHandler(this.NUD_BuildingType_ValueChanged); + // + // L_BuildingY + // + this.L_BuildingY.Location = new System.Drawing.Point(107, 34); + this.L_BuildingY.Name = "L_BuildingY"; + this.L_BuildingY.Size = new System.Drawing.Size(23, 18); + this.L_BuildingY.TabIndex = 10; + this.L_BuildingY.Text = "Y:"; + this.L_BuildingY.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // NUD_Rot + // + this.NUD_Rot.Location = new System.Drawing.Point(112, 60); + this.NUD_Rot.Maximum = new decimal(new int[] { + 65535, + 0, + 0, + 0}); + this.NUD_Rot.Name = "NUD_Rot"; + this.NUD_Rot.Size = new System.Drawing.Size(69, 20); + this.NUD_Rot.TabIndex = 13; + this.NUD_Rot.ValueChanged += new System.EventHandler(this.NUD_BuildingType_ValueChanged); + // + // L_BuildingRotation + // + this.L_BuildingRotation.Location = new System.Drawing.Point(6, 59); + this.L_BuildingRotation.Name = "L_BuildingRotation"; + this.L_BuildingRotation.Size = new System.Drawing.Size(100, 18); + this.L_BuildingRotation.TabIndex = 12; + this.L_BuildingRotation.Text = "Rotation:"; + this.L_BuildingRotation.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // NUD_08 + // + this.NUD_08.Location = new System.Drawing.Point(112, 80); + this.NUD_08.Maximum = new decimal(new int[] { + 65535, + 0, + 0, + 0}); + this.NUD_08.Name = "NUD_08"; + this.NUD_08.Size = new System.Drawing.Size(69, 20); + this.NUD_08.TabIndex = 15; + this.NUD_08.ValueChanged += new System.EventHandler(this.NUD_BuildingType_ValueChanged); + // + // L_Building08 + // + this.L_Building08.Location = new System.Drawing.Point(6, 79); + this.L_Building08.Name = "L_Building08"; + this.L_Building08.Size = new System.Drawing.Size(100, 18); + this.L_Building08.TabIndex = 14; + this.L_Building08.Text = "Unknown 0x08:"; + this.L_Building08.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // NUD_0C + // + this.NUD_0C.Location = new System.Drawing.Point(112, 100); + this.NUD_0C.Maximum = new decimal(new int[] { + 65535, + 0, + 0, + 0}); + this.NUD_0C.Name = "NUD_0C"; + this.NUD_0C.Size = new System.Drawing.Size(69, 20); + this.NUD_0C.TabIndex = 17; + this.NUD_0C.ValueChanged += new System.EventHandler(this.NUD_BuildingType_ValueChanged); + // + // L_Building0C + // + this.L_Building0C.Location = new System.Drawing.Point(6, 99); + this.L_Building0C.Name = "L_Building0C"; + this.L_Building0C.Size = new System.Drawing.Size(100, 18); + this.L_Building0C.TabIndex = 16; + this.L_Building0C.Text = "Unknown 0x0A:"; + this.L_Building0C.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // NUD_10 + // + this.NUD_10.Location = new System.Drawing.Point(112, 120); + this.NUD_10.Maximum = new decimal(new int[] { + 65535, + 0, + 0, + 0}); + this.NUD_10.Name = "NUD_10"; + this.NUD_10.Size = new System.Drawing.Size(69, 20); + this.NUD_10.TabIndex = 19; + this.NUD_10.ValueChanged += new System.EventHandler(this.NUD_BuildingType_ValueChanged); + // + // L_Building10 + // + this.L_Building10.Location = new System.Drawing.Point(6, 119); + this.L_Building10.Name = "L_Building10"; + this.L_Building10.Size = new System.Drawing.Size(100, 18); + this.L_Building10.TabIndex = 18; + this.L_Building10.Text = "Unknown 0x0C:"; + this.L_Building10.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // GB_Building + // + this.GB_Building.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.GB_Building.Controls.Add(this.L_BuildingType); + this.GB_Building.Controls.Add(this.NUD_BuildingType); + this.GB_Building.Controls.Add(this.NUD_10); + this.GB_Building.Controls.Add(this.L_BuildingX); + this.GB_Building.Controls.Add(this.L_Building10); + this.GB_Building.Controls.Add(this.NUD_X); + this.GB_Building.Controls.Add(this.NUD_0C); + this.GB_Building.Controls.Add(this.L_BuildingY); + this.GB_Building.Controls.Add(this.L_Building0C); + this.GB_Building.Controls.Add(this.NUD_Y); + this.GB_Building.Controls.Add(this.NUD_08); + this.GB_Building.Controls.Add(this.L_BuildingRotation); + this.GB_Building.Controls.Add(this.L_Building08); + this.GB_Building.Controls.Add(this.NUD_Rot); + this.GB_Building.Location = new System.Drawing.Point(224, 404); + this.GB_Building.Name = "GB_Building"; + this.GB_Building.Size = new System.Drawing.Size(194, 147); + this.GB_Building.TabIndex = 21; + this.GB_Building.TabStop = false; + this.GB_Building.Text = "Editor"; + // + // GB_Info + // + this.GB_Info.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.GB_Info.Controls.Add(this.L_StructureValues); + this.GB_Info.Controls.Add(this.CB_StructureValues); + this.GB_Info.Controls.Add(this.L_StructureType); + this.GB_Info.Controls.Add(this.CB_StructureType); + this.GB_Info.Location = new System.Drawing.Point(424, 404); + this.GB_Info.Name = "GB_Info"; + this.GB_Info.Size = new System.Drawing.Size(250, 103); + this.GB_Info.TabIndex = 22; + this.GB_Info.TabStop = false; + this.GB_Info.Text = "Info"; + // + // CB_StructureType + // + this.CB_StructureType.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.CB_StructureType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.CB_StructureType.FormattingEnabled = true; + this.CB_StructureType.Location = new System.Drawing.Point(20, 33); + this.CB_StructureType.Name = "CB_StructureType"; + this.CB_StructureType.Size = new System.Drawing.Size(221, 21); + this.CB_StructureType.TabIndex = 0; + this.CB_StructureType.SelectedIndexChanged += new System.EventHandler(this.CB_StructureType_SelectedIndexChanged); + // + // L_StructureType + // + this.L_StructureType.AutoSize = true; + this.L_StructureType.Location = new System.Drawing.Point(17, 17); + this.L_StructureType.Name = "L_StructureType"; + this.L_StructureType.Size = new System.Drawing.Size(80, 13); + this.L_StructureType.TabIndex = 20; + this.L_StructureType.Text = "Structure Type:"; + this.L_StructureType.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // L_StructureValues + // + this.L_StructureValues.AutoSize = true; + this.L_StructureValues.Location = new System.Drawing.Point(17, 58); + this.L_StructureValues.Name = "L_StructureValues"; + this.L_StructureValues.Size = new System.Drawing.Size(42, 13); + this.L_StructureValues.TabIndex = 22; + this.L_StructureValues.Text = "Values:"; + this.L_StructureValues.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // CB_StructureValues + // + this.CB_StructureValues.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.CB_StructureValues.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.CB_StructureValues.DropDownWidth = 322; + this.CB_StructureValues.FormattingEnabled = true; + this.CB_StructureValues.Location = new System.Drawing.Point(20, 74); + this.CB_StructureValues.Name = "CB_StructureValues"; + this.CB_StructureValues.Size = new System.Drawing.Size(221, 21); + this.CB_StructureValues.TabIndex = 21; + // + // BuildingEditor + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(684, 561); + this.Controls.Add(this.GB_Info); + this.Controls.Add(this.GB_Building); + this.Controls.Add(this.PB_Map); + this.Controls.Add(this.LB_Items); + this.Controls.Add(this.B_Cancel); + this.Controls.Add(this.B_Save); + this.Icon = global::NHSE.WinForms.Properties.Resources.icon; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "BuildingEditor"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Building Editor"; + ((System.ComponentModel.ISupportInitialize)(this.PB_Map)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_BuildingType)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_X)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_Y)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_Rot)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_08)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_0C)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_10)).EndInit(); + this.GB_Building.ResumeLayout(false); + this.GB_Info.ResumeLayout(false); + this.GB_Info.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.Button B_Save; + private System.Windows.Forms.Button B_Cancel; + private System.Windows.Forms.ListBox LB_Items; + private System.Windows.Forms.PictureBox PB_Map; + private System.Windows.Forms.Label L_BuildingType; + private System.Windows.Forms.NumericUpDown NUD_BuildingType; + private System.Windows.Forms.NumericUpDown NUD_X; + private System.Windows.Forms.Label L_BuildingX; + private System.Windows.Forms.NumericUpDown NUD_Y; + private System.Windows.Forms.Label L_BuildingY; + private System.Windows.Forms.NumericUpDown NUD_Rot; + private System.Windows.Forms.Label L_BuildingRotation; + private System.Windows.Forms.NumericUpDown NUD_08; + private System.Windows.Forms.Label L_Building08; + private System.Windows.Forms.NumericUpDown NUD_0C; + private System.Windows.Forms.Label L_Building0C; + private System.Windows.Forms.NumericUpDown NUD_10; + private System.Windows.Forms.Label L_Building10; + private System.Windows.Forms.GroupBox GB_Building; + private System.Windows.Forms.GroupBox GB_Info; + private System.Windows.Forms.Label L_StructureValues; + private System.Windows.Forms.ComboBox CB_StructureValues; + private System.Windows.Forms.Label L_StructureType; + private System.Windows.Forms.ComboBox CB_StructureType; + } +} \ No newline at end of file diff --git a/NHSE.WinForms/Subforms/BuildingEditor.cs b/NHSE.WinForms/Subforms/BuildingEditor.cs new file mode 100644 index 0000000..6a745a7 --- /dev/null +++ b/NHSE.WinForms/Subforms/BuildingEditor.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using NHSE.Core; +using NHSE.Sprites; + +namespace NHSE.WinForms +{ + public partial class BuildingEditor : Form + { + private readonly IReadOnlyList Buildings; + private readonly TerrainManager Terrain; + private static readonly IReadOnlyDictionary HelpDictionary = StructureUtil.GetStructureHelpList(); + + public BuildingEditor(IReadOnlyList buildings, MainSave sav) + { + InitializeComponent(); + Buildings = buildings; + DialogResult = DialogResult.Cancel; + + foreach (var obj in buildings) + LB_Items.Items.Add(obj.ToString()); + + Terrain = new TerrainManager(sav.GetTerrain()); + + LB_Items.SelectedIndex = 0; + foreach (var entry in HelpDictionary) + CB_StructureType.Items.Add(entry.Key); + CB_StructureType.SelectedIndex = 0; + } + + private void B_Cancel_Click(object sender, EventArgs e) => Close(); + + private void B_Save_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.OK; + Close(); + } + + private int Index; + private bool Loading; + private void DrawMap(in int index) => PB_Map.Image = TerrainSprite.GetMapWithBuildings(Terrain, Buildings, B_Save.Font, 4, index); + + private void LB_Items_SelectedIndexChanged(object sender, EventArgs e) + { + if (LB_Items.SelectedIndex < 0) + return; + LoadIndex(LB_Items.SelectedIndex); + DrawMap(Index); + } + + private void LoadIndex(int index) + { + Loading = true; + Index = index; + var b = Buildings[index]; + NUD_BuildingType.Value = (int)b.BuildingType; + NUD_X.Value = b.X; + NUD_Y.Value = b.Y; + NUD_Rot.Value = b.Rotation; + NUD_08.Value = b.Unk08; + NUD_0C.Value = b.Unk0C; + NUD_10.Value = b.Unk10; + Loading = false; + } + + private void NUD_BuildingType_ValueChanged(object sender, EventArgs e) + { + if (Loading || !(sender is NumericUpDown n)) + return; + + var b = Buildings[Index]; + if (sender == NUD_BuildingType) + b.BuildingType = (BuildingType)n.Value; + else if (sender == NUD_X) + b.X = (ushort)n.Value; + else if (sender == NUD_Y) + b.Y = (ushort)n.Value; + else if (sender == NUD_Rot) + b.Rotation = (ushort)n.Value; + else if (sender == NUD_08) + b.Unk08 = (uint)n.Value; + else if (sender == NUD_0C) + b.Unk0C = (uint)n.Value; + else if (sender == NUD_10) + b.Unk10 = (uint)n.Value; + + LB_Items.Items[Index] = Buildings[Index].ToString(); + DrawMap(Index); + } + + private void CB_StructureType_SelectedIndexChanged(object sender, EventArgs e) + { + var name = CB_StructureType.Text; + var values = HelpDictionary[name]; + CB_StructureValues.Items.Clear(); + foreach (var item in values) + CB_StructureValues.Items.Add(item); + CB_StructureValues.SelectedIndex = 0; + } + } +} diff --git a/NHSE.WinForms/Subforms/BuildingEditor.resx b/NHSE.WinForms/Subforms/BuildingEditor.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/NHSE.WinForms/Subforms/BuildingEditor.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