Ejemplo n.º 1
0
 /// <summary>
 /// 结束所有状态,遍历状态列表中的所有当前状态,执行结束动作over,然后将当前状态列表设为NULL
 /// </summary>
 public void shutdown()
 {
     for (int i = this.currState_.Count - 1; i >= 0; --i)
     {
         State state = this.currState_[i] as State;
         state.over();
     }
     this.currState_ = null;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据名称转换为对应的状态,然后将该状态放到当前可执行状态前端
        /// </summary>
        /// <param name="name"></param>
        public void translation(string name)
        {
            State target = this.states_[name] as State; //target state

            if (target == null)                         //if no target return!
            {
                return;
            }

            //如果该状态为状态列表中的最后一个状态,则初始化该状态,即先结束该状态,然后在开始该状态
            //if current, reset
            if (target == this.currState_[this.currState_.Count - 1])
            {
                target.over();
                target.start();
                return;
            }

            //当转换的状态不是当前状态时,记录之前的状态转换
            State preState = this.currState_[this.currState_.Count - 1] as State;

            //排除根目录
            if (preState.name != "root")
            {
                //首次添加
                if (stateOrder.Count == 0)
                {
                    stateOrder.Add(preState);
                }
                else
                {
                    State temp = stateOrder[stateOrder.Count - 1];

                    //排除弹出框,只有弹出框是双界面显示 和弹出框返回的界面
                    if (preState.fatherName != temp.name)
                    {
                        if (stateOrder.Contains(preState))
                        {
                            stateOrder.Remove(preState);
                        }

                        stateOrder.Add(preState);
                    }
                    else
                    {
                        //如果弹出框取消,进入的是同一个界面,则移除该界面
                        if (target == temp)
                        {
                            stateOrder.Remove(temp);
                        }
                    }
                }
            }



            State publicState = null;

            ArrayList stateList = new ArrayList();

            State  tempState  = target;
            string fatherName = tempState.fatherName;

            //do loop
            while (tempState != null)
            {
                //reiterator current list
                for (var i = this.currState_.Count - 1; i >= 0; i--)
                {
                    State state = this.currState_[i] as State;
                    //if has public
                    if (state == tempState)
                    {
                        publicState = state;
                        break;
                    }
                }

                //end
                if (publicState != null)
                {
                    break;
                }

                //else push state_list
                stateList.Insert(0, tempState);
                //state_list.unshift(temp_state);

                if (fatherName != "")
                {
                    tempState  = this.states_[fatherName] as State;
                    fatherName = tempState.fatherName;
                }
                else
                {
                    tempState = null;
                }
            }
            //if no public return
            if (publicState == null)
            {
                return;
            }

            ArrayList newCurrState = new ArrayList();
            bool      under        = true;

            //-- 析构状态
            for (int i2 = this.currState_.Count - 1; i2 >= 0; --i2)
            {
                State state2 = this.currState_[i2] as State;
                if (state2 == publicState)
                {
                    under = false;
                }
                if (under)
                {
                    state2.over();
                }
                else
                {
                    newCurrState.Insert(0, state2);
                }
            }


            //-- 构建状态
            for (int i3 = 0; i3 < stateList.Count; ++i3)
            {
                State state3 = stateList[i3] as State;
                state3.start();
                newCurrState.Add(state3);
            }
            this.currState_ = newCurrState;
        }