add location retire overlay

develop
Myk Taylor 2024-01-03 18:02:10 -08:00
parent 8816286614
commit f28763fcdd
No known key found for this signature in database
2 changed files with 90 additions and 2 deletions

@ -158,8 +158,10 @@ cages you want to use. Then use ``zone set`` (like with ``assign``) and run
``zone tocages <filter>``. ``tocages`` can be used together with ``nick`` or
``remnick`` to adjust nicknames while assigning to cages.
Overlay
-------
Overlays
--------
Animal Assignment
Advanced unit selection is available via an `overlay` widget that appears when
you select a cage, restraint, pasture zone, or pit/pond zone.
@ -186,3 +188,13 @@ without having to close and reopen the window.
Just like all other overlays, you can disable this one in `gui/control-panel` on
the Overlays tab if you don't want the option of using it.
Location retirement
When viewing location (temple, guildhall, tavern, etc.) details, there is now a
"Retire location" button that you can use to remove the location from the list
of available locations for your fort.
Before you can retire the location, you have to remove all units assigned
occupations for that location and you have to detach the location from any
zones. Once you confirm retirement, the location will be removed from the list.

@ -1,5 +1,6 @@
local _ENV = mkmodule('plugins.zone')
local dialogs = require('gui.dialogs')
local gui = require('gui')
local overlay = require('plugins.overlay')
local utils = require('utils')
@ -1086,9 +1087,84 @@ function CageChainOverlay:init()
}
end
-- ---------------------
-- RetireLocationOverlay
--
local function location_details_is_on_top()
return not df.global.game.main_interface.name_creator.open and
not df.global.game.main_interface.unit_selector.open
end
RetireLocationOverlay = defclass(RetireLocationOverlay, overlay.OverlayWidget)
RetireLocationOverlay.ATTRS{
desc='Adds a button to retire unneeded locations to the location details screen.',
default_pos={x=-39,y=6},
default_enabled=true,
viewscreens='dwarfmode/LocationDetails',
frame={w=25, h=3},
}
function RetireLocationOverlay:init()
self:addviews{
widgets.Panel{
frame_background=gui.CLEAR_PEN,
frame_style=gui.FRAME_MEDIUM,
visible=location_details_is_on_top,
subviews={
widgets.HotkeyLabel{
frame={t=0, l=0},
label='Retire location',
key='CUSTOM_CTRL_D',
on_activate=self:callback('retire'),
},
},
},
}
end
function RetireLocationOverlay:retire()
local mi = df.global.game.main_interface
local details = mi.location_details
local location = details.selected_ab
local has_occupations, has_zones = false, #location.contents.building_ids ~= 0
for _, occupation in ipairs(location.occupations) do
if occupation.histfig_id ~= -1 then
has_occupations = true
break
end
end
if has_occupations or has_zones then
local messages = {'Cannot retire location! Please:', ''}
if has_occupations then
table.insert(messages, '- unassign location occupations')
end
if has_zones then
table.insert(messages, ('- detach this location from %d zone(s)'):format(#location.contents.building_ids))
end
table.insert(messages, '')
table.insert(messages, 'and try again')
dialogs.showMessage('Location in use', table.concat(messages, NEWLINE))
return
end
dialogs.showYesNoPrompt('Confirm retire location',
'Are you sure you want to retire this location?'..NEWLINE..'You won\'t be able to use it again.',
COLOR_WHITE,
function()
location.flags.DOES_NOT_EXIST = true
for idx, loc in ipairs(mi.location_selector.valid_ab) do
if loc.id == location.id then
mi.location_selector.valid_ab:erase(idx)
break
end
end
end)
end
OVERLAY_WIDGETS = {
pasturepond=PasturePondOverlay,
cagechain=CageChainOverlay,
retirelocation=RetireLocationOverlay,
}
return _ENV