Add Gui::refreshSidebar()

This handles feeding CURSOR_DOWN_Z and CURSOR_UP_Z properly, avoiding issues
when on the lowest z-level.
develop
lethosor 2017-06-22 23:56:35 -04:00
parent b4700f6fb0
commit ae809afde7
11 changed files with 33 additions and 35 deletions

@ -1486,7 +1486,9 @@ static const LuaWrapper::FunctionReg dfhack_gui_module[] = {
WRAPM(Gui, showZoomAnnouncement), WRAPM(Gui, showZoomAnnouncement),
WRAPM(Gui, showPopupAnnouncement), WRAPM(Gui, showPopupAnnouncement),
WRAPM(Gui, showAutoAnnouncement), WRAPM(Gui, showAutoAnnouncement),
WRAPM(Gui, resetDwarfmodeView),
WRAPM(Gui, revealInDwarfmodeMap), WRAPM(Gui, revealInDwarfmodeMap),
WRAPM(Gui, refreshSidebar),
WRAPM(Gui, getDepthAt), WRAPM(Gui, getDepthAt),
{ NULL, NULL } { NULL, NULL }
}; };

@ -148,6 +148,7 @@ namespace DFHack
DFHACK_EXPORT void resetDwarfmodeView(bool pause = false); DFHACK_EXPORT void resetDwarfmodeView(bool pause = false);
DFHACK_EXPORT bool revealInDwarfmodeMap(df::coord pos, bool center = 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 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); DFHACK_EXPORT bool setViewCoords (const int32_t x, const int32_t y, const int32_t z);

@ -14,6 +14,8 @@ local world_map = df.global.world.map
AREA_MAP_WIDTH = 23 AREA_MAP_WIDTH = 23
MENU_WIDTH = 30 MENU_WIDTH = 30
refreshSidebar = dfhack.gui.refreshSidebar
function getPanelLayout() function getPanelLayout()
local dims = dfhack.gui.getDwarfmodeViewDims() local dims = dfhack.gui.getDwarfmodeViewDims()
local area_pos = df.global.ui_area_map_width local area_pos = df.global.ui_area_map_width

@ -1594,6 +1594,26 @@ bool Gui::revealInDwarfmodeMap(df::coord pos, bool center)
return true; return true;
} }
bool Gui::refreshSidebar()
{
auto scr = getViewscreenByType<df::viewscreen_dwarfmodest>(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) bool Gui::getViewCoords (int32_t &x, int32_t &y, int32_t &z)
{ {
x = *df::global::window_x; x = *df::global::window_x;

@ -868,8 +868,7 @@ struct jobutils_hook : public df::viewscreen_dwarfmodest
void move_cursor(df::coord &pos) void move_cursor(df::coord &pos)
{ {
Gui::setCursorCoords(pos.x, pos.y, pos.z); Gui::setCursorCoords(pos.x, pos.y, pos.z);
send_key(interface_key::CURSOR_DOWN_Z); Gui::refreshSidebar();
send_key(interface_key::CURSOR_UP_Z);
} }
void move_cursor(coord32_t &pos) void move_cursor(coord32_t &pos)

@ -107,8 +107,7 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
planmode_enabled[type] = !planmode_enabled[type]; planmode_enabled[type] = !planmode_enabled[type];
if (!planmode_enabled[type]) if (!planmode_enabled[type])
{ {
send_key(interface_key::CURSOR_DOWN_Z); Gui::refreshSidebar();
send_key(interface_key::CURSOR_UP_Z);
planner.in_dummmy_screen = false; planner.in_dummmy_screen = false;
} }
return true; return true;
@ -140,8 +139,7 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
{ {
if (ui_build_selector->errors.size() == 0 && planner.allocatePlannedBuilding(type)) if (ui_build_selector->errors.size() == 0 && planner.allocatePlannedBuilding(type))
{ {
send_key(interface_key::CURSOR_DOWN_Z); Gui::refreshSidebar();
send_key(interface_key::CURSOR_UP_Z);
if (planner.inQuickFortMode()) if (planner.inQuickFortMode())
{ {
planner.in_dummmy_screen = true; planner.in_dummmy_screen = true;

@ -147,8 +147,7 @@ static void send_key(const df::interface_key &key)
static void move_cursor(df::coord &pos) static void move_cursor(df::coord &pos)
{ {
Gui::setCursorCoords(pos.x, pos.y, pos.z); Gui::setCursorCoords(pos.x, pos.y, pos.z);
send_key(interface_key::CURSOR_DOWN_Z); Gui::refreshSidebar();
send_key(interface_key::CURSOR_UP_Z);
} }
static void open_stats_srceen(); static void open_stats_srceen();

@ -507,16 +507,7 @@ struct mousequery_hook : public df::viewscreen_dwarfmodest
return; return;
Gui::setCursorCoords(mpos.x, mpos.y, mpos.z); Gui::setCursorCoords(mpos.x, mpos.y, mpos.z);
if (mpos.z == 0) Gui::refreshSidebar();
{
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);
}
} }
bool inBuildPlacement() bool inBuildPlacement()

@ -981,8 +981,7 @@ public:
void move_cursor(const df::coord &pos) void move_cursor(const df::coord &pos)
{ {
Gui::setCursorCoords(pos.x, pos.y, pos.z); Gui::setCursorCoords(pos.x, pos.y, pos.z);
send_key(interface_key::CURSOR_DOWN_Z); Gui::refreshSidebar();
send_key(interface_key::CURSOR_UP_Z);
} }
void send_key(const df::interface_key &key) void send_key(const df::interface_key &key)

@ -52,20 +52,7 @@ struct stable_cursor_hook : df::viewscreen_dwarfmodest
last_cursor.isValid() && cur_cursor.isValid()) last_cursor.isValid() && cur_cursor.isValid())
{ {
Gui::setCursorCoords(last_cursor.x, last_cursor.y, last_cursor.z); Gui::setCursorCoords(last_cursor.x, last_cursor.y, last_cursor.z);
Gui::refreshSidebar();
// Force update of ui state
set<df::interface_key> 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);
} }
else if (!is_default && cur_cursor.isValid()) else if (!is_default && cur_cursor.isValid())
{ {

@ -1 +1 @@
Subproject commit d461a8417260cba96db7028ef0602a787e48274b Subproject commit 3e431de4fe3ffa39c9854d74b6d85de5e92834bd