working on script editor

This commit is contained in:
codeimp 2008-11-02 22:07:20 +00:00
parent 0958677cac
commit 4a2bf61c1c
5 changed files with 5750 additions and 3 deletions

File diff suppressed because it is too large Load diff

View file

@ -25,6 +25,11 @@ using System.Windows.Forms;
using Microsoft.Win32;
using System.Drawing.Drawing2D;
using CodeImp.DoomBuilder.Config;
using System.IO;
using System.Reflection;
using CodeImp.DoomBuilder.IO;
using System.Collections;
using System.Globalization;
#endregion
@ -32,11 +37,14 @@ namespace CodeImp.DoomBuilder.Controls
{
internal partial class BuilderScriptControl : UserControl
{
#region ================== Delegates / Events
#region ================== Constants
private const string LEXERS_RESOURCE = "Lexers.cfg";
private const int DEFAULT_STYLE = (int)ScriptStylesCommon.Default;
#endregion
#region ================== Constants
#region ================== Delegates / Events
#endregion
@ -75,6 +83,7 @@ namespace CodeImp.DoomBuilder.Controls
scriptedit.SetMarginTypeN(0, (int)ScriptMarginType.Symbol);
scriptedit.SetMarginWidthN(1, 42);
scriptedit.SetMarginTypeN(1, (int)ScriptMarginType.Number);
scriptedit.CaretWidth = 2;
}
#endregion
@ -84,7 +93,97 @@ namespace CodeImp.DoomBuilder.Controls
// This sets up the script editor with a script configuration
public void SetupStyles(ScriptConfiguration config)
{
Stream lexersdata;
StreamReader lexersreader;
Configuration lexercfg = new Configuration();
string[] resnames;
// Find a resource named Actions.cfg
resnames = General.ThisAssembly.GetManifestResourceNames();
foreach(string rn in resnames)
{
// Found one?
if(rn.EndsWith(LEXERS_RESOURCE, StringComparison.InvariantCultureIgnoreCase))
{
// Get a stream from the resource
lexersdata = General.ThisAssembly.GetManifestResourceStream(rn);
lexersreader = new StreamReader(lexersdata, Encoding.ASCII);
// Load configuration from stream
lexercfg.InputConfiguration(lexersreader.ReadToEnd());
// Done with the resource
lexersreader.Dispose();
lexersdata.Dispose();
}
}
// Check if specified lexer exists and set the lexer to use
string lexername = "lexer" + config.Lexer.ToString(CultureInfo.InvariantCulture);
if(!lexercfg.SettingExists(lexername)) throw new InvalidOperationException("Unknown lexer " + config.Lexer + " specified in script configuration!");
scriptedit.Lexer = config.Lexer;
// Set the default style and settings
scriptedit.StyleSetFont(DEFAULT_STYLE, "Lucida Console");
scriptedit.StyleSetBack(DEFAULT_STYLE, General.Colors.ScriptBackground.ToColorRef());
scriptedit.StyleSetBold(DEFAULT_STYLE, true);
scriptedit.StyleSetCase(DEFAULT_STYLE, ScriptCaseVisible.Mixed);
scriptedit.StyleSetFore(DEFAULT_STYLE, General.Colors.PlainText.ToColorRef());
scriptedit.StyleSetItalic(DEFAULT_STYLE, false);
scriptedit.StyleSetSize(DEFAULT_STYLE, 10);
scriptedit.StyleSetUnderline(DEFAULT_STYLE, false);
scriptedit.CaretPeriod = SystemInformation.CaretBlinkTime;
scriptedit.CaretFore = General.Colors.ScriptBackground.Inverse().ToColorRef();
scriptedit.StyleBits = 7;
// This applies the default style to all styles
scriptedit.StyleClearAll();
// Clear all keywords
for(int i = 0; i < 9; i++) scriptedit.KeyWords(i, null);
// Now go for all elements in the lexer configuration
// We are looking for the numeric keys, because these are the
// style index to set and the value is the color index to apply
IDictionary dic = lexercfg.ReadSetting(lexername, new Hashtable());
foreach(DictionaryEntry de in dic)
{
// Check if this is a numeric key
int stylenum = -1;
if(int.TryParse(de.Key.ToString(), out stylenum))
{
// Apply color to style
scriptedit.StyleSetFore(stylenum, General.Colors.Colors[(int)de.Value].ToColorRef());
}
}
// Create the keywords list and apply it
int keywordsindex = lexercfg.ReadSetting(lexername + ".keywordsindex", -1);
if(keywordsindex > -1)
{
StringBuilder keywordslist = new StringBuilder("");
foreach(string k in config.Keywords)
{
if(keywordslist.Length > 0) keywordslist.Append(" ");
keywordslist.Append(k);
}
string words = keywordslist.ToString();
scriptedit.KeyWords(keywordsindex, words.ToLowerInvariant());
}
// Create the constants list and apply it
int constantsindex = lexercfg.ReadSetting(lexername + ".constantsindex", -1);
if(constantsindex > -1)
{
StringBuilder constantslist = new StringBuilder("");
foreach(string c in config.Constants)
{
if(constantslist.Length > 0) constantslist.Append(" ");
constantslist.Append(c);
}
string words = constantslist.ToString();
scriptedit.KeyWords(constantsindex, words.ToLowerInvariant());
}
}
#endregion

View file

@ -408,7 +408,7 @@ namespace CodeImp.DoomBuilder
// Make script configuration
ScriptConfiguration scfg = new ScriptConfiguration(cfg);
string filename = Path.GetFileName(filepath);
scriptconfigs.Add(filename, scfg);
scriptconfigs.Add(filename.ToLowerInvariant(), scfg);
}
catch(Exception e)
{

View file

@ -110,6 +110,12 @@ namespace CodeImp.DoomBuilder.Rendering
return Color.FromArgb(a, r, g, b);
}
// To ColorRef (alpha-less)
public int ToColorRef()
{
return ((int)r + ((int)b << 16) + ((int)g << 8));
}
// To ColorValue
public Color4 ToColorValue()
{

View file

@ -36,6 +36,7 @@ namespace CodeImp.DoomBuilder.Windows
public ScriptEditTestForm()
{
InitializeComponent();
script.SetupStyles(General.ScriptConfigs["zdoom_acs.cfg"]);
}
}
}