Merge pull request #4134 from myk002/myk_retire

[zone] add location retire overlay
develop
Myk 2024-01-03 18:26:19 -08:00 committed by GitHub
commit b07573f370
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 91 additions and 3 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 ``zone tocages <filter>``. ``tocages`` can be used together with ``nick`` or
``remnick`` to adjust nicknames while assigning to cages. ``remnick`` to adjust nicknames while assigning to cages.
Overlay Overlays
------- --------
Animal Assignment
Advanced unit selection is available via an `overlay` widget that appears when Advanced unit selection is available via an `overlay` widget that appears when
you select a cage, restraint, pasture zone, or pit/pond zone. 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 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. 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 +1 @@
Subproject commit 743be55c277731490f56b2ca47dca78fa1a90438 Subproject commit e7134f51ea1da848a2c37c7d410e996a5b66c526

@ -1,5 +1,6 @@
local _ENV = mkmodule('plugins.zone') local _ENV = mkmodule('plugins.zone')
local dialogs = require('gui.dialogs')
local gui = require('gui') local gui = require('gui')
local overlay = require('plugins.overlay') local overlay = require('plugins.overlay')
local utils = require('utils') local utils = require('utils')
@ -1086,9 +1087,84 @@ function CageChainOverlay:init()
} }
end 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 = { OVERLAY_WIDGETS = {
pasturepond=PasturePondOverlay, pasturepond=PasturePondOverlay,
cagechain=CageChainOverlay, cagechain=CageChainOverlay,
retirelocation=RetireLocationOverlay,
} }
return _ENV return _ENV