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 ;
2013-11-21 10:53:11 +00:00
using System.Drawing ;
2009-04-19 18:07:22 +00:00
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
2013-11-21 10:53:11 +00:00
//mxd. Window setup stuff
private static Point location = Point . Empty ;
2013-07-09 11:29:10 +00:00
private struct SectorProperties //mxd
{
2014-05-05 14:24:57 +00:00
public readonly int Brightness ;
public readonly int FloorHeight ;
public readonly int CeilHeight ;
public readonly string FloorTexture ;
public readonly string CeilTexture ;
2013-07-09 11:29:10 +00:00
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 ( ) ;
2013-11-21 10:53:11 +00:00
//mxd. Widow setup
if ( location ! = Point . Empty ) {
this . StartPosition = FormStartPosition . Manual ;
this . Location = location ;
}
2009-04-19 18:07:22 +00:00
// 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-08-28 08:29:06 +00:00
tagSelector . Setup ( UniversalType . SectorTag ) ; //mxd
2013-03-18 13:52:27 +00:00
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 = "" ;
2014-03-05 09:21:28 +00:00
if ( s . FloorTexture ! = floortex . TextureName ) {
floortex . MultipleTextures = true ; //mxd
floortex . TextureName = "" ;
}
if ( s . CeilTexture ! = ceilingtex . TextureName ) {
ceilingtex . MultipleTextures = true ; //mxd
ceilingtex . TextureName = "" ;
}
2009-04-19 18:07:22 +00:00
// 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 ( )
{
int delta = 0 ;
2013-09-17 08:21:12 +00:00
int index = - 1 ; //mxd
int i = 0 ; //mxd
2009-04-19 18:07:22 +00:00
// Check all selected sectors
2013-09-17 08:21:12 +00:00
foreach ( Sector s in sectors ) {
if ( index = = - 1 ) {
2009-04-19 18:07:22 +00:00
// First sector in list
delta = s . CeilHeight - s . FloorHeight ;
2013-09-17 08:21:12 +00:00
index = i ; //mxd
} else if ( delta ! = ( s . CeilHeight - s . FloorHeight ) ) {
// We can't show heights because the delta
// heights for the sectors is different
index = - 1 ;
break ;
2009-04-19 18:07:22 +00:00
}
2013-09-17 08:21:12 +00:00
i + + ;
2009-04-19 18:07:22 +00:00
}
2013-09-17 08:21:12 +00:00
if ( index > - 1 ) {
int fh = floorheight . GetResult ( sectorProps [ index ] . FloorHeight ) ; //mxd
int ch = ceilingheight . GetResult ( sectorProps [ index ] . CeilHeight ) ; //mxd
2009-04-19 18:07:22 +00:00
int height = ch - fh ;
sectorheight . Text = height . ToString ( ) ;
sectorheight . Visible = true ;
sectorheightlabel . Visible = true ;
2013-09-17 08:21:12 +00:00
} else {
2009-04-19 18:07:22 +00:00
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
2014-08-05 11:03:55 +00:00
int tagoffset = 0 ; //mxd
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
2014-08-11 08:35:39 +00:00
s . Tag = General . Clamp ( tagSelector . GetSmartTag ( s . Tag , tagoffset + + ) , General . Map . FormatInterface . MinTag , General . Map . FormatInterface . MaxTag ) ; //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-11-21 10:53:11 +00:00
//mxd
private void SectorEditForm_FormClosing ( object sender , FormClosingEventArgs e ) {
location = this . Location ;
}
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 )
{
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
}
2013-09-17 08:21:12 +00:00
UpdateSectorHeight ( ) ;
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 )
{
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
}
2013-09-17 08:21:12 +00:00
UpdateSectorHeight ( ) ;
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
2013-11-21 10:53:11 +00:00
2009-04-19 18:07:22 +00:00
}
}