phigros.tools

Screens

Pages over the song list are made of copies of its own parts, so they look and move like the game. local ui = phigrospp.ui first.

ConfirmTile

FieldType
icon?Unitya Sprite
labelstring
colour?Colour
tap?fun()
on?fun(): booleanlit while it returns true
note?fun(): string

ConfirmOptions

FieldType
titlestring
message?string
yes?string|falsefalse leaves only no
no?string|falsefalse leaves only yes
danger?booleanmakes yes red
grid?{ cells: (string|ConfirmTile)[], columns: integer, height: number }aligned columns, one is centered
input?stringa text box's placeholder: its text is returned second
progress?fun(): number, stringa bar from 0 to 1 and its message, redrawn

ChooseTile

FieldType
iconIcon
labelstring
colour?Colour
valueany

PageList

FieldType
countinteger
rowfun(row: Unity, i: integer)sets a SongListItem
selected?fun(row: Unity, i: integer)sets the middle one's songName, artist, level and levelText
select?fun(i: integer)runs when it changes

Page

A page sliding over the song list.

Page:part(name)

A copy of a song list part where it is: topbar, shadows, background (the list's dimming), info (record panel), cover, selected, up, down, back, play.

local page = phigrospp.ui.page()
page:part("topbar")
local cover = page:part("cover").transform
ParameterType
name"topbar"|"shadows"|"background"|"info"|"cover"|"selected"|"up"|"down"|"back"|"play"

Returns GameObject

Page:back()

The back button closes the page.

local page = phigrospp.ui.page()
page:back() -- the back arrow slides it out

Page:play(fn)

The play button runs fn.

local play = page:play(function() toast("Play!") end) -- the copy of the play button
play:SetActive(false)
ParameterType
fnfun()

Returns GameObject

Page:list(options)

The song list's list.

page:list({
  count = #replays,
  row = function(row, i) row.songName.text, row.difficulty.text = replays[i].date, "" end,
  selected = function(row, i) row.songName.text = replays[i].date end,
  select = function(i) shown = replays[i] end,
})
ParameterType
optionsPageList

Page:close()

Slides back.

page:play(function()
  page:close()
  phigrospp.play(id, "IN")
end)

View

A screen of its own over the menus, like the rooms. The song list under it takes no touch meanwhile. Its pieces are placed in units from its bottom left.

FieldType
heightnumber1080
widthnumber
leftnumberwhere the columns start
topnumberthe middle of the top bar

View.show(screen)

Slides a panel in, another one's out.

local view = phigrospp.ui.view("my-mod")
view.show("list")
ParameterType
screenstring

View.hide()

Slides it out.

view.part("all", "", function(root) view.back(root, view.hide) end)

View.shown()

The panel showing.

print(view.shown()) --> list

Returns string?

View.part(name, key, draw)

Draws a part again only when its key changed.

view.show("scores")
view.part("all", #scores, function(root) -- drawn again only when #scores changes
  view.text(root, { view.left, view.top }, 44, ("%d scores"):format(#scores))
end)
ParameterType
namestring
keyany
drawfun(root: Unity)

View.text(parent, pos, size, text, colour?, alignment?, pivot?, box?)

A text from the middle of its left side.

local title = view.text(root, { view.left, view.top }, 44, "Scores")
view.text(root, { view.width - view.left, view.top }, 30, "11.3288", ui.colours.dim, 5, { 1, 0.5 }) -- MiddleRight
view.text(row, { 300, 66 }, 34, "A very long song name", ui.colours.white, 3, nil, 400) -- cut at 400 with ...
local after = title.preferredWidth + 20 -- a UnityEngine.UI.Text
ParameterType
parentUnity
posVector
sizenumber
textstring
colour?Colour
alignment?integera TextAnchor, MiddleLeft when left out
pivot?Vector
box?numbera width: what goes past it is cut and ends with "..."

Returns Text

View.icon(parent, pos, size, icon, colour?)

One of ui.icon's icons.

view.icon(root, { 60, 60 }, 48, "trophy", ui.colours.gold)
ParameterType
parentUnity
posVector
sizenumber
iconIcon
colour?Colour

Returns Image

View.plate(parent, pos, size, colour, fontSize, label, ink?)

A slanted bar with a centred text.

view.plate(row, { 300, 44 }, { 116, 34 }, ui.colours.IN, 22, "IN 15.8")
ParameterType
parentUnity
posVector
sizeVector
colourColour
fontSizenumber
labelstring
ink?Colour

Returns LeanPolygon

View.action(parent, pos, width, label, fn?, lit?)

A button, lit in a colour when given one. Without fn it's only a label.

view.action(root, { 1500, 120 }, 300, "Start", function() toast("Go") end, ui.colours.green)
view.action(root, { 1500, 30 }, 300, "Waiting") -- only a label
ParameterType
parentUnity
posVector
widthnumber
labelstring
fn?fun()|false
lit?Colour|false

Returns LeanPolygon

View.back(root, fn)

The back arrow.

view.part("all", "", function(root) view.back(root, view.hide) end)
ParameterType
rootUnity
fnfun()

View.tappable(shape, fn)

Makes anything a button.

local box = ui.rect(parent, "my-tap", { 0, 0 }, { 200, 80 }, { 0, 0, 0, 0 })
view.tappable(box, function() toast("Tapped") end)
ParameterType
shapeUnity
fnfun()

View.checkbox(parent, pos, label, checked, fn)

A checkbox ending at pos.

view.checkbox(root, { 1800, 120 }, "Spectators", allowed, function() allowed = not allowed end)
ParameterType
parentUnity
posVector
labelstring
checkedboolean
fnfun()

View.titles(root, titles, own, pick)

The top bar's titles for screens that go together: pick(title) runs when another one's is tapped.

local shown = "Rooms"
view.titles(root, { "Rooms", "Friends" }, shown, function(title)
  shown = title
  draw()
end)
ParameterType
rootUnity
titlesstring[]
ownstring
pickfun(title: string)

Panel

A screen sliding in over a canvas and its shade.

FieldType
transformUnityto fill
closefun()slides it out, then closed() runs

ui.colours

{ white: Colour, dim: Colour, faint: Colour, dark: Colour, gold: Colour, green: Colour, red: Colour, EZ: Colour, HD: Colour, IN: Colour, AT: Colour }

What they're drawn in, and a level's plate.

ui.icon(name)

A Lucide icon (lucide.dev) as a white Sprite tinted by its Image: one of the names listed, or another icon's svg.

local star = ui.icon("star")
image.sprite, image.color = star, ui.colours.gold
ParameterType
nameIcon

Returns Sprite

ui.clone(button, offset, fn)

A copy of a game button moved by an offset, running fn instead.

local copy = ui.clone(original, { -150, 0 }, function() toast("Mine") end)
ParameterType
buttonUnity
offsetVector
fnfun()

Returns GameObject

ui.sideButton(play, slot, sprite, fn)

A copy of a play button slot slots left of it, showing a sprite.

local selector = CS.UnityEngine.Object.FindObjectOfType(CS.SongSelectorControl)
local bot = ui.sideButton(selector.startButton, 2, ui.icon("eye"), function() toast("Autoplay") end)
bot:SetActive(false) -- a GameObject
ParameterType
playUnity
slotinteger
spriteUnity
fnfun()

Returns GameObject

ui.switch(label, lit, fn)

A switch like the song list's Mirror one, after it and those already there: lit while lit says so, fn runs on a tap.

local practice = setting("Practice", false)
on("scene", function(name)
  if name == "SongSelector" then ui.switch("Practice", practice, function() practice(not practice()) end) end
end)
ParameterType
labelstring
litfun(): boolean
fnfun()

ui.shortcut(icon, fn)

A tab left of the chapter screen's settings and of those already there, showing an icon: asked for at each "ChapterSelector" scene.

on("scene", function(name)
  if name == "ChapterSelector" then ui.shortcut("users", open) end
end)
ParameterType
iconIcon
fnfun()

ui.page()

Slides the song list out to the left and an empty page in.

local page = ui.page()
page:part("topbar")
page:part("background")
page:back()

Returns Page

ui.confirm(options)

The game's popup, from a button's function or a coroutine: waits for the choice and returns true for yes.

if ui.confirm({ title = "Delete replay", message = "...", yes = "Delete", danger = true }) then end
ParameterType
optionsConfirmOptions

Returns boolean (yes)

Returns string? (text)

ui.close(...)

Closes the open popup, its confirm returning what's given.

button("Ask", function()
  after(5, function() ui.close(false) end) -- no answer in 5 seconds is a no
  if ui.confirm({ title = "Still there?" }) then toast("Yes") end
end)
ParameterType
...any

ui.choose(title, choices)

A popup of tiles to pick one of, called like confirm: returns the value of the one tapped, nothing when the player backs out.

local value = ui.choose("ggmolly#0042", { { icon = "eye", label = "Watch", colour = ui.colours.green, value = "watch" } })
ParameterType
titlestring
choicesChooseTile[]

Returns any

ui.bar(parent, name, pos, size, colour)

A bar slanted like the game's, from its top left corner.

local bar = ui.bar(parent, "my-bar", { 0, 96 }, { 600, 96 }, ui.colours.faint)
view.text(bar.transform, { 40, 48 }, 34, "In the bar")
ParameterType
parentUnity
namestring
posVector
sizeVector
colourColour

Returns LeanPolygon

ui.cover(parent, name, pos, size, id, level?)

A song's illustration cut to fill such a bar, what's put in it is cut to its shape too. It's the level's own when the level has one. A few songs have one per level: given a level, it's that level's.

ui.cover(row, "my-cover", { 0, 96 }, { 170, 96 }, "Glaciaxion.SunsetRay.0", "IN")
ParameterType
parentUnity
namestring
posVector
sizeVector
idstringthe song's id
level?Difficulty

Returns LeanPolygon

ui.panel(canvas, name, closed?, shade?)

A screen sliding in over a canvas and its shade.

local canvas = ui.screen("my-mod", 50)
local panel = ui.panel(canvas, "my-panel", function() print("gone") end)
ui.rect(panel.transform, "my-box", { 100, 100 }, { 400, 300 }, ui.colours.dark)
after(3, panel.close)
ParameterType
canvasUnity
namestring
closed?function
shade?numberhow dark it is (0.85), for a screen whose texts go over what's under

Returns Panel

ui.place(parent, name, kind, pos, size, pivot?)

A component on a new object under parent, placed from its bottom left corner: what ui.rect and ui.text make theirs with.

local raw = ui.place(parent, "my-picture", CS.UnityEngine.UI.RawImage, { 0, 0 }, { 400, 400 })
ParameterType
parentUnity
namestring
kindUnitya component's class
posVector
sizeVector
pivot?Vector{ 0, 0.5 } when left out

Returns Unity (component)

ui.rect(parent, name, pos, size, colour, pivot?)

A plain Image in a colour, placed like ui.place.

local box = ui.rect(parent, "my-box", { 100, 100 }, { 400, 300 }, ui.colours.dark)
box.sprite = image("logo.png")
ParameterType
parentUnity
namestring
posVector
sizeVector
colourColour
pivot?Vector

Returns Image (image)

ui.text(parent, name, font, pos, size, fontSize, alignment, pivot?)

A Text in white, placed like ui.place, its text overflowing its box. alignment is a TextAnchor.

local label = ui.text(parent, "my-label", font, { 40, 40 }, { 0, 0 }, 32, 3) -- MiddleLeft
label.text = "Hello"
ParameterType
parentUnity
namestring
fontUnity
posVector
sizeVector
fontSizenumber
alignmentinteger
pivot?Vector

Returns Text (text)

ui.screen(name, order)

A canvas over everything in any scene, 1080 units high like the game's menus and width wide, whose buttons take taps.

local canvas, width = ui.screen("my-mod", 50)
print(width) --> 1617.98 on a 3200x2136 screen
ui.rect(canvas, "my-corner", { width - 120, 1080 - 120 }, { 100, 100 }, ui.colours.red)
ParameterType
namestring
orderinteger

Returns RectTransform (canvas)

Returns number (width)

ui.view(name)

A screen of its own over the menus.

local view = ui.view("my-mod")
button("Open", function()
  view.show("main")
  view.part("all", "", function(root)
    view.back(root, view.hide)
    view.text(root, { view.left, view.top }, 44, "My mod")
  end)
end)
ParameterType
namestring

Returns View

ui.toasted(x, y)

Whether a point of the screen (pixels) is on a toast, for what reads the touches itself.

for _, touch in ipairs(touches()) do
  if not ui.toasted(touch.x, touch.y) then press(touch) end
end
ParameterType
xnumber
ynumber

Returns boolean

ui.avatar(parent, name, pos, size, key)

A player's avatar in a square, from the game's key of it.

ui.avatar(row, "my-avatar", { 40, 48 }, 64, appearance().avatar)
ParameterType
parentUnity
namestring
posVector
sizenumber
keystring

Returns Image

ui.list(parent, name, pos, size, width?)

A list scrolling like the game's: bars width wide go in list.rows at { -y * slope, -y }, list.content.sizeDelta's y is their height. Without a width it's upright: what's put in rows scrolls straight up and down, with a thin bar on its right.

local list = ui.list(root, "my-list", { 200, 30 }, { 1200, 900 }, 1000)
local slope = CS.SettingItemsManager.InverseSlope
for i, name in ipairs(names) do
  local y = (i - 1) * 108
  view.plate(list.rows, { -y * slope, -y }, { list.width, 96 }, ui.colours.faint, 34, name)
end
list.content.sizeDelta = { 0, #names * 108 }
ParameterType
parentUnity
namestring
posVector
sizeVector
width?number

Returns { transform: Unity, content: Unity, rows: Unity, width: number? }

ui.video(parent, name, pos, size, url, poster?, pivot?)

A RawImage looping a video of a url or a file without sound, showing poster (a Texture) until it plays.

ui.video(parent, "my-clip", { 0, 0 }, { 640, 360 }, "https://phigros.tools/catalog/clip.mp4")
ParameterType
parentUnity
namestring
posVector
sizeVector
urlstring
poster?Unity
pivot?Vector

Returns RawImage

ui.fit(rawImage, texture)

Shows a texture, the image shrinking to its shape.

local shown = ui.place(parent, "my-picture", CS.UnityEngine.UI.RawImage, { 0, 0 }, { 400, 400 })
ui.fit(shown, phigrospp.texture(phigrospp.read(phigrospp.dir() .. "art.png")))
ParameterType
rawImageUnity
textureUnity

ui.checkbox(parent, name, font, pos, size, label, checked, fn)

A checkbox.

ui.checkbox(parent, "my-check", font, { 600, 40 }, 32, "Mirror", mirrored, function() mirrored = not mirrored end)
ParameterType
parentUnity
namestring
fontUnity
posVector
sizenumber
labelstring
checkedboolean
fnfun()