2008-01-05 18:11:29 +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.ComponentModel ;
using System.Drawing ;
using System.Text ;
using System.Windows.Forms ;
using CodeImp.DoomBuilder.Map ;
using CodeImp.DoomBuilder.Data ;
using CodeImp.DoomBuilder.IO ;
using System.IO ;
using CodeImp.DoomBuilder.Config ;
using CodeImp.DoomBuilder.Editing ;
2008-05-29 11:54:45 +00:00
using CodeImp.DoomBuilder.Controls ;
2008-01-05 18:11:29 +00:00
#endregion
2008-05-29 11:54:45 +00:00
namespace CodeImp.DoomBuilder.Windows
2008-01-05 18:11:29 +00:00
{
2008-02-21 06:47:43 +00:00
internal partial class SectorEditForm : DelayedForm
2008-01-05 18:11:29 +00:00
{
2008-02-21 06:47:43 +00:00
// Variables
private ICollection < Sector > sectors ;
2008-01-05 18:11:29 +00:00
// Constructor
public SectorEditForm ( )
{
// Initialize
InitializeComponent ( ) ;
2008-02-22 17:11:29 +00:00
// Fill effects list
effect . AddInfo ( General . Map . Config . SortedSectorEffects . ToArray ( ) ) ;
// Fill universal fields list
fieldslist . ListFixedFields ( General . Map . Config . SectorFields ) ;
// Initialize image selectors
floortex . Initialize ( ) ;
ceilingtex . Initialize ( ) ;
2008-05-30 22:14:12 +00:00
2009-04-08 19:11:40 +00:00
// Custom fields?
if ( ! General . Map . FormatInterface . HasCustomFields )
2008-06-03 19:02:06 +00:00
tabs . TabPages . Remove ( tabcustom ) ;
2008-05-30 22:14:12 +00:00
// Initialize custom fields editor
2008-06-02 04:55:51 +00:00
fieldslist . Setup ( "sector" ) ;
2008-01-05 18:11:29 +00:00
}
2008-02-21 06:47:43 +00:00
// This sets up the form to edit the given sectors
public void Setup ( ICollection < Sector > sectors )
{
2008-02-22 17:11:29 +00:00
Sector sc ;
2008-02-21 06:47:43 +00:00
// Keep this list
this . sectors = sectors ;
if ( sectors . Count > 1 ) this . Text = "Edit Sectors (" + sectors . Count + ")" ;
2008-02-22 17:11:29 +00:00
////////////////////////////////////////////////////////////////////////
// Set all options to the first sector properties
////////////////////////////////////////////////////////////////////////
// Get first sector
2009-01-04 09:54:15 +00:00
sc = General . GetByIndex ( sectors , 0 ) ;
2008-02-22 17:11:29 +00:00
// Effects
effect . Value = sc . Effect ;
brightness . Text = sc . Brightness . ToString ( ) ;
// Floor/ceiling
floorheight . Text = sc . FloorHeight . ToString ( ) ;
ceilingheight . Text = sc . CeilHeight . ToString ( ) ;
floortex . TextureName = sc . FloorTexture ;
ceilingtex . TextureName = sc . CeilTexture ;
// Action
tag . Text = sc . Tag . ToString ( ) ;
2008-06-01 20:25:46 +00:00
// Custom fields
fieldslist . SetValues ( sc . Fields , true ) ;
2008-02-21 06:47:43 +00:00
2008-02-22 17:11:29 +00:00
////////////////////////////////////////////////////////////////////////
// Now go for all sectors and change the options when a setting is different
////////////////////////////////////////////////////////////////////////
// Go for all sectors
foreach ( Sector s in sectors )
{
// Effects
if ( s . Effect ! = effect . Value ) effect . Empty = true ;
if ( s . Brightness . ToString ( ) ! = brightness . Text ) brightness . Text = "" ;
// Floor/Ceiling
if ( s . FloorHeight . ToString ( ) ! = floorheight . Text ) floorheight . Text = "" ;
if ( s . CeilHeight . ToString ( ) ! = ceilingheight . Text ) ceilingheight . Text = "" ;
if ( s . FloorTexture ! = floortex . TextureName ) floortex . TextureName = "" ;
if ( s . CeilTexture ! = ceilingtex . TextureName ) ceilingtex . TextureName = "" ;
// Action
if ( s . Tag . ToString ( ) ! = tag . Text ) tag . Text = "" ;
2008-06-01 20:25:46 +00:00
// Custom fields
fieldslist . SetValues ( s . Fields , false ) ;
2008-02-22 17:11:29 +00:00
}
2009-01-12 20:25:08 +00:00
// Show sector height
UpdateSectorHeight ( ) ;
}
// This updates the sector height field
private void UpdateSectorHeight ( )
{
bool showheight = true ;
int delta = 0 ;
Sector first = null ;
// Check all selected sectors
foreach ( Sector s in sectors )
{
if ( first = = null )
{
// First sector in list
delta = s . CeilHeight - s . FloorHeight ;
showheight = true ;
first = s ;
}
else
{
if ( delta ! = ( s . CeilHeight - s . FloorHeight ) )
{
// We can't show heights because the delta
// heights for the sectors is different
showheight = false ;
break ;
}
}
}
if ( showheight )
{
int fh = floorheight . GetResult ( first . FloorHeight ) ;
int ch = ceilingheight . GetResult ( first . CeilHeight ) ;
int height = ch - fh ;
sectorheight . Text = height . ToString ( ) ;
sectorheight . Visible = true ;
sectorheightlabel . Visible = true ;
}
else
{
sectorheight . Visible = false ;
sectorheightlabel . Visible = false ;
}
2008-02-22 17:11:29 +00:00
}
// OK clicked
private void apply_Click ( object sender , EventArgs e )
{
string undodesc = "sector" ;
2009-04-08 19:11:40 +00:00
// Verify the tag
2009-04-09 11:46:51 +00:00
if ( ( tag . GetResult ( 0 ) < General . Map . FormatInterface . MinTag ) | | ( tag . GetResult ( 0 ) > General . Map . FormatInterface . MaxTag ) )
2009-04-08 19:11:40 +00:00
{
2009-04-09 11:46:51 +00:00
General . ShowWarningMessage ( "Sector tag must be between " + General . Map . FormatInterface . MinTag + " and " + General . Map . FormatInterface . MaxTag + "." , MessageBoxButtons . OK ) ;
2009-04-08 19:11:40 +00:00
return ;
}
2008-02-22 17:11:29 +00:00
2009-04-08 19:11:40 +00:00
// Verify the effect
2009-04-09 11:46:51 +00:00
if ( ( effect . Value < General . Map . FormatInterface . MinEffect ) | | ( effect . Value > General . Map . FormatInterface . MaxEffect ) )
2009-04-08 19:11:40 +00:00
{
2009-04-09 11:46:51 +00:00
General . ShowWarningMessage ( "Sector effect must be between " + General . Map . FormatInterface . MinEffect + " and " + General . Map . FormatInterface . MaxEffect + "." , MessageBoxButtons . OK ) ;
2009-04-08 19:11:40 +00:00
return ;
}
// Verify the brightness
2009-04-09 11:46:51 +00:00
if ( ( brightness . GetResult ( 0 ) < General . Map . FormatInterface . MinBrightness ) | | ( brightness . GetResult ( 0 ) > General . Map . FormatInterface . MaxBrightness ) )
2009-04-08 19:11:40 +00:00
{
2009-04-09 11:46:51 +00:00
General . ShowWarningMessage ( "Sector brightness must be between " + General . Map . FormatInterface . MinBrightness + " and " + General . Map . FormatInterface . MaxBrightness + "." , MessageBoxButtons . OK ) ;
2009-04-08 19:11:40 +00:00
return ;
}
2008-02-22 17:11:29 +00:00
// Make undo
if ( sectors . Count > 1 ) undodesc = sectors . Count + " sectors" ;
2008-12-24 18:27:13 +00:00
General . Map . UndoRedo . CreateUndo ( "Edit " + undodesc ) ;
2008-02-22 17:11:29 +00:00
// Go for all sectors
foreach ( Sector s in sectors )
{
// Effects
if ( ! effect . Empty ) s . Effect = effect . Value ;
2009-04-09 11:46:51 +00:00
s . Brightness = General . Clamp ( brightness . GetResult ( s . Brightness ) , General . Map . FormatInterface . MinBrightness , General . Map . FormatInterface . MaxBrightness ) ;
2008-02-22 17:11:29 +00:00
// Floor/Ceiling
s . FloorHeight = floorheight . GetResult ( s . FloorHeight ) ;
s . CeilHeight = ceilingheight . GetResult ( s . CeilHeight ) ;
s . SetFloorTexture ( floortex . GetResult ( s . FloorTexture ) ) ;
s . SetCeilTexture ( ceilingtex . GetResult ( s . CeilTexture ) ) ;
// Action
2009-04-09 11:46:51 +00:00
s . Tag = General . Clamp ( tag . GetResult ( s . Tag ) , General . Map . FormatInterface . MinTag , General . Map . FormatInterface . MaxTag ) ;
2008-06-01 20:25:46 +00:00
// Custom fields
fieldslist . Apply ( s . Fields ) ;
2008-02-22 17:11:29 +00:00
}
2008-09-28 21:20:56 +00:00
// Update the used textures
General . Map . Data . UpdateUsedTextures ( ) ;
2008-02-22 17:11:29 +00:00
// Done
2008-05-18 11:56:45 +00:00
General . Map . IsChanged = true ;
2008-02-22 17:11:29 +00:00
this . DialogResult = DialogResult . OK ;
this . Close ( ) ;
2008-02-21 06:47:43 +00:00
}
// Cancel clicked
private void cancel_Click ( object sender , EventArgs e )
{
// Be gone
this . DialogResult = DialogResult . Cancel ;
this . Close ( ) ;
}
// This finds a new (unused) tag
private void newtag_Click ( object sender , EventArgs e )
{
tag . Text = General . Map . Map . GetNewTag ( ) . ToString ( ) ;
}
2008-02-22 17:11:29 +00:00
// Browse Effect clicked
private void browseeffect_Click ( object sender , EventArgs e )
{
effect . Value = EffectBrowserForm . BrowseEffect ( this , effect . Value ) ;
}
2009-01-12 20:25:08 +00:00
// Ceiling height changes
private void ceilingheight_TextChanged ( object sender , EventArgs e )
{
UpdateSectorHeight ( ) ;
}
// Floor height changes
private void floorheight_TextChanged ( object sender , EventArgs e )
{
UpdateSectorHeight ( ) ;
}
2009-04-05 19:29:27 +00:00
// Help
private void SectorEditForm_HelpRequested ( object sender , HelpEventArgs hlpevent )
{
General . ShowHelp ( "w_sectoredit.html" ) ;
hlpevent . Handled = true ;
}
2008-01-05 18:11:29 +00:00
}
}