fixup unnecessary changes, remove unnecessary stuff

develop
Robob27 2023-02-02 01:20:42 -05:00
parent 3da1964c53
commit 86b57380a6
10 changed files with 13 additions and 128 deletions

@ -29,46 +29,6 @@ SIDEBAR_MODE_KEYS = {
[df.ui_sidebar_mode.ViewUnits]='D_VIEWUNIT', [df.ui_sidebar_mode.ViewUnits]='D_VIEWUNIT',
} }
-- Sends ESC keycodes until we get to dwarfmode/Default and then enters the
-- specified sidebar mode with the corresponding keycode. If we don't get to
-- Default after max_esc presses of ESC (default value is 10), we throw an
-- error. The target sidebar mode must be a member of SIDEBAR_MODE_KEYS
function enterSidebarMode(sidebar_mode, max_esc)
local navkey = SIDEBAR_MODE_KEYS[sidebar_mode]
if not navkey then
error(('Invalid or unsupported sidebar mode: %s (%s)')
:format(sidebar_mode, df.ui_sidebar_mode[sidebar_mode]))
end
local max_esc_num = tonumber(max_esc)
if max_esc and (not max_esc_num or max_esc_num <= 0) then
error(('max_esc must be a positive number: got %s')
:format(tostring(max_esc)))
end
local remaining_esc = max_esc_num or 10
local focus_string = ''
while remaining_esc > 0 do
local screen = dfhack.gui.getCurViewscreen(true)
focus_string = dfhack.gui.getFocusStrings(screen)
if df.global.plotinfo.main.mode == df.ui_sidebar_mode.Default and
focus_string == 'dwarfmode/Default' then
if #navkey > 0 then gui.simulateInput(screen, navkey) end
if navkey == 'D_DESIGNATE' then
-- if the z-level happens to be on the surface, the mode will be
-- set to DesignateChopTrees. we need an extra step to get to
-- DesignateMine
gui.simulateInput(dfhack.gui.getCurViewscreen(true),
'DESIGNATE_DIG')
end
return
end
gui.simulateInput(screen, 'LEAVESCREEN')
remaining_esc = remaining_esc - 1
end
error(('Unable to get into target sidebar mode (%s) from' ..
' current UI viewscreen (%s).'):format(
df.ui_sidebar_mode[sidebar_mode], focus_string))
end
function getPanelLayout() function getPanelLayout()
local dims = dfhack.gui.getDwarfmodeViewDims() local dims = dfhack.gui.getDwarfmodeViewDims()
return { return {

@ -1081,7 +1081,7 @@ using df::identity_traits;
#define CUR_STRUCT dfhack_viewscreen #define CUR_STRUCT dfhack_viewscreen
static const struct_field_info dfhack_viewscreen_fields[] = { static const struct_field_info dfhack_viewscreen_fields[] = {
{ METHOD(OBJ_METHOD, is_lua_screen), 0, 0 }, { METHOD(OBJ_METHOD, is_lua_screen), 0, 0 },
{ METHOD(OBJ_METHOD, getFocusStrings), 0, 0 }, { METHOD(OBJ_METHOD, getFocusString), 0, 0 },
{ METHOD(OBJ_METHOD, onShow), 0, 0 }, { METHOD(OBJ_METHOD, onShow), 0, 0 },
{ METHOD(OBJ_METHOD, onDismiss), 0, 0 }, { METHOD(OBJ_METHOD, onDismiss), 0, 0 },
{ METHOD(OBJ_METHOD, getSelectedUnit), 0, 0 }, { METHOD(OBJ_METHOD, getSelectedUnit), 0, 0 },

@ -56,7 +56,7 @@ public:
void render(); void render();
std::string getFocusStrings() { return "buildingplan_choosemat"; } std::string getFocusString() { return "buildingplan_choosemat"; }
private: private:
ListColumn<df::dfhack_material_category> masks_column; ListColumn<df::dfhack_material_category> masks_column;

@ -410,7 +410,7 @@ public:
OutputHotkeyString(x, y, "Zoom Unit", CUSTOM_SHIFT_Z); OutputHotkeyString(x, y, "Zoom Unit", CUSTOM_SHIFT_Z);
} }
std::vector<std::string> getFocusStrings() { return std::vector<std::string>{"dwarfmonitor_dwarfstats"}; } std::string getFocusString() { return "dwarfmonitor_dwarfstats"; }
private: private:
ListColumn<df::unit *> dwarves_column; ListColumn<df::unit *> dwarves_column;
@ -1021,7 +1021,7 @@ public:
OutputHotkeyString(x, y, "Zoom Unit", CUSTOM_SHIFT_Z); OutputHotkeyString(x, y, "Zoom Unit", CUSTOM_SHIFT_Z);
} }
std::vector<std::string> getFocusStrings() { return std::vector<std::string>{"dwarfmonitor_fortstats"}; } std::string getFocusString() { return "dwarfmonitor_fortstats"; }
private: private:
ListColumn<activity_type> fort_activity_column, category_breakdown_column; ListColumn<activity_type> fort_activity_column, category_breakdown_column;
@ -1652,7 +1652,7 @@ public:
getSelectedUnit() ? COLOR_WHITE : COLOR_DARKGREY); getSelectedUnit() ? COLOR_WHITE : COLOR_DARKGREY);
} }
std::vector<std::string> getFocusStrings() override { return std::vector<std::string>{"dwarfmonitor_preferences"}; } std::string getFocusString() override { return "dwarfmonitor_preferences"; }
private: private:
ListColumn<size_t> preferences_column; ListColumn<size_t> preferences_column;

