Last active
February 25, 2018 19:58
-
-
Save kyzentun/de7c19d18b3cbb9002832c8a87c47422 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- adjust_luma belongs in 02 Colors.lua | |
function adjust_luma(from_color, adjustment) | |
local res_color= {} | |
for i= 1, 3 do | |
res_color[i]= (from_color[i]^2.2 * adjustment)^(1/2.2) | |
end | |
res_color[4]= from_color[4] | |
return res_color | |
end | |
-- Remove "Protiming" bool from 02 player_config.lua, replace with protiming | |
-- table: | |
protiming= { | |
hidden= true, | |
width= 10, | |
height= 100, | |
x= 0, | |
y= 0, | |
scale= 1, | |
marker_scale= 1, | |
} | |
-- Menu options that belong in 04 player_options.lua: | |
-- These also need strings added in the translation file. | |
gameplay_options[#gameplay_options+1]= { | |
"submenu", "protiming", { | |
{"item", player_config, "protiming.hidden", "bool"}, | |
{"item", player_config, "protiming.width", "number"}, | |
{"item", player_config, "protiming.height", "number"}, | |
{"item", player_config, "protiming.x", "number"}, | |
{"item", player_config, "protiming.y", "number"}, | |
{"item", player_config, "protiming.scale", "percent"}, | |
{"item", player_config, "protiming.marker_scale", "percent"}, | |
}} | |
-- The rest is an actor to load in "Player judgment". | |
local player = Var("Player") | |
local judge_colors= {} | |
-- This code converts the judgmentline colors to bright and dark variants | |
-- Use a different set of judge colors as the base if you want. | |
local dark_judge_colors= {} | |
local bright_judge_colors= {} | |
for name, c in pairs(GameColor.Judgment) do | |
local tns_name= "TapNoteScore_"..ToEnumShortString(name) | |
dark_judge_colors[tns_name]= adjust_luma(c, .5) | |
bright_judge_colors[tns_name]= adjust_luma(c, 2) | |
end | |
local function dark_judge_i(index) | |
return dark_judge_colors["TapNoteScore_W"..index] or dark_judge_colors.TapNoteScore_Miss | |
end | |
-- Store children so GetChild doesn't need to be called. | |
local protiming_bg= false | |
local protiming_marker= false | |
-- protiming_bg_scale scales from tap note offset to position, for placing the marker | |
local protiming_bg_scale= 1 | |
local hidden= false | |
local window_scale= PREFSMAN:GetPreference("TimingWindowScale") | |
local max_offset= PREFSMAN:GetPreference("TimingWindowSecondsW5") * window_scale | |
local miss_offset= max_offset * 1.25 | |
local vertical_protiming= Def.ActorFrame{ | |
InitCommand= function(self) | |
self:play_command_no_recurse("Resize") | |
end, | |
MenuValueChangedMessageCommand= function(self, param) | |
if param.pn ~= player then return end | |
if param.field_name and param.field_name:find("protiming") then | |
self:play_command_no_recurse("Resize") | |
end | |
end, | |
ResizeCommand= function(self) | |
local conf= player_config:get_data(player).protiming | |
hidden= conf.hidden | |
self:xy(conf.x, conf.y):zoom(conf.scale) | |
protiming_bg:playcommand("Resize", conf) | |
protiming_marker:playcommand("Resize", conf) | |
if hidden then | |
self:hibernate(math.huge) | |
else | |
self:hibernate(0) | |
end | |
end, | |
Def.ActorMultiVertex{ | |
InitCommand= function(self) | |
protiming_bg= self | |
self:SetDrawState{Mode= "DrawMode_Quads"} | |
local verts= {} | |
local windows= { | |
PREFSMAN:GetPreference("TimingWindowSecondsW1") * window_scale, | |
PREFSMAN:GetPreference("TimingWindowSecondsW2") * window_scale, | |
PREFSMAN:GetPreference("TimingWindowSecondsW3") * window_scale, | |
PREFSMAN:GetPreference("TimingWindowSecondsW4") * window_scale, | |
PREFSMAN:GetPreference("TimingWindowSecondsW5") * window_scale, | |
} | |
local ms_scale= 1 | |
local function add_verts(lms, hms, col) | |
local lypos= lms * ms_scale | |
local hypos= hms * ms_scale | |
verts[#verts+1]= {{-.5, lypos, 0}, col} | |
verts[#verts+1]= {{.5, lypos, 0}, col} | |
verts[#verts+1]= {{.5, hypos, 0}, col} | |
verts[#verts+1]= {{-.5, hypos, 0}, col} | |
end | |
for i= #windows, 1, -1 do | |
add_verts(-windows[i], -(windows[i-1] or 0), dark_judge_i(i)) | |
end | |
for i= 1, #windows do | |
add_verts(windows[i-1] or 0, windows[i], dark_judge_i(i)) | |
end | |
self:SetVertices(verts) | |
end, | |
ResizeCommand= function(self, conf) | |
local bg_height= max_offset*2 | |
protiming_bg_scale= conf.height / bg_height | |
self:zoomx(conf.width):zoomy(conf.height / bg_height) | |
end, | |
}, | |
Def.Sprite{ | |
Texture= THEME:GetPathG("Protiming", "marker"), | |
InitCommand= function(self) | |
protiming_marker= self | |
end, | |
ResizeCommand= function(self, conf) | |
-- Scale to conventional size before applying the player's scale, so | |
-- that when the image changes, it has the same size on the screen. | |
local conventional_width = 32 | |
local image_width = self:GetWidth() | |
local conventional_scale= image_width / conventional_width | |
self:zoom(conf.marker_scale * conventional_scale) | |
end, | |
JudgmentMessageCommand= function(self, judge) | |
if hidden then return end | |
if judge.Player ~= player then return end | |
if not judge.TapNoteScore then return end | |
if not judge.TapNoteOffset then return end | |
local offset= judge.TapNoteOffset | |
if judge.TapNoteScore == "TapNoteScore_Miss" then | |
offset= miss_offset | |
end | |
self:diffuse(bright_judge_colors[judge.TapNoteScore]) | |
:y(protiming_bg_scale * offset) | |
end, | |
}, | |
} | |
return vertical_protiming |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment