Git Product home page Git Product logo

uiextenderlib's Introduction

Library for Mount & Blade: Bannerlord that enables multiple mods to alter standard game interface.

Introduction

  • UIExtenderLib is a library that you use in your project, which provides a number of attributes to decorate your classes with, which will enable those classes to alter Gauntlet prefabs and make additions to default ViewModels.
  • UIExtenderLibModule which should be loaded on target computer will then collect all of the extensions, and will patch them in on startup of the game.

Installation

Download latest version of UIExtenderLibModule from releases and drop it into your Modules folder. UIExtenderLib doesn't need to be installed as it comes with the mods.

When you should use it

If you change any of the game standard prefab .xml files you should use this library or similar approach in order to not overwrite changes to the same elements by other mods. You don't need to use this if you are adding a completely new screen or a menu item in the encounter overlay, since things like that are already handled correctly by the game API.

Quickstart

You mark your prefab extensions based on one of the IPrefabPatch descendants and marking it with PrefabExtension attribute, therefore enabling you to make additions to the specified Movie's XML data.

    [PrefabExtension("MapBar", "descendant::ListPanel[@Id='BottomInfoBar']/Children")]
    public class PrefabExtension : PrefabExtensionInsertPatch
    {
        public override int Position => PositionLast;
        public override string Name => "HorseAmountIndicator";
    }

This specific extension will load prefab HorseAmountIndicator.xml from Mod/GUI/PrefabExtensions/ folder.

In order to add data to the prefab, you need to add properties to the target datasource class, which in case of BottomInfoBar is MapInfoVM, this is done by making a mixin class, inheriting from BaseViewModelMixin<T> and marking it with ViewModelMixin attribute. This class will be mixed in to the target view model T, making fields and methods accessible in the prefab:

    [ViewModelMixin]
    public class ViewModelMixin : BaseViewModelMixin<MapInfoVM>
    {
        private int _horsesAmount;
        private string _horsesTooltip;
        
        [DataSourceProperty] public BasicTooltipViewModel HorsesAmountHint => new BasicTooltipViewModel(() => _horsesTooltip);
        [DataSourceProperty] public string HorsesAmount => "" + _horsesAmount;

        public ViewModelMixin(MapInfoVM vm) : base(vm)
        {
        }
        
        public override void Refresh()
        {
            var horses = MobileParty.MainParty.ItemRoster.Where(i => i.EquipmentElement.Item.ItemCategory.Id == new MBGUID(671088673));
            var newTooltip = horses.Aggregate("Horses: ", (s, element) => $"{s}\n{element.EquipmentElement.Item.Name}: {element.Amount}");

            if (newTooltip != _horsesTooltip)
            {
                _horsesAmount = horses.Sum(item => item.Amount);
                _horsesTooltip = newTooltip;

                _vm.OnPropertyChanged(nameof(HorsesAmount));
            }
        }
    }

The last thing is to call UIExtender.Register(); to register your attributed classes:

        protected override void OnSubModuleLoad()
        {
            base.OnSubModuleLoad();
            
            UIExtender.Register();
        }

Documentation

Rest of the documentation is located on wiki.

Examples

uiextenderlib's People

Contributors

shdwp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.