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.Map ;
using CodeImp.DoomBuilder.Data ;
using CodeImp.DoomBuilder.Config ;
using CodeImp.DoomBuilder.Geometry ;
2012-06-01 10:17:47 +00:00
using CodeImp.DoomBuilder.GZBuilder.Data ;
2013-08-08 11:04:13 +00:00
using CodeImp.DoomBuilder.Types ;
2009-04-19 18:07:22 +00:00
#endregion
namespace CodeImp.DoomBuilder.Windows
{
2009-05-21 08:18:34 +00:00
/// <summary>
/// Dialog window that allows viewing and editing of Thing properties.
/// </summary>
2013-07-10 08:59:17 +00:00
internal partial class ThingEditForm : DelayedForm
2009-04-19 18:07:22 +00:00
{
2013-07-19 15:30:58 +00:00
#region = = = = = = = = = = = = = = = = = = Events
public event EventHandler OnValuesChanged ; //mxd
#endregion
2009-04-19 18:07:22 +00:00
#region = = = = = = = = = = = = = = = = = = Variables
private ICollection < Thing > things ;
private ThingTypeInfo thinginfo ;
2013-08-08 11:04:13 +00:00
private bool preventchanges ;
2013-09-11 09:47:53 +00:00
//mxd
2013-07-19 15:30:58 +00:00
private static bool useAbsoluteHeight ;
private List < ThingProperties > thingProps ; //mxd
2009-04-19 18:07:22 +00:00
2013-11-21 10:53:11 +00:00
//mxd. Window setup stuff
private static Point location = Point . Empty ;
private static int activeTab ;
2013-07-19 15:30:58 +00:00
private struct ThingProperties //mxd
{
2014-09-03 14:07:08 +00:00
//public readonly int Type;
2014-04-21 09:30:00 +00:00
public readonly int AngleDoom ;
public readonly float X ;
public readonly float Y ;
public readonly float Z ;
2013-07-19 15:30:58 +00:00
2014-05-02 11:37:37 +00:00
public ThingProperties ( Thing t )
{
2013-07-19 15:30:58 +00:00
X = t . Position . x ;
Y = t . Position . y ;
Z = t . Position . z ;
2014-09-03 14:07:08 +00:00
//Type = t.Type;
2013-07-19 15:30:58 +00:00
AngleDoom = t . AngleDoom ;
}
}
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor
// Constructor
public ThingEditForm ( )
{
// Initialize
InitializeComponent ( ) ;
2013-11-21 10:53:11 +00:00
//mxd. Widow setup
2014-12-03 23:15:26 +00:00
if ( location ! = Point . Empty )
{
2013-11-21 10:53:11 +00:00
this . StartPosition = FormStartPosition . Manual ;
this . Location = location ;
2014-12-03 23:15:26 +00:00
if ( activeTab > 0 & & activeTab < tabs . TabCount )
{
2013-11-21 10:53:11 +00:00
tabs . SelectTab ( activeTab ) ;
2014-12-03 23:15:26 +00:00
}
else
{
2013-11-21 10:53:11 +00:00
activeTab = 0 ;
}
}
2009-04-26 19:53:36 +00:00
2009-04-19 18:07:22 +00:00
// Fill flags list
foreach ( KeyValuePair < string , string > tf in General . Map . Config . ThingFlags )
flags . Add ( tf . Value , tf . Key ) ;
// Fill actions list
action . GeneralizedCategories = General . Map . Config . GenActionCategories ;
action . AddInfo ( General . Map . Config . SortedLinedefActions . ToArray ( ) ) ;
// Tag/Effects?
2014-12-03 23:15:26 +00:00
if ( ! General . Map . FormatInterface . HasThingAction & & ! General . Map . FormatInterface . HasThingTag )
{
2009-04-19 18:07:22 +00:00
tabs . TabPages . Remove ( tabeffects ) ;
2014-12-03 23:15:26 +00:00
}
else //mxd. Setup script numbers
{
2013-08-08 11:04:13 +00:00
scriptNumbers . Location = arg0 . Location ;
foreach ( ScriptItem si in General . Map . NumberedScripts )
scriptNumbers . Items . Add ( si ) ;
2013-08-13 09:49:29 +00:00
scriptNumbers . DropDownWidth = Tools . GetDropDownWidth ( scriptNumbers ) ;
2013-08-08 11:04:13 +00:00
}
2009-04-19 18:07:22 +00:00
// Thing height?
2012-09-16 19:54:16 +00:00
posZ . Visible = General . Map . FormatInterface . HasThingHeight ;
zlabel . Visible = General . Map . FormatInterface . HasThingHeight ;
cbAbsoluteHeight . Visible = General . Map . FormatInterface . HasThingHeight ; //mxd
2013-07-19 15:30:58 +00:00
//mxd. Decimals allowed?
2014-12-03 23:15:26 +00:00
if ( General . Map . FormatInterface . VertexDecimals > 0 )
{
2013-07-19 15:30:58 +00:00
posX . AllowDecimal = true ;
posY . AllowDecimal = true ;
posZ . AllowDecimal = true ;
}
2009-04-19 18:07:22 +00:00
// Setup types list
thingtype . Setup ( ) ;
}
// This sets up the form to edit the given things
public void Setup ( ICollection < Thing > things )
{
2010-10-03 13:58:11 +00:00
preventchanges = true ;
2009-04-19 18:07:22 +00:00
// Keep this list
this . things = things ;
2013-12-23 12:02:58 +00:00
if ( things . Count > 1 ) this . Text = "Edit Things (" + things . Count + ")" ;
hint . Visible = things . Count > 1 ; //mxd
hintlabel . Visible = things . Count > 1 ; //mxd
2014-10-29 11:35:27 +00:00
thingtype . UseMultiSelection = things . Count > 1 ; //mxd
2013-07-19 15:30:58 +00:00
//mxd. Make undo
string undodesc = "thing" ;
if ( things . Count > 1 ) undodesc = things . Count + " things" ;
General . Map . UndoRedo . CreateUndo ( "Edit " + undodesc ) ;
2009-04-19 18:07:22 +00:00
////////////////////////////////////////////////////////////////////////
// Set all options to the first thing properties
////////////////////////////////////////////////////////////////////////
2013-12-23 12:02:58 +00:00
Thing ft = General . GetByIndex ( things , 0 ) ;
2009-04-19 18:07:22 +00:00
// Set type
thingtype . SelectType ( ft . Type ) ;
// Flags
foreach ( CheckBox c in flags . Checkboxes )
if ( ft . Flags . ContainsKey ( c . Tag . ToString ( ) ) ) c . Checked = ft . Flags [ c . Tag . ToString ( ) ] ;
// Coordination
2010-10-05 08:31:27 +00:00
angle . Text = ft . AngleDoom . ToString ( ) ;
2013-12-10 13:01:27 +00:00
zlabel . Text = useAbsoluteHeight ? "Abs. Z:" : "Z:" ; //mxd
2013-07-19 15:30:58 +00:00
cbAbsoluteHeight . Checked = useAbsoluteHeight ; //mxd
2012-06-29 18:58:18 +00:00
2013-09-11 09:47:53 +00:00
//mxd
2014-09-03 14:07:08 +00:00
ft . DetermineSector ( ) ;
int floorheight = ( ft . Sector ! = null ? ft . Sector . FloorHeight : 0 ) ;
2013-09-11 09:47:53 +00:00
posX . Text = ( ( int ) ft . Position . x ) . ToString ( ) ;
posY . Text = ( ( int ) ft . Position . y ) . ToString ( ) ;
2014-09-03 14:07:08 +00:00
posZ . Text = useAbsoluteHeight ? ( ( int ) ft . Position . z + floorheight ) . ToString ( ) : ( ( int ) ft . Position . z ) . ToString ( ) ;
2013-09-11 09:47:53 +00:00
posX . ButtonStep = General . Map . Grid . GridSize ;
posY . ButtonStep = General . Map . Grid . GridSize ;
2012-09-16 19:54:16 +00:00
posZ . ButtonStep = General . Map . Grid . GridSize ;
2012-07-10 10:20:45 +00:00
2009-04-19 18:07:22 +00:00
// Action/tags
action . Value = ft . Action ;
2014-12-03 23:15:26 +00:00
if ( General . Map . FormatInterface . HasThingTag ) //mxd
{
2013-08-28 08:29:06 +00:00
tagSelector . Setup ( UniversalType . ThingTag ) ;
2013-03-18 13:52:27 +00:00
tagSelector . SetTag ( ft . Tag ) ;
}
2009-04-19 18:07:22 +00:00
arg0 . SetValue ( ft . Args [ 0 ] ) ;
arg1 . SetValue ( ft . Args [ 1 ] ) ;
arg2 . SetValue ( ft . Args [ 2 ] ) ;
arg3 . SetValue ( ft . Args [ 3 ] ) ;
arg4 . SetValue ( ft . Args [ 4 ] ) ;
////////////////////////////////////////////////////////////////////////
// Now go for all lines and change the options when a setting is different
////////////////////////////////////////////////////////////////////////
2013-07-19 15:30:58 +00:00
thingProps = new List < ThingProperties > ( ) ;
2009-04-19 18:07:22 +00:00
// Go for all things
foreach ( Thing t in things )
{
2014-09-03 14:07:08 +00:00
//mxd. Update sector info
t . DetermineSector ( ) ;
2009-04-19 18:07:22 +00:00
// Type does not match?
2013-03-18 13:52:27 +00:00
ThingTypeInfo info = thingtype . GetSelectedInfo ( ) ; //mxd
if ( info ! = null & & info . Index ! = t . Type )
2009-04-19 18:07:22 +00:00
thingtype . ClearSelectedType ( ) ;
// Flags
foreach ( CheckBox c in flags . Checkboxes )
{
2014-08-05 08:22:49 +00:00
if ( c . CheckState = = CheckState . Indeterminate ) continue ; //mxd
if ( t . 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
}
}
// Coordination
2010-10-05 08:31:27 +00:00
if ( t . AngleDoom . ToString ( ) ! = angle . Text ) angle . Text = "" ;
2012-09-16 19:54:16 +00:00
2014-09-03 14:07:08 +00:00
//mxd. Position
if ( ( ( int ) t . Position . x ) . ToString ( ) ! = posX . Text ) posX . Text = "" ;
if ( ( ( int ) t . Position . y ) . ToString ( ) ! = posY . Text ) posY . Text = "" ;
2014-12-03 23:15:26 +00:00
if ( useAbsoluteHeight & & t . Sector ! = null )
{
2012-09-16 19:54:16 +00:00
if ( ( ( int ) t . Position . z + t . Sector . FloorHeight ) . ToString ( ) ! = posZ . Text ) posZ . Text = "" ;
2014-12-03 23:15:26 +00:00
}
else if ( ( ( int ) t . Position . z ) . ToString ( ) ! = posZ . Text )
{
2013-08-08 11:04:13 +00:00
posZ . Text = "" ;
2012-09-16 19:54:16 +00:00
}
2009-04-19 18:07:22 +00:00
// Action/tags
if ( t . Action ! = action . Value ) action . Empty = true ;
2013-03-18 13:52:27 +00:00
if ( General . Map . FormatInterface . HasThingTag & & t . Tag ! = ft . Tag ) tagSelector . ClearTag ( ) ; //mxd
2009-04-19 18:07:22 +00:00
if ( t . Args [ 0 ] ! = arg0 . GetResult ( - 1 ) ) arg0 . ClearValue ( ) ;
if ( t . Args [ 1 ] ! = arg1 . GetResult ( - 1 ) ) arg1 . ClearValue ( ) ;
if ( t . Args [ 2 ] ! = arg2 . GetResult ( - 1 ) ) arg2 . ClearValue ( ) ;
if ( t . Args [ 3 ] ! = arg3 . GetResult ( - 1 ) ) arg3 . ClearValue ( ) ;
if ( t . Args [ 4 ] ! = arg4 . GetResult ( - 1 ) ) arg4 . ClearValue ( ) ;
2013-07-19 15:30:58 +00:00
//mxd. Store initial properties
thingProps . Add ( new ThingProperties ( t ) ) ;
2009-04-19 18:07:22 +00:00
}
2010-10-03 13:58:11 +00:00
preventchanges = false ;
2012-07-10 10:20:45 +00:00
2014-09-29 20:49:41 +00:00
//mxd. Trigger updates manually...
2014-05-02 11:37:37 +00:00
angle_WhenTextChanged ( angle , EventArgs . Empty ) ;
2014-09-29 20:49:41 +00:00
flags_OnValueChanged ( flags , EventArgs . Empty ) ;
2014-05-02 11:37:37 +00:00
2014-12-03 23:15:26 +00:00
UpdateScriptControls ( ) ; //mxd
2014-12-05 14:33:31 +00:00
actionhelp . UpdateAction ( action . GetValue ( ) ) ; //mxd
2012-09-16 19:54:16 +00:00
2013-08-08 11:04:13 +00:00
//mxd. Set intial script-related values, if required
2014-12-03 23:15:26 +00:00
if ( Array . IndexOf ( GZBuilder . GZGeneral . ACS_SPECIALS , action . Value ) ! = - 1 )
{
2014-04-21 09:30:00 +00:00
int a0 = arg0 . GetResult ( 0 ) ;
2014-12-03 23:15:26 +00:00
if ( a0 > 0 )
{
for ( int i = 0 ; i < General . Map . NumberedScripts . Count ; i + + )
{
if ( General . Map . NumberedScripts [ i ] . Index = = a0 )
{
2014-04-21 09:30:00 +00:00
scriptNumbers . SelectedIndex = i ;
break ;
2013-08-08 11:04:13 +00:00
}
2014-04-21 09:30:00 +00:00
}
2013-08-08 11:04:13 +00:00
2014-12-03 23:15:26 +00:00
if ( scriptNumbers . SelectedIndex = = - 1 )
{
2014-04-21 09:30:00 +00:00
scriptNumbers . Items . Add ( new ScriptItem ( a0 , "Script " + a0 ) ) ;
scriptNumbers . SelectedIndex = scriptNumbers . Items . Count - 1 ;
2013-08-08 11:04:13 +00:00
}
2014-12-03 23:15:26 +00:00
}
else
{
2014-04-21 09:30:00 +00:00
scriptNumbers . Text = arg0 . Text ;
2013-08-08 11:04:13 +00:00
}
2014-12-03 23:15:26 +00:00
}
else
{
2013-08-08 11:04:13 +00:00
scriptNumbers . Text = "0" ;
}
}
//mxd
2014-12-03 23:15:26 +00:00
private void UpdateScriptControls ( )
2014-05-02 11:37:37 +00:00
{
2014-04-21 09:30:00 +00:00
scriptNumbers . Visible = ( Array . IndexOf ( GZBuilder . GZGeneral . ACS_SPECIALS , action . Value ) ! = - 1 ) ;
2013-08-08 11:04:13 +00:00
}
2009-04-19 18:07:22 +00:00
#endregion
2013-07-19 15:30:58 +00:00
#region = = = = = = = = = = = = = = = = = = Events
2013-07-11 11:43:49 +00:00
//mxd
2014-05-02 11:37:37 +00:00
private void thingtype_OnTypeDoubleClicked ( )
{
2013-07-11 11:43:49 +00:00
apply_Click ( this , EventArgs . Empty ) ;
}
2009-04-19 18:07:22 +00:00
// Action changes
private void action_ValueChanges ( object sender , EventArgs e )
{
int showaction = 0 ;
ArgumentInfo [ ] arginfo ;
// Only when line type is known, otherwise use the thing arguments
if ( General . Map . Config . LinedefActions . ContainsKey ( action . Value ) ) showaction = action . Value ;
2014-12-05 21:34:16 +00:00
if ( ( showaction = = 0 ) & & ( thinginfo ! = null ) ) arginfo = thinginfo . Args ;
else arginfo = General . Map . Config . LinedefActions [ showaction ] . Args ;
2009-04-19 18:07:22 +00:00
// Change the argument descriptions
arg0label . Text = arginfo [ 0 ] . Title + ":" ;
arg1label . Text = arginfo [ 1 ] . Title + ":" ;
arg2label . Text = arginfo [ 2 ] . Title + ":" ;
arg3label . Text = arginfo [ 3 ] . Title + ":" ;
arg4label . Text = arginfo [ 4 ] . Title + ":" ;
arg0label . Enabled = arginfo [ 0 ] . Used ;
arg1label . Enabled = arginfo [ 1 ] . Used ;
arg2label . Enabled = arginfo [ 2 ] . Used ;
arg3label . Enabled = arginfo [ 3 ] . Used ;
arg4label . Enabled = arginfo [ 4 ] . Used ;
2014-04-21 09:30:00 +00:00
arg0 . ForeColor = ( arg0label . Enabled ? SystemColors . WindowText : SystemColors . GrayText ) ;
arg1 . ForeColor = ( arg1label . Enabled ? SystemColors . WindowText : SystemColors . GrayText ) ;
arg2 . ForeColor = ( arg2label . Enabled ? SystemColors . WindowText : SystemColors . GrayText ) ;
arg3 . ForeColor = ( arg3label . Enabled ? SystemColors . WindowText : SystemColors . GrayText ) ;
arg4 . ForeColor = ( arg4label . Enabled ? SystemColors . WindowText : SystemColors . GrayText ) ;
2013-09-11 09:47:53 +00:00
arg0 . Setup ( arginfo [ 0 ] ) ;
arg1 . Setup ( arginfo [ 1 ] ) ;
arg2 . Setup ( arginfo [ 2 ] ) ;
arg3 . Setup ( arginfo [ 3 ] ) ;
arg4 . Setup ( arginfo [ 4 ] ) ;
2010-10-03 13:58:11 +00:00
2014-12-05 14:33:31 +00:00
if ( ! preventchanges )
{
2014-12-05 21:34:16 +00:00
// mxd. Apply action's or thing's default arguments
if ( showaction ! = 0 | | thinginfo ! = null )
{
arg0 . SetDefaultValue ( ) ;
arg1 . SetDefaultValue ( ) ;
arg2 . SetDefaultValue ( ) ;
arg3 . SetDefaultValue ( ) ;
arg4 . SetDefaultValue ( ) ;
}
else //or set them to 0
{
arg0 . SetValue ( 0 ) ;
arg1 . SetValue ( 0 ) ;
arg2 . SetValue ( 0 ) ;
arg3 . SetValue ( 0 ) ;
arg4 . SetValue ( 0 ) ;
}
//mxd. Update what must be updated
UpdateScriptControls ( ) ;
actionhelp . UpdateAction ( showaction ) ;
2014-12-05 14:33:31 +00:00
}
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 ) ;
}
// Angle text changes
2014-05-02 11:37:37 +00:00
private void angle_WhenTextChanged ( object sender , EventArgs e )
2009-04-19 18:07:22 +00:00
{
2014-05-02 11:37:37 +00:00
if ( preventchanges ) return ;
preventchanges = true ;
2014-10-17 11:55:08 +00:00
anglecontrol . Angle = angle . GetResult ( GZBuilder . Controls . AngleControl . NO_ANGLE ) ;
2014-05-02 11:37:37 +00:00
preventchanges = false ;
2014-12-03 23:15:26 +00:00
UpdateAngle ( ) ; //mxd
2009-04-19 18:07:22 +00:00
}
2013-12-04 13:27:34 +00:00
//mxd. Angle control clicked
2014-05-02 11:37:37 +00:00
private void anglecontrol_AngleChanged ( )
{
if ( preventchanges ) return ;
2013-12-04 13:27:34 +00:00
angle . Text = anglecontrol . Angle . ToString ( ) ;
2014-12-03 23:15:26 +00:00
UpdateAngle ( ) ;
2009-04-19 18:07:22 +00:00
}
// Apply clicked
private void apply_Click ( object sender , EventArgs e )
{
List < string > defaultflags = new List < string > ( ) ;
// Verify the tag
2013-03-18 13:52:27 +00:00
if ( General . Map . FormatInterface . HasThingTag ) //mxd
2009-04-19 18:07:22 +00:00
{
2013-03-18 13:52:27 +00:00
tagSelector . ValidateTag ( ) ; //mxd
2014-12-03 23:15:26 +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 ( "Thing 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 type
if ( ( ( thingtype . GetResult ( 0 ) < General . Map . FormatInterface . MinThingType ) | | ( thingtype . GetResult ( 0 ) > General . Map . FormatInterface . MaxThingType ) ) )
{
General . ShowWarningMessage ( "Thing type must be between " + General . Map . FormatInterface . MinThingType + " and " + General . Map . FormatInterface . MaxThingType + "." , MessageBoxButtons . OK ) ;
return ;
}
// Verify the action
if ( General . Map . FormatInterface . HasThingAction & & ( ( action . Value < General . Map . FormatInterface . MinAction ) | | ( action . Value > General . Map . FormatInterface . MaxAction ) ) )
{
General . ShowWarningMessage ( "Thing action must be between " + General . Map . FormatInterface . MinAction + " and " + General . Map . FormatInterface . MaxAction + "." , MessageBoxButtons . OK ) ;
return ;
}
2013-08-08 11:04:13 +00:00
bool hasAcs = ! action . Empty & & Array . IndexOf ( GZBuilder . GZGeneral . ACS_SPECIALS , action . Value ) ! = - 1 ; //mxd
2012-07-10 10:20:45 +00:00
2009-04-19 18:07:22 +00:00
// Go for all the things
2014-08-05 11:03:55 +00:00
int tagoffset = 0 ; //mxd
2009-04-19 18:07:22 +00:00
foreach ( Thing t in things )
{
// Coordination
2013-08-08 11:04:13 +00:00
if ( cbRandomAngle . Checked ) t . Rotate ( General . Random ( 0 , 359 ) ) ; //mxd
2013-07-19 15:30:58 +00:00
//mxd. Check position
float px = General . Clamp ( t . Position . x , General . Map . Config . LeftBoundary , General . Map . Config . RightBoundary ) ;
float py = General . Clamp ( t . Position . y , General . Map . Config . BottomBoundary , General . Map . Config . TopBoundary ) ;
2014-04-21 09:30:00 +00:00
if ( t . Position . x ! = px | | t . Position . y ! = py ) t . Move ( new Vector2D ( px , py ) ) ;
2009-04-19 18:07:22 +00:00
// Apply all flags
foreach ( CheckBox c in flags . Checkboxes )
{
2009-06-11 21:21:20 +00:00
if ( c . CheckState = = CheckState . Checked ) t . SetFlag ( c . Tag . ToString ( ) , true ) ;
else if ( c . CheckState = = CheckState . Unchecked ) t . SetFlag ( c . Tag . ToString ( ) , false ) ;
2009-04-19 18:07:22 +00:00
}
// Action/tags
2014-08-11 08:35:39 +00:00
t . Tag = General . Clamp ( tagSelector . GetSmartTag ( t . Tag , tagoffset + + ) , General . Map . FormatInterface . MinTag , General . Map . FormatInterface . MaxTag ) ; //mxd
2014-12-03 23:15:26 +00:00
if ( ! action . Empty )
{
2013-08-08 11:04:13 +00:00
t . Action = action . Value ;
2014-04-21 09:30:00 +00:00
//mxd. Script number handling
2014-12-03 23:15:26 +00:00
if ( hasAcs )
{
if ( ! string . IsNullOrEmpty ( scriptNumbers . Text ) )
{
2014-04-21 09:30:00 +00:00
if ( scriptNumbers . SelectedItem ! = null )
t . Args [ 0 ] = ( ( ScriptItem ) scriptNumbers . SelectedItem ) . Index ;
else if ( ! int . TryParse ( scriptNumbers . Text . Trim ( ) , out t . Args [ 0 ] ) )
t . Args [ 0 ] = 0 ;
2014-12-03 23:15:26 +00:00
if ( t . Fields . ContainsKey ( "arg0str" ) ) t . Fields . Remove ( "arg0str" ) ;
2013-08-08 11:04:13 +00:00
}
2014-12-03 23:15:26 +00:00
}
else
{
2013-08-08 11:04:13 +00:00
t . Args [ 0 ] = arg0 . GetResult ( t . Args [ 0 ] ) ;
if ( t . Fields . ContainsKey ( "arg0str" ) ) t . Fields . Remove ( "arg0str" ) ;
}
2014-12-03 23:15:26 +00:00
}
else
{
2013-08-08 11:04:13 +00:00
t . Args [ 0 ] = arg0 . GetResult ( t . Args [ 0 ] ) ;
}
2012-07-10 10:20:45 +00:00
2009-04-19 18:07:22 +00:00
t . Args [ 1 ] = arg1 . GetResult ( t . Args [ 1 ] ) ;
t . Args [ 2 ] = arg2 . GetResult ( t . Args [ 2 ] ) ;
t . Args [ 3 ] = arg3 . GetResult ( t . Args [ 3 ] ) ;
t . Args [ 4 ] = arg4 . GetResult ( t . Args [ 4 ] ) ;
// Update settings
t . UpdateConfiguration ( ) ;
}
// Set as defaults
foreach ( CheckBox c in flags . Checkboxes )
if ( c . CheckState = = CheckState . Checked ) defaultflags . Add ( c . Tag . ToString ( ) ) ;
General . Settings . DefaultThingType = thingtype . GetResult ( General . Settings . DefaultThingType ) ;
General . Settings . DefaultThingAngle = Angle2D . DegToRad ( ( float ) angle . GetResult ( ( int ) Angle2D . RadToDeg ( General . Settings . DefaultThingAngle ) - 90 ) + 90 ) ;
General . Settings . SetDefaultThingFlags ( defaultflags ) ;
// 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. perform undo
General . Map . UndoRedo . WithdrawUndo ( ) ;
2009-04-19 18:07:22 +00:00
// Be gone
this . DialogResult = DialogResult . Cancel ;
this . Close ( ) ;
}
2012-09-16 19:54:16 +00:00
//mxd
2014-05-02 11:37:37 +00:00
private void cbAbsoluteHeight_CheckedChanged ( object sender , EventArgs e )
{
2014-09-03 14:07:08 +00:00
if ( preventchanges ) return ;
2013-07-19 15:30:58 +00:00
useAbsoluteHeight = cbAbsoluteHeight . Checked ;
2014-09-03 14:07:08 +00:00
zlabel . Text = ( useAbsoluteHeight ? "Abs. Z:" : "Z:" ) ;
preventchanges = true ;
//update label text
Thing ft = General . GetByIndex ( things , 0 ) ;
float z = ft . Position . z ;
if ( useAbsoluteHeight & & ft . Sector ! = null ) z + = ft . Sector . FloorHeight ;
posZ . Text = z . ToString ( ) ;
2014-12-03 23:15:26 +00:00
foreach ( Thing t in things )
{
2014-09-03 14:07:08 +00:00
z = t . Position . z ;
if ( useAbsoluteHeight & & t . Sector ! = null ) z + = t . Sector . FloorHeight ;
2014-12-03 23:15:26 +00:00
if ( posZ . Text ! = z . ToString ( ) )
{
2014-09-03 14:07:08 +00:00
posZ . Text = "" ;
break ;
}
}
preventchanges = false ;
2012-09-16 19:54:16 +00:00
}
2013-03-18 13:52:27 +00:00
//mxd
2014-05-02 11:37:37 +00:00
private void cbRandomAngle_CheckedChanged ( object sender , EventArgs e )
{
2013-03-18 13:52:27 +00:00
angle . Enabled = ! cbRandomAngle . Checked ;
anglecontrol . Enabled = ! cbRandomAngle . Checked ;
}
2013-11-21 10:53:11 +00:00
//mxd
2014-05-02 11:37:37 +00:00
private void ThingEditForm_FormClosing ( object sender , FormClosingEventArgs e )
{
2013-11-21 10:53:11 +00:00
location = this . Location ;
activeTab = tabs . SelectedIndex ;
}
2009-04-19 18:07:22 +00:00
// Help
private void ThingEditForm_HelpRequested ( object sender , HelpEventArgs hlpevent )
{
General . ShowHelp ( "w_thingeditor.html" ) ;
hlpevent . Handled = true ;
}
2013-03-18 13:52:27 +00:00
2009-04-19 18:07:22 +00:00
#endregion
2013-07-19 15:30:58 +00:00
#region = = = = = = = = = = = = = = = = = = mxd . Realtime events
2014-05-02 11:37:37 +00:00
private void posX_WhenTextChanged ( object sender , EventArgs e )
{
2013-07-19 15:30:58 +00:00
if ( preventchanges ) return ;
int i = 0 ;
2014-09-03 14:07:08 +00:00
// Update values
foreach ( Thing t in things )
t . Move ( new Vector2D ( posX . GetResultFloat ( thingProps [ i + + ] . X ) , t . Position . y ) ) ;
2013-07-19 15:30:58 +00:00
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
2014-05-02 11:37:37 +00:00
private void posY_WhenTextChanged ( object sender , EventArgs e )
{
2013-07-19 15:30:58 +00:00
if ( preventchanges ) return ;
int i = 0 ;
2014-09-03 14:07:08 +00:00
// Update values
foreach ( Thing t in things )
t . Move ( new Vector2D ( t . Position . x , posY . GetResultFloat ( thingProps [ i + + ] . Y ) ) ) ;
2013-07-19 15:30:58 +00:00
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
2014-05-02 11:37:37 +00:00
private void posZ_WhenTextChanged ( object sender , EventArgs e )
{
2013-07-19 15:30:58 +00:00
if ( preventchanges ) return ;
2014-09-03 14:07:08 +00:00
int i = 0 ;
2013-07-19 15:30:58 +00:00
2014-12-03 23:15:26 +00:00
if ( string . IsNullOrEmpty ( posZ . Text ) )
{
2014-09-03 14:07:08 +00:00
// Restore values
2013-07-19 15:30:58 +00:00
foreach ( Thing t in things )
t . Move ( new Vector3D ( t . Position . x , t . Position . y , thingProps [ i + + ] . Z ) ) ;
2014-12-03 23:15:26 +00:00
}
else
{
2014-09-03 14:07:08 +00:00
// Update values
2014-12-03 23:15:26 +00:00
foreach ( Thing t in things )
{
2014-09-03 14:07:08 +00:00
float z = posZ . GetResultFloat ( thingProps [ i + + ] . Z ) ;
if ( useAbsoluteHeight & & ! posZ . CheckIsRelative ( ) & & t . Sector ! = null )
z - = t . Sector . FloorHeight ;
2013-07-19 15:30:58 +00:00
t . Move ( new Vector3D ( t . Position . x , t . Position . y , z ) ) ;
}
}
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
// Selected type changes
2014-05-02 11:37:37 +00:00
private void thingtype_OnTypeChanged ( ThingTypeInfo value )
{
2013-07-19 15:30:58 +00:00
thinginfo = value ;
// Update arguments
action_ValueChanges ( this , EventArgs . Empty ) ;
//mxd. Update things
if ( preventchanges ) return ;
if ( ( ( thingtype . GetResult ( 0 ) < General . Map . FormatInterface . MinThingType ) | | ( thingtype . GetResult ( 0 ) > General . Map . FormatInterface . MaxThingType ) ) )
return ;
2014-12-03 23:15:26 +00:00
foreach ( Thing t in things )
{
2013-07-19 15:30:58 +00:00
//Set type
t . Type = thingtype . GetResult ( t . Type ) ;
// Update settings
t . UpdateConfiguration ( ) ;
}
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
//mxd
2014-12-03 23:15:26 +00:00
private void UpdateAngle ( )
2014-05-02 11:37:37 +00:00
{
2013-07-19 15:30:58 +00:00
if ( preventchanges ) return ;
2013-08-22 15:30:50 +00:00
int i = 0 ;
2013-07-19 15:30:58 +00:00
//restore values
2014-12-03 23:15:26 +00:00
if ( string . IsNullOrEmpty ( angle . Text ) )
{
2013-07-19 15:30:58 +00:00
// Apply rotation
foreach ( Thing t in things )
t . Rotate ( thingProps [ i + + ] . AngleDoom ) ;
2014-12-03 23:15:26 +00:00
}
else
{ //update values
2013-07-19 15:30:58 +00:00
// Apply rotation
foreach ( Thing t in things )
2013-08-22 15:30:50 +00:00
t . Rotate ( angle . GetResult ( thingProps [ i + + ] . AngleDoom ) ) ;
2013-07-19 15:30:58 +00:00
}
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
2014-09-29 20:49:41 +00:00
//mxd
private void flags_OnValueChanged ( object sender , EventArgs e )
{
if ( preventchanges ) return ;
2014-11-03 13:02:59 +00:00
string warn = ThingFlagsCompare . CheckThingEditFormFlags ( flags . Checkboxes ) ;
if ( ! string . IsNullOrEmpty ( warn ) )
2014-09-29 20:49:41 +00:00
{
2014-11-03 13:02:59 +00:00
//got missing flags
tooltip . SetToolTip ( missingflags , warn ) ;
missingflags . Visible = true ;
settingsgroup . ForeColor = Color . DarkRed ;
return ;
2014-09-29 20:49:41 +00:00
}
2014-11-03 13:02:59 +00:00
//everything is OK
2014-09-29 20:49:41 +00:00
missingflags . Visible = false ;
settingsgroup . ForeColor = SystemColors . ControlText ;
}
2013-07-19 15:30:58 +00:00
#endregion
2013-11-21 10:53:11 +00:00
2009-04-19 18:07:22 +00:00
}
}