diff --git a/changelog.txt b/changelog.txt index d9d0d44ea..832ef011d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -27,6 +27,7 @@ Template for new versions: # Future ## New Tools +- `gui/logcleaner`: graphical overlay for configuring the logcleaner plugin with enable and filter toggles. ## New Features diff --git a/docs/gui/logcleaner.rst b/docs/gui/logcleaner.rst new file mode 100644 index 000000000..3a3547fb9 --- /dev/null +++ b/docs/gui/logcleaner.rst @@ -0,0 +1,24 @@ +gui/logcleaner +============== + +.. dfhack-tool:: + :summary: Configure logcleaner plugin settings. + :tags: fort auto units + +This is the configuration interface for the `logcleaner` plugin. You can enable +or disable the plugin and toggle which report types are automatically cleared. + +Usage +----- + +:: + + gui/logcleaner + +Hotkeys +--------- + +- Shift+E: Enable/disable the plugin +- Shift+C: Toggle combat report clearing +- Shift+S: Toggle sparring report clearing (default enabled) +- Shift+H: Toggle hunting report clearing diff --git a/gui/logcleaner.lua b/gui/logcleaner.lua new file mode 100644 index 000000000..3b7b7edf6 --- /dev/null +++ b/gui/logcleaner.lua @@ -0,0 +1,105 @@ +-- configuration and status panel interface for logcleaner + +local gui = require('gui') +local plugin = require('plugins.logcleaner') +local widgets = require('gui.widgets') + +Logcleaner = defclass(Logcleaner, widgets.Window) +Logcleaner.ATTRS{ + frame_title='Logcleaner', + frame={w=45, h=14}, + frame_inset=1, +} + +function Logcleaner:init() + self:addviews{ + widgets.ToggleHotkeyLabel{ + view_id='enable_toggle', + frame={t=0, l=0}, + key='CUSTOM_SHIFT_E', + label='logcleaner is', + options={ + {value=true, label='Enabled', pen=COLOR_GREEN}, + {value=false, label='Disabled', pen=COLOR_RED}, + }, + on_change=function(val) + dfhack.run_command({val and 'enable' or 'disable', 'logcleaner'}) + end, + }, + widgets.Label{ + frame={t=2, l=0}, + text='Select log types to automatically clear.', + text_pen=COLOR_GREY, + }, + widgets.ToggleHotkeyLabel{ + view_id='combat_toggle', + frame={t=4, l=0}, + key='CUSTOM_SHIFT_C', + label='Combat:', + options={ + {value=true, label='Enabled', pen=COLOR_GREEN}, + {value=false, label='Disabled', pen=COLOR_RED}, + }, + on_change=function(val) + plugin.logcleaner_setCombat(val) + end, + }, + widgets.ToggleHotkeyLabel{ + view_id='sparring_toggle', + frame={t=6, l=0}, + key='CUSTOM_SHIFT_S', + label='Sparring:', + options={ + {value=true, label='Enabled', pen=COLOR_GREEN}, + {value=false, label='Disabled', pen=COLOR_RED}, + }, + on_change=function(val) + plugin.logcleaner_setSparring(val) + end, + }, + widgets.ToggleHotkeyLabel{ + view_id='hunting_toggle', + frame={t=8, l=0}, + key='CUSTOM_SHIFT_H', + label='Hunting:', + options={ + {value=true, label='Enabled', pen=COLOR_GREEN}, + {value=false, label='Disabled', pen=COLOR_RED}, + }, + on_change=function(val) + plugin.logcleaner_setHunting(val) + end, + }, + } +end + +function Logcleaner:onRenderBody(dc) + self.subviews.enable_toggle:setOption(plugin.isEnabled()) + self.subviews.combat_toggle:setOption(plugin.logcleaner_getCombat()) + self.subviews.sparring_toggle:setOption(plugin.logcleaner_getSparring()) + self.subviews.hunting_toggle:setOption(plugin.logcleaner_getHunting()) + Logcleaner.super.onRenderBody(self, dc) +end + +-- +-- LogcleanerScreen +-- + +LogcleanerScreen = defclass(LogcleanerScreen, gui.ZScreen) +LogcleanerScreen.ATTRS{ + focus_path='logcleaner', +} + +function LogcleanerScreen:init() + self:addviews{Logcleaner{}} +end + +function LogcleanerScreen:onDismiss() + view = nil +end + +if not dfhack.isMapLoaded() or not dfhack.world.isFortressMode() then + qerror('logcleaner requires a fortress map to be loaded') +end + +view = view and view:raise() or LogcleanerScreen{}:show() diff --git a/internal/control-panel/registry.lua b/internal/control-panel/registry.lua index 7187e7e8d..cb4ad82f0 100644 --- a/internal/control-panel/registry.lua +++ b/internal/control-panel/registry.lua @@ -140,6 +140,11 @@ COMMANDS_BY_IDX = { {command='hide-tutorials', group='gameplay', mode='system_enable'}, {command='immortal-cravings', group='gameplay', mode='enable'}, {command='light-aquifers-only', group='gameplay', mode='run'}, + {command='logcleaner', group='gameplay', mode='enable'}, + {command='logcleaner all', group='gameplay', mode='run', + desc='Enable logcleaner with all filters (combat, sparring, hunting).'}, + {command='logcleaner sparring', group='gameplay', mode='run', + desc='Enable logcleaner with sparring filter (default).'}, {command='misery', group='gameplay', mode='enable'}, {command='orders-reevaluate', help_command='orders', group='gameplay', mode='repeat', desc='Invalidates all work orders once a month, allowing conditions to be rechecked.',