private void ManagePartSelectedEvent(IPartScript OldPart, IPartScript NewPart)
 {
     if (Input.GetKey(KeyCode.Tab))
     {
         if (OldPart != null && !_selectedParts.Contains(OldPart))
         {
             _selectedParts.Add(OldPart);
         }
         if (!_selectedParts.Contains(NewPart))
         {
             _selectedParts.Add(NewPart);
             Debug.Log("Added Part to selection: " + NewPart);
         }
         else
         {
             _partHighlighter.RemovePartHighlight(NewPart);
             _selectedParts.Remove(NewPart);
             Debug.Log("Removed Part from selection: " + NewPart);
         }
         SelectLastPart();
     }
     else
     {
         DeselectAllParts();
     }
 }
示例#2
0
        public void PaintPart(IPartScript part, bool flag, int MaterialLevel, int MaterialID, bool paintSymmetricParts)
        {
            if (MaterialLevel == -1)
            {
                for (int i = 0; i < part.Data.MaterialIds.Count; i++)
                {
                    if (part.Data.MaterialIds[i] != MaterialID)
                    {
                        part.PartMaterialScript.SetMaterial(MaterialID, i); flag = true;
                    }
                }
            }
            else if (part.Data.MaterialIds[MaterialLevel] != MaterialID)
            {
                part.PartMaterialScript.SetMaterial(MaterialID, MaterialLevel); flag = true;
            }

            if (paintSymmetricParts)
            {
                foreach (IPartScript item in Symmetry.EnumerateSymmetricPartScripts(part))
                {
                    PaintPart(item, flag, MaterialLevel, MaterialID, false);
                }
            }

            if (flag)
            {
                foreach (PartModifierData modifier in part.Data.Modifiers)
                {
                    ((IDesignerPartModifierData)modifier).DesignerPartProperties.OnPartMaterialsChanged();
                }
            }
        }
示例#3
0
 void SelectedPartChanged(IPartScript oldPart, IPartScript newPart)
 {
     try
     {
         buttonScript.SetButtonEnabled(newPart != null);
     }
     catch (NullReferenceException) { }
 }
示例#4
0
 public void Initialize(
     CameraVantageScript cameraScript,
     IPartScript dockingPortScript)
 {
     this.cameraVantage = cameraScript;
     this.dockingPort   = dockingPortScript;
     this.firstUpdate   = true;
 }
示例#5
0
        public XElement GetXML()
        {
            part = Game.Instance.Designer.SelectedPart;
            var res = part.Data.GenerateXml(part.CraftScript.Transform, false);

            res.SetAttributeValue("activated", part.Data.Activated); // temp fix for activated bug.
            backupXml = XElement.Parse(res.ToString(SaveOptions.DisableFormatting));
            return(res);
        }
示例#6
0
 public void ConsumePower(float DeltaTime, IPartScript part)
 {
     if (!_battery.IsEmpty)
     {
         _battery.RemoveFuel(PowerConsumption * DeltaTime);
     }
     else
     {
         part.Data.Activated = false;
     }
 }
示例#7
0
 public void OnPartSelected(IPartScript part)
 {
     _SelectorManager.RequestPartSelectionEvent = false;
     if (_ToolState == null)
     {
         return;
     }
     if (_ToolState.Type == PartToolStateTypes.Align)
     {
         AlignPartsTo(part);
     }
 }
