Merge pull request #2694 from myk002/myk_orders_overlay

first attempt at a manager orders overlay
develop
Myk 2023-01-22 17:09:42 -08:00 committed by GitHub
commit 7e51d3e5aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 113 additions and 1 deletions

@ -38,6 +38,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Fixes
## Misc Improvements
- `orders`: orders plugin functionality is now offered via an overlay widget when the manager orders screen is open
## Documentation

@ -40,6 +40,17 @@ Examples
Import manager orders from the library that keep your fort stocked with
basic essentials.
Overlay
-------
Orders plugin functionality is directly available when the manager orders screen
is open via an `overlay` widget. There are hotkeys assigned to export, import,
sort, and clear. You can also click on the hotkey hints as if they were buttons.
Clearing will ask for confirmation before acting.
If you want to change where the hotkey hints appear, you can move them via
`gui/overlay`.
The orders library
------------------

@ -134,7 +134,7 @@ dfhack_plugin(misery misery.cpp)
#dfhack_plugin(mode mode.cpp)
#dfhack_plugin(mousequery mousequery.cpp)
dfhack_plugin(nestboxes nestboxes.cpp)
dfhack_plugin(orders orders.cpp LINK_LIBRARIES jsoncpp_static)
dfhack_plugin(orders orders.cpp LINK_LIBRARIES jsoncpp_static lua)
dfhack_plugin(overlay overlay.cpp LINK_LIBRARIES lua)
dfhack_plugin(pathable pathable.cpp LINK_LIBRARIES lua)
#dfhack_plugin(petcapRemover petcapRemover.cpp)

@ -0,0 +1,100 @@
local _ENV = mkmodule('plugins.orders')
local dialogs = require('gui.dialogs')
local gui = require('gui')
local overlay = require('plugins.overlay')
local widgets = require('gui.widgets')
--
-- OrdersOverlay
--
local function is_orders_panel_visible()
local info = df.global.game.main_interface.info
return info.open and info.current_mode == df.info_interface_mode_type.WORK_ORDERS
end
local function do_sort()
dfhack.run_command('orders', 'sort')
end
local function do_clear()
dialogs.showYesNoPrompt('Clear manager orders?',
'Are you sure you want to clear the manager orders?', nil,
function() dfhack.run_command('orders', 'clear') end)
end
local function do_import()
local output = dfhack.run_command_silent('orders', 'list')
dialogs.ListBox{
frame_title='Import Manager Orders',
with_filter=true,
choices=output:split('\n'),
on_select=function(idx, choice)
dfhack.run_command('orders', 'import', choice.text)
end,
}:show()
end
local function do_export()
dialogs.InputBox{
frame_title='Export Manager Orders',
on_input=function(text)
dfhack.run_command('orders', 'export', text)
end
}:show()
end
OrdersOverlay = defclass(OrdersOverlay, overlay.OverlayWidget)
OrdersOverlay.ATTRS{
default_pos={x=61,y=-6},
viewscreens='dwarfmode',
frame={w=30, h=4},
frame_style=gui.GREY_LINE_FRAME,
frame_background=gui.CLEAR_PEN,
}
function OrdersOverlay:init()
self:addviews{
widgets.HotkeyLabel{
frame={t=0, l=0},
label='import',
key='CUSTOM_CTRL_I',
on_activate=do_import,
},
widgets.HotkeyLabel{
frame={t=1, l=0},
label='export',
key='CUSTOM_CTRL_E',
on_activate=do_export,
},
widgets.HotkeyLabel{
frame={t=0, l=15},
label='sort',
key='CUSTOM_CTRL_O',
on_activate=do_sort,
},
widgets.HotkeyLabel{
frame={t=1, l=15},
label='clear',
key='CUSTOM_CTRL_C',
on_activate=do_clear,
},
}
end
function OrdersOverlay:render(dc)
if not is_orders_panel_visible() then return false end
OrdersOverlay.super.render(self, dc)
end
function OrdersOverlay:onInput(keys)
if not is_orders_panel_visible() then return false end
OrdersOverlay.super.onInput(self, keys)
end
OVERLAY_WIDGETS = {
overlay=OrdersOverlay,
}
return _ENV