From 08ade07652d02441d81ab16387a51755ac1b0f77 Mon Sep 17 00:00:00 2001 From: hyousatsu <118750527+hyousatsu@users.noreply.github.com> Date: Sun, 18 Aug 2024 00:31:00 +0000 Subject: [PATCH] Optimize the selection menu. --- main.js | 14 +++++++------- modules.js/AssFormat.js | 5 +++++ modules.js/SelectionMenu.js | 21 +++++++++++++++------ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/main.js b/main.js index 3b38f60..f230efd 100644 --- a/main.js +++ b/main.js @@ -301,7 +301,7 @@ var DLNA_Browser = function(options) { DLNA_Browser.prototype.findDLNAServers = function() { this.scan = false; this.menu.title = "Scanning for DLNA Servers"; - this.menu.renderMenu("", 1); + this.menu.renderMenu(null, 1); mp.msg.info("scanning for dlna servers"); @@ -330,7 +330,7 @@ DLNA_Browser.prototype.findDLNAServers = function() { this.current_folder = this.servers; this.menu.setOptions(this.servers, 0); - this.menu.renderMenu("", 1); + this.menu.renderMenu(null, 1); }; @@ -846,7 +846,7 @@ DLNA_Browser.prototype.autocomplete_text = function(text, message, tabbing) { // Update the menu selection to match this.menu.selectionIdx = this.selected_auto.findex; - this.menu.renderMenu("", 1); + this.menu.renderMenu(null, 1); message = Ass.alpha("DDDD6E") + this.selected_auto.pre + Ass.alpha("00") + message + Ass.alpha("DDDD6E") + this.selected_auto.post; @@ -950,7 +950,7 @@ DLNA_Browser.prototype.command_ep = function(args, text) { if (episode_info.start <= s_target && s_target <= episode_info.end) { this.select(selection.children[i]); this.menu.selectionIdx = j; - this.menu.renderMenu("", 1); + this.menu.renderMenu(null, 1); // Make the output look nice var E = episode_info.start; @@ -1051,7 +1051,7 @@ DLNA_Browser.prototype.on_file_load = function() { // Update the now playing indicator and rerender the menu if necessary folder[episode.id].isPlaying = true; - this.menu.renderMenu("", 1); + this.menu.renderMenu(null, 1); // Set the title to match the current episode mp.msg.trace("setting title to: " + episode.folder.name + ": " + folder[episode.id].name); @@ -1234,7 +1234,7 @@ DLNA_Browser.prototype.select = function(selection) { success = true; } - this.menu.renderMenu("", 1); + this.menu.renderMenu(null, 1); return success; } @@ -1311,7 +1311,7 @@ DLNA_Browser.prototype.back = function() { this.generateMenuTitle(this.titles[this.titles.length-1]); } - this.menu.renderMenu("", 1); + this.menu.renderMenu(null, 1); } DLNA_Browser.prototype._registerCallbacks = function() { diff --git a/modules.js/AssFormat.js b/modules.js/AssFormat.js index 19fdca8..3c2b437 100644 --- a/modules.js/AssFormat.js +++ b/modules.js/AssFormat.js @@ -43,6 +43,11 @@ Ass.esc = function(str, escape) return str.replace(/\\/g, '\\\u2060').replace(/\{/g, '\\{'); }; +Ass.bold = function(bold, output) +{ + return output === false ? '' : '{\\b'+(bold === false ? '0' : '1')+'}'; +}; + Ass.size = function(fontSize, output) { return output === false ? '' : '{\\fs'+fontSize+'}'; diff --git a/modules.js/SelectionMenu.js b/modules.js/SelectionMenu.js index 260b15c..af4c092 100644 --- a/modules.js/SelectionMenu.js +++ b/modules.js/SelectionMenu.js @@ -450,10 +450,17 @@ SelectionMenu.prototype.renderMenu = function(selectionPrefix, renderMode) var opt; for (var i = startIdx; i <= endIdx; ++i) { opt = this.options[i]; - if (i === this.selectionIdx) - // NOTE: Prefix stays on screen until cursor-move or re-render.z - finalString += Ass.yellow(c)+'> '+(typeof selectionPrefix === 'string' ? - Ass.esc(selectionPrefix, c)+' ' : ''); + + if (i === this.selectionIdx) finalString += '\n'+Ass.bold(true); + + if (opt.isPlaying) finalString += Ass.green(c); + else if (i === this.selectionIdx) finalString += Ass.yellow(c); + + // NOTE: Prefix stays on screen until cursor-move or re-render.z + finalString += i === this.selectionIdx ? '> ' : '| '; + + finalString += typeof selectionPrefix === 'string' ? + Ass.esc(selectionPrefix, c)+' ' : ''; // If the menu option has no children to move to // then it should be colored red and ignored @@ -474,10 +481,12 @@ SelectionMenu.prototype.renderMenu = function(selectionPrefix, renderMode) if (opt.isPlaying) finalString += " <=="; - if (i === this.selectionIdx || (opt.children != null && opt.children.length == 0)) + if (i === this.selectionIdx) finalString += Ass.bold(false); + + if (opt.isPlaying || i === this.selectionIdx || (opt.children != null && opt.children.length == 0)) finalString += Ass.white(c); if (i !== endIdx) - finalString += '\n'; + finalString += i === this.selectionIdx ? '\n\n' : '\n'; } }