Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 40 additions & 66 deletions ScriptLab/ConfigDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Forms;
Expand All @@ -14,7 +15,7 @@ namespace pyrochild.effects.scriptlab
{
public partial class ConfigDialog : EffectConfigDialog
{
Dictionary<string, Type> AvailableEffects = new Dictionary<string, Type>();
Dictionary<string, IEffectInfo> AvailableEffects = new Dictionary<string, IEffectInfo>();
List<Image> AvailableEffectsIcons;
List<string> AvailableEffectsNames;

Expand All @@ -37,66 +38,39 @@ public ConfigDialog()
btnDonate.Image = new Bitmap(typeof(ScriptLab), "images.money.png");
btnChangeColor.Image = new Bitmap(typeof(ScriptLab), "images.colorwheel.png");
Text = ScriptLab.StaticDialogName;
}

List<Type> RawEffects = CommonUtil.GatherEffects();

RawEffects.Sort((t1, t2) =>
{
try
{
string e1 = ((Effect)(t1.GetConstructor(Type.EmptyTypes).Invoke(new object[0]))).Name;
string e2 = ((Effect)(t2.GetConstructor(Type.EmptyTypes).Invoke(new object[0]))).Name;
if (e1.Contains("&"))
{
e1 = e1.Remove(e1.IndexOf("&"), 1);
}
if (e2.Contains("&"))
{
e2 = e2.Remove(e2.IndexOf("&"), 1);
}
protected override void OnLoad(EventArgs e)
{
string slName = this.Effect.Name;

return e1.CompareTo(e2);
}
catch
{
return 0;
}
});
List<IEffectInfo> RawEffects = this.Services
.GetService<IEffectsService>().EffectInfos
.Where(x => x.Name != slName)
.OrderBy(x => x.Name)
.ToList();

AvailableEffectsNames = new List<string>();
AvailableEffectsIcons = new List<Image>();

for (int i = 0; i < RawEffects.Count; i++)
{
try
if ((RawEffects[i].Category != EffectCategory.DoNotDisplay //effects that don't want to be shown
|| RawEffects[i].Type.Name == nameof(RotateZoomEffect)) //unless it's the rotatezoomeffect which hides itself from the ffects menu so it can be put in Layers
&& !AvailableEffects.ContainsKey(RawEffects[i].Type.FullName + ":" + RawEffects[i].Name))
{
Effect effect = (Effect)(RawEffects[i].GetConstructor(Type.EmptyTypes).Invoke(new object[0]));

if ((effect.Category != EffectCategory.DoNotDisplay //effects that don't want to be shown
|| effect is RotateZoomEffect) //unless it's the rotatezoomeffect which hides itself from the ffects menu so it can be put in Layers
&& !AvailableEffects.ContainsKey(RawEffects[i].FullName + ":" + effect.Name))
{
AvailableEffects.Add(RawEffects[i].FullName + ":" + effect.Name, RawEffects[i]);
AvailableEffectsNames.Add(effect.Name);
AvailableEffectsIcons.Add(effect.Image);
SearchResultEffects.Add(RawEffects[i].FullName + ":" + effect.Name);
SearchResultIndices.Add(i, i);
}
else
{
RawEffects.RemoveAt(i);
--i;
}
}
catch
{
RawEffects.RemoveAt(i);
--i;
AvailableEffects.Add(RawEffects[i].Type.FullName + ":" + RawEffects[i].Name, RawEffects[i]);
AvailableEffectsNames.Add(RawEffects[i].Name);
AvailableEffectsIcons.Add(RawEffects[i].Image);
SearchResultEffects.Add(RawEffects[i].Type.FullName + ":" + RawEffects[i].Name);
SearchResultIndices.Add(i, i);
}
}

lbAvailable.Items.AddRange(AvailableEffectsNames.ToArray());
lbAvailable.Invalidate();

base.OnLoad(e);
}

void lbScript_DrawItem(object sender, DrawItemEventArgs e)
Expand All @@ -111,7 +85,7 @@ void lbScript_DrawItem(object sender, DrawItemEventArgs e)
Image icon = step.Icon;
string text = step.Name;

if (step.EffectType == null) //effect wasn't found
if (!step.EffectAvailable) //effect wasn't found
{
e.Graphics.DrawRectangle(Pens.Red, Rectangle.Inflate(e.Bounds, -1, -1));
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(127, Color.Red)), Rectangle.Inflate(e.Bounds, -1, -1));
Expand Down Expand Up @@ -237,8 +211,8 @@ void AddSelectedEffect()
{
ConfigToken token = (ConfigToken)theEffectToken;
string effectidentifiername = SearchResultEffects[lbAvailable.SelectedIndex];
Type t = AvailableEffects[effectidentifiername];
Effect effect = (Effect)t.GetConstructor(Type.EmptyTypes).Invoke(new object[0]);
IEffectInfo effectInfo = AvailableEffects[effectidentifiername];
Effect effect = effectInfo.CreateInstance();
effect.EnvironmentParameters = Effect.EnvironmentParameters;
effect.Services = Services;
if (effect.Options.Flags.HasFlag(EffectFlags.Configurable))
Expand All @@ -250,23 +224,23 @@ void AddSelectedEffect()

if (dialog.ShowDialog(this) == DialogResult.OK)
{
token.effects.Add(new ScriptStep(effect.Name, effect.Image, t, dialog.EffectToken, Effect.EnvironmentParameters.PrimaryColor, Effect.EnvironmentParameters.SecondaryColor));
lbScript.Items.Add(effect.Name);
token.effects.Add(new ScriptStep(effectInfo, dialog.EffectToken, Effect.EnvironmentParameters.PrimaryColor, Effect.EnvironmentParameters.SecondaryColor));
lbScript.Items.Add(effectInfo.Name);
FinishTokenUpdate();
}
}
catch (Exception e)
{
MessageBox.Show(this,
"Error occurred in configuration dialog for " + effect.Name + ":\n\n" + e.ToString(),
effect.Name+" Error",
"Error occurred in configuration dialog for " + effectInfo.Name + ":\n\n" + e.ToString(),
effectInfo.Name+" Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
token.effects.Add(new ScriptStep(effect.Name, effect.Image, t, null, Effect.EnvironmentParameters.PrimaryColor, Effect.EnvironmentParameters.SecondaryColor));
lbScript.Items.Add(effect.Name);
token.effects.Add(new ScriptStep(effectInfo, null, Effect.EnvironmentParameters.PrimaryColor, Effect.EnvironmentParameters.SecondaryColor));
lbScript.Items.Add(effectInfo.Name);
FinishTokenUpdate();
}
}
Expand Down Expand Up @@ -351,10 +325,10 @@ private void ChangeSelectedEffect()
ConfigToken token = (ConfigToken)theEffectToken;
int i = lbScript.SelectedIndex;
ScriptStep step = token.effects[i];
Type type = step.EffectType;
if (type != null)

