Skip to content

Commit a283f4e

Browse files
committed
Fix/improvement: ctrl+wasd moves larger cursors by one tile instead of skipping by preview
1 parent 6469da4 commit a283f4e

1 file changed

Lines changed: 68 additions & 50 deletions

File tree

control.lua

Lines changed: 68 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,44 @@ local function move(direction, pindex, nudged)
13811381
end
13821382

13831383
--Moves the cursor, and conducts an area scan for larger cursors. If the player is in a slow moving vehicle, it is stopped.
1384+
---Move a large cursor by n tiles and read the area
1385+
---@param pindex number
1386+
---@param direction defines.direction
1387+
---@param tiles number Number of tiles to move
1388+
---@param prefix_text string? Optional text to prepend to the reading
1389+
local function move_large_cursor_by(pindex, direction, tiles, prefix_text)
1390+
local vp = Viewpoint.get_viewpoint(pindex)
1391+
local cursor_pos = vp:get_cursor_pos()
1392+
local cursor_size = vp:get_cursor_size()
1393+
local p = game.get_player(pindex)
1394+
1395+
cursor_pos = FaUtils.offset_position_legacy(cursor_pos, direction, tiles)
1396+
vp:set_cursor_pos(cursor_pos)
1397+
1398+
local scan_left_top = {
1399+
x = math.floor(cursor_pos.x) - cursor_size,
1400+
y = math.floor(cursor_pos.y) - cursor_size,
1401+
}
1402+
local scan_right_bottom = {
1403+
x = math.floor(cursor_pos.x) + cursor_size + 1,
1404+
y = math.floor(cursor_pos.y) + cursor_size + 1,
1405+
}
1406+
local scan_summary = FaInfo.area_scan_summary_info(pindex, scan_left_top, scan_right_bottom)
1407+
if prefix_text and prefix_text ~= "" then scan_summary = prefix_text .. scan_summary end
1408+
Graphics.draw_large_cursor(scan_left_top, scan_right_bottom, pindex)
1409+
Speech.speak(pindex, scan_summary)
1410+
1411+
if storage.players[pindex].remote_view then
1412+
sounds.play_building_placement(p.index, cursor_pos)
1413+
else
1414+
p.play_sound({
1415+
path = "Close-Inventory-Sound",
1416+
position = storage.players[pindex].position,
1417+
volume_modifier = 0.75,
1418+
})
1419+
end
1420+
end
1421+
13841422
local function cursor_mode_move(direction, pindex, single_only)
13851423
local vp = Viewpoint.get_viewpoint(pindex)
13861424
local cursor_pos = vp:get_cursor_pos()
@@ -1389,12 +1427,11 @@ local function cursor_mode_move(direction, pindex, single_only)
13891427
if single_only then diff = 1 end
13901428
local p = game.get_player(pindex)
13911429

1392-
cursor_pos = FaUtils.offset_position_legacy(cursor_pos, direction, diff)
1393-
-- Use continuous movement tracking for WASD movements
1394-
vp:set_cursor_pos_continuous(cursor_pos, direction)
1395-
13961430
if cursor_size == 0 then
13971431
-- Cursor size 0 ("1 by 1"): Read tile
1432+
cursor_pos = FaUtils.offset_position_legacy(cursor_pos, direction, diff)
1433+
vp:set_cursor_pos_continuous(cursor_pos, direction)
1434+
13981435
EntitySelection.reset_entity_index(pindex)
13991436
read_tile(pindex)
14001437

@@ -1416,34 +1453,24 @@ local function cursor_mode_move(direction, pindex, single_only)
14161453
else
14171454
Graphics.draw_cursor_highlight(pindex, nil, nil)
14181455
end
1456+
1457+
if storage.players[pindex].remote_view then
1458+
sounds.play_building_placement(p.index, cursor_pos)
1459+
else
1460+
p.play_sound({
1461+
path = "Close-Inventory-Sound",
1462+
position = storage.players[pindex].position,
1463+
volume_modifier = 0.75,
1464+
})
1465+
end
14191466
else
1420-
-- Larger cursor sizes: scan area
1421-
local scan_left_top = {
1422-
x = math.floor(cursor_pos.x) - cursor_size,
1423-
y = math.floor(cursor_pos.y) - cursor_size,
1424-
}
1425-
local scan_right_bottom = {
1426-
x = math.floor(cursor_pos.x) + cursor_size + 1,
1427-
y = math.floor(cursor_pos.y) + cursor_size + 1,
1428-
}
1429-
local scan_summary = FaInfo.area_scan_summary_info(pindex, scan_left_top, scan_right_bottom)
1430-
Graphics.draw_large_cursor(scan_left_top, scan_right_bottom, pindex)
1431-
Speech.speak(pindex, scan_summary)
1467+
-- Use continuous movement tracking for WASD movements
1468+
vp:set_cursor_pos_continuous(cursor_pos, direction)
1469+
move_large_cursor_by(pindex, direction, diff)
14321470
end
14331471

