Last active
May 13, 2020 21:08
-
-
Save Rio6/8abac0f9b38b31e30c95cd14af320b83 to your computer and use it in GitHub Desktop.
Swap unit with mouse wheel in Istrolid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var scrollunit = {}; | |
| scrollunit.draw = buildBar.draw; | |
| scrollunit.slotFleet = [6, 6, 4, 4, 7, 2, 3, 5, 5, 1]; | |
| scrollunit.slotIndex = []; | |
| scrollunit.findUnitIndex = function(spec, fleet) { | |
| for(var i = 0; i < 10; i++) { | |
| if(commander.fleet[fleet + "," + i] === spec) { | |
| return i; | |
| } | |
| } | |
| return -1; | |
| } | |
| scrollunit.getBtnIndex = function(btn) { | |
| if (!btn || btn.style.position !== "absolute") return -1; | |
| var i = 0; | |
| while (btn = btn.previousElementSibling) { | |
| i++; | |
| } | |
| return i; | |
| } | |
| buildBar.draw = function(folded) { | |
| var ret = scrollunit.draw.call(this, folded); | |
| var btns = document.getElementsByClassName("unitpic"); | |
| for(var i in btns) { | |
| if(btns[i].style && btns[i].style.position !== "absolute") continue; | |
| btns[i].onwheel = function(e) { | |
| var index = scrollunit.getBtnIndex(this); | |
| if(commander.fleet.selection.row === 0 && commander.fleet.selection.tab === "default" && | |
| scrollunit.slotFleet[index] > 0) { | |
| e.stopPropagation(); | |
| if(scrollunit.slotIndex[index] == undefined) { | |
| scrollunit.slotIndex[index] = scrollunit.findUnitIndex( | |
| commander.buildBar[index], | |
| scrollunit.slotFleet[index]); | |
| } | |
| var ind = scrollunit.slotIndex[index]; | |
| do { | |
| ind -= Math.sign(e.deltaY); | |
| if(ind > 9) | |
| ind = 0; | |
| else if(ind < 0) | |
| ind = 9; | |
| } while(ind != scrollunit.slotIndex[index] && | |
| buildBar.emptySpec(commander.fleet[ | |
| scrollunit.slotFleet[index] + "," + ind])); | |
| buildBar.setSpec(index, commander.fleet[ | |
| scrollunit.slotFleet[index] + "," + ind]); | |
| scrollunit.slotIndex[index] = ind; | |
| onecup.refresh(); | |
| account.save(); | |
| e.preventDefault(); | |
| } | |
| } | |
| } | |
| return ret; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment