menu

The game's own menus: buttons in its style, pages, the game's buttons hidden or moved, menu events.

The game's own menus, for mods: buttons that look and behave like the game's in its menus, the game's buttons hidden or moved, whole pages drawn with the game's backgrounds, fonts and buttons (no ImGui), and the menu actions as events. The Menus and pages guide walks through it; Ice Age and Dinosaur Hunter work the same, on PC and on Android (the game's touch handling drives the buttons).

Menus (the where of menu.button, menu.hide ...): main (the main menu), more (MORE), hunt_area, hunt_species, hunt_weapon (the three hunt menu pages), game (the hunt's menu: ESCAPE / RESTART / OPTIONS), or the id of one of your pages.

Units: game units, as the game lays out its menus: the screen is 320 units high (480 wide on screens narrower than 3:2; menu.screen() gives the size), x from the left, y from the top. An item's x, y is its centre (texts: x by align, y the top). Left out, items are placed in their menu: the main menu's grid continues below the game's rows, MORE's column below its buttons, the hunt pages stack them in the right column, the hunt's menu gets cells around the game's, a page has one centred column from the top.

The game's buttons by name: main: hunt, survive (Dinosaur Hunter), trophy, more, mods, quit. more: options, switch, about, back. hunt_area: back, next, dawn, day, night, observer. hunt_species: back, next. hunt_weapon: back, hunt, camouflage, cover_scent, tranquilizer, radar. game: escape, restart, options (hidden only).

Items (what menu.button, menu.text, menu.image, menu.list and the page's functions return) have methods: item:setText(text), item:text(), item:setVisible(on), item:setEnabled(on), item:move(x, y) (no arguments: back to its automatic place), item:position() (its centre this frame), item:setSprite(name), item:setColor(color [, textColor]), item:remove(), item:valid(); lists also item:setRows(rows), item:select(i), item:selected() (index, text). Pages (menu.page) have page:button / text / image / list (as menu.* with the page as where), page:open([{fade = false}]), page:close(), page:isOpen(), page:clear() (removes its items) and page:remove().

Options every item takes: x, y, scale, textScale, color, textColor, font (the game's: lith18 (the buttons' stone letters, no digits in Ice Age), ofs15, ofs13, ccra14), order, visible, enabled, sound (a .wav played on a click, e.g. "menugo.wav"). Texts are UTF-8; the game's fonts show Latin-1, other characters as ?, and # (the game's colour codes) as a space.

While the mods load the game's GUI does not exist yet: items can be made then, but sizes, sprites and fonts are known from the menu_ready event on.

Functions

# menu.button(where, label, fn?, options?) → table

since API 3

A button of the game's own kind in that menu: its sprite, its font and its touch (the label lights up while pressed). In the hunt's menu (game) a cell like ESCAPE / RESTART / OPTIONS that slides in with them.

ParameterType
wherestringa menu (main, more, hunt_area, hunt_species, hunt_weapon, game) or a page id
labelstringthe text on it
fn optionalfunctionfn(item), called when it is pressed
options optionaltablex, y, scale, textScale, color, textColor, font, order, visible, enabled, sound, sprite (main: button_med_01..04, more and pages: button_med_02, hunt pages: button_small_02), pressedSprite
Returns
tablethe item
menu.button("main", "ARENA", function() arena:open() end)
menu.button("game", "Help", function() helpPage:open() end)
menu.button("hunt_weapon", "LOADOUT", showLoadout, {x = 420, y = 210})

# menu.text(where, text, options?) → table

since API 3

A text in one of the game's fonts (default ofs15).

ParameterType
wherestringa menu or a page id
textstringUTF-8; \n breaks lines
options optionaltablex, y, scale, textScale, color, textColor, font, order, visible, enabled, sound, width (wraps the text), align ("left", "center" (default), "right")
Returns
tablethe item
page:text("Pick a mission.", {width = 300})

# menu.image(where, sprite, options?) → table

since API 3

A picture: one of the game's sprites (menu cells, icons, buttons, backgrounds) or your own.

ParameterType
wherestringa menu or a page id
spritestringa sprite of the game (ui/*.cfg), of your sprite file (menu.loadSprites), or a .tga file of your mod
options optionaltablex, y, scale, textScale, color, textColor, font, order, visible, enabled, sound
Returns
tablethe item
page:image("button_dino_active_9", {scale = 0.8})

# menu.list(where, rows, fn?, options?) → table

since API 3

A list of rows to pick from; the picked one in the game's gold. More rows than fit: small arrows page through them.

ParameterType
wherestringa menu or a page id
rowstablethe rows' texts
fn optionalfunctionfn(index, text, item) when a row is picked
options optionaltablex, y, scale, textScale, color, textColor, font, order, visible, enabled, sound, width (240), rows (shown at once, 6), rowHeight, selected (index)
Returns
tablethe item
local list = page:list({"Easy", "Normal", "Hard"}, function(i, text) difficulty = i end, {rows = 3, selected = 2})

# menu.page(id, options?) → table

since API 3

A whole screen in the game's style: its background, a red title, a BACK button at the game's place (Esc and the Android back button close it too), and the items you add. Opened over any menu or the hunt (which waits meanwhile); pages opened from a page stack. The same id again returns that page with its options changed.

ParameterType
idstringyour page's id (prefix it with your mod's)
options optionaltabletitle, background (a sprite, default the MORE screen's; false: the screen dimmed), back (false: no BACK button; a string: its label), top (the first automatic row, default 64), onOpen(page), onClose(page), onBack(page) (return false to stay open), draw(page) (draw.* in game units, every frame)
Returns
tablethe page
local shop = menu.page("myshop:main", {title = "Trader", onOpen = refresh})
shop:text("Your credits: " .. player.credits())
shop:button("BUY AMMO", buyAmmo)
menu.button("main", "TRADER", function() shop:open() end)

# menu.open(page, options?)

since API 3

Opens a page.

ParameterType
pagestring|tablea page or its id
options optionaltablefade (default true: the game's black fade)

# menu.close(page?)

since API 3

Closes a page (back to what was under it).

ParameterType
page optionalstring|tablea page (default: the one on top)

# menu.current() → string|nil

since API 3

Where the player is.

Returns
string|nilthe open page's id, else the menu shown (main, more, hunt_area ..., game), nil elsewhere

# menu.hide(where, name)

since API 3

Hides one of the game's buttons (it takes no presses either) until menu.show or the scripts reload.

ParameterType
wherestringa menu
namestringone of the game's buttons there (see above)
menu.hide("main", "survive")
menu.hide("hunt_weapon", "tranquilizer")

# menu.show(where, name)

since API 3

Shows a button menu.hide hid.

ParameterType
wherestring
namestring

# menu.move(where, name, x?, y?)

since API 3

Moves one of the game's buttons (with its icon); without x, y it goes back. The hunt's menu cells can only be hidden.

ParameterType
wherestring
namestring
x optionalnumberits new centre
y optionalnumber
menu.move("more", "about", 400, 120)

# menu.buttons(where) → table

since API 3

The game's buttons of a menu, where they are now.

ParameterType
wherestringa menu
Returns
table{{name, x, y, w, h, shown, text}, ...}: centre and size in game units

# menu.reset()

since API 3

Every hidden or moved game button back as the game has it.

# menu.screen() → number, number

since API 3

The screen in game units (0, 0 before menu_ready).

Returns
numberwidth in game units
numberheight (320 on screens 3:2 and wider)

# menu.selection() → table

since API 3

The hunt menu's choice as it stands: what the next hunt would be. price: licences (Dinosaur Hunter) or what the hunt costs against the credits (Ice Age); ammoPrice: paid when the hunt starts (Dinosaur Hunter: ammunition and equipment).

Returns
table{map, time ("dawn" "day" "night"), observer, species = {ids}, weapons = {ids}, equipment = {ids}, price, ammoPrice}
on("menu_action", function(e)
  if e.button == "hunt" and #menu.selection().species > 5 then
    game.message("Five species at most in this mod")
    e.cancelled = true
  end
end)

# menu.loadSprites(file) → integer

since API 3

Loads your own sprites (a texture and the rectangles in it, as the game's ui/*.cfg); then they are known by name to menu.image, draw.sprite, sprite = options (the format).

ParameterType
filestringa sprite file (.cfg, the game's format) of your mod
Returns
integerhow many sprites it added

# menu.spriteSize(name) → number|nil, number|nil

since API 3

A sprite's size (nothing when there is no such sprite).

ParameterType
namestringa sprite
Returns
number|nilwidth in game units
number|nilheight

# menu.textSize(text, font?, size?) → number, number

since API 3

The size a text takes in one of the game's fonts.

ParameterType
textstring
font optionalstringdefault ofs15
size optionalnumbertext height in game units
Returns
numberwidth
numberheight