public SaiHistoryHandler(SmartScriptBase script, ISmartFactory smartFactory) { this.script = script; this.smartFactory = smartFactory; this.script.Events.CollectionChanged += Events_CollectionChanged; this.script.BulkEditingStarted += OnBulkEditingStarted; this.script.BulkEditingFinished += OnBulkEditingFinished; variablesDisposable = this.script.GlobalVariables.ToStream().Subscribe(e => { if (e.Type == CollectionEventType.Add) { e.Item.CommentChanged += OnGlobalVariableCommentChanged; e.Item.VariableTypeChanged += OnGlobalVariableTypeChanged; e.Item.NameChanged += OnGlobalVariableNameChanged; e.Item.KeyChanged += OnGlobalVariableKeyChanged; } else { e.Item.CommentChanged -= OnGlobalVariableCommentChanged; e.Item.VariableTypeChanged -= OnGlobalVariableTypeChanged; e.Item.NameChanged -= OnGlobalVariableNameChanged; e.Item.KeyChanged -= OnGlobalVariableKeyChanged; } }); script.GlobalVariables.CollectionChanged += GlobalVariablesOnCollectionChanged; foreach (SmartEvent ev in this.script.Events) { BindEvent(ev); } }
public SmartScript(SmartScriptSolutionItem item, ISmartFactory smartFactory) { EntryOrGuid = item.Entry; SourceType = item.SmartType; Events = new ObservableCollection <SmartEvent>(); this.smartFactory = smartFactory; }
public TrinityCoreSmartScriptImporter(ISmartFactory smartFactory, ISmartDataManager smartDataManager, IMessageBoxService messageBoxService) { this.smartFactory = smartFactory; this.smartDataManager = smartDataManager; this.messageBoxService = messageBoxService; }
public SmartScript(ISmartScriptSolutionItem item, ISmartFactory smartFactory, ISmartDataManager smartDataManager, IMessageBoxService messageBoxService) : base(smartFactory, smartDataManager, messageBoxService) { EntryOrGuid = (int)item.Entry; SourceType = item.SmartType; }
public TrinityCoreSmartScriptExporter(ISmartFactory smartFactory, ISmartDataManager smartDataManager, ICurrentCoreVersion currentCoreVersion, IConditionQueryGenerator conditionQueryGenerator) { this.smartFactory = smartFactory; this.smartDataManager = smartDataManager; this.currentCoreVersion = currentCoreVersion; this.conditionQueryGenerator = conditionQueryGenerator; }
public TrinityCoreSmartScriptImporter(ISmartFactory smartFactory, ISmartDataManager smartDataManager, IMessageBoxService messageBoxService, IDatabaseProvider databaseProvider) { this.smartFactory = smartFactory; this.smartDataManager = smartDataManager; this.messageBoxService = messageBoxService; this.databaseProvider = databaseProvider; }
public SaiHistoryHandler(SmartScriptBase script, ISmartFactory smartFactory) { this.script = script; this.smartFactory = smartFactory; this.script.Events.CollectionChanged += Events_CollectionChanged; this.script.BulkEditingStarted += OnBulkEditingStarted; this.script.BulkEditingFinished += OnBulkEditingFinished; foreach (SmartEvent ev in this.script.Events) { BindEvent(ev); } }
public TrinityCoreSmartScriptExporter(ISmartFactory smartFactory, ISmartDataManager smartDataManager, ICurrentCoreVersion currentCoreVersion, ISolutionItemNameRegistry nameRegistry, IDatabaseProvider databaseProvider, IConditionQueryGenerator conditionQueryGenerator) { this.smartFactory = smartFactory; this.smartDataManager = smartDataManager; this.currentCoreVersion = currentCoreVersion; this.nameRegistry = nameRegistry; this.databaseProvider = databaseProvider; this.conditionQueryGenerator = conditionQueryGenerator; }
public SmartScriptEditorViewModel(SmartScriptSolutionItem item, IHistoryManager history, IDatabaseProvider database, IEventAggregator eventAggregator, ISmartDataManager smartDataManager, ISmartFactory smartFactory, IItemFromListProvider itemFromListProvider, ISmartTypeListProvider smartTypeListProvider, ISolutionItemNameRegistry itemNameRegistry) { _item = item; _history = history; this.database = database; this.smartDataManager = smartDataManager; this.smartFactory = smartFactory; this.itemFromListProvider = itemFromListProvider; this.smartTypeListProvider = smartTypeListProvider; this.itemNameRegistry = itemNameRegistry; var lines = database.GetScriptFor(_item.Entry, _item.SmartType); script = new SmartScript(_item, smartFactory); script.Load(lines); EditEvent = new DelegateCommand(EditEventCommand); EditAction = new DelegateCommand <SmartAction>(EditActionCommand); AddEvent = new DelegateCommand(AddEventCommand); AddAction = new DelegateCommand <SmartEvent>(AddActionCommand); SaveCommand = new DelegateCommand(SaveAllToDb); DeleteAction = new DelegateCommand <SmartAction>(DeleteActionCommand); DeleteEvent = new DelegateCommand(DeleteEventCommand); _history.AddHandler(new SaiHistoryHandler(script)); UndoCommand = new DelegateCommand(history.Undo, () => history.CanUndo); RedoCommand = new DelegateCommand(history.Redo, () => history.CanRedo); _history.PropertyChanged += (sender, args) => { UndoCommand.RaiseCanExecuteChanged(); RedoCommand.RaiseCanExecuteChanged(); }; eventAggregator.GetEvent <EventRequestGenerateSql>().Subscribe((args) => { if (args.Item is SmartScriptSolutionItem) { var itemm = args.Item as SmartScriptSolutionItem; if (itemm.Entry == _item.Entry && itemm.SmartType == _item.SmartType) { args.Sql = new SmartScriptExporter(script, smartFactory).GetSql(); } } }); }
public SmartScriptEditorProvider( ISolutionItemNameRegistry solutionItemNameRegistry, IHistoryManager historyManager, IDatabaseProvider databaseProvider, IEventAggregator eventAggregator, ISmartFactory smartFactory, IItemFromListProvider itemFromListProvider, SmartTypeListProvider smartTypeListProvider ) { this.solutionItemNameRegistry = solutionItemNameRegistry; this.historyManager = historyManager; this.databaseProvider = databaseProvider; this.eventAggregator = eventAggregator; this.smartFactory = smartFactory; this.itemFromListProvider = itemFromListProvider; this.smartTypeListProvider = smartTypeListProvider; }
public SmartScript(ISmartScriptSolutionItem item, ISmartFactory smartFactory, ISmartDataManager smartDataManager, IMessageBoxService messageBoxService) { this.smartFactory = smartFactory; this.smartDataManager = smartDataManager; this.messageBoxService = messageBoxService; EntryOrGuid = (int)item.Entry; SourceType = item.SmartType; Events = new ObservableCollection <SmartEvent>(); selectionHelper = new SmartSelectionHelper(this); selectionHelper.ScriptSelectedChanged += CallScriptSelectedChanged; AllSmartObjectsFlat = selectionHelper.AllSmartObjectsFlat; Events.ToStream() .Subscribe((e) => { if (e.Type == CollectionEventType.Add) { e.Item.Parent = this; } }); }
public TrinityCoreSmartScriptExporter(ISmartFactory smartFactory, ISmartDataManager smartDataManager) { this.smartFactory = smartFactory; this.smartDataManager = smartDataManager; }
public SmartScriptExporter(SmartScript script, ISmartFactory smartFactory) { _script = script; this.smartFactory = smartFactory; }
public static ISmartScriptLine[] ToWaitFreeSmartScriptLines(this SmartScript script, ISmartFactory smartFactory) { if (script.Events.Count == 0) { return(new ISmartScriptLine[0]); } int eventId = 0; List <ISmartScriptLine> lines = new List <ISmartScriptLine>(); bool previousWasWait = false; int nextTriggerId = script.Events.Where(e => e.Id == SmartConstants.EVENT_TRIGGER_TIMED).Select(e => e.GetParameter(0).Value).DefaultIfEmpty(0).Max() + 1; //@todo: don't use hardcoded IDs!!!! foreach (SmartEvent e in script.Events) { if (e.Actions.Count == 0) { continue; } e.ActualId = eventId; for (int index = 0; index < e.Actions.Count; ++index) { SmartEvent actualEvent = e; if (previousWasWait) { actualEvent = smartFactory.EventFactory(SmartConstants.EVENT_TRIGGER_TIMED); actualEvent.SetParameter(0, nextTriggerId++); } else if (index > 0) { actualEvent = smartFactory.EventFactory(SmartConstants.EVENT_LINK); } int linkTo = (e.Actions.Count - 1 == index ? 0 : eventId + 1); SmartAction actualAction = e.Actions[index]; if (actualAction.Id == SmartConstants.ACTION_WAIT) { linkTo = 0; SmartAction waitAction = actualAction; actualAction = smartFactory.ActionFactory(SmartConstants.ACTION_TRIGGER_TIMED, smartFactory.SourceFactory(SmartConstants.SOURCE_NONE), smartFactory.TargetFactory(SmartConstants.TARGET_NONE)); actualAction.SetParameter(0, nextTriggerId); actualAction.SetParameter(1, waitAction.GetParameter(0).GetValue()); actualAction.SetParameter(2, waitAction.GetParameter(0).GetValue()); actualAction.Comment = SmartConstants.COMMENT_WAIT; previousWasWait = true; } else { previousWasWait = false; } SmartEvent eventToSerialize = actualEvent.ShallowCopy(); eventToSerialize.Actions.Add(actualAction.Copy()); var serialized = eventToSerialize.ToSmartScriptLines(script.EntryOrGuid, script.SourceType, eventId, linkTo); if (serialized.Length != 1) { throw new InvalidOperationException(); } lines.Add(serialized[0]); eventId++; } } return(lines.ToArray()); }
public SmartScriptEditorViewModel(IHistoryManager history, IDatabaseProvider database, IEventAggregator eventAggregator, ISmartDataManager smartDataManager, ISmartFactory smartFactory, IItemFromListProvider itemFromListProvider, ISmartTypeListProvider smartTypeListProvider, IStatusBar statusbar, ISolutionItemNameRegistry itemNameRegistry) { this.history = history; this.database = database; this.smartDataManager = smartDataManager; this.smartFactory = smartFactory; this.itemFromListProvider = itemFromListProvider; this.smartTypeListProvider = smartTypeListProvider; this.statusbar = statusbar; this.itemNameRegistry = itemNameRegistry; EditEvent = new DelegateCommand(EditEventCommand); DeselectActions = new DelegateCommand(() => { foreach (var e in Events) { if (!e.IsSelected) { foreach (var a in e.Actions) { a.IsSelected = false; } } } }); DeselectAll = new DelegateCommand(() => { foreach (var e in Events) { foreach (var a in e.Actions) { a.IsSelected = false; } e.IsSelected = false; } }); DeselectAllEvents = new DelegateCommand(() => { foreach (var e in Events) { e.IsSelected = false; } }); OnDropItems = new DelegateCommand <int?>(destIndex => { using (script.BulkEdit("Reorder events")) { var selected = new List <SmartEvent>(); int d = destIndex.Value; for (int i = Events.Count - 1; i >= 0; --i) { if (Events[i].IsSelected) { if (i <= destIndex) { d--; } selected.Add(Events[i]); script.Events.RemoveAt(i); } } if (d == -1) { d = 0; } selected.Reverse(); foreach (var s in selected) { script.Events.Insert(d++, s); } } }); OnDropActions = new DelegateCommand <DropActionsArgs>(data => { using (script.BulkEdit("Reorder actions")) { var selected = new List <SmartAction>(); var d = data.ActionIndex; for (var eventIndex = 0; eventIndex < Events.Count; eventIndex++) { var e = Events[eventIndex]; for (int i = e.Actions.Count - 1; i >= 0; --i) { if (e.Actions[i].IsSelected) { if (eventIndex == data.EventIndex && i < data.ActionIndex) { d--; } selected.Add(e.Actions[i]); e.Actions.RemoveAt(i); } } } selected.Reverse(); foreach (var s in selected) { Events[data.EventIndex].Actions.Insert(d++, s); } } }); EditAction = new DelegateCommand <SmartAction>(action => EditActionCommand(action)); AddEvent = new DelegateCommand(AddEventCommand); AddAction = new DelegateCommand <NewActionViewModel>(AddActionCommand); SaveCommand = new AsyncAutoCommand(SaveAllToDb, null, e => { statusbar.PublishNotification(new PlainNotification(NotificationType.Error, "Error while saving script to the database: " + e.Message)); }); DeleteAction = new DelegateCommand <SmartAction>(DeleteActionCommand); DeleteSelected = new DelegateCommand(() => { if (anyEventSelected) { using (script.BulkEdit("Delete events")) { int?nextSelect = firstSelectedIndex; if (multipleEventsSelected) { nextSelect = null; } for (int i = Events.Count - 1; i >= 0; --i) { if (Events[i].IsSelected) { Events.RemoveAt(i); } } if (nextSelect.HasValue) { if (nextSelect.Value < Events.Count) { Events[nextSelect.Value].IsSelected = true; } else if (nextSelect.Value - 1 >= 0 && nextSelect.Value - 1 < Events.Count) { Events[nextSelect.Value - 1].IsSelected = true; } } } } else if (anyActionSelected) { using (script.BulkEdit("Delete actions")) { (int eventIndex, int actionIndex)? nextSelect = firstSelectedActionIndex; if (multipleActionsSelected) { nextSelect = null; } for (int i = 0; i < Events.Count; ++i) { var e = Events[i]; for (int j = e.Actions.Count - 1; j >= 0; --j) { if (e.Actions[j].IsSelected) { e.Actions.RemoveAt(j); } } } if (nextSelect.HasValue && nextSelect.Value.actionIndex < Events[nextSelect.Value.eventIndex].Actions.Count) { Events[nextSelect.Value.eventIndex].Actions[nextSelect.Value.actionIndex].IsSelected = true; } } } }); UndoCommand = new DelegateCommand(history.Undo, () => history.CanUndo); RedoCommand = new DelegateCommand(history.Redo, () => history.CanRedo); EditSelected = new DelegateCommand(() => { if (anyEventSelected) { if (!multipleEventsSelected) { EditEventCommand(); } } else if (anyActionSelected && !multipleActionsSelected) { EditActionCommand(Events[firstSelectedActionIndex.eventIndex] .Actions[firstSelectedActionIndex.actionIndex]); } }); CopyCommand = new DelegateCommand(() => { var selectedEvents = Events.Where(e => e.IsSelected).ToList(); if (selectedEvents.Count > 0) { var lines = string.Join("\n", selectedEvents.SelectMany((e, index) => e.ToSmartScriptLines(script.EntryOrGuid, script.SourceType, index)).Select(s => s.ToSqlString())); Clipboard.SetText(lines); } else { var selectedActions = Events.SelectMany(e => e.Actions).Where(e => e.IsSelected).ToList(); if (selectedActions.Count > 0) { var fakeEvent = new SmartEvent(-1) { ReadableHint = "" }; foreach (var a in selectedActions) { fakeEvent.AddAction(a.Copy()); } var lines = string.Join("\n", fakeEvent.ToSmartScriptLines(script.EntryOrGuid, script.SourceType, 0).Select(s => s.ToSqlString())); Clipboard.SetText(lines); } } }); CutCommand = new DelegateCommand(() => { CopyCommand.Execute(); DeleteSelected.Execute(); }); PasteCommand = new DelegateCommand(() => { var lines = (Clipboard.GetText() ?? "").Split('\n').Select(line => { if (line.TryToISmartScriptLine(out var s)) { return(s); } return(null); }).Where(l => l != null).ToList(); if (lines.Count > 0) { if (lines[0].EventType == -1) // actions { int?eventIndex = null; int?actionIndex = null; using (script.BulkEdit("Paste actions")) { for (int i = 0; i < Events.Count - 1; ++i) { if (Events[i].IsSelected) { eventIndex = i; } for (int j = Events[i].Actions.Count - 1; j >= 0; j--) { if (Events[i].Actions[j].IsSelected) { eventIndex = i; if (!actionIndex.HasValue) { actionIndex = j; } else { actionIndex--; } //Events[i].Actions.RemoveAt(j); } } } if (!eventIndex.HasValue) { eventIndex = Events.Count - 1; } if (eventIndex < 0) { return; } if (!actionIndex.HasValue) { actionIndex = Events[eventIndex.Value].Actions.Count - 1; } if (actionIndex < 0) { actionIndex = 0; } DeselectAll.Execute(); foreach (var smartAction in lines.Select(line => script.SafeActionFactory(line))) { Events[eventIndex.Value].Actions.Insert(actionIndex.Value, smartAction); smartAction.IsSelected = true; actionIndex++; } } } else { int?index = null; using (script.BulkEdit("Paste events")) { for (int i = Events.Count - 1; i >= 0; --i) { if (Events[i].IsSelected) { if (!index.HasValue) { index = i; } else { index--; } //Events.RemoveAt(i); } } if (!index.HasValue) { index = Events.Count; } script.InsertFromClipboard(index.Value, lines); } } } }); Action <bool, int> selectionUpDown = (addToSelection, diff) => { if (anyEventSelected) { var selectedEventIndex = Math.Clamp(firstSelectedIndex + diff, 0, Events.Count - 1); if (!addToSelection) { DeselectAll.Execute(); } Events[selectedEventIndex].IsSelected = true; } else if (anyActionSelected) { var nextActionIndex = firstSelectedActionIndex.actionIndex + diff; var nextEventIndex = firstSelectedActionIndex.eventIndex; while (nextActionIndex == -1 || nextActionIndex >= Events[nextEventIndex].Actions.Count) { nextEventIndex += diff; if (nextEventIndex >= 0 && nextEventIndex < Events.Count) { nextActionIndex = diff > 0 ? (Events[nextEventIndex].Actions.Count > 0 ? 0 : -1) : Events[nextEventIndex].Actions.Count - 1; } else { break; } } if (nextActionIndex != -1 && nextEventIndex >= 0 && nextEventIndex < Events.Count) { DeselectAll.Execute(); Events[nextEventIndex].Actions[nextActionIndex].IsSelected = true; } } else { if (Events.Count > 0) { Events[diff > 0 ? 0 : Events.Count - 1].IsSelected = true; } } }; SelectionUp = new DelegateCommand <bool?>(addToSelection => selectionUpDown(addToSelection ?? false, -1)); SelectionDown = new DelegateCommand <bool?>(addToSelection => selectionUpDown(addToSelection ?? false, 1)); SelectionLeft = new DelegateCommand(() => { if (!anyEventSelected && anyActionSelected) { var actionEventIndex = firstSelectedActionIndex; DeselectAll.Execute(); Events[actionEventIndex.eventIndex].IsSelected = true; } else if (!anyEventSelected && !anyActionSelected) { selectionUpDown(false, -1); } }); SelectionRight = new DelegateCommand(() => { if (!anyEventSelected) { selectionUpDown(false, -1); } if (anyEventSelected) { var eventIndex = firstSelectedIndex; if (Events[eventIndex].Actions.Count > 0) { DeselectAll.Execute(); Events[eventIndex].Actions[0].IsSelected = true; } } }); SelectAll = new DelegateCommand(() => { foreach (var e in Events) { e.IsSelected = true; } }); this.history.PropertyChanged += (sender, args) => { UndoCommand.RaiseCanExecuteChanged(); RedoCommand.RaiseCanExecuteChanged(); }; token = eventAggregator.GetEvent <EventRequestGenerateSql>().Subscribe((args) => { if (args.Item is SmartScriptSolutionItem) { var itemm = args.Item as SmartScriptSolutionItem; if (itemm.Entry == _item.Entry && itemm.SmartType == _item.SmartType) { args.Sql = new SmartScriptExporter(script, smartFactory).GetSql(); } } }); }
protected virtual void Start() { factory = SmartFactory.Instance; }