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
2016-04-04 12:09:38 +00:00
using System ;
2009-04-19 18:07:22 +00:00
using System.Collections ;
using System.Collections.Generic ;
using System.Globalization ;
using CodeImp.DoomBuilder.IO ;
2016-07-14 12:42:16 +00:00
using CodeImp.DoomBuilder.Rendering ;
2015-05-30 12:42:55 +00:00
using CodeImp.DoomBuilder.Types ;
2016-07-14 12:42:16 +00:00
using CodeImp.DoomBuilder.ZDoom ;
2009-04-19 18:07:22 +00:00
#endregion
namespace CodeImp.DoomBuilder.Config
{
public class ArgumentInfo
{
#region = = = = = = = = = = = = = = = = = = Constants
2016-07-14 12:42:16 +00:00
private const int HELPER_SHAPE_ALPHA = 192 ; //mxd
2017-01-06 12:59:41 +00:00
private const int RANGE_SHAPE_ALPHA = 96 ; //mxd
2016-07-14 12:42:16 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Enums ( mxd )
public enum ArgumentRenderStyle
{
NONE ,
CIRCLE ,
RECTANGLE ,
}
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Variables
2014-12-05 14:33:31 +00:00
private readonly string title ;
2015-05-23 21:01:44 +00:00
private readonly string tooltip ; //mxd
2014-12-05 14:33:31 +00:00
private readonly bool used ;
private readonly int type ;
2015-04-14 11:33:57 +00:00
private EnumList enumlist ;
2016-04-11 12:05:23 +00:00
private EnumList flagslist ; //mxd
2014-12-05 14:33:31 +00:00
private readonly object defaultvalue ; //mxd
2016-04-04 12:09:38 +00:00
private readonly HashSet < string > targetclasses ; //mxd
2016-07-14 12:42:16 +00:00
private readonly ArgumentRenderStyle renderstyle ; //mxd
private readonly PixelColor rendercolor ; //mxd
2017-01-06 12:59:41 +00:00
private readonly PixelColor minrangecolor ; //mxd
private readonly PixelColor maxrangecolor ; //mxd
private readonly int minrange ; //mxd
private readonly int maxrange ; //mxd
2017-02-23 11:54:42 +00:00
private readonly bool str ; // [ZZ]
private readonly string titlestr ; // [ZZ]
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Properties
public string Title { get { return title ; } }
2015-05-23 21:01:44 +00:00
public string ToolTip { get { return tooltip ; } } //mxd
2009-04-19 18:07:22 +00:00
public bool Used { get { return used ; } }
public int Type { get { return type ; } }
2016-04-04 12:09:38 +00:00
public HashSet < string > TargetClasses { get { return targetclasses ; } } //mxd
2015-04-14 11:33:57 +00:00
public EnumList Enum { get { return enumlist ; } internal set { enumlist = value ; } }
2016-04-11 12:05:23 +00:00
public EnumList Flags { get { return flagslist ; } internal set { flagslist = value ; } } //mxd
2014-12-05 14:33:31 +00:00
public object DefaultValue { get { return defaultvalue ; } } //mxd
2016-07-14 12:42:16 +00:00
public ArgumentRenderStyle RenderStyle { get { return renderstyle ; } } //mxd
public PixelColor RenderColor { get { return rendercolor ; } } //mxd
2017-01-06 12:59:41 +00:00
public PixelColor MinRangeColor { get { return minrangecolor ; } } //mxd
public PixelColor MaxRangeColor { get { return maxrangecolor ; } } //mxd
public int MinRange { get { return minrange ; } } //mxd
public int MaxRange { get { return maxrange ; } } //mxd
2017-02-23 11:54:42 +00:00
public bool Str { get { return str ; } } // [ZZ]
public string TitleStr { get { return titlestr ; } } // [ZZ]
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor / Disposer
// Constructor for argument info from configuration
internal ArgumentInfo ( Configuration cfg , string argspath , int argindex , IDictionary < string , EnumList > enums )
{
// Read
string istr = argindex . ToString ( CultureInfo . InvariantCulture ) ;
this . used = cfg . SettingExists ( argspath + ".arg" + istr ) ;
this . title = cfg . ReadSetting ( argspath + ".arg" + istr + ".title" , "Argument " + ( argindex + 1 ) ) ;
2015-05-23 21:01:44 +00:00
this . tooltip = cfg . ReadSetting ( argspath + ".arg" + istr + ".tooltip" , string . Empty ) ; //mxd
2009-04-19 18:07:22 +00:00
this . type = cfg . ReadSetting ( argspath + ".arg" + istr + ".type" , 0 ) ;
2017-02-23 11:54:42 +00:00
this . str = cfg . ReadSetting ( argspath + ".arg" + istr + ".str" , false ) ;
this . titlestr = cfg . ReadSetting ( argspath + ".arg" + istr + ".titlestr" , this . title ) ;
2018-02-04 00:50:38 +00:00
this . defaultvalue = cfg . ReadSetting ( argspath + ".arg" + istr + ".default" , 0 ) ;
2018-02-03 20:31:34 +00:00
//mxd. Get rendering hint settings
string renderstyle = cfg . ReadSetting ( argspath + ".arg" + istr + ".renderstyle" , string . Empty ) ;
2016-07-14 12:42:16 +00:00
switch ( renderstyle . ToLowerInvariant ( ) )
{
case "circle" :
this . renderstyle = ArgumentRenderStyle . CIRCLE ;
break ;
case "rectangle" :
this . renderstyle = ArgumentRenderStyle . RECTANGLE ;
break ;
default :
this . renderstyle = ArgumentRenderStyle . NONE ;
if ( ! string . IsNullOrEmpty ( renderstyle ) )
General . ErrorLogger . Add ( ErrorType . Error , "\"" + argspath + ".arg" + istr + "\": action argument \"" + this . title + "\" has unknown renderstyle \"" + renderstyle + "\"!" ) ;
break ;
}
if ( this . renderstyle ! = ArgumentRenderStyle . NONE )
{
2017-01-06 12:59:41 +00:00
// Get rendercolor
2016-07-14 12:42:16 +00:00
string rendercolor = cfg . ReadSetting ( argspath + ".arg" + istr + ".rendercolor" , string . Empty ) ;
2017-01-06 12:59:41 +00:00
this . rendercolor = General . Colors . InfoLine ;
2018-02-04 03:16:52 +00:00
if ( ! string . IsNullOrEmpty ( rendercolor ) & & ! ZDTextParser . GetColorFromString ( rendercolor , out this . rendercolor ) )
2017-01-06 12:59:41 +00:00
General . ErrorLogger . Add ( ErrorType . Error , "\"" + argspath + ".arg" + istr + "\": action argument \"" + this . title + "\": unable to get rendercolor from value \"" + rendercolor + "\"!" ) ;
this . rendercolor . a = HELPER_SHAPE_ALPHA ;
// Get minrange settings
string minrange = cfg . ReadSetting ( argspath + ".arg" + istr + ".minrange" , string . Empty ) ;
if ( int . TryParse ( minrange , NumberStyles . Integer , CultureInfo . InvariantCulture , out this . minrange ) & & this . minrange > 0f )
2016-07-14 12:42:16 +00:00
{
2017-01-06 12:59:41 +00:00
// Get minrangecolor
string minrangecolor = cfg . ReadSetting ( argspath + ".arg" + istr + ".minrangecolor" , string . Empty ) ;
this . minrangecolor = General . Colors . Indication ;
2018-02-04 03:16:52 +00:00
if ( ! string . IsNullOrEmpty ( minrangecolor ) & & ! ZDTextParser . GetColorFromString ( minrangecolor , out this . minrangecolor ) )
2017-01-06 12:59:41 +00:00
General . ErrorLogger . Add ( ErrorType . Error , "\"" + argspath + ".arg" + istr + "\": action argument \"" + this . title + "\": unable to get minrangecolor from value \"" + minrangecolor + "\"!" ) ;
this . minrangecolor . a = RANGE_SHAPE_ALPHA ;
2016-07-14 12:42:16 +00:00
}
2017-01-06 12:59:41 +00:00
// Get maxrange settings
string maxrange = cfg . ReadSetting ( argspath + ".arg" + istr + ".maxrange" , string . Empty ) ;
if ( int . TryParse ( maxrange , NumberStyles . Integer , CultureInfo . InvariantCulture , out this . maxrange ) & & this . maxrange > 0f )
2016-07-14 12:42:16 +00:00
{
2017-01-06 12:59:41 +00:00
// Get minrangecolor
string maxrangecolor = cfg . ReadSetting ( argspath + ".arg" + istr + ".maxrangecolor" , string . Empty ) ;
this . maxrangecolor = General . Colors . Indication ;
2018-02-04 03:16:52 +00:00
if ( ! string . IsNullOrEmpty ( maxrangecolor ) & & ! ZDTextParser . GetColorFromString ( maxrangecolor , out this . maxrangecolor ) )
2017-01-06 12:59:41 +00:00
General . ErrorLogger . Add ( ErrorType . Error , "\"" + argspath + ".arg" + istr + "\": action argument \"" + this . title + "\": unable to get maxrangecolor from value \"" + maxrangecolor + "\"!" ) ;
this . maxrangecolor . a = RANGE_SHAPE_ALPHA ;
}
// Update tooltip?
if ( this . minrange > 0f | | this . maxrange > 0f )
{
if ( ! string . IsNullOrEmpty ( this . tooltip ) ) this . tooltip + = Environment . NewLine ;
if ( this . minrange > 0f & & this . maxrange > 0f )
this . tooltip + = "Range: " + this . minrange + " - " + this . maxrange ;
else if ( this . minrange > 0f )
this . tooltip + = "Minimum range: " + this . minrange ;
else
this . tooltip + = "Maximum range: " + this . maxrange ;
2016-07-14 12:42:16 +00:00
}
}
2016-04-04 12:09:38 +00:00
//mxd. Check for TargetClass?
this . targetclasses = new HashSet < string > ( StringComparer . InvariantCultureIgnoreCase ) ;
if ( this . type = = ( int ) UniversalType . ThingTag )
{
string s = cfg . ReadSetting ( argspath + ".arg" + istr + ".targetclasses" , string . Empty ) ;
if ( ! string . IsNullOrEmpty ( s ) )
{
foreach ( string tclass in s . Split ( new [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries ) )
targetclasses . Add ( tclass . Trim ( ) ) ;
}
}
2009-04-19 18:07:22 +00:00
// Determine enum type
IDictionary argdic = cfg . ReadSetting ( argspath + ".arg" + istr , new Hashtable ( ) ) ;
2015-12-28 15:01:53 +00:00
if ( argdic . Contains ( "enum" ) )
2009-04-19 18:07:22 +00:00
{
// Enum fully specified?
2015-12-28 15:01:53 +00:00
if ( argdic [ "enum" ] is IDictionary )
2009-04-19 18:07:22 +00:00
{
// Create anonymous enum
2016-03-18 12:52:12 +00:00
this . enumlist = new EnumList ( ( IDictionary ) argdic [ "enum" ] ) ;
2009-04-19 18:07:22 +00:00
}
else
{
// Check if referenced enum exists
2015-12-28 15:01:53 +00:00
if ( ( argdic [ "enum" ] . ToString ( ) . Length > 0 ) & & enums . ContainsKey ( argdic [ "enum" ] . ToString ( ) ) )
2009-04-19 18:07:22 +00:00
{
// Get the enum list
2014-02-18 14:04:14 +00:00
this . enumlist = enums [ argdic [ "enum" ] . ToString ( ) ] ;
2009-04-19 18:07:22 +00:00
}
else
{
2016-02-22 08:04:06 +00:00
General . ErrorLogger . Add ( ErrorType . Warning , "\"" + argspath + ".arg" + istr + "\" references unknown enumeration \"" + argdic [ "enum" ] + "\"." ) ;
2009-04-19 18:07:22 +00:00
}
}
}
2016-04-11 12:05:23 +00:00
//mxd. Determine flags type
if ( argdic . Contains ( "flags" ) )
{
// Enum fully specified?
if ( argdic [ "flags" ] is IDictionary )
{
// Create anonymous enum
this . flagslist = new EnumList ( ( IDictionary ) argdic [ "flags" ] ) ;
}
else
{
// Check if referenced enum exists
if ( ( argdic [ "flags" ] . ToString ( ) . Length > 0 ) & & enums . ContainsKey ( argdic [ "flags" ] . ToString ( ) ) )
{
// Get the enum list
this . flagslist = enums [ argdic [ "flags" ] . ToString ( ) ] ;
}
else
{
General . ErrorLogger . Add ( ErrorType . Warning , "\"" + argspath + ".arg" + istr + "\" references unknown flags enumeration \"" + argdic [ "flags" ] + "\"." ) ;
}
}
}
2014-12-05 14:33:31 +00:00
2015-12-28 15:01:53 +00:00
if ( this . enumlist = = null ) this . enumlist = new EnumList ( ) ; //mxd
2016-04-11 12:05:23 +00:00
if ( this . flagslist = = null ) this . flagslist = new EnumList ( ) ; //mxd
2009-04-19 18:07:22 +00:00
}
2015-02-04 18:02:03 +00:00
//mxd. Constructor for an argument info defined in DECORATE
2017-03-01 22:21:08 +00:00
// [ZZ] Constructor for an argument info defined in DECORATE/ZScript. reworked.
internal ArgumentInfo ( ActorStructure actor , int i )
{
if ( ! actor . HasPropertyWithValue ( "$arg" + i ) )
{
used = false ;
return ;
}
string argtitle = ZDTextParser . StripQuotes ( actor . GetPropertyAllValues ( "$arg" + i ) ) ;
string tooltip = ZDTextParser . StripQuotes ( actor . GetPropertyAllValues ( "$arg" + i + "tooltip" ) . Replace ( "\\n" , Environment . NewLine ) ) ;
int type = actor . GetPropertyValueInt ( "$arg" + i + "type" , 0 ) ;
string targetclasses = ZDTextParser . StripQuotes ( actor . GetPropertyAllValues ( "$arg" + i + "targetclasses" ) ) ;
int defaultvalue = actor . GetPropertyValueInt ( "$arg" + i + "default" , 0 ) ;
string enumstr = ZDTextParser . StripQuotes ( actor . GetPropertyAllValues ( "$arg" + i + "enum" ) ) ;
string renderstyle = ZDTextParser . StripQuotes ( actor . GetPropertyAllValues ( "$arg" + i + "renderstyle" ) ) ;
string rendercolor , minrange , maxrange , minrangecolor , maxrangecolor ;
bool str = ( actor . HasProperty ( "$arg" + i + "str" ) ) ;
string argtitlestr = ZDTextParser . StripQuotes ( actor . GetPropertyAllValues ( "$arg" + i + "str" ) ) ;
if ( string . IsNullOrEmpty ( argtitlestr ) ) argtitlestr = argtitle ;
if ( ! string . IsNullOrEmpty ( renderstyle ) )
{
rendercolor = ZDTextParser . StripQuotes ( actor . GetPropertyAllValues ( "$arg" + i + "rendercolor" ) ) ;
minrange = ZDTextParser . StripQuotes ( actor . GetPropertyAllValues ( "$arg" + i + "minrange" ) ) ;
minrangecolor = ZDTextParser . StripQuotes ( actor . GetPropertyAllValues ( "$arg" + i + "minrangecolor" ) ) ;
maxrange = ZDTextParser . StripQuotes ( actor . GetPropertyAllValues ( "$arg" + i + "maxrange" ) ) ;
maxrangecolor = ZDTextParser . StripQuotes ( actor . GetPropertyAllValues ( "$arg" + i + "maxrangecolor" ) ) ;
}
else
{
rendercolor = string . Empty ; minrange = string . Empty ; maxrange = string . Empty ; minrangecolor = string . Empty ; maxrangecolor = string . Empty ;
}
string actorname = actor . ClassName ;
IDictionary < string , EnumList > enums = General . Map . Config . Enums ;
2015-02-04 18:02:03 +00:00
this . used = true ;
2015-05-30 12:42:55 +00:00
this . title = argtitle ;
2015-05-23 21:01:44 +00:00
this . tooltip = tooltip ;
2015-05-31 21:11:21 +00:00
this . defaultvalue = defaultvalue ;
2016-04-11 12:05:23 +00:00
this . flagslist = new EnumList ( ) ; //mxd
2017-02-25 08:41:03 +00:00
this . str = str ;
this . titlestr = argtitlestr ;
2015-05-30 12:42:55 +00:00
2016-07-14 12:42:16 +00:00
// Get rendering hint settings
switch ( renderstyle . ToLowerInvariant ( ) )
{
case "circle" : this . renderstyle = ArgumentRenderStyle . CIRCLE ; break ;
case "rectangle" : this . renderstyle = ArgumentRenderStyle . RECTANGLE ; break ;
default :
this . renderstyle = ArgumentRenderStyle . NONE ;
if ( ! string . IsNullOrEmpty ( renderstyle ) )
General . ErrorLogger . Add ( ErrorType . Error , actorname + ": action argument \"" + argtitle + "\" has unknown renderstyle \"" + renderstyle + "\"!" ) ;
break ;
}
if ( this . renderstyle ! = ArgumentRenderStyle . NONE )
{
2017-01-06 12:59:41 +00:00
// Get rendercolor
this . rendercolor = General . Colors . InfoLine ;
2018-02-04 03:16:52 +00:00
if ( ! string . IsNullOrEmpty ( rendercolor ) & & ! ZDTextParser . GetColorFromString ( rendercolor , out this . rendercolor ) )
2017-01-06 12:59:41 +00:00
General . ErrorLogger . Add ( ErrorType . Error , actorname + ": action argument \"" + argtitle + "\": unable to get rendercolor from value \"" + rendercolor + "\"!" ) ;
this . rendercolor . a = HELPER_SHAPE_ALPHA ;
// Get minrange settings
if ( int . TryParse ( minrange , NumberStyles . Integer , CultureInfo . InvariantCulture , out this . minrange ) & & this . minrange > 0f )
2016-07-14 12:42:16 +00:00
{
2017-01-06 12:59:41 +00:00
// Get minrangecolor
this . minrangecolor = General . Colors . Indication ;
2018-02-04 03:16:52 +00:00
if ( ! string . IsNullOrEmpty ( minrangecolor ) & & ! ZDTextParser . GetColorFromString ( minrangecolor , out this . minrangecolor ) )
2017-01-06 12:59:41 +00:00
General . ErrorLogger . Add ( ErrorType . Error , actorname + ": action argument \"" + this . title + "\": unable to get minrangecolor from value \"" + minrangecolor + "\"!" ) ;
this . minrangecolor . a = RANGE_SHAPE_ALPHA ;
2016-07-14 12:42:16 +00:00
}
2017-01-06 12:59:41 +00:00
// Get maxrange settings
if ( int . TryParse ( maxrange , NumberStyles . Integer , CultureInfo . InvariantCulture , out this . maxrange ) & & this . maxrange > 0f )
2016-07-14 12:42:16 +00:00
{
2017-01-06 12:59:41 +00:00
// Get minrangecolor
this . maxrangecolor = General . Colors . Indication ;
2018-02-04 03:16:52 +00:00
if ( ! string . IsNullOrEmpty ( maxrangecolor ) & & ! ZDTextParser . GetColorFromString ( maxrangecolor , out this . maxrangecolor ) )
2017-01-06 12:59:41 +00:00
General . ErrorLogger . Add ( ErrorType . Error , actorname + ": action argument \"" + this . title + "\": unable to get maxrangecolor from value \"" + maxrangecolor + "\"!" ) ;
this . maxrangecolor . a = RANGE_SHAPE_ALPHA ;
}
// Update tooltip?
if ( this . minrange > 0f | | this . maxrange > 0f )
{
if ( ! string . IsNullOrEmpty ( this . tooltip ) ) this . tooltip + = Environment . NewLine + Environment . NewLine ;
if ( this . minrange > 0f & & this . maxrange > 0f )
this . tooltip + = "Expected range: " + this . minrange + " - " + this . maxrange ;
else if ( this . minrange > 0f )
this . tooltip + = "Minimum: " + this . minrange ;
else
this . tooltip + = "Maximum: " + this . maxrange ;
2016-07-14 12:42:16 +00:00
}
}
2017-02-15 19:03:17 +00:00
//Check for TargetClass
this . targetclasses = new HashSet < string > ( StringComparer . InvariantCultureIgnoreCase ) ;
if ( type = = ( int ) UniversalType . ThingTag )
{
if ( ! string . IsNullOrEmpty ( targetclasses ) )
{
foreach ( string tclass in targetclasses . Split ( new [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries ) )
this . targetclasses . Add ( tclass . Trim ( ) ) ;
}
}
2015-05-30 12:42:55 +00:00
// Get argument type
if ( System . Enum . IsDefined ( typeof ( UniversalType ) , type ) )
{
this . type = type ;
}
else
{
General . ErrorLogger . Add ( ErrorType . Error , actorname + ": action argument \"" + argtitle + "\" has unknown type " + type + "!" ) ;
this . type = 0 ;
}
// Get or create enum
if ( ! string . IsNullOrEmpty ( enumstr ) )
{
if ( enums . ContainsKey ( enumstr . ToLowerInvariant ( ) ) )
{
this . enumlist = enums [ enumstr . ToLowerInvariant ( ) ] ;
}
else
{
Configuration cfg = new Configuration ( ) ;
if ( cfg . InputConfiguration ( "enum" + enumstr , true ) )
{
IDictionary argdic = cfg . ReadSetting ( "enum" , new Hashtable ( ) ) ;
if ( argdic . Keys . Count > 0 )
this . enumlist = new EnumList ( argdic ) ;
else
General . ErrorLogger . Add ( ErrorType . Error , actorname + ": unable to parse explicit enum structure for argument \"" + argtitle + "\"!" ) ;
}
else
{
General . ErrorLogger . Add ( ErrorType . Error , actorname + ": unable to parse enum structure for argument \"" + argtitle + "\"!" ) ;
}
}
}
if ( this . enumlist = = null ) this . enumlist = new EnumList ( ) ;
2015-02-04 18:02:03 +00:00
}
2009-04-19 18:07:22 +00:00
// Constructor for unknown argument info
internal ArgumentInfo ( int argindex )
{
this . used = false ;
this . title = "Argument " + ( argindex + 1 ) ;
this . type = 0 ;
this . enumlist = new EnumList ( ) ;
2016-04-11 12:05:23 +00:00
this . flagslist = new EnumList ( ) ; //mxd
2014-12-05 14:33:31 +00:00
this . defaultvalue = 0 ; //mxd
2009-04-19 18:07:22 +00:00
}
#endregion
#region = = = = = = = = = = = = = = = = = = Methods
// This gets the description for an argument value
public string GetValueDescription ( int value )
{
// TODO: Use the registered type editor to get the description!
return value . ToString ( ) ;
}
#endregion
}
}