Skip to content

sf2.ui

Menus and screens built by your mod. Open a view described by a table of widgets, update it while it is open, and close it. The game can also draw two screens of its own for you, filled with your text and pictures: a boss’s pre-fight screen and a Prepare screen that pauses the fight. Views can also be buttons in the dojo. Get sf2 with local sf2 = require("sf2").

Open a menu or HUD view described by a table of widgets.

Signature: sf2.ui.open(definition)

Parameters

Parameter Type Required
definition UiDefinition Required

Fields of UiDefinition

Field Type Required Meaning
id string Optional Label used in diagnostics. Omit it to get a free one.
mount "menu"|"modal"|"hud" Required —
root UiNode Required —
placement UiPlacement Optional —
pause_fight boolean Optional Modal only. true freezes a running single-player fight until the view closes. Does nothing outside fights; an error in versus and online fights. Default false.
on_back fun(view:UiHandle) Optional —
on_change fun(view:UiHandle,widget_id:string,value:boolean|number|string) Optional —
on_click fun(view:UiHandle,widget_id:string) Optional —
on_close fun(view:UiHandle,reason:"script"|"back"|"scene"|"error"|"destroyed") Optional —

Returns: A view handle. Invalid definitions are errors.

When: While the game UI is available.

local count = 0
local view = sf2.ui.open {
mount = "menu",
root = { kind = "column", width = 320, height = 96, gap = 8, children = {
{ id = "count", kind = "text", width = 320, height = 40, text = "0" },
{ id = "add", kind = "button", width = 320, height = 48, text = "Add one",
on_click = function(current)
count = count + 1
sf2.ui.update(current, "count", { text = tostring(count) })
end },
} },
}

Scene changes close the view, so open it from the lifecycle callback of the scene where it should appear. Keep the handle and change widgets with sf2.ui.update rather than reopening. See menus and settings.

A view does not pause combat on its own. Add pause_fight = true to a modal to freeze a running fight while it is open, as the game’s pause menu does: fighters, timers, AI and fight callbacks stop, and effects and sounds hold still, while the view’s own handlers keep running. The game’s pause menu cannot open on top of it, and Back reaches the view’s on_back (or closes it). The fight resumes when the last pausing view closes, however it closes. Only single-player fights pause: outside a fight the field does nothing, and in a versus or online fight it is an error. It is also an error on a menu or hud view.

Change one widget of an open view; pass only the fields to change.

Signature: sf2.ui.update(view, widget_id, changes)

Parameters

Parameter Type Required
view UiHandle Required
widget_id string Required
changes UiWidgetChanges Required

Fields of UiWidgetChanges

Field Type Required Meaning
text string Optional New text.
sprite string|SpriteHandle Optional New artwork (image widgets).
value number Optional New value, 0..1 for progress bars and sliders.
checked boolean Optional New state of a toggle.
visible boolean Optional —
enabled boolean Optional —

Returns: Nothing.

When: After opening, including from click, change and tick callbacks.

sf2.ui.update(view, "portrait", { sprite = alternate })
sf2.ui.update(view, "meter", { value = math.min(1, charge / maximum) })
sf2.ui.update(view, "arm", { enabled = charge >= 1, text = "Charge: " .. charge })

Updates never rebuild the layout or trigger on_change. Fields that do not suit the widget type, unknown fields or IDs, and closed views are errors. To hide artwork set visible = false; nil is not a sprite. visible and enabled on a container affect everything inside it.

Read the text in a widget of an open view.

Signature: sf2.ui.text(view, widget_id)

Parameters

Parameter Type Required
view UiHandle Required
widget_id string Required

Returns: The current string, "" when empty.

When: E.g. reading a text input on submit.

local name = sf2.ui.text(view, "name")
if name == "" then sf2.log.info("Please enter a name") end

Inside on_change it already returns the new value. A text input returns its value, never the placeholder.

Check whether a view you opened is still showing.

Signature: sf2.ui.is_open(view)

Parameters

Parameter Type Required
view UiHandle Required

Returns: true while open, otherwise false.

When: Before an update; Back or a scene change may have closed the view.

if view and sf2.ui.is_open(view) then sf2.ui.update(view, "count", { text = "Ready" }) end

Close a view you opened.

Signature: sf2.ui.close(view)

Parameters

Parameter Type Required
view UiHandle Required

