1
0
mirror of https://github.com/LDDestroier/CC/ synced 2025-10-20 18:17:43 +00:00

Updated mouse input method

This commit is contained in:
LDDestroier
2019-01-12 23:52:14 -05:00
committed by GitHub
parent 6816186cf6
commit ad0af3635f

View File

@@ -8,6 +8,7 @@
local port = 701 local port = 701
local kioskMode = false local kioskMode = false
local debugShowKeys = false local debugShowKeys = false
local useLegacyMouseControl = false
local scr_x, scr_y = term.getSize() local scr_x, scr_y = term.getSize()
local scr_mx, scr_my = scr_x / 2, scr_y / 2 local scr_mx, scr_my = scr_x / 2, scr_y / 2
@@ -616,7 +617,9 @@ local render = function(useSetVisible)
termsetBackgroundColor(tocolors[grid.voidcol]) termsetBackgroundColor(tocolors[grid.voidcol])
term.write("P" .. you) term.write("P" .. you)
if debugShowKeys then if debugShowKeys then
local y = 2 term.setCursorPos(1,2)
term.write("dir = " .. player[you].direction .. " ")
local y = 3
for k,v in pairs(keysDown) do for k,v in pairs(keysDown) do
if v then if v then
term.setCursorPos(1,y) term.setCursorPos(1,y)
@@ -798,22 +801,48 @@ local cleanExit = function()
print("Thanks for playing!") print("Thanks for playing!")
end end
local parseMouseInput = function(button, x, y) local parseMouseInput = function(button, x, y, direction)
local output = nil local output = false
local cx, cy = (x - scr_mx) * (scr_y / scr_x), y - scr_my local cx = x - scr_mx
if cx > cy then local cy = y - scr_my
if -cx > cy then
output = "up" if useLegacyMouseControl then -- outdated mouse input
cx = cx * (scr_y / scr_x)
if cx > cy then
if -cx > cy then
output = "up"
else
output = "right"
end
else else
output = "right" if -cx < cy then
output = "down"
else
output = "left"
end
end end
else else
if -cx < cy then cx = cx + scrollAdjX
output = "down" cy = cy + scrollAdjY
else if button == 1 then -- move player
output = "left" if direction % 2 == 0 then -- moving horizontally
if cy > 0 then
output = "down"
elseif cy < 0 then
output = "up"
end
else -- moving vertically
if cx > 0 then
output = "right"
elseif cx < 0 then
output = "left"
end
end
elseif button == 2 then -- release trail
output = "release"
end end
end end
return control[output] return control[output]
end end
@@ -837,16 +866,16 @@ local getInput = function()
keysDown[evt[2]] = true keysDown[evt[2]] = true
elseif evt[1] == "key_up" then elseif evt[1] == "key_up" then
keysDown[evt[2]] = false keysDown[evt[2]] = false
elseif evt[1] == "mouse_click" or evt[1] == "mouse_drag" then elseif evt[1] == "mouse_click" or (useLegacyMouseControl and evt[1] == "mouse_drag") then
if evt[1] == "mouse_drag" then if evt[1] == "mouse_drag" then
keysDown[mkey] = false keysDown[mkey] = false
end end
mkey = parseMouseInput(evt[2], evt[3], evt[4]) mkey = parseMouseInput(evt[2], evt[3], evt[4], player[you].direction) or -1
lastDirectionPressed = revControl[mkey] lastDirectionPressed = revControl[mkey]
keysDown[mkey] = true keysDown[mkey] = true
elseif evt[1] == "mouse_up" then elseif evt[1] == "mouse_up" then
keysDown[mkey] = false keysDown[mkey] = false
mkey = parseMouseInput(evt[2], evt[3], evt[4]) mkey = parseMouseInput(evt[2], evt[3], evt[4], player[you].direction) or -1
keysDown[mkey] = false keysDown[mkey] = false
end end
end end
@@ -1032,10 +1061,10 @@ local game = function()
scrollAdjX = scrollAdjX + 2 scrollAdjX = scrollAdjX + 2
end end
if keysDown[control.lookUp] then if keysDown[control.lookUp] then
scrollAdjY = scrollAdjY - 1.5 scrollAdjY = scrollAdjY - 1.25
end end
if keysDown[control.lookDown] then if keysDown[control.lookDown] then
scrollAdjY = scrollAdjY + 1.5 scrollAdjY = scrollAdjY + 1.25
end end
scrollAdjX = scrollAdjX * 0.8 scrollAdjX = scrollAdjX * 0.8