Beispiel #1
0
        ///////////////////////////////////////////////
        //////////////////PROPERTIES///////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        ////////////////////METHODS////////////////////
        ///////////////////////////////////////////////

        //////////////TRANSFORM_METHODS////////////////

        public void moveTo(GlPointR2 newBelongsPoint)
        {
            if (newBelongsPoint == null || newBelongsPoint.isNullPoint())
            {
                return;
            }

            if (OnMoveStart != null)
            {
                if (!OnMoveStart.Invoke(this, this.pointOfLine.X, this.pointOfLine.Y))
                {
                    return;
                }
            }

            if (OnMoving != null)
            {
                OnMoving.Invoke(this, this.pointOfLine.X, this.pointOfLine.Y);
            }

            GlPointR2 OP = new GlPointR2(this.PointOfLine);

            this.pointOfLine = newBelongsPoint;

            if (OnMoved != null)
            {
                OnMoved.Invoke(this, OP.X, OP.Y);
            }
        }
Beispiel #2
0
        ///////////////////////////////////////////////
        //////////////////PROPERTIES///////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        ////////////////////METHODS////////////////////
        ///////////////////////////////////////////////

        //////////////TRANSFORM_METHODS////////////////

        public override void moveTo(float x, float y)
        {
            float oldX = this.Center.X;
            float oldY = this.Center.Y;

            if (OnMoveStart != null)
            {
                if (!OnMoveStart.Invoke(this, oldX, oldY))
                {
                    return;
                }
            }

            if (OnMoving != null)
            {
                OnMoving.Invoke(this, oldX, oldY);
            }

            this.systemCenter = new GlPointR2(x, y);
            updatePointsPosition();

            if (OnMoved != null)
            {
                OnMoved.Invoke(this, oldX, oldY);
            }
        }
Beispiel #3
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     base.OnMouseMove(e);
     if (isDown)
     {
         if (Dir == Direction.Horizontal)
         {
             if (e.X - downPoint.X > this.Height)
             {
                 OnMoving?.Invoke(this, new BlockMoveArgs(MoveDir.Right));
             }
             else if (downPoint.X - e.X > this.Height)
             {
                 OnMoving?.Invoke(this, new BlockMoveArgs(MoveDir.Left));
             }
         }
         else
         {
             if (e.Y - downPoint.Y > this.Width)
             {
                 OnMoving?.Invoke(this, new BlockMoveArgs(MoveDir.Down));
             }
             else if (downPoint.Y - e.Y > this.Width)
             {
                 OnMoving?.Invoke(this, new BlockMoveArgs(MoveDir.Up));
             }
         }
     }
 }
