Exemplo n.º 1
0
 void AddWeaponLink_Click(object xiSender, EventArgs xiArgs)
 {
     FlatChunk.WeaponEntry lWeapon = new FlatChunk.WeaponEntry();
     lWeapon.WeaponType       = eWeaponType.Mines;
     lWeapon.ShortUnknown     = 1;
     lWeapon.OriginPosition   = new Short3Coord();
     lWeapon.OriginPosition.X = mSubject.OriginPosition.X;
     lWeapon.OriginPosition.Y = mSubject.OriginPosition.Y;
     lWeapon.OriginPosition.Z = mSubject.OriginPosition.Z;
     AddWeaponToTable(lWeapon);
 }
Exemplo n.º 2
0
        private void AddWeaponToTable(FlatChunk.WeaponEntry xiWeapon)
        {
            Panel.WeaponsTable.RowStyles.Add(new RowStyle(SizeType.AutoSize));

            ComboBox lWeaponTypeBox = new ComboBox();

            lWeaponTypeBox.Items.AddRange(Enum.GetNames(typeof(eWeaponType)));
            lWeaponTypeBox.Text  = xiWeapon.WeaponType.ToString();
            lWeaponTypeBox.Width = 120;
            Panel.WeaponsTable.Controls.Add(lWeaponTypeBox);

            TextBox lUnknownBox = new TextBox();

            lUnknownBox.Text  = xiWeapon.ShortUnknown.ToString();
            lUnknownBox.Width = 60;
            Panel.WeaponsTable.Controls.Add(lUnknownBox);

            TextBox lXBox = new TextBox();

            lXBox.Text  = xiWeapon.OriginPosition.X.ToString();
            lXBox.Width = 60;
            Panel.WeaponsTable.Controls.Add(lXBox);

            TextBox lYBox = new TextBox();

            lYBox.Text  = xiWeapon.OriginPosition.Y.ToString();
            lYBox.Width = 60;
            Panel.WeaponsTable.Controls.Add(lYBox);

            TextBox lZBox = new TextBox();

            lZBox.Text  = xiWeapon.OriginPosition.Z.ToString();
            lZBox.Width = 60;
            Panel.WeaponsTable.Controls.Add(lZBox);

            LinkLabel lDeleteLink = new LinkLabel();

            lDeleteLink.Text   = "Delete";
            lDeleteLink.Click += new EventHandler(delegate(object xiSender, System.EventArgs xiArgs)
            {
                Panel.WeaponsTable.SuspendLayout();
                Panel.WeaponsTable.RowStyles.RemoveAt(1);
                Panel.WeaponsTable.Controls.Remove(lWeaponTypeBox);
                Panel.WeaponsTable.Controls.Remove(lUnknownBox);
                Panel.WeaponsTable.Controls.Remove(lXBox);
                Panel.WeaponsTable.Controls.Remove(lYBox);
                Panel.WeaponsTable.Controls.Remove(lZBox);
                Panel.WeaponsTable.Controls.Remove(lDeleteLink);
                Panel.WeaponsTable.ResumeLayout();
            });
            Panel.WeaponsTable.Controls.Add(lDeleteLink);
        }
Exemplo n.º 3
0
 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;
     }
 }
Exemplo n.º 4
0
        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);
            }
        }