diff --git a/DS.css b/DS.css new file mode 100644 index 0000000..52d60ab --- /dev/null +++ b/DS.css @@ -0,0 +1,301 @@ +body { + background-color: darkslateblue; +} + +.button { + border:1px solid rgba(50,50,50,1); + width:25px; + height:25px; + border-radius:13px; + display:inline-block; + background: rgba(70,70,70,1); + padding:0px; + margin:px; + text-align:center; + vertical-align:middle; + font-weight: bold; + position:absolute; + text-shadow: 1px 1px 1px rgba(0,0,0,0.25), 0px 1px 1px rgba(0,0,0,0.25), 1px 0px 1px rgba(0,0,0,0.25); +} + +.button_4, .button_5, .button_6, .button_7 { + width:35px; + height:20px; + border-radius:8px; +} + +.button_8 { + width:30px; + height:15px; + border-radius:4px; +} + +.button_9 { + border:0px; + background:transparent; +} + + +.button::after { + position:relative; + color: rgba(250,250,250,1); + font-size:13px; + font-family: Arial; +} + +.button_0::after { + display: block; + content:"✕"; + color: rgba(80,120,200,1); + font-size:22px; + top:-4px; + left: 0px; +} + +.button_1::after { + display: block; + content:"○"; + color: rgba(200,120,80,1); + font-size:41px; + top:-14px; + left: 0px; +} + +.button_2::after { + display: block; + content:"□"; /*square*/ + color: rgba(250,80,80,1); + font-size:35px; + top:-10px; + left: 0px; +} + +.button_3::after { + display: block; + content:"△";/*triangle*/ + color: rgba(60,200,100,1); + font-size:23px; + top:-2px; + left: 0px; +} + +.button_4::after { + display: block; + position: relative; + content:"L1"; + left:0px; + top:0px; +} + +.button_5::after { + display: block; + position: relative; + content:"R1"; + left:0px; + top:0px; +} + +.button_6::after { + display: block; + position: relative; + content:"L2"; + left:0px; + top:0px; +} + +.button_7::after { + display: block; + content:"R2"; + left:0px; + top:0px; +} + +.button_10::after { + display: block; + content:"L3"; + position: relative; + top:2px; + left:0px; +} + +.button_11::after { + display: block; + position: relative; + content:"R3"; + top:2px; + left:0px; +} + +#button_9_border { + display: block; + position:relative; + top:3px; +} + +.button_12, .button_13, .button_14, .button_15 { + border:0px; + background:transparent; + height:25px; + width:25px; + } + +.button_12 { + left:46px; + top:14px; +} +.button_13 { + left:46px; + top:63px; +} + +.button_14 { + left:21px; + top:39px; +} +.button_15 { + left:70px; + top:39px; +} + +.button_16 { + display: none; + left:140px; + top:10px; +} + +.button_3 { + left:226px; + top:12px; +} +.button_0 { + left:226px; + top:61px; +} + +.button_2 { + left:201px; + top:37px; +} +.button_1 { + left:250px; + top:37px; +} + +.button_4 { + left:2px; + top: 1px; +} +.button_6 { + left:80px; + top: 1px; +} + +.button_5 { + left:260px; + top: 1px; + +} +.button_7 { + left:182px; + top: 1px; +} + +.button_8 { + left:111px; + top:42px; + transform: none; +} + +.button_9 { + left:161px; + top:37px; + transform: none; + background-color: transparent; + +} + +.button_10 { + position:relative; + border:1px solid rgba(250,200,150,1); +} + +.button_11 { + position:relative; + border:1px solid rgba(250,200,150,1); +} + + +#buttons { + position:absolute; + background-image: none; +} + +#style_select { + position:absolute; + left: 410px; +} + + +.axisbox { + border-radius:20px; + border:1px solid red; + width:40px; + height:40px; + position:absolute; + top: 65px; + border:1px solid rgba(50,50,50,1); + background: rgba(70,70,70,0.5); + display:block; +} + +.axisbox_0 { + left:105px; + display:block; +} + +.axisbox_1 { + left:155px; + display:block; +} + +.axis{ + margin-left:-5px; + margin-top:-5px; + border-radius:5px; + border:1px solid black; + width:10px; + height:10px; + display:block; + position:relative; +} + + + +#controller_SNES { + display: none; + visibility: hidden; + position: absolute; + width:400px; + height:400px; +} + +#controller_DS { + display: none; + position: absolute; + width:400px; + height:400px; +} + +#controller_NES { + display: none; + position: absolute; + width:400px; + height:400px; +} + +#controller_XBOX { + display: none; + position: absolute; + width:400px; + height:400px; +} \ No newline at end of file diff --git a/NES.css b/NES.css new file mode 100644 index 0000000..1f76e6f --- /dev/null +++ b/NES.css @@ -0,0 +1,265 @@ +body { + background-color: brown; +} + +.button { + border:1px solid rgba(50,50,50,1); + width:31px; + height:31px; + border-radius:20px; + display:inline-block; + background: rgba(70,70,70,1); + padding:0px; + margin:px; + text-align:center; + vertical-align:middle; + font-weight: bold; + position:absolute; + text-shadow: 1px 1px 1px rgba(0,0,0,0.25), 0px 1px 1px rgba(0,0,0,0.25), 1px 0px 1px rgba(0,0,0,0.25); +} + +.button_4, .button_5, .button_6, .button_7 { + width:35px; + height:20px; + border-radius:8px; +} + +.button_8 { + width:30px; + height:15px; + border-radius:4px; +} + + + +.button::after { + position:relative; + color: rgba(250,250,250,1); + font-size:13px; + font-family: Arial; +} + +.button_0::after { + display: none; + content:"A"; + color: rgba(250,250,250,0.5); + font-size:10px; + top:34px; + left:16px; +} + +.button_1::after { + display: none; + content:"○"; + color: rgba(220,120,80,1); + font-size:35px; + top:-14px; +} + +.button_2::after { + display: none; + content:"B"; /*square*/ + color: rgba(250,250,250,0.5); + font-size:10px; + top:34px; + left:16px; +} + +.button_3::after { + display: none; + content:"△";/*triangle*/ + color: rgba(60,200,100,1); + font-size:23px; + top:-2px; +} + +.button_4::after { + display: none; + content:"L1"; +} + +.button_5::after { + display: none; + content:"R1"; +} + +.button_6::after { + display: none; + content:"L2"; +} + +.button_7::after { + display: none; + content:"R2"; +} + +.button_10::after { + display: none; + content:"L3"; + top:2px; +} + +.button_11::after { + display: none; + content:"R3"; + top:2px; +} + + +.button_12, .button_13, .button_14, .button_15 { + border:0px; + background:transparent; + height:25px; + width:25px; + } + +.button_12 { + left:57px; + top:180px; +} +.button_13 { + left:48px; + top:222px; +} + +.button_14 { + left:30px; + top:198px; +} +.button_15 { + left:74px; + top:206px; +} + +.button_16 { + display: none; + left:0px; + top:0px; +} + +.button_3 { + display: none; + left:264px; + top:218px; +} +.button_0 { + display: block; + left:316px; + top:218px; +} + +.button_2 { + display: block; + left:264px; + top:218px; +} + +.button_1 { + display: none; + left:226px; + top:12px; +} + +.button_4 { + display: none; + left:2px; + top: 1px; +} +.button_6 { + display: none; + left:80px; + top: 1px; +} + +.button_5 { + display: none; + left:260px; + top: 1px; + +} +.button_7 { + display: none; + left:182px; + top: 1px; +} + +.button_8 { + width:30px; + height:10px; + border-radius:4px; + left:140px; + top:230px; + background-color: rgba(30,30,30,1); + transform: none; +} + +.button_9 { + width:30px; + height:10px; + border-radius:4px; + left:194px; + top:230px; + background-color: rgba(300,30,30,1); + transform: none; +} + +.button_10 { + display: none; + position:relative; + border:1px solid rgba(250,200,150,1); +} + +.button_11 { + display: none; + position:relative; + border:1px solid rgba(250,200,150,1); +} + + +#buttons { + position:absolute; + width: 400px ; + height: 400px ; + background-image: none; +} + +#style_select { + position:absolute; + left: 410px; +} + +.axisbox { + display:none; + } + + .axisbox_0 { + display:none; + } + + .axisbox_1 { + display:none; + } + + .axis{ + display:none; + } + + +#controller_SNES { + display: none; +} + +#controller_DS { + display: none; +} + +#controller_NES { + display: block; + position: absolute; + width:400px; + height:400px; +} + +#controller_XBOX { + display: none; +} \ No newline at end of file diff --git a/README.md b/README.md index 2c67ac6..7ac72a2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,25 @@ # JS-DualShock3-Monitor -Pure javascript-driven gamepad monitor (styled for Dualshock 3) -![screenshot](Screenshot_2020-01-19%20Screenshot.png) +Pure javascript-driven gamepad monitor (styled for Dualshock 3, NES, SNES, XBox 360) + +Built to be used in OBS an an overlay. +That means the controller will be semi-transparent. +Compatible with any XInput device (xbox controllers, Mayflash Magic adapters in XInput mode, etc) + +## How to use + +- Add a browser source +- Set page size to 500x400 +- Tick the "Local File" box +- Click "Browse" and select the index.html from this repo +- Tick the "Shutdown source when not visible" box +- Tick the "Refresh browser when scene becomes active" box +- Make suse the browser source has `body { background-color: rgba(0, 0, 0, 0); margin: 0px auto; overflow: hidden; }` in the `Custom CSS` field + +### To change styles: +- Right click your browser source +- Pick the "Ineteract" options +- Click on dropdown list utill it's open. Note that you won't see any actual items, instead there will be thick border inside the list ![looks like this](dropdown.png) +- Use up/down arrows to chose the desired style + +![screenshot](Screenshot.png) diff --git a/SNES.css b/SNES.css new file mode 100644 index 0000000..a87af74 --- /dev/null +++ b/SNES.css @@ -0,0 +1,235 @@ +body { + background-color: darkcyan; +} + +.button { + border:1px solid rgba(0,0,0,1); + width:26px; + height:26px; + border-radius:13px; + display:inline-block; + background: rgba(70,70,70,1); + padding:0px; + margin:px; + text-align:center; + vertical-align:middle; + font-weight: bold; + position:absolute; + text-shadow: 1px 1px 1px rgba(0,0,0,0.25), 0px 1px 1px rgba(0,0,0,0.25), 1px 0px 1px rgba(0,0,0,0.25); +} + +.button_4, .button_5, .button_6, .button_7 { + width:55px; + height:5px; + border-radius: 8px 8px 0px 0px; +} + + + + +.button::after { + position:relative; + color: rgba(250,250,250,1); + font-size:13px; + font-family: Arial; +} + +.button_0::after { + display: block; + content:"B"; + color: rgb(188, 200, 80); + font-size:22px; + top:0px; + left:0px; +} + +.button_1::after { + display: block; + content:"A"; + color: rgba(250,80,80,1); + font-size:22px; + top:0px; + left:0px; +} + +.button_2::after { + display: block; + content:"Y"; /*square*/ + color: rgba(60,200,100,1); + font-size:22px; + top:0px; + left:0px; +} + +.button_3::after { + display: block; + content:"X";/*triangle*/ + color: rgba(80,120,200,1); + font-size:22px; + top:0px; + left:0px; +} + +.button_4::after { + content:""; +} + +.button_5::after { + content:""; +} + + +#button_9_border { + position:relative; + top:3px; +} + +.button_12, .button_13, .button_14, .button_15 { + border:0px; + background:transparent; + height:25px; + width:25px; + } + +.button_12 { + left:75px; + top:170px; +} +.button_13 { + left:73px; + top:207px; +} + +.button_14 { + left:55px; + top:188px; +} +.button_15 { + left:94px; + top:190px; +} + +.button_16 { + display: none; + left:0px; + top:0px; +} + +.button_3 { + display: block; + left:296px; + top:156px; +} +.button_0 { + display: block; + left:296px; + top:214px; +} + +.button_2 { + display: block; + left:259px; + top:185px; +} +.button_1 { + display: block; + left:332px; + top:185px; +} + +.button_4 { + left:83px; + top: 113px; +} + +.button_5 { + left:266px; + top: 113px; + +} + +.button_6 { + display: none; +} + +.button_7 { + display: none; +} + +.button_8 { + width:30px; + height:8px; + border-radius:4px; + left:147px; + top:206px; + transform: rotate(-37deg); +} + +.button_9 { + width:30px; + height:8px; + border-radius:4px; + left:189px; + top:206px; + transform: rotate(-37deg); +} + + + +#buttons { + position:absolute; + width: 400px ; + height: 400px ; + background-image: none; +} + +#style_select { + position:absolute; + left: 410px; +} + +.axisbox { + display:none; +} + + .axisbox_0 { + display:none; +} + + .axisbox_1 { + position:absolute; + } + + .axis{ + display:none; + } + + +#controller_SNES { + display: block; + visibility: visible; + position: absolute; + width:400px; + height:400px; +} + +#controller_DS { + display: none; + position: absolute; + width:400px; + height:400px; +} + +#controller_NES { + display: none; + position: absolute; + width:400px; + height:400px; +} + +#controller_XBOX { + display: none; + position: absolute; + width:400px; + height:400px; +} \ No newline at end of file diff --git a/Screenshot.png b/Screenshot.png new file mode 100644 index 0000000..caf7e2e Binary files /dev/null and b/Screenshot.png differ diff --git a/Screenshot_2020-01-19 Screenshot.png b/Screenshot_2020-01-19 Screenshot.png deleted file mode 100644 index 0bb5365..0000000 Binary files a/Screenshot_2020-01-19 Screenshot.png and /dev/null differ diff --git a/Xbox.css b/Xbox.css new file mode 100644 index 0000000..a07fc04 --- /dev/null +++ b/Xbox.css @@ -0,0 +1,303 @@ +body { + background-color: darkgreen; +} + +.button { + width:25px; + height:25px; + + display:inline-block; + border: none; + padding:0px; + margin:px; + text-align:center; + vertical-align:middle; + font-weight: bold; + position:absolute; + text-shadow: 1px 1px 1px rgba(0,0,0,0.25), 0px 1px 1px rgba(0,0,0,0.25), 1px 0px 1px rgba(0,0,0,0.25); + font-family: Arial; + +} + +.button_4, .button_5, .button_6, .button_7 { + width:35px; + height:20px; + border-radius:8px; +} + +.button_8 { + width:30px; + height:15px; + border-radius:4px; + display:block; +} + +.button_9 { + border:0px; + background:transparent; + display:block; +} + + +.button::after { + display: block; + position:relative; + color: rgba(250,250,250,0.7); + font-size:12px; +} + +.button_0::after { + left: 305px; + top: 217px; + position: absolute; + content:"A"; + color: rgba(80,120,200,0.7); + font-size:12px; + + display: block; +} + +.button_1::after { + left: 336px; + top: 192px; + position: absolute; + content:"B"; + color: rgba(200,120,80,0.7); + + display: block; +} + +.button_2::after { + left: 277px; + top: 194px; + position: absolute; + content:"X"; /*square*/ + color: rgba(250,80,80,0.7); + display: block; +} + +.button_3::after { + left: 308px; + top: 168px; + position: absolute; + content:"Y";/*triangle*/ + color: rgba(60,200,100,0.7); + display:block; +} + +.button_4::after { + left: 75px; + top: 120px; + position: relative; + content:"LB"; + display:block; +} + +.button_5::after { + left: 289px; + top: 120px; + position: relative; + content:"RB"; + display:block; +} + +.button_6::after { + left: 81px; + top: 92px; + position: relative; + content:"LT"; + display:block; +} + +.button_7::after { + left: 285px; + top: 92px; + position: relative; + content:"RT"; + display:block; +} + +.button_10::after { + content:"L3"; + top:204px; + left:76px; + display:block; +} + +.button_11::after { + content:"R3"; + top:260px; + left:238px; + display:block; +} + +#button_9_border { + position:relative; + top:3px; + display:none; +} + +.button_12, .button_13, .button_14, .button_15 { + border:0px; + background:transparent; + height:25px; + width:25px; + } + +.button_16 { + display: block; + left:0px; + top:0px; +} +.button_12 { + left:0px; + top:0px; +} +.button_13 { + left:0px; + top:0px; +} + +.button_14 { + left:0px; + top:0px; +} +.button_15 { + left:0px; + top:0px; +} + +.button_3 { + left:0px; + top:0px; +} +.button_0 { + left:0px; + top:0px; +} + +.button_2 { + left:0px; + top:0px; +} +.button_1 { + left:0px; + top:0px; +} + +.button_4 { + left:0px; + top:0px; +} +.button_6 { + left:0px; + top:0px; +} + +.button_5 { + left:0px; + top:0px; + +} +.button_7 { + left:0px; + top:0px; +} + +.button_8 { + left:0px; + top:0px; + border: none; + transform: none; +} + +.button_9 { + left:0px; + top:0px; + border: none; + transform: none; +} + +.button_10 { + position:absolute; + top:0px; + left:0px; + border: none; + transform: none; +} + +.button_11 { + position:absolute; + top:0px; + left:0px; + border: none; + transform: none; +} + + +#buttons { + position:absolute; + width: 400px ; + height: 400px ; + background-image: none; +} + +#style_select { + position:absolute; + left: 410px; +} + +.axisbox { + display:none; +} + +.axisbox_0 { + position:absolute; + top:0px; + left:0px; + border: none; + display:block; + background: none; +} + +.axisbox_1 { + position:absolute; + top:0px; + left:0px; + border: none; + display:block; + background: none; +} + +.axis{ + display:none; +} + + +#controller_SNES { + display: none; + position: absolute; + width:400px; + height:400px; +} + +#controller_DS { + display: none; + position: absolute; + width:400px; + height:400px; +} + +#controller_NES { + display: none; + position: absolute; + width:400px; + height:400px; +} + +#controller_XBOX { + display: block; + position: absolute; + width:400px; + height:400px; +} diff --git a/dropdown.png b/dropdown.png new file mode 100644 index 0000000..8845094 Binary files /dev/null and b/dropdown.png differ diff --git a/gpcon.js b/gpcon.js index d20ec49..55fc9f8 100644 --- a/gpcon.js +++ b/gpcon.js @@ -20,7 +20,49 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - + +let current_style = localStorage.getItem("gpcon_style") || "DS" + +// called upon page loading +function prep() { + + // gets style select element that controls the stylesheets + let style_select = document.getElementById("style_select") + style_select.addEventListener("change", style_change) + + // this changes style by deleting an old element and creating a new one + function style_change(event) { + let head = document.getElementsByTagName( "head" )[0] + + for (let child of head.children) { + if (child.tagName == "LINK") { + delete child + } + } + + let link = document.createElement('link') + link.href = style_select.value + ".css" + link.rel = "stylesheet" + head.appendChild(link) + current_style = style_select.value + localStorage.setItem("gpcon_style",style_select.value) // remember to save selected style + console.log(link) + } + + // this loads last selected style or deaults to DS one + for (let idx in style_select.options) { + if (style_select[idx].value == current_style) { + style_select.selectedIndex = idx + style_change() + break + } + } + +} + + + + let buttons = []; // remembers if button was added let axes = []; // remembers if axis was added (separate X and Y values) let axes_c = []; // remembers if axis box was added (combines X and Y of one stick) @@ -52,7 +94,7 @@ function onFrame() { // gets repeatedly executed let buttdiv = document.getElementById('buttons') // so, we get our container element (see index.html) and add 'buttons' to it for (j = 0; j < gp.buttons.length; j++) { // we cycle through all detected buttons and add those to a 'buttons' array if (typeof buttons[j] === "undefined") { // if jth button isn't added yet, we will do just that - if (j>15) {continue;} // just be sure to skip weird non-existing buttons on your gamepad (PS3 Dualshock here) + if (j>16) {continue;} // just be sure to skip weird non-existing buttons on your gamepad (PS3 Dualshock here) if (j==l_stick || j==r_stick) continue; // we also need to skip sticks to add those later (if your gamepad doesn't have 'pressable' sticks - comment this line) let buttEle = document.createElement('span'); // create a new element (a button) @@ -67,44 +109,368 @@ function onFrame() { // gets repeatedly executed let buttEle = document.getElementById('button_'+j); // we get correnponding element in our HTML document let val = gp.buttons[j].value; // val keeps the value browser got from jth button (can be 0, 1 or smth in-between for analogue buttons) if (gp.buttons[j].pressed) { // if current button is pressed we can alter it's style - if (j==9) { // the 'start' button (as well as any other non-round-shaped button) has to have it's innerHTML rewritten - buttEle.innerHTML = ''; + if (j==8) { + if (current_style == "DS") { + buttEle.style.background='rgba(255,255,255,0.5)'; + buttEle.innerHTML = "" + } else if (current_style == "SNES") { + buttEle.style.background='rgba(255,255,255,0.5)'; + buttEle.innerHTML = "" + } else if (current_style == "NES") { + buttEle.style.background='rgba(255,255,255,0.5)'; + buttEle.innerHTML = "" + } else if (current_style == "XBOX") { + buttEle.style.background='rgba(255,255,255,0)'; + buttEle.innerHTML = ''; + } + } else if (j==9) { // the 'start' button (as well as any other non-round-shaped button) has to have it's innerHTML rewritten + if (current_style == "DS") { + buttEle.innerHTML = ''; + } else if (current_style == "SNES") { + buttEle.style.background='rgba(255,255,255,0.5)'; + buttEle.innerHTML = "" + } else if (current_style == "NES") { + buttEle.style.background='rgba(255,255,255,0.5)'; + buttEle.innerHTML = "" + } else if (current_style == "XBOX") { + buttEle.style.background='rgba(255,255,255,0)'; + buttEle.innerHTML = ''; + } } else { // sure, this could've been coded better, but what the heck, it works if (j<=11) { // buttons with id lower that 12 are usually the round-shaped ones; on-stick buttons go here as well buttEle.style.background='linear-gradient(to top, rgba(255,255,255,0.5) '+val*100+'%, rgba(170,70,70,0.5) '+val*100+'%)';// gradient really helps to visualize partial presses - } - if (j>=12) {// up - buttEle.innerHTML = ''; + buttEle.innerHTML = "" + if (j==0) { + if (current_style == "XBOX") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + if (j==1) { + if (current_style == "XBOX") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + if (j==2) { + if (current_style == "XBOX") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + if (j==3) { + if (current_style == "XBOX") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + if (j==4) {//L1 + if (current_style == "DS") { + buttEle.innerHTML = ''; + } else if (current_style == "XBOX") { + + buttEle.style.background='rgba(255,25,55,0)'; + //buttEle.innerHTML = '' + buttEle.innerHTML = '' + } + } + if (j==6) {//L2 + if (current_style == "DS") { + buttEle.innerHTML = ''; + } else if (current_style == "XBOX") { + + buttEle.style.background='rgba(255,25,55,0)'; + //buttEle.innerHTML = '' + buttEle.innerHTML = '' + } + } + if (j==5) {//R1 + if (current_style == "DS") { + buttEle.innerHTML = ''; + } else if (current_style == "XBOX") { + + buttEle.style.background='rgba(255,25,55,0)'; + //buttEle.innerHTML = '' + buttEle.innerHTML = '' + } + } + if (j==7) {//R2 + if (current_style == "DS") { + buttEle.innerHTML = ''; + } else if (current_style == "XBOX") { + + buttEle.style.background='rgba(255,25,55,0)'; + //buttEle.innerHTML = '' + buttEle.innerHTML = '' + } + } + if (j==10) {//L3 + if (current_style == "DS") { + buttEle.innerHTML = ''; + } else if (current_style == "XBOX") { + + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + if (j==11) {//R3 + if (current_style == "DS") { + buttEle.innerHTML = ''; + } else if (current_style == "XBOX") { + + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } } - if (j==13) {// down - buttEle.innerHTML = ''; - } - if (j==14) {// left - buttEle.innerHTML = ''; - } - if (j==15) {// right - buttEle.innerHTML = ''; + if (current_style == "DS") { + if (j==12) {// up + buttEle.innerHTML = ''; + } + if (j==13) {// down + buttEle.innerHTML = ''; + } + if (j==14) {// left + buttEle.innerHTML = ''; + } + if (j==15) {// right + buttEle.innerHTML = ''; + } + } else if (current_style == "SNES") { + if (j==12) {// up + buttEle.innerHTML = ''; + } + if (j==13) {// down + buttEle.innerHTML = ''; + } + if (j==14) {// left + buttEle.innerHTML = ''; + } + if (j==15) {// right + buttEle.innerHTML = ''; + } + } else if (current_style == "NES") { + if (j==12) {// up + buttEle.innerHTML = ''; + } + if (j==13) {// down + buttEle.innerHTML = ''; + } + if (j==14) {// left + buttEle.innerHTML = ''; + } + if (j==15) {// right + buttEle.innerHTML = ''; + } + } else if (current_style == "XBOX") { + if (j==12) {// up + buttEle.innerHTML = ''; + } + if (j==13) {// down + buttEle.innerHTML = ''; + } + if (j==14) {// left + buttEle.innerHTML = ''; + } + if (j==15) {// right + buttEle.innerHTML = ''; + } + if (j==16) {//home + if (current_style == "XBOX") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } } } } else { // if current button is *not* pressed we should revert it's style - if (j==9) {// once again, the 'start' button needs special attention - buttEle.innerHTML = ''; - } else { - if (j<=11) { // round-shaped buttons can be processed similarly + if (j==8) { + if (current_style == "DS") { buttEle.style.background='rgba(70,70,70,0.5)'; buttEle.style['background-image'] = "linear-gradient(to bottom, rgba(190,190,190,0.25) 0%, rgba(50,50,50,0.25) 100%), linear-gradient(to right, rgba(190,190,190,0.25) 0%, rgba(50,50,50,0.25) 100%)"; + } else if (current_style == "SNES") { + buttEle.style.background='rgba(0,0,0,0.0)'; + buttEle.innerHTML = "" + } else if (current_style == "NES") { + buttEle.style.background='rgba(30,30,30,1)'; + buttEle.innerHTML = "" + } else if (current_style == "XBOX") { + buttEle.style.background='rgba(30,30,30,0)'; + buttEle.innerHTML = ''; } - if (j==12) { // and of cource directional buttons: up - buttEle.innerHTML = ''; + } else if (j==9) {// once again, the 'start' button needs special attention + if (current_style == "DS") { + buttEle.style.background='rgba(0,0,0,0.0)'; + buttEle.innerHTML = ''; + } else if (current_style == "SNES") { + buttEle.style.background='rgba(0,0,0,0.0)'; + buttEle.innerHTML = "" + } else if (current_style == "NES") { + buttEle.style.background='rgba(30,30,30,1)'; + buttEle.innerHTML = "" + } else if (current_style == "XBOX") { + buttEle.style.background='rgba(30,30,30,0)'; + buttEle.innerHTML = "" + } + } else { + if (j<=11) { // round-shaped buttons can be processed similarly + if (j==0) { + if (current_style == "XBOX") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + if (j==1) { + if (current_style == "XBOX") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + if (j==2) { + if (current_style == "XBOX") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + if (j==3) { + if (current_style == "XBOX") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + if (j==4) {//L1 + if (current_style == "DS") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = ''; + } else if (current_style == "XBOX") { + + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + if (j==6) {//L2 + if (current_style == "DS") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = ''; + } else if (current_style == "XBOX") { + + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + if (j==5) {//R1 + if (current_style == "DS") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = ''; + } else if (current_style == "XBOX") { + + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + if (j==7) {//R2 + if (current_style == "DS") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = ''; + } else if (current_style == "XBOX") { + + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + if (j==10) {//L3 + if (current_style == "DS") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = ''; + } else if (current_style == "XBOX") { + + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + if (j==11) {//R3 + if (current_style == "DS") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = ''; + } else if (current_style == "XBOX") { + + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } + + if (current_style == "DS") { + buttEle.style.background='rgba(70,70,70,0.5)'; + buttEle.style['background-image'] = "linear-gradient(to bottom, rgba(190,190,190,0.25) 0%, rgba(50,50,50,0.25) 100%), linear-gradient(to right, rgba(190,190,190,0.25) 0%, rgba(50,50,50,0.25) 100%)"; + } else if (current_style == "SNES") { + buttEle.style.background='rgba(0,0,0,0.0)'; + buttEle.innerHTML = "" + } else if (current_style == "NES") { + buttEle.style.background='rgba(0,0,0,0.0)'; + buttEle.innerHTML = "" + } else if (current_style == "XBOX") { + //buttEle.style.background='rgba(0,0,0,0.0)'; + //buttEle.innerHTML = "" + } } - if (j==13) {// down - buttEle.innerHTML = ''; - } - if (j==14) {// left - buttEle.innerHTML = ''; - } - if (j==15) {// right - buttEle.innerHTML = ''; + if (current_style == "DS") { + if (j==12) { // and of course directional buttons: up + buttEle.innerHTML = ''; + } + if (j==13) {// down + buttEle.innerHTML = ''; + } + if (j==14) {// left + buttEle.innerHTML = ''; + } + if (j==15) {// right + buttEle.innerHTML = ''; + } + } else if (current_style == "SNES") { + if (j==12) {// up + buttEle.innerHTML = ''; + } + if (j==13) {// down + buttEle.innerHTML = ''; + } + if (j==14) {// left + buttEle.innerHTML = ''; + } + if (j==15) {// right + buttEle.innerHTML = ''; + } + } else if (current_style == "NES") { + if (j==12) {// up + buttEle.innerHTML = ''; + } + if (j==13) {// down + buttEle.innerHTML = ''; + } + if (j==14) {// left + buttEle.innerHTML = ''; + } + if (j==15) {// right + buttEle.innerHTML = ''; + } + } else if (current_style == "XBOX") { + if (j==12) {// up + buttEle.innerHTML = ''; + } + if (j==13) {// down + buttEle.innerHTML = ''; + } + if (j==14) {// left + buttEle.innerHTML = ''; + } + if (j==15) {// right + buttEle.innerHTML = ''; + } + if (j==16) {//home + if (current_style == "XBOX") { + buttEle.style.background='rgba(255,25,55,0)'; + buttEle.innerHTML = '' + } + } } } } @@ -132,11 +498,19 @@ function onFrame() { // gets repeatedly executed } else { // now this is for moving 'sticks' around let b = (j)/2|0; // just like before we determine what axes pair is this and let axisEleL = document.getElementById('button_'+(b+l_stick)); // get the correct id of a button to move - if (b === ((j)/2)|0 ) { // if axis id is odd, then we are dealing with Y axis - axisEleL.style.left = ((gp.axes[j]*1000)/100|0)+6+'px'; - } else { // if it's even - with X axis - axisEleL.style.top = ((gp.axes[j]*1000)/100|0)+6+'px'; - }; + if (current_style == 'XBOX') { + if (b === ((j)/2)|0 ) { // if axis id is odd, then we are dealing with Y axis + axisEleL.style.left = ((gp.axes[j]*1000)/100|0)+'px'; + } else { // if it's even - with X axis + axisEleL.style.top = ((gp.axes[j]*1000)/100|0)+'px'; + }; + } else { + if (b === ((j)/2)|0 ) { // if axis id is odd, then we are dealing with Y axis + axisEleL.style.left = ((gp.axes[j]*1000)/100|0)+6+'px'; + } else { // if it's even - with X axis + axisEleL.style.top = ((gp.axes[j]*1000)/100|0)+6+'px'; + }; + } } } } diff --git a/index.html b/index.html index 124bbae..56fc274 100644 --- a/index.html +++ b/index.html @@ -2,10 +2,135 @@ - - - + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+