REFACTORING

This commit is contained in:
2021-10-04 23:25:42 +03:00
parent c71d2b8356
commit 2defc3ae5e
25 changed files with 583 additions and 539 deletions

View File

@@ -16,26 +16,26 @@ namespace DTLib.ConsoleGUI
public Container(string name, string layout_file)
{
Name = name;
Name=name;
ParseLayoutFile(layout_file);
}
void ParseLayoutFile(string layout_file)
{
DtsodV23 layout = new(File.ReadAllText(layout_file));
AnchorPoint = (layout[Name]["anchor"][0], layout[Name]["anchor"][1]);
Width = layout[Name]["width"];
Height = layout[Name]["height"];
foreach (string element_name in layout[Name]["children"].Keys)
AnchorPoint=(layout[Name]["anchor"][0], layout[Name]["anchor"][1]);
Width=layout[Name]["width"];
Height=layout[Name]["height"];
foreach(string element_name in layout[Name]["children"].Keys)
{
switch (layout[Name]["children"][element_name]["type"])
switch(layout[Name]["children"][element_name]["type"])
{
case "label":
this.Add(new Label(element_name,
layout[Name]["children"][element_name]["resdir"] + $"\\{element_name}.textmap",
layout[Name]["children"][element_name]["resdir"] + $"\\{element_name}.colormap")
Add(new Label(element_name,
layout[Name]["children"][element_name]["resdir"]+$"\\{element_name}.textmap",
layout[Name]["children"][element_name]["resdir"]+$"\\{element_name}.colormap")
{
AnchorPoint = (layout[Name]["children"][element_name]["anchor"][0],
AnchorPoint=(layout[Name]["children"][element_name]["anchor"][0],
layout[Name]["children"][element_name]["anchor"][1])
});
break;
@@ -45,18 +45,18 @@ namespace DTLib.ConsoleGUI
public void GenTextmap()
{
Textmap = new char[Width * Height];
for (int i = 0; i < Textmap.Length; i++)
Textmap[i] = ' ';
foreach (var element in this)
Textmap=new char[Width*Height];
for(int i = 0; i<Textmap.Length; i++)
Textmap[i]=' ';
foreach(IDrawable element in this)
{
element.GenTextmap();
Log("m", $"Length: {element.Textmap.Length} calculated: {element.Width * element.Height}\n");
for (ushort y = 0; y < element.Height; y++)
for (ushort x = 0; x < element.Width; x++)
Log("m", $"Length: {element.Textmap.Length} calculated: {element.Width*element.Height}\n");
for(ushort y = 0; y<element.Height; y++)
for(ushort x = 0; x<element.Width; x++)
{
//Textmap[(element.AnchorPoint.y + y) * Width + element.AnchorPoint.x + x] = element.Textmap[y * element.Width + x];
Textmap[(y) * Width + x] = element.Textmap[y * element.Width + x];
Textmap[(y)*Width+x]=element.Textmap[y*element.Width+x];
}
}
}

View File

@@ -18,21 +18,18 @@ namespace DTLib.ConsoleGUI
public Label(string name, string textmapFile, string colormapFile)
{
TextmapFile = textmapFile;
ColormapFile = colormapFile;
Name = name;
TextmapFile=textmapFile;
ColormapFile=colormapFile;
Name=name;
}
public void GenColormap()
{
Colormap = File.ReadAllText(ColormapFile).ToCharArray();
}
public void GenColormap() => Colormap=File.ReadAllText(ColormapFile).ToCharArray();
public void GenTextmap()
{
Textmap = File.ReadAllText(TextmapFile).ToCharArray();
Width = 12;
Height = 3;
Textmap=File.ReadAllText(TextmapFile).ToCharArray();
Width=12;
Height=3;
}
}
}

View File

@@ -13,11 +13,11 @@ namespace DTLib.ConsoleGUI
public Window(string layout_file) : base("window", layout_file)
{
Console.Clear();
Console.SetWindowSize(Width + 1, Height + 1);
Console.SetBufferSize(Width + 1, Height + 1);
Console.OutputEncoding = Encoding.Unicode;
Console.InputEncoding = Encoding.Unicode;
Console.CursorVisible = false;
Console.SetWindowSize(Width+1, Height+1);
Console.SetBufferSize(Width+1, Height+1);
Console.OutputEncoding=Encoding.Unicode;
Console.InputEncoding=Encoding.Unicode;
Console.CursorVisible=false;
}
// выводит все символы

View File

@@ -21,29 +21,29 @@ namespace DTLib.ConsoleGUI
public WindowOld(int windowWidth, int windowHeight)
{
WindowWidth = windowWidth;
WindowHeight = windowHeight;
Text = new char[windowWidth, windowHeight];
TextColors = new char[windowWidth, windowHeight];
nowText = TextColors;
nowTextColors = new char[windowWidth, windowHeight];
Console.WindowWidth = WindowWidth + 1;
Console.WindowHeight = WindowHeight + 1;
Console.BufferWidth = WindowWidth + 1;
Console.BufferHeight = WindowHeight + 1;
Console.OutputEncoding = Encoding.Unicode;
Console.InputEncoding = Encoding.Unicode;
Console.CursorVisible = false;
WindowWidth=windowWidth;
WindowHeight=windowHeight;
Text=new char[windowWidth, windowHeight];
TextColors=new char[windowWidth, windowHeight];
nowText=TextColors;
nowTextColors=new char[windowWidth, windowHeight];
Console.WindowWidth=WindowWidth+1;
Console.WindowHeight=WindowHeight+1;
Console.BufferWidth=WindowWidth+1;
Console.BufferHeight=WindowHeight+1;
Console.OutputEncoding=Encoding.Unicode;
Console.InputEncoding=Encoding.Unicode;
Console.CursorVisible=false;
// заполнение массивов
for (sbyte y = 0; y < WindowHeight; y++)
for(sbyte y = 0; y<WindowHeight; y++)
{
for (sbyte x = 0; x < WindowWidth; x++)
for(sbyte x = 0; x<WindowWidth; x++)
{
Text[x, y] = ' ';
TextColors[x, y] = 'w';
Text[x, y]=' ';
TextColors[x, y]='w';
}
}
nowText = TextColors;
nowText=TextColors;
}
/*// считывает массив символов из файла
@@ -97,34 +97,31 @@ namespace DTLib.ConsoleGUI
r.Close();
}*/
public void ResetCursor()
{
Console.SetCursorPosition(0, WindowHeight);
}
public void ResetCursor() => Console.SetCursorPosition(0, WindowHeight);
// заменяет символ выведенный, использовать после ShowAll()
public void ChangeChar(sbyte x, sbyte y, char ch)
{
Text[x, y] = ch;
nowText[x, y] = ch;
Text[x, y]=ch;
nowText[x, y]=ch;
Console.SetCursorPosition(x, y);
ColoredConsole.Write(TextColors[x, y].ToString(), ch.ToString());
}
public void ChangeColor(sbyte x, sbyte y, char color)
{
TextColors[x, y] = color;
nowTextColors[x, y] = color;
TextColors[x, y]=color;
nowTextColors[x, y]=color;
Console.SetCursorPosition(x, y);
ColoredConsole.Write(color.ToString(), Text[x, y].ToString());
}
public void ChangeCharAndColor(sbyte x, sbyte y, char color, char ch)
{
Text[x, y] = ch;
nowText[x, y] = ch;
TextColors[x, y] = color;
nowTextColors[x, y] = color;
Text[x, y]=ch;
nowText[x, y]=ch;
TextColors[x, y]=color;
nowTextColors[x, y]=color;
Console.SetCursorPosition(x, y);
ColoredConsole.Write(color.ToString(), ch.ToString());
}
@@ -132,12 +129,12 @@ namespace DTLib.ConsoleGUI
public void ChangeLine(sbyte x, sbyte y, char color, string line)
{
Console.SetCursorPosition(x, y);
for (sbyte i = 0; i < line.Length; i++)
for(sbyte i = 0; i<line.Length; i++)
{
Text[x + i, y] = line[i];
nowText[x + i, y] = line[i];
TextColors[x + i, y] = color;
nowTextColors[x + i, y] = color;
Text[x+i, y]=line[i];
nowText[x+i, y]=line[i];
TextColors[x+i, y]=color;
nowTextColors[x+i, y]=color;
}
ColoredConsole.Write(color.ToString(), line);
}
@@ -146,14 +143,14 @@ namespace DTLib.ConsoleGUI
public void ShowAll()
{
var l = new List<string>();
for (sbyte y = 0; y < WindowHeight; y++)
for(sbyte y = 0; y<WindowHeight; y++)
{
for (sbyte x = 0; x < WindowWidth; x++)
for(sbyte x = 0; x<WindowWidth; x++)
{
l.Add(TextColors[x, y].ToString());
l.Add(Text[x, y].ToString());
nowText[x, y] = Text[x, y];
nowTextColors[x, y] = TextColors[x, y];
nowText[x, y]=Text[x, y];
nowTextColors[x, y]=TextColors[x, y];
}
l.Add("w");
l.Add("\n");
@@ -164,16 +161,16 @@ namespace DTLib.ConsoleGUI
public void UpdateAll()
{
for (sbyte y = 0; y < WindowHeight; y++)
for(sbyte y = 0; y<WindowHeight; y++)
{
for (sbyte x = 0; x < WindowWidth; x++)
for(sbyte x = 0; x<WindowWidth; x++)
{
Console.SetCursorPosition(x, y);
if (TextColors[x, y] != nowTextColors[x, y] || Text[x, y] != nowText[x, y])
if(TextColors[x, y]!=nowTextColors[x, y]||Text[x, y]!=nowText[x, y])
{
ColoredConsole.Write(TextColors[x, y].ToString(), Text[x, y].ToString());
nowText[x, y] = Text[x, y];
nowTextColors[x, y] = TextColors[x, y];
nowText[x, y]=Text[x, y];
nowTextColors[x, y]=TextColors[x, y];
}
}
Console.Write('\n');