void AddObjectLink_Click(object xiSender, EventArgs xiArgs) { FlatChunk.ObjectEntry lObject = new FlatChunk.ObjectEntry(); lObject.ObjtType = 1; lObject.OriginPosition = new Short3Coord(); lObject.OriginPosition.X = mSubject.OriginPosition.X; lObject.OriginPosition.Y = mSubject.OriginPosition.Y; lObject.OriginPosition.Z = mSubject.OriginPosition.Z; lObject.RotationVector = new Short3Coord(); lObject.RotationVector.X = 0; lObject.RotationVector.Y = 0; lObject.RotationVector.Z = 0; lObject.IsSolid = true; lObject.FlagUnknown = true; lObject.ShortUnknown = 0; AddObjectToTable(lObject); }
void Viewer3DRenderingSurface_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Middle) { Mesh lMesh = mRenderer.Pick(e.X, e.Y); if (lMesh != null) { if (lMesh is OwnedMesh && ((OwnedMesh)lMesh).Owner is Chunk) { OwnedMesh om = (OwnedMesh)lMesh; Chunk c = (Chunk)om.Owner; MessageBox.Show(string.Format("Clicked on {0} with name {1}", c.GetType().Name, c.Name)); } else if (lMesh is OwnedMesh && ((OwnedMesh)lMesh).Owner is FlatChunk.ObjectEntry) { FlatChunk.ObjectEntry oe = (FlatChunk.ObjectEntry)((OwnedMesh)lMesh).Owner; MessageBox.Show(string.Format("Clicked on object type {0} at {1}, rotation {2}", oe.ObjtType, oe.OriginPosition, oe.RotationVector)); } else if (lMesh is OwnedMesh && ((OwnedMesh)lMesh).Owner is FlatChunk.WeaponEntry) { FlatChunk.WeaponEntry we = (FlatChunk.WeaponEntry)((OwnedMesh)lMesh).Owner; MessageBox.Show(string.Format("Clicked on weapon type {0} at {1}", we.WeaponType, we.OriginPosition)); } else { lMesh.RenderMode = lMesh.RenderMode == RenderMode.Filled ? RenderMode.Textured : RenderMode.Filled; InvalidateViewer(); } } } else { mMainForm.Viewer3DRenderingSurface.Capture = true; mLastMouseDown = e.Location; mDraggingButton = e.Button; mDraggingView = true; } }
private void AddObjectToTable(FlatChunk.ObjectEntry xiObject) { Panel.ObjectsTable.RowStyles.Add(new RowStyle(SizeType.AutoSize)); TextBox lTypeBox = new TextBox(); lTypeBox.Text = xiObject.ObjtType.ToString(); lTypeBox.Width = 60; Panel.ObjectsTable.Controls.Add(lTypeBox); TextBox lXBox = new TextBox(); lXBox.Text = xiObject.OriginPosition.X.ToString(); lXBox.Width = 60; Panel.ObjectsTable.Controls.Add(lXBox); TextBox lYBox = new TextBox(); lYBox.Text = xiObject.OriginPosition.Y.ToString(); lYBox.Width = 60; Panel.ObjectsTable.Controls.Add(lYBox); TextBox lZBox = new TextBox(); lZBox.Text = xiObject.OriginPosition.Z.ToString(); lZBox.Width = 60; Panel.ObjectsTable.Controls.Add(lZBox); TextBox lRXBox = new TextBox(); lRXBox.Text = xiObject.RotationVector.X.ToString(); lRXBox.Width = 60; Panel.ObjectsTable.Controls.Add(lRXBox); TextBox lRYBox = new TextBox(); lRYBox.Text = xiObject.RotationVector.Y.ToString(); lRYBox.Width = 60; Panel.ObjectsTable.Controls.Add(lRYBox); TextBox lRZBox = new TextBox(); lRZBox.Text = xiObject.RotationVector.Z.ToString(); lRZBox.Width = 60; Panel.ObjectsTable.Controls.Add(lRZBox); CheckBox lSolidBox = new CheckBox(); lSolidBox.Checked = xiObject.IsSolid; lSolidBox.Text = ""; lSolidBox.AutoSize = true; Panel.ObjectsTable.Controls.Add(lSolidBox); CheckBox lUnkBox1 = new CheckBox(); lUnkBox1.Checked = xiObject.FlagUnknown; lUnkBox1.Text = ""; lUnkBox1.AutoSize = true; Panel.ObjectsTable.Controls.Add(lUnkBox1); TextBox lUnkBox2 = new TextBox(); lUnkBox2.Text = xiObject.ShortUnknown.ToString(); lUnkBox2.Width = 60; lUnkBox2.AutoSize = true; Panel.ObjectsTable.Controls.Add(lUnkBox2); LinkLabel lDeleteLink = new LinkLabel(); lDeleteLink.Text = "Delete"; lDeleteLink.Click += new EventHandler(delegate(object xiSender, System.EventArgs xiArgs) { Panel.ObjectsTable.SuspendLayout(); Panel.ObjectsTable.RowStyles.RemoveAt(1); Panel.ObjectsTable.Controls.Remove(lTypeBox); Panel.ObjectsTable.Controls.Remove(lXBox); Panel.ObjectsTable.Controls.Remove(lYBox); Panel.ObjectsTable.Controls.Remove(lZBox); Panel.ObjectsTable.Controls.Remove(lRXBox); Panel.ObjectsTable.Controls.Remove(lRYBox); Panel.ObjectsTable.Controls.Remove(lRZBox); Panel.ObjectsTable.Controls.Remove(lSolidBox); Panel.ObjectsTable.Controls.Remove(lUnkBox1); Panel.ObjectsTable.Controls.Remove(lUnkBox2); Panel.ObjectsTable.Controls.Remove(lDeleteLink); Panel.ObjectsTable.ResumeLayout(); }); Panel.ObjectsTable.Controls.Add(lDeleteLink); }
public void CommitButton_Click(object xiSender, EventArgs xiArgs) { if (mSubject == null) { MessageBox.Show("Can't do that -- mSubject is null!"); return; } Level lLevel = mMainForm.CurrentLevel; //======================================================================= // Warn about changing flags //======================================================================= if (mSubject.HasMetaData != Panel.HasMetaDataCheckBox.Checked && !Panel.HasMetaDataCheckBox.Checked) { if (MessageBox.Show("You are about to remove all metadata from this flat, eg bump settings. Are you sure?", "Removing Meta Data", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } } if (mSubject.FlgB != Panel.FlagBCheckBox.Checked || mSubject.FlgC != Panel.FlagCCheckBox.Checked || mSubject.FlgE != Panel.FlagECheckBox.Checked) { if (MessageBox.Show("Changing flags may (or may not) be rather a dangerous thing to do. " + (mSubject.HasMetaData != Panel.HasMetaDataCheckBox.Checked && !Panel.HasMetaDataCheckBox.Checked ? "In particular, unsetting Flag A will delete all you tex meta data e.g. bump settings. " : "") + "Are you sure you want to do this?", "Changing Flat Flags", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } } //======================================================================= // Offer to be helpful if changing the origin (should really do this // for rotation too...) //======================================================================= short lNewX = short.Parse(Panel.OriginXTextBox.Text); short lNewY = short.Parse(Panel.OriginYTextBox.Text); short lNewZ = short.Parse(Panel.OriginZTextBox.Text); short lDeltaX = 0; short lDeltaY = 0; short lDeltaZ = 0; if ((mSubject.OriginPosition.X != lNewX || mSubject.OriginPosition.Y != lNewY || mSubject.OriginPosition.Z != lNewZ) && (Panel.WeaponsTable.Controls.Count > 6 || Panel.ObjectsTable.Controls.Count > 11)) { if (MessageBox.Show("You are moving the flat. Do you want to move all the objects and weapons by the same amount?", "MMEd", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { lDeltaX = (short)(lNewX - mSubject.OriginPosition.X); lDeltaY = (short)(lNewY - mSubject.OriginPosition.Y); lDeltaZ = (short)(lNewZ - mSubject.OriginPosition.Z); } } //======================================================================= // Save simple values //======================================================================= mSubject.DeclaredName = Panel.NameTextBox.Text; mSubject.OriginPosition.X = lNewX; mSubject.OriginPosition.Y = lNewY; mSubject.OriginPosition.Z = lNewZ; mSubject.RotationVector.X = short.Parse(Panel.RotationXTextBox.Text); mSubject.RotationVector.Y = short.Parse(Panel.RotationYTextBox.Text); mSubject.RotationVector.Z = short.Parse(Panel.RotationZTextBox.Text); mSubject.ScaleX = short.Parse(Panel.ScaleXTextBox.Text); mSubject.ScaleY = short.Parse(Panel.ScaleYTextBox.Text); mSubject.FlgB = Panel.FlagBCheckBox.Checked; mSubject.FlgC = Panel.FlagCCheckBox.Checked; mSubject.Visible = Panel.VisibleCheckBox.Checked; mSubject.FlgE = Panel.FlagECheckBox.Checked; //======================================================================= // Change width, height and HasMetaData if appropriate //======================================================================= short lNewWidth = short.Parse(Panel.WidthTextBox.Text); short lNewHeight = short.Parse(Panel.HeightTextBox.Text); FlatChunk.eResizeOptions lResizeOptions = FlatChunk.eResizeOptions.Default; int lSizeIncrease; if (mSubject.Width != lNewWidth) { if (MessageBox.Show("You are changing the width of the flat. Do you want to fix the left-hand side of the flat? (Alternative is right-hand side)", "MMEd", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { lResizeOptions |= FlatChunk.eResizeOptions.KeepRight; } } if (mSubject.Height != lNewHeight) { if (MessageBox.Show("You are changing the height of the flat. Do you want to fix the top side of the flat? (Alternative is bottom side)", "MMEd", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { lResizeOptions |= FlatChunk.eResizeOptions.KeepBottom; } } if (mSubject.Width != lNewWidth || mSubject.Height != lNewHeight || mSubject.HasMetaData != Panel.HasMetaDataCheckBox.Checked) { lSizeIncrease = mSubject.Resize(Panel.HasMetaDataCheckBox.Checked, lNewWidth, lNewHeight, lResizeOptions); lLevel.SHET.TrailingZeroByteCount -= lSizeIncrease; } //======================================================================= // Save weapons //======================================================================= List <FlatChunk.WeaponEntry> lWeapons = new List <FlatChunk.WeaponEntry>(); for (int ii = 6; ii < Panel.WeaponsTable.Controls.Count; ii += 6) { FlatChunk.WeaponEntry lWeapon = new FlatChunk.WeaponEntry(); lWeapon.WeaponType = (eWeaponType)Enum.Parse(typeof(eWeaponType), ((ComboBox)Panel.WeaponsTable.Controls[ii]).Text); lWeapon.ShortUnknown = short.Parse(((TextBox)Panel.WeaponsTable.Controls[ii + 1]).Text); lWeapon.OriginPosition = new Short3Coord(); lWeapon.OriginPosition.X = (short)(short.Parse(((TextBox)Panel.WeaponsTable.Controls[ii + 2]).Text) + lDeltaX); lWeapon.OriginPosition.Y = (short)(short.Parse(((TextBox)Panel.WeaponsTable.Controls[ii + 3]).Text) + lDeltaY); lWeapon.OriginPosition.Z = (short)(short.Parse(((TextBox)Panel.WeaponsTable.Controls[ii + 4]).Text) + lDeltaZ); lWeapons.Add(lWeapon); } lSizeIncrease = mSubject.ReplaceWeapons(lWeapons); lLevel.SHET.TrailingZeroByteCount -= lSizeIncrease; //======================================================================= // Save objects //======================================================================= List <FlatChunk.ObjectEntry> lObjects = new List <FlatChunk.ObjectEntry>(); for (int ii = 11; ii < Panel.ObjectsTable.Controls.Count; ii += 11) { FlatChunk.ObjectEntry lObject = new FlatChunk.ObjectEntry(); lObject.ObjtType = short.Parse(((TextBox)Panel.ObjectsTable.Controls[ii]).Text); lObject.OriginPosition = new Short3Coord(); lObject.OriginPosition.X = (short)(short.Parse(((TextBox)Panel.ObjectsTable.Controls[ii + 1]).Text) + lDeltaX); lObject.OriginPosition.Y = (short)(short.Parse(((TextBox)Panel.ObjectsTable.Controls[ii + 2]).Text) + lDeltaY); lObject.OriginPosition.Z = (short)(short.Parse(((TextBox)Panel.ObjectsTable.Controls[ii + 3]).Text) + lDeltaZ); lObject.RotationVector = new Short3Coord(); lObject.RotationVector.X = short.Parse(((TextBox)Panel.ObjectsTable.Controls[ii + 4]).Text); lObject.RotationVector.Y = short.Parse(((TextBox)Panel.ObjectsTable.Controls[ii + 5]).Text); lObject.RotationVector.Z = short.Parse(((TextBox)Panel.ObjectsTable.Controls[ii + 6]).Text); lObject.IsSolid = ((CheckBox)Panel.ObjectsTable.Controls[ii + 7]).Checked; lObject.FlagUnknown = ((CheckBox)Panel.ObjectsTable.Controls[ii + 8]).Checked; lObject.ShortUnknown = short.Parse(((TextBox)Panel.ObjectsTable.Controls[ii + 9]).Text); lObjects.Add(lObject); } lSizeIncrease = mSubject.ReplaceObjects(lObjects); lLevel.SHET.TrailingZeroByteCount -= lSizeIncrease; //======================================================================= // Warn if we've run out of space //======================================================================= if (lLevel.SHET.TrailingZeroByteCount < 0) { MessageBox.Show("WARNING: You do not currently have enough spare space at the end of your level file. " + string.Format("You will need to free up {0} bytes from the file before you can save to disk.", -lLevel.SHET.TrailingZeroByteCount), "MMEd", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }