From dde0f194e8483521c571abb6732830e8f02de9d7 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Mon, 24 Mar 2014 19:39:34 +0400 Subject: [PATCH] Add a script that clones the currently selected military uniform. To be precise, it applies to the entity uniform templates, not uniforms for specific squad positions. --- Readme.rst | 10 ++++++++ dfhack.init-example | 3 +++ scripts/gui/clone-uniform.lua | 48 +++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 scripts/gui/clone-uniform.lua diff --git a/Readme.rst b/Readme.rst index 29f0a71fa..9af33e759 100644 --- a/Readme.rst +++ b/Readme.rst @@ -2636,6 +2636,16 @@ Rationale: individual choice seems to be unreliable when there is a weapon short and may lead to inappropriate weapons being selected. +gui/clone-uniform +================= + +Bind to a key (the example config uses Ctrl-C), and activate in the Uniforms +page of the military screen with the cursor in the leftmost list. + +When invoked, the script duplicates the currently selected uniform template, +and selects the newly created copy. + + gui/guide-path ============== diff --git a/dfhack.init-example b/dfhack.init-example index 05fd020bc..62d6c1125 100644 --- a/dfhack.init-example +++ b/dfhack.init-example @@ -90,6 +90,9 @@ keybinding add Alt-A@dwarfmode/QueryBuilding/Some/SiegeEngine gui/siege-engine # military weapon auto-select keybinding add Ctrl-W@layer_military/Equip/Customize/View gui/choose-weapons +# military copy uniform +keybinding add Ctrl-C@layer_military/Uniforms gui/clone-uniform + # minecart Guide path keybinding add Alt-P@dwarfmode/Hauling/DefineStop/Cond/Guide gui/guide-path diff --git a/scripts/gui/clone-uniform.lua b/scripts/gui/clone-uniform.lua new file mode 100644 index 000000000..2257c655f --- /dev/null +++ b/scripts/gui/clone-uniform.lua @@ -0,0 +1,48 @@ +-- Clone the current uniform template in the military screen. + +local utils = require 'utils' +local gui = require 'gui' + +local entity = df.global.ui.main.fortress_entity + +local args = {...} +local vs = dfhack.gui.getCurViewscreen() +local vstype = df.viewscreen_layer_militaryst +if not vstype:is_instance(vs) then + qerror('Call this from the military screen') +end + +local slist = vs.layer_objects[0] + +if vs.page == vstype.T_page.Uniforms +and slist.active and slist.num_entries > 0 +and not vs.equip.in_name_uniform +then + local idx = slist.num_entries + + if #vs.equip.uniforms ~= idx or #entity.uniforms ~= idx then + error('Uniform vector length mismatch') + end + + local uniform = vs.equip.uniforms[slist:getListCursor()] + + local ucopy = uniform:new() + ucopy.id = entity.next_uniform_id + ucopy.name = ucopy.name..'(Copy)' + + for k,v in ipairs(ucopy.uniform_item_info) do + for k2,v2 in ipairs(v) do + v[k2] = v2:new() + end + end + + entity.next_uniform_id = entity.next_uniform_id + 1 + entity.uniforms:insert('#',ucopy) + vs.equip.uniforms:insert('#',ucopy) + + slist.num_entries = idx+1 + slist.cursor = idx-1 + gui.simulateInput(vs, 'STANDARDSCROLL_DOWN') +else + qerror('Call this with a uniform selected on the Uniforms page of military screen') +end