project structure changed

This commit is contained in:
2021-08-24 20:35:02 +03:00
parent 60e3bc6251
commit 13421f2c77
16 changed files with 961 additions and 313 deletions

View File

@@ -1,4 +1,7 @@
using System.Collections.Generic;
using DTLib.Dtsod;
using DTLib.Filesystem;
using System.Collections.Generic;
using static DTLib.PublicLog;
namespace DTLib.ConsoleGUI
{
@@ -9,13 +12,35 @@ namespace DTLib.ConsoleGUI
public ushort Height { get; set; }
public char[] Textmap { get; private set; }
public char[] Colormap { get; private set; }
public string Name { get; private set; }
public Container() { }
public Container(ushort width, ushort height)
public Container(string name, string layout_file)
{
Width = width;
Height = height;
Name = name;
ParseLayoutFile(layout_file);
}
void ParseLayoutFile(string layout_file)
{
DtsodV22 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)
{
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")
{
AnchorPoint = (layout[Name]["children"][element_name]["anchor"][0],
layout[Name]["children"][element_name]["anchor"][1])
});
break;
}
}
}
public void GenTextmap()
@@ -25,11 +50,13 @@ namespace DTLib.ConsoleGUI
Textmap[i] = ' ';
foreach (var 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++)
{
element.GenTextmap();
Textmap[(element.AnchorPoint.y + y) * Width + element.AnchorPoint.x + x] = element.Textmap[y * 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];
}
}
}

View File

@@ -1,19 +1,14 @@
namespace DTLib.ConsoleGUI
{
public class Control : IDrawable
public class Control : Label
{
public (ushort x, ushort y) AnchorPoint { get; set; }
public ushort Width { get; }
public ushort Height { get; }
public char[] Textmap { get; private set; }
public char[] Colormap { get; private set; }
public void GenColormap()
public new void GenColormap()
{
}
public void GenTextmap()
public new void GenTextmap()
{
}

View File

@@ -7,6 +7,7 @@
public ushort Height { get; }
public char[] Textmap { get; }
public char[] Colormap { get; }
public string Name { get; }
public void GenTextmap();

View File

@@ -1,32 +1,38 @@
namespace DTLib.ConsoleGUI
using DTLib.Filesystem;
namespace DTLib.ConsoleGUI
{
public class Label : IDrawable
{
public (ushort x, ushort y) AnchorPoint { get; set; }
public ushort Width { get; }
public ushort Height { get; }
public (ushort x, ushort y) AnchorPoint { get; set; } = (0, 0);
public ushort Width { get; private set; }
public ushort Height { get; private set; }
public char[] Textmap { get; private set; }
public char[] Colormap { get; private set; }
public string TextmapFile { get; set; }
public string ColormapFile { get; set; }
public string Name { get; init; }
public Label() { }
public Label(string textmapFile, string colormapFile)
public Label(string name, string textmapFile, string colormapFile)
{
TextmapFile = textmapFile;
ColormapFile = colormapFile;
Name = name;
}
public void GenColormap()
{
Colormap = File.ReadAllText(ColormapFile).ToCharArray();
}
public void GenTextmap()
{
Textmap = File.ReadAllText(TextmapFile).ToCharArray();
Width = 12;
Height = 3;
}
}
}

View File

@@ -1,6 +1,5 @@
using DTLib.Filesystem;
using System;
using System.Collections.Generic;
using System.Text;
namespace DTLib.ConsoleGUI
@@ -8,182 +7,30 @@ namespace DTLib.ConsoleGUI
//
// создание gui из текста в консоли
//
public class Window
public class Window : Container
{
public int WindowWidth { get; private set; }
public int WindowHeight { get; private set; }
public char[,] Text;
public char[,] nowText;
public char[,] TextColors;
public char[,] nowTextColors;
public Container WindowContainer;
public Window(int windowWidth, int windowHeight)
public Window(string layout_file) : base("window", layout_file)
{
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.Clear();
Console.SetWindowSize(Width + 1, Height + 1);
Console.SetBufferSize(Width + 1, Height + 1);
Console.OutputEncoding = Encoding.Unicode;
Console.InputEncoding = Encoding.Unicode;
Console.CursorVisible = false;
// заполнение массивов
for (sbyte y = 0; y < WindowHeight; y++)
{
for (sbyte x = 0; x < WindowWidth; x++)
{
Text[x, y] = ' ';
TextColors[x, y] = 'w';
}
}
nowText = TextColors;
}
/*// считывает массив символов из файла
// ширина и высота текста должны быть как указанные при инициализации объекта этого класса
public void ReadFromFile(string path)
{
var r = new StreamReader(path, SimpleConverter.UTF8);
char[] s = new char[1];
// считывание текста
sbyte y = 0, x = 0;
r.Read(s, 0, 1);
while (!r.EndOfStream && y < WindowHeight)
{
if (x == WindowWidth)
{
r.Read(s, 0, 1);
x = 0;
y++;
}
else
{
Text[x, y] = s[0];
x++;
}
r.Read(s, 0, 1);
}
r.Read(s, 0, 1);
// считывание цвета
// если не находит цвет в файле, оставляет старый
if (s[0] == '\n')
{
r.Read(s, 0, 1);
y = 0;
x = 0;
while (!r.EndOfStream && y < WindowHeight)
{
if (x == WindowWidth)
{
r.Read(s, 0, 1);
x = 0;
y++;
}
else
{
TextColors[x, y] = s[0];
x++;
}
r.Read(s, 0, 1);
}
}
r.Close();
}*/
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;
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;
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;
Console.SetCursorPosition(x, y);
ColoredConsole.Write(color.ToString(), ch.ToString());
}
public void ChangeLine(sbyte x, sbyte y, char color, string line)
{
Console.SetCursorPosition(x, y);
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;
}
ColoredConsole.Write(color.ToString(), line);
}
// выводит все символы
public void ShowAll()
{
var l = new List<string>();
for (sbyte y = 0; y < WindowHeight; y++)
{
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];
}
l.Add("w");
l.Add("\n");
}
ColoredConsole.Write(l.ToArray());
//Console.WriteLine();
}
public void UpdateAll()
{
for (sbyte y = 0; y < WindowHeight; y++)
{
for (sbyte x = 0; x < WindowWidth; x++)
{
Console.SetCursorPosition(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];
}
}
Console.Write('\n');
}
}
public void RenderFile(string file)
{
Console.Clear();
Console.WriteLine(File.ReadAllText(file));
}
public void Render()
{
GenTextmap();
Console.WriteLine(SimpleConverter.MergeToString(Textmap));
}
}
}

