//////////////// private void PopulateList(string modName) { string currModName = ModMenuHelpers.GetModName(MenuContextService.GetPreviousMenuUI(), this.MyUI ?? MenuContextService.GetCurrentMenuUI()); if (modName != currModName) { return; } this.RecommendsList.Clear(); string err = ""; IList <Tuple <string, string> > recommends = this.GetRecommendsFromActiveMod(modName) ?? this.GetRecommendsFromUI(modName, ref err); if (string.IsNullOrEmpty(err)) { this.RecommendsList.AddModEntriesAsync(modName, recommends.Take(ModRecommendsMenuContext.Limit)); } else { LogHelpers.Log("!ModHelpers.ModRecommendsMenuContext.PopulateList - " + err); } }
public void SubmitTags() { if (string.IsNullOrEmpty(this.CurrentModName)) { UIState prevMenuUI = MenuContextService.GetPreviousMenuUI(); UIState currMenuUI = MenuContextService.GetCurrentMenuUI(); this.CurrentModName = ModMenuHelpers.GetModName(prevMenuUI, currMenuUI) ?? ""; if (string.IsNullOrEmpty(this.CurrentModName)) { throw new ModHelpersException("Invalid mod name."); } } Action <Exception, string> onError = (e, output) => { this.SetInfoText("Error: " + (string.IsNullOrEmpty(output) ? e.Message : output), Color.Red); LogHelpers.Log(e.ToString()); }; ISet <string> newTags = this.GetTagsWithGivenState(1); // Update snapshot of tags for the given mod (locally) if (this.AllModTagsSnapshot != null) { this.AllModTagsSnapshot[this.CurrentModName] = newTags; } PostModInfo.SubmitModInfo(this.CurrentModName, newTags, onError, this.PostSubmitTags); ModTagsManager.RecentTaggedMods.Add(this.CurrentModName); }
internal void SubmitTags() { if (string.IsNullOrEmpty(this.CurrentModName)) { this.CurrentModName = ModMenuHelpers.GetModName(MenuContextService.GetPreviousMenuUI(), MenuContextService.GetCurrentMenuUI()) ?? ""; if (string.IsNullOrEmpty(this.CurrentModName)) { throw new HamstarException("Invalid mod name."); } } Action <string> onSuccess = delegate(string output) { this.InfoDisplay?.SetText(output, Color.Lime); ErrorLogger.Log("Mod info submit result: " + output); }; Action <Exception, string> onFail = (e, output) => { this.InfoDisplay?.SetText("Error: " + (string.IsNullOrEmpty(output)?e.Message:output), Color.Red); LogHelpers.Log(e.ToString()); }; ISet <string> newTags = this.GetTagsOfState(1); // Update snapshot of tags for the given mod (locally) if (this.AllModTagsSnapshot != null) { this.AllModTagsSnapshot[this.CurrentModName] = newTags; } PostModInfo.SubmitModInfo(this.CurrentModName, newTags, onSuccess, onFail); this.FinishButton.Lock(); this.ResetButton.Lock(); }
//////////////// private void ShowGeneral(UIState ui) { string modName = ModMenuHelpers.GetModName(MenuContextService.GetCurrentMenuUI(), ui); this.InfoDisplay.SetDefaultText(""); if (modName == null) { LogHelpers.Warn("Could not load mod tags; no mod found"); } else { this.ResetUIState(modName); this.SetCurrentMod(ui, modName); this.RecalculateMenuObjects(); } UIElement elem; if (ReflectionHelpers.Get(ui, "uIElement", out elem)) { elem.Left.Pixels += UITagButton.ColumnWidth; elem.Recalculate(); } }
private void CheckForAndApplyLowEffortTag(string modName) { UITagMenuButton tagButton; if (!this.TagButtons.TryGetValue("Low Effort", out tagButton)) { return; } if (tagButton.TagState == 1) { return; } BuildPropertiesViewer viewer = BuildPropertiesViewer.GetBuildPropertiesForActiveMod(modName); string desc = viewer?.Description ?? ""; if (viewer == null || string.IsNullOrEmpty(desc)) { if (!ModMenuHelpers.GetModDescriptionFromCurrentMenuUI(out desc)) { desc = ""; } } if (desc == "" || desc.Contains("Modify this file with a description of your mod.")) { tagButton.SetTagState(1); } }
private void HandleFilteredMods(UIState _menuUi, bool isFiltered, IList <string> filteredModNameList, int onTagCount, int offTagCount) { string filterName = "Tags"; if (onTagCount > 0 || offTagCount > 0) { filterName += " "; if (onTagCount > 0) { filterName += "+" + onTagCount; if (offTagCount > 0) { filterName += " "; } } if (offTagCount > 0) { filterName += "-" + offTagCount; } } if (ReflectionHelpers.Set(_menuUi, "UpdateFilterMode", (UpdateFilter)0)) { ModMenuHelpers.ApplyModBrowserFilter(filterName, isFiltered, (List <string>)filteredModNameList); } else { LogHelpers.Alert("Could not set UpdateFilterMode for the mod browser"); } }
internal void FilterMods() { IList <string> modNames = new List <string>(); UIState myUI = this.MyUI; object items; if (!ReflectionHelpers.Get(myUI, "items", out items)) { throw new HamstarException("No 'items' field in ui " + myUI); } var itemsArr = (Array)items.GetType() .GetMethod("ToArray") .Invoke(items, new object[] { }); for (int i = 0; i < itemsArr.Length; i++) { object item = itemsArr.GetValue(i); string modName; if (ReflectionHelpers.Get(item, "mod", out modName)) { modNames.Add(modName); } } this.FilterModsAsync(modNames, (isFiltered, filteredModNameList, onTagCount, offTagCount) => { string filterName = "Tags"; if (onTagCount > 0 || offTagCount > 0) { filterName += " "; if (onTagCount > 0) { filterName += "+" + onTagCount; if (offTagCount > 0) { filterName += " "; } } if (offTagCount > 0) { filterName += "-" + offTagCount; } } ReflectionHelpers.Set(myUI, "updateFilterMode", (UpdateFilter)0); ModMenuHelpers.ApplyModBrowserFilter(filterName, isFiltered, (List <string>)filteredModNameList); }); }
//////////////// public void AddModEntriesAsync(string forModName, IEnumerable <Tuple <string, string> > recomMods) { foreach (var recomMod in recomMods) { string recomModName = recomMod.Item1; string recommendedBecause = recomMod.Item2; Mod mod = ModLoader.GetMod(recomModName); this.AddRawModEntry(mod?.DisplayName, recomModName, recommendedBecause); } Promises.AddValidatedPromise <ModInfoListPromiseArguments>(GetModInfo.ModInfoListPromiseValidator, (args) => { string currModName = ModMenuHelpers.GetModName(MenuContextService.GetPreviousMenuUI(), this.MenuContext.MyUI ?? MenuContextService.GetCurrentMenuUI()); // Validate we're in the same UI if (this.MenuContext.MyUI.GetType().Name != "UIModInfo") { return(false); } // Validate we're viewing the mod we started with if (forModName != currModName) { return(false); } this.List.RemoveAllChildren(); this.ModNameList.Clear(); foreach (var recomMod in recomMods) { string recomModName = recomMod.Item1; string recommendedBecause = recomMod.Item2; if (args.ModInfo.ContainsKey(recomModName)) { this.AddModEntry(args.ModInfo[recomModName].DisplayName, recomModName, recommendedBecause); } else { this.AddRawModEntry(null, recomModName, recommendedBecause); } } return(false); }); this.EmptyText.Remove(); this.Recalculate(); }
//////////////// public override void Show(UIState ui) { base.Show(ui); string modName = ModMenuHelpers.GetModName(MenuContextService.GetCurrentMenuUI(), ui); if (modName == null) { LogHelpers.Log("Could not load mod recommendations; no mod found."); return; } this.PopulateList(modName); }
public override void Show(UIState ui) { base.Show(ui); UIState prevUi = MenuContextService.GetCurrentMenuUI(); if (prevUi == ui) { prevUi = MenuContextService.GetPreviousMenuUI(); } string modName = ModMenuHelpers.GetModName(prevUi, ui); this.InfoDisplay.SetDefaultText(""); this.MyManager.MyTagsUI.ResetTagButtonOnStates(true); if (modName == null) { LogHelpers.Warn("Could not load mod tags; no mod found"); return; } this.MyManager.SetCurrentModAsync(modName); }