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.
develop
Alexander Gavrilov 2014-03-24 19:39:34 +04:00
parent 827dd121d8
commit dde0f194e8
3 changed files with 61 additions and 0 deletions

@ -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. 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 gui/guide-path
============== ==============

@ -90,6 +90,9 @@ keybinding add Alt-A@dwarfmode/QueryBuilding/Some/SiegeEngine gui/siege-engine
# military weapon auto-select # military weapon auto-select
keybinding add Ctrl-W@layer_military/Equip/Customize/View gui/choose-weapons 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 # minecart Guide path
keybinding add Alt-P@dwarfmode/Hauling/DefineStop/Cond/Guide gui/guide-path keybinding add Alt-P@dwarfmode/Hauling/DefineStop/Cond/Guide gui/guide-path

@ -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