Tweak Box name get/set

This commit is contained in:
Kaphotics 2016-02-01 22:33:10 -08:00
parent 10f542f240
commit a329a17c62
2 changed files with 21 additions and 18 deletions

View file

@ -649,7 +649,12 @@ namespace PKHeX
}
public string getBoxName(int box)
{
return Encoding.Unicode.GetString(Data, PCLayout + 0x22*box, 0x22).Trim();
return Util.TrimFromZero(Encoding.Unicode.GetString(Data, PCLayout + 0x22*box, 0x22));
}
public void setBoxName(int box, string val)
{
Encoding.Unicode.GetBytes(val.PadRight(0x11, '\0')).CopyTo(Data, PCLayout + 0x22*box);
Edited = true;
}
public void setParty()
{

View file

@ -1,6 +1,5 @@
using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PKHeX
@ -11,7 +10,7 @@ namespace PKHeX
{
InitializeComponent();
Util.TranslateInterface(this, Main.curlanguage);
sav = (byte[])Main.SAV.Data.Clone();
sav = new SAV6((byte[])Main.SAV.Data.Clone());
editing = true;
// Repopulate Wallpaper names
@ -20,29 +19,28 @@ namespace PKHeX
CB_BG.Items.Add(wallpaper);
// Go
MT_BG1.Text = sav[Main.SAV.PCFlags + 0].ToString();
CB_Unlocked.SelectedIndex = sav[Main.SAV.PCFlags + 1] - 1;
MT_BG2.Text = sav[Main.SAV.PCFlags + 2].ToString();
MT_BG1.Text = sav.Data[sav.PCFlags + 0].ToString();
CB_Unlocked.SelectedIndex = sav.Data[sav.PCFlags + 1] - 1;
MT_BG2.Text = sav.Data[sav.PCFlags + 2].ToString();
LB_BoxSelect.SelectedIndex = box;
}
public byte[] sav;
public SAV6 sav;
public bool editing;
private void changeBox(object sender, EventArgs e)
{
editing = true;
int bgoff = Main.SAV.PCBackgrounds + LB_BoxSelect.SelectedIndex;
CB_BG.SelectedIndex = sav[bgoff];
TB_BoxName.Text = Encoding.Unicode.GetString(sav, Main.SAV.PCLayout + 0x22 * LB_BoxSelect.SelectedIndex, 0x22).Trim();
int bgoff = sav.PCBackgrounds + LB_BoxSelect.SelectedIndex;
CB_BG.SelectedIndex = sav.Data[bgoff];
TB_BoxName.Text = sav.getBoxName(LB_BoxSelect.SelectedIndex);
editing = false;
}
private void changeBoxDetails(object sender, EventArgs e)
{
if (!editing)
Encoding.Unicode.GetBytes(TB_BoxName.Text.PadRight(17))
.CopyTo(sav, Main.SAV.PCLayout + 0x22 * LB_BoxSelect.SelectedIndex);
sav.setBoxName(LB_BoxSelect.SelectedIndex, TB_BoxName.Text);
}
private void B_Cancel_Click(object sender, EventArgs e)
{
@ -50,11 +48,11 @@ namespace PKHeX
}
private void B_Save_Click(object sender, EventArgs e)
{
sav[Main.SAV.PCFlags + 0] = (byte)Util.ToUInt32(MT_BG1.Text);
sav[Main.SAV.PCFlags + 1] = (byte)Util.ToUInt32(CB_Unlocked.Text);
sav[Main.SAV.PCFlags + 2] = (byte)Util.ToUInt32(MT_BG2.Text);
sav.Data[sav.PCFlags + 0] = (byte)Util.ToUInt32(MT_BG1.Text);
sav.Data[sav.PCFlags + 1] = (byte)Util.ToUInt32(CB_Unlocked.Text);
sav.Data[sav.PCFlags + 2] = (byte)Util.ToUInt32(MT_BG2.Text);
Array.Copy(sav, Main.SAV.Data, sav.Length);
Array.Copy(sav.Data, Main.SAV.Data, sav.Data.Length);
Main.SAV.Edited = true;
Close();
}
@ -62,9 +60,9 @@ namespace PKHeX
private void changeBoxBG(object sender, EventArgs e)
{
if (!editing)
sav[Main.SAV.PCBackgrounds + LB_BoxSelect.SelectedIndex] = (byte)CB_BG.SelectedIndex;
sav.Data[Main.SAV.PCBackgrounds + LB_BoxSelect.SelectedIndex] = (byte)CB_BG.SelectedIndex;
string imagename = "box_wp" + (CB_BG.SelectedIndex + 1).ToString("00"); if (Main.SAV.ORAS && CB_BG.SelectedIndex + 1 > 16) imagename += "o";
string imagename = "box_wp" + (CB_BG.SelectedIndex + 1).ToString("00"); if (sav.ORAS && CB_BG.SelectedIndex + 1 > 16) imagename += "o";
PAN_BG.BackgroundImage = (Image)Properties.Resources.ResourceManager.GetObject(imagename);
}
}