123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- using System.Drawing;
- using System.Text;
- using System.Threading;
- using NTERA.Console.RenderItem;
- using NTERA.Core;
- using NTERA.Core.Interop;
- namespace NTERA.Console
- {
- public class EraConsoleInstance : IConsole
- {
- public ConsoleRenderer Renderer { get; }
- public IScriptEngine ScriptEngine { get; }
- public AutoResetEvent InputResetEvent { get; protected set; } = new AutoResetEvent(false);
- public Color ForeColor = Color.White;
- public void AddText(string text, Color? color = null, bool print = true)
- {
- var item = new TextRenderItem(text)
- {
- TextBrush = new SolidBrush(color ?? ForeColor),
- Alignment = Alignment
- };
- if (print)
- Renderer.PrintItem(item);
- else
- Renderer.WriteItem(item);
- }
-
- public bool IsRunning { get; set; } = true;
- public bool Enabled { get; set; } = true;
- public string LastInput { get; protected set; }
- public EraConsoleInstance(ConsoleRenderer renderer, IScriptEngine scriptEngine)
- {
- Renderer = renderer;
- ScriptEngine = scriptEngine;
- }
- public InputRequest CurrentRequest { get; set; }
- public void GiveInput(string input)
- {
- LastInput = input;
- PrintSingleLine(input);
- InputResetEvent.Set();
- }
- public void PrintError(string message)
- {
- System.Console.Write("ERROR: " + message + "\n");
- AddText(message, Color.Red);
- }
- public void PrintSystemLine(string message)
- {
- System.Console.Write("INFO: " + message + "\n");
- AddText(message, Color.Gray);
- }
- public void DebugClearTraceLog()
- {
- }
- public void DebugAddTraceLog(string message)
- {
- }
- public void DebugRemoveTraceLog()
- {
- }
- public bool RunERBFromMemory { get; set; }
- public void PrintWarning(string message, int level)
- {
- System.Console.Write("WARNING: " + message + "\n");
- AddText(message, Color.Yellow);
- }
- public void setStBar(string bar)
- {
- }
- public void ReadAnyKey()
- {
- IsRunning = false;
- Thread.Sleep(500);
- IsRunning = true;
- }
- public void WaitInput(InputRequest request)
- {
- CurrentRequest = request;
- IsRunning = false;
- InputResetEvent.WaitOne();
- CurrentRequest = null;
- IsRunning = true;
- }
- public void ResetStyle()
- {
- ForeColor = Color.White;
- }
- public void OutputLog(string log)
- {
- AddText(log);
- }
- public bool noOutputLog { get; set; }
- public void ThrowTitleError(bool something)
- {
- }
- public void PrintBar()
- {
- printCustomBar("-");
- }
- public void PrintSingleLine(string line, bool temporary = false)
- {
- AddText(line, print: true);
- }
- public void RefreshStrings(bool something)
- {
- }
- public void SetWindowTitle(string title)
- {
- }
- public void ThrowError(bool playSound)
- {
- }
- public void PrintErrorButton(string message)
- {
- }
- protected StringBuilder bodyBuilder = new StringBuilder();
- public void Write(string message)
- {
- //message.Replace(' ', ' ');
- //bodyBuilder.Append(message);
- AddText(message, print: false);
- }
- public void NewLine()
- {
- AddText(bodyBuilder.ToString());
- bodyBuilder.Length = 0;
- }
- public bool UseSetColorStyle { get; set; }
- public void PrintC(string message, bool something)
- {
- AddText(message);
- }
- public DisplayLineAlignment Alignment { get; set; } = DisplayLineAlignment.LEFT;
- public void ClearLine(int line)
- {
- }
- public void PrintTemporaryLine(string line)
- {
- AddText(line);
- }
- public bool updatedGeneration { get; set; }
- public void PrintFlush(bool something)
- {
- }
- public bool LastLineIsTemporary { get; set; }
- public bool LastLineIsEmpty { get; set; }
- public void ReloadErbFinished()
- {
- }
- public bool MesSkip { get; set; }
- public Color bgColor { get; set; }
- public ConsoleRedraw Redraw { get; set; }
- public bool EmptyLine { get; set; }
- public string getStBar(string something)
- {
- return "";
- }
- public void PrintButton(string something, long something1)
- {
- Write(something);
- }
- public void PrintButton(string something, string something1)
- {
- Write(something);
- }
- public void PrintButtonC(string something, long something1, bool something2)
- {
- Write(something);
- }
- public void PrintButtonC(string something, string something1, bool something2)
- {
- Write(something);
- }
- public void PrintPlain(string message)
- {
- AddText(message);
- }
- public void printCustomBar(string bar)
- {
- AddText("".PadRight(300, bar[0]));
- }
- public bool UseUserStyle { get; set; }
- public void Quit()
- {
- }
- public void PrintHtml(string html, bool newline)
- {
- foreach (var item in HtmlParser.ParseHtml(html, ScriptEngine.GetImage))
- Renderer.PrintItem(item);
- }
- public void PrintImg(string img)
- {
- var image = ScriptEngine.GetImage(img);
- Renderer.WriteItem(new ImageRenderItem(image.Bitmap, image.Rectangle, alignment: Alignment));
- }
- public void PrintShape(string shape, int[] param)
- {
- AddText(shape);
- }
-
- public void DebugPrint(string message)
- {
- AddText(message);
- }
- public void DebugNewLine()
- {
- }
- public void DebugClear()
- {
- }
- public void ReadAnyKey(bool something, bool something2)
- {
- Thread.Sleep(500);
- }
- public void SetStringStyle(Color color)
- {
- ForeColor = color;
- }
- public void SetStringStyle(FontStyle fontStyle)
- {
- }
- public void SetBgColor(Color color)
- {
- }
- public void SetToolTipColor(Color fc, Color bc)
- {
- }
- public void SetToolTipDelay(int delay)
- {
- }
- public void SetToolTipDuration(int duration)
- {
- }
- public void SetFont(string font)
- {
- }
- public void SetRedraw(long value)
- {
- }
- public int NewButtonGeneration { get; set; }
- public void UpdateGeneration()
- {
- }
- public string GetWindowTitle()
- {
- return "title";
- }
- public long LineCount { get; set; }
- public string getDefStBar()
- {
- return "";
- }
- public bool IsTimeOut { get; set; }
- }
- }
|