A command, as is given to the game loop for processing.
Esempio n. 1
0
        public CommandData GetCommand(Keys keypress, String state, Boolean isMouse)
        {
            if (state == null || state == String.Empty)
            {
                if (keycommands.ContainsKey(keypress))
                {
                    CommandData cmd = new CommandData(keycommands[keypress], isMouse);
                    return cmd;
                }
                else
                {
                    return null;
                }
            }

            int dotindex = state.IndexOf('.');
            String childname = null;
            String childns = null;
            if (dotindex == -1)
                childname = state;
            else
            {
                childname = state.Substring(0, dotindex);
                childns = state.Substring(dotindex + 1);
            }

            CommandData childresult = null;
            if (children.ContainsKey(childname))
                childresult = children[childname].GetCommand(keypress, childns);

            if (childresult == null)
            {
                if (keycommands.ContainsKey(keypress))
                {
                    CommandData cmd = new CommandData(keycommands[keypress], isMouse);
                    return cmd;
                }
                else
                {
                    return null;
                }
            }
            return childresult;
        }
Esempio n. 2
0
 public CommandEventArgs(CommandData cmdData)
 {
     Handled = false;
     CommandData = cmdData;
 }
Esempio n. 3
0
 /// <summary>
 /// Performs a one-shot trigger of a given command.
 /// </summary>
 /// <param name="command">The command to trigger.</param>
 public void TriggerCommand(CommandData command)
 {
     if (command == null)
         return;
     if (this.CommandTriggered != null)
         CommandTriggered(this, new CommandEventArgs(command));
 }
Esempio n. 4
0
        /// <summary>
        /// Starts a game command. This command will be duplicated as a trigger, and will be
        /// re-triggered as a key-repeat until it is ended by a call to EndCommand().
        /// </summary>
        /// <param name="command">The command to start.</param>
        public void StartCommand(CommandData command)
        {
            if (command == null)
                return;
            if (!keytimers.ContainsKey(command.Command))
            {
                if (this.CommandStarted != null)
                    CommandStarted(this, new CommandEventArgs(command));

                TriggerCommand(command);
                Timer t = new Timer();
                t.Interval = 250;
                t.Start();
                t.Tick += delegate(object sender, EventArgs e)
                {
                    TriggerCommand(command);
                    t.Interval = 100;
                    t.Stop();
                    t.Start();
                };
                keytimers.Add(command.Command, t);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Ends a command that was previously started. This will stop the command from being repeat-triggered.
        /// </summary>
        /// <param name="command">The name of the command to stop</param>
        public void EndCommand(CommandData command)
        {
            if (command == null)
                return;
            if (this.CommandEnded != null)
                CommandEnded(this, new CommandEventArgs(command));

            if (keytimers.ContainsKey(command.Command))
            {
                keytimers[command.Command].Dispose();
                keytimers.Remove(command.Command);
            }
        }