Skip to content

Commit

Permalink
Fix broken options button
Browse files Browse the repository at this point in the history
  • Loading branch information
sergystepanov committed Mar 16, 2024
1 parent 29eedee commit 47bd72e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 34 deletions.
6 changes: 3 additions & 3 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@

<script src="js/gui/gui.js?v=3"></script>
<script src="js/utils.js?v1"></script>
<script src="js/gui/message.js?v=3"></script>
<script src="js/gui/message.js?v=4"></script>
<script src="js/log.js?v=5"></script>
<script src="js/event/event.js?v=6"></script>
<script src="js/input/keys.js?v=3"></script>
<script src="js/settings/opts.js?v=3"></script>
<script src="js/settings/settings.js?v=7"></script>
<script src="js/settings/settings.js?v=8"></script>
<script src="js/env.js?v=6"></script>
<script src="js/input/input.js?v=3"></script>
<script src="js/gameList.js?v=5"></script>
Expand All @@ -122,7 +122,7 @@
<script src="js/api/api.js?v=3"></script>
<script src="js/workerManager.js?v=1"></script>
<script src="js/stats/stats.js?v=1"></script>
<script src="js/controller.js?v=12"></script>
<script src="js/controller.js?v=13"></script>
<script src="js/input/keyboard.js?v=6"></script>
<script src="js/input/touch.js?v=3"></script>
<script src="js/input/joystick.js?v=3"></script>
Expand Down
9 changes: 4 additions & 5 deletions web/js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,10 @@
..._default,
_uber: true,
name: 'settings',
keyRelease: key => {
if (key === KEY.SETTINGS) {
!settings.ui.toggle() && setState(lastState)
}
},
keyRelease: (() => {
settings.ui.onToggle = (o) => !o && setState(lastState);
return (key) => key === KEY.SETTINGS && settings.ui.toggle()
})(),
menuReady: showMenuScreen
},

Expand Down
30 changes: 16 additions & 14 deletions web/js/gui/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,18 @@ const gui = (() => {

const panel = (root, title = '', cc = '', content, buttons = [], onToggle) => {
const state = {
br: null,
shown: false,
loading: false,
title: title,
}

const tHandlers = [];
onToggle && tHandlers.push(onToggle);

const _root = root || _create('div');
_root.classList.add('panel');
gui.hide(_root);

const header = _create('div', (el) => el.classList.add('panel__header'));
const _content = _create('div', (el) => {
if (cc) {
Expand Down Expand Up @@ -131,23 +135,21 @@ const gui = (() => {
_title.innerText = state.loading ? `${state.title}...` : state.title;
}

function toggle(show = true) {
state.shown = show;

// hack not transparent jpeg corners :_;
show ? _root.parentElement.style.borderRadius = '0px' :
state.br ? _root.parentElement.style.borderRadius = state.br :
state.br = window.getComputedStyle(_root.parentElement).borderRadius

onToggle && onToggle(state.shown, _root)

state.shown ? gui.show(_root) : gui.hide(_root)
return state.shown;
}
const toggle = (() => {
let br = window.getComputedStyle(_root.parentElement).borderRadius;
return (force) => {
state.shown = force !== undefined ? force : !state.shown;
// hack for not transparent jpeg corners :_;
_root.parentElement.style.borderRadius = state.shown ? '0px' : br;
tHandlers.forEach(h => h?.(state.shown, _root));
state.shown ? gui.show(_root) : gui.hide(_root)
}
})()

return {
contentEl: _content,
isHidden: () => !state.shown,
onToggle: (fn) => tHandlers.push(fn),
setContent,
setLoad,
toggle,
Expand Down
17 changes: 5 additions & 12 deletions web/js/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,6 @@ const settings = (() => {
event.pub(KEYBOARD_TOGGLE_FILTER_MODE, {mode: true});
})

panel.toggle(false);

const toggle = (() => {
let x = false;
return () => {
x = !x;
panel.toggle(x);
}
})();

function _getType(value) {
if (value === undefined) return option.undefined
else if (Array.isArray(value)) return option.list
Expand Down Expand Up @@ -334,7 +324,10 @@ const settings = (() => {
import: _import,
export: _export,
ui: {
toggle,
set onToggle(fn) {
panel.onToggle(fn);
},
toggle: () => panel.toggle(),
},
set renderer(fn) {
_renderer = fn;
Expand Down Expand Up @@ -501,7 +494,7 @@ settings.renderer = (() => {
.withDescription(
'Whether games should open in full-screen mode after starting up (excluding mobile devices)'
)
.add(gui.checkbox(k, onChange, value, 'Enbabled', 'settings__option-checkbox'))
.add(gui.checkbox(k, onChange, value, 'Enabled', 'settings__option-checkbox'))
.build()
break;
default:
Expand Down

0 comments on commit 47bd72e

Please sign in to comment.