From 2a52582c1f0305ae26d3931a50b276763681ef89 Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 9 May 2018 10:23:05 -0400 Subject: [PATCH] Add Gui::inRenameBuilding --- library/LuaApi.cpp | 1 + library/include/modules/Gui.h | 2 ++ library/modules/Gui.cpp | 18 ++++++++++++++---- plugins/buildingplan.cpp | 4 +--- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 852f4e29d..b78d621ce 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1493,6 +1493,7 @@ static const LuaWrapper::FunctionReg dfhack_gui_module[] = { WRAPM(Gui, resetDwarfmodeView), WRAPM(Gui, revealInDwarfmodeMap), WRAPM(Gui, refreshSidebar), + WRAPM(Gui, inRenameBuilding), WRAPM(Gui, getDepthAt), { NULL, NULL } }; diff --git a/library/include/modules/Gui.h b/library/include/modules/Gui.h index ec5d1ea94..819ad1558 100644 --- a/library/include/modules/Gui.h +++ b/library/include/modules/Gui.h @@ -150,6 +150,8 @@ namespace DFHack DFHACK_EXPORT bool revealInDwarfmodeMap(df::coord pos, bool center = false); DFHACK_EXPORT bool refreshSidebar(); + DFHACK_EXPORT bool inRenameBuilding(); + DFHACK_EXPORT bool getViewCoords (int32_t &x, int32_t &y, int32_t &z); DFHACK_EXPORT bool setViewCoords (const int32_t x, const int32_t y, const int32_t z); diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 53bacb129..271aedcaf 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -111,14 +111,16 @@ using namespace DFHack; #include "df/world.h" using namespace df::enums; + +using df::global::gamemode; +using df::global::gps; using df::global::gview; using df::global::init; -using df::global::gps; -using df::global::ui; -using df::global::world; using df::global::selection_rect; +using df::global::ui; using df::global::ui_menu_width; -using df::global::gamemode; +using df::global::ui_sidebar_menus; +using df::global::world; static df::layer_object_listst *getLayerList(df::viewscreen_layer *layer, int idx) { @@ -1757,6 +1759,14 @@ bool Gui::refreshSidebar() return false; } +bool Gui::inRenameBuilding() +{ + if (!ui_sidebar_menus) + return false; + + return ui_sidebar_menus->barracks.in_rename; +} + bool Gui::getViewCoords (int32_t &x, int32_t &y, int32_t &z) { x = *df::global::window_x; diff --git a/plugins/buildingplan.cpp b/plugins/buildingplan.cpp index eb6d2a661..37bb069a4 100644 --- a/plugins/buildingplan.cpp +++ b/plugins/buildingplan.cpp @@ -1,11 +1,9 @@ #include "buildingplan-lib.h" -#include "df/ui_sidebar_menus.h" DFHACK_PLUGIN("buildingplan"); #define PLUGIN_VERSION 0.14 REQUIRE_GLOBAL(ui); REQUIRE_GLOBAL(ui_build_selector); -REQUIRE_GLOBAL(ui_sidebar_menus); REQUIRE_GLOBAL(world); DFhackCExport command_result plugin_shutdown ( color_ostream &out ) @@ -188,7 +186,7 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest } else if (isInNobleRoomQueryMode()) { - if (ui_sidebar_menus->barracks.in_rename) + if (Gui::inRenameBuilding()) return false; auto np = getNoblePositionOfSelectedBuildingOwner(); df::interface_key last_token = get_string_key(input);