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 ;
using System.Collections.Generic ;
using System.Drawing ;
using System.Windows.Forms ;
using CodeImp.DoomBuilder.Config ;
2015-07-27 09:02:28 +00:00
using CodeImp.DoomBuilder.Map ;
2013-06-10 14:04:23 +00:00
using CodeImp.DoomBuilder.Types ;
2009-04-19 18:07:22 +00:00
#endregion
namespace CodeImp.DoomBuilder.Windows
{
internal partial class LinedefEditForm : DelayedForm
{
2013-07-19 15:30:58 +00:00
#region = = = = = = = = = = = = = = = = = = Events
public event EventHandler OnValuesChanged ; //mxd
#endregion
#region = = = = = = = = = = = = = = = = = = Variables
2009-04-19 18:07:22 +00:00
private ICollection < Linedef > lines ;
2015-01-26 08:53:05 +00:00
private List < LinedefProperties > linedefprops ; //mxd
2013-12-20 13:41:57 +00:00
private bool preventchanges ;
2015-01-26 08:53:05 +00:00
private bool undocreated ; //mxd
2013-07-19 15:30:58 +00:00
2013-11-21 10:53:11 +00:00
//mxd. Window setup stuff
private static Point location = Point . Empty ;
2013-07-19 15:30:58 +00:00
private struct LinedefProperties //mxd
{
2014-05-05 14:24:57 +00:00
public readonly Dictionary < string , bool > Flags ;
public readonly SidedefProperties Front ;
public readonly SidedefProperties Back ;
2013-07-19 15:30:58 +00:00
2014-09-15 14:12:31 +00:00
public LinedefProperties ( Linedef line )
{
2013-07-19 15:30:58 +00:00
Front = ( line . Front ! = null ? new SidedefProperties ( line . Front ) : null ) ;
Back = ( line . Back ! = null ? new SidedefProperties ( line . Back ) : null ) ;
Flags = line . GetFlags ( ) ;
}
}
private class SidedefProperties //mxd
{
2014-05-05 14:24:57 +00:00
public readonly int OffsetX ;
public readonly int OffsetY ;
2013-07-19 15:30:58 +00:00
2016-02-26 12:46:17 +00:00
public readonly string HighTexture ;
public readonly string MiddleTexture ;
public readonly string LowTexture ;
2013-07-19 15:30:58 +00:00
2014-09-15 14:12:31 +00:00
public SidedefProperties ( Sidedef side )
{
2016-02-26 12:46:17 +00:00
// Offset
2013-07-19 15:30:58 +00:00
OffsetX = side . OffsetX ;
OffsetY = side . OffsetY ;
2016-02-26 12:46:17 +00:00
// Textures
HighTexture = side . HighTexture ;
MiddleTexture = side . MiddleTexture ;
LowTexture = side . LowTexture ;
2013-07-19 15:30:58 +00:00
}
}
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor
2009-04-19 18:07:22 +00:00
public LinedefEditForm ( )
{
// Initialize
InitializeComponent ( ) ;
2013-11-21 10:53:11 +00:00
//mxd. Widow setup
2014-09-15 14:12:31 +00:00
if ( location ! = Point . Empty )
{
2013-11-21 10:53:11 +00:00
this . StartPosition = FormStartPosition . Manual ;
this . Location = location ;
}
2009-04-19 18:07:22 +00:00
2013-07-19 15:30:58 +00:00
// Fill flags lists
2009-04-19 18:07:22 +00:00
foreach ( KeyValuePair < string , string > lf in General . Map . Config . LinedefFlags )
flags . Add ( lf . Value , lf . Key ) ;
// Fill actions list
action . GeneralizedCategories = General . Map . Config . GenActionCategories ;
action . AddInfo ( General . Map . Config . SortedLinedefActions . ToArray ( ) ) ;
// Fill activations list
activation . Items . AddRange ( General . Map . Config . LinedefActivates . ToArray ( ) ) ;
// Initialize image selectors
fronthigh . Initialize ( ) ;
frontmid . Initialize ( ) ;
frontlow . Initialize ( ) ;
backhigh . Initialize ( ) ;
backmid . Initialize ( ) ;
backlow . Initialize ( ) ;
2014-09-15 14:12:31 +00:00
// Mixed activations?
if ( General . Map . FormatInterface . HasPresetActivations )
2009-04-19 18:07:22 +00:00
hexenpanel . Visible = true ;
// Action arguments?
2015-07-27 09:02:28 +00:00
if ( General . Map . FormatInterface . HasActionArgs ) argscontrol . Visible = true ;
2009-04-19 18:07:22 +00:00
// Arrange panels
2014-09-15 14:12:31 +00:00
if ( ! General . Map . FormatInterface . HasMixedActivations & &
2013-09-11 09:47:53 +00:00
! General . Map . FormatInterface . HasActionArgs & &
! General . Map . FormatInterface . HasPresetActivations )
2009-04-19 18:07:22 +00:00
{
2015-07-27 09:02:28 +00:00
actiongroup . Height = argscontrol . Top + argscontrol . Margin . Top ; //mxd
2009-04-19 18:07:22 +00:00
}
2015-01-05 10:30:32 +00:00
// Arrange or hide Identification panel
2009-04-19 18:07:22 +00:00
if ( General . Map . FormatInterface . HasLinedefTag )
{
// Match position after the action group
idgroup . Top = actiongroup . Bottom + actiongroup . Margin . Bottom + idgroup . Margin . Top ;
2015-01-05 10:30:32 +00:00
panel . Height = idgroup . Bottom + idgroup . Margin . Bottom * 2 ;
2009-04-19 18:07:22 +00:00
}
else
{
idgroup . Visible = false ;
2015-01-05 10:30:32 +00:00
panel . Height = actiongroup . Bottom + actiongroup . Margin . Bottom * 2 ;
2009-04-19 18:07:22 +00:00
}
2015-01-05 10:30:32 +00:00
// Arrange Apply/Cancel buttons
apply . Top = panel . Bottom + panel . Margin . Bottom + apply . Margin . Top ;
cancel . Top = apply . Top ;
// Update window height
this . Height = apply . Bottom + apply . Margin . Bottom * 2 + ( this . Height - this . ClientRectangle . Height ) + 1 ;
2009-04-19 18:07:22 +00:00
}
2013-07-19 15:30:58 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Methods
2009-04-19 18:07:22 +00:00
// This sets up the form to edit the given lines
public void Setup ( ICollection < Linedef > lines )
{
2010-10-03 13:31:29 +00:00
preventchanges = true ;
2009-04-19 18:07:22 +00:00
// Keep this list
this . lines = lines ;
if ( lines . Count > 1 ) this . Text = "Edit Linedefs (" + lines . Count + ")" ;
2015-01-26 08:53:05 +00:00
linedefprops = new List < LinedefProperties > ( ) ;
2009-04-19 18:07:22 +00:00
////////////////////////////////////////////////////////////////////////
// Set all options to the first linedef properties
////////////////////////////////////////////////////////////////////////
// Get first line
2014-09-15 14:12:31 +00:00
Linedef fl = General . GetByIndex ( lines , 0 ) ;
2009-04-19 18:07:22 +00:00
// Flags
foreach ( CheckBox c in flags . Checkboxes )
if ( fl . Flags . ContainsKey ( c . Tag . ToString ( ) ) ) c . Checked = fl . Flags [ c . Tag . ToString ( ) ] ;
// Activations
foreach ( LinedefActivateInfo ai in activation . Items )
if ( ( fl . Activate & ai . Index ) = = ai . Index ) activation . SelectedItem = ai ;
// Action/tags
action . Value = fl . Action ;
2013-06-10 14:04:23 +00:00
2014-09-15 14:12:31 +00:00
if ( General . Map . FormatInterface . HasLinedefTag ) //mxd
{
2013-08-28 08:29:06 +00:00
tagSelector . Setup ( UniversalType . LinedefTag ) ;
2013-03-18 13:52:27 +00:00
tagSelector . SetTag ( fl . Tag ) ;
}
2013-06-10 14:04:23 +00:00
2015-07-27 09:02:28 +00:00
//mxd. Args
argscontrol . SetValue ( fl , true ) ;
2009-04-19 18:07:22 +00:00
// Front side and back side checkboxes
frontside . Checked = ( fl . Front ! = null ) ;
backside . Checked = ( fl . Back ! = null ) ;
// Front settings
if ( fl . Front ! = null )
{
fronthigh . TextureName = fl . Front . HighTexture ;
frontmid . TextureName = fl . Front . MiddleTexture ;
frontlow . TextureName = fl . Front . LowTexture ;
fronthigh . Required = fl . Front . HighRequired ( ) ;
frontmid . Required = fl . Front . MiddleRequired ( ) ;
frontlow . Required = fl . Front . LowRequired ( ) ;
2009-06-05 19:03:56 +00:00
frontsector . Text = fl . Front . Sector . Index . ToString ( ) ;
2014-01-20 08:47:49 +00:00
frontTextureOffset . SetValues ( fl . Front . OffsetX , fl . Front . OffsetY , true ) ; //mxd
2009-04-19 18:07:22 +00:00
}
// Back settings
if ( fl . Back ! = null )
{
backhigh . TextureName = fl . Back . HighTexture ;
backmid . TextureName = fl . Back . MiddleTexture ;
backlow . TextureName = fl . Back . LowTexture ;
backhigh . Required = fl . Back . HighRequired ( ) ;
backmid . Required = fl . Back . MiddleRequired ( ) ;
backlow . Required = fl . Back . LowRequired ( ) ;
2009-06-05 19:03:56 +00:00
backsector . Text = fl . Back . Sector . Index . ToString ( ) ;
2014-01-20 08:47:49 +00:00
backTextureOffset . SetValues ( fl . Back . OffsetX , fl . Back . OffsetY , true ) ; //mxd
2009-04-19 18:07:22 +00:00
}
////////////////////////////////////////////////////////////////////////
// Now go for all lines and change the options when a setting is different
////////////////////////////////////////////////////////////////////////
// Go for all lines
foreach ( Linedef l in lines )
{
// Flags
foreach ( CheckBox c in flags . Checkboxes )
{
2014-08-05 08:22:49 +00:00
if ( c . CheckState = = CheckState . Indeterminate ) continue ; //mxd
if ( l . IsFlagSet ( c . Tag . ToString ( ) ) ! = c . Checked )
2009-04-19 18:07:22 +00:00
{
2014-08-05 08:22:49 +00:00
c . ThreeState = true ;
c . CheckState = CheckState . Indeterminate ;
2009-04-19 18:07:22 +00:00
}
}
// Activations
if ( activation . Items . Count > 0 )
{
2014-09-15 14:12:31 +00:00
LinedefActivateInfo sai = ( activation . Items [ 0 ] as LinedefActivateInfo ) ;
2009-04-19 18:07:22 +00:00
foreach ( LinedefActivateInfo ai in activation . Items )
if ( ( l . Activate & ai . Index ) = = ai . Index ) sai = ai ;
if ( sai ! = activation . SelectedItem ) activation . SelectedIndex = - 1 ;
}
// Action/tags
if ( l . Action ! = action . Value ) action . Empty = true ;
2013-03-18 13:52:27 +00:00
if ( General . Map . FormatInterface . HasLinedefTag & & l . Tag ! = fl . Tag ) tagSelector . ClearTag ( ) ; //mxd
2015-07-27 09:02:28 +00:00
//mxd. Arguments
argscontrol . SetValue ( l , false ) ;
2009-04-19 18:07:22 +00:00
// Front side checkbox
if ( ( l . Front ! = null ) ! = frontside . Checked )
{
frontside . ThreeState = true ;
frontside . CheckState = CheckState . Indeterminate ;
frontside . AutoCheck = false ;
}
// Back side checkbox
if ( ( l . Back ! = null ) ! = backside . Checked )
{
backside . ThreeState = true ;
backside . CheckState = CheckState . Indeterminate ;
backside . AutoCheck = false ;
}
// Front settings
if ( l . Front ! = null )
{
2014-03-05 09:21:28 +00:00
//mxd
2016-03-01 23:24:41 +00:00
if ( ! string . IsNullOrEmpty ( fronthigh . TextureName ) & & fronthigh . TextureName ! = l . Front . HighTexture )
2014-09-15 14:12:31 +00:00
{
2014-03-05 09:21:28 +00:00
if ( ! fronthigh . Required & & l . Front . HighRequired ( ) ) fronthigh . Required = true ;
2016-03-01 23:24:41 +00:00
fronthigh . MultipleTextures = true ;
2014-03-05 09:21:28 +00:00
fronthigh . TextureName = string . Empty ;
}
2016-03-01 23:24:41 +00:00
if ( ! string . IsNullOrEmpty ( frontmid . TextureName ) & & frontmid . TextureName ! = l . Front . MiddleTexture )
2014-09-15 14:12:31 +00:00
{
2014-03-05 09:21:28 +00:00
if ( ! frontmid . Required & & l . Front . MiddleRequired ( ) ) frontmid . Required = true ;
2016-03-01 23:24:41 +00:00
frontmid . MultipleTextures = true ;
2014-03-05 09:21:28 +00:00
frontmid . TextureName = string . Empty ;
}
2016-03-01 23:24:41 +00:00
if ( ! string . IsNullOrEmpty ( frontlow . TextureName ) & & frontlow . TextureName ! = l . Front . LowTexture )
2014-09-15 14:12:31 +00:00
{
2014-03-05 09:21:28 +00:00
if ( ! frontlow . Required & & l . Front . LowRequired ( ) ) frontlow . Required = true ;
2016-03-01 23:24:41 +00:00
frontlow . MultipleTextures = true ;
2014-03-05 09:21:28 +00:00
frontlow . TextureName = string . Empty ;
}
2014-01-20 08:47:49 +00:00
if ( frontsector . Text ! = l . Front . Sector . Index . ToString ( ) ) frontsector . Text = string . Empty ;
2012-11-05 12:31:24 +00:00
2014-01-20 08:47:49 +00:00
frontTextureOffset . SetValues ( l . Front . OffsetX , l . Front . OffsetY , false ) ; //mxd
2009-04-19 18:07:22 +00:00
}
// Back settings
if ( l . Back ! = null )
{
2014-03-05 09:21:28 +00:00
//mxd
2016-03-01 23:24:41 +00:00
if ( ! string . IsNullOrEmpty ( backhigh . TextureName ) & & backhigh . TextureName ! = l . Back . HighTexture )
2014-09-15 14:12:31 +00:00
{
2014-03-05 09:21:28 +00:00
if ( ! backhigh . Required & & l . Back . HighRequired ( ) ) backhigh . Required = true ;
2016-03-01 23:24:41 +00:00
backhigh . MultipleTextures = true ;
2014-03-05 09:21:28 +00:00
backhigh . TextureName = string . Empty ;
}
2016-03-01 23:24:41 +00:00
if ( ! string . IsNullOrEmpty ( backmid . TextureName ) & & backmid . TextureName ! = l . Back . MiddleTexture )
2014-09-15 14:12:31 +00:00
{
2014-03-05 09:21:28 +00:00
if ( ! backmid . Required & & l . Back . MiddleRequired ( ) ) backmid . Required = true ;
2016-03-01 23:24:41 +00:00
backmid . MultipleTextures = true ;
2014-03-05 09:21:28 +00:00
backmid . TextureName = string . Empty ;
}
2016-03-01 23:24:41 +00:00
if ( ! string . IsNullOrEmpty ( backlow . TextureName ) & & backlow . TextureName ! = l . Back . LowTexture )
2014-09-15 14:12:31 +00:00
{
2014-03-05 09:21:28 +00:00
if ( ! backlow . Required & & l . Back . LowRequired ( ) ) backlow . Required = true ;
2016-03-01 23:24:41 +00:00
backlow . MultipleTextures = true ;
2014-03-05 09:21:28 +00:00
backlow . TextureName = string . Empty ;
}
2014-01-20 08:47:49 +00:00
if ( backsector . Text ! = l . Back . Sector . Index . ToString ( ) ) backsector . Text = string . Empty ;
2012-11-05 12:31:24 +00:00
2014-01-20 08:47:49 +00:00
backTextureOffset . SetValues ( l . Back . OffsetX , l . Back . OffsetY , false ) ; //mxd
2009-04-19 18:07:22 +00:00
}
2013-07-19 15:30:58 +00:00
//mxd
2015-01-26 08:53:05 +00:00
linedefprops . Add ( new LinedefProperties ( l ) ) ;
2009-04-19 18:07:22 +00:00
}
// Refresh controls so that they show their image
backhigh . Refresh ( ) ;
backmid . Refresh ( ) ;
backlow . Refresh ( ) ;
fronthigh . Refresh ( ) ;
frontmid . Refresh ( ) ;
frontlow . Refresh ( ) ;
2010-10-03 13:31:29 +00:00
preventchanges = false ;
2012-07-10 10:20:45 +00:00
2015-07-27 09:02:28 +00:00
argscontrol . UpdateScriptControls ( ) ; //mxd
2014-12-05 14:33:31 +00:00
actionhelp . UpdateAction ( action . GetValue ( ) ) ; //mxd
2013-08-08 11:04:13 +00:00
2015-01-05 14:56:44 +00:00
//mxd. Update some labels
if ( frontside . CheckState ! = CheckState . Unchecked )
{
labelFrontTextureOffset . Enabled = frontTextureOffset . NonDefaultValue ;
}
if ( backside . CheckState ! = CheckState . Unchecked )
{
labelBackTextureOffset . Enabled = backTextureOffset . NonDefaultValue ;
}
2013-08-08 11:04:13 +00:00
}
2012-07-10 10:20:45 +00:00
2015-01-26 08:53:05 +00:00
//mxd
private void MakeUndo ( )
{
if ( undocreated ) return ;
undocreated = true ;
//mxd. Make undo
General . Map . UndoRedo . CreateUndo ( "Edit " + ( lines . Count > 1 ? lines . Count + " linedefs" : "linedef" ) ) ;
}
2013-07-19 15:30:58 +00:00
#endregion
2009-04-19 18:07:22 +00:00
2013-08-08 11:04:13 +00:00
#region = = = = = = = = = = = = = = = = = = Events
2009-04-19 18:07:22 +00:00
// Apply clicked
private void apply_Click ( object sender , EventArgs e )
{
// Verify the tag
2013-03-18 13:52:27 +00:00
if ( General . Map . FormatInterface . HasLinedefTag )
2009-04-19 18:07:22 +00:00
{
2013-03-18 13:52:27 +00:00
tagSelector . ValidateTag ( ) ; //mxd
2014-09-15 14:12:31 +00:00
if ( ( ( tagSelector . GetTag ( 0 ) < General . Map . FormatInterface . MinTag ) | | ( tagSelector . GetTag ( 0 ) > General . Map . FormatInterface . MaxTag ) ) )
{
2013-03-18 13:52:27 +00:00
General . ShowWarningMessage ( "Linedef tag must be between " + General . Map . FormatInterface . MinTag + " and " + General . Map . FormatInterface . MaxTag + "." , MessageBoxButtons . OK ) ;
return ;
}
2009-04-19 18:07:22 +00:00
}
// Verify the action
if ( ( action . Value < General . Map . FormatInterface . MinAction ) | | ( action . Value > General . Map . FormatInterface . MaxAction ) )
{
General . ShowWarningMessage ( "Linedef action must be between " + General . Map . FormatInterface . MinAction + " and " + General . Map . FormatInterface . MaxAction + "." , MessageBoxButtons . OK ) ;
return ;
}
2012-07-10 10:20:45 +00:00
2015-01-26 08:53:05 +00:00
MakeUndo ( ) ; //mxd
2009-04-19 18:07:22 +00:00
// Go for all the lines
2016-08-29 10:06:16 +00:00
int offset = 0 ; //mxd
2009-04-19 18:07:22 +00:00
foreach ( Linedef l in lines )
{
// Apply chosen activation flag
if ( activation . SelectedIndex > - 1 )
l . Activate = ( activation . SelectedItem as LinedefActivateInfo ) . Index ;
// Action/tags
2016-08-29 10:06:16 +00:00
l . Tag = General . Clamp ( tagSelector . GetSmartTag ( l . Tag , offset ) , General . Map . FormatInterface . MinTag , General . Map . FormatInterface . MaxTag ) ; //mxd
2015-07-27 09:02:28 +00:00
if ( ! action . Empty ) l . Action = action . Value ;
2013-08-08 11:04:13 +00:00
2015-07-27 09:02:28 +00:00
//mxd. Apply args
2016-08-29 10:06:16 +00:00
argscontrol . Apply ( l , offset ) ;
2009-04-19 18:07:22 +00:00
// Remove front side?
if ( ( l . Front ! = null ) & & ( frontside . CheckState = = CheckState . Unchecked ) )
{
l . Front . Dispose ( ) ;
}
// Create or modify front side?
else if ( frontside . CheckState = = CheckState . Checked )
{
// Make sure we have a valid sector (make a new one if needed)
2015-12-28 15:01:53 +00:00
int index = ( l . Front ! = null ? l . Front . Sector . Index : - 1 ) ;
2010-08-15 19:43:00 +00:00
index = frontsector . GetResult ( index ) ;
if ( ( index > - 1 ) & & ( index < General . Map . Map . Sectors . Count ) )
{
2015-12-28 15:01:53 +00:00
Sector s = ( General . Map . Map . GetSectorByIndex ( index ) ? ? General . Map . Map . CreateSector ( ) ) ;
2010-08-15 19:43:00 +00:00
if ( s ! = null )
{
// Create new sidedef?
if ( l . Front = = null ) General . Map . Map . CreateSidedef ( l , true , s ) ;
2012-11-05 12:31:24 +00:00
2013-07-19 15:30:58 +00:00
// Change sector?
if ( l . Front ! = null & & l . Front . Sector ! = s ) l . Front . SetSector ( s ) ;
2010-08-15 19:43:00 +00:00
}
}
2009-04-19 18:07:22 +00:00
}
// Remove back side?
if ( ( l . Back ! = null ) & & ( backside . CheckState = = CheckState . Unchecked ) )
{
l . Back . Dispose ( ) ;
}
// Create or modify back side?
else if ( backside . CheckState = = CheckState . Checked )
{
// Make sure we have a valid sector (make a new one if needed)
2015-12-28 15:01:53 +00:00
int index = ( l . Back ! = null ? l . Back . Sector . Index : - 1 ) ;
2010-08-15 19:43:00 +00:00
index = backsector . GetResult ( index ) ;
if ( ( index > - 1 ) & & ( index < General . Map . Map . Sectors . Count ) )
{
2015-12-28 15:01:53 +00:00
Sector s = ( General . Map . Map . GetSectorByIndex ( index ) ? ? General . Map . Map . CreateSector ( ) ) ;
2010-08-15 19:43:00 +00:00
if ( s ! = null )
{
// Create new sidedef?
if ( l . Back = = null ) General . Map . Map . CreateSidedef ( l , false , s ) ;
2013-07-19 15:30:58 +00:00
// Change sector?
if ( l . Back ! = null & & l . Back . Sector ! = s ) l . Back . SetSector ( s ) ;
2010-08-15 19:43:00 +00:00
}
}
2009-04-19 18:07:22 +00:00
}
2016-08-29 10:06:16 +00:00
//mxd. Increase offset...
offset + + ;
2009-04-19 18:07:22 +00:00
}
// Update the used textures
General . Map . Data . UpdateUsedTextures ( ) ;
// Done
General . Map . IsChanged = true ;
2013-07-19 15:30:58 +00:00
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ; //mxd
2009-04-19 18:07:22 +00:00
this . DialogResult = DialogResult . OK ;
this . Close ( ) ;
}
// Cancel clicked
private void cancel_Click ( object sender , EventArgs e )
{
2013-07-19 15:30:58 +00:00
//mxd. Let's pretend nothing of this really happened...
2015-01-26 08:53:05 +00:00
if ( undocreated ) General . Map . UndoRedo . WithdrawUndo ( ) ;
2013-07-19 15:30:58 +00:00
2009-04-19 18:07:22 +00:00
// Be gone
this . DialogResult = DialogResult . Cancel ;
this . Close ( ) ;
}
2013-07-19 15:30:58 +00:00
// Front side (un)checked
private void frontside_CheckStateChanged ( object sender , EventArgs e )
{
// Enable/disable panel
// NOTE: Also enabled when checkbox is grayed!
frontgroup . Enabled = ( frontside . CheckState ! = CheckState . Unchecked ) ;
}
// Back side (un)checked
private void backside_CheckStateChanged ( object sender , EventArgs e )
{
// Enable/disable panel
// NOTE: Also enabled when checkbox is grayed!
backgroup . Enabled = ( backside . CheckState ! = CheckState . Unchecked ) ;
}
2009-04-19 18:07:22 +00:00
// Action changes
private void action_ValueChanges ( object sender , EventArgs e )
{
int showaction = 0 ;
// Only when line type is known
if ( General . Map . Config . LinedefActions . ContainsKey ( action . Value ) ) showaction = action . Value ;
2015-07-27 09:02:28 +00:00
//mxd. Change the argument descriptions
argscontrol . UpdateAction ( showaction , preventchanges ) ;
2010-10-03 13:31:29 +00:00
2014-09-15 14:12:31 +00:00
if ( ! preventchanges )
{
2015-01-26 08:53:05 +00:00
MakeUndo ( ) ; //mxd
2012-07-10 10:20:45 +00:00
2014-12-05 21:34:16 +00:00
//mxd. Update what must be updated
2015-07-27 09:02:28 +00:00
argscontrol . UpdateScriptControls ( ) ;
2014-12-05 21:34:16 +00:00
actionhelp . UpdateAction ( showaction ) ;
}
2009-04-19 18:07:22 +00:00
}
// Browse Action clicked
private void browseaction_Click ( object sender , EventArgs e )
{
action . Value = ActionBrowserForm . BrowseAction ( this , action . Value ) ;
}
2013-11-21 10:53:11 +00:00
//mxd. Store window location
2014-09-15 14:12:31 +00:00
private void LinedefEditForm_FormClosing ( object sender , FormClosingEventArgs e )
{
2016-02-26 12:46:17 +00:00
// Save location
2013-11-21 10:53:11 +00:00
location = this . Location ;
}
2009-04-19 18:07:22 +00:00
// Help!
private void LinedefEditForm_HelpRequested ( object sender , HelpEventArgs hlpevent )
{
General . ShowHelp ( "w_linedefedit.html" ) ;
hlpevent . Handled = true ;
}
2013-07-19 15:30:58 +00:00
#endregion
2014-09-15 14:12:31 +00:00
#region = = = = = = = = = = = = = = = = = = Linedef realtime events ( mxd )
2013-07-19 15:30:58 +00:00
2014-12-03 23:15:26 +00:00
private void flags_OnValueChanged ( object sender , EventArgs e )
{
2013-07-19 15:30:58 +00:00
if ( preventchanges ) return ;
2015-01-26 08:53:05 +00:00
MakeUndo ( ) ; //mxd
2013-07-19 15:30:58 +00:00
int i = 0 ;
2014-09-15 14:12:31 +00:00
foreach ( Linedef l in lines )
{
2013-07-19 15:30:58 +00:00
// Apply all flags
2014-09-15 14:12:31 +00:00
foreach ( CheckBox c in flags . Checkboxes )
{
2013-07-19 15:30:58 +00:00
if ( c . CheckState = = CheckState . Checked )
l . SetFlag ( c . Tag . ToString ( ) , true ) ;
else if ( c . CheckState = = CheckState . Unchecked )
l . SetFlag ( c . Tag . ToString ( ) , false ) ;
2015-01-26 08:53:05 +00:00
else if ( linedefprops [ i ] . Flags . ContainsKey ( c . Tag . ToString ( ) ) )
l . SetFlag ( c . Tag . ToString ( ) , linedefprops [ i ] . Flags [ c . Tag . ToString ( ) ] ) ;
2014-08-06 10:21:12 +00:00
else //linedefs created in the editor have empty Flags by default
l . SetFlag ( c . Tag . ToString ( ) , false ) ;
2013-07-19 15:30:58 +00:00
}
i + + ;
}
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
#endregion
2014-09-15 14:12:31 +00:00
#region = = = = = = = = = = = = = = = = = = Sidedef reltime events ( mxd )
2013-07-19 15:30:58 +00:00
2014-09-15 14:12:31 +00:00
private void fronthigh_OnValueChanged ( object sender , EventArgs e )
{
2013-07-19 15:30:58 +00:00
if ( preventchanges ) return ;
2016-02-26 12:46:17 +00:00
MakeUndo ( ) ;
2013-07-19 15:30:58 +00:00
2016-02-26 12:46:17 +00:00
// Restore values
2014-09-15 14:12:31 +00:00
if ( string . IsNullOrEmpty ( fronthigh . TextureName ) )
{
2013-07-19 15:30:58 +00:00
int i = 0 ;
2014-09-15 14:12:31 +00:00
foreach ( Linedef l in lines )
{
2016-02-26 12:46:17 +00:00
if ( l . Front ! = null ) l . Front . SetTextureHigh ( linedefprops [ i ] . Front ! = null ? linedefprops [ i ] . Front . HighTexture : "-" ) ;
2013-07-19 15:30:58 +00:00
i + + ;
}
2016-02-26 12:46:17 +00:00
}
// Update values
else
2014-09-15 14:12:31 +00:00
{
2016-02-26 12:46:17 +00:00
foreach ( Linedef l in lines )
{
2016-06-05 22:06:56 +00:00
if ( l . Front ! = null ) l . Front . SetTextureHigh ( fronthigh . GetResult ( l . Front . HighTexture ) ) ;
2016-02-26 12:46:17 +00:00
}
2013-07-19 15:30:58 +00:00
}
// Update the used textures
General . Map . Data . UpdateUsedTextures ( ) ;
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
2014-09-15 14:12:31 +00:00
private void frontmid_OnValueChanged ( object sender , EventArgs e )
{
2013-07-19 15:30:58 +00:00
if ( preventchanges ) return ;
2016-02-26 12:46:17 +00:00
MakeUndo ( ) ;
2013-07-19 15:30:58 +00:00
2016-02-26 12:46:17 +00:00
// Restore values
2014-09-15 14:12:31 +00:00
if ( string . IsNullOrEmpty ( frontmid . TextureName ) )
{
2013-07-19 15:30:58 +00:00
int i = 0 ;
2014-09-15 14:12:31 +00:00
foreach ( Linedef l in lines )
{
2016-02-26 12:46:17 +00:00
if ( l . Front ! = null ) l . Front . SetTextureMid ( linedefprops [ i ] . Front ! = null ? linedefprops [ i ] . Front . MiddleTexture : "-" ) ;
2013-07-19 15:30:58 +00:00
i + + ;
}
2016-02-26 12:46:17 +00:00
}
// Update values
else
2014-09-15 14:12:31 +00:00
{
2016-02-26 12:46:17 +00:00
foreach ( Linedef l in lines )
{
2016-06-05 22:06:56 +00:00
if ( l . Front ! = null ) l . Front . SetTextureMid ( frontmid . GetResult ( l . Front . MiddleTexture ) ) ;
2016-02-26 12:46:17 +00:00
}
2013-07-19 15:30:58 +00:00
}
// Update the used textures
General . Map . Data . UpdateUsedTextures ( ) ;
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
2014-09-15 14:12:31 +00:00
private void frontlow_OnValueChanged ( object sender , EventArgs e )
{
2013-07-19 15:30:58 +00:00
if ( preventchanges ) return ;
2016-02-26 12:46:17 +00:00
MakeUndo ( ) ;
2013-07-19 15:30:58 +00:00
2016-02-26 12:46:17 +00:00
// Restore values
2014-09-15 14:12:31 +00:00
if ( string . IsNullOrEmpty ( frontlow . TextureName ) )
{
2013-07-19 15:30:58 +00:00
int i = 0 ;
2014-09-15 14:12:31 +00:00
foreach ( Linedef l in lines )
{
2016-02-26 12:46:17 +00:00
if ( l . Front ! = null ) l . Front . SetTextureLow ( linedefprops [ i ] . Front ! = null ? linedefprops [ i ] . Front . LowTexture : "-" ) ;
2013-07-19 15:30:58 +00:00
i + + ;
}
2016-02-26 12:46:17 +00:00
}
// Update values
else
2014-09-15 14:12:31 +00:00
{
2013-07-19 15:30:58 +00:00
foreach ( Linedef l in lines )
2016-02-26 12:46:17 +00:00
{
2016-06-05 22:06:56 +00:00
if ( l . Front ! = null ) l . Front . SetTextureLow ( frontlow . GetResult ( l . Front . LowTexture ) ) ;
2016-02-26 12:46:17 +00:00
}
2013-07-19 15:30:58 +00:00
}
// Update the used textures
General . Map . Data . UpdateUsedTextures ( ) ;
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
2014-09-15 14:12:31 +00:00
private void backhigh_OnValueChanged ( object sender , EventArgs e )
{
2013-07-19 15:30:58 +00:00
if ( preventchanges ) return ;
2016-02-26 12:46:17 +00:00
MakeUndo ( ) ;
2013-07-19 15:30:58 +00:00
2016-02-26 12:46:17 +00:00
// Restore values
2014-09-15 14:12:31 +00:00
if ( string . IsNullOrEmpty ( backhigh . TextureName ) )
{
2013-07-19 15:30:58 +00:00
int i = 0 ;
2014-09-15 14:12:31 +00:00
foreach ( Linedef l in lines )
{
2016-02-26 12:46:17 +00:00
if ( l . Back ! = null ) l . Back . SetTextureHigh ( linedefprops [ i ] . Back ! = null ? linedefprops [ i ] . Back . HighTexture : "-" ) ;
2013-07-19 15:30:58 +00:00
i + + ;
}
2016-02-26 12:46:17 +00:00
}
// Update values
else
2014-09-15 14:12:31 +00:00
{
2013-07-19 15:30:58 +00:00
foreach ( Linedef l in lines )
2016-02-26 12:46:17 +00:00
{
2016-06-05 22:06:56 +00:00
if ( l . Back ! = null ) l . Back . SetTextureHigh ( backhigh . GetResult ( l . Back . HighTexture ) ) ;
2016-02-26 12:46:17 +00:00
}
2013-07-19 15:30:58 +00:00
}
// Update the used textures
General . Map . Data . UpdateUsedTextures ( ) ;
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
2014-09-15 14:12:31 +00:00
private void backmid_OnValueChanged ( object sender , EventArgs e )
{
2013-07-19 15:30:58 +00:00
if ( preventchanges ) return ;
2016-02-26 12:46:17 +00:00
MakeUndo ( ) ;
2013-07-19 15:30:58 +00:00
2016-02-26 12:46:17 +00:00
// Restore values
2014-09-15 14:12:31 +00:00
if ( string . IsNullOrEmpty ( backmid . TextureName ) )
{
2013-07-19 15:30:58 +00:00
int i = 0 ;
2014-09-15 14:12:31 +00:00
foreach ( Linedef l in lines )
{
2016-02-26 12:46:17 +00:00
if ( l . Back ! = null ) l . Back . SetTextureMid ( linedefprops [ i ] . Back ! = null ? linedefprops [ i ] . Back . MiddleTexture : "-" ) ;
2013-07-19 15:30:58 +00:00
i + + ;
}
2016-02-26 12:46:17 +00:00
}
// Update values
else
2014-09-15 14:12:31 +00:00
{
2013-07-19 15:30:58 +00:00
foreach ( Linedef l in lines )
2016-02-26 12:46:17 +00:00
{
2016-06-05 22:06:56 +00:00
if ( l . Back ! = null ) l . Back . SetTextureMid ( backmid . GetResult ( l . Back . MiddleTexture ) ) ;
2016-02-26 12:46:17 +00:00
}
2013-07-19 15:30:58 +00:00
}
// Update the used textures
General . Map . Data . UpdateUsedTextures ( ) ;
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
2014-09-15 14:12:31 +00:00
private void backlow_OnValueChanged ( object sender , EventArgs e )
{
2013-07-19 15:30:58 +00:00
if ( preventchanges ) return ;
2016-02-26 12:46:17 +00:00
MakeUndo ( ) ;
2013-07-19 15:30:58 +00:00
2016-02-26 12:46:17 +00:00
// Restore values
2014-09-15 14:12:31 +00:00
if ( string . IsNullOrEmpty ( backlow . TextureName ) )
{
2013-07-19 15:30:58 +00:00
int i = 0 ;
2014-09-15 14:12:31 +00:00
foreach ( Linedef l in lines )
{
2016-02-26 12:46:17 +00:00
if ( l . Back ! = null ) l . Back . SetTextureLow ( linedefprops [ i ] . Back ! = null ? linedefprops [ i ] . Back . LowTexture : "-" ) ;
2013-07-19 15:30:58 +00:00
i + + ;
}
2016-02-26 12:46:17 +00:00
}
// Update values
else
2014-09-15 14:12:31 +00:00
{
2013-07-19 15:30:58 +00:00
foreach ( Linedef l in lines )
2016-02-26 12:46:17 +00:00
{
2016-06-05 22:06:56 +00:00
if ( l . Back ! = null ) l . Back . SetTextureLow ( backlow . GetResult ( l . Back . LowTexture ) ) ;
2016-02-26 12:46:17 +00:00
}
2013-07-19 15:30:58 +00:00
}
// Update the used textures
General . Map . Data . UpdateUsedTextures ( ) ;
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
2014-09-15 14:12:31 +00:00
private void frontTextureOffset_OnValuesChanged ( object sender , EventArgs e )
{
2013-07-19 15:30:58 +00:00
if ( preventchanges ) return ;
2015-01-26 08:53:05 +00:00
MakeUndo ( ) ; //mxd
2013-07-19 15:30:58 +00:00
int i = 0 ;
2014-09-15 14:12:31 +00:00
foreach ( Linedef l in lines )
{
if ( l . Front ! = null )
{
2015-01-26 08:53:05 +00:00
if ( linedefprops [ i ] . Front ! = null )
2014-09-15 14:12:31 +00:00
{
2015-01-26 08:53:05 +00:00
l . Front . OffsetX = frontTextureOffset . GetValue1 ( linedefprops [ i ] . Front . OffsetX ) ;
l . Front . OffsetY = frontTextureOffset . GetValue2 ( linedefprops [ i ] . Front . OffsetY ) ;
2014-09-15 14:12:31 +00:00
}
else
{
2013-07-19 15:30:58 +00:00
l . Front . OffsetX = frontTextureOffset . GetValue1 ( 0 ) ;
l . Front . OffsetY = frontTextureOffset . GetValue2 ( 0 ) ;
}
}
i + + ;
}
General . Map . IsChanged = true ;
2015-01-05 14:56:44 +00:00
labelFrontTextureOffset . Enabled = frontTextureOffset . NonDefaultValue ;
2013-07-19 15:30:58 +00:00
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
2014-09-15 14:12:31 +00:00
private void backTextureOffset_OnValuesChanged ( object sender , EventArgs e )
{
2013-07-19 15:30:58 +00:00
if ( preventchanges ) return ;
2015-01-26 08:53:05 +00:00
MakeUndo ( ) ; //mxd
2013-07-19 15:30:58 +00:00
int i = 0 ;
2014-09-15 14:12:31 +00:00
foreach ( Linedef l in lines )
{
if ( l . Back ! = null )
{
2015-01-26 08:53:05 +00:00
if ( linedefprops [ i ] . Back ! = null )
2014-09-15 14:12:31 +00:00
{
2015-01-26 08:53:05 +00:00
l . Back . OffsetX = backTextureOffset . GetValue1 ( linedefprops [ i ] . Back . OffsetX ) ;
l . Back . OffsetY = backTextureOffset . GetValue2 ( linedefprops [ i ] . Back . OffsetY ) ;
2014-09-15 14:12:31 +00:00
}
else
{
2013-07-19 15:30:58 +00:00
l . Back . OffsetX = backTextureOffset . GetValue1 ( 0 ) ;
l . Back . OffsetY = backTextureOffset . GetValue2 ( 0 ) ;
}
}
i + + ;
}
General . Map . IsChanged = true ;
2015-01-05 14:56:44 +00:00
labelBackTextureOffset . Enabled = backTextureOffset . NonDefaultValue ;
2013-07-19 15:30:58 +00:00
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
#endregion
2009-04-19 18:07:22 +00:00
}
}