Skip to content

Commit

Permalink
Version v0.1.1 update
Browse files Browse the repository at this point in the history
Mostly a bug fix update with 2 new options in the settings menu.
  • Loading branch information
DavidSM64 committed Jul 9, 2017
1 parent ce8e2cc commit c78a7c4
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 64 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Quad64 v0.1
# Quad64 v0.1.1
An open-source SM64 level editor written in C# 4.0, and uses Windows Forms and OpenTK.

<a href="http://i.imgur.com/Mm4Spu7.png"><img src="http://i.imgur.com/Mm4Spu7.png"/></a>
Expand Down
41 changes: 21 additions & 20 deletions src/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Forms/SettingsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions src/Forms/SettingsForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Quad64.src.JSON;
using OpenTK.Graphics.OpenGL;
using Quad64.src.JSON;
using Quad64.src.TestROM;
using System;
using System.Collections.Generic;
Expand All @@ -24,8 +25,9 @@ private void SettingsForm_Load(object sender, EventArgs e)
AddAdvancedSettings();
}

TextBox emuPathTextBox;
Button setEmuPathButton;
private TextBox emuPathTextBox;
private Button setEmuPathButton;
private CheckBox autoSaveWithEmulatorBox;
private void AddAdvancedSettings()
{
int xOffset = 0, yOffset = 10, SeperatorWidth = Advanced.Width - 6;
Expand All @@ -34,6 +36,9 @@ private void AddAdvancedSettings()
yOffset += 25;
addButtonWithTextBox(Advanced, "Browse", Globals.pathToEmulator, true, xOffset, yOffset, Advanced.Width,
ref emuPathTextBox, ref setEmuPathButton, OpenEmulatorPath_Click);
yOffset += 30;
Advanced.Controls.Add(newCheckBox("Automatically save ROM when launching emulator", xOffset, yOffset, Globals.autoSaveWhenClickEmulator));
autoSaveWithEmulatorBox = (CheckBox)Advanced.Controls[Advanced.Controls.Count - 1];
}

private void addButtonWithTextBox(TabPage page, string buttonText, string textBoxText, bool isTextBoxReadOnly, int x, int y, int screenWidth, ref TextBox box, ref Button button, EventHandler buttonClickEvent)
Expand All @@ -49,8 +54,8 @@ private void OpenEmulatorPath_Click(object sender, EventArgs e)
LaunchROM.setEmulatorPath();
emuPathTextBox.Text = Globals.pathToEmulator;
}

private CheckBox enableWireframe, drawObjMdls, autoLoadROM;
private CheckBox enableWireframe, enableBFculling, drawObjMdls, autoLoadROM;
private ComboBox renderMap, useHex;
private void AddBasicSettings()
{
Expand All @@ -62,6 +67,9 @@ private void AddBasicSettings()
Basic.Controls.Add(newCheckBox("Enable wireframe", xOffset, yOffset, Globals.doWireframe));
enableWireframe = (CheckBox)Basic.Controls[Basic.Controls.Count - 1];
yOffset += 25;
Basic.Controls.Add(newCheckBox("Enable backface culling", xOffset, yOffset, Globals.doBackfaceCulling));
enableBFculling = (CheckBox)Basic.Controls[Basic.Controls.Count - 1];
yOffset += 25;
Basic.Controls.Add(newCheckBox("Draw Object Models", xOffset, yOffset, Globals.drawObjectModels));
drawObjMdls = (CheckBox)Basic.Controls[Basic.Controls.Count - 1];
yOffset += 30;
Expand Down Expand Up @@ -179,9 +187,16 @@ private void updateGlobalSettings()
Globals.doWireframe = enableWireframe.Checked;
Globals.drawObjectModels = drawObjMdls.Checked;
Globals.autoLoadROMOnStartup = autoLoadROM.Checked;
Globals.doBackfaceCulling = enableBFculling.Checked;
Globals.renderCollisionMap = (renderMap.SelectedIndex == 1);
Globals.useHexadecimal = (useHex.SelectedIndex != 0);
Globals.useSignedHex = (useHex.SelectedIndex == 1);
Globals.autoSaveWhenClickEmulator = autoSaveWithEmulatorBox.Checked;

if (Globals.doBackfaceCulling)
GL.Enable(EnableCap.CullFace);
else
GL.Disable(EnableCap.CullFace);
}

private void saveButton_Click(object sender, EventArgs e)
Expand Down
16 changes: 12 additions & 4 deletions src/Globals.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Quad64.src.JSON;
using OpenTK.Graphics.OpenGL;
using Quad64.src.JSON;
using System;
using System.Collections.Generic;
using System.Drawing;
Expand All @@ -13,21 +14,28 @@ class Globals
public static bool doWireframe = false;
public static bool drawObjectModels = true;
public static bool renderCollisionMap = false;
public static bool doBackfaceCulling = false;

// Editor Options
public static bool autoLoadROMOnStartup = false;
public static string pathToAutoLoadROM = "";
public static bool useHexadecimal = true;
public static bool useSignedHex = true;
public static bool useHexadecimal = false;
public static bool useSignedHex = false;

// Advanced Options
public static string pathToEmulator = "";

public static bool autoSaveWhenClickEmulator = false;

// Speed multipliers
public static float camSpeedMultiplier = 1.0f;
public static float objSpeedMultiplier = 1.0f;

// TreeView selection
public static int list_selected = -1;
public static int item_selected = -1;

// Keeps track if the user needs to save their changes.
public static bool needToSave = false;

