Skip to content

Commit

Permalink
DOTK : fixed effects copy from EditionTable & effects/TE deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Vroonsh committed Feb 17, 2021
1 parent 045edd7 commit 8c30f7f
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 24 deletions.
6 changes: 3 additions & 3 deletions DirectOutput/FX/EffectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public virtual void SetAssignedToy(IToy toy) { }
/// <summary>
/// Will populate a List with all effects from an effect hierarchy
/// </summary>
/// <param name="Effects">a List of effets to fill</param>
public virtual void GetAllEffects(List<IEffect> Effects)
/// <returns>an array containing all effects</returns>
public virtual IEffect[] GetAllEffects()
{
Effects.Add(this);
return new IEffect[] { this };
}
}
}
13 changes: 9 additions & 4 deletions DirectOutput/FX/EffectEffectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,17 @@ public override void SetAssignedToy(IToy toy)
/// <summary>
/// Will populate a List with all effects from an effect hierarchy
/// </summary>
/// <param name="Effects">a List of effets to fill</param>
public override void GetAllEffects(List<IEffect> Effects)
/// <returns>an array containing all effects</returns>
public override IEffect[] GetAllEffects()
{
Effects.Add(this);
if (TargetEffect != null) {
TargetEffect.GetAllEffects(Effects);
var targeteffects = TargetEffect.GetAllEffects();
var effects = new IEffect[targeteffects.Length + 1];
effects[0] = this;
targeteffects.CopyTo(effects, 1);
return effects;
} else {
return new IEffect[] { this };
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions DirectOutput/FX/IEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public interface IEffect:INamedItem
/// <summary>
/// Will populate a List with all effects from an effect hierarchy
/// </summary>
/// <param name="Effects">a List of effets to fill</param>
void GetAllEffects(List<IEffect> Effects);
/// <returns>an array containing all effects</returns>
IEffect[] GetAllEffects();
}
}
9 changes: 5 additions & 4 deletions DirectOutputToolkit/Forms/DirectOutputToolkitForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 37 additions & 4 deletions DirectOutputToolkit/Forms/DirectOutputToolkitForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public DirectOutputToolkitForm()
privateDoubleBuffered.SetValue(treeViewEditionTable, true);
privateDoubleBuffered.SetValue(treeViewReferenceTable, true);

treeViewEditionTable.ShowNodeToolTips = true;

