/// <summary> /// Pops the command map from the stack exposing the next one as the active one /// This is only needed to be done when the object is no longer activated or /// within the running stack of objects /// </summary> /// <param name="commandMap"></param> public static void Pop(CommandMap commandMap) { if (commandMaps.Count > 0) { // Currently not needed. Useful to uncomment for debugging. //CommandMap activeMap = commandMaps[commandMaps.Count - 1]; //commandMaps.Remove(commandMap); // We can't just do a Remove here. If a command map is in // the stack more than once the Remove will take out the // wrong one. The whole reason we're in this mess is because // the command "stack" doesn't always act like a stack. Hence // having to pass in the element that we want to pop. This // should be cleaned up. int index = commandMaps.LastIndexOf(commandMap); // I have no idea why the programming UI is popping command // that aren't on the stack... if (index >= 0) { commandMaps.RemoveAt(index); } SyncTop(commandMap); GamePadInput.ClearAllWasPressedState(); #if DEBUG_SPEW Debug.Print("pop " + commandMap.name); PrintStack(); #endif } }
public void Remove(CommandMap map) { for (int indexCommand = 0; indexCommand < map.commands.Count; indexCommand++) { InputCommand command = map.commands[indexCommand]; this.commands.Remove(command); } }
public static void DetachCommandOverride(CommandMap command) { Debug.Assert(commandOverride == command, "you shouldn't clear someone elses override"); if (commandOverride == command) { commandOverride = null; } }
public void Add(CommandMap map) { for (int indexCommand = 0; indexCommand < map.commands.Count; indexCommand++) { InputCommand command = map.commands[indexCommand]; Debug.Assert(command != null); this.commands.Add(command); } }
protected static void SyncTop(CommandMap prevActiveCommandMap) { // sync the new top map collection if (commandMaps.Count > 0) { CommandMap activeMap = commandMaps[commandMaps.Count - 1]; activeMap.Sync(prevActiveCommandMap); } }
protected static void ResetTop() { // reset the last top map collection if (commandMaps.Count > 0) { CommandMap activeMap = commandMaps[commandMaps.Count - 1]; activeMap.Reset(); } }
/// <summary> /// This method is used to create and load a command map xml file and /// map any events to the given eventTarget object /// </summary> /// <param name="eventTarget"></param> /// <param name="filepath"></param> /// <returns></returns> static public CommandMap Deserialize(object eventTarget, string filepath) { CommandMap profile = Deserialize(filepath); if (profile != null) { profile.eventTarget = eventTarget; profile.LateBindEvents(); } return(profile); }
/// <summary> /// (see above) /// Used to ignore the Override and look deeper into the stack /// Used by those who are setting the override /// </summary> /// <param name="depth"></param> /// <returns></returns> public static CommandMap Peek(int depth) { if (depth >= 0 && commandMaps.Count > depth) { CommandMap activeMap = commandMaps[commandMaps.Count - (depth + 1)]; return(activeMap); } else { return(null); } }
/// <summary> /// Called on every update by the root game object /// This will update keyboard and gamepad states and /// then update the top command map input commands /// </summary> public static void Update() { if (commandOverride != null) { // update static state InputCommand.UpdateState(); commandOverride.Update(); } else if (commandMaps.Count > 0) { // update static state InputCommand.UpdateState(); // now update all commands in the top map collection CommandMap activeMap = commandMaps[commandMaps.Count - 1]; activeMap.Update(); } }
public void Sync(CommandMap prevMap) { for (int indexCommand = 0; indexCommand < this.commands.Count; indexCommand++) { bool clone = false; InputCommand command = this.commands[indexCommand]; if (prevMap != null) { // if we have a previous active map // check if this inputCommand was in it already clone = prevMap.commands.Contains(command); } // do not call sync on an inputCommand that was just active if (!clone && (command != null)) { command.Sync(); } } }
/// <summary> /// Adds the command map to the stack as the top and /// input will be directed to the top map of the stack /// </summary> /// <param name="commandMap"></param> public static void Push(CommandMap commandMap) { Debug.Assert(commandMap != null); //ResetTop(); CommandMap prevActiveCommandMap = null; if (commandMaps.Count > 0) { prevActiveCommandMap = commandMaps[commandMaps.Count - 1]; } commandMaps.Add(commandMap); SyncTop(prevActiveCommandMap); #if DEBUG_SPEW Debug.Print("push " + commandMap.name); PrintStack(); #endif }
/// <summary> /// This is used for override ability and should not be used by any normal UI /// Its primary use is for a tutorial /// </summary> /// <param name="command"></param> public static void AttachCommandOverride(CommandMap command) { Debug.Assert(commandOverride == null); commandOverride = command; }