Esempio n. 1
0
        private static void CheckLoadOrder()
        {
            var loadedModules = ModuleInfoHelper.GetLoadedModules().ToList();

            var sb = new StringBuilder();

            var harmonyModule      = loadedModules.SingleOrDefault(x => x.Id == "Bannerlord.Harmony");
            var harmonyModuleIndex = harmonyModule is not null?loadedModules.IndexOf(harmonyModule) : -1;

            if (harmonyModuleIndex == -1)
            {
                if (sb.Length != 0)
                {
                    sb.AppendLine();
                }
                sb.AppendLine(TextObjectHelper.Create(SErrorHarmonyNotFound)?.ToString() ?? "ERROR");
            }

            var uiExtenderModule = loadedModules.SingleOrDefault(x => x.Id == "Bannerlord.UIExtenderEx");
            var uiExtenderIndex  = uiExtenderModule is not null?loadedModules.IndexOf(uiExtenderModule) : -1;

            if (uiExtenderIndex == -1)
            {
                if (sb.Length != 0)
                {
                    sb.AppendLine();
                }
                sb.AppendLine(TextObjectHelper.Create(SErrorUIExtenderExNotFound)?.ToString() ?? "ERROR");
            }

            var officialModules     = loadedModules.Where(x => x.IsOfficial).Select(x => (Module: x, Index: loadedModules.IndexOf(x)));
            var modulesLoadedBefore = officialModules.Where(tuple => tuple.Index < uiExtenderIndex).ToList();

            if (modulesLoadedBefore.Count > 0)
            {
                if (sb.Length != 0)
                {
                    sb.AppendLine();
                }
                sb.AppendLine(TextObjectHelper.Create(SErrorOfficialModulesLoadedBefore)?.ToString() ?? "ERROR");
                sb.AppendLine(TextObjectHelper.Create(SErrorOfficialModules)?.ToString() ?? "ERROR");
                foreach (var(module, _) in modulesLoadedBefore)
                {
                    sb.AppendLine(module.Id);
                }
            }

            if (sb.Length > 0)
            {
                sb.AppendLine();
                sb.AppendLine(TextObjectHelper.Create(SMessageContinue)?.ToString() ?? "ERROR");

                switch (MessageBox.Show(sb.ToString(), TextObjectHelper.Create(SWarningTitle)?.ToString() ?? "ERROR", MessageBoxButtons.YesNo))
                {
                case DialogResult.Yes:
                    Environment.Exit(1);
                    break;
                }
            }
        }
        protected BasePropertyDefinitionWrapper(object @object)
        {
            var type = @object.GetType();

            DisplayName    = TextObjectHelper.Create(type.GetProperty(nameof(DisplayName))?.GetValue(@object) as string ?? "ERROR")?.ToString() ?? "ERROR";;
            Order          = type.GetProperty(nameof(Order))?.GetValue(@object) as int? ?? -1;
            RequireRestart = type.GetProperty(nameof(RequireRestart))?.GetValue(@object) as bool? ?? true;
            HintText       = TextObjectHelper.Create(type.GetProperty(nameof(HintText))?.GetValue(@object) as string ?? "ERROR")?.ToString() ?? "ERROR";;
        }
Esempio n. 3
0
 public static HintViewModel?Create(string text)
 {
     if (V1 is not null)
     {
         return(V1(text));
     }
     if (V2 is not null)
     {
         return(V2(TextObjectHelper.Create(text)));
     }
     return(null);
 }
        public HotKeyCategoryContainer(string categoryId, IEnumerable <HotKeyBase> keys) : base(categoryId, ListCapacity)
        {
            var keyName         = Module.CurrentModule.GlobalTextManager.AddGameText("str_key_name");
            var keyDesc         = Module.CurrentModule.GlobalTextManager.AddGameText("str_key_description");
            var variationString = $"{categoryId}_";

            foreach (var key in keys)
            {
                keyName.AddVariationWithId($"{variationString}{key.Id}", TextObjectHelper.Create(key.DisplayName), new List <GameTextManager.ChoiceTag>());
                keyDesc.AddVariationWithId($"{variationString}{key.Id}", TextObjectHelper.Create(key.Description), new List <GameTextManager.ChoiceTag>());
                RegisterGameKey(new GameKey(key.Id, key.Uid, categoryId, key.DefaultKey, key.Category));
            }
        }