1434-
--Update player direction to face the cursor (after the vanilla move event that turns the character too, and only ends when the movement key is released)
1472+
--Update player direction to face the cursor
14351473
turn_to_cursor_direction_precise(pindex)
1436-
1437-
--Play Sound
1438-
if storage.players[pindex].remote_view then
1439-
sounds.play_building_placement(p.index, cursor_pos)
1440-
else
1441-
p.play_sound({
1442-
path = "Close-Inventory-Sound",
1443-
position = storage.players[pindex].position,
1444-
volume_modifier = 0.75,
1445-
})
1446-
end
14471474
end
14481475

14491476
--Chooses the function to call after a movement keypress, according to the current mode.
@@ -1722,23 +1749,30 @@ end
17221749
--Runs the cursor skip actions and reads out results
17231750
local function cursor_skip(pindex, direction, iteration_limit, use_preview_size)
17241751
local vp = Viewpoint.get_viewpoint(pindex)
1725-
local cursor_pos = vp:get_cursor_pos()
17261752
local cursor_size = vp:get_cursor_size()
17271753
local p = game.get_player(pindex)
17281754
local limit = iteration_limit or 100
1729-
local result = ""
1730-
local skip_by_preview_size = use_preview_size or false
17311755

1732-
--Run the iteration and play sound
1756+
--Special case: larger cursors move by 1 tile with ctrl+WASD
1757+
if use_preview_size and cursor_size > 0 then
1758+
move_large_cursor_by(pindex, direction, 1)
1759+
return
1760+
end
1761+
1762+
local cursor_pos = vp:get_cursor_pos()
1763+
local result = ""
17331764
local moved_count = 0
1734-
if skip_by_preview_size == true then
1765+
if use_preview_size == true then
17351766
moved_count = apply_skip_by_preview_size(pindex, direction)
17361767
result = "Skipped by preview size " .. moved_count .. ", "
17371768
else
17381769
moved_count = cursor_skip_iteration(pindex, direction, limit)
17391770
result = "Skipped "
17401771
end
1741-
if skip_by_preview_size then
1772+
1773+
cursor_pos = vp:get_cursor_pos()
1774+
1775+
if use_preview_size then
17421776
--Rolling always plays the regular moving sound
17431777
if storage.players[pindex].remote_view then
17441778
sounds.play_building_placement(p.index, cursor_pos)
@@ -1752,7 +1786,6 @@ local function cursor_skip(pindex, direction, iteration_limit, use_preview_size)
17521786
elseif moved_count < 0 then
17531787
--No change found within the limit
17541788
result = result .. limit .. " tiles without a change, "
1755-
--Play Sound
17561789
if storage.players[pindex].remote_view then
17571790
sounds.play_sound_at_position({ path = "inventory-wrap-around", volume_modifier = 1 }, cursor_pos)
17581791
else
@@ -1764,7 +1797,6 @@ local function cursor_skip(pindex, direction, iteration_limit, use_preview_size)
17641797
end
17651798
elseif moved_count == 1 then
17661799
result = ""
1767-
--Play Sound
17681800
if storage.players[pindex].remote_view then
17691801
sounds.play_building_placement(p.index, cursor_pos)
17701802
else
@@ -1777,7 +1809,6 @@ local function cursor_skip(pindex, direction, iteration_limit, use_preview_size)
17771809
elseif moved_count > 1 then
17781810
--Change found, with more than 1 tile moved
17791811
result = result .. moved_count .. " tiles, "
1780-
--Play Sound
17811812
if storage.players[pindex].remote_view then
17821813
sounds.play_sound_at_position({ path = "inventory-wrap-around", volume_modifier = 1 }, cursor_pos)
17831814
else
@@ -1792,19 +1823,6 @@ local function cursor_skip(pindex, direction, iteration_limit, use_preview_size)
17921823
--Read the tile reached
17931824
read_tile(pindex, result)
17941825
Graphics.sync_build_cursor_graphics(pindex)
1795-
1796-
--Draw large cursor boxes if present
1797-
if cursor_size > 0 then
1798-
local left_top = {
1799-
math.floor(cursor_pos.x) - cursor_size,
1800-
math.floor(cursor_pos.y) - cursor_size,
1801-
}
1802-
local right_bottom = {
1803-
math.floor(cursor_pos.x) + cursor_size + 1,
1804-
math.floor(cursor_pos.y) + cursor_size + 1,
1805-
}
1806-
Graphics.draw_large_cursor(left_top, right_bottom, pindex)
1807-
end
18081826
end
18091827

18101828
EventManager.on_event(

0 commit comments

Comments
 (0)