Skip to content

Commit 16bd197

Browse files
authored
Merge pull request #1536 from pajawojciech/log-cleaner
Add gui to logcleaner
2 parents 103e1b3 + 4484d32 commit 16bd197

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Template for new versions:
2929
# Future
3030

3131
## New Tools
32+
- `gui/logcleaner`: graphical overlay for configuring the logcleaner plugin with enable and filter toggles.
3233

3334
## New Features
3435
- `trackstop`: can now modify pressure plates; permits minecart and creature triggers to be set beyond normal sensitivity

docs/gui/logcleaner.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
gui/logcleaner
2+
==============
3+
4+
.. dfhack-tool::
5+
:summary: Configure logcleaner plugin settings.
6+
:tags: fort auto units
7+
8+
This is the configuration interface for the `logcleaner` plugin. You can enable
9+
or disable the plugin and toggle which report types are automatically cleared.
10+
11+
Usage
12+
-----
13+
14+
::
15+
16+
gui/logcleaner
17+
18+
Hotkeys
19+
---------
20+
21+
- Shift+E: Enable/disable the plugin
22+
- Shift+C: Toggle combat report clearing
23+
- Shift+S: Toggle sparring report clearing (default enabled)
24+
- Shift+H: Toggle hunting report clearing

gui/logcleaner.lua

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
-- configuration and status panel interface for logcleaner
2+
3+
local gui = require('gui')
4+
local plugin = require('plugins.logcleaner')
5+
local widgets = require('gui.widgets')
6+
7+
Logcleaner = defclass(Logcleaner, widgets.Window)
8+
Logcleaner.ATTRS{
9+
frame_title='Logcleaner',
10+
frame={w=45, h=14},
11+
frame_inset=1,
12+
}
13+
14+
function Logcleaner:init()
15+
self:addviews{
16+
widgets.ToggleHotkeyLabel{
17+
view_id='enable_toggle',
18+
frame={t=0, l=0},
19+
key='CUSTOM_SHIFT_E',
20+
label='logcleaner is',
21+
options={
22+
{value=true, label='Enabled', pen=COLOR_GREEN},
23+
{value=false, label='Disabled', pen=COLOR_RED},
24+
},
25+
on_change=function(val)
26+
dfhack.run_command({val and 'enable' or 'disable', 'logcleaner'})
27+
end,
28+
},
29+
widgets.Label{
30+
frame={t=2, l=0},
31+
text='Select log types to automatically clear.',
32+
text_pen=COLOR_GREY,
33+
},
34+
widgets.ToggleHotkeyLabel{
35+
view_id='combat_toggle',
36+
frame={t=4, l=0},
37+
key='CUSTOM_SHIFT_C',
38+
label='Combat:',
39+
options={
40+
{value=true, label='Enabled', pen=COLOR_GREEN},
41+
{value=false, label='Disabled', pen=COLOR_RED},
42+
},
43+
on_change=function(val)
44+
plugin.logcleaner_setCombat(val)
45+
end,
46+
},
47+
widgets.ToggleHotkeyLabel{
48+
view_id='sparring_toggle',
49+
frame={t=6, l=0},
50+
key='CUSTOM_SHIFT_S',
51+
label='Sparring:',
52+
options={
53+
{value=true, label='Enabled', pen=COLOR_GREEN},
54+
{value=false, label='Disabled', pen=COLOR_RED},
55+
},
56+
on_change=function(val)
57+
plugin.logcleaner_setSparring(val)
58+
end,
59+
},
60+
widgets.ToggleHotkeyLabel{
61+
view_id='hunting_toggle',
62+
frame={t=8, l=0},
63+
key='CUSTOM_SHIFT_H',
64+
label='Hunting:',
65+
options={
66+
{value=true, label='Enabled', pen=COLOR_GREEN},
67+
{value=false, label='Disabled', pen=COLOR_RED},
68+
},
69+
on_change=function(val)
70+
plugin.logcleaner_setHunting(val)
71+
end,
72+
},
73+
}
74+
end
75+
76+
function Logcleaner:onRenderBody(dc)
77+
self.subviews.enable_toggle:setOption(plugin.isEnabled())
78+
self.subviews.combat_toggle:setOption(plugin.logcleaner_getCombat())
79+
self.subviews.sparring_toggle:setOption(plugin.logcleaner_getSparring())
80+
self.subviews.hunting_toggle:setOption(plugin.logcleaner_getHunting())
81+
Logcleaner.super.onRenderBody(self, dc)
82+
end
83+
84+
--
85+
-- LogcleanerScreen
86+
--
87+
88+
LogcleanerScreen = defclass(LogcleanerScreen, gui.ZScreen)
89+
LogcleanerScreen.ATTRS{
90+
focus_path='logcleaner',
91+
}
92+
93+
function LogcleanerScreen:init()
94+
self:addviews{Logcleaner{}}
95+
end
96+
97+
function LogcleanerScreen:onDismiss()
98+
view = nil
99+
end
100+
101+
if not dfhack.isMapLoaded() or not dfhack.world.isFortressMode() then
102+
qerror('logcleaner requires a fortress map to be loaded')
103+
end
104+
105+
view = view and view:raise() or LogcleanerScreen{}:show()

internal/control-panel/registry.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ COMMANDS_BY_IDX = {
140140
{command='hide-tutorials', group='gameplay', mode='system_enable'},
141141
{command='immortal-cravings', group='gameplay', mode='enable'},
142142
{command='light-aquifers-only', group='gameplay', mode='run'},
143+
{command='logcleaner', group='gameplay', mode='enable'},
144+
{command='logcleaner all', group='gameplay', mode='run',
145+
desc='Enable logcleaner with all filters (combat, sparring, hunting).'},
146+
{command='logcleaner sparring', group='gameplay', mode='run',
147+
desc='Enable logcleaner with sparring filter (default).'},
143148
{command='misery', group='gameplay', mode='enable'},
144149
{command='orders-reevaluate', help_command='orders', group='gameplay', mode='repeat',
145150
desc='Invalidates all work orders once a month, allowing conditions to be rechecked.',

0 commit comments

Comments
 (0)