[UI] Can I add a new button next to 'Kick from clan'?

Users who are viewing this thread

Hello all,

Recently got Bannerlord and have about 120 hours logged in already. Just had a small modding idea and started checking documentation and the few YouTube guides I could find.

My question is: Is it possible to add a new button next to 'Kick from clan'?
I have been reading the modding tutorial/guides for the last hour but haven't found much on this, yet.
And if it is possible, are there any mods that already does this that you can reference, so that I can check their code and learn how it's done?

What I have found so far, on the file system, is the following strings in files:
* module_strings.xml <string id="str_kick_from_clan" text="{=vvXTnr8i}Kick from clan" />
* std_module_strings_xml.xml <string id="vvXTnr8i" text="Kick from clan" />
However I do not know how/where code references this to generate the actual UI. I did see a message about UI being similar to a Microsoft technology (WPF) but that doesn't help me much as I never used it and unsure how to actually do it in Bannerlord.

And if it is not possible to modify the UI yet, would it make sense to add a global shortcut (such as F4, ALT+X or something) to trigger functionality (a function from a C# compiled mod) when looking at a "clan member profile" in Clan section?

Thanks!
 
Solution
Yes, there may be more efficient ways of doing this but this way works. I added a second button that changes the kick from clan text to count how many times I pressed the custom button.
Screenshot-149.png
What you want to do is copy ClanMembers.xml (Mount & Blade II Bannerlord\Modules\SandBox\GUI\Prefabs\Clan) to the mods GUI/prefabs folder so the clan members UI is overridden by the mod. Then simply copy the widget with the kick button and change it to your liking. You can add your own hint if you want to but I simply removed it and changed the TextWidget for the button to say Custom Button instead, you can set a string in code and then reference it with @variablename if you prefer it that way...
Yes, there may be more efficient ways of doing this but this way works. I added a second button that changes the kick from clan text to count how many times I pressed the custom button.
Screenshot-149.png
What you want to do is copy ClanMembers.xml (Mount & Blade II Bannerlord\Modules\SandBox\GUI\Prefabs\Clan) to the mods GUI/prefabs folder so the clan members UI is overridden by the mod. Then simply copy the widget with the kick button and change it to your liking. You can add your own hint if you want to but I simply removed it and changed the TextWidget for the button to say Custom Button instead, you can set a string in code and then reference it with @variablename if you prefer it that way. When pressed the button will call the function in Command.Click="FunctionName"
Screenshot-150.png
So in order to call your code/access your variables you need to add it to ClanMembersVM. This is easily done with Harmony. First make a derived class with your new methods/fields.
Screenshot-152.png
Then use Harmony to replace the original, which is instantiated in ClanManagementVM. Unfortunately ClanMembersVM needs a private function of ClanManagementVM in the constructor so a bit of reflection is needed to access it. The ClanMembers property in ClanManagementVM is set only once and so this way of setting the derived VM should be safe in this case.
Screenshot-151.png

Now you can change Command.Click to use your new function in the ClanMembers.xml and it should hopefully work. Hopefully this has been a clear enough answer for this question, once again there may be better ways to do this (that don't need Harmony) but this should work until someone more experienced can explain such a way.
 
Upvote 0
Solution
Yes, there may be more <snip>

What you want to do is copy ClanMembers.xml (Mount & Blade II Bannerlord\Modules\SandBox\GUI\Prefabs\Clan) to the mods GUI/prefabs folder so the clan members UI is overridden by the mod. Then simply copy the widget with the kick button and change it to your liking. You can add your own hint if you want to but I simply removed it and changed the TextWidget for the button to say Custom Button instead, you can set a string in code and then reference it with @variablename if you prefer it that way. When pressed the button will call the function in Command.Click="FunctionName"

I started working through your post; haven't followed the C# part in your advice yet however I have been able to follow the most simple bit at the top so far and thus successfully added a button (with CompanionText as placeholder for now) which is a great first step for me!

8wOnoP9.png


Thanks again!
 
Upvote 0
Back
Top Bottom