add 'enable all' option for buildingplan

This kind of functionality is much more important now than it used to
be since there are so many supported building types.

Also modified the 'Planning Mode' status on the building placement
screen to reflect whether we're in quickfort mode, enable all mode, or
whether just the building type is enabled.

this setting is not persisted (just like quickfort_mode is not
persisted), but it can be set from onMapLoad.init
develop
Myk Taylor 2020-11-04 08:52:19 -08:00 committed by myk002
parent d01e61c658
commit d0fc448a39
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
2 changed files with 31 additions and 4 deletions

@ -27,6 +27,7 @@ REQUIRE_GLOBAL(world); // used in buildingplan library
bool show_help = false; bool show_help = false;
bool quickfort_mode = false; bool quickfort_mode = false;
bool all_enabled = false;
bool in_dummy_screen = false; bool in_dummy_screen = false;
std::unordered_map<BuildingTypeKey, bool, BuildingTypeKeyHash> planmode_enabled; std::unordered_map<BuildingTypeKey, bool, BuildingTypeKeyHash> planmode_enabled;
@ -284,7 +285,7 @@ void ViewscreenChooseMaterial::render()
//START Viewscreen Hook //START Viewscreen Hook
static bool is_planmode_enabled(BuildingTypeKey key) static bool is_planmode_enabled(BuildingTypeKey key)
{ {
return planmode_enabled[key] || quickfort_mode; return planmode_enabled[key] || quickfort_mode || all_enabled;
} }
static std::string get_item_label(const BuildingTypeKey &key, int item_idx) static std::string get_item_label(const BuildingTypeKey &key, int item_idx)
@ -387,6 +388,7 @@ static void show_global_settings_dialog()
lua_newtable(L); lua_newtable(L);
int ctable = lua_gettop(L); int ctable = lua_gettop(L);
Lua::SetField(L, quickfort_mode, ctable, "quickfort_mode"); Lua::SetField(L, quickfort_mode, ctable, "quickfort_mode");
Lua::SetField(L, all_enabled, ctable, "all_enabled");
for (auto & setting : planner.getGlobalSettings()) for (auto & setting : planner.getGlobalSettings())
{ {
@ -629,7 +631,8 @@ struct buildingplan_place_hook : public df::viewscreen_dwarfmodest
show_help = true; show_help = true;
} }
if (input->count(interface_key::CUSTOM_SHIFT_P)) if (!quickfort_mode && !all_enabled
&& input->count(interface_key::CUSTOM_SHIFT_P))
{ {
planmode_enabled[key] = !planmode_enabled[key]; planmode_enabled[key] = !planmode_enabled[key];
if (!is_planmode_enabled(key)) if (!is_planmode_enabled(key))
@ -765,8 +768,16 @@ struct buildingplan_place_hook : public df::viewscreen_dwarfmodest
OutputString(COLOR_WHITE, x, y, "Use Shift-Keys here", true, left_margin); OutputString(COLOR_WHITE, x, y, "Use Shift-Keys here", true, left_margin);
} }
OutputToggleString(x, y, "Planning Mode", interface_key::CUSTOM_SHIFT_P, OutputHotkeyString(x, y, "Planning Mode", interface_key::CUSTOM_SHIFT_P);
planmode_enabled[key], true, left_margin, COLOR_WHITE, COLOR_LIGHTRED); OutputString(COLOR_WHITE, x, y, ": ");
if (quickfort_mode)
OutputString(COLOR_YELLOW, x, y, "Quickfort", true, left_margin);
else if (all_enabled)
OutputString(COLOR_YELLOW, x, y, "All", true, left_margin);
else if (planmode_enabled[key])
OutputString(COLOR_GREEN, x, y, "On", true, left_margin);
else
OutputString(COLOR_GREY, x, y, "Off", true, left_margin);
OutputHotkeyString(x, y, "Global Settings", interface_key::CUSTOM_SHIFT_G, OutputHotkeyString(x, y, "Global Settings", interface_key::CUSTOM_SHIFT_G,
true, left_margin, COLOR_WHITE, COLOR_LIGHTRED); true, left_margin, COLOR_WHITE, COLOR_LIGHTRED);
@ -963,6 +974,7 @@ static command_result buildingplan_cmd(color_ostream &out, vector <string> & par
// display current settings // display current settings
out.print("active settings:\n"); out.print("active settings:\n");
out.print(" all_enabled = %s\n", all_enabled ? "true" : "false");
for (auto & setting : planner.getGlobalSettings()) for (auto & setting : planner.getGlobalSettings())
{ {
out.print(" %s = %s\n", setting.first.c_str(), out.print(" %s = %s\n", setting.first.c_str(),
@ -1108,6 +1120,12 @@ static bool setSetting(std::string name, bool value) {
quickfort_mode = value; quickfort_mode = value;
return true; return true;
} }
if (name == "all_enabled")
{
debug("setting all_enabled %d -> %d", all_enabled, value);
all_enabled = value;
return;
}
return planner.setGlobalSetting(name, value); return planner.setGlobalSetting(name, value);
} }

@ -229,7 +229,16 @@ end
setting is not needed for DFHack quickfort. setting is not needed for DFHack quickfort.
--]] --]]
function GlobalSettings:init() function GlobalSettings:init()
self.subviews.label:setText{ self.subviews.label:setText{
self:make_setting_label_token('Enable all', 'CUSTOM_E', 'all_enabled', 12),
self:make_setting_value_token('all_enabled'), '\n',
' Enables buildingplan for all building types. Use this to avoid having\n',
' to manually enable buildingplan for each building type that you want\n',
' to plan. Note that DFHack quickfort will use buildingplan to manage\n',
' buildings regardless of whether buildingplan is "enabled" for the\n',
' building type.\n',
'\n',
'Allowed types for generic, fire-safe, and magma-safe building material:\n', 'Allowed types for generic, fire-safe, and magma-safe building material:\n',
self:make_setting_label_token('Blocks', 'CUSTOM_B', 'blocks', 10), self:make_setting_label_token('Blocks', 'CUSTOM_B', 'blocks', 10),
self:make_setting_value_token('blocks'), '\n', self:make_setting_value_token('blocks'), '\n',