diff --git a/data/dfhack-config/quickfort/quickfort.txt b/data/dfhack-config/quickfort/quickfort.txt index e3f5aeaec..92af2909e 100644 --- a/data/dfhack-config/quickfort/quickfort.txt +++ b/data/dfhack-config/quickfort/quickfort.txt @@ -4,8 +4,8 @@ # temporarily overridden in the active session with the `quickfort set` command. # # If you have edited this file but want to revert to "factory defaults", delete -# this file and a fresh one will be copied from -# dfhack-config/default/quickfort/quickfort.txt the next time you start DFHack. +# this file and a default one will be regenerated for you the next time you +# start DFHack. # Directory tree to search for blueprints. Can be set to an absolute or relative # path. If set to a relative path, resolves to a directory under the DF folder. @@ -30,8 +30,8 @@ query_unsafe=false # Set to the maximum number of resources you want assigned to stockpiles of the # relevant types. Set to -1 for DF defaults (number of stockpile tiles for # stockpiles that take barrels and bins, 1 wheelbarrow for stone stockpiles). -# The default here for wheelbarrows is 0 since using wheelbarrows normally -# *decreases* the efficiency of your fort. +# The default here for wheelbarrows is 0 since restricting stockpiles to a +# single wheelbarrow can drastically *decrease* the efficiency of your fort. stockpiles_max_barrels=-1 stockpiles_max_bins=-1 stockpiles_max_wheelbarrows=0 diff --git a/docs/changelog.txt b/docs/changelog.txt index 5e1904e43..0fa791fd8 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -39,6 +39,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Misc Improvements - `hotkeys`: clicking on the DFHack logo no longer closes the popup menu +- `orders`: orders plugin functionality is now offered via an overlay widget when the manager orders screen is open ## Documentation diff --git a/docs/dev/overlay-dev-guide.rst b/docs/dev/overlay-dev-guide.rst index bce623180..50998530a 100644 --- a/docs/dev/overlay-dev-guide.rst +++ b/docs/dev/overlay-dev-guide.rst @@ -125,10 +125,6 @@ The ``overlay.OverlayWidget`` superclass defines the following class attributes: not annoy the player. Set to 0 to be called at the maximum rate. Be aware that running more often than you really need to will impact game FPS, especially if your widget can run while the game is unpaused. -- ``always_enabled`` (default: ``false``) - Set this to ``true`` if you don't want to let the user disable the widget. - This is useful for widgets that are controlled purely through their - triggers. See `gui/pathable` for an example. Registering a widget with the overlay framework *********************************************** diff --git a/docs/plugins/orders.rst b/docs/plugins/orders.rst index 8beb246e4..5dfe23758 100644 --- a/docs/plugins/orders.rst +++ b/docs/plugins/orders.rst @@ -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 ------------------ diff --git a/library/lua/gui/dialogs.lua b/library/lua/gui/dialogs.lua index e7228db1e..0b923e7c0 100644 --- a/library/lua/gui/dialogs.lua +++ b/library/lua/gui/dialogs.lua @@ -218,9 +218,9 @@ end function ListBox:onRenderFrame(dc,rect) ListBox.super.onRenderFrame(self,dc,rect) - if self.select2_hint then - dc:seek(rect.x1+2,rect.y2):key('SEC_SELECT'):string(': '..self.select2_hint,COLOR_GREY) - end + --if self.select2_hint then + -- dc:seek(rect.x1+2,rect.y2):key('SEC_SELECT'):string(': '..self.select2_hint,COLOR_GREY) + --end end function ListBox:getWantedFrameSize() diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 3d36b95fc..a05ae6a83 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -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) diff --git a/plugins/lua/fortplan.lua b/plugins/lua/fortplan.lua deleted file mode 100644 index 71e69c69d..000000000 --- a/plugins/lua/fortplan.lua +++ /dev/null @@ -1,13 +0,0 @@ -local _ENV = mkmodule('plugins.fortplan') - -require('dfhack.buildings') - -function construct_building_from_params(building_type, x, y, z) - local pos = xyz2pos(x, y, z) - local bld, err = - dfhack.buildings.constructBuilding{type=building_type, pos=pos} - if err then error(err) end - return bld -end - -return _ENV diff --git a/plugins/lua/orders.lua b/plugins/lua/orders.lua new file mode 100644 index 000000000..aecd940d6 --- /dev/null +++ b/plugins/lua/orders.lua @@ -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 diff --git a/plugins/lua/overlay.lua b/plugins/lua/overlay.lua index cf599fd08..b90c1c651 100644 --- a/plugins/lua/overlay.lua +++ b/plugins/lua/overlay.lua @@ -184,7 +184,6 @@ end local function do_disable(args, quiet) local disable_fn = function(name, db_entry) - if db_entry.widget.always_enabled then return end overlay_config[name].enabled = false if db_entry.widget.hotspot then active_hotspot_widgets[name] = nil @@ -252,7 +251,7 @@ local function load_widget(name, widget_class) local config = overlay_config[name] config.pos = sanitize_pos(config.pos or widget.default_pos) widget.frame = make_frame(config.pos, widget.frame) - if config.enabled or widget.always_enabled then + if config.enabled then do_enable(name, true, true) else config.enabled = false @@ -492,7 +491,6 @@ OverlayWidget.ATTRS{ hotspot=false, -- whether to call overlay_onupdate on all screens viewscreens={}, -- override with associated viewscreen or list of viewscrens overlay_onupdate_max_freq_seconds=5, -- throttle calls to overlay_onupdate - always_enabled=false, -- for overlays that should never be disabled } function OverlayWidget:init()