diff --git a/evennia/web/webclient/static/webclient/js/plugins/font.js b/evennia/web/webclient/static/webclient/js/plugins/font.js index 82008b4930..8b2bb80caa 100644 --- a/evennia/web/webclient/static/webclient/js/plugins/font.js +++ b/evennia/web/webclient/static/webclient/js/plugins/font.js @@ -57,8 +57,8 @@ let font_plugin = (function () { // var onFontFamily = function (evnt) { var family = $(evnt.target).val(); - $(document.body).css('font-family', family); - localStorage.setItem('evenniaFontFamily', family); + $(document.body).css("font-family", family); + localStorage.setItem("evenniaFontFamily", family); } // @@ -76,15 +76,13 @@ let font_plugin = (function () { var sizeselect = $(""); + option.on("click", onSwitchLayout); + div.append(option); + + if( name !== "default" && name !== activeLayoutName ) { + var remove = $(""); + remove.on("click", onRemoveLayout); + div.append(remove); + } + + layoutDiv.append(div); + } + + + // + // + var onSaveLayout = function () { + // get the name from the select box + var name = $("#layoutName").val(); + var layouts = $("#goldenlayouts"); + + // make sure we have a valid name + if( name !== "" ) { + // Is this name new or pre-existing? + if( !evenniaGoldenLayouts.has(name) ) { + // this is a new name, so add a new UI item for it. + addLayoutUI( layouts, name ); + } + + // Force Close the Options Menu so that it isn't part of the saved layout. + window.plugins["options2"].onOpenCloseOptions(); + + // store the current layout to the local list of layouts + evenniaGoldenLayouts.set( name, myLayout.toConfig() ); + activeLayoutName = name; + activeLayoutModified = false; + + // store the newly requested layout into localStorage. + localStorage.setItem( "evenniaGoldenLayoutSavedState", JSON.stringify( evenniaGoldenLayouts.get(name) ) ); + localStorage.setItem( "evenniaGoldenLayoutSavedStateName", activeLayoutName ); + + // upload it to the server + if( window.Evennia.isConnected() && myLayout.isInitialised ) { + window.options["webclientActiveLayout"] = name; + window.options["webclientLayouts"] = JSON.stringify( evenniaGoldenLayouts ); + window.Evennia.msg("webclient_options", [], window.options); + } + + resetUI( evenniaGoldenLayouts.get(name) ); + } + } + + // // Public // @@ -615,7 +669,11 @@ let goldenlayout = (function () { var onGotOptions = function (args, kwargs) { // Reset the UI if the JSON layout sent from the server doesn't match the client's current JSON if( "webclientLayouts" in kwargs ) { - evenniaGoldenLayouts = JSON.parse( kwargs["webclientLayouts"] ); + let mapping = JSON.parse( kwargs["webclientLayouts"] ); + evenniaGoldenLayouts = new Map(); + for( var layout in mapping ) { + evenniaGoldenLayouts.set( layout, mapping[layout] ); + } } } @@ -623,33 +681,43 @@ let goldenlayout = (function () { // // var onOptionsUI = function (parentdiv) { - var layoutInput = $(""); - var saveButton = $(""); + var layoutName = $(""); + var saveButton = $(""); + var layoutDiv = $("
"); if( activeLayoutName === "default" ) { saveButton.prop( "disabled", true ); } - var layouts = Object.keys( evenniaGoldenLayouts ); - for (var x = 0; x < layouts.length; x++) { - var option = $(""); - layoutInput.append(option); + for (const name of evenniaGoldenLayouts.keys() ) { + addLayoutUI(layoutDiv, name); } - layoutInput.val( activeLayoutName ); // current selection + // currently active layout layoutName.val( activeLayoutName ); + layoutName.on("keydown", function (evnt) { + var name = $(evnt.target).val(); + if( name === "default" || name === "" ) { + saveButton.prop( "disabled", true ); + } else { + saveButton.prop( "disabled", false ); + } + }); // Layout selection on-change callback - layoutInput.on('change', onSwitchLayout); - saveButton.on('click', onSaveLayout); + saveButton.on("click", onSaveLayout); + + var saveDiv = $("
"); + saveDiv.append(layoutName); + saveDiv.append(saveButton); // add the selection dialog control to our parentdiv - parentdiv.addClass("goldenlayout-ui"); - parentdiv.append("
UI Layout Selection (This list may be longer after login):
"); - parentdiv.append(layoutInput); - parentdiv.append(layoutName); - parentdiv.append(saveButton); + parentdiv.addClass("goldenlayout-options-ui"); + parentdiv.append("
GoldenLayout Options:
"); + parentdiv.append("
Activate a new layout:
"); + parentdiv.append(layoutDiv); + parentdiv.append("
Save current layout as (best if used when logged in):
"); + parentdiv.append(saveDiv); } @@ -697,8 +765,7 @@ let goldenlayout = (function () { var mainsub = document.getElementById("main-sub"); // pre-load the evenniaGoldenLayouts with the hard-coded default - Object.assign( evenniaGoldenLayouts, { "default" : window.goldenlayout_config } ); - Object.assign( evenniaGoldenLayouts, { "default-modified" : window.goldenlayout_config } ); + evenniaGoldenLayouts.set( "default", window.goldenlayout_config ); if( activeName !== null ) { activeLayoutName = activeName; @@ -708,13 +775,13 @@ let goldenlayout = (function () { // Overwrite the global-variable configuration from // webclient/js/plugins/goldenlayout_default_config.js // with the version from localstorage - evenniaGoldenLayouts[activeLayoutName] = JSON.parse(savedState); + evenniaGoldenLayouts.set( activeLayoutName, JSON.parse(savedState) ); } else { localStorage.setItem( "evenniaGoldenLayoutSavedState", JSON.stringify( window.goldenlayout_config ) ); - localStorage.setItem( "evenniaGoldenLayoutSavedStateName", "default-modified" ); + localStorage.setItem( "evenniaGoldenLayoutSavedStateName", "default" ); } - myLayout = new window.GoldenLayout( evenniaGoldenLayouts[activeLayoutName], mainsub ); + myLayout = new window.GoldenLayout( evenniaGoldenLayouts.get(activeLayoutName), mainsub ); $("#prompt").remove(); // remove the HTML-defined prompt div $("#inputcontrol").remove(); // remove the cluttered, HTML-defined input divs diff --git a/evennia/web/webclient/static/webclient/js/plugins/options2.js b/evennia/web/webclient/static/webclient/js/plugins/options2.js index 01eba285c8..24acd4b314 100644 --- a/evennia/web/webclient/static/webclient/js/plugins/options2.js +++ b/evennia/web/webclient/static/webclient/js/plugins/options2.js @@ -183,6 +183,7 @@ let options2 = (function () { onOptionsUI: onOptionsUI, onPrompt: onPrompt, onOptionCheckboxChanged: onOptionCheckboxChanged, + onOpenCloseOptions: onOpenCloseOptions, } })(); window.plugin_handler.add("options2", options2);