Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use guidm cursor fns #1402

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,25 @@ Template for new versions:
- `devel/export-map`: export map tile data to a JSON file
- `autocheese`: automatically make cheese using barrels that have accumulated sufficient milk
- `gui/spectate`: interactive UI for configuring `spectate`
- `launch`: (reinstated) thrash your enemies with a flying suplex
- `putontable`: (reinstated) make an item appear on a table like in adventure mode

## New Features
- `advtools`: new ``advtools.fastcombat`` overlay (enabled by default) allows you to skip combat animations and the announcement "More" button by mashing the movement keys
- `advtools`: new ``advtools.fastcombat`` overlay (enabled by default) allows you to skip combat animations and the announcement "More" button by mashing the movement keys

## Fixes
- `position`: support for adv mode look cursor
- `devel/query`, `devel/tree-info`, `hfs-pit`, `colonies`, `toggle-kbd-cursor`: now function in adventure mode
- `hfs-pit`: fix up tiletypes of pit walls, better placement of stairs (w/r/t eerie pits and ramp tops)
- `modtools/create-item`: ``hackWish`` now respects ``opts.pos`` and will spawn items there if provided

## Misc Improvements
- `hide-tutorials`: handle tutorial popups for adventure mode
- `hide-tutorials`: new ``reset`` command that will re-enable popups in the current game (in case you hid them all and now want them back)
- `gui/notify`: moody dwarf notification turns red when they can't reach workshop or items
- `gui/confirm`: in the delete manager order confirmation dialog, show a description of which order you have selected to delete
- `position`: display both adventurer and site pos simultaneously. Display map block pos+offset of selected tile.
- `gui/create-item`: now accepts a ``pos`` argument of where to spawn items

## Removed

Expand Down
6 changes: 4 additions & 2 deletions colonies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ and ``colonies convert TERMITE`` ends your beekeeping industry.

]====]

local guidm = require('gui.dwarfmode')

function findVermin(target_verm)
for k,v in ipairs(df.global.world.raws.creatures.all) do
if v.creature_id == target_verm then
Expand Down Expand Up @@ -50,8 +52,8 @@ function convert_vermin_to(target_verm)
end

function place_vermin(target_verm)
local pos = copyall(df.global.cursor)
if pos.x == -30000 then
local pos = guidm.getCursorPos()
if not pos then
qerror("Cursor must be pointing somewhere")
end
local verm = df.vermin:new()
Expand Down
8 changes: 1 addition & 7 deletions devel/light.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ function setCell(x,y,cell)
cell.bo=cell.bo or {r=0,g=0,b=0}
render.setCell(x,y,cell)
end
function getCursorPos()
local g_cursor=df.global.cursor
if g_cursor.x ~= -30000 then
return copyall(g_cursor)
end
end
--luacheck: skip
function falloff(color,sqDist,maxdist)
local v1=1/(sqDist/maxdist+1)
Expand Down Expand Up @@ -273,7 +267,7 @@ function LightOverlay:calculateLightSun()
end
end
function LightOverlay:calculateLightCursor()
local c=getCursorPos()
local c=guidm.getCursorPos()

if c then