Esempio n. 5
0
        public ModLibSettingPropertyAttributeWrapper(object @object)
        {
            var type = @object.GetType();

            DisplayName    = TextObjectHelper.Create(type.GetProperty(nameof(v1SettingPropertyAttribute.DisplayName))?.GetValue(@object) as string ?? "ERROR")?.ToString() ?? "ERROR";
            HintText       = TextObjectHelper.Create(type.GetProperty(nameof(v1SettingPropertyAttribute.HintText))?.GetValue(@object) as string ?? "ERROR")?.ToString() ?? "ERROR";
            Order          = -1;
            RequireRestart = true;

            MinValue         = (decimal)(type.GetProperty(nameof(v1SettingPropertyAttribute.MinValue))?.GetValue(@object) as float? ?? 0);
            MaxValue         = (decimal)(type.GetProperty(nameof(v1SettingPropertyAttribute.MaxValue))?.GetValue(@object) as float? ?? 0);
            EditableMinValue = (decimal)(type.GetProperty(nameof(v1SettingPropertyAttribute.EditableMinValue))?.GetValue(@object) as float? ?? 0);
            EditableMaxValue = (decimal)(type.GetProperty(nameof(v1SettingPropertyAttribute.EditableMaxValue))?.GetValue(@object) as float? ?? 0);
        }
        public MBOv1PropertyDefinitionWrapper(object @object)
        {
            var type = @object.GetType();

            DisplayName    = TextObjectHelper.Create((type.GetProperty("DisplayName") ?? type.GetProperty("Name"))?.GetValue(@object) as string ?? "ERROR")?.ToString() ?? "ERROR";
            HintText       = TextObjectHelper.Create(type.GetProperty("HintText")?.GetValue(@object) as string ?? "ERROR")?.ToString() ?? "ERROR";
            Order          = type.GetProperty("Order")?.GetValue(@object) as int? ?? 0;
            RequireRestart = type.GetProperty("RequireRestart")?.GetValue(@object) as bool? ?? true;

            MinValue         = (decimal)(type.GetProperty("MinValue")?.GetValue(@object) as float? ?? 0);
            MaxValue         = (decimal)(type.GetProperty("MaxValue")?.GetValue(@object) as float? ?? 0);
            ValueFormat      = type.GetProperty("ValueFormat")?.GetValue(@object) as string ?? string.Empty;
            SelectedIndex    = type.GetProperty("SelectedIndex")?.GetValue(@object) as int? ?? 0;
            EditableMinValue = (decimal)(type.GetProperty("EditableMinValue")?.GetValue(@object) as float? ?? (float)MinValue);
            EditableMaxValue = (decimal)(type.GetProperty("EditableMaxValue")?.GetValue(@object) as float? ?? (float)MaxValue);
        }
        private void AddDescriptorToExistingCampaign()
        {
            _descriptorToBeAssigned = Campaign.Current.GameStarted && Hero.All.FirstOrDefault(h => h.Id.SubId == 1) is { } baseHero
                ? new CampaignDescriptorImplementation(baseHero)
                : null;
            if (_descriptorToBeAssigned is null)
            {
                return;
            }

            var possiblyMatchingDescriptors = LoadExistingDescriptors()
                                              .Where(cd => cd.ImmutableKey == _descriptorToBeAssigned.ImmutableKey)
                                              .ToList();

            if (possiblyMatchingDescriptors.Count > 0)
            {
                var inquiryElements = possiblyMatchingDescriptors
                                      .ConvertAll(existingDescriptor => new InquiryElement(
                                                      existingDescriptor,
                                                      existingDescriptor.FullCharacterName,
                                                      new ImageIdentifier(existingDescriptor.CharacterCode),
                                                      true,
                                                      string.Join(" - ", existingDescriptor.Descriptor, existingDescriptor.KeyValue)));

                var newIdTextObject = TextObjectHelper.Create("{=wF4qRrhmEu}Assign new ID");
                var inquiryBody     = $"{TextObjectHelper.Create(InquiryUpperBody)}\n \n{TextObjectHelper.Create(InquiryLowerBody, new Dictionary<string, TextObject> {["NEW_ID"] = newIdTextObject})}";
                inquiryElements.Add(new InquiryElement(null, newIdTextObject.ToString(),
                                                       new ImageIdentifier(), true,
                                                       TextObjectHelper.Create("{=25Ts3iQnv6}This is a standalone campaign and must be assigned a new ID.").ToString()));
                InformationManager.ShowMultiSelectionInquiry(new MultiSelectionInquiryData(
                                                                 TextObjectHelper.Create("{=4BuIRaILsb}Select identified ongoing campaign").ToString(),
                                                                 inquiryBody, inquiryElements, true, 1, GameTexts.FindText("str_done").ToString(), "",
                                                                 OnDescriptorSelectionOver,
                                                                 OnDescriptorSelectionOver));
                return;
            }

            ApplyPredeterminedDescriptor();
        }
