Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Template for new versions:
## New Tools

## New Features
- `sort`: added ``Uniformed`` filter to squad assignment screen to filter dwarves with mining, woodcutting, or hunting labors

## Fixes

Expand Down
73 changes: 48 additions & 25 deletions plugins/lua/sort.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1029,12 +1029,29 @@ function SquadFilterOverlay:init()

local left_panel = widgets.Panel{
view_id='left_panel',
frame={t=1, b=0, l=0, w=NARROW_WIDTH-4},
frame={t=0, b=0, l=0, w=NARROW_WIDTH-4},
visible=true,
subviews={
widgets.HotkeyLabel{
view_id='toggle_all',
frame={t=0, l=0},
key='CUSTOM_SHIFT_A',
label='Toggle all',
on_activate=function()
local target = self.subviews.military:getOptionValue() == 'exclude' and 'include' or 'exclude'
self.subviews.military:setOption(target)
self.subviews.officials:setOption(target)
self.subviews.nobles:setOption(target)
self.subviews.infant:setOption(target)
self.subviews.unstable:setOption(target)
self.subviews.maimed:setOption(target)
self.subviews.labor_conflict:setOption(target)
poke_list()
end,
},
widgets.CycleHotkeyLabel{
view_id='military',
frame={t=0, l=0},
frame={t=1, l=0},
key='CUSTOM_SHIFT_Q',
label='Other squads:',
options={
Expand All @@ -1047,7 +1064,7 @@ function SquadFilterOverlay:init()
},
widgets.CycleHotkeyLabel{
view_id='officials',
frame={t=1, l=0},
frame={t=2, l=0},
key='CUSTOM_SHIFT_O',
label=' Officials:',
options={
Expand All @@ -1060,7 +1077,7 @@ function SquadFilterOverlay:init()
},
widgets.CycleHotkeyLabel{
view_id='nobles',
frame={t=2, l=0},
frame={t=3, l=0},
key='CUSTOM_SHIFT_N',
label=' Nobility:',
options={
Expand All @@ -1076,12 +1093,25 @@ function SquadFilterOverlay:init()

local right_panel = widgets.Panel{
view_id='right_panel',
frame={t=1, b=0, r=2, w=NARROW_WIDTH-4},
frame={t=0, b=0, r=2, w=NARROW_WIDTH-4},
visible=false,
subviews={
widgets.CycleHotkeyLabel{
view_id='infant',
view_id='labor_conflict',
frame={t=0, l=0},
key='CUSTOM_SHIFT_U',
label=' Uniformed:',
options={
{label='Include', value='include', pen=COLOR_GREEN},
{label='Only', value='only', pen=COLOR_YELLOW},
{label='Exclude', value='exclude', pen=COLOR_LIGHTRED},
},
initial_option='include',
on_change=poke_list,
},
widgets.CycleHotkeyLabel{
view_id='infant',
frame={t=1, l=0},
key='CUSTOM_SHIFT_M',
label='With infants:',
options={
Expand All @@ -1094,7 +1124,7 @@ function SquadFilterOverlay:init()
},
widgets.CycleHotkeyLabel{
view_id='unstable',
frame={t=1, l=0},
frame={t=2, l=0},
key='CUSTOM_SHIFT_D',
label='Hates combat:',
options={
Expand All @@ -1107,7 +1137,7 @@ function SquadFilterOverlay:init()
},
widgets.CycleHotkeyLabel{
view_id='maimed',
frame={t=2, l=0},
frame={t=3, l=0},
key='CUSTOM_SHIFT_I',
label=' Maimed:',
options={
Expand All @@ -1125,21 +1155,6 @@ function SquadFilterOverlay:init()
frame_style=gui.FRAME_MEDIUM,
frame_background=gui.CLEAR_PEN,
subviews={
widgets.HotkeyLabel{
frame={t=0, w=NARROW_WIDTH-3},
key='CUSTOM_SHIFT_A',
label='Toggle all filters',
on_activate=function()
local target = self.subviews.military:getOptionValue() == 'exclude' and 'include' or 'exclude'
self.subviews.military:setOption(target)
self.subviews.officials:setOption(target)
self.subviews.nobles:setOption(target)
self.subviews.infant:setOption(target)
self.subviews.unstable:setOption(target)
self.subviews.maimed:setOption(target)
poke_list()
end,
},
left_panel,
widgets.Label{
view_id='shifter',
Expand Down Expand Up @@ -1167,9 +1182,8 @@ function SquadFilterOverlay:init()
main_panel,
widgets.Divider{
view_id='divider',
frame={l=NARROW_WIDTH-1, w=1, t=2},
frame={l=NARROW_WIDTH-1, w=1, t=0},
frame_style=gui.FRAME_MEDIUM,
frame_style_t=false,
visible=false,
},
widgets.HelpButton{
Expand Down Expand Up @@ -1253,6 +1267,12 @@ local function is_maimed(unit)
unit.status2.limbs_stand_count == 0
end

local function has_labor_conflict(unit)
return unit.status.labors[df.unit_labor.MINE] or
unit.status.labors[df.unit_labor.CUTWOOD] or
unit.status.labors[df.unit_labor.HUNT]
end

local function filter_matches(unit, filter)
if filter.military == 'only' and not is_in_military(unit) then return false end
if filter.military == 'exclude' and is_in_military(unit) then return false end
Expand All @@ -1266,6 +1286,8 @@ local function filter_matches(unit, filter)
if filter.unstable == 'exclude' and is_unstable(unit) then return false end
if filter.maimed == 'only' and not is_maimed(unit) then return false end
if filter.maimed == 'exclude' and is_maimed(unit) then return false end
if filter.labor_conflict == 'only' and not has_labor_conflict(unit) then return false end
if filter.labor_conflict == 'exclude' and has_labor_conflict(unit) then return false end
return true
end

Expand All @@ -1281,6 +1303,7 @@ function do_squad_filter(unit)
infant=self.subviews.infant:getOptionValue(),
unstable=self.subviews.unstable:getOptionValue(),
maimed=self.subviews.maimed:getOptionValue(),
labor_conflict=self.subviews.labor_conflict:getOptionValue(),
}
return filter_matches(unit, filter)
end
Expand Down