2015-06-30 00:07:12 +07:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace FalloutClient {
|
2019-04-04 10:22:02 +08:00
|
|
|
|
|
|
|
|
public enum DataType : int { None = 0, Int = 1, Float = 2, String = 3 }
|
|
|
|
|
|
|
|
|
|
public partial class EditorWindow : Form
|
|
|
|
|
{
|
2015-06-30 00:07:12 +07:00
|
|
|
private readonly DataType[] types;
|
|
|
|
|
private readonly string[] values;
|
|
|
|
|
private bool save;
|
|
|
|
|
|
2019-04-05 09:17:43 +08:00
|
|
|
private EditorWindow(string[] names, DataType[] types, string[] values, bool isMap) {
|
2019-04-04 10:22:02 +08:00
|
|
|
this.types = types;
|
|
|
|
|
this.values = values;
|
2015-06-30 00:07:12 +07:00
|
|
|
InitializeComponent();
|
|
|
|
|
dataGridView1.SuspendLayout();
|
2019-04-04 10:22:02 +08:00
|
|
|
if (names == null)
|
2019-04-05 09:17:43 +08:00
|
|
|
for (int i = 0; i < types.Length; i++) {
|
|
|
|
|
string element = i.ToString();
|
|
|
|
|
if (isMap && (i % 2) == 0) element += " - Key";
|
|
|
|
|
dataGridView1.Rows.Add(element, types[i].ToString(), values[i]);
|
|
|
|
|
}
|
2019-04-04 10:22:02 +08:00
|
|
|
else
|
2019-04-05 09:17:43 +08:00
|
|
|
for (int i = 0; i < types.Length; i++) dataGridView1.Rows.Add("[0x" + (i * 4).ToString("x").ToUpper() + "]" + names[i], types[i].ToString(), values[i]);
|
2015-06-30 00:07:12 +07:00
|
|
|
dataGridView1.ResumeLayout();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-05 09:17:43 +08:00
|
|
|
public static string[] ShowEditor(string[] names, DataType[] types, string[] values, bool isMap = false) {
|
|
|
|
|
EditorWindow editor = new EditorWindow(names, types, values, isMap);
|
2015-06-30 00:07:12 +07:00
|
|
|
editor.ShowDialog();
|
2019-04-04 10:22:02 +08:00
|
|
|
if (editor.save)
|
|
|
|
|
return editor.values;
|
|
|
|
|
else
|
|
|
|
|
return null;
|
2015-06-30 00:07:12 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool CheckInput(DataType type, string str) {
|
2019-04-04 10:22:02 +08:00
|
|
|
switch (type) {
|
2015-06-30 00:07:12 +07:00
|
|
|
case DataType.Int:
|
|
|
|
|
int i;
|
|
|
|
|
return int.TryParse(str, out i);
|
|
|
|
|
case DataType.Float:
|
|
|
|
|
float f;
|
|
|
|
|
return float.TryParse(str, out f);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
|
2019-04-04 10:22:02 +08:00
|
|
|
string str = (string)dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
|
|
|
|
|
if (CheckInput(types[e.RowIndex], str))
|
|
|
|
|
values[e.RowIndex] = str;
|
|
|
|
|
else
|
|
|
|
|
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = values[e.RowIndex];
|
2015-06-30 00:07:12 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void bCancel_Click(object sender, EventArgs e) {
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void bSave_Click(object sender, EventArgs e) {
|
2019-04-04 10:22:02 +08:00
|
|
|
save = true;
|
2015-06-30 00:07:12 +07:00
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|