Skip to content

Commit

Permalink
Just some code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-fadely committed Feb 6, 2015
1 parent 680837a commit c391708
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 55 deletions.
26 changes: 17 additions & 9 deletions SADXLVL2/MainForm.cs
Expand Up @@ -92,7 +92,7 @@ private void ShowLevelSelect()
{
if (isStageLoaded)
{
if (SavePrompt() == DialogResult.Cancel)
if (SavePrompt(true) == DialogResult.Cancel)
return;
}

Expand Down Expand Up @@ -338,16 +338,20 @@ private static bool CheckMenuItemByTag(ToolStripDropDownItem parent, string tag,

return false;
}

private DialogResult SavePrompt()
/// <summary>
/// Displays a dialog asking if the user would like to save.
/// </summary>
/// <param name="autoCloseDialog">Defines whether or not the save progress dialog should close on completion.</param>
/// <returns></returns>
private DialogResult SavePrompt(bool autoCloseDialog = false)
{
DialogResult result = MessageBox.Show(this, "Do you want to save?", "SADXLVL2",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

switch (result)
{
case DialogResult.Yes:
SaveStage();
SaveStage(autoCloseDialog);
break;
}

Expand All @@ -358,7 +362,7 @@ private void LevelToolStripMenuItem_Clicked(object sender, EventArgs e)
{
fileToolStripMenuItem.HideDropDown();

if (!isStageLoaded || SavePrompt() != DialogResult.Cancel)
if (!isStageLoaded || SavePrompt(true) != DialogResult.Cancel)
{
UncheckMenuItems(changeLevelToolStripMenuItem);
((ToolStripMenuItem)sender).Checked = true;
Expand Down Expand Up @@ -1080,7 +1084,7 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (isStageLoaded)
{
if (SavePrompt() == DialogResult.Cancel)
if (SavePrompt(true) == DialogResult.Cancel)
e.Cancel = true;

LevelData.StateChanged -= LevelData_StateChanged;
Expand All @@ -1090,15 +1094,19 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)

private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveStage();
SaveStage(false);
}

private void SaveStage()
/// <summary>
/// Saves changes made to the currently loaded stage.
/// </summary>
/// <param name="autoCloseDialog">Defines whether or not the progress dialog should close on completion.</param>
private void SaveStage(bool autoCloseDialog)
{
if (!isStageLoaded)
return;

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

Expand Down
92 changes: 46 additions & 46 deletions SAEditorCommon/UI/MaterialEditor.cs
Expand Up @@ -9,8 +9,10 @@ namespace SonicRetro.SAModel.SAEditorCommon.UI
public partial class MaterialEditor : Form
{
#region Events

public delegate void FormUpdatedHandler(object sender, EventArgs e);
public event FormUpdatedHandler FormUpdated;

#endregion

private readonly List<Material> materials;
Expand All @@ -23,13 +25,6 @@ public MaterialEditor(List<Material> mats, BMPInfo[] textures)
InitializeComponent();
}

/*
private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
{
FormUpdated(this, null);
}
*/

private void MaterialEditor_Load(object sender, EventArgs e)
{
for (int i = 0; i < materials.Count; i++)
Expand All @@ -40,6 +35,10 @@ private void MaterialEditor_Load(object sender, EventArgs e)
SetControls(comboMaterial.SelectedIndex);
}

/// <summary>
/// Populates the form with data from a material index.
/// </summary>
/// <param name="index">Index of the material to use.</param>
private void SetControls(int index)
{
// setting general
Expand Down Expand Up @@ -72,12 +71,11 @@ private void SetControls(int index)
private void comboMaterial_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboMaterial.SelectedIndex > -1)
{
SetControls(comboMaterial.SelectedIndex);
}
}

#region General Control Event Methods

private void textureBox_Click(object sender, EventArgs e)
{
using (TexturePicker texPicker = new TexturePicker(textures, materials[comboMaterial.SelectedIndex].TextureID))
Expand All @@ -86,8 +84,8 @@ private void textureBox_Click(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].TextureID = texPicker.SelectedValue;
textureBox.Image = textures[materials[comboMaterial.SelectedIndex].TextureID].Image;
FormUpdated(this, null);

RaiseFormUpdated();
}
}
}
Expand All @@ -99,7 +97,7 @@ private void diffuseColorBox_Click(object sender, EventArgs e)
{
diffuseColorBox.BackColor = colorDialog.Color;
materials[comboMaterial.SelectedIndex].DiffuseColor = colorDialog.Color;
FormUpdated(this, null);
RaiseFormUpdated();
}
}

Expand All @@ -110,32 +108,26 @@ private void specColorBox_Click(object sender, EventArgs e)
{
specColorBox.BackColor = colorDialog.Color;
materials[comboMaterial.SelectedIndex].SpecularColor = colorDialog.Color;
FormUpdated(this, null);
RaiseFormUpdated();
}
}

