public void ExecuteListTransfer(SettingSortingOrderVM sorter, int index, string targetTag) { _sortingOrder.Remove(sorter); if (index > _sortingOrder.Count) { _sortingOrder.Insert(index - 1, sorter); } else { _sortingOrder.Insert(index, sorter); } }
//TODO: FIX TRANSFER WITH 3 ITEMS IN LIST -> DRAG TOP TO VERY BOTTOM AND IT TRIES INDEX 3. IF YOU TRY IN BETWEEN IT PUTS IT LAST IN LIST public void ExecuteListTransfer(SettingSortVM sorter, int index, string targetTag) { if (targetTag == "SettingList") { if (sorter.Side != SettingSide.RIGHT) { ExecuteTransfer(sorter, index, SettingSide.RIGHT); } else { _settingList.Remove(sorter); if (index > _settingList.Count) { _settingList.Insert(index - 1, sorter); } else { _settingList.Insert(index, sorter); } } } else if (targetTag == "PossibleSettingList") { if (sorter.Side != SettingSide.LEFT) { ExecuteTransfer(sorter, index, SettingSide.LEFT); } else { _possibleSettingList.Remove(sorter); if (index > _possibleSettingList.Count) { _possibleSettingList.Insert(index - 1, sorter); } else { _possibleSettingList.Insert(index, sorter); } } } }
private static void SortAnyParty(MBBindingList <PartyCharacterVM> toSort, PartyBase party, TroopRoster rosterToSort, PartySort sorter) { if (rosterToSort == null || rosterToSort.Count == 0 || toSort == null || toSort.IsEmpty()) { return; } CharacterObject leaderOfParty = party?.LeaderHero?.CharacterObject; // Sort the list, this is done for the visual unit cards to be properly positioned after the sort // This is not yet persisted to the actual roster, that is done after this. toSort.StableSort(sorter); // Sanity check to ensure the leader is *always* at the top of the party. if (leaderOfParty != null) { var index = toSort.FindIndex((character) => character.Character.Equals(leaderOfParty)); PartyCharacterVM leaderVm = toSort[index]; toSort.RemoveAt(index); toSort.Insert(0, leaderVm); } // Here we manually clear the roster while ignoring the party leader. // Don't use `rosterToSort.Clear()` as that seems to cause the party leader to get unset permanently afterward, which stops upgrades from working. rosterToSort.RemoveIf((item) => item.Character != leaderOfParty); // Re-add the correctly sorted troops to the roster. We need to do it in this janky way due to the fact that we can't easily sort // the underlying roster array. foreach (PartyCharacterVM character in toSort) { if (character.Character != leaderOfParty) { rosterToSort.AddToCounts( character.Troop.Character, character.Troop.Number, false, character.Troop.WoundedNumber, character.Troop.Xp); } } }
private static void UpdateTooltipPostfix(TooltipVM __instance, Type type, object[] args) { if (args.Length > 0) { if (args[0].GetType() == typeof(Settlement) && (Settlement)args[0] != null) { Settlement settlement = (Settlement)args[0]; if (settlement.IsCastle || settlement.IsTown || settlement.IsVillage) { string factionDefinitionLabel = "Faction"; string troopTypesDefinitionLabel = "Troops"; int indexOfFaction = __instance.TooltipPropertyList.FindIndex(x => x.DefinitionLabel.Equals(factionDefinitionLabel)); MBBindingList <TooltipProperty> tooltipProperties = __instance.TooltipPropertyList; if (indexOfFaction != 0) { //Add Culture to tooltip if (settlement.Culture != null) { tooltipProperties.Insert(indexOfFaction, new TooltipProperty("Culture", settlement.Culture.ToString(), 0, false)); } } __instance.TooltipPropertyList = tooltipProperties; List <TooltipProperty> tooltipPropertyMoreInfoList = __instance.TooltipPropertyList.ToList(); if (DynaCultureManager.Instance.InfluenceMap.Count == 0) { DynaCultureManager.Initialize(); } //Add Influences to tooltip Dictionary <string, decimal> influences = DynaCultureManager.Instance.InfluenceMap[settlement.StringId].CurrentInfluences; if (influences.Count != 0) { int indexForInfluence = __instance.TooltipPropertyList.FindIndex(x => x.DefinitionLabel.Equals(troopTypesDefinitionLabel)); if (indexForInfluence >= 0) { tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty("Influences", " ", 0, true)); indexForInfluence++; tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty("", "", 0, true, TooltipProperty.TooltipPropertyFlags.RundownSeperator)); indexForInfluence++; foreach (KeyValuePair <string, decimal> influence in influences.OrderByDescending(i => i.Value)) { decimal previousInfluenceValue = DynaCultureManager.Instance.InfluenceMap[settlement.StringId].GetPreviousInfluenceForCulture(influence.Key) * 100; decimal influenceValue = influence.Value * 100; decimal differenceInfluenceValue = influenceValue - previousInfluenceValue; string culture = String.Empty; if (influence.Key.Length > 1) { culture = char.ToUpper(influence.Key[0]) + influence.Key.Substring(1); } else { culture = influence.Key; } tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty($"{culture}", $"{influenceValue.ToString("0.##")} ({differenceInfluenceValue.ToString("0.##")})", 0, true)); indexForInfluence++; } tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty("", "", -1, true)); indexForInfluence++; __instance.TooltipPropertyList = new MBBindingList <TooltipProperty>(); __instance.UpdateTooltip(tooltipPropertyMoreInfoList); } } } } } }
private static void UpdateTooltipPostfix(TooltipVM __instance, Type type, object[] args) { try { if (args.Length > 0) { System.Diagnostics.Debug.WriteLine(args[0].GetType()); if (args[0].GetType() == typeof(Settlement) && (Settlement)args[0] != null) { Settlement settlement = (Settlement)args[0]; if (settlement.IsCastle || settlement.IsTown || settlement.IsVillage) { string factionDefinitionLabel = "Faction"; string troopTypesDefinitionLabel = "Troop Types"; int indexOfFaction = __instance.TooltipPropertyList.FindIndex(x => x.DefinitionLabel.Equals(factionDefinitionLabel)); MBBindingList <TooltipProperty> tooltipProperties = __instance.TooltipPropertyList; if (indexOfFaction != 0) { //Add Culture to tooltip if (settlement.Culture != null) { tooltipProperties.Insert(indexOfFaction, new TooltipProperty("Culture", settlement.Culture.ToString(), 0, false)); } } __instance.TooltipPropertyList = tooltipProperties; List <TooltipProperty> tooltipPropertyMoreInfoList = __instance.TooltipPropertyList.ToList(); //Add Influences to tooltip Dictionary <string, decimal> influences = DynaCultureManager.Instance.InfluenceMap[settlement.StringId].getInfluenceForSettlement(); if (influences.Count != 0) { int indexForInfluence = __instance.TooltipPropertyList.FindIndex(x => x.DefinitionLabel.Equals(troopTypesDefinitionLabel)); if (indexForInfluence != 0) { tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty("Influences", " ", 0, true)); indexForInfluence++; tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty("", "", 0, true, TooltipProperty.TooltipPropertyFlags.RundownSeperator)); indexForInfluence++; foreach (KeyValuePair <string, decimal> influence in influences) { decimal targetInfluenceValue = DynaCultureManager.Instance.InfluenceMap[settlement.StringId].getTargetInfluenceValueForSettlement(influence.Key) * 100; decimal influenceValue = influence.Value * 100; decimal differenceInfluenceValue = influenceValue - targetInfluenceValue; string culture = ""; if (influence.Key.Length > 1) { culture = char.ToUpper(influence.Key[0]) + influence.Key.Substring(1); } else { culture = influence.Key; } tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty($"{culture}", $"{influenceValue.ToString("0.##")} ({differenceInfluenceValue.ToString("0.##")})", 0, true)); indexForInfluence++; } tooltipPropertyMoreInfoList.Insert(indexForInfluence, new TooltipProperty("", "", -1, true)); indexForInfluence++; } } __instance.TooltipPropertyList = new MBBindingList <TooltipProperty>(); __instance.UpdateTooltip(tooltipPropertyMoreInfoList); } } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); System.Diagnostics.Debug.WriteLine(ex.StackTrace); } }
public static void Postfix(EscapeMenuVM __instance, ref MBBindingList <EscapeMenuItemVM> ____menuItems, IEnumerable <EscapeMenuItemVM> items, TextObject title = null) { if (CommunityPatchSubModule.DontGroupThirdPartyMenuOptions) { ____menuItems.Add(new EscapeMenuItemVM(new TextObject("{=CommunityPatchOptions}Community Patch Options"), _ => CommunityPatchSubModule.Current.ShowOptions(), _groupEscMenuOptsKey, false)); return; } var list = ____menuItems.ToList(); var customOptions = new List <EscapeMenuItemVM>(); for (var i = 0; i < list.Count; i++) { var item = list[i]; try { var act = (Action <object>)EscapeMenuItemVmOnExecute.GetValue(item); var actAsm = act.Method.DeclaringType?.Assembly; var optAsmName = actAsm?.GetName().Name; if (optAsmName == null || optAsmName.StartsWith("TaleWorlds.") || optAsmName.StartsWith("SandBox.") || optAsmName.StartsWith("SandBoxCore.") || optAsmName.StartsWith("StoryMode.")) { if (PathHelpers.IsOfficialAssembly(actAsm)) { continue; } } } catch { // yeah, it's 3rd party. } customOptions.Add(item); list[i] = null; } var newList = new MBBindingList <EscapeMenuItemVM>(); foreach (var item in list) { if (item != null) { newList.Add(item); } } if (customOptions.Count <= 0) { newList.Insert(newList.Count - 2, new EscapeMenuItemVM(new TextObject("{=CommunityPatchOptions}Community Patch Options"), _ => CommunityPatchSubModule.Current.ShowOptions(), _groupEscMenuOptsKey, false)); ____menuItems = newList; return; } newList.Insert(newList.Count - 2, new EscapeMenuItemVM(new TextObject("{=MoreOptions}More Options"), _ => { var options = new List <InquiryElement>(); foreach (var item in customOptions) { options.Add(new InquiryElement(item, item.ActionText, null, !item.IsDisabled, null)); } options.Add(new InquiryElement(_groupEscMenuOptsKey, new TextObject("{=CommunityPatchOptions}Community Patch Options").ToString(), null)); InformationManager.ShowMultiSelectionInquiry(new MultiSelectionInquiryData( new TextObject("{=MoreOptions}More Options").ToString(), null, options, true, true, new TextObject("{=Open}Open").ToString(), null, selection => { var picked = selection.FirstOrDefault()?.Identifier; if (picked == _groupEscMenuOptsKey) { CommunityPatchSubModule.Current.ShowOptions(); return; } if (picked is EscapeMenuItemVM vm) { SynchronizationContext.Current.Post(_ => { vm.ExecuteAction(); }, null); } }, null ), true); }, "MoreOptions", false));