From def11659faa2bfabfbd089ec3458b74a4d1f3960 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 9 Jan 2025 18:10:46 -0800 Subject: [PATCH] allow units to be given nicknames on the embark screen --- changelog.txt | 1 + docs/gui/rename.rst | 3 +++ gui/rename.lua | 60 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/changelog.txt b/changelog.txt index 7d91af061..c553a5304 100644 --- a/changelog.txt +++ b/changelog.txt @@ -34,6 +34,7 @@ Template for new versions: - `gui/settings-manager`: new overlay on the Labor -> Standing Orders tab for configuring the number of barrels to reserve for job use (so you can brew alcohol and not have all your barrels claimed by stockpiles for container storage) - `gui/settings-manager`: standing orders save/load now includes the reserved barrels setting - `gui/rename`: add overlay to worldgen screen allowing you to rename the world before the new world is saved +- `gui/rename`: add overlay to the "Prepare carefully" embark screen that transparently fixes a DF bug where you can't give units nicknames or custom professions ## Fixes - `fix/dry-buckets`: don't empty buckets for wells that are actively in use diff --git a/docs/gui/rename.rst b/docs/gui/rename.rst index 39b64c632..56705b57c 100644 --- a/docs/gui/rename.rst +++ b/docs/gui/rename.rst @@ -105,3 +105,6 @@ This tool supports the following overlays: ``gui/rename.world`` Adds a widget to the world generation screen for renaming the world. +``gui/rename.unit_embark`` + Transparently fixes DF :bug:`12060` on the "Prepare carefully" embark screen + where the player is unable to give units nicknames or custom professions. diff --git a/gui/rename.lua b/gui/rename.lua index 00ed9b036..bb22f0ba4 100644 --- a/gui/rename.lua +++ b/gui/rename.lua @@ -797,7 +797,67 @@ function WorldRenameOverlay:init() } end +-- +-- UnitEmbarkRenameOverlay +-- + +local mi = df.global.game.main_interface + +UnitEmbarkRenameOverlay = defclass(UnitEmbarkRenameOverlay, overlay.OverlayWidget) +UnitEmbarkRenameOverlay.ATTRS { + desc='Allows editing of unit nicknames on the embark preparation screen.', + default_enabled=true, + viewscreens='setupdwarfgame/Dwarves', + fullscreen=true, + active=function() return mi.view_sheets.open end, +} + +local function get_selected_embark_unit() + local scr = dfhack.gui.getDFViewscreen(true) + return scr.s_unit[scr.selected_u] +end + +function UnitEmbarkRenameOverlay:onInput(keys) + if (keys.SELECT or keys._STRING) and mi.view_sheets.unit_overview_customizing then + if mi.view_sheets.unit_overview_entering_nickname then + if keys.SELECT then + mi.view_sheets.unit_overview_entering_nickname = false + return true + end + local unit = get_selected_embark_unit() + if unit then + if keys._STRING == 0 then + unit.name.nickname = string.sub(unit.name.nickname, 1, -2) + else + unit.name.nickname = unit.name.nickname .. string.char(keys._STRING) + end + local hf = df.historical_figure.find(unit.hist_figure_id) + if hf then + hf.name.nickname = unit.name.nickname + end + return true + end + elseif mi.view_sheets.unit_overview_entering_profession_nickname then + if keys.SELECT then + mi.view_sheets.unit_overview_entering_profession_nickname = false + return true + end + local unit = get_selected_embark_unit() + if unit then + if keys._STRING == 0 then + unit.custom_profession = string.sub(unit.custom_profession, 1, -2) + else + unit.custom_profession = unit.custom_profession .. string.char(keys._STRING) + end + return true + end + end + end + return false +end + OVERLAY_WIDGETS = { + unit_embark=UnitEmbarkRenameOverlay, world=WorldRenameOverlay, }