示例#8
0
 public void OnPartSelected(IPartScript part)
 {
     _selectorManager.requestPartSelectionEvent = false;
     if (_toolState == null)
     {
         return;
     }
     if (_toolState.Type == PartToolStateTypes.AlignPosition)
     {
         AlignPartsPositionTo(part);
     }
     if (_toolState.Type == PartToolStateTypes.AlignRotation)
     {
         AlignPartsRotationTo(part);
     }
 }
        public void OnPartPainted(IPartScript PaintedPart)
        {
            if (_selectedParts.Count > 0 && PaintedPart != null && _selectedParts.Contains(PaintedPart))
            {
                bool flag          = false;
                int  MaterialLevel = designer.PaintTool.MaterialLevel;
                int  MaterialID    = designer.PaintTool.MaterialId;

                foreach (IPartScript part in _selectedParts)
                {
                    if (part.Data.Id != PaintedPart.Data.Id)
                    {
                        _partTools.PaintPart(part, flag, MaterialLevel, MaterialID, true);
                    }
                }
            }
        }
        public void OnSelectedPartChanged(IPartScript OldPart, IPartScript NewPart)
        {
            //Debug.Log ("Selected Part Changed: " + NewPart?.Data.PartType.Id);
            if (!ignoreNextPartSelectionEvent)
            {
                if (NewPart != null)
                {
                    if (!requestPartSelectionEvent)
                    {
                        if (designer.AllowPartSelection && ModSettings.Instance.DevMode)
                        {
                            ManagePartSelectedEvent(OldPart, NewPart);
                        }
                    }
                    else
                    {
                        _mod.partTools.OnPartSelected(NewPart);
                        SelectLastPart();
                    }
                }
            }
            else
            {
                ignoreNextPartSelectionEvent = false;
            }

            if (NewPart != null)
            {
                if (!_selectedParts.Contains(NewPart))
                {
                    _selectedParts.Add(NewPart);
                }

                if (!ModSettings.Instance.DevMode)
                {
                    return;
                }

                _prevPartState = _selectedPart.Data.GenerateXml(designer.CraftScript.Transform, optimizeXml: false);
                Debug.Log(NewPart.Data.GenerateXml(designer.CraftScript.Transform, optimizeXml: false));
            }
            else
            {
                DeselectAllParts();
            }
        }
 private void ManagePartSelectedEvent(IPartScript OldPart, IPartScript NewPart)
 {
     if (NewPart != null && TabPressed)
     {
         if (OldPart != null && !_SelectedParts.Contains(OldPart))
         {
             _SelectedParts.Add(OldPart);
         }
         if (!_SelectedParts.Contains(NewPart))
         {
             if (_SelectedPartsAreSame && _SelectedParts.Count > 0 && NewPart.Data.PartType.Id != _SelectedParts.Last().Data.PartType.Id)
             {
                 _SelectedPartsAreSame = false;
             }
             _SelectedParts.Add(NewPart);
             Debug.Log("Added Part to selection: " + NewPart);
         }
         else
         {
             _SelectedParts.Remove(NewPart);
             Debug.Log("Removed Part from selection: " + NewPart);
             if (!_SelectedPartsAreSame && _SelectedParts.Count > 0)
             {
                 _SelectedPartsAreSame = true;
                 foreach (IPartScript part in _SelectedParts)
                 {
                     if (part.Data.PartType.Id != _SelectedParts.Last().Data.PartType.Id)
                     {
                         _SelectedPartsAreSame = false; break;
                     }
                 }
             }
         }
         if (_SelectedPart != _SelectedParts.Last())
         {
             _Designer.SelectPart(_SelectedParts.Last(), null, false);
             IgnoreNextPartSelectionEvent = true;
         }
         //_PrevPartState = new PartState (_SelectedPart.Data);
         _PrevPartState = ClonePartData(_SelectedPart.Data);
     }
     else
     {
         DeselectAllParts();
     }
 }
示例#12
0
        private void AlignPartsRotationTo(IPartScript part)
        {
            if (_selectorManager.selectedParts.Count > 0)
            {
                if (_toolState != null)
                {
                    foreach (IPartScript selectedPart in _selectorManager.selectedParts)
                    {
                        Vector3 selectedPartRot = selectedPart.Transform.rotation.eulerAngles;
                        Vector3 newRotation;
                        float   DeltaRotation;

                        if (_toolState.Axis == 'X')
                        {
                            DeltaRotation = part.Transform.rotation.eulerAngles.x - selectedPartRot.x;
                            newRotation   = new Vector3(selectedPartRot.x + DeltaRotation, selectedPartRot.y, selectedPartRot.z);
                        }
                        else if (_toolState.Axis == 'Y')
                        {
                            DeltaRotation = part.Transform.rotation.eulerAngles.y - selectedPartRot.y;
                            newRotation   = new Vector3(selectedPartRot.x, selectedPartRot.y + DeltaRotation, selectedPartRot.z);
                        }
                        else
                        {
                            DeltaRotation = part.Transform.rotation.eulerAngles.z - selectedPartRot.z;
                            newRotation   = new Vector3(selectedPartRot.x, selectedPartRot.y, selectedPartRot.z + DeltaRotation);
                        }
                        selectedPart.Transform.rotation = Quaternion.Euler(newRotation);
                    }
                    _designer.DesignerUi.ShowMessage("Parts Rotation Aligned");
                }
                else
                {
                    _designer.DesignerUi.ShowMessage(_mod.errorColor + "Part Alignment failed : ToolState Changed");
                }
            }
            else
            {
                _designer.DesignerUi.ShowMessage(_mod.errorColor = "Part Alignment failed : Part Selection Changed");
            }
            _toolState = null;
        }
