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

Create toolbar overlay for mass-remove #1422

Merged
merged 19 commits into from
Mar 23, 2025
Merged
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
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Template for new versions:
## New Tools

## New Features

- `gui/mass-remove`: added a button to the bottom toolbar when eraser mode is active for launching `gui/mass-remove`
- `idle-crafting`: default to only considering happy and ecstatic units for the highest need threshold

## Fixes
Expand Down
13 changes: 13 additions & 0 deletions docs/gui/mass-remove.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@ Usage
::

gui/mass-remove

Overlay
-------

This tool also provides one overlay that is managed by the `overlay`
framework.

massremovetoolbar
~~~~~~~~~~~~~~~~~

The ``mass-remove.massremovetoolbar`` overlay adds a button to the toolbar at the bottom of the
screen when eraser mode is active. It allows you to conveniently open the ``gui/mass-remove``
interface.
100 changes: 100 additions & 0 deletions gui/mass-remove.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
-- building/construction mass removal/suspension tool

--@ module = true

local toolbar_textures = dfhack.textures.loadTileset('hack/data/art/mass_remove_toolbar.png', 8, 12)

local gui = require('gui')
local guidm = require('gui.dwarfmode')
local utils = require('utils')
local widgets = require('gui.widgets')
local overlay = require('plugins.overlay')

local function noop()
end

function launch_mass_remove()
local vs = dfhack.gui.getDFViewscreen(true)
gui.simulateInput(vs,'LEAVESCREEN')
dfhack.run_script('gui/mass-remove')
end

local function get_first_job(bld)
if not bld then return end
if #bld.jobs ~= 1 then return end
Expand Down Expand Up @@ -383,6 +394,95 @@ function MassRemoveScreen:onDismiss()
view = nil
end


-- --------------------------------
-- MassRemoveToolbarOverlay
--

MassRemoveToolbarOverlay = defclass(MassRemoveToolbarOverlay, overlay.OverlayWidget)
MassRemoveToolbarOverlay.ATTRS{
desc='Adds a button to the erase toolbar to open the mass removal tool',
default_pos={x=42, y=-4},
default_enabled=true,
viewscreens='dwarfmode/Designate/ERASE',
frame={w=26, h=11},
}

function MassRemoveToolbarOverlay:init()
local button_chars = {
{218, 196, 196, 191},
{179, 'M', 'R', 179},
{192, 196, 196, 217},
}

self:addviews{
widgets.Panel{
frame={t=0, r=0, w=26, h=6},
frame_style=gui.FRAME_PANEL,
frame_background=gui.CLEAR_PEN,
frame_inset={l=1, r=1},
visible=function() return self.subviews.icon:getMousePos() end,
subviews={
widgets.Label{
text={
'Open mass removal', NEWLINE,
'interface.', NEWLINE,
NEWLINE,
{text='Hotkey: ', pen=COLOR_GRAY}, {key='CUSTOM_M'},
},
},
},
},
widgets.Panel{
view_id='icon',
frame={b=0, r=22, w=4, h=3},
subviews={
widgets.Label{
text=widgets.makeButtonLabelText{
chars=button_chars,
pens=COLOR_GRAY,
tileset=toolbar_textures,
tileset_offset=1,
tileset_stride=8,
},
on_click=launch_mass_remove,
visible=function () return not self.subviews.icon:getMousePos() end,
},
widgets.Label{
text=widgets.makeButtonLabelText{
chars=button_chars,
pens={
{COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE},
{COLOR_WHITE, COLOR_GRAY, COLOR_GRAY, COLOR_WHITE},
{COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE},
},
tileset=toolbar_textures,
tileset_offset=5,
tileset_stride=8,
},
on_click=launch_mass_remove,
visible=function() return self.subviews.icon:getMousePos() end,
},
},
},
}
end

function MassRemoveToolbarOverlay:preUpdateLayout(parent_rect)
self.frame.w = (parent_rect.width+1)//2 - 16
end

function MassRemoveToolbarOverlay:onInput(keys)
if keys.CUSTOM_M then
launch_mass_remove()
return true
end
return MassRemoveToolbarOverlay.super.onInput(self, keys)
end

OVERLAY_WIDGETS = {massremovetoolbar=MassRemoveToolbarOverlay}


if dfhack_flags.module then
return
end
Expand Down