public static void TryRemove(ModButton mod)
 {
     _allButtons.TryRemove(mod);
     _activeButtons.TryRemove(mod);
     _availableButtons.TryRemove(mod);
     Notify_ModOrderChanged();
 }
Exemple #2
0
        private static FailReason Sort_Visit(ModButton node, Dictionary <ModButton, HashSet <ModButton> > graph, ref HashSet <
                                                 ModButton> done,
                                             ref HashSet <ModButton> progress)
        {
            if (done.Contains(node))
            {
                return(true);
            }
            if (progress.Contains(node))
            {
                return(node.Name);
            }

            progress.Add(node);
            foreach (var dep in graph[node])
            {
                var success = Sort_Visit(dep, graph, ref done, ref progress);
                if (!success)
                {
                    return(success.Reason ?? dep.Name);
                }
            }

            progress.Remove(node);
            Debug.Log(node.Name);
            done.Add(node);
            return(true);
        }
Exemple #3
0
        public static void ResolveCoreShouldLoadFirst(ModButton core)
        {
            var options = NewOptions;

            options.Add(new FloatMenuOption(I18n.MoveCoreToFirst, () => ModButtonManager.Insert(core, 0)));
            FloatMenu(options);
        }
 public static ModAttributes AttributesFor(ModButton button)
 {
     if (button is ModButton_Installed installed)
     {
         return(AttributesFor(installed.Selected));
     }
     return(null);
 }
Exemple #5
0
        public static void ResolveFindMod(
            string identifier,
            ModButton requester            = null,
            Version desired                = null,
            Dependency.EqualityOperator op = Dependency.EqualityOperator.GreaterEqual,
            Version current                = null,
            bool replace = false)
        {
            // find identifier in available
            var mods = ModButtonManager.AvailableMods
                       .Where(m => m.MatchesIdentifier(identifier))
                       .Where(m => m.VersionCompatible)
                       .Where(m => desired == null || Dependency.MatchesVersion(m, op, desired, true))
                       .Where(m => current == null || Manifest.For(m)?.Version > current)
                       .OrderByDescending(m => Manifest.For(m)?.Version);

            var options = NewOptions;

            if (mods.Any())
            {
                var insertIndex = requester != null
                    ? ModButtonManager.ActiveButtons.IndexOf(requester)
                    : ModButtonManager.ActiveButtons.Count;

                foreach (var mod in mods)
                {
                    options.Add(new FloatMenuOption(I18n.ActivateMod(mod), () =>
                    {
                        var button      = ModButton_Installed.For(mod);
                        button.Selected = mod;
                        ModButtonManager.Insert(button, insertIndex);
                        if (replace && requester != null && requester != button)
                        {
                            requester.Active = false;
                        }
                    }));
                }
            }
            else
            {
                if (desired != null)
                {
                    options.Add(new FloatMenuOption(I18n.NoMatchingModInstalled(identifier, desired, op), null));
                }
                else
                {
                    options.Add(new FloatMenuOption(I18n.NoMatchingModInstalled(identifier), null));
                }
            }
            if (requester is ModButton_Missing missing && missing.Identifier.IsSteamWorkshopIdentifier())
            {
                options.Add(SubscribeOption(missing.Name, missing.Identifier));
            }
            options.Add(WorkshopSearchOption(requester?.TrimmedName ?? identifier));
            options.Add(ForumSearchOption(requester?.TrimmedName ?? identifier));
            FloatMenu(options);
        }
Exemple #6
0
 public ModIssue(Severity severity, Subject subject, ModButton button, string targetId, string tip = null, Action resolver = null)
 {
     this.severity = severity;
     this.subject  = subject;
     this.button   = button;
     this.targetId = targetId;
     this.tip      = tip;
     this.resolver = resolver;
 }
Exemple #7
0
 public static void TryRemove(ModButton mod)
 {
     _allButtons.TryRemove(mod);
     if (_activeButtons.TryRemove(mod) && mod is ModButton_Installed installed)
     {
         Notify_ModListChanged();
     }
     _availableButtons.TryRemove(mod);
 }