if (step.EffectAvailable)
{
Effect effect = (Effect)type.GetConstructor(Type.EmptyTypes).Invoke(new object[0]);
Effect effect = step.CreateInstance();
effect.EnvironmentParameters = Effect.EnvironmentParameters;
effect.Services = Services;
if (effect.Options.Flags.HasFlag(EffectFlags.Configurable))
Expand Down Expand Up @@ -464,10 +438,10 @@ private bool SaveTxtFile(string path, out Exception exception)
sw.WriteLine();

string effectname = sls.Effects[i];
Type effecttype;
if (AvailableEffects.TryGetValue(effectname, out effecttype))
IEffectInfo effectInfo;
if (AvailableEffects.TryGetValue(effectname, out effectInfo))
{
Effect effect = (Effect)effecttype.GetConstructor(Type.EmptyTypes).Invoke(new object[0]);
Effect effect = effectInfo.CreateInstance();
effect.EnvironmentParameters = Effect.EnvironmentParameters;
effect.Services = Services;
if (effect.Options.Flags.HasFlag(EffectFlags.Configurable))
Expand Down Expand Up @@ -681,7 +655,7 @@ private void txtSearch_TextChanged(object sender, EventArgs e)
{
name = name.Remove(name.IndexOf("&"), 1);
}
Effect effect = (Effect)AvailableEffects[keyenumerator.Current].GetConstructor(Type.EmptyTypes).Invoke(new object[0]);
IEffectInfo effect = AvailableEffects[keyenumerator.Current];
if (name.ToLower().Contains(txtSearch.Text.ToLower())
|| (effect.SubMenuName != null && effect.SubMenuName.ToLower().Contains(txtSearch.Text.ToLower())))
{
Expand Down Expand Up @@ -853,10 +827,10 @@ private void EnableScriptControlButtons()
ConfigToken token = (ConfigToken)theEffectToken;
int i = lbScript.SelectedIndex;
ScriptStep step = token.effects[i];
Type type = step.EffectType;
if (type != null)

if (step.EffectAvailable)
{
Effect effect = (Effect)type.GetConstructor(Type.EmptyTypes).Invoke(new object[0]);
Effect effect = step.CreateInstance();
if (effect.Options.Flags.HasFlag(EffectFlags.Configurable))
{
btnChange.Enabled = true;
Expand Down
6 changes: 3 additions & 3 deletions ScriptLab/Effect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,21 @@ public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, Re
for (int i = 0; i < token.effects.Count; ++i)
{
ScriptStep step = token.effects[i];
Type type = step.EffectType;

if (type == null)
if (!step.EffectAvailable)
{
if (dialog != null)
dialog.IncrementProgressBarValue(i, 1);
}
else
{
Effect effect = (Effect)(type.GetConstructor(Type.EmptyTypes).Invoke(new object[0]));
Effect effect = step.CreateInstance();
effect.Services = Services;
effect.EnvironmentParameters = new EffectEnvironmentParameters(
step.PrimaryColor,
step.SecondaryColor,
EnvironmentParameters.BrushWidth,
Document.DefaultResolution,
selection,
EnvironmentParameters.SourceSurface);

Expand Down
2 changes: 2 additions & 0 deletions ScriptLab/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
Expand All @@ -12,6 +13,7 @@
[assembly: AssemblyCopyright("Copyright © 2007-2016 Zach Walker")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: SupportedOSPlatform("Windows")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
Expand Down
Loading