189
ConsoleGUI/WindowOld.cs Normal file
View File

@@ -0,0 +1,189 @@
using DTLib.Filesystem;
using System;
using System.Collections.Generic;
using System.Text;
namespace DTLib.ConsoleGUI
{
//
// создание gui из текста в консоли
//
public class WindowOld
{
public int WindowWidth { get; private set; }
public int WindowHeight { get; private set; }
public char[,] Text;
public char[,] nowText;
public char[,] TextColors;
public char[,] nowTextColors;
public Container WindowContainer;
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;
// заполнение массивов
for (sbyte y = 0; y < WindowHeight; y++)
{
for (sbyte x = 0; x < WindowWidth; x++)
{
Text[x, y] = ' ';
TextColors[x, y] = 'w';
}
}
nowText = TextColors;
}
/*// считывает массив символов из файла
// ширина и высота текста должны быть как указанные при инициализации объекта этого класса
public void ReadFromFile(string path)
{
var r = new StreamReader(path, SimpleConverter.UTF8);
char[] s = new char[1];
// считывание текста
sbyte y = 0, x = 0;
r.Read(s, 0, 1);
while (!r.EndOfStream && y < WindowHeight)
{
if (x == WindowWidth)
{
r.Read(s, 0, 1);
x = 0;
y++;
}
else
{
Text[x, y] = s[0];
x++;
}
r.Read(s, 0, 1);
}
r.Read(s, 0, 1);
// считывание цвета
// если не находит цвет в файле, оставляет старый
if (s[0] == '\n')
{
r.Read(s, 0, 1);
y = 0;
x = 0;
while (!r.EndOfStream && y < WindowHeight)
{
if (x == WindowWidth)
{
r.Read(s, 0, 1);
x = 0;
y++;
}
else
{
TextColors[x, y] = s[0];
x++;
}
r.Read(s, 0, 1);
}
}
r.Close();
}*/
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;
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;
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;
Console.SetCursorPosition(x, y);
ColoredConsole.Write(color.ToString(), ch.ToString());
}
public void ChangeLine(sbyte x, sbyte y, char color, string line)
{
Console.SetCursorPosition(x, y);
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;
}
ColoredConsole.Write(color.ToString(), line);
}
// выводит все символы
public void ShowAll()
{
var l = new List<string>();
for (sbyte y = 0; y < WindowHeight; y++)
{
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];
}
l.Add("w");
l.Add("\n");
}
ColoredConsole.Write(l.ToArray());
//Console.WriteLine();
}
public void UpdateAll()
{
for (sbyte y = 0; y < WindowHeight; y++)
{
for (sbyte x = 0; x < WindowWidth; x++)
{
Console.SetCursorPosition(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];
}
}
Console.Write('\n');
}
}
public void RenderFile(string file)
{
Console.Clear();
Console.WriteLine(File.ReadAllText(file));
}
}
}