Files
YataiDONNijiiro/Scripts/dan_select/dan_select.lua
T

104 lines
4.1 KiB
Lua

-- DAN_SELECT paint surface: selection cursor breathing loop and arrow chips,
-- sampled from the cabinet's own clips. The dan boxes themselves are drawn by the
-- parent skin's dan_select.lua, which is loaded first and extended here.
-- the parent skin's copy of this script: the second match on package.path (the first is this file)
local function load_parent(name)
local seen = false
for tmpl in package.path:gmatch("[^;]+") do
local chunk = loadfile((tmpl:gsub("%?", name)))
if chunk then
if seen then return chunk end
seen = true
end
end
end
local parent = load_parent("dan_select/dan_select")
if parent then parent() end
if not DanSelect then
DanSelect = {}
DanSelect.__index = DanSelect
end
local parent_new = DanSelect.new
local ok, anim = pcall(require, "anim/sampler")
if not ok then anim = { safe = function()
local n = {}
n.at = function() return nil end; n.get = function() return nil end
n.label = function() return nil end; n.has = function() return false end
n.first = function() return 0 end; n.last = function() return 0 end
return n
end } end
local CUR = anim.safe("anim/dan_cursor")
local ARW = anim.safe("anim/dan_arrow")
local ARW_OFF = ARW:label("arrow_off") or 61
-- No real clip data at all -> no draw_cursor: the engine draws the cursor from its
-- inline tables (the boxes are still drawn by the parent's DanSelect).
local HAS_CLIPS = CUR:has("#259@0") or ARW:has("#261@0")
function DanSelect.new()
local self = parent_new and parent_new() or setmetatable({}, DanSelect)
self.t_cursor = tex.get_texture("dan_select/box/cursor")
self.t_arrow_r = tex.get_texture("dan_select/box/arrow_r")
self.t_arrow_l = tex.get_texture("dan_select/box/arrow_l")
return self
end
-- pos: selected chip x (the textures' own json positions carry the rest);
-- now_ms: engine clock; moved_ms: ms since the last ribbon step (-1 = never).
local function draw_cursor(self, pos, now_ms, moved_ms)
if self.t_cursor then
local f = (now_ms * 0.06) % 60
local a = CUR:get("#259@0", f, "a") or 1
tex.draw_texture(self.t_cursor, { x = pos, fade = a })
end
if moved_ms and moved_ms >= 0 then
local f = moved_ms * 0.06
if f <= (ARW_OFF - 1) then
local drift = ARW:get("#261@0", f, "tx") or 0
local a = ARW:get("#261@0", f, "a") or 0
if a > 0 then
if self.t_arrow_r then
tex.draw_texture(self.t_arrow_r, { x = pos + drift, fade = a })
end
if self.t_arrow_l then
tex.draw_texture(self.t_arrow_l, { x = pos - drift, fade = a })
end
end
end
end
end
if HAS_CLIPS then DanSelect.draw_cursor = draw_cursor end
-- The course's clear stamp (yellow_box/clear_mark) sits over the dan plate and Don, as the
-- cabinet's stamp_detail does (it is above don_1p). The parent draws it with the box, under
-- both, so it is held back there and drawn with the title, which the engine draws after
-- the chara and the nameplate.
local parent_open, parent_title = DanSelect.draw_dan_open, DanSelect.draw_title
local held_stamp -- shared: the boxes and the title can be drawn through different instances
if parent_open then
function DanSelect:draw_dan_open(box)
local stamp = tex.get_texture("dan_select/yellow_box/clear_mark")
if not stamp or box.clear_mark <= 0 then return parent_open(self, box) end
local draw = tex.draw_texture
tex.draw_texture = function(id, p)
if id == stamp then return end
return draw(id, p)
end
local ok, err = pcall(parent_open, self, box)
tex.draw_texture = draw
if not ok then error(err, 0) end
held_stamp = { id = stamp, frame = box.clear_mark - 1, fade = box.open_fade.attribute }
end
function DanSelect:draw_title()
if parent_title then parent_title(self) end
local s = held_stamp
held_stamp = nil
if s then tex.draw_texture(s.id, { frame = s.frame, fade = s.fade }) end
end
end