Returns: Nothing.

When: Any time, including inside a click handler.

sf2.ui.close(view)

Closing a closed view, or nil, does nothing. Your own variables are not reset.

Open the game’s own pre-fight screen for a boss: its stages on a paper scroll, and a card with its portrait and how often it was beaten, the consumables held, the Armory loadouts and a Fight button.

Signature: sf2.ui.challenge(definition)

Parameters

Parameter Type Required
definition ChallengeDefinition Required

Fields of ChallengeDefinition

Field Type Required Meaning
title string Required The boss’s name, already in the player’s language. Up to 128 characters.
subtitle string Optional One line under the name. Up to 512 characters.
portrait string|SpriteHandle Required Drawn in the round portrait frame.
bar ScreenBar Optional The blue shield bar, with “value/max” under it.
stages ScreenStage[] Required 1 to 6 rows on the scroll.
items ChallengeItem[] Optional Up to 4 consumable slots; those with count 0 are left out. They only show.
items_note string Optional A line under the slots.
loadouts boolean Optional The Armory loadouts the player has saved, as buttons; pressing one equips it. Default false.
note string Optional On a ribbon of ink under the heading: a rule the player should not miss.
victories integer Optional How many times the player has beaten the boss: a red hanko on the portrait with the count, an empty ring at 0. Default: no hanko.
golden boolean Optional Draws the hanko in gold. Default false.
buttons ScreenButton[] Optional Up to 4 small buttons on the card, under the note. Pressing one runs on_button.
tally TallyGroup[] Optional Up to 12 groups of small diamonds under the name (64 marks at most). Pressing the strip runs on_tally.
stakes ScreenIcon[] Optional Up to 4 pictures with short words on an ink ribbon.
choices ScreenChoice[] Optional Up to 4 tiles to pick. Pressing one runs on_choice.
pouch ScreenIcon[] Optional Up to 8 pictures with counts, under the items.
grid ScreenGrid Optional A page of pictures the scroll shows in place of the stages. Pressing a cell runs on_cell.
guide ScreenGuide Optional Walks the player through the parts of the screen once it has unrolled; its controls do nothing until the guide ends.
on_fight fun(view:UiHandle) Required The Fight button. The screen stays open until you close it or the scene changes.
on_back fun(view:UiHandle) Optional The Back button and the back key. Replaces the default close.
on_stage fun(view:UiHandle,index:integer) Optional Makes the stage rows pressable; index is 1 for the first row.
on_item fun(view:UiHandle,index:integer) Optional Makes every item slot pressable, also empty ones; index is 1 for the first slot.
on_button fun(view:UiHandle,id:string) Optional One of the card’s buttons was pressed.
on_tally fun(view:UiHandle) Optional Makes the tally strip pressable.
on_choice fun(view:UiHandle,id:string) Optional Makes the choice tiles pressable.
on_cell fun(view:UiHandle,id:string) Optional Makes the grid’s cells pressable.

Returns: A view handle for sf2.ui.is_open and sf2.ui.close. An invalid definition is an error, and so is opening it during a fight.

When: Outside fights: on the map or another menu scene, for example from a story event or a map button.

-- Loaded once, while the mod loads.
local text = {
name = sf2.text.get("arkhos.name"),
hard_ground = sf2.text.get("seal.hard_ground"),
hard_ground_hint = sf2.text.get("seal.hard_ground.hint"),
darkness = sf2.text.get("seal.darkness"),
darkness_hint = sf2.text.get("seal.darkness.hint"),
eruption = sf2.text.get("seal.eruption"),
}
local portrait = sf2.assets.sprite("ui/arkhos_portrait")
local seal = sf2.assets.sprite("ui/seal")
local elixir = sf2.items.get(sf2.mod.id .. ":items/consumable/healing_elixir")
local function open_arkhos()
return sf2.ui.challenge {
title = sf2.text.read(text.name),
portrait = portrait,
victories = sf2.profile.fight(sf2.mod.id .. ":fights/arkhos/1").wins, -- the hanko on the portrait
stages = {
{ name = sf2.text.read(text.hard_ground), text = sf2.text.read(text.hard_ground_hint),
icon = seal, state = "done" },
{ name = sf2.text.read(text.darkness), text = sf2.text.read(text.darkness_hint),
icon = seal, state = "next" },
{ name = sf2.text.read(text.eruption), icon = seal, state = "upcoming" },
},
items = { { item = elixir, count = sf2.profile.item_count(elixir) } },
loadouts = true,
on_fight = function(view)
sf2.story.start_fight("arkhos") -- entering the fight closes the screen
end,
}
end

