Skip to content

Commit

Permalink
同步与整合上游
Browse files Browse the repository at this point in the history
着色器 fsrcnnx 分支跟进与重命名(变体 x1 不执行放大操作)

脚本 uosc 更新至4.6.0
  • Loading branch information
hooke007 committed Feb 15, 2023
1 parent 605363d commit f0a8af5
Show file tree
Hide file tree
Showing 19 changed files with 3,547 additions and 1,232 deletions.
11 changes: 9 additions & 2 deletions portable_config/script-opts.conf
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@

script-opts-append = uosc-autoload=no # 如果播放列表中不存在其它文件且当前文件未结束,自动加载当前路径的下一个文件。默认 no
# 需要 mpv.conf 中设置 --keep-open=yes
script-opts-append = uosc-autoload_types=video
# 当uosc自动加载或uosc跳转下一个文件时限制的文件类型
# 多个值用半角逗号分隔,默认 video 可用的其它值 audio image subtitle
script-opts-append = uosc-shuffle=no # 启用播放列表/当前目录的乱序播放,默认 no

script-opts-append = uosc-ui_scale=1 # 界面元素的缩放率,默认 1
Expand All @@ -562,10 +565,14 @@
script-opts-append = uosc-curtain_opacity=0.5 # 打开上下文菜单时,背景画面的变暗系数,0 即禁用,默认 0.5
script-opts-append = uosc-stream_quality_options=4320,2160,1440,1080,720,480,360,240,144
# 流式传输质量 列表中列出的可选偏好项,示例即默认值
script-opts-append = uosc-media_types=aac,ape,avi,dsf,dts,flac,flv,m2ts,m4a,m4v,mka,mkv,mov,mp3,mp4,mpeg,mpg,ogg,ogv,opus,rm,rmvb,ts,vob,wav,webm,wma,wmv,wv
# (加载文件/导入视频音频轨时)文件浏览器的扩展名过滤列表。默认值覆盖极广,此预设精简为常见的视频和音频格式

##(加载文件/导入视频音频轨时)文件浏览器的扩展名过滤列表。默认值覆盖极广,此预设精简为常见的视频和音频格式
script-opts-append = uosc-video_types=avi,flv,m2ts,m4v,mkv,mov,mp4,mpeg,mpg,ogv,rm,rmvb,ts,vob,webm,wmv
script-opts-append = uosc-audio_types=aac,ape,dsf,dts,flac,m4a,mka,mp3,ogg,opus,wav,wma,wv
script-opts-append = uosc-image_types=apng,avif,bmp,gif,jfif,jpeg,jpg,jxl,png,svg,tif,tiff,webp
script-opts-append = uosc-subtitle_types=ass,idx,lrc,mks,pgs,sup,srt,ssa,txt,vtt
# (导入字幕时)文件浏览器的扩展名过滤列表。默认值覆盖极广,此预设精简为常见的字幕格式

script-opts-append = uosc-font_height_to_letter_width_ratio=0.5 # 用于估算文本宽度。如果你的字体很宽且在菜单中看到明显的右侧裁切,可以尝试提高其值。默认 0.5
script-opts-append = uosc-default_directory=~/
# 文件浏览器的默认目录,示例即默认值
Expand Down
11 changes: 9 additions & 2 deletions portable_config/script-opts/uosc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ top_bar_persistency=
window_border_size=1
window_border_opacity=0.8

# 如果播放列表中不存在其它文件且当前文件未结束,自动加载当前路径的下一个文件。默认 no
# 如果播放列表中不存在其它文件且当前文件未结束,uosc自动加载当前路径的下一个文件。默认 no
# 需要 mpv.conf 中设置 --keep-open=yes
autoload=no
# 当uosc自动加载或uosc跳转下一个文件时限制的文件类型
# 多个值用半角逗号分隔,默认 video 可用的其它值 audio image subtitle
autoload_types=video
# 启用播放列表/当前目录的乱序播放,默认 no
shuffle=no

Expand Down Expand Up @@ -123,10 +126,14 @@ pause_indicator=flash
curtain_opacity=0.5
# 流式传输质量 列表中列出的可选偏好项,示例即默认值
stream_quality_options=4320,2160,1440,1080,720,480,360,240,144

