private void ReloadMods() { _selectedMod = null; // haha yikes _plugin.ModManager = new ModManager(new DirectoryInfo(_plugin.Configuration.BaseFolder)); _plugin.ModManager.DiscoverMods(); }
void DrawModsSelector() { // Selector pane ImGui.BeginGroup(); ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(0, 0)); // Inlay selector list ImGui.BeginChild("availableModList", new Vector2(180, -ImGui.GetFrameHeightWithSpacing()), true); for (var modIndex = 0; modIndex < _plugin.ModManager.AvailableMods.Count; modIndex++) { var mod = _plugin.ModManager.AvailableMods.ElementAt(modIndex); if (ImGui.Selectable(mod.Value.Meta.Name, modIndex == _selectedModIndex)) { _selectedModIndex = modIndex; _selectedMod = mod.Value; } } ImGui.EndChild(); // Selector controls ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0, 0)); ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 0); ImGui.PushFont(UiBuilder.IconFont); if (_selectedModIndex != 0) { if (ImGui.Button(FontAwesomeIcon.ArrowUp.ToIconString(), new Vector2(45, 0))) { } } else { ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 0.5f); ImGui.Button(FontAwesomeIcon.ArrowUp.ToIconString(), new Vector2(45, 0)); ImGui.PopStyleVar(); } ImGui.PopFont(); if (ImGui.IsItemHovered()) { ImGui.SetTooltip("Move the selected mod up in priority"); } ImGui.PushFont(UiBuilder.IconFont); ImGui.SameLine(); if (_selectedModIndex != _plugin.ModManager.AvailableMods.Count - 1) { if (ImGui.Button(FontAwesomeIcon.ArrowDown.ToIconString(), new Vector2(45, 0))) { } } else { ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 0.5f); ImGui.Button(FontAwesomeIcon.ArrowDown.ToIconString(), new Vector2(45, 0)); ImGui.PopStyleVar(); } ImGui.PopFont(); if (ImGui.IsItemHovered()) { ImGui.SetTooltip("Move the selected mod down in priority"); } ImGui.PushFont(UiBuilder.IconFont); ImGui.SameLine(); if (ImGui.Button(FontAwesomeIcon.Trash.ToIconString(), new Vector2(45, 0))) { } ImGui.PopFont(); if (ImGui.IsItemHovered()) { ImGui.SetTooltip("Delete the selected mod"); } ImGui.PushFont(UiBuilder.IconFont); ImGui.SameLine(); if (ImGui.Button(FontAwesomeIcon.Plus.ToIconString(), new Vector2(45, 0))) { } ImGui.PopFont(); if (ImGui.IsItemHovered()) { ImGui.SetTooltip("Add an empty mod"); } ImGui.PopStyleVar(3); ImGui.EndGroup(); }
public void DiscoverMods() { if (BasePath == null) { return; } if (!BasePath.Exists) { return; } AvailableMods.Clear(); ResolvedFiles.Clear(); // get all mod dirs foreach (var modDir in BasePath.EnumerateDirectories()) { var metaFile = modDir.EnumerateFiles().FirstOrDefault(f => f.Name == "meta.json"); if (metaFile == null) { PluginLog.LogError("mod meta is missing for resource mod: {ResourceModLocation}", modDir); continue; } var meta = JsonConvert.DeserializeObject <Models.ModMeta>(File.ReadAllText(metaFile.FullName)); var mod = new ResourceMod { Meta = meta, ModBasePath = modDir }; AvailableMods[modDir.Name] = mod; mod.RefreshModFiles(); } // todo: sort the mods by priority here so that the file discovery works correctly foreach (var mod in AvailableMods.Select(m => m.Value)) { // fixup path var baseDir = mod.ModBasePath.FullName; foreach (var file in mod.ModFiles) { var path = file.FullName.Substring(baseDir.Length).ToLowerInvariant() .TrimStart('\\').Replace('\\', '/'); // todo: notify when collisions happen? or some extra state on the file? not sure yet // this code is shit all the same if (!ResolvedFiles.ContainsKey(path)) { ResolvedFiles[path] = file; } else { PluginLog.LogError( "a different mod already f***s this file: {FilePath}", ResolvedFiles[path].FullName ); } } } }