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.Map ;
2012-11-05 12:31:24 +00:00
using CodeImp.DoomBuilder.Types ;
2009-04-19 18:07:22 +00:00
#endregion
namespace CodeImp.DoomBuilder.Windows
{
2013-07-10 08:59:17 +00:00
internal partial class SectorEditForm : DelayedForm
2009-04-19 18:07:22 +00:00
{
2013-07-09 11:29:10 +00:00
#region = = = = = = = = = = = = = = = = = = Events
public event EventHandler OnValuesChanged ; //mxd
#endregion
#region = = = = = = = = = = = = = = = = = = Variables
2009-04-19 18:07:22 +00:00
private ICollection < Sector > sectors ;
2013-07-19 15:30:58 +00:00
private List < SectorProperties > sectorProps ; //mxd
2013-07-09 11:29:10 +00:00
private bool blockUpdate ; //mxd
private struct SectorProperties //mxd
{
public int Brightness ;
public int FloorHeight ;
public int CeilHeight ;
public string FloorTexture ;
public string CeilTexture ;
public SectorProperties ( Sector s ) {
Brightness = s . Brightness ;
FloorHeight = s . FloorHeight ;
CeilHeight = s . CeilHeight ;
FloorTexture = s . FloorTexture ;
CeilTexture = s . CeilTexture ;
}
}
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor
2009-04-19 18:07:22 +00:00
// Constructor
public SectorEditForm ( )
{
// Initialize
InitializeComponent ( ) ;
// Fill effects list
effect . AddInfo ( General . Map . Config . SortedSectorEffects . ToArray ( ) ) ;
// Initialize image selectors
floortex . Initialize ( ) ;
ceilingtex . Initialize ( ) ;
2009-07-10 19:15:22 +00:00
// Set steps for brightness field
brightness . StepValues = General . Map . Config . BrightnessLevels ;
2009-04-19 18:07:22 +00:00
}
2013-07-09 11:29:10 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Methods
2009-04-19 18:07:22 +00:00
// This sets up the form to edit the given sectors
public void Setup ( ICollection < Sector > sectors )
{
2013-07-19 15:30:58 +00:00
blockUpdate = true ; //mxd
2013-07-09 11:29:10 +00:00
2009-04-19 18:07:22 +00:00
Sector sc ;
// Keep this list
this . sectors = sectors ;
if ( sectors . Count > 1 ) this . Text = "Edit Sectors (" + sectors . Count + ")" ;
2013-07-19 15:30:58 +00:00
sectorProps = new List < SectorProperties > ( ) ; //mxd
//mxd. Make undo
string undodesc = "sector" ;
if ( sectors . Count > 1 ) undodesc = sectors . Count + " sectors" ;
General . Map . UndoRedo . CreateUndo ( "Edit " + undodesc ) ;
2009-04-19 18:07:22 +00:00
////////////////////////////////////////////////////////////////////////
// Set all options to the first sector properties
////////////////////////////////////////////////////////////////////////
// Get first sector
sc = General . GetByIndex ( sectors , 0 ) ;
// 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
2013-03-18 13:52:27 +00:00
tagSelector . Setup ( ) ; //mxd
tagSelector . SetTag ( sc . Tag ) ; //mxd
2009-04-19 18:07:22 +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
2013-03-18 13:52:27 +00:00
if ( s . Tag ! = sc . Tag ) tagSelector . ClearTag ( ) ; //mxd
2013-07-09 11:29:10 +00:00
//mxd. Store initial properties
sectorProps . Add ( new SectorProperties ( s ) ) ;
2009-04-19 18:07:22 +00:00
}
// Show sector height
UpdateSectorHeight ( ) ;
2013-07-09 11:29:10 +00:00
2013-07-19 15:30:58 +00:00
blockUpdate = false ; //mxd
2009-04-19 18:07:22 +00:00
}
// 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 ;
}
}
2013-07-09 11:29:10 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Events
2009-04-19 18:07:22 +00:00
// OK clicked
private void apply_Click ( object sender , EventArgs e )
{
2013-07-09 11:29:10 +00:00
//mxd. Apply "Static" properties
2009-04-19 18:07:22 +00:00
// Verify the tag
2013-03-18 13:52:27 +00:00
tagSelector . ValidateTag ( ) ; //mxd
2013-07-09 11:29:10 +00:00
if ( ( tagSelector . GetTag ( 0 ) < General . Map . FormatInterface . MinTag ) | | ( tagSelector . GetTag ( 0 ) > General . Map . FormatInterface . MaxTag ) ) {
2009-04-19 18:07:22 +00:00
General . ShowWarningMessage ( "Sector tag must be between " + General . Map . FormatInterface . MinTag + " and " + General . Map . FormatInterface . MaxTag + "." , MessageBoxButtons . OK ) ;
return ;
}
// Verify the effect
2013-07-09 11:29:10 +00:00
if ( ( effect . Value < General . Map . FormatInterface . MinEffect ) | | ( effect . Value > General . Map . FormatInterface . MaxEffect ) ) {
2009-04-19 18:07:22 +00:00
General . ShowWarningMessage ( "Sector effect must be between " + General . Map . FormatInterface . MinEffect + " and " + General . Map . FormatInterface . MaxEffect + "." , MessageBoxButtons . OK ) ;
return ;
}
// Go for all sectors
2013-07-09 11:29:10 +00:00
foreach ( Sector s in sectors ) {
2009-04-19 18:07:22 +00:00
// Effects
if ( ! effect . Empty ) s . Effect = effect . Value ;
// Action
2013-03-18 13:52:27 +00:00
s . Tag = tagSelector . GetTag ( s . Tag ) ; //mxd
2009-04-19 18:07:22 +00:00
}
2013-07-09 11:29:10 +00:00
2009-04-19 18:07:22 +00:00
// 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-09 11:29:10 +00:00
//mxd. perform undo
2013-07-19 15:30:58 +00:00
General . Map . UndoRedo . WithdrawUndo ( ) ;
2013-07-09 11:29:10 +00:00
// And be gone
2009-04-19 18:07:22 +00:00
this . DialogResult = DialogResult . Cancel ;
this . Close ( ) ;
}
// Browse Effect clicked
private void browseeffect_Click ( object sender , EventArgs e )
{
effect . Value = EffectBrowserForm . BrowseEffect ( this , effect . Value ) ;
}
2013-07-09 11:29:10 +00:00
// Help
private void SectorEditForm_HelpRequested ( object sender , HelpEventArgs hlpevent ) {
General . ShowHelp ( "w_sectoredit.html" ) ;
hlpevent . Handled = true ;
}
#endregion
2013-07-19 15:30:58 +00:00
#region = = = = = = = = = = = = = = = = = = mxd . Realtime Events
2013-07-09 11:29:10 +00:00
2009-04-19 18:07:22 +00:00
// Ceiling height changes
private void ceilingheight_TextChanged ( object sender , EventArgs e )
{
UpdateSectorHeight ( ) ;
2013-07-09 11:29:10 +00:00
if ( blockUpdate ) return ;
2013-08-22 15:30:50 +00:00
int i = 0 ;
2013-07-09 11:29:10 +00:00
//restore values
if ( string . IsNullOrEmpty ( ceilingheight . Text ) ) {
foreach ( Sector s in sectors )
s . CeilHeight = sectorProps [ i + + ] . CeilHeight ;
//update values
} else {
2013-08-22 15:30:50 +00:00
foreach ( Sector s in sectors )
s . CeilHeight = ceilingheight . GetResult ( sectorProps [ i + + ] . CeilHeight ) ;
2013-07-09 11:29:10 +00:00
}
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
2009-04-19 18:07:22 +00:00
}
// Floor height changes
private void floorheight_TextChanged ( object sender , EventArgs e )
{
UpdateSectorHeight ( ) ;
2013-07-09 11:29:10 +00:00
if ( blockUpdate ) return ;
2013-08-22 15:30:50 +00:00
int i = 0 ;
2013-07-09 11:29:10 +00:00
//restore values
if ( string . IsNullOrEmpty ( floorheight . Text ) ) {
foreach ( Sector s in sectors )
s . FloorHeight = sectorProps [ i + + ] . FloorHeight ;
//update values
} else {
foreach ( Sector s in sectors )
2013-08-22 15:30:50 +00:00
s . FloorHeight = floorheight . GetResult ( sectorProps [ i + + ] . FloorHeight ) ;
2013-07-09 11:29:10 +00:00
}
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
2009-04-19 18:07:22 +00:00
}
2013-07-09 11:29:10 +00:00
private void floortex_OnValueChanged ( object sender , EventArgs e ) {
if ( blockUpdate ) return ;
//restore values
if ( string . IsNullOrEmpty ( floortex . TextureName ) ) {
int i = 0 ;
foreach ( Sector s in sectors )
s . SetFloorTexture ( sectorProps [ i + + ] . FloorTexture ) ;
//update values
} else {
foreach ( Sector s in sectors )
s . SetFloorTexture ( floortex . GetResult ( s . FloorTexture ) ) ;
}
// Update the used textures
General . Map . Data . UpdateUsedTextures ( ) ;
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
private void ceilingtex_OnValueChanged ( object sender , EventArgs e ) {
if ( blockUpdate ) return ;
//restore values
if ( string . IsNullOrEmpty ( ceilingtex . TextureName ) ) {
int i = 0 ;
foreach ( Sector s in sectors )
s . SetCeilTexture ( sectorProps [ i + + ] . CeilTexture ) ;
//update values
} else {
foreach ( Sector s in sectors )
s . SetCeilTexture ( ceilingtex . GetResult ( s . CeilTexture ) ) ;
}
// Update the used textures
General . Map . Data . UpdateUsedTextures ( ) ;
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
2009-04-19 18:07:22 +00:00
}
2013-07-09 11:29:10 +00:00
private void brightness_WhenTextChanged ( object sender , EventArgs e ) {
if ( blockUpdate ) return ;
2013-08-22 15:30:50 +00:00
int i = 0 ;
2013-07-09 11:29:10 +00:00
//restore values
if ( string . IsNullOrEmpty ( brightness . Text ) ) {
foreach ( Sector s in sectors )
s . Brightness = sectorProps [ i + + ] . Brightness ;
//update values
} else {
foreach ( Sector s in sectors )
2013-08-22 15:30:50 +00:00
s . Brightness = General . Clamp ( brightness . GetResult ( sectorProps [ i + + ] . Brightness ) , General . Map . FormatInterface . MinBrightness , General . Map . FormatInterface . MaxBrightness ) ;
2013-07-09 11:29:10 +00:00
}
General . Map . IsChanged = true ;
if ( OnValuesChanged ! = null ) OnValuesChanged ( this , EventArgs . Empty ) ;
}
#endregion
2009-04-19 18:07:22 +00:00
}
}