# (加载文件/导入视频音频轨时)文件浏览器的扩展名过滤列表。默认值覆盖极广,此预设精简为常见的视频和音频格式
media_types=aac,ape,avi,dsf,dts,flac,flv,m2ts,m4a,m4v,mka,mkv,mov,mp3,mp4,mpeg,mpg,ogg,ogv,opus,rm,rmvb,ts,vob,wav,webm,wma,wmv,wv
video_types=avi,flv,m2ts,m4v,mkv,mov,mp4,mpeg,mpg,ogv,rm,rmvb,ts,vob,webm,wmv
audio_types=aac,ape,dsf,dts,flac,m4a,mka,mp3,ogg,opus,wav,wma,wv
image_types=apng,avif,bmp,gif,jfif,jpeg,jpg,jxl,png,svg,tif,tiff,webp
# (导入字幕时)文件浏览器的扩展名过滤列表。默认值覆盖极广,此预设精简为常见的字幕格式
subtitle_types=ass,idx,lrc,mks,pgs,sup,srt,ssa,txt,vtt

# 用于估算文本宽度。如果你的字体很宽且在菜单中看到明显的右侧裁切,可以尝试提高其值。默认 0.5
font_height_to_letter_width_ratio=0.5
# 文件浏览器的默认目录,示例即默认值
Expand Down
57 changes: 43 additions & 14 deletions portable_config/scripts/uosc/elements/Menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ local Element = require('elements/Element')
---@alias MenuStackValue {title?: string; hint?: string; icon?: string; value: any; active?: boolean; bold?: boolean; italic?: boolean; muted?: boolean; keep_open?: boolean; separator?: boolean; title_width: number; hint_width: number}
---@alias Fling {y: number, distance: number, time: number, easing: fun(x: number), duration: number, update_cursor?: boolean}

---@alias Modifiers {shift?: boolean, ctrl?: boolean, alt?: boolean}
---@alias MenuCallbackMeta {modifiers: Modifiers}
---@alias MenuCallback fun(value: any, meta: MenuCallbackMeta)

---@class Menu : Element
local Menu = class(Element)

---@param data MenuData
---@param callback fun(value: any)
---@param callback MenuCallback
---@param opts? MenuOptions
function Menu:open(data, callback, opts)
local open_menu = self:is_open()
Expand Down Expand Up @@ -64,12 +68,12 @@ function Menu:close(immediate, callback)
end

---@param data MenuData
---@param callback fun(value: any)
---@param callback MenuCallback
---@param opts? MenuOptions
---@return Menu
function Menu:new(data, callback, opts) return Class.new(self, data, callback, opts) --[[@as Menu]] end
---@param data MenuData
---@param callback fun(value: any)
---@param callback MenuCallback
---@param opts? MenuOptions
function Menu:init(data, callback, opts)
Element.init(self, 'menu', {ignores_menu = true})
Expand All @@ -79,6 +83,8 @@ function Menu:init(data, callback, opts)
self.opts = opts or {}
self.offset_x = 0 -- Used for submenu transition animation.
self.mouse_nav = self.opts.mouse_nav -- Stops pre-selecting items
---@type Modifiers|nil
self.modifiers = nil
self.item_height = nil
self.item_spacing = 1
self.item_padding = nil
Expand Down Expand Up @@ -135,7 +141,7 @@ function Menu:update(data)
local menus_to_serialize = {{new_root, data}}
local old_current_id = self.current and self.current.id

table_assign(new_root, data, {'title', 'hint', 'keep_open'})
table_assign(new_root, data, {'type', 'title', 'hint', 'keep_open'})

