2009-04-19 18:07:22 +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 ;
2014-07-11 10:13:26 +00:00
using System.Collections.Generic ;
2009-04-19 18:07:22 +00:00
using System.Windows.Forms ;
using CodeImp.DoomBuilder.Map ;
using CodeImp.DoomBuilder.Data ;
using CodeImp.DoomBuilder.IO ;
using System.IO ;
using CodeImp.DoomBuilder.Config ;
#endregion
namespace CodeImp.DoomBuilder.Windows
{
internal partial class MapOptionsForm : DelayedForm
{
// Variables
private MapOptions options ;
private bool newmap ;
2014-08-26 11:08:34 +00:00
private string previousdefaultmaplumpname ; //mxd
2009-04-19 18:07:22 +00:00
// Properties
public MapOptions Options { get { return options ; } }
// Constructor
2013-03-21 11:23:29 +00:00
public MapOptionsForm ( MapOptions options , bool newmap )
2009-04-19 18:07:22 +00:00
{
2013-03-21 11:23:29 +00:00
this . newmap = newmap ;
2009-04-19 18:07:22 +00:00
int index ;
// Initialize
InitializeComponent ( ) ;
// Keep settings
this . options = options ;
2014-02-18 14:04:14 +00:00
//mxd. Go for all enabled configurations
2009-04-19 18:07:22 +00:00
for ( int i = 0 ; i < General . Configs . Count ; i + + )
{
2014-02-18 14:04:14 +00:00
//mxd. No disabled configs here
if ( ! General . Configs [ i ] . Enabled ) continue ;
2009-04-19 18:07:22 +00:00
// Add config name to list
index = config . Items . Add ( General . Configs [ i ] ) ;
2013-03-21 11:23:29 +00:00
//mxd.
if ( newmap & & ! string . IsNullOrEmpty ( General . Settings . LastUsedConfigName ) & & General . Configs [ i ] . Name = = General . Settings . LastUsedConfigName )
{
// Select this item
config . SelectedIndex = index ;
} // Is this configuration currently selected?
else if ( string . Compare ( General . Configs [ i ] . Filename , options . ConfigFile , true ) = = 0 ) // Is this configuration currently selected?
2009-04-19 18:07:22 +00:00
{
// Select this item
config . SelectedIndex = index ;
}
}
2014-02-18 14:04:14 +00:00
//mxd. No dice? Check disabled ones
if ( config . SelectedIndex = = - 1 )
{
for ( int i = 0 ; i < General . Configs . Count ; i + + )
{
//No enabled configs here
if ( General . Configs [ i ] . Enabled ) continue ;
if ( ( newmap & & ! string . IsNullOrEmpty ( General . Settings . LastUsedConfigName ) & & General . Configs [ i ] . Name = = General . Settings . LastUsedConfigName ) | |
string . Compare ( General . Configs [ i ] . Filename , options . ConfigFile , true ) = = 0 )
{
//Add and select this item
config . SelectedIndex = config . Items . Add ( General . Configs [ i ] ) ;
break ;
}
}
}
2013-09-11 09:47:53 +00:00
//mxd. Still better than nothing :)
2014-02-18 14:04:14 +00:00
if ( config . SelectedIndex = = - 1 & & config . Items . Count > 0 ) config . SelectedIndex = 0 ;
2012-07-10 10:20:45 +00:00
2013-03-18 13:52:27 +00:00
//mxd
2014-02-18 14:04:14 +00:00
if ( General . Map ! = null ) datalocations . StartPath = General . Map . FilePathName ;
2013-03-18 13:52:27 +00:00
2014-07-11 10:13:26 +00:00
//mxd. Set script compiler
if ( config . SelectedIndex ! = - 1 )
{
ConfigurationInfo ci = config . SelectedItem as ConfigurationInfo ;
foreach ( KeyValuePair < string , ScriptConfiguration > group in General . CompiledScriptConfigs )
{
scriptcompiler . Items . Add ( group . Value ) ;
if ( group . Key = = options . ScriptCompiler )
scriptcompiler . SelectedIndex = scriptcompiler . Items . Count - 1 ;
}
//Nothing selected? Let's try default one form the game configuration, if we have any
if ( scriptcompiler . SelectedIndex = = - 1 & & ! string . IsNullOrEmpty ( ci . DefaultScriptCompiler ) )
{
int cfgindex = 0 ;
foreach ( KeyValuePair < string , ScriptConfiguration > group in General . CompiledScriptConfigs )
{
if ( group . Key = = ci . DefaultScriptCompiler )
{
scriptcompiler . SelectedIndex = cfgindex ;
break ;
}
cfgindex + + ;
}
}
if ( General . CompiledScriptConfigs . Count = = 0 | | string . IsNullOrEmpty ( ci . DefaultScriptCompiler ) )
{
scriptcompiler . Enabled = false ;
scriptcompilerlabel . Enabled = false ;
}
else if ( scriptcompiler . SelectedIndex = = - 1 & & scriptcompiler . Items . Count > 0 )
{
scriptcompiler . SelectedIndex = 0 ;
}
}
2009-04-19 18:07:22 +00:00
// Set the level name
2014-02-18 14:04:14 +00:00
if ( ! string . IsNullOrEmpty ( options . CurrentName ) ) levelname . Text = options . CurrentName ; //mxd
2009-04-19 18:07:22 +00:00
// Set strict patches loading
strictpatches . Checked = options . StrictPatches ;
// Fill the resources list
datalocations . EditResourceLocationList ( options . Resources ) ;
}
// OK clicked
private void apply_Click ( object sender , EventArgs e )
{
// 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 ( ) ;
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 ( ) ;
return ;
}
// Collect information
2014-02-18 14:04:14 +00:00
ConfigurationInfo configinfo = config . SelectedItem as ConfigurationInfo ; //mxd
2009-04-19 18:07:22 +00:00
DataLocationList locations = datalocations . GetResources ( ) ;
// When making a new map, check if we should warn the user for missing resources
2013-03-21 11:28:50 +00:00
if ( newmap )
2009-04-19 18:07:22 +00:00
{
2013-03-21 11:28:50 +00:00
General . Settings . LastUsedConfigName = configinfo . Name ; //mxd
if ( ( locations . Count = = 0 ) & & ( configinfo . Resources . Count = = 0 ) & &
MessageBox . Show ( this , "You are about to make a map without selecting any resources. Textures, flats and " +
2009-04-19 18:07:22 +00:00
"sprites may not be shown correctly or may not show up at all. Do you want to continue?" , Application . ProductName ,
MessageBoxButtons . YesNo , MessageBoxIcon . Warning , MessageBoxDefaultButton . Button2 ) = = DialogResult . No )
{
return ;
}
}
// Next checks are only for maps that are already opened
if ( ! newmap )
{
// Now we check if the map name the user has given does already exist in the source WAD file
// We have to warn the user about that, because it would create a level name conflict in the WAD
// Level name changed and the map exists in a source wad?
if ( ( levelname . Text ! = options . CurrentName ) & & ( General . Map ! = null ) & &
( General . Map . FilePathName ! = "" ) & & File . Exists ( General . Map . FilePathName ) )
{
// Open the source wad file to check for conflicting name
2014-02-18 14:04:14 +00:00
WAD sourcewad = new WAD ( General . Map . FilePathName , true ) ;
bool conflictingname = ( sourcewad . FindLumpIndex ( levelname . Text ) > - 1 ) ;
2009-04-19 18:07:22 +00:00
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 ;
}
}
}
// When the user changed the configuration to one that has a different read/write interface,
// we have to warn the user that the map may not be compatible.
// Configuration changed?
2014-02-18 14:04:14 +00:00
if ( ( options . ConfigFile ! = "" ) & & ( configinfo . Filename ! = options . ConfigFile ) )
2009-04-19 18:07:22 +00:00
{
// Check if the config uses a different IO interface
2014-02-18 14:04:14 +00:00
if ( configinfo . Configuration . ReadSetting ( "formatinterface" , "" ) ! = General . Map . Config . FormatInterface )
2009-04-19 18:07:22 +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?
2014-02-18 14:04:14 +00:00
if ( string . Compare ( ( config . Items [ i ] as ConfigurationInfo ) . Filename , options . ConfigFile , true ) = = 0 )
2009-04-19 18:07:22 +00:00
{
// Select this item
config . SelectedIndex = i ;
}
}
return ;
2013-05-31 13:57:49 +00:00
}
2014-02-18 14:04:14 +00:00
//mxd. Otherwise map data won't be saved if a user decides to save the map right after converting to new map format
General . Map . IsChanged = true ;
2009-04-19 18:07:22 +00:00
}
}
}
// Apply changes
options . ClearResources ( ) ;
2014-02-18 14:04:14 +00:00
options . ConfigFile = ( config . SelectedItem as ConfigurationInfo ) . Filename ; //mxd
2009-04-19 18:07:22 +00:00
options . CurrentName = levelname . Text . Trim ( ) . ToUpper ( ) ;
options . StrictPatches = strictpatches . Checked ;
options . CopyResources ( datalocations . GetResources ( ) ) ;
2014-07-11 10:13:26 +00:00
//mxd. Store script compiler
if ( scriptcompiler . Enabled & & scriptcompiler . SelectedIndex > - 1 )
{
ScriptConfiguration scriptcfg = scriptcompiler . SelectedItem as ScriptConfiguration ;
foreach ( KeyValuePair < string , ScriptConfiguration > group in General . CompiledScriptConfigs )
{
if ( group . Value = = scriptcfg )
{
options . ScriptCompiler = group . Key ;
break ;
}
}
}
2009-05-31 10:59:42 +00:00
2009-04-19 18:07:22 +00:00
// Hide window
this . DialogResult = DialogResult . OK ;
this . Close ( ) ;
}
// Cancel clicked
private void cancel_Click ( object sender , EventArgs e )
{
// Just hide window
this . DialogResult = DialogResult . Cancel ;
this . Close ( ) ;
}
// Game configuration chosen
private void config_SelectedIndexChanged ( object sender , EventArgs e )
{
// Anything selected?
if ( config . SelectedIndex > - 1 )
{
// Get the info
2014-02-18 14:04:14 +00:00
ConfigurationInfo ci = config . SelectedItem as ConfigurationInfo ;
2009-04-19 18:07:22 +00:00
// No lump name in the name field?
2014-08-26 11:08:34 +00:00
if ( levelname . Text . Trim ( ) . Length = = 0 | | levelname . Text . Trim ( ) = = previousdefaultmaplumpname )
2013-09-11 09:47:53 +00:00
{
// Get default lump name from configuration
levelname . Text = ci . DefaultLumpName ;
}
2014-07-11 10:13:26 +00:00
//mxd
bool enablescriptcompiler = ! string . IsNullOrEmpty ( ci . DefaultScriptCompiler ) ;
scriptcompiler . Enabled = enablescriptcompiler ;
scriptcompilerlabel . Enabled = enablescriptcompiler ;
2014-08-26 11:08:34 +00:00
previousdefaultmaplumpname = ci . DefaultLumpName ;
2014-07-11 10:13:26 +00:00
//mxd. Select default script compiler for this game configuration
if ( scriptcompiler . Enabled )
{
if ( General . CompiledScriptConfigs . ContainsKey ( ci . DefaultScriptCompiler ) )
scriptcompiler . SelectedItem = General . CompiledScriptConfigs [ ci . DefaultScriptCompiler ] ;
}
else
{
scriptcompiler . SelectedIndex = - 1 ;
}
2009-04-19 18:07:22 +00:00
// Show resources
datalocations . FixedResourceLocationList ( ci . Resources ) ;
}
}
// 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 ;
}
}
// Help
private void MapOptionsForm_HelpRequested ( object sender , HelpEventArgs hlpevent )
{
General . ShowHelp ( "w_mapoptions.html" ) ;
hlpevent . Handled = true ;
}
}
}