/// <summary> /// Initializes a new XConsole. /// </summary> /// <param name="services">A service provider where the console can find the IKeyboardInputService and IGraphicsDeviceService.</param> /// <param name="fontName">The name of a font to use for the console. Must be relative path from executable.</param> public GameConsole(IServiceProvider services, string fontName) { // only allow one instance at a time if (Instance != null) throw new InvalidOperationException("Only one XConsole can exist. Use XConsole.Instance to access it."); Instance = this; // attempt to get the input service try { keyboard = services.GetService(typeof(IKeyboardInputService)) as IKeyboardInputService; } catch { keyboard = null; } finally { if (keyboard == null) throw new InvalidOperationException("Could not find IKeyboardInputService in services."); } // attempt to get the graphics service try { graphics = services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService; } catch { graphics = null; } finally { if (graphics == null) throw new InvalidOperationException("Could not find IGraphicsDeviceService in services."); } // create our content manager content = new ContentManager(services); // initialize some state CurrentState = State.Closed; ToggleKey = Keys.OemTilde; this.fontName = fontName; KeyToCharacter = KeyString.KeyToString; StringParser = new DefaultStringParser(); BackgroundOpacity = .6f; // register all the default console commands RegisterDefaultCommands(); }
/// <summary> /// Initializes a new XConsole. /// </summary> /// <param name="services">A service provider where the console can find the IKeyboardInputService and IGraphicsDeviceService.</param> /// <param name="fontName">The name of a font to use for the console. Must be relative path from executable.</param> public XConsole() { // only allow one instance at a time if (Instance != null) throw new InvalidOperationException("Only one XConsole can exist. Use XConsole.Instance to access it."); Instance = this; // initialize some state CurrentState = ConsoleState.Closed; ToggleKey = Keys.OemTilde; KeyToCharacter = KeyString.KeyToString; StringParser = new DefaultStringParser(); BackgroundOpacity = .6f; // register all the default console commands RegisterDefaultCommands(); }