Merge pull request #3684 from myk002/myk_sort_by_race

[zone] offer sort by race on animal assignment screen
develop
Myk 2023-08-19 02:20:10 -07:00 committed by GitHub
commit 4f247b79f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 11 deletions

@ -65,6 +65,7 @@ Template for new versions:
## Misc Improvements ## Misc Improvements
- Surround DFHack-specific UI elements with square brackets instead of red-yellow blocks for better readability - Surround DFHack-specific UI elements with square brackets instead of red-yellow blocks for better readability
- `hotkeys`: don't display DFHack logo in legends mode since it covers up important interface elements. the Ctrl-Shift-C hotkey to bring up the menu and the mouseover hotspot still function, though. - `hotkeys`: don't display DFHack logo in legends mode since it covers up important interface elements. the Ctrl-Shift-C hotkey to bring up the menu and the mouseover hotspot still function, though.
- `sort`: animals are now sortable by race on the assignment screens
## Documentation ## Documentation

@ -56,65 +56,72 @@ local function sort_noop(a, b)
error('sort_noop should not be called') error('sort_noop should not be called')
end end
local function sort_base(a, b) local function sort_by_race_desc(a, b)
if a.data.race == b.data.race then if a.data.race == b.data.race then
return a.data.gender < b.data.gender return a.data.gender < b.data.gender
end end
return a.data.race < b.data.race return a.data.race < b.data.race
end end
local function sort_by_race_asc(a, b)
if a.data.race == b.data.race then
return a.data.gender < b.data.gender
end
return a.data.race > b.data.race
end
local function sort_by_name_desc(a, b) local function sort_by_name_desc(a, b)
if a.search_key == b.search_key then if a.search_key == b.search_key then
return sort_base(a, b) return sort_by_race_desc(a, b)
end end
return a.search_key < b.search_key return a.search_key < b.search_key
end end
local function sort_by_name_asc(a, b) local function sort_by_name_asc(a, b)
if a.search_key == b.search_key then if a.search_key == b.search_key then
return sort_base(a, b) return sort_by_race_desc(a, b)
end end
return a.search_key > b.search_key return a.search_key > b.search_key
end end
local function sort_by_gender_desc(a, b) local function sort_by_gender_desc(a, b)
if a.data.gender == b.data.gender then if a.data.gender == b.data.gender then
return sort_base(a, b) return sort_by_race_desc(a, b)
end end
return a.data.gender < b.data.gender return a.data.gender < b.data.gender
end end
local function sort_by_gender_asc(a, b) local function sort_by_gender_asc(a, b)
if a.data.gender == b.data.gender then if a.data.gender == b.data.gender then
return sort_base(a, b) return sort_by_race_desc(a, b)
end end
return a.data.gender > b.data.gender return a.data.gender > b.data.gender
end end
local function sort_by_disposition_desc(a, b) local function sort_by_disposition_desc(a, b)
if a.data.disposition == b.data.disposition then if a.data.disposition == b.data.disposition then
return sort_base(a, b) return sort_by_race_desc(a, b)
end end
return a.data.disposition < b.data.disposition return a.data.disposition < b.data.disposition
end end
local function sort_by_disposition_asc(a, b) local function sort_by_disposition_asc(a, b)
if a.data.disposition == b.data.disposition then if a.data.disposition == b.data.disposition then
return sort_base(a, b) return sort_by_race_desc(a, b)
end end
return a.data.disposition > b.data.disposition return a.data.disposition > b.data.disposition
end end
local function sort_by_status_desc(a, b) local function sort_by_status_desc(a, b)
if a.data.status == b.data.status then if a.data.status == b.data.status then
return sort_base(a, b) return sort_by_race_desc(a, b)
end end
return a.data.status < b.data.status return a.data.status < b.data.status
end end
local function sort_by_status_asc(a, b) local function sort_by_status_asc(a, b)
if a.data.status == b.data.status then if a.data.status == b.data.status then
return sort_base(a, b) return sort_by_race_desc(a, b)
end end
return a.data.status > b.data.status return a.data.status > b.data.status
end end
@ -145,6 +152,8 @@ function AssignAnimal:init()
{label='disposition'..CH_UP, value=sort_by_disposition_asc}, {label='disposition'..CH_UP, value=sort_by_disposition_asc},
{label='gender'..CH_DN, value=sort_by_gender_desc}, {label='gender'..CH_DN, value=sort_by_gender_desc},
{label='gender'..CH_UP, value=sort_by_gender_asc}, {label='gender'..CH_UP, value=sort_by_gender_asc},
{label='race'..CH_DN, value=sort_by_race_desc},
{label='race'..CH_UP, value=sort_by_race_asc},
{label='name'..CH_DN, value=sort_by_name_desc}, {label='name'..CH_DN, value=sort_by_name_desc},
{label='name'..CH_UP, value=sort_by_name_asc}, {label='name'..CH_UP, value=sort_by_name_asc},
}, },
@ -327,8 +336,19 @@ function AssignAnimal:init()
on_change=self:callback('refresh_list', 'sort_gender'), on_change=self:callback('refresh_list', 'sort_gender'),
}, },
widgets.CycleHotkeyLabel{ widgets.CycleHotkeyLabel{
view_id='sort_name', view_id='sort_race',
frame={t=0, l=STATUS_COL_WIDTH+2+DISPOSITION_COL_WIDTH+2+GENDER_COL_WIDTH+2, w=5}, frame={t=0, l=STATUS_COL_WIDTH+2+DISPOSITION_COL_WIDTH+2+GENDER_COL_WIDTH+2, w=5},
options={
{label='race', value=sort_noop},
{label='race'..CH_DN, value=sort_by_race_desc},
{label='race'..CH_UP, value=sort_by_race_asc},
},
option_gap=0,
on_change=self:callback('refresh_list', 'sort_race'),
},
widgets.CycleHotkeyLabel{
view_id='sort_name',
frame={t=0, l=STATUS_COL_WIDTH+2+DISPOSITION_COL_WIDTH+2+GENDER_COL_WIDTH+2+7, w=5},
options={ options={
{label='name', value=sort_noop}, {label='name', value=sort_noop},
{label='name'..CH_DN, value=sort_by_name_desc}, {label='name'..CH_DN, value=sort_by_name_desc},
@ -380,7 +400,7 @@ function AssignAnimal:refresh_list(sort_widget, sort_fn)
self.subviews[sort_widget]:cycle() self.subviews[sort_widget]:cycle()
return return
end end
for _,widget_name in ipairs{'sort', 'sort_status', 'sort_disposition', 'sort_gender', 'sort_name'} do for _,widget_name in ipairs{'sort', 'sort_status', 'sort_disposition', 'sort_gender', 'sort_race', 'sort_name'} do
self.subviews[widget_name]:setOption(sort_fn) self.subviews[widget_name]:setOption(sort_fn)
end end
local list = self.subviews.list local list = self.subviews.list