diff --git a/js/interface/themes.js b/js/interface/themes.js index e0b08ab6..80d22baa 100644 --- a/js/interface/themes.js +++ b/js/interface/themes.js @@ -3,6 +3,7 @@ const CustomTheme = { id: 'dark', name: '', author: '', + customized: false, borders: false, main_font: '', headline_font: '', @@ -31,11 +32,29 @@ const CustomTheme = { wireframe: '#576f82', checkerboard: '#1c2026', }, + sideloaded_themes: [], setup() { function saveChanges() { localStorage.setItem('theme', JSON.stringify(CustomTheme.data)); } + if (isApp && localStorage.getItem('themes_sideloaded')) { + try { + let sideloaded = JSON.parse(localStorage.getItem('themes_sideloaded')); + if (sideloaded instanceof Array && sideloaded.length) { + CustomTheme.sideloaded_themes = sideloaded; + Blockbench.read(CustomTheme.sideloaded_themes, {}, files => { + files.forEach(file => { + let data = JSON.parse(file.content); + data.id = file.name.replace(/\.\w+$/, ''); + if (!data.name) data.name = data.id; + CustomTheme.themes.push(data); + + }) + }) + } + } catch (err) {} + } CustomTheme.dialog = new Dialog({ id: 'theme', @@ -85,6 +104,8 @@ const CustomTheme = { CustomTheme.themes.push(theme); }) }).catch(console.error) + + } }, component: { @@ -126,6 +147,9 @@ const CustomTheme = { CustomTheme.loadTheme(theme); saveChanges(); }, + customizeTheme() { + CustomTheme.customizeTheme(); + }, getThemeThumbnailStyle(theme) { let style = {}; for (let key in theme.colors) { @@ -134,13 +158,22 @@ const CustomTheme = { return style; } }, + computed: { + listed_themes() { + let themes = this.themes.slice(); + if (this.data.customized) { + themes.splice(0, 0, this.data); + } + return themes; + } + }, template: `

${tl('layout.select')}

-
+
@@ -161,7 +194,7 @@ const CustomTheme = {
{{ theme.name }}
-
{{ theme.author || 'Default' }}
+
{{ theme.author }}
@@ -181,37 +214,37 @@ const CustomTheme = {

${tl('layout.options')}

-
+
- +
-
+
- +

- +
- +
- +

${tl('layout.css')}

- +
@@ -243,6 +276,7 @@ const CustomTheme = { chooseText: tl('dialog.confirm'), move(c) { CustomTheme.data.colors[scope_key] = c.toHexString(); + CustomTheme.customizeTheme(); }, change(c) { last_color = c.toHexString(); @@ -260,6 +294,20 @@ const CustomTheme = { } CustomTheme.dialog_is_setup = true; }, + customizeTheme() { + if (!CustomTheme.data.customized) { + CustomTheme.data.customized = true; + CustomTheme.data.name = CustomTheme.data.name ? ('Copy of ' + CustomTheme.data.name) : 'Custom Theme'; + CustomTheme.data.author = settings.username.value; + CustomTheme.data.id = 'custom_theme'; + let i = 0; + while (CustomTheme.themes.find(theme => theme.id == CustomTheme.data.id)) { + i++; + CustomTheme.data.id = 'custom_theme_'+i; + } + localStorage.setItem('theme', JSON.stringify(CustomTheme.data)); + } + }, updateColors() { for (var key in CustomTheme.data.colors) { @@ -314,6 +362,7 @@ const CustomTheme = { } } Merge.string(app, theme, 'css'); + app.customized = false; this.updateColors(); this.updateSettings(); }, @@ -334,9 +383,16 @@ const CustomTheme = { app.colors.accent_text = data.text_acc } - } else { - if (data && data.colors) { - CustomTheme.loadTheme(data); + } else if (data && data.colors) { + data.id = file.name.replace(/\.\w+$/, ''); + if (!data.name) data.name = data.id; + + CustomTheme.loadTheme(data); + CustomTheme.themes.push(data); + + if (isApp) { + CustomTheme.sideloaded_themes.push(file.path); + localStorage.setItem('themes_sideloaded', JSON.stringify(CustomTheme.sideloaded_themes)); } } } @@ -356,6 +412,7 @@ const CustomTheme = { } if (stored_theme) { CustomTheme.loadTheme(stored_theme); + if (stored_theme.customized) CustomTheme.data.customized = true; } })() @@ -386,28 +443,19 @@ BARS.defineActions(function() { icon: 'style', category: 'blockbench', click: function () { + let theme = {}; + Object.assign(theme, CustomTheme.data); + delete theme.customized; + delete theme.id; Blockbench.export({ resource_id: 'config', type: 'Blockbench Theme', extensions: ['bbtheme'], + name: theme.id, content: compileJSON(CustomTheme.data) }) } }) - new Action('reset_theme', { - icon: 'replay', - category: 'blockbench', - click() { - var app = CustomTheme.data; - app.main_font = ''; - app.headline_font = ''; - app.code_font = ''; - app.css = ''; - for (var key in app.colors) { - Merge.string(app.colors, CustomTheme.defaultColors, key); - } - } - }) //Only interface new Action('reset_layout', { icon: 'replay', @@ -425,7 +473,6 @@ BARS.defineActions(function() { }) BarItems.import_theme.toElement('#layout_title_bar') BarItems.export_theme.toElement('#layout_title_bar') - BarItems.reset_theme.toElement('#layout_title_bar') }) diff --git a/keymaps/blender.bbkeymap b/keymaps/blender.bbkeymap index c6b32dcb..daeb5441 100644 --- a/keymaps/blender.bbkeymap +++ b/keymaps/blender.bbkeymap @@ -32,7 +32,6 @@ "action_control": {"key": 70}, "import_theme": null, "export_theme": null, - "reset_theme": null, "reset_layout": null, "start": null, "edit": {"key": 49}, diff --git a/keymaps/cinema4d.bbkeymap b/keymaps/cinema4d.bbkeymap index 66c9a1a6..493bc7ac 100644 --- a/keymaps/cinema4d.bbkeymap +++ b/keymaps/cinema4d.bbkeymap @@ -32,7 +32,6 @@ "action_control": {"key": 112}, "import_theme": null, "export_theme": null, - "reset_theme": null, "reset_layout": null, "start": null, "edit": null, diff --git a/keymaps/maya.bbkeymap b/keymaps/maya.bbkeymap index 19edb197..4bb30380 100644 --- a/keymaps/maya.bbkeymap +++ b/keymaps/maya.bbkeymap @@ -32,7 +32,6 @@ "action_control": {"key": 112}, "import_theme": null, "export_theme": null, - "reset_theme": null, "reset_layout": null, "start": null, "edit": null, diff --git a/lang/en.json b/lang/en.json index 622c9fe4..1589dc42 100644 --- a/lang/en.json +++ b/lang/en.json @@ -862,8 +862,6 @@ "action.import_theme": "Import Theme", "action.export_theme": "Export Theme", "action.export_theme.desc": "Create a theme file based on the current settings", - "action.reset_theme": "Reset Theme", - "action.reset_theme.desc": "Reset to the default Blockbench theme", "action.uv_dialog": "UV Window...", "action.uv_dialog.desc": "Open the UV dialog to see all faces next to each other", diff --git a/themes/contrast.bbtheme b/themes/contrast.bbtheme index 4bd81145..55a2187e 100644 --- a/themes/contrast.bbtheme +++ b/themes/contrast.bbtheme @@ -1,7 +1,7 @@ { "id": "contrast", "name": "Contrast", - "author": "", + "author": "Default", "borders": true, "main_font": "", "headline_font": "", diff --git a/themes/dark.bbtheme b/themes/dark.bbtheme index a8cc28b6..c759f906 100644 --- a/themes/dark.bbtheme +++ b/themes/dark.bbtheme @@ -1,7 +1,7 @@ { "id": "dark", "name": "Default (Dark)", - "author": "", + "author": "Default", "main_font": "", "headline_font": "", "code_font": "", diff --git a/themes/light.bbtheme b/themes/light.bbtheme index 150aa430..b531a5f7 100644 --- a/themes/light.bbtheme +++ b/themes/light.bbtheme @@ -1,7 +1,7 @@ { "id": "light", "name": "Default (Light)", - "author": "", + "author": "Default", "main_font": "", "headline_font": "", "code_font": "",