@ -1613,7 +1613,7 @@ namespace embark_assist {
void render(); void render();
std::vector<std::string> getFocusStrings() { return std::vector<std::string>{"Finder UI"}; } std::string getFocusString() { return "Finder UI"; }
private: private:
}; };

@ -31,7 +31,7 @@ namespace embark_assist{
void render(); void render();
std::vector<std::string> getFocusStrings() { return std::vector<std::string>{"Help UI"}; } std::string getFocusString() { return "Help UI"; }
private: private:
pages current_page = pages::Intro; pages current_page = pages::Intro;

@ -572,7 +572,7 @@ public:
embark_tools_settings () { }; embark_tools_settings () { };
~embark_tools_settings () { }; ~embark_tools_settings () { };
void help () { }; void help () { };
std::vector<std::string> getFocusStrings () { return std::vector<std::string>{"embark-tools/options"}; }; std::string getFocusString () { return "embark-tools/options"; };
void render () void render ()
{ {
parent->render(); parent->render();

@ -864,7 +864,7 @@ public:
} }
} }
} }
std::vector<std::string> getFocusStrings() { return std::vector<std::string>{"unitlabors/batch"}; } std::string getFocusString() { return "unitlabors/batch"; }
void select_page (page p) void select_page (page p)
{ {
if (p == NICKNAME || p == PROFNAME) if (p == NICKNAME || p == PROFNAME)
@ -1034,7 +1034,7 @@ public:
} }
} }
} }
std::vector<std::string> getFocusStrings() { return std::vector<std::string>{"unitlabors/profession"}; } std::string getFocusString() { return "unitlabors/profession"; }
void feed(set<df::interface_key> *events) void feed(set<df::interface_key> *events)
{ {
if (events->count(interface_key::LEAVESCREEN)) if (events->count(interface_key::LEAVESCREEN))
@ -1146,7 +1146,7 @@ public:
void help() { } void help() { }
std::vector<std::string> getFocusStrings() { return std::vector<std::string>{"unitlabors"}; } std::string getFocusString() { return "unitlabors"; }
df::unit *getSelectedUnit(); df::unit *getSelectedUnit();

@ -620,7 +620,7 @@ public:
for (auto line = lines.begin(); line != lines.end(); ++line) for (auto line = lines.begin(); line != lines.end(); ++line)
OutputString(COLOR_WHITE, x, y, line->c_str(), true, left_margin); OutputString(COLOR_WHITE, x, y, line->c_str(), true, left_margin);
} }
std::vector<std::string> getFocusStrings() { return std::vector<std::string>{"stocks_view/search_help"}; } std::string getFocusString() { return "stocks_view/search_help"; }
}; };
class ViewscreenStocks : public dfhack_viewscreen class ViewscreenStocks : public dfhack_viewscreen
@ -973,7 +973,7 @@ public:
OutputHotkeyString(x, y, "Search help", interface_key::HELP, true, left_margin); OutputHotkeyString(x, y, "Search help", interface_key::HELP, true, left_margin);
} }
std::vector<std::string> getFocusStrings() { return std::vector<std::string>{"stocks_view"}; } std::string getFocusString() { return "stocks_view"; }
df::item *getSelectedItem() override df::item *getSelectedItem() override
{ {

@ -1,75 +0,0 @@
config = {
mode = 'fortress',
}
local gui = require('gui')
local guidm = require('gui.dwarfmode')
function test.enterSidebarMode()
expect.error_match('Invalid or unsupported sidebar mode',
function() guidm.enterSidebarMode('badmode') end)
expect.error_match('Invalid or unsupported sidebar mode',
function() guidm.enterSidebarMode(
df.ui_sidebar_mode.OrdersRefuse) end)
expect.error_match('must be a positive number',
function() guidm.enterSidebarMode(0, 'gg') end)
expect.error_match('must be a positive number',
function() guidm.enterSidebarMode(0, 0) end)
expect.error_match('must be a positive number',
function() guidm.enterSidebarMode(0, '0') end)
expect.error_match('must be a positive number',
function() guidm.enterSidebarMode(0, -1) end)
expect.error_match('must be a positive number',
function() guidm.enterSidebarMode(0, '-1') end)
-- Simulate not being able to get to default from a screen via mocks. This
-- failure can actually happen in-game in some situations, such as when
-- naming a building with ctrl-N (no way to cancel changes).
mock.patch({{dfhack.gui, 'getFocusStrings', mock.func()},
{gui, 'simulateInput', mock.func()}},
function()
expect.error_match('Unable to get into target sidebar mode',
function()
guidm.enterSidebarMode(df.ui_sidebar_mode.Default)
end)
end)
-- verify expected starting state
expect.eq(df.ui_sidebar_mode.Default, df.global.plotinfo.main.mode)
expect.eq('dwarfmode/Default', dfhack.gui.getCurFocus(true))
-- get into the orders screen
gui.simulateInput(dfhack.gui.getCurViewscreen(true), 'D_JOBLIST')
gui.simulateInput(dfhack.gui.getCurViewscreen(true), 'UNITJOB_MANAGER')
expect.eq(df.ui_sidebar_mode.Default, df.global.plotinfo.main.mode)
expect.eq('jobmanagement/Main', dfhack.gui.getCurFocus(true))
-- get back into default from some deep screen
guidm.enterSidebarMode(df.ui_sidebar_mode.Default)
expect.eq(df.ui_sidebar_mode.Default, df.global.plotinfo.main.mode)
expect.eq('dwarfmode/Default', dfhack.gui.getCurFocus(true))
-- move from default to some other mode
guidm.enterSidebarMode(df.ui_sidebar_mode.QueryBuilding)
expect.eq(df.ui_sidebar_mode.QueryBuilding, df.global.plotinfo.main.mode)
expect.str_find('^dwarfmode/QueryBuilding', dfhack.gui.getCurFocus(true))
-- move between non-default modes
guidm.enterSidebarMode(df.ui_sidebar_mode.LookAround)
expect.eq(df.ui_sidebar_mode.LookAround, df.global.plotinfo.main.mode)
expect.str_find('^dwarfmode/LookAround', dfhack.gui.getCurFocus(true))
-- get back into default from a supported mode
guidm.enterSidebarMode(df.ui_sidebar_mode.Default)
expect.eq(df.ui_sidebar_mode.Default, df.global.plotinfo.main.mode)
expect.eq('dwarfmode/Default', dfhack.gui.getCurFocus(true))
-- verify that all supported modes lead where we say they'll go
for k,v in pairs(guidm.SIDEBAR_MODE_KEYS) do
guidm.enterSidebarMode(k)
expect.eq(k, df.global.plotinfo.main.mode, df.ui_sidebar_mode[k])
end
-- end test back in default so the test harness doesn't have to autocorrect
guidm.enterSidebarMode(df.ui_sidebar_mode.Default)
end