Repository navigation
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.
-
Layers.
ui::UIManagerhas 8 groups (GROUP_MAX) and up to 32 live layers. A layer is a row of the BDAT tableMNU_Layer(columnsgroup,sheet01,sheet02, ...);createLayerinstantiates every non-empty sheet of the row in its group, andterminateLayer,releaseLayerandpreloadLayeriterate 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;requestGameEventqueues one for the single globalUIGameListener(the full-screen manager).EventDatais0x18bytes: a u16 type at 0 and four u32 parameters at0x08,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 callsUIObjectListener::reciveEvent(event, handle)on the registered listener (skipped when the object is terminating); game events go toUIGameListener::reciveEvent. Registering a listener pushes an event of type 1 ("created") to it. The baseUIObjectListener::reciveEventhandles only type 2 (it terminates the object); every menu listener passes unknown events to it.
- A
GfMenuObject(an intrusive list node,0x28bytes) wraps one UI object handle with virtualinitialize,finalize,update,reloadParamand a layer id. About 123gf_menu_obj_*.cppclasses exist (M/object/). Each registers one or moreUIObjectListenersubclasses (typical names:MainListener,ContentsListener,IndexListener,CloseListener,ChrChangeListener) on its sub-objects, which are addressed by names such asLAY_main,LAY_contents,TXT_contents_item@01. - Static helpers on
GfMenuObjectwrap input selection and pad or pointer setup, event senders (sendEvent,sendOpenEvent= type0x21,sendCloseEvent=0x22,sendEventToChild/Parent), event-condition watchers, timers and full-screen helpers. The enumGfMenuTypes::unknown003labels0x21(open),0x22(close) and0x100to0x104(start, suspend, resume, end, update); these are inferred roles and individual objects reuse the0x100+ 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'sseq*functions are an example (seqCreateSetupqueues "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,0xcclear the layer stack of a group. Per-object event 2 is "abort or close".
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,0x20bytes) are stored withregistLayerParam. -
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(untilUIManager::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 event0x43with 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. AUIInputSwitcherof 8 manages which object receives input per layer.
-
GfMenuManager::openMenu(menu),openBladeCreateFromEvent(event)andopenSave()register an open parameter onGfMenuObjMainRoot(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::initializereads the menu id (default 1), looks its UI layer up in the BDAT tableMNU_FSMenu(columnlayer_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 event0x43.MNU_FSMenualso hasicon,text,desccolumns. -
Call contexts (how gameplay code waits for a menu):
GfMenuCallManagerhas 135 "call" slots mapping a call id to an attached UI object and up to 256 call contexts. AGfMenuCallContextis 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;postUpdatereleases terminated contexts. Menu ids called through contexts include 68 (chapter telop), 69 (zone telop), 100 (common text window) and 121 (dummy tutorial).
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 columnsuseCond,title,subTitle,titleIcon,guide; texts come frommenu_main_contents_ms. A row whoseuseCondfails shows a fixed "disabled" message id0x67cfrommenu_ms, and aSelectionCheckeronly allows selecting rowiwhen itsuseCondpasses. - 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:setMainmenuOpenMapuses page 1,setMainmenuOpenSystempage 6; the sentinel for "no sub menu" is0x28, and0x27means the character-change panel is open. Its call id is0x5f; external helpers (setCloseKeyEnable,setSubIndexText,setGuideText,openCharChange, ...) find the object through it and send UI events (0x105open main menu,0x106system key enable,0x108set sub layer,0x10aguide text,0x10emap 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, thenopenMainMenu); with none open it terminatesLAY_mainafter 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.
M/gf_menu_manager.cpp; the object is 0x4158 bytes.
-
isInitializedrequires 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
changeBattleStateand game events and applied byupdateHudStatefor 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.GfMenuHUDcreates everyMNU_*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 flag0x3a + itemTypeso an item category tab becomes visible; item types 1 to 20).setupGameinitialises menu flags0x28to0x31and 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.
startTutorialchecks a one-shot flag per tutorial (0xc710 + (tutorial - idTop)overBDAT_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 gamma2v + 1.2on the layer and render system. The region is stored as JP or US (isRegionJP,isRegionUS).
Engine-Overview, Blade-Creation, Event-System, Drivers-Blades-Party