Skip to content

Add toolbar button for gui/design #1425

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Template for new versions:
- `gui/mass-remove`: add 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
- `gui/sitemap`: add a button to the toolbar at the bottom left corner of the screen for launching `gui/sitemap`
- `gui/design`: add a button to the toolbar at the bottom left corner of the screen for launching `gui/design`

## Fixes
- `idle-crafting`: check that units still have crafting needs before creating a job for them
Expand Down
100 changes: 95 additions & 5 deletions gui/design.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ local util = reqscript('internal/design/util')
local utils = require('utils')
local widgets = require('gui.widgets')

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

function launch_design()
dfhack.run_script('gui/design')
end


local Point = util.Point
local getMousePoint = util.getMousePoint

Expand Down Expand Up @@ -168,11 +175,6 @@ function RightClickOverlay:onInput(keys)
end
end

OVERLAY_WIDGETS = {
dimensions=DimensionsOverlay,
rightclick=RightClickOverlay,
}

---
--- HelpWindow
---
Expand Down Expand Up @@ -1565,6 +1567,94 @@ function DesignScreen:onDismiss()
view = nil
end


-- --------------------------------
-- DesignToolbarOverlay
--

DesignToolbarOverlay = defclass(DesignToolbarOverlay, overlay.OverlayWidget)
DesignToolbarOverlay.ATTRS{
desc='Adds a button to the toolbar at the bottom of the screen for launching gui/design.',
default_pos={x=50, y=-1},
Copy link
Member

@myk002 myk002 Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This position isn't going to work:
image

mayyybe here in the dig toolbar?
image

though that bar is already quite crowded..

another option could be moving the sitemap button over one tile and placing this next to it, but that might also be too crowded. The space next to the sitemap button is there for a reason.

default_enabled=true,
viewscreens='dwarfmode',
frame={w=28, h=10},
}

function DesignToolbarOverlay:init()
local button_chars = {
{218, 196, 196, 191},
{179, '[', ']', 179},
{192, 196, 196, 217},
}

self:addviews{
widgets.Panel{
frame={t=0, l=0, w=20, 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 the design', NEWLINE,
'interface.', NEWLINE,
NEWLINE,
{text='Hotkey: ', pen=COLOR_GRAY}, {key='CUSTOM_CTRL_D'},
},
},
},
},
widgets.Panel{
view_id='icon',
frame={b=0, l=0, w=4, h=3},
subviews={
widgets.Label{
text=widgets.makeButtonLabelText{
chars=button_chars,
pens={
{COLOR_GRAY, COLOR_GRAY, COLOR_GRAY, COLOR_GRAY},
{COLOR_GRAY, COLOR_BLUE, COLOR_BLUE, COLOR_GRAY},
{COLOR_GRAY, COLOR_GRAY, COLOR_GRAY, COLOR_GRAY},
},
tileset=toolbar_textures,
tileset_offset=1,
tileset_stride=8,
},
on_click=launch_design,
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_BLUE, COLOR_BLUE, COLOR_WHITE},
{COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE},
},
tileset=toolbar_textures,
tileset_offset=5,
tileset_stride=8,
},
on_click=launch_design,
visible=function() return self.subviews.icon:getMousePos() end,
},
},
},
}
end

function DesignToolbarOverlay:onInput(keys)
return DesignToolbarOverlay.super.onInput(self, keys)
end
Comment on lines +1648 to +1650
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is a noop and can be removed


OVERLAY_WIDGETS = {
dimensions=DimensionsOverlay,
rightclick=RightClickOverlay,
toolbar=DesignToolbarOverlay
}

if dfhack_flags.module then return end

if not dfhack.isMapLoaded() then
Expand Down
Loading