diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 38319dcfc..ca958cfdc 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1486,7 +1486,9 @@ static const LuaWrapper::FunctionReg dfhack_gui_module[] = { WRAPM(Gui, showZoomAnnouncement), WRAPM(Gui, showPopupAnnouncement), WRAPM(Gui, showAutoAnnouncement), + WRAPM(Gui, resetDwarfmodeView), WRAPM(Gui, revealInDwarfmodeMap), + WRAPM(Gui, refreshSidebar), WRAPM(Gui, getDepthAt), { NULL, NULL } }; diff --git a/library/include/modules/Gui.h b/library/include/modules/Gui.h index d3e8497ce..ec5d1ea94 100644 --- a/library/include/modules/Gui.h +++ b/library/include/modules/Gui.h @@ -148,6 +148,7 @@ namespace DFHack DFHACK_EXPORT void resetDwarfmodeView(bool pause = false); DFHACK_EXPORT bool revealInDwarfmodeMap(df::coord pos, bool center = false); + DFHACK_EXPORT bool refreshSidebar(); 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/lua/gui/dwarfmode.lua b/library/lua/gui/dwarfmode.lua index 27649bc6e..3764c4df7 100644 --- a/library/lua/gui/dwarfmode.lua +++ b/library/lua/gui/dwarfmode.lua @@ -14,6 +14,8 @@ local world_map = df.global.world.map AREA_MAP_WIDTH = 23 MENU_WIDTH = 30 +refreshSidebar = dfhack.gui.refreshSidebar + function getPanelLayout() local dims = dfhack.gui.getDwarfmodeViewDims() local area_pos = df.global.ui_area_map_width diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 611e00205..950aef60a 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -1594,6 +1594,26 @@ bool Gui::revealInDwarfmodeMap(df::coord pos, bool center) return true; } +bool Gui::refreshSidebar() +{ + auto scr = getViewscreenByType(0); + if (scr) + { + if (df::global::window_z && *df::global::window_z == 0) + { + scr->feed_key(interface_key::CURSOR_UP_Z); + scr->feed_key(interface_key::CURSOR_DOWN_Z); + } + else + { + scr->feed_key(interface_key::CURSOR_UP_Z); + scr->feed_key(interface_key::CURSOR_DOWN_Z); + } + return true; + } + return false; +} + bool Gui::getViewCoords (int32_t &x, int32_t &y, int32_t &z) { x = *df::global::window_x; diff --git a/plugins/automaterial.cpp b/plugins/automaterial.cpp index 2465c6325..cfbc95ae7 100644 --- a/plugins/automaterial.cpp +++ b/plugins/automaterial.cpp @@ -868,8 +868,7 @@ struct jobutils_hook : public df::viewscreen_dwarfmodest void move_cursor(df::coord &pos) { Gui::setCursorCoords(pos.x, pos.y, pos.z); - send_key(interface_key::CURSOR_DOWN_Z); - send_key(interface_key::CURSOR_UP_Z); + Gui::refreshSidebar(); } void move_cursor(coord32_t &pos) diff --git a/plugins/buildingplan.cpp b/plugins/buildingplan.cpp index f72888d00..747e5cfb7 100644 --- a/plugins/buildingplan.cpp +++ b/plugins/buildingplan.cpp @@ -107,8 +107,7 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest planmode_enabled[type] = !planmode_enabled[type]; if (!planmode_enabled[type]) { - send_key(interface_key::CURSOR_DOWN_Z); - send_key(interface_key::CURSOR_UP_Z); + Gui::refreshSidebar(); planner.in_dummmy_screen = false; } return true; @@ -140,8 +139,7 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest { if (ui_build_selector->errors.size() == 0 && planner.allocatePlannedBuilding(type)) { - send_key(interface_key::CURSOR_DOWN_Z); - send_key(interface_key::CURSOR_UP_Z); + Gui::refreshSidebar(); if (planner.inQuickFortMode()) { planner.in_dummmy_screen = true; diff --git a/plugins/dwarfmonitor.cpp b/plugins/dwarfmonitor.cpp index 2c78c0854..2ea811f38 100644 --- a/plugins/dwarfmonitor.cpp +++ b/plugins/dwarfmonitor.cpp @@ -147,8 +147,7 @@ static void send_key(const df::interface_key &key) static void move_cursor(df::coord &pos) { Gui::setCursorCoords(pos.x, pos.y, pos.z); - send_key(interface_key::CURSOR_DOWN_Z); - send_key(interface_key::CURSOR_UP_Z); + Gui::refreshSidebar(); } static void open_stats_srceen(); diff --git a/plugins/mousequery.cpp b/plugins/mousequery.cpp index 7f0095c58..7a70f29c4 100644 --- a/plugins/mousequery.cpp +++ b/plugins/mousequery.cpp @@ -507,16 +507,7 @@ struct mousequery_hook : public df::viewscreen_dwarfmodest return; Gui::setCursorCoords(mpos.x, mpos.y, mpos.z); - if (mpos.z == 0) - { - sendKey(interface_key::CURSOR_UP_Z); - sendKey(interface_key::CURSOR_DOWN_Z); - } - else - { - sendKey(interface_key::CURSOR_DOWN_Z); - sendKey(interface_key::CURSOR_UP_Z); - } + Gui::refreshSidebar(); } bool inBuildPlacement() diff --git a/plugins/stocks.cpp b/plugins/stocks.cpp index 1d3d04d6f..a5b84672d 100644 --- a/plugins/stocks.cpp +++ b/plugins/stocks.cpp @@ -981,8 +981,7 @@ public: void move_cursor(const df::coord &pos) { Gui::setCursorCoords(pos.x, pos.y, pos.z); - send_key(interface_key::CURSOR_DOWN_Z); - send_key(interface_key::CURSOR_UP_Z); + Gui::refreshSidebar(); } void send_key(const df::interface_key &key) diff --git a/plugins/tweak/tweaks/stable-cursor.h b/plugins/tweak/tweaks/stable-cursor.h index 105510c8b..7b6482d7b 100644 --- a/plugins/tweak/tweaks/stable-cursor.h +++ b/plugins/tweak/tweaks/stable-cursor.h @@ -52,20 +52,7 @@ struct stable_cursor_hook : df::viewscreen_dwarfmodest last_cursor.isValid() && cur_cursor.isValid()) { Gui::setCursorCoords(last_cursor.x, last_cursor.y, last_cursor.z); - - // Force update of ui state - set tmp; - if (last_cursor.z < 2) - tmp.insert(interface_key::CURSOR_UP_Z); - else - tmp.insert(interface_key::CURSOR_DOWN_Z); - INTERPOSE_NEXT(feed)(&tmp); - tmp.clear(); - if (last_cursor.z < 2) - tmp.insert(interface_key::CURSOR_DOWN_Z); - else - tmp.insert(interface_key::CURSOR_UP_Z); - INTERPOSE_NEXT(feed)(&tmp); + Gui::refreshSidebar(); } else if (!is_default && cur_cursor.isValid()) { diff --git a/scripts b/scripts index d461a8417..3e431de4f 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit d461a8417260cba96db7028ef0602a787e48274b +Subproject commit 3e431de4fe3ffa39c9854d74b6d85de5e92834bd