コード例 #1
0
        protected async Task EditParameter(IParameterValue parameterValue)
        {
            if (!parameterValue.BaseParameter.HasItems)
            {
                return;
            }

            if (parameterValue is ParameterValue <long> valueHolder)
            {
                var result = await itemFromListProvider.GetItemFromList(valueHolder.Parameter.Items,
                                                                        valueHolder.Parameter is FlagParameter, valueHolder.Value);

                if (result.HasValue)
                {
                    valueHolder.Value = result.Value;
                }
            }
            else if (parameterValue is ParameterValue <string> stringValueHolder)
            {
                var result = await itemFromListProvider.GetItemFromList(stringValueHolder.Parameter.Items,
                                                                        stringValueHolder.Parameter is MultiSwitchStringParameter, stringValueHolder.Value);

                if (result != null)
                {
                    stringValueHolder.Value = result;
                }
            }
        }
コード例 #2
0
        public GameobjectParameter(IDatabaseProvider database,
                                   IServerIntegration serverIntegration,
                                   IItemFromListProvider itemFromListProvider)
        {
            this.database  = database;
            SpecialCommand = async() =>
            {
                var entry = await serverIntegration.GetNearestGameObjects();

                if (entry == null || entry.Count == 0)
                {
                    return(null);
                }

                var options = entry.GroupBy(e => e.Entry)
                              .OrderBy(group => group.Key)
                              .ToDictionary(g => (long)g.Key,
                                            g => new SelectOption(database.GetGameObjectTemplate(g.Key)?.Name ?? "Unknown name",
                                                                  $"{g.First().Distance} yd away"));

                if (options.Count == 1)
                {
                    return((uint)options.Keys.First());
                }

                var pick = await itemFromListProvider.GetItemFromList(options, false);

                if (pick.HasValue)
                {
                    return((uint)pick.Value);
                }

                return(null);
            };
        }
コード例 #3
0
    private async Task <(long, bool)> FallbackPicker(long value)
    {
        var item = await itemFromListProvider.GetItemFromList(null, false, value, "Pick creature text group id");

        if (item.HasValue)
        {
            return(item.Value, true);
        }
        return(0, false);
    }
コード例 #4
0
    private async Task <(long, bool)> FallbackPicker(long value)
    {
        var item = await itemFromListProvider.GetItemFromList(null, false, value, "Pick gossip menu option");

        if (item.HasValue)
        {
            return(item.Value, true);
        }
        return(0, false);
    }
コード例 #5
0
 private void SelectItem()
 {
     if (Parameter.Items != null)
     {
         int?val = itemFromListProvider.GetItemFromList(Parameter.Items, Parameter is FlagParameter);
         if (val.HasValue)
         {
             Parameter.Value = val.Value;
         }
     }
 }
コード例 #6
0
 private void SelectItem()
 {
     if (Parameter.Parameter.Items != null)
     {
         if (Parameter is ParameterValueHolder <int> p)
         {
             int?val = itemFromListProvider.GetItemFromList(p.Parameter.Items, Parameter.Parameter is FlagParameter, p.Value);
             if (val.HasValue)
             {
                 p.Value = val.Value;
             }
         }
     }
 }
コード例 #7
0
        public async Task <ISolutionItem?> CreateSolutionItem()
        {
            var file = await windowManager.ShowOpenFileDialog("Sniff file|pkt,bin|Parsed packets (*.dat)|dat|All files|*");

            if (file == null)
            {
                return(null);
            }
            var items = Enum
                        .GetValues <ClientVersionBuild>()
                        .ToDictionary(v => (long)v, v => new SelectOption(v.ToString().Replace("V_", "").Replace("_", ".")));
            var version = await itemFromListProvider.GetItemFromList(items, false);

            if (version == null)
            {
                return(null);
            }
            return(new PacketDocumentSolutionItem(file, (int)version.Value));
        }
