2018-05-12 15:00:21 -06:00
|
|
|
#include "MiscUtils.h"
|
|
|
|
#include "VTableInterpose.h"
|
2015-07-28 16:34:29 -06:00
|
|
|
#include "uicommon.h"
|
|
|
|
|
2018-05-12 15:00:21 -06:00
|
|
|
#include "modules/Buildings.h"
|
|
|
|
#include "modules/Gui.h"
|
|
|
|
#include "modules/Job.h"
|
|
|
|
#include "modules/Screen.h"
|
|
|
|
#include "modules/Translation.h"
|
|
|
|
#include "modules/Units.h"
|
|
|
|
|
2015-12-27 13:49:10 -07:00
|
|
|
#include "df/creature_raw.h"
|
2018-05-12 15:00:21 -06:00
|
|
|
#include "df/global_objects.h"
|
2015-06-11 19:37:58 -06:00
|
|
|
#include "df/historical_figure.h"
|
2012-10-19 06:38:28 -06:00
|
|
|
#include "df/interface_key.h"
|
2012-11-03 05:34:04 -06:00
|
|
|
#include "df/interfacest.h"
|
2012-12-27 02:23:13 -07:00
|
|
|
#include "df/job.h"
|
2018-05-12 15:00:21 -06:00
|
|
|
#include "df/layer_object_listst.h"
|
|
|
|
#include "df/misc_trait_type.h"
|
2012-12-27 02:23:13 -07:00
|
|
|
#include "df/report.h"
|
2018-05-12 15:00:21 -06:00
|
|
|
#include "df/ui_look_list.h"
|
2012-12-27 02:23:13 -07:00
|
|
|
#include "df/unit.h"
|
2013-01-16 07:30:29 -07:00
|
|
|
#include "df/unit_misc_trait.h"
|
2018-05-12 15:00:21 -06:00
|
|
|
#include "df/viewscreen_announcelistst.h"
|
|
|
|
#include "df/viewscreen_buildinglistst.h"
|
|
|
|
#include "df/viewscreen_dwarfmodest.h"
|
|
|
|
#include "df/viewscreen_joblistst.h"
|
2020-04-06 11:13:18 -06:00
|
|
|
#include "df/viewscreen_justicest.h"
|
2018-05-16 22:11:52 -06:00
|
|
|
#include "df/viewscreen_kitchenprefst.h"
|
2018-05-12 15:00:21 -06:00
|
|
|
#include "df/viewscreen_layer_militaryst.h"
|
|
|
|
#include "df/viewscreen_layer_noblelistst.h"
|
|
|
|
#include "df/viewscreen_layer_stockpilest.h"
|
2018-05-14 20:30:21 -06:00
|
|
|
#include "df/viewscreen_layer_stone_restrictionst.h"
|
2018-05-12 15:00:21 -06:00
|
|
|
#include "df/viewscreen_locationsst.h"
|
|
|
|
#include "df/viewscreen_petst.h"
|
|
|
|
#include "df/viewscreen_storesst.h"
|
|
|
|
#include "df/viewscreen_topicmeeting_fill_land_holder_positionsst.h"
|
|
|
|
#include "df/viewscreen_tradegoodsst.h"
|
|
|
|
#include "df/viewscreen_unitlistst.h"
|
|
|
|
#include "df/viewscreen_workshop_profilest.h"
|
2012-10-19 06:38:28 -06:00
|
|
|
|
2013-10-08 07:41:49 -06:00
|
|
|
using namespace std;
|
2012-10-19 06:38:28 -06:00
|
|
|
using std::set;
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
|
2014-12-06 16:47:35 -07:00
|
|
|
DFHACK_PLUGIN("search");
|
|
|
|
DFHACK_PLUGIN_IS_ENABLED(is_enabled);
|
|
|
|
|
|
|
|
REQUIRE_GLOBAL(gps);
|
|
|
|
REQUIRE_GLOBAL(gview);
|
|
|
|
REQUIRE_GLOBAL(ui);
|
2015-01-05 17:36:06 -07:00
|
|
|
REQUIRE_GLOBAL(ui_building_assign_units);
|
|
|
|
REQUIRE_GLOBAL(ui_building_in_assign);
|
|
|
|
REQUIRE_GLOBAL(ui_building_item_cursor);
|
2015-06-16 18:36:19 -06:00
|
|
|
REQUIRE_GLOBAL(ui_look_cursor);
|
|
|
|
REQUIRE_GLOBAL(ui_look_list);
|
2018-05-14 20:30:21 -06:00
|
|
|
REQUIRE_GLOBAL(world);
|
2012-10-19 06:38:28 -06:00
|
|
|
|
2012-10-23 02:20:51 -06:00
|
|
|
/*
|
|
|
|
Search Plugin
|
|
|
|
|
|
|
|
A plugin that adds a "Search" hotkey to some screens (Units, Trade and Stocks)
|
|
|
|
that allows filtering of the list items by a typed query.
|
|
|
|
|
|
|
|
Works by manipulating the vector(s) that the list based viewscreens use to store
|
|
|
|
their items. When a search is started the plugin saves the original vectors and
|
|
|
|
with each keystroke creates a new filtered vector off the saves for the screen
|
|
|
|
to use.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-01-16 09:42:41 -07:00
|
|
|
void make_text_dim(int x1, int x2, int y)
|
|
|
|
{
|
|
|
|
for (int x = x1; x <= x2; x++)
|
|
|
|
{
|
|
|
|
Screen::Pen pen = Screen::readTile(x,y);
|
|
|
|
|
|
|
|
if (pen.valid())
|
|
|
|
{
|
|
|
|
if (pen.fg != 0)
|
|
|
|
{
|
|
|
|
if (pen.fg == 7)
|
|
|
|
pen.adjust(0,true);
|
|
|
|
else
|
|
|
|
pen.bold = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Screen::paintTile(pen,x,y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-03 05:34:04 -06:00
|
|
|
static bool is_live_screen(const df::viewscreen *screen)
|
|
|
|
{
|
|
|
|
for (df::viewscreen *cur = &gview->view; cur; cur = cur->child)
|
|
|
|
if (cur == screen)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
static string get_unit_description(df::unit *unit)
|
|
|
|
{
|
2015-06-30 14:18:27 -06:00
|
|
|
if (!unit)
|
|
|
|
return "";
|
2012-12-27 02:23:13 -07:00
|
|
|
string desc;
|
|
|
|
auto name = Units::getVisibleName(unit);
|
|
|
|
if (name->has_name)
|
|
|
|
desc = Translation::TranslateName(name, false);
|
|
|
|
desc += ", " + Units::getProfessionName(unit); // Check animal type too
|
|
|
|
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
2015-06-16 18:36:19 -06:00
|
|
|
static bool cursor_key_pressed (std::set<df::interface_key> *input)
|
|
|
|
{
|
2015-06-30 14:45:45 -06:00
|
|
|
// give text input (e.g. "2") priority over cursor keys
|
|
|
|
for (auto it = input->begin(); it != input->end(); ++it)
|
|
|
|
{
|
|
|
|
if (Screen::keyToChar(*it) != -1)
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-16 18:36:19 -06:00
|
|
|
return
|
|
|
|
input->count(df::interface_key::CURSOR_UP) ||
|
|
|
|
input->count(df::interface_key::CURSOR_DOWN) ||
|
|
|
|
input->count(df::interface_key::CURSOR_LEFT) ||
|
|
|
|
input->count(df::interface_key::CURSOR_RIGHT) ||
|
|
|
|
input->count(df::interface_key::CURSOR_UPLEFT) ||
|
|
|
|
input->count(df::interface_key::CURSOR_UPRIGHT) ||
|
|
|
|
input->count(df::interface_key::CURSOR_DOWNLEFT) ||
|
|
|
|
input->count(df::interface_key::CURSOR_DOWNRIGHT) ||
|
|
|
|
input->count(df::interface_key::CURSOR_UP_FAST) ||
|
|
|
|
input->count(df::interface_key::CURSOR_DOWN_FAST) ||
|
|
|
|
input->count(df::interface_key::CURSOR_LEFT_FAST) ||
|
|
|
|
input->count(df::interface_key::CURSOR_RIGHT_FAST) ||
|
|
|
|
input->count(df::interface_key::CURSOR_UPLEFT_FAST) ||
|
|
|
|
input->count(df::interface_key::CURSOR_UPRIGHT_FAST) ||
|
|
|
|
input->count(df::interface_key::CURSOR_DOWNLEFT_FAST) ||
|
|
|
|
input->count(df::interface_key::CURSOR_DOWNRIGHT_FAST) ||
|
|
|
|
input->count(df::interface_key::CURSOR_UP_Z) ||
|
|
|
|
input->count(df::interface_key::CURSOR_DOWN_Z) ||
|
|
|
|
input->count(df::interface_key::CURSOR_UP_Z_AUX) ||
|
|
|
|
input->count(df::interface_key::CURSOR_DOWN_Z_AUX);
|
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
|
2012-10-20 19:18:29 -06:00
|
|
|
//
|
2012-12-27 02:23:13 -07:00
|
|
|
// START: Generic Search functionality
|
2012-10-20 19:18:29 -06:00
|
|
|
//
|
2012-10-23 02:20:51 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
template <class S, class T>
|
|
|
|
class search_generic
|
2012-10-19 06:38:28 -06:00
|
|
|
{
|
2012-10-21 02:32:01 -06:00
|
|
|
public:
|
2012-12-27 02:23:13 -07:00
|
|
|
bool init(S *screen)
|
|
|
|
{
|
|
|
|
if (screen != viewscreen && !reset_on_change())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!can_init(screen))
|
2013-01-16 09:30:11 -07:00
|
|
|
{
|
|
|
|
if (is_valid())
|
|
|
|
{
|
|
|
|
clear_search();
|
|
|
|
reset_all();
|
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
return false;
|
2013-01-16 09:30:11 -07:00
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
if (!is_valid())
|
|
|
|
{
|
|
|
|
this->viewscreen = screen;
|
|
|
|
this->cursor_pos = get_viewscreen_cursor();
|
|
|
|
this->primary_list = get_primary_list();
|
|
|
|
this->select_key = get_search_select_key();
|
2014-08-11 04:23:19 -06:00
|
|
|
select_token = Screen::charToKey(select_key);
|
|
|
|
shift_select_token = Screen::charToKey(select_key + 'A' - 'a');
|
2012-12-27 02:23:13 -07:00
|
|
|
valid = true;
|
|
|
|
do_post_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-23 02:20:51 -06:00
|
|
|
// Called each time you enter or leave a searchable screen. Resets everything.
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual void reset_all()
|
2012-10-21 02:32:01 -06:00
|
|
|
{
|
|
|
|
reset_search();
|
|
|
|
valid = false;
|
2012-12-27 02:23:13 -07:00
|
|
|
primary_list = NULL;
|
2012-10-21 02:32:01 -06:00
|
|
|
viewscreen = NULL;
|
|
|
|
select_key = 's';
|
|
|
|
}
|
|
|
|
|
2012-11-03 05:34:04 -06:00
|
|
|
bool reset_on_change()
|
|
|
|
{
|
|
|
|
if (valid && is_live_screen(viewscreen))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
reset_all();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-30 05:01:04 -07:00
|
|
|
bool is_valid()
|
|
|
|
{
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2012-10-23 02:20:51 -06:00
|
|
|
// A new keystroke is received in a searchable screen
|
2012-10-21 02:32:01 -06:00
|
|
|
virtual bool process_input(set<df::interface_key> *input)
|
|
|
|
{
|
2012-10-23 02:20:51 -06:00
|
|
|
// If the page has two search options (Trade screen), only allow one to operate
|
|
|
|
// at a time
|
2012-10-21 02:32:01 -06:00
|
|
|
if (lock != NULL && lock != this)
|
|
|
|
return false;
|
|
|
|
|
2012-10-23 02:20:51 -06:00
|
|
|
// Allows custom preprocessing for each screen
|
2012-10-21 02:32:01 -06:00
|
|
|
if (!should_check_input(input))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool key_processed = true;
|
|
|
|
|
|
|
|
if (entry_mode)
|
|
|
|
{
|
2012-10-23 02:20:51 -06:00
|
|
|
// Query typing mode
|
|
|
|
|
2015-07-28 16:34:29 -06:00
|
|
|
df::interface_key last_token = get_string_key(input);
|
2014-08-11 04:23:19 -06:00
|
|
|
int charcode = Screen::keyToChar(last_token);
|
|
|
|
if (charcode >= 32 && charcode <= 126)
|
2012-10-21 02:32:01 -06:00
|
|
|
{
|
2012-10-23 02:20:51 -06:00
|
|
|
// Standard character
|
2014-08-11 04:23:19 -06:00
|
|
|
search_string += char(charcode);
|
2012-10-21 02:32:01 -06:00
|
|
|
do_search();
|
|
|
|
}
|
|
|
|
else if (last_token == interface_key::STRING_A000)
|
|
|
|
{
|
2012-10-23 02:20:51 -06:00
|
|
|
// Backspace
|
2012-10-21 02:32:01 -06:00
|
|
|
if (search_string.length() > 0)
|
|
|
|
{
|
|
|
|
search_string.erase(search_string.length()-1);
|
|
|
|
do_search();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (input->count(interface_key::SELECT) || input->count(interface_key::LEAVESCREEN))
|
|
|
|
{
|
2012-10-23 02:20:51 -06:00
|
|
|
// ENTER or ESC: leave typing mode
|
2012-10-21 02:32:01 -06:00
|
|
|
end_entry_mode();
|
|
|
|
}
|
2015-06-16 18:36:19 -06:00
|
|
|
else if (cursor_key_pressed(input))
|
2012-10-21 02:32:01 -06:00
|
|
|
{
|
2012-10-23 02:20:51 -06:00
|
|
|
// Arrow key pressed. Leave entry mode and allow screen to process key
|
2012-10-21 02:32:01 -06:00
|
|
|
end_entry_mode();
|
|
|
|
key_processed = false;
|
|
|
|
}
|
|
|
|
}
|
2012-10-23 02:20:51 -06:00
|
|
|
// Not in query typing mode
|
2012-10-21 02:32:01 -06:00
|
|
|
else if (input->count(select_token))
|
|
|
|
{
|
2012-10-23 02:20:51 -06:00
|
|
|
// Hotkey pressed, enter typing mode
|
2012-10-21 02:32:01 -06:00
|
|
|
start_entry_mode();
|
|
|
|
}
|
2014-08-11 04:23:19 -06:00
|
|
|
else if (input->count(shift_select_token))
|
2012-10-21 02:32:01 -06:00
|
|
|
{
|
2012-10-23 02:20:51 -06:00
|
|
|
// Shift + Hotkey pressed, clear query
|
2012-10-21 02:32:01 -06:00
|
|
|
clear_search();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-23 02:20:51 -06:00
|
|
|
// Not a key for us, pass it on to the screen
|
2012-10-21 02:32:01 -06:00
|
|
|
key_processed = false;
|
|
|
|
}
|
|
|
|
|
2012-10-23 02:20:51 -06:00
|
|
|
return key_processed || entry_mode; // Only pass unrecognized keys down if not in typing mode
|
2012-10-21 02:32:01 -06:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
// Called after a keystroke has been processed
|
|
|
|
virtual void do_post_input_feed()
|
2012-10-21 02:32:01 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
static search_generic<S, T> *lock;
|
2012-10-21 02:32:01 -06:00
|
|
|
|
2015-05-08 14:27:52 -06:00
|
|
|
bool in_entry_mode()
|
|
|
|
{
|
|
|
|
return entry_mode;
|
|
|
|
}
|
|
|
|
|
2012-10-21 02:32:01 -06:00
|
|
|
protected:
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual string get_element_description(T element) const = 0;
|
|
|
|
virtual void render() const = 0;
|
|
|
|
virtual int32_t *get_viewscreen_cursor() = 0;
|
|
|
|
virtual vector<T> *get_primary_list() = 0;
|
2012-10-20 19:18:29 -06:00
|
|
|
|
2014-08-11 04:23:19 -06:00
|
|
|
search_generic()
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
|
|
|
reset_all();
|
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual bool can_init(S *screen)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void do_post_init()
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
2012-10-21 02:32:01 -06:00
|
|
|
|
|
|
|
void start_entry_mode()
|
|
|
|
{
|
|
|
|
entry_mode = true;
|
|
|
|
lock = this;
|
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
|
2012-10-21 02:32:01 -06:00
|
|
|
void end_entry_mode()
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
|
|
|
entry_mode = false;
|
2012-10-21 02:32:01 -06:00
|
|
|
lock = NULL;
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual char get_search_select_key()
|
|
|
|
{
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void reset_search()
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-10-21 02:32:01 -06:00
|
|
|
end_entry_mode();
|
|
|
|
search_string = "";
|
|
|
|
saved_list1.clear();
|
2012-10-21 07:42:17 -06:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
// Shortcut to clear the search immediately
|
|
|
|
virtual void clear_search()
|
2012-10-21 07:42:17 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
if (saved_list1.size() > 0)
|
2012-10-21 07:42:17 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
*primary_list = saved_list1;
|
|
|
|
saved_list1.clear();
|
|
|
|
}
|
|
|
|
search_string = "";
|
|
|
|
}
|
2012-10-21 07:42:17 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual void save_original_values()
|
|
|
|
{
|
|
|
|
saved_list1 = *primary_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void do_pre_incremental_search()
|
|
|
|
{
|
2012-10-21 07:42:17 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual void clear_viewscreen_vectors()
|
2012-11-30 05:01:04 -07:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
primary_list->clear();
|
2012-11-30 05:01:04 -07:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual void add_to_filtered_list(size_t i)
|
2012-10-21 07:42:17 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
primary_list->push_back(saved_list1[i]);
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual void do_post_search()
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-11-03 05:34:04 -06:00
|
|
|
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:14:25 -07:00
|
|
|
virtual bool is_valid_for_search(size_t index)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-16 09:30:11 -07:00
|
|
|
virtual bool force_in_search(size_t index)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-23 02:20:51 -06:00
|
|
|
// The actual sort
|
2012-11-30 05:01:04 -07:00
|
|
|
virtual void do_search()
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
|
|
|
if (search_string.length() == 0)
|
|
|
|
{
|
|
|
|
clear_search();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (saved_list1.size() == 0)
|
2012-10-23 02:20:51 -06:00
|
|
|
// On first run, save the original list
|
2012-12-27 02:23:13 -07:00
|
|
|
save_original_values();
|
2012-10-21 07:42:17 -06:00
|
|
|
else
|
2012-12-27 02:23:13 -07:00
|
|
|
do_pre_incremental_search();
|
2012-10-21 07:42:17 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
clear_viewscreen_vectors();
|
2012-10-20 19:18:29 -06:00
|
|
|
|
|
|
|
string search_string_l = toLower(search_string);
|
2012-11-03 04:31:07 -06:00
|
|
|
for (size_t i = 0; i < saved_list1.size(); i++ )
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2013-01-16 09:30:11 -07:00
|
|
|
if (force_in_search(i))
|
|
|
|
{
|
|
|
|
add_to_filtered_list(i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-05 22:14:25 -07:00
|
|
|
if (!is_valid_for_search(i))
|
|
|
|
continue;
|
|
|
|
|
2012-10-21 07:42:17 -06:00
|
|
|
T element = saved_list1[i];
|
2012-10-20 19:18:29 -06:00
|
|
|
string desc = toLower(get_element_description(element));
|
|
|
|
if (desc.find(search_string_l) != string::npos)
|
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
add_to_filtered_list(i);
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
do_post_search();
|
2012-10-21 07:42:17 -06:00
|
|
|
|
2012-11-30 05:01:04 -07:00
|
|
|
if (cursor_pos)
|
|
|
|
*cursor_pos = 0;
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
|
|
|
|
2012-10-21 02:32:01 -06:00
|
|
|
virtual bool should_check_input(set<df::interface_key> *input)
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-10-21 02:32:01 -06:00
|
|
|
return true;
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
|
|
|
|
2012-10-23 02:20:51 -06:00
|
|
|
// Display hotkey message
|
2012-10-21 02:32:01 -06:00
|
|
|
void print_search_option(int x, int y = -1) const
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-11-23 18:18:56 -07:00
|
|
|
auto dim = Screen::getWindowSize();
|
2012-10-21 02:32:01 -06:00
|
|
|
if (y == -1)
|
2012-11-23 18:18:56 -07:00
|
|
|
y = dim.y - 2;
|
2012-10-20 19:18:29 -06:00
|
|
|
|
2012-10-21 02:32:01 -06:00
|
|
|
OutputString((entry_mode) ? 4 : 12, x, y, string(1, select_key));
|
|
|
|
OutputString((entry_mode) ? 10 : 15, x, y, ": Search");
|
2012-10-20 19:18:29 -06:00
|
|
|
if (search_string.length() > 0 || entry_mode)
|
2012-10-21 02:32:01 -06:00
|
|
|
OutputString(15, x, y, ": " + search_string);
|
2012-10-20 19:18:29 -06:00
|
|
|
if (entry_mode)
|
2012-10-21 02:32:01 -06:00
|
|
|
OutputString(10, x, y, "_");
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
2012-10-21 02:32:01 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
S *viewscreen;
|
|
|
|
vector <T> saved_list1, reference_list, *primary_list;
|
|
|
|
|
|
|
|
//bool redo_search;
|
|
|
|
string search_string;
|
2012-10-21 02:32:01 -06:00
|
|
|
|
2014-09-04 23:28:59 -06:00
|
|
|
protected:
|
2012-10-21 02:32:01 -06:00
|
|
|
int *cursor_pos;
|
|
|
|
char select_key;
|
2012-11-30 05:01:04 -07:00
|
|
|
bool valid;
|
2012-10-21 02:32:01 -06:00
|
|
|
bool entry_mode;
|
|
|
|
|
|
|
|
df::interface_key select_token;
|
2014-08-11 04:23:19 -06:00
|
|
|
df::interface_key shift_select_token;
|
2012-10-19 06:38:28 -06:00
|
|
|
};
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
template <class S, class T> search_generic<S, T> *search_generic<S, T> ::lock = NULL;
|
2012-10-20 19:18:29 -06:00
|
|
|
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
// Search class helper for layered screens
|
|
|
|
template <class S, class T, int LIST_ID>
|
|
|
|
class layered_search : public search_generic<S, T>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual bool can_init(S *screen)
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
auto list = getLayerList(screen);
|
2014-05-04 04:04:03 -06:00
|
|
|
if (!is_list_valid(screen) || !list || !list->active)
|
2012-12-27 02:23:13 -07:00
|
|
|
return false;
|
2012-10-20 19:18:29 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
return true;
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
|
|
|
|
2013-04-02 02:03:37 -06:00
|
|
|
virtual bool is_list_valid(S*)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-05 18:59:39 -07:00
|
|
|
virtual void do_search()
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2013-01-05 18:59:39 -07:00
|
|
|
search_generic<S,T>::do_search();
|
|
|
|
auto list = getLayerList(this->viewscreen);
|
|
|
|
list->num_entries = this->get_primary_list()->size();
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
2013-01-05 18:59:39 -07:00
|
|
|
|
|
|
|
int32_t *get_viewscreen_cursor()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
2013-01-05 18:59:39 -07:00
|
|
|
auto list = getLayerList(this->viewscreen);
|
2012-12-27 02:23:13 -07:00
|
|
|
return &list->cursor;
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
2012-10-19 06:38:28 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual void clear_search()
|
|
|
|
{
|
2013-01-05 18:59:39 -07:00
|
|
|
search_generic<S,T>::clear_search();
|
2013-04-02 02:03:37 -06:00
|
|
|
|
|
|
|
if (is_list_valid(this->viewscreen))
|
|
|
|
{
|
|
|
|
auto list = getLayerList(this->viewscreen);
|
|
|
|
list->num_entries = this->get_primary_list()->size();
|
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
2012-10-19 06:38:28 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
private:
|
|
|
|
static df::layer_object_listst *getLayerList(const df::viewscreen_layer *layer)
|
|
|
|
{
|
|
|
|
return virtual_cast<df::layer_object_listst>(vector_get(layer->layer_objects, LIST_ID));
|
|
|
|
}
|
|
|
|
};
|
2012-10-19 06:38:28 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
// Parent class for screens that have more than one primary list to synchronise
|
|
|
|
template < class S, class T, class PARENT = search_generic<S,T> >
|
|
|
|
class search_multicolumn_modifiable_generic : public PARENT
|
2012-10-19 06:38:28 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
protected:
|
|
|
|
vector <T> reference_list;
|
|
|
|
vector <int> saved_indexes;
|
|
|
|
bool read_only;
|
2012-10-21 02:32:01 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual void update_saved_secondary_list_item(size_t i, size_t j) = 0;
|
|
|
|
virtual void save_secondary_values() = 0;
|
|
|
|
virtual void clear_secondary_viewscreen_vectors() = 0;
|
|
|
|
virtual void add_to_filtered_secondary_lists(size_t i) = 0;
|
|
|
|
virtual void clear_secondary_saved_lists() = 0;
|
|
|
|
virtual void reset_secondary_viewscreen_vectors() = 0;
|
|
|
|
virtual void restore_secondary_values() = 0;
|
|
|
|
|
|
|
|
virtual void do_post_init()
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
// If true, secondary list isn't modifiable so don't bother synchronising values
|
|
|
|
read_only = false;
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void reset_all()
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
PARENT::reset_all();
|
|
|
|
reference_list.clear();
|
|
|
|
saved_indexes.clear();
|
|
|
|
reset_secondary_viewscreen_vectors();
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void reset_search()
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
PARENT::reset_search();
|
|
|
|
reference_list.clear();
|
|
|
|
saved_indexes.clear();
|
|
|
|
clear_secondary_saved_lists();
|
|
|
|
}
|
2012-11-03 05:34:04 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual void clear_search()
|
|
|
|
{
|
2013-01-05 18:59:39 -07:00
|
|
|
if (this->saved_list1.size() > 0)
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
do_pre_incremental_search();
|
|
|
|
restore_secondary_values();
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
clear_secondary_saved_lists();
|
|
|
|
PARENT::clear_search();
|
|
|
|
do_post_search();
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
2012-10-19 06:38:28 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual bool is_match(T &a, T &b) = 0;
|
2012-10-21 02:32:01 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual bool is_match(vector<T> &a, vector<T> &b) = 0;
|
2013-01-05 18:59:39 -07:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void do_pre_incremental_search()
|
2012-10-21 02:32:01 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
PARENT::do_pre_incremental_search();
|
|
|
|
if (read_only)
|
|
|
|
return;
|
2012-10-21 02:32:01 -06:00
|
|
|
|
2013-01-05 18:59:39 -07:00
|
|
|
bool list_has_been_sorted = (this->primary_list->size() == reference_list.size()
|
|
|
|
&& !is_match(*this->primary_list, reference_list));
|
2012-10-21 02:32:01 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
for (size_t i = 0; i < saved_indexes.size(); i++)
|
2012-10-21 02:32:01 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
int adjusted_item_index = i;
|
|
|
|
if (list_has_been_sorted)
|
|
|
|
{
|
2013-01-05 18:59:39 -07:00
|
|
|
for (size_t j = 0; j < this->primary_list->size(); j++)
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
2013-01-05 18:59:39 -07:00
|
|
|
if (is_match((*this->primary_list)[j], reference_list[i]))
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
adjusted_item_index = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-21 02:32:01 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
update_saved_secondary_list_item(saved_indexes[i], adjusted_item_index);
|
2012-10-21 02:32:01 -06:00
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
saved_indexes.clear();
|
|
|
|
}
|
2012-10-21 02:32:01 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void clear_viewscreen_vectors()
|
|
|
|
{
|
2013-01-05 18:59:39 -07:00
|
|
|
search_generic<S,T>::clear_viewscreen_vectors();
|
2012-12-27 02:23:13 -07:00
|
|
|
saved_indexes.clear();
|
|
|
|
clear_secondary_viewscreen_vectors();
|
2012-10-21 02:32:01 -06:00
|
|
|
}
|
2012-10-19 06:38:28 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void add_to_filtered_list(size_t i)
|
|
|
|
{
|
2013-01-05 18:59:39 -07:00
|
|
|
search_generic<S,T>::add_to_filtered_list(i);
|
2012-12-27 02:23:13 -07:00
|
|
|
add_to_filtered_secondary_lists(i);
|
|
|
|
if (!read_only)
|
|
|
|
saved_indexes.push_back(i); // Used to map filtered indexes back to original, if needed
|
|
|
|
}
|
2012-10-19 06:38:28 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual void do_post_search()
|
|
|
|
{
|
|
|
|
if (!read_only)
|
2013-01-05 18:59:39 -07:00
|
|
|
reference_list = *this->primary_list;
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
2012-10-20 19:18:29 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void save_original_values()
|
|
|
|
{
|
2013-01-05 18:59:39 -07:00
|
|
|
search_generic<S,T>::save_original_values();
|
2012-12-27 02:23:13 -07:00
|
|
|
save_secondary_values();
|
|
|
|
}
|
|
|
|
};
|
2012-10-19 06:38:28 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
// This basic match function is separated out from the generic multi column class, because the
|
2015-12-27 13:49:10 -07:00
|
|
|
// pets screen, which uses a union in its primary list, will cause a compile failure if this
|
2012-12-27 02:23:13 -07:00
|
|
|
// match function exists in the generic class
|
|
|
|
template < class S, class T, class PARENT = search_generic<S,T> >
|
|
|
|
class search_multicolumn_modifiable : public search_multicolumn_modifiable_generic<S, T, PARENT>
|
|
|
|
{
|
|
|
|
bool is_match(T &a, T &b)
|
|
|
|
{
|
|
|
|
return a == b;
|
|
|
|
}
|
2012-10-19 06:38:28 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
bool is_match(vector<T> &a, vector<T> &b)
|
|
|
|
{
|
|
|
|
return a == b;
|
|
|
|
}
|
|
|
|
};
|
2012-10-19 06:38:28 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
// General class for screens that have only one secondary list to keep in sync
|
|
|
|
template < class S, class T, class V, class PARENT = search_generic<S,T> >
|
|
|
|
class search_twocolumn_modifiable : public search_multicolumn_modifiable<S, T, PARENT>
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-10-21 02:32:01 -06:00
|
|
|
public:
|
2012-12-27 02:23:13 -07:00
|
|
|
protected:
|
|
|
|
virtual vector<V> * get_secondary_list() = 0;
|
2012-10-21 02:32:01 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual void do_post_init()
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2013-01-05 18:59:39 -07:00
|
|
|
search_multicolumn_modifiable<S, T, PARENT>::do_post_init();
|
2012-12-27 02:23:13 -07:00
|
|
|
secondary_list = get_secondary_list();
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void save_secondary_values()
|
2012-10-21 02:32:01 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
saved_secondary_list = *secondary_list;
|
|
|
|
}
|
2012-11-03 05:34:04 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void reset_secondary_viewscreen_vectors()
|
|
|
|
{
|
|
|
|
secondary_list = NULL;
|
2012-10-21 02:32:01 -06:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
virtual void update_saved_secondary_list_item(size_t i, size_t j)
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
saved_secondary_list[i] = (*secondary_list)[j];
|
|
|
|
}
|
2012-10-22 02:44:02 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void clear_secondary_viewscreen_vectors()
|
|
|
|
{
|
|
|
|
secondary_list->clear();
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void add_to_filtered_secondary_lists(size_t i)
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
secondary_list->push_back(saved_secondary_list[i]);
|
|
|
|
}
|
2012-10-21 02:32:01 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void clear_secondary_saved_lists()
|
|
|
|
{
|
|
|
|
saved_secondary_list.clear();
|
|
|
|
}
|
2012-10-20 19:18:29 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void restore_secondary_values()
|
|
|
|
{
|
|
|
|
*secondary_list = saved_secondary_list;
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
vector<V> *secondary_list, saved_secondary_list;
|
2012-10-21 02:32:01 -06:00
|
|
|
};
|
|
|
|
|
2012-10-22 02:44:02 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
// Parent struct for the hooks, use optional param D to generate multiple search classes in the same
|
|
|
|
// viewscreen but different static modules
|
|
|
|
template <class T, class V, int D = 0>
|
|
|
|
struct generic_search_hook : T
|
2012-10-21 02:32:01 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
typedef T interpose_base;
|
2012-10-21 02:32:01 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
static V module;
|
2012-11-03 05:34:04 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, feed, (set<df::interface_key> *input))
|
2012-11-03 05:34:04 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
if (!module.init(this))
|
|
|
|
{
|
|
|
|
INTERPOSE_NEXT(feed)(input);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!module.process_input(input))
|
|
|
|
{
|
|
|
|
INTERPOSE_NEXT(feed)(input);
|
|
|
|
module.do_post_input_feed();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, render, ())
|
|
|
|
{
|
|
|
|
bool ok = module.init(this);
|
|
|
|
INTERPOSE_NEXT(render)();
|
|
|
|
if (ok)
|
|
|
|
module.render();
|
|
|
|
}
|
2015-05-08 14:27:52 -06:00
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(bool, key_conflict, (df::interface_key key))
|
|
|
|
{
|
|
|
|
if (module.in_entry_mode() && (key == interface_key::MOVIES || key == interface_key::HELP))
|
|
|
|
return true;
|
|
|
|
return INTERPOSE_NEXT(key_conflict)(key);
|
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T, class V, int D> V generic_search_hook<T, V, D> ::module;
|
|
|
|
|
|
|
|
|
|
|
|
// Hook definition helpers
|
2014-08-25 21:18:52 -06:00
|
|
|
#define IMPLEMENT_HOOKS_WITH_ID(screen, module, id, prio) \
|
2012-12-27 02:23:13 -07:00
|
|
|
typedef generic_search_hook<screen, module, id> module##_hook; \
|
2014-08-25 21:18:52 -06:00
|
|
|
template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, feed, prio); \
|
2015-05-08 14:27:52 -06:00
|
|
|
template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, render, prio); \
|
|
|
|
template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, key_conflict, prio)
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
#define IMPLEMENT_HOOKS(screen, module) \
|
|
|
|
typedef generic_search_hook<screen, module> module##_hook; \
|
|
|
|
template<> IMPLEMENT_VMETHOD_INTERPOSE(module##_hook, feed); \
|
2015-05-08 14:27:52 -06:00
|
|
|
template<> IMPLEMENT_VMETHOD_INTERPOSE(module##_hook, render); \
|
|
|
|
template<> IMPLEMENT_VMETHOD_INTERPOSE(module##_hook, key_conflict)
|
2012-12-27 02:23:13 -07:00
|
|
|
|
2013-01-16 09:30:11 -07:00
|
|
|
#define IMPLEMENT_HOOKS_PRIO(screen, module, prio) \
|
|
|
|
typedef generic_search_hook<screen, module> module##_hook; \
|
2014-05-04 04:04:03 -06:00
|
|
|
template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, feed, prio); \
|
2015-05-08 14:27:52 -06:00
|
|
|
template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, render, prio); \
|
2015-12-27 13:49:10 -07:00
|
|
|
template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, key_conflict, prio);
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// END: Generic Search functionality
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// START: Animal screen search
|
|
|
|
//
|
|
|
|
|
2015-12-27 13:49:10 -07:00
|
|
|
typedef search_multicolumn_modifiable_generic<df::viewscreen_petst, df::viewscreen_petst::T_animal> pets_search_base;
|
|
|
|
class pets_search : public pets_search_base
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
2015-12-27 13:49:10 -07:00
|
|
|
typedef df::viewscreen_petst::T_animal T_animal;
|
|
|
|
typedef df::viewscreen_petst::T_mode T_mode;
|
2012-12-27 02:23:13 -07:00
|
|
|
public:
|
|
|
|
void render() const
|
|
|
|
{
|
2015-12-27 13:49:10 -07:00
|
|
|
print_search_option(25, 4);
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-12-27 13:49:10 -07:00
|
|
|
bool can_init(df::viewscreen_petst *screen)
|
|
|
|
{
|
|
|
|
return pets_search_base::can_init(screen) && screen->mode == T_mode::List;
|
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
int32_t *get_viewscreen_cursor()
|
|
|
|
{
|
|
|
|
return &viewscreen->cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<T_animal> *get_primary_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->animal;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void do_post_init()
|
|
|
|
{
|
|
|
|
is_vermin = &viewscreen->is_vermin;
|
|
|
|
is_tame = &viewscreen->is_tame;
|
|
|
|
is_adopting = &viewscreen->is_adopting;
|
|
|
|
}
|
|
|
|
|
|
|
|
string get_element_description(df::viewscreen_petst::T_animal element) const
|
|
|
|
{
|
|
|
|
return get_unit_description(element.unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool should_check_input()
|
|
|
|
{
|
|
|
|
return viewscreen->mode == T_mode::List;
|
|
|
|
}
|
|
|
|
|
2013-01-05 22:14:25 -07:00
|
|
|
bool is_valid_for_search(size_t i)
|
|
|
|
{
|
|
|
|
return is_vermin_s[i] == 0;
|
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void save_secondary_values()
|
|
|
|
{
|
|
|
|
is_vermin_s = *is_vermin;
|
|
|
|
is_tame_s = *is_tame;
|
|
|
|
is_adopting_s = *is_adopting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset_secondary_viewscreen_vectors()
|
|
|
|
{
|
|
|
|
is_vermin = NULL;
|
|
|
|
is_tame = NULL;
|
|
|
|
is_adopting = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_saved_secondary_list_item(size_t i, size_t j)
|
|
|
|
{
|
|
|
|
is_vermin_s[i] = (*is_vermin)[j];
|
|
|
|
is_tame_s[i] = (*is_tame)[j];
|
|
|
|
is_adopting_s[i] = (*is_adopting)[j];
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear_secondary_viewscreen_vectors()
|
|
|
|
{
|
|
|
|
is_vermin->clear();
|
|
|
|
is_tame->clear();
|
|
|
|
is_adopting->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_to_filtered_secondary_lists(size_t i)
|
|
|
|
{
|
|
|
|
is_vermin->push_back(is_vermin_s[i]);
|
|
|
|
is_tame->push_back(is_tame_s[i]);
|
|
|
|
is_adopting->push_back(is_adopting_s[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear_secondary_saved_lists()
|
|
|
|
{
|
|
|
|
is_vermin_s.clear();
|
|
|
|
is_tame_s.clear();
|
|
|
|
is_adopting_s.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void restore_secondary_values()
|
|
|
|
{
|
|
|
|
*is_vermin = is_vermin_s;
|
|
|
|
*is_tame = is_tame_s;
|
|
|
|
*is_adopting = is_adopting_s;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_match(T_animal &a, T_animal &b)
|
|
|
|
{
|
|
|
|
return a.unit == b.unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_match(vector<T_animal> &a, vector<T_animal> &b)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < a.size(); i++)
|
|
|
|
{
|
|
|
|
if (!is_match(a[i], b[i]))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<char > *is_vermin, is_vermin_s;
|
|
|
|
std::vector<char > *is_tame, is_tame_s;
|
|
|
|
std::vector<char > *is_adopting, is_adopting_s;
|
|
|
|
};
|
|
|
|
|
2015-12-27 13:49:10 -07:00
|
|
|
IMPLEMENT_HOOKS_WITH_ID(df::viewscreen_petst, pets_search, 1, 0);
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// END: Animal screen search
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2015-12-27 13:49:10 -07:00
|
|
|
//
|
|
|
|
// START: Animal knowledge screen search
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef search_generic<df::viewscreen_petst, int32_t> animal_knowledge_search_base;
|
|
|
|
class animal_knowledge_search : public animal_knowledge_search_base
|
|
|
|
{
|
|
|
|
typedef df::viewscreen_petst::T_mode T_mode;
|
|
|
|
bool can_init(df::viewscreen_petst *screen)
|
|
|
|
{
|
|
|
|
return animal_knowledge_search_base::can_init(screen) && screen->mode == T_mode::TrainingKnowledge;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
void render() const
|
|
|
|
{
|
|
|
|
print_search_option(2, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32_t *get_viewscreen_cursor()
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<int32_t> *get_primary_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->known;
|
|
|
|
}
|
|
|
|
|
|
|
|
string get_element_description(int32_t id) const
|
|
|
|
{
|
|
|
|
auto craw = df::creature_raw::find(id);
|
|
|
|
string out;
|
|
|
|
if (craw)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < 3; ++i)
|
|
|
|
out += craw->name[i] + " ";
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_HOOKS_WITH_ID(df::viewscreen_petst, animal_knowledge_search, 2, 0);
|
|
|
|
|
|
|
|
//
|
|
|
|
// END: Animal knowledge screen search
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// START: Animal trainer search
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef search_twocolumn_modifiable<df::viewscreen_petst, df::unit*, df::viewscreen_petst::T_trainer_mode> animal_trainer_search_base;
|
|
|
|
class animal_trainer_search : public animal_trainer_search_base
|
|
|
|
{
|
|
|
|
typedef df::viewscreen_petst::T_mode T_mode;
|
|
|
|
typedef df::viewscreen_petst::T_trainer_mode T_trainer_mode;
|
|
|
|
|
|
|
|
bool can_init(df::viewscreen_petst *screen)
|
|
|
|
{
|
|
|
|
return animal_trainer_search_base::can_init(screen) && screen->mode == T_mode::SelectTrainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
void render() const
|
|
|
|
{
|
2018-04-06 20:22:48 -06:00
|
|
|
Screen::paintTile(Screen::Pen('\xBA', 8, 0), 14, 2);
|
|
|
|
Screen::paintTile(Screen::Pen('\xBA', 8, 0), gps->dimx - 14, 2);
|
|
|
|
Screen::paintTile(Screen::Pen('\xC9', 8, 0), 14, 1);
|
|
|
|
Screen::paintTile(Screen::Pen('\xBB', 8, 0), gps->dimx - 14, 1);
|
2015-12-27 13:49:10 -07:00
|
|
|
for (int x = 15; x <= gps->dimx - 15; ++x)
|
|
|
|
{
|
2018-04-06 20:22:48 -06:00
|
|
|
Screen::paintTile(Screen::Pen('\xCD', 8, 0), x, 1);
|
|
|
|
Screen::paintTile(Screen::Pen('\x00', 0, 0), x, 2);
|
2015-12-27 13:49:10 -07:00
|
|
|
}
|
|
|
|
print_search_option(16, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32_t *get_viewscreen_cursor()
|
|
|
|
{
|
|
|
|
return &viewscreen->trainer_cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<df::unit*> *get_primary_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->trainer_unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
string get_element_description(df::unit *u) const
|
|
|
|
{
|
|
|
|
return get_unit_description(u);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<T_trainer_mode> *get_secondary_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->trainer_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool process_input(set<df::interface_key> *input)
|
|
|
|
{
|
|
|
|
if (input->count(interface_key::SELECT) && viewscreen->trainer_unit.empty() && !in_entry_mode())
|
|
|
|
return true;
|
|
|
|
return animal_trainer_search_base::process_input(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_HOOKS_WITH_ID(df::viewscreen_petst, animal_trainer_search, 3, 0);
|
|
|
|
|
|
|
|
//
|
|
|
|
// END: Animal trainer search
|
|
|
|
//
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// START: Stocks screen search
|
|
|
|
//
|
2013-02-14 04:45:58 -07:00
|
|
|
typedef search_generic<df::viewscreen_storesst, df::item*> stocks_search_base;
|
|
|
|
class stocks_search : public stocks_search_base
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
void render() const
|
|
|
|
{
|
|
|
|
if (!viewscreen->in_group_mode)
|
|
|
|
print_search_option(2);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto dim = Screen::getWindowSize();
|
|
|
|
int x = 2, y = dim.y - 2;
|
|
|
|
OutputString(15, x, y, "Tab to enable Search");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool process_input(set<df::interface_key> *input)
|
|
|
|
{
|
|
|
|
if (viewscreen->in_group_mode)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
redo_search = false;
|
|
|
|
|
|
|
|
if ((input->count(interface_key::CURSOR_UP) || input->count(interface_key::CURSOR_DOWN)) && !viewscreen->in_right_list)
|
|
|
|
{
|
|
|
|
// Redo search if category changes
|
|
|
|
saved_list1.clear();
|
|
|
|
end_entry_mode();
|
|
|
|
if (search_string.length() > 0)
|
|
|
|
redo_search = true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-14 04:45:58 -07:00
|
|
|
return stocks_search_base::process_input(input);
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void do_post_input_feed()
|
|
|
|
{
|
|
|
|
if (viewscreen->in_group_mode)
|
|
|
|
{
|
|
|
|
// Disable search if item lists are grouped
|
|
|
|
clear_search();
|
|
|
|
reset_search();
|
|
|
|
}
|
|
|
|
else if (redo_search)
|
|
|
|
{
|
|
|
|
do_search();
|
|
|
|
redo_search = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32_t *get_viewscreen_cursor()
|
|
|
|
{
|
|
|
|
return &viewscreen->item_cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual vector<df::item*> *get_primary_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->items;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
string get_element_description(df::item *element) const
|
|
|
|
{
|
2015-06-30 14:18:27 -06:00
|
|
|
if (!element)
|
|
|
|
return "";
|
2012-12-27 02:23:13 -07:00
|
|
|
return Items::getDescription(element, 0, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool redo_search;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-05-04 04:04:03 -06:00
|
|
|
IMPLEMENT_HOOKS_PRIO(df::viewscreen_storesst, stocks_search, 100);
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// END: Stocks screen search
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// START: Unit screen search
|
|
|
|
//
|
2013-02-14 04:45:58 -07:00
|
|
|
typedef search_twocolumn_modifiable<df::viewscreen_unitlistst, df::unit*, df::job*> unitlist_search_base;
|
|
|
|
class unitlist_search : public unitlist_search_base
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
void render() const
|
|
|
|
{
|
|
|
|
print_search_option(28);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void do_post_init()
|
|
|
|
{
|
2013-02-14 04:45:58 -07:00
|
|
|
unitlist_search_base::do_post_init();
|
2012-12-27 02:23:13 -07:00
|
|
|
read_only = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static string get_non_work_description(df::unit *unit)
|
|
|
|
{
|
2015-06-30 14:18:27 -06:00
|
|
|
if (!unit)
|
|
|
|
return "";
|
2013-01-16 07:30:29 -07:00
|
|
|
for (auto p = unit->status.misc_traits.begin(); p < unit->status.misc_traits.end(); p++)
|
|
|
|
{
|
2018-11-24 12:52:26 -07:00
|
|
|
if ((*p)->id == misc_trait_type::Migrant)
|
2013-01-16 07:30:29 -07:00
|
|
|
{
|
2018-11-24 12:52:26 -07:00
|
|
|
return ".new arrival.migrant";
|
2013-01-16 07:30:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 14:26:17 -07:00
|
|
|
if (Units::isBaby(unit) ||
|
|
|
|
Units::isChild(unit) ||
|
2013-01-16 07:30:29 -07:00
|
|
|
unit->profession == profession::DRUNK)
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ENUM_ATTR(profession, military, unit->profession))
|
|
|
|
return ".military";
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
return ".idle.no job";
|
|
|
|
}
|
|
|
|
|
|
|
|
string get_element_description(df::unit *unit) const
|
|
|
|
{
|
2015-06-30 14:18:27 -06:00
|
|
|
if (!unit)
|
|
|
|
return "Inactive";
|
2012-12-27 02:23:13 -07:00
|
|
|
string desc = get_unit_description(unit);
|
|
|
|
if (!unit->job.current_job)
|
|
|
|
{
|
|
|
|
desc += get_non_work_description(unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
bool should_check_input(set<df::interface_key> *input)
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
2018-04-05 08:08:07 -06:00
|
|
|
if (input->count(interface_key::STANDARDSCROLL_LEFT) ||
|
|
|
|
input->count(interface_key::STANDARDSCROLL_RIGHT) ||
|
2012-12-27 02:23:13 -07:00
|
|
|
(!in_entry_mode() && input->count(interface_key::UNITVIEW_PRF_PROF)))
|
|
|
|
{
|
|
|
|
if (!in_entry_mode())
|
|
|
|
{
|
|
|
|
// Changing screens, reset search
|
2016-05-17 21:23:54 -06:00
|
|
|
int32_t *cursor_pos = get_viewscreen_cursor();
|
|
|
|
if (cursor_pos && *cursor_pos < 0)
|
|
|
|
*cursor_pos = 0;
|
2012-12-27 02:23:13 -07:00
|
|
|
clear_search();
|
|
|
|
reset_all();
|
2018-04-05 08:08:07 -06:00
|
|
|
return false;
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
|
|
|
else
|
2018-04-05 08:08:07 -06:00
|
|
|
{
|
|
|
|
// Ignore cursor keys when typing
|
|
|
|
input->erase(interface_key::STANDARDSCROLL_LEFT);
|
|
|
|
input->erase(interface_key::STANDARDSCROLL_RIGHT);
|
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-10 14:57:19 -06:00
|
|
|
char get_search_select_key()
|
|
|
|
{
|
|
|
|
return 'q';
|
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
vector<df::job*> *get_secondary_list()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return &viewscreen->jobs[viewscreen->page];
|
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
int32_t *get_viewscreen_cursor()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return &viewscreen->cursor_pos[viewscreen->page];
|
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
vector<df::unit*> *get_primary_list()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return &viewscreen->units[viewscreen->page];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-16 07:54:35 -07:00
|
|
|
typedef generic_search_hook<df::viewscreen_unitlistst, unitlist_search> unitlist_search_hook;
|
2015-05-08 14:27:52 -06:00
|
|
|
IMPLEMENT_HOOKS_PRIO(df::viewscreen_unitlistst, unitlist_search, 100);
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
//
|
|
|
|
// END: Unit screen search
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// START: Trade screen search
|
|
|
|
//
|
2020-08-25 15:15:41 -06:00
|
|
|
class trade_search_base : public search_multicolumn_modifiable<df::viewscreen_tradegoodsst, df::item*>
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
2020-08-25 15:15:41 -06:00
|
|
|
protected:
|
|
|
|
virtual vector<char> *get_selected_list() = 0;
|
|
|
|
virtual vector<int32_t> *get_count_list() = 0;
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
string get_element_description(df::item *element) const
|
|
|
|
{
|
2015-06-30 14:18:27 -06:00
|
|
|
if (!element)
|
|
|
|
return "";
|
2012-12-27 02:23:13 -07:00
|
|
|
return Items::getDescription(element, 0, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool should_check_input(set<df::interface_key> *input)
|
|
|
|
{
|
|
|
|
if (in_entry_mode())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (input->count(interface_key::TRADE_TRADE) ||
|
|
|
|
input->count(interface_key::TRADE_OFFER) ||
|
|
|
|
input->count(interface_key::TRADE_SEIZE))
|
|
|
|
{
|
|
|
|
// Block the keys if were searching
|
|
|
|
if (!search_string.empty())
|
2014-05-04 04:04:03 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
input->clear();
|
2014-05-04 04:04:03 -06:00
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (input->count(interface_key::CUSTOM_ALT_C))
|
|
|
|
{
|
|
|
|
clear_search_for_trade();
|
2012-11-03 05:34:04 -06:00
|
|
|
return true;
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear_search_for_trade()
|
|
|
|
{
|
|
|
|
// Trying to trade, reset search
|
|
|
|
clear_search();
|
|
|
|
reset_all();
|
|
|
|
}
|
2020-08-25 15:15:41 -06:00
|
|
|
|
|
|
|
void do_post_init()
|
|
|
|
{
|
|
|
|
search_multicolumn_modifiable::do_post_init();
|
|
|
|
|
|
|
|
selected = get_selected_list();
|
|
|
|
count = get_count_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
void save_secondary_values()
|
|
|
|
{
|
|
|
|
selected_s = *selected;
|
|
|
|
count_s = *count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset_secondary_viewscreen_vectors()
|
|
|
|
{
|
|
|
|
selected = NULL;
|
|
|
|
count = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_saved_secondary_list_item(size_t i, size_t j)
|
|
|
|
{
|
|
|
|
selected_s[i] = (*selected)[j];
|
|
|
|
count_s[i] = (*count)[j];
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear_secondary_viewscreen_vectors()
|
|
|
|
{
|
|
|
|
selected->clear();
|
|
|
|
count->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_to_filtered_secondary_lists(size_t i)
|
|
|
|
{
|
|
|
|
selected->push_back(selected_s[i]);
|
|
|
|
count->push_back(count_s[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear_secondary_saved_lists()
|
|
|
|
{
|
|
|
|
selected_s.clear();
|
|
|
|
count_s.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void restore_secondary_values()
|
|
|
|
{
|
|
|
|
*selected = selected_s;
|
|
|
|
*count = count_s;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<char> *selected, selected_s;
|
|
|
|
std::vector<int32_t> *count, count_s;
|
2012-12-27 02:23:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class trade_search_merc : public trade_search_base
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void render() const
|
|
|
|
{
|
2014-09-04 21:08:46 -06:00
|
|
|
if (viewscreen->counteroffer.size() > 0)
|
|
|
|
{
|
|
|
|
// The merchant is proposing a counteroffer.
|
|
|
|
// Not only is there nothing to search,
|
|
|
|
// but the native hotkeys are where we normally write.
|
|
|
|
return;
|
|
|
|
}
|
2015-01-08 14:59:37 -07:00
|
|
|
|
2014-08-17 10:59:33 -06:00
|
|
|
print_search_option(2, -1);
|
2013-01-16 09:42:41 -07:00
|
|
|
|
|
|
|
if (!search_string.empty())
|
|
|
|
{
|
2014-05-04 04:04:03 -06:00
|
|
|
int32_t x = 2;
|
|
|
|
int32_t y = gps->dimy - 3;
|
2014-11-06 22:05:05 -07:00
|
|
|
make_text_dim(2, gps->dimx-2, y);
|
2014-09-04 23:28:59 -06:00
|
|
|
OutputString(COLOR_LIGHTRED, x, y, string(1, select_key + 'A' - 'a'));
|
|
|
|
OutputString(COLOR_WHITE, x, y, ": Clear search to trade ");
|
2013-01-16 09:42:41 -07:00
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32_t *get_viewscreen_cursor()
|
|
|
|
{
|
|
|
|
return &viewscreen->trader_cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<df::item*> *get_primary_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->trader_items;
|
|
|
|
}
|
|
|
|
|
2020-08-25 15:15:41 -06:00
|
|
|
vector<char> *get_selected_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->trader_selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<int32_t> *get_count_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->trader_count;
|
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
char get_search_select_key()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return 'q';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-25 21:18:52 -06:00
|
|
|
IMPLEMENT_HOOKS_WITH_ID(df::viewscreen_tradegoodsst, trade_search_merc, 1, 100);
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
|
|
|
|
class trade_search_fort : public trade_search_base
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void render() const
|
|
|
|
{
|
2014-09-04 21:08:46 -06:00
|
|
|
if (viewscreen->counteroffer.size() > 0)
|
|
|
|
{
|
|
|
|
// The merchant is proposing a counteroffer.
|
|
|
|
// Not only is there nothing to search,
|
|
|
|
// but the native hotkeys are where we normally write.
|
|
|
|
return;
|
|
|
|
}
|
2015-01-08 14:59:37 -07:00
|
|
|
|
2014-11-06 22:05:05 -07:00
|
|
|
int32_t x = gps->dimx / 2 + 2;
|
|
|
|
print_search_option(x, -1);
|
2013-01-16 09:42:41 -07:00
|
|
|
|
|
|
|
if (!search_string.empty())
|
|
|
|
{
|
2014-05-04 04:04:03 -06:00
|
|
|
int32_t y = gps->dimy - 3;
|
2014-11-06 22:05:05 -07:00
|
|
|
make_text_dim(2, gps->dimx-2, y);
|
2014-09-04 23:28:59 -06:00
|
|
|
OutputString(COLOR_LIGHTRED, x, y, string(1, select_key + 'A' - 'a'));
|
|
|
|
OutputString(COLOR_WHITE, x, y, ": Clear search to trade ");
|
2013-01-16 09:42:41 -07:00
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32_t *get_viewscreen_cursor()
|
|
|
|
{
|
|
|
|
return &viewscreen->broker_cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<df::item*> *get_primary_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->broker_items;
|
|
|
|
}
|
|
|
|
|
2020-08-25 15:15:41 -06:00
|
|
|
vector<char> *get_selected_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->broker_selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<int32_t> *get_count_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->broker_count;
|
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
char get_search_select_key()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return 'w';
|
|
|
|
}
|
|
|
|
};
|
2012-11-30 02:44:05 -07:00
|
|
|
|
2014-08-25 21:18:52 -06:00
|
|
|
IMPLEMENT_HOOKS_WITH_ID(df::viewscreen_tradegoodsst, trade_search_fort, 2, 100);
|
2012-11-03 05:34:04 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
//
|
|
|
|
// END: Trade screen search
|
|
|
|
//
|
2012-11-03 05:34:04 -06:00
|
|
|
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
//
|
|
|
|
// START: Stockpile screen search
|
|
|
|
//
|
|
|
|
typedef layered_search<df::viewscreen_layer_stockpilest, string *, 2> stocks_layer;
|
|
|
|
class stockpile_search : public search_twocolumn_modifiable<df::viewscreen_layer_stockpilest, string *, bool *, stocks_layer>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void update_saved_secondary_list_item(size_t i, size_t j)
|
|
|
|
{
|
|
|
|
*saved_secondary_list[i] = *(*secondary_list)[j];
|
|
|
|
}
|
2012-11-03 05:34:04 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
string get_element_description(string *element) const
|
|
|
|
{
|
|
|
|
return *element;
|
|
|
|
}
|
|
|
|
|
|
|
|
void render() const
|
|
|
|
{
|
|
|
|
print_search_option(51, 23);
|
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
vector<string *> *get_primary_list()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return &viewscreen->item_names;
|
2012-11-30 02:44:05 -07:00
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
vector<bool *> *get_secondary_list()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return &viewscreen->item_status;
|
2012-11-03 05:34:04 -06:00
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
|
2015-09-21 17:25:20 -06:00
|
|
|
bool should_check_input(set<df::interface_key> *input)
|
|
|
|
{
|
|
|
|
if (input->count(interface_key::STOCKPILE_SETTINGS_DISABLE) && !in_entry_mode() && !search_string.empty())
|
|
|
|
{
|
|
|
|
// Restore original list
|
|
|
|
clear_search();
|
|
|
|
reset_all();
|
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
|
2015-09-21 17:25:20 -06:00
|
|
|
return true;
|
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
|
2012-10-21 02:32:01 -06:00
|
|
|
};
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_layer_stockpilest, stockpile_search);
|
2012-10-21 02:32:01 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
//
|
|
|
|
// END: Stockpile screen search
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// START: Military screen search
|
|
|
|
//
|
2013-02-14 04:45:58 -07:00
|
|
|
typedef layered_search<df::viewscreen_layer_militaryst, df::unit *, 2> military_search_base;
|
|
|
|
class military_search : public military_search_base
|
2012-10-21 02:32:01 -06:00
|
|
|
{
|
|
|
|
public:
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
string get_element_description(df::unit *element) const
|
2012-10-21 02:32:01 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
return get_unit_description(element);
|
2012-10-21 02:32:01 -06:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void render() const
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
print_search_option(52, 22);
|
2012-10-21 02:32:01 -06:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
char get_search_select_key()
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
return 'q';
|
|
|
|
}
|
|
|
|
|
2013-04-02 02:03:37 -06:00
|
|
|
// When not on the positions page, this list is used for something
|
|
|
|
// else entirely, so screwing with it seriously breaks stuff.
|
|
|
|
bool is_list_valid(df::viewscreen_layer_militaryst *screen)
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
if (screen->page != df::viewscreen_layer_militaryst::Positions)
|
2012-11-03 05:34:04 -06:00
|
|
|
return false;
|
|
|
|
|
2013-04-02 02:03:37 -06:00
|
|
|
return true;
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
vector<df::unit *> *get_primary_list()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return &viewscreen->positions.candidates;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool should_check_input(set<df::interface_key> *input)
|
|
|
|
{
|
|
|
|
if (input->count(interface_key::SELECT) && !in_entry_mode() && !search_string.empty())
|
2012-10-20 19:18:29 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
// About to make an assignment, so restore original list (it will be changed by the game)
|
|
|
|
int32_t *cursor = get_viewscreen_cursor();
|
2015-11-15 09:15:05 -07:00
|
|
|
auto list = get_primary_list();
|
2018-04-06 00:18:15 -06:00
|
|
|
if (size_t(*cursor) >= list->size())
|
2015-11-15 09:15:05 -07:00
|
|
|
return false;
|
|
|
|
df::unit *selected_unit = list->at(*cursor);
|
2012-12-27 02:23:13 -07:00
|
|
|
clear_search();
|
2015-01-08 14:59:37 -07:00
|
|
|
|
2018-04-06 00:18:15 -06:00
|
|
|
for (*cursor = 0; size_t(*cursor) < list->size(); (*cursor)++)
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
2015-11-15 09:15:05 -07:00
|
|
|
if (list->at(*cursor) == selected_unit)
|
2012-12-27 02:23:13 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
reset_all();
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
2012-11-03 05:34:04 -06:00
|
|
|
|
|
|
|
return true;
|
2012-10-20 19:18:29 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-16 09:30:11 -07:00
|
|
|
IMPLEMENT_HOOKS_PRIO(df::viewscreen_layer_militaryst, military_search, 100);
|
2012-10-21 02:32:01 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
//
|
|
|
|
// END: Military screen search
|
|
|
|
//
|
2012-10-21 02:32:01 -06:00
|
|
|
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
//
|
|
|
|
// START: Room list search
|
|
|
|
//
|
2013-02-14 04:45:58 -07:00
|
|
|
typedef search_twocolumn_modifiable<df::viewscreen_buildinglistst, df::building*, int32_t> roomlist_search_base;
|
|
|
|
class roomlist_search : public roomlist_search_base
|
2012-10-21 02:32:01 -06:00
|
|
|
{
|
|
|
|
public:
|
2012-12-27 02:23:13 -07:00
|
|
|
void render() const
|
2012-10-21 02:32:01 -06:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
print_search_option(2, 23);
|
2012-10-21 02:32:01 -06:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
private:
|
|
|
|
void do_post_init()
|
2012-10-21 02:32:01 -06:00
|
|
|
{
|
2013-02-14 04:45:58 -07:00
|
|
|
roomlist_search_base::do_post_init();
|
2012-12-27 02:23:13 -07:00
|
|
|
read_only = true;
|
|
|
|
}
|
2012-11-03 05:34:04 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
string get_element_description(df::building *bld) const
|
|
|
|
{
|
2015-06-30 14:18:27 -06:00
|
|
|
if (!bld)
|
|
|
|
return "";
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
string desc;
|
|
|
|
desc.reserve(100);
|
|
|
|
if (bld->owner)
|
|
|
|
desc += get_unit_description(bld->owner);
|
|
|
|
|
|
|
|
desc += ".";
|
|
|
|
|
2018-05-12 15:00:21 -06:00
|
|
|
string room_desc = Buildings::getRoomDescription(bld, nullptr);
|
|
|
|
desc += room_desc;
|
|
|
|
if (room_desc.empty())
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
2018-05-12 15:00:21 -06:00
|
|
|
if (!bld->owner)
|
|
|
|
desc += "no owner";
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
string name;
|
|
|
|
bld->getName(&name);
|
|
|
|
if (!name.empty())
|
|
|
|
{
|
|
|
|
desc += name;
|
|
|
|
}
|
2012-10-21 02:32:01 -06:00
|
|
|
}
|
2015-01-08 14:59:37 -07:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
return desc;
|
|
|
|
}
|
2012-11-03 05:34:04 -06:00
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
vector<int32_t> *get_secondary_list()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return &viewscreen->room_value;
|
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
int32_t *get_viewscreen_cursor()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return &viewscreen->cursor;
|
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
vector<df::building*> *get_primary_list()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return &viewscreen->buildings;
|
2012-10-21 02:32:01 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_buildinglistst, roomlist_search);
|
2012-10-20 19:18:29 -06:00
|
|
|
|
|
|
|
//
|
2012-12-27 02:23:13 -07:00
|
|
|
// END: Room list search
|
2012-10-20 19:18:29 -06:00
|
|
|
//
|
2012-10-19 06:38:28 -06:00
|
|
|
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
|
2012-11-30 05:01:04 -07:00
|
|
|
//
|
2012-12-27 02:23:13 -07:00
|
|
|
// START: Announcement list search
|
2012-11-30 05:01:04 -07:00
|
|
|
//
|
2015-01-08 14:59:25 -07:00
|
|
|
class announcement_search : public search_generic<df::viewscreen_announcelistst, df::report*>
|
2012-11-30 05:01:04 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-12-27 02:23:13 -07:00
|
|
|
void render() const
|
2012-11-30 05:01:04 -07:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
print_search_option(2, gps->dimy - 3);
|
2012-11-30 05:01:04 -07:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
private:
|
|
|
|
int32_t *get_viewscreen_cursor()
|
2012-11-30 05:01:04 -07:00
|
|
|
{
|
2013-01-16 07:55:05 -07:00
|
|
|
return &viewscreen->sel_idx;
|
2012-11-30 05:01:04 -07:00
|
|
|
}
|
|
|
|
|
2013-01-16 07:55:05 -07:00
|
|
|
virtual vector<df::report *> *get_primary_list()
|
2012-11-30 05:01:04 -07:00
|
|
|
{
|
2013-01-16 07:55:05 -07:00
|
|
|
return &viewscreen->reports;
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2013-01-16 07:55:05 -07:00
|
|
|
string get_element_description(df::report *element) const
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
2015-06-30 14:18:27 -06:00
|
|
|
if (!element)
|
|
|
|
return "";
|
2013-01-16 07:55:05 -07:00
|
|
|
return element->text;
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-01-08 14:59:25 -07:00
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_announcelistst, announcement_search);
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// END: Announcement list search
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// START: Nobles search list
|
|
|
|
//
|
|
|
|
typedef df::viewscreen_layer_noblelistst::T_candidates T_candidates;
|
2013-02-14 04:45:58 -07:00
|
|
|
typedef layered_search<df::viewscreen_layer_noblelistst, T_candidates *, 1> nobles_search_base;
|
|
|
|
class nobles_search : public nobles_search_base
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
string get_element_description(T_candidates *element) const
|
2012-11-30 05:01:04 -07:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
if (!element->unit)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
return get_unit_description(element->unit);
|
2012-11-30 05:01:04 -07:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void render() const
|
2012-11-30 05:01:04 -07:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
print_search_option(2, 23);
|
2012-11-30 05:01:04 -07:00
|
|
|
}
|
|
|
|
|
2013-01-16 09:30:11 -07:00
|
|
|
bool force_in_search(size_t index)
|
|
|
|
{
|
|
|
|
return index == 0; // Leave Vacant
|
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
bool can_init(df::viewscreen_layer_noblelistst *screen)
|
2012-11-30 05:01:04 -07:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
if (screen->mode != df::viewscreen_layer_noblelistst::Appoint)
|
2012-11-30 05:01:04 -07:00
|
|
|
return false;
|
|
|
|
|
2013-02-14 04:45:58 -07:00
|
|
|
return nobles_search_base::can_init(screen);
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
vector<T_candidates *> *get_primary_list()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return &viewscreen->candidates;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_layer_noblelistst, nobles_search);
|
|
|
|
|
|
|
|
//
|
|
|
|
// END: Nobles search list
|
|
|
|
//
|
|
|
|
|
2014-05-04 04:04:03 -06:00
|
|
|
//
|
|
|
|
// START: Workshop profiles search list
|
|
|
|
//
|
2016-05-14 09:43:37 -06:00
|
|
|
typedef search_generic<df::viewscreen_workshop_profilest, df::unit*> profiles_search_base;
|
2014-05-04 04:04:03 -06:00
|
|
|
class profiles_search : public profiles_search_base
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2016-05-14 09:43:37 -06:00
|
|
|
bool can_init (df::viewscreen_workshop_profilest *screen)
|
|
|
|
{
|
|
|
|
return screen->tab == df::viewscreen_workshop_profilest::T_tab::Workers;
|
|
|
|
}
|
|
|
|
|
2014-05-04 04:04:03 -06:00
|
|
|
string get_element_description(df::unit *element) const
|
|
|
|
{
|
|
|
|
return get_unit_description(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
void render() const
|
|
|
|
{
|
2016-05-15 22:49:35 -06:00
|
|
|
print_search_option(2, gps->dimy - 5);
|
2014-05-04 04:04:03 -06:00
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
vector<df::unit *> *get_primary_list()
|
2014-05-04 04:04:03 -06:00
|
|
|
{
|
|
|
|
return &viewscreen->workers;
|
|
|
|
}
|
2016-05-14 09:43:37 -06:00
|
|
|
|
|
|
|
int32_t *get_viewscreen_cursor()
|
|
|
|
{
|
|
|
|
return &viewscreen->worker_idx;
|
|
|
|
}
|
2014-05-04 04:04:03 -06:00
|
|
|
};
|
|
|
|
|
2016-05-14 09:43:37 -06:00
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_workshop_profilest, profiles_search);
|
2014-05-04 04:04:03 -06:00
|
|
|
|
|
|
|
//
|
|
|
|
// END: Workshop profiles search list
|
|
|
|
//
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// START: Job list search
|
|
|
|
//
|
|
|
|
void get_job_details(string &desc, df::job *job)
|
|
|
|
{
|
|
|
|
string job_name = ENUM_KEY_STR(job_type,job->job_type);
|
|
|
|
for (size_t i = 0; i < job_name.length(); i++)
|
|
|
|
{
|
|
|
|
char c = job_name[i];
|
|
|
|
if (c >= 'A' && c <= 'Z')
|
|
|
|
desc += " ";
|
|
|
|
desc += c;
|
|
|
|
}
|
|
|
|
desc += ".";
|
2015-01-08 14:59:37 -07:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
df::item_type itype = ENUM_ATTR(job_type, item, job->job_type);
|
|
|
|
|
|
|
|
MaterialInfo mat(job);
|
|
|
|
if (itype == item_type::FOOD)
|
|
|
|
mat.decode(-1);
|
|
|
|
|
|
|
|
if (mat.isValid() || job->material_category.whole)
|
|
|
|
{
|
|
|
|
desc += mat.toString();
|
|
|
|
desc += ".";
|
|
|
|
if (job->material_category.whole)
|
2012-11-30 05:01:04 -07:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
desc += bitfield_to_string(job->material_category);
|
|
|
|
desc += ".";
|
|
|
|
}
|
|
|
|
}
|
2012-11-30 05:01:04 -07:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
if (!job->reaction_name.empty())
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < job->reaction_name.length(); i++)
|
|
|
|
{
|
|
|
|
if (job->reaction_name[i] == '_')
|
|
|
|
desc += " ";
|
|
|
|
else
|
|
|
|
desc += job->reaction_name[i];
|
2012-11-30 05:01:04 -07:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
desc += ".";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (job->flags.bits.suspend)
|
|
|
|
desc += "suspended.";
|
|
|
|
}
|
|
|
|
|
2013-02-14 04:45:58 -07:00
|
|
|
typedef search_twocolumn_modifiable<df::viewscreen_joblistst, df::job*, df::unit*> joblist_search_base;
|
|
|
|
class joblist_search : public joblist_search_base
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
void render() const
|
|
|
|
{
|
|
|
|
print_search_option(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void do_post_init()
|
|
|
|
{
|
2013-02-14 04:45:58 -07:00
|
|
|
joblist_search_base::do_post_init();
|
2012-12-27 02:23:13 -07:00
|
|
|
read_only = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
string get_element_description(df::job *element) const
|
|
|
|
{
|
|
|
|
if (!element)
|
|
|
|
return "no job.idle";
|
|
|
|
|
|
|
|
string desc;
|
|
|
|
desc.reserve(100);
|
|
|
|
get_job_details(desc, element);
|
|
|
|
df::unit *worker = DFHack::Job::getWorker(element);
|
|
|
|
if (worker)
|
|
|
|
desc += get_unit_description(worker);
|
|
|
|
else
|
|
|
|
desc += "Inactive";
|
|
|
|
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
2014-09-10 14:57:19 -06:00
|
|
|
char get_search_select_key()
|
|
|
|
{
|
|
|
|
return 'q';
|
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
vector<df::unit*> *get_secondary_list()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return &viewscreen->units;
|
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
int32_t *get_viewscreen_cursor()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return &viewscreen->cursor_pos;
|
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
vector<df::job*> *get_primary_list()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return &viewscreen->jobs;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_joblistst, joblist_search);
|
|
|
|
|
|
|
|
//
|
|
|
|
// END: Job list search
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2015-06-16 18:36:19 -06:00
|
|
|
//
|
|
|
|
// START: Look menu search
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef search_generic<df::viewscreen_dwarfmodest, df::ui_look_list::T_items*> look_menu_search_base;
|
|
|
|
class look_menu_search : public look_menu_search_base
|
|
|
|
{
|
|
|
|
typedef df::ui_look_list::T_items::T_type elt_type;
|
|
|
|
public:
|
|
|
|
bool can_init(df::viewscreen_dwarfmodest *screen)
|
|
|
|
{
|
|
|
|
if (ui->main.mode == df::ui_sidebar_mode::LookAround)
|
|
|
|
{
|
|
|
|
return look_menu_search_base::can_init(screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
string get_element_description(df::ui_look_list::T_items *element) const
|
|
|
|
{
|
|
|
|
std::string desc = "";
|
|
|
|
switch (element->type)
|
|
|
|
{
|
|
|
|
case elt_type::Item:
|
2020-03-06 15:06:27 -07:00
|
|
|
if (element->data.Item)
|
|
|
|
desc = Items::getDescription(element->data.Item, 0, true);
|
2015-06-16 18:36:19 -06:00
|
|
|
break;
|
|
|
|
case elt_type::Unit:
|
2020-03-06 15:06:27 -07:00
|
|
|
if (element->data.Unit)
|
|
|
|
desc = get_unit_description(element->data.Unit);
|
2015-06-16 18:36:19 -06:00
|
|
|
break;
|
|
|
|
case elt_type::Building:
|
2020-03-06 15:06:27 -07:00
|
|
|
if (element->data.Building)
|
|
|
|
element->data.Building->getName(&desc);
|
2015-06-16 18:36:19 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool force_in_search (size_t i)
|
|
|
|
{
|
|
|
|
df::ui_look_list::T_items *element = saved_list1[i];
|
|
|
|
switch (element->type)
|
|
|
|
{
|
|
|
|
case elt_type::Item:
|
|
|
|
case elt_type::Unit:
|
|
|
|
case elt_type::Building:
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void render() const
|
|
|
|
{
|
|
|
|
auto dims = Gui::getDwarfmodeViewDims();
|
|
|
|
int left_margin = dims.menu_x1 + 1;
|
|
|
|
int x = left_margin;
|
|
|
|
int y = 1;
|
|
|
|
|
|
|
|
print_search_option(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<df::ui_look_list::T_items*> *get_primary_list()
|
|
|
|
{
|
|
|
|
return &ui_look_list->items;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int32_t * get_viewscreen_cursor()
|
|
|
|
{
|
|
|
|
return ui_look_cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool should_check_input(set<df::interface_key> *input)
|
|
|
|
{
|
|
|
|
if (input->count(interface_key::SECONDSCROLL_UP)
|
|
|
|
|| input->count(interface_key::SECONDSCROLL_DOWN)
|
|
|
|
|| input->count(interface_key::SECONDSCROLL_PAGEUP)
|
|
|
|
|| input->count(interface_key::SECONDSCROLL_PAGEDOWN))
|
|
|
|
{
|
|
|
|
end_entry_mode();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (cursor_key_pressed(input))
|
|
|
|
{
|
|
|
|
end_entry_mode();
|
|
|
|
clear_search();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_dwarfmodest, look_menu_search);
|
|
|
|
|
|
|
|
//
|
|
|
|
// END: Look menu search
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
//
|
|
|
|
// START: Burrow assignment search
|
|
|
|
//
|
|
|
|
|
2013-02-14 04:45:58 -07:00
|
|
|
typedef search_twocolumn_modifiable<df::viewscreen_dwarfmodest, df::unit*, bool> burrow_search_base;
|
|
|
|
class burrow_search : public burrow_search_base
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool can_init(df::viewscreen_dwarfmodest *screen)
|
|
|
|
{
|
|
|
|
if (ui->main.mode == df::ui_sidebar_mode::Burrows && ui->burrows.in_add_units_mode)
|
2012-11-30 05:01:04 -07:00
|
|
|
{
|
2013-02-14 04:45:58 -07:00
|
|
|
return burrow_search_base::can_init(screen);
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
2012-11-30 05:01:04 -07:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
string get_element_description(df::unit *element) const
|
|
|
|
{
|
|
|
|
return get_unit_description(element);
|
2012-11-30 05:01:04 -07:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
void render() const
|
|
|
|
{
|
2013-01-16 07:30:29 -07:00
|
|
|
auto dims = Gui::getDwarfmodeViewDims();
|
|
|
|
int left_margin = dims.menu_x1 + 1;
|
|
|
|
int x = left_margin;
|
|
|
|
int y = 23;
|
|
|
|
|
|
|
|
print_search_option(x, y);
|
2012-12-27 02:23:13 -07:00
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
vector<df::unit *> *get_primary_list()
|
2012-12-27 02:23:13 -07:00
|
|
|
{
|
|
|
|
return &ui->burrows.list_units;
|
2012-11-30 05:01:04 -07:00
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
vector<bool> *get_secondary_list()
|
2012-11-30 05:01:04 -07:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
return &ui->burrows.sel_units;
|
2012-11-30 05:01:04 -07:00
|
|
|
}
|
|
|
|
|
2015-01-08 14:59:37 -07:00
|
|
|
virtual int32_t * get_viewscreen_cursor()
|
2012-11-30 05:01:04 -07:00
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
return &ui->burrows.unit_cursor_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool should_check_input(set<df::interface_key> *input)
|
|
|
|
{
|
|
|
|
if (input->count(interface_key::SECONDSCROLL_UP) || input->count(interface_key::SECONDSCROLL_DOWN)
|
|
|
|
|| input->count(interface_key::SECONDSCROLL_PAGEUP) || input->count(interface_key::SECONDSCROLL_PAGEDOWN))
|
|
|
|
{
|
|
|
|
end_entry_mode();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-11-30 05:01:04 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_dwarfmodest, burrow_search);
|
2012-11-30 05:01:04 -07:00
|
|
|
|
|
|
|
//
|
2012-12-27 02:23:13 -07:00
|
|
|
// END: Burrow assignment search
|
2012-11-30 05:01:04 -07:00
|
|
|
//
|
|
|
|
|
|
|
|
|
2015-01-05 17:36:06 -07:00
|
|
|
//
|
|
|
|
// START: Room assignment search
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef search_generic<df::viewscreen_dwarfmodest, df::unit*> room_assign_search_base;
|
|
|
|
class room_assign_search : public room_assign_search_base
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool can_init(df::viewscreen_dwarfmodest *screen)
|
|
|
|
{
|
|
|
|
if (ui->main.mode == df::ui_sidebar_mode::QueryBuilding && *ui_building_in_assign)
|
|
|
|
{
|
|
|
|
return room_assign_search_base::can_init(screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
string get_element_description(df::unit *element) const
|
|
|
|
{
|
|
|
|
return element ? get_unit_description(element) : "Nobody";
|
|
|
|
}
|
|
|
|
|
|
|
|
void render() const
|
|
|
|
{
|
|
|
|
auto dims = Gui::getDwarfmodeViewDims();
|
|
|
|
int left_margin = dims.menu_x1 + 1;
|
|
|
|
int x = left_margin;
|
|
|
|
int y = 19;
|
|
|
|
|
|
|
|
print_search_option(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<df::unit *> *get_primary_list()
|
|
|
|
{
|
|
|
|
return ui_building_assign_units;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int32_t * get_viewscreen_cursor()
|
|
|
|
{
|
|
|
|
return ui_building_item_cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool should_check_input(set<df::interface_key> *input)
|
|
|
|
{
|
|
|
|
if (input->count(interface_key::SECONDSCROLL_UP) || input->count(interface_key::SECONDSCROLL_DOWN)
|
|
|
|
|| input->count(interface_key::SECONDSCROLL_PAGEUP) || input->count(interface_key::SECONDSCROLL_PAGEDOWN))
|
|
|
|
{
|
|
|
|
end_entry_mode();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_dwarfmodest, room_assign_search);
|
|
|
|
|
|
|
|
//
|
|
|
|
// END: Room assignment search
|
|
|
|
//
|
|
|
|
|
2015-06-11 19:37:58 -06:00
|
|
|
//
|
|
|
|
// START: Noble suggestion search
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef search_generic<df::viewscreen_topicmeeting_fill_land_holder_positionsst, int32_t> noble_suggest_search_base;
|
|
|
|
class noble_suggest_search : public noble_suggest_search_base
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
string get_element_description (int32_t hf_id) const
|
|
|
|
{
|
|
|
|
df::historical_figure *histfig = df::historical_figure::find(hf_id);
|
|
|
|
if (!histfig)
|
|
|
|
return "";
|
|
|
|
df::unit *unit = df::unit::find(histfig->unit_id);
|
|
|
|
if (!unit)
|
|
|
|
return "";
|
|
|
|
return get_unit_description(unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void render() const
|
|
|
|
{
|
|
|
|
print_search_option(2, gps->dimy - 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<int32_t> *get_primary_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->candidate_histfig_ids;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int32_t *get_viewscreen_cursor()
|
|
|
|
{
|
|
|
|
return &viewscreen->cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_topicmeeting_fill_land_holder_positionsst, noble_suggest_search);
|
|
|
|
|
|
|
|
//
|
|
|
|
// END: Noble suggestion search
|
|
|
|
//
|
|
|
|
|
2015-12-23 14:57:43 -07:00
|
|
|
//
|
|
|
|
// START: Location occupation assignment search
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef search_generic<df::viewscreen_locationsst, df::unit*> location_assign_occupation_search_base;
|
|
|
|
class location_assign_occupation_search : public location_assign_occupation_search_base
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool can_init (df::viewscreen_locationsst *screen)
|
|
|
|
{
|
|
|
|
return screen->menu == df::viewscreen_locationsst::AssignOccupation;
|
|
|
|
}
|
|
|
|
|
|
|
|
string get_element_description (df::unit *unit) const
|
|
|
|
{
|
|
|
|
return unit ? get_unit_description(unit) : "Nobody";
|
|
|
|
}
|
|
|
|
|
|
|
|
void render() const
|
|
|
|
{
|
|
|
|
print_search_option(37, gps->dimy - 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<df::unit*> *get_primary_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->units;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int32_t *get_viewscreen_cursor()
|
|
|
|
{
|
|
|
|
return &viewscreen->unit_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_locationsst, location_assign_occupation_search);
|
|
|
|
|
|
|
|
//
|
|
|
|
// END: Location occupation assignment search
|
|
|
|
//
|
|
|
|
|
2018-05-16 22:11:52 -06:00
|
|
|
//
|
|
|
|
// START: Kitchen preferences search
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef search_multicolumn_modifiable<df::viewscreen_kitchenprefst, std::string*> kitchen_pref_search_base;
|
|
|
|
class kitchen_pref_search : public kitchen_pref_search_base
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
string get_element_description(string *s) const override
|
|
|
|
{
|
|
|
|
return s ? *s : "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void render() const override
|
|
|
|
{
|
2018-05-17 17:47:56 -06:00
|
|
|
print_search_option(40, gps->dimy - 2);
|
2018-05-16 22:11:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t *get_viewscreen_cursor() override
|
|
|
|
{
|
|
|
|
return &viewscreen->cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<string*> *get_primary_list() override
|
|
|
|
{
|
|
|
|
return &viewscreen->item_str[viewscreen->page];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool should_check_input(set<df::interface_key> *input) override
|
|
|
|
{
|
|
|
|
if (input->count(interface_key::CHANGETAB) || input->count(interface_key::SEC_CHANGETAB))
|
|
|
|
{
|
|
|
|
// Restore original list
|
|
|
|
clear_search();
|
|
|
|
reset_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define KITCHEN_VECTORS \
|
|
|
|
KVEC(df::item_type, item_type); \
|
|
|
|
KVEC(int16_t, item_subtype); \
|
|
|
|
KVEC(int16_t, mat_type); \
|
|
|
|
KVEC(int32_t, mat_index); \
|
|
|
|
KVEC(int32_t, count); \
|
2018-05-17 17:34:03 -06:00
|
|
|
KVEC(df::kitchen_pref_flag, forbidden); \
|
|
|
|
KVEC(df::kitchen_pref_flag, possible)
|
2018-05-16 22:11:52 -06:00
|
|
|
|
|
|
|
|
|
|
|
virtual void do_post_init()
|
|
|
|
{
|
|
|
|
kitchen_pref_search_base::do_post_init();
|
|
|
|
#define KVEC(type, name) name = &viewscreen->name[viewscreen->page]
|
|
|
|
KITCHEN_VECTORS;
|
|
|
|
#undef KVEC
|
|
|
|
}
|
|
|
|
|
|
|
|
void save_secondary_values()
|
|
|
|
{
|
|
|
|
#define KVEC(type, name) name##_s = *name
|
|
|
|
KITCHEN_VECTORS;
|
|
|
|
#undef KVEC
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset_secondary_viewscreen_vectors()
|
|
|
|
{
|
|
|
|
#define KVEC(type, name) name = nullptr
|
|
|
|
KITCHEN_VECTORS;
|
|
|
|
#undef KVEC
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void update_saved_secondary_list_item(size_t i, size_t j)
|
|
|
|
{
|
|
|
|
#define KVEC(type, name) name##_s[i] = (*name)[j];
|
|
|
|
KITCHEN_VECTORS;
|
|
|
|
#undef KVEC
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear_secondary_viewscreen_vectors()
|
|
|
|
{
|
|
|
|
#define KVEC(type, name) name->clear()
|
|
|
|
KITCHEN_VECTORS;
|
|
|
|
#undef KVEC
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_to_filtered_secondary_lists(size_t i)
|
|
|
|
{
|
|
|
|
#define KVEC(type, name) name->push_back(name##_s[i])
|
|
|
|
KITCHEN_VECTORS;
|
|
|
|
#undef KVEC
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear_secondary_saved_lists()
|
|
|
|
{
|
|
|
|
#define KVEC(type, name) name##_s.clear()
|
|
|
|
KITCHEN_VECTORS;
|
|
|
|
#undef KVEC
|
|
|
|
}
|
|
|
|
|
|
|
|
void restore_secondary_values()
|
|
|
|
{
|
|
|
|
#define KVEC(type, name) *name = name##_s
|
|
|
|
KITCHEN_VECTORS;
|
|
|
|
#undef KVEC
|
|
|
|
}
|
|
|
|
|
|
|
|
#define KVEC(type, name) vector<type> *name, name##_s
|
|
|
|
KITCHEN_VECTORS;
|
|
|
|
#undef KVEC
|
|
|
|
#undef KITCHEN_VECTORS
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_kitchenprefst, kitchen_pref_search);
|
|
|
|
|
|
|
|
//
|
|
|
|
// END: Kitchen preferences search
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2018-05-14 20:30:21 -06:00
|
|
|
//
|
|
|
|
// START: Stone status screen search
|
|
|
|
//
|
|
|
|
typedef layered_search<df::viewscreen_layer_stone_restrictionst, int32_t, 0> stone_search_layer;
|
|
|
|
class stone_search : public search_twocolumn_modifiable<df::viewscreen_layer_stone_restrictionst, int32_t, bool*, stone_search_layer>
|
|
|
|
{
|
|
|
|
// bool in_update = false;
|
|
|
|
public:
|
|
|
|
void render() const override
|
|
|
|
{
|
|
|
|
print_search_option(21, 23);
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<int32_t> *get_primary_list() override
|
|
|
|
{
|
|
|
|
return &viewscreen->stone_type[viewscreen->type_tab];
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<bool*> *get_secondary_list() override
|
|
|
|
{
|
|
|
|
return &viewscreen->stone_economic[viewscreen->type_tab];
|
|
|
|
}
|
|
|
|
|
|
|
|
string get_element_description(int32_t stone_type) const override
|
|
|
|
{
|
|
|
|
auto iraw = vector_get(world->raws.inorganics, stone_type);
|
|
|
|
if (!iraw)
|
|
|
|
return "";
|
|
|
|
return iraw->material.stone_name + " " + iraw->material.state_name[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool should_check_input(set<df::interface_key> *input) override
|
|
|
|
{
|
|
|
|
// if (in_update)
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
if (input->count(interface_key::CHANGETAB))
|
|
|
|
{
|
|
|
|
// Restore original list
|
|
|
|
clear_search();
|
|
|
|
reset_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// virtual void do_post_input_feed() override
|
|
|
|
// {
|
|
|
|
// auto *list1 = get_primary_list();
|
|
|
|
// auto *list2 = get_secondary_list();
|
|
|
|
// bool appended = false;
|
|
|
|
// if (list1->empty())
|
|
|
|
// {
|
|
|
|
// // Clear uses
|
|
|
|
// auto *use_list = virtual_cast<df::layer_object_listst>(viewscreen->layer_objects[4]);
|
|
|
|
// if (use_list)
|
|
|
|
// use_list->num_entries = 0;
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// else if (list1->size() == 1)
|
|
|
|
// {
|
|
|
|
// list1->push_back(list1->back());
|
|
|
|
// list2->push_back(list2->back());
|
|
|
|
// appended = true;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// in_update = true;
|
|
|
|
// Core::printerr("updating\n");
|
|
|
|
// viewscreen->feed_key(interface_key::STANDARDSCROLL_DOWN);
|
|
|
|
// viewscreen->feed_key(interface_key::STANDARDSCROLL_UP);
|
|
|
|
// Core::printerr("updating done\n");
|
|
|
|
// in_update = false;
|
|
|
|
|
|
|
|
// if (appended)
|
|
|
|
// {
|
|
|
|
// list1->pop_back();
|
|
|
|
// list2->pop_back();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_layer_stone_restrictionst, stone_search);
|
|
|
|
|
|
|
|
//
|
|
|
|
// END: Stone status screen search
|
|
|
|
//
|
|
|
|
|
2020-04-06 11:13:18 -06:00
|
|
|
//
|
|
|
|
// START: Justice screen conviction search
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef search_generic<df::viewscreen_justicest, df::unit*> justice_conviction_search_base;
|
|
|
|
class justice_conviction_search : public justice_conviction_search_base
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool can_init (df::viewscreen_justicest *screen)
|
|
|
|
{
|
|
|
|
return screen->cur_column == df::viewscreen_justicest::ConvictChoices;
|
|
|
|
}
|
|
|
|
|
|
|
|
string get_element_description (df::unit *unit) const
|
|
|
|
{
|
|
|
|
return get_unit_description(unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void render() const
|
|
|
|
{
|
|
|
|
print_search_option(37);
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<df::unit*> *get_primary_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->convict_choices;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int32_t *get_viewscreen_cursor()
|
|
|
|
{
|
|
|
|
return &viewscreen->cursor_right;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_justicest, justice_conviction_search);
|
|
|
|
|
|
|
|
//
|
|
|
|
// END: Justice screen conviction search
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// START: Justice screen interrogation search
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef search_generic<df::viewscreen_justicest, df::unit*> justice_interrogation_search_base;
|
|
|
|
class justice_interrogation_search : public justice_interrogation_search_base
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool can_init (df::viewscreen_justicest *screen)
|
|
|
|
{
|
|
|
|
return screen->cur_column == df::viewscreen_justicest::InterrogateChoices;
|
|
|
|
}
|
|
|
|
|
|
|
|
string get_element_description (df::unit *unit) const
|
|
|
|
{
|
|
|
|
return get_unit_description(unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void render() const
|
|
|
|
{
|
|
|
|
print_search_option(37);
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<df::unit*> *get_primary_list()
|
|
|
|
{
|
|
|
|
return &viewscreen->interrogate_choices;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int32_t *get_viewscreen_cursor()
|
|
|
|
{
|
|
|
|
return &viewscreen->cursor_right;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_HOOKS(df::viewscreen_justicest, justice_interrogation_search);
|
|
|
|
|
|
|
|
//
|
|
|
|
// END: Justice screen conviction search
|
|
|
|
//
|
2018-05-14 20:30:21 -06:00
|
|
|
|
2012-12-27 02:23:13 -07:00
|
|
|
#define SEARCH_HOOKS \
|
|
|
|
HOOK_ACTION(unitlist_search_hook) \
|
|
|
|
HOOK_ACTION(roomlist_search_hook) \
|
|
|
|
HOOK_ACTION(trade_search_merc_hook) \
|
|
|
|
HOOK_ACTION(trade_search_fort_hook) \
|
|
|
|
HOOK_ACTION(stocks_search_hook) \
|
|
|
|
HOOK_ACTION(pets_search_hook) \
|
2015-12-27 13:49:10 -07:00
|
|
|
HOOK_ACTION(animal_knowledge_search_hook) \
|
|
|
|
HOOK_ACTION(animal_trainer_search_hook) \
|
2012-12-27 02:23:13 -07:00
|
|
|
HOOK_ACTION(military_search_hook) \
|
|
|
|
HOOK_ACTION(nobles_search_hook) \
|
2014-05-04 04:04:03 -06:00
|
|
|
HOOK_ACTION(profiles_search_hook) \
|
2015-01-08 14:59:25 -07:00
|
|
|
HOOK_ACTION(announcement_search_hook) \
|
2012-12-27 02:23:13 -07:00
|
|
|
HOOK_ACTION(joblist_search_hook) \
|
2015-06-16 18:36:19 -06:00
|
|
|
HOOK_ACTION(look_menu_search_hook) \
|
2012-12-27 02:23:13 -07:00
|
|
|
HOOK_ACTION(burrow_search_hook) \
|
2015-01-05 17:36:06 -07:00
|
|
|
HOOK_ACTION(stockpile_search_hook) \
|
2015-06-11 19:37:58 -06:00
|
|
|
HOOK_ACTION(room_assign_search_hook) \
|
2015-12-23 14:57:43 -07:00
|
|
|
HOOK_ACTION(noble_suggest_search_hook) \
|
2018-05-14 20:30:21 -06:00
|
|
|
HOOK_ACTION(location_assign_occupation_search_hook) \
|
2018-05-16 22:11:52 -06:00
|
|
|
HOOK_ACTION(kitchen_pref_search_hook) \
|
2018-05-14 20:30:21 -06:00
|
|
|
HOOK_ACTION(stone_search_hook) \
|
2020-04-06 11:13:18 -06:00
|
|
|
HOOK_ACTION(justice_conviction_search_hook) \
|
|
|
|
HOOK_ACTION(justice_interrogation_search_hook) \
|
2018-05-14 20:30:21 -06:00
|
|
|
|
2012-10-19 06:38:28 -06:00
|
|
|
|
2013-09-30 03:19:51 -06:00
|
|
|
DFhackCExport command_result plugin_enable ( color_ostream &out, bool enable)
|
2012-10-19 06:38:28 -06:00
|
|
|
{
|
2013-09-30 03:19:51 -06:00
|
|
|
if (!gps || !gview)
|
|
|
|
return CR_FAILURE;
|
|
|
|
|
|
|
|
if (is_enabled != enable)
|
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
#define HOOK_ACTION(hook) \
|
2013-09-30 03:19:51 -06:00
|
|
|
!INTERPOSE_HOOK(hook, feed).apply(enable) || \
|
2015-05-08 14:27:52 -06:00
|
|
|
!INTERPOSE_HOOK(hook, render).apply(enable) || \
|
|
|
|
!INTERPOSE_HOOK(hook, key_conflict).apply(enable) ||
|
2012-12-27 02:23:13 -07:00
|
|
|
|
2013-09-30 03:19:51 -06:00
|
|
|
if (SEARCH_HOOKS 0)
|
|
|
|
return CR_FAILURE;
|
|
|
|
|
|
|
|
is_enabled = enable;
|
|
|
|
}
|
2018-05-12 15:00:21 -06:00
|
|
|
#undef HOOK_ACTION
|
2012-10-19 06:38:28 -06:00
|
|
|
|
2013-09-30 03:19:51 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, vector <PluginCommand> &commands)
|
|
|
|
{
|
2012-10-19 06:38:28 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
#define HOOK_ACTION(hook) \
|
|
|
|
INTERPOSE_HOOK(hook, feed).remove(); \
|
2015-05-08 14:27:52 -06:00
|
|
|
INTERPOSE_HOOK(hook, render).remove(); \
|
|
|
|
INTERPOSE_HOOK(hook, key_conflict).remove();
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
SEARCH_HOOKS
|
|
|
|
|
|
|
|
#undef HOOK_ACTION
|
|
|
|
|
2012-10-19 06:38:28 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_onstatechange ( color_ostream &out, state_change_event event )
|
|
|
|
{
|
2012-12-27 02:23:13 -07:00
|
|
|
#define HOOK_ACTION(hook) hook::module.reset_on_change();
|
|
|
|
|
2012-11-03 04:31:07 -06:00
|
|
|
switch (event) {
|
|
|
|
case SC_VIEWSCREEN_CHANGED:
|
2012-12-27 02:23:13 -07:00
|
|
|
SEARCH_HOOKS
|
2012-11-03 04:31:07 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-20 19:18:29 -06:00
|
|
|
return CR_OK;
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
#undef HOOK_ACTION
|
2012-11-03 04:31:07 -06:00
|
|
|
}
|
2012-12-27 02:23:13 -07:00
|
|
|
|
|
|
|
#undef IMPLEMENT_HOOKS
|
2013-01-16 07:30:29 -07:00
|
|
|
#undef SEARCH_HOOKS
|