local i = 0
while i < #menus_to_serialize do
Expand Down Expand Up @@ -475,7 +481,7 @@ function Menu:open_selected_item(opts)
self:tween(self.offset_x + menu.width / 2, 0, function(offset) self:set_offset_x(offset) end)
self.opacity = 1 -- in case tween above canceled fade in animation
else
self.callback(item.value)
self.callback(item.value, {modifiers = self.modifiers or {}})
if not item.keep_open and not opts.keep_open then self:close() end
end
end
Expand All @@ -493,7 +499,7 @@ function Menu:on_global_mbtn_left_down()
self.drag_data = {{y = cursor.y, time = mp.get_time()}}
self.current.fling = nil
else
if cursor.x < self.ax then self:back()
if cursor.x < self.ax and self.current.parent_menu then self:back()
else self:close() end
end
end
Expand All @@ -511,7 +517,7 @@ end
function Menu:on_global_mbtn_left_up()
if self.proximity_raw == 0 and self.drag_data and not self.is_dragging then
self:select_item_below_cursor()
self:open_selected_item({preselect_submenu_item = false})
self:open_selected_item({preselect_submenu_item = false, keep_open = self.modifiers and self.modifiers.shift})
end
if self.is_dragging then
local distance = self:fling_distance()
Expand Down Expand Up @@ -581,14 +587,22 @@ function Menu:enable_key_bindings()
self:add_key_binding('down', 'menu-next1', self:create_key_action('next'), 'repeatable')
self:add_key_binding('left', 'menu-back1', self:create_key_action('back'))
self:add_key_binding('right', 'menu-select1', self:create_key_action('open_selected_item_preselect'))
self:add_key_binding('shift+right', 'menu-select-soft1', self:create_key_action('open_selected_item_soft'))
self:add_key_binding('shift+mbtn_left', 'menu-select-soft', self:create_key_action('open_selected_item_soft'))
self:add_key_binding('shift+right', 'menu-select-soft1',
self:create_key_action('open_selected_item_soft', {shift = true}))
self:add_key_binding('shift+mbtn_left', 'menu-select3', self:create_modified_mbtn_left_handler({shift = true}))
self:add_key_binding('ctrl+mbtn_left', 'menu-select4', self:create_modified_mbtn_left_handler({ctrl = true}))
self:add_key_binding('mbtn_back', 'menu-back-alt3', self:create_key_action('back'))
self:add_key_binding('bs', 'menu-back-alt4', self:create_key_action('back'))
self:add_key_binding('enter', 'menu-select-alt3', self:create_key_action('open_selected_item_preselect'))
self:add_key_binding('kp_enter', 'menu-select-alt4', self:create_key_action('open_selected_item_preselect'))
self:add_key_binding('shift+enter', 'menu-select-alt5', self:create_key_action('open_selected_item_soft'))
self:add_key_binding('shift+kp_enter', 'menu-select-alt6', self:create_key_action('open_selected_item_soft'))
self:add_key_binding('ctrl+enter', 'menu-select-ctrl1',
self:create_key_action('open_selected_item_preselect', {ctrl = true}))
self:add_key_binding('ctrl+kp_enter', 'menu-select-ctrl2',
self:create_key_action('open_selected_item_preselect', {ctrl = true}))
self:add_key_binding('shift+enter', 'menu-select-alt5',
self:create_key_action('open_selected_item_soft', {shift = true}))
self:add_key_binding('shift+kp_enter', 'menu-select-alt6',
self:create_key_action('open_selected_item_soft', {shift = true}))
self:add_key_binding('esc', 'menu-close', self:create_key_action('close'))
self:add_key_binding('pgup', 'menu-page-up', self:create_key_action('on_pgup'), 'repeatable')
self:add_key_binding('pgdwn', 'menu-page-down', self:create_key_action('on_pgdwn'), 'repeatable')
Expand All @@ -601,10 +615,25 @@ function Menu:disable_key_bindings()
self.key_bindings = {}
end

function Menu:create_key_action(name)
return function(...)
---@param modifiers Modifiers
function Menu:create_modified_mbtn_left_handler(modifiers)
return function()
self.mouse_nav = true
self.modifiers = modifiers
self:on_global_mbtn_left_down()
self:on_global_mbtn_left_up()
self.modifiers = nil
end
end

---@param name string
---@param modifiers? Modifiers
function Menu:create_key_action(name, modifiers)
return function()
self.mouse_nav = false
self:maybe(name, ...)
self.modifiers = modifiers
self:maybe(name)
self.modifiers = nil
end
end

Expand Down
36 changes: 29 additions & 7 deletions portable_config/scripts/uosc/elements/Timeline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,30 @@ function Timeline:render()
end
end

if state.ab_loop_a and state.ab_loop_a > 0 then draw_chapter(state.ab_loop_a, diamond_radius) end
if state.ab_loop_b and state.ab_loop_b > 0 then draw_chapter(state.ab_loop_b, diamond_radius) end
-- A-B loop indicators
local has_a, has_b = state.ab_loop_a and state.ab_loop_a >= 0, state.ab_loop_b and state.ab_loop_b > 0
local ab_radius = round(math.min(math.max(8, foreground_size * 0.25), foreground_size))

---@param time number
---@param kind 'a'|'b'
local function draw_ab_indicator(time, kind)
local x = t2x(time)
ass:new_event()
ass:append(string.format(
'{\\pos(0,0)\\rDefault\\an7\\blur0\\yshad0.01\\bord%f\\1c&H%s\\3c&H%s\\4c&H%s\\1a&H%X&\\3a&H00&\\4a&H00&}',
diamond_border, fg, bg, bg, opacity_to_alpha(options.timeline_opacity * options.timeline_chapters_opacity)
))
ass:draw_start()
ass:move_to(x, fby - ab_radius)
if kind == 'b' then ass:line_to(x + 3, fby - ab_radius) end
ass:line_to(x + (kind == 'a' and 0 or ab_radius), fby)
ass:line_to(x - (kind == 'b' and 0 or ab_radius), fby)
if kind == 'a' then ass:line_to(x - 3, fby - ab_radius) end
ass:draw_stop()
end

