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.Windows.Forms ;
using CodeImp.DoomBuilder.Geometry ;
using CodeImp.DoomBuilder.Map ;
2012-11-27 23:04:49 +00:00
using CodeImp.DoomBuilder.GZBuilder.Tools ;
2009-04-19 18:07:22 +00:00
#endregion
namespace CodeImp.DoomBuilder.Windows
{
public partial class VertexEditForm : DelayedForm
{
#region = = = = = = = = = = = = = = = = = = Constants
#endregion
#region = = = = = = = = = = = = = = = = = = Variables
private ICollection < Vertex > vertices ;
#endregion
#region = = = = = = = = = = = = = = = = = = Properties
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor
// Constructor
public VertexEditForm ( )
{
InitializeComponent ( ) ;
// Fill universal fields list
fieldslist . ListFixedFields ( General . Map . Config . VertexFields ) ;
// Custom fields?
if ( ! General . Map . FormatInterface . HasCustomFields )
tabs . TabPages . Remove ( tabcustom ) ;
// Decimals allowed?
if ( General . Map . FormatInterface . VertexDecimals > 0 )
{
positionx . AllowDecimal = true ;
positiony . AllowDecimal = true ;
2012-11-27 23:04:49 +00:00
//mxd
zceiling . AllowDecimal = true ;
zfloor . AllowDecimal = true ;
2009-04-19 18:07:22 +00:00
}
2012-11-27 23:04:49 +00:00
if ( ! General . Map . UDMF ) panelHeightControls . Visible = false ;
2009-04-19 18:07:22 +00:00
// Initialize custom fields editor
fieldslist . Setup ( "vertex" ) ;
}
#endregion
#region = = = = = = = = = = = = = = = = = = Methods
// This sets up the form to edit the given vertices
2013-03-18 13:52:27 +00:00
public void Setup ( ICollection < Vertex > vertices , bool allowPositionChange )
2009-04-19 18:07:22 +00:00
{
// Keep this list
this . vertices = vertices ;
if ( vertices . Count > 1 ) this . Text = "Edit Vertices (" + vertices . Count + ")" ;
////////////////////////////////////////////////////////////////////////
// Set all options to the first vertex properties
////////////////////////////////////////////////////////////////////////
// Get first vertex
Vertex vc = General . GetByIndex ( vertices , 0 ) ;
// Position
positionx . Text = vc . Position . x . ToString ( ) ;
positiony . Text = vc . Position . y . ToString ( ) ;
2013-03-18 13:52:27 +00:00
//mxd
positionx . Enabled = allowPositionChange ;
positiony . Enabled = allowPositionChange ;
2009-04-19 18:07:22 +00:00
// Custom fields
fieldslist . SetValues ( vc . Fields , true ) ;
////////////////////////////////////////////////////////////////////////
// Now go for all sectors and change the options when a setting is different
////////////////////////////////////////////////////////////////////////
// Go for all vertices
foreach ( Vertex v in vertices )
{
// Position
if ( positionx . Text ! = v . Position . x . ToString ( ) ) positionx . Text = "" ;
if ( positiony . Text ! = v . Position . y . ToString ( ) ) positiony . Text = "" ;
// Custom fields
fieldslist . SetValues ( v . Fields , false ) ;
}
2012-11-27 23:04:49 +00:00
//mxd. Height offsets
if ( General . Map . UDMF ) {
2013-03-18 13:52:27 +00:00
zceiling . Text = vc . Fields . GetValue ( "zceiling" , 0f ) . ToString ( ) ;
zfloor . Text = vc . Fields . GetValue ( "zfloor" , 0f ) . ToString ( ) ;
2012-11-27 23:04:49 +00:00
foreach ( Vertex v in vertices ) {
2013-03-18 13:52:27 +00:00
if ( zceiling . Text ! = v . Fields . GetValue ( "zceiling" , 0f ) . ToString ( ) )
2012-11-27 23:04:49 +00:00
zceiling . Text = "" ;
2013-03-18 13:52:27 +00:00
if ( zfloor . Text ! = v . Fields . GetValue ( "zfloor" , 0f ) . ToString ( ) )
2012-11-27 23:04:49 +00:00
zfloor . Text = "" ;
}
}
2009-04-19 18:07:22 +00:00
}
#endregion
#region = = = = = = = = = = = = = = = = = = Events
// OK clicked
private void apply_Click ( object sender , EventArgs e )
{
string undodesc = "vertex" ;
// Verify the coordinates
if ( ( positionx . GetResultFloat ( 0.0f ) < General . Map . FormatInterface . MinCoordinate ) | | ( positionx . GetResultFloat ( 0.0f ) > General . Map . FormatInterface . MaxCoordinate ) | |
( positiony . GetResultFloat ( 0.0f ) < General . Map . FormatInterface . MinCoordinate ) | | ( positiony . GetResultFloat ( 0.0f ) > General . Map . FormatInterface . MaxCoordinate ) )
{
General . ShowWarningMessage ( "Vertex coordinates must be between " + General . Map . FormatInterface . MinCoordinate + " and " + General . Map . FormatInterface . MaxCoordinate + "." , MessageBoxButtons . OK ) ;
return ;
}
// Make undo
if ( vertices . Count > 1 ) undodesc = vertices . Count + " vertices" ;
General . Map . UndoRedo . CreateUndo ( "Edit " + undodesc ) ;
// Go for all vertices
foreach ( Vertex v in vertices )
{
// Apply position
Vector2D p = new Vector2D ( ) ;
p . x = General . Clamp ( positionx . GetResultFloat ( v . Position . x ) , ( float ) General . Map . FormatInterface . MinCoordinate , ( float ) General . Map . FormatInterface . MaxCoordinate ) ;
p . y = General . Clamp ( positiony . GetResultFloat ( v . Position . y ) , ( float ) General . Map . FormatInterface . MinCoordinate , ( float ) General . Map . FormatInterface . MaxCoordinate ) ;
v . Move ( p ) ;
2012-11-27 23:04:49 +00:00
2009-04-19 18:07:22 +00:00
// Custom fields
fieldslist . Apply ( v . Fields ) ;
}
2012-11-27 23:04:49 +00:00
//mxd. Height offsets
if ( General . Map . UDMF ) {
foreach ( Vertex v in vertices ) {
2013-03-18 13:52:27 +00:00
if ( string . IsNullOrEmpty ( zceiling . Text ) ) {
if ( v . Fields . ContainsKey ( "zceiling" ) )
v . Fields . Remove ( "zceiling" ) ;
} else {
float oldCeil = v . Fields . GetValue ( "zceiling" , 0f ) ;
UDMFTools . SetFloat ( v . Fields , "zceiling" , zceiling . GetResultFloat ( oldCeil ) , 0 , false ) ;
}
if ( string . IsNullOrEmpty ( zfloor . Text ) ) {
if ( v . Fields . ContainsKey ( "zfloor" ) )
v . Fields . Remove ( "zfloor" ) ;
} else {
float oldFloor = v . Fields . GetValue ( "zfloor" , 0f ) ;
UDMFTools . SetFloat ( v . Fields , "zfloor" , zfloor . GetResultFloat ( oldFloor ) , 0 , false ) ;
}
2012-11-27 23:04:49 +00:00
}
}
2009-04-19 18:07:22 +00:00
// Done
General . Map . IsChanged = true ;
this . DialogResult = DialogResult . OK ;
this . Close ( ) ;
}
// Cancel clicked
private void cancel_Click ( object sender , EventArgs e )
{
// Just close
this . DialogResult = DialogResult . Cancel ;
this . Close ( ) ;
}
// Help requested
private void VertexEditForm_HelpRequested ( object sender , HelpEventArgs hlpevent )
{
General . ShowHelp ( "w_vertexeditor.html" ) ;
hlpevent . Handled = true ;
}
#endregion
}
}