Update for MyConsole
This commit is contained in:
parent
5bb7a987fd
commit
156590a1a1
|
@ -1,116 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cons = System.Console;
|
||||
|
||||
namespace Galactic_Colors_Control_Common
|
||||
{
|
||||
public class Console
|
||||
{
|
||||
private static string inputBuffer = "";
|
||||
private static List<ColorStrings> outputBuffer = new List<ColorStrings>();
|
||||
public static string Title { get { return Cons.Title; } set { Cons.Title = value; } }
|
||||
private static object locker = new object();
|
||||
|
||||
public static void Write(ColorStrings Text)
|
||||
{
|
||||
outputBuffer.Add(Text);
|
||||
while (outputBuffer.Count > Cons.WindowHeight - 2) { outputBuffer.RemoveAt(0); }
|
||||
Update();
|
||||
}
|
||||
|
||||
public static string Read()
|
||||
{
|
||||
ConsoleKeyInfo key = Cons.ReadKey();
|
||||
while (key.Key != ConsoleKey.Enter)
|
||||
{
|
||||
switch (key.Key)
|
||||
{
|
||||
case ConsoleKey.Backspace:
|
||||
if (inputBuffer.Length == 0) { SetInputPos(); }
|
||||
if (inputBuffer.Length == 1) { inputBuffer = ""; }
|
||||
if (inputBuffer.Length > 1) { inputBuffer = inputBuffer.Substring(0, inputBuffer.Length - 1); }
|
||||
break;
|
||||
|
||||
default:
|
||||
inputBuffer += key.KeyChar;
|
||||
break;
|
||||
}
|
||||
Update();
|
||||
key = Cons.ReadKey();
|
||||
}
|
||||
Cons.WriteLine();
|
||||
string res = inputBuffer;
|
||||
inputBuffer = "";
|
||||
return res;
|
||||
}
|
||||
|
||||
private static void Update()
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
Cons.Clear();
|
||||
Cons.SetCursorPosition(0, 0);
|
||||
foreach (ColorStrings output in outputBuffer) { output.Write(); }
|
||||
SetInputPos();
|
||||
Cons.ForegroundColor = ConsoleColor.White;
|
||||
Cons.BackgroundColor = ConsoleColor.Black;
|
||||
Cons.Write("> " + inputBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetInputPos()
|
||||
{
|
||||
Cons.SetCursorPosition(0, Math.Max(Cons.WindowHeight - 1, Cons.CursorTop + 1));
|
||||
}
|
||||
|
||||
public static void ClearInput()
|
||||
{
|
||||
inputBuffer = ""; Update();
|
||||
}
|
||||
|
||||
public static void ClearOutput()
|
||||
{
|
||||
outputBuffer.Clear(); Update();
|
||||
}
|
||||
}
|
||||
|
||||
public class ColorStrings
|
||||
{
|
||||
public ColorString[] Text;
|
||||
|
||||
public ColorStrings(params ColorString[] strings)
|
||||
{
|
||||
Text = strings;
|
||||
}
|
||||
|
||||
public ColorStrings(string text)
|
||||
{
|
||||
Text = new ColorString[1] { new ColorString(text) };
|
||||
}
|
||||
|
||||
public void Write()
|
||||
{
|
||||
foreach (ColorString cstring in Text)
|
||||
{
|
||||
Cons.BackgroundColor = cstring.Back;
|
||||
Cons.ForegroundColor = cstring.Fore;
|
||||
Cons.Write(cstring.Text);
|
||||
}
|
||||
Cons.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
public class ColorString
|
||||
{
|
||||
public string Text;
|
||||
public ConsoleColor Fore;
|
||||
public ConsoleColor Back;
|
||||
|
||||
public ColorString(string text, ConsoleColor fore = ConsoleColor.White, ConsoleColor back = ConsoleColor.Black)
|
||||
{
|
||||
Text = text;
|
||||
Fore = fore;
|
||||
Back = back;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,6 +37,9 @@
|
|||
<Reference Include="MyCommon">
|
||||
<HintPath>..\..\MyCommon\MyCommon\bin\Release\MyCommon.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MyConsole">
|
||||
<HintPath>..\..\MyConsole\MyConsole\bin\Release\MyConsole.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
|
@ -52,7 +55,6 @@
|
|||
</Compile>
|
||||
<Compile Include="Binary.cs" />
|
||||
<Compile Include="Common.cs" />
|
||||
<Compile Include="Console.cs" />
|
||||
<Compile Include="Logger.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using MyConsole;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
|
|
|
@ -37,6 +37,9 @@
|
|||
<Reference Include="MyCommon">
|
||||
<HintPath>..\..\MyCommon\MyCommon\bin\Release\MyCommon.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MyConsole">
|
||||
<HintPath>..\..\MyConsole\MyConsole\bin\Release\MyConsole.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
|
|
|
@ -3,8 +3,9 @@ using Galactic_Colors_Control_Common;
|
|||
using Galactic_Colors_Control_Common.Protocol;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Consol = Galactic_Colors_Control_Common.Console;
|
||||
using Consol = MyConsole.ConsoleIO;
|
||||
using MyCommon;
|
||||
using MyConsole;
|
||||
|
||||
namespace Galactic_Colors_Control_Console
|
||||
{
|
||||
|
|
|
@ -64,6 +64,9 @@
|
|||
<Reference Include="MyCommon">
|
||||
<HintPath>..\..\MyCommon\MyCommon\bin\Release\MyCommon.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MyConsole">
|
||||
<HintPath>..\..\MyConsole\MyConsole\bin\Release\MyConsole.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MyMonoGame">
|
||||
<HintPath>..\..\MonoGame\MyMonoGameGUI\MyMonoGameGUI\bin\Release\MyMonoGame.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Galactic_Colors_Control_Common;
|
||||
using System;
|
||||
using Console = Galactic_Colors_Control_Common.Console;
|
||||
using Console = MyConsole.ConsoleIO;
|
||||
using MyConsole;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using Galactic_Colors_Control_Common;
|
||||
using Galactic_Colors_Control_Common.Protocol;
|
||||
using System.Net.Sockets;
|
||||
using Console = Galactic_Colors_Control_Common.Console;
|
||||
using Console = MyConsole.ConsoleIO;
|
||||
|
||||
namespace Galactic_Colors_Control_Server.Commands
|
||||
{
|
||||
|
|
|
@ -52,6 +52,9 @@
|
|||
<Reference Include="MyCommon">
|
||||
<HintPath>..\..\MyCommon\MyCommon\bin\Release\MyCommon.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MyConsole">
|
||||
<HintPath>..\..\MyConsole\MyConsole\bin\Release\MyConsole.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.XML" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -8,7 +8,8 @@ using System.Net.Sockets;
|
|||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using MyCommon;
|
||||
using Console = Galactic_Colors_Control_Common.Console;
|
||||
using Console = MyConsole.ConsoleIO;
|
||||
using MyConsole;
|
||||
|
||||
//TODO gui parties pages
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@ using Galactic_Colors_Control_Common.Protocol;
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using Console = Galactic_Colors_Control_Common.Console;
|
||||
using Console = MyConsole.ConsoleIO;
|
||||
using MyConsole;
|
||||
|
||||
namespace Galactic_Colors_Control_Server
|
||||
{
|
||||
|
|
|
@ -63,6 +63,8 @@ See also the list of [contributors](https://github.com/sheychen290/Galactic_Colo
|
|||
* .Net/[Mono](https://github.com/mono/mono)
|
||||
* [Monogame](https://github.com/MonoGame/MonoGame)
|
||||
* [MyMonoGame.GUI](https://github.com/sheychen290/MyMonoGame)
|
||||
* [MyCommon](https://github.com/sheychen290/MyCommon)
|
||||
* [MyConsole](https://github.com/sheychen290/MyConsole)
|
||||
* [Space Sprites](https://gamedevelopment.tutsplus.com/articles/enjoy-these-totally-free-space-based-shoot-em-up-sprites--gamedev-2368)
|
||||
|
||||
## License
|
||||
|
|
Reference in New Issue