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;
        return true;
    },
    delegate (MenuCallbackArgs args)
    {
        InformationManager.DisplayMessage(new InformationMessage("My menu works!"));
    }, false, 1, false);
}
  • "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.

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:

campaignGameStarter.AddWaitGameMenu("wait_menu_name", "top text", delegate (MenuCallbackArgs args)
{
    args.MenuContext.GameMenu.SetTargetedWaitingTimeAndInitialProgress(10f, 0f);
}, delegate (MenuCallbackArgs args)
{
    return true;
}, delegate (MenuCallbackArgs args)
{
    GameMenu.ExitToLast();
}, delegate (MenuCallbackArgs args, CampaignTime dt)
{
    args.MenuContext.GameMenu.SetProgressOfWaitingInMenu((float)this._startTimeOfWaiting.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");