Exemplo n.º 1
0
        private void SetupGameConsole()
        {
            GameConsole.Initialize(this, "DiagnosticFont", Color.White, Color.Black, 0.5f, 15);
            IGameConsole console = (IGameConsole)Services.GetService(typeof(IGameConsole));

            console.LoadStuff();
            console.Log("Type '?' for help");

            console.BindCommandHandler("?", delegate(GameTime time, string[] args)
            {
                console.Log("Commands");
                console.Log("--------");
                //console.Log("PrintArgs [arg1] [arg2] [arg3] ... - Prints the list of arguments passed to it, one per line");
                //console.Log("PrintLine [text] - Prints the specified text to the console");
                //console.Log("SetDefaultLogLevel [level] - Sets the default log level to the specified level");
                //console.Log("SetEchoLogLevel [level] - Sets the log level for echoed output from user input");
                //console.Log("SetLogLevelThreshold [threshold] - Sets the log level threshold to the specified threshold value");
                //console.Log("SetDisplayLevelThreshold [threshold] - Sets the display level threshold to the specified threshold value");
                //console.Log("ToggleEchoEnabled - Toggles the auto input echo feature");
                //console.Log("ToggleTimestamp - Toggles the display of each message's timestamp");
                //console.Log("ToggleLogLevel - Toggles the display of each message's log level");
                //console.Log("SetTextColor [r] [g] [b] - Sets the default text color of console text, where r, g, and b are in the range 0-255");
                //console.Log("SetLogLevelColor [level] [r] [g] [b] - Sets the text color for the specified log level, where r, g and b are in the range 0-255");
                console.Log("SetGameBackgroundColor [r] [g] [b] - Sets the game back color, where r, g and b are in the range 0-255");
                console.Log("SceneStats - Displays the stats of the currently active scene");
            });

            console.BindCommandHandler("PrintArgs", delegate(GameTime time, string[] args)
            {
                foreach (string arg in args)
                {
                    console.Log(arg);
                }
            }, ' ');

            console.BindCommandHandler("SceneStats", delegate(GameTime time, string[] args)
            {
                string _str = "";
                _str        = "Scene Items Count : " + SceneManager.ActiveScene.SceneItems.Count.ToString();
                console.Log(_str);
            }, ' ');


            console.BindCommandHandler("SetGameBackgroundColor", delegate(GameTime time, string[] args)
            {
                if (args.Length < 3)
                {
                    return;
                }

                try
                {
                    byte r = byte.Parse(args[0]);
                    byte g = byte.Parse(args[1]);
                    byte b = byte.Parse(args[2]);

                    console.TextColor = new Color(r, g, b, 255);
                }
                catch { }
            }, ' ');
            console.BindCommandHandler("PrintLine", delegate(GameTime time, string[] args)
            {
                if (args.Length == 0)
                {
                    return;
                }

                console.Log(args[0]);
            });

            console.BindCommandHandler("SetDefaultLogLevel", delegate(GameTime time, string[] args)
            {
                if (args.Length == 0)
                {
                    return;
                }

                try
                {
                    console.DefaultLogLevel = uint.Parse(args[0]);
                }
                catch { }
            }, ' ');

            console.BindCommandHandler("SetEchoLogLevel", delegate(GameTime time, string[] args)
            {
                if (args.Length == 0)
                {
                    return;
                }

                try
                {
                    console.EchoLogLevel = uint.Parse(args[0]);
                }
                catch { }
            }, ' ');

            console.BindCommandHandler("SetLogLevelThreshold", delegate(GameTime time, string[] args)
            {
                if (args.Length == 0)
                {
                    return;
                }

                try
                {
                    console.LogLevelThreshold = int.Parse(args[0]);
                }
                catch { }
            }, ' ');

            console.BindCommandHandler("SetDisplayLevelThreshold", delegate(GameTime time, string[] args)
            {
                if (args.Length == 0)
                {
                    return;
                }

                try
                {
                    console.DisplayLevelThreshold = int.Parse(args[0]);
                }
                catch { }
            }, ' ');

            console.BindCommandHandler("ToggleEchoEnabled", delegate(GameTime time, string[] args)
            {
                console.EchoEnabled = !console.EchoEnabled;
            });

            console.BindCommandHandler("ToggleTimestamp", delegate(GameTime time, string[] args)
            {
                if ((console.DisplayOptions & ConsoleDisplayOptions.TimeStamp) == ConsoleDisplayOptions.TimeStamp)
                {
                    console.DisplayOptions &= ~ConsoleDisplayOptions.TimeStamp;
                }
                else
                {
                    console.DisplayOptions |= ConsoleDisplayOptions.TimeStamp;
                }
            });

            console.BindCommandHandler("ToggleLogLevel", delegate(GameTime time, string[] args)
            {
                if ((console.DisplayOptions & ConsoleDisplayOptions.LogLevel) == ConsoleDisplayOptions.LogLevel)
                {
                    console.DisplayOptions &= ~ConsoleDisplayOptions.LogLevel;
                }
                else
                {
                    console.DisplayOptions |= ConsoleDisplayOptions.LogLevel;
                }
            });

            console.BindCommandHandler("SetTextColor", delegate(GameTime time, string[] args)
            {
                if (args.Length < 3)
                {
                    return;
                }

                try
                {
                    byte r = byte.Parse(args[0]);
                    byte g = byte.Parse(args[1]);
                    byte b = byte.Parse(args[2]);

                    console.TextColor = new Color(r, g, b, 255);
                }
                catch { }
            }, ' ');

            console.BindCommandHandler("SetLogLevelColor", delegate(GameTime time, string[] args)
            {
                if (args.Length < 4)
                {
                    return;
                }

                try
                {
                    uint level = uint.Parse(args[0]);
                    byte r     = byte.Parse(args[1]);
                    byte g     = byte.Parse(args[2]);
                    byte b     = byte.Parse(args[3]);

                    console.SetLogLevelCustomColor(level, new Color(r, g, b, 255));
                }
                catch { }
            }, ' ');
        }