Esempio n. 1
0
        /// <summary>
        /// Opens prop palette from given file.
        /// </summary>
        /// <param name="filePath"></param>
        private void Open(string filePath)
        {
            var ext = Path.GetExtension(filePath);

            if (ext != ".plt")
            {
                MessageBox.Show($"Unknown file extension '{ext.TrimStart('.')}'", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                PropPalette.Clear();
                PropPalette.Load(filePath);

                this.RefreshPropList();

                _openFilePath = filePath;

                this.SetChanges(false);
                this.SelectProp(null);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Opening file failed. Error: '{ex.Message}'", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Saves open prop palette to given file.
 /// </summary>
 /// <param name="filePath"></param>
 private void Save(string filePath)
 {
     try
     {
         PropPalette.Save(filePath);
     }
     catch (Exception ex)
     {
         MessageBox.Show($"Saving file failed. Error: '{ex.Message}'", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Reloads prop list.
        /// </summary>
        private void RefreshPropList()
        {
            var props = PropPalette.GetEntries().OrderBy(a => a.Id);

            this.LstProps.BeginUpdate();

            this.LstProps.Items.Clear();
            foreach (var prop in props)
            {
                var lvi = new ListViewItem();
                lvi.Text = string.Format("{0}", prop.Id);
                lvi.SubItems.Add(prop.State);
                lvi.Tag = prop;

                this.LstProps.Items.Add(lvi);
            }

            this.LstProps.EndUpdate();
        }
Esempio n. 4
0
        /// <summary>
        /// Creates prop based on data.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        private Prop GenerateBaseProp(int id, float x, float y, float z)
        {
            Prop prop = null;

            if (PropPalette.TryGetEntry(id, out var pltProp))
            {
                prop = pltProp.Copy();
            }
            else
            {
                prop = new Prop();
            }

            prop.Id = id;
            prop.MoveTo(x, y, z);

            prop.LoadData();

            return(prop);
        }
Esempio n. 5
0
        /// <summary>
        /// Called when a key was pressed on the prop list.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LstProps_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Delete)
            {
                return;
            }

            if (!this.TryGetSelectedProp(out var prop))
            {
                MessageBox.Show("No prop selected.", Title, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (!PropPalette.Remove(prop.Id))
            {
                MessageBox.Show("Failed to remove prop, not found in file.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var selectedIndex = this.LstProps.SelectedIndices[0];

            if (this.LstProps.Items.Count > 0)
            {
                this.LstProps.BeginUpdate();
                this.LstProps.Items.RemoveAt(selectedIndex);

                selectedIndex = Math.Max(0, Math.Min(this.LstProps.Items.Count - 1, selectedIndex));

                this.LstProps.SelectedIndices.Clear();
                this.LstProps.SelectedIndices.Add(selectedIndex);
                this.LstProps.Items[selectedIndex].EnsureVisible();

                this.LstProps.EndUpdate();
            }

            this.SetChanges(true);
        }
Esempio n. 6
0
        /// <summary>
        /// Saves or adds prop based on the form data.
        /// </summary>
        /// <param name="addNew"></param>
        private void HandlePropForm(bool addNew)
        {
            var propName      = this.TxtPropName.Text.Trim();
            var propTitle     = this.TxtPropTitle.Text.Trim();
            var propState     = this.TxtPropState.Text.Trim();
            var isCollision   = this.ChkPropCollision.Checked;
            var fixedAltitude = this.ChkPropFixedAltitude.Checked;

            if (!int.TryParse(this.TxtPropId.Text, out var propId))
            {
                MessageBox.Show("Invalid id.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!float.TryParse(this.TxtPropScale.Text, out var propScale))
            {
                MessageBox.Show("Invalid scale.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!float.TryParse(this.TxtPropRotation.Text, out var propRotation))
            {
                MessageBox.Show("Invalid rotation.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!uint.TryParse(this.TxtPropColorOverride.Text.Replace("0x", ""), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var propColorOverride))
            {
                MessageBox.Show("Invalid color override.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!uint.TryParse(this.TxtPropColor1.Text.Replace("0x", ""), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var propColor1))
            {
                MessageBox.Show("Invalid color 1.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!uint.TryParse(this.TxtPropColor2.Text.Replace("0x", ""), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var propColor2))
            {
                MessageBox.Show("Invalid color 2.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!uint.TryParse(this.TxtPropColor3.Text.Replace("0x", ""), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var propColor3))
            {
                MessageBox.Show("Invalid color 3.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!uint.TryParse(this.TxtPropColor4.Text.Replace("0x", ""), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var propColor4))
            {
                MessageBox.Show("Invalid color 4.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!uint.TryParse(this.TxtPropColor5.Text.Replace("0x", ""), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var propColor5))
            {
                MessageBox.Show("Invalid color 5.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!uint.TryParse(this.TxtPropColor6.Text.Replace("0x", ""), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var propColor6))
            {
                MessageBox.Show("Invalid color 6.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!uint.TryParse(this.TxtPropColor7.Text.Replace("0x", ""), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var propColor7))
            {
                MessageBox.Show("Invalid color 7.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!uint.TryParse(this.TxtPropColor8.Text.Replace("0x", ""), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var propColor8))
            {
                MessageBox.Show("Invalid color 8.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!uint.TryParse(this.TxtPropColor9.Text.Replace("0x", ""), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var propColor9))
            {
                MessageBox.Show("Invalid color 9.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var bottomLeftSplit = this.TxtPropBottomLeft.Text.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            if (bottomLeftSplit.Length < 3)
            {
                MessageBox.Show("Invalid bottom left coordinates, expected format: X;Y;Z.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!float.TryParse(bottomLeftSplit[0], out var bottomLeftX))
            {
                MessageBox.Show("Invalid bottom left X coordinate.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!float.TryParse(bottomLeftSplit[1], out var bottomLeftY))
            {
                MessageBox.Show("Invalid bottom left Y coordinate.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!float.TryParse(bottomLeftSplit[2], out var bottomLeftZ))
            {
                MessageBox.Show("Invalid bottom left Z coordinate.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var topRightSplit = this.TxtPropTopRight.Text.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            if (topRightSplit.Length < 3)
            {
                MessageBox.Show("Invalid top right coordinates, expected format: X;Y;Z.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!float.TryParse(topRightSplit[0], out var topRightX))
            {
                MessageBox.Show("Invalid top right X coordinate.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!float.TryParse(topRightSplit[1], out var topRightY))
            {
                MessageBox.Show("Invalid top right Y coordinate.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!float.TryParse(topRightSplit[2], out var topRightZ))
            {
                MessageBox.Show("Invalid top right Z coordinate.", Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var prop = _workProp;

            prop.Id            = propId;
            prop.Name          = propName;
            prop.Title         = propTitle;
            prop.State         = propState;
            prop.Scale         = propScale;
            prop.Rotation      = propRotation;
            prop.BottomLeft    = new Vector3F(bottomLeftX, bottomLeftY, bottomLeftZ);
            prop.TopRight      = new Vector3F(topRightX, topRightY, topRightZ);
            prop.ColorOverride = Color.FromArgb((int)propColorOverride);
            prop.Colors[0]     = Color.FromArgb((int)propColor1);
            prop.Colors[1]     = Color.FromArgb((int)propColor2);
            prop.Colors[2]     = Color.FromArgb((int)propColor3);
            prop.Colors[3]     = Color.FromArgb((int)propColor4);
            prop.Colors[4]     = Color.FromArgb((int)propColor5);
            prop.Colors[5]     = Color.FromArgb((int)propColor6);
            prop.Colors[6]     = Color.FromArgb((int)propColor7);
            prop.Colors[7]     = Color.FromArgb((int)propColor8);
            prop.Colors[8]     = Color.FromArgb((int)propColor9);
            prop.IsCollision   = this.ChkPropCollision.Checked;
            prop.FixedAltitude = this.ChkPropFixedAltitude.Checked;

            if (addNew)
            {
                var newIndex = GetNextPropIndex();
                prop.EntityId = 0x000A_0000_0400_0000 | (ulong)newIndex;

                PropPalette.Add(prop.Copy());

                this.LstProps.BeginUpdate();

                var lvi = new ListViewItem();
                lvi.Text = string.Format("{0}", prop.Id);
                lvi.SubItems.Add(prop.State);
                lvi.Tag = prop;

                this.LstProps.Items.Add(lvi);

                lvi.Selected = true;
                lvi.EnsureVisible();

                this.LstProps.EndUpdate();
            }
            else
            {
                var selectedItem = this.LstProps.SelectedItems[0];
                var listProp     = selectedItem.Tag as Prop;

                listProp.Id            = prop.Id;
                listProp.Name          = prop.Name;
                listProp.Title         = prop.Title;
                listProp.State         = prop.State;
                listProp.Scale         = prop.Scale;
                listProp.Rotation      = prop.Rotation;
                listProp.BottomLeft    = prop.BottomLeft;
                listProp.TopRight      = prop.TopRight;
                listProp.ColorOverride = prop.ColorOverride;
                for (var i = 0; i < 9; ++i)
                {
                    listProp.Colors[i] = prop.Colors[i];
                }
                listProp.IsCollision   = prop.IsCollision;
                listProp.FixedAltitude = prop.FixedAltitude;
                listProp.Shapes.Clear();
                listProp.Shapes.AddRange(prop.Shapes);

                selectedItem.SubItems[0].Text = listProp.Id.ToString();
                selectedItem.SubItems[1].Text = listProp.State;
            }
        }