コード例 #1
0
        public DesignPart Clone()
        {
            DesignPart retVal = new DesignPart(_options);

            retVal.Part2D = this.Part2D;                // this shouldn't be cloned, it's just a link to the source

            if (this.Part2D == null)
            {
                retVal.Part3D = BotConstructor.GetPartDesign(this.Part3D.GetDNA(), _options, this.Part3D.IsFinalModel);
            }
            else
            {
                retVal.Part3D = retVal.Part2D.GetNewDesignPart();
            }

            ModelVisual3D model = new ModelVisual3D();

            model.Content = retVal.Part3D.Model;
            retVal.Model  = model;

            retVal.Part3D.Position    = this.Part3D.Position;
            retVal.Part3D.Orientation = this.Part3D.Orientation;
            retVal.Part3D.Scale       = this.Part3D.Scale;

            if (this.GuideLines != null)                // this needs to be created after the position is set
            {
                retVal.CreateGuildLines();
            }

            return(retVal);
        }
コード例 #2
0
        public DesignPart Clone()
        {
            DesignPart retVal = new DesignPart(_options);
            retVal.Part2D = this.Part2D;		// this shouldn't be cloned, it's just a link to the source

            if(this.Part2D == null)
            {
                retVal.Part3D = BotConstructor.GetPartDesign(this.Part3D.GetDNA(), _options, this.Part3D.IsFinalModel);
            }
            else
            {
                retVal.Part3D = retVal.Part2D.GetNewDesignPart();
            }

            ModelVisual3D model = new ModelVisual3D();
            model.Content = retVal.Part3D.Model;
            retVal.Model = model;

            retVal.Part3D.Position = this.Part3D.Position;
            retVal.Part3D.Orientation = this.Part3D.Orientation;
            retVal.Part3D.Scale = this.Part3D.Scale;

            if (this.GuideLines != null)		// this needs to be created after the position is set
            {
                retVal.CreateGuildLines();
            }

            return retVal;
        }
コード例 #3
0
        /// <summary>
        /// NOTE: This constructor clones the part, makes sure the token is the same, and clears guide lines
        /// </summary>
        public UndoRedoAddRemove(bool isAdd, DesignPart part, int layerIndex)
            : base(part.Part3D.Token, layerIndex)
        {
            this.IsAdd = isAdd;

            this.Part = part.Clone();
            this.Part.Part3D.Token = this.Token;
            this.Part.GuideLines = null;
        }
コード例 #4
0
        /// <summary>
        /// NOTE: This constructor clones the part, makes sure the token is the same, and clears guide lines
        /// </summary>
        public UndoRedoAddRemove(bool isAdd, DesignPart part, int layerIndex)
            : base(part.Part3D.Token, layerIndex)
        {
            this.IsAdd = isAdd;

            this.Part = part.Clone();
            this.Part.Part3D.Token = this.Token;
            this.Part.GuideLines   = null;
        }