The screen is drawn by the game in its own art, so it looks like the raid screens and the Armory. You give it the words and pictures; you do not lay it out.

  • Left: the shop’s paper scroll lists the stages, one row each: the stage’s number, its icon on a tile, the name in bold and text under it. A "next" stage lies on the light band the raid leaderboard uses for the current row, its icon breathing in a glow; an "upcoming" stage (still to come) is drawn in full, without the band; a "done" stage gets a red seal stamped on its icon; and a "locked" stage (one the player cannot reach yet) is faded. Leave out state for "locked". A stage without an icon shows the raid screen’s round mark at the end of its row instead.

  • Right: a second paper scroll, the card, in three parts:

    • Who: the portrait drawn as it is (a picture with a transparent background works best) under a soft drop shadow, the title and the subtitle. Give victories, how many times the player has beaten this boss, and a hanko sits on the portrait’s corner: an empty ink ring at 0, and from the first win a red seal with the count beside it (“x3”). sf2.profile.fight’s wins is a good source. Leave it out for no hanko.
    • The stakes: an optional blue shield bar with value/max under it and a divider at each of its marks, then the stakes ribbon (below).
    • The info line: a paper slip of a fixed height under the stakes that is always there. It names whatever the player has selected (see Selecting and spending) with a line about it, and shows note, the place for a short message such as the result of the last press. Nothing on the card moves when its words change; they fade.
    • Preparation, under a brush line: the items the player holds, as raid consumable slots with the item’s picture and count (items with a count of 0 are left out), then items_note, then the loadouts.

    The card is scaled to fit the screen’s height. On screens 16:10 and wider it is laid out wide so it reads larger: the portrait sits on the left with the title, tally, stakes and info line beside it, and everything else runs across the card under them. Narrower screens stack the parts from the portrait down.

  • Loadouts: with loadouts = true the card shows the loadouts the player has saved in the Armory, each as a button with a small three-dot marker under it; with none saved, one line saying where to save them. The one being worn is gold. Pressing a button equips it exactly as sf2.profile.equip_loadout does; pressing its dots opens a window listing that loadout’s items with their levels and enchantments (pieces the player no longer owns are faded). The window closes with its cross, Back, or a press outside it, and your handlers are not called for it.

  • Buttons: the green Fight! button runs on_fight(view), and Back runs on_back(view). The screen does not close by itself after on_fight: start the fight (the scene change closes it) or call sf2.ui.close. Without on_back, Back and the back key simply close it.

  • Your own buttons: buttons puts up to 4 of the game’s small buttons on the card, under the info line, each { id, text, enabled?, selected? }. A selected button is gold, like the loadout being worn, and a disabled one is dark. Pressing one runs on_button(view, id). Use them for a choice the player makes before the fight, such as a difficulty.

  • Pressing rows and slots: every stage row can be selected for the info line; with on_stage, pressing one also runs on_stage(view, index) (1 for the first row). With on_item, every item slot is drawn, also those with a count of 0 (pale, in its own colours, with a 0), and pressing one runs on_item(view, index) (see Selecting and spending for items that ask first). The screen does not take or give anything: do that in the handler, then show the result with sf2.ui.refresh.

  • Gold hanko: golden = true draws the hanko in gold instead of red, for a boss the player has mastered. Give hanko_info = { title, text } and the hanko can be pressed to say what it counts on the info line.

A press on this screen never spends anything by surprise. Anything with words to say can be selected, by a press or by keys and pads moving onto it, and the info line then shows its name and a line: a stage’s name and text, an item’s info (its title defaults to the item’s name), a choice’s info (title defaults to its name), and the info of a stake or pouch picture, which makes those pictures selectable. With nothing selected the info line shows info = { title, text } if you gave it, otherwise the "next" stage.

