Example #1
0
        private int addVersionDisplay()
        {
            int boxLeft        = Console.WindowWidth / 2 + 1,
                boxTop         = 3;
            const int boxRight = -1,
                      boxH     = 5;

            if (ChangePlan.IsAnyAvailable(registry, mod.identifier))
            {
                List <CkanModule> avail  = registry.AllAvailable(mod.identifier);
                CkanModule        inst   = registry.GetInstalledVersion(mod.identifier);
                CkanModule        latest = registry.LatestAvailable(mod.identifier, null);
                bool installed           = registry.IsInstalled(mod.identifier, false);
                bool latestIsInstalled   = inst?.Equals(latest) ?? false;
                List <CkanModule> others = avail;

                others.Remove(inst);
                others.Remove(latest);

                if (installed)
                {
                    DateTime?instTime = InstalledOn(mod.identifier);

                    if (latestIsInstalled)
                    {
                        addVersionBox(
                            boxLeft, boxTop, boxRight, boxTop + boxH - 1,
                            () => $"Latest/Installed {instTime?.ToString("d") ?? "manually"}",
                            () => ConsoleTheme.Current.ActiveFrameFg,
                            true,
                            new List <CkanModule>()
                        {
                            inst
                        }
                            );
                        boxTop += boxH;
                    }
                    else
                    {
                        addVersionBox(
                            boxLeft, boxTop, boxRight, boxTop + boxH - 1,
                            () => "Latest Version",
                            () => ConsoleTheme.Current.AlertFrameFg,
                            false,
                            new List <CkanModule>()
                        {
                            latest
                        }
                            );
                        boxTop += boxH;

                        addVersionBox(
                            boxLeft, boxTop, boxRight, boxTop + boxH - 1,
                            () => $"Installed {instTime?.ToString("d") ?? "manually"}",
                            () => ConsoleTheme.Current.ActiveFrameFg,
                            true,
                            new List <CkanModule>()
                        {
                            inst
                        }
                            );
                        boxTop += boxH;
                    }
                }
                else
                {
                    addVersionBox(
                        boxLeft, boxTop, boxRight, boxTop + boxH - 1,
                        () => "Latest Version",
                        () => ConsoleTheme.Current.NormalFrameFg,
                        false,
                        new List <CkanModule>()
                    {
                        latest
                    }
                        );
                    boxTop += boxH;
                }

                if (others.Count > 0)
                {
                    addVersionBox(
                        boxLeft, boxTop, boxRight, boxTop + boxH - 1,
                        () => "Other Versions",
                        () => ConsoleTheme.Current.NormalFrameFg,
                        false,
                        others
                        );
                    boxTop += boxH;
                }
            }
            else
            {
                DateTime?instTime = InstalledOn(mod.identifier);
                // Mod is no longer indexed, but we can generate a display
                // of the old info about it from when we installed it
                addVersionBox(
                    boxLeft, boxTop, boxRight, boxTop + boxH - 1,
                    () => $"UNAVAILABLE/Installed {instTime?.ToString("d") ?? "manually"}",
                    () => ConsoleTheme.Current.AlertFrameFg,
                    true,
                    new List <CkanModule>()
                {
                    mod
                }
                    );
                boxTop += boxH;
            }

            return(boxTop - 1);
        }
