private void DrawModAddButton() { if (ImGui.BeginPopupContextItem(LabelAddModPopup)) { if (_keyboardFocus) { ImGui.SetKeyboardFocusHere(); _keyboardFocus = false; } var newName = ""; if (ImGui.InputTextWithHint("##AddMod", "New Mod Name...", ref newName, 64, ImGuiInputTextFlags.EnterReturnsTrue)) { try { var newDir = TexToolsImport.CreateModFolder(new DirectoryInfo(_base._plugin.Configuration !.CurrentCollection), newName); var modMeta = new ModMeta { Author = "Unknown", Name = newName, Description = string.Empty, }; var metaPath = Path.Combine(newDir.FullName, "meta.json"); File.WriteAllText(metaPath, JsonConvert.SerializeObject(modMeta, Formatting.Indented)); _base.ReloadMods(); SelectModByDir(newDir.Name); } catch (Exception e) { PluginLog.Error($"Could not create directory for new Mod {newName}:\n{e}"); } ImGui.CloseCurrentPopup(); } if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGuiKey.Escape))) { ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); } ImGui.PushFont(UiBuilder.IconFont); if (ImGui.Button(FontAwesomeIcon.Plus.ToIconString(), SelectorButtonSizes)) { _keyboardFocus = true; ImGui.OpenPopup(LabelAddModPopup); } ImGui.PopFont(); if (ImGui.IsItemHovered()) { ImGui.SetTooltip(TooltipAdd); } }
private void DrawRediscoverButton() { if (ImGui.Button(LabelRediscoverButton)) { _base.ReloadMods(); _base._menu.InstalledTab.Selector.ClearSelection(); } }
private void DrawDeleteModal() { if (_deleteIndex == null) { return; } ImGui.OpenPopup(DialogDeleteMod); var ret = ImGui.BeginPopupModal(DialogDeleteMod); if (!ret) { return; } if (_mod?.Mod == null) { ImGui.CloseCurrentPopup(); ImGui.EndPopup(); return; } ImGui.Text("Are you sure you want to delete the following mod:"); // todo: why the f**k does this become null?????? ImGui.Text(_mod?.Mod?.Meta?.Name); if (ImGui.Button(ButtonYesDelete)) { ImGui.CloseCurrentPopup(); Service <ModManager> .Get().DeleteMod(_mod?.Mod); ClearSelection(); _base.ReloadMods(); } ImGui.SameLine(); if (ImGui.Button(ButtonNoDelete)) { ImGui.CloseCurrentPopup(); _deleteIndex = null; } ImGui.EndPopup(); }
private void DrawRenameModFolderButton() { var _ = true; _keyboardFocus |= !ImGui.IsPopupOpen(PopupRenameFolder); ImGui.SetNextWindowPos(ImGui.GetMainViewport().GetCenter(), ImGuiCond.Appearing, new Vector2(0.5f, 1f)); if (ImGui.BeginPopupModal(PopupRenameFolder, ref _, ImGuiWindowFlags.AlwaysAutoResize)) { if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGuiKey.Escape))) { ImGui.CloseCurrentPopup(); } var newName = Mod !.FolderName; if (_keyboardFocus) { PluginLog.Log("F**k you"); ImGui.SetKeyboardFocusHere(); _keyboardFocus = false; } if (ImGui.InputText("New Folder Name##RenameFolderInput", ref newName, 64, ImGuiInputTextFlags.EnterReturnsTrue)) { _newName = newName.RemoveNonAsciiSymbols().RemoveInvalidPathSymbols(); if (_newName.Length == 0) { ImGui.CloseCurrentPopup(); } else if (!string.Equals(_newName, Mod !.FolderName, StringComparison.InvariantCultureIgnoreCase)) { DirectoryInfo dir = Mod !.Mod.ModBasePath; DirectoryInfo newDir = new(Path.Combine(dir.Parent !.FullName, _newName)); if (newDir.Exists) { PluginLog.Error("GOTT"); ImGui.OpenPopup("OverwriteDir"); } else { try { dir.MoveTo(newDir.FullName); } catch (Exception e) { PluginLog.Error($"Error while renaming directory {dir.FullName} to {newDir.FullName}:\n{e}"); } Mod !.FolderName = _newName; Mod !.Mod.ModBasePath = newDir; _selector.ReloadCurrentMod(); Service <ModManager> .Get() !.Mods !.Save(); ImGui.CloseCurrentPopup(); } } } ImGui.TextColored(GreyColor, "Please restrict yourself to ascii symbols that are valid in a windows path,\nother symbols will be replaced by underscores."); var closeParent = false; _ = true; ImGui.SetNextWindowPos(ImGui.GetMainViewport().GetCenter(), ImGuiCond.Appearing, Vector2.One / 2); if (ImGui.BeginPopupModal("OverwriteDir", ref _, ImGuiWindowFlags.AlwaysAutoResize)) { DirectoryInfo dir = Mod !.Mod.ModBasePath; DirectoryInfo newDir = new(Path.Combine(dir.Parent !.FullName, _newName)); ImGui.Text( $"The mod directory {newDir} already exists.\nDo you want to merge / overwrite both mods?\nThis may corrupt the resulting mod in irrecoverable ways."); var buttonSize = new Vector2(120, 0); if (ImGui.Button("Yes", buttonSize)) { try { foreach (var file in dir.EnumerateFiles("*", SearchOption.AllDirectories)) { var target = new FileInfo(Path.Combine(newDir.FullName, file.FullName.Substring(dir.FullName.Length))); if (target.Exists) { target.Delete(); } target.Directory?.Create(); file.MoveTo(target.FullName); } dir.Delete(true); var mod = Service <ModManager> .Get() !.Mods !.ModSettings ! .RemoveAll(m => m.FolderName == _newName); Mod !.FolderName = _newName; Mod !.Mod.ModBasePath = newDir; Service <ModManager> .Get() !.Mods !.Save(); _base.ReloadMods(); _selector.SelectModByDir(_newName); } catch (Exception e) { PluginLog.Error($"Error while renaming directory {dir.FullName} to {newDir.FullName}:\n{e}"); } closeParent = true; ImGui.CloseCurrentPopup(); } ImGui.SameLine(); if (ImGui.Button("Cancel", buttonSize)) { PluginLog.Error("FUCKFUCK"); _keyboardFocus = true; ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); } if (closeParent) { ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); } if (ImGui.Button(ButtonRenameModFolder)) { ImGui.OpenPopup(PopupRenameFolder); } if (ImGui.IsItemHovered()) { ImGui.SetTooltip(TooltipRenameModFolder); } }