mirror of
https://github.com/AdAstra-LD/DS-Pokemon-Rom-Editor.git
synced 2026-09-09 19:55:18 -05:00
Code formatting & minor refactors
This commit is contained in:
@@ -10,11 +10,12 @@ using static DSPRE.RomInfo;
|
||||
namespace DSPRE {
|
||||
public partial class BuildingEditor : Form {
|
||||
#region Variables
|
||||
string folder;
|
||||
public static string temp_btxname = "BLDtexture.nsbtx";
|
||||
private readonly string folder;
|
||||
bool disableHandlers = new bool();
|
||||
RomInfo rom;
|
||||
readonly RomInfo rom;
|
||||
NSBMD currentNSBMD;
|
||||
NSBMDGlRenderer renderer = new NSBMDGlRenderer();
|
||||
readonly NSBMDGlRenderer renderer = new NSBMDGlRenderer();
|
||||
|
||||
public static float ang = 0.0f;
|
||||
public static float dist = 12.8f;
|
||||
@@ -34,8 +35,9 @@ namespace DSPRE {
|
||||
buildingOpenGLControl.MouseWheel += new MouseEventHandler(buildingOpenGLControl_MouseWheel);
|
||||
Gl.glEnable(Gl.GL_TEXTURE_2D);
|
||||
|
||||
if (RomInfo.gameFamily == gFamEnum.HGSS)
|
||||
if (RomInfo.gameFamily == gFamEnum.HGSS) {
|
||||
interiorCheckBox.Enabled = true;
|
||||
}
|
||||
|
||||
disableHandlers = true;
|
||||
FillListBox(false);
|
||||
@@ -48,7 +50,6 @@ namespace DSPRE {
|
||||
#region Subroutines
|
||||
private void CreateEmbeddedTexturesFile(int modelID, bool interior) {
|
||||
string readingPath = folder + rom.GetBuildingModelsDirPath(interior) + "\\" + modelID.ToString("D4");
|
||||
string writingPath = Path.GetTempPath() + "BLDtexture.nsbtx";
|
||||
|
||||
byte[] txFile = File.ReadAllBytes(readingPath);
|
||||
byte[] texData = DSUtils.GetTexturesFromTexturedNSBMD(txFile);
|
||||
@@ -57,7 +58,7 @@ namespace DSPRE {
|
||||
Console.WriteLine("No textures found");
|
||||
return;
|
||||
}
|
||||
DSUtils.WriteToFile(writingPath, texData, fromScratch: true);
|
||||
DSUtils.WriteToFile(Path.GetTempPath() + temp_btxname, texData, fromScratch: true);
|
||||
}
|
||||
private void FillListBox(bool interior) {
|
||||
int modelCount = Directory.GetFiles(folder + rom.GetBuildingModelsDirPath(interior)).Length;
|
||||
@@ -74,8 +75,9 @@ namespace DSPRE {
|
||||
int texturesCount = Directory.GetFiles(folder + RomInfo.gameDirs[DirNames.buildingTextures].unpackedDir).Length;
|
||||
textureComboBox.Items.Add("Embedded textures");
|
||||
|
||||
for (int i = 0; i < texturesCount; i++)
|
||||
for (int i = 0; i < texturesCount; i++) {
|
||||
textureComboBox.Items.Add("Texture " + i);
|
||||
}
|
||||
}
|
||||
private void LoadBuildingModel(int modelID, bool interior) {
|
||||
string path = folder + rom.GetBuildingModelsDirPath(interior) + "\\" + modelID.ToString("D4");
|
||||
@@ -84,10 +86,12 @@ namespace DSPRE {
|
||||
}
|
||||
private void LoadModelTextures(int fileID) {
|
||||
string path;
|
||||
if (fileID > -1)
|
||||
if (fileID > -1) {
|
||||
path = folder + RomInfo.gameDirs[RomInfo.DirNames.buildingTextures].unpackedDir + "\\" + fileID.ToString("D4");
|
||||
else
|
||||
path = Path.GetTempPath() + "BLDtexture.nsbtx"; // Load Embedded textures if the argument passed to this function is -1
|
||||
} else {
|
||||
path = Path.GetTempPath() + temp_btxname; // Load Embedded textures if the argument passed to this function is -1
|
||||
}
|
||||
|
||||
try {
|
||||
currentNSBMD.materials = NSBTXLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(path)), out currentNSBMD.Textures, out currentNSBMD.Palettes);
|
||||
currentNSBMD.MatchTextures();
|
||||
@@ -146,12 +150,14 @@ namespace DSPRE {
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void buildingOpenGLControl_MouseWheel(object sender, MouseEventArgs e) // Zoom In/Out
|
||||
{
|
||||
if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
|
||||
dist += (float)e.Delta / 200;
|
||||
else
|
||||
dist -= (float)e.Delta / 200;
|
||||
private void buildingOpenGLControl_MouseWheel(object sender, MouseEventArgs e) { // Zoom In/Out
|
||||
float val = (float)e.Delta / 200;
|
||||
if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) {
|
||||
dist += val;
|
||||
} else {
|
||||
dist -= val;
|
||||
}
|
||||
|
||||
RenderModel();
|
||||
}
|
||||
private void buildingEditorListBox_SelectedIndexChanged(object sender, EventArgs e) {
|
||||
@@ -165,19 +171,23 @@ namespace DSPRE {
|
||||
RenderModel();
|
||||
}
|
||||
private void exportButton_Click(object sender, EventArgs e) {
|
||||
SaveFileDialog em = new SaveFileDialog();
|
||||
em.Filter = "NSBMD model (*.nsbmd)|*.nsbmd";
|
||||
em.FileName = buildingEditorBldListBox.SelectedItem.ToString();
|
||||
if (em.ShowDialog(this) != DialogResult.OK)
|
||||
SaveFileDialog em = new SaveFileDialog {
|
||||
Filter = "NSBMD model (*.nsbmd)|*.nsbmd",
|
||||
FileName = buildingEditorBldListBox.SelectedItem.ToString()
|
||||
};
|
||||
if (em.ShowDialog(this) != DialogResult.OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
File.Copy(folder + rom.GetBuildingModelsDirPath(interiorCheckBox.Checked) + "\\" + buildingEditorBldListBox.SelectedIndex.ToString("D4"), em.FileName, true);
|
||||
}
|
||||
private void importButton_Click(object sender, EventArgs e) {
|
||||
OpenFileDialog im = new OpenFileDialog();
|
||||
im.Filter = "NSBMD model (*.nsbmd)|*.nsbmd";
|
||||
if (im.ShowDialog(this) != DialogResult.OK)
|
||||
OpenFileDialog im = new OpenFileDialog {
|
||||
Filter = "NSBMD model (*.nsbmd)|*.nsbmd"
|
||||
};
|
||||
if (im.ShowDialog(this) != DialogResult.OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
using (BinaryReader reader = new BinaryReader(new FileStream(im.FileName, FileMode.Open))) {
|
||||
if (reader.ReadUInt32() != NSBMD.NDS_TYPE_BMD0) {
|
||||
|
||||
@@ -4157,8 +4157,9 @@ namespace DSPRE {
|
||||
OpenFileDialog ip = new OpenFileDialog {
|
||||
Filter = "Permissions File (*.per)|*.per"
|
||||
};
|
||||
if (ip.ShowDialog(this) != DialogResult.OK)
|
||||
if (ip.ShowDialog(this) != DialogResult.OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentMapFile.ImportPermissions(new FileStream(ip.FileName, FileMode.Open));
|
||||
|
||||
@@ -4301,8 +4302,9 @@ namespace DSPRE {
|
||||
OpenFileDialog im = new OpenFileDialog {
|
||||
Filter = "NSBMD model (*.nsbmd)|*.nsbmd"
|
||||
};
|
||||
if (im.ShowDialog(this) != DialogResult.OK)
|
||||
if (im.ShowDialog(this) != DialogResult.OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentMapFile.LoadMapModel(DSUtils.ReadFromFile(im.FileName));
|
||||
|
||||
@@ -4326,11 +4328,13 @@ namespace DSPRE {
|
||||
MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
private void exportMapButton_Click(object sender, EventArgs e) {
|
||||
SaveFileDialog em = new SaveFileDialog();
|
||||
em.Filter = "NSBMD model (*.nsbmd)|*.nsbmd";
|
||||
em.FileName = selectMapComboBox.SelectedItem.ToString();
|
||||
if (em.ShowDialog(this) != DialogResult.OK)
|
||||
SaveFileDialog em = new SaveFileDialog {
|
||||
Filter = "NSBMD model (*.nsbmd)|*.nsbmd",
|
||||
FileName = selectMapComboBox.SelectedItem.ToString()
|
||||
};
|
||||
if (em.ShowDialog(this) != DialogResult.OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (embedTexturesInMapModelCheckBox.Checked) {
|
||||
string texturePath = RomInfo.gameDirs[DirNames.mapTextures].unpackedDir + "\\" + (mapTextureComboBox.SelectedIndex - 1).ToString("D4");
|
||||
@@ -4353,8 +4357,9 @@ namespace DSPRE {
|
||||
it.Filter = "Terrain File (*.bdhc, *.bdhcam)|*.bdhc;*.bdhcam";
|
||||
}
|
||||
|
||||
if (it.ShowDialog(this) != DialogResult.OK)
|
||||
if (it.ShowDialog(this) != DialogResult.OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentMapFile.ImportTerrain(new FileStream(it.FileName, FileMode.Open));
|
||||
TerrainSizeTXT.Text = currentMapFile.bdhc.Length.ToString() + " B";
|
||||
@@ -4365,11 +4370,13 @@ namespace DSPRE {
|
||||
Filter = "Terrain File (*.bdhc)|*.bdhc",
|
||||
FileName = selectMapComboBox.SelectedItem.ToString()
|
||||
};
|
||||
if (eb.ShowDialog(this) != DialogResult.OK)
|
||||
if (eb.ShowDialog(this) != DialogResult.OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(eb.FileName)))
|
||||
using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(eb.FileName))) {
|
||||
writer.Write(currentMapFile.bdhc);
|
||||
}
|
||||
|
||||
TerrainSizeTXT.Text = currentMapFile.bdhc.Length.ToString() + " B";
|
||||
MessageBox.Show("Terrain settings exported successfully!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
@@ -4379,8 +4386,9 @@ namespace DSPRE {
|
||||
Filter = "BackGround Sound File (*.bgs)|*.bgs"
|
||||
};
|
||||
|
||||
if (it.ShowDialog(this) != DialogResult.OK)
|
||||
if (it.ShowDialog(this) != DialogResult.OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentMapFile.ImportSoundPlates(new FileStream(it.FileName, FileMode.Open));
|
||||
BGSSizeTXT.Text = currentMapFile.bgs.Length.ToString() + " B";
|
||||
@@ -4391,11 +4399,13 @@ namespace DSPRE {
|
||||
Filter = "BackGround Sound File (*.bgs)|*.bgs",
|
||||
FileName = selectMapComboBox.SelectedItem.ToString()
|
||||
};
|
||||
if (eb.ShowDialog(this) != DialogResult.OK)
|
||||
if (eb.ShowDialog(this) != DialogResult.OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(eb.FileName)))
|
||||
using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(eb.FileName))) {
|
||||
writer.Write(currentMapFile.bgs);
|
||||
}
|
||||
|
||||
BGSSizeTXT.Text = currentMapFile.bgs.Length.ToString() + " B";
|
||||
MessageBox.Show("BackGround Sound data exported successfully!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
@@ -4649,23 +4659,27 @@ namespace DSPRE {
|
||||
}
|
||||
private void FillSpawnablesBox() {
|
||||
spawnablesListBox.Items.Clear();
|
||||
for (int i = 0; i < currentEvFile.spawnables.Count; i++)
|
||||
for (int i = 0; i < currentEvFile.spawnables.Count; i++) {
|
||||
spawnablesListBox.Items.Add("Spawnable " + i);
|
||||
}
|
||||
}
|
||||
private void FillOverworldsBox() {
|
||||
overworldsListBox.Items.Clear();
|
||||
for (int i = 0; i < currentEvFile.overworlds.Count; i++)
|
||||
for (int i = 0; i < currentEvFile.overworlds.Count; i++) {
|
||||
overworldsListBox.Items.Add("Overworld " + i);
|
||||
}
|
||||
}
|
||||
private void FillWarpsBox() {
|
||||
warpsListBox.Items.Clear();
|
||||
for (int i = 0; i < currentEvFile.warps.Count; i++)
|
||||
for (int i = 0; i < currentEvFile.warps.Count; i++) {
|
||||
warpsListBox.Items.Add("Warp " + i);
|
||||
}
|
||||
}
|
||||
private void FillTriggersBox() {
|
||||
triggersListBox.Items.Clear();
|
||||
for (int i = 0; i < currentEvFile.triggers.Count; i++)
|
||||
for (int i = 0; i < currentEvFile.triggers.Count; i++) {
|
||||
triggersListBox.Items.Add("Trigger " + i);
|
||||
}
|
||||
}
|
||||
private Bitmap GetOverworldImage(ushort eventEntryID, ushort orientation) {
|
||||
/* Find sprite corresponding to ID and load it*/
|
||||
|
||||
Reference in New Issue
Block a user