Added Cursor Box Tracking

This commit is contained in:
MasterGordon 2018-03-18 21:07:55 +01:00
parent 7009ab904c
commit dbd79a94d2
2 changed files with 49 additions and 10 deletions

View File

@ -176,8 +176,3 @@ function drawInfoBar() {
} }
} }
} }
function buildselect() {
$('#buildselect').show()
mode = "build"
}

View File

@ -5,7 +5,7 @@ $(window).resize(function() {
$(document).ready(function() { $(document).ready(function() {
style(); style();
document.addEventListener('mousemove', onDocumentMouseMove, false); document.addEventListener('mousemove', onDocumentMouseMove, false);
$('body').on("contextmenu",function(){ $('body').on("contextmenu", function() {
return false; return false;
}) })
}) })
@ -13,16 +13,27 @@ $(document).ready(function() {
var screenleftpos = 0 var screenleftpos = 0
var screentoppos = 0 var screentoppos = 0
var infoleftpos = 0
var itemcounttoppos = 0
var cursorScreenX = -1 var cursorScreenX = -1
var cursorScreenY = -1 var cursorScreenY = -1
var cursorItemCountX = -1
var cursorItemCountY = -1
var cursorInfoX = -1
var cursorInfoY = -1
var isCursorInScreen = true var isCursorInScreen = true
var isCursorInItemCount = true
var isCursorInInfo = true
function style() { function style() {
var screenMarginTop = window.innerHeight - 912 var screenMarginTop = window.innerHeight - 912
var screenMarginLeft = (window.innerWidth - 1200) / 2 var screenMarginLeft = (window.innerWidth - 1200) / 2
var itemCountMarginTop = screenMarginTop+624 var itemCountMarginTop = screenMarginTop + 624
var infoMarginLeft = screenMarginLeft+768 var infoMarginLeft = screenMarginLeft + 768
$('#screen').css('margin-top', screenMarginTop) $('#screen').css('margin-top', screenMarginTop)
$('#screen').css('margin-left', screenMarginLeft) $('#screen').css('margin-left', screenMarginLeft)
@ -32,14 +43,17 @@ function style() {
$('#info').css('margin-left', infoMarginLeft) $('#info').css('margin-left', infoMarginLeft)
$('#itemcount').css('margin-top', itemCountMarginTop) $('#itemcount').css('margin-top', itemCountMarginTop)
$('#itemcount').css('margin-left', screenMarginLeft) $('#itemcount').css('margin-left', screenMarginLeft)
screenleftpos = pxToInt($('#screen').css("margin-left")) screenleftpos = screenMarginLeft
screentoppos = pxToInt($('#screen').css("margin-top")) screentoppos = screenMarginTop
infoleftpos = infoMarginLeft
itemcounttoppos = itemCountMarginTop
} }
function pxToInt(px) { function pxToInt(px) {
return parseInt(px.substring(0, px.length - 2)) return parseInt(px.substring(0, px.length - 2))
} }
//SELECTION UND BOX TRACKING
function onDocumentMouseMove(event) { function onDocumentMouseMove(event) {
var mX = event.clientX - screenleftpos; var mX = event.clientX - screenleftpos;
@ -47,6 +61,24 @@ function onDocumentMouseMove(event) {
if (mX < 0 || mX > 1200 || mY < 0 || mY > 576) { if (mX < 0 || mX > 1200 || mY < 0 || mY > 576) {
cursorScreenX = -1 cursorScreenX = -1
cursorScreenY = -1 cursorScreenY = -1
mX = event.clientX - screenleftpos;
mY = event.clientY - itemcounttoppos;
if (mX < 0 || mX > 720 || mY < 0 || mY > 240) {
cursorItemCountX = -1
cursorItemCountY = -1
mX = event.clientX - infoleftpos;
mY = event.clientY - itemcounttoppos;
if (mX < 0 || mX > 432 || mY < 0 || mY > 240) {
cursorInfoX = -1
cursorInfoY = -1
} else {
cursorInfoX = Math.floor(mX / 48);
cursorInfoY = Math.floor(mY / 48);
}
} else {
cursorItemCountX = Math.floor(mX / 48);
cursorItemCountY = Math.floor(mY / 48);
}
} else { } else {
cursorScreenX = Math.floor(mX / 48); cursorScreenX = Math.floor(mX / 48);
cursorScreenY = Math.floor(mY / 48); cursorScreenY = Math.floor(mY / 48);
@ -56,4 +88,16 @@ function onDocumentMouseMove(event) {
} else { } else {
isCursorInScreen = false isCursorInScreen = false
} }
if (cursorItemCountX != -1 && cursorItemCountY != -1) {
isCursorInItemCount = true
} else {
isCursorInItemCount = false
}
if (cursorInfoX != -1 && cursorInfoY != -1) {
isCursorInInfo = true
} else {
isCursorInInfo = false
}
} }