Exemple #8
0
        public static void Update()
        {
            if (Dropped)
            {
                Dragged = null;
                Dropped = false;
                SoundDefOf.Tick_Low.PlayOneShotOnCamera();
            }

            if (Dragging && Event.current.type == EventType.MouseUp)
            {
                Dropped = true;
            }
        }
 public static void Insert(ModButton button, int to)
 {
     AvailableButtons.TryRemove(button);
     if (ActiveButtons.Contains(button))
     {
         if (ActiveButtons.IndexOf(button) < to)
         {
             to--;
         }
         ActiveButtons.Remove(button);
     }
     ActiveButtons.Insert(Mathf.Clamp(to, 0, ActiveButtons.Count), button);
     Notify_ModOrderChanged();
 }
 public static void Notify_Activated(ModButton mod, bool active)
 {
     if (active)
     {
         _availableButtons.TryRemove(mod);
         _activeButtons.TryAdd(mod);
         Notify_ModOrderChanged();
     }
     else
     {
         _activeButtons.TryRemove(mod);
         _availableButtons.TryAdd(mod);
         Notify_ModOrderChanged();
         SortAvailable();
     }
 }
Exemple #11
0
 public static void Insert(ModButton button, int to)
 {
     AllButtons.TryAdd(button);
     AvailableButtons.TryRemove(button);
     if (ActiveButtons.Contains(button))
     {
         if (ActiveButtons.IndexOf(button) < to)
         {
             to--;
         }
         ActiveButtons.Remove(button);
     }
     ActiveButtons.Insert(Mathf.Clamp(to, 0, ActiveButtons.Count), button);
     if (button is ModButton_Installed installed)
     {
         Notify_ModListChanged();
     }
 }
Exemple #12
0
 public static void TryAdd(ModButton button, bool notifyModListChanged = true)
 {
     _allButtons.TryAdd(button);
     if (button.Active)
     {
         _activeButtons.TryAdd(button);
         _availableButtons.TryRemove(button);
         if (notifyModListChanged && button is ModButton_Installed)
         {
             Notify_ModListChanged();
         }
     }
     else
     {
         _availableButtons.TryAdd(button);
         _activeButtons.TryRemove(button);
         SortAvailable();
     }
 }
Exemple #13
0
 internal virtual void HandleInteractions(Rect canvas, Action clickAction, Action doubleClickAction)
 {
     if (Mouse.IsOver(canvas))
     {
         Widgets.DrawHighlight(canvas);
         if (Event.current.type == EventType.mouseDown)
         {
             _focus = this;
             if (Event.current.clickCount == 2)
             {
                 doubleClickAction?.Invoke();
             }
         }
         if (Event.current.type == EventType.mouseUp && _focus == this)
         {
             clickAction?.Invoke();
         }
     }
 }
 public static void TryAdd(ModButton button, bool notify_orderChanged = true)
 {
     _allButtons.TryAdd(button);
     if (button.Active)
     {
         _activeButtons.TryAdd(button);
         _availableButtons.TryRemove(button);
         if (notify_orderChanged)
         {
             Notify_ModOrderChanged();
         }
     }
     else
     {
         _availableButtons.TryAdd(button);
         _activeButtons.TryRemove(button);
         SortAvailable();
     }
 }
Exemple #15
0
        public static bool ContainerUpdate <T>(IEnumerable <T> mods, Rect rect, out int index) where T : ModButton
        {
            index = -1;
            if (!Mouse.IsOver(rect))
            {
                return(false);
            }

            // get index of mousePosition
            var position = (Event.current.mousePosition.y - rect.yMin) / ModButtonHeight;

            // start drag
            var dragIndex        = Mathf.FloorToInt(position);
            var clampedDragIndex = Mathf.Clamp(dragIndex, 0, mods.Count() - 1);

            if (!Dragging && Event.current.type == EventType.MouseDrag && dragIndex == clampedDragIndex)
            {
                SoundDefOf.Tick_High.PlayOneShotOnCamera();
                Dragged = mods.ElementAt(clampedDragIndex);
            }

            if (Dragging)
            {
                var dropIndex        = Mathf.RoundToInt(position);
                var clampedDropIndex = Mathf.Clamp(dropIndex, 0, mods.Count());
                index = clampedDropIndex;

                // drop element into place
                if (Dropped)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #16
0
 public static ModIssue CoreNotFirst(ModButton core)
 {
     return(new ModIssue(Severity.Critical, Subject.LoadOrder, core, core.Identifier,
                         I18n.CoreNotFirst, () => Resolvers.ResolveCoreShouldLoadFirst(core)));
 }
Exemple #17
0
 public static void MoveBefore(ModButton from, ModButton to)
 {
     Insert(from, ActiveButtons.IndexOf(to));
 }
Exemple #18
0
 public static void MoveAfter(ModButton from, ModButton to)
 {
     Insert(from, ActiveButtons.IndexOf(to) + 1);
 }