Ejemplo n.º 1
0
        protected override void Switch(bool turnOn)
        {
            if (m_ChildNodes.Count == 0)
            {
                mIsOpen = turnOn;
                SwitchEvent.Invoke(turnOn);
                return;
            }

            switch (SwitchTurnMode)
            {
            case TurnMode.TreeDownToTop:
            case TurnMode.TreeTopToDown:
            case TurnMode.TreeReverseTopToDown:
            case TurnMode.TreeReverseDownToTop:
                InvokeTreeMode(turnOn);
                break;

            case TurnMode.LayerTopToDown:
            case TurnMode.LayerReverseTopToDown:
                InvokeLayerTopToDown(turnOn);
                break;

            case TurnMode.LayerDownToTop:
            case TurnMode.LayerReverseDownToTop:
                InvokeLayerDownToTop(turnOn);
                break;
            }
        }
Ejemplo n.º 2
0
 private void OnSwitchEvent(SwitchEvent e)
 {
     if (e.Id != Id)
     {
         return;
     }
     IsOpen         = e.IsOpen;
     _render.sprite = IsOpen ? OpenSprite : _closeSprite;
 }
Ejemplo n.º 3
0
 private void OnGameEvent(GameEvent e)
 {
     if (e == GameEvent.StopTimeline)
     {
         var switchEvent = new SwitchEvent();
         switchEvent.Id     = Id;
         switchEvent.IsOpen = false;
         EventBus.Trigger(switchEvent);
     }
 }
Ejemplo n.º 4
0
 /// <summary>GameEvents callback.</summary>
 /// <remarks>
 /// Detects vessel switch and remembers old camera settings if switching from the currently active
 /// vessel.
 /// </remarks>
 /// <param name="fromVessel">A vessel prior the switch.</param>
 /// <param name="toVessel">A new active vessel.</param>
 void OnVesselSwitch(Vessel fromVessel, Vessel toVessel)
 {
     if (_state == SwitchEvent.Idle && _cameraStabilizationMode != CameraStabilization.None &&
         fromVessel != null && fromVessel.isActiveVessel)
     {
         _state = SwitchEvent.VesselSwitched;
         DebugEx.Info("Detected switch from {0} to {1}. Request camera stabilization.", fromVessel, toVessel);
         _newInfo = new VesselInfo(toVessel);
         _oldInfo = new VesselInfo(fromVessel, FlightCamera.fetch);
     }
 }
Ejemplo n.º 5
0
 protected override void ResetNodeState(bool turnOn)
 {
     if (turnOn)
     {
         OpenChildCount = m_ChildNodes.Count;
     }
     else
     {
         OpenChildCount = 0;
     }
     mIsOpen = turnOn;
     SwitchEvent.Invoke(IsOpen);
 }
Ejemplo n.º 6
0
    private void OnCommandEvent(CommandEvent e)
    {
        if (e.PhaseType != CommandPhaseType.AfterRun)
        {
            return;
        }

        var item        = MapMgr.Inst.GetMapItem(Cell);
        var switchEvent = new SwitchEvent();

        switchEvent.Id     = Id;
        switchEvent.IsOpen = item != null;
        EventBus.Trigger(switchEvent);
    }
