Skip to content

Commit 9fe2a46

Browse files
Add ui button for gui/sitemap (#1423)
* Make sitemap toolbar button overlay Co-authored-by: Myk <myk.taylor@gmail.com>
1 parent 1d67a72 commit 9fe2a46

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Template for new versions:
3131
## New Features
3232
- `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
34+
- `gui/sitemap`: added a button to the toolbar at the bottom left corner of the screen with the other menu buttons for launching `gui/sitemap`
3435

3536
## Fixes
3637

docs/gui/sitemap.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,16 @@ Usage
2424
::
2525

2626
gui/sitemap
27+
28+
Overlay
29+
-------
30+
31+
This tool also provides one overlay that is managed by the `overlay`
32+
framework.
33+
34+
gui/sitemap.toolbar
35+
~~~~~~~~~~~~~~~~~~~
36+
37+
The ``gui/sitemap.toolbar`` overlay adds a button to the toolbar at the bottom left corner of the
38+
screen with the other menu buttons. It allows you to conveniently open the ``gui/sitemap``
39+
interface.

gui/sitemap.lua

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
local gui = require('gui')
44
local utils = require('utils')
55
local widgets = require('gui.widgets')
6+
local overlay = require('plugins.overlay')
7+
8+
local toolbar_textures = dfhack.textures.loadTileset('hack/data/art/sitemap_toolbar.png', 8, 12)
9+
10+
function launch_sitemap()
11+
dfhack.run_script('gui/sitemap')
12+
end
613

714
--
815
-- Sitemap
@@ -353,6 +360,87 @@ function SitemapScreen:onDismiss()
353360
view = nil
354361
end
355362

363+
364+
-- --------------------------------
365+
-- SitemapToolbarOverlay
366+
--
367+
368+
SitemapToolbarOverlay = defclass(SitemapToolbarOverlay, overlay.OverlayWidget)
369+
SitemapToolbarOverlay.ATTRS{
370+
desc='Adds a button to the toolbar at the bottom left corner of the screen for launching gui/sitemap.',
371+
default_pos={x=35, y=-1},
372+
default_enabled=true,
373+
viewscreens='dwarfmode',
374+
frame={w=28, h=9},
375+
}
376+
377+
function SitemapToolbarOverlay:init()
378+
local button_chars = {
379+
{218, 196, 196, 191},
380+
{179, '-', 'O', 179},
381+
{192, 196, 196, 217},
382+
}
383+
384+
self:addviews{
385+
widgets.Panel{
386+
frame={t=0, l=0, w=26, h=5},
387+
frame_style=gui.FRAME_PANEL,
388+
frame_background=gui.CLEAR_PEN,
389+
frame_inset={l=1, r=1},
390+
visible=function() return self.subviews.icon:getMousePos() end,
391+
subviews={
392+
widgets.Label{
393+
text={
394+
'Open the general search', NEWLINE,
395+
'interface.', NEWLINE,
396+
NEWLINE,
397+
{text='Hotkey: ', pen=COLOR_GRAY}, {key='CUSTOM_CTRL_G'},
398+
},
399+
},
400+
},
401+
},
402+
widgets.Panel{
403+
view_id='icon',
404+
frame={b=0, l=0, w=4, h=3},
405+
subviews={
406+
widgets.Label{
407+
text=widgets.makeButtonLabelText{
408+
chars=button_chars,
409+
pens=COLOR_GRAY,
410+
tileset=toolbar_textures,
411+
tileset_offset=1,
412+
tileset_stride=8,
413+
},
414+
on_click=launch_sitemap,
415+
visible=function () return not self.subviews.icon:getMousePos() end,
416+
},
417+
widgets.Label{
418+
text=widgets.makeButtonLabelText{
419+
chars=button_chars,
420+
pens={
421+
{COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE},
422+
{COLOR_WHITE, COLOR_GRAY, COLOR_GRAY, COLOR_WHITE},
423+
{COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE},
424+
},
425+
tileset=toolbar_textures,
426+
tileset_offset=5,
427+
tileset_stride=8,
428+
},
429+
on_click=launch_sitemap,
430+
visible=function() return not not self.subviews.icon:getMousePos() end,
431+
},
432+
},
433+
},
434+
}
435+
end
436+
437+
function SitemapToolbarOverlay:onInput(keys)
438+
return SitemapToolbarOverlay.super.onInput(self, keys)
439+
end
440+
441+
OVERLAY_WIDGETS = {toolbar=SitemapToolbarOverlay}
442+
443+
356444
if dfhack_flags.module then
357445
return
358446
end

0 commit comments

Comments
 (0)