Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandConsole"/> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="assemblies">The assemblies containing commands and options to add to this <see cref="CommandConsole"/> instance.</param>
        public CommandConsole(Game game, SpriteFont font, Control parent, params Assembly[] assemblies)
            : base(parent)
        {
            engine = new CommandEngine(assemblies);

            PresentationParameters pp = game.GraphicsDevice.PresentationParameters;

            SetSize(0, pp.BackBufferHeight / 3);
            SetPoint(Points.Top, 0, 5);
            SetPoint(Points.Left, 5, 0);
            SetPoint(Points.Right, -5, 0);
            Strata = new ControlStrata()
            {
                Layer = Layer.Overlay, Offset = 100
            };
            FocusPriority    = int.MaxValue;
            LikesHavingFocus = false;
            IsVisible        = false;
            RespectSafeArea  = true;
            ToggleKey        = Keys.Oem8;

            //var font = Content.Load<SpriteFont>(game, "Consolas");
            //skin = Content.Load<Skin>(game, "Console");
            //skin.BackgroundColour = new Color(1f, 1f, 1f, 0.8f);
            background = new Texture2D(game.GraphicsDevice, 1, 1);
            background.SetData(new Color[] { Color.Black });

            textBox = new TextBox(this, game, font, "Command Console", "Enter you command");
            textBox.SetPoint(Points.Bottom, 0, -3);
            textBox.SetPoint(Points.Left, 3, 0);
            textBox.SetPoint(Points.Right, -3, 0);
            textBox.FocusPriority   = 1;
            textBox.FocusedChanged += c => { if (c.IsFocused)
                                             {
                                                 textBox.BeginTyping(PlayerIndex.One);
                                             }
            };
            textBox.IgnoredCharacters.Add('`');

            log = new TextLog(this, font, (int)(3 * Area.Height / (float)font.LineSpacing));
            log.SetPoint(Points.TopLeft, 3, 3);
            log.SetPoint(Points.TopRight, -3, 3);
            log.SetPoint(Points.Bottom, 0, 0, textBox, Points.Top);
            log.WriteLine("Hello world");

            tabCompletion = new Label(this, font);
            tabCompletion.SetSize(300, 0);
            tabCompletion.SetPoint(Points.TopLeft, 3, 6, this, Points.BottomLeft);

            infoBox = new Label(this, font);
            infoBox.SetPoint(Points.TopRight, -3, 6, this, Points.BottomRight);

            AreaChanged += delegate(Frame c)
            {
                infoBox.SetSize(Math.Max(0, c.Area.Width - 311), 0);
            };

            commandStack = new CommandStack(textBox, Gestures);

#if WINDOWS
            ConsoleTraceListener cts = new ConsoleTraceListener(this);
            Listener = cts;
            Trace.Listeners.Add(cts);

            Engine.AddCommand(cts.RegexFilter, "AddFilter", "Console.Trace.AddFilter");
            Engine.AddCommand(cts.RegexFilter, "ListFilters", "Console.Trace.ListFilters");
            Engine.AddCommand(cts.RegexFilter, "RemoveAt", "Console.Trace.RemoveFilter");
#endif

            BindGestures();

            Gestures.BlockedDevices.Add(typeof(KeyboardDevice));
        }