Skip to content

Menus

Tutorials/Resources

Basic example

Adds new menu option into Village menu

public override void RegisterEvents()
{
    CampaignEvents.OnSessionLaunchedEvent.AddNonSerializedListener(this, new Action<CampaignGameStarter>(this.OnSessionLaunched));
}

private void OnSessionLaunched(CampaignGameStarter starter)
{
    AddGameMenus(starter);
}

private void AddGameMenus(CampaignGameStarter starter)
{
    starter.AddGameMenuOption("village", "test_menu", "My test menu",
    (MenuCallbackArgs args) => {
        args.optionLeaveType = GameMenuOption.LeaveType.HostileAction;
        args.Tooltip = new TextObject("{GOLD_ICON} Tooltip! {GOLD_ICON}", null);
        return true;
    },
    delegate (MenuCallbackArgs args)
    {
        InformationManager.DisplayMessage(new InformationMessage("My menu works!"));
    }, false, 1, false);
}

Another example

Town menu:

private void AddHolyPlaceMenus(CampaignGameStarter starter)
{
    starter.AddGameMenuOption("town", "holy_place", "Go to the {HOLY_PLACE}",
    (MenuCallbackArgs args) => {
        args.optionLeaveType = GameMenuOption.LeaveType.Submenu;
        // set dynamic holy place name - church, mosque, etc
        MBTextManager.SetTextVariable("HOLY_PLACE", "holy place", false);
        return true;
    },
    delegate (MenuCallbackArgs args)
    {
        GameMenu.SwitchToMenu("holy_place");
    }, false, 1, false);

    starter.AddGameMenu("holy_place", "{MENU_TEXT}",
    (MenuCallbackArgs args) => {

        // set proper background picture
        // args.MenuContext.SetBackgroundMeshName("some_bg_picture");

        // set dynamic menu text
        MBTextManager.SetTextVariable("MENU_TEXT", "You are in the holy place...", false);
    }, TaleWorlds.CampaignSystem.Overlay.GameOverlays.MenuOverlayType.SettlementWithBoth);

    starter.AddGameMenuOption("holy_place", "holy_place_enter", "Enter inside", (MenuCallbackArgs args) =>
    {
        args.optionLeaveType = GameMenuOption.LeaveType.Mission;
        return true;
    }, (MenuCallbackArgs args) =>
    {
        InformationManager.DisplayMessage(new InformationMessage("Closed!"));
    }, true);

    starter.AddGameMenuOption("holy_place", "leave", "Leave", (MenuCallbackArgs args) =>
    {
        args.optionLeaveType = GameMenuOption.LeaveType.Leave;
        return true;
    }, (MenuCallbackArgs args) => { GameMenu.SwitchToMenu("town"); }, true);
}
  • "town"
    • "town_keep"
    • "town_arena"
    • "town_backstreet" Tavern District
  • "castle"
  • "village"

AddGameMenu

public void AddGameMenu(
    string menuId,
    string menuText,
    OnInitDelegate initDelegate,
    GameOverlays.MenuOverlayType overlay = GameOverlays.MenuOverlayType.None,
    GameMenu.MenuFlags menuFlags = GameMenu.MenuFlags.None,
    object relatedObject = null)

Background Image

args.MenuContext.SetBackgroundMeshName("wait_raiding_village");

Defined in Modules\Native\GUI\NativeSpriteData.xml

Can use custom 445x805 sprite there.

TaleWorlds.CampaignSystem.Overlay.GameOverlays.MenuOverlayType.SettlementWithBoth

Possible types:

public enum MenuOverlayType
{
    None,
    SettlementWithParties,
    SettlementWithCharacters,
    SettlementWithBoth,
    Encounter
}

AddGameMenuOption

public void AddGameMenuOption(
    string menuId,
    string optionId,
    string optionText,
    GameMenuOption.OnConditionDelegate condition,
    GameMenuOption.OnConsequenceDelegate consequence,
    bool isLeave = false,
    int index = -1,
    bool isRepeatable = false)
  • bool isLeave = false - if True, by pressing Tab goes back to previous menu or to the map
  • int index = -1 - order in the menu (some options can be hidden, so will not always show in the exact index you define), -1 - at the very end

Enabled/Disabled

args.IsEnabled = false;

Tooltip

args.Tooltip = new TextObject("{=yNMrF2QF}You are wounded", null);

Icon

args.optionLeaveType = GameMenuOption.LeaveType.ICON_NAME;
ICON_NAMEs 1.1.0+

ICON_NAMEs 1.0.3

Back to previous menu

GameMenu.ExitToLast();
AddWaitGameMenu
Basic example:

private static CampaignTime actionStart = CampaignTime.Now;

campaignGameStarter.AddWaitGameMenu("wait_menu_name", "top text", delegate (MenuCallbackArgs args)
{
    args.MenuContext.GameMenu.SetTargetedWaitingTimeAndInitialProgress(10f, 0f);
    actionStart = CampaignTime.Now;
}, delegate (MenuCallbackArgs args)
{
    return true;
}, delegate (MenuCallbackArgs args)
{
    GameMenu.ExitToLast();
}, delegate (MenuCallbackArgs args, CampaignTime dt)
{
    args.MenuContext.GameMenu.SetProgressOfWaitingInMenu((float)actionStart.ElapsedHoursUntilNow / 10);
}, GameMenu.MenuAndOptionType.WaitMenuShowOnlyProgressOption, GameOverlays.MenuOverlayType.None, 0f, GameMenu.MenuFlags.None, null);

campaignGameStarter.AddGameMenuOption("wait_menu_name", "leave", "Leave", delegate (MenuCallbackArgs args)
{
    args.optionLeaveType = GameMenuOption.LeaveType.Leave;
    return true;
}, delegate (MenuCallbackArgs args)
{
    GameMenu.ExitToLast();
}, false, -1, false);

args.MenuContext.GameMenu.SetTargetedWaitingTimeAndInitialProgress(10, 0f); - set's how long to wait

args.MenuContext.GameMenu.SetProgressOfWaitingInMenu(100); - stops the waiting (even if previously wait time is not reached yet)

ProgressBar

  • GameMenu.MenuAndOptionType.WaitMenuShowOnlyProgressOption - only progress bar
  • GameMenu.MenuAndOptionType.WaitMenuShowProgressAndHoursOption - writes total wait hours on top of progress bar

Progressbar will not be shown if there are no AddGameMenuOption after the AddWaitGameMenu

Sound in menus

args.MenuContext.SetPanelSound("event:/ui/panels/settlement_village");
args.MenuContext.SetAmbientSound("event:/map/ambient/node/settlements/2d/village");