Fix the rename plugin and script to use the new getSelectedBuilding API.

develop
Alexander Gavrilov 2012-09-20 11:11:59 +04:00
parent c39a337223
commit 462bedb757
3 changed files with 12 additions and 7 deletions

@ -357,10 +357,11 @@ static command_result rename(color_ostream &out, vector <string> &parameters)
if (parameters.size() != 2) if (parameters.size() != 2)
return CR_WRONG_USAGE; return CR_WRONG_USAGE;
if (ui->main.mode != ui_sidebar_mode::QueryBuilding) df::building *bld = Gui::getSelectedBuilding(out, true);
if (!bld)
return CR_WRONG_USAGE; return CR_WRONG_USAGE;
if (!renameBuilding(world->selected_building, parameters[1])) if (!renameBuilding(bld, parameters[1]))
{ {
out.printerr("This type of building is not supported.\n"); out.printerr("This type of building is not supported.\n");
return CR_FAILURE; return CR_FAILURE;

@ -13,10 +13,12 @@ local function verify_mode(expected)
end end
end end
if string.match(focus, '^dwarfmode/QueryBuilding/Some') then local unit = dfhack.gui.getSelectedUnit(true)
local building = dfhack.gui.getSelectedBuilding(true)
if building and (not unit or mode == 'building') then
verify_mode('building') verify_mode('building')
local building = df.global.world.selected_building
if plugin.canRenameBuilding(building) then if plugin.canRenameBuilding(building) then
dlg.showInputPrompt( dlg.showInputPrompt(
'Rename Building', 'Rename Building',
@ -30,9 +32,7 @@ if string.match(focus, '^dwarfmode/QueryBuilding/Some') then
'Cannot rename this type of building.', COLOR_LIGHTRED 'Cannot rename this type of building.', COLOR_LIGHTRED
) )
end end
elseif dfhack.gui.getSelectedUnit(true) then elseif unit then
local unit = dfhack.gui.getSelectedUnit(true)
if mode == 'unit-profession' then if mode == 'unit-profession' then
dlg.showInputPrompt( dlg.showInputPrompt(
'Rename Unit', 'Rename Unit',

@ -74,6 +74,10 @@ function SiegeEngine:onDestroy()
end end
end end
function SiegeEngine:onGetSelectedBuilding()
return df.global.world.selected_building
end
function SiegeEngine:showCursor(enable) function SiegeEngine:showCursor(enable)
local cursor = guidm.getCursorPos() local cursor = guidm.getCursorPos()
if cursor and not enable then if cursor and not enable then