allow dark mode changes to be immediate and not require page reload

This commit is contained in:
Stewart Allen 2020-07-08 15:36:46 -04:00
commit c4bee0b762
3 changed files with 20 additions and 11 deletions

View file

@ -88,7 +88,6 @@
function booleanSave() {
let control = settings().controller;
let isDark = control.dark;
let isReload = false;
control.expert = UI.expert.checked;
control.showOrigin = UI.showOrigin.checked;
control.autoLayout = UI.autoLayout.checked;
@ -104,14 +103,8 @@
platform.layout();
platform.update_stock();
API.conf.save();
// if dark mode changed, reload UI
if (isDark !== control.dark) {
isReload = true;
}
API.mode.set_expert(control.expert);
if (isReload) {
API.space.reload();
}
API.platform.update_size();
}
function onLayerToggle() {

View file

@ -1017,10 +1017,12 @@
if (ctrl.dark) {
SPACE.platform.setGrid(gridMajor, gridMinor, 0x999999, 0x333333);
SPACE.platform.opacity(0.8);
SPACE.setSkyColor(0);
DOC.body.classList.add('dark');
} else {
SPACE.platform.setGrid(gridMajor, gridMinor, 0x999999, 0xcccccc);
SPACE.platform.opacity(0.3);
SPACE.setSkyColor(0xffffff);
DOC.body.classList.remove('dark');
}
SPACE.platform.setGZOff(height/2 - 0.1);

View file

@ -29,6 +29,8 @@
alignedTracking = false,
skyColor = 0xbbbbbb,
skyGridColor = 0xcccccc,
skyMaterial = undefined,
skyGridMaterial = undefined,
showSkyGrid = true,
showPlatform = true,
hidePlatformBelow = true,
@ -581,9 +583,19 @@
update: requestRefresh,
refresh: refresh,
showSkyGrid: function(b) { showSkyGrid = b },
setSkyColor: function(c) { skyColor = c },
setSkyGridColor: function(c) { skyGridColor = c },
showSkyGrid: function(b) {
showSkyGrid = b;
},
setSkyColor: function(c) {
skyColor = c;
if (skyMaterial) skyMaterial.color = new THREE.Color(c);
},
setSkyGridColor: function(c) {
skyGridColor = c;
if (skyGridMaterial) skyGridMaterial.color = new THREE.Color(c);
},
scene: {
add: function (o) {
@ -752,10 +764,12 @@
let sky = new THREE.Mesh(
new THREE.BoxGeometry(50000, 50000, 50000, 1, 1, 1),
skyMaterial =
new THREE.MeshBasicMaterial({ color: skyColor, side: THREE.DoubleSide })
),
skygrid = new THREE.Mesh(
new THREE.BoxGeometry(5000, 5000, 5000, 10, 10, 10),
skyGridMaterial =
new THREE.MeshBasicMaterial({ color: skyGridColor, side: THREE.DoubleSide })
);