develop
Robob27 2023-02-01 17:22:56 -05:00
parent a770a4cae4
commit 6e442a26ca
4 changed files with 106 additions and 88 deletions

@ -948,7 +948,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first_, v
<< "Context may be used to limit the scope of the binding, by" << endl << "Context may be used to limit the scope of the binding, by" << endl
<< "requiring the current context to have a certain prefix." << endl << "requiring the current context to have a certain prefix." << endl
<< "Current UI context is: " << endl << "Current UI context is: " << endl
<< join_strings("\n", Gui::getFocusStrings(Gui::getDFViewscreen())) << endl; << join_strings("\n", Gui::getFocusStrings(Gui::getCurViewscreen(true))) << endl;
} }
} }
else if (first == "alias") else if (first == "alias")
@ -2431,6 +2431,7 @@ bool Core::SelectHotkey(int sym, int modifiers)
} }
if (!found) { if (!found) {
// TODO: fix error: format %s expects argument of type char*, but argument 3 has type std::string {aka std::basic_string<char>} [-Werror=format=]
DEBUG(keybinding).print("skipping keybinding due to focus string mismatch: '%s' !~ '%s'\n", DEBUG(keybinding).print("skipping keybinding due to focus string mismatch: '%s' !~ '%s'\n",
join_strings(", ", focusStrings), binding.focus.c_str()); join_strings(", ", focusStrings), binding.focus.c_str());
continue; continue;

@ -172,6 +172,15 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode)
newFocusString += "/Hauling"; newFocusString += "/Hauling";
focusStrings.push_back(newFocusString); focusStrings.push_back(newFocusString);
} }
if (game->main_interface.bottom_mode_selected == df::enums::main_bottom_mode_type::ZONE) {
newFocusString = baseFocus;
newFocusString += "/Zone";
if (game->main_interface.civzone.cur_bld) {
newFocusString += "/Some";
newFocusString += "/" + enum_item_key(game->main_interface.civzone.cur_bld->type);
}
focusStrings.push_back(newFocusString);
}
if (game->main_interface.trade.open) { if (game->main_interface.trade.open) {
newFocusString = baseFocus; newFocusString = baseFocus;
newFocusString += "/Trade"; newFocusString += "/Trade";
@ -351,7 +360,7 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode)
bool Gui::matchFocusString(std::string focusString) { bool Gui::matchFocusString(std::string focusString) {
focusString = toLower(focusString); focusString = toLower(focusString);
std::vector<std::string> currentFocus = getFocusStrings(Core::getTopViewscreen()); std::vector<std::string> currentFocus = getFocusStrings(getCurViewscreen(true));
return std::find_if(currentFocus.begin(), currentFocus.end(), [&focusString](std::string item) { return std::find_if(currentFocus.begin(), currentFocus.end(), [&focusString](std::string item) {
return focusString == toLower(item); return focusString == toLower(item);

@ -317,12 +317,7 @@ public:
if (paused) if (paused)
{ {
// TODO: fix
if (paused_focus != "" && (input->count(df::interface_key::LEAVESCREEN) || mouseExit)) if (paused_focus != "" && (input->count(df::interface_key::LEAVESCREEN) || mouseExit))
if(mouseExit) {
df::global::enabler->mouse_rbut = 0;
df::global::enabler->mouse_rbut_down = 0;
}
conf_lua::api::unpause(NULL); conf_lua::api::unpause(NULL);
return false; return false;
} }
@ -381,16 +376,11 @@ public:
set_state(SELECTED); set_state(SELECTED);
else if (input->count(df::interface_key::CUSTOM_P)) else if (input->count(df::interface_key::CUSTOM_P))
{ {
// TODO: fix
DEBUG(status).print("pausing\n"); DEBUG(status).print("pausing\n");
paused = true; paused = true;
// only record the screen when we're not at the top viewscreen
// since this screen will *always* be on the stack. for
// dwarfmode screens, use ESC detection to discover when to
// unpause
std::vector<std::string> focusStrings = Gui::getFocusStrings(Gui::getCurViewscreen()); std::vector<std::string> focusStrings = Gui::getFocusStrings(Gui::getCurViewscreen(true));
std::string current_focus = focusStrings[0]; std::string current_focus = focusStrings[0];// TODO: fix
if (current_focus != "dwarfmode") { if (current_focus != "dwarfmode") {
paused_focus = current_focus; paused_focus = current_focus;
@ -602,21 +592,27 @@ static int conf_register_##cls = conf_register(&cls##_instance, {\
IDs (used in the "confirm enable/disable" command, by Lua, and in the docs) IDs (used in the "confirm enable/disable" command, by Lua, and in the docs)
are obtained by replacing '_' with '-' in the first argument to DEFINE_CONFIRMATION are obtained by replacing '_' with '-' in the first argument to DEFINE_CONFIRMATION
*/ */
DEFINE_CONFIRMATION(trade, viewscreen_dwarfmodest);
DEFINE_CONFIRMATION(trade_cancel, viewscreen_dwarfmodest); DEFINE_CONFIRMATION(trade_cancel, viewscreen_dwarfmodest);
//DEFINE_CONFIRMATION(trade_seize, viewscreen_tradegoodsst);
//DEFINE_CONFIRMATION(trade_offer, viewscreen_tradegoodsst);
//DEFINE_CONFIRMATION(trade_select_all, viewscreen_tradegoodsst);
DEFINE_CONFIRMATION(haul_delete_route, viewscreen_dwarfmodest); DEFINE_CONFIRMATION(haul_delete_route, viewscreen_dwarfmodest);
DEFINE_CONFIRMATION(haul_delete_stop, viewscreen_dwarfmodest); DEFINE_CONFIRMATION(haul_delete_stop, viewscreen_dwarfmodest);
DEFINE_CONFIRMATION(depot_remove, viewscreen_dwarfmodest); DEFINE_CONFIRMATION(depot_remove, viewscreen_dwarfmodest);
DEFINE_CONFIRMATION(squad_disband, viewscreen_dwarfmodest); DEFINE_CONFIRMATION(squad_disband, viewscreen_dwarfmodest);
//DEFINE_CONFIRMATION(uniform_delete, viewscreen_layer_militaryst); DEFINE_CONFIRMATION(order_remove, viewscreen_dwarfmodest);
DEFINE_CONFIRMATION(zone_remove, viewscreen_dwarfmodest);
// these are more complex to implement
//DEFINE_CONFIRMATION(convict, viewscreen_dwarfmodest);
//DEFINE_CONFIRMATION(trade, viewscreen_dwarfmodest);
//DEFINE_CONFIRMATION(trade_seize, viewscreen_dwarfmodest);
//DEFINE_CONFIRMATION(trade_offer, viewscreen_dwarfmodest);
//DEFINE_CONFIRMATION(trade_select_all, viewscreen_dwarfmodest);
//DEFINE_CONFIRMATION(uniform_delete, viewscreen_dwarfmodest);
//DEFINE_CONFIRMATION(note_delete, viewscreen_dwarfmodest); //DEFINE_CONFIRMATION(note_delete, viewscreen_dwarfmodest);
//DEFINE_CONFIRMATION(route_delete, viewscreen_dwarfmodest); //DEFINE_CONFIRMATION(route_delete, viewscreen_dwarfmodest);
// locations can't be retired currently
//DEFINE_CONFIRMATION(location_retire, viewscreen_locationsst); //DEFINE_CONFIRMATION(location_retire, viewscreen_locationsst);
//DEFINE_CONFIRMATION(convict, viewscreen_justicest);
//DEFINE_CONFIRMATION(order_remove, viewscreen_jobmanagementst);
DFhackCExport command_result plugin_init (color_ostream &out, vector <PluginCommand> &commands) DFhackCExport command_result plugin_init (color_ostream &out, vector <PluginCommand> &commands)
{ {

@ -58,9 +58,71 @@ is equivalent to:
]] ]]
trade_cancel = defconf('trade-cancel')
function trade_cancel.intercept_key(key)
return dfhack.gui.matchFocusString("dwarfmode/Trade") and
(key == keys.LEAVESCREEN or key == MOUSE_RIGHT) and
(trader_goods_selected(screen) or broker_goods_selected(screen))
end
trade_cancel.title = "Cancel trade"
trade_cancel.message = "Are you sure you want leave this screen?\nSelected items will not be saved."
haul_delete_route = defconf('haul-delete-route')
function haul_delete_route.intercept_key(key)
return df.global.game.main_interface.current_hover == 180 and key == MOUSE_LEFT
end
haul_delete_route.title = "Confirm deletion"
haul_delete_route.message = "Are you sure you want to delete this route?"
haul_delete_stop = defconf('haul-delete-stop')
function haul_delete_stop.intercept_key(key)
return df.global.game.main_interface.current_hover == 185 and key == MOUSE_LEFT
end
haul_delete_stop.title = "Confirm deletion"
haul_delete_stop.message = "Are you sure you want to delete this stop?"
depot_remove = defconf('depot-remove')
function depot_remove.intercept_key(key)
if df.global.game.main_interface.current_hover == 299 and
key == MOUSE_LEFT and
df.building_tradedepotst:is_instance(dfhack.gui.getSelectedBuilding(true)) then
for _, caravan in pairs(df.global.plotinfo.caravans) do
if caravan.time_remaining > 0 then
return true
end
end
end
end
depot_remove.title = "Confirm depot removal"
depot_remove.message = "Are you sure you want to remove this depot?\n" ..
"Merchants are present and will lose profits."
squad_disband = defconf('squad-disband')
function squad_disband.intercept_key(key)
return key == MOUSE_LEFT and df.global.game.main_interface.current_hover == 341
end
squad_disband.title = "Disband squad"
squad_disband.message = "Are you sure you want to disband this squad?"
order_remove = defconf('order-remove')
function order_remove.intercept_key(key)
return key == MOUSE_LEFT and df.global.game.main_interface.current_hover == 222
end
order_remove.title = "Remove manager order"
order_remove.message = "Are you sure you want to remove this order?"
zone_remove = defconf('zone-remove')
function zone_remove.intercept_key(key)
return key == MOUSE_LEFT and df.global.game.main_interface.current_hover == 130
end
zone_remove.title = "Remove zone"
zone_remove.message = "Are you sure you want to remove this zone?"
-- these confirmations have more complex button detection requirements
--[[
trade = defconf('trade') trade = defconf('trade')
function trade.intercept_key(key) function trade.intercept_key(key)
return false--dfhack.gui.matchFocusString("dwarfmode/Trade") and key == MOUSE_LEFT and hovering over trade button? dfhack.gui.matchFocusString("dwarfmode/Trade") and key == MOUSE_LEFT and hovering over trade button?
end end
trade.title = "Confirm trade" trade.title = "Confirm trade"
function trade.get_message() function trade.get_message()
@ -81,16 +143,7 @@ function trade.get_message()
end end
end end
trade_cancel = defconf('trade-cancel') trade_seize = defconf('trade-seize')
function trade_cancel.intercept_key(key)
return dfhack.gui.matchFocusString("dwarfmode/Trade") and
(key == keys.LEAVESCREEN or key == MOUSE_RIGHT) and
(trader_goods_selected(screen) or broker_goods_selected(screen))
end
trade_cancel.title = "Cancel trade"
trade_cancel.message = "Are you sure you want leave this screen?\nSelected items will not be saved."
--[[trade_seize = defconf('trade-seize')
function trade_seize.intercept_key(key) function trade_seize.intercept_key(key)
return screen.in_edit_count == 0 and return screen.in_edit_count == 0 and
trader_goods_selected(screen) and trader_goods_selected(screen) and
@ -121,46 +174,9 @@ function trade_select_all.intercept_key(key)
end end
trade_select_all.title = "Confirm selection" trade_select_all.title = "Confirm selection"
trade_select_all.message = "Selecting all goods will overwrite your current selection\n" .. trade_select_all.message = "Selecting all goods will overwrite your current selection\n" ..
"and cannot be undone. Continue?"--]] "and cannot be undone. Continue?"
haul_delete_route = defconf('haul-delete-route') uniform_delete = defconf('uniform-delete')
function haul_delete_route.intercept_key(key)
return df.global.game.main_interface.current_hover == 180 and key == MOUSE_LEFT
end
haul_delete_route.title = "Confirm deletion"
haul_delete_route.message = "Are you sure you want to delete this route?"
haul_delete_stop = defconf('haul-delete-stop')
function haul_delete_stop.intercept_key(key)
return df.global.game.main_interface.current_hover == 185 and key == MOUSE_LEFT
end
haul_delete_stop.title = "Confirm deletion"
haul_delete_stop.message = "Are you sure you want to delete this stop?"
depot_remove = defconf('depot-remove')
function depot_remove.intercept_key(key)
if df.global.game.main_interface.current_hover == 299 and
key == MOUSE_LEFT and
df.building_tradedepotst:is_instance(dfhack.gui.getSelectedBuilding(true)) then
for _, caravan in pairs(df.global.plotinfo.caravans) do
if caravan.time_remaining > 0 then
return true
end
end
end
end
depot_remove.title = "Confirm depot removal"
depot_remove.message = "Are you sure you want to remove this depot?\n" ..
"Merchants are present and will lose profits."
squad_disband = defconf('squad-disband')
function squad_disband.intercept_key(key)
return key == MOUSE_LEFT and df.global.game.main_interface.current_hover == 341
end
squad_disband.title = "Disband squad"
squad_disband.message = "Are you sure you want to disband this squad?"
--[[uniform_delete = defconf('uniform-delete')
function uniform_delete.intercept_key(key) function uniform_delete.intercept_key(key)
return key == keys.D_MILITARY_DELETE_UNIFORM and return key == keys.D_MILITARY_DELETE_UNIFORM and
screen.page == screen._type.T_page.Uniforms and screen.page == screen._type.T_page.Uniforms and
@ -189,17 +205,6 @@ end
route_delete.title = "Delete route" route_delete.title = "Delete route"
route_delete.message = "Are you sure you want to delete this route?" route_delete.message = "Are you sure you want to delete this route?"
location_retire = defconf('location-retire')
function location_retire.intercept_key(key)
return key == keys.LOCATION_RETIRE and
(screen.menu == df.viewscreen_locationsst.T_menu.Locations or
screen.menu == df.viewscreen_locationsst.T_menu.Occupations) and
screen.in_edit == df.viewscreen_locationsst.T_in_edit.None and
screen.locations[screen.location_idx]
end
location_retire.title = "Retire location"
location_retire.message = "Are you sure you want to retire this location?"
convict = defconf('convict') convict = defconf('convict')
convict.title = "Confirm conviction" convict.title = "Confirm conviction"
function convict.intercept_key(key) function convict.intercept_key(key)
@ -214,15 +219,22 @@ function convict.get_message()
return "Are you sure you want to convict " .. name .. "?\n" .. return "Are you sure you want to convict " .. name .. "?\n" ..
"This action is irreversible." "This action is irreversible."
end end
]]--
order_remove = defconf('order-remove') -- locations cannot be retired currently
function order_remove.intercept_key(key) --[[
return key == keys.MANAGER_REMOVE and location_retire = defconf('location-retire')
not screen.in_max_workshops function location_retire.intercept_key(key)
return key == keys.LOCATION_RETIRE and
(screen.menu == df.viewscreen_locationsst.T_menu.Locations or
screen.menu == df.viewscreen_locationsst.T_menu.Occupations) and
screen.in_edit == df.viewscreen_locationsst.T_in_edit.None and
screen.locations[screen.location_idx]
end end
order_remove.title = "Remove manager order" location_retire.title = "Retire location"
order_remove.message = "Are you sure you want to remove this order?" location_retire.message = "Are you sure you want to retire this location?"
]]-- ]]--
-- End of confirmation definitions -- End of confirmation definitions
function check() function check()