diff options
| author | Alexander Gavrilov | 2012-09-05 21:27:42 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-09-05 21:27:42 +0400 |
| commit | 8d876cc7d92faf1616d914e03c890772256ebb83 (patch) | |
| tree | 86a87e2dc8a586a0d12f51966d065b9f5ae92de1 /scripts | |
| parent | 57086ac56eb489abd0c7759aed084020edc71148 (diff) | |
| download | dfhack-8d876cc7d92faf1616d914e03c890772256ebb83.tar.gz dfhack-8d876cc7d92faf1616d914e03c890772256ebb83.tar.bz2 dfhack-8d876cc7d92faf1616d914e03c890772256ebb83.tar.xz | |
Support renaming some buildings, and arbitrary units, via gui script.
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/gui/rename.lua | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/scripts/gui/rename.lua b/scripts/gui/rename.lua new file mode 100644 index 00000000..a457a0bf --- /dev/null +++ b/scripts/gui/rename.lua @@ -0,0 +1,63 @@ +-- Rename various objects via gui. + +local gui = require 'gui' +local dlg = require 'gui.dialogs' +local plugin = require 'plugins.rename' + +local mode = ... +local focus = dfhack.gui.getCurFocus() + +local function verify_mode(expected) + if mode ~= nil and mode ~= expected then + qerror('Invalid UI state for mode '..mode) + end +end + +if string.match(focus, '^dwarfmode/QueryBuilding/Some') then + verify_mode('building') + + local building = df.global.world.selected_building + if plugin.canRenameBuilding(building) then + dlg.showInputPrompt( + 'Rename Building', + 'Enter a new name for the building:', COLOR_GREEN, + building.name, + curry(plugin.renameBuilding, building) + ) + else + dlg.showMessage( + 'Rename Building', + 'Cannot rename this type of building.', COLOR_LIGHTRED + ) + end +elseif dfhack.gui.getSelectedUnit(true) then + local unit = dfhack.gui.getSelectedUnit(true) + + if mode == 'unit-profession' then + dlg.showInputPrompt( + 'Rename Unit', + 'Enter a new profession for the unit:', COLOR_GREEN, + unit.custom_profession, + function(newval) + unit.custom_profession = newval + end + ) + else + verify_mode('unit') + + local vname = dfhack.units.getVisibleName(unit) + local vnick = '' + if vname and vname.has_name then + vnick = vname.nickname + end + + dlg.showInputPrompt( + 'Rename Unit', + 'Enter a new nickname for the unit:', COLOR_GREEN, + vnick, + curry(dfhack.units.setNickname, unit) + ) + end +elseif mode then + verify_mode(nil) +end |