Esempio n. 8
0
        public SettingsPropertyDefinition(IEnumerable <IPropertyDefinitionBase> propertyDefinitions, IPropertyGroupDefinition propertyGroupDefinition, IRef propertyReference, char subGroupDelimiter)
        {
            SubGroupDelimiter = subGroupDelimiter;

            var groups = propertyGroupDefinition.GroupName.Split(SubGroupDelimiter);

            GroupName  = string.Join(SubGroupDelimiter.ToString(), groups.Select(x => TextObjectHelper.Create(x)?.ToString()));
            GroupOrder = propertyGroupDefinition.GroupOrder;

            PropertyReference = propertyReference;

            if (PropertyReference is PropertyRef propertyRef)
            {
                Id = propertyRef.PropertyInfo.Name;
            }

            if (PropertyReference.Type == typeof(bool))
            {
                SettingType = SettingType.Bool;
            }
            else if (PropertyReference.Type == typeof(int))
            {
                SettingType = SettingType.Int;
            }
            else if (PropertyReference.Type == typeof(float))
            {
                SettingType = SettingType.Float;
            }
            else if (PropertyReference.Type == typeof(string))
            {
                SettingType = SettingType.String;
            }
            else if (SettingsUtils.IsForGenericDropdown(PropertyReference.Type))
            {
                SettingType = SettingType.Dropdown;
            }

            foreach (var propertyDefinition in propertyDefinitions)
            {
                if (propertyDefinition is IPropertyDefinitionBase propertyBase)
                {
                    DisplayName    = TextObjectHelper.Create(propertyBase.DisplayName)?.ToString() ?? "ERROR";
                    Order          = propertyBase.Order;
                    RequireRestart = propertyBase.RequireRestart;
                    HintText       = TextObjectHelper.Create(propertyBase.HintText)?.ToString() ?? "ERROR";
                }
                if (propertyDefinition is SettingPropertyAttribute settingPropertyAttribute) // v1
                {
                    MinValue         = settingPropertyAttribute.MinValue;
                    MaxValue         = settingPropertyAttribute.MaxValue;
                    EditableMinValue = settingPropertyAttribute.MinValue;
                    EditableMaxValue = settingPropertyAttribute.MaxValue;
                }
                if (propertyDefinition is IPropertyDefinitionBool propertyDefinitionBool) // v2
                {
                    // Do nothing
                }
                if (propertyDefinition is IPropertyDefinitionWithMinMax propertyDefinitionWithMinMax)
                {
                    MinValue         = propertyDefinitionWithMinMax.MinValue;
                    MaxValue         = propertyDefinitionWithMinMax.MaxValue;
                    EditableMinValue = propertyDefinitionWithMinMax.MinValue;
                    EditableMaxValue = propertyDefinitionWithMinMax.MaxValue;
                }
                if (propertyDefinition is IPropertyDefinitionWithEditableMinMax propertyDefinitionWithEditableMinMax)
                {
                    EditableMinValue = propertyDefinitionWithEditableMinMax.EditableMinValue;
                    EditableMaxValue = propertyDefinitionWithEditableMinMax.EditableMaxValue;
                }
                if (propertyDefinition is IPropertyDefinitionWithFormat propertyDefinitionWithFormat)
                {
                    ValueFormat = propertyDefinitionWithFormat.ValueFormat;
                }
                if (propertyDefinition is IPropertyDefinitionWithCustomFormatter propertyDefinitionWithCustomFormatter)
                {
                    CustomFormatter = propertyDefinitionWithCustomFormatter.CustomFormatter;
                }
                if (propertyDefinition is IPropertyDefinitionWithActionFormat propertyDefinitionWithActionFormat)
                {
                    // TODO:
                }
                if (propertyDefinition is IPropertyDefinitionText propertyDefinitionText)
                {
                    // Do nothing
                }
                if (propertyDefinition is IPropertyDefinitionDropdown propertyDefinitionDropdown)
                {
                    SelectedIndex = propertyDefinitionDropdown.SelectedIndex;
                }
                if (propertyDefinition is IPropertyDefinitionWithId propertyDefinitionWithId)
                {
                    Id = propertyDefinitionWithId.Id;
                }
                if (propertyDefinition is IPropertyDefinitionGroupToggle propertyDefinitionGroupToggle)
                {
                    IsToggle = propertyDefinitionGroupToggle.IsToggle;
                }
            }
        }
        public SettingsPropertyDefinitionWrapper(object @object)
        {
            var type = @object.GetType();

            var settingTypeProperty      = AccessTools2.Property(type, nameof(SettingType));
            var propertyProperty         = AccessTools2.Property(type, nameof(PropertyReference));
            var displayNameProperty      = AccessTools2.Property(type, nameof(DisplayName));
            var hintTextProperty         = AccessTools2.Property(type, nameof(HintText));
            var orderProperty            = AccessTools2.Property(type, nameof(Order));
            var requireRestartProperty   = AccessTools2.Property(type, nameof(RequireRestart));
            var groupNameProperty        = AccessTools2.Property(type, nameof(GroupName));
            var groupOrderProperty       = AccessTools2.Property(type, nameof(GroupOrder));
            var minValueProperty         = AccessTools2.Property(type, nameof(MinValue));
            var maxValueProperty         = AccessTools2.Property(type, nameof(MaxValue));
            var editableMinValueProperty = AccessTools2.Property(type, nameof(EditableMinValue));
            var editableMaxValueProperty = AccessTools2.Property(type, nameof(EditableMaxValue));
            var selectedIndexProperty    = AccessTools2.Property(type, nameof(SelectedIndex));
            var valueFormatProperty      = AccessTools2.Property(type, nameof(ValueFormat));
            var customFormatterProperty  = AccessTools2.Property(type, nameof(CustomFormatter));
            var idProperty                = AccessTools2.Property(type, nameof(Id));
            var isToggleProperty          = AccessTools2.Property(type, nameof(IsToggle));
            var subGroupDelimiterProperty = AccessTools2.Property(type, nameof(SubGroupDelimiter));


            SettingType = settingTypeProperty?.GetValue(@object) is { } settingTypeObject
                ? Enum.TryParse <SettingType>(settingTypeObject.ToString(), out var resultEnum)
                    ? resultEnum
                    : SettingType.NONE
                : SettingType.NONE;

            PropertyReference = propertyProperty?.GetValue(@object) is { } value
                ? value is IRef @ref ? @ref : new RefWrapper(value)
                : new ProxyRef <object?>(() => null, _ => { });

            DisplayName = displayNameProperty?.GetValue(@object) switch
            {
                string str => TextObjectHelper.Create(str)?.ToString() ?? "ERROR",
                TextObject to => to.ToString(),
                _ => "ERROR"
            };
            HintText = hintTextProperty?.GetValue(@object) switch
            {
                string str => TextObjectHelper.Create(str)?.ToString() ?? "ERROR",
                TextObject to => to.ToString(),
                _ => "ERROR"
            };
            Order          = orderProperty?.GetValue(@object) as int? ?? -1;
            RequireRestart = requireRestartProperty?.GetValue(@object) as bool? ?? true;

            GroupName  = TextObjectHelper.Create(groupNameProperty?.GetValue(@object) as string ?? string.Empty)?.ToString() ?? "ERROR";
            GroupOrder = groupOrderProperty?.GetValue(@object) as int? ?? -1;

            MinValue         = minValueProperty?.GetValue(@object) is { } minVal?minVal as decimal? ?? 0 : 0;
            MaxValue         = maxValueProperty?.GetValue(@object) is { } maxVal?maxVal as decimal? ?? 0 : 0;
            EditableMinValue = editableMinValueProperty?.GetValue(@object) is { } eMinVal?  eMinVal as decimal? ?? 0 : 0;
            EditableMaxValue = editableMaxValueProperty?.GetValue(@object) is { } eMaxValue?eMaxValue as decimal? ?? 0 : 0;

            SelectedIndex = selectedIndexProperty?.GetValue(@object) as int? ?? 0;

            ValueFormat = valueFormatProperty?.GetValue(@object) as string ?? SettingType switch
            {
                SettingType.Int => "0",
                SettingType.Float => "0.00",
                _ => string.Empty
            };
            CustomFormatter = customFormatterProperty?.GetValue(@object) as Type;
            Id       = idProperty?.GetValue(@object) as string ?? string.Empty;
            IsToggle = isToggleProperty?.GetValue(@object) as bool? ?? false;

            SubGroupDelimiter = subGroupDelimiterProperty?.GetValue(@object) as char? ?? '/';
        }
