// draw debug information public static void DrawDebug() { // draw registers string regs = ""; for (int i = 0; i < MaxRegisters; i++) { regs += DataUtils.IntToHex(Registers[i], "X2") + " "; } if (regs.Length > 0) { TextGraphics.DrawString(0, CLI.Height - 1, regs, Color.Cyan, CLI.BackColor); } // draw program counter TextGraphics.DrawString(48, CLI.Height - 1, "PC=" + DataUtils.IntToHex(ProgCtr), Color.Yellow, CLI.BackColor); // draw i register TextGraphics.DrawString(58, CLI.Height - 1, "I=" + DataUtils.IntToHex(I), Color.Green, CLI.BackColor); // draw w register TextGraphics.DrawString(67, CLI.Height - 1, "W=" + DataUtils.IntToHex(W), Color.Magenta, CLI.BackColor); // draw waiting TextGraphics.DrawString(72, CLI.Height - 1, "WAIT=" + (IsWaiting ? "1" : "0"), Color.DarkRed, CLI.BackColor); }
private static void Save() { // save file string document = ""; try { for (int i = 0; i < Lines.Count; i++) { document += Lines[i] + "\n"; } PMFAT.WriteAllText(CurrentFile, document); TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "Successfully saved \"" + CurrentFile + "\"", Color.Green, Color.Black); } catch (Exception ex) { TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "Unable to save file \"" + CurrentFile + "\"", Color.Red, Color.Black); } // finish Kernel.Delay(500); Draw(); }
/// <summary> /// Draws the table of inventory items. /// </summary> /// <param name="invItems">The List of the items in the inventory table.</param> /// <param name="selectedItem">The currently selected item.</param> private void DrawInventoryItems(List <InvItem> invItems, InvItem selectedItem) { textGraphics.DrawString(this.pixels, "You are carrying:", 11 * 8, 0 * 8, 0, 15); foreach (InvItem invItem in invItems) { if ((invItem == selectedItem) && state.Flags[Defines.ENABLE_SELECT]) { textGraphics.DrawString(this.pixels, invItem.Name, invItem.Col * 8, invItem.Row * 8, 15, 0); } else { textGraphics.DrawString(this.pixels, invItem.Name, invItem.Col * 8, invItem.Row * 8, 0, 15); } } if (state.Flags[Defines.ENABLE_SELECT]) { textGraphics.DrawString(this.pixels, "Press ENTER to select, ESC to cancel", 2 * 8, 24 * 8, 0, 15); } else { textGraphics.DrawString(this.pixels, "Press a key to return to the game", 4 * 8, 24 * 8, 0, 15); } }
private void SetupScreen() { CLI.ForceClear(Color.Black); Shell.DrawTitleBar(); TextGraphics.FillRect(2, 2, CLI.Width - 4, CLI.Height - 3, ' ', Color.White, Color.Blue); TextGraphics.DrawLineH(2, 2, CLI.Width - 4, ' ', Color.White, Color.Cyan); TextGraphics.DrawString(2, 2, " CMD DESCRIPTION", Color.Black, Color.Cyan); TextGraphics.DrawLineH(0, 3, CLI.Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(Shell.TitleBarTime.Length, 0, " | Run \"help [cmd]\" for usage", Shell.TitleColor, Shell.TitleBarColor); CLI.SetCursorPos(2, 2); }
private static void Load() { // draw Draw(); TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "FILENAME: ", Color.White, Color.Black); CLI.SetCursorPos(10, StartY); // get file string file = Console.ReadLine(); // load file LoadFile(file); }
public static void LoadFile(string file) { // format filename if (!file.StartsWith(@"0:\")) { file = @"0:\" + file; } // load file bool error = false; if (PMFAT.FileExists(file)) { try { string[] lines = PMFAT.ReadLines(file); Clear(false); for (int i = 0; i < lines.Length; i++) { Lines.Add(lines[i]); } TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "Successfully loaded \"" + file + "\"", Color.Green, Color.Black); error = false; } catch (Exception ex) { error = true; } } else { error = true; } if (error) { TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "Unable to load file \"" + file + "\"", Color.Red, Color.Black); } if (!error) { CurrentFile = file; } Kernel.Delay(500); Draw(); ReadInput(); }
public override void Execute(string line, string[] args) { // show menu if (args.Length == 1) { // draw SetupScreen(); DrawMessage(); // exit message TextGraphics.DrawString(2, CLI.Height - 2, "Press any key to exit...", Color.White, Color.Blue); // exit CLI.SetCursorPos(CLI.Width - 13, 0); CLI.ReadKey(true); Shell.DrawFresh(); } // show command usage else { string cmd = args[1].ToUpper(); bool invalid = false; for (int i = 0; i < Shell.Commands.Count; i++) { if (Shell.Commands[i].Name == cmd) { CLI.WriteLine(Shell.Commands[i].Help); if (Shell.Commands[i].Usage.Length > 0) { CLI.WriteLine(Shell.Commands[i].Usage, Color.Gray); } invalid = false; break; } else { invalid = true; } } if (invalid) { CLI.WriteLine("Invalid argument!", Color.Red); CLI.WriteLine("Type help without an argument to see available commands.", Color.White); } } }
private static void SaveAs() { // draw Draw(); TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "FILENAME: ", Color.White, Color.Black); CLI.SetCursorPos(10, StartY); // get file string file = Console.ReadLine(); // format filename if (!file.StartsWith(@"0:\")) { file = @"0:\" + file; } // save file string document = ""; try { for (int i = 0; i < Lines.Count; i++) { document += Lines[i] + "\n"; } PMFAT.WriteAllText(file, document); TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "Successfully saved \"" + file + "\"", Color.Green, Color.Black); } catch (Exception ex) { TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "Unable to save file \"" + file + "\"", Color.Red, Color.Black); } // finish CurrentFile = file; Kernel.Delay(500); Draw(); }
private static void Draw() { // draw fresh DrawFresh(); // draw document for (int i = 0; i < CLI.Height; i++) { int pos = i + Scroll; if (pos < Lines.Count) { TextGraphics.DrawString(StartX, StartY + i, Lines[pos], Color.Black, Color.White); } } // draw doc pos TextGraphics.DrawString(Shell.TitleBarTime.Length, 0, " | CUR: " + DocX.ToString() + " LINE:" + DocY.ToString(), Shell.TitleColor, Shell.TitleBarColor); // return cursor position to document SendScreenPos(); }
private void DrawMessage() { int dx = 3, dy = 4; for (int i = 0; i < Shell.Commands.Count; i++) { TextGraphics.DrawString(dx, dy, "---------------------", Color.DarkGray, Color.Blue); TextGraphics.DrawString(dx, dy, Shell.Commands[i].Name + " ", Color.White, Color.Blue); TextGraphics.DrawString(dx + 22, dy, Shell.Commands[i].Help, Color.Gray, Color.Blue); dy += 1; if (dy >= 23) { // next message TextGraphics.DrawString(2, CLI.Height - 2, "Press any key to goto next page", Color.White, Color.Blue); CLI.SetCursorPos(CLI.Width - 13, 0); // goto next page CLI.ReadKey(true); SetupScreen(); dy = 4; } } }
// draw time public static void DrawTime() { TextGraphics.DrawString(0, 0, TitleBarTime, DateTimeColor, TitleBarColor); }
// draw title bar public static void DrawTitleBar() { TextGraphics.DrawLineH(0, 0, CLI.Width, ' ', Color.Black, TitleBarColor); // draw background DrawTime(); // draw time TextGraphics.DrawString(CLI.Width - TitleBarText.Length, 0, TitleBarText, TitleColor, TitleBarColor); // draw title }
private void DrawMessage() { TextGraphics.DrawLineH(2, 2, CLI.Width - 4, ' ', Color.White, Color.Cyan); TextGraphics.DrawString(2, 2, " C COLOR VALUE", Color.Black, Color.Cyan); TextGraphics.DrawLineH(0, 3, CLI.Width, ' ', Color.White, Color.Black); int dx = 3, dy = 4; Color bg = Color.Black; // black TextGraphics.DrawChar(dx, dy, '#', Color.Black, bg); TextGraphics.DrawString(dx + 5, dy, "BLACK", Color.White, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.Black, "X2"), Color.Yellow, Color.Blue); dy++; // dark gray TextGraphics.DrawChar(dx, dy, '#', Color.DarkGray, bg); TextGraphics.DrawString(dx + 5, dy, "DARK GRAY", Color.DarkGray, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.DarkGray, "X2"), Color.Yellow, Color.Blue); dy++; // gray TextGraphics.DrawChar(dx, dy, '#', Color.Gray, bg); TextGraphics.DrawString(dx + 5, dy, "GRAY", Color.Gray, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.Gray, "X2"), Color.Yellow, Color.Blue); dy++; // white TextGraphics.DrawChar(dx, dy, '#', Color.White, bg); TextGraphics.DrawString(dx + 5, dy, "WHITE", Color.White, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.White, "X2"), Color.Yellow, Color.Blue); dy++; // dark red TextGraphics.DrawChar(dx, dy, '#', Color.DarkRed, bg); TextGraphics.DrawString(dx + 5, dy, "DARK RED", Color.DarkRed, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.DarkRed, "X2"), Color.Yellow, Color.Blue); dy++; // red TextGraphics.DrawChar(dx, dy, '#', Color.Red, bg); TextGraphics.DrawString(dx + 5, dy, "RED", Color.Red, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.Red, "X2"), Color.Yellow, Color.Blue); dy++; // dark yellow TextGraphics.DrawChar(dx, dy, '#', Color.DarkYellow, bg); TextGraphics.DrawString(dx + 5, dy, "DARK YELLOW", Color.DarkYellow, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.DarkYellow, "X2"), Color.Yellow, Color.Blue); dy++; // yellow TextGraphics.DrawChar(dx, dy, '#', Color.Yellow, bg); TextGraphics.DrawString(dx + 5, dy, "YELLOW", Color.Yellow, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.Yellow, "X2"), Color.Yellow, Color.Blue); dy++; // dark green TextGraphics.DrawChar(dx, dy, '#', Color.DarkGreen, bg); TextGraphics.DrawString(dx + 5, dy, "DARK GREEN", Color.DarkGreen, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.DarkGreen, "X2"), Color.Yellow, Color.Blue); dy++; // green TextGraphics.DrawChar(dx, dy, '#', Color.Green, bg); TextGraphics.DrawString(dx + 5, dy, "GREEN", Color.Green, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.Green, "X2"), Color.Yellow, Color.Blue); dy++; // dark cyan TextGraphics.DrawChar(dx, dy, '#', Color.DarkCyan, bg); TextGraphics.DrawString(dx + 5, dy, "DARK CYAN", Color.DarkCyan, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.DarkCyan, "X2"), Color.Yellow, Color.Blue); dy++; // cyan TextGraphics.DrawChar(dx, dy, '#', Color.Cyan, bg); TextGraphics.DrawString(dx + 5, dy, "CYAN", Color.Cyan, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.Cyan, "X2"), Color.Yellow, Color.Blue); dy++; // dark blue TextGraphics.DrawChar(dx, dy, '#', Color.DarkBlue, bg); TextGraphics.DrawString(dx + 5, dy, "DARK BLUE", Color.Blue, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.DarkBlue, "X2"), Color.Yellow, Color.Blue); dy++; // blue TextGraphics.DrawChar(dx, dy, '#', Color.Blue, bg);; TextGraphics.DrawString(dx + 5, dy, "BLUE", Color.Blue, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.Blue, "X2"), Color.Yellow, Color.Blue);; dy++; // dark magenta TextGraphics.DrawChar(dx, dy, '#', Color.DarkMagenta, bg); TextGraphics.DrawString(dx + 5, dy, "DARK MAGENTA", Color.DarkMagenta, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.DarkMagenta, "X2"), Color.Yellow, Color.Blue); dy++; // magenta TextGraphics.DrawChar(dx, dy, '#', Color.Magenta, bg); TextGraphics.DrawString(dx + 5, dy, "MAGENTA", Color.Magenta, Color.Blue); TextGraphics.DrawString(dx + 28, dy, DataUtils.IntToHex((int)Color.Magenta, "X2"), Color.Yellow, Color.Blue); dy++; // exit message TextGraphics.DrawString(2, CLI.Height - 2, "Press any key to exit...", Color.White, Color.Blue); }
private static void ReadInputMenu() { // draw document Draw(); // draw menu TextGraphics.FillRect(0, 1, 20, 5, ' ', Color.White, Shell.TitleBarColor); TextGraphics.DrawString(1, 1, "New", Color.White, Shell.TitleBarColor); TextGraphics.DrawString(1, 2, "Open...", Color.White, Shell.TitleBarColor); TextGraphics.DrawString(1, 3, "Save", Color.White, Shell.TitleBarColor); TextGraphics.DrawString(1, 4, "Save As...", Color.White, Shell.TitleBarColor); TextGraphics.DrawString(1, 5, "Exit", Color.White, Shell.TitleBarColor); TextGraphics.DrawChar(0, StartY + MenuIndex, '>', Color.Yellow, Shell.TitleBarColor); CLI.SetCursorPos(0, StartY + MenuIndex); try { ConsoleKeyInfo key = CLI.ReadKey(true); // return to document if (key.Key == ConsoleKey.Escape) { Draw(); ReadInput(); } // move up else if (key.Key == ConsoleKey.UpArrow) { if (MenuIndex > 0) { MenuIndex--; } } // move down else if (key.Key == ConsoleKey.DownArrow) { if (MenuIndex < 4) { MenuIndex++; } } // select option else if (key.Key == ConsoleKey.Enter) { // new document if (MenuIndex == 0) { Clear(true); } // load document if (MenuIndex == 1) { Load(); } // save document if (MenuIndex == 2) { if (PMFAT.FileExists(CurrentFile)) { Save(); } else { SaveAs(); } } // save document as if (MenuIndex == 3) { SaveAs(); } // exit if (MenuIndex == 4) { Exit(); } Draw(); ReadInput(); } ReadInputMenu(); } catch (Exception ex) { Clear(false); CLI.Write("[FATAL] ", Color.Red); CLI.WriteLine(ex.Message, Color.White); } }
/// <summary> /// Renders the given MenuItem in a selected state. /// </summary> /// <param name="item">The MenuItem to render in the selected state.</param> private void Select(MenuItem item) { textGraphics.DrawString(pixels, item.Name, item.Col * 8, item.Row * 8, 15, 0, !item.Enabled); }