Things that spend take two presses:

  • Stage actions: a stage may have action = { icon, text?, confirm?, enabled?, reason? }, a small control at the end of its row showing its price: the icon with text (1 to 3 letters, such as "1"). With on_action, the first press arms it: it turns red and pulses, and the info line shows confirm (such as “Press again to spend an Omen and roll a new rule.”). The second press runs on_action(view, index). Pressing anything else, or moving the focus away, disarms it. With enabled = false it is dark, cannot be armed, and a press only shows reason on the info line. action_stock = { icon, count } shows what the actions spend and how many the player holds, above their column.
  • Items: an item with confirm is selected and armed by its first press (the info line shows its info and confirm) and runs on_item on the second. An item with enabled = false never runs on_item; a press shows reason. Without confirm, a press runs on_item at once, as before.

If you leave out confirm or reason, the game says “Press again to confirm.” or “Not available now.”.

The card can say most things with pictures. A picture that is not lit keeps its colours, pale over an empty ink socket, so the player can still tell which one is missing.

  • Tally: tally is a strip of small diamonds under the name, in groups: { color = "#RRGGBB", count, filled } draws count marks with filled of them lit in that colour (the others outlined in it). Use it for a collection’s progress. With on_tally(view) the strip sits on a tile with an arrow at its end and can be pressed, for example to open the collection’s page (grid, below). tally_new = true makes it pulse, for example after a fight that added to the collection.
  • Stakes: stakes puts up to 4 pictures with a few words beside them ({ icon, text, lit?, info? }, such as a coin and “+50%”) on a ribbon of ink above the info line. Write a rate as a rate (“+10% / seal”), not as if it were a total.
  • Choices: choices draws up to 4 tiles to pick from, each { id, icon, name?, chosen?, mark?, tag?, info? }: the picture in full colour on a tile with its name under it and tag (up to 16 characters, such as “+25%”) on an ink band across its corner. A chosen tile carries a small red seal with its mark (such as “II”); the others an empty ink ring that breathes, inviting a press. Pressing one runs on_choice(view, id) and shows its info. Tiles that become chosen in a refresh are stamped one after another, so taking the third of three that include the ones before it stamps I, II and III in turn.
  • Headings: choices_label and items_label put a small heading over the tiles and over the item slots, like the loadouts’ own.
  • Costs: an item may have cost, up to 6 pictures under its slot ({ icon, count?, lit? }) showing what one more costs: one picture per kind, with count on it when more than one is needed. Unlit ones are those the player lacks.
  • Pouch: pouch is a row of up to 8 pictures with how many the player holds ({ icon, count, info? }), under the items. A count of 0 draws the picture pale.
  • Stamps: a stage may have stamp, 1 to 3 letters on a small red seal after its name, such as a mark for something new. It is never faded with its row.
  • A grid page: with grid, the scroll shows a page of pictures in place of the stages: { title?, count?, caption?, text?, rows = { { { id, icon, lit?, selected?, label?, fresh? }, ... }, ... } }, up to 8 rows of 10 cells and 64 in all. Unlit cells are pale ghosts, the selected one is ringed in red, and a cell’s label sits under it; caption and text sit at the foot, so keep a cell selected. A fresh cell cracks in, one after another, once the page has unrolled. Pressing a cell runs on_cell(view, id). Show and hide the page with sf2.ui.refresh; the scroll rolls up and unrolls again as it changes. With on_close_grid(view) the page has its own close cross: close the page there, and in on_back, which the back key still runs.

A boss screen with tallies, stakes, pacts and costs is a lot to take in the first time. Give guide and the screen walks the player through its parts once it has unrolled: everything is dimmed except the part being explained, which is framed in gold, and your words sit beside it on a paper slip with the step’s number on a red seal.

sf2.ui.challenge {
-- ...the screen's content and handlers as usual...
guide = {
steps = {
{ target = "stages", title = "Seals", text = "His health is split into these seals. Each one turns on its rule." },
{ target = "stakes", title = "Momentum", text = "+10% rewards for every seal broken without opening Prepare." },
{ target = "buttons", title = "Ready?", text = "Nothing starts until you press FIGHT!" },
},
on_done = function(view, skipped)
sf2.state.set { guide_seen = true } -- a state field your mod registered
end,
},
}
  • steps (required): 1 to 16 steps, each { target?, title?, text? } with a title, a text or both (title up to 128 characters, text up to 512). Keep each to a sentence or two.
  • target: the part the step frames. "card" and "scroll" frame the whole card or scroll. The card’s parts are "portrait", "hanko", "title" (with the subtitle), "tally", "bar", "stakes", "info" (the info line), "card_buttons" (your buttons), "choices", "items" (with their costs), "pouch", "loadouts" and "buttons" (Fight! and Back). On the scroll: "stages" (all the rows), "stage-1" to "stage-6" (one row), "actions" (the stage actions’ column) and "grid" (the grid page). Leave target out to show the words in the middle of the dimmed screen, for a welcome or a closing word. A step whose part is not on the screen (no pouch, say, or the grid page showing in place of the stages) is passed over.
  • on_done(view, skipped) (optional): runs as the guide ends; skipped is true when the player skipped it.

