/// <summary> /// Initializes a new instance of the class, which creates a console for executing commands while running a game. /// </summary> /// <param name="game"></param> /// <param name="interp"></param> /// <param name="font"></param> public XnaConsoleComponent(Game game, SpriteFont font) : base(game) { this.game = game; device = game.GraphicsDevice; spriteBatch = new SpriteBatch(device); this.font = font; background = new Texture2D(device, 1, 1); background.SetData<Color>(new Color[1] { new Color(0, 0, 0, 125) }); InputBuffer = ""; history = new History(); WriteLine("###"); WriteLine("### " + Version); WriteLine("###"); consoleXSize = Game.Window.ClientBounds.Right - Game.Window.ClientBounds.Left - 20; consoleYSize = font.LineSpacing * LinesDisplayed + 20; lineWidth = (int)(consoleXSize / font.MeasureString("a").X) - 2; //calculate number of letters that fit on a line, using "a" as example character State = ConsoleState.Closed; StateStartTime = 0; LastKeyState = this.CurrentKeyState = Keyboard.GetState(); firstInterval = 500f; repeatInterval = 50f; //used for repeating keystrokes keyTimes = new Dictionary<Keys, double>(); for (int i = 0; i < Enum.GetValues(typeof(Keys)).Length; i++) { Keys key = (Keys)Enum.GetValues(typeof(Keys)).GetValue(i); keyTimes[key] = 0f; } }
public GameManager() { _gameSize = new Size(BlockSize * 4, BlockSize * 4); _consoleManager = new ConsoleManager(); _consoleState = _consoleManager.SaveConsoleState(); _consoleManager.SetForGraphics(); _consoleManager.ResizeConsoleWindow(_gameSize); }
//todo: add in task cancellation tokens automatically generated and passed to the menu items! protected override void RunItem(ConsoleState state, MenuItem item) { var task = Task.Run(() => base.RunItem(state, item)); lock (_locker) { _tasks.Add(task); } }
public Mobile(string hostName, string deviceId, string deviceAccessKey, TransportType transportType) : base(hostName, deviceId, deviceAccessKey, transportType) { _state = new MobileState { Id = deviceId, }; _consoleState = null; _consoleTelemetry = null; }
/// <summary> /// Method, which allows user to show Console and define its state. /// </summary> /// <param name="state">Initial state of console</param> public static void ShowConsole(ConsoleState state = ConsoleState.Show, bool clear = true) { if (clear) { Console.Clear(); } State = state; Console.ForegroundColor = ConsoleColor.White; }
public void Clear() { currentState = ConsoleState.GridSize; currentGrid = null; currentRobot = null; System.Console.WriteLine("Input size of grid"); }
public DevConsole(Main game) { this.game = game; prevState = currentState; backgroundTexture = game.textureHandler.consoleBG; selectedBackgroundTexture = game.textureHandler.consoleSelectedBG; consoleFont = game.fontHandler.devFont; bounds = new Rectangle(0, -300, 500, 300); currentLine = ""; }
void Awake() { Guard.CheckIsNull(_inputText, "InputText", gameObject); Guard.CheckIsNull(_reportText, "ReportText", gameObject); Guard.CheckIsNull(_inputField, "InputField", gameObject); Instance = this; ConsoleState = ConsoleState.Closed; RegisterCommands(); }
public XNAConsole(Game game) : base(game) { Visible = false; AnimationTime = 0.3f; MaxLineCount = 20; consoleState = ConsoleState.Closed; stateStartTime = 0; outputBuffer = new StringBuilder(1024); stringWriter = new StringWriter(outputBuffer); Console.SetOut(stringWriter); }
public void TextSplitLines_Should_Return_Expected() { // arrange var state = new ConsoleState(new InputHistory()); state.Text.Append($"test code line 1{NewLine}test code line 2{NewLine}test code line 3"); // act var lines = state.TextSplitLines; // assert Assert.That(lines.Length, Is.EqualTo(3)); }
private void RunItem(ConsoleState state, MenuItem item) { try { _menuConsole.State = state; BeforeMenu(); item.Action?.Invoke(); item.ConsoleAction?.Invoke(_output); } finally { AfterMenu(); _menuConsole.State = state; } }
public void IsEndOfTextPosition_Should_Return_Expected(int linePosition, bool expectedIsEnd) { // arrange var state = new ConsoleState(new InputHistory()) { ColPosition = linePosition }; state.Text.Append("line1\nline2\nline3"); // act var isEndOfTextPosition = state.IsEndOfTextPosition(); // assert Assert.That(isEndOfTextPosition, Is.EqualTo(expectedIsEnd)); }
public void CurrentLineText_Should_Return_Expected_Line_When_Row_Position( string fullText, int textRowPosition, string expectedText) { // arrange var state = new ConsoleState(new InputHistory()); state.Text.Append(fullText); state.TextRowPosition = textRowPosition; // act var line = state.CurrentLineText; // assert Assert.That(line, Is.EqualTo(expectedText)); Assert.That(state.Text.ToString(), Is.EqualTo(fullText)); }
public override void Update(GameTime gameTime) { double now = gameTime.TotalGameTime.TotalSeconds; double elapsedTime = gameTime.ElapsedGameTime.TotalMilliseconds; switch (consoleState) { case ConsoleState.Opening: if (now - stateStartTime > AnimationTime) { consoleState = ConsoleState.Open; stateStartTime = now; } break; case ConsoleState.Closing: if (now - stateStartTime > AnimationTime) { consoleState = ConsoleState.Closed; stateStartTime = now; Visible = false; } break; case ConsoleState.Open: if (InputManager.IsKeyPressed(Keys.OemTilde)) { consoleState = ConsoleState.Closing; stateStartTime = now; } break; case ConsoleState.Closed: if (InputManager.IsKeyPressed(Keys.OemTilde)) { consoleState = ConsoleState.Opening; stateStartTime = now; Visible = true; } break; } if (Visible) { CheckInput(); } }
public XNAConsole(Game game, SpriteFont font) : base(game) { this.Visible = false; device = game.GraphicsDevice; spriteBatch = new SpriteBatch(device); this.font = font; background = new Texture2D(device, 1, 1, false, SurfaceFormat.Color); background.SetData<Color>(new Color[1] { new Color(0, 0, 0, 125) }); consoleXSize = Game.Window.ClientBounds.Right - Game.Window.ClientBounds.Left - 20; consoleYSize = font.LineSpacing * LinesDisplayed + 20; lineWidth = (int)((consoleXSize - 20) / font.MeasureString("a").X) - 2; State = ConsoleState.Closed; StateStartTime = 0; LastKeyState = this.CurrentKeyState = Keyboard.GetState(); OutputBuffer = ""; }
public void Toggle() { switch (State) { case ConsoleState.Closed: State = ConsoleState.Open; break; case ConsoleState.Open: State = ConsoleState.OpenNoInput; break; case ConsoleState.OpenNoInput: State = ConsoleState.FullOpen; break; case ConsoleState.FullOpen: State = ConsoleState.FullOpenNoInput; break; case ConsoleState.FullOpenNoInput: State = ConsoleState.Closed; break; } }
public void ReloadErbFinished() { state = prevState; PrintLine(" "); if (timer_suspended) { timer_suspended = false; timer.Start(); } }
public void ReloadFolder(string erbPath) { if (state == ConsoleState.Error) { MessageBox.Show("エラー発生時はこの機能は使えません"); return; } if (state == ConsoleState.Initializing) { MessageBox.Show("初期化中はこの機能は使えません"); return; } if (timer != null && timer.Enabled) { timer.Stop(); timer_suspended = true; } List<string> paths = new List<string>(); SearchOption op = SearchOption.AllDirectories; if (!Config.SearchSubdirectory) op = SearchOption.TopDirectoryOnly; string[] fnames = Directory.GetFiles(erbPath, "*.ERB", op); for (int i = 0; i < fnames.Length; i++) if (Path.GetExtension(fnames[i]).ToUpper() == ".ERB") paths.Add(fnames[i]); bool notRedraw = false; if (redraw == ConsoleRedraw.None) { notRedraw = true; redraw = ConsoleRedraw.Normal; } prevState = state; state = ConsoleState.Initializing; PrintSingleLine("ERB再読み込み中……", false, true); force_temporary = true; emuera.ReloadPartialErb(paths); force_temporary = false; PrintSingleLine("再読み込み完了", false, true); RefreshStrings(true); //強制的にボタン世代が切り替わるのを防ぐ updatedGeneration = true; if (notRedraw) redraw = ConsoleRedraw.None; }
public void ReadStringWithTimer(Int64 time, string def_result, Int64 isDisplay, bool isOne, string label) { results = def_result; state = (isOne) ? ConsoleState.WaitOneStringWithTimer : ConsoleState.WaitStringWithTimer; isDisp = isDisplay != 0; timeup_label = label; if (isOne) window.update_lastinput(); setTimer((int)time); }
public void ReadSystemInteger() { state = ConsoleState.WaitSystemInteger; }
public void waitInputWithTimer(Int64 time, Int64 flag) { if (flag == 0) state = ConsoleState.WaitKeyWithTimer; else state = ConsoleState.WaitKeyWithTimerF; isDisp = false; setTimer((int)time); }
public void ReadString(string def) { state = ConsoleState.WaitString; defStr = def; hasDefValue = true; }
public void ReadOneInteger() { state = ConsoleState.WaitOneInteger; }
public void ThrowError(bool playSound) { if (playSound) System.Media.SystemSounds.Hand.Play(); forceUpdateGeneration(); UseUserStyle = false; PrintFlush(false); state = ConsoleState.Error; }
public void ReadAnyKeyForce() { emuera.NeedWaitToEventComEnd = false; state = ConsoleState.WaitKey; isForceWait = true; }
public void ReadInteger() { state = ConsoleState.WaitInteger; }
public void GotoTitle() { //if (state == ConsoleState.Error) //{ // MessageBox.Show("エラー発生時はこの機能は使えません"); //} if (timer != null && timer.Enabled) stopTimer(); displayLineList.Clear(); ClearDisplay(); logicalLineCount = 0; lineNo = 0; lastDrawnLineNo = -1; if (redraw == ConsoleRedraw.None) redraw = ConsoleRedraw.Normal; useUserStyle = false; userStyle = new StringStyle(Config.ForeColor, FontStyle.Regular, null); emuera.BeginTitle(); state = ConsoleState.WaitKey; callEmueraProgram(""); RefreshStrings(true); }
private void endTimer(object sender, EventArgs e) { countTime += 100; if (countTime >= timeLimit) { if (wait_timeout) return; stopTimer(); isTimeout = true; if (isDisp) changeLastLine(timeup_label); else if (state != ConsoleState.WaitKeyWithTimer && state != ConsoleState.WaitKeyWithTimerF) PrintLine(timeup_label); if (state == ConsoleState.WaitIntegerWithTimer || state == ConsoleState.WaitOneIntegerWithTimer) state = ConsoleState.Timeout; else if (state == ConsoleState.WaitStringWithTimer || state == ConsoleState.WaitOneStringWithTimer) state = ConsoleState.Timeouts; callEmueraProgram(""); RefreshStrings(true); return; } if (!isDisp) return; int time = (timeLimit - countTime) / 100; string timeString1 = "残り "; string timeString2 = ((double)time / 10.0).ToString(); changeLastLine(timeString1 + timeString2); }
public void ReloadPartialErb(List<string> path) { if (state == ConsoleState.Error) { MessageBox.Show("エラー発生時はこの機能は使えません"); return; } if (state == ConsoleState.Initializing) { MessageBox.Show("初期化中はこの機能は使えません"); return; } bool notRedraw = false; if (redraw == ConsoleRedraw.None) { notRedraw = true; redraw = ConsoleRedraw.Normal; } if (timer != null && timer.Enabled) { timer.Stop(); timer_suspended = true; } prevState = state; state = ConsoleState.Initializing; PrintSingleLine("ERB再読み込み中……", false, true); force_temporary = true; emuera.ReloadPartialErb(path); force_temporary = false; PrintSingleLine("再読み込み完了", false, true); RefreshStrings(true); //強制的にボタン世代が切り替わるのを防ぐ updatedGeneration = true; if (notRedraw) redraw = ConsoleRedraw.None; }
public void ReadOneInteger(Int64 def) { state = ConsoleState.WaitOneInteger; defNum = def; hasDefValue = true; }
public EmueraConsole(MainWindow parent) { window = parent; //1.713 この段階でsetStBarを使用してはいけない //setStBar(StaticConfig.DrawLineString); state = ConsoleState.Initializing; if (Config.FPS > 0) msPerFrame = 1000 / (uint)Config.FPS; displayLineList = new List<ConsoleDisplayLine>(); printBuffer = new PrintStringBuffer(this); MainPicBoxSizeChanged(); }
public void ReadString() { state = ConsoleState.WaitString; }
public void ThrowTitleError(bool error) { state = ConsoleState.Error; notToTitle = true; byError = error; }
/// <summary> /// Opens the console /// </summary> public void Open() { if (State == ConsoleState.Closed) { State = ConsoleState.Opening; this.Visible = true; } }
private void callEmueraProgram(string str) { if (!doInputToEmueraProgram(str)) return; if (state == ConsoleState.Error) return; state = ConsoleState.Running; emuera.DoScript(); if (state == ConsoleState.Running) {//RunningならProcessは処理を継続するべき state = ConsoleState.Error; PrintError("emuera.exeのエラー:プログラムの状態を特定できません"); } if (state == ConsoleState.Error && !noOutputLog) outputLog("emuera.log"); PrintFlush(false); newGeneration(); }
public override void Update(GameTime gameTime) { double now = gameTime.TotalRealTime.TotalSeconds; double elapsedTime = gameTime.ElapsedGameTime.TotalMilliseconds; //time since last update call //get keyboard state LastKeyState = CurrentKeyState; CurrentKeyState = Keyboard.GetState(); #region Closing & Opening states management if (State == ConsoleState.Closing) { if (now - StateStartTime > AnimationTime) { State = ConsoleState.Closed; StateStartTime = now; } return; } if (State == ConsoleState.Opening) { if (now - StateStartTime > AnimationTime) { State = ConsoleState.Open; StateStartTime = now; } return; } #endregion #region Closed state management if (State == ConsoleState.Closed) { State = ConsoleState.Opening; StateStartTime = now; this.Visible = true; } #endregion if (State == ConsoleState.Open) { #region initialize closing animation if user presses ` or ~ if (IsKeyPressed(Keys.OemTilde)) { State = ConsoleState.Closing; StateStartTime = now; return; } #endregion //execute current line with the interpreter if (IsKeyPressed(Keys.Enter)) { if (InputBuffer.Length > 0) { history.Add(InputBuffer); //add command to history } WriteLine(InputBuffer); input(InputBuffer); InputBuffer = ""; cursorPos = 0; } //erase previous letter when backspace is pressed if (KeyPressWithRepeat(Keys.Back, elapsedTime)) { if (cursorPos > 0) { InputBuffer = InputBuffer.Remove(cursorPos-1, 1); cursorPos--; } } //delete next letter when delete is pressed if (KeyPressWithRepeat(Keys.Delete, elapsedTime)) { if (InputBuffer.Length != 0) InputBuffer = InputBuffer.Remove(cursorPos, 1); } //cycle backwards through the command history if (KeyPressWithRepeat(Keys.Up, elapsedTime)) { InputBuffer = history.Previous(); cursorPos = InputBuffer.Length; } //cycle forwards through the command history if (KeyPressWithRepeat(Keys.Down, elapsedTime)) { InputBuffer = history.Next(); cursorPos = InputBuffer.Length; } //move the cursor to the right if (KeyPressWithRepeat(Keys.Right, elapsedTime) && cursorPos != InputBuffer.Length) { cursorPos++; } //move the cursor left if (KeyPressWithRepeat(Keys.Left, elapsedTime) && cursorPos > 0) { cursorPos--; } //move the cursor to the beginning of the line if (IsKeyPressed(Keys.Home)) { cursorPos = 0; } //move the cursor to the end of the line if (IsKeyPressed(Keys.End)) { cursorPos = InputBuffer.Length; } //get a letter from input string nextChar = GetStringFromKeyState(elapsedTime); //only add it if it isn't null if (nextChar != "") { //if the cursor is at the end of the line, add the letter to the end if (InputBuffer.Length == cursorPos) { InputBuffer += nextChar; } //otherwise insert it where the cursor is else { InputBuffer = InputBuffer.Insert(cursorPos, nextChar); } cursorPos += nextChar.Length; } } }
public void DebugCommand(string com, bool munchkin, bool outputDebugConsole) { ConsoleState temp_state = state; isDebug = true; //スクリプト等が失敗した場合に備えて念のための保存 GlobalStatic.Process.saveCurrentState(false); try { LogicalLine line = null; if (!com.StartsWith("@") && !com.StartsWith("\"") && !com.StartsWith("\\")) line = LogicalLineParser.ParseLine(com, null); if (line == null || (line is InvalidLine)) { WordCollection wc = LexicalAnalyzer.Analyse(new StringStream(com), LexEndWith.EoL, false, false); IOperandTerm term = ExpressionParser.ReduceExpressionTerm(wc, TermEndWith.EoL); if (term == null) throw new CodeEE("解釈不能なコードです"); if (term.GetOperandType() == typeof(Int64)) { if (outputDebugConsole) com = "DEBUGPRINTFORML {" + com + "}"; else com = "PRINTVL " + com; } else { if (outputDebugConsole) com = "DEBUGPRINTFORML %" + com + "%"; else com = "PRINTFORMSL " + com; } line = LogicalLineParser.ParseLine(com, null); } if (line == null) throw new CodeEE("解釈不能なコードです"); if (line is InvalidLine) throw new CodeEE(line.ErrMes); if (!(line is InstructionLine)) throw new CodeEE("デバッグコマンドで使用できるのは代入文か命令文だけです"); InstructionLine func = (InstructionLine)line; if (func.Function.IsFlowContorol()) throw new CodeEE("フロー制御命令は使用できません"); //__METHOD_SAFE__をみるならいらないかも if (func.Function.IsWaitInput()) throw new CodeEE(func.Function.Name + "命令は使用できません"); //1750 __METHOD_SAFE__とほぼ条件同じだよねってことで if (!func.Function.IsMethodSafe()) throw new CodeEE(func.Function.Name + "命令は使用できません"); //1756 SIFの次に来てはいけないものはここでも不可。 if (func.Function.IsPartial()) throw new CodeEE(func.Function.Name + "命令は使用できません"); switch (func.FunctionCode) {//取りこぼし //逆にOUTPUTLOG、QUITはDebugCommandの前に捕まえる case FunctionCode.PUTFORM: case FunctionCode.UPCHECK: case FunctionCode.CUPCHECK: case FunctionCode.SAVEDATA: throw new CodeEE(func.Function.Name + "命令は使用できません"); } ArgumentParser.SetArgumentTo(func); if (func.IsError) throw new CodeEE(func.ErrMes); emuera.DoDebugNormalFunction(func, munchkin); if (func.FunctionCode == FunctionCode.SET) { if (!outputDebugConsole) PrintLine(com); //DebugWindowのほうは少しくどくなるのでいらないかな } } catch (Exception e) { if (outputDebugConsole) { DebugPrint(e.Message); DebugNewLine(); } else PrintError(e.Message); emuera.clearMethodStack(); } finally { //確実に元の状態に戻す GlobalStatic.Process.loadPrevState(); isDebug = false; state = temp_state; } }
public void Quit() { state = ConsoleState.Quit; }
public void Initialize() { GlobalStatic.Console = this; GlobalStatic.MainWindow = window; emuera = new GameProc.Process(this); GlobalStatic.Process = emuera; if (Program.DebugMode && Config.DebugShowWindow) { OpenDebugDialog(); window.Focus(); } ClearDisplay(); if (!emuera.Initialize()) { state = ConsoleState.Error; outputLog(null); PrintFlush(false); RefreshStrings(true); return; } callEmueraProgram(""); RefreshStrings(true); }
public void ReadAnyKeyAndGo() { emuera.NeedWaitToEventComEnd = false; state = ConsoleState.WaitAnyKey; }