static public SIDData[] CreateArray(string[] names) { SIDData[] SIDs = new SIDData[names.Length]; for (int x = 0; x < names.Length; x++) { SIDs[x] = new SIDData(); SIDs[x].Index = x; SIDs[x].Name = names[x]; } return(SIDs); }
public static SIDData[] CreateArray(string[] names) { SIDData[] SIDs = new SIDData[names.Length]; for (int x = 0; x < names.Length; x++) { SIDs[x] = new SIDData(); SIDs[x].Index = x; SIDs[x].Name = names[x]; } return SIDs; }
private void SaveFieldChange(Control c) { BW.BaseStream.Position = (int)c.Tag; switch (FieldControl.GetType().ToString()) { // For bytes, (u)int16, (u)int32 // *This section complete (? may still be missing types)* case "entity.MetaEditor2.DataValues": long Value; float FValue; if (long.TryParse(c.Text, out Value)) { switch (((DataValues)FieldControl).ValueType) { case HaloMap.Plugins.IFPIO.ObjectEnum.Byte: BW.Write((byte)Value); c.Text = ((byte)Value).ToString(); break; case HaloMap.Plugins.IFPIO.ObjectEnum.Short: BW.Write((Int16)Value); c.Text = ((Int16)Value).ToString(); break; case HaloMap.Plugins.IFPIO.ObjectEnum.UShort: BW.Write((UInt16)Value); c.Text = ((UInt16)Value).ToString(); break; case HaloMap.Plugins.IFPIO.ObjectEnum.Int: BW.Write((Int32)Value); c.Text = ((Int32)Value).ToString(); break; case HaloMap.Plugins.IFPIO.ObjectEnum.UInt: BW.Write((UInt32)Value); c.Text = ((UInt32)Value).ToString(); break; } } else if (float.TryParse(c.Text, out FValue)) { switch (((DataValues)FieldControl).ValueType) { case HaloMap.Plugins.IFPIO.ObjectEnum.Float: BW.Write((float)FValue); c.Text = ((float)FValue).ToString(); break; } } else { this.Enabled = false; // In case of error, reset to saved value PopulateValue(c.Parent); this.Enabled = true; } break; // *This section Complete* case "entity.MetaEditor2.EntStrings": EntStrings EntString = (EntStrings)FieldControl; byte[] StringBytes = Encoding.ASCII.GetBytes(c.Text.ToCharArray()); Array.Resize(ref StringBytes, EntString.length); BW.Write(StringBytes); break; // *This section Complete* case "entity.MetaEditor2.Ident": ComboBox TagType = (ComboBox)c.Parent.Controls[0]; ComboBox Ident = (ComboBox)c.Parent.Controls[1]; BW.BaseStream.Position = (int)TagType.Tag; if (((Ident)FieldControl).HasTagType) { if (TagType.Text != "null") { byte[] TagTypeBytes = ASCIIEncoding.ASCII.GetBytes(TagType.Text); Array.Reverse(TagTypeBytes); BW.Write(TagTypeBytes); } else { byte[] TagTypeBytes = new byte[4] { 0xFF, 0xFF, 0xFF, 0xFF }; BW.Write(TagTypeBytes); } } int Index = FieldControl.map.Functions.ForMeta.FindByNameAndTagType(TagType.Text, Ident.Text); if (Index != -1) { BW.Write(FieldControl.map.MetaInfo.Ident[Index]); } else { BW.Write((int)-1); } break; // *This section Complete* case "entity.MetaEditor2.SID": SIDData sd = (SIDData)((ComboBox)c).SelectedItem; BW.Write((short)sd.Index); BW.Write((byte)0); BW.Write((byte)FieldControl.map.Strings.Length[sd.Index]); //FieldControl.map.Strings.Name[(c.Text)]; break; // *This section Complete* case "entity.MetaEditor2.Enums": Enums Enum = (Enums)FieldControl; HaloMap.Plugins.IFPIO.Option o = (HaloMap.Plugins.IFPIO.Option)Enum.Options[((ComboBox)c).SelectedIndex]; switch (Enum.enumType) { case 8: BW.Write((byte)o.value); break; case 16: BW.Write((short)o.value); break; case 32: BW.Write((int)o.value); break; } break; // *This section Complete* case "entity.MetaEditor2.Indices": Indices indices = (Indices)FieldControl; int IndexValue = indices.IndicesList.IndexOf(c.Text); // Last listing is for nulled resources if (IndexValue == indices.IndicesList.Count - 1) { IndexValue = -1; } switch (indices.ValueType) { case HaloMap.Plugins.IFPIO.ObjectEnum.Byte: BW.Write((byte)IndexValue); break; case HaloMap.Plugins.IFPIO.ObjectEnum.Short: BW.Write((short)IndexValue); break; case HaloMap.Plugins.IFPIO.ObjectEnum.UShort: BW.Write((ushort)IndexValue); break; case HaloMap.Plugins.IFPIO.ObjectEnum.Int: BW.Write((int)IndexValue); break; case HaloMap.Plugins.IFPIO.ObjectEnum.UInt: BW.Write((uint)IndexValue); break; } break; } }
/// <summary> /// Creates one control of the selected type for each chunk in the reflexive. /// Idents will have the tag types filled in & tag names will be auto filled when /// the tag type is selected. /// String IDs will have the strings list populated here. /// </summary> private void GenerateFields(int progressBarStart, int progressBarEnd) { this.SuspendLayout(); this.progressBar1.Value = progressBarStart; try { pnlAutoFill.Visible = false; ToolTip t = new ToolTip(); this.pnlFieldControls.Controls.Clear(); this.Size = new Size(400, 500); pnlFieldControls.AutoScroll = true; //pnlFieldControls.AutoScrollMargin = new Size(20, pnlFieldControls.Height); pnlFieldControls.AutoScrollMinSize = new Size(20, pnlFieldControls.Height); int StartChunk = int.Parse(cbStartChunk.Text); int EndChunk = int.Parse(cbEndChunk.Text); StartOffset = RD.baseOffset + FieldControl.chunkOffset - (RD.chunkSelected * RD.reflexive.chunkSize); switch (FieldControl.GetType().ToString()) { case "entity.MetaEditor2.DataValues": try { Control c = FieldControl.Controls[1]; for (int x = StartChunk; x <= EndChunk; x++) { // Update progress bar this.progressBar1.Value = (x - StartChunk) * (progressBarEnd - progressBarStart) / Math.Max(1, (EndChunk - StartChunk)); this.progressBar1.Refresh(); Control Casing = new Control(); Casing.Dock = DockStyle.Top; Casing.Padding = new Padding(4); Casing.Size = new Size(this.Width, 31); Label LBL = new Label(); LBL.Dock = DockStyle.Left; LBL.Location = new Point(10, 4); LBL.Size = new Size(140, 23); LBL.Text = FieldControl.EntName + " #" + x.ToString(); LBL.TextAlign = ContentAlignment.MiddleLeft; TextBox TB = new TextBox(); TB.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; TB.Location = new Point(150, 5); TB.Height = c.Height; TB.Width = c.Width; TB.Tag = StartOffset + x * RD.reflexive.chunkSize; TB.Leave += new EventHandler(Field_Leave); TB.TextChanged += new EventHandler(Field_TextChanged); t.SetToolTip(TB, TB.Tag.ToString()); Casing.Controls.Add(TB); Casing.Controls.Add(LBL); pnlFieldControls.Controls.Add(Casing); Casing.BringToFront(); } pnlAutoFill.Visible = true; } catch { MessageBox.Show("An error occured reading DataValues fields"); } break; case "entity.MetaEditor2.EntStrings": try { Control c = FieldControl.Controls[1]; for (int x = StartChunk; x <= EndChunk; x++) { // Update progress bar this.progressBar1.Value = (x - StartChunk) * (progressBarEnd - progressBarStart) / Math.Max(1, (EndChunk - StartChunk)); this.progressBar1.Refresh(); Control Casing = new Control(); Casing.Dock = DockStyle.Top; Casing.Padding = new Padding(4); Casing.Size = new Size(this.Width, 31); Label LBL = new Label(); LBL.Dock = DockStyle.Left; LBL.Location = new Point(10, 4); LBL.Size = new Size(140, 23); LBL.Text = FieldControl.EntName + " #" + x.ToString(); LBL.TextAlign = ContentAlignment.MiddleLeft; TextBox TB = new TextBox(); TB.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; TB.Location = new Point(150, 5); TB.Height = c.Height; TB.MaxLength = ((EntStrings)FieldControl).length; TB.Width = Casing.Width - TB.Left - 30; TB.Tag = StartOffset + x * RD.reflexive.chunkSize; TB.Leave += new EventHandler(Field_Leave); t.SetToolTip(TB, TB.Tag.ToString()); Casing.Controls.Add(TB); Casing.Controls.Add(LBL); pnlFieldControls.Controls.Add(Casing); Casing.BringToFront(); } } catch { MessageBox.Show("An error occured reading EntStrings fields"); } break; case "entity.MetaEditor2.Ident": try { Control c = FieldControl.Controls[1]; this.Size = new Size(FieldControl.Width, 500); System.Collections.IEnumerator i = FieldControl.map.MetaInfo.TagTypes.Keys.GetEnumerator(); List <string> TagTypes = new List <string>(); while (i.MoveNext()) { TagTypes.Add((string)i.Current); } TagTypes.Sort(); TagTypes.Add((string)"null"); for (int x = StartChunk; x <= EndChunk; x++) { // Update progress bar this.progressBar1.Value = (x - StartChunk) * (progressBarEnd - progressBarStart) / Math.Max(1, (EndChunk - StartChunk)); this.progressBar1.Refresh(); Control Casing = new Control(); Casing.Dock = DockStyle.Top; Casing.Padding = new Padding(4); Casing.Size = new Size(this.Width, 31); Label LBL = new Label(); LBL.Dock = DockStyle.Left; LBL.Location = new Point(10, 4); LBL.Size = new Size(140, 23); LBL.Text = FieldControl.EntName + " #" + x.ToString(); LBL.TextAlign = ContentAlignment.MiddleLeft; ComboBox FieldTagType = new ComboBox(); FieldTagType.Anchor = AnchorStyles.Left | AnchorStyles.Top; FieldTagType.DropDownStyle = ComboBoxStyle.DropDownList; FieldTagType.Location = new Point(150, 5); FieldTagType.Height = c.Height; FieldTagType.Items.AddRange(TagTypes.ToArray()); FieldTagType.Width = FieldControl.Controls[2].Width; FieldTagType.Tag = StartOffset + x * RD.reflexive.chunkSize; FieldTagType.SelectedIndexChanged += new EventHandler(FieldTagType_SelectedIndexChanged); FieldTagType.Leave += new EventHandler(Field_Leave); FieldTagType.TextChanged += new EventHandler(Field_TextChanged); t.SetToolTip(FieldTagType, FieldTagType.Tag.ToString()); ComboBox FieldIdent = new ComboBox(); FieldIdent.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; FieldIdent.DropDownStyle = ComboBoxStyle.DropDownList; FieldIdent.Location = new Point(250, 5); FieldIdent.Height = c.Height; FieldIdent.Width = FieldControl.Controls[1].Width; if (((Ident)FieldControl).HasTagType) { FieldIdent.Tag = StartOffset + x * RD.reflexive.chunkSize + 4; } else { FieldIdent.Tag = StartOffset + x * RD.reflexive.chunkSize; } FieldIdent.Leave += new EventHandler(Field_Leave); t.SetToolTip(FieldIdent, FieldIdent.Tag.ToString()); Casing.Controls.Add(FieldTagType); Casing.Controls.Add(FieldIdent); Casing.Controls.Add(LBL); pnlFieldControls.Controls.Add(Casing); Casing.BringToFront(); } } catch { MessageBox.Show("An error occured reading Tag/Ident fields"); } break; case "entity.MetaEditor2.SID": try { Control c = FieldControl.Controls[1]; this.Size = new Size(FieldControl.Width, 500); List <SIDData> SIDs = new List <SIDData>(); SIDs.AddRange(SIDData.CreateArray(FieldControl.map.Strings.Name)); SortStringIDs(ref SIDs); for (int x = StartChunk; x <= EndChunk; x++) { // Update progress bar this.progressBar1.Value = (x - StartChunk) * (progressBarEnd - progressBarStart) / Math.Max(1, (EndChunk - StartChunk)); this.progressBar1.Refresh(); Control Casing = new Control(); Casing.Dock = DockStyle.Top; Casing.Padding = new Padding(4); Casing.Size = new Size(this.Width, 31); Label LBL = new Label(); LBL.Dock = DockStyle.Left; LBL.Location = new Point(10, 4); LBL.Size = new Size(140, 23); LBL.Text = FieldControl.EntName + " #" + x.ToString(); LBL.TextAlign = ContentAlignment.MiddleLeft; ComboBox SIDBox = new ComboBox(); SIDBox.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; SIDBox.DropDownStyle = ComboBoxStyle.DropDownList; SIDBox.Location = new Point(150, 5); SIDBox.Height = c.Height; SIDBox.Items.AddRange(SIDs.ToArray()); SIDBox.DisplayMember = "Name"; SIDBox.Width = FieldControl.Controls[1].Width; SIDBox.Tag = StartOffset + x * RD.reflexive.chunkSize; SIDBox.Leave += new EventHandler(Field_Leave); t.SetToolTip(SIDBox, SIDBox.Tag.ToString()); Casing.Controls.Add(SIDBox); Casing.Controls.Add(LBL); pnlFieldControls.Controls.Add(Casing); Casing.BringToFront(); } } catch { MessageBox.Show("An error occured reading String ID fields"); } break; case "entity.MetaEditor2.Enums": try { ComboBox c = (ComboBox)FieldControl.Controls[1]; for (int x = StartChunk; x <= EndChunk; x++) { // Update progress bar this.progressBar1.Value = (x - StartChunk) * (progressBarEnd - progressBarStart) / Math.Max(1, (EndChunk - StartChunk)); this.progressBar1.Refresh(); Control Casing = new Control(); Casing.Dock = DockStyle.Top; Casing.Padding = new Padding(4); Casing.Size = new Size(this.Width, 31); Label LBL = new Label(); LBL.Dock = DockStyle.Left; LBL.Location = new Point(10, 4); LBL.Size = new Size(140, 23); LBL.Text = FieldControl.EntName + " #" + x.ToString(); LBL.TextAlign = ContentAlignment.MiddleLeft; ComboBox EnumsBox = new ComboBox(); EnumsBox.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; EnumsBox.Location = new Point(150, 5); EnumsBox.Height = c.Height; object[] objs = new object[c.Items.Count]; c.Items.CopyTo(objs, 0); EnumsBox.Items.AddRange(objs); EnumsBox.Width = FieldControl.Controls[1].Width; EnumsBox.Tag = StartOffset + x * RD.reflexive.chunkSize; EnumsBox.Leave += new EventHandler(Field_Leave); t.SetToolTip(EnumsBox, EnumsBox.Tag.ToString()); Casing.Controls.Add(EnumsBox); Casing.Controls.Add(LBL); pnlFieldControls.Controls.Add(Casing); Casing.BringToFront(); } pnlAutoFill.Visible = true; } catch { MessageBox.Show("An error occured reading Enums fields"); } break; case "entity.MetaEditor2.Indices": try { Control c = FieldControl.Controls[1]; this.Size = new Size(FieldControl.Width, 500); Indices indices = ((Indices)FieldControl); // Make sure all values have been added to combobox (happens on dropdown) indices.UpdateSelectionList(true); for (int x = StartChunk; x <= EndChunk; x++) { // Update progress bar this.progressBar1.Value = (x - StartChunk) * (progressBarEnd - progressBarStart) / Math.Max(1, (EndChunk - StartChunk)); this.progressBar1.Refresh(); Control Casing = new Control(); Casing.Dock = DockStyle.Top; Casing.Padding = new Padding(4); Casing.Size = new Size(this.Width, 31); Label LBL = new Label(); LBL.Dock = DockStyle.Left; LBL.Location = new Point(10, 4); LBL.Size = new Size(140, 23); LBL.Text = FieldControl.EntName + " #" + x.ToString(); LBL.TextAlign = ContentAlignment.MiddleLeft; ComboBox Indices = new ComboBox(); Indices.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; Indices.DropDownStyle = ComboBoxStyle.DropDownList; Indices.Location = new Point(150, 5); Indices.Height = c.Height; Indices.Items.AddRange(indices.IndicesList.ToArray()); Indices.DisplayMember = "Name"; Indices.Width = Casing.Width - Indices.Left - 50; Indices.Tag = StartOffset + x * RD.reflexive.chunkSize; Indices.Leave += new EventHandler(Field_Leave); t.SetToolTip(Indices, Indices.Tag.ToString()); Casing.Controls.Add(Indices); Casing.Controls.Add(LBL); pnlFieldControls.Controls.Add(Casing); Casing.BringToFront(); } } catch { MessageBox.Show("An error occured reading Indices/Block Index fields"); } break; default: MessageBox.Show(FieldControl.GetType().ToString() + " fields are currently Unsupported."); this.Close(); break; } } finally { this.ResumeLayout(true); } }