Skip to content

Commit 22842e4

Browse files
authored
Merge pull request #1422 from SquidCoderIndustries/squid-destroytoolbar
Create toolbar overlay for mass-remove
2 parents 58badec + c14f328 commit 22842e4

3 files changed

Lines changed: 114 additions & 1 deletion

File tree

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Template for new versions:
2929
## New Tools
3030

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

3535
## Fixes

docs/gui/mass-remove.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,16 @@ Usage
1919
::
2020

2121
gui/mass-remove
22+
23+
Overlay
24+
-------
25+
26+
This tool also provides one overlay that is managed by the `overlay`
27+
framework.
28+
29+
massremovetoolbar
30+
~~~~~~~~~~~~~~~~~
31+
32+
The ``mass-remove.massremovetoolbar`` overlay adds a button to the toolbar at the bottom of the
33+
screen when eraser mode is active. It allows you to conveniently open the ``gui/mass-remove``
34+
interface.

gui/mass-remove.lua

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
-- building/construction mass removal/suspension tool
22

3+
--@ module = true
4+
5+
local toolbar_textures = dfhack.textures.loadTileset('hack/data/art/mass_remove_toolbar.png', 8, 12)
6+
37
local gui = require('gui')
48
local guidm = require('gui.dwarfmode')
59
local utils = require('utils')
610
local widgets = require('gui.widgets')
11+
local overlay = require('plugins.overlay')
712

813
local function noop()
914
end
1015

16+
function launch_mass_remove()
17+
local vs = dfhack.gui.getDFViewscreen(true)
18+
gui.simulateInput(vs,'LEAVESCREEN')
19+
dfhack.run_script('gui/mass-remove')
20+
end
21+
1122
local function get_first_job(bld)
1223
if not bld then return end
1324
if #bld.jobs ~= 1 then return end
@@ -383,6 +394,95 @@ function MassRemoveScreen:onDismiss()
383394
view = nil
384395
end
385396

397+
398+
-- --------------------------------
399+
-- MassRemoveToolbarOverlay
400+
--
401+
402+
MassRemoveToolbarOverlay = defclass(MassRemoveToolbarOverlay, overlay.OverlayWidget)
403+
MassRemoveToolbarOverlay.ATTRS{
404+
desc='Adds a button to the erase toolbar to open the mass removal tool',
405+
default_pos={x=42, y=-4},
406+
default_enabled=true,
407+
viewscreens='dwarfmode/Designate/ERASE',
408+
frame={w=26, h=11},
409+
}
410+
411+
function MassRemoveToolbarOverlay:init()
412+
local button_chars = {
413+
{218, 196, 196, 191},
414+
{179, 'M', 'R', 179},
415+
{192, 196, 196, 217},
416+
}
417+
418+
self:addviews{
419+
widgets.Panel{
420+
frame={t=0, r=0, w=26, h=6},
421+
frame_style=gui.FRAME_PANEL,
422+
frame_background=gui.CLEAR_PEN,
423+
frame_inset={l=1, r=1},
424+
visible=function() return self.subviews.icon:getMousePos() end,
425+
subviews={
426+
widgets.Label{
427+
text={
428+
'Open mass removal', NEWLINE,
429+
'interface.', NEWLINE,
430+
NEWLINE,
431+
{text='Hotkey: ', pen=COLOR_GRAY}, {key='CUSTOM_M'},
432+
},
433+
},
434+
},
435+
},
436+
widgets.Panel{
437+
view_id='icon',
438+
frame={b=0, r=22, w=4, h=3},
439+
subviews={
440+
widgets.Label{
441+
text=widgets.makeButtonLabelText{
442+
chars=button_chars,
443+
pens=COLOR_GRAY,
444+
tileset=toolbar_textures,
445+
tileset_offset=1,
446+
tileset_stride=8,
447+
},
448+
on_click=launch_mass_remove,
449+
visible=function () return not self.subviews.icon:getMousePos() end,
450+
},
451+
widgets.Label{
452+
text=widgets.makeButtonLabelText{
453+
chars=button_chars,
454+
pens={
455+
{COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE},
456+
{COLOR_WHITE, COLOR_GRAY, COLOR_GRAY, COLOR_WHITE},
457+
{COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE},
458+
},
459+
tileset=toolbar_textures,
460+
tileset_offset=5,
461+
tileset_stride=8,
462+
},
463+
on_click=launch_mass_remove,
464+
visible=function() return self.subviews.icon:getMousePos() end,
465+
},
466+
},
467+
},
468+
}
469+
end
470+
471+
function MassRemoveToolbarOverlay:preUpdateLayout(parent_rect)
472+
self.frame.w = (parent_rect.width+1)//2 - 16
473+
end
474+
475+
function MassRemoveToolbarOverlay:onInput(keys)
476+
if keys.CUSTOM_M then
477+
launch_mass_remove()
478+
return true
479+
end
480+
return MassRemoveToolbarOverlay.super.onInput(self, keys)
481+
end
482+
483+
OVERLAY_WIDGETS = {massremovetoolbar=MassRemoveToolbarOverlay}
484+
485+
386486
if dfhack_flags.module then
387487
return
388488
end

0 commit comments

Comments
 (0)