Пример #1
0
        public override void OnOpen()
        {
            base.OnOpen();

            if (this.dalamud.PluginRepository.State != PluginRepository.InitializationState.InProgress)
            {
                this.dalamud.PluginRepository.ReloadPluginMasterAsync();
            }

            this.pluginListAvailable = null;
            this.pluginListInstalled = null;
            this.updateComplete      = false;
            this.updatePluginCount   = 0;
            this.updatedPlugins      = null;
            this.searchText          = string.Empty;
            this.sortKind            = PluginSortKind.Alphabetical;
            this.filterText          = Loc.Localize("SortAlphabetical", "Alphabetical");
        }
Пример #2
0
        /// <summary>
        /// Draw the plugin installer view ImGui.
        /// </summary>
        public override void Draw()
        {
            ImGui.SetCursorPosY(ImGui.GetCursorPosY() - (5 * ImGui.GetIO().FontGlobalScale));
            var descriptionText = Loc.Localize("InstallerHint", "This window allows you to install and remove in-game plugins.\nThey are made by third-party developers.");

            ImGui.Text(descriptionText);

            var sortingTextSize = ImGui.CalcTextSize(Loc.Localize("SortDownloadCounts", "Download Count")) + ImGui.CalcTextSize(Loc.Localize("PluginSort", "Sort By"));

            ImGui.SameLine(ImGui.GetWindowWidth() - sortingTextSize.X - ((250 + 20) * ImGui.GetIO().FontGlobalScale));
            ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (ImGui.CalcTextSize(descriptionText).Y / 4) - 2);
            ImGui.SetCursorPosX(ImGui.GetWindowWidth() - sortingTextSize.X - ((250 + 20) * ImGui.GetIO().FontGlobalScale));

            ImGui.SetNextItemWidth(240 * ImGui.GetIO().FontGlobalScale);
            ImGui.InputTextWithHint("###XPlPluginInstaller_Search", Loc.Localize("InstallerSearch", "Search"), ref this.searchText, 100);

            ImGui.SameLine();
            ImGui.SetNextItemWidth((10 * ImGui.GetIO().FontGlobalScale) + ImGui.CalcTextSize(Loc.Localize("SortDownloadCounts", "Download Count")).X);
            if (ImGui.BeginCombo(Loc.Localize("PluginSort", "Sort By"), this.filterText, ImGuiComboFlags.NoArrowButton))
            {
                if (ImGui.Selectable(Loc.Localize("SortAlphabetical", "Alphabetical")))
                {
                    this.sortKind   = PluginSortKind.Alphabetical;
                    this.filterText = Loc.Localize("SortAlphabetical", "Alphabetical");

                    this.ResortPlugins();
                }

                if (ImGui.Selectable(Loc.Localize("SortDownloadCounts", "Download Count")))
                {
                    this.sortKind   = PluginSortKind.DownloadCount;
                    this.filterText = Loc.Localize("SortDownloadCounts", "Download Count");

                    this.ResortPlugins();
                }

                if (ImGui.Selectable(Loc.Localize("SortLastUpdate", "Last Update")))
                {
                    this.sortKind   = PluginSortKind.LastUpdate;
                    this.filterText = Loc.Localize("SortLastUpdate", "Last Update");

                    this.ResortPlugins();
                }

                ImGui.EndCombo();
            }

            ImGui.SetCursorPosY(ImGui.GetCursorPosY() - (5 * ImGui.GetIO().FontGlobalScale));

            string initializationStatusText = null;

            if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.InProgress)
            {
                initializationStatusText = Loc.Localize("InstallerLoading", "Loading plugins...");
                this.pluginListAvailable = null;
            }
            else if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.Fail)
            {
                initializationStatusText = Loc.Localize("InstallerDownloadFailed", "Download failed.");
                this.pluginListAvailable = null;
            }
            else if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.FailThirdRepo)
            {
                initializationStatusText = Loc.Localize("InstallerDownloadFailedThird", "One of your third party repos is unreachable or there is no internet connection.");
                this.pluginListAvailable = null;
            }
            else
            {
                if (this.pluginListAvailable == null)
                {
                    this.RefetchPlugins();
                }
            }

            ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(1, 3) * ImGui.GetIO().FontGlobalScale);

            if (ImGui.BeginTabBar("PluginsTabBar", ImGuiTabBarFlags.NoTooltip))
            {
                this.DrawTab(false, initializationStatusText);
                this.DrawTab(true, initializationStatusText);

                ImGui.EndTabBar();
                ImGui.Separator();
            }

            ImGui.PopStyleVar();

            ImGui.Dummy(new Vector2(3f, 3f) * ImGui.GetIO().FontGlobalScale);

            if (this.installStatus == PluginInstallStatus.InProgress)
            {
                ImGui.Button(Loc.Localize("InstallerUpdating", "Updating..."));
            }
            else
            {
                if (this.updateComplete)
                {
                    ImGui.Button(this.updatePluginCount == 0
                                     ? Loc.Localize("InstallerNoUpdates", "No updates found!")
                                     : string.Format(Loc.Localize("InstallerUpdateComplete", "{0} plugins updated!"), this.updatePluginCount));
                }
                else
                {
                    if (ImGui.Button(Loc.Localize("InstallerUpdatePlugins", "Update plugins")) &&
                        this.dalamud.PluginRepository.State == PluginRepository.InitializationState.Success)
                    {
                        this.installStatus = PluginInstallStatus.InProgress;

                        Task.Run(() => this.dalamud.PluginRepository.UpdatePlugins()).ContinueWith(t =>
                        {
                            this.installStatus =
                                t.Result.Success ? PluginInstallStatus.Success : PluginInstallStatus.Fail;
                            this.installStatus =
                                t.IsFaulted ? PluginInstallStatus.Fail : this.installStatus;

                            if (this.installStatus == PluginInstallStatus.Success)
                            {
                                this.updateComplete = true;
                            }

                            if (t.Result.UpdatedPlugins != null)
                            {
                                this.updatePluginCount = t.Result.UpdatedPlugins.Count;
                                this.updatedPlugins    = t.Result.UpdatedPlugins;
                            }

                            this.errorModalDrawing     = this.installStatus == PluginInstallStatus.Fail;
                            this.errorModalOnNextFrame = this.installStatus == PluginInstallStatus.Fail;

                            this.dalamud.PluginRepository.PrintUpdatedPlugins(
                                this.updatedPlugins, Loc.Localize("DalamudPluginUpdates", "Updates:"));

                            this.RefetchPlugins();
                        });
                    }
                }
            }

            ImGui.SameLine();

            if (ImGui.Button(Loc.Localize("SettingsInstaller", "Settings")))
            {
                this.dalamud.DalamudUi.OpenSettings();
            }

            var closeText = Loc.Localize("Close", "Close");

            ImGui.SameLine(ImGui.GetWindowWidth() - ImGui.CalcTextSize(closeText).X - (16 * ImGui.GetIO().FontGlobalScale));
            if (ImGui.Button(closeText))
            {
                this.IsOpen = false;
                this.dalamud.Configuration.Save();
            }

            if (ImGui.BeginPopupModal(Loc.Localize("InstallerError", "Installer failed"), ref this.errorModalDrawing, ImGuiWindowFlags.AlwaysAutoResize))
            {
                var message = Loc.Localize(
                    "InstallerErrorHint",
                    "The plugin installer ran into an issue or the plugin is incompatible.\nPlease restart the game and report this error on our discord.");

                if (this.updatedPlugins != null)
                {
                    if (this.updatedPlugins.Any(x => x.WasUpdated == false))
                    {
                        var extraInfoMessage = Loc.Localize(
                            "InstallerErrorPluginInfo",
                            "\n\nThe following plugins caused these issues:\n\n{0}\nYou may try removing these plugins manually and reinstalling them.");

                        var insert = this.updatedPlugins.Where(x => x.WasUpdated == false)
                                     .Aggregate(
                            string.Empty,
                            (current, pluginUpdateStatus) =>
                            current + $"* {pluginUpdateStatus.InternalName}\n");
                        extraInfoMessage = string.Format(extraInfoMessage, insert);
                        message         += extraInfoMessage;
                    }
                }

                ImGui.Text(message);

                ImGui.Spacing();

                if (ImGui.Button(Loc.Localize("OK", "OK"), new Vector2(120, 40)))
                {
                    ImGui.CloseCurrentPopup();
                }

                ImGui.EndPopup();
            }

            if (this.errorModalOnNextFrame)
            {
                ImGui.OpenPopup(Loc.Localize("InstallerError", "Installer failed"));
                this.errorModalOnNextFrame = false;
            }
        }