Ejemplo n.º 7
0
        /// <summary>GameEvents callback.</summary>
        /// <remarks>Highlights newly selected vessel and handles camera stabilization.</remarks>
        /// <param name="vessel">A new active vessel.</param>
        void OnVesselChange(Vessel vessel)
        {
            // Temporarily highlight the new vessel.
            if (_state == SwitchEvent.VesselSwitched || _state == SwitchEvent.Idle)
            {
                StartCoroutine(TimedHighlightCoroutine(
                                   vessel, _newVesselHighlightTimeout, _targetVesselHighlightColor));
            }

            if (_state != SwitchEvent.VesselSwitched)
            {
                return;
            }
            _state = SwitchEvent.Idle;

            var camera = FlightCamera.fetch;

            _newInfo.UpdateCameraFrom(camera);
            // Camera position cannot be transitioned between any modes. Some modes (e.g. LOCKED) don't
            // allow the camera to be placed at any place. Don't do camera stabilization or
            // aligning for such modes. In the modes that allow free camera position the transformations
            // can be very different so, just copy source mode into the target vessel.
            // TODO(ihsoft): Find a way to do the translation between different modes.
            if (Vector3.Distance(_oldInfo.anchorPos, _newInfo.anchorPos) > _maxVesselDistance)
            {
                // On the distant vessels respect camera modes of the both vessels. If either of them is not
                // "free" then just fallback to the default behavior (restore latest known position).
                if (IsFreeCameraPositionMode(_oldInfo.cameraMode) &&
                    IsFreeCameraPositionMode(_newInfo.cameraMode))
                {
                    SetCurrentCameraMode(_oldInfo.cameraMode); // Sync modes to match transformations.
                    AlignCamera();
                }
            }
            else
            {
                // On close vessels if source mode is "free" then substitute target mode with it. Only do so
                // when mouse select is used (i.e. it's an explicit EVS action). Fallback to the default
                // behavior if it was an implicit switch (via a KSP hotkey) and the target mode is not
                // "free".
                if (IsFreeCameraPositionMode(_oldInfo.cameraMode) &&
                    (_evsSwitchAction || IsFreeCameraPositionMode(_newInfo.cameraMode)))
                {
                    SetCurrentCameraMode(_oldInfo.cameraMode); // Sync modes to match transformations.
                    StabilizeCamera();
                }
            }
            _evsSwitchAction = false;
        }
Ejemplo n.º 8
0
 /// <summary>GameEvents callback.</summary>
 /// <remarks>
 /// Detects vessel docking events.
 /// <para>
 /// Parts coupling is not a straightforward event. Depending on what has docked to what there may
 /// or may not be a vessel switch event sent. To be on a safe side just disable switch event
 /// handling in such case and fix camera in <c>LastUpdate</c>.
 /// </para>
 /// </remarks>
 void OnPartCouple(GameEvents.FromToAction <Part, Part> action)
 {
     // Only do camera fix if either the source or the destination is an active vessel.
     if (action.from.vessel.isActiveVessel)
     {
         _state = SwitchEvent.VesselDocked;
         DebugEx.Info("Active vessel docked to a station. Waiting for LateUpdate...");
         _oldInfo = new VesselInfo(action.from.vessel, FlightCamera.fetch);
     }
     else if (action.to.vessel.isActiveVessel)
     {
         _state = SwitchEvent.VesselDocked;
         DebugEx.Info("Something has docked to the active vessel. Waiting for LateUpdate...");
         _oldInfo = new VesselInfo(action.to.vessel, FlightCamera.fetch);
     }
 }
Ejemplo n.º 9
0
        /// <summary>Overridden from MonoBehaviour.</summary>
        /// <remarks>
        /// Updates camera and vessels highlighting when two vessels docked.
        /// <para>
        /// EVS stabilization mode is not supported. Camera position is updated via normal KSP behavior:
        /// keep distance and rotation while slowly moving focus to the new center of mass.
        /// </para>
        /// </remarks>
        void LateUpdate()
        {
            if (_state == SwitchEvent.VesselDocked)
            {
                _state = SwitchEvent.Idle;
                DebugEx.Info("Setting camera pivot to the new CoM.");
                var camera = FlightCamera.fetch;
                camera.GetPivot().position = _oldInfo.cameraPivotPos;
                camera.SetCamCoordsFromPosition(_oldInfo.cameraPos);
                camera.GetCameraTransform().position = _oldInfo.cameraPos;

                StartCoroutine(TimedHighlightCoroutine(
                                   FlightGlobals.ActiveVessel, _newVesselHighlightTimeout, _targetVesselHighlightColor,
                                   isBeingDocked: true));
            }
        }
