Skip to content

Menus and UI

Kevin Bonnoron edited this page Nov 21, 2026 · 1 revision

Menus and UI

How the menu system is built: the ui widget library (layers, objects, events), the GfMenu* game layer on top (the full-screen manager, menu objects, call contexts, the HUD) and a worked example, the main menu. Files: src/application/BF2/ui/ (U/), src/application/BF2/gf/menu/ (M/), and the 2D layout renderer in src/libs/layer (see Engine-Overview). Reading guide: Home. Snapshot: main at commit a313ecb66. Members named unknownXX carry inferred roles; "inferred" marks those. The Blade creation screen (Blade-Creation) is one more worked example of everything below.

Coverage. Several of the central functions are not decompiled yet: GfMenuManager::postUpdate (0x71003c30b0, 1,164 bytes), GfMenuManager::reciveEvent (0x71003c35f4, 6,524), GfMenuManager::initialize (1,656), GfMenuFullScreen::open, isOpen and reciveUIEvent (0x71003bbb18, 892), ui::UIManager's constructor, destructor, update and createLayer. The behaviour of the pieces below is what the surrounding matched code shows.

The ui library

  • Layers. ui::UIManager has 8 groups (GROUP_MAX) and up to 32 live layers. A layer is a row of the BDAT table MNU_Layer (columns group, sheet01, sheet02, ...); createLayer instantiates every non-empty sheet of the row in its group, and terminateLayer, releaseLayer and preloadLayer iterate the same sheets. Menu tables loaded at init: MNU_ResImage, MNU_ResLayout, MNU_ResFont, MNU_ResFontStyle, MNU_ResMSProj, menu_ms, MNU_Layer, MNU_InputPad, MNU_InputWheel, MNU_InputPointer, MNU_InputAct, MNU_TextProperty, MNU_ColorList, MNU_FacePatternList, MNU_ResMotion, MNU_ResUio. UIUtil::getGroupPriority(g) = g << 5 | 1 (U/ui_util.cpp).
  • Handles and events. Every UI object has a handle. UIManager::requestObjectEvent(handle, EventData, delay) queues an event for an object; requestGameEvent queues one for the single global UIGameListener (the full-screen manager). EventData is 0x18 bytes: a u16 type at 0 and four u32 parameters at 0x08, 0x0c, 0x10, 0x14 (U/event/ui_event_data.h).
  • Delivery. UIEventManager::update (U/event/ui_event_manager.cpp) first evaluates conditions (watchers for number, display and position changes, which emit event type 13 with the changed value), then pops events whose delay (seconds) has run out and calls UIObjectListener::reciveEvent(event, handle) on the registered listener (skipped when the object is terminating); game events go to UIGameListener::reciveEvent. Registering a listener pushes an event of type 1 ("created") to it. The base UIObjectListener::reciveEvent handles only type 2 (it terminates the object); every menu listener passes unknown events to it.

Menu objects (GfMenuObject)

  • A GfMenuObject (an intrusive list node, 0x28 bytes) wraps one UI object handle with virtual initialize, finalize, update, reloadParam and a layer id. About 123 gf_menu_obj_*.cpp classes exist (M/object/). Each registers one or more UIObjectListener subclasses (typical names: MainListener, ContentsListener, IndexListener, CloseListener, ChrChangeListener) on its sub-objects, which are addressed by names such as LAY_main, LAY_contents, TXT_contents_item@01.
  • Static helpers on GfMenuObject wrap input selection and pad or pointer setup, event senders (sendEvent, sendOpenEvent = type 0x21, sendCloseEvent = 0x22, sendEventToChild/Parent), event-condition watchers, timers and full-screen helpers. The enum GfMenuTypes::unknown003 labels 0x21 (open), 0x22 (close) and 0x100 to 0x104 (start, suspend, resume, end, update); these are inferred roles and individual objects reuse the 0x100+ ids differently.
  • Sequences. A menu object runs steps through a GfMenuSequence<T, 8>: a queue of up to 8 member-function steps, each run once per frame until it returns true; helpers queue waits (frame counts) and animation jobs (start an animation, wait until it stops). The Blade creation screen's seq* functions are an example (seqCreateSetup queues "start driver, wait 120 frames, start sound, wait driver, wait fade, build Blade").
  • Game events sent to the full-screen manager (GfMenuObject::changeFSLayer, returnFSLayer, closeFSLayer, changeFSSubLayer, returnFSSubLayer, clearLayerStatck, addResultCallContext, termCallContext): 1 change layer or sub layer (layer, group, keep flag), 3 return from a layer, 7 close the full-screen layer (fade flag, keep flag), 8 add a result to a call context (type, value), 9 terminate a call context, 0xc clear the layer stack of a group. Per-object event 2 is "abort or close".

