|
| 1 | +using ImGuiNET; |
| 2 | +using StudioCore.Core.Project; |
| 3 | +using StudioCore.Interface; |
| 4 | +using StudioCore.Platform; |
| 5 | +using StudioCore.Utilities; |
| 6 | +using System; |
| 7 | +using System.Collections.Generic; |
| 8 | +using System.IO; |
| 9 | +using System.Linq; |
| 10 | +using System.Numerics; |
| 11 | +using System.Text; |
| 12 | +using System.Threading.Tasks; |
| 13 | + |
| 14 | +namespace StudioCore.Core.Manifest; |
| 15 | + |
| 16 | +public static class ManifestEditWindow |
| 17 | +{ |
| 18 | + private static string _name = ""; |
| 19 | + private static string _modid = ""; |
| 20 | + private static string _description = ""; |
| 21 | + private static string _author = ""; |
| 22 | + private static string _version = ""; |
| 23 | + private static string _created_on = ""; |
| 24 | + private static string _modifies_level = ""; |
| 25 | + private static bool _modifies_levelBool = false; |
| 26 | + private static string _dependencies = ""; |
| 27 | + |
| 28 | + private static bool MenuOpenState = false; |
| 29 | + |
| 30 | + public static void ToggleMenuVisibility() |
| 31 | + { |
| 32 | + if(ManifestHandler.ManifestDocument != null) |
| 33 | + { |
| 34 | + MenuOpenState = !MenuOpenState; |
| 35 | + |
| 36 | + var infoElement = ManifestHandler.ManifestDocument.Root.Element("info"); |
| 37 | + |
| 38 | + _name = infoElement.Element("name").Value; |
| 39 | + _modid = infoElement.Element("modid").Value; |
| 40 | + _description = infoElement.Element("description").Value; |
| 41 | + _author = infoElement.Element("author").Value; |
| 42 | + _version = infoElement.Element("version").Value; |
| 43 | + _created_on = infoElement.Element("created_on").Value; |
| 44 | + _modifies_level = infoElement.Element("modifies_level").Value; |
| 45 | + _dependencies = infoElement.Element("dependencies").Value; |
| 46 | + |
| 47 | + if(_modifies_level == "true") |
| 48 | + { |
| 49 | + _modifies_levelBool = true; |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + public static void Display() |
| 55 | + { |
| 56 | + var scale = Warbox.GetUIScale(); |
| 57 | + |
| 58 | + if (!MenuOpenState) |
| 59 | + return; |
| 60 | + |
| 61 | + if (ManifestHandler.ManifestDocument == null) |
| 62 | + return; |
| 63 | + |
| 64 | + ImGui.SetNextWindowSize(new Vector2(600.0f, 400.0f) * scale, ImGuiCond.FirstUseEver); |
| 65 | + ImGui.PushStyleColor(ImGuiCol.WindowBg, CFG.Current.Imgui_Moveable_MainBg); |
| 66 | + ImGui.PushStyleColor(ImGuiCol.TitleBg, CFG.Current.Imgui_Moveable_TitleBg); |
| 67 | + ImGui.PushStyleColor(ImGuiCol.TitleBgActive, CFG.Current.Imgui_Moveable_TitleBg_Active); |
| 68 | + ImGui.PushStyleColor(ImGuiCol.ChildBg, CFG.Current.Imgui_Moveable_ChildBg); |
| 69 | + ImGui.PushStyleColor(ImGuiCol.Text, CFG.Current.ImGui_Default_Text_Color); |
| 70 | + ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(10.0f, 10.0f) * scale); |
| 71 | + ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(5.0f, 5.0f) * scale); |
| 72 | + ImGui.PushStyleVar(ImGuiStyleVar.IndentSpacing, 20.0f * scale); |
| 73 | + |
| 74 | + var flags = ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.NoResize; |
| 75 | + |
| 76 | + if (ImGui.Begin("Mod Manifest", ref MenuOpenState, flags)) |
| 77 | + { |
| 78 | + DisplayModManifestEdit(); |
| 79 | + } |
| 80 | + |
| 81 | + ImGui.End(); |
| 82 | + |
| 83 | + ImGui.PopStyleVar(3); |
| 84 | + ImGui.PopStyleColor(5); |
| 85 | + } |
| 86 | + |
| 87 | + public static void DisplayModManifestEdit() |
| 88 | + { |
| 89 | + var width = ImGui.GetWindowWidth(); |
| 90 | + var flags = ImGuiTableFlags.SizingFixedFit; |
| 91 | + |
| 92 | + var infoElement = ManifestHandler.ManifestDocument.Root.Element("info"); |
| 93 | + |
| 94 | + if (ImGui.BeginTable($"ModManifestTable", 2, flags)) |
| 95 | + { |
| 96 | + ImGui.TableSetupColumn("Name", ImGuiTableColumnFlags.WidthFixed, 150); |
| 97 | + ImGui.TableSetupColumn("Input", ImGuiTableColumnFlags.WidthFixed, 400); |
| 98 | + |
| 99 | + // Name |
| 100 | + ImGui.TableNextRow(); |
| 101 | + |
| 102 | + ImGui.TableSetColumnIndex(0); |
| 103 | + ImGui.AlignTextToFramePadding(); |
| 104 | + |
| 105 | + ImGui.Text("Name"); |
| 106 | + UIHelper.ShowHoverTooltip("The name of the mod."); |
| 107 | + |
| 108 | + ImGui.TableSetColumnIndex(1); |
| 109 | + |
| 110 | + ImGui.AlignTextToFramePadding(); |
| 111 | + |
| 112 | + ImGui.SetNextItemWidth(400); |
| 113 | + if(ImGui.InputText("##input_name", ref _name, 255)) |
| 114 | + { |
| 115 | + infoElement.Element("name").Value = _name; |
| 116 | + } |
| 117 | + |
| 118 | + // Mod ID |
| 119 | + ImGui.TableNextRow(); |
| 120 | + |
| 121 | + ImGui.TableSetColumnIndex(0); |
| 122 | + ImGui.AlignTextToFramePadding(); |
| 123 | + |
| 124 | + ImGui.Text("Mod ID"); |
| 125 | + UIHelper.ShowHoverTooltip("The name of the mod when appending to files for patching purposes."); |
| 126 | + |
| 127 | + ImGui.TableSetColumnIndex(1); |
| 128 | + |
| 129 | + ImGui.AlignTextToFramePadding(); |
| 130 | + |
| 131 | + ImGui.SetNextItemWidth(400); |
| 132 | + if (ImGui.InputText("##input_modid", ref _modid, 255)) |
| 133 | + { |
| 134 | + infoElement.Element("modid").Value = _modid; |
| 135 | + } |
| 136 | + |
| 137 | + // Description |
| 138 | + ImGui.TableNextRow(); |
| 139 | + |
| 140 | + ImGui.TableSetColumnIndex(0); |
| 141 | + ImGui.AlignTextToFramePadding(); |
| 142 | + |
| 143 | + ImGui.Text("Description"); |
| 144 | + UIHelper.ShowHoverTooltip("A description of what the mod does."); |
| 145 | + |
| 146 | + ImGui.TableSetColumnIndex(1); |
| 147 | + |
| 148 | + ImGui.AlignTextToFramePadding(); |
| 149 | + |
| 150 | + ImGui.SetNextItemWidth(400); |
| 151 | + if (ImGui.InputText("##input_description", ref _description, 255)) |
| 152 | + { |
| 153 | + infoElement.Element("description").Value = _description; |
| 154 | + } |
| 155 | + |
| 156 | + // Author |
| 157 | + ImGui.TableNextRow(); |
| 158 | + |
| 159 | + ImGui.TableSetColumnIndex(0); |
| 160 | + ImGui.AlignTextToFramePadding(); |
| 161 | + |
| 162 | + ImGui.Text("Author"); |
| 163 | + UIHelper.ShowHoverTooltip("The names of the author or authors of the mod."); |
| 164 | + |
| 165 | + ImGui.TableSetColumnIndex(1); |
| 166 | + |
| 167 | + ImGui.AlignTextToFramePadding(); |
| 168 | + |
| 169 | + ImGui.SetNextItemWidth(400); |
| 170 | + if (ImGui.InputText("##input_author", ref _author, 255)) |
| 171 | + { |
| 172 | + infoElement.Element("author").Value = _author; |
| 173 | + } |
| 174 | + |
| 175 | + // Version |
| 176 | + ImGui.TableNextRow(); |
| 177 | + |
| 178 | + ImGui.TableSetColumnIndex(0); |
| 179 | + ImGui.AlignTextToFramePadding(); |
| 180 | + |
| 181 | + ImGui.Text("Version"); |
| 182 | + UIHelper.ShowHoverTooltip("The version of the mod these files represent."); |
| 183 | + |
| 184 | + ImGui.TableSetColumnIndex(1); |
| 185 | + |
| 186 | + ImGui.AlignTextToFramePadding(); |
| 187 | + |
| 188 | + ImGui.SetNextItemWidth(400); |
| 189 | + if (ImGui.InputText("##input_version", ref _version, 255)) |
| 190 | + { |
| 191 | + infoElement.Element("version").Value = _version; |
| 192 | + } |
| 193 | + |
| 194 | + // Created On |
| 195 | + ImGui.TableNextRow(); |
| 196 | + |
| 197 | + ImGui.TableSetColumnIndex(0); |
| 198 | + ImGui.AlignTextToFramePadding(); |
| 199 | + |
| 200 | + ImGui.Text("Created On"); |
| 201 | + UIHelper.ShowHoverTooltip("The date on which this mod was created."); |
| 202 | + |
| 203 | + ImGui.TableSetColumnIndex(1); |
| 204 | + |
| 205 | + ImGui.AlignTextToFramePadding(); |
| 206 | + |
| 207 | + ImGui.SetNextItemWidth(400); |
| 208 | + if (ImGui.InputText("##input_created_on", ref _created_on, 255)) |
| 209 | + { |
| 210 | + infoElement.Element("created_on").Value = _created_on; |
| 211 | + } |
| 212 | + |
| 213 | + // Modifies Level |
| 214 | + ImGui.TableNextRow(); |
| 215 | + |
| 216 | + ImGui.TableSetColumnIndex(0); |
| 217 | + ImGui.AlignTextToFramePadding(); |
| 218 | + |
| 219 | + ImGui.Text("Modifies Map"); |
| 220 | + UIHelper.ShowHoverTooltip("Whether this mod affects any of the maps."); |
| 221 | + |
| 222 | + ImGui.TableSetColumnIndex(1); |
| 223 | + |
| 224 | + ImGui.AlignTextToFramePadding(); |
| 225 | + |
| 226 | + ImGui.SetNextItemWidth(400); |
| 227 | + if (ImGui.Checkbox("##input_modifies_level", ref _modifies_levelBool)) |
| 228 | + { |
| 229 | + if(_modifies_levelBool) |
| 230 | + { |
| 231 | + infoElement.Element("modifies_level").Value = "true"; |
| 232 | + } |
| 233 | + else |
| 234 | + { |
| 235 | + infoElement.Element("modifies_level").Value = "false"; |
| 236 | + } |
| 237 | + } |
| 238 | + |
| 239 | + // Dependencies |
| 240 | + ImGui.TableNextRow(); |
| 241 | + |
| 242 | + ImGui.TableSetColumnIndex(0); |
| 243 | + ImGui.AlignTextToFramePadding(); |
| 244 | + |
| 245 | + ImGui.Text("Dependencies"); |
| 246 | + UIHelper.ShowHoverTooltip("Any mod dependencies this mod has."); |
| 247 | + |
| 248 | + ImGui.TableSetColumnIndex(1); |
| 249 | + |
| 250 | + ImGui.AlignTextToFramePadding(); |
| 251 | + |
| 252 | + ImGui.SetNextItemWidth(400); |
| 253 | + if (ImGui.InputText("##input_dependencies", ref _dependencies, 255)) |
| 254 | + { |
| 255 | + infoElement.Element("dependencies").Value = _dependencies; |
| 256 | + } |
| 257 | + |
| 258 | + // Edit |
| 259 | + if (ImGui.Button("Commit Edits", new Vector2(400, 24))) |
| 260 | + { |
| 261 | + ManifestHandler.WriteManifest(); |
| 262 | + |
| 263 | + ToggleMenuVisibility(); |
| 264 | + } |
| 265 | + |
| 266 | + ImGui.EndTable(); |
| 267 | + } |
| 268 | + } |
| 269 | +} |
0 commit comments