Expand Down
16 changes: 7 additions & 9 deletions devel/query.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
-- Written by Josh Cooper(cppcooper) on 2017-12-21, last modified: 2021-06-13
-- Version: 3.2
--luacheck:skip-entirely
local utils=require('utils')
local guidm = require('gui.dwarfmode')
local utils = require('utils')
local validArgs = utils.invert({
'help',

Expand Down Expand Up @@ -221,14 +222,11 @@ function getSelectionData()
elseif args.job then
debugf(0,"job selection")
selection = dfhack.gui.getSelectedJob(true)
if selection == nil and df.global.cursor.x >= 0 then
local pos = { x=df.global.cursor.x,
y=df.global.cursor.y,
z=df.global.cursor.z }
local pos = guidm.getCursorPos()
if selection == nil and pos then
print("searching for a job at the cursor")
for _link, job in utils.listpairs(df.global.world.jobs.list) do
local jp = job.pos
if jp.x == pos.x and jp.y == pos.y and jp.z == pos.z then
if same_xyz(job.pos, pos) then
if selection == nil then
selection = {}
end
Expand All @@ -240,7 +238,7 @@ function getSelectionData()
path_info_pattern = path_info
elseif args.tile then
debugf(0,"tile selection")
local pos = copyall(df.global.cursor)
local pos = guidm.getCursorPos()
selection = dfhack.maps.ensureTileBlock(pos.x,pos.y,pos.z)
bpos = selection.map_pos
path_info = string.format("tile[%d][%d][%d]",pos.x,pos.y,pos.z)
Expand All @@ -249,7 +247,7 @@ function getSelectionData()
tiley = pos.y%16
elseif args.block then
debugf(0,"block selection")
local pos = copyall(df.global.cursor)
local pos = guidm.getCursorPos()
selection = dfhack.maps.ensureTileBlock(pos.x,pos.y,pos.z)
bpos = selection.map_pos
path_info = string.format("blocks[%d][%d][%d]",bpos.x,bpos.y,bpos.z)
Expand Down
7 changes: 6 additions & 1 deletion devel/tree-info.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
--Print a tree_info visualization of the tree at the cursor.
--@module = true
local guidm = require('gui.dwarfmode')

-- [w][n][e][s]
local branch_chars = {
Expand Down Expand Up @@ -172,7 +173,11 @@ function printTree(t)
end

if not dfhack_flags.module then
local p = dfhack.maps.getPlantAtTile(copyall(df.global.cursor))
local p = guidm.getCursorPos()
if not p then
qerror('No cursor!')
end
p = dfhack.maps.getPlantAtTile(p)
if p and p.tree_info then
printTree(p.tree_info)
else
Expand Down
2 changes: 1 addition & 1 deletion docs/extinguish.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extinguish

.. dfhack-tool::
:summary: Put out fires.
:tags: fort armok buildings items map units
:tags: fort adventure armok buildings items map units

With this tool, you can put out fires affecting map tiles, plants, units, items,
and buildings.
Expand Down
2 changes: 1 addition & 1 deletion docs/firestarter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ firestarter

.. dfhack-tool::
:summary: Lights things on fire.
:tags: fort armok items map units
:tags: fort adventure armok items map units

Feel the need to burn something? Set items, locations, or even entire
inventories on fire! Use while viewing an item, with the cursor over a map tile,
Expand Down
4 changes: 4 additions & 0 deletions docs/gui/create-item.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Options
``-f``, ``--unrestricted``
Don't restrict the material options to only those that are normally
appropriate for the selected item type.
``-p``, ``--pos <x>,<y>,<z>``
If specified, items will be spawned at the given coordinates instead of at
the creator unit's feet. ``here`` can be used in place of ``<x>,<y>,<z>``
to use the active keyboard cursor.
``--startup``
Instead of showing the item creation interface, start monitoring for a
modded reaction with a code of ``DFHACK_WISH``. When a reaction with that
Expand Down
2 changes: 1 addition & 1 deletion docs/launch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ launch

.. dfhack-tool::
:summary: Thrash your enemies with a flying suplex.
:tags: unavailable
:tags: adventure armok units

Attack another unit and then run this command to grab them and fly in a glorious
parabolic arc to where you have placed the cursor. You'll land safely and your
Expand Down
3 changes: 2 additions & 1 deletion docs/modtools/create-item.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ Options
caste associated with it.
``-p``, ``--pos <x>,<y>,<z>``
If specified, items will be spawned at the given coordinates instead of at
the creator unit's feet.
the creator unit's feet. ``here`` can be used in place of ``<x>,<y>,<z>``
to use the active keyboard cursor.
2 changes: 1 addition & 1 deletion docs/putontable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ putontable

.. dfhack-tool::
:summary: Make an item appear on a table.
:tags: unavailable
:tags: adventure fort armok buildings items

To use this tool, move an item to the ground on the same tile as a built table.
Then, place the cursor over the table and item and run this command. The item
Expand Down
9 changes: 7 additions & 2 deletions docs/toggle-kbd-cursor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ toggle-kbd-cursor

.. dfhack-tool::
:summary: Toggles the keyboard cursor.
:tags: interface
:tags: adventure fort interface

This tool simply toggles the keyboard cursor so you can quickly switch it on when you need it. Many other tools, like `autodump`, need a keyboard cursor for selecting a target tile. Note that you'll still need to enter an interface mode where the keyboard cursor is visible, like mining mode or dumping mode, in order to use the cursor.
This tool simply toggles the keyboard cursor so you can quickly switch it on
when you need it. Many other tools, like `autodump`, need a keyboard cursor for
selecting a target tile. Note that you'll still need to enter an interface mode
where the keyboard cursor is visible, like mining mode or dumping mode, in
order to use the cursor. In adventure mode, this tool toggles look mode via
simulated input.

Usage
-----
Expand Down
48 changes: 25 additions & 23 deletions gui/advfort.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ build_filter.HUMANish={
--[[ FIXME: maybe let player select which to disable?]]
for k,v in ipairs(df.global.plotinfo.economic_stone) do df.global.plotinfo.economic_stone[k]=0 end

local gui = require 'gui'
local wid=require 'gui.widgets'
local dialog=require 'gui.dialogs'
local buildings=require 'dfhack.buildings'
local bdialog=require 'gui.buildings'
local workshopJobs=require 'dfhack.workshops'
local utils=require 'utils'
local gscript=require 'gui.script'
local gui = require('gui')
local guidm = require('gui.dwarfmode')
local wid = require('gui.widgets')
local dialog = require('gui.dialogs')
local buildings = require('dfhack.buildings')
local bdialog = require('gui.buildings')
local workshopJobs = require('dfhack.workshops')
local utils = require('utils')
local gscript = require('gui.script')

local advfort_items = reqscript('internal/advfort/advfort_items')

Expand Down Expand Up @@ -375,15 +376,15 @@ end
function AssignUnitToJob(job,unit,unit_pos)
job.general_refs:insert("#",{new=df.general_ref_unit_workerst,unit_id=unit.id})
unit.job.current_job=job
unit_pos=unit_pos or {x=job.pos.x,y=job.pos.y,z=job.pos.z}
unit_pos=unit_pos or copyall(job.pos)
unit.path.dest:assign(unit_pos)
return true
end
function SetCreatureRef(args)
local job=args.job
local pos=args.pos
for k,v in pairs(df.global.world.units.active) do
if v.pos.x==pos.x and v.pos.y==pos.y and v.pos.z==pos.z then
if same_xyz(v.pos, pos) then
job.general_refs:insert("#",{new=df.general_ref_unit_cageest,unit_id=v.id})
return
end
Expand All @@ -393,7 +394,7 @@ end
function SetWebRef(args)
local pos=args.pos
for k,v in pairs(df.global.world.items.other.ANY_WEBS) do
if v.pos.x==pos.x and v.pos.y==pos.y and v.pos.z==pos.z then
if same_xyz(v.pos, pos) then
args.job.general_refs:insert("#",{new=df.general_ref_item,item_id=v.id})
return
end
Expand All @@ -403,7 +404,7 @@ function SetPatientRef(args)
local job=args.job
local pos=args.pos
for k,v in pairs(df.global.world.units.active) do
if v.pos.x==pos.x and v.pos.y==pos.y and v.pos.z==pos.z then
if same_xyz(v.pos, pos) then
job.general_refs:insert("#",{new=df.general_ref_unit_patientst,unit_id=v.id})
return
end
Expand Down Expand Up @@ -481,7 +482,7 @@ end
function SameSquare(args)
local pos1=args.pos
local pos2=args.from_pos
if pos1.x==pos2.x and pos1.y==pos2.y and pos1.z==pos2.z then
if same_xyz(pos1, pos2) then
return true
else
return false, "Can only do it on same square"
Expand Down Expand Up @@ -547,7 +548,7 @@ end
function IsUnit(args)
local pos=args.pos
for k,v in pairs(df.global.world.units.active) do
if v.pos.x==pos.x and v.pos.y==pos.y and v.pos.z==pos.z then
if same_xyz(v.pos, pos) then
return true
end
end
Expand All @@ -556,7 +557,7 @@ end
function itemsAtPos(pos,tbl)
local ret=tbl or {}
for k,v in pairs(df.global.world.items.other.IN_PLAY) do
if v.pos.x==pos.x and v.pos.y==pos.y and v.pos.z==pos.z and v.flags.on_ground then
if v.flags.on_ground and same_xyz(v.pos, pos) then
table.insert(ret,v)
end
end
Expand Down Expand Up @@ -776,7 +777,7 @@ function EnumItems(args)
end
elseif args.pos~=nil then
for k,v in pairs(df.global.world.items.other.IN_PLAY) do
if v.pos.x==args.pos.x and v.pos.y==args.pos.y and v.pos.z==args.pos.z and v.flags.on_ground then
if v.flags.on_ground and same_xyz(v.pos, args.pos) then
AddItem(ret,v,args.deep)
end
end
Expand Down Expand Up @@ -1303,7 +1304,7 @@ function siegeWeaponActionChosen(args,actionid)
end
args.job_type=action
args.unit=dfhack.world.getAdventurer()
local from_pos={x=args.unit.pos.x,y=args.unit.pos.y, z=args.unit.pos.z}
local from_pos=copyall(args.unit.pos)
args.from_pos=from_pos
args.pos=from_pos
elseif actionid==3 then --Fire
Expand All @@ -1313,7 +1314,7 @@ function siegeWeaponActionChosen(args,actionid)
end
args.job_type=action
args.unit=dfhack.world.getAdventurer()
local from_pos={x=args.unit.pos.x,y=args.unit.pos.y, z=args.unit.pos.z}
local from_pos=copyall(args.unit.pos)
args.from_pos=from_pos
args.pos=from_pos
end
Expand Down Expand Up @@ -1397,7 +1398,7 @@ function usetool:openShopWindow(building)

local filter_pile=workshopJobs.getJobs(building:getType(),building:getSubtype(),building:getCustomType())
if filter_pile then
local state={unit=adv,from_pos={x=adv.pos.x,y=adv.pos.y, z=adv.pos.z},building=building,screen=self,bld=building}
local state={unit=adv,from_pos=copyall(adv.pos),building=building,screen=self,bld=building}
local choices={}
for k,v in pairs(filter_pile) do
table.insert(choices,{job_id=0,text=v.name:lower(),filter=v})
Expand Down Expand Up @@ -1687,15 +1688,16 @@ function usetool:fieldInput(keys)
unit=adv,
pos=moddedpos(adv.pos,MOVEMENT_KEYS[code]),
dir=MOVEMENT_KEYS[code],
from_pos={x=adv.pos.x,y=adv.pos.y, z=adv.pos.z},
from_pos=copyall(adv.pos),
post_actions=cur_mode[4],
pre_actions=cur_mode[5],
job_type=cur_mode[2],
screen=self}

if code=="SELECT" then --do job in the distance, TODO: check if you can still cheat-mine (and co.) remotely
if df.global.cursor.x~=-30000 then
state.pos={x=df.global.cursor.x,y=df.global.cursor.y,z=df.global.cursor.z}
local cursor=guidm.getCursorPos()
if cursor then
state.pos=cursor
else
break
end
Expand Down Expand Up @@ -1747,7 +1749,7 @@ function usetool:onInput(keys)
local adv=dfhack.world.getAdventurer()

if keys.LEAVESCREEN then
if df.global.cursor.x~=-30000 then --if not poiting at anything
if guidm.getCursorPos() then --if not poiting at anything
self:sendInputToParent("LEAVESCREEN") --leave poiting
else
self:dismiss() --leave the adv-tools all together
Expand Down
2 changes: 1 addition & 1 deletion gui/blueprint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ function Blueprint:onShow()
end

function Blueprint:save_cursor_pos()
self.saved_cursor = copyall(df.global.cursor)
self.saved_cursor = guidm.getCursorPos()
end

function Blueprint:is_setting_start_pos()
Expand Down
Loading