public static void PrintPanel()
{
Console.Clear(); // 추가!
StringBuilder sb = new StringBuilder(); // 줄바꿈 고려
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
sb.Append(uiPanel[y, x]);
}
sb.AppendLine(); // 줄 바꿈
}
Console.Write(sb.ToString());
}
public static void UIUpdater(UIName name)
{
Console.Clear();
var printUI = UITable.UITableDic[name];
foreach (var value in printUI)
{
ChangeUiPanel(name, UITable.UIDic[value]);
}
// 출력
PrintPanel();
// 커서 위치 변경
ReadLineAt(cusorPosition.Item1, cusorPosition.Item2);
}
@@@@@@@@@@@@= /
. @ . :@@@@ /
@@@ -+ =@= /
@: @@@@@*:@@@@@- @@ /
@@@ @@ @:@@ /
.@@@@ .@@@@- /
@ .@@@@ .@@+@@ @@ /
@=@ #@= -@ @@@@ /
@@ -@@ /
@ @@@@@ @ /
@@@@@@@% :@@@@@@@. /
#@ @*@@ -@@@ :@@@@ /
:@ @@@@@ :@%.@@@@@@- %@ /
@% %@* - @@%@@@@ @ .@@+ /
:@@@.=@@@ @ @: @==.-:@@ @@%@ @* /
@ @@@ @@@ @ @- .@:= * @@ @@ @@= @ /
@@ # *@@@@ -@ @@*@@@@@ @ @ @ /
@ :@@@ + @@ @ @@@@@@@@ +. #@ @ /
@@- -@. % .@@@@@@@@@@ +@ @+ /
@@@ . - @@@@@@@@ =@ @@ /
-@@@@@@@ .@@:.+@@@ @ @+ /
@@@@@+ -@ @@@ @ @@@@@@@@@ /
@ @- =@ * @ @: @ /
@ @- =@@@ .:.@ @# =@ /
@ @= =@=@@ :.@ @* .@ /
@@ @* +@ :@ ..@ @# @@ /
@@ @ +@ :=@ :@@ /
@@@@@@= *@ : =@@@@@@ /
@. .@@+.:: @@ /
*@@@* @= @- @@@ @@ /
-@@ @@@@@ @@@@@@@@@ /
*@@ .=*%@@@ @@ %@@ /
+@@%+= :#@@#* /"
Console.SetCursorPosition(left + displayWidth, height - top);
를 통해 커서를 조작하고, ReadLine을 통해 키를 입력받을때, 엔터키를 치지 않아도 입력이 단 하나라도 들어오면
스크롤을 내려 ReadLine 의 커서가 있는곳이 최상단이 되도록 수정해버리는 문제
public static void ReadLineAt(int left, int top)
{
string inputBuffer = "";
int displayWidth = 0;
while (true)
{
ConsoleKeyInfo keyInfo = Console.ReadKey(intercept: true);
if (keyInfo.Key == ConsoleKey.Enter)
break;
if (keyInfo.Key == ConsoleKey.Backspace)
{
if (inputBuffer.Length > 0)
{
char lastChar = inputBuffer[^1];
int charWidth = GetCharWidth(lastChar);
displayWidth -= charWidth;
inputBuffer = inputBuffer.Substring(0, inputBuffer.Length - 1);
for (int i = 0; i < charWidth; i++)
uiPanel[height - top, left + displayWidth + i] = ' ';
}
}
else if (!char.IsControl(keyInfo.KeyChar))
{
char c = keyInfo.KeyChar;
int charWidth = GetCharWidth(c);
if (left + displayWidth + charWidth <= width) // overflow 방지
{
inputBuffer += c;
uiPanel[height - top, left + displayWidth] = c;
if (charWidth == 2)
uiPanel[height - top, left + displayWidth + 1] = ' ';
displayWidth += charWidth;
}
}
PrintPanel();
Console.SetCursorPosition(left + displayWidth, height - top);
}
}
정말이지... 콘솔창을 이용해서 UI를 구현 해보려는 시도를 하면서 유니티의 UI가 선녀같이 보입니다...