Null checks + minor refactor + enforcing if brackets

This commit is contained in:
AdAstra-LD 2024-06-11 13:46:07 +02:00
parent 23b19eff54
commit 7520a264e2
39 changed files with 715 additions and 714 deletions

View File

@ -133,17 +133,15 @@ namespace DSPRE {
}
public static void TryUnpackNarcs(List<DirNames> IDs) {
if (gameDirs == null || gameDirs.Count == 0) {
return;
}
Parallel.ForEach(IDs, id => {
if (gameDirs.TryGetValue(id, out (string packedPath, string unpackedPath) paths)) {
DirectoryInfo di = new DirectoryInfo(paths.unpackedPath);
if (!di.Exists || di.GetFiles().Length == 0) {
Narc opened = Narc.Open(paths.packedPath);
if (opened is null) {
throw new NullReferenceException();
}
Narc opened = Narc.Open(paths.packedPath) ?? throw new NullReferenceException();
opened.ExtractToFolder(paths.unpackedPath);
}
}

View File

@ -342,7 +342,7 @@ namespace DSPRE
private void PokemonSelector_TextChanged(object sender, EventArgs e)
{
if (sender == null || !(sender is ComboBox)) { return; }
if (sender == null || !(sender is ComboBox)){ { return; } }
ComboBox comboBox = (ComboBox)sender;
string enteredText = comboBox.Text.ToLower();

View File

@ -8,484 +8,481 @@ using System.Windows.Forms;
using DSPRE.ROMFiles;
namespace DSPRE.Editors {
public partial class HeadbuttEncounterEditor : UserControl {
public bool headbuttEncounterEditorIsReady { get; set; } = false;
public partial class HeadbuttEncounterEditor : UserControl {
public bool headbuttEncounterEditorIsReady { get; set; } = false;
private ListBox2 listBoxTrees;
private HeadbuttTree headbuttTree;
private ListBox2 listBoxTrees;
private HeadbuttTree headbuttTree;
private HeaderHGSS mapHeader;
private HeadbuttEncounterFile headbuttEncounterFile;
private HeadbuttEncounterMap headbuttEncounterMap;
private GameMatrix gameMatrix;
private AreaData areaData;
private MapFile mapFile;
private string locationName;
private HeaderHGSS mapHeader;
private HeadbuttEncounterFile headbuttEncounterFile;
private HeadbuttEncounterMap headbuttEncounterMap;
private GameMatrix gameMatrix;
private AreaData areaData;
private MapFile mapFile;
private string locationName;
private int width;
private int height;
static SimpleOpenGlControl2 openGlControl;
private int width;
private int height;
static SimpleOpenGlControl2 openGlControl;
private Pen selectedPen;
private Pen normalPen;
private SolidBrush normalBrush;
private Pen specialPen;
private SolidBrush specialBrush;
private Pen selectedPen;
private Pen normalPen;
private SolidBrush normalBrush;
private Pen specialPen;
private SolidBrush specialBrush;
private static float perspective;
private static float ang;
private static float dist;
private static float elev;
private static float perspective;
private static float ang;
private static float dist;
private static float elev;
public HeadbuttEncounterEditor() {
InitializeComponent();
}
//TODO: refresh headers list if a header is added
public void SetupHeadbuttEncounterEditor(bool force = false) {
if (headbuttEncounterEditorIsReady && !force) return;
headbuttEncounterEditorIsReady = true;
DSUtils.TryUnpackNarcs(new List<RomInfo.DirNames>() {
RomInfo.DirNames.dynamicHeaders,
RomInfo.DirNames.matrices,
RomInfo.DirNames.textArchives,
RomInfo.DirNames.areaData,
RomInfo.DirNames.headbutt,
RomInfo.DirNames.maps,
RomInfo.DirNames.mapTextures,
RomInfo.DirNames.exteriorBuildingModels,
RomInfo.DirNames.buildingTextures,
});
width = openGlPictureBox.Width;
height = openGlPictureBox.Height;
openGlControl = new SimpleOpenGlControl2();
openGlControl.InitializeContexts();
openGlControl.Width = width;
openGlControl.Height = height;
openGlControl.Invalidate();
openGlControl.MakeCurrent();
List<string> headerListBoxNames = Helpers.getHeaderListBoxNames();
Color selectedColor = Color.FromArgb(255, Color.White);
selectedPen = new Pen(selectedColor);
Color normalColor = Color.FromArgb(128, Color.DarkBlue);
normalPen = new Pen(normalColor);
normalBrush = new SolidBrush(normalColor);
Color specialColor = Color.FromArgb(128, Color.DarkRed);
specialPen = new Pen(specialColor);
specialBrush = new SolidBrush(specialColor);
Helpers.DisableHandlers();
for (int i = 0; i < Filesystem.GetHeadbuttCount(); i++) {
if (i < headerListBoxNames.Count) {
comboBoxMapHeader.Items.Add(headerListBoxNames[i]);
public HeadbuttEncounterEditor() {
InitializeComponent();
}
else {
i.ToString("D4");
}
}
string[] pokemonNames = RomInfo.GetPokemonNames();
headbuttEncounterEditorTabNormal.comboBoxPokemon.Items.AddRange(pokemonNames);
headbuttEncounterEditorTabNormal.comboBoxPokemon.SelectedIndex = 0;
headbuttEncounterEditorTabNormal.listBoxTrees.SelectedIndexChanged += ListBoxTrees_SelectedIndexChanged;
headbuttEncounterEditorTabSpecial.comboBoxPokemon.Items.AddRange(pokemonNames);
headbuttEncounterEditorTabSpecial.comboBoxPokemon.SelectedIndex = 0;
headbuttEncounterEditorTabSpecial.listBoxTrees.SelectedIndexChanged += ListBoxTrees_SelectedIndexChanged;
openGlPictureBox.BringToFront();
SetCam2DValues();
Helpers.EnableHandlers();
if (comboBoxMapHeader.Items.Count > 0) {
comboBoxMapHeader.SelectedIndex = 0;
}
}
public void makeCurrent() {
openGlControl.MakeCurrent();
}
private void comboBoxMapHeader_SelectedIndexChanged(object sender, EventArgs e) {
ushort headbuttID = (ushort)comboBoxMapHeader.SelectedIndex;
this.headbuttEncounterFile = new HeadbuttEncounterFile(headbuttID);
setCurrentMap(headbuttEncounterFile);
}
public void setCurrentMap(HeadbuttEncounterFile headbuttEncounterFile) {
this.mapFile = null;
this.headbuttEncounterMap = null;
comboBoxMapFile.Items.Clear();
labelLocationName.Text = "";
listBoxTrees = null;
if (headbuttTree != null) headbuttTree.picked = false;
headbuttTree = null;
headbuttEncounterEditorTabNormal.Reset();
headbuttEncounterEditorTabSpecial.Reset();
numericUpDownTreeGlobalX.Value = 0;
numericUpDownTreeGlobalY.Value = 0;
numericUpDownTreeMatrixX.Value = 0;
numericUpDownTreeMatrixY.Value = 0;
numericUpDownTreeMapX.Value = 0;
numericUpDownTreeMapY.Value = 0;
RenderBackground();
try {
if (headbuttEncounterFile.ID == GameMatrix.EMPTY) return;
this.mapHeader = (HeaderHGSS)MapHeader.GetMapHeader(headbuttEncounterFile.ID);
}
catch (Exception ex) {
//most likely more headbutt files than map headers
//there should be the same amount
Console.WriteLine(ex);
return;
}
this.gameMatrix = new GameMatrix(mapHeader.matrixID);
this.areaData = new AreaData(mapHeader.areaDataID);
TextArchive currentTextArchive = new TextArchive(RomInfo.locationNamesTextNumber);
this.locationName = currentTextArchive.messages[mapHeader.locationName];
labelLocationName.Text = locationName;
headbuttEncounterEditorTabNormal.SetHeadbuttEncounter(headbuttEncounterFile.normalEncounters, headbuttEncounterFile.normalTreeGroups);
headbuttEncounterEditorTabSpecial.SetHeadbuttEncounter(headbuttEncounterFile.specialEncounters, headbuttEncounterFile.specialTreeGroups);
List<HeadbuttEncounterMap> mapHeaderMapsIDsList = new List<HeadbuttEncounterMap>();
if (gameMatrix.hasHeadersSection) {
for (int y = 0; y < gameMatrix.height; y++) {
for (int x = 0; x < gameMatrix.width; x++) {
if (gameMatrix.headers[y, x] == mapHeader.ID) {
int mapID = gameMatrix.maps[y, x];
if (mapID == GameMatrix.EMPTY) continue;
HeadbuttEncounterMap map = new HeadbuttEncounterMap(mapID, x, y);
if (mapHeaderMapsIDsList.Contains(map)) continue;
mapHeaderMapsIDsList.Add(map);
//TODO: refresh headers list if a header is added
public void SetupHeadbuttEncounterEditor(bool force = false) {
if (headbuttEncounterEditorIsReady && !force) {
return;
}
}
}
}
else {
for (int y = 0; y < gameMatrix.height; y++) {
for (int x = 0; x < gameMatrix.width; x++) {
int mapID = gameMatrix.maps[y, x];
if (mapID == GameMatrix.EMPTY) continue;
HeadbuttEncounterMap map = new HeadbuttEncounterMap(mapID, x, y);
if (mapHeaderMapsIDsList.Contains(map)) continue;
mapHeaderMapsIDsList.Add(map);
}
}
}
foreach (HeadbuttTreeGroup treeGroup in headbuttEncounterFile.normalTreeGroups) {
foreach (HeadbuttTree tree in treeGroup.trees) {
if (tree.unused) continue;
if (tree.matrixX >= gameMatrix.width || tree.matrixY >= gameMatrix.height) continue;
int x = tree.matrixX;
int y = tree.matrixY;
int mapID = gameMatrix.maps[y, x];
if (mapID == GameMatrix.EMPTY) continue;
HeadbuttEncounterMap map = new HeadbuttEncounterMap(mapID, x, y);
if (mapHeaderMapsIDsList.Contains(map)) continue;
mapHeaderMapsIDsList.Add(map);
}
}
headbuttEncounterEditorIsReady = true;
foreach (HeadbuttTreeGroup treeGroup in headbuttEncounterFile.specialTreeGroups) {
foreach (HeadbuttTree tree in treeGroup.trees) {
if (tree.unused) continue;
if (tree.matrixX >= gameMatrix.width || tree.matrixY >= gameMatrix.height) continue;
int x = tree.matrixX;
int y = tree.matrixY;
int mapID = gameMatrix.maps[y, x];
if (mapID == GameMatrix.EMPTY) continue;
HeadbuttEncounterMap map = new HeadbuttEncounterMap(mapID, x, y);
if (mapHeaderMapsIDsList.Contains(map)) continue;
mapHeaderMapsIDsList.Add(map);
}
}
DSUtils.TryUnpackNarcs(new List<RomInfo.DirNames>() {
RomInfo.DirNames.dynamicHeaders,
RomInfo.DirNames.matrices,
RomInfo.DirNames.textArchives,
RomInfo.DirNames.areaData,
RomInfo.DirNames.headbutt,
RomInfo.DirNames.maps,
RomInfo.DirNames.mapTextures,
RomInfo.DirNames.exteriorBuildingModels,
RomInfo.DirNames.buildingTextures,
});
mapHeaderMapsIDsList.Sort((first, second) => {
int ret = first.mapID.CompareTo(second.mapID);
return ret != 0 ? ret : first.x.CompareTo(second.x);
});
foreach (HeadbuttEncounterMap map in mapHeaderMapsIDsList) {
comboBoxMapFile.Items.Add(map);
}
width = openGlPictureBox.Width;
height = openGlPictureBox.Height;
if (comboBoxMapFile.Items.Count > 0) {
comboBoxMapFile.SelectedIndex = 0;
}
}
openGlControl = new SimpleOpenGlControl2();
openGlControl.InitializeContexts();
openGlControl.Width = width;
openGlControl.Height = height;
openGlControl.Invalidate();
openGlControl.MakeCurrent();
private void buttonSave_Click(object sender, EventArgs e) {
if (headbuttEncounterFile == null) return;
headbuttEncounterFile.SaveToFile();
}
List<string> headerListBoxNames = Helpers.getHeaderListBoxNames();
private void buttonSaveAs_Click(object sender, EventArgs e) {
if (headbuttEncounterFile == null) return;
Color selectedColor = Color.FromArgb(255, Color.White);
selectedPen = new Pen(selectedColor);
SaveFileDialog sfd = new SaveFileDialog();
try {
sfd.InitialDirectory = Path.GetDirectoryName(sfd.FileName);
sfd.FileName = Path.GetFileName(sfd.FileName);
}
catch (Exception ex) {
sfd.InitialDirectory = Path.GetDirectoryName(Environment.SpecialFolder.UserProfile.ToString());
sfd.FileName = Path.GetFileName(sfd.FileName);
}
Color normalColor = Color.FromArgb(128, Color.DarkBlue);
normalPen = new Pen(normalColor);
normalBrush = new SolidBrush(normalColor);
if (sfd.ShowDialog() != DialogResult.OK) return;
Color specialColor = Color.FromArgb(128, Color.DarkRed);
specialPen = new Pen(specialColor);
specialBrush = new SolidBrush(specialColor);
headbuttEncounterFile.SaveToFile(sfd.FileName);
}
Helpers.DisableHandlers();
private void buttonImport_Click(object sender, EventArgs e) {
OpenFileDialog ofd = new OpenFileDialog();
try {
ofd.InitialDirectory = Path.GetDirectoryName(ofd.FileName);
ofd.FileName = Path.GetFileName(ofd.FileName);
}
catch (Exception ex) {
ofd.InitialDirectory = Path.GetDirectoryName(Environment.SpecialFolder.UserProfile.ToString());
ofd.FileName = Path.GetFileName(ofd.FileName);
}
for (int i = 0; i < Filesystem.GetHeadbuttCount(); i++) {
if (i < headerListBoxNames.Count) {
comboBoxMapHeader.Items.Add(headerListBoxNames[i]);
} else {
i.ToString("D4");
}
}
if (ofd.ShowDialog() != DialogResult.OK) return;
string[] pokemonNames = RomInfo.GetPokemonNames();
headbuttEncounterEditorTabNormal.comboBoxPokemon.Items.AddRange(pokemonNames);
headbuttEncounterEditorTabNormal.comboBoxPokemon.SelectedIndex = 0;
headbuttEncounterEditorTabNormal.listBoxTrees.SelectedIndexChanged += ListBoxTrees_SelectedIndexChanged;
this.headbuttEncounterFile = new HeadbuttEncounterFile(ofd.FileName);
headbuttEncounterFile.ID = (ushort)comboBoxMapHeader.SelectedIndex;
setCurrentMap(headbuttEncounterFile);
}
headbuttEncounterEditorTabSpecial.comboBoxPokemon.Items.AddRange(pokemonNames);
headbuttEncounterEditorTabSpecial.comboBoxPokemon.SelectedIndex = 0;
headbuttEncounterEditorTabSpecial.listBoxTrees.SelectedIndexChanged += ListBoxTrees_SelectedIndexChanged;
private void comboBoxMapFile_SelectedIndexChanged(object sender, EventArgs e) {
HeadbuttEncounterMap map = comboBoxMapFile.SelectedItem as HeadbuttEncounterMap;
int mapID = gameMatrix.maps[map.y, map.x];
this.mapFile = new MapFile(mapID, RomInfo.gameFamily, discardMoveperms: true);
this.headbuttEncounterMap = map;
RenderBackground();
}
openGlPictureBox.BringToFront();
SetCam2DValues();
private Bitmap GetMapBitmap() {
Bitmap bm = RenderMap();
openGlControl.Invalidate();
return bm;
}
Helpers.EnableHandlers();
private void RenderBackground() {
Bitmap bm = GetMapBitmap();
if (headbuttEncounterFile != null) {
using (Graphics g = Graphics.FromImage(bm)) {
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
MarkTrees(g, headbuttEncounterFile.normalTreeGroups, HeadbuttTree.Types.Normal);
MarkTrees(g, headbuttEncounterFile.specialTreeGroups, HeadbuttTree.Types.Special);
}
}
openGlPictureBox.BackgroundImage = bm;
}
private Bitmap RenderMap() {
MapFile currentMapFile = this.mapFile;
if (currentMapFile == null) {
Bitmap blank = new Bitmap(openGlPictureBox.Width, openGlPictureBox.Height);
using (Graphics g = Graphics.FromImage(blank)) {
g.Clear(Color.Black);
if (comboBoxMapHeader.Items.Count > 0) {
comboBoxMapHeader.SelectedIndex = 0;
}
}
return blank;
}
Helpers.MW_LoadModelTextures(currentMapFile, areaData.mapTileset);
bool isInteriorMap = false;
if (RomInfo.gameFamily == RomInfo.GameFamilies.HGSS && areaData.areaType == AreaData.TYPE_INDOOR) {
isInteriorMap = true;
}
for (int i = 0; i < currentMapFile.buildings.Count; i++) {
Building building = currentMapFile.buildings[i];
building.LoadModelData(isInteriorMap); // Load building nsbmd
Helpers.MW_LoadModelTextures(building, areaData.buildingsTileset); // Load building textures
}
Helpers.RenderMap(ref currentMapFile, openGlControl.Width, openGlControl.Height, ang, dist, elev, perspective);
return Helpers.GrabMapScreenshot(width, height);
}
private void MarkTrees(Graphics g, BindingList<HeadbuttTreeGroup> treeGroups, HeadbuttTree.Types treeType) {
HeadbuttEncounterMap map = comboBoxMapFile.SelectedItem as HeadbuttEncounterMap;
if (map == null) return;
foreach (HeadbuttTreeGroup treeGroup in treeGroups) {
foreach (HeadbuttTree tree in treeGroup.trees) {
if (tree.unused) continue;
if (tree.matrixX != map.x || tree.matrixY != map.y) continue;
MarkTree(g, tree, treeType);
public void makeCurrent() {
openGlControl.MakeCurrent();
}
}
}
private void MarkTree(Graphics g, HeadbuttTree tree, HeadbuttTree.Types treeType) {
Pen paintPen;
SolidBrush paintBrush;
if (treeType == HeadbuttTree.Types.Normal) {
paintPen = normalPen;
paintBrush = normalBrush;
}
else {
paintPen = specialPen;
paintBrush = specialBrush;
}
if (tree.picked) {
paintPen = selectedPen;
}
int tileWidth = openGlControl.Width / MapFile.mapSize;
int tileHeight = openGlControl.Height / MapFile.mapSize;
int tileX = tree.mapX * tileWidth;
int tileY = tree.mapY * tileHeight;
int padding = 1;
Rectangle rectangle = new Rectangle(tileX + padding, tileY + padding, tileWidth - padding, tileHeight - padding);
g.FillRectangle(paintBrush, rectangle);
g.DrawRectangle(paintPen, rectangle);
}
private void ListBoxTrees_SelectedIndexChanged(object sender, EventArgs e) {
listBoxTrees = sender as ListBox2;
headbuttTree = listBoxTrees.SelectedItem as HeadbuttTree;
if (headbuttTree == null) return;
numericUpDownTreeGlobalX.Value = headbuttTree.globalX;
numericUpDownTreeGlobalY.Value = headbuttTree.globalY;
numericUpDownTreeMatrixX.Value = headbuttTree.matrixX;
numericUpDownTreeMatrixY.Value = headbuttTree.matrixY;
numericUpDownTreeMapX.Value = headbuttTree.mapX;
numericUpDownTreeMapY.Value = headbuttTree.mapY;
}
private void openGlPictureBox_Click(object sender, EventArgs e) {
MouseEventArgs mea = (MouseEventArgs)e;
int tileWidth = openGlControl.Width / MapFile.mapSize;
int tileHeight = openGlControl.Height / MapFile.mapSize;
int mouseX = openGlPictureBox.PointToClient(MousePosition).X / tileWidth;
int mouseY = openGlPictureBox.PointToClient(MousePosition).Y / tileHeight;
if (mea.Button == MouseButtons.Left) {
if (this.headbuttEncounterMap != null) {
numericUpDownTreeMatrixX.Value = headbuttEncounterMap.x;
numericUpDownTreeMatrixY.Value = headbuttEncounterMap.y;
numericUpDownTreeMapX.Value = mouseX;
numericUpDownTreeMapY.Value = mouseY;
private void comboBoxMapHeader_SelectedIndexChanged(object sender, EventArgs e) {
ushort headbuttID = (ushort)comboBoxMapHeader.SelectedIndex;
this.headbuttEncounterFile = new HeadbuttEncounterFile(headbuttID);
setCurrentMap(headbuttEncounterFile);
}
}
else if (mea.Button == MouseButtons.Middle) {
//warp
}
else if (mea.Button == MouseButtons.Right) {
if (headbuttTree != null) headbuttTree.picked = false;
if (FindTreeFromMap(headbuttEncounterEditorTabNormal.listBoxTreeGroups, headbuttEncounterEditorTabNormal.listBoxTrees, mouseX, mouseY)) {
tabControl.SelectedTab = tabPageNormal;
public void setCurrentMap(HeadbuttEncounterFile headbuttEncounterFile) {
this.mapFile = null;
this.headbuttEncounterMap = null;
comboBoxMapFile.Items.Clear();
labelLocationName.Text = "";
listBoxTrees = null;
if (headbuttTree != null) { headbuttTree.picked = false; }
headbuttTree = null;
headbuttEncounterEditorTabNormal.Reset();
headbuttEncounterEditorTabSpecial.Reset();
numericUpDownTreeGlobalX.Value = 0;
numericUpDownTreeGlobalY.Value = 0;
numericUpDownTreeMatrixX.Value = 0;
numericUpDownTreeMatrixY.Value = 0;
numericUpDownTreeMapX.Value = 0;
numericUpDownTreeMapY.Value = 0;
RenderBackground();
try {
if (headbuttEncounterFile.ID == GameMatrix.EMPTY) { return; }
this.mapHeader = (HeaderHGSS)MapHeader.GetMapHeader(headbuttEncounterFile.ID);
} catch (Exception ex) {
//most likely more headbutt files than map headers
//there should be the same amount
Console.WriteLine(ex);
return;
}
this.gameMatrix = new GameMatrix(mapHeader.matrixID);
this.areaData = new AreaData(mapHeader.areaDataID);
TextArchive currentTextArchive = new TextArchive(RomInfo.locationNamesTextNumber);
this.locationName = currentTextArchive.messages[mapHeader.locationName];
labelLocationName.Text = locationName;
headbuttEncounterEditorTabNormal.SetHeadbuttEncounter(headbuttEncounterFile.normalEncounters, headbuttEncounterFile.normalTreeGroups);
headbuttEncounterEditorTabSpecial.SetHeadbuttEncounter(headbuttEncounterFile.specialEncounters, headbuttEncounterFile.specialTreeGroups);
List<HeadbuttEncounterMap> mapHeaderMapsIDsList = new List<HeadbuttEncounterMap>();
if (gameMatrix.hasHeadersSection) {
for (int y = 0; y < gameMatrix.height; y++) {
for (int x = 0; x < gameMatrix.width; x++) {
if (gameMatrix.headers[y, x] == mapHeader.ID) {
int mapID = gameMatrix.maps[y, x];
if (mapID == GameMatrix.EMPTY) { continue; }
HeadbuttEncounterMap map = new HeadbuttEncounterMap(mapID, x, y);
if (mapHeaderMapsIDsList.Contains(map)) { continue; }
mapHeaderMapsIDsList.Add(map);
}
}
}
} else {
for (int y = 0; y < gameMatrix.height; y++) {
for (int x = 0; x < gameMatrix.width; x++) {
int mapID = gameMatrix.maps[y, x];
if (mapID == GameMatrix.EMPTY) { continue; }
HeadbuttEncounterMap map = new HeadbuttEncounterMap(mapID, x, y);
if (mapHeaderMapsIDsList.Contains(map)) { continue; }
mapHeaderMapsIDsList.Add(map);
}
}
}
foreach (HeadbuttTreeGroup treeGroup in headbuttEncounterFile.normalTreeGroups) {
foreach (HeadbuttTree tree in treeGroup.trees) {
if (tree.unused) { continue; }
if (tree.matrixX >= gameMatrix.width || tree.matrixY >= gameMatrix.height) { continue; }
int x = tree.matrixX;
int y = tree.matrixY;
int mapID = gameMatrix.maps[y, x];
if (mapID == GameMatrix.EMPTY) { continue; }
HeadbuttEncounterMap map = new HeadbuttEncounterMap(mapID, x, y);
if (mapHeaderMapsIDsList.Contains(map)) { continue; }
mapHeaderMapsIDsList.Add(map);
}
}
foreach (HeadbuttTreeGroup treeGroup in headbuttEncounterFile.specialTreeGroups) {
foreach (HeadbuttTree tree in treeGroup.trees) {
if (tree.unused) { continue; }
if (tree.matrixX >= gameMatrix.width || tree.matrixY >= gameMatrix.height) { continue; }
int x = tree.matrixX;
int y = tree.matrixY;
int mapID = gameMatrix.maps[y, x];
if (mapID == GameMatrix.EMPTY) { continue; }
HeadbuttEncounterMap map = new HeadbuttEncounterMap(mapID, x, y);
if (mapHeaderMapsIDsList.Contains(map)) { continue; }
mapHeaderMapsIDsList.Add(map);
}
}
mapHeaderMapsIDsList.Sort((first, second) => {
int ret = first.mapID.CompareTo(second.mapID);
return ret != 0 ? ret : first.x.CompareTo(second.x);
});
foreach (HeadbuttEncounterMap map in mapHeaderMapsIDsList) {
comboBoxMapFile.Items.Add(map);
}
if (comboBoxMapFile.Items.Count > 0) {
comboBoxMapFile.SelectedIndex = 0;
}
}
else if (FindTreeFromMap(headbuttEncounterEditorTabSpecial.listBoxTreeGroups, headbuttEncounterEditorTabSpecial.listBoxTrees, mouseX, mouseY)) {
tabControl.SelectedTab = tabPageSpecial;
private void buttonSave_Click(object sender, EventArgs e) {
if (headbuttEncounterFile == null) { return; }
headbuttEncounterFile.SaveToFile();
}
else {
headbuttEncounterEditorTabNormal.listBoxTreeGroups.SelectedItem = null;
headbuttEncounterEditorTabNormal.listBoxTrees.SelectedItem = null;
headbuttEncounterEditorTabSpecial.listBoxTreeGroups.SelectedItem = null;
headbuttEncounterEditorTabSpecial.listBoxTrees.SelectedItem = null;
private void buttonSaveAs_Click(object sender, EventArgs e) {
if (headbuttEncounterFile == null) { return; }
SaveFileDialog sfd = new SaveFileDialog();
try {
sfd.InitialDirectory = Path.GetDirectoryName(sfd.FileName);
sfd.FileName = Path.GetFileName(sfd.FileName);
} catch (Exception ex) {
sfd.InitialDirectory = Path.GetDirectoryName(Environment.SpecialFolder.UserProfile.ToString());
sfd.FileName = Path.GetFileName(sfd.FileName);
}
if (sfd.ShowDialog() != DialogResult.OK) { return; }
headbuttEncounterFile.SaveToFile(sfd.FileName);
}
}
RenderBackground();
}
private void buttonImport_Click(object sender, EventArgs e) {
OpenFileDialog ofd = new OpenFileDialog();
try {
ofd.InitialDirectory = Path.GetDirectoryName(ofd.FileName);
ofd.FileName = Path.GetFileName(ofd.FileName);
} catch (Exception ex) {
ofd.InitialDirectory = Path.GetDirectoryName(Environment.SpecialFolder.UserProfile.ToString());
ofd.FileName = Path.GetFileName(ofd.FileName);
}
private bool FindTreeFromMap(ListBox2 listBoxTreeGroups, ListBox2 listBoxTrees, int x, int y) {
foreach (HeadbuttTreeGroup headbuttTreeGroup in listBoxTreeGroups.Items) {
foreach (HeadbuttTree tree in headbuttTreeGroup.trees) {
if (tree.mapX != x || tree.mapY != y) continue;
listBoxTreeGroups.SelectedItem = headbuttTreeGroup;
listBoxTrees.SelectedItem = tree;
tree.picked = true;
return true;
if (ofd.ShowDialog() != DialogResult.OK) { return; }
this.headbuttEncounterFile = new HeadbuttEncounterFile(ofd.FileName);
headbuttEncounterFile.ID = (ushort)comboBoxMapHeader.SelectedIndex;
setCurrentMap(headbuttEncounterFile);
}
}
return false;
}
private void comboBoxMapFile_SelectedIndexChanged(object sender, EventArgs e) {
HeadbuttEncounterMap map = comboBoxMapFile.SelectedItem as HeadbuttEncounterMap;
int mapID = gameMatrix.maps[map.y, map.x];
this.mapFile = new MapFile(mapID, RomInfo.gameFamily, discardMoveperms: true);
this.headbuttEncounterMap = map;
RenderBackground();
}
private void numericUpDownTreeGlobalX_ValueChanged(object sender, EventArgs e) {
if (headbuttTree == null) return;
headbuttTree.globalX = (ushort)((NumericUpDown)sender).Value;
listBoxTrees.RefreshItem(listBoxTrees.SelectedIndex);
}
private Bitmap GetMapBitmap() {
Bitmap bm = RenderMap();
openGlControl.Invalidate();
return bm;
}
private void numericUpDownTreeGlobalY_ValueChanged(object sender, EventArgs e) {
if (headbuttTree == null) return;
headbuttTree.globalY = (ushort)((NumericUpDown)sender).Value;
listBoxTrees.RefreshItem(listBoxTrees.SelectedIndex);
}
private void RenderBackground() {
Bitmap bm = GetMapBitmap();
private void numericUpDownTreeMatrixX_ValueChanged(object sender, EventArgs e) {
if (headbuttTree == null) return;
headbuttTree.matrixX = (ushort)((NumericUpDown)sender).Value;
listBoxTrees.RefreshItem(listBoxTrees.SelectedIndex);
}
if (headbuttEncounterFile != null) {
using (Graphics g = Graphics.FromImage(bm)) {
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
MarkTrees(g, headbuttEncounterFile.normalTreeGroups, HeadbuttTree.Types.Normal);
MarkTrees(g, headbuttEncounterFile.specialTreeGroups, HeadbuttTree.Types.Special);
}
}
private void numericUpDownTreeMatrixY_ValueChanged(object sender, EventArgs e) {
if (headbuttTree == null) return;
headbuttTree.matrixY = (ushort)((NumericUpDown)sender).Value;
listBoxTrees.RefreshItem(listBoxTrees.SelectedIndex);
}
openGlPictureBox.BackgroundImage = bm;
}
private void numericUpDownTreeMapX_ValueChanged(object sender, EventArgs e) {
if (headbuttTree == null) return;
headbuttTree.mapX = (ushort)((NumericUpDown)sender).Value;
listBoxTrees.RefreshItem(listBoxTrees.SelectedIndex);
}
private Bitmap RenderMap() {
MapFile currentMapFile = this.mapFile;
private void numericUpDownTreeMapY_ValueChanged(object sender, EventArgs e) {
if (headbuttTree == null) return;
headbuttTree.mapY = (ushort)((NumericUpDown)sender).Value;
listBoxTrees.RefreshItem(listBoxTrees.SelectedIndex);
}
if (currentMapFile == null) {
Bitmap blank = new Bitmap(openGlPictureBox.Width, openGlPictureBox.Height);
using (Graphics g = Graphics.FromImage(blank)) {
g.Clear(Color.Black);
}
private void mapScreenshotButton_Click(object sender, EventArgs e) {
SaveFileDialog imageSFD = new SaveFileDialog { Filter = "PNG File(*.png)|*.png", };
if (imageSFD.ShowDialog() != DialogResult.OK) return;
openGlPictureBox.BackgroundImage.Save(imageSFD.FileName);
MessageBox.Show("Screenshot saved.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
return blank;
}
private void SetCam2DValues() {
perspective = 4f;
ang = 0f;
dist = 115.2f;
elev = 90f;
Helpers.MW_LoadModelTextures(currentMapFile, areaData.mapTileset);
bool isInteriorMap = false;
if (RomInfo.gameFamily == RomInfo.GameFamilies.HGSS && areaData.areaType == AreaData.TYPE_INDOOR) {
isInteriorMap = true;
}
for (int i = 0; i < currentMapFile.buildings.Count; i++) {
Building building = currentMapFile.buildings[i];
building.LoadModelData(isInteriorMap); // Load building nsbmd
Helpers.MW_LoadModelTextures(building, areaData.buildingsTileset); // Load building textures
}
Helpers.RenderMap(ref currentMapFile, openGlControl.Width, openGlControl.Height, ang, dist, elev, perspective);
return Helpers.GrabMapScreenshot(width, height);
}
private void MarkTrees(Graphics g, BindingList<HeadbuttTreeGroup> treeGroups, HeadbuttTree.Types treeType) {
HeadbuttEncounterMap map = comboBoxMapFile.SelectedItem as HeadbuttEncounterMap;
if (map == null) { return; }
foreach (HeadbuttTreeGroup treeGroup in treeGroups) {
foreach (HeadbuttTree tree in treeGroup.trees) {
if (tree.unused) { continue; }
if (tree.matrixX != map.x || tree.matrixY != map.y) { continue; }
MarkTree(g, tree, treeType);
}
}
}
private void MarkTree(Graphics g, HeadbuttTree tree, HeadbuttTree.Types treeType) {
Pen paintPen;
SolidBrush paintBrush;
if (treeType == HeadbuttTree.Types.Normal) {
paintPen = normalPen;
paintBrush = normalBrush;
} else {
paintPen = specialPen;
paintBrush = specialBrush;
}
if (tree.picked) {
paintPen = selectedPen;
}
int tileWidth = openGlControl.Width / MapFile.mapSize;
int tileHeight = openGlControl.Height / MapFile.mapSize;
int tileX = tree.mapX * tileWidth;
int tileY = tree.mapY * tileHeight;
int padding = 1;
Rectangle rectangle = new Rectangle(tileX + padding, tileY + padding, tileWidth - padding, tileHeight - padding);
g.FillRectangle(paintBrush, rectangle);
g.DrawRectangle(paintPen, rectangle);
}
private void ListBoxTrees_SelectedIndexChanged(object sender, EventArgs e) {
listBoxTrees = sender as ListBox2;
headbuttTree = listBoxTrees.SelectedItem as HeadbuttTree;
if (headbuttTree == null) { return; }
numericUpDownTreeGlobalX.Value = headbuttTree.globalX;
numericUpDownTreeGlobalY.Value = headbuttTree.globalY;
numericUpDownTreeMatrixX.Value = headbuttTree.matrixX;
numericUpDownTreeMatrixY.Value = headbuttTree.matrixY;
numericUpDownTreeMapX.Value = headbuttTree.mapX;
numericUpDownTreeMapY.Value = headbuttTree.mapY;
}
private void openGlPictureBox_Click(object sender, EventArgs e) {
MouseEventArgs mea = (MouseEventArgs)e;
int tileWidth = openGlControl.Width / MapFile.mapSize;
int tileHeight = openGlControl.Height / MapFile.mapSize;
int mouseX = openGlPictureBox.PointToClient(MousePosition).X / tileWidth;
int mouseY = openGlPictureBox.PointToClient(MousePosition).Y / tileHeight;
if (mea.Button == MouseButtons.Left) {
if (this.headbuttEncounterMap != null) {
numericUpDownTreeMatrixX.Value = headbuttEncounterMap.x;
numericUpDownTreeMatrixY.Value = headbuttEncounterMap.y;
numericUpDownTreeMapX.Value = mouseX;
numericUpDownTreeMapY.Value = mouseY;
}
} else if (mea.Button == MouseButtons.Middle) {
//warp
} else if (mea.Button == MouseButtons.Right) {
if (headbuttTree != null) { headbuttTree.picked = false; }
if (FindTreeFromMap(headbuttEncounterEditorTabNormal.listBoxTreeGroups, headbuttEncounterEditorTabNormal.listBoxTrees, mouseX, mouseY)) {
tabControl.SelectedTab = tabPageNormal;
} else if (FindTreeFromMap(headbuttEncounterEditorTabSpecial.listBoxTreeGroups, headbuttEncounterEditorTabSpecial.listBoxTrees, mouseX, mouseY)) {
tabControl.SelectedTab = tabPageSpecial;
} else {
headbuttEncounterEditorTabNormal.listBoxTreeGroups.SelectedItem = null;
headbuttEncounterEditorTabNormal.listBoxTrees.SelectedItem = null;
headbuttEncounterEditorTabSpecial.listBoxTreeGroups.SelectedItem = null;
headbuttEncounterEditorTabSpecial.listBoxTrees.SelectedItem = null;
}
}
RenderBackground();
}
private bool FindTreeFromMap(ListBox2 listBoxTreeGroups, ListBox2 listBoxTrees, int x, int y) {
foreach (HeadbuttTreeGroup headbuttTreeGroup in listBoxTreeGroups.Items) {
foreach (HeadbuttTree tree in headbuttTreeGroup.trees) {
if (tree.mapX != x || tree.mapY != y) { continue; }
listBoxTreeGroups.SelectedItem = headbuttTreeGroup;
listBoxTrees.SelectedItem = tree;
tree.picked = true;
return true;
}
}
return false;
}
private void numericUpDownTreeGlobalX_ValueChanged(object sender, EventArgs e) {
if (headbuttTree == null) { return; }
headbuttTree.globalX = (ushort)((NumericUpDown)sender).Value;
listBoxTrees.RefreshItem(listBoxTrees.SelectedIndex);
}
private void numericUpDownTreeGlobalY_ValueChanged(object sender, EventArgs e) {
if (headbuttTree == null) { return; }
headbuttTree.globalY = (ushort)((NumericUpDown)sender).Value;
listBoxTrees.RefreshItem(listBoxTrees.SelectedIndex);
}
private void numericUpDownTreeMatrixX_ValueChanged(object sender, EventArgs e) {
if (headbuttTree == null) { return; }
headbuttTree.matrixX = (ushort)((NumericUpDown)sender).Value;
listBoxTrees.RefreshItem(listBoxTrees.SelectedIndex);
}
private void numericUpDownTreeMatrixY_ValueChanged(object sender, EventArgs e) {
if (headbuttTree == null) { return; }
headbuttTree.matrixY = (ushort)((NumericUpDown)sender).Value;
listBoxTrees.RefreshItem(listBoxTrees.SelectedIndex);
}
private void numericUpDownTreeMapX_ValueChanged(object sender, EventArgs e) {
if (headbuttTree == null) { return; }
headbuttTree.mapX = (ushort)((NumericUpDown)sender).Value;
listBoxTrees.RefreshItem(listBoxTrees.SelectedIndex);
}
private void numericUpDownTreeMapY_ValueChanged(object sender, EventArgs e) {
if (headbuttTree == null) { return; }
headbuttTree.mapY = (ushort)((NumericUpDown)sender).Value;
listBoxTrees.RefreshItem(listBoxTrees.SelectedIndex);
}
private void mapScreenshotButton_Click(object sender, EventArgs e) {
SaveFileDialog imageSFD = new SaveFileDialog {
Filter = "PNG File(*.png)|*.png"
};
if (imageSFD.ShowDialog() != DialogResult.OK) {
return;
}
openGlPictureBox.BackgroundImage.Save(imageSFD.FileName);
MessageBox.Show("Screenshot saved.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void SetCam2DValues() {
perspective = 4f;
ang = 0f;
dist = 115.2f;
elev = 90f;
}
}
}
}

View File

@ -36,9 +36,9 @@ namespace DSPRE.Editors {
}
private void listBoxEncounters_SelectedIndexChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
HeadbuttEncounter headbuttEncounter = (HeadbuttEncounter)listBoxEncounters.SelectedItem;
if (headbuttEncounter == null) return;
if (headbuttEncounter == null){ return; }
comboBoxPokemon.SelectedIndex = headbuttEncounter.pokemonID;
numericUpDownMinLevel.Value = headbuttEncounter.minLevel;
numericUpDownMaxLevel.Value = headbuttEncounter.maxLevel;
@ -46,33 +46,33 @@ namespace DSPRE.Editors {
private void comboBoxPokemon_SelectedIndexChanged(object sender, EventArgs e)
{
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
HeadbuttEncounter headbuttEncounter = (HeadbuttEncounter)listBoxEncounters.SelectedItem;
if (headbuttEncounter == null) return;
if (headbuttEncounter == null){ return; }
headbuttEncounter.pokemonID = (ushort)comboBoxPokemon.SelectedIndex;
listBoxEncounters.RefreshItem(listBoxEncounters.SelectedIndex);
}
private void numericUpDownMinLevel_ValueChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
HeadbuttEncounter headbuttEncounter = (HeadbuttEncounter)listBoxEncounters.SelectedItem;
if (headbuttEncounter == null) return;
if (headbuttEncounter == null){ return; }
headbuttEncounter.minLevel = (byte)numericUpDownMinLevel.Value;
listBoxEncounters.RefreshItem(listBoxEncounters.SelectedIndex);
}
private void numericUpDownMaxLevel_ValueChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
HeadbuttEncounter headbuttEncounter = (HeadbuttEncounter)listBoxEncounters.SelectedItem;
if (headbuttEncounter == null) return;
if (headbuttEncounter == null){ return; }
headbuttEncounter.maxLevel = (byte)numericUpDownMaxLevel.Value;
listBoxEncounters.RefreshItem(listBoxEncounters.SelectedIndex);
}
private void listBoxTreeGroups_SelectedIndexChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
HeadbuttTreeGroup headbuttTreeGroup = (HeadbuttTreeGroup)listBoxTreeGroups.SelectedItem;
if (headbuttTreeGroup == null) return;
if (headbuttTreeGroup == null){ return; }
listBoxTrees.DataSource = headbuttTreeGroup.trees;
}
@ -82,13 +82,13 @@ namespace DSPRE.Editors {
private void buttonRemoveTreeGroup_Click(object sender, EventArgs e) {
int selectedIndex = listBoxTreeGroups.SelectedIndex;
if (selectedIndex == -1) return;
if (selectedIndex == -1){ return; }
treeGroups.RemoveAt(selectedIndex);
}
private void buttonDuplicateTreeGroup_Click(object sender, EventArgs e) {
HeadbuttTreeGroup headbuttTreeGroup = (HeadbuttTreeGroup)listBoxTreeGroups.SelectedItem;
if (headbuttTreeGroup == null) return;
if (headbuttTreeGroup == null){ return; }
treeGroups.Add(new HeadbuttTreeGroup(headbuttTreeGroup));
}
}

View File

@ -16,7 +16,7 @@ namespace DSPRE.Editors {
}
public void SetUpLevelScriptEditor(MainProgram parent, bool force = false) {
if (levelScriptEditorIsReady && !force) return;
if (levelScriptEditorIsReady && !force){ return; }
levelScriptEditorIsReady = true;
this._parent = parent;
DSUtils.TryUnpackNarcs(new List<RomInfo.DirNames> { RomInfo.DirNames.scripts }); //12 = scripts Narc Dir
@ -126,7 +126,7 @@ namespace DSPRE.Editors {
_levelScriptFile = new LevelScriptFile(selectScriptFileComboBox.SelectedIndex);
listBoxTriggers.DataSource = _levelScriptFile.bufferSet;
if (listBoxTriggers.Items.Count > 0) listBoxTriggers.SelectedIndex = 0;
if (listBoxTriggers.Items.Count > 0){ listBoxTriggers.SelectedIndex = 0; }
enableButtons();
} catch (InvalidDataException ex) { //not a level script
@ -216,7 +216,7 @@ namespace DSPRE.Editors {
}
void buttonLocate_Click(object sender, EventArgs e) {
if (_levelScriptFile == null) return;
if (_levelScriptFile == null){ return; }
string path = Filesystem.GetScriptPath(_levelScriptFile.ID);
Helpers.ExplorerSelect(path);
}
@ -271,7 +271,7 @@ namespace DSPRE.Editors {
}
private void handleAutoFormat() {
if (!radioButtonAuto.Checked) return;
if (!radioButtonAuto.Checked){ return; }
textBoxScriptID.Clear();
textBoxVariableName.Clear();
@ -287,7 +287,7 @@ namespace DSPRE.Editors {
}
private void handleHexFormat() {
if (!radioButtonHex.Checked) return;
if (!radioButtonHex.Checked){ return; }
textBoxScriptID.Clear();
textBoxVariableName.Clear();
@ -303,7 +303,7 @@ namespace DSPRE.Editors {
}
private void handleDecimalFormat() {
if (!radioButtonDecimal.Checked) return;
if (!radioButtonDecimal.Checked){ return; }
textBoxScriptID.Clear();
textBoxVariableName.Clear();

View File

@ -14,7 +14,7 @@ namespace DSPRE.Editors {
}
public void SetupSafariZoneEditor(bool force = false) {
if (safariZoneEditorIsReady && !force) return;
if (safariZoneEditorIsReady && !force){ return; }
safariZoneEditorIsReady = true;
DSUtils.TryUnpackNarcs(new List<RomInfo.DirNames>() {
@ -59,12 +59,12 @@ namespace DSPRE.Editors {
}
private void buttonSave_Click(object sender, EventArgs e) {
if (safariZoneEncounterFile == null) return;
if (safariZoneEncounterFile == null){ return; }
safariZoneEncounterFile.SaveToFile();
}
private void buttonSaveAs_Click(object sender, EventArgs e) {
if (safariZoneEncounterFile == null) return;
if (safariZoneEncounterFile == null){ return; }
SaveFileDialog sfd = new SaveFileDialog();
try {
@ -75,13 +75,13 @@ namespace DSPRE.Editors {
sfd.InitialDirectory = Path.GetDirectoryName(Environment.SpecialFolder.UserProfile.ToString());
sfd.FileName = Path.GetFileName(sfd.FileName);
}
if (sfd.ShowDialog() != DialogResult.OK) return;
if (sfd.ShowDialog() != DialogResult.OK){ return; }
safariZoneEncounterFile.SaveToFile(sfd.FileName);
}
private void buttonImport_Click(object sender, EventArgs e) {
if (safariZoneEncounterFile == null) return;
if (safariZoneEncounterFile == null){ return; }
OpenFileDialog ofd = new OpenFileDialog();
try {
@ -92,7 +92,7 @@ namespace DSPRE.Editors {
ofd.InitialDirectory = Path.GetDirectoryName(Environment.SpecialFolder.UserProfile.ToString());
ofd.FileName = Path.GetFileName(ofd.FileName);
}
if (ofd.ShowDialog() != DialogResult.OK) return;
if (ofd.ShowDialog() != DialogResult.OK){ return; }
safariZoneEncounterFile = new SafariZoneEncounterFile(ofd.FileName);
safariZoneEncounterGroupEditorGrass.SetData(safariZoneEncounterFile.grassEncounterGroup);

View File

@ -9,34 +9,34 @@ namespace DSPRE.Editors {
}
private void listBoxEncounters_SelectedIndexChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
SafariZoneEncounter safariZoneEncounter = (SafariZoneEncounter)listBoxEncounters.SelectedItem;
if (safariZoneEncounter == null) return;
if (safariZoneEncounter == null){ return; }
comboBoxPokemon.SelectedIndex = safariZoneEncounter.pokemonID;
numericUpDownLevel.Value = safariZoneEncounter.level;
}
private void comboBoxPokemon_SelectedIndexChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
SafariZoneEncounter safariZoneEncounter = (SafariZoneEncounter)listBoxEncounters.SelectedItem;
if (safariZoneEncounter == null) return;
if (safariZoneEncounter == null){ return; }
safariZoneEncounter.pokemonID = (ushort)comboBoxPokemon.SelectedIndex;
listBoxEncounters.RefreshItem(listBoxEncounters.SelectedIndex);
}
private void numericUpDownLevel_ValueChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
SafariZoneEncounter safariZoneEncounter = (SafariZoneEncounter)listBoxEncounters.SelectedItem;
if (safariZoneEncounter == null) return;
if (safariZoneEncounter == null){ return; }
safariZoneEncounter.level = (byte)numericUpDownLevel.Value;
listBoxEncounters.RefreshItem(listBoxEncounters.SelectedIndex);
}
private void listBoxEncountersObject_SelectedIndexChanged(object sender, EventArgs e)
{
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
SafariZoneEncounter safariZoneEncounter = (SafariZoneEncounter)listBoxEncountersObject.SelectedItem;
if (safariZoneEncounter == null) return;
if (safariZoneEncounter == null){ return; }
comboBoxPokemonObject.SelectedIndex = safariZoneEncounter.pokemonID;
numericUpDownLevelObject.Value = safariZoneEncounter.level;
@ -44,18 +44,18 @@ namespace DSPRE.Editors {
private void comboBoxPokemonObject_SelectedIndexChanged(object sender, EventArgs e)
{
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
SafariZoneEncounter safariZoneEncounter = (SafariZoneEncounter)listBoxEncountersObject.SelectedItem;
if (safariZoneEncounter == null) return;
if (safariZoneEncounter == null){ return; }
safariZoneEncounter.pokemonID = (ushort)comboBoxPokemonObject.SelectedIndex;
listBoxEncountersObject.RefreshItem(listBoxEncountersObject.SelectedIndex);
}
private void numericUpDownLevelObject_ValueChanged(object sender, EventArgs e)
{
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
SafariZoneEncounter safariZoneEncounter = (SafariZoneEncounter)listBoxEncountersObject.SelectedItem;
if (safariZoneEncounter == null) return;
if (safariZoneEncounter == null){ return; }
safariZoneEncounter.level = (byte)numericUpDownLevelObject.Value;
listBoxEncountersObject.RefreshItem(listBoxEncountersObject.SelectedIndex);
}

View File

@ -70,57 +70,57 @@ namespace DSPRE.Editors {
}
private void listBoxObjectRequirements_SelectedIndexChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
SafariZoneObjectRequirement safariZoneObjectRequirement = (SafariZoneObjectRequirement)listBoxObjectRequirements.SelectedItem;
if (safariZoneObjectRequirement == null) return;
if (safariZoneObjectRequirement == null){ return; }
comboBoxObjectRequirementType.SelectedIndex = safariZoneObjectRequirement.typeID;
numericUpDownObjectRequirementQty.Value = safariZoneObjectRequirement.quantity;
}
private void comboBoxObjectRequirementType_SelectedIndexChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled) return;
// if (comboBoxObjectRequirementType.SelectedIndex == 0) comboBoxObjectRequirementType.SelectedIndex = 1; //no requirement is not valid
if (Helpers.HandlersDisabled){ return; }
// if (comboBoxObjectRequirementType.SelectedIndex == 0){ comboBoxObjectRequirementType.SelectedIndex = 1; } //no requirement is not valid
SafariZoneObjectRequirement safariZoneObjectRequirement = (SafariZoneObjectRequirement)listBoxObjectRequirements.SelectedItem;
if (safariZoneObjectRequirement == null) return;
if (safariZoneObjectRequirement == null){ return; }
safariZoneObjectRequirement.typeID = (byte)comboBoxObjectRequirementType.SelectedIndex;
listBoxObjectRequirements.RefreshItem(listBoxObjectRequirements.SelectedIndex);
}
private void numericUpDownObjectRequirementQty_ValueChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
SafariZoneObjectRequirement safariZoneObjectRequirement = (SafariZoneObjectRequirement)listBoxObjectRequirements.SelectedItem;
if (safariZoneObjectRequirement == null) return;
if (safariZoneObjectRequirement == null){ return; }
safariZoneObjectRequirement.quantity = (byte)numericUpDownObjectRequirementQty.Value;
listBoxObjectRequirements.RefreshItem(listBoxObjectRequirements.SelectedIndex);
}
private void listBoxObjectOptionalRequirements_SelectedIndexChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
SafariZoneObjectRequirement safariZoneObjectRequirement = (SafariZoneObjectRequirement)listBoxObjectOptionalRequirements.SelectedItem;
if (safariZoneObjectRequirement == null) return;
if (safariZoneObjectRequirement == null){ return; }
comboBoxOptionalObjectRequirementType.SelectedIndex = safariZoneObjectRequirement.typeID;
numericUpDownObjectOptionalRequirementQty.Value = safariZoneObjectRequirement.quantity;
}
private void comboBoxOptionalObjectRequirementType_SelectedIndexChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
SafariZoneObjectRequirement safariZoneObjectRequirement = (SafariZoneObjectRequirement)listBoxObjectOptionalRequirements.SelectedItem;
if (safariZoneObjectRequirement == null) return;
if (safariZoneObjectRequirement == null){ return; }
safariZoneObjectRequirement.typeID = (byte)comboBoxOptionalObjectRequirementType.SelectedIndex;
listBoxObjectOptionalRequirements.RefreshItem(listBoxObjectOptionalRequirements.SelectedIndex);
}
private void numericUpDownObjectOptionalRequirementQty_ValueChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled) return;
if (Helpers.HandlersDisabled){ return; }
SafariZoneObjectRequirement safariZoneObjectRequirement = (SafariZoneObjectRequirement)listBoxObjectOptionalRequirements.SelectedItem;
if (safariZoneObjectRequirement == null) return;
if (safariZoneObjectRequirement == null){ return; }
safariZoneObjectRequirement.quantity = (byte)numericUpDownObjectOptionalRequirementQty.Value;
listBoxObjectOptionalRequirements.RefreshItem(listBoxObjectOptionalRequirements.SelectedIndex);
}
private void buttonAddObjectEncounter_Click(object sender, EventArgs e) {
if (this.safariZoneEncounterGroup == null) return;
if (listBoxObjectOptionalRequirements.SelectedIndex == -1) return;
if (this.safariZoneEncounterGroup == null){ return; }
if (listBoxObjectOptionalRequirements.SelectedIndex == -1){ return; }
safariZoneEncounterGroup.MorningEncountersObject.Add(new SafariZoneEncounter());
safariZoneEncounterGroup.DayEncountersObject.Add(new SafariZoneEncounter());
safariZoneEncounterGroup.NightEncountersObject.Add(new SafariZoneEncounter());
@ -130,8 +130,8 @@ namespace DSPRE.Editors {
}
private void buttonRemoveObjectEncounter_Click(object sender, EventArgs e) {
if (this.safariZoneEncounterGroup == null) return;
if (listBoxObjectOptionalRequirements.SelectedIndex == -1) return;
if (this.safariZoneEncounterGroup == null){ return; }
if (listBoxObjectOptionalRequirements.SelectedIndex == -1){ return; }
safariZoneEncounterGroup.MorningEncountersObject.RemoveAt(safariZoneEncounterGroup.MorningEncountersObject.Count - 1);
safariZoneEncounterGroup.DayEncountersObject.RemoveAt(safariZoneEncounterGroup.DayEncountersObject.Count - 1);
safariZoneEncounterGroup.NightEncountersObject.RemoveAt(safariZoneEncounterGroup.NightEncountersObject.Count - 1);

View File

@ -98,7 +98,7 @@ namespace DSPRE.Editors {
}
public void SetupScriptEditor(MainProgram parent, bool force = false) {
if (scriptEditorIsReady && !force) return;
if (scriptEditorIsReady && !force){ return; }
scriptEditorIsReady = true;
this._parent = parent;
SetupScriptEditorTextAreas();
@ -984,7 +984,7 @@ namespace DSPRE.Editors {
}
private void goToSearchResult() {
if (searchInScriptsResultListBox.SelectedItem == null) return;
if (searchInScriptsResultListBox.SelectedItem == null){ return; }
ScriptEditorSearchResult searchResult = (ScriptEditorSearchResult)searchInScriptsResultListBox.SelectedItem;
ScriptFile scriptFile = searchResult.scriptFile;

View File

@ -8,7 +8,7 @@ namespace DSPRE {
/// </summary>
public static void IncrementNoAnimation(this ProgressBar pb, int amount = 1) {
pb.Value += amount;
if (pb.Value != pb.Maximum) pb.Value++;
if (pb.Value != pb.Maximum){ pb.Value++; }
pb.Value--;
}

View File

@ -2,28 +2,28 @@
namespace DSPRE {
public static class Filesystem {
public static string eventFiles { get { return RomInfo.gameDirs[RomInfo.DirNames.eventFiles].unpackedDir; } }
public static string OWSprites { get { return RomInfo.gameDirs[RomInfo.DirNames.OWSprites].unpackedDir; } }
public static string mapTextures { get { return RomInfo.gameDirs[RomInfo.DirNames.mapTextures].unpackedDir; } }
public static string buildingTextures { get { return RomInfo.gameDirs[RomInfo.DirNames.buildingTextures].unpackedDir; } }
public static string dynamicHeaders { get { return RomInfo.gameDirs[RomInfo.DirNames.dynamicHeaders].unpackedDir; } }
public static string dynamicHeadersPacked { get { return RomInfo.gameDirs[RomInfo.DirNames.dynamicHeaders].packedDir; } }
public static string scripts { get { return RomInfo.gameDirs[RomInfo.DirNames.scripts].unpackedDir; } }
public static string maps { get { return RomInfo.gameDirs[RomInfo.DirNames.maps].unpackedDir; } }
public static string matrices { get { return RomInfo.gameDirs[RomInfo.DirNames.matrices].unpackedDir; } }
public static string buildingConfigFiles { get { return RomInfo.gameDirs[RomInfo.DirNames.buildingConfigFiles].unpackedDir; } }
public static string areaData { get { return RomInfo.gameDirs[RomInfo.DirNames.areaData].unpackedDir; } }
public static string textArchives { get { return RomInfo.gameDirs[RomInfo.DirNames.textArchives].unpackedDir; } }
public static string trainerProperties { get { return RomInfo.gameDirs[RomInfo.DirNames.trainerProperties].unpackedDir; } }
public static string trainerParty { get { return RomInfo.gameDirs[RomInfo.DirNames.trainerParty].unpackedDir; } }
public static string trainerGraphics { get { return RomInfo.gameDirs[RomInfo.DirNames.trainerGraphics].unpackedDir; } }
public static string encounters { get { return RomInfo.gameDirs[RomInfo.DirNames.encounters].unpackedDir; } }
public static string headbutt { get { return RomInfo.gameDirs[RomInfo.DirNames.headbutt].unpackedDir; } }
public static string safariZone { get { return RomInfo.gameDirs[RomInfo.DirNames.safariZone].unpackedDir; } }
public static string monIcons { get { return RomInfo.gameDirs[RomInfo.DirNames.monIcons].unpackedDir; } }
public static string synthOverlay { get { return RomInfo.gameDirs[RomInfo.DirNames.synthOverlay].unpackedDir; } }
public static string interiorBuildingModels { get { return RomInfo.gameDirs[RomInfo.DirNames.interiorBuildingModels].unpackedDir; } }
public static string exteriorBuildingModels { get { return RomInfo.gameDirs[RomInfo.DirNames.exteriorBuildingModels].unpackedDir; } }
public static string eventFiles => RomInfo.gameDirs[RomInfo.DirNames.eventFiles].unpackedDir;
public static string OWSprites => RomInfo.gameDirs[RomInfo.DirNames.OWSprites].unpackedDir;
public static string mapTextures => RomInfo.gameDirs[RomInfo.DirNames.mapTextures].unpackedDir;
public static string buildingTextures => RomInfo.gameDirs[RomInfo.DirNames.buildingTextures].unpackedDir;
public static string dynamicHeaders => RomInfo.gameDirs[RomInfo.DirNames.dynamicHeaders].unpackedDir;
public static string dynamicHeadersPacked => RomInfo.gameDirs[RomInfo.DirNames.dynamicHeaders].packedDir;
public static string scripts => RomInfo.gameDirs[RomInfo.DirNames.scripts].unpackedDir;
public static string maps => RomInfo.gameDirs[RomInfo.DirNames.maps].unpackedDir;
public static string matrices => RomInfo.gameDirs[RomInfo.DirNames.matrices].unpackedDir;
public static string buildingConfigFiles => RomInfo.gameDirs[RomInfo.DirNames.buildingConfigFiles].unpackedDir;
public static string areaData => RomInfo.gameDirs[RomInfo.DirNames.areaData].unpackedDir;
public static string textArchives => RomInfo.gameDirs[RomInfo.DirNames.textArchives].unpackedDir;
public static string trainerProperties => RomInfo.gameDirs[RomInfo.DirNames.trainerProperties].unpackedDir;
public static string trainerParty => RomInfo.gameDirs[RomInfo.DirNames.trainerParty].unpackedDir;
public static string trainerGraphics => RomInfo.gameDirs[RomInfo.DirNames.trainerGraphics].unpackedDir;
public static string encounters => RomInfo.gameDirs[RomInfo.DirNames.encounters].unpackedDir;
public static string headbutt => RomInfo.gameDirs[RomInfo.DirNames.headbutt].unpackedDir;
public static string safariZone => RomInfo.gameDirs[RomInfo.DirNames.safariZone].unpackedDir;
public static string monIcons => RomInfo.gameDirs[RomInfo.DirNames.monIcons].unpackedDir;
public static string synthOverlay => RomInfo.gameDirs[RomInfo.DirNames.synthOverlay].unpackedDir;
public static string interiorBuildingModels => RomInfo.gameDirs[RomInfo.DirNames.interiorBuildingModels].unpackedDir;
public static string exteriorBuildingModels => RomInfo.gameDirs[RomInfo.DirNames.exteriorBuildingModels].unpackedDir;
public static string GetBuildingModelsDirPath(bool interior) {
if (interior) {
@ -33,7 +33,7 @@ namespace DSPRE {
}
}
public static string expArmPath { get { return Path.Combine(synthOverlay, PatchToolboxDialog.expandedARMfileID.ToString("D4")); } }
public static string expArmPath => Path.Combine(synthOverlay, PatchToolboxDialog.expandedARMfileID.ToString("D4"));
public static string GetPath(string path, int id, string format = "D4") {
return Path.Combine(path, id.ToString(format));
@ -44,7 +44,7 @@ namespace DSPRE {
}
static string[] GetBuildingModelFiles(bool interior) {
return Directory.GetFiles(Filesystem.GetBuildingModelsDirPath(interior));
return string.IsNullOrWhiteSpace(Filesystem.GetBuildingModelsDirPath(interior)) ? null : Directory.GetFiles(Filesystem.GetBuildingModelsDirPath(interior));
}
public static string GetBuildingModelPath(bool interior, int id) {
@ -56,7 +56,7 @@ namespace DSPRE {
}
public static string[] GetAreaDataFiles() {
return Directory.GetFiles(Filesystem.areaData);
return string.IsNullOrWhiteSpace(Filesystem.areaData) ? null : Directory.GetFiles(Filesystem.areaData);
}
public static string GetAreaDataPath(int id) {
@ -75,7 +75,7 @@ namespace DSPRE {
}
static string[] GetMapTextureFiles() {
return Directory.GetFiles(Filesystem.mapTextures);
return string.IsNullOrWhiteSpace(Filesystem.mapTextures) ? null : Directory.GetFiles(Filesystem.mapTextures);
}
public static string GetMapTexturePath(int id) {
@ -87,7 +87,7 @@ namespace DSPRE {
}
static string[] GetBuildingTextureFiles() {
return Directory.GetFiles(Filesystem.buildingTextures);
return string.IsNullOrWhiteSpace(Filesystem.buildingTextures) ? null : Directory.GetFiles(Filesystem.buildingTextures);
}
public static string GetBuildingTexturePath(int id) {
@ -99,7 +99,7 @@ namespace DSPRE {
}
static string[] GetMatrixFiles() {
return Directory.GetFiles(Filesystem.matrices);
return string.IsNullOrWhiteSpace(Filesystem.matrices) ? null : Directory.GetFiles(Filesystem.matrices);
}
public static string GetMatrixPath(int id) {
@ -111,7 +111,7 @@ namespace DSPRE {
}
static string[] GetTextArchiveFiles() {
return Directory.GetFiles(Filesystem.textArchives);
return string.IsNullOrWhiteSpace(Filesystem.textArchives) ? null : Directory.GetFiles(Filesystem.textArchives);
}
public static string GetTextArchivePath(int id) {
@ -123,7 +123,7 @@ namespace DSPRE {
}
static string[] GetMapFiles() {
return Directory.GetFiles(Filesystem.maps);
return string.IsNullOrWhiteSpace(Filesystem.maps) ? null : Directory.GetFiles(Filesystem.maps);
}
public static string GetMapPath(int id) {
@ -135,7 +135,7 @@ namespace DSPRE {
}
static string[] GetScriptFiles() {
return Directory.GetFiles(Filesystem.scripts);
return string.IsNullOrWhiteSpace(Filesystem.scripts) ? null : Directory.GetFiles(Filesystem.scripts);
}
public static string GetScriptPath(int id) {
@ -147,7 +147,7 @@ namespace DSPRE {
}
static string[] GetEventFiles() {
return Directory.GetFiles(Filesystem.eventFiles);
return string.IsNullOrWhiteSpace(Filesystem.eventFiles) ? null : Directory.GetFiles(Filesystem.eventFiles);
}
public static string GetEventPath(int id) {
@ -159,7 +159,7 @@ namespace DSPRE {
}
static string[] GetTrainerPropertiesFiles() {
return Directory.GetFiles(Filesystem.trainerProperties);
return string.IsNullOrWhiteSpace(Filesystem.trainerProperties) ? null : Directory.GetFiles(Filesystem.trainerProperties);
}
public static string GetTrainerPropertiesPath(int id) {
@ -171,7 +171,7 @@ namespace DSPRE {
}
static string[] GetDynamicHeaderFiles() {
return Directory.GetFiles(Filesystem.dynamicHeaders);
return string.IsNullOrWhiteSpace(Filesystem.dynamicHeaders) ? null : Directory.GetFiles(Filesystem.dynamicHeaders);
}
public static string GetDynamicHeaderPath(int id) {
@ -183,7 +183,7 @@ namespace DSPRE {
}
static string[] GetEncounterFiles() {
return Directory.GetFiles(Filesystem.encounters);
return string.IsNullOrWhiteSpace(Filesystem.encounters) ? null : Directory.GetFiles(Filesystem.encounters);
}
public static string GetEncounterPath(int id) {
@ -195,7 +195,7 @@ namespace DSPRE {
}
static string[] GetSafariZoneFiles() {
return Directory.GetFiles(Filesystem.safariZone);
return string.IsNullOrWhiteSpace(Filesystem.safariZone) ? null : Directory.GetFiles(Filesystem.safariZone);
}
public static string GetSafariZonePath(int id) {
@ -207,7 +207,7 @@ namespace DSPRE {
}
static string[] GetHeadbuttFiles() {
return Directory.GetFiles(Filesystem.headbutt);
return string.IsNullOrWhiteSpace(Filesystem.headbutt) ? null : Directory.GetFiles(Filesystem.headbutt);
}
public static string GetHeadbuttPath(int id) {

View File

@ -343,6 +343,10 @@ namespace DSPRE {
}
public static List<string> getHeaderListBoxNames() {
if (string.IsNullOrWhiteSpace(RomInfo.internalNamesPath)) {
return null;
}
List<string> headerListBoxNames = new List<string>();
using (DSUtils.EasyReader reader = new DSUtils.EasyReader(RomInfo.internalNamesPath)) {

View File

@ -32,8 +32,8 @@ namespace System.IO {
: this(baseStream, Endianness.BigEndian) { }
public EndianBinaryReader(Stream baseStream, Endianness endianness) {
if (baseStream is null) throw new ArgumentNullException("baseStream");
if (!baseStream.CanRead) throw new ArgumentException("baseStream");
if (baseStream is null){ throw new ArgumentNullException("baseStream"); }
if (!baseStream.CanRead){ throw new ArgumentException("baseStream"); }
BaseStream = baseStream;
Endianness = endianness;

View File

@ -37,9 +37,9 @@ namespace SM64DSe {
public static bool VectorsEqual(Vector3 a, Vector3 b) {
float epsilon = 0.00001f;
if (Math.Abs(a.X - b.X) > epsilon) return false;
if (Math.Abs(a.Y - b.Y) > epsilon) return false;
if (Math.Abs(a.Z - b.Z) > epsilon) return false;
if (Math.Abs(a.X - b.X) > epsilon){ return false; }
if (Math.Abs(a.Y - b.Y) > epsilon){ return false; }
if (Math.Abs(a.Z - b.Z) > epsilon){ return false; }
return true;
}
}

View File

@ -83,7 +83,7 @@ namespace LibNDSFormats.NSBCA {
Console.WriteLine("No. of Joint = %02x\n", num);
//dataoffset = (int*)malloc(sizeof(int));
//if (!dataoffset) return NULL;
//if (!dataoffset){ return NULL; }
reader.BaseStream.Seek(10 + (num << 2), SeekOrigin.Current); // skip [char xyz], useless
blockptr += 10;
@ -99,16 +99,16 @@ namespace LibNDSFormats.NSBCA {
for (i = 0; i < num; i++) {
reader.BaseStream.Seek(dataoffset[i], SeekOrigin.Begin);
//j = getdword();
if (reader.ReadBytes(4) == new byte[] { 0x4A, 0x00, 0x41, 0x43 }) return null;
if (reader.ReadBytes(4) == new byte[] { 0x4A, 0x00, 0x41, 0x43 }){ return null; }
blockptr += 4;
animlen.Add(getword(reader.ReadBytes(2)));
objnum = getword(reader.ReadBytes(2));
//if (objnum != g_model[0].objnum) return NULL;
//if (objnum != g_model[0].objnum){ return NULL; }
blockptr += 4;
//animation = (ANIMATION*)calloc(sizeof(ANIMATION), objnum);
//if (!animation) return NULL;
//if (!animation){ return NULL; }
animation = new NSBMDAnimation[objnum];
reader.BaseStream.Seek(4, SeekOrigin.Current); // skip 4 zeros

View File

@ -565,13 +565,13 @@ namespace LibNDSFormats.NSBMD {
if (((mat.PolyAttrib >> 0xf) & 0x1) == 1 && (((mat.PolyAttrib >> 0) & 0x1) == 0 && ((mat.PolyAttrib >> 1) & 0x1) == 0 && ((mat.PolyAttrib >> 2) & 0x1) == 0 && ((mat.PolyAttrib >> 2) & 0x1) == 0) == false) {
Gl.glEnable(Gl.GL_LIGHTING);
if (((mat.PolyAttrib >> 0) & 0x1) == 1) Gl.glEnable(Gl.GL_LIGHT0);
if (((mat.PolyAttrib >> 0) & 0x1) == 1){ Gl.glEnable(Gl.GL_LIGHT0); }
else Gl.glDisable(Gl.GL_LIGHT0);
if (((mat.PolyAttrib >> 1) & 0x1) == 1) Gl.glEnable(Gl.GL_LIGHT1);
if (((mat.PolyAttrib >> 1) & 0x1) == 1){ Gl.glEnable(Gl.GL_LIGHT1); }
else Gl.glDisable(Gl.GL_LIGHT1);
if (((mat.PolyAttrib >> 2) & 0x1) == 1) Gl.glEnable(Gl.GL_LIGHT2);
if (((mat.PolyAttrib >> 2) & 0x1) == 1){ Gl.glEnable(Gl.GL_LIGHT2); }
else Gl.glDisable(Gl.GL_LIGHT2);
if (((mat.PolyAttrib >> 3) & 0x1) == 1) Gl.glEnable(Gl.GL_LIGHT3);
if (((mat.PolyAttrib >> 3) & 0x1) == 1){ Gl.glEnable(Gl.GL_LIGHT3); }
else Gl.glDisable(Gl.GL_LIGHT3);
Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE);
@ -736,11 +736,11 @@ namespace LibNDSFormats.NSBMD {
full = OpenTK.Matrix4.Mult(full, Y);
full = OpenTK.Matrix4.Mult(full, Z);
/*int x = (param) & 0xFF;
if ((x & 0x200) != 0) x |= -256;
if ((x & 0x200) != 0){ x |= -256; }
int y = (param >> 8) & 0xFF;
if ((y & 0x200) != 0) y |= -256;
if ((y & 0x200) != 0){ y |= -256; }
int z = (param >> 16) & 0xFF;
if ((z & 0x200) != 0) z |= -256;*/
if ((z & 0x200) != 0){ z |= -256; }*/
//Gl.glRotatef((float)x / 32768F * 180F, 1, 0, 0);
//Gl.glRotatef((float)y / 32768F * 180F, 0, 1, 0);
//Gl.glRotatef((float)z / 32768F * 180F, 0, 0, 1);
@ -1072,7 +1072,7 @@ namespace LibNDSFormats.NSBMD {
switch (mode) {
case 0:
pixel = pal[(addr << 1) + texel];
if (texel == 3) pixel = RGBA.Transparent; // make it transparent, alpha = 0
if (texel == 3){ pixel = RGBA.Transparent; } // make it transparent, alpha = 0
break;
case 2:
pixel = pal[(addr << 1) + texel];
@ -1183,7 +1183,7 @@ namespace LibNDSFormats.NSBMD {
break;
// 4-Color Palette Texture
case 2:
if (mat.color0 != 0) mat.paldata[0] = RGBA.Transparent; // made palette entry 0 transparent
if (mat.color0 != 0){ mat.paldata[0] = RGBA.Transparent; } // made palette entry 0 transparent
for (int j = 0; j < pixelnum; j++) {
uint index = mat.texdata[j / 4];
index = (index >> ((j % 4) << 1)) & 3;
@ -1192,7 +1192,7 @@ namespace LibNDSFormats.NSBMD {
break;
// 16-Color Palette Texture
case 3:
if (mat.color0 != 0) mat.paldata[0] = RGBA.Transparent; // made palette entry 0 transparent
if (mat.color0 != 0){ mat.paldata[0] = RGBA.Transparent; } // made palette entry 0 transparent
for (int j = 0; j < pixelnum; j++) {
var matindex = j / 2;
if (mat.texdata.Length < matindex)
@ -1210,7 +1210,7 @@ namespace LibNDSFormats.NSBMD {
break;
// 256-Color Palette Texture
case 4:
if (mat.color0 != 0) mat.paldata[0] = RGBA.Transparent; // made palette entry 0 transparent
if (mat.color0 != 0){ mat.paldata[0] = RGBA.Transparent; } // made palette entry 0 transparent
// made palette entry 0 transparent
for (int j = 0; j < pixelnum; j++) {
image[j] = mat.paldata[mat.texdata[j]];
@ -1378,7 +1378,7 @@ namespace LibNDSFormats.NSBMD {
break;
// 4-Color Palette Texture
case 2:
if (mat.color0 != 0) mat.paldata[0] = RGBA.Transparent; // made palette entry 0 transparent
if (mat.color0 != 0){ mat.paldata[0] = RGBA.Transparent; } // made palette entry 0 transparent
for (int j = 0; j < pixelnum; j++) {
uint index = mat.texdata[j / 4];
index = (index >> ((j % 4) << 1)) & 3;
@ -1387,7 +1387,7 @@ namespace LibNDSFormats.NSBMD {
break;
// 16-Color Palette Texture
case 3:
if (mat.color0 != 0) mat.paldata[0] = RGBA.Transparent; // made palette entry 0 transparent
if (mat.color0 != 0){ mat.paldata[0] = RGBA.Transparent; } // made palette entry 0 transparent
for (int j = 0; j < pixelnum; j++) {
var matindex = j / 2;
if (mat.texdata.Length < matindex)
@ -1405,7 +1405,7 @@ namespace LibNDSFormats.NSBMD {
break;
// 256-Color Palette Texture
case 4:
if (mat.color0 != 0) mat.paldata[0] = RGBA.Transparent; // made palette entry 0 transparent
if (mat.color0 != 0){ mat.paldata[0] = RGBA.Transparent; } // made palette entry 0 transparent
// made palette entry 0 transparent
for (int j = 0; j < pixelnum; j++) {
image[j] = mat.paldata[mat.texdata[j]];
@ -1725,9 +1725,9 @@ namespace LibNDSFormats.NSBMD {
if ((x & 0x200) != 0)
x |= -1024;
y = (xyz >> 10) & 0x3FF;
if ((y & 0x200) != 0) y |= -1024;
if ((y & 0x200) != 0){ y |= -1024; }
z = (xyz >> 20) & 0x3FF;
if ((z & 0x200) != 0) z |= -1024;
if ((z & 0x200) != 0){ z |= -1024; }
Gl.glNormal3f(((float)x) / 512.0f, ((float)y) / 512.0f, ((float)z) / 512.0f);
if (writevertex) {
//normals.Add(new float[] { ((float)x) / 512.0f, ((float)y) / 512.0f, ((float)z) / 512.0f });
@ -1751,9 +1751,9 @@ namespace LibNDSFormats.NSBMD {
commandptr += 4;
s = (st >> 0) & 0xffff;
if ((s & 0x8000) != 0) s |= unchecked((int)0xFFFF0000);//-65536;
if ((s & 0x8000) != 0){ s |= unchecked((int)0xFFFF0000); }//-65536;
t = (st >> 16) & 0xffff;
if ((t & 0x8000) != 0) t |= unchecked((int)0xFFFF0000);//-65536;
if ((t & 0x8000) != 0){ t |= unchecked((int)0xFFFF0000); }//-65536;
Gl.glTexCoord2f(((float)s) / 16.0f, ((float)t) / 16.0f);
if (writevertex) {
@ -1777,14 +1777,14 @@ namespace LibNDSFormats.NSBMD {
commandptr += 4;
x = Sign((parameter >> 0) & 0xFFFF, 16);
//if ((x & 0x8000) != 0) x |= unchecked((int)0xFFFF0000);//-65536;
//if ((x & 0x8000) != 0){ x |= unchecked((int)0xFFFF0000); }//-65536;
y = Sign((parameter >> 16) & 0xFFFF, 16);
//if ((y & 0x8000) != 0) y |= unchecked((int)0xFFFF0000);//-65536;
//if ((y & 0x8000) != 0){ y |= unchecked((int)0xFFFF0000); }//-65536;
parameter = Utils.Read4BytesAsInt32(polydata, commandptr);
commandptr += 4;
z = Sign(parameter & 0xFFFF, 16);
// if ((z & 0x8000) != 0) z |= unchecked((int)0xFFFF0000);//-65536;
// if ((z & 0x8000) != 0){ z |= unchecked((int)0xFFFF0000); }//-65536;
vtx_state[0] = ((float)x) / SCALE_IV;
vtx_state[1] = ((float)y) / SCALE_IV;
@ -1845,11 +1845,11 @@ namespace LibNDSFormats.NSBMD {
commandptr += 4;
x = Sign((xyz >> 0) & 0x3FF, 10);
// if ((x & 0x200) != 0) x |= unchecked((int)0xFFFFFC00);//-1024;
// if ((x & 0x200) != 0){ x |= unchecked((int)0xFFFFFC00); }//-1024;
y = Sign((xyz >> 10) & 0x3FF, 10);
//if ((y & 0x200) != 0) y |= unchecked((int)0xFFFFFC00);//-1024;
//if ((y & 0x200) != 0){ y |= unchecked((int)0xFFFFFC00); }//-1024;
z = Sign((xyz >> 20) & 0x3FF, 10);
// if ((z & 0x200) != 0) z |= unchecked((int)0xFFFFFC00);//-1024;
// if ((z & 0x200) != 0){ z |= unchecked((int)0xFFFFFC00); }//-1024;
vtx_state[0] = (float)x / 64.0f;
vtx_state[1] = (float)y / 64.0f;
@ -1908,9 +1908,9 @@ namespace LibNDSFormats.NSBMD {
commandptr += 4;
x = Sign((xy >> 0) & 0xFFFF, 16);
//if ((x & 0x8000) != 0) x |= unchecked((int)0xFFFF0000);//-65536;
//if ((x & 0x8000) != 0){ x |= unchecked((int)0xFFFF0000); }//-65536;
y = Sign((xy >> 16) & 0xFFFF, 16);
//if ((y & 0x8000) != 0) y |= unchecked((int)0xFFFF0000);//-65536;
//if ((y & 0x8000) != 0){ y |= unchecked((int)0xFFFF0000); }//-65536;
vtx_state[0] = ((float)x) / SCALE_IV;
vtx_state[1] = ((float)y) / SCALE_IV;
@ -1968,9 +1968,9 @@ namespace LibNDSFormats.NSBMD {
commandptr += 4;
x = Sign((xz >> 0) & 0xFFFF, 16);
// if ((x & 0x8000) != 0) x |= unchecked((int)0xFFFF0000);//-65536;
// if ((x & 0x8000) != 0){ x |= unchecked((int)0xFFFF0000); }//-65536;
z = Sign((xz >> 16) & 0xFFFF, 16);
// if ((z & 0x8000) != 0) z |= unchecked((int)0xFFFF0000);//-65536;
// if ((z & 0x8000) != 0){ z |= unchecked((int)0xFFFF0000); }//-65536;
vtx_state[0] = ((float)x) / SCALE_IV;
vtx_state[2] = ((float)z) / SCALE_IV;
@ -2027,9 +2027,9 @@ namespace LibNDSFormats.NSBMD {
commandptr += 4;
y = Sign((yz >> 0) & 0xFFFF, 16);
//if ((y & 0x8000) != 0) y |= unchecked((int)0xFFFF0000);//-65536;
//if ((y & 0x8000) != 0){ y |= unchecked((int)0xFFFF0000); }//-65536;
z = Sign((yz >> 16) & 0xFFFF, 16);
//if ((z & 0x8000) != 0) z |= unchecked((int)0xFFFF0000);//-65536;
//if ((z & 0x8000) != 0){ z |= unchecked((int)0xFFFF0000); }//-65536;
vtx_state[1] = ((float)y) / SCALE_IV;
vtx_state[2] = ((float)z) / SCALE_IV;
@ -2088,11 +2088,11 @@ namespace LibNDSFormats.NSBMD {
commandptr += 4;
x = Sign((xyz >> 0) & 0x3FF, 10);
//if ((x & 0x200) != 0) x |= unchecked((int)0xFFFFFC00);//-1024;
//if ((x & 0x200) != 0){ x |= unchecked((int)0xFFFFFC00); }//-1024;
y = Sign((xyz >> 10) & 0x3FF, 10);
//if ((y & 0x200) != 0) y |= unchecked((int)0xFFFFFC00);
//if ((y & 0x200) != 0){ y |= unchecked((int)0xFFFFFC00); }
z = Sign((xyz >> 20) & 0x3FF, 10);
//if ((z & 0x200) != 0) z |= unchecked((int)0xFFFFFC00);
//if ((z & 0x200) != 0){ z |= unchecked((int)0xFFFFFC00); }
vtx_state[0] += ((float)x) / SCALE_IV;

View File

@ -95,7 +95,7 @@ namespace NSMBe4
//public static void close()
//{
// if (FS is null) return;
// if (FS is null){ return; }
// FS.close();
//}
@ -126,7 +126,7 @@ namespace NSMBe4
int lineNum = 0;
try
{
if (!System.IO.File.Exists(DescriptionPath)) return;
if (!System.IO.File.Exists(DescriptionPath)){ return; }
System.IO.StreamReader s = new System.IO.StreamReader(DescriptionPath);
List<string> curList = null;
while (!s.EndOfStream)

View File

@ -164,7 +164,7 @@ namespace NSMBe4
public string ReadString(int l)
{
if (l == 0) return ""; // simple error checking
if (l == 0){ return ""; } // simple error checking
byte[] arr = new byte[l];
read(arr);

View File

@ -73,7 +73,7 @@ namespace NSMBe4.DSFileSystem
newDir = d;
break;
}
if (newDir is null) return null;
if (newDir is null){ return null; }
dir = newDir;
}

View File

@ -47,8 +47,8 @@ namespace NSMBe4
private int getPixelVal(int x, int y)
{
int i = x + y * width;
if (bpp == 8) return data[i];
if (bpp == 16) return data[i * 2] | data[i * 2 + 1] << 8;
if (bpp == 8){ return data[i]; }
if (bpp == 16){ return data[i * 2] | data[i * 2 + 1] << 8; }
if (bpp == 4)
{
int res = data[i / 2];
@ -69,7 +69,7 @@ namespace NSMBe4
private void setPixelVal(int x, int y, int v)
{
int i = x + y * width;
if (bpp == 8) data[i] = (byte)v;
if (bpp == 8){ data[i] = (byte)v; }
else if (bpp == 16)
{
data[i * 2] = (byte)(v & 0xFF);
@ -96,18 +96,18 @@ namespace NSMBe4
}
public override int getPixel(int x, int y)
{
if (x < 0 || x >= width) return 0;
if (y < 0 || y >= height) return 0;
if (x < 0 || x >= width){ return 0; }
if (y < 0 || y >= height){ return 0; }
int val = getPixelVal(x, y);
if (format == 1) val &= 0x1F;
if (format == 6) val &= 0x07;
if (format == 1){ val &= 0x1F; }
if (format == 6){ val &= 0x07; }
return val;
}
public override void setPixel(int x, int y, int c)
{
if (x < 0 || x >= width) return;
if (y < 0 || y >= height) return;
if (x < 0 || x >= width){ return; }
if (y < 0 || y >= height){ return; }
if (format == 1)
{
c &= 0x1F;

View File

@ -70,15 +70,15 @@ namespace NSMBe4
switch (mode)
{
case 0:
if (color == 3) col = Color.Transparent;
if (color == 3){ col = Color.Transparent; }
break;
case 1:
if (color == 2) col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 1, 1);
if (color == 3) col = Color.Transparent;
if (color == 2){ col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 1, 1); }
if (color == 3){ col = Color.Transparent; }
break;
case 3:
if (color == 2) col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 5, 3);
if (color == 3) col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 3, 5);
if (color == 2){ col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 5, 3); }
if (color == 3){ col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 3, 5); }
break;
}
b.SetPixel((int)x * 4 + (int)xx, (int)y * 4 + (int)yy, col);

View File

@ -91,7 +91,7 @@ namespace NSMBe4 {
int ct = 0;
foreach (MultiColor c in freqTable.Keys)
if (c.someTransparent()) ct++;
if (c.someTransparent()){ ct++; }
Console.Out.WriteLine("Transparent: " + ct);
@ -100,9 +100,9 @@ namespace NSMBe4 {
if (!c.deleteFlag) {
int cnt = freqTable[c];
foreach (MultiColor c2 in freqTable.Keys) {
if (c2 is null) continue;
if (c2.deleteFlag) continue;
if (c2 == c) continue;
if (c2 is null){ continue; }
if (c2.deleteFlag){ continue; }
if (c2 == c){ continue; }
if (c.diff(c2) == 0) {
cnt += freqTable[c2];
@ -119,7 +119,7 @@ namespace NSMBe4 {
ct = 0;
foreach (MultiColor c in freqTable.Keys)
if (c.someTransparent()) ct++;
if (c.someTransparent()){ ct++; }
Console.Out.WriteLine("Transparent2: " + ct);
// NOW CREATE THE PALETTE ZONES
@ -241,12 +241,12 @@ namespace NSMBe4 {
//ALGORITHM CORE
private byte closestMultiColor(MultiColor mc) {
if (mc.allTransparent()) return 0;
if (mc.allTransparent()){ return 0; }
else {
int best = -1;
float bestd = float.PositiveInfinity;
for (int i = 0; i < multiPalette.Length; i++) {
if (multiPalette[i] is null) continue;
if (multiPalette[i] is null){ continue; }
float d = mc.diff(multiPalette[i]);
if (d < bestd || best == -1) {
best = i;
@ -332,8 +332,8 @@ namespace NSMBe4 {
for (int i = 0; i < c.data.Length; i++) {
if (!c.transp[i])
if (def[i]) {
if (min[i] > c.data[i]) min[i] = c.data[i];
if (max[i] < c.data[i]) max[i] = c.data[i];
if (min[i] > c.data[i]){ min[i] = c.data[i]; }
if (max[i] < c.data[i]){ max[i] = c.data[i]; }
} else {
min[i] = c.data[i];
max[i] = c.data[i];
@ -389,18 +389,18 @@ namespace NSMBe4 {
}
public Color getColor(int i) {
if (transp[i * 3]) return Color.Transparent;
if (transp[i * 3]){ return Color.Transparent; }
return Color.FromArgb(data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
}
public bool allTransparent() {
for (int i = 0; i < transp.Length; i += 3)
if (!transp[i]) return false;
if (!transp[i]){ return false; }
return true;
}
public bool someTransparent() {
for (int i = 0; i < transp.Length; i += 3)
if (transp[i]) return true;
if (transp[i]){ return true; }
return false;
}
@ -412,7 +412,7 @@ namespace NSMBe4 {
for (int i = 0; i < data.Length; i++) {
hash = (hash ^ data[i]) * p;
if (transp[i]) hash++;
if (transp[i]){ hash++; }
}
hash += hash << 13;
@ -436,8 +436,8 @@ namespace NSMBe4 {
return false;
for (int i = 0; i < data.Length; i++) {
if (data[i] != c.data[i]) return false;
if (transp[i] != c.transp[i]) return false;
if (data[i] != c.data[i]){ return false; }
if (transp[i] != c.transp[i]){ return false; }
}
return true;
} else return false;
@ -487,16 +487,16 @@ namespace NSMBe4 {
public bool inside(MultiColor c) {
for (int i = 0; i < min.Length; i++) {
if (c.transp[i]) continue;
if (c.data[i] < min[i]) return false;
if (c.data[i] > max[i]) return false;
if (c.transp[i]){ continue; }
if (c.data[i] < min[i]){ return false; }
if (c.data[i] > max[i]){ return false; }
}
return true;
}
public int dominantDimension(Dictionary<MultiColor, int> freqTable) {
int d = dominantDimensionNum(freqTable);
if (d == 255) return 0;
if (d == 255){ return 0; }
return max[d] - min[d];
}
@ -544,7 +544,7 @@ namespace NSMBe4 {
}
public bool canSplit(Dictionary<MultiColor, int> freqTable) {
if (splittablecached) return splittable;
if (splittablecached){ return splittable; }
else {
splittablecached = true;
splittable = canSplit2(freqTable);
@ -690,7 +690,7 @@ namespace NSMBe4 {
}
public static float colorDifference(Color a, Color b) {
if (a.A != b.A) return float.MaxValue;
if (a.A != b.A){ return float.MaxValue; }
float res = 0;
res += (a.R - b.R) * (a.R - b.R) / 40;

View File

@ -60,11 +60,11 @@ namespace NSMBe4.NSBMD
//Find the two most similar palettes
for (int i = 0; i < palettes.Length; i++)
{
if (paletteCounts[i] == 0) continue;
if (paletteCounts[i] == 0){ continue; }
for (int j = 0; j < palettes.Length; j++)
{
if (i == j) continue;
if (paletteCounts[j] == 0) continue;
if (i == j){ continue; }
if (paletteCounts[j] == 0){ continue; }
if (paletteDiffs[i, j] < bestDif)
{
@ -136,7 +136,7 @@ namespace NSMBe4.NSBMD
else
{
col = (byte)ImageIndexer.closest(coll, palettes[paletteNumbers[x, y]]);
if (col == 3) { col = 2; }
if (col == 3){ { col = 2; } }
}
b |= (byte)(pow * col);
pow *= 4;
@ -257,7 +257,7 @@ namespace NSMBe4.NSBMD
Progress += add;
bw.ReportProgress((int)Progress, "Generating Picture " + percent.ToString("000") + "%");
percent += add2;
if (bw.CancellationPending) { bw.ReportProgress(0, "Canceled"); return; }
if (bw.CancellationPending){ { bw.ReportProgress(0, "Canceled"); } return; }
}
percent = 0;
add2 = 100d / (((double)countUsedPalettes() - (double)paletteMaxNum));
@ -274,11 +274,11 @@ namespace NSMBe4.NSBMD
//Find the two most similar palettes
for (int i = 0; i < palettes.Count; i++)
{
if (paletteCounts[i] == 0) continue;
if (paletteCounts[i] == 0){ continue; }
for (int j = 0; j < palettes.Count; j++)
{
if (i == j) continue;
if (paletteCounts[j] == 0) continue;
if (i == j){ continue; }
if (paletteCounts[j] == 0){ continue; }
if (paletteDiffs[i, j] < bestDif)
{
@ -303,7 +303,7 @@ namespace NSMBe4.NSBMD
percent += add2;
bw.ReportProgress((int)Progress, "Generating Palette " + percent.ToString("000") + "%");
if (bw.CancellationPending) { bw.ReportProgress(0, "Canceled"); return; }
if (bw.CancellationPending){ { bw.ReportProgress(0, "Canceled"); } return; }
}
@ -365,7 +365,7 @@ namespace NSMBe4.NSBMD
colo.RemoveAt(3);
}
col = (byte)ImageIndexer.closest(coll, colo.ToArray());
//if (col == 3) { col = 2; }
//if (col == 3){ { col = 2; } }
}
b |= (byte)(pow * col);
pow *= 4;
@ -633,7 +633,7 @@ namespace NSMBe4.NSBMD
bool aTransp = a[3] == Color.Transparent;
bool bTransp = b[3] == Color.Transparent;
if (aTransp != bTransp) return float.PositiveInfinity;
if (aTransp != bTransp){ return float.PositiveInfinity; }
float dif = 0;
int len = aTransp ? 3 : 4;
@ -647,7 +647,7 @@ namespace NSMBe4.NSBMD
int i2 = -1;
for (int j = 0; j < len; j++)
{
if (sel[j]) continue;
if (sel[j]){ continue; }
float diff2 = ImageIndexer.colorDifference(c, b[j]);
if (diff2 < diff || i2 == -1)
{
@ -694,7 +694,7 @@ namespace NSMBe4.NSBMD
// pal1.AddRange(ImageIndexer.createPaletteForImage(bi, 2, trans));//(trans ? 3 : 4), false));
// pal1.AddRange(new Color[2]);
//}
//if (trans) { pal1.Add(Color.Transparent); }
//if (trans){ { pal1.Add(Color.Transparent); } }
Color[] pal = pal1.ToArray();
transparentToTheEnd(pal);
return pal;

View File

@ -74,11 +74,11 @@ namespace NSMBe4
for (int xt = 0; xt < (b.Height/8) * (b.Width/8); xt++)
{
//p.setValue(xt);
if (tiles[xt] is null) continue;
if (tiles[xt] is null){ continue; }
for (int yt = 0; yt < xt; yt++)
{
if (tiles[yt] is null) continue;
if (tiles[yt] is null){ continue; }
float diff = tiles[xt].difference(tiles[yt]);
if (diff < 0.5)
mergeTiles(xt, yt);
@ -116,9 +116,9 @@ namespace NSMBe4
TileDiff td = en.Current;
int t1 = td.t1;
int t2 = td.t2;
if (tiles[t1] is null) continue;
if (tiles[t2] is null) continue;
if (t1 == t2) throw new Exception("Should never happen");
if (tiles[t1] is null){ continue; }
if (tiles[t2] is null){ continue; }
if (t1 == t2){ throw new Exception("Should never happen"); }
mergeTiles(t1, t2);
@ -213,8 +213,8 @@ namespace NSMBe4
{
for (int t = 0; t < tileCount; t++)
{
if (t == tile) continue;
if (tiles[t] is null) continue;
if (t == tile){ continue; }
if (tiles[t] is null){ continue; }
float diff = tiles[tile].difference(tiles[t]);
if (diff == 0)
return t;
@ -232,7 +232,7 @@ namespace NSMBe4
private static float colorDifference(Color a, Color b)
{
if (a.A != b.A) return 10000f;
if (a.A != b.A){ return 10000f; }
float res = 0;
/*res += (float)(a.R - b.R) * (float)(a.R - b.R) / 65536f;
@ -292,8 +292,8 @@ namespace NSMBe4
public static Color colorMean(Color a, Color b, int wa, int wb)
{
if (a.A == 0) return b;
if (b.A == 0) return a;
if (a.A == 0){ return b; }
if (b.A == 0){ return a; }
return Color.FromArgb(mean(a.R, b.R, wa, wb),
mean(a.G, b.G, wa, wb),

View File

@ -597,7 +597,7 @@ namespace NSMBe4
{
ControlByte &= 0xF;
int num = t.Map16PaletteOffset;
if (value) num++;
if (value){ num++; }
ControlByte |= (byte)(num << 4);
}
}*/
@ -605,12 +605,12 @@ namespace NSMBe4
/*public bool xFlip
{
get { return (ControlByte & 4) != 0; }
set { if (((ControlByte & 4) != 0) != value) ControlByte ^= 4; }
set { if (((ControlByte & 4) != 0) != value){ ControlByte ^= 4; } }
}
public bool yFlip
{
get { return (ControlByte & 8) != 0; }
set { if (((ControlByte & 8) != 0) != value) ControlByte ^= 8; }
set { if (((ControlByte & 8) != 0) != value){ ControlByte ^= 8; } }
}
public Map16Quarter(NSMBTileset t)
@ -1065,9 +1065,9 @@ namespace NSMBe4
public bool objectExists(int objNum)
{
if (objNum < 0) return false;
if (objNum >= Objects.Length) return false;
if (Objects[objNum] is null) return false;
if (objNum < 0){ return false; }
if (objNum >= Objects.Length){ return false; }
if (Objects[objNum] is null){ return false; }
return true;
}
#endregion
@ -1083,12 +1083,12 @@ namespace NSMBe4
Bitmap b = new Bitmap(256, tileCount / (256 / 8) * 8);
for (int i = 0; i < tileCount; i++)
{
if (tilesUsed[i] == 0) continue;
if (tilesUsed[i] == 0){ continue; }
int tx = (i % 32) * 8;
int ty = (int)(i / 32) * 8;
int palOffs = 0;
if (tilesUsed[i] == 2) palOffs = 256;
if (tilesUsed[i] == 2){ palOffs = 256; }
for (int x = 0; x < 8; x++)
for (int y = 0; y < 8; y++)
@ -1129,9 +1129,9 @@ namespace NSMBe4
int ty = (int)(i / 32) * 8;
Graphics dest = ga;
if (newInSecondPal) dest = gb;
if (tilesUsed[i] == 1) dest = ga;
if (tilesUsed[i] == 2) dest = gb;
if (newInSecondPal){ dest = gb; }
if (tilesUsed[i] == 1){ dest = ga; }
if (tilesUsed[i] == 2){ dest = gb; }
dest.DrawImage(img, new Rectangle(i * 8, 0, 8, 8), tx, ty, 8, 8, GraphicsUnit.Pixel);
}
@ -1148,9 +1148,9 @@ namespace NSMBe4
int ty = (int)(i / 32) * 8;
ImageIndexer src = ia;
if (newInSecondPal) src = ib;
if (tilesUsed[i] == 1) src = ia;
if (tilesUsed[i] == 2) src = ib;
if (newInSecondPal){ src = ib; }
if (tilesUsed[i] == 1){ src = ia; }
if (tilesUsed[i] == 2){ src = ib; }
Array.Copy(src.palettedImage, i * 64, RawGFXData, i * 64, 64);
}
@ -1169,8 +1169,8 @@ namespace NSMBe4
private void checkMap16UsedQuarter(Map16Quarter q, int[] tilesUsed)
{
if (q.TileNum < 0) return;
if (q.TileNum >= tilesUsed.Length) return;
if (q.TileNum < 0){ return; }
if (q.TileNum >= tilesUsed.Length){ return; }
if (q.secondPalette)
tilesUsed[q.TileNum] |= 2;

View File

@ -824,7 +824,7 @@ namespace NSMBe4.NSBMD
switch (mode) {
case 0:
pixel = pal[(addr << 1) + texel];
if (texel == 3) pixel = Color.Transparent; // make it transparent, alpha = 0
if (texel == 3){ pixel = Color.Transparent; } // make it transparent, alpha = 0
break;
case 2:
pixel = pal[(addr << 1) + texel];

View File

@ -3963,7 +3963,7 @@ namespace DSPRE {
currentMapFile.ImportBuildings(File.ReadAllBytes(ib.FileName));
FillBuildingsBox();
if (buildingsListBox.Items.Count > 0) buildingsListBox.SelectedIndex = 0;
if (buildingsListBox.Items.Count > 0){ buildingsListBox.SelectedIndex = 0; }
for (int i = 0; i < currentMapFile.buildings.Count; i++) {
currentMapFile.buildings[i].LoadModelData(romInfo.GetBuildingModelsDirPath(interiorbldRadioButton.Checked)); // Load building nsbmd

View File

@ -29,10 +29,10 @@ namespace DSPRE.ROMFiles {
//first byte is the script type
//if not a valid script type, break loop
byte triggerType = br.ReadByte();
if (!LevelScriptTrigger.IsValidTriggerType(triggerType)) break;
if (!LevelScriptTrigger.IsValidTriggerType(triggerType)){ break; }
//subtract triggerType length from conditionalStructureOffset
if (hasConditionalStructure) conditionalStructureOffset -= sizeof(byte);
if (hasConditionalStructure){ conditionalStructureOffset -= sizeof(byte); }
//if trigger type is a variable value, that doesn't immediately mean we're processing that trigger
//the trigger data is processed last if it is there
@ -47,7 +47,7 @@ namespace DSPRE.ROMFiles {
bufferSet.Add(new MapScreenLoadTrigger(triggerType, (int)scriptToTrigger));
//subtract scriptToTrigger length from conditionalStructureOffset
if (hasConditionalStructure) conditionalStructureOffset -= sizeof(UInt32);
if (hasConditionalStructure){ conditionalStructureOffset -= sizeof(UInt32); }
}
//the earliest position a trigger can be
@ -83,7 +83,7 @@ namespace DSPRE.ROMFiles {
while (true) {
//there are no variables below 1
int variableID = br.ReadUInt16();
if (variableID <= 0) break;
if (variableID <= 0){ break; }
int varExpectedValue = br.ReadUInt16();
int scriptToTrigger = br.ReadUInt16();

View File

@ -39,7 +39,7 @@ namespace DSPRE.ROMFiles {
public void parse_file(string path) {
FileStream fs = new FileStream(path, FileMode.Open);
using (BinaryReader br = new BinaryReader(fs)) {
if (br.BaseStream.Length < 5) return;
if (br.BaseStream.Length < 5){ return; }
//#1 Section - Object Arrangement Allocation
grassEncounterGroup.readObjectSlots(br);
surfEncounterGroup.readObjectSlots(br);

View File

@ -294,7 +294,7 @@ namespace Ekona.Images
switch (format)
{
case ColorFormat.A3I5:
if (data.Length <= pos) break;
if (data.Length <= pos){ break; }
index = data[pos] & 0x1F;
alpha = (data[pos] >> 5);
alpha = ((alpha * 4) + (alpha / 2)) * 8;
@ -307,7 +307,7 @@ namespace Ekona.Images
pos++;
break;
case ColorFormat.A4I4:
if (data.Length <= pos) break;
if (data.Length <= pos){ break; }
index = data[pos] & 0xF;
alpha = (data[pos] >> 4);
alpha *= 16;
@ -320,7 +320,7 @@ namespace Ekona.Images
pos++;
break;
case ColorFormat.A5I3:
if (data.Length <= pos) break;
if (data.Length <= pos){ break; }
index = data[pos] & 0x7;
alpha = (data[pos] >> 3);
alpha *= 8;
@ -334,7 +334,7 @@ namespace Ekona.Images
break;
case ColorFormat.colors2:
if (data.Length <= (pos / 8)) break;
if (data.Length <= (pos / 8)){ break; }
byte bit1 = data[pos / 8];
index = Helper.BitsConverter.ByteToBits(bit1)[pos % 8];
if (palette.Length > index)
@ -342,7 +342,7 @@ namespace Ekona.Images
pos++;
break;
case ColorFormat.colors4:
if (data.Length <= (pos / 4)) break;
if (data.Length <= (pos / 4)){ break; }
byte bit2 = data[pos / 4];
index = Helper.BitsConverter.ByteToBit2(bit2)[pos % 4];
if (palette.Length > index)
@ -350,7 +350,7 @@ namespace Ekona.Images
pos++;
break;
case ColorFormat.colors16:
if (data.Length <= (pos / 2)) break;
if (data.Length <= (pos / 2)){ break; }
byte bit4 = data[pos / 2];
index = Helper.BitsConverter.ByteToBit4(bit4)[pos % 2];
if (palette.Length > index)
@ -644,11 +644,11 @@ namespace Ekona.Images
uint offset = partOffset + partSize;
addedLength = (partSize % blockSize != 0) ? blockSize - partSize % blockSize : 0;
if (offset == result.Count) result.AddRange(new byte[addedLength]);
if (offset == result.Count){ result.AddRange(new byte[addedLength]); }
else result.InsertRange((int)offset, new byte[addedLength]);
offset += addedLength;
if (offset == result.Count) result.AddRange(newData);
if (offset == result.Count){ result.AddRange(newData); }
else result.InsertRange((int)offset, newData);
addedLength += (uint)newData.Length;

View File

@ -206,22 +206,22 @@ namespace Ekona.Images.Dialogs
switch (oam.obj0.shape)
{
case 0:
if (oam.obj1.size == 0) comboSize.SelectedIndex = 0;
else if (oam.obj1.size == 1) comboSize.SelectedIndex = 1;
else if (oam.obj1.size == 2) comboSize.SelectedIndex = 2;
else if (oam.obj1.size == 3) comboSize.SelectedIndex = 3;
if (oam.obj1.size == 0){ comboSize.SelectedIndex = 0; }
else if (oam.obj1.size == 1){ comboSize.SelectedIndex = 1; }
else if (oam.obj1.size == 2){ comboSize.SelectedIndex = 2; }
else if (oam.obj1.size == 3){ comboSize.SelectedIndex = 3; }
break;
case 1:
if (oam.obj1.size == 0) comboSize.SelectedIndex = 4;
else if (oam.obj1.size == 1) comboSize.SelectedIndex = 5;
else if (oam.obj1.size == 2) comboSize.SelectedIndex = 6;
else if (oam.obj1.size == 3) comboSize.SelectedIndex = 7;
if (oam.obj1.size == 0){ comboSize.SelectedIndex = 4; }
else if (oam.obj1.size == 1){ comboSize.SelectedIndex = 5; }
else if (oam.obj1.size == 2){ comboSize.SelectedIndex = 6; }
else if (oam.obj1.size == 3){ comboSize.SelectedIndex = 7; }
break;
case 2:
if (oam.obj1.size == 0) comboSize.SelectedIndex = 8;
else if (oam.obj1.size == 1) comboSize.SelectedIndex = 9;
else if (oam.obj1.size == 2) comboSize.SelectedIndex = 10;
else if (oam.obj1.size == 3) comboSize.SelectedIndex = 11;
if (oam.obj1.size == 0){ comboSize.SelectedIndex = 8; }
else if (oam.obj1.size == 1){ comboSize.SelectedIndex = 9; }
else if (oam.obj1.size == 2){ comboSize.SelectedIndex = 10; }
else if (oam.obj1.size == 3){ comboSize.SelectedIndex = 11; }
break;
}

View File

@ -79,7 +79,7 @@ namespace Ekona.Images.Formats
bw.Write((uint)palette[0].Length * 4 + 4); // data_size = file_length - 0x14
bw.Write((ushort)0x0300); // version = 00 03
bw.Write((ushort)(palette[0].Length)); // num_colors
if (gimp_error) bw.Write((uint)0x00); // Error in Gimp 2.8
if (gimp_error){ bw.Write((uint)0x00); } // Error in Gimp 2.8
for (int i = 0; i < palette[0].Length; i++)
{
bw.Write(palette[0][i].R);

View File

@ -93,7 +93,7 @@ namespace Ekona.Images
Byte[] img_tiles;
if (tileForm == Images.TileForm.Horizontal)
{
if (height < tile_size) height = tile_size;
if (height < tile_size){ height = tile_size; }
img_tiles = Actions.LinealToHorizontal(tiles, width, height, bpp, tile_size);
tilePal = Actions.LinealToHorizontal(tilePal, width, height, 8, tile_size);
}
@ -234,7 +234,7 @@ namespace Ekona.Images
height = value;
if (tileForm == TileForm.Horizontal || tileForm == TileForm.Vertical)
{
if (this.height < this.tile_size) this.height = this.tile_size;
if (this.height < this.tile_size){ this.height = this.tile_size; }
if (this.height % this.tile_size != 0)
this.height += this.tile_size - (this.height % this.tile_size);
}
@ -248,7 +248,7 @@ namespace Ekona.Images
width = value;
if (tileForm == TileForm.Horizontal || tileForm == TileForm.Vertical)
{
if (this.width < this.tile_size) this.width = this.tile_size;
if (this.width < this.tile_size){ this.width = this.tile_size; }
if (this.width % this.tile_size != 0)
this.width += this.tile_size - (this.width % this.tile_size);
}

View File

@ -39,8 +39,8 @@ namespace Ekona.Images
private static double Clamp(double a)
{
if (a > 255) a = 255;
if (a < 0) a = 0;
if (a > 255){ a = 255; }
if (a < 0){ a = 0; }
return a;
}
@ -137,7 +137,7 @@ namespace Ekona.Images
int r = 2 * c.R - boundColor.R;
int g = 2 * c.G - boundColor.G;
int b = 2 * c.B - boundColor.B;
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) return c;
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255){ return c; }
return Color.FromArgb(255, r, g, b);
}
@ -150,7 +150,7 @@ namespace Ekona.Images
uniqueColors[0] = colors[aIndex];
uniqueColors[count - 1] = colors[bIndex];
for (int i = 0, j = 1; i < colors.Length && j < count - 1; i++)
if (uniqueFlags[i] && i != aIndex && i != bIndex) uniqueColors[j++] = colors[i];
if (uniqueFlags[i] && i != aIndex && i != bIndex){ uniqueColors[j++] = colors[i]; }
for (int i = 0; i < count; i++)
inputPoints[i] = new Vector3(uniqueColors[i].R / 8, uniqueColors[i].G / 8, uniqueColors[i].B / 8);
}
@ -335,7 +335,7 @@ namespace Ekona.Images
uint bits = indices >> (2 * i);
float beta = (float)(bits & 1);
if ((bits & 2) > 0) beta = 0.5f;
if ((bits & 2) > 0){ beta = 0.5f; }
float alpha = 1.0f - beta;
alpha2_sum += alpha * alpha;
@ -346,7 +346,7 @@ namespace Ekona.Images
}
float denom = alpha2_sum * beta2_sum - alphabeta_sum * alphabeta_sum;
if (NvMath.Equal(denom, 0.0f)) return;
if (NvMath.Equal(denom, 0.0f)){ return; }
float factor = 1.0f / denom;
@ -383,7 +383,9 @@ namespace Ekona.Images
uint bits = indices >> (2 * i);
float beta = (float)(bits & 1);
if ((bits & 2) > 0) beta = (1 + beta) / 3.0f;
if ((bits & 2) > 0){
beta = (1 + beta) / 3.0f;
}
float alpha = 1.0f - beta;
alpha2_sum += alpha * alpha;
@ -394,7 +396,7 @@ namespace Ekona.Images
}
float denom = alpha2_sum * beta2_sum - alphabeta_sum * alphabeta_sum;
if (NvMath.Equal(denom, 0.0f)) return;
if (NvMath.Equal(denom, 0.0f)){ return; }
float factor = 1.0f / denom;
@ -433,8 +435,8 @@ namespace Ekona.Images
double d2 = ColorDistance(palette[2], block[i]);
uint index;
if (d0 < d1 && d0 < d2) index = 0;
else if (d1 < d2) index = 1;
if (d0 < d1 && d0 < d2){ index = 0; }
else if (d1 < d2){ index = 1; }
else index = 2;
indices |= index << (2 * i);
@ -489,15 +491,15 @@ namespace Ekona.Images
float r0 = (float)(((r + 0) << 3) | ((r + 0) >> 2));
float r1 = (float)(((r + 1) << 3) | ((r + 1) >> 2));
if (Math.Abs(v.X - r1) < Math.Abs(v.X - r0)) r = Math.Min(r + 1, 31U);
if (Math.Abs(v.X - r1) < Math.Abs(v.X - r0)){ r = Math.Min(r + 1, 31U); }
float g0 = (float)(((g + 0) << 3) | ((g + 0) >> 2));
float g1 = (float)(((g + 1) << 3) | ((g + 1) >> 2));
if (Math.Abs(v.Y - g1) < Math.Abs(v.Y - g0)) g = Math.Min(g + 1, 31U);
if (Math.Abs(v.Y - g1) < Math.Abs(v.Y - g0)){ g = Math.Min(g + 1, 31U); }
float b0 = (float)(((b + 0) << 3) | ((b + 0) >> 2));
float b1 = (float)(((b + 1) << 3) | ((b + 1) >> 2));
if (Math.Abs(v.Z - b1) < Math.Abs(v.Z - b0)) b = Math.Min(b + 1, 31U);
if (Math.Abs(v.Z - b1) < Math.Abs(v.Z - b0)){ b = Math.Min(b + 1, 31U); }
ushort w = (ushort)((b << 10) | (g << 5) | r);
@ -592,13 +594,13 @@ namespace Ekona.Images
{
count++;
uniqueFlags[i] = true;
if (maxDistance < 0) lowIds[0] = i;
if (maxDistance < 0){ lowIds[0] = i; }
}
if (!dubledWithMask && mask[i] > 0)
{
countWithmask++;
if (maxDistanceWithMask < 0) lowIds[2] = i;
if (maxDistanceWithMask < 0){ lowIds[2] = i; }
}
}
else hasAlpha = true;
@ -675,14 +677,14 @@ namespace Ekona.Images
c0 = RoundAndExpand(ref dxtBoundPoints[0]);
c1 = RoundAndExpand(ref dxtBoundPoints[1]);
if (c0 == c1) hasAlpha = true;
if (c0 == c1){ hasAlpha = true; }
if (c0 > c1 == hasAlpha)
{
NvMath.Swap(ref c0, ref c1);
NvMath.Swap(ref dxtBoundPoints[0], ref dxtBoundPoints[1]);
}
if (c0 > c1) NvMath.Swap(ref dxtBoundPoints[0], ref dxtBoundPoints[1]);
if (c0 > c1){ NvMath.Swap(ref dxtBoundPoints[0], ref dxtBoundPoints[1]); }
compressColors = new Color[4];
for (int i = 0; i < 2; i++) compressColors[i] = VectorToColor(dxtBoundPoints[i]);
@ -842,7 +844,7 @@ namespace Ekona.Images
ushort[] c = new ushort[4];
for (int ci = 0; ci < 4; ci++)
{
if (cN[ci] > 0) cV[ci] /= cN[ci];
if (cN[ci] > 0){ cV[ci] /= cN[ci]; }
c[ci] = RoundAndExpand(ref cV[ci]);
}
@ -890,7 +892,7 @@ namespace Ekona.Images
}
}
if (colorIndex > 0x3FFF) colorIndex = 0;
if (colorIndex > 0x3FFF){ colorIndex = 0; }
ushort palInfo = (ushort)((colorIndex & 0x3FFF) | (palTypes[i] << 14));
uint resIndex = texelsCount * 4 + i * 2;
result[resIndex + 0] = (byte)((palInfo >> 0) & 0xFF);

View File

@ -127,7 +127,7 @@ namespace Ekona.Images
// Get the new palette data
int size = original.Length - start;
if (size > 0x2000) size = 0x2000;
if (size > 0x2000){ size = 0x2000; }
Byte[] data = new byte[size];
Array.Copy(original, start, data, 0, data.Length);

View File

@ -206,7 +206,7 @@ namespace Ekona.Images
else if (o.FilterIndex == 1 || o.FilterIndex == 2)
{
Formats.PaletteWin palwin = new Formats.PaletteWin(palette.Palette[(int)numericPalette.Value]);
if (o.FilterIndex == 1) palwin.Gimp_Error = true;
if (o.FilterIndex == 1){ palwin.Gimp_Error = true; }
palwin.Write(o.FileName);
}
else if (o.FilterIndex == 4)

View File

@ -83,11 +83,11 @@ namespace Ekona.Images
BinaryReader br = new BinaryReader(File.OpenRead(fileIn));
prev_data = br.ReadBytes(offset);
if (fileSize <= 0) fileSize = (int)br.BaseStream.Length;
if (fileSize > 0x2000) fileSize = 0x2000;
if (fileSize <= 0){ fileSize = (int)br.BaseStream.Length; }
if (fileSize > 0x2000){ fileSize = 0x2000; }
int palette_length = 0x200;
if (depth == ColorFormat.colors16 || fileSize < 0x200) palette_length = 0x20;
if (depth == ColorFormat.colors16 || fileSize < 0x200){ palette_length = 0x20; }
// Color data
Color[][] palette = new Color[fileSize / palette_length][];
@ -108,10 +108,10 @@ namespace Ekona.Images
if (fileSize <= 0)
fileSize = (int)br.BaseStream.Length;
int fileSize_ = fileSize;
if (fileSize > 0x2000) fileSize = 0x2000;
if (fileSize > 0x2000){ fileSize = 0x2000; }
int palette_length = 0x200;
if (fileSize < 0x200) palette_length = fileSize;
if (fileSize < 0x200){ palette_length = fileSize; }
// Color data
Color[][] palette = new Color[fileSize / palette_length][];

View File

@ -405,7 +405,7 @@ namespace Ekona.Mathematics
double angle = firstVector.Angle(secondVector);
Vector3 z = Vector3.CrossProduct(firstVector, secondVector);
double det = Vector3.DotProduct(z, direction);
if (det < 0) angle = 2 * Math.PI - angle;
if (det < 0){ angle = 2 * Math.PI - angle; }
return angle;
@ -523,7 +523,7 @@ namespace Ekona.Mathematics
public Vector3 Unit()
{
Vector3 result = new Vector3(this);
if (result == Vector3.Zero) return result;
if (result == Vector3.Zero){ return result; }
result.Normalize();
return result;
}

View File

@ -370,7 +370,7 @@ namespace Images
{
ncer.cebk.banks[i].partition_offset = Banks[i].data_offset;
ncer.cebk.banks[i].partition_size = Banks[i].data_size;
if (ncer.cebk.banks[i].partition_size > max_partition_size) max_partition_size = ncer.cebk.banks[i].partition_size;
if (ncer.cebk.banks[i].partition_size > max_partition_size){ max_partition_size = ncer.cebk.banks[i].partition_size; }
}
else
{