treeViewReferenceTable.ImageList = imageListIcons;
treeViewReferenceTable.FullRowSelect = true;
treeViewReferenceTable.HideSelection = false;
Expand Down Expand Up @@ -290,14 +292,14 @@ private void DeleteEffectNode(EffectTreeNode node, bool silent = false)
if (silent || MessageBox.Show($"Do you want to delete effect {node.Text} from {(node.Parent as TableElementTreeNode)?.TE.Name} ?", "Delete Effect", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) {
if (node.Parent is TableElementTreeNode TENode) {
TENode.TE.AssignedEffects.RemoveAll(AE => AE.Effect == node.Effect);
Handler.RemoveEffects(new List<IEffect> { node.Effect }, (node.Parent as TableElementTreeNode)?.TE, node.GetTableType());
Handler.RemoveEffects(node.Effect.GetAllEffects(), (node.Parent as TableElementTreeNode)?.TE, node.GetTableType());
if (!silent) {
TENode.Rebuild(Handler);
SetCurrentSelectedNode(TENode);
}
} else if (node.Parent is StaticEffectsTreeNode staticEffectsNode) {
EditionTableNode.EditionTable.AssignedStaticEffects.RemoveAll(AE => AE.Effect == node.Effect);
Handler.RemoveEffects(new List<IEffect> { node.Effect }, null, node.GetTableType());
Handler.RemoveEffects(node.Effect.GetAllEffects(), null, node.GetTableType());
if (!silent) {
staticEffectsNode.Rebuild(Handler);
SetCurrentSelectedNode(staticEffectsNode);
Expand Down Expand Up @@ -721,15 +723,15 @@ private void OnCopyEffectToEditor(object sender, EventArgs e)
if (targetTENodes.Count > 0) {
foreach(var node in targetTENodes) {
var newEffectNode = new EffectTreeNode(node.TE, DirectOutputToolkitHandler.ETableType.EditionTable, SrcEffectNode.Effect, Handler);
newEffectNode.Rebuild(Handler, null);
newEffectNode.Rebuild(Handler, SrcEffectNode.Effect);
parentTE.AssignedEffects.Init(EditionTable);
TENode.Nodes.Add(newEffectNode);
TENode.Rebuild(Handler);
SetCurrentSelectedNode(TENode);
}
} else {
var newEffectNode = new EffectTreeNode(null, DirectOutputToolkitHandler.ETableType.EditionTable, SrcEffectNode.Effect, Handler);
newEffectNode.Rebuild(Handler, null);
newEffectNode.Rebuild(Handler, SrcEffectNode.Effect);
EditionTable.AssignedStaticEffects.Init(EditionTable);
EditionTableNode.StaticEffectsNode.Rebuild(Handler);
SetCurrentSelectedNode(EditionTableNode.StaticEffectsNode);
Expand Down Expand Up @@ -891,6 +893,37 @@ private void ShowContextMenu(TreeView treeview, TreeNode treeNode, Point locatio
}
}
}

bool ShowDebugNodes = false;
ToolTip DebugNodeTooltip = new ToolTip() { InitialDelay = 500 };

private void treeViewEditionTable_MouseMove(object sender, MouseEventArgs e)
{
if (!ShowDebugNodes) return;

var hit = treeViewEditionTable.HitTest(e.X, e.Y);
if (hit.Node == null) {
DebugNodeTooltip.Hide(this);
} else {
var message = string.Empty;

if (hit.Node is EditionTableTreeNode tableNode) {
message = $"{tableNode.EditionTable.AssignedStaticEffects.Count} static effects\n" +
$"{tableNode.EditionTable.Effects.Count} effects\n" +
$"{string.Join("\n", tableNode.EditionTable.Effects.Select(E => E.Name))}" +
$"{tableNode.EditionTable.TableElements.Count} tableElements\n" +
$"{tableNode.EditionTable.Bitmaps.Count} bitmaps";
}

if (message != string.Empty) {
DebugNodeTooltip.Show(message, this, e.Location.X + 10, e.Location.Y);
} else {
DebugNodeTooltip.Hide(this);
}
}


}
#endregion

}
Expand Down
2 changes: 1 addition & 1 deletion DirectOutputToolkit/Forms/DirectOutputToolkitForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD0
CAAAAk1TRnQBSQFMAgEBAgEAAUABAgFAAQIBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CAAAAk1TRnQBSQFMAgEBAgEAAVABAgFQAQIBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
Expand Down
4 changes: 2 additions & 2 deletions DirectOutputToolkit/Handler/DirectOutputToolkitHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ internal void InitEffect(AssignedEffect eff, ETableType tableType)
eff.Init(TableDescriptors[tableType].Table);
}

internal void RemoveEffects(List<IEffect> allEffects, TableElement parentTE, ETableType tableType)
internal void RemoveEffects(IEffect[] effects, TableElement parentTE, ETableType tableType)
{
ResetRunnigTableElement(parentTE);
var Table = TableDescriptors[tableType].Table;
foreach (var eff in allEffects) {
foreach (var eff in effects) {
Table.Effects.RemoveAll(E=> E == eff);
Table.AssignedStaticEffects.RemoveAll(AE => AE.Effect == eff);
foreach (var TE in Table.TableElements) {
Expand Down
9 changes: 5 additions & 4 deletions DirectOutputToolkit/TreeNodes/EffectTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public void Rebuild(DirectOutputToolkitHandler Handler, IEffect SrcEffect)
var RefEffect = SrcEffect != null ? SrcEffect : Effect;

//rebuild Effect
List<IEffect> allEffects = new List<IEffect>();
RefEffect.GetAllEffects(allEffects);
var allEffects = RefEffect.GetAllEffects();

//Retrieve necessary data for the Configurator directly from the effect name
int LedWizNumber, TCCNumber, SettingNumber;
Expand All @@ -86,8 +85,10 @@ public void Rebuild(DirectOutputToolkitHandler Handler, IEffect SrcEffect)
//Retrieve Toy & TCCNumber from Chosen Output
var Toy = RefEffect.GetAssignedToy();

//Remove all effects from Table & AssignedEffects before rebuilding
Handler.RemoveEffects(allEffects, (Parent as TableElementTreeNode)?.TE, _TableType);
//Remove all effects from Table & AssignedEffects before rebuilding if we're using our own effect as reference
if (SrcEffect == null) {
Handler.RemoveEffects(allEffects, (Parent as TableElementTreeNode)?.TE, _TableType);
}

// The create effect will add the effects to the provided Table & TebleElements' assigned effects
var newEffect = Handler.CreateEffect(TCS, TCCNumber, SettingNumber, _TableType, Toy, LedWizNumber);
Expand Down

0 comments on commit 8c30f7f

Please sign in to comment.