if has_a then draw_ab_indicator(state.ab_loop_a, 'a') end
if has_b then draw_ab_indicator(state.ab_loop_b, 'b') end
end
end

Expand All @@ -325,9 +347,8 @@ function Timeline:render()
local cache_opts = {size = self.font_size * 0.8, opacity = text_opacity * 0.6, border = 1}
local human = round(math.max(buffered_playtime, 0)) .. 's'
local width = text_width(human, cache_opts)
local time_width = text_width('00:00:00', time_opts)
local time_width_end = options.destination_time == 'total' and time_width
or text_width('-00:00:00', time_opts)
local time_width = timestamp_width(state.time_human, time_opts)
local time_width_end = timestamp_width(state.destination_time_human, time_opts)
local min_x, max_x = bax + spacing + 5 + time_width, bbx - spacing - 5 - time_width_end
if x < min_x then x = min_x elseif x + width > max_x then x, align = max_x, 6 end
draw_timeline_text(x, fcy, align, human, cache_opts)
Expand Down Expand Up @@ -360,8 +381,9 @@ function Timeline:render()
-- Timestamp
local offset = #state.chapters > 0 and 10 or 4
local opts = {size = self.font_size, offset = offset}
opts.width_overwrite = text_width('00:00:00', opts)
ass:tooltip(tooltip_anchor, format_time(hovered_seconds), opts)
local hovered_time_human = format_time(hovered_seconds, state.duration)
opts.width_overwrite = timestamp_width(hovered_time_human, opts)
ass:tooltip(tooltip_anchor, hovered_time_human, opts)
tooltip_anchor.ay = tooltip_anchor.ay - self.font_size - offset

-- Thumbnail
Expand Down
28 changes: 18 additions & 10 deletions portable_config/scripts/uosc/lib/menus.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
---@param data MenuData
---@param opts? {submenu?: string; mouse_nav?: boolean}
---@param opts? {submenu?: string; mouse_nav?: boolean; on_close?: string | string[]}
function open_command_menu(data, opts)
local menu = Menu:open(data, function(value)
if type(value) == 'string' then
mp.command(value)
local function run_command(command)
if type(command) == 'string' then
mp.command(command)
else
---@diagnostic disable-next-line: deprecated
mp.commandv(unpack(value))
mp.commandv(unpack(command))
end
end, opts)
end
---@type MenuOptions
local menu_opts = {}
if opts then
menu_opts.submenu, menu_opts.mouse_nav = opts.submenu, opts.mouse_nav
if opts.on_close then menu_opts.on_close = function() run_command(opts.on_close) end end
end
local menu = Menu:open(data, run_command, menu_opts)
if opts and opts.submenu then menu:activate_submenu(opts.submenu) end
return menu
end

---@param opts? {submenu?: string; mouse_nav?: boolean}
---@param opts? {submenu?: string; mouse_nav?: boolean; on_close?: string | string[]}
function toggle_menu_with_items(opts)
if Menu:is_open('menu') then Menu:close()
else open_command_menu({type = 'menu', items = config.menu_items}, opts) end
Expand Down Expand Up @@ -198,7 +205,8 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
if opts.selected_path == item.value then selected_index = index end
end

local function open_path(path)
---@type MenuCallback
local function open_path(path, meta)
local is_drives = path == '{drives}'
local is_to_parent = is_drives or #path < #directory_path
local inheritable_options = {
Expand All @@ -222,7 +230,7 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
return
end

if info.is_dir then
if info.is_dir and not meta.modifiers.ctrl then
-- Preselect directory we are coming from
if is_to_parent then
inheritable_options.selected_path = directory.path
Expand All @@ -235,7 +243,7 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
end

local function handle_back()
if back_path then open_path(back_path) end
if back_path then open_path(back_path, {modifiers = {}}) end
end

local menu_data = {
Expand Down
18 changes: 18 additions & 0 deletions portable_config/scripts/uosc/lib/text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,24 @@ do
end
end

do
---@type {[string]: string}
local cache = {}

---Get width of formatted timestamp as if all the digits were replaced with 0
---@param timestamp string
---@param opts {size: number; bold?: boolean; italic?: boolean}
---@return number
function timestamp_width(timestamp, opts)
local substitute = cache[#timestamp]
if not substitute then
substitute = timestamp:gsub('%d', '0')
cache[#timestamp] = substitute
end
return text_width(substitute, opts)
end
end

---Wrap the text at the closest opportunity to target_line_length
---@param text string
---@param opts {size: number; bold?: boolean; italic?: boolean}
Expand Down
Loading

0 comments on commit f0a8af5

Please sign in to comment.