Beispiel #4
0
        ///////////////////////////////////////////////
        //////////////////PROPERTIES///////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        ////////////////////METHODS////////////////////
        ///////////////////////////////////////////////

        //////////////TRANSFORM_METHODS////////////////

        public override void moveTo(float x, float y)
        {
            if (OnMoveStart != null)
            {
                if (!OnMoveStart.Invoke(this, this.polyCenter.X, this.polyCenter.Y))
                {
                    return;
                }
            }

            if (OnMoving != null)
            {
                OnMoving.Invoke(this, this.polyCenter.X, this.polyCenter.Y);
            }

            GlVectorR2 delta = new GlVectorR2(x - polyCenter.X, y - polyCenter.Y);

            for (int i = 0; i < vertexes.Length; i++)
            {
                vertexes[i] = delta.fromPointToPoint(vertexes[i]);
            }

            GlPointR2 OP = new GlPointR2(this.polyCenter);

            this.polyCenter = new GlPointR2(x, y);

            if (OnMoved != null)
            {
                OnMoved.Invoke(this, OP.X, OP.Y);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Updates a move operation based of the provided position. <see cref="OnMoving"/>
        /// </summary>
        /// <returns>True if a move operation is running.</returns>
        public bool Drag(float x, float y)
        {
            if (!IsMoving)
            {
                return(false);
            }

            float dx = x - originX;
            float dy = y - originY;

            float nx = originalSelection.X + dx;
            float ny = originalSelection.Y + dy;

            Selection = new RectangleF(nx, ny, Selection.Width, Selection.Height);

            foreach (TransformerItem item in items)
            {
                item.Item.X = item.OriginX + dx;
                item.Item.Y = item.OriginY + dy;
            }

            OnMoving?.Invoke(this, EventArgs.Empty);

            return(true);
        }
        ///////////////////////////////////////////////
        //////////////////PROPERTIES///////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        ////////////////////METHODS////////////////////
        ///////////////////////////////////////////////

        //////////////TRANSFORM_METHODS////////////////

        public override void moveTo(float x, float y)
        {
            float oldX = systemCenter.X, oldY = systemCenter.Y;

            if (OnMoveStart != null)
            {
                if (!OnMoveStart.Invoke(this, oldX, oldY))
                {
                    return;
                }
            }

            if (OnMoving != null)
            {
                OnMoving.Invoke(this, oldX, oldY);
            }

            GlVectorR2 moveVector = new GlVectorR2(x - this.systemCenter.X, y - this.systemCenter.Y);

            this.systemCenter = new GlPointR2(x, y);

            foreach (GlFigure F in this.figuresAmount)
            {
                GlPointR2 newCenter = moveVector.fromPointToPoint(F.Center);
                F.moveTo(newCenter.X, newCenter.Y);
            }

            if (OnMoved != null)
            {
                OnMoving.Invoke(this, oldX, oldY);
            }
        }
Beispiel #7
0
        ///////////////////////////////////////////////
        //////////////////PROPERTIES///////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        ////////////////////METHODS////////////////////
        ///////////////////////////////////////////////

        //////////////TRANSFORM_METHODS////////////////

        public override void moveTo(float x, float y)
        {
            if (OnMoveStart != null)
            {
                if (!OnMoveStart.Invoke(this, this.x, this.y))
                {
                    return;
                }
            }

            if (OnMoving != null)
            {
                OnMoving.Invoke(this, this.x, this.y);
            }

            float oldX = this.x, oldy = this.y;

            this.X = x;
            this.Y = y;

            if (OnMoved != null)
            {
                OnMoved.Invoke(this, oldX, oldy);
            }
        }
Beispiel #8
0
        private void Deploy()
        {
            if (deployed)
            {
                return;
            }

            OnMoving.Fire(0f, 1f);

            if (UIPartActionController.Instance is UIPartActionController partActionController && partActionController.GetItem(part, false) is UIPartActionWindow window)
            {
                window.displayDirty = true;
            }

            foreach (FairingSlice slice in slices)
            {
                GameObject     gameObject = slice.SliceRootObject;
                physicalObject physObj    = physicalObject.ConvertToPhysicalObject(part, gameObject);
                Rigidbody      rigidBody  = physObj.rb;

                rigidBody.useGravity         = true;
                rigidBody.mass               = slice.Mass;
                rigidBody.centerOfMass       = slice.CalculateCoM();
                rigidBody.drag               = part.Rigidbody.drag / numSlices;
                rigidBody.angularDrag        = part.Rigidbody.angularDrag;
                rigidBody.angularVelocity    = part.Rigidbody.angularVelocity;
                rigidBody.maxAngularVelocity = PhysicsGlobals.MaxAngularVelocity;
                rigidBody.velocity           = part.Rigidbody.velocity + Vector3.Cross(part.Rigidbody.worldCenterOfMass - vessel.CurrentCoM, vessel.angularVelocity);

                Vector3 planeNormal           = part.partTransform.TransformDirection(axis);
                Vector3 centerOfMassDirection = (rigidBody.worldCenterOfMass - part.Rigidbody.worldCenterOfMass).normalized;
                Vector3 outDirection          = Vector3.ProjectOnPlane(centerOfMassDirection, planeNormal).normalized;

                Vector3 forceDirection  = (planeNormal * 0.5f + outDirection).normalized;
                Vector3 torqueDirection = Vector3.Cross(planeNormal, outDirection);

                rigidBody.AddForce(forceDirection * deploySpeed, ForceMode.VelocityChange);
                rigidBody.AddTorque(torqueDirection * deployAngularSpeed, ForceMode.VelocityChange);
            }

            slices.Clear();

            part.ModifyCoM();

            needsNotifyFARToRevoxelize = true;
            NotifyFARToRevoxelize();

            part.DragCubes.SetCubeWeight(DRAG_CUBE_NAME_CLOSED, 0);
            part.DragCubes.SetCubeWeight(DRAG_CUBE_NAME_DEPLOYED, 1);
            part.DragCubes.ForceUpdate(weights: true, occlusion: true);

            OnStop.Fire(1f);

            HideDeployEvent();

            deployed = true;

            GameEvents.onVesselWasModified.Fire(vessel);
        }
Beispiel #9
0
 public virtual void MoveTo(PositionInGrid direction)
 {
     Board.ElementMoveTo(this, direction.x, direction.y);
     if (AudioSource && MoveSound)
     {
         AudioSource.clip = MoveSound;
         AudioSource.Play();
     }
     OnMoving?.Invoke(this);
     transform.position += new Vector3(direction.x, direction.y);
 }
        private void OnVesselWasModified(Vessel v)
        {
            bool wasDecoupled = decoupled;

            CheckDecoupled();
            if (!wasDecoupled && decoupled)
            {
                OnMoving.Fire(0, 1);
                OnStop.Fire(1);
            }
        }
Beispiel #11
0
 public new void Decouple()
 {
     if (waitForAnimation && (object)anim != null)
     {
         anim.Play(animationName);
         isDecoupling = true;
         OnMoving.Fire(0f, 1f);
         StartCoroutine(DelayedDecouple());
     }
     else
     {
         OnDecouple();
     }
 }
Beispiel #12
0
 private void OnVesselWasModified(Vessel v)
 {
     if ((object)v != null && v == vessel)
     {
         if (!(isDecoupling || isDecoupled))
         {
             if ((object)part.FindAttachNode(this.explosiveNodeID).attachedPart == null)
             {
                 isDecoupling = true;
                 OnMoving.Fire(0f, 1f);
                 OnStop.Fire(1f);
             }
         }
     }
 }
Beispiel #13
0
    private void FixedUpdate()
    {
        OnMovingArgs args = new OnMovingArgs(movement + (AddGravity ? Physics.gravity : Vector3.zero));

        if (OnMoving != null)
        {
            OnMoving.Invoke(this, args);
        }

        if (!args.Cancel)
        {
            physics.velocity = (args.Velocity * MovementMultiplicator);
            movement         = Vector3.zero;
        }
    }
 public void Decouple()
 {
     OnMoving.Fire(0, 1);
     if (decoupler != null && !decoupler.isDecoupled)
     {
         decoupler.Decouple();
     }
     foreach (ModuleDecouple d in panels)
     {
         if (!d.isDecoupled)
         {
             d.Decouple();
         }
     }
     OnStop.Fire(1);
 }
Beispiel #15
0
 // TODO Consider deprecating checkForDecoupling; it should no longer be necessary
 private void checkForDecoupling(EventReport separationData)
 {
     if (separationData.eventType == FlightEvents.STAGESEPARATION && separationData.origin == this.part)
     {
         // PROBABLY got called because we decoupled, but no way to know because ModuleAnchoredDecoupler doesn't SET isDecoupled until after the event fires.
         OnMoving.Fire(0f, 1f);
         if (animationName != "" && (object)anim != null && (!this.animationComplete || !this.anim.IsPlaying(animationName)))
         {
             this.anim.Play(animationName);
             this.animationComplete = true;
             Debug.Log("ModuleAnimatedAnchoredDecoupler.onStageSeparation() triggered animation " + this.animationName);
         }
         this.isDecoupling = true;
         this.OnStop.Fire(1f);
     }
 }
Beispiel #16
0
        private void OnEditorToggleJettisoned(BaseField field, object oldValue)
        {
            if (!HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            OnMoving.Fire(isJettisoned ? 0 : 1, isJettisoned ? 1 : 0);

            if (jettisons.Length > 0)
            {
                SetJettisoned(isJettisoned);
            }

            OnStop.Fire(isJettisoned ? 1 : 0);
        }
Beispiel #17
0
        public void Jettison()
        {
            if (isJettisoned)
            {
                return;
            }

            if (jettisons.Length == 0)
            {
                return;
            }

            OnMoving.Fire(0, 1);

            for (int i = 0; i < jettisons.Length; i++)
            {
                Rigidbody rb = physicalObject.ConvertToPhysicalObject(part, jettisons[i].gameObject).rb;
                rb.useGravity         = true;
                rb.mass               = jettisonedObjectMass / jettisons.Length;
                rb.maxAngularVelocity = PhysicsGlobals.MaxAngularVelocity;
                rb.angularVelocity    = part.Rigidbody.angularVelocity;
                rb.velocity           = part.Rigidbody.velocity + Vector3.Cross(part.Rigidbody.worldCenterOfMass - vessel.CurrentCoM, vessel.angularVelocity);

                Vector3 d = jettisonDirection;
                if (d == Vector3.zero)
                {
                    d = Vector3.Normalize(rb.transform.position - part.transform.position);
                }
                else
                {
                    d = part.transform.TransformDirection(d);
                }

                //rb.AddForce(part.transform.TransformDirection(jettisonDirection) * (jettisonForce * 0.5f), ForceMode.Force);
                rb.AddForceAtPosition(d * (jettisonForce * 0.5f), part.transform.position, ForceMode.Force);
                rb.AddTorque(d * jettisonTorque, ForceMode.VelocityChange);
                //part.Rigidbody.AddForce(d * (-jettisonForce * 0.5f), ForceMode.Force);
            }

            jettisons = new Transform[0];

            isJettisoned = true;

            SetJettisoned(isJettisoned);

            OnStop.Fire(1);
        }
Beispiel #18
0
 private void OnVesselWasModified(Vessel v)
 {
     if ((object)v != null && v == vessel)
     {
         if (!(isDecoupling || isDecoupled))
         {
             Part p;
             p = this.ExplosiveNode.attachedPart;
             if (p = null)
             {
                 isDecoupling = true;
                 OnMoving.Fire(0f, 1f);
                 OnStop.Fire(1f);
             }
         }
     }
 }
Beispiel #19
0
 public void SetDeployed(bool newState)
 {
     if (deployed != newState)
     {
         if (newState)
         {
             OnMoving.Fire(stowedAnchor, deployedAnchor);
         }
         else
         {
             OnMoving.Fire(deployedAnchor, stowedAnchor);
         }
         OnStop.Fire(SpringAnchor());
     }
     deployed = newState;
     Events["Deploy"].guiActive     = !deployed;
     Actions["DeployAction"].active = !deployed;
 }
Beispiel #20
0
        public void PlayAnimation(float speed)
        {
            float moveTo = animPosition;

            if (speed < 0)
            {
                moveTo = 0f;
            }
            else if (speed > 0)
            {
                moveTo = 1f;
            }

            OnMoving.Fire(animPosition, moveTo);

            foreach (var anim in animationStates)
            {
                anim.speed = speed;
            }

            playing = speed != 0f;
        }
Beispiel #21
0
 public override void OnActive()
 {
     if (staged)
     {
         if ((object)anim != null)
         {
             anim.Play(animationName);
             isDecoupling = true;
             OnMoving.Fire(0f, 1f);
             if (waitForAnimation)
             {
                 StartCoroutine(DelayedDecouple());
             }
             else
             {
                 OnDecouple();
             }
         }
         else
         {
             OnDecouple();
         }
     }
 }
        private void fireEvents(AnimState newState)
        {
            switch (newState)
            {
            case AnimState.STOPPED_START:
                OnStop.Fire(0f);
                break;

            case AnimState.STOPPED_END:
                OnStop.Fire(1f);
                break;

            case AnimState.PLAYING_FORWARD:
                OnMoving.Fire(0, 1);
                break;

            case AnimState.PLAYING_BACKWARD:
                OnMoving.Fire(1, 0);
                break;

            default:
                break;
            }
        }
Beispiel #23
0
 private void OnMove(InputValue inputValue)
 {
     OnMoving?.Invoke(inputValue.Get <float>());
 }
Beispiel #24
0
        public virtual void OnMouseMove(MouseEventArgs e)
        {
            if (!_enabled)
            {
                return;
            }


            if (Moving)
            {
                Point tempPoint = CMain.MPoint.Subtract(_movePoint);

                if (Parent == null)
                {
                    if (tempPoint.Y + TrueSize.Height > Settings.ScreenHeight)
                    {
                        tempPoint.Y = Settings.ScreenHeight - TrueSize.Height - 1;
                    }

                    if (tempPoint.X + TrueSize.Width > Settings.ScreenWidth)
                    {
                        tempPoint.X = Settings.ScreenWidth - TrueSize.Width - 1;
                    }
                }
                else
                {
                    if (tempPoint.Y + TrueSize.Height > Parent.TrueSize.Height)
                    {
                        tempPoint.Y = Parent.TrueSize.Height - TrueSize.Height;
                    }

                    if (tempPoint.X + TrueSize.Width > Parent.TrueSize.Width)
                    {
                        tempPoint.X = Parent.TrueSize.Width - TrueSize.Width;
                    }
                }

                if (tempPoint.X < 0)
                {
                    tempPoint.X = 0;
                }
                if (tempPoint.Y < 0)
                {
                    tempPoint.Y = 0;
                }

                Location = tempPoint;
                if (OnMoving != null)
                {
                    OnMoving.Invoke(this, e);
                }
                return;
            }

            if (Controls != null)
            {
                for (int i = Controls.Count - 1; i >= 0; i--)
                {
                    if (Controls[i].IsMouseOver(CMain.MPoint))
                    {
                        Controls[i].OnMouseMove(e);
                        return;
                    }
                }
            }

            Highlight();

            if (MouseMove != null)
            {
                MouseMove.Invoke(this, e);
            }
        }
 private void Moving(float inputAxis)
 {
     // TODO: Moving Implement Here
     OnMoving?.Invoke();
 }
Beispiel #26
0
 public void OnDestroy()
 {
     OnMoving.Remove(DoOnMovingEffect);
     OnStop.Remove(StopEffect);
 }
Beispiel #27
0
 public void Start()
 {
     OnMoving.Add(DoOnMovingEffect);
     OnStop.Add(StopEffect);
 }
 private void DoStartAnimation(float pos, float moveto)
 {
     OnMoving.Fire(animPosition, moveto);
     part.Effect("deploy");
 }
Beispiel #29
0
        public void Jettison()
        {
            if (isJettisoned)
            {
                return;
            }

            if (jettisons.Length == 0)
            {
                return;
            }

            OnMoving.Fire(0, 1);

            for (int i = 0; i < jettisons.Length; i++)
            {
                Rigidbody rb = physicalObject.ConvertToPhysicalObject(part, jettisons[i].gameObject).rb;
                rb.useGravity         = true;
                rb.mass               = jettisonedObjectMass / jettisons.Length;
                rb.maxAngularVelocity = PhysicsGlobals.MaxAngularVelocity;
                rb.angularVelocity    = part.Rigidbody.angularVelocity;
                rb.velocity           = part.Rigidbody.velocity + Vector3.Cross(part.Rigidbody.worldCenterOfMass - vessel.CurrentCoM, vessel.angularVelocity);

                Vector3 d = jettisonDirection;
                if (d == Vector3.zero)
                {
                    d = Vector3.Normalize(rb.transform.position - part.transform.position);
                }
                else
                {
                    d = part.transform.TransformDirection(d);
                }

                //rb.AddForce(part.transform.TransformDirection(jettisonDirection) * (jettisonForce * 0.5f), ForceMode.Force);
                rb.AddForceAtPosition(d * (jettisonForce * 0.5f), part.transform.position, ForceMode.Force);
                part.Rigidbody.AddForce(d * (-jettisonForce * 0.5f), ForceMode.Force);
            }

            jettisons = new Transform[0];

            if (part.temperature < part.skinMaxTemp)
            {
                part.skinTemperature = part.temperature;
            }

            isJettisoned = true;

            SetJettisoned(isJettisoned);

            OnStop.Fire(1);

            EnableOtherModules();

            FXGroup effect = part.findFxGroup(fxGroupName);

            if (effect != null)
            {
                effect.Burst();
            }

            GameEvents.onVesselWasModified.Fire(vessel);
        }