The full-screen manager (GfMenuFullScreen)

M/gf_menu_fullscreen.cpp.

  • Screens and groups. 8 screen ids map to UI layer ids through the table {0, 9, 2, 4, 7, 11, 3, 26} (0 means none; ids above 7 have no layer). There are 4 layer groups, each holding a layer id, a list of up to 8 terminated layers (the "stack" used for returning), a layer object handle and a shadow flag. Up to 8 per-layer parameters (GfMenuTypes::Param, 0x20 bytes) are stored with registLayerParam.
  • Opening and closing is a delegate state machine run from postUpdate: switchLayerStart (terminate the current layers, black fade-out, default 15 frames) -> wait for the fade -> release layers -> wait for the release -> OpenScreen (create group 0's layer) -> WaitScreen (until UIManager::isLoading() has been false for 2 frames) -> fade in (default 15 frames) -> done. A close request sets the target screen to 0, runs the same chain and creates no new layer. Sub-layers (groups 1 to 3) use a separate chain (subLayerWaitRelease, subLayerCreate, subLayerWaitOpen); when a sub-layer closes and its parent has a registered object, the parent gets event 0x43 with the group index.
  • Input. While switching, UI input priority is getGroupPriority(4); afterwards it goes back to priority group 3, or to a one-shot override. A UIInputSwitcher of 8 manages which object receives input per layer.

Calling menus from game code

  • GfMenuManager::openMenu(menu), openBladeCreateFromEvent(event) and openSave() register an open parameter on GfMenuObjMainRoot (a menu id, for example 11 for Blade creation and 53 for save/load), optionally a page-specific parameter, and open full screen 2 with fade out and in. GfMenuObjMainRoot::initialize reads the menu id (default 1), looks its UI layer up in the BDAT table MNU_FSMenu (column layer_id; layer 1 if the id is invalid) and opens it as sub-layer group 1; its listener closes the full-screen layer on result 3 or event 0x43. MNU_FSMenu also has icon, text, desc columns.
  • Call contexts (how gameplay code waits for a menu): GfMenuCallManager has 135 "call" slots mapping a call id to an attached UI object and up to 256 call contexts. A GfMenuCallContext is reference-counted and records the target menu, the object, up to 4 results (value and type) and a terminated flag. States: 0 no UI object attached, 1 attached and running, 2 terminating; postUpdate releases terminated contexts. Menu ids called through contexts include 68 (chapter telop), 69 (zone telop), 100 (common text window) and 121 (dummy tutorial).

The main menu (GfMenuObjMainMenu2)

M/object/gf_menu_obj_mainmenu2.cpp; the object is 0x328 bytes.

  • Entries come from the BDAT table MNU_MainOrder: up to 7 rows (FixedVector<u32, 7>) with columns useCond, title, subTitle, titleIcon, guide; texts come from menu_main_contents_ms. A row whose useCond fails shows a fixed "disabled" message id 0x67c from menu_ms, and a SelectionChecker only allows selecting row i when its useCond passes.
  • Five listeners on LAY_main, LAY_contents, LAY_index, LAY_close, LAY_chr_change, with 2 call contexts. The open parameter ("page") goes to full screen 1: setMainmenuOpenMap uses page 1, setMainmenuOpenSystem page 6; the sentinel for "no sub menu" is 0x28, and 0x27 means the character-change panel is open. Its call id is 0x5f; external helpers (setCloseKeyEnable, setSubIndexText, setGuideText, openCharChange, ...) find the object through it and send UI events (0x105 open main menu, 0x106 system key enable, 0x108 set sub layer, 0x10a guide text, 0x10e map jump).
  • The character-change panel lists up to 16 drivers (GfPartySelect, party list) or the Blade list (see Drivers-Blades-Party).
  • Closing: with a sub-menu open, "cancel" returns to the main list (returnFSSubLayer, then openMainMenu); with none open it terminates LAY_main after a 16-frame step queue. Opening fades field BGM to 1.0 over 0.5 s and pauses popup pickups; closing resumes pickups after 20 frames unless a map jump was requested.
  • Not decompiled: ContentsListener::reciveEvent (the main-list selection handler, 0x7100485e6c, 2,940 bytes), openChrChangeSub, openChrChange2Sub, dispGuide.

The manager (GfMenuManager)

M/gf_menu_manager.cpp; the object is 0x4158 bytes.

  • isInitialized requires 21 sub-managers to be up: Reference, CallManager, AdapterManager, Fade, FullScreen, HUD, Status, Equip, Main, Shop, Precious, Kizunaring, Quest, Minimap, ScriptManager, FieldSkill, ManyObjects, OrderMgr, Location, MapInfo, SoundManager. Three fades exist (isFading() checks fades 0 to 2).
  • HUD. HUD state is a 32-bit bitset updated by changeBattleState and game events and applied by updateHudState for 6 HUD groups (the roles are a reading of what each branch opens or hides): 0 battle HUD (arts palette, party gauge, Blade change, special gauge, party status), 1 target and status HUD (party status, target info and cursor, field icons, enemy status, action window), 2 field HUD (compass, minimap, environment info, help), 3 quest log, Blade switch, popups, 4 hide target info, combo route, party gauge, 5 hide enemy status, combo route, party status 2, party gauge. GfMenuHUD creates every MNU_* layer row of groups 0, 1, 2 and 4 at start-up.
  • Game events it listens to: gevBattleStart/End, gevPlayEvent (codes 9, 11, 12, 13), gevPlayerControl (14, 15), gevSalvageStateChange, gevAccessTarget (opens the action window), gevChangeTarget (enemy status and party status lock), gevItemAdd (sets a menu flag 0x3a + itemType so an item category tab becomes visible; item types 1 to 20). setupGame initialises menu flags 0x28 to 0x31 and sets the flag of every item type that has items. The combo route opens and closes when the target enemy's combo flag changes (checkElementCombo).
  • Pooled HUD objects (GfMenuManyObjects): 8 queues with capacities damage value 32, damage buff 32, chain icon 32, drop item 64, popup 64; when a queue is full the oldest entry is closed and disposed before a new one is pushed.
  • Other direct layers: battle model view layer 10, name select 12, opening telop 13, staff roll 14. The chapter telop is limited to chapters 1 to 10. startTutorial checks a one-shot flag per tutorial (0xc710 + (tutorial - idTop) over BDAT_MNU_TUTORIAL) before creating a tutorial.
  • First boot language selection (selectLanguage): a 6-step state machine that loads language images; confirm and cancel pad bits choose among 3 languages (reload-text requests with language types 0, 11 or 6). Gamma: applyGammaCorrectValue(v) sets gamma 2v + 1.2 on the layer and render system. The region is stored as JP or US (isRegionJP, isRegionUS).

See also

Engine-Overview, Blade-Creation, Event-System, Drivers-Blades-Party

Clone this wiki locally