info = { type = "image", title = "Play Go", category = "other", author = "BRRRO", version = "1.0", license = "MIT", desc = "A retro dialog: click GO, load, close, repeat", api = 33, } local tr = ({ sk = { ["Title bar colour"] = "Farba záhlavia", ["Window title"] = "Názov okna" }, cs = { ["Title bar colour"] = "Barva záhlaví", ["Window title"] = "Název okna" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "bar", label = T("Title bar colour"), type = "color", default = "#28B0B0" }, { key = "title", label = T("Window title"), type = "text", default = "NEW GAME" }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin = math.floor, math.sin local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local WX, WY, WW, WH = 6, 13, 52, 38 local TITLE_OPTS = { font = "4x6", w = 34, fit = "3x5" } local CELL = { font = "4x6", cell = true } local GO_OPTS = { font = "4x6", w = 22 } local GO_T, GO_B = gfx.text_ink("GO", GO_OPTS) local GO_DY = (11 - (GO_B - GO_T + 1)) // 2 - GO_T local BAR, BAR_L = { 40, 176, 176 }, { 120, 224, 220 } local BODY, INK = { 224, 216, 248 }, { 52, 38, 104 } local EDGE = { 36, 26, 80 } local BTN, BTN_L, BTN_D = { 255, 202, 72 }, { 255, 238, 160 }, { 176, 112, 24 } local BTN_P = { 232, 168, 40 } local TRACK, SEG, SEG_H = { 84, 68, 140 }, { 255, 110, 172 }, { 255, 176, 212 } local TITLE = "NEW GAME" function on_settings() local c = cfg.bar or { r = 40, g = 176, b = 176 } BAR = { c.r, c.g, c.b } BAR_L = { c.r + (255 - c.r) * 6 // 10, c.g + (255 - c.g) * 6 // 10, c.b + (255 - c.b) * 6 // 10 } TITLE = (cfg.title and cfg.title ~= "") and cfg.title or "NEW GAME" end local CUR_ROWS = { "1.......", "11......", "121.....", "1221....", "12221...", "122221..", "1222221.", "12222111", "121221..", "11.1221.", "1..1221.", "....11..", } local CUR = {} for i = 1, #CUR_ROWS do CUR[i] = CUR_ROWS[i]:gsub(".", { ["."] = "\0", ["1"] = "\1", ["2"] = "\2" }) end CUR = table.concat(CUR) local CUR_PAL = { 0, 0, 0, 30, 20, 50, 255, 255, 255 } local BG = nil local function build_bg() rect(0, 0, W, 16, 64, 46, 128); rect(0, 16, W, 16, 88, 62, 160) rect(0, 32, W, 16, 114, 82, 184); rect(0, 48, W, 16, 142, 106, 206) for x = 0, W - 1, 2 do px(x, 15, 88, 62, 160); px(x + 1, 31, 114, 82, 184); px(x, 47, 142, 106, 206) end BG = gfx.snapshot(0, 0, W, H) end local SPK = {} for i = 1, 7 do local h = hash32(i * 0x9E3779B1) SPK[i] = { 2 + umod(h, 60), (i % 2 == 0) and 2 + umod(h >> 8, 9) or 53 + umod(h >> 8, 9), umod(h >> 16, 90) } end local function bevel(x, y, w, h, face, lt, dk, pressed) rect(x, y, w, h, face[1], face[2], face[3]) local a, b = lt, dk if pressed then a, b = dk, lt end rect(x, y, w, 1, a[1], a[2], a[3]); rect(x, y, 1, h, a[1], a[2], a[3]) rect(x, y + h - 1, w, 1, b[1], b[2], b[3]); rect(x + w - 1, y, 1, h, b[1], b[2], b[3]) end local function window(title, pressed, mode, fill, pct) rect(WX + 2, WY + 2, WW, WH, 44, 30, 96) rect(WX - 1, WY - 1, WW + 2, WH + 2, EDGE[1], EDGE[2], EDGE[3]) rect(WX, WY, WW, WH, BODY[1], BODY[2], BODY[3]) rect(WX, WY, WW, 9, BAR[1], BAR[2], BAR[3]) rect(WX, WY + 8, WW, 1, BAR_L[1], BAR_L[2], BAR_L[3]) gfx.text(WX + 3, WY + 2, title, 255, 255, 255, TITLE_OPTS) rect(WX + WW - 9, WY + 2, 6, 5, BODY[1], BODY[2], BODY[3]) px(WX + WW - 8, WY + 3, EDGE[1], EDGE[2], EDGE[3]); px(WX + WW - 4, WY + 3, EDGE[1], EDGE[2], EDGE[3]) px(WX + WW - 6, WY + 4, EDGE[1], EDGE[2], EDGE[3]) px(WX + WW - 8, WY + 5, EDGE[1], EDGE[2], EDGE[3]); px(WX + WW - 4, WY + 5, EDGE[1], EDGE[2], EDGE[3]) if mode == 0 then gfx.text(WX + (WW - gfx.text_width("READY", CELL)) // 2, WY + 12, "READY", INK[1], INK[2], INK[3], CELL) gfx.text(WX + (WW - gfx.text_width("PLAYER?", CELL)) // 2, WY + 19, "PLAYER?", INK[1], INK[2], INK[3], CELL) if pressed then bevel(WX + 15, WY + 26, 22, 10, BTN_P, BTN_L, BTN_D, true) else bevel(WX + 15, WY + 25, 22, 11, BTN, BTN_L, BTN_D, false) end gfx.text(WX + 15, WY + 25 + GO_DY + (pressed and 1 or 0), "GO", INK[1], INK[2], INK[3], GO_OPTS) else local msg = mode == 1 and "LOADING" or "ALL SET!" gfx.text(WX + (WW - gfx.text_width(msg, CELL)) // 2, WY + 13, msg, INK[1], INK[2], INK[3], CELL) rect(WX + 5, WY + 21, 42, 9, TRACK[1], TRACK[2], TRACK[3]) for i = 0, 7 do local x = WX + 7 + i * 5 if i < fill then rect(x, WY + 23, 4, 5, SEG[1], SEG[2], SEG[3]); rect(x, WY + 23, 4, 1, SEG_H[1], SEG_H[2], SEG_H[3]) elseif i == fill and mode == 1 then rect(x, WY + 24, 4, 3, SEG[1], SEG[2], SEG[3]) end end local s = pct .. "%" gfx.text(WX + (WW - gfx.text_width(s, CELL)) // 2, WY + 32, s, INK[1], INK[2], INK[3], CELL) end end local OPEN, CUR0, CUR1, PRESS, LOAD, SEGF, DONE, SHUT, GAP = 12, 36, 96, 8, 114, 12, 30, 16, 44 local T_PRESS = CUR1 local T_LOAD = LOAD local T_DONE = LOAD + 8 * SEGF local T_SHUT = T_DONE + DONE local T_GAP = T_SHUT + SHUT local CYCLE = T_GAP + GAP local TX, TY = WX + 26, WY + 31 local SX0, SY0 = 60, 62 function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local f = frame * STEP_HZ // FPS local t = f % CYCLE for i = 1, #SPK do local s = SPK[i] local on = sin((f + s[3]) * 0.15) > 0 local a = on and 255 or 200 px(s[1], s[2], a, a, a) if on then px(s[1] - 1, s[2], 230, 220, 255); px(s[1] + 1, s[2], 230, 220, 255) px(s[1], s[2] - 1, 230, 220, 255); px(s[1], s[2] + 1, 230, 220, 255) end end if t >= T_GAP then return end local cy = WY + WH // 2 local cw, ch = WW + 4, WH + 4 local x0, y0 = WX - 1, WY - 1 if t < OPEN then ch = 2 + (WH * t) // OPEN y0 = cy - ch // 2 elseif t >= T_SHUT then local k = t - T_SHUT if k < 10 then ch = 2 + (WH * (10 - k)) // 10; y0 = cy - ch // 2 else ch = 2; y0 = cy - 1 cw = 2 + (WW * (SHUT - k)) // (SHUT - 10); x0 = WX + WW // 2 - cw // 2 end end gfx.clip(x0, y0, cw + 2, ch + 3) if ch <= 6 then rect(x0, y0, cw + 2, ch, 244, 240, 255) elseif t < T_PRESS + PRESS then window(TITLE, t >= T_PRESS, 0, 0, 0) elseif t < T_DONE then local e = t - T_LOAD local fill = e // SEGF if fill > 7 then fill = 8 end local pct = (100 * e) // (8 * SEGF) if e < 0 then pct, fill = 0, 0 end window("LOADING", false, 1, fill, pct) else window(TITLE, false, 2, 8, 100) end gfx.clip() if t >= CUR0 and t < T_LOAD + 4 then local i = t - CUR0 local N = CUR1 - CUR0 local x, y if i < N then x = SX0 + ((TX - SX0) * i) // N y = SY0 + ((TY - SY0) * i) // N else x, y = TX, TY end if t >= T_PRESS and t < T_PRESS + PRESS then x, y = x + 1, y + 1 end if t >= T_PRESS + PRESS then local o = t - T_PRESS - PRESS x, y = TX + o, TY + o * 2 end gfx.blit_indexed(CUR, CUR_PAL, x, y, 8, 12, 8, 12, true) if t >= T_PRESS and t < T_PRESS + 6 then local r = 3 + (t - T_PRESS) px(TX - r, TY, 255, 255, 255); px(TX + r, TY, 255, 255, 255) px(TX, TY - r, 255, 255, 255); px(TX, TY + r, 255, 255, 255) end end end