private void doneButton_Click(object sender, EventArgs e)
{
// check to see if exponent can be parsed
float expParse = 0f;

if (!float.TryParse(exponentTextBox.Text, out expParse))
{
MessageBox.Show("Specular exponent was invalid - setting to 10");
materials[comboMaterial.SelectedIndex].Exponent = 10;
}
else
{
materials[comboMaterial.SelectedIndex].Exponent = expParse;
}

ValidateExponent();
Close();
}

private void exponentTextBox_Leave(object sender, EventArgs e)
{
ValidateExponent();
RaiseFormUpdated();
}

private void ValidateExponent()
{
// check to see if exponent can be parsed
float expParse = 0f;
float expParse;

if (!float.TryParse(exponentTextBox.Text, out expParse))
{
Expand All @@ -146,118 +138,126 @@ private void exponentTextBox_Leave(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].Exponent = expParse;
}
FormUpdated(this, null);
}

private void alphaDiffuseNumeric_ValueChanged(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].DiffuseColor = Color.FromArgb((int)alphaDiffuseNumeric.Value, materials[comboMaterial.SelectedIndex].DiffuseColor);
FormUpdated(this, null);
RaiseFormUpdated();
}

#endregion

#region Flag Check Event Methods

private void pickStatusCheck_Click(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].PickStatus = pickStatusCheck.Checked;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void superSampleCheck_Click(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].SuperSample = superSampleCheck.Checked;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void clampUCheck_Click(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].ClampU = clampUCheck.Checked;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void clampVCheck_Click(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].ClampV = clampVCheck.Checked;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void flipUCheck_Click(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].FlipU = flipUCheck.Checked;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void flipVCheck_Click(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].FlipV = flipVCheck.Checked;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void ignoreSpecCheck_Click(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].IgnoreSpecular = ignoreSpecCheck.Checked;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void useAlphaCheck_Click(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].UseAlpha = useAlphaCheck.Checked;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void useTextureCheck_Click(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].UseTexture = useTextureCheck.Checked;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void envMapCheck_Click(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].EnvironmentMap = envMapCheck.Checked;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void doubleSideCheck_Click(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].DoubleSided = doubleSideCheck.Checked;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void flatShadeCheck_Click(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].FlatShading = flatShadeCheck.Checked;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void ignoreLightCheck_Click(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].IgnoreLighting = ignoreLightCheck.Checked;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void userFlagsNumeric_ValueChanged(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].UserFlags = (byte)userFlagsNumeric.Value;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void filterModeDropDown_SelectionChangeCommitted(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].FilterMode = (FilterMode)filterModeDropDown.SelectedIndex;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void srcAlphaCombo_SelectionChangeCommitted(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].SourceAlpha = (AlphaInstruction)srcAlphaCombo.SelectedIndex;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void dstAlphaCombo_SelectedIndexChanged(object sender, EventArgs e)
{
materials[comboMaterial.SelectedIndex].DestinationAlpha = (AlphaInstruction)dstAlphaCombo.SelectedIndex;
FormUpdated(this, null);
RaiseFormUpdated();
}

private void RaiseFormUpdated()
{
if (FormUpdated != null)
FormUpdated(this, EventArgs.Empty);
}

#endregion
}
}

0 comments on commit c391708

Please sign in to comment.