|
1 | 1 | -- building/construction mass removal/suspension tool |
2 | 2 |
|
| 3 | +--@ module = true |
| 4 | + |
| 5 | +local toolbar_textures = dfhack.textures.loadTileset('hack/data/art/mass_remove_toolbar.png', 8, 12) |
| 6 | + |
3 | 7 | local gui = require('gui') |
4 | 8 | local guidm = require('gui.dwarfmode') |
5 | 9 | local utils = require('utils') |
6 | 10 | local widgets = require('gui.widgets') |
| 11 | +local overlay = require('plugins.overlay') |
7 | 12 |
|
8 | 13 | local function noop() |
9 | 14 | end |
10 | 15 |
|
| 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 | + |
11 | 22 | local function get_first_job(bld) |
12 | 23 | if not bld then return end |
13 | 24 | if #bld.jobs ~= 1 then return end |
@@ -383,6 +394,95 @@ function MassRemoveScreen:onDismiss() |
383 | 394 | view = nil |
384 | 395 | end |
385 | 396 |
|
| 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 | + |
386 | 486 | if dfhack_flags.module then |
387 | 487 | return |
388 | 488 | end |
|
0 commit comments