예제 #1
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);
              }
        }
예제 #2
0
 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);
 }