private string Tabcallback(string s) { var x = Console.CursorLeft; var y = Console.CursorTop; ExtendedConsole.ClearConsoleLine(48); Console.SetCursorPosition(0, 48); var ret = PrintLevel(s); Console.SetCursorPosition(x, y); return(ret); }
public void Run() { Player.ChangeLocation(new Locations.OfficeBuilding.TheCloset.DarkPlace()); PrintHeader(); Console.ForegroundColor = ConsoleColor.DarkGray; do { DrawInventory(); OutputPane.Draw(); ExtendedConsole.ClearConsoleLine(49); Console.SetCursorPosition(0, 49); var str = ReadMyLine(PrintStr, Tabcallback).Trim(); var match = Player.Verbs.FirstOrDefault( o => o.FirstPart.Permute().Any(x => x.ToString().Equals(str, StringComparison.InvariantCultureIgnoreCase))); if (match?.Action != null) { if (!CommandHistory.LastOrDefault()?.Equals(str, StringComparison.InvariantCultureIgnoreCase) ?? true) { CommandHistory.Add(str); } if (OutputPane.Entries.Last().Length != 0) { OutputPane.WriteLine(); } //OutputPane.Write($"{str}> ".DarkGray()); match.Action(str); } else { ExtendedConsole.ClearConsoleLine(48); Console.SetCursorPosition(0, 48); "\rCould not find that command...".Red(true).Write(); } CommandHistoryIndex = 0; } while (Player.Verbs.Any()); }
public void Draw(FormattedString header, FormattedString post, IEnumerable <FormattedString> options) { var opts = options.ToArray(); var space = Width - header.Length; var maxl = space; ExtendedConsole.ClearConsoleLine((short)Y); while (opts.Select(o => o.Length + post.Length > maxl ? o.ToString().Substring(0, Math.Min(o.Length, maxl)) + post : o).Distinct().Sum(o => o.Length + 2) - 2 > space) { maxl--; if (maxl <= 0) { return; } } Console.SetCursorPosition(X, Y); var x = opts.GroupBy(o => o.Length + post.Length > maxl ? o.ToString().Substring(0, Math.Min(o.Length, maxl)).White() + post : o); var str = x.Select(o => o.First()).Aggregate(header, (s, formattedString) => s + formattedString + ", ".DarkGray()); str.Sections.RemoveAt(str.Sections.Count - 1); str.Write(); }
public string PrintLevel(string entry) { var b = new StringBuilder(); var options = Player.Verbs.Where(o => o.Enabled && o.FirstPart.Permute().Any(x => x.StartsWith(entry, StringComparison.CurrentCultureIgnoreCase))).Select(o => o.FirstPart).ToArray(); if (!options.Any()) { return(null); } var groups = options.SelectMany(o => o.Permute().Select(s => s.ToString())).GroupBy(g => g.Split(' ')[0]).ToArray(); while (groups.Length == 1) { b.Append(groups[0].Key + " "); var addedLen = groups[0].Key.Length + 1; if (entry.Length > 0) { entry = entry.Substring(entry.Length < addedLen ? entry.Length : addedLen); } if (groups[0].Count() == 1) { b.Append(groups[0].First().Substring(groups[0].Key.Length + 1)); ExtendedConsole.ClearConsoleLine(48); return(b.ToString()); } groups = groups[0].Select(o => o.Substring(groups[0].Key.Length + 1)).Where(o => o.StartsWith(entry, StringComparison.InvariantCultureIgnoreCase)).GroupBy(o => o.Split(' ')[0]).ToArray(); } var suggest = new List <FormattedString>(); foreach (var t in groups) { var group = t.Key; if (t.Any(o => o.Length == group.Length)) { group = group.Trim(); if (t.Count() > 1) { group += "..."; } suggest.Add(group); continue; } var nextChar = t.First()[group.Length]; while (t.All(o => o.StartsWith(group + nextChar))) { group += nextChar; if (t.Any(o => o.Length == group.Length)) { nextChar = '\0'; break; } nextChar = t.First()[group.Length]; } group = group.Trim(); if (nextChar != '\0') { group += "..."; } suggest.Add(group); } if (suggest.Count <= 0) { return(b.ToString()); } _optionsPane.Draw("Options: ".DarkGray(), "...".DarkGray(), suggest); b.Append(entry); return(b.ToString()); }