UltimateZoneBuilder/Source/Windows/MapOptionsForm.cs

204 lines
6 KiB
C#
Raw Normal View History

2007-06-16 19:53:51 +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
2007-06-14 23:31:57 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CodeImp.DoomBuilder.Map;
2007-10-01 20:53:10 +00:00
using CodeImp.DoomBuilder.Data;
2007-10-14 21:31:45 +00:00
using CodeImp.DoomBuilder.IO;
using System.IO;
using CodeImp.DoomBuilder.Config;
using CodeImp.DoomBuilder.Controls;
2007-06-14 23:31:57 +00:00
2007-06-16 19:53:51 +00:00
#endregion
namespace CodeImp.DoomBuilder.Windows
2007-06-14 23:31:57 +00:00
{
2008-01-02 21:49:43 +00:00
internal partial class MapOptionsForm : DelayedForm
2007-06-14 23:31:57 +00:00
{
// Variables
private MapOptions options;
// Properties
public MapOptions Options { get { return options; } }
2007-06-15 10:18:03 +00:00
2007-06-14 23:31:57 +00:00
// Constructor
public MapOptionsForm(MapOptions options)
{
2007-09-30 20:07:14 +00:00
int index;
2007-06-14 23:31:57 +00:00
// Initialize
InitializeComponent();
// Keep settings
this.options = options;
// Go for all configurations
for(int i = 0; i < General.Configs.Count; i++)
{
// Add config name to list
2007-09-30 20:07:14 +00:00
index = config.Items.Add(General.Configs[i]);
2007-06-14 23:31:57 +00:00
// Is this configuration currently selected?
2007-09-27 22:55:03 +00:00
if(string.Compare(General.Configs[i].Filename, options.ConfigFile, true) == 0)
2007-06-14 23:31:57 +00:00
{
// Select this item
2007-09-30 20:07:14 +00:00
config.SelectedIndex = index;
2007-06-14 23:31:57 +00:00
}
}
// Set the level name
levelname.Text = options.CurrentName;
// Fill the resources list
2007-10-01 20:53:10 +00:00
datalocations.EditResourceLocationList(options.Resources);
2007-06-14 23:31:57 +00:00
}
// OK clicked
private void apply_Click(object sender, EventArgs e)
{
2007-10-14 21:31:45 +00:00
Configuration newcfg;
WAD sourcewad;
bool conflictingname;
2007-06-14 23:31:57 +00:00
// Configuration selected?
if(config.SelectedIndex == -1)
{
// Select a configuration!
MessageBox.Show(this, "Please select a game configuration to use for editing your map.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
config.Focus();
2007-06-14 23:31:57 +00:00
return;
}
// Level name empty?
if(levelname.Text.Length == 0)
{
// Enter a level name!
MessageBox.Show(this, "Please enter a level name for your map.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
levelname.Focus();
2007-06-14 23:31:57 +00:00
return;
}
2007-10-14 21:31:45 +00:00
// Level name changed and the map exists in a source wad?
2007-10-14 21:35:49 +00:00
if((levelname.Text != options.CurrentName) && (General.Map != null) &&
2007-10-14 21:31:45 +00:00
(General.Map.FilePathName != "") && File.Exists(General.Map.FilePathName))
{
// Open the source wad file to check for conflicting name
sourcewad = new WAD(General.Map.FilePathName, true);
conflictingname = (sourcewad.FindLumpIndex(levelname.Text) > -1);
sourcewad.Dispose();
// Names conflict?
if(conflictingname)
{
// Show warning!
if(General.ShowWarningMessage("The map name \"" + levelname.Text + "\" is already in use by another map or data lump in the source WAD file. Saving your map with this name will cause conflicting data lumps in the WAD file. Do you want to continue?", MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button2) == DialogResult.No)
{
return;
}
}
}
// Configuration changed?
2007-10-14 21:35:49 +00:00
if((options.ConfigFile != "") && (General.Configs[config.SelectedIndex].Filename != options.ConfigFile))
2007-10-14 21:31:45 +00:00
{
// Load the new cfg file
newcfg = General.LoadGameConfiguration(General.Configs[config.SelectedIndex].Filename);
if(newcfg == null) return;
// Check if the config uses a different IO interface
2007-10-24 17:25:03 +00:00
if(newcfg.ReadSetting("formatinterface", "") != General.Map.Config.FormatInterface)
2007-10-14 21:31:45 +00:00
{
// Warn the user about IO interface change
if(General.ShowWarningMessage("The game configuration you selected uses a different file format than your current map. Because your map was not designed for this format it may cause the map to work incorrectly in the game. Do you want to continue?", MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button2) == DialogResult.No)
{
// Reset to old configuration
for(int i = 0; i < config.Items.Count; i++)
{
// Is this configuration the old config?
if(string.Compare(General.Configs[i].Filename, options.ConfigFile, true) == 0)
{
// Select this item
config.SelectedIndex = i;
}
}
return;
}
}
}
2007-06-14 23:31:57 +00:00
// Apply changes
options.ClearResources();
2007-09-27 22:55:03 +00:00
options.ConfigFile = General.Configs[config.SelectedIndex].Filename;
2007-06-14 23:31:57 +00:00
options.CurrentName = levelname.Text.Trim().ToUpper();
2007-10-01 20:53:10 +00:00
options.CopyResources(datalocations.GetResources());
2007-06-14 23:31:57 +00:00
// Hide window
this.DialogResult = DialogResult.OK;
2007-10-14 21:31:45 +00:00
this.Close();
2007-06-14 23:31:57 +00:00
}
// Cancel clicked
private void cancel_Click(object sender, EventArgs e)
{
// Just hide window
this.DialogResult = DialogResult.Cancel;
2007-10-14 21:31:45 +00:00
this.Close();
2007-06-14 23:31:57 +00:00
}
2007-09-30 20:07:14 +00:00
// Game configuration chosen
private void config_SelectedIndexChanged(object sender, EventArgs e)
{
ConfigurationInfo ci;
// Anything selected?
if(config.SelectedIndex > -1)
{
// Get the info
ci = (ConfigurationInfo)config.SelectedItem;
// No lump name in the name field?
if(levelname.Text.Trim().Length == 0)
{
// Get default lump name from configuration
levelname.Text = ci.DefaultLumpName;
}
2007-09-30 20:07:14 +00:00
// Show resources
2007-10-01 20:53:10 +00:00
datalocations.FixedResourceLocationList(ci.Resources);
2007-09-30 20:07:14 +00:00
}
}
// When keys are pressed in the level name field
private void levelname_KeyPress(object sender, KeyPressEventArgs e)
{
string allowedchars = Lump.MAP_LUMP_NAME_CHARS + Lump.MAP_LUMP_NAME_CHARS.ToLowerInvariant() + "\b";
// Check if key is not allowed
if(allowedchars.IndexOf(e.KeyChar) == -1)
{
// Cancel this
e.Handled = true;
}
}
2007-06-14 23:31:57 +00:00
}
}