dan select: extend the parent's DanSelect instead of replacing it #42
@@ -1,7 +1,25 @@
|
|||||||
-- DAN_SELECT paint surface: selection cursor breathing loop and arrow chips,
|
-- DAN_SELECT paint surface: selection cursor breathing loop and arrow chips,
|
||||||
-- sampled from the cabinet's own clips.
|
-- sampled from the cabinet's own clips. The dan boxes themselves are drawn by the
|
||||||
DanSelect = {}
|
-- parent skin's dan_select.lua, which is loaded first and extended here.
|
||||||
DanSelect.__index = DanSelect
|
|
||||||
|
-- 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")
|
local ok, anim = pcall(require, "anim/sampler")
|
||||||
if not ok then anim = { safe = function()
|
if not ok then anim = { safe = function()
|
||||||
@@ -16,11 +34,12 @@ local CUR = anim.safe("anim/dan_cursor")
|
|||||||
local ARW = anim.safe("anim/dan_arrow")
|
local ARW = anim.safe("anim/dan_arrow")
|
||||||
local ARW_OFF = ARW:label("arrow_off") or 61
|
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()
|
function DanSelect.new()
|
||||||
-- No real clip data at all -> hand the whole draw back to the engine's
|
local self = parent_new and parent_new() or setmetatable({}, DanSelect)
|
||||||
-- inline tables (returning nil leaves fn_draw_cursor invalid, C++ side).
|
|
||||||
if not CUR:has("#259@0") and not ARW:has("#261@0") then return nil end
|
|
||||||
local self = setmetatable({}, DanSelect)
|
|
||||||
self.t_cursor = tex.get_texture("dan_select/box/cursor")
|
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_r = tex.get_texture("dan_select/box/arrow_r")
|
||||||
self.t_arrow_l = tex.get_texture("dan_select/box/arrow_l")
|
self.t_arrow_l = tex.get_texture("dan_select/box/arrow_l")
|
||||||
@@ -29,7 +48,7 @@ end
|
|||||||
|
|
||||||
-- pos: selected chip x (the textures' own json positions carry the rest);
|
-- 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).
|
-- now_ms: engine clock; moved_ms: ms since the last ribbon step (-1 = never).
|
||||||
function DanSelect:draw_cursor(pos, now_ms, moved_ms)
|
local function draw_cursor(self, pos, now_ms, moved_ms)
|
||||||
if self.t_cursor then
|
if self.t_cursor then
|
||||||
local f = (now_ms * 0.06) % 60
|
local f = (now_ms * 0.06) % 60
|
||||||
local a = CUR:get("#259@0", f, "a") or 1
|
local a = CUR:get("#259@0", f, "a") or 1
|
||||||
@@ -51,3 +70,5 @@ function DanSelect:draw_cursor(pos, now_ms, moved_ms)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if HAS_CLIPS then DanSelect.draw_cursor = draw_cursor end
|
||||||
Reference in new issue
Block a user