2017-06-25 14:42:30 -06:00
|
|
|
#include "df/burrow.h"
|
|
|
|
|
2023-01-05 18:11:01 -07:00
|
|
|
using df::global::plotinfo;
|
2017-06-25 14:42:30 -06:00
|
|
|
|
|
|
|
struct burrow_name_cancel_hook : df::viewscreen_dwarfmodest {
|
|
|
|
typedef df::viewscreen_dwarfmodest interpose_base;
|
|
|
|
|
|
|
|
static std::string old_name;
|
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, feed, (std::set<df::interface_key> *input))
|
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
if (plotinfo->main.mode == df::ui_sidebar_mode::Burrows)
|
2017-06-25 14:42:30 -06:00
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
bool was_naming = plotinfo->burrows.in_edit_name_mode;
|
2017-06-25 14:42:30 -06:00
|
|
|
INTERPOSE_NEXT(feed)(input);
|
2023-01-05 18:11:01 -07:00
|
|
|
df::burrow *burrow = vector_get(plotinfo->burrows.list, plotinfo->burrows.sel_index);
|
2017-06-25 14:42:30 -06:00
|
|
|
if (!burrow)
|
|
|
|
return;
|
|
|
|
|
2023-01-05 18:11:01 -07:00
|
|
|
if (plotinfo->burrows.in_edit_name_mode)
|
2017-06-25 14:42:30 -06:00
|
|
|
{
|
|
|
|
if (!was_naming)
|
|
|
|
{
|
|
|
|
// Just started renaming - make a copy of the old name
|
|
|
|
old_name = burrow->name;
|
|
|
|
}
|
|
|
|
if (input->count(df::interface_key::LEAVESCREEN))
|
|
|
|
{
|
|
|
|
// Cancel and restore the old name
|
2023-01-05 18:11:01 -07:00
|
|
|
plotinfo->burrows.in_edit_name_mode = false;
|
2017-06-25 14:42:30 -06:00
|
|
|
burrow->name = old_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
INTERPOSE_NEXT(feed)(input);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string burrow_name_cancel_hook::old_name;
|
|
|
|
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(burrow_name_cancel_hook, feed);
|