diff --git a/scripts/menu.js b/scripts/menu.js index eb7ca28..abdf1b8 100644 --- a/scripts/menu.js +++ b/scripts/menu.js @@ -1,447 +1,456 @@ /* * 3DCycles - A lightcycle game. * Copyright (C) 2019 Glen Harpring * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //change setting via keyboard (menuselect left or right) function changeMenuItem(name,add,wrap=false,from=false,ref=false) { var actmenu = document.getElementsByClassName("menu-active")[0]; var actsp = name.split(":"); //console.log(actsp); if(actsp[0] == "list") { var elem = actmenu.children[0].children[1]; var keys = Object.keys(elem.options); var elempos = -1; for(i=0;i= keys.length) if(wrap) elempos = 0; else elempos = keys.length-1; if(elempos < 0) if(wrap) elempos = key.length-1; else elempos = 0; elem.innerHTML = replaceColors(elem.options[keys[elempos]]); elem.call(keys[elempos]); } else if(actsp[2] == "num") { var elem = actmenu.children[0].children[1]; var value = parseFloat(elem.innerText); if(from != "key:enter") value += add*actmenu.add; if(value > actmenu.max) if(wrap) value = actmenu.min; else value = actmenu.max; if(value < actmenu.min) if(wrap) value = actmenu.max; else value = actmenu.min; elem.innerText = value; chsetting(actsp[1],value); } } //MENU SELECT //keyboard function menuSelect(direction) { //detect menu //if (from != 'menu-about') {//if its a screen that has a menu with options var themenu = document.getElementById('menuList').childNodes; //detect menu position var selectedItem = -1; for(var x=0;x= themenu.length) selectedItem = 0; //wrap to first item hoverSelect(themenu[selectedItem]); break; case "esc": //Exit Menu should be the last item, so convenient hack selectedItem = themenu.length-1; //[[FALLTHROUGH]] case "enter": document.activeElement.blur();//remove focus from any clicked menu items menu(themenu[selectedItem].id,"key:"+direction); break; //adjust setting - used to change a setting from current value, up or down some, whatever it is case "left": changeMenuItem(themenu[selectedItem].id,-1,false,"key:"+direction); break; case "right": changeMenuItem(themenu[selectedItem].id,1,false,"key:"+direction); break; } } function menuFindPrevSelectable() { var themenu = document.getElementById('menuList').childNodes; var selectedItem = -1; for(var x=themenu.length-1;x>=0;x--) { if(selectedItem >= 0 && themenu[x].href) { return x; } if(hasClass(themenu[x],'menu-active')) selectedItem = x; //find which one is selected } return themenu.length-1; } function menuFindNextSelectable() { var themenu = document.getElementById('menuList').childNodes; var selectedItem = -1; for(var x=0;x= 0 && themenu[x].href) { return x; } if(hasClass(themenu[x],'menu-active')) selectedItem = x; //find which one is selected } return 0; } function hoverSelect(item) { var themenu = document.getElementById('menuList').childNodes; for(var x=0;x 0) { var menus = doc[0].getElementsByTagName("Menu"); for(var x=0;x"; var items = cmenu.getElementsByTagName("Item"); var list = document.createElement("UL"); list.setAttribute("id","menuList"); for(var i=0;i