UltimateZoneBuilder/Source/Windows/ConfigForm.cs

534 lines
15 KiB
C#
Raw Normal View History

2007-09-25 05:57:42 +00:00
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Diagnostics;
using CodeImp.DoomBuilder.Actions;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Config;
using System.IO;
using CodeImp.DoomBuilder.Controls;
using CodeImp.DoomBuilder.Editing;
2007-09-25 05:57:42 +00:00
#endregion
namespace CodeImp.DoomBuilder.Windows
2007-09-25 05:57:42 +00:00
{
2008-01-02 21:49:43 +00:00
internal partial class ConfigForm : DelayedForm
2007-09-25 05:57:42 +00:00
{
// Variables
private GameConfiguration gameconfig;
2008-10-01 08:21:10 +00:00
private ConfigurationInfo configinfo;
2008-10-01 15:06:46 +00:00
private List<DefinedTextureSet> copiedsets;
2007-09-25 05:57:42 +00:00
// Constructor
public ConfigForm()
{
ListViewItem lvi;
2007-09-29 15:43:59 +00:00
2007-09-25 05:57:42 +00:00
// Initialize
InitializeComponent();
2008-11-27 12:37:20 +00:00
// Make list column header full width
columnname.Width = listconfigs.ClientRectangle.Width - SystemInformation.VerticalScrollBarWidth - 2;
2007-09-30 19:37:57 +00:00
2007-09-27 22:55:03 +00:00
// Fill list of configurations
foreach(ConfigurationInfo ci in General.Configs)
{
// Add a copy
lvi = listconfigs.Items.Add(ci.Name);
lvi.Tag = ci.Clone();
// This is the current configuration?
if((General.Map != null) && (General.Map.ConfigSettings.Filename == ci.Filename))
lvi.Selected = true;
2007-09-30 19:37:57 +00:00
}
// No skill
skill.Value = 0;
// Nodebuilders are allowed to be empty
nodebuildersave.Items.Add(new NodebuilderInfo());
nodebuildertest.Items.Add(new NodebuilderInfo());
2007-09-30 19:37:57 +00:00
// Fill comboboxes with nodebuilders
nodebuildersave.Items.AddRange(General.Nodebuilders.ToArray());
nodebuildertest.Items.AddRange(General.Nodebuilders.ToArray());
// Fill list of editing modes
foreach(EditModeInfo emi in General.Editing.ModesInfo)
{
2008-11-27 12:37:20 +00:00
// Is this mode selectable by the user?
2008-11-27 19:25:13 +00:00
if(emi.IsOptional)
2008-11-27 12:37:20 +00:00
{
lvi = listmodes.Items.Add(emi.Attributes.DisplayName);
lvi.Tag = emi;
lvi.SubItems.Add(emi.Plugin.Plug.Name);
}
}
}
2008-11-27 12:37:20 +00:00
// This shows a specific page
public void ShowTab(int index)
{
tabs.SelectedIndex = index;
2007-09-30 19:37:57 +00:00
}
2007-09-28 08:56:18 +00:00
// Configuration item selected
private void listconfigs_SelectedIndexChanged(object sender, EventArgs e)
{
2007-09-29 15:43:59 +00:00
NodebuilderInfo ni;
2007-09-28 08:56:18 +00:00
2007-09-29 15:43:59 +00:00
// Item selected?
if(listconfigs.SelectedItems.Count > 0)
2007-09-29 15:43:59 +00:00
{
// Enable panels
tabs.Enabled = true;
2007-09-29 15:43:59 +00:00
// Get config info of selected item
2008-10-01 08:21:10 +00:00
configinfo = listconfigs.SelectedItems[0].Tag as ConfigurationInfo;
2008-10-01 12:42:30 +00:00
// Load the game configuration
2008-10-01 08:21:10 +00:00
gameconfig = new GameConfiguration(General.LoadGameConfiguration(configinfo.Filename));
2008-11-27 19:25:13 +00:00
// Set defaults
configinfo.ApplyDefaults(gameconfig);
2007-09-29 15:43:59 +00:00
// Fill resources list
2008-10-01 08:21:10 +00:00
configdata.EditResourceLocationList(configinfo.Resources);
2008-10-01 12:42:30 +00:00
// Go for all nodebuilder save items
nodebuildersave.SelectedIndex = -1;
for(int i = 0; i < nodebuildersave.Items.Count; i++)
{
// Get item
ni = nodebuildersave.Items[i] as NodebuilderInfo;
// Item matches configuration setting?
2008-10-01 08:21:10 +00:00
if(string.Compare(ni.Name, configinfo.NodebuilderSave, false) == 0)
{
// Select this item
nodebuildersave.SelectedIndex = i;
break;
}
}
2008-10-01 12:42:30 +00:00
// Go for all nodebuilder test items
nodebuildertest.SelectedIndex = -1;
for(int i = 0; i < nodebuildertest.Items.Count; i++)
2007-09-29 15:43:59 +00:00
{
// Get item
ni = nodebuildertest.Items[i] as NodebuilderInfo;
// Item matches configuration setting?
2008-10-01 08:21:10 +00:00
if(string.Compare(ni.Name, configinfo.NodebuilderTest, false) == 0)
{
// Select this item
nodebuildertest.SelectedIndex = i;
break;
}
}
2007-09-29 15:43:59 +00:00
// Fill skills list
skill.ClearInfo();
skill.AddInfo(gameconfig.Skills.ToArray());
2007-09-29 15:43:59 +00:00
// Set test application and parameters
if(!configinfo.CustomParameters)
{
configinfo.TestParameters = gameconfig.TestParameters;
configinfo.TestShortPaths = gameconfig.TestShortPaths;
}
2008-10-01 08:21:10 +00:00
testapplication.Text = configinfo.TestProgram;
testparameters.Text = configinfo.TestParameters;
shortpaths.Checked = configinfo.TestShortPaths;
2008-10-01 08:21:10 +00:00
int skilllevel = configinfo.TestSkill;
skill.Value = skilllevel - 1;
skill.Value = skilllevel;
2008-10-01 08:21:10 +00:00
customparameters.Checked = configinfo.CustomParameters;
2008-10-01 12:42:30 +00:00
2008-10-01 08:21:10 +00:00
// Fill texture sets list
listtextures.Items.Clear();
2008-10-01 15:06:46 +00:00
foreach(DefinedTextureSet ts in configinfo.TextureSets)
{
ListViewItem item = listtextures.Items.Add(ts.Name);
item.Tag = ts;
item.ImageIndex = 0;
2008-10-01 15:06:46 +00:00
}
listtextures.Sort();
2008-11-27 12:37:20 +00:00
// Go for all the editing modes in the list
foreach(ListViewItem lvi in listmodes.Items)
{
EditModeInfo emi = (lvi.Tag as EditModeInfo);
2008-11-27 19:25:13 +00:00
lvi.Checked = (configinfo.EditModes.ContainsKey(emi.Type.FullName) && configinfo.EditModes[emi.Type.FullName]);
2008-11-27 12:37:20 +00:00
}
2007-09-29 15:43:59 +00:00
}
}
2008-10-01 15:06:46 +00:00
// Key released
private void listconfigs_KeyUp(object sender, KeyEventArgs e)
{
// Nothing selected?
if(listconfigs.SelectedItems.Count == 0)
2007-09-29 15:43:59 +00:00
{
// Disable panels
2008-10-01 08:21:10 +00:00
gameconfig = null;
configinfo = null;
configdata.FixedResourceLocationList(new DataLocationList());
configdata.EditResourceLocationList(new DataLocationList());
nodebuildersave.SelectedIndex = -1;
nodebuildertest.SelectedIndex = -1;
testapplication.Text = "";
testparameters.Text = "";
shortpaths.Checked = false;
skill.Value = 0;
skill.ClearInfo();
customparameters.Checked = false;
tabs.Enabled = false;
2008-10-01 15:06:46 +00:00
listtextures.Items.Clear();
2007-09-29 15:43:59 +00:00
}
}
2008-10-01 15:06:46 +00:00
// Mouse released
private void listconfigs_MouseUp(object sender, MouseEventArgs e)
{
listconfigs_KeyUp(sender, new KeyEventArgs(Keys.None));
}
2007-09-29 15:43:59 +00:00
// Resource locations changed
private void resourcelocations_OnContentChanged()
{
// Leave when no configuration selected
2008-10-01 08:21:10 +00:00
if(configinfo == null) return;
2007-09-29 15:43:59 +00:00
// Apply to selected configuration
2008-10-01 08:21:10 +00:00
configinfo.Resources.Clear();
configinfo.Resources.AddRange(configdata.GetResources());
2007-09-29 15:43:59 +00:00
}
// Nodebuilder selection changed
private void nodebuildersave_SelectedIndexChanged(object sender, EventArgs e)
2007-09-29 15:43:59 +00:00
{
// Leave when no configuration selected
2008-10-01 08:21:10 +00:00
if(configinfo == null) return;
2008-11-27 12:37:20 +00:00
2007-09-29 15:43:59 +00:00
// Apply to selected configuration
if(nodebuildersave.SelectedItem != null)
2008-10-01 08:21:10 +00:00
configinfo.NodebuilderSave = (nodebuildersave.SelectedItem as NodebuilderInfo).Name;
2007-09-29 15:43:59 +00:00
}
// Nodebuilder selection changed
private void nodebuildertest_SelectedIndexChanged(object sender, EventArgs e)
2007-09-29 15:43:59 +00:00
{
// Leave when no configuration selected
2008-10-01 08:21:10 +00:00
if(configinfo == null) return;
2007-09-29 15:43:59 +00:00
// Apply to selected configuration
if(nodebuildertest.SelectedItem != null)
2008-10-01 08:21:10 +00:00
configinfo.NodebuilderTest = (nodebuildertest.SelectedItem as NodebuilderInfo).Name;
2007-09-29 15:43:59 +00:00
}
2007-09-29 15:43:59 +00:00
// Test application changed
private void testapplication_TextChanged(object sender, EventArgs e)
{
// Leave when no configuration selected
2008-10-01 08:21:10 +00:00
if(configinfo == null) return;
2007-09-29 15:43:59 +00:00
// Apply to selected configuration
2008-10-01 08:21:10 +00:00
configinfo.TestProgram = testapplication.Text;
2007-09-29 15:43:59 +00:00
}
// Test parameters changed
private void testparameters_TextChanged(object sender, EventArgs e)
{
// Leave when no configuration selected
2008-10-01 08:21:10 +00:00
if(configinfo == null) return;
2007-09-29 15:43:59 +00:00
// Apply to selected configuration
2008-10-01 08:21:10 +00:00
configinfo = listconfigs.SelectedItems[0].Tag as ConfigurationInfo;
configinfo.TestParameters = testparameters.Text;
// Show example result
CreateParametersExample();
}
// This creates a new parameters example
private void CreateParametersExample()
{
// Map loaded?
if(General.Map != null)
{
// Make converted parameters
testresult.Text = General.Map.Launcher.ConvertParameters(testparameters.Text, skill.Value, shortpaths.Checked);
}
2007-09-29 15:43:59 +00:00
}
// OK clicked
private void apply_Click(object sender, EventArgs e)
{
ConfigurationInfo ci;
2007-09-30 19:37:57 +00:00
2007-09-29 15:43:59 +00:00
// Apply configuration items
foreach(ListViewItem lvi in listconfigs.Items)
2007-09-29 15:43:59 +00:00
{
// Get configuration item
ci = lvi.Tag as ConfigurationInfo;
2007-09-29 15:43:59 +00:00
// Find same configuration info in originals
foreach(ConfigurationInfo oci in General.Configs)
{
// Apply settings when they match
if(string.Compare(ci.Filename, oci.Filename) == 0) oci.Apply(ci);
}
}
2007-09-30 19:37:57 +00:00
2007-09-29 15:43:59 +00:00
// Close
this.DialogResult = DialogResult.OK;
2007-10-14 21:31:45 +00:00
this.Close();
2007-09-29 15:43:59 +00:00
}
// Cancel clicked
private void cancel_Click(object sender, EventArgs e)
{
// Close
this.DialogResult = DialogResult.Cancel;
2007-10-14 21:31:45 +00:00
this.Close();
2007-09-25 05:57:42 +00:00
}
2007-09-28 08:56:18 +00:00
// Browse test program
private void browsetestprogram_Click(object sender, EventArgs e)
{
// Set initial directory
if(testapplication.Text.Length > 0)
{
try { testprogramdialog.InitialDirectory = Path.GetDirectoryName(testapplication.Text); }
catch(Exception) { }
}
// Browse for test program
if(testprogramdialog.ShowDialog() == DialogResult.OK)
{
// Apply
testapplication.Text = testprogramdialog.FileName;
}
}
// Customize parameters (un)checked
private void customparameters_CheckedChanged(object sender, EventArgs e)
{
// Leave when no configuration selected
2008-10-01 08:21:10 +00:00
if(configinfo == null) return;
// Apply to selected configuration
2008-10-01 08:21:10 +00:00
configinfo.CustomParameters = customparameters.Checked;
// Update interface
labelparameters.Visible = customparameters.Checked;
testparameters.Visible = customparameters.Checked;
shortpaths.Visible = customparameters.Checked;
// Check if a map is loaded
if(General.Map != null)
{
// Show parameters example result
labelresult.Visible = customparameters.Checked;
testresult.Visible = customparameters.Checked;
noresultlabel.Visible = false;
}
else
{
// Cannot show parameters example result
labelresult.Visible = false;
testresult.Visible = false;
noresultlabel.Visible = customparameters.Checked;
}
}
// Use short paths changed
private void shortpaths_CheckedChanged(object sender, EventArgs e)
{
// Leave when no configuration selected
if(configinfo == null) return;
// Apply to selected configuration
configinfo.TestShortPaths = shortpaths.Checked;
CreateParametersExample();
}
// Skill changes
private void skill_ValueChanges(object sender, EventArgs e)
{
// Leave when no configuration selected
2008-10-01 08:21:10 +00:00
if(configinfo == null) return;
2008-10-01 12:42:30 +00:00
// Apply to selected configuration
2008-10-01 08:21:10 +00:00
configinfo.TestSkill = skill.Value;
2008-10-01 12:42:30 +00:00
CreateParametersExample();
}
2008-10-01 08:21:10 +00:00
// Make new texture set
private void addtextureset_Click(object sender, EventArgs e)
{
DefinedTextureSet s = new DefinedTextureSet("New Texture Set");
TextureSetForm form = new TextureSetForm();
form.Setup(s);
if(form.ShowDialog(this) == DialogResult.OK)
{
// Add to texture sets
configinfo.TextureSets.Add(s);
2008-10-01 15:06:46 +00:00
ListViewItem item = listtextures.Items.Add(s.Name);
item.Tag = s;
item.ImageIndex = 0;
2008-10-01 15:06:46 +00:00
listtextures.Sort();
2008-10-01 08:21:10 +00:00
}
}
// Edit texture set
private void edittextureset_Click(object sender, EventArgs e)
{
// Texture Set selected?
2008-10-01 15:06:46 +00:00
if(listtextures.SelectedItems.Count > 0)
2008-10-01 08:21:10 +00:00
{
2008-10-01 15:06:46 +00:00
DefinedTextureSet s = (listtextures.SelectedItems[0].Tag as DefinedTextureSet);
2008-10-01 08:21:10 +00:00
TextureSetForm form = new TextureSetForm();
form.Setup(s);
form.ShowDialog(this);
2008-10-01 15:06:46 +00:00
listtextures.SelectedItems[0].Text = s.Name;
listtextures.Sort();
2008-10-01 08:21:10 +00:00
}
}
2008-10-01 12:42:30 +00:00
// Remove texture set
private void removetextureset_Click(object sender, EventArgs e)
{
// Texture Set selected?
while(listtextures.SelectedItems.Count > 0)
2008-10-01 12:42:30 +00:00
{
// Remove from config info and list
2008-10-01 15:06:46 +00:00
DefinedTextureSet s = (listtextures.SelectedItems[0].Tag as DefinedTextureSet);
2008-10-01 12:42:30 +00:00
configinfo.TextureSets.Remove(s);
2008-10-01 15:06:46 +00:00
listtextures.SelectedItems[0].Remove();
2008-10-01 12:42:30 +00:00
}
}
2008-10-01 08:21:10 +00:00
// Texture Set selected/deselected
private void listtextures_SelectedIndexChanged(object sender, EventArgs e)
{
2008-10-01 15:06:46 +00:00
edittextureset.Enabled = (listtextures.SelectedItems.Count > 0);
removetextureset.Enabled = (listtextures.SelectedItems.Count > 0);
copytexturesets.Enabled = (listtextures.SelectedItems.Count > 0);
2008-10-01 08:21:10 +00:00
}
2008-10-01 12:42:30 +00:00
// Doubleclicking a texture set
private void listtextures_DoubleClick(object sender, EventArgs e)
{
edittextureset_Click(sender, e);
}
2008-10-01 15:06:46 +00:00
// Copy selected texture sets
private void copytexturesets_Click(object sender, EventArgs e)
{
// Make copies
copiedsets = new List<DefinedTextureSet>();
foreach(ListViewItem item in listtextures.SelectedItems)
{
DefinedTextureSet s = (item.Tag as DefinedTextureSet);
copiedsets.Add(s.Copy());
}
// Enable button
pastetexturesets.Enabled = true;
}
// Paste copied texture sets
private void pastetexturesets_Click(object sender, EventArgs e)
{
if(copiedsets != null)
{
// Add copies
foreach(DefinedTextureSet ts in copiedsets)
{
DefinedTextureSet s = ts.Copy();
ListViewItem item = listtextures.Items.Add(s.Name);
item.Tag = s;
item.ImageIndex = 0;
2008-10-01 15:06:46 +00:00
configinfo.TextureSets.Add(s);
}
listtextures.Sort();
}
}
// This will add the default sets from game configuration
private void restoretexturesets_Click(object sender, EventArgs e)
{
// Ask nicely first
if(MessageBox.Show(this, "This will add the default Texture Sets from the Game Configuration. Do you want to continue?",
"Add Default Sets", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
// Add copies
foreach(DefinedTextureSet ts in gameconfig.TextureSets)
2008-10-01 15:06:46 +00:00
{
DefinedTextureSet s = ts.Copy();
ListViewItem item = listtextures.Items.Add(s.Name);
item.Tag = s;
item.ImageIndex = 0;
2008-10-01 15:06:46 +00:00
configinfo.TextureSets.Add(s);
}
listtextures.Sort();
}
}
2008-11-27 12:37:20 +00:00
// This is called when an editing mode item is checked or unchecked
private void listmodes_ItemChecked(object sender, ItemCheckedEventArgs e)
{
// Leave when no configuration selected
if(configinfo == null) return;
// Apply changes
EditModeInfo emi = (e.Item.Tag as EditModeInfo);
2008-11-27 19:25:13 +00:00
bool currentstate = (configinfo.EditModes.ContainsKey(emi.Type.FullName) && configinfo.EditModes[emi.Type.FullName]);
2008-11-27 12:37:20 +00:00
if(e.Item.Checked && !currentstate)
{
// Add
2008-11-27 19:25:13 +00:00
configinfo.EditModes[emi.Type.FullName] = true;
2008-11-27 12:37:20 +00:00
}
else if(!e.Item.Checked && currentstate)
{
// Remove
2008-11-27 19:25:13 +00:00
configinfo.EditModes[emi.Type.FullName] = false;
2008-11-27 12:37:20 +00:00
}
}
2009-04-05 19:29:27 +00:00
// Help requested
private void ConfigForm_HelpRequested(object sender, HelpEventArgs hlpevent)
{
General.ShowHelp("w_gameconfigurations.html");
hlpevent.Handled = true;
}
2007-09-25 05:57:42 +00:00
}
}