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 ;
2016-04-27 09:13:07 +00:00
using CodeImp.DoomBuilder.Controls ;
2009-04-19 18:07:22 +00:00
using CodeImp.DoomBuilder.Geometry ;
2015-07-27 09:02:28 +00:00
using CodeImp.DoomBuilder.Map ;
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 ;
2015-01-26 08:53:05 +00:00
private bool preventmapchange ; //mxd
private bool undocreated ; //mxd
2015-04-15 12:49:28 +00:00
private static bool useabsoluteheight ; //mxd
2015-01-26 08:53:05 +00:00
private List < ThingProperties > thingprops ; //mxd
2016-07-15 14:07:30 +00:00
private Dictionary < string , string > flagsrename ; //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 ;
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 ;
}
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?
2015-02-27 10:55:18 +00:00
actiongroup . Visible = General . Map . FormatInterface . HasThingAction ;
idgroup . Visible = General . Map . FormatInterface . HasThingTag ;
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 ;
}
2015-02-27 10:55:18 +00:00
2016-06-15 22:02:51 +00:00
//mxd. Use doom angle clamping?
anglecontrol . DoomAngleClamping = General . Map . Config . DoomThingRotationAngles ;
2015-02-27 10:55:18 +00:00
//mxd. Arrange inteface
int targetheight ;
if ( General . Map . FormatInterface . HasThingAction )
targetheight = actiongroup . Bottom + actiongroup . Margin . Bottom ;
else
targetheight = typegroup . Bottom + typegroup . Margin . Bottom * 2 ;
if ( General . Map . FormatInterface . HasThingTag )
{
idgroup . Top = targetheight ;
targetheight = idgroup . Bottom + idgroup . Margin . Bottom * 2 ;
}
panel . Height = targetheight ;
//mxd. Arrange Apply/Cancel buttons
applypanel . Top = panel . Bottom + panel . Margin . Bottom * 2 ;
//mxd. Update window height
this . Height = applypanel . Bottom + applypanel . Margin . Bottom + ( this . Height - this . ClientRectangle . Height ) + 1 ;
2009-04-19 18:07:22 +00:00
// Setup types list
thingtype . Setup ( ) ;
}
2015-05-23 21:01:44 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Methods
2009-04-19 18:07:22 +00:00
// 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 ;
2015-12-28 15:01:53 +00:00
if ( things . Count > 1 ) this . Text = "Edit Things (" + things . Count + ")" ;
2013-12-23 12:02:58 +00:00
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
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 ( ) ;
2015-04-15 12:49:28 +00:00
zlabel . Text = useabsoluteheight ? "Z:" : "Height:" ; //mxd
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 ( ) ;
2015-04-15 12:49:28 +00:00
float floorheight = ( ft . Sector ! = null ? Sector . GetFloorPlane ( ft . Sector ) . GetZ ( ft . Position ) : 0 ) ;
2013-09-11 09:47:53 +00:00
posX . Text = ( ( int ) ft . Position . x ) . ToString ( ) ;
posY . Text = ( ( int ) ft . Position . y ) . ToString ( ) ;
2015-04-15 12:49:28 +00:00
posZ . Text = ( useabsoluteheight ? ( ( int ) Math . Round ( 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
2016-07-15 14:07:30 +00:00
//mxd
thinginfo = General . Map . Data . GetThingInfoEx ( ft . Type ) ;
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 ) ;
}
2015-07-27 09:02:28 +00:00
//mxd. Args
argscontrol . SetValue ( ft , true ) ;
2009-04-19 18:07:22 +00:00
////////////////////////////////////////////////////////////////////////
// Now go for all lines and change the options when a setting is different
////////////////////////////////////////////////////////////////////////
2013-07-19 15:30:58 +00:00
2015-01-26 08:53:05 +00:00
thingprops = new List < ThingProperties > ( ) ;
2013-07-19 15:30:58 +00:00
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 )
2016-07-15 14:07:30 +00:00
{
2009-04-19 18:07:22 +00:00
thingtype . ClearSelectedType ( ) ;
2016-07-15 14:07:30 +00:00
thinginfo = null ; //mxd
}
2009-04-19 18:07:22 +00:00
// 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 = "" ;
2015-12-28 15:01:53 +00:00
if ( useabsoluteheight & & t . Sector ! = null )
2014-12-03 23:15:26 +00:00
{
2015-04-15 12:49:28 +00:00
if ( ( ( int ) Math . Round ( Sector . GetFloorPlane ( t . Sector ) . GetZ ( t . Position ) + t . Position . z ) ) . 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
2015-07-27 09:02:28 +00:00
//mxd. Arguments
argscontrol . SetValue ( t , false ) ;
2009-04-19 18:07:22 +00:00
2013-07-19 15:30:58 +00:00
//mxd. Store initial properties
2015-01-26 08:53:05 +00:00
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...
2015-01-26 08:53:05 +00:00
preventmapchange = true ;
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 ) ;
2015-01-26 08:53:05 +00:00
preventmapchange = false ;
2014-05-02 11:37:37 +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
2016-07-15 14:07:30 +00:00
UpdateFlagNames ( ) ; //mxd
2013-08-08 11:04:13 +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 " + ( things . Count > 1 ? things . Count + " things" : "thing" ) ) ;
}
2016-07-15 14:07:30 +00:00
//mxd
private void UpdateFlagNames ( )
{
Dictionary < string , string > newflagsrename = ( thinginfo ! = null ? thinginfo . FlagsRename : null ) ;
// Update flag names?
if ( flagsrename ! = null | | newflagsrename ! = null )
{
flags . SuspendLayout ( ) ;
// Restore default flags?
if ( flagsrename ! = null )
{
foreach ( CheckBox cb in flags . Checkboxes )
{
string flag = cb . Tag . ToString ( ) ;
if ( flagsrename . ContainsKey ( flag ) )
{
cb . Text = General . Map . Config . ThingFlags [ flag ] ;
cb . ForeColor = SystemColors . WindowText ;
}
}
}
// Apply new renaming?
if ( newflagsrename ! = null )
{
foreach ( CheckBox cb in flags . Checkboxes )
{
string flag = cb . Tag . ToString ( ) ;
if ( newflagsrename . ContainsKey ( flag ) )
{
cb . Text = newflagsrename [ flag ] ;
cb . ForeColor = SystemColors . HotTrack ;
}
}
}
flags . ResumeLayout ( ) ;
}
// Store current flag names
flagsrename = newflagsrename ;
}
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 ;
// Only when line type is known, otherwise use the thing arguments
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 , ( action . Empty ? null : thinginfo ) ) ;
2010-10-03 13:58:11 +00:00
2014-12-05 14:33:31 +00:00
if ( ! preventchanges )
{
2015-01-26 08:53:05 +00:00
MakeUndo ( ) ;
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 ) ;
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 ;
2016-04-27 09:13:07 +00:00
anglecontrol . Angle = angle . GetResult ( AngleControlEx . NO_ANGLE ) ;
2014-05-02 11:37:37 +00:00
preventchanges = false ;
2015-01-26 08:53:05 +00:00
if ( ! preventmapchange ) ApplyAngleChange ( ) ; //mxd
2009-04-19 18:07:22 +00:00
}
2013-12-04 13:27:34 +00:00
//mxd. Angle control clicked
2014-12-24 18:32:24 +00:00
private void anglecontrol_AngleChanged ( object sender , EventArgs e )
2014-05-02 11:37:37 +00:00
{
if ( preventchanges ) return ;
2013-12-04 13:27:34 +00:00
angle . Text = anglecontrol . Angle . ToString ( ) ;
2015-01-26 08:53:05 +00:00
if ( ! preventmapchange ) ApplyAngleChange ( ) ;
2009-04-19 18:07:22 +00:00
}
// Apply clicked
private void apply_Click ( object sender , EventArgs e )
{
2015-01-26 08:53:05 +00:00
MakeUndo ( ) ;
2009-04-19 18:07:22 +00:00
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
2016-02-29 08:10:11 +00:00
if ( ! string . IsNullOrEmpty ( thingtype . TypeStringValue ) & & ( ( thingtype . GetResult ( 0 ) < General . Map . FormatInterface . MinThingType ) | | ( thingtype . GetResult ( 0 ) > General . Map . FormatInterface . MaxThingType ) ) )
2009-04-19 18:07:22 +00:00
{
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 ;
}
// Go for all the things
2016-08-29 10:06:16 +00:00
int offset = 0 ; //mxd
2009-04-19 18:07:22 +00:00
foreach ( Thing t in things )
{
// Coordination
2016-06-15 22:02:51 +00:00
if ( cbRandomAngle . Checked ) //mxd
{
int newangle = General . Random ( 0 , 359 ) ;
if ( General . Map . Config . DoomThingRotationAngles ) newangle = newangle / 45 * 45 ;
t . Rotate ( newangle ) ;
}
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 )
{
2015-12-28 15:01:53 +00:00
switch ( c . CheckState )
2015-07-15 09:09:47 +00:00
{
case CheckState . Checked : t . SetFlag ( c . Tag . ToString ( ) , true ) ; break ;
case CheckState . Unchecked : t . SetFlag ( c . Tag . ToString ( ) , false ) ; break ;
}
2009-04-19 18:07:22 +00:00
}
// Action/tags
2016-08-29 10:06:16 +00:00
t . Tag = General . Clamp ( tagSelector . GetSmartTag ( t . Tag , offset ) , General . Map . FormatInterface . MinTag , General . Map . FormatInterface . MaxTag ) ; //mxd
2015-12-28 15:01:53 +00:00
if ( ! action . Empty ) t . Action = action . Value ;
2012-07-10 10:20:45 +00:00
2015-07-27 09:02:28 +00:00
//mxd. Apply args
2016-08-29 10:06:16 +00:00
argscontrol . Apply ( t , offset ) ;
2009-04-19 18:07:22 +00:00
// Update settings
t . UpdateConfiguration ( ) ;
2016-08-29 10:06:16 +00:00
//mxd. Increase offset...
offset + + ;
2009-04-19 18:07:22 +00:00
}
// 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 )
{
2015-01-26 08:53:05 +00:00
//mxd. Perform undo?
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 ( ) ;
}
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 ;
2015-04-15 12:49:28 +00:00
MakeUndo ( ) ;
2015-01-26 08:53:05 +00:00
2015-04-15 12:49:28 +00:00
useabsoluteheight = cbAbsoluteHeight . Checked ;
zlabel . Text = ( useabsoluteheight ? "Z:" : "Height:" ) ;
2014-09-03 14:07:08 +00:00
preventchanges = true ;
//update label text
Thing ft = General . GetByIndex ( things , 0 ) ;
float z = ft . Position . z ;
2015-04-15 12:49:28 +00:00
if ( useabsoluteheight & & ft . Sector ! = null ) z + = Sector . GetFloorPlane ( ft . Sector ) . GetZ ( ft . Position ) ;
posZ . Text = ( ( float ) Math . Round ( z , General . Map . FormatInterface . VertexDecimals ) ) . ToString ( ) ;
2014-09-03 14:07:08 +00:00
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 ;
2015-04-15 12:49:28 +00:00
if ( useabsoluteheight & & t . Sector ! = null ) z + = Sector . GetFloorPlane ( t . Sector ) . GetZ ( t . Position ) ;
string ztext = ( ( float ) Math . Round ( z , General . Map . FormatInterface . VertexDecimals ) ) . ToString ( ) ;
if ( posZ . Text ! = ztext )
2014-12-03 23:15:26 +00:00
{
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 ;
}
Fixed, Visual mode, Auto-align actions: incorrect texture was used when clamping texture offsets of 3D floor sides.
Fixed, Numeric textbox: incorrect character was treated as decimal separator character was used when using certain Windows regional settings.
Changed, Edit Things window: when applicable, the "Filter" textbox is now focused when opening the window.
Changed, Sector Effects browser window: when applicable, the "Filter" textbox is now focused when opening the window.
Changed, Edit Things window: when the "Filter" textbox is focused, pressing the "Down" key will now switch focus to the Things list.
Changed, Sector Effects Browser window: when the "Filter" textbox is focused, pressing the "Down" key will now switch focus to the Effects list.
Changed, Linedef Action Browser window: when the "Filter" textbox is focused, pressing the "Down" key will now switch focus to the Actions list.
Configurations, Doom map format thing flags: changed "Multiplayer" flag name to "Multiplayer only".
2015-09-23 11:04:12 +00:00
//mxd
private void ThingEditForm_Shown ( object sender , EventArgs e )
{
thingtype . FocusTextbox ( ) ;
}
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 ;
}
2009-04-19 18:07:22 +00:00
// Help
private void ThingEditForm_HelpRequested ( object sender , HelpEventArgs hlpevent )
{
2015-06-01 21:46:28 +00:00
General . ShowHelp ( "w_thingedit.html" ) ;
2009-04-19 18:07:22 +00:00
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 ;
2015-01-26 08:53:05 +00:00
MakeUndo ( ) ; //mxd
2013-07-19 15:30:58 +00:00
int i = 0 ;
2014-09-03 14:07:08 +00:00
// Update values
foreach ( Thing t in things )
2015-01-26 08:53:05 +00:00
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 ;
2015-01-26 08:53:05 +00:00
MakeUndo ( ) ; //mxd
2013-07-19 15:30:58 +00:00
int i = 0 ;
2014-09-03 14:07:08 +00:00
// Update values
foreach ( Thing t in things )
2015-01-26 08:53:05 +00:00
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 ;
2015-01-26 08:53:05 +00:00
MakeUndo ( ) ; //mxd
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 )
2015-01-26 08:53:05 +00:00
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 )
{
2015-01-26 08:53:05 +00:00
float z = posZ . GetResultFloat ( thingprops [ i + + ] . Z ) ;
2015-04-15 12:49:28 +00:00
if ( useabsoluteheight & & ! posZ . CheckIsRelative ( ) & & t . Sector ! = null )
z - = ( float ) Math . Round ( Sector . GetFloorPlane ( t . Sector ) . GetZ ( t . Position . x , t . Position . y ) , General . Map . FormatInterface . VertexDecimals ) ;
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
2016-02-29 08:10:11 +00:00
if ( preventchanges | |
( ! string . IsNullOrEmpty ( thingtype . TypeStringValue ) & &
thingtype . GetResult ( 0 ) < General . Map . FormatInterface . MinThingType
| | thingtype . GetResult ( 0 ) > General . Map . FormatInterface . MaxThingType ) )
2013-07-19 15:30:58 +00:00
return ;
2016-02-29 08:10:11 +00:00
MakeUndo ( ) ; //mxd
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 ( ) ;
}
2016-07-15 14:07:30 +00:00
UpdateFlagNames ( ) ; //mxd
2013-07-19 15:30:58 +00:00
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
//mxd
2015-01-26 08:53:05 +00:00
private void ApplyAngleChange ( )
2014-05-02 11:37:37 +00:00
{
2013-07-19 15:30:58 +00:00
if ( preventchanges ) return ;
2015-01-26 08:53:05 +00:00
MakeUndo ( ) ; //mxd
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 )
2015-01-26 08:53:05 +00:00
t . Rotate ( thingprops [ i + + ] . AngleDoom ) ;
}
else //update values
{
2013-07-19 15:30:58 +00:00
// Apply rotation
foreach ( Thing t in things )
2015-01-26 08:53:05 +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 ;
2015-12-28 15:01:53 +00:00
// Gather enabled flags
HashSet < string > activeflags = new HashSet < string > ( ) ;
foreach ( CheckBox cb in flags . Checkboxes )
{
if ( cb . CheckState ! = CheckState . Unchecked ) activeflags . Add ( cb . Tag . ToString ( ) ) ;
}
// Check em
List < string > warnings = ThingFlagsCompare . CheckFlags ( activeflags ) ;
if ( warnings . Count > 0 )
2014-09-29 20:49:41 +00:00
{
2014-11-03 13:02:59 +00:00
//got missing flags
2015-12-28 15:01:53 +00:00
tooltip . SetToolTip ( missingflags , string . Join ( Environment . NewLine , warnings . ToArray ( ) ) ) ;
2014-11-03 13:02:59 +00:00
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
}
}