move quickfort logic from Planner to buildingplan

where all the other gui-related logic is.
develop
Myk Taylor 2020-09-08 17:34:11 -07:00
parent f3da131db7
commit 3b362294b9
3 changed files with 25 additions and 53 deletions

@ -291,11 +291,9 @@ void PlannedBuilding::remove()
* Planner
*/
Planner::Planner() : in_dummmy_screen(false), quickfort_mode(false) { }
Planner::Planner() { }
void enable_quickfort_fn(pair<const df::building_type, bool>& pair) { pair.second = true; }
bool Planner::isPlanableBuilding(const df::building_type type) const
bool Planner::isPlannableBuilding(const df::building_type type) const
{
return item_for_building_type.find(type) != item_for_building_type.end();
}
@ -321,8 +319,6 @@ void Planner::initialize()
default_item_filters[df::building_type::btype] = ItemFilter(); \
available_item_vectors[df::item_type::itype] = std::vector<df::item *>(); \
is_relevant_item_type[df::item_type::itype] = true; \
if (planmode_enabled.find(df::building_type::btype) == planmode_enabled.end()) \
planmode_enabled[df::building_type::btype] = false
FOR_ENUM_ITEMS(item_type, it)
is_relevant_item_type[it] = false;
@ -474,22 +470,6 @@ void Planner::adjustMaxQuality(df::building_type type, int amount)
(*min_quality) = *max_quality;
}
void Planner::enableQuickfortMode()
{
saved_planmodes = planmode_enabled;
for_each_(planmode_enabled, enable_quickfort_fn);
quickfort_mode = true;
}
void Planner::disableQuickfortMode()
{
planmode_enabled = saved_planmodes;
quickfort_mode = false;
}
bool Planner::inQuickFortMode() { return quickfort_mode; }
void Planner::boundsCheckItemQuality(item_quality::item_quality *quality)
{
*quality = static_cast<df::item_quality>(*quality);
@ -517,7 +497,7 @@ void Planner::gather_available_items()
F(in_building); F(construction); F(artifact);
#undef F
std::vector<df::item*> &items = df::global::world->items.other[df::items_other_id::IN_PLAY];
std::vector<df::item*> &items = df::global::world->items.other[df::items_other_id::IN_PLAY];
for (size_t i = 0; i < items.size(); i++)
{
@ -548,5 +528,4 @@ void Planner::gather_available_items()
}
}
std::map<df::building_type, bool> planmode_enabled, saved_planmodes;
Planner planner;

@ -61,11 +61,9 @@ private:
class Planner
{
public:
bool in_dummmy_screen;
Planner();
bool isPlanableBuilding(const df::building_type type) const;
bool isPlannableBuilding(const df::building_type type) const;
void reset(DFHack::color_ostream &out);
@ -86,16 +84,11 @@ public:
void adjustMinQuality(df::building_type type, int amount);
void adjustMaxQuality(df::building_type type, int amount);
void enableQuickfortMode();
void disableQuickfortMode();
bool inQuickFortMode();
private:
std::map<df::building_type, df::item_type> item_for_building_type;
std::map<df::building_type, ItemFilter> default_item_filters;
std::map<df::item_type, std::vector<df::item *>> available_item_vectors;
std::map<df::item_type, bool> is_relevant_item_type; //Needed for fast check when looping over all items
bool quickfort_mode;
std::vector<PlannedBuilding> planned_buildings;
@ -104,5 +97,4 @@ private:
void gather_available_items();
};
extern std::map<df::building_type, bool> planmode_enabled, saved_planmodes;
extern Planner planner;

@ -28,6 +28,9 @@ using namespace DFHack;
using namespace df::enums;
bool show_help = false;
bool quickfort_mode = false;
bool in_dummy_screen = false;
std::map<df::building_type, bool> planmode_enabled;
class ViewscreenChooseMaterial : public dfhack_viewscreen
{
@ -316,7 +319,7 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
return ui->main.mode == ui_sidebar_mode::Build &&
df::global::ui_build_selector &&
df::global::ui_build_selector->stage < 2 &&
planner.isPlanableBuilding(ui_build_selector->building_type);
planner.isPlannableBuilding(ui_build_selector->building_type);
}
std::vector<Units::NoblePosition> getNoblePositionOfSelectedBuildingOwner()
@ -357,11 +360,16 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
auto type = ui_build_selector->building_type;
if (input->count(interface_key::CUSTOM_SHIFT_P))
{
if (planmode_enabled.find(type) == planmode_enabled.end())
{
planmode_enabled[type] = false;
}
planmode_enabled[type] = !planmode_enabled[type];
if (!planmode_enabled[type])
{
Gui::refreshSidebar();
planner.in_dummmy_screen = false;
in_dummy_screen = false;
}
return true;
}
@ -375,12 +383,12 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
if (is_planmode_enabled(type))
{
if (planner.inQuickFortMode() && planner.in_dummmy_screen)
if (quickfort_mode && in_dummy_screen)
{
if (input->count(interface_key::SELECT) || input->count(interface_key::SEC_SELECT)
|| input->count(interface_key::LEAVESCREEN))
{
planner.in_dummmy_screen = false;
in_dummy_screen = false;
send_key(interface_key::LEAVESCREEN);
}
@ -392,9 +400,9 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
if (ui_build_selector->errors.size() == 0 && planner.allocatePlannedBuilding(type))
{
Gui::refreshSidebar();
if (planner.inQuickFortMode())
if (quickfort_mode)
{
planner.in_dummmy_screen = true;
in_dummy_screen = true;
}
}
@ -402,14 +410,7 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
}
else if (input->count(interface_key::CUSTOM_SHIFT_F))
{
if (!planner.inQuickFortMode())
{
planner.enableQuickfortMode();
}
else
{
planner.disableQuickfortMode();
}
quickfort_mode = !quickfort_mode;
}
else if (input->count(interface_key::CUSTOM_SHIFT_M))
{
@ -509,7 +510,7 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
auto type = ui_build_selector->building_type;
if (plannable)
{
if (planner.inQuickFortMode() && planner.in_dummmy_screen)
if (quickfort_mode && in_dummy_screen)
{
Screen::Pen pen(' ',COLOR_BLACK);
int y = dims.y1 + 1;
@ -533,7 +534,7 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
if (is_planmode_enabled(type))
{
OutputToggleString(x, y, "Quickfort Mode", "F", planner.inQuickFortMode(), true, left_margin);
OutputToggleString(x, y, "Quickfort Mode", "F", quickfort_mode, true, left_margin);
auto filter = planner.getDefaultItemFilterForType(type);
@ -552,13 +553,13 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
}
else
{
planner.in_dummmy_screen = false;
in_dummy_screen = false;
}
}
}
else if (isInPlannedBuildingQueryMode())
{
planner.in_dummmy_screen = false;
in_dummy_screen = false;
// Hide suspend toggle option
int y = 20;
@ -597,7 +598,7 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
}
else
{
planner.in_dummmy_screen = false;
in_dummy_screen = false;
show_help = false;
}
}
@ -690,7 +691,7 @@ DFhackCExport command_result plugin_shutdown(color_ostream &)
// Lua API section
static bool isPlannableBuilding(df::building_type type) {
return planner.isPlanableBuilding(type);
return planner.isPlannableBuilding(type);
}
static void addPlannedBuilding(df::building *bld) {