diff --git a/changelog.txt b/changelog.txt index c4cb15b52..56aa6b584 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 diff --git a/docs/gui/mass-remove.rst b/docs/gui/mass-remove.rst index 6a3becb8f..1a8ea4b54 100644 --- a/docs/gui/mass-remove.rst +++ b/docs/gui/mass-remove.rst @@ -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. diff --git a/gui/mass-remove.lua b/gui/mass-remove.lua index f138c50d8..fc4546b46 100644 --- a/gui/mass-remove.lua +++ b/gui/mass-remove.lua @@ -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 @@ -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