コード例 #8
0
        public ConditionsEditorViewModel(
            IConditionsFactory conditionsFactory,
            IConditionDataManager conditionDataManager,
            IItemFromListProvider itemFromListProvider,
            IHistoryManager historyManager,
            IEnumerable <ICondition>?conditions,
            int conditionSourceType)
        {
            this.conditionsFactory    = conditionsFactory;
            this.conditionDataManager = conditionDataManager;
            this.HistoryManager       = historyManager;

            ConditionTypes = conditionDataManager
                             .GetConditionGroups()
                             .SelectMany(group => group.Members)
                             .Where(conditionDataManager.HasConditionData)
                             .Select(conditionDataManager.GetConditionData)
                             .ToList();

            if (conditions != null)
            {
                int previousElseGroup = -1;
                foreach (var c in conditions)
                {
                    var vm = conditionsFactory.Create(conditionSourceType, c);
                    if (vm == null)
                    {
                        continue;
                    }

                    if (c.ElseGroup != previousElseGroup && previousElseGroup != -1)
                    {
                        Conditions.Add(conditionsFactory.CreateOr(conditionSourceType));
                    }

                    previousElseGroup = c.ElseGroup;
                    Conditions.Add(vm);
                }
            }

            Accept      = new DelegateCommand(() => CloseOk?.Invoke());
            Cancel      = new DelegateCommand(() => CloseCancel?.Invoke());
            PickCommand = new AsyncAutoCommand <ParameterValueHolder <long> >(async prh =>
            {
                if (!prh.HasItems)
                {
                    return;
                }

                var newItem = await itemFromListProvider.GetItemFromList(prh.Parameter.Items, prh.Parameter is FlagParameter, prh.Value);
                if (newItem.HasValue)
                {
                    prh.Value = newItem.Value;
                }
            });
            AddItemCommand = new DelegateCommand(() =>
            {
                int index = Conditions.Count;
                if (SelectedCondition != null)
                {
                    index = Conditions.IndexOf(SelectedCondition) + 1;
                }
                index = Math.Clamp(index, 0, Conditions.Count);

                Conditions.Insert(index, conditionsFactory.Create(conditionSourceType, 0) ?? conditionsFactory.CreateOr(conditionSourceType));
            });
            RemoveItemCommand = new DelegateCommand(() =>
            {
                if (SelectedCondition == null)
                {
                    return;
                }

                int indexOf = Conditions.IndexOf(SelectedCondition);
                if (indexOf != -1)
                {
                    Conditions.RemoveAt(indexOf);
                    if (indexOf - 1 >= 0 && Conditions.Count > 0)
                    {
                        SelectedCondition = Conditions[indexOf - 1];
                    }
                    else if (Conditions.Count > 0)
                    {
                        SelectedCondition = Conditions[indexOf];
                    }
                }
            }, () => SelectedCondition != null).ObservesProperty(() => SelectedCondition);
            CopyCommand = new DelegateCommand(() =>
            {
                if (SelectedCondition != null)
                {
                    Clipboard = SelectedCondition?.ToCondition(0);
                }
            }, () => SelectedCondition != null).ObservesProperty(() => SelectedCondition);
            CutCommand = new DelegateCommand(() =>
            {
                if (SelectedCondition != null)
                {
                    Clipboard = SelectedCondition?.ToCondition(0);
                    Conditions.Remove(SelectedCondition !);
                    SelectedCondition = null;
                }
            }, () => SelectedCondition != null).ObservesProperty(() => SelectedCondition);
            PasteCommand = new DelegateCommand(() =>
            {
                if (clipboard != null)
                {
                    int indexOf = Conditions.Count;
                    if (SelectedCondition != null)
                    {
                        indexOf = Conditions.IndexOf(SelectedCondition) + 1;
                    }
                    var item = conditionsFactory.Create(conditionSourceType, clipboard);
                    if (item != null)
                    {
                        Conditions.Insert(indexOf, item);
                    }
                }
            }, () => Clipboard != null).ObservesProperty(() => Clipboard);

            UndoCommand =
                new DelegateCommand(HistoryManager.Undo, () => HistoryManager.CanUndo).ObservesProperty(() =>
                                                                                                        HistoryManager.CanUndo);
            RedoCommand =
                new DelegateCommand(HistoryManager.Redo, () => HistoryManager.CanRedo).ObservesProperty(() =>
                                                                                                        HistoryManager.CanRedo);

            Watch(this, t => t.SelectedCondition, nameof(SelectedConditionsType));

            historyHandler = AutoDispose(new ConditionsEditorHistoryHandler(this, conditionsFactory));
            HistoryManager.AddHandler(historyHandler);
        }
コード例 #9
0
        private async Task <(long, bool)> FallbackPicker(long value)
        {
            var result = await itemFromListProvider.GetItemFromList(null, false, value, "Pick a " + name);

            return(result ?? 0, result.HasValue);
        }