コード例 #5
0
        private DesignPart CreateDesignPart(ShipPartDNA dna)
        {
            #region Find ToolItem

            // Find the corresponding tool item
            List<PartToolItemBase> toolItems = _partToolItems.Where(o => o.PartType == dna.PartType).ToList();
            if (toolItems.Count == 0)
            {
                throw new ApplicationException("Couldn't find the tool item for \"" + dna.PartType + "\"");
            }

            // Narrow down to one
            PartToolItemBase toolItem = null;
            if (toolItems.Count == 1)		// if there's more than one, then it needs to be further filtered
            {
                toolItem = toolItems[0];
            }
            else if (dna.PartType == ConverterRadiationToEnergy.PARTTYPE)
            {
                #region ConverterRadiationToEnergy

                ConverterRadiationToEnergyDNA dnaCast = (ConverterRadiationToEnergyDNA)dna;

                List<PartToolItemBase> additionalFilter = toolItems.Where(o => ((ConverterRadiationToEnergyToolItem)o).Shape == dnaCast.Shape).ToList();
                if (additionalFilter.Count == 1)
                {
                    toolItem = additionalFilter[0];
                }

                #endregion
            }
            else if (dna.PartType == Thruster.PARTTYPE)
            {
                #region Thruster

                ThrusterDNA dnaCast = (ThrusterDNA)dna;
                if (dnaCast.ThrusterType == ThrusterType.Custom)
                {
                    // Make a new one with the dna's directions
                    toolItem = new ThrusterToolItem(editor1.Options, dnaCast.ThrusterDirections, "Custom");
                }
                else
                {
                    List<PartToolItemBase> additionalFilter = toolItems.Where(o => ((ThrusterToolItem)o).ThrusterType == dnaCast.ThrusterType).ToList();
                    if (additionalFilter.Count == 1)
                    {
                        toolItem = additionalFilter[0];
                    }
                }

                #endregion
            }
            else
            {
                throw new ApplicationException("Should have only found one tool item for this part type: " + dna.PartType);
            }

            if (toolItem == null)
            {
                throw new ApplicationException("Couldn't find the tool item for this part type: " + dna.PartType);
            }

            #endregion

            DesignPart retVal = new DesignPart(editor1.Options);
            retVal.Part2D = toolItem;

            retVal.Part3D = toolItem.GetNewDesignPart();
            retVal.Part3D.SetDNA(dna);

            ModelVisual3D visual = new ModelVisual3D();
            visual.Content = retVal.Part3D.Model;
            retVal.Model = visual;

            return retVal;
        }
コード例 #6
0
        public void Remove(DesignPart part)
        {
            int index = _parts.IndexOf(part);
            if (index < 0)
            {
                // This should never happen, but no need to complain
                return;
            }

            if (_parts.Count != _pointLights.Count)
            {
                throw new ApplicationException("The parts and lights should always be synced");
            }

            HideModifiers();

            // PointLight
            _viewport.Children.Remove(_pointLights[index]);
            _pointLights.RemoveAt(index);

            // Part
            //_parts[index].Part3D.TransformChanged -= new EventHandler(Part3D_TransformChanged);
            _parts[index].Part3D.IsSelected = false;
            _parts.RemoveAt(index);

            if (_parts.Count > 1)
            {
                _orientation = _options.DefaultOrientation;
            }

            if (_parts.Count > 0 && !this.IsLocked)
            {
                // Recalculate the modifiers
                ShowModifiers();
            }
        }
コード例 #7
0
        public void Add(DesignPart part)
        {
            HideModifiers();

            _parts.Add(part);

            part.Part3D.IsSelected = true;

            if (_parts.Count > 1)
            {
                _orientation = _options.DefaultOrientation;
            }

            //No need to listen to this event anymore, the transform changed is now called directly by this class's propert sets
            //part.Part3D.TransformChanged += new EventHandler(Part3D_TransformChanged);

            // Point Light
            PointLight pointLight = new PointLight();
            pointLight.Color = _options.EditorColors.SelectionLightColor;
            pointLight.QuadraticAttenuation = 1d;
            pointLight.Range = 10d;
            ModelVisual3D pointLightModel = new ModelVisual3D();
            pointLightModel.Content = pointLight;
            _viewport.Children.Add(pointLightModel);
            _pointLights.Add(pointLightModel);

            if (!this.IsLocked)
            {
                ShowModifiers();
            }

            // Move the visuals to be relative to the part
            TransformChanged();
        }
コード例 #8
0
        private static DesignPart CreateDesignPart(ShipPartDNA dna, EditorOptions options)
        {
            DesignPart retVal = new DesignPart(options)
            {
                Part2D = null,      // setting 2D to null will tell the editor that the part can't be resized or copied, only moved around
                Part3D = BotConstructor.GetPartDesign(dna, options, false),
            };

            ModelVisual3D visual = new ModelVisual3D();
            visual.Content = retVal.Part3D.Model;
            retVal.Model = visual;

            return retVal;
        }