Esempio n. 10
0
        private static void CheckLoadOrder()
        {
            var loadedModules = BUTR.Shared.Helpers.ModuleInfoHelper.GetLoadedModules().ToList();

            if (loadedModules.Count == 0)
            {
                return;
            }

            var sb = new StringBuilder();

            var harmonyModule = loadedModules.SingleOrDefault(x => x.Id == "Bannerlord.Harmony");

            var harmonyModuleIndex = harmonyModule is not null?loadedModules.IndexOf(harmonyModule) : -1;

            if (harmonyModuleIndex == -1)
            {
                if (sb.Length != 0)
                {
                    sb.AppendLine();
                }
                sb.AppendLine(TextObjectHelper.Create(SErrorHarmonyNotFound)?.ToString());
            }

            // TODO: Keep it optional for now

            /*
             * var moduleLoaderModule = loadedModules.SingleOrDefault(x => x.Id == "Bannerlord.ModuleLoader");
             * var moduleLoaderIndex = moduleLoaderModule is not null ? loadedModules.IndexOf(moduleLoaderModule) : -1;
             * if (moduleLoaderIndex == -1)
             * {
             *  if (sb.Length != 0) sb.AppendLine();
             *  sb.AppendLine(TextObjectHelper.Create((SErrorModuleLoaderNotFound).ToString());
             * }
             */

            var butterLibModule      = loadedModules.SingleOrDefault(x => x.Id == "Bannerlord.ButterLib");
            var butterLibModuleIndex = butterLibModule is not null?loadedModules.IndexOf(butterLibModule) : -1;

            if (butterLibModuleIndex == -1)
            {
                if (sb.Length != 0)
                {
                    sb.AppendLine();
                }
                sb.AppendLine(TextObjectHelper.Create(SErrorButterLibNotFound)?.ToString());
            }

            var officialModules = loadedModules.Where(x => x.IsOfficial).Select(x => (Module: x, Index: loadedModules.IndexOf(x)));
            var modulesLoadedBeforeButterLib = officialModules.Where(tuple => tuple.Index < butterLibModuleIndex).ToList();

            if (modulesLoadedBeforeButterLib.Count > 0)
            {
                if (sb.Length != 0)
                {
                    sb.AppendLine();
                }
                sb.AppendLine(TextObjectHelper.Create(SErrorOfficialModulesLoadedBeforeButterLib)?.ToString());
                sb.AppendLine(TextObjectHelper.Create(SErrorOfficialModules)?.ToString());
                foreach (var(module, _) in modulesLoadedBeforeButterLib)
                {
                    sb.AppendLine(module.Id);
                }
            }

            if (sb.Length > 0)
            {
                sb.AppendLine();
                sb.AppendLine(TextObjectHelper.Create(SMessageContinue)?.ToString());

                switch (MessageBox.Show(sb.ToString(), TextObjectHelper.Create(SWarningTitle)?.ToString(), MessageBoxButtons.YesNo))
                {
                case DialogResult.Yes:
                    Environment.Exit(1);
                    break;
                }
            }
        }