From bf5a51963b099972be89f290a43c9f0de2bb4b05 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sat, 1 Dec 2018 01:35:22 +0100 Subject: [PATCH] forgot to commit new files --- js/lib/KeyboardShortcutParser.js | 21 ++++++++ js/lib/libghettoui/settings/ActionItem.js | 39 ++++++++++++++ res/settings/js/customization.js | 65 +++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 js/lib/KeyboardShortcutParser.js create mode 100644 js/lib/libghettoui/settings/ActionItem.js create mode 100644 res/settings/js/customization.js diff --git a/js/lib/KeyboardShortcutParser.js b/js/lib/KeyboardShortcutParser.js new file mode 100644 index 0000000..b5c70cd --- /dev/null +++ b/js/lib/KeyboardShortcutParser.js @@ -0,0 +1,21 @@ +class KeyboardShortcutParser { + static parseShortcut(keypress) { + var shortcutCombo = ''; + + if (keypress.ctrlKey) { + shortcutCombo += 'Ctrl + '; + } + if (keypress.shiftKey) { + shortcutCombo += 'Shift + '; + } + if (keypress.metaKey) { + shortcutCombo += 'Meta + '; + } + if (keypress.altKey) { + shortcutCombo += 'Alt + '; + } + shortcutCombo += keypress.key.toUpperCase(); + + return shortcutCombo; + } +} \ No newline at end of file diff --git a/js/lib/libghettoui/settings/ActionItem.js b/js/lib/libghettoui/settings/ActionItem.js new file mode 100644 index 0000000..123e320 --- /dev/null +++ b/js/lib/libghettoui/settings/ActionItem.js @@ -0,0 +1,39 @@ +class ActionItem extends BaseElement { + constructor(id, action, onClick) { + super(id, undefined, onClick); + this.element.classList.add("action-list-item", "flex", "flex-row"); + + // action list item looks like this + // [ action.label | shortcut | visibility checkboxes ] + + var cmd = document.createElement('div') + var label = document.createElement('div'); + var shortcut = document.createElement('div'); + var popupVideoCb = document.createElement('div'); + var popupSiteCb = document.createElement('div'); + var popupGlobalCb = document.createElement('div'); + var playerUi = document.createElement('div'); + + cmd.classList.add('cmd', 'flex'); + label.classList.add('label', 'flex'); + shortcut.classList.add('shortcut', 'flex'); + popupVideoCb.classList.add('checkbox', 'flex'); + popupSiteCb.classList.add('checkbox', 'flex'); + popupGlobalCb.classList.add('checkbox', 'flex'); + playerUi.classList.add('checkbox', 'flex'); + + for (var c in action.cmd) { + cmd.textContent += `${c > 0 ? '; ' : ''}${action.cmd[0].action} ${action.cmd[0].arg}` + } + label.textContent = action.label; + shortcut.textContent = action.parsedShortcut; + + this.element.appendChild(label); + this.element.appendChild(cmd); + this.element.appendChild(shortcut); + this.element.appendChild(popupVideoCb); + this.element.appendChild(popupSiteCb); + this.element.appendChild(popupGlobalCb); + this.element.appendChild(playerUi); + } +} \ No newline at end of file diff --git a/res/settings/js/customization.js b/res/settings/js/customization.js new file mode 100644 index 0000000..b87b564 --- /dev/null +++ b/res/settings/js/customization.js @@ -0,0 +1,65 @@ +if (Debug.debug) { + console.log("[customization.js] loading script for customization tab") +} + +function loadActions() { + if (Debug.debug) { + console.log("[customization.js] loading actions\n", settings, "\n", settings.active.actions) + } + + // build actions list + + const actions = settings.active.actions; + + const cropActions = actions.filter(action => action.cmd.length === 1 && action.cmd[0].action === 'set-ar'); + const stretchActions = actions.filter(action => action.cmd.length === 1 && action.cmd[0].action === 'set-stretch'); + const alignActions = actions.filter(action => action.cmd.length === 1 && action.cmd[0].action === 'set-alignment'); + const zoomPanActions = actions.filter(action => action.cmd.length === 1 && ( + action.cmd[0].action === 'set-zoom' || + action.cmd[0].action === 'set-pan' || + action.cmd[0].action === 'pan' || + action.cmd[0].action === 'set-pan') + ); + + // this is shit on performance but it'll cut it for this job + const otherActions = actions.filter(action => action.cmd.length > 1 || ( + action.cmd.length === 1 && + cropActions.indexOf(action) === -1 && + stretchActions.indexOf(action) === -1 && + alignActions.indexOf(action) === -1 && + zoomPanActions.indexOf(action) === -1 ) + ); + + loadActionSection(cropActions, ui.customization.actionList); + loadActionSection(stretchActions, ui.customization.actionList); + loadActionSection(alignActions, ui.customization.actionList); + loadActionSection(zoomPanActions, ui.customization.actionList); + loadActionSection(otherActions, ui.customization.actionList); + + ui.customization.actionItems.push(cropActions); + ui.customization.actionItems.push(stretchActions); + ui.customization.actionItems.push(alignActions); + ui.customization.actionItems.push(zoomPanActions); + ui.customization.actionItems.push(otherActions); + + console.log("ui.customization:", ui.customization) +} + +function loadActionSection(actions, container) { + for(action of actions) { + if (action.shortcut && action.shortcut[0].key) { + action.parsedShortcut = KeyboardShortcutParser.parseShortcut(action.shortcut[0]) + } + var actionIndex = settings.active.actions.indexOf(action); + var newAction = new ActionItem( + undefined, + action, + () => editShortcut(actionIndex) + ); + newAction.appendTo(container); + } +} + +function editShortcut(actionIndex) { + alert(`customization.js/editShortcut: Implement me pls. ActionIndex: ${actionIndex}`); +} \ No newline at end of file