コード例 #9
0
        private DesignPart CreateDesignPart(ShipPartDNA dna)
        {
            #region Find ToolItem

            // Find the corresponding tool item
            List <PartToolItemBase> toolItems = _partToolItems.Where(o => o.PartType == dna.PartType).ToList();
            if (toolItems.Count == 0)
            {
                throw new ApplicationException("Couldn't find the tool item for \"" + dna.PartType + "\"");
            }

            // Narrow down to one
            PartToolItemBase toolItem = null;
            if (toolItems.Count == 1)           // if there's more than one, then it needs to be further filtered
            {
                toolItem = toolItems[0];
            }
            else if (dna.PartType == ConverterRadiationToEnergy.PARTTYPE)
            {
                #region ConverterRadiationToEnergy

                ConverterRadiationToEnergyDNA dnaCast = (ConverterRadiationToEnergyDNA)dna;

                List <PartToolItemBase> additionalFilter = toolItems.Where(o => ((ConverterRadiationToEnergyToolItem)o).Shape == dnaCast.Shape).ToList();
                if (additionalFilter.Count == 1)
                {
                    toolItem = additionalFilter[0];
                }

                #endregion
            }
            else if (dna.PartType == Thruster.PARTTYPE)
            {
                #region Thruster

                ThrusterDNA dnaCast = (ThrusterDNA)dna;
                if (dnaCast.ThrusterType == ThrusterType.Custom)
                {
                    // Make a new one with the dna's directions
                    toolItem = new ThrusterToolItem(editor1.Options, dnaCast.ThrusterDirections, "Custom");
                }
                else
                {
                    List <PartToolItemBase> additionalFilter = toolItems.Where(o => ((ThrusterToolItem)o).ThrusterType == dnaCast.ThrusterType).ToList();
                    if (additionalFilter.Count == 1)
                    {
                        toolItem = additionalFilter[0];
                    }
                }

                #endregion
            }
            else
            {
                throw new ApplicationException("Should have only found one tool item for this part type: " + dna.PartType);
            }

            if (toolItem == null)
            {
                throw new ApplicationException("Couldn't find the tool item for this part type: " + dna.PartType);
            }

            #endregion

            DesignPart retVal = new DesignPart(editor1.Options);
            retVal.Part2D = toolItem;

            retVal.Part3D = toolItem.GetNewDesignPart();
            retVal.Part3D.SetDNA(dna);

            ModelVisual3D visual = new ModelVisual3D();
            visual.Content = retVal.Part3D.Model;
            retVal.Model   = visual;

            return(retVal);
        }
コード例 #10
0
        private void grdViewPort_Drop(object sender, DragEventArgs e)
        {
            try
            {
                if (e.Data.GetDataPresent(TabControlParts.DRAGDROP_FORMAT))
                {
                    // Mousemove already moved it, just leave it committed
                    if (_draggingDropObject != null && _draggingDropObject.HasAddedToViewport)      // just making sure
                    {
                        #region Store Part

                        DesignPart design = new DesignPart(_options)
                        {
                            Model = _draggingDropObject.Model,
                            Part2D = _draggingDropObject.Part2D,        // could be null
                            Part3D = _draggingDropObject.Part3D
                        };

                        while (_parts.Count <= _currentLayerIndex)
                        {
                            _parts.Add(new List<DesignPart>());
                        }

                        _parts[_currentLayerIndex].Add(design);

                        #endregion

                        // Store in undo/redo
                        AddNewUndoRedoItem(new UndoRedoAddRemove[] { new UndoRedoAddRemove(true, design, _currentLayerIndex) });
                    }

                    // Let the source know.  This is useful for cases when the tab control represents specific inventory (the part is either in inventory, or
                    // on this surface)
                    TabControlParts_DragItem dragItem = (TabControlParts_DragItem)e.Data.GetData(TabControlParts.DRAGDROP_FORMAT);
                    dragItem.Dropped();

                    _draggingDropObject = null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), _msgboxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #11
0
 private void RemovePartFromTabCtrl(DesignPart part)
 {
     TabControlPartsVM vm = tabCtrl.DataContext as TabControlPartsVM;
     if (vm != null)
     {
         vm.RemovePart(part.Part2D, part.Part3D);
     }
 }
コード例 #12
0
 private void AddPartToTabCtrl(DesignPart part)
 {
     TabControlPartsVM vm = tabCtrl.DataContext as TabControlPartsVM;
     if (vm != null)
     {
         vm.AddPart(part.Part2D, part.Part3D);
     }
 }