public void StateChanged(GameScreenBase gameScreen) { currentScreen = gameScreen; //drawer.SetDrawableObjectsProvider(currentScreen); }
public void registerState(string stateName, GameScreenBase gameState) { this.RegisterStateChange(stateName, gameState); }
public void RegisterStateChange(string state, GameScreenBase gameScreen) { if (!state.Equals(States.END_STATE)) { if (!isRegisteredState(state)) stateChangeMap.Add(state, new List<GameScreenBase>()); stateChangeMap[state].Add(gameScreen); gameScreen.ScreenChangeRequested += onScreenChangeRequested; } //swiezo zakomentowane: //if (currentScreen == null) //{ // currentScreen = gameScreen; //} }
protected void updateStates() { // we can only change the states if stateChangeLocked is false (i.e. the state change // isn't called from one of the enter or exit state functions) if (!stateChangeLocked) { // set the lock stateChangeLocked = true; // push all our new state changes onto the pending state change list foreach (string info in newStateChangeRequests) pendingStateChangeRequests.Add(info); newStateChangeRequests.Clear(); // now process the pending state changes while (pendingStateChangeRequests.Count != 0) { foreach (string stateChangeRequest in pendingStateChangeRequests) { if (!stateChangeRequest.Equals(currentState)) { // call the exit function for all state listeners that are in the current state if (stateChangeMap.ContainsKey(currentState)) { foreach (GameScreenBase info in stateChangeMap[currentState]) { info.Dispose(); } } if (!stateChangeRequest.Equals(States.END_STATE)) { if (stateChangeMap.ContainsKey(stateChangeRequest)) { foreach (GameScreenBase info in stateChangeMap[stateChangeRequest]) { info.Init(); } } } } currentState = stateChangeRequest; currentScreen = stateChangeMap[currentState][0]; //nowo dodane: screenChangeListener.StateChanged(currentScreen); } // all current pending state changes have been processed, so clear the list pendingStateChangeRequests.Clear(); // push all our new state changes onto the pending state change list foreach (string info in newStateChangeRequests) pendingStateChangeRequests.Add(info); newStateChangeRequests.Clear(); } stateChangeLocked = false; } }