public void LoadTagEditor(CachedTag tag) { if (tag == null || (CurrentTag != null && CurrentTag.Index == tag.Index)) { return; } LoadingTag = true; object definition = null; if (CurrentTags.ContainsKey(tag.Index)) { definition = CurrentTags[tag.Index]; } tagTreeView.Enabled = false; tagEditorPanel.Controls.Clear(); var tagName = tag.Name ?? $"0x{tag.Index:X4}"; var groupName = Cache.StringTable.GetString(tag.Group.Name); statusLabel.Text = $"Loading {tagName}.{ groupName}..."; progressBar.Style = ProgressBarStyle.Marquee; progressBar.MarqueeAnimationSpeed = 30; if (definition == null) { using (var stream = Cache.OpenCacheRead()) definition = Cache.Deserialize(stream, tag); } if (tagName.Contains("\\")) { var index = tagName.LastIndexOf('\\') + 1; tagName = tagName.Substring(index, tagName.Length - index); } statusLabel.Text = $"Generating {groupName} interface..."; Application.DoEvents(); var point = new Point(); if (tag.IsInGroup("matg") || tag.IsInGroup("mulg") || tag.IsInGroup("scnr") || tag.IsInGroup("sbsp")) { var control = new StructMultiControl(this, Cache, tag, definition) { Dock = DockStyle.Fill }; control.GetFieldValue(null, definition, definition); tagEditorPanel.Controls.Add(control); } // todo: fixup/clean model rendering code // todo: finish bitm editing (save/import dds, add size scaling to image) else if (tag.IsInGroup("bitm") || tag.IsInGroup("obje")) { var splitContainer = new SplitContainer { Dock = DockStyle.Fill, Orientation = Orientation.Horizontal }; splitContainer.FixedPanel = FixedPanel.Panel1; tagEditorPanel.Controls.Add(splitContainer); splitContainer.BringToFront(); /*if (tag.IsInGroup("bitm")) * splitContainer.SplitterDistance = 384;//Math.Min((short)512, Math.Max((short)16, ((TagTool.Tags.Definitions.Bitmap)definition).Images[0].Height)); * else if (tag.IsInGroup("obje")) * splitContainer.SplitterDistance = 384;*/ if (tag.IsInGroup("bitm")) { var bitmDefinition = (TagTool.Tags.Definitions.Bitmap)definition; if (Cache.ResourceCache.GetBitmapTextureInteropResource(bitmDefinition.Resources[0]) != null) { splitContainer.SplitterDistance = 384; var bitmapControl = new BitmapControl(Cache, bitmDefinition) { Dock = DockStyle.Fill }; splitContainer.Panel1.Controls.Add(bitmapControl); bitmapControl.BringToFront(); } } /*else if (tag.IsInGroup("obje")) * { * var modelControl = new ObjectControl(Cache, (GameObject)definition) * { * Dock = DockStyle.Fill * }; * * splitContainer.Panel1.Controls.Add(modelControl); * modelControl.BringToFront(); * }*/ var control = tag.IsInGroup("obje") ? (Control) new StructMultiControl(this, Cache, tag, definition) { Dock = DockStyle.Fill } : new StructControl(this, Cache, definition.GetType(), null); ((IFieldControl)control).GetFieldValue(null, definition, definition); control.Location = point; splitContainer.Panel2.Controls.Add(control); splitContainer.Panel2.AutoScroll = true; } else { if (tag.IsInGroup("snd!")) { var soundControl = new SoundControl(Cache, tag, (Sound)definition) { Dock = DockStyle.Top }; tagEditorPanel.Controls.Add(soundControl); soundControl.BringToFront(); point.Y = soundControl.Bottom; } var control = new StructControl(this, Cache, definition.GetType(), null); control.GetFieldValue(null, definition, definition); control.Location = point; tagEditorPanel.Controls.Add(control); } statusLabel.Text = ""; progressBar.Style = ProgressBarStyle.Continuous; progressBar.MarqueeAnimationSpeed = 0; tagTreeView.Enabled = true; CurrentTag = tag; if (!CurrentTags.ContainsKey(tag.Index)) { CurrentTags[tag.Index] = definition; var item = new TagInstanceItem { Cache = Cache, Tag = tag }; currentTagsComboBox.Items.Add(item); currentTagsComboBox.SelectedItem = item; } else { for (var i = 0; i < currentTagsComboBox.Items.Count; i++) { var item = (TagInstanceItem)currentTagsComboBox.Items[i]; if (item.Tag.Index == tag.Index) { currentTagsComboBox.SelectedIndex = i; break; } } } LoadingTag = false; }
public static void GenerateControls(FlowLayoutPanel panel, Block block) { //Suspend panel.SuspendLayout(); //Loop foreach (Field field in block.Fields) { //Prepare Control control = null; //Handle switch (field.Type) { case FieldType.FieldExplanation: control = new ExplanationControl((ExplanationField)field); break; case FieldType.FieldBlock: control = new BlockControl((BlockField)field); break; case FieldType.FieldStruct: control = new StructControl((StructField)field); break; case FieldType.FieldString: case FieldType.FieldLongString: control = new StringControl(field); break; case FieldType.FieldTagReference: control = new TagReferenceControl(field); break; case FieldType.FieldStringId: case FieldType.FieldOldStringId: control = new StringIdControl(field); break; case FieldType.FieldCharInteger: case FieldType.FieldShortInteger: case FieldType.FieldLongInteger: case FieldType.FieldAngle: case FieldType.FieldTag: case FieldType.FieldReal: case FieldType.FieldRealFraction: control = new ValueControl(field); break; case FieldType.FieldCharEnum: case FieldType.FieldEnum: case FieldType.FieldLongEnum: control = new EnumControl(field); break; case FieldType.FieldLongFlags: control = new FlagsControl() { Field = field, Title = field.Name, Information = field.Information, Options = ((LongFlagsField)field).Options.Select(o => o.Name).ToArray(), Details = field.Details, Value = field.Value, ValueChanged = FlagsControl_ValueChanged }; break; case FieldType.FieldWordFlags: control = new FlagsControl() { Field = field, Title = field.Name, Information = field.Information, Options = ((WordFlagsField)field).Options.Select(o => o.Name).ToArray(), Details = field.Details, Value = field.Value, ValueChanged = FlagsControl_ValueChanged }; break; case FieldType.FieldByteFlags: control = new FlagsControl() { Field = field, Title = field.Name, Information = field.Information, Options = ((ByteFlagsField)field).Options.Select(o => o.Name).ToArray(), Details = field.Details, Value = field.Value, ValueChanged = FlagsControl_ValueChanged }; break; case FieldType.FieldShortBounds: control = new RangeControl() { Field = field, Title = field.Name, RangeValue = new string[] { ((ShortBounds)field.Value).Min.ToString(), ((ShortBounds)field.Value).Max.ToString() } }; break; case FieldType.FieldAngleBounds: case FieldType.FieldRealBounds: case FieldType.FieldRealFractionBounds: control = new RangeControl() { Field = field, Title = field.Name, RangeValue = new string[] { ((FloatBounds)field.Value).Min.ToString(), ((FloatBounds)field.Value).Max.ToString() } }; break; case FieldType.FieldPoint2D: control = new TwoTupleControl() { LabelA = "x", LabelB = "y", Field = field, Title = field.Name, TupleValue = new string[] { ((Point2)field.Value).X.ToString(), ((Point2)field.Value).Y.ToString() } }; break; case FieldType.FieldRealPoint2D: control = new TwoTupleControl() { LabelA = "x", LabelB = "y", Field = field, Title = field.Name, TupleValue = new string[] { ((Point2F)field.Value).X.ToString(), ((Point2F)field.Value).Y.ToString() } }; break; case FieldType.FieldRealPoint3D: control = new ThreeTupleControl() { LabelA = "x", LabelB = "y", LabelC = "z", Field = field, Title = field.Name, TupleValue = new string[] { ((Point3F)field.Value).X.ToString(), ((Point3F)field.Value).Y.ToString(), ((Point3F)field.Value).Z.ToString() } }; break; case FieldType.FieldRealVector2D: control = new TwoTupleControl() { LabelA = "i", LabelB = "j", Field = field, Title = field.Name, TupleValue = new string[] { ((Vector2)field.Value).I.ToString(), ((Vector2)field.Value).J.ToString() } }; break; case FieldType.FieldRealVector3D: control = new ThreeTupleControl() { LabelA = "i", LabelB = "j", LabelC = "k", Field = field, Title = field.Name, TupleValue = new string[] { ((Vector3)field.Value).I.ToString(), ((Vector3)field.Value).J.ToString(), ((Vector3)field.Value).K.ToString() } }; break; case FieldType.FieldRectangle2D: control = new FourTupleControl() { LabelA = "t", LabelB = "l", LabelC = "r", LabelD = "b", Field = field, Title = field.Name, TupleValue = new string[] { ((Rectangle2)field.Value).Top.ToString(), ((Rectangle2)field.Value).Left.ToString(), ((Rectangle2)field.Value).Right.ToString(), ((Rectangle2)field.Value).Bottom.ToString() } }; break; case FieldType.FieldRgbColor: control = new ThreeTupleControl() { LabelA = "r", LabelB = "g", LabelC = "b", Field = field, Title = field.Name, }; break; case FieldType.FieldArgbColor: control = new FourTupleControl() { LabelA = "a", LabelB = "r", LabelC = "g", LabelD = "b", Field = field, Title = field.Name, }; break; case FieldType.FieldRealRgbColor: control = new ThreeTupleControl() { LabelA = "r", LabelB = "g", LabelC = "b", Field = field, Title = field.Name, }; break; case FieldType.FieldRealArgbColor: control = new FourTupleControl() { LabelA = "a", LabelB = "r", LabelC = "g", LabelD = "b", Field = field, Title = field.Name, }; break; case FieldType.FieldRealHsvColor: control = new ThreeTupleControl() { LabelA = "h", LabelB = "s", LabelC = "v", Field = field, Title = field.Name, }; break; case FieldType.FieldRealAhsvColor: control = new FourTupleControl() { LabelA = "a", LabelB = "h", LabelC = "s", LabelD = "v", Field = field, Title = field.Name, }; break; case FieldType.FieldQuaternion: control = new FourTupleControl() { LabelA = "w", LabelB = "i", LabelC = "j", LabelD = "k", Field = field, Title = field.Name, TupleValue = new string[] { ((Quaternion)field.Value).W.ToString(), ((Quaternion)field.Value).I.ToString(), ((Quaternion)field.Value).J.ToString(), ((Quaternion)field.Value).K.ToString() } }; break; case FieldType.FieldEulerAngles2D: control = new TwoTupleControl() { LabelA = "i", LabelB = "j", Field = field, Title = field.Name, TupleValue = new string[] { ((Vector2)field.Value).I.ToString(), ((Vector2)field.Value).J.ToString() } }; break; case FieldType.FieldEulerAngles3D: control = new ThreeTupleControl() { LabelA = "i", LabelB = "j", LabelC = "k", Field = field, Title = field.Name, TupleValue = new string[] { ((Vector3)field.Value).I.ToString(), ((Vector3)field.Value).J.ToString(), ((Vector3)field.Value).K.ToString() } }; break; case FieldType.FieldRealPlane2D: control = new ThreeTupleControl() { LabelA = "i", LabelB = "j", LabelC = "d", Field = field, Title = field.Name, TupleValue = new string[] { ((Vector3)field.Value).I.ToString(), ((Vector3)field.Value).J.ToString(), ((Vector3)field.Value).K.ToString() } }; break; case FieldType.FieldRealPlane3D: control = new FourTupleControl() { LabelA = "i", LabelB = "j", LabelC = "k", LabelD = "d", Field = field, Title = field.Name, TupleValue = new string[] { ((Vector4)field.Value).I.ToString(), ((Vector4)field.Value).J.ToString(), ((Vector4)field.Value).K.ToString(), ((Vector4)field.Value).W.ToString() } }; break; default: control = new GuerillaControl() { Visible = false }; break; } //Check if (control != null) { panel.Controls.Add(control); } } //Resume panel.ResumeLayout(); }