Ejemplo n.º 10
0
    public static SwitchEvent Serdes(SwitchEvent e, AssetMapping mapping, ISerializer s)
    {
        if (s == null)
        {
            throw new ArgumentNullException(nameof(s));
        }
        e ??= new SwitchEvent();
        e.Operation = s.EnumU8(nameof(Operation), e.Operation);
        e.Unk3      = s.UInt8(nameof(Unk3), e.Unk3);
        int zeroed = s.UInt8(null, 0);

        zeroed    += s.UInt8(null, 0);
        e.SwitchId = SwitchId.SerdesU16(nameof(SwitchId), e.SwitchId, mapping, s);
        zeroed    += s.UInt16(null, 0);
        s.Assert(zeroed == 0, "SwitchEvent: Expected fields 4,5,8 to be 0");
        return(e);
    }
Ejemplo n.º 11
0
        public bool UpdateStatus(string userId, string switchId, bool status)
        {
            var @switch = _switchRepository.Get(switchId);

            if (@switch.Site.UserId != userId)
            {
                throw new LynexException(string.Format("User {0} does not have permission over Switch {1}", userId, switchId));
            }

            var switchEvent = new SwitchEvent
            {
                Processed = false,
                Status    = status,
                SwitchId  = switchId,
                SiteId    = @switch.SiteId
            };

            //_switchEventRepository.AddEvent(switchEvent);

            return(_switchRepository.UpdateStatus(switchId, status));
        }
Ejemplo n.º 12
0
    public static ModifyEvent BaseSerdes(ModifyEvent genericEvent, AssetMapping mapping, AssetId eventSource, ISerializer s)
    {
        if (s == null)
        {
            throw new ArgumentNullException(nameof(s));
        }
        var subType = s.EnumU8("SubType", genericEvent?.SubType ?? ModifyType.Unk2);

        return(subType switch
        {
            ModifyType.Switch => SwitchEvent.Serdes((SwitchEvent)genericEvent, mapping, s),                                        // 0
            ModifyType.DisableEventChain => DisableEventChainEvent.Serdes((DisableEventChainEvent)genericEvent, eventSource, s),   // 1
            ModifyType.Unk2 => ModifyUnk2Event.Serdes((ModifyUnk2Event)genericEvent, s),                                           // 2
            ModifyType.NpcActive => DisableNpcEvent.Serdes((DisableNpcEvent)genericEvent, s),                                      // 4
            ModifyType.AddPartyMember => AddPartyMemberEvent.Serdes((AddPartyMemberEvent)genericEvent, mapping, s),                // 5
            ModifyType.InventoryItem => AddRemoveInventoryItemEvent.Serdes((AddRemoveInventoryItemEvent)genericEvent, mapping, s), // 6
            ModifyType.MapLighting => SetMapLightingEvent.Serdes((SetMapLightingEvent)genericEvent, s),                            // B
            ModifyType.PartyGold => ChangePartyGoldEvent.Serdes((ChangePartyGoldEvent)genericEvent, s),                            // F
            ModifyType.PartyRations => ChangePartyRationsEvent.Serdes((ChangePartyRationsEvent)genericEvent, s),                   // 10
            ModifyType.Time => ChangeTimeEvent.Serdes((ChangeTimeEvent)genericEvent, s),                                           // 12
            ModifyType.Leader => SetPartyLeaderEvent.Serdes((SetPartyLeaderEvent)genericEvent, mapping, s),                        // 1A
            ModifyType.Ticker => TickerEvent.Serdes((TickerEvent)genericEvent, mapping, s),                                        // 1C
            _ => throw new InvalidEnumArgumentException(nameof(subType), (int)subType, typeof(ModifyType))
        });
Ejemplo n.º 13
0
 public void addSwitchEventReceiver(SwitchEvent pReceiver)
 {
     switchEvent += pReceiver;
 }
Ejemplo n.º 14
0
 void Start()
 {
     if (switchEvent == null)
         switchEvent = nullSwitchEvent;
 }
Ejemplo n.º 15
0
 public void addClickEventReceiver(VoidCallFunc pReceiver)
 {
     switchEvent += (x) => pReceiver();
 }