Exemple #1
0
 public static void InvokeStateChanged(DonationTransaction trans, DonationTransactionState oldState)
 {
     if (OnStateChanged != null)
     {
         OnStateChanged.Invoke(new StateChangedEventArgs(trans, oldState));
     }
 }
Exemple #2
0
        private void HandleNewState()
        {
            if (stateHandler_ != null)
            {
                stateHandler_.Cleanup();
                stateHandler_ = null;
            }

            switch (state_)
            {
            case State.CanJoin:
                stateHandler_ = new StateCanJoin(player_, currentStateContainer_, MoveToNextState, MoveToPreviousState);
                break;

            case State.Skin:
                stateHandler_ = new StateSkinCustomization(player_, currentStateContainer_, MoveToNextState, MoveToPreviousState);
                break;

            case State.Nickname:
                stateHandler_ = new StateNicknameCustomization(player_, currentStateContainer_, MoveToNextState, MoveToPreviousState);
                break;

            case State.Ready:
                stateHandler_ = new StateReady(player_, currentStateContainer_, MoveToNextState, MoveToPreviousState);
                break;
            }

            OnStateChanged.Invoke();
        }
Exemple #3
0
        private async Task OnChanged(CheckboxState state, SelectedItem val)
        {
            // 子选项点击后,更新其余组件
            if (!IsDisabled)
            {
                // 通知其余兄弟控件
                if (state == CheckboxState.Checked && Items != null)
                {
                    foreach (var item in Items)
                    {
                        item.Active = item == val;
                    }

                    StateHasChanged();
                }

                // 触发外界 OnStateChanged 事件
                if (ValueChanged.HasDelegate)
                {
                    await ValueChanged.InvokeAsync(val);
                }
                if (OnStateChanged != null)
                {
                    await OnStateChanged.Invoke(state, val);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Swithes state machine to the state
        /// </summary>
        /// <param name="stateEnter"></param>
        public void SwitchToState(StateEnter stateEnter)
        {
            if (stateToId.ContainsKey(stateEnter) == false)
            {
                Debug.LogError("[StateMachine] Error: This state is not mapped, you must map all states");
            }

            if (currentState.stateExit != null)
            {
                currentState.stateExit();
            }

            // internal switch state
            currentStateId = stateToId[stateEnter];
            currentState   = idToState[currentStateId];

            if (OnStateChanged != null)
            {
                OnStateChanged.Invoke(currentStateId);
            }

            currentState.stateEnter();

            //Debug.LogWarning("[State Machine] Enter state: " + currentStateId + ", " + currentState);
        }
 private void Condition_OnStateChanged(object sender, ToggleAutomationConditionStateChangedHandler args)
 {
     if (args.NewState != State)
     {
         State = args.NewState;
         OnStateChanged.Invoke(this, new ToggleAutomationRuleStateChangedHandler(this, args.NewState));
     }
 }
Exemple #6
0
 void StateChanged(BotState state)
 {
     //Invoke status changed if not null
     if (OnStateChanged != null)
     {
         OnStateChanged.Invoke(state);
     }
 }
Exemple #7
0
        private void _vlcPlayer_StateChanged(object sender, Meta.Vlc.ObjectEventArgs <Meta.Vlc.Interop.Media.MediaState> e)
        {
            state = GetMediaState();

            if (OnStateChanged != null)
            {
                OnStateChanged.Invoke(this, EventArgs.Empty);
            }
        }
 public void ChangeState(StateUI state)
 {
     currentState = state;
     StartCoroutine(state.ToString() + "State");
     if (OnStateChanged != null)
     {
         OnStateChanged.Invoke(this, new EventArgs <int>((int)state));
     }
 }
 private void SwitchToNewState(Type nextState)
 {
     PreviousState = CurrentState;
     CurrentState  = _availableStates[nextState];
     if (OnStateChanged != null)
     {
         OnStateChanged.Invoke(CurrentState);
     }
 }
Exemple #10
0
        public void SetState(bool state)
        {
            Debug.Log("Toggle. Current state: " + this.state + "  new state: " + state);

            if (isBusy && this.state == state)
            {
                return;
            }

            isBusy = true;

            this.state = state;

#if USING_UNITY_EVENT
            if (onStateChanged != null)
            {
                onStateChanged.Invoke(state);
            }
#else
            if (OnStateChanged != null)
            {
                OnStateChanged.Invoke(state);
            }
#endif

            animationTweenCase = movableElement.DOAnchoredPosition(new Vector3(state ? offsetValue : -offsetValue, 0), 0.1f, true).SetEasing(Ease.Type.CubicOut).OnComplete(delegate
            {
                if (state)
                {
                    enableText.color  = activeOnTextColor;
                    disableText.color = disabledTextColor;

                    if (icon != null)
                    {
                        icon.color = activeOnTextColor;
                    }

                    movableElementGraphic.color = activeOnTextColor;
                }
                else
                {
                    enableText.color  = disabledTextColor;
                    disableText.color = activeOffTextColor;

                    if (icon != null)
                    {
                        icon.color = activeOffTextColor;
                    }

                    movableElementGraphic.color = activeOffTextColor;
                }

                isBusy = false;
            });
        }
 private void TaskOnStateChanged(object sender, BaseTaskState e)
 {
     try
     {
         OnStateChanged.Invoke(sender, e);
     }
     catch (Exception error)
     {
         _logger.LogError($"RecognitionTask state listener thrown unhandled exception:\n{error}");
     }
 }
Exemple #12
0
 /// <summary>
 /// 点击选择框方法
 /// </summary>
 protected override async Task OnToggleClick()
 {
     if (!IsDisabled && State == CheckboxState.UnChecked)
     {
         State = CheckboxState.Checked;
         if (OnStateChanged != null)
         {
             await OnStateChanged.Invoke(State, Value);
         }
     }
 }
Exemple #13
0
        private void OnStateReceived(Message msg, Connection con)
        {
            var data = DataStorage.CreateForRead(msg.Body);

            while (!data.Empty)
            {
                int         id = data.ReadInt32();
                StateObject so = new StateObject();
                so.ReadFromDs(data);
                OnStateChanged.Invoke(id, so);
            }
        }
Exemple #14
0
        /// <typeparam name="TAction">TAction must implement the IAction interface.</typeparam>
        /// <param name="action">The action to be dispatched.</param>
        /// <returns></returns>
        public TState Dispatch <TAction>(TAction action) where TAction : IAction <TState>
        {
            TState nextState = action.Reduce(state);

            if (OnStateChanged != null)
            {
                OnStateChanged.Invoke(new StateChangeEventArgs <TState>(state, nextState));
            }

            state = nextState;

            return(state);
        }
Exemple #15
0
        /// <summary>
        /// Changes the state
        /// </summary>
        /// <param name="newState"></param>
        private void ChangeState(BlockState newState)
        {
            this.BlockState = newState;

            if (_fxBody != null)
            {
                UpdateFx();
            }

            _stateTime = 0;

            OnStateChanged.Invoke(new BlockStateArgs(this, newState));
        }
Exemple #16
0
        public void SetStateImmediately(bool state)
        {
            if (this.state != state)
            {
                if (animationTweenCase != null && !animationTweenCase.isCompleted)
                {
                    animationTweenCase.Kill();
                }

                this.state = state;

#if USING_UNITY_EVENT
                if (onStateChanged != null)
                {
                    onStateChanged.Invoke(state);
                }
#else
                if (OnStateChanged != null)
                {
                    OnStateChanged.Invoke(state);
                }
#endif

                movableElement.anchoredPosition = new Vector2(state ? offsetValue : -offsetValue, 0);

                if (state)
                {
                    enableText.color  = activeOnTextColor;
                    disableText.color = disabledTextColor;

                    if (icon != null)
                    {
                        icon.color = activeOnTextColor;
                    }

                    movableElementGraphic.color = activeOnTextColor;
                }
                else
                {
                    enableText.color  = disabledTextColor;
                    disableText.color = activeOffTextColor;

                    if (icon != null)
                    {
                        icon.color = activeOffTextColor;
                    }

                    movableElementGraphic.color = activeOffTextColor;
                }
            }
        }
Exemple #17
0
 private void XmppOnOnXmppConnectionStateChanged(object sender, XmppConnectionState state)
 {
     Trace.WriteLine("[Xmpp]State: " + state.ToString());
     if (OnStateChanged != null)
     {
         OnStateChanged.Invoke(this, state.ToString());
     }
     if (state == XmppConnectionState.Disconnected)
     {
         if (OnDisconnect != null)
         {
             OnDisconnect.Invoke(this, null);
         }
     }
 }
Exemple #18
0
 void ApplyWorkingState()
 {
     if (OnStateChanged != null)
     {
         OnStateChanged.Invoke(this);
     }
     foreach (var obj in _IfActiveObject)
     {
         obj.SetActive(isWorking);
     }
     foreach (var obj in _IfInactiveObject)
     {
         obj.SetActive(!isWorking);
     }
 }
Exemple #19
0
    public void ChangeStates()
    {
        OnStateChanged.Invoke();

        switch (currentState)
        {
        case IrisStates.Move:
            currentState = IrisStates.MemoryLeap;
            ChangeScripts(true);
            break;

        case IrisStates.MemoryLeap:
            currentState = IrisStates.Move;
            ChangeScripts(false);
            break;
        }
    }
Exemple #20
0
 public bool SetConnection(ComponentBase component)
 {
     if (_Component)
     {
         Assert.IsTrue(_Component._Connection == this);
         _Component._Connection = null;
     }
     _Component = component;
     if (_Component)
     {
         _Component._Connection = this;
     }
     if (OnStateChanged != null)
     {
         OnStateChanged.Invoke(this);
     }
     Assert.IsTrue(!_TranformProxy.transform.hasChanged);
     return(true);
 }
Exemple #21
0
        public void SetState(TStateName key, bool restartCurrentState = false)
        {
            if (!restartCurrentState && CurrentState != null && CurrentState.Name.Equals(key))
            {
                return;
            }

            if (CurrentState != null)
            {
                CurrentState.OnExitState();
            }

            CurrentState = _states[key];
            CurrentState.OnEnterState();

            if (OnStateChanged != null)
            {
                OnStateChanged.Invoke(CurrentState);
            }
        }
Exemple #22
0
        /// <summary>
        /// Update the state of the sniffer
        /// </summary>
        private void UpdateState()
        {
            //Super complex state machine of state transitions
            switch (currentState)
            {
            case SnifferState.IN_MENUS:
                if (currentMemoryReadout.songTimer != 0)
                {
                    currentState = SnifferState.SONG_SELECTED;
                }
                break;

            case SnifferState.SONG_SELECTED:
                if (currentMemoryReadout.songTimer == 0)
                {
                    currentState = SnifferState.SONG_STARTING;
                }

                //If we somehow missed some states, skip to SONG_PLAYING
                //Or if the user reset
                if (currentMemoryReadout.songTimer > 1)
                {
                    currentState = SnifferState.SONG_PLAYING;
                }
                break;

            case SnifferState.SONG_STARTING:
                if (currentMemoryReadout.songTimer > 0)
                {
                    currentState = SnifferState.SONG_PLAYING;
                }
                break;

            case SnifferState.SONG_PLAYING:
                //Allow 5 seconds of error margin on song ending
                if (currentMemoryReadout.songTimer >= currentCDLCDetails.songLength - 5)
                {
                    currentState = SnifferState.SONG_ENDING;
                }
                //If the timer goes to 0, the user must have quit
                if (currentMemoryReadout.songTimer == 0)
                {
                    currentState = SnifferState.IN_MENUS;
                }
                break;

            case SnifferState.SONG_ENDING:
                if (currentMemoryReadout.songTimer == 0)
                {
                    currentState = SnifferState.IN_MENUS;
                }
                break;

            default:
                break;
            }

            //Force state to IN_MENUS if the current song details are not valid
            if (!currentCDLCDetails.IsValid())
            {
                currentState = SnifferState.IN_MENUS;
            }

            //If state changed
            if (currentState != previousState)
            {
                //Invoke event
                OnStateChanged?.Invoke(this, new OnStateChangedArgs()
                {
                    oldState = previousState, newState = currentState
                });

                //Remember previous state
                previousState = currentState;

                if (Logger.logStateMachine)
                {
                    Logger.Log("Current state: {0}", currentState.ToString());
                }
            }
        }
 public Task NotifyStateChangedAsync() =>
     OnStateChanged?.Invoke() ?? Task.CompletedTask;
Exemple #24
0
 public void Use()
 {
     this.IsUsed = true;
     OnStateChanged.Invoke(this.ID, true);
 }
Exemple #25
0
 public void UnUse()
 {
     this.IsUsed = false;
     OnStateChanged.Invoke(this.ID, false);
 }
        private void ListGUI(GUIElement[] tree, GroupElement parent)
        {
            // Start of scroll view list
            parent.scroll = GUILayout.BeginScrollView(parent.scroll);

            EditorGUIUtility.SetIconSize(new Vector2(16, 16));

            List <GUIElement> children = GetChildren(tree, parent);

            Rect selectedRect = new Rect();


            // Iterate through the children
            for (int i = 0; i < children.Count; i++)
            {
                GUIElement e = children[i];

                Rect r;
                if (e is WarningElement)
                {
                    var height = s_Styles.warning.CalcHeight(e.content, Position.width);
                    var lines  = (int)height / 20;
                    r = GUILayoutUtility.GetRect(16, (lines + 1) * 20, GUILayout.ExpandWidth(true));
                }
                else
                {
                    r = GUILayoutUtility.GetRect(16, 20, GUILayout.ExpandWidth(true));
                }

                // Select the element the mouse cursor is over.
                // Only do it on mouse move - keyboard controls are allowed to overwrite this until the next time the mouse moves.
                if (Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDown)
                {
                    if (parent.selectedIndex != i && r.Contains(Event.current.mousePosition))
                    {
                        parent.selectedIndex = i;
                        OnStateChanged.Invoke();
                    }
                }

                bool selected = false;
                // Handle selected item
                if (i == parent.selectedIndex)
                {
                    selected     = true;
                    selectedRect = r;
                }

                // Draw element
                if (Event.current.type == EventType.Repaint)
                {
                    GUIStyle   labelStyle;
                    GUIContent labelContent = e.content;

                    bool isComponent = e is LeafElement;
                    bool isWarning   = e is WarningElement;
                    bool isGroup     = e is GroupElement;

                    if (isWarning)
                    {
                        labelStyle = s_Styles.warning;
                    }
                    else if (isComponent)
                    {
                        labelStyle = s_Styles.componentButton;
                    }
                    else
                    {
                        labelStyle = s_Styles.groupButton;
                    }

                    if (!isWarning)
                    {
                        labelStyle.normal.textColor = e.element.Included ? new Color(0.8f, 0.8f, 0.8f) : Color.gray;
                    }

                    GUI.Label(r, labelContent, labelStyle);
                    labelStyle.Draw(r, labelContent, false, false, selected, selected);

                    if (isGroup)
                    {
                        Rect arrowRect = new Rect(r.x + r.width - 13, r.y + 4, 13, 13);
                        s_Styles.rightArrow.Draw(arrowRect, false, false, false, false);
                    }
                }
                if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition))
                {
                    Event.current.Use();
                    parent.selectedIndex = i;
                    GoToChild(e, true);
                }
            }

            EditorGUIUtility.SetIconSize(Vector2.zero);

            GUILayout.EndScrollView();

            // Scroll to show selected
            if (m_ScrollToSelected && Event.current.type == EventType.Repaint)
            {
                m_ScrollToSelected = false;
                Rect scrollRect = GUILayoutUtility.GetLastRect();
                if (selectedRect.yMax - scrollRect.height > parent.scroll.y)
                {
                    parent.scroll.y = selectedRect.yMax - scrollRect.height;
                    OnStateChanged.Invoke();
                }
                if (selectedRect.y < parent.scroll.y)
                {
                    parent.scroll.y = selectedRect.y;
                    OnStateChanged.Invoke();
                }
            }
        }
        public void OnGUI(Rect position)
        {
            if (m_Rebuild)
            {
                foreach (var element in m_Elements)
                {
                    Add(element, 1);
                }
                SetElements(m_InternalElements);
            }
            Position = position;

            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }

            GUI.Label(new Rect(0, 0, position.width, position.height), GUIContent.none, s_Styles.background);

            // Keyboard
            HandleKeyboard();

            GUILayout.Space(7);

            // Search
            Rect searchRect = GUILayoutUtility.GetRect(10, 20);

            searchRect.x     += 8;
            searchRect.width -= 16;

            GUI.SetNextControlName("ComponentSearch");
            string newSearch = s_ComponentSearchField.OnGUI(searchRect, m_DelayedSearch ?? m_Search);

            if (newSearch != m_Search || m_DelayedSearch != null)
            {
                if (!IsAnimating)
                {
                    m_Search = m_DelayedSearch ?? newSearch;
                    RebuildSearch();
                    m_DelayedSearch = null;
                }
                else
                {
                    m_DelayedSearch = newSearch;
                }
            }

            // Show lists
            ListGUI(activeTree, m_Anim, GetElementRelative(0), GetElementRelative(-1));
            if (m_Anim < 1)
            {
                ListGUI(activeTree, m_Anim + 1, GetElementRelative(-1), GetElementRelative(-2));
            }

            // Animate
            if (IsAnimating && Event.current.type == EventType.Repaint)
            {
                long  now       = System.DateTime.Now.Ticks;
                float deltaTime = (now - m_LastTime) / (float)System.TimeSpan.TicksPerSecond;
                m_LastTime = now;
                m_Anim     = Mathf.MoveTowards(m_Anim, m_AnimTarget, deltaTime * 4);
                if (m_AnimTarget == 0 && m_Anim == 0)
                {
                    m_Anim       = 1;
                    m_AnimTarget = 1;
                    m_Stack.RemoveAt(m_Stack.Count - 1);
                }
                OnStateChanged.Invoke();
            }
        }
 private void SwitchToNewState(Type nextState)
 {
     CurrentState = _availableStates[nextState];
     OnStateChanged?.Invoke(CurrentState);
 }