A click, tap, Enter or pad A goes on to the next step, and the arrow keys or stick step forwards and back. Back, Escape, pad B or the slip’s Skip button ends it at once. While the guide runs the screen’s own controls only show: no press reaches them, none of your handlers run, and nothing is spent, taken or started. When it ends the screen is exactly as it was, ready to use.

The screen does not remember that a guide was shown, so save that yourself (in on_done, or as you open the screen) and give guide only while it is still due. sf2.ui.refresh content may carry a guide too, which starts it over the refreshed screen at once; refreshes without one leave a running guide as it is, so give guide only in the content that should start it.

As it opens, the map behind it is dimmed and the map’s own battle panel (with its Fight button) is hidden until the screen closes. Both scrolls unroll from the middle, showing what is printed on them as the rollers pass, and a red seal is stamped on each "done" stage. On the card the portrait pops in before a slowly turning halo of light, its hanko is stamped if the boss has been beaten, the title drops in a letter at a time, each landing with a thud and a puff of dust, over a gold brush line, the slots pop in, and the bar fills from empty while its numbers count up, finishing in a spray of sparks. While it is open, embers drift up behind the scrolls, the portrait floats, the slots bob, the "next" stage’s band breathes while its icon rocks in a glow, a gleam runs along the bar now and then and a glow breathes behind Fight!, which throws sparks when pressed. A refresh shows what changed: a stage whose name changed washes out in ink and the new words ink in, chosen tiles are stamped, and when an item’s count goes up while pouch counts go down, the pouch pictures fly to its slot and its count ticks up. Any press, key or pad move settles whatever is still moving at once and still does what it was pressed for. With the player’s reduced-motion setting on, it opens settled and stays still.

Text is shown as you give it, so pass strings already in the player’s language. Pictures must be sprites; a missing one is an error when the screen opens. Keys and pads move between the buttons, Enter or pad A presses the one that flashes, and Escape or pad B is Back. On phones the screen is drawn larger to suit fingers.

It is a modal view: it sits over the scene, takes the input, and closes on a scene change. sf2.ui.is_open and sf2.ui.close work on its handle; sf2.ui.update and sf2.ui.text do not, since it has no widgets of yours. To show new values while it is open, give it new content with sf2.ui.refresh.

Limits: 1 to 16 guide steps; 1 to 6 stages, up to 4 items and up to 4 buttons (each id 1 to 64 letters, digits, _ or -, unique); counts and victories from 0 to 9999; a bar’s max above 0 and at most 100000, value from 0 to max, and up to 16 marks between them; title and stage names up to 128 characters, other text up to 512. See menus and settings for a whole boss menu.

Pause a single-player fight under the game’s own Prepare screen, where the player uses consumables and switches to an Armory loadout before going on.

Signature: sf2.ui.prepare(definition)

Parameters

Parameter Type Required
definition PrepareDefinition Required

Fields of PrepareDefinition

Field Type Required Meaning
title string Required The card’s heading, already in the player’s language. Up to 128 characters.
subtitle string Optional One line under the heading.
items PrepareItem[] Optional Up to 4 rows on the scroll.
loadouts boolean Optional The Armory’s three loadouts as buttons; pressing one equips it. Default false.
note string Optional A line above Continue.
on_use fun(view:UiHandle,id:string):integer|nil,boolean|nil Optional A row was pressed. Return the new count and whether it stays enabled; nil keeps either. Without on_use the rows only show.
on_continue fun(view:UiHandle) Optional Continue and the back key. The screen then closes and the fight resumes.

Returns: A view handle for sf2.ui.is_open and sf2.ui.close. An invalid definition is an error, and so is opening it anywhere but a single-player fight that is still being played.

