Esempio n. 1
0
        /// <summary>
        /// Creates default input bindings.
        /// </summary>
        public static void Initialize(GameServices gs)
        {
            InputManager.gs = gs;
            // TODO: GameCommand list should be set by the application, not the engine, so enum may not be good.
            inputNodeList = new InputNode[Enum.GetValues(typeof(GameCommand)).Length];
            aliasNodeList = new InputNode[Enum.GetValues(typeof(GameCommand)).Length];
            for (int i = 0; i < inputNodeList.Length; i++)
            {
                inputNodeList[i] = new InputNode((GameCommand)i);
                aliasNodeList[i] = new InputNode((GameCommand)i);
            }

            crossBindings = new List <Tuple <GameCommand, GameCommand> >();
            AddCrossBinding(GameCommand.Up, GameCommand.MenuUp);
            AddCrossBinding(GameCommand.Down, GameCommand.MenuDown);
            AddCrossBinding(GameCommand.Left, GameCommand.MenuLeft);
            AddCrossBinding(GameCommand.Right, GameCommand.MenuRight);
            AddCrossBinding(GameCommand.Action1, GameCommand.MenuConfirm);
            AddCrossBinding(GameCommand.Action2, GameCommand.MenuCancel);
            AddCrossBinding(GameCommand.Action3, GameCommand.MenuConfirm);
            AddCrossBinding(GameCommand.MenuUp, GameCommand.Up);
            AddCrossBinding(GameCommand.MenuDown, GameCommand.Down);
            AddCrossBinding(GameCommand.MenuLeft, GameCommand.Left);
            AddCrossBinding(GameCommand.MenuRight, GameCommand.Right);

            Default();
        }
Esempio n. 2
0
        public static void UpdateAliases()
        {
            //ClearAliases();

            // Copy commands to alias list.
            for (int i = 0; i < inputNodeList.Length; i++)
            {
                aliasNodeList[i].Clear();
                foreach (UniversalInputCombo ic in inputNodeList[i].InternalInputCombos)
                {
                    aliasNodeList[i].AddCombo(ic.ToString());
                }
            }

            // Create requested aliases as long as there are no conflicts.
            foreach (Tuple <GameCommand, GameCommand> cb in crossBindings)
            {
                //if ((int)cb.Item1 >= (int)GameCommand.MenuUp) continue;
                //if ((int)cb.Item2 < (int)GameCommand.MenuUp) continue;
                InputNode leftNode       = inputNodeList[(int)cb.Item1];
                InputNode rightAliasNode = aliasNodeList[(int)cb.Item2];
                //foreach (UniversalInputCombo ic in leftNode.InternalInputCombos)
                for (int i = 0; i < leftNode.InternalInputCombos.Count; i++)
                {
                    UniversalInputCombo ic = leftNode.InternalInputCombos[i];
                    bool used = false;
                    int  startJ, endJ;
                    if ((int)cb.Item1 < (int)GameCommand.MenuUp)
                    {
                        startJ = (int)GameCommand.MenuUp;
                        endJ   = (int)GameCommand.Save;
                    }
                    else
                    {
                        startJ = (int)GameCommand.Up;
                        endJ   = (int)GameCommand.MenuUp;
                    }
                    for (int j = startJ; j < endJ; j++)
                    {
                        InputNode otherNode = inputNodeList[j];
                        if (otherNode.Conflict(ic))
                        {
                            used = true;
                            break;
                        }
                    }
                    if (!used)
                    {
                        rightAliasNode.AddCombo(leftNode.InternalInputCombos[i].ToString());
                    }
                }
            }

            Reset();
        }