/// <summary> /// Creates and registers a new mod wiki. /// You must pass in your mod instance. Do not call this method more than once per mod! /// </summary> /// <param name="mod">Your mod instance.</param> /// <returns>The newly created ModWiki object, or null if creation failed.</returns> public static ModWiki Create(Mod mod) { if (mod == null) { Log.Error("Cannot pass in null mod to create wiki."); return(null); } try { var wiki = new ModWiki(); wiki.Mod = mod; wiki.GenerateFromMod(mod); allWikis.Add(wiki); Log.Message($"<color=cyan>A new wiki was registered for mod '{mod.Content.Name}'.</color>"); return(wiki); } catch (Exception e) { Log.Error($"Exception creating wiki for {mod.Content.Name}: {e}"); return(null); } }
protected WikiWindow(ModWiki wiki) { this.Wiki = wiki; resizeable = true; doCloseButton = true; draggable = true; drawShadow = true; onlyOneOfTypeAllowed = true; absorbInputAroundWindow = false; preventCameraMotion = false; }
/// <summary> /// Opens the wiki window to a specific page from a specific wiki. /// </summary> public static void ShowPage(ModWiki wiki, WikiPage page) { if (wiki == null || page == null) { return; } if (WikiWindow.CurrentActive != null && WikiWindow.CurrentActive.Wiki == wiki) { WikiWindow.CurrentActive.CurrentPage = page; } else { WikiWindow.Open(wiki, page); } }
public static WikiWindow Open(ModWiki wiki, WikiPage page = null) { if (wiki == null) return null; if (CurrentActive != null && CurrentActive.Wiki != wiki) { //Log.Warn("There is already an open wiki page, closing old."); CurrentActive.Close(true); } var created = new WikiWindow(wiki); created.CurrentPage = page; CurrentActive = created; Find.WindowStack?.Add(created); return created; }
/// <summary> /// Generates wiki pages from the .txt files supplied by the mod inside it's Wiki folder. /// Uses the currently active language where possible, or defaults to English. /// </summary> /// <param name="wiki">The mod wiki to generate the files for.</param> /// <param name="dir">The Wiki directory to find files in.</param> /// <returns>The name of the language used, or null if loading failed.</returns> public static string AddAllFromDirectory(ModWiki wiki, string dir) { if (wiki == null) { return(null); } if (!Directory.Exists(dir)) { return(null); } var activeLang = LanguageDatabase.activeLanguage; string langName = activeLang.folderName; string defaultLangName = LanguageDatabase.DefaultLangFolderName; bool hasActiveLanguage = Directory.Exists(Path.Combine(dir, langName)); if (!hasActiveLanguage) { string modName = wiki.Mod?.Content?.Name ?? "UKN"; Log.Warning($"Mod {modName} has a wiki folder, but does not support language '{langName}'. {(langName == defaultLangName ? "Falling back to first found." : $"Falling back to '{defaultLangName}', or first found.")} "); // Look for default (english) language. hasActiveLanguage = Directory.Exists(Path.Combine(dir, defaultLangName)); if (hasActiveLanguage) { // English found. Use it. dir = Path.Combine(dir, defaultLangName); Log.Warning($"Using {defaultLangName}."); } else { // Okay, mod doesn't have native language and also doesn't have english. Look for any language at all. var folders = Directory.GetDirectories(dir, "", SearchOption.TopDirectoryOnly); if (folders.Length == 0) { Log.Warning($"Mod {modName} has wiki folder, but no languages. The folder structure should be 'ModName/Wiki/LanguageName/'."); } else { // Just go with the first one. dir = folders[0]; Log.Warning($"Failed to find wiki in '{defaultLangName}', using first found: '{new DirectoryInfo(dir).Name}'."); } } }
/// <summary> /// Creates and registers a new mod wiki. /// You must pass in your mod instance. Do not call this method more than once per mod! /// You must also supply an instance of a ModWiki subclass. This version should only be used if you need to add specialized custom behaviour to the /// ModWiki. Otherwise, use <see cref="Create(Mod)"/>. /// </summary> /// <param name="mod">Your mod instance.</param> /// <param name="wiki">Your non-null ModWiki subclass instance.</param> /// <returns>The newly created ModWiki object, or null if creation failed.</returns> public static ModWiki Create(Mod mod, ModWiki wiki) { if (mod == null) { Log.Error("Cannot pass in null mod to create wiki."); return(null); } if (wiki == null) { Log.Error("Cannot pass in null ModWiki instance to create wiki."); return(null); } try { wiki.Mod = mod; // If the wiki mod is not installed, then don't generate wiki contents, they aren't needed. // This could cause issues if mod's try to the access those pages later, but normally wiki // creation will be fire-and-forget. if (!IsWikiModInstalled) { Log.Warning($"A wiki was registered for mod '{mod.Content.Name}', but the InGameWiki mod is not installed. Dummy wiki has been created instead."); return(wiki); } wiki.GenerateFromMod(mod); allWikis.Add(wiki); Log.Message($"<color=cyan>A new wiki was registered for mod '{mod.Content.Name}'.</color>"); return(wiki); } catch (Exception e) { Log.Error($"Exception creating wiki for {mod.Content.Name}: {e}"); return(null); } }
public bool GoToPage(Def def, bool openInspectWindow = false) { if (def == null) return false; var page = Wiki.FindPageFromDef(def.defName); if (page == null) { if (openInspectWindow) { ModWiki.OpenInspectWindow(def); return true; } return false; } else { this.CurrentPage = page; return true; } }
public static WikiPage CreateFromThingDef(ModWiki wiki, ThingDef thing) { if (thing == null) { return(null); } WikiPage p = new WikiPage(wiki); try { p.Title = thing.LabelCap; p.ShortDescription = thing.DescriptionDetailed; p.Icon = thing.uiIcon; } catch (Exception e) { throw new Exception("Exception setting page basics.", e); } try { // Cost. if (thing.costList != null) { var cost = new SectionWikiElement(); cost.Name = "Wiki.Cost".Translate(); foreach (var costThing in thing.costList) { cost.Elements.Add(new WikiElement() { DefForIconAndLabel = costThing.thingDef, Text = costThing.count <= 1 ? "" : $"x{costThing.count}" }); } int outputCount = thing.recipeMaker?.productCount ?? 1; cost.Elements.Add(WikiElement.Create("Wiki.OutputCount".Translate(outputCount))); if (cost.Elements.Count > 0) { p.Elements.Add(cost); } var creates = new SectionWikiElement(); creates.Name = "Wiki.Creates".Translate(); // Show recipes added by this production thing. foreach (var rec in thing.AllRecipes) { creates.Elements.Add(WikiElement.Create($" • {rec.LabelCap}")); } if (creates.Elements.Count > 0) { p.Elements.Add(creates); } } } catch (Exception e) { throw new Exception("Exception generating thing cost list.", e); } try { // Crafting (where is it crafted) if (thing.recipeMaker?.recipeUsers != null) { var crafting = new SectionWikiElement(); crafting.Name = "Wiki.CraftedAt".Translate(); foreach (var user in thing.recipeMaker.recipeUsers) { crafting.Elements.Add(new WikiElement() { DefForIconAndLabel = user }); } if (crafting.Elements.Count > 0) { p.Elements.Add(crafting); } } } catch (Exception e) { throw new Exception("Exception generating thing crafting location list.", e); } try { // Research prerequisite. var research = new SectionWikiElement(); research.Name = "Wiki.ResearchToUnlock".Translate(); if (thing.researchPrerequisites != null && thing.researchPrerequisites.Count > 0) // Generally buildings. { foreach (var r in thing.researchPrerequisites) { research.Elements.Add(new WikiElement() { Text = $" • {r.LabelCap}" }); } } if (thing.recipeMaker?.researchPrerequisites != null) // Generally craftable items. { foreach (var r in thing.recipeMaker.researchPrerequisites) { research.Elements.Add(new WikiElement() { Text = $" • {r.LabelCap}" }); } } if (thing.recipeMaker?.researchPrerequisite != null) // Generally craftable items. { var r = thing.recipeMaker.researchPrerequisite; research.Elements.Add(new WikiElement() { Text = $" • {r.LabelCap}" }); } if (research.Elements.Count > 0) { p.Elements.Add(research); } if (DebugMode) { if (thing.weaponTags != null) { foreach (var tag in thing.weaponTags) { p.Elements.Add(new WikiElement() { Text = $"WeaponTag: {tag}" }); } } } } catch (Exception e) { throw new Exception("Exception generating thing research requirements.", e); } p.Def = thing; return(p); }