Skip to content

127 worked example the front end menus as pack data

Alex Diakovsky edited this page Oct 11, 2026 · 1 revision

127. Worked example: the front end's menus as pack data

Question: the original's front end is a fixed chain of Windows dialogs. How does the port make its menus configurable by a pack, without changing what Return Fire shows? (Issue #83; the design constraint is the user's: the menu must be configurable by the pack, not by editing the engine.)

This is a port design, not a new trace. What the original does is in document 122 (the dialogs: DialogBoxParamA with resources 2001 Player Selector, 2002 Level Selector, and the rest) and document 125 (the Level Selector, whose nine "Level n" radios are the difficulty, LEVL + 1, each radio a folder WORLDS\1Player\LEVELn or 2Player). The original has no menu data to extract: each dialog is a resource plus a hand-written procedure. So the engine takes the shape of today's flow as its default, and a pack may replace it.

Step 1: the definition

MenuDef (game/menu_def.gd) is the engine's default flow, written as the data a pack would write:

const DEFAULT := {
	"start": "title",
	"screens": {
		"title": {"type": "title", "next": "main"},
		"main": {"title": "Main menu", "items": [
			{"label": "Campaign", "action": {"screen": "campaign"}},
			{"label": "Multiplayer", "action": {"screen": "multiplayer"}},
			{"label": "Settings", "action": {"screen": "settings"}}]},
		"campaign": {"type": "level_select", "players": 1, "difficulty_filter": true, "back": "main"},
		"multiplayer": {"type": "level_select", "players": 2, "difficulty_filter": true, "back": "main"},
		...

A pack's ui/menus.json is laid over it: a screen it names replaces the default's screen of that id (a null removes one), start picks the first screen. Layers merge the same way (Pack.ui_menus). Three screen types exist: title (the picture, any key goes on), dialog (a title, a message, a column of buttons) and level_select. An item's action is exactly one of {"screen": id}, {"start_level": id}, {"hook": name}; a hook is a Callable the game registered with GameFlow.register_hook, which is how a game reaches its own code (Return Fire's "Game files..." stays a Settings entry the same way). MenuDef.problems() lists dead screen references and unknown actions, and GameFlow logs them when the game starts.

Step 2: the interpreter

GameFlow no longer has a function per screen. One entry point reads the definition:

func show_screen(id: String) -> void:
	if id == "@last":
		id = _last_select
	var screen: Variant = _menus.screens.get(id)
	...
	match String(screen.get("type", "dialog")):
		"title": _show_title_screen(screen)
		"level_select": _show_level_select_screen(id, screen)
		_: _show_dialog(screen)

"@last" is the level select shown most recently: where Escape, a win and "Mission failed" return to, as the old _players field did.

Step 3: the difficulty filter

The original's nine radios become an optional "Difficulty" choice on a level_select screen (difficulty_filter: true): All, or Level 1 to 9. Each level's difficulty is read from the file's text, without parsing it, like the player count:

static func peek_difficulty(level_dir: String) -> int:
	var m := RegEx.create_from_string("\"levl_value\"\s*:\s*(\d+)").search(FileAccess.get_file_as_string(level_dir.path_join("level.json")))
	return int(m.get_string(1)) + 1 if m != null else 1

Choosing a difficulty rebuilds the list from the screen's candidates and reselects the first row, which also redraws the map and the facts window. It is a filter over the one list Return Fire has today, not the original's folder structure.

What stays as it is

Return Fire's pack ships no ui/menus.json: its menus are the engine default, unchanged apart from the filter. The original's own menu order (Player Selector first, the Add-Ons list, saved progress icons) is not built. How progression, unlocking and the saved records worked is traced in issue #92.

Checks: tests/menu_def_check.gd (default has no problems, a dead reference is reported, a pack's own start screen and hook, the filter narrowing and emptying the list) and the existing game-flow checks, which now call show_screen.

Clone this wiki locally