160 lines
4.1 KiB
C#
160 lines
4.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
|
|
public class SettingsToHtml : MonoBehaviour
|
|
{
|
|
|
|
const string FORM_GROUP_STYLE = "style=\"border: 2px solid black;border-radius: 5px;\"";
|
|
|
|
|
|
public static string GetSettingsPage(List<Setting> settings)
|
|
{
|
|
return Decorate(GetSettingsString(settings));
|
|
}
|
|
|
|
public static string GetSettingsString(List<Setting> settings)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.AppendLine("<h1>Настройки фишки</h1>");
|
|
|
|
sb.AppendLine("<form action=\"/upd\" method=\"POST\" class=\"form-root\">");
|
|
foreach (Setting setting in settings)
|
|
{
|
|
string view = string.Empty;
|
|
|
|
if(setting.Type== SettingType.Bool)
|
|
{
|
|
view = GetBoolView(setting);
|
|
}
|
|
else if(setting.Type == SettingType.Float)
|
|
{
|
|
view = GetFloatView(setting);
|
|
}
|
|
else if(setting.Type == SettingType.String)
|
|
{
|
|
view = GetStringView(setting);
|
|
}
|
|
else
|
|
{
|
|
view = $"<p>{setting.Alias}: {setting.IntValue.ToString()}</p>";
|
|
}
|
|
sb.AppendLine(view);
|
|
}
|
|
sb.AppendLine("<input type=\"submit\">");
|
|
sb.AppendLine("</form>");
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
|
|
|
|
private static string GetBoolView(Setting setting)
|
|
{
|
|
string name = setting.Id;
|
|
string id = name + "ID";
|
|
|
|
|
|
string res = string.Empty;
|
|
res += $"<div class=\"form-group\" {FORM_GROUP_STYLE}>";
|
|
res += $"<label for=\"{id}\">{setting.Alias}</label>";
|
|
string ischecked = setting.BoolValue ? "checked" : "";
|
|
res += $"<input type=\"checkbox\" name=\"{name}\" id=\"{id}\" {ischecked}>";
|
|
res += "</div>";
|
|
|
|
return res;
|
|
}
|
|
|
|
private static string GetFloatView(Setting setting)
|
|
{
|
|
string name = setting.Id;
|
|
string id = name + "ID";
|
|
string res = string.Empty;
|
|
|
|
string min = setting.FloatMin.ToString(CultureInfo.InvariantCulture);
|
|
string max = setting.FloatMax.ToString(CultureInfo.InvariantCulture);
|
|
string value = setting.FloatValue.ToString(CultureInfo.InvariantCulture);
|
|
string step = setting.FloatStep.ToString(CultureInfo.InvariantCulture);
|
|
|
|
res += $"<div class=\"form-group\" {FORM_GROUP_STYLE}>";
|
|
res += $"<label for=\"{id}\">{setting.Alias}</label>";
|
|
res += $"<input id=\"{id}\" type=\"range\" min=\"{min}\" max=\"{max}\" value=\"{value}\" step=\"{step}\" name=\"{name}\">";
|
|
res += "</div>";
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
private static string GetStringView(Setting setting)
|
|
{
|
|
string res = string.Empty;
|
|
|
|
res += $"<div class=\"form-group\" {FORM_GROUP_STYLE}>";
|
|
res += $"<p>{setting.Alias}</p>";
|
|
|
|
for (int i = 0; i < setting.AllowedValues.Count; i++)
|
|
{
|
|
string stringValue = setting.AllowedValues[i];
|
|
|
|
string name = setting.Id;
|
|
string id = name + "ID";
|
|
|
|
|
|
bool isChecked = setting.StringValue == stringValue;
|
|
string Checked = isChecked ? "checked" : "";
|
|
|
|
|
|
|
|
res += "<div>";
|
|
|
|
res += $"<label for=\"ID\">{stringValue}</label>";
|
|
res += $"<input type=\"radio\" id=\"{id}\" name=\"{name}\" value=\"{stringValue}\" {Checked}>";
|
|
|
|
|
|
res += "</div>";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
res += "</div>";
|
|
|
|
|
|
|
|
|
|
return res;
|
|
}
|
|
|
|
private static string GetIntView(Setting setting)
|
|
{
|
|
|
|
return string.Empty;
|
|
}
|
|
|
|
private static string Decorate(string content)
|
|
{
|
|
string res = "<!DOCTYPE html>"
|
|
+ "<html lang=\"ru\">"
|
|
+ "<head>"
|
|
+ "<meta charset=\"utf-8\">"
|
|
+ "<link rel=\"stylesheet\" href=\"style.css\">"
|
|
+ "<title>Настройки Фишки</title>"
|
|
+ "</head>"
|
|
+ "<body>";
|
|
|
|
res += content;
|
|
|
|
res += "</body>" +
|
|
"</html>";
|
|
|
|
return res;
|
|
}
|
|
|
|
|
|
}
|