When: During a fight: from a fight HUD button’s handler, or from a combat callback such as on_tick.

-- Loaded once, while the mod loads.
local elixir = sf2.items.get(sf2.mod.id .. ":items/consumable/healing_elixir")
local text = {
title = sf2.text.get("prepare.title"),
healing = sf2.text.get("elixir.healing.short"),
}
local heal_next_tick = false -- the round controller heals when the fight resumes
local function open_prepare()
return sf2.ui.prepare {
title = sf2.text.read(text.title),
items = {
{ id = "healing", item = elixir, count = sf2.profile.item_count(elixir),
text = sf2.text.read(text.healing), enabled = not heal_next_tick },
},
loadouts = true,
on_use = function(view, id)
if id == "healing" and sf2.profile.take_item(elixir, 1) then
heal_next_tick = true
return sf2.profile.item_count(elixir), false -- one elixir per Prepare
end
end,
}
end

The fight stands still while the screen is open, exactly as under a modal opened with pause_fight = true: fighters, the round timer, the AI and fight callbacks stop, and effects and sounds hold. It resumes as soon as the screen closes, however it closes.

The screen is drawn by the game in the same art as sf2.ui.challenge:

  • Left: a paper scroll with a row for each of the items: the item’s picture in a raid consumable slot with how many the player holds, its name in bold and your text under it. A row can be pressed while it is enabled (the default) and its count is above 0; other rows are faded. Leave out items and the scroll is not drawn.
  • Right: a second paper scroll, the card, with the title, the subtitle, note on a ribbon of ink, the loadouts the player has saved in the Armory when loadouts = true (or one line saying where to save them), and the green Continue button.

It opens the way sf2.ui.challenge does: both scrolls unroll, the title drops in a letter at a time and embers drift behind the scrolls. Using an item makes its picture pop and throw sparks, and a glow breathes behind Continue. Under reduced motion it is all still.

Pressing a row calls on_use(view, id) with the row’s id. Return the row’s new count and whether it stays enabled: return 1, false. Either may be nil to keep it as it is, and returning nothing changes nothing. Without on_use the rows only show what the player holds. The handler runs while the fight is paused, so it cannot reach the fighters: take the item with sf2.profile.take_item, remember the effect in a Lua variable, and apply it from your round controller’s next on_tick.

Continue, Escape and pad B run on_continue(view) if you gave one, then close the screen, and the fight goes on.

The dots under a loadout button open the same item list as on sf2.ui.challenge. A loadout button equips that loadout exactly as sf2.profile.equip_loadout does in a paused fight: the player’s fighter is rebuilt in the new gear as the fight resumes, keeping its share of health. The worn loadout’s button turns gold at once. If the gear cannot change at that moment (between rounds, or when the player fights as another character), nothing changes and the mod’s log says why.

Only single-player fights that are still being played can show it: on the map, in the dojo, after the fight’s result is in, and in versus or online fights it is an error. Text is shown as you give it, so pass strings already in the player’s language. Keys and pads move between the rows and buttons. sf2.ui.update and sf2.ui.text do not work on its handle.

Limits: up to 4 items, each id 1 to 64 letters, digits, _ or - and unique; counts from 0 to 9999; title up to 128 characters, other text up to 512. See menus and settings.

Create a button in the dojo menu that your mod can open a screen from.

Signature: sf2.ui.dojo_button { id = "...", image = sprite, pressed_image = sprite }

Parameters

Parameter Type Required
definition DojoButtonDefinition Required

Fields of DojoButtonDefinition

Field Type Required Meaning
id string Required 1-64 lowercase letters, digits, _ or -; qualified as modid.id in click events.
image string|SpriteHandle Required —
pressed_image string|SpriteHandle Optional Shown while the button is held; default: image.

Returns: The qualified name, <mod-id>.<id>.

When: During loading.

local name = sf2.ui.dojo_button { id = "wardrobe",
image = sf2.assets.sprite("sprites/wardrobe_button"),
pressed_image = sf2.assets.sprite("sprites/wardrobe_button_pressed") }
sf2.story.on("dojo_button", function(event)
if event.button == name then
-- open an owned UI view here
end
end)

Buttons line up beside the disciple button in load order, once the story tutorial’s first boss (Shin) is beaten: in a row to its left, or in a column below it on screens 21:9 and wider. While the disciple is still locked, the first button takes its place. For a dojo chooser, sf2.world.dojo_picker does both steps.