// For the bounding boxes in the area
public static Color ObjectColor = Color.Red;
Expand Down
6 changes: 6 additions & 0 deletions src/JSON/SettingsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ public static void SaveGlobalSettings(string profileName)
{
JObject s = new JObject();
s["EnableWireframe"] = Globals.doWireframe.ToString();
s["EnableBackfaceCulling"] = Globals.doBackfaceCulling.ToString();
s["DrawObjectModels"] = Globals.drawObjectModels.ToString();
s["RenderCollisionMap"] = Globals.renderCollisionMap.ToString();
s["AutoLoadROMFile"] = Globals.autoLoadROMOnStartup.ToString();
s["LastROMFile"] = Globals.pathToAutoLoadROM;
s["EnableHex"] = Globals.useHexadecimal.ToString();
s["SignedHex"] = Globals.useSignedHex.ToString();
s["EmulatorPath"] = Globals.pathToEmulator;
s["AutoSaveOnLaunchROM"] = Globals.autoSaveWhenClickEmulator;

string savePath = "./data/profiles/" + profileName + "/";
Directory.CreateDirectory(savePath); // Create directory if it doesn't exist!
Expand All @@ -35,6 +37,8 @@ public static void LoadGlobalSettings(string profileName)
JObject o = JObject.Parse(json);
if (o["EnableWireframe"] != null)
Globals.doWireframe = bool.Parse(o["EnableWireframe"].ToString());
if (o["EnableBackfaceCulling"] != null)
Globals.doBackfaceCulling = bool.Parse(o["EnableBackfaceCulling"].ToString());
if (o["DrawObjectModels"] != null)
Globals.drawObjectModels = bool.Parse(o["DrawObjectModels"].ToString());
if (o["RenderCollisionMap"] != null)
Expand All @@ -49,6 +53,8 @@ public static void LoadGlobalSettings(string profileName)
Globals.useSignedHex = bool.Parse(o["SignedHex"].ToString());
if(o["EmulatorPath"] != null)
Globals.pathToEmulator = o["EmulatorPath"].ToString();
if (o["AutoSaveOnLaunchROM"] != null)
Globals.autoSaveWhenClickEmulator = bool.Parse(o["AutoSaveOnLaunchROM"].ToString());
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/LevelInfo/Object3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ public void updateROMData()
}
else if (Globals.list_selected == 1) // Macro Object
{
//ushort presetNum = (ushort)(rom.readHalfwordUnsigned(romAddr) & 0x1FF);
ushort first = (ushort)(((int)(yRot / 22.5f) << 9) | (presetID & 0x1FF));
//Console.WriteLine("Preset ID = 0x" + presetID.ToString("X"));
ushort first = (ushort)((ushort)((yRot << 9) / 2.8125f) | (presetID & 0x1FF));
rom.writeHalfword(romAddr, first);
rom.writeHalfword(romAddr + 2, xPos);
rom.writeHalfword(romAddr + 4, yPos);
Expand All @@ -261,6 +261,7 @@ public void updateROMData()
}
else if (Globals.list_selected == 2) // Special Object
{
Console.WriteLine("Special Preset ID = 0x" + presetID.ToString("X"));
rom.writeHalfword(romAddr, presetID);
rom.writeHalfword(romAddr + 2, xPos);
rom.writeHalfword(romAddr + 4, yPos);
Expand Down
12 changes: 12 additions & 0 deletions src/Prompts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ namespace Quad64.src
{
class Prompts
{
public static DialogResult ShowShouldSaveDialog()
{
if (Globals.needToSave)
{
DialogResult result = MessageBox.Show("You have unsaved changes, would you like to save the ROM?", "Save ROM?", MessageBoxButtons.YesNoCancel);
if (result == DialogResult.Yes)
ROM.Instance.saveFileAs(ROM.Instance.Filepath, ROM.Instance.Endian);
return result;
}
return DialogResult.None;
}

public static string ShowInputDialog(string text, string title)
{
Form prompt = new Form()
Expand Down
12 changes: 10 additions & 2 deletions src/ROM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public void readFile(string filename)
bytes = File.ReadAllBytes(filename);
checkROM();
Globals.pathToAutoLoadROM = filepath;
Globals.needToSave = false;
SettingsFile.SaveGlobalSettings("default");
}

Expand All @@ -223,6 +224,7 @@ public void saveFile()
File.WriteAllBytes(filepath, bytes);
}
Globals.pathToAutoLoadROM = filepath;
Globals.needToSave = false;
SettingsFile.SaveGlobalSettings("default");
}

Expand All @@ -247,6 +249,7 @@ public void saveFileAs(string filename, ROM_Endian saveType)
File.WriteAllBytes(filename, bytes);
endian = ROM_Endian.BIG;
}
Globals.needToSave = false;
filepath = filename;
Globals.pathToAutoLoadROM = filepath;
SettingsFile.SaveGlobalSettings("default");
Expand Down Expand Up @@ -310,13 +313,18 @@ public byte[] getDataFromSegmentAddress_safe(uint segOffset, uint size)
{
byte seg = (byte)(segOffset >> 24);
uint off = segOffset & 0x00FFFFFF;

return getSubArray_safe(segData[seg], off, size);
if(segData[seg] != null)
return getSubArray_safe(segData[seg], off, size);
else
return new byte[size];
}


public byte[] getSubArray_safe(byte[] arr, uint offset, uint size)
{
if (arr == null)
return new byte[size];

byte[] newArr = new byte[size];
for (uint i = 0; i < size; i++)
{
Expand Down
Loading

0 comments on commit c78a7c4

Please sign in to comment.