Skip to content

Commit

Permalink
Merge pull request #1086 from Ajhaa/master
Browse files Browse the repository at this point in the history
gui/autobutcher changes
  • Loading branch information
myk002 authored Apr 25, 2024
2 parents 3ffccfb + d6f223b commit 467f4b8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 14 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Template for new versions:
## Fixes

## Misc Improvements
- `gui/autobutcher`: add functionality to butcher and unbutcher all animals
- `gui/autobutcher`: add warning if autobutcher is disabled
- `combine`: respect container limits
- `combine`: reduce combined drink sizes to 25

Expand Down
76 changes: 62 additions & 14 deletions gui/autobutcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function WatchList:init()

local window = widgets.Window{
frame_title='Autobutcher',
frame={w=97, h=30},
frame={w=97, h=31},
resizable=true,
subviews={
widgets.CycleHotkeyLabel{
Expand Down Expand Up @@ -190,7 +190,7 @@ function WatchList:init()
},
widgets.Panel{
view_id='list_panel',
frame={t=2, l=0, r=0, b=7},
frame={t=2, l=0, r=0, b=8},
frame_style=gui.FRAME_INTERIOR,
subviews={
widgets.CycleHotkeyLabel{
Expand Down Expand Up @@ -306,17 +306,25 @@ function WatchList:init()
frame={t=1, l=82},
text='ordered'
},
widgets.Label{
view_id='disabled_warning',
visible=function() return not plugin.isEnabled() end,
frame={t=3, l=8, h=1},
text={"Enable autobutcher to change settings"},
text_pen=COLOR_YELLOW
},
widgets.List{
view_id='list',
frame={t=3, b=0},
visible=plugin.isEnabled,
on_double_click = self:callback('onDoubleClick'),
on_double_click2 = self:callback('zeroOut'),
},
},
},
widgets.Panel{
view_id='footer',
frame={l=0, r=0, b=0, h=6},
frame={l=0, r=0, b=0, h=7},
subviews={
widgets.Label{
frame={t=0, l=0},
Expand All @@ -343,68 +351,84 @@ function WatchList:init()
},
widgets.HotkeyLabel{
view_id='fa',
frame={t=3, l=11},
frame={t=3, l=17},
key='CUSTOM_SHIFT_F',
label='F adults',
auto_width=true,
on_activate=self:callback('editVal', 'female adults', 'fa'),
},
widgets.HotkeyLabel{
view_id='ma',
frame={t=4, l=11},
frame={t=4, l=17},
key='CUSTOM_SHIFT_M',
label='M adults',
auto_width=true,
on_activate=self:callback('editVal', 'male adults', 'ma'),
},
widgets.HotkeyLabel{
view_id='butcher',
frame={t=3, l=24},
frame={t=5, l=0},
key='CUSTOM_B',
label='Butcher race',
auto_width=true,
on_activate=self:callback('onButcherRace'),
},
widgets.HotkeyLabel{
view_id='unbutcher',
frame={t=4, l=24},
frame={t=5, l=17},
key='CUSTOM_SHIFT_B',
label='Unbutcher race',
auto_width=true,
on_activate=self:callback('onUnbutcherRace'),
},
widgets.HotkeyLabel{
view_id='watch',
frame={t=3, l=43},
frame={t=3, l=36},
key='CUSTOM_W',
label='Toggle watch',
auto_width=true,
on_activate=self:callback('onToggleWatching'),
},
widgets.HotkeyLabel{
frame={t=4, l=43},
frame={t=4, l=36},
key='CUSTOM_X',
label='Delete row',
auto_width=true,
on_activate=self:callback('onDeleteEntry'),
},
widgets.HotkeyLabel{
frame={t=3, l=60},
frame={t=3, l=54},
key='CUSTOM_R',
label='Set row targets to 0',
auto_width=true,
on_activate=self:callback('zeroOut'),
},
widgets.HotkeyLabel{
frame={t=4, l=60},
frame={t=4, l=54},
key='CUSTOM_SHIFT_R',
label='Set row targets to N',
auto_width=true,
on_activate=self:callback('onSetRow'),
},
widgets.HotkeyLabel{
view_id='butcher_all',
frame={t=5, l=36},
key='CUSTOM_E',
label='Butcher all',
auto_width=true,
on_activate=self:callback('onButcherAll'),
},
widgets.HotkeyLabel{
view_id='unbutcher_all',
frame={t=5, l=54},
key='CUSTOM_SHIFT_E',
label='Unbutcher all',
auto_width=true,
on_activate=self:callback('onUnbutcherAll'),
},
widgets.ToggleHotkeyLabel{
view_id='enable_toggle',
frame={t=5, l=0, w=26},
frame={t=6, l=0, w=26},
label='Autobutcher is',
key='CUSTOM_SHIFT_A',
options={{value=true, label='Enabled', pen=COLOR_GREEN},
Expand All @@ -416,7 +440,7 @@ function WatchList:init()
},
widgets.ToggleHotkeyLabel{
view_id='autowatch_toggle',
frame={t=5, l=43, w=24},
frame={t=6, l=36, w=24},
label='Autowatch is',
key='CUSTOM_SHIFT_W',
options={{value=true, label='Enabled', pen=COLOR_GREEN},
Expand Down Expand Up @@ -507,8 +531,9 @@ function WatchList:refresh(sort_widget, sort_fn)

local choices = {}

-- first two rows are for "edit all races" and "edit new races"
local settings = plugin.autobutcher_getSettings()

-- first two rows are for "edit all races" and "edit new races"
table.insert(choices, {
text=make_row_text('!! ALL RACES PLUS NEW', settings),
race=1,
Expand Down Expand Up @@ -710,6 +735,29 @@ function WatchList:onButcherRace()
self:refresh()
end

function WatchList:onUnbutcherAll()
for _, data in ipairs(plugin.autobutcher_getWatchList()) do
plugin.autobutcher_unbutcherRace(data.id)
end

self:refresh()
end

function WatchList:onButcherAll()
dlg.showYesNoPrompt(
'Butcher all animals',
'Warning! This will mark ALL animals for butchering.'..NEWLINE..'Proceed with caution.',
COLOR_YELLOW,
function()
for _, data in ipairs(plugin.autobutcher_getWatchList()) do
plugin.autobutcher_butcherRace(data.id)
end

self:refresh()
end
)
end

function WatchList:onDismiss()
view = nil
end
Expand Down

0 comments on commit 467f4b8

Please sign in to comment.