Show new content on an open challenge screen at once, without opening it again.

Signature: sf2.ui.refresh(view, definition)

Parameters

Parameter Type Required
view UiHandle Required
definition ChallengeContent,The whole new content, as for sf2.ui.challenge without handlers. Required

Fields of ChallengeContent

Field Type Required Meaning
title string Required —
subtitle string Optional —
portrait string|SpriteHandle Required —
bar ScreenBar Optional —
stages ScreenStage[] Required —
items ChallengeItem[] Optional —
items_note string Optional —
loadouts boolean Optional —
note string Optional —
victories integer Optional —
golden boolean Optional —
buttons ScreenButton[] Optional —
tally TallyGroup[] Optional —
stakes ScreenIcon[] Optional —
choices ScreenChoice[] Optional —
pouch ScreenIcon[] Optional —
grid ScreenGrid Optional —
guide ScreenGuide Optional Starts this guide over the refreshed screen; left out, a running guide goes on.

Returns: Nothing. A view that is not an open challenge screen, or an invalid definition, is an error.

When: While a challenge screen is open, usually from one of its handlers (on_button, on_stage, on_item).

local level = 0
local function definition()
return {
title = "The Warden",
portrait = portrait,
stages = stages_for(level),
note = "Rewards +" .. (25 * level) .. "%",
buttons = {
{ id = "easier", text = "Easier", enabled = level > 0 },
{ id = "harder", text = "Harder", enabled = level < 3 },
},
}
end
local function open_menu()
local menu = definition()
menu.on_fight = function(view) sf2.story.start_fight("warden") end
menu.on_button = function(view, id)
level = level + (id == "harder" and 1 or -1)
sf2.ui.refresh(view, definition())
end
return sf2.ui.challenge(menu)
end

definition takes the same content fields as sf2.ui.challenge: title, subtitle, portrait, bar, stages, items, items_note, loadouts, note, victories, buttons, golden, tally, stakes, choices, pouch, grid, info, hanko_info, tally_new, action_stock, choices_label, items_label and guide. Give the whole content again, not only what changed: a field left out is shown as left out. The exception is guide: one given here starts that guide over the refreshed screen at once (with its own on_done), and leaving it out keeps a running guide going, so refreshes that answer presses never restart it.

The handlers stay as the screen was opened with, so leave on_fight, on_back, on_stage, on_item, on_button, on_tally, on_choice, on_cell, on_action and on_close_grid out; giving one is an error. Whether rows and slots can be pressed also stays as it was opened.

The screen is drawn again at once and settled: the scrolls do not unroll again, nothing drops in and no seal is stamped a second time. Only what changed moves: a stage renamed in place washes out and inks in again, newly chosen tiles are stamped in turn, pictures fly from the pouch to an item whose count went up, and the scroll rolls the grid page in or out. The control keys or a pad were on keeps its place when it still exists, and so does what the player had selected for the info line. note shows on the info line until the player selects something else or the next refresh, so give it only in the refresh that answers a press.

Show the game’s results screen in place of the result tally when a single-player fight ends: your stages and words, with the rewards the fight paid counted up by the game.

Signature: sf2.ui.results(definition)

Parameters

Parameter Type Required
definition ResultsDefinition Required

Fields of ResultsDefinition

Field Type Required Meaning
title string Required The heading, such as “Victory”, already in the player’s language. Up to 128 characters.
subtitle string Optional One line under the heading. Up to 512 characters.
portrait string|SpriteHandle Optional The boss’s picture. On a win it darkens and a red seal is stamped across it.
stages ScreenStage[] Optional Up to 6 rows on the scroll, as the fight left them.
bonus string Optional What your reward bonus is called, such as “Momentum”, shown with the share fighter:set_reward_bonus added. Up to 128 characters. Default “Bonus”.
note string Optional On a ribbon of ink, above Continue.
victories integer Optional How many times the boss has now been beaten, this fight included: the hanko on the portrait, stamped on a win.
items ChallengeItem[] Optional Up to 8 items your mod gave itself, shown after what the fight paid. Counts 1-9999.
golden boolean Optional Draws the hanko in gold. Default false.
on_continue fun(view:UiHandle) Optional Continue and the back key, before the game leaves the fight for the map.