示例#13
0
        private void AlignPartsTo(IPartScript part)
        {
            if (_SelectorManager.SelectedParts.Count > 0)
            {
                if (_ToolState != null)
                {
                    foreach (IPartScript selectedPart in _SelectorManager.SelectedParts)
                    {
                        Vector3 selectedPartPos = selectedPart.Transform.position;
                        Vector3 newPosition;
                        float   DeltaPosition;

                        if (_ToolState.Axis == 'X')
                        {
                            DeltaPosition = part.Transform.position.x - selectedPartPos.x;
                            newPosition   = new Vector3(selectedPartPos.x + DeltaPosition, selectedPartPos.y, selectedPartPos.z);
                        }
                        else if (_ToolState.Axis == 'Y')
                        {
                            DeltaPosition = part.Transform.position.y - selectedPartPos.y;
                            newPosition   = new Vector3(selectedPartPos.x, selectedPartPos.y + DeltaPosition, selectedPartPos.z);
                        }
                        else
                        {
                            DeltaPosition = part.Transform.position.z - selectedPartPos.z;
                            newPosition   = new Vector3(selectedPartPos.x, selectedPartPos.y, selectedPartPos.z + DeltaPosition);
                        }
                        selectedPart.Transform.position = newPosition;
                    }
                    _Designer.DesignerUi.ShowMessage("Part Aligned");
                }
                else
                {
                    _Designer.DesignerUi.ShowMessage("<color=#b33e46> Part Alignment failed : ToolState Changed");
                }
            }
            else
            {
                _Designer.DesignerUi.ShowMessage("<color=#b33e46> Part Alignment failed : Part Selection Changed");
            }
            _ToolState = null;
        }
 public void OnSelectedPartChanged(IPartScript OldPart, IPartScript NewPart)
 {
     //Debug.Log ("Selected Part Changed: " + NewPart?.Data.PartType.Id);
     if (!IgnoreNextPartSelectionEvent)
     {
         if (!RequestPartSelectionEvent)
         {
             if (_Designer.AllowPartSelection)
             {
                 ManagePartSelectedEvent(OldPart, NewPart);
             }
         }
         else
         {
             Mod.Instance.PartTools.OnPartSelected(NewPart);
         }
     }
     else
     {
         IgnoreNextPartSelectionEvent = false;
     }
 }
        /// <summary>
        /// Add to Dictionary and return AirTarget ref of the adde missile
        /// </summary>
        /// <param name="missileScript"></param>
        /// <returns>Generated Target</returns>
        public ITarget CreateTarget4LaunchedMissile(IMissileScript missileScript)
        {
            //Register callback to handle missile explsion event
            missileScript.Exploded += OnMissleExploded;
            //Add AircraftScript to the missile
            var missileAircraftScript = (MonoBehaviour)((MonoBehaviour)missileScript).gameObject.AddComponent(AircraftScript.type);

            missileAircraftScript.enabled = false;
            IAircraft   tempAircraft = NewAircraft;
            IPartScript partScript   = (IPartScript)missileAircraftScript.GetComponent(PartScript.type);
            var         firedByName  = ((MonoBehaviour)partScript.Aircraft).name;

            //Rename Aircraft
            tempAircraft.Name = $"{missileAircraftScript.name} ({firedByName})";
            //Set AircraftScript values
            AircraftScript.InvokeMethod("set_Aircraft", missileAircraftScript, new object[] { tempAircraft });
            ((IAircraftScript)missileAircraftScript).MainCockpit = partScript;
            //Create the target presenting missile
            var target = (ITarget)AirTarget.type.GetConstructor(new Type[] { AircraftScript.type }).Invoke(new object[] { missileAircraftScript });

            aircraftLaunchedMissiles.Add(target, new MissileInfo((IAircraftScript)missileAircraftScript, (IMissileScript)missileScript));
            return(target);
        }
示例#16
0
 public override void OnSymmetry(SymmetryMode mode, IPartScript originalPart, bool created)
 {
     UpdateTank();
 }