// Macro Edit click private void Button_Click_37(object sender, RoutedEventArgs e) { Macro m = ((Button)sender).DataContext is Macro mac ? mac : this.LV_Macros.SelectedItems == null || this.LV_Macros.SelectedItems.Count == 0 ? null : (Macro)this.LV_Macros.SelectedItems[0]; if (m == null) { return; } byte[] arr; using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { m.Serialize(bw); } arr = ms.ToArray(); } EditMacroWindow emw = new EditMacroWindow(m); if (!emw.ShowDialog() ?? true) { using (MemoryStream ms = new MemoryStream(arr)) { using (BinaryReader br = new BinaryReader(ms)) { m.Deserialize(br); } } } }
// Add Macro Click private void Button_Click_35(object sender, RoutedEventArgs e) { EditMacroWindow emw = new EditMacroWindow(new Roll20.Macros.Macro() { Name = "New Macro", Description = "The macro description goes here." }); if (emw.ShowDialog() ?? false) { MacroSerializer.Macros.Add(emw.EditedMacro); } }
public void RecursivelyAddActions(EditMacroWindow win, TreeViewItem root, LinkedList <MacroAction> actions) { foreach (MacroAction ma in actions) { if (ma is MacroActionCondition mac) { TreeViewItem exp = new TreeViewItem { Header = MainWindow.Translate("Macro_Generic_Condition"), Tag = mac }; win.AssignConditionalExpressionMenu(exp); TreeViewItem conditions = new TreeViewItem { Header = MainWindow.Translate("Macro_Generic_If"), Tag = mac.If }; TreeViewItem thens = new TreeViewItem { Header = MainWindow.Translate("Macro_Generic_Then"), Tag = mac.Then }; TreeViewItem elses = new TreeViewItem { Header = MainWindow.Translate("Macro_Generic_Else"), Tag = mac.Else }; win.AssignIfConditionsMenu(conditions); win.AssignRootActionsMenu(thens); win.AssignRootActionsMenu(elses); exp.Items.Add(conditions); exp.Items.Add(thens); exp.Items.Add(elses); this.RecursivelyAddActions(win, conditions, mac.If); this.RecursivelyAddActions(win, thens, mac.Then); this.RecursivelyAddActions(win, elses, mac.Else); root.Items.Add(exp); } else { TreeViewItem tvi = new TreeViewItem() { Header = ma.CreateFullInnerText(), Tag = ma }; win.AssignGenericActionMenu(tvi); root.Items.Add(tvi); } } }
public void Populate(EditMacroWindow win, TreeViewItem links, TreeViewItem locals, TreeViewItem actions) { foreach (KeyValuePair <string, Guid> ilinks in this.ItemsLinked) { InventoryItem ii = AppState.Current.State.Inventory.Items.FirstOrDefault(i => i.ObjectID.Equals(ilinks.Value)); TreeViewItem tvi = new TreeViewItem() { Header = $"{ ilinks.Key }: {(ii == null ? MainWindow.Translate("Macro_Generic_Err_NoLink") : (ii.Name + "|" + ii.ObjectID.ToString()))}" }; tvi.Tag = new Tuple <string, bool, Guid>(ilinks.Key, true, ilinks.Value); win.AssignMenuToLink(tvi); links.Items.Add(tvi); } foreach (KeyValuePair <string, Guid> slinks in this.SpellsLinked) { Spell s = AppState.Current.State.Spellbook.AllSpells.FirstOrDefault(i => i.ObjectID.Equals(slinks.Value)); TreeViewItem tvi = new TreeViewItem() { Header = $"{ slinks.Key }: {(s == null ? MainWindow.Translate("Macro_Generic_Err_NoLink") : (s.Name + "|" + s.ObjectID.ToString()))}" }; tvi.Tag = new Tuple <string, bool, Guid>(slinks.Key, false, slinks.Value); win.AssignMenuToLink(tvi); links.Items.Add(tvi); } foreach (KeyValuePair <string, Tuple <int, int> > intLocal in this.NumberLocals) { TreeViewItem tvi = new TreeViewItem() { Header = $"{ MainWindow.Translate("Macro_Type_Number") } { intLocal.Key } = { intLocal.Value.Item2 }" }; win.AssignMenuToLocal(tvi); tvi.Tag = new Tuple <string, LocalType>(intLocal.Key, LocalType.Integer); locals.Items.Add(tvi); } foreach (KeyValuePair <string, Tuple <float, float> > floatLocal in this.RealLocals) { TreeViewItem tvi = new TreeViewItem() { Header = $"{ MainWindow.Translate("Macro_Type_Real") } { floatLocal.Key } = { floatLocal.Value.Item2 }" }; win.AssignMenuToLocal(tvi); tvi.Tag = new Tuple <string, LocalType>(floatLocal.Key, LocalType.Real); locals.Items.Add(tvi); } foreach (KeyValuePair <string, Tuple <bool, bool> > boolLocal in this.BoolLocals) { TreeViewItem tvi = new TreeViewItem() { Header = $"{ MainWindow.Translate("Macro_Type_Boolean") } { boolLocal.Key } = { boolLocal.Value.Item2 }" }; win.AssignMenuToLocal(tvi); tvi.Tag = new Tuple <string, LocalType>(boolLocal.Key, LocalType.Boolean); locals.Items.Add(tvi); } foreach (KeyValuePair <string, Tuple <string, string> > stringLocal in this.StringLocals) { TreeViewItem tvi = new TreeViewItem() { Header = $"{ MainWindow.Translate("Macro_Type_Text") } { stringLocal.Key } = { stringLocal.Value.Item2 }" }; win.AssignMenuToLocal(tvi); tvi.Tag = new Tuple <string, LocalType>(stringLocal.Key, LocalType.String); locals.Items.Add(tvi); } this.RecursivelyAddActions(win, actions, this.Actions); links.InvalidateVisual(); locals.InvalidateVisual(); actions.InvalidateVisual(); links.ExpandSubtree(); locals.ExpandSubtree(); actions.ExpandSubtree(); }
private void EditMacroCommandExecuted(object macroParameter) { EditMacroWindow editWindow = new EditMacroWindow(macroParameter); editWindow.ShowDialog(); }