Exemple #29
0
 private void NotifyStateChanged() => OnStateChanged?.Invoke();
Exemple #30
0
        // Sets BattleState to PBEBattleState.ReadyToBegin
        private void CheckForReadiness()
        {
            if (Array.TrueForAll(Teams, t => t.NumPkmnAlive > 0))
            {
                switch (BattleFormat)
                {
                case PBEBattleFormat.Single:
                {
                    foreach (PBETeam team in Teams)
                    {
                        team.Party[0].FieldPosition = PBEFieldPosition.Center;
                        team.SwitchInQueue.Add(team.Party[0]);
                    }
                    break;
                }

                case PBEBattleFormat.Double:
                {
                    foreach (PBETeam team in Teams)
                    {
                        team.Party[0].FieldPosition = PBEFieldPosition.Left;
                        team.SwitchInQueue.Add(team.Party[0]);
                        if (team.Party.Count > 1)
                        {
                            team.Party[1].FieldPosition = PBEFieldPosition.Right;
                            team.SwitchInQueue.Add(team.Party[1]);
                        }
                    }
                    break;
                }

                case PBEBattleFormat.Triple:
                {
                    foreach (PBETeam team in Teams)
                    {
                        team.Party[0].FieldPosition = PBEFieldPosition.Left;
                        team.SwitchInQueue.Add(team.Party[0]);
                        if (team.Party.Count > 1)
                        {
                            team.Party[1].FieldPosition = PBEFieldPosition.Center;
                            team.SwitchInQueue.Add(team.Party[1]);
                        }
                        if (team.Party.Count > 2)
                        {
                            team.Party[2].FieldPosition = PBEFieldPosition.Right;
                            team.SwitchInQueue.Add(team.Party[2]);
                        }
                    }
                    break;
                }

                case PBEBattleFormat.Rotation:
                {
                    foreach (PBETeam team in Teams)
                    {
                        team.Party[0].FieldPosition = PBEFieldPosition.Center;
                        team.SwitchInQueue.Add(team.Party[0]);
                        if (team.Party.Count > 1)
                        {
                            team.Party[1].FieldPosition = PBEFieldPosition.Left;
                            team.SwitchInQueue.Add(team.Party[1]);
                        }
                        if (team.Party.Count > 2)
                        {
                            team.Party[2].FieldPosition = PBEFieldPosition.Right;
                            team.SwitchInQueue.Add(team.Party[2]);
                        }
                    }
                    break;
                }

                default: throw new ArgumentOutOfRangeException(nameof(BattleFormat));
                }

                BattleState = PBEBattleState.ReadyToBegin;
                OnStateChanged?.Invoke(this);
            }
        }