Example #2
0
        /// <summary>
        /// Initialize the Screen
        /// </summary>
        /// <param name="mgr">KSP manager containing game instances</param>
        /// <param name="cp">Plan of other mods to be added or removed</param>
        /// <param name="m">The module to display</param>
        /// <param name="dbg">True if debug options should be available, false otherwise</param>
        public ModInfoScreen(KSPManager mgr, ChangePlan cp, CkanModule m, bool dbg)
        {
            debug    = dbg;
            mod      = m;
            manager  = mgr;
            plan     = cp;
            registry = RegistryManager.Instance(manager.CurrentInstance).registry;

            int midL = Console.WindowWidth / 2 - 1;

            AddObject(new ConsoleLabel(
                          1, 1, -1,
                          () => mod.name == mod.identifier ? mod.name : $"{mod.name} ({mod.identifier})",
                          null,
                          () => ConsoleTheme.Current.ActiveFrameFg
                          ));
            AddObject(new ConsoleLabel(
                          1, 2, -1,
                          () => $"By {string.Join(", ", mod.author)}"
                          ));

            AddObject(new ConsoleFrame(
                          1, 3, midL, 7,
                          () => "",
                          () => ConsoleTheme.Current.NormalFrameFg,
                          false
                          ));
            AddObject(new ConsoleLabel(
                          3, 4, 11,
                          () => "License:",
                          null,
                          () => ConsoleTheme.Current.DimLabelFg
                          ));
            AddObject(new ConsoleLabel(
                          13, 4, midL - 2,
                          () => string.Join(", ", Array.ConvertAll <License, string>(
                                                mod.license.ToArray(), (l => l.ToString())))
                          ));
            AddObject(new ConsoleLabel(
                          3, 5, 12,
                          () => "Download:",
                          null,
                          () => ConsoleTheme.Current.DimLabelFg
                          ));
            AddObject(new ConsoleLabel(
                          13, 5, midL - 2,
                          () => CkanModule.FmtSize(mod.download_size)
                          ));
            AddObject(new ConsoleLabel(
                          3, 6, midL - 2,
                          HostedOn
                          ));

            int depsBot = addDependencies();
            int versBot = addVersionDisplay();

            AddObject(new ConsoleFrame(
                          1, Math.Max(depsBot, versBot) + 1, -1, -1,
                          () => "Description",
                          () => ConsoleTheme.Current.NormalFrameFg,
                          false
                          ));
            ConsoleTextBox tb = new ConsoleTextBox(
                3, Math.Max(depsBot, versBot) + 2, -3, -2, false,
                TextAlign.Left,
                () => ConsoleTheme.Current.MainBg,
                () => ConsoleTheme.Current.LabelFg
                );

            tb.AddLine(mod.@abstract);
            if (!string.IsNullOrEmpty(mod.description) &&
                mod.description != mod.@abstract)
            {
                tb.AddLine(mod.description);
            }
            AddObject(tb);
            if (!ChangePlan.IsAnyAvailable(registry, mod.identifier))
            {
                tb.AddLine("\r\nNOTE: This mod is installed but no longer available.");
                tb.AddLine("If you uninstall it, CKAN will not be able to re-install it.");
            }
            tb.AddScrollBindings(this);

            AddTip("Esc", "Back");
            AddBinding(Keys.Escape, (object sender) => false);

            AddTip("Ctrl+D", "Download",
                   () => !manager.Cache.IsMaybeCachedZip(mod)
                   );
            AddBinding(Keys.CtrlD, (object sender) => {
                Download();
                return(true);
            });

            if (mod.resources != null)
            {
                List <ConsoleMenuOption> opts = new List <ConsoleMenuOption>();

                if (mod.resources.homepage != null)
                {
                    opts.Add(new ConsoleMenuOption(
                                 "Home page", "", "Open the home page URL in a browser",
                                 true,
                                 () => LaunchURL(mod.resources.homepage)
                                 ));
                }
                if (mod.resources.repository != null)
                {
                    opts.Add(new ConsoleMenuOption(
                                 "Repository", "", "Open the repository URL in a browser",
                                 true,
                                 () => LaunchURL(mod.resources.repository)
                                 ));
                }
                if (mod.resources.bugtracker != null)
                {
                    opts.Add(new ConsoleMenuOption(
                                 "Bugtracker", "", "Open the bug tracker URL in a browser",
                                 true,
                                 () => LaunchURL(mod.resources.bugtracker)
                                 ));
                }
                if (mod.resources.spacedock != null)
                {
                    opts.Add(new ConsoleMenuOption(
                                 "SpaceDock", "", "Open the SpaceDock URL in a browser",
                                 true,
                                 () => LaunchURL(mod.resources.spacedock)
                                 ));
                }
                if (mod.resources.curse != null)
                {
                    opts.Add(new ConsoleMenuOption(
                                 "Curse", "", "Open the Curse URL in a browser",
                                 true,
                                 () => LaunchURL(mod.resources.curse)
                                 ));
                }
                if (debug)
                {
                    opts.Add(null);
                    opts.Add(new ConsoleMenuOption(
                                 "DEBUG: View metadata", "", "Display the full registry data for this mod",
                                 true,
                                 ViewMetadata
                                 ));
                }

                if (opts.Count > 0)
                {
                    mainMenu = new ConsolePopupMenu(opts);
                }
            }
        }