delver-se/Program.cs

131 lines
4.0 KiB
C#
Raw Normal View History

2021-02-04 00:04:05 +03:00
using System;
2021-02-04 16:44:07 +03:00
using System.IO;
using System.Text.Json;
2021-02-04 00:04:05 +03:00
using System.Collections.Generic;
using Terminal.Gui;
class Program
{
static void Main()
{
Application.Init();
2021-02-04 21:11:31 +03:00
Colors.Base = Colors.Dialog; // WTF?!
2021-02-04 00:04:05 +03:00
var top = Application.Top;
2021-02-04 11:53:40 +03:00
var mainWindow = new Window("Delver Save Editor")
2021-02-04 00:04:05 +03:00
{ X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() };
2021-02-04 11:53:40 +03:00
var menuWindow = new MenuBar (new MenuBarItem [] {
2021-02-04 00:04:05 +03:00
new MenuBarItem ("_File", new MenuItem [] {
new MenuItem ("_Refresh", "Refresh Delver saves", null),
new MenuItem ("_About", "About this program", null),
2021-02-04 11:53:40 +03:00
new MenuItem ("_Quit", "", () => { if (Quit()) top.Running = false; })
2021-02-04 00:04:05 +03:00
})
});
2021-02-04 21:11:31 +03:00
var delverPath = loadGamePath();
2021-02-04 11:53:40 +03:00
var delverPathLabel = new Label("Delver path:")
{ X = 1, Y = 1, Width = 13, Height = 1 };
2021-02-04 16:44:07 +03:00
var delverPathField = new TextField(delverPath)
2021-02-04 21:11:31 +03:00
{ X = 14, Y = 1, Width = Dim.Fill() - 1, Height = 1 };
2021-02-04 00:04:05 +03:00
2021-02-04 11:53:40 +03:00
var savesListData = new List<string>() { "Save 0", "Save 1", "Save 3" };
var savesList = new ListView(savesListData) {
2021-02-04 16:44:07 +03:00
X = 1,
2021-02-04 00:04:05 +03:00
Y = 0,
2021-02-04 16:44:07 +03:00
Width = Dim.Fill() - 1,
Height = Dim.Fill() - 1,
2021-02-04 00:04:05 +03:00
AllowsMarking = false
};
var savesWindow = new Window("Saves slot")
{ X = 0, Y = 3, Width = 20, Height = Dim.Fill() };
var dataWindow = new Window("Data Editor")
2021-02-04 11:53:40 +03:00
{ X = 21, Y = 3, Width = Dim.Fill(), Height = Dim.Fill() };
var playerHpLabel = new Label("HP:")
2021-02-04 16:44:07 +03:00
{ X = 0, Y = 1, Width = 10, Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right };
2021-02-04 11:53:40 +03:00
var playerHp = new TextField()
2021-02-04 16:44:07 +03:00
{ X = 11, Y = 1, Width = Dim.Fill() - 2, Height = 1 };
2021-02-04 11:53:40 +03:00
var playerMaxHpLabel = new Label("Max HP:")
2021-02-04 16:44:07 +03:00
{ X = 0, Y = 3, Width = 10, Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right };
2021-02-04 11:53:40 +03:00
var playerMaxHp = new TextField()
2021-02-04 16:44:07 +03:00
{ X = 11, Y = 3, Width = Dim.Fill() - 2, Height = 1 };
2021-02-04 11:53:40 +03:00
var playerGoldLabel = new Label("Gold:")
2021-02-04 16:44:07 +03:00
{ X = 0, Y = 5, Width = 10, Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right };
2021-02-04 11:53:40 +03:00
var playerGold = new TextField()
2021-02-04 16:44:07 +03:00
{ X = 11, Y = 5, Width = Dim.Fill() - 2, Height = 1 };
2021-02-04 11:53:40 +03:00
var playerXpLabel = new Label("XP:")
2021-02-04 16:44:07 +03:00
{ X = 0, Y = 7, Width = 10, Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right };
2021-02-04 11:53:40 +03:00
var playerXp = new TextField()
2021-02-04 16:44:07 +03:00
{ X = 11, Y = 7, Width = Dim.Fill() - 2, Height = 1 };
var updateButton = new Button ("Update", is_default: false)
{ X = 11, Y = 9, Height = 1 };
updateButton.Clicked += () => { };
2021-02-04 00:04:05 +03:00
2021-02-04 11:53:40 +03:00
savesWindow.Add(savesList);
dataWindow.Add
(
playerHpLabel,playerHp,
playerMaxHpLabel, playerMaxHp,
playerGoldLabel, playerGold,
2021-02-04 16:44:07 +03:00
playerXpLabel, playerXp,
updateButton
2021-02-04 11:53:40 +03:00
);
mainWindow.Add(delverPathLabel, delverPathField, savesWindow, dataWindow);
2021-02-04 16:44:07 +03:00
top.Add(menuWindow, mainWindow);
2021-02-04 11:53:40 +03:00
Application.Run();
2021-02-04 00:04:05 +03:00
}
2021-02-04 11:53:40 +03:00
static bool Quit()
2021-02-04 00:04:05 +03:00
{
2021-02-04 16:44:07 +03:00
var n = MessageBox.Query (20, 5, "Quit", "Вы лох?", "Yes", "No");
2021-02-04 00:04:05 +03:00
return n == 0;
}
2021-02-04 16:44:07 +03:00
2021-02-04 21:11:31 +03:00
// return Delver path
static string loadGamePath()
2021-02-04 16:44:07 +03:00
{
// check config.json file exist
2021-02-04 21:11:31 +03:00
if (File.Exists("./config.json"))
2021-02-04 16:44:07 +03:00
{
2021-02-04 21:11:31 +03:00
string jsonString = System.IO.File.ReadAllText("./config.json");
var data = JsonSerializer.Deserialize<Dictionary<string, string>>(jsonString);
2021-02-04 16:44:07 +03:00
2021-02-04 21:11:31 +03:00
return(data["delver_path"]);
2021-02-04 16:44:07 +03:00
}
else
{
2021-02-04 21:11:31 +03:00
// create file with "default" path
StreamWriter configFile = System.IO.File.CreateText("./config.json");
configFile.WriteLine("{\n \"delver_path\": \"C:\\\\\"\n}");
configFile.Close();
2021-02-04 16:44:07 +03:00
return("C:\\");
}
}
static void saveReadFile()
{
// string text = System.IO.File.ReadAllText(@"C:\Users\Public\TestFolder\WriteText.txt");
}
static void loadSavesSlot()
{
// try
// {
// string[] savesSlots = Directory.GetDirectories(@"c:\", "p*", SearchOption.TopDirectoryOnly);
// Console.WriteLine("The number of directories starting with p is {0}.", dirs.Length);
// foreach (string dir in dirs)
// {
// Console.WriteLine(dir);
// }
// }
// catch (Exception e)
// {
// Console.WriteLine("The process failed: {0}", e.ToString());
// }
}
2021-02-04 00:04:05 +03:00
}