public void addExitStateListener(string state, StateChangeDelegate method) { if (state.Length == 0) { throw new StateMachineException("string 'state' canont be empty."); } if (method == null) { throw new StateMachineException("StateChangeDelegate 'method' cannot be null."); } if (stateUpdateMethods.ContainsKey(state) == false) { throw new StateMachineException("Cannot add listener because state, " + state + ", does not exist."); } if (exitStateListeners.ContainsKey(state) == false) { exitStateListeners.Add(state, new List <StateChangeDelegate>()); exitStateListeners[state].Add(method); } else if (exitStateListeners[state].Contains(method) == false) { exitStateListeners[state].Add(method); } }
public VOState(int id, List <int> from, StateChangeDelegate enter, StateChangeDelegate update, StateChangeDelegate exit) { this.id = id; this.from = from; this.enter = enter; this.update = update; this.exit = exit; }
private void HandleInput() { //if the left mouse button is pressed then paint the tile onto the Map if (mInputProcessor.currentMouseState[Util.MouseButtons.Left] == ButtonState.Pressed && canvasActive == true) { //Console.WriteLine(string.Format("changing tile at x:{0} y:{1}",gridx, gridy)); //if the brush is a tile if (tileTextures.dict.ContainsValue(brushTexture)) { if (Map.terrainTiles[gridy, gridx].texture != brushTexture) { Map.ChangeTile(gridx, gridy, brushTexture); } } //else if the brush is a decoration else if (decorationTextures.dict.ContainsValue(brushTexture)) { if (mInputProcessor.previousMouseState[Util.MouseButtons.Left] == ButtonState.Released) { Map.PaintDecoration(Mouse.GetState().X, Mouse.GetState().Y, brushTexture); } } } //if the toolbox is active and the user clicked else if (mInputProcessor.currentMouseState[Util.MouseButtons.Left] == ButtonState.Pressed && toolbox.active == true) { Texture2D textureClick = toolbox.Click(); if (textureClick != null) { brushTexture = textureClick; } } //transition from the canvas being active to the toolbox being active if (canvasActive == true && mInputProcessor.currentButtonStates[Keys.T] == true && mInputProcessor.previousButtonStates[Keys.T] == false) { canvasActive = false; toolbox.active = true; } //transition from the toolbox being active to the canvas being active else if (canvasActive == false && mInputProcessor.currentButtonStates[Keys.T] == true && mInputProcessor.previousButtonStates[Keys.T] == false) { canvasActive = true; toolbox.active = false; //Map.SaveToFile("Map.txt"); } if (mInputProcessor.currentButtonStates[Keys.Escape] && !mInputProcessor.previousButtonStates[Keys.Escape]) { StateChangeDelegate?.Invoke(3); } }
public void removeEnterStateListener(string state, StateChangeDelegate method) { if (state.Length == 0) { throw new StateMachineException("string 'state' canont be empty."); } if (method == null) { throw new StateMachineException("StateChangeDelegate 'method' cannot be null."); } if (stateUpdateMethods.ContainsKey(state) == false) { throw new StateMachineException("Cannot remove listener because state, " + state + ", does not exist."); } if (enterStateListeners.ContainsKey(state) && enterStateListeners[state].Contains(method) == false) { enterStateListeners[state].Remove(method); } }
/// <summary> /// 添加状态处理 /// </summary> /// <param name="state">State.</param> /// <param name="handler">Handler.</param> public void AddStateHandler(int state, StateChangeDelegate handler) { _StateChangeHandlers [state] = handler; }