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

View file

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

View file

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