private void effectMenuItem_Click(object sender, EventArgs e) { ToolStripItem menuItem = sender as ToolStripMenuItem; string nativeClassName = menuItem.Tag as String; //-- 创建特效元素并添加到资源对象中 string elemName = ("SFX_" + DateTime.Now.ToFileTime()); NEffectElement newElem = NEffectElement.CreateEffectElement(nativeClassName, elemName); if (newElem == null) { return; } m_res.AddElement(newElem); m_preview.ShowSpecialEffect(m_res); m_preview.Refresh(); //-- 创建对应的控件 int numCtrl = m_elementsCtrl.Count; SFXElement newCtrl = new SFXElement(newElem); this.splitContainerV.Panel2.Controls.Add(newCtrl); newCtrl.Location = new Point(2 + numCtrl * (newCtrl.Width + 2), 2); int h = this.splitContainerV.Panel2.Height - 20; newCtrl.Height = h; m_elementsCtrl.Add(newCtrl); newCtrl.SetActive(true); newCtrl.RemoveElement += new EventHandler(OnRemoveElement); newCtrl.PropertySelected += new EventHandler(OnElementPropertySelected); newCtrl.PostPropertyEdit += new EventHandler(OnElementPostPropertyEdit); newCtrl.ActiveElement += new EventHandler(OnActiveElement); newCtrl.RestartInstance += new EventHandler(OnRestartInstance); }
void OnElementPostPropertyEdit(object sender, EventArgs e) { SFXElement elemCtrl = sender as SFXElement; NActorComponent comp = m_preview.ResourceActorComponent; NSpecialEffectInstance sfxComp = comp as NSpecialEffectInstance; if (sfxComp != null) { sfxComp.ResetResource(m_res); } }
void OnActiveElement(object sender, EventArgs e) { SFXElement elemCtrl = sender as SFXElement; if (elemCtrl.EditElement != null) { elemCtrl.EditElement.Visible = elemCtrl.IsActive(); } //-- 更新UI m_preview.Refresh(); }
void OnRestartInstance(object sender, EventArgs e) { SFXElement elemCtrl = sender as SFXElement; //-- 处理资源和渲染对象 NActorComponent comp = m_preview.ResourceActorComponent; NSpecialEffectInstance sfxComp = comp as NSpecialEffectInstance; if (sfxComp != null) { sfxComp.ResetResource(m_res); } }
private void openOToolStripMenuItem_Click(object sender, EventArgs e) { //打开特效 using (VirtualFileDialog dlg = new VirtualFileDialog()) { dlg.Text = "加载特效 ..."; if (dlg.ShowDialog(this) == DialogResult.OK) { NResourceLoc loc = dlg.GetResourceLocation(); m_res.Clear(); m_elementsCtrl.Clear(); m_Timeline.Clear(); this.splitContainerV.Panel2.Controls.Clear(); m_res.LoadFromFile(loc); //更新控制器 for (int i = 0; i < m_res.ElementCount(); ++i) { NEffectElement elem = m_res.GetElement(i); int numCtrl = m_elementsCtrl.Count; SFXElement newCtrl = new SFXElement(elem); this.splitContainerV.Panel2.Controls.Add(newCtrl); newCtrl.Location = new Point(2 + numCtrl * (newCtrl.Width + 2), 2); int h = this.splitContainerV.Panel2.Height - 20; newCtrl.Height = h; m_elementsCtrl.Add(newCtrl); newCtrl.SetActive(true); newCtrl.RemoveElement += new EventHandler(OnRemoveElement); newCtrl.PropertySelected += new EventHandler(OnElementPropertySelected); newCtrl.PostPropertyEdit += new EventHandler(OnElementPostPropertyEdit); newCtrl.ActiveElement += new EventHandler(OnActiveElement); newCtrl.RestartInstance += new EventHandler(OnRestartInstance); } NActorComponent comp = m_preview.ResourceActorComponent; NSpecialEffectInstance sfxComp = comp as NSpecialEffectInstance; if (sfxComp != null) { sfxComp.ResetResource(m_res); } m_preview.Refresh(); } } }
void OnRemoveElement(object sender, EventArgs e) { SFXElement elemCtrl = sender as SFXElement; //-- 处理资源和渲染对象 m_res.RemoveElement(elemCtrl.EditElement.Name); NActorComponent comp = m_preview.ResourceActorComponent; NSpecialEffectInstance sfxComp = comp as NSpecialEffectInstance; if (sfxComp != null) { sfxComp.ResetResource(m_res); } //-- 更新UI m_Timeline.Clear(); this.splitContainerV.Panel2.Controls.Clear(); m_elementsCtrl.Remove(elemCtrl); //更新控制器 for (int i = 0; i < m_res.ElementCount(); ++i) { NEffectElement elem = m_res.GetElement(i); int numCtrl = i; SFXElement newCtrl = new SFXElement(elem); this.splitContainerV.Panel2.Controls.Add(newCtrl); newCtrl.Location = new Point(2 + numCtrl * (newCtrl.Width + 2), 2); int h = this.splitContainerV.Panel2.Height - 20; newCtrl.Height = h; newCtrl.SetActive(true); newCtrl.RemoveElement += new EventHandler(OnRemoveElement); newCtrl.PropertySelected += new EventHandler(OnElementPropertySelected); newCtrl.PostPropertyEdit += new EventHandler(OnElementPostPropertyEdit); newCtrl.ActiveElement += new EventHandler(OnActiveElement); newCtrl.RestartInstance += new EventHandler(OnRestartInstance); } m_preview.Refresh(); }
void OnElementPropertySelected(object sender, EventArgs e) { SFXElement senderSFX = sender as SFXElement; SelectedGridItemChangedEventArgs se = e as SelectedGridItemChangedEventArgs; object value = se.NewSelection.Value; if (value == null) { return; } string name = se.NewSelection.Label; this.propertyGridDist.SelectedObject = value; this.propertyGridDist.Text = name; Type valueType = value.GetType(); Type baseType = valueType.BaseType; bool isDist = valueType.IsSubclassOf(typeof(NexusEngine.NDistribution)); if (isDist) { this.groupBoxObject.Text = se.NewSelection.Label; this.groupBoxObject.Tag = senderSFX.EditElement; this.comboBoxType.Items.Clear(); int sel = 0; foreach (Type t in m_distributionClasses) { if (t.IsSubclassOf(baseType)) { this.comboBoxType.Items.Add(t.Name); if (t.Name == valueType.Name) { sel = this.comboBoxType.Items.Count - 1; } } } this.comboBoxType.SelectedIndex = sel; if (valueType == typeof(NexusEngine.NDistributionFloatCurve)) { FloatCurve item = new FloatCurve(); item.Name = name; item.Bind((NexusEngine.NDistributionFloatCurve)value); m_Timeline.AddItem(item); } else if (valueType == typeof(NexusEngine.NDistributionVector2Curve)) { VectorCurve2 item = new VectorCurve2(); item.Name = name; item.Bind((NexusEngine.NDistributionVector2Curve)value); m_Timeline.AddItem(item); } else if (valueType == typeof(NexusEngine.NDistributionVector3Curve)) { VectorCurve3 item = new VectorCurve3(); item.Name = name; item.Bind((NexusEngine.NDistributionVector3Curve)value); m_Timeline.AddItem(item); } else if (valueType == typeof(NexusEngine.NDistributionColorCurve)) { ColorCurve item = new ColorCurve(); item.Name = name; item.Bind((NexusEngine.NDistributionColorCurve)value); m_Timeline.AddItem(item); } else { m_Timeline.Clear(); } } else { m_Timeline.Clear(); } this.splitContainerH.Panel2.Enabled = isDist; }