Skip to content

Commit

Permalink
SADXLVL2:
Browse files Browse the repository at this point in the history
* Added documentation to LevelSelectDialog and ProgressDialog
* Feature: ProgressDialog now has an auto-close-on-complete option.
* Added a ProgressDialog to the save procedure.
* Made use of the new ProgressDialog functionality in the save and export procedures.
* Made titlebar strings across all of our ProgressDialog instances more consistent.
  • Loading branch information
michael-fadely committed Feb 4, 2015
1 parent fa48385 commit 84a2144
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 31 deletions.
8 changes: 8 additions & 0 deletions SADXLVL2/LevelSelectDialog.cs
Expand Up @@ -6,11 +6,19 @@ namespace SonicRetro.SAModel.SADXLVL2
{
public partial class LevelSelectDialog : Form
{
/// <summary>
/// Gets the "tag" for the selected stage. (e.g "Action Stages\Emerald Coast")
/// </summary>
public string SelectedStage { get; private set; }

private readonly Dictionary<string, List<string>> levels;

// TODO: Add parameter to select last loaded stage on open.

/// <summary>
/// Initializes a LevelSelect dialog with a dropdown list of categories and a list of levels below.
/// </summary>
/// <param name="levels">A dictionary containing the list of levels to populate the dialog with.</param>
public LevelSelectDialog(Dictionary<string, List<string>> levels)
{
InitializeComponent();
Expand Down
49 changes: 42 additions & 7 deletions SADXLVL2/MainForm.cs
Expand Up @@ -413,7 +413,7 @@ private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)

toolStrip1.Enabled = false;

using (ProgressDialog progress = new ProgressDialog("Loading " + levelName, steps))
using (ProgressDialog progress = new ProgressDialog("Loading stage: " + levelName, steps))
{
LevelData.Character = 0;
Dictionary<string, string> group = ini[levelID];
Expand Down Expand Up @@ -1032,19 +1032,32 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)

private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!isStageLoaded) return;
if (!isStageLoaded)
return;

ProgressDialog progress = new ProgressDialog("Saving stage: " + levelName, 5, true, false);
progress.Show(this); Application.DoEvents();

Dictionary<string, string> group = ini[levelID];
string syspath = Path.Combine(Environment.CurrentDirectory, ini[string.Empty]["syspath"]);
string modpath = null;
if (ini[string.Empty].ContainsKey("modpath"))
modpath = ini[string.Empty]["modpath"];
SA1LevelAct levelact = new SA1LevelAct(group.GetValueOrDefault("LevelID", "0000"));

progress.SetTaskAndStep("Saving:", "Geometry...");

if (LevelData.geo != null)
{
LevelData.geo.Tool = "SADXLVL2";
LevelData.geo.SaveToFile(group["LevelGeo"], LandTableFormat.SA1);
}

progress.StepProgress();

progress.Step = "Start positions...";
Application.DoEvents();

for (int i = 0; i < LevelData.StartPositions.Length; i++)
{
Dictionary<SA1LevelAct, SA1StartPosInfo> posini = SA1StartPosList.Load(ini[string.Empty][LevelData.Characters[i] + "start"]);
Expand All @@ -1061,6 +1074,12 @@ private void saveToolStripMenuItem_Click(object sender, EventArgs e)
}
posini.Save(ini[string.Empty][LevelData.Characters[i] + "start"]);
}

progress.StepProgress();

progress.Step = "Death zones...";
Application.DoEvents();

if (LevelData.DeathZones != null)
{
DeathZoneFlags[] dzini = new DeathZoneFlags[LevelData.DeathZones.Count];
Expand All @@ -1070,7 +1089,13 @@ private void saveToolStripMenuItem_Click(object sender, EventArgs e)
dzini.Save(group["DeathZones"]);
}

progress.StepProgress();

#region Saving SET Items

progress.Step = "SET items...";
Application.DoEvents();

if (LevelData.SETItems != null)
{
for (int i = 0; i < LevelData.SETItems.Length; i++)
Expand All @@ -1091,9 +1116,14 @@ private void saveToolStripMenuItem_Click(object sender, EventArgs e)
File.WriteAllBytes(setstr, file.ToArray());
}
}

progress.StepProgress();
#endregion

#region Saving CAM Items
progress.Step = "CAM items...";
Application.DoEvents();

if (LevelData.CAMItems != null)
{
for (int i = 0; i < LevelData.CAMItems.Length; i++)
Expand All @@ -1118,9 +1148,15 @@ private void saveToolStripMenuItem_Click(object sender, EventArgs e)
File.WriteAllBytes(camString, file.ToArray());
}
}

progress.StepProgress();
progress.SetTaskAndStep("Save complete!");
Application.DoEvents();

#endregion
}


private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
Expand Down Expand Up @@ -1940,9 +1976,9 @@ private void exportOBJToolStripMenuItem_Click(object sender, EventArgs e)
if (LevelData.geo.Anim != null)
stepCount += LevelData.geo.Anim.Count;

ProgressDialog progress = new ProgressDialog("Exporting stage...", stepCount);
progress.Show();
progress.Task = "Exporting:";
ProgressDialog progress = new ProgressDialog("Exporting stage: " + levelName, stepCount, true, false);
progress.Show(this);
progress.SetTaskAndStep("Exporting...");

// This is admittedly not an accurate representation of the materials used in the model - HOWEVER, it makes the materials more managable in MAX
// So we're doing it this way. In the future we should come back and add an option to do it this way or the original way.
Expand Down Expand Up @@ -2004,8 +2040,7 @@ private void exportOBJToolStripMenuItem_Click(object sender, EventArgs e)
MessageBoxButtons.OK, MessageBoxIcon.Error);
}

progress.Close();
MessageBox.Show("Export complete!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
progress.SetTaskAndStep("Export complete!");
}
}
}
Expand Down
34 changes: 31 additions & 3 deletions SADXLVL2/ProgressDialog.Designer.cs

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

0 comments on commit 84a2144

Please sign in to comment.