Returns: Nothing. An invalid definition is an error, and so is asking outside a single-player fight that is being played or has just ended.

When: During a fight or as it ends, normally from the round controller’s on_fight_end.

-- Loaded once, while the mod loads.
local portrait = sf2.assets.sprite("ui/warden")
local seal = { intact = sf2.assets.sprite("ui/seal"), broken = sf2.assets.sprite("ui/seal_broken") }
local text = {
won = sf2.text.get("warden.won"), lost = sf2.text.get("warden.lost"),
momentum = sf2.text.get("warden.momentum"),
stages = { sf2.text.get("warden.first"), sf2.text.get("warden.second"), sf2.text.get("warden.last") },
}
local reached = 1 -- the seal being fought, kept up to date by on_tick
local began = 1 -- the seal the fight started at
local controller = {
on_fight_end = function(self, fighter, event)
local won = event.player_result == "win"
local stages = {}
for index, name in ipairs(text.stages) do
local broken = won or index < reached
stages[index] = { name = sf2.text.read(name), icon = broken and seal.broken or seal.intact,
state = broken and "done" or (index == reached and "next" or "upcoming") }
-- Broken in this fight, or before it (a fight that began at a later seal)?
if broken then stages[index].fresh = index >= began end
end
sf2.ui.results {
title = sf2.text.read(won and text.won or text.lost),
portrait = portrait,
stages = stages,
bonus = sf2.text.read(text.momentum),
-- The profile counts this fight after on_fight_end, so add the win being shown.
victories = sf2.profile.fight(sf2.mod.id .. ":fights/warden/1").wins + (won and 1 or 0),
}
end,
}

Asking for the screen does not open it straight away. The fight finishes as usual: its rewards are counted, paid and saved. Then, where the game would show its result tally, it shows this screen instead, in the same art as sf2.ui.challenge:

  • Left: a paper scroll with your stages as the fight left them, drawn as on the challenge screen: a "done" stage gets a red seal stamped on it, a "next" stage lies on the light band, an "upcoming" stage is drawn in full and a "locked" stage is faded. Give a "done" stage fresh = true when it was done in this fight: those are stamped one after another, each with a crack of sparks. fresh = false marks one done before this fight (such as in an earlier, lost attempt): it shows settled, under an ink seal instead of a red one. Leave fresh out and every "done" stage is stamped as the scroll unrolls. Leave out stages and the scroll is not drawn.
  • Right: a second paper scroll, the card, with the portrait, the title and subtitle, and then the rewards the fight paid, filled in by the game:
    • The coins, gems and experience count up from nothing, the experience star with a small caption. Kinds the fight did not pay are left out.
    • The forge materials the fight paid (the enchant orbs) count up on a row of their own beneath them, each with its orb. They show only once the player has the forge, since the game pays them only then.
    • If the fight was won with a reward bonus from fighter:set_reward_bonus, the counters (forge materials included) first stop at the amounts before it. Then a line with your bonus name and its share (“Momentum +30%”) is stamped in, and the counters climb to what was paid.
    • Each item the fight paid drops in on a tile, with its count on a round plate at the corner. Items your mod gave itself, such as with sf2.profile.give_item, can join them: list them in items as { item, count } (up to 8, counts 1 to 9999). They only show; the screen gives nothing.
    • With victories (how many times the boss has now been beaten), the portrait carries the hanko as on sf2.ui.challenge, gold with golden = true, and hanko_info = { title } puts a small caption under it (such as “Wins”): on a win the portrait darkens and the red seal is stamped on its corner once everything is counted, the count popping in beside it; on a loss it shows as it was before the fight.
    • note on a ribbon of ink, and the green Continue button, close the card.

Continue and the back key run on_continue(view) if you gave one, then the game leaves the fight for the map, as the tally’s OK does. The screen has no Retry. It only shows what was paid; it never pays anything itself.

The screen replaces the tally only for the fight you asked during. A later call in the same fight replaces the earlier one. A surrender still goes straight to the map, and raids keep their own result. If the screen cannot open, the game’s own tally shows instead, so the player is never left without a way out. Text is shown as you give it, so pass strings already in the player’s language.

As it opens, both scrolls unroll, the title drops in a letter at a time and the rewards count up with ticking and sparks. With the player’s reduced-motion setting on, it opens with everything counted and stays still.