mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-18 14:31:50 +00:00
Fixed, Game configurations window: new test engine entry was still added when pressing "New Test Engine" button, then canceling the browse dialog.
Fixed, general interface: in some cases opening "Test Map" drop-down resulted in an exception when trying to access a disposed/non-existing test engine icon.
This commit is contained in:
parent
13aabd4257
commit
7667f14ca2
2 changed files with 99 additions and 57 deletions
|
@ -1,66 +1,62 @@
|
|||
using System;
|
||||
#region ================== Namespaces
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.GZBuilder.Data
|
||||
{
|
||||
public class EngineInfo : IDisposable
|
||||
{
|
||||
// Disposing
|
||||
private bool isdisposed;
|
||||
|
||||
#region ================== Constants
|
||||
|
||||
public const string DEFAULT_ENGINE_NAME = "Engine with no name";
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
// Settings
|
||||
private string testprogramname;
|
||||
public string TestProgramName { get { return testprogramname; } set { testprogramname = value; CheckProgramName(); } }
|
||||
public string TestProgram;
|
||||
private string testprogram;
|
||||
private Bitmap icon;
|
||||
public string TestParameters;
|
||||
public bool CustomParameters;
|
||||
public int TestSkill;
|
||||
public bool TestShortPaths;
|
||||
private Bitmap icon;
|
||||
public Bitmap TestProgramIcon { get { return icon; } }
|
||||
|
||||
public EngineInfo()
|
||||
// Disposing
|
||||
private bool isdisposed;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public string TestProgramName { get { return testprogramname; } set { testprogramname = value; CheckProgramName(); } }
|
||||
public string TestProgram { get { return testprogram; } set { testprogram = value; CheckProgramName(); } }
|
||||
public Bitmap TestProgramIcon { get { if(icon == null) UpdateIcon(); return icon; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructors / Disposer
|
||||
|
||||
public EngineInfo()
|
||||
{
|
||||
testprogramname = DEFAULT_ENGINE_NAME;
|
||||
}
|
||||
|
||||
public EngineInfo(EngineInfo other)
|
||||
public EngineInfo(EngineInfo other)
|
||||
{
|
||||
testprogramname = other.TestProgramName;
|
||||
TestProgram = other.TestProgram;
|
||||
testprogram = other.testprogram;
|
||||
TestParameters = other.TestParameters;
|
||||
CustomParameters = other.CustomParameters;
|
||||
TestSkill = other.TestSkill;
|
||||
TestShortPaths = other.TestShortPaths;
|
||||
icon = other.icon;
|
||||
}
|
||||
|
||||
private void CheckProgramName()
|
||||
{
|
||||
if(testprogramname == DEFAULT_ENGINE_NAME && !String.IsNullOrEmpty(TestProgram))
|
||||
{
|
||||
// Get engine name from path
|
||||
testprogramname = Path.GetFileNameWithoutExtension(TestProgram);
|
||||
}
|
||||
|
||||
// Update icon
|
||||
if(icon != null)
|
||||
{
|
||||
icon.Dispose();
|
||||
icon = null;
|
||||
}
|
||||
|
||||
if(File.Exists(TestProgram))
|
||||
{
|
||||
Icon i = Icon.ExtractAssociatedIcon(TestProgram);
|
||||
icon = (i != null ? i.ToBitmap() : new Bitmap(Properties.Resources.Question));
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = new Bitmap(Properties.Resources.Warning);
|
||||
}
|
||||
UpdateIcon();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
@ -75,5 +71,39 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data
|
|||
isdisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
private void CheckProgramName()
|
||||
{
|
||||
if(testprogramname == DEFAULT_ENGINE_NAME && !String.IsNullOrEmpty(testprogram))
|
||||
{
|
||||
// Get engine name from path
|
||||
testprogramname = Path.GetFileNameWithoutExtension(testprogram);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateIcon()
|
||||
{
|
||||
if(icon != null)
|
||||
{
|
||||
icon.Dispose();
|
||||
icon = null;
|
||||
}
|
||||
|
||||
if(File.Exists(testprogram))
|
||||
{
|
||||
Icon i = Icon.ExtractAssociatedIcon(testprogram);
|
||||
icon = (i != null ? i.ToBitmap() : new Bitmap(Properties.Resources.Question));
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = new Bitmap(Properties.Resources.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -698,29 +698,41 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
//mxd
|
||||
private void btnNewEngine_Click(object sender, EventArgs e)
|
||||
{
|
||||
preventchanges = true;
|
||||
|
||||
EngineInfo newInfo = new EngineInfo();
|
||||
newInfo.TestSkill = (int)Math.Ceiling(gameconfig.Skills.Count / 2f); //set Medium skill level
|
||||
configinfo.TestEngines.Add(newInfo);
|
||||
configinfo.Changed = true;
|
||||
|
||||
//store current engine name
|
||||
if(!String.IsNullOrEmpty(cbEngineSelector.Text))
|
||||
configinfo.TestProgramName = cbEngineSelector.Text;
|
||||
// Set initial directory?
|
||||
if(testapplication.Text.Length > 0)
|
||||
{
|
||||
try { testprogramdialog.InitialDirectory = Path.GetDirectoryName(testapplication.Text); }
|
||||
catch(Exception) { }
|
||||
}
|
||||
|
||||
//refresh engines list
|
||||
cbEngineSelector.Items.Clear();
|
||||
foreach(EngineInfo info in configinfo.TestEngines)
|
||||
cbEngineSelector.Items.Add(info.TestProgramName);
|
||||
// Browse for test program
|
||||
if(testprogramdialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
preventchanges = true;
|
||||
|
||||
cbEngineSelector.SelectedIndex = configinfo.TestEngines.Count - 1;
|
||||
btnRemoveEngine.Enabled = true;
|
||||
// Add new EngineInfo
|
||||
EngineInfo newInfo = new EngineInfo();
|
||||
newInfo.TestSkill = (int)Math.Ceiling(gameconfig.Skills.Count / 2f); // Set Medium skill level
|
||||
configinfo.TestEngines.Add(newInfo);
|
||||
configinfo.Changed = true;
|
||||
|
||||
preventchanges = false;
|
||||
// Store current engine name
|
||||
if(!String.IsNullOrEmpty(cbEngineSelector.Text))
|
||||
configinfo.TestProgramName = cbEngineSelector.Text;
|
||||
|
||||
// Open engine browser
|
||||
browsetestprogram_Click(this, EventArgs.Empty);
|
||||
// Refresh engines list
|
||||
cbEngineSelector.Items.Clear();
|
||||
foreach(EngineInfo info in configinfo.TestEngines)
|
||||
cbEngineSelector.Items.Add(info.TestProgramName);
|
||||
|
||||
cbEngineSelector.SelectedIndex = configinfo.TestEngines.Count - 1;
|
||||
btnRemoveEngine.Enabled = true;
|
||||
|
||||
preventchanges = false;
|
||||
|
||||
// Set engine path
|
||||
testapplication.Text = testprogramdialog.FileName;
|
||||
}
|
||||
}
|
||||
|
||||
//mxd
|
||||
|
|
Loading…
Reference in a new issue