Пример #3
0
        public bool Draw()
        {
            var windowOpen = true;

            ImGui.SetNextWindowSize(new Vector2(810, 520) * ImGui.GetIO().FontGlobalScale);

            ImGui.Begin(Loc.Localize("InstallerHeader", "Plugin Installer") + (this.dalamud.Configuration.DoPluginTest ? " (TESTING)" : string.Empty) + "###XlPluginInstaller", ref windowOpen,
                        ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoScrollbar);

            ImGui.Text(Loc.Localize("InstallerHint", "This window allows you install and remove in-game plugins.\nThey are made by third-party developers."));

            ImGui.SameLine(ImGui.GetWindowWidth() - ((250 + 20 + ImGui.CalcTextSize(Loc.Localize("SortDownloadCounts", "Download Count")).X + ImGui.CalcTextSize(Loc.Localize("PluginSort", "Sort By")).X) * ImGui.GetIO().FontGlobalScale));

            ImGui.SetNextItemWidth(240 * ImGui.GetIO().FontGlobalScale);
            ImGui.InputTextWithHint("###XPlPluginInstaller_Search", Loc.Localize("InstallerSearch", "Search"), ref this.searchText, 100);

            ImGui.SameLine();
            ImGui.SetNextItemWidth(10 + (ImGui.CalcTextSize(Loc.Localize("SortDownloadCounts", "Download Count")).X) * ImGui.GetIO().FontGlobalScale);
            if (ImGui.BeginCombo(Loc.Localize("PluginSort", "Sort By"), this.filterText, ImGuiComboFlags.NoArrowButton))
            {
                if (ImGui.Selectable(Loc.Localize("SortAlphabetical", "Alphabetical")))
                {
                    this.sortKind   = PluginSortKind.Alphabetical;
                    this.filterText = Loc.Localize("SortAlphabetical", "Alphabetical");

                    ResortAvailable();
                }

                if (ImGui.Selectable(Loc.Localize("SortDownloadCounts", "Download Count")))
                {
                    this.sortKind   = PluginSortKind.DownloadCount;
                    this.filterText = Loc.Localize("SortDownloadCounts", "Download Count");

                    ResortAvailable();
                }

                if (ImGui.Selectable(Loc.Localize("SortLastUpdate", "Last Update")))
                {
                    this.sortKind   = PluginSortKind.LastUpdate;
                    this.filterText = Loc.Localize("SortLastUpdate", "Last Update");

                    ResortAvailable();
                }

                ImGui.EndCombo();
            }

            ImGui.BeginChild("scrolling", new Vector2(0, 400 * ImGui.GetIO().FontGlobalScale), true, ImGuiWindowFlags.HorizontalScrollbar);

            ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(1, 3) * ImGui.GetIO().FontGlobalScale);

            if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.InProgress)
            {
                ImGui.Text(Loc.Localize("InstallerLoading", "Loading plugins..."));
            }
            else if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.Fail)
            {
                ImGui.Text(Loc.Localize("InstallerDownloadFailed", "Download failed."));
            }
            else if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.FailThirdRepo)
            {
                ImGui.Text(Loc.Localize("InstallerDownloadFailedThird", "One of your third party repos is unreachable or there is no internet connection."));
            }
            else
            {
                if (this.pluginListAvailable == null)
                {
                    var hiddenPlugins = this.dalamud.PluginManager.Plugins.Where(
                        x => this.dalamud.PluginRepository.PluginMaster.All(
                            y => y.InternalName != x.Definition.InternalName || y.InternalName == x.Definition.InternalName && y.IsHide)).Select(x => x.Definition).ToList();
                    this.pluginListInstalled = this.dalamud.PluginRepository.PluginMaster
                                               .Where(def => {
                        return(this.dalamud.PluginManager.Plugins.Where(x => x.Definition != null).Any(
                                   x => x.Definition.InternalName == def.InternalName));
                    })
                                               .ToList();
                    this.pluginListInstalled.AddRange(hiddenPlugins);
                    this.pluginListInstalled.Sort((x, y) => x.Name.CompareTo(y.Name));

                    ResortAvailable();
                }

                ImGui.TextColored(this.colorGrey,
                                  Loc.Localize("InstallerAvailablePluginList",
                                               "Available Plugins:"));
                DrawPluginList(this.pluginListAvailable, false);

                ImGui.Dummy(new Vector2(5, 5));
                ImGui.Separator();
                ImGui.Dummy(new Vector2(5, 5));

                ImGui.TextColored(this.colorGrey,
                                  Loc.Localize("InstallerInstalledPluginList",
                                               "Installed Plugins:"));
                DrawPluginList(this.pluginListInstalled, true);
            }

            ImGui.PopStyleVar();

            ImGui.EndChild();

            ImGui.Separator();

            if (this.installStatus == PluginInstallStatus.InProgress)
            {
                ImGui.Button(Loc.Localize("InstallerUpdating", "Updating..."));
            }
            else
            {
                if (this.updateComplete)
                {
                    ImGui.Button(this.updatePluginCount == 0
                                     ? Loc.Localize("InstallerNoUpdates", "No updates found!")
                                     : string.Format(Loc.Localize("InstallerUpdateComplete", "{0} plugins updated!"), this.updatePluginCount));
                }
                else
                {
                    if (ImGui.Button(Loc.Localize("InstallerUpdatePlugins", "Update plugins")))
                    {
                        this.installStatus = PluginInstallStatus.InProgress;

                        Task.Run(() => this.dalamud.PluginRepository.UpdatePlugins()).ContinueWith(t => {
                            this.installStatus =
                                t.Result.Success ? PluginInstallStatus.Success : PluginInstallStatus.Fail;
                            this.installStatus =
                                t.IsFaulted ? PluginInstallStatus.Fail : this.installStatus;

                            if (this.installStatus == PluginInstallStatus.Success)
                            {
                                this.updateComplete = true;
                            }

                            if (t.Result.UpdatedPlugins != null)
                            {
                                this.updatePluginCount = t.Result.UpdatedPlugins.Count;
                                this.updatedPlugins    = t.Result.UpdatedPlugins;
                            }

                            this.errorModalDrawing     = this.installStatus == PluginInstallStatus.Fail;
                            this.errorModalOnNextFrame = this.installStatus == PluginInstallStatus.Fail;

                            this.dalamud.PluginRepository.PrintUpdatedPlugins(updatedPlugins, Loc.Localize("DalamudPluginUpdates", "Updates:"));
                        });
                    }
                }
            }


            ImGui.SameLine();

            if (ImGui.Button(Loc.Localize("Close", "Close")))
            {
                windowOpen = false;
            }

            ImGui.Spacing();

            if (ImGui.BeginPopupModal(Loc.Localize("InstallerError", "Installer failed"), ref this.errorModalDrawing, ImGuiWindowFlags.AlwaysAutoResize))
            {
                var message = Loc.Localize("InstallerErrorHint",
                                           "The plugin installer ran into an issue or the plugin is incompatible.\nPlease restart the game and report this error on our discord.");

                if (this.updatedPlugins != null)
                {
                    if (this.updatedPlugins.Any(x => x.WasUpdated == false))
                    {
                        var extraInfoMessage = Loc.Localize("InstallerErrorPluginInfo",
                                                            "\n\nThe following plugins caused these issues:\n\n{0}\nYou may try removing these plugins manually and reinstalling them.");

                        var insert = this.updatedPlugins.Where(x => x.WasUpdated == false)
                                     .Aggregate(string.Empty,
                                                (current, pluginUpdateStatus) =>
                                                current + $"* {pluginUpdateStatus.InternalName}\n");
                        extraInfoMessage = string.Format(extraInfoMessage, insert);
                        message         += extraInfoMessage;
                    }
                }

                ImGui.Text(message);

                ImGui.Spacing();

                if (ImGui.Button(Loc.Localize("OK", "OK"), new Vector2(120, 40)))
                {
                    ImGui.CloseCurrentPopup();
                }

                ImGui.EndPopup();
            }

            if (this.errorModalOnNextFrame)
            {
                ImGui.OpenPopup(Loc.Localize("InstallerError", "Installer failed"));
                this.errorModalOnNextFrame = false;
            }


            ImGui.End();

            return(windowOpen);
        }