2011-12-04 05:09:49 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Substrate.Nbt;
|
|
|
|
|
|
2011-12-04 07:18:27 +00:00
|
|
|
|
namespace NBTExplorer
|
2011-12-04 05:09:49 +00:00
|
|
|
|
{
|
|
|
|
|
public partial class EditValue : Form
|
|
|
|
|
{
|
|
|
|
|
private TagNode _tag;
|
|
|
|
|
|
|
|
|
|
public EditValue (TagNode tag)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
_tag = tag;
|
|
|
|
|
|
|
|
|
|
if (tag == null) {
|
|
|
|
|
DialogResult = DialogResult.Abort;
|
|
|
|
|
Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
textBox1.Text = _tag.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TagNode NodeTag
|
|
|
|
|
{
|
|
|
|
|
get { return _tag; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-24 03:58:11 +00:00
|
|
|
|
private void Apply ()
|
2011-12-04 05:09:49 +00:00
|
|
|
|
{
|
2012-08-24 03:58:11 +00:00
|
|
|
|
if (ValidateInput()) {
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
Close();
|
2011-12-04 05:09:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ValidateInput ()
|
|
|
|
|
{
|
2012-08-24 03:58:11 +00:00
|
|
|
|
return ValidateValueInput();
|
2011-12-04 05:09:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ValidateValueInput ()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
switch (_tag.GetTagType()) {
|
|
|
|
|
case TagType.TAG_BYTE:
|
|
|
|
|
_tag.ToTagByte().Data = byte.Parse(textBox1.Text);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TagType.TAG_SHORT:
|
|
|
|
|
_tag.ToTagShort().Data = short.Parse(textBox1.Text);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TagType.TAG_INT:
|
|
|
|
|
_tag.ToTagInt().Data = int.Parse(textBox1.Text);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TagType.TAG_LONG:
|
|
|
|
|
_tag.ToTagLong().Data = long.Parse(textBox1.Text);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TagType.TAG_FLOAT:
|
|
|
|
|
_tag.ToTagFloat().Data = float.Parse(textBox1.Text);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TagType.TAG_DOUBLE:
|
|
|
|
|
_tag.ToTagDouble().Data = double.Parse(textBox1.Text);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TagType.TAG_STRING:
|
|
|
|
|
_tag.ToTagString().Data = textBox1.Text;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (FormatException) {
|
|
|
|
|
MessageBox.Show("The value is formatted incorrectly for the given type.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
catch (OverflowException) {
|
|
|
|
|
MessageBox.Show("The value is outside the acceptable range for the given type.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
catch {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-24 03:58:11 +00:00
|
|
|
|
private void _buttonOK_Click (object sender, EventArgs e)
|
2011-12-04 05:09:49 +00:00
|
|
|
|
{
|
2012-08-24 03:58:11 +00:00
|
|
|
|
Apply();
|
2011-12-04 05:09:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|