From 79913c79503a233634463ee5bd54d80206450840 Mon Sep 17 00:00:00 2001 From: MasterGordon Date: Mon, 26 Mar 2018 14:12:17 +0200 Subject: [PATCH] Build Hold Left Mouse. --- js/userinterface.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/js/userinterface.js b/js/userinterface.js index 458f7d5..794e54a 100644 --- a/js/userinterface.js +++ b/js/userinterface.js @@ -58,6 +58,8 @@ var isCursorInScreen = true var isCursorInItemCount = true var isCursorInInfo = true +var mousedown = false + function onDocumentMouseMove(event) { var mX = event.clientX - screenleftpos; @@ -104,6 +106,11 @@ function onDocumentMouseMove(event) { } else { isCursorInInfo = false } + if (mousedown && mode == "build") { + if (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] == 0) { + factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = new toBuild(cursorScreenX, cursorScreenY, factorys[currentFactory]) + } + } } function clickEvents() { @@ -162,11 +169,6 @@ function buildEvents() { factorys[currentFactory].tiles[cursorScreenX][cursorScreenY].rotate() } } - if (mode == "build") { - if (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] == 0) { - factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = new toBuild(cursorScreenX, cursorScreenY, factorys[currentFactory]) - } - } if (mode == "move") { if (isCursorInScreen) { if (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] != 0) { @@ -177,6 +179,8 @@ function buildEvents() { factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = factorys[currentFactory].tiles[moveFromCX][moveFromCY] factorys[currentFactory].tiles[cursorScreenX][cursorScreenY].x = cursorScreenX factorys[currentFactory].tiles[cursorScreenX][cursorScreenY].y = cursorScreenY + while (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY].input.items.length > 0) + var item = factorys[currentFactory].tiles[cursorScreenX][cursorScreenY].input.items.pop() factorys[currentFactory].tiles[moveFromCX][moveFromCY] = 0 } else { moveFromCX = cursorScreenX @@ -187,6 +191,11 @@ function buildEvents() { } } } + if (mode == "build") { + if (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] == 0) { + factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = new toBuild(cursorScreenX, cursorScreenY, factorys[currentFactory]) + } + } if ((mode == "none") && isCursorInScreen) { if (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] != 0) { selectedTile = factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] @@ -213,7 +222,10 @@ function buildEvents() { } ); - $('body').mousedown(function() { + + $('body').mousedown(function(e) { + if (e.which == 1) + mousedown = true if (mode == "move") { if (isCursorInScreen) { moveFromX = cursorScreenX @@ -222,7 +234,9 @@ function buildEvents() { } }) - $('body').mouseup(function() { + $('body').mouseup(function(e) { + if (e.which == 1) + mousedown = false if (mode == "move") { if (isCursorInScreen && moveFromX != -1) { if (moveFromX != cursorScreenX || moveFromY != cursorScreenY) { @@ -230,6 +244,8 @@ function buildEvents() { factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = factorys[currentFactory].tiles[moveFromX][moveFromY] factorys[currentFactory].tiles[cursorScreenX][cursorScreenY].x = cursorScreenX factorys[currentFactory].tiles[cursorScreenX][cursorScreenY].y = cursorScreenY + while (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY].input.items.length > 0) + var item = factorys[currentFactory].tiles[cursorScreenX][cursorScreenY].input.items.pop() factorys[currentFactory].tiles[moveFromX][moveFromY] = 0 } moveFromX = -1 @@ -265,6 +281,10 @@ function closeUi() { mode = "none" return false } + if (mode == "delete") { + mode = "none" + return false + } } var itemId = []