2012-11-23 23:48:26 -07:00
|
|
|
#include <VTableInterpose.h>
|
|
|
|
|
|
|
|
#include "df/building.h"
|
|
|
|
#include "df/item.h"
|
|
|
|
#include "df/unit.h"
|
|
|
|
#include "df/viewscreen_dwarfmodest.h"
|
|
|
|
#include "df/world.h"
|
2014-05-04 03:55:58 -06:00
|
|
|
#include "df/items_other_id.h"
|
|
|
|
#include "df/ui_build_selector.h"
|
|
|
|
#include "df/ui_sidebar_menus.h"
|
2012-11-23 23:48:26 -07:00
|
|
|
|
|
|
|
#include "modules/Gui.h"
|
2014-05-04 03:55:58 -06:00
|
|
|
#include "modules/World.h"
|
|
|
|
#include "modules/Maps.h"
|
|
|
|
#include "modules/Buildings.h"
|
|
|
|
#include "modules/Items.h"
|
|
|
|
#include "modules/Units.h"
|
|
|
|
#include "modules/Translation.h"
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
#include "uicommon.h"
|
|
|
|
#include "TileTypes.h"
|
|
|
|
#include "DataFuncs.h"
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-12-06 16:47:35 -07:00
|
|
|
DFHACK_PLUGIN("mousequery");
|
2015-07-28 19:48:00 -06:00
|
|
|
REQUIRE_GLOBAL(enabler);
|
|
|
|
REQUIRE_GLOBAL(gps);
|
2014-12-06 16:47:35 -07:00
|
|
|
REQUIRE_GLOBAL(world);
|
|
|
|
REQUIRE_GLOBAL(ui);
|
|
|
|
REQUIRE_GLOBAL(ui_build_selector);
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
using namespace df::enums::ui_sidebar_mode;
|
|
|
|
|
2014-06-01 04:13:36 -06:00
|
|
|
#define PLUGIN_VERSION 0.18
|
2014-05-04 03:55:58 -06:00
|
|
|
|
|
|
|
static int32_t last_clicked_x, last_clicked_y, last_clicked_z;
|
|
|
|
static int32_t last_pos_x, last_pos_y, last_pos_z;
|
|
|
|
static df::coord last_move_pos;
|
|
|
|
static size_t max_list_size = 300000; // Avoid iterating over huge lists
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
static bool plugin_enabled = true;
|
|
|
|
static bool rbutton_enabled = true;
|
|
|
|
static bool tracking_enabled = false;
|
|
|
|
static bool active_scrolling = false;
|
|
|
|
static bool box_designation_enabled = false;
|
|
|
|
static bool live_view = true;
|
|
|
|
static bool skip_tracking_once = false;
|
|
|
|
static bool mouse_moved = false;
|
|
|
|
|
|
|
|
static int scroll_delay = 100;
|
|
|
|
|
|
|
|
static df::coord get_mouse_pos(int32_t &mx, int32_t &my)
|
|
|
|
{
|
|
|
|
df::coord pos;
|
|
|
|
pos.x = -30000;
|
|
|
|
|
|
|
|
if (!enabler->tracking_on)
|
|
|
|
return pos;
|
|
|
|
|
|
|
|
if (!Gui::getMousePos(mx, my))
|
|
|
|
return pos;
|
|
|
|
|
|
|
|
int32_t vx, vy, vz;
|
|
|
|
if (!Gui::getViewCoords(vx, vy, vz))
|
|
|
|
return pos;
|
|
|
|
|
|
|
|
pos.x = vx + mx - 1;
|
|
|
|
pos.y = vy + my - 1;
|
2017-06-02 13:39:23 -06:00
|
|
|
pos.z = vz - Gui::getDepthAt(mx, my);
|
2014-05-04 03:55:58 -06:00
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_valid_pos(const df::coord pos)
|
|
|
|
{
|
|
|
|
auto designation = Maps::getTileDesignation(pos);
|
|
|
|
if (!designation)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (designation->bits.hidden)
|
|
|
|
return false; // Items in parts of the map not yet revealed
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static vector<df::unit *> get_units_at(const df::coord pos, bool only_one)
|
|
|
|
{
|
|
|
|
vector<df::unit *> list;
|
|
|
|
|
|
|
|
auto count = world->units.active.size();
|
|
|
|
if (count > max_list_size)
|
|
|
|
return list;
|
|
|
|
|
|
|
|
df::unit_flags1 bad_flags;
|
|
|
|
bad_flags.whole = 0;
|
|
|
|
bad_flags.bits.dead = true;
|
|
|
|
bad_flags.bits.hidden_ambusher = true;
|
|
|
|
bad_flags.bits.hidden_in_ambush = true;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
df::unit *unit = world->units.active[i];
|
|
|
|
|
2014-12-21 14:42:12 -07:00
|
|
|
if(unit->pos.x == pos.x && unit->pos.y == pos.y && unit->pos.z == pos.z &&
|
2014-05-04 03:55:58 -06:00
|
|
|
!(unit->flags1.whole & bad_flags.whole) &&
|
|
|
|
unit->profession != profession::THIEF && unit->profession != profession::MASTER_THIEF)
|
|
|
|
{
|
|
|
|
list.push_back(unit);
|
|
|
|
if (only_one)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static vector<df::item *> get_items_at(const df::coord pos, bool only_one)
|
|
|
|
{
|
|
|
|
vector<df::item *> list;
|
|
|
|
auto count = world->items.other[items_other_id::IN_PLAY].size();
|
|
|
|
if (count > max_list_size)
|
|
|
|
return list;
|
|
|
|
|
|
|
|
df::item_flags bad_flags;
|
|
|
|
bad_flags.whole = 0;
|
|
|
|
bad_flags.bits.in_building = true;
|
|
|
|
bad_flags.bits.garbage_collect = true;
|
|
|
|
bad_flags.bits.removed = true;
|
|
|
|
bad_flags.bits.dead_dwarf = true;
|
|
|
|
bad_flags.bits.murder = true;
|
|
|
|
bad_flags.bits.construction = true;
|
|
|
|
bad_flags.bits.in_inventory = true;
|
|
|
|
bad_flags.bits.in_chest = true;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
df::item *item = world->items.other[items_other_id::IN_PLAY][i];
|
|
|
|
if (item->flags.whole & bad_flags.whole)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (pos.z == item->pos.z && pos.x == item->pos.x && pos.y == item->pos.y)
|
|
|
|
list.push_back(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static df::interface_key get_default_query_mode(const df::coord pos)
|
|
|
|
{
|
|
|
|
if (!is_valid_pos(pos))
|
|
|
|
return df::interface_key::D_LOOK;
|
|
|
|
|
|
|
|
bool fallback_to_building_query = false;
|
|
|
|
|
|
|
|
// Check for unit under cursor
|
|
|
|
auto ulist = get_units_at(pos, true);
|
|
|
|
if (ulist.size() > 0)
|
|
|
|
return df::interface_key::D_VIEWUNIT;
|
|
|
|
|
|
|
|
// Check for building under cursor
|
|
|
|
auto bld = Buildings::findAtTile(pos);
|
|
|
|
if (bld)
|
|
|
|
{
|
|
|
|
df::building_type type = bld->getType();
|
|
|
|
|
|
|
|
if (type == building_type::Stockpile)
|
|
|
|
{
|
|
|
|
fallback_to_building_query = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// For containers use item view, for everything else, query view
|
|
|
|
return (type == building_type::Box || type == building_type::Cabinet ||
|
2014-12-21 14:42:12 -07:00
|
|
|
type == building_type::Weaponrack || type == building_type::Armorstand)
|
2014-05-04 03:55:58 -06:00
|
|
|
? df::interface_key::D_BUILDITEM : df::interface_key::D_BUILDJOB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for items under cursor
|
|
|
|
auto ilist = get_items_at(pos, true);
|
|
|
|
if (ilist.size() > 0)
|
|
|
|
return df::interface_key::D_LOOK;
|
|
|
|
|
|
|
|
return (fallback_to_building_query) ? df::interface_key::D_BUILDJOB : df::interface_key::D_LOOK;
|
|
|
|
}
|
2012-11-23 23:48:26 -07:00
|
|
|
|
|
|
|
struct mousequery_hook : public df::viewscreen_dwarfmodest
|
|
|
|
{
|
|
|
|
typedef df::viewscreen_dwarfmodest interpose_base;
|
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
void sendKey(const df::interface_key &key)
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
|
|
|
set<df::interface_key> tmp;
|
|
|
|
tmp.insert(key);
|
2014-05-04 03:55:58 -06:00
|
|
|
INTERPOSE_NEXT(feed)(&tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isInDesignationMenu()
|
|
|
|
{
|
|
|
|
switch (ui->main.mode)
|
|
|
|
{
|
|
|
|
case DesignateMine:
|
|
|
|
case DesignateRemoveRamps:
|
|
|
|
case DesignateUpStair:
|
|
|
|
case DesignateDownStair:
|
|
|
|
case DesignateUpDownStair:
|
|
|
|
case DesignateUpRamp:
|
|
|
|
case DesignateChannel:
|
|
|
|
case DesignateGatherPlants:
|
|
|
|
case DesignateRemoveDesignation:
|
|
|
|
case DesignateSmooth:
|
|
|
|
case DesignateCarveTrack:
|
|
|
|
case DesignateEngrave:
|
|
|
|
case DesignateCarveFortification:
|
2014-12-21 14:42:12 -07:00
|
|
|
case DesignateItemsClaim:
|
|
|
|
case DesignateItemsForbid:
|
|
|
|
case DesignateItemsMelt:
|
|
|
|
case DesignateItemsUnmelt:
|
|
|
|
case DesignateItemsDump:
|
|
|
|
case DesignateItemsUndump:
|
|
|
|
case DesignateItemsHide:
|
|
|
|
case DesignateItemsUnhide:
|
2014-05-04 03:55:58 -06:00
|
|
|
case DesignateChopTrees:
|
|
|
|
case DesignateToggleEngravings:
|
2014-12-21 14:42:12 -07:00
|
|
|
case DesignateToggleMarker:
|
2014-05-04 03:55:58 -06:00
|
|
|
case DesignateTrafficHigh:
|
|
|
|
case DesignateTrafficNormal:
|
|
|
|
case DesignateTrafficLow:
|
|
|
|
case DesignateTrafficRestricted:
|
2014-12-21 14:42:12 -07:00
|
|
|
case DesignateRemoveConstruction:
|
2014-05-04 03:55:58 -06:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case Burrows:
|
|
|
|
return ui->burrows.in_define_mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
return false;
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
bool isInTrackableMode()
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
if (isInDesignationMenu())
|
|
|
|
return box_designation_enabled;
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
switch (ui->main.mode)
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
case DesignateItemsClaim:
|
|
|
|
case DesignateItemsForbid:
|
|
|
|
case DesignateItemsMelt:
|
|
|
|
case DesignateItemsUnmelt:
|
|
|
|
case DesignateItemsDump:
|
|
|
|
case DesignateItemsUndump:
|
|
|
|
case DesignateItemsHide:
|
|
|
|
case DesignateItemsUnhide:
|
|
|
|
case DesignateTrafficHigh:
|
|
|
|
case DesignateTrafficNormal:
|
|
|
|
case DesignateTrafficLow:
|
|
|
|
case DesignateTrafficRestricted:
|
|
|
|
case Stockpiles:
|
|
|
|
case Squads:
|
|
|
|
case NotesPoints:
|
|
|
|
case NotesRoutes:
|
|
|
|
case Zones:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case Build:
|
|
|
|
return inBuildPlacement();
|
|
|
|
|
|
|
|
case QueryBuilding:
|
|
|
|
case BuildingItems:
|
|
|
|
case ViewUnits:
|
|
|
|
case LookAround:
|
|
|
|
return !enabler->mouse_lbut;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
bool isInAreaSelectionMode()
|
|
|
|
{
|
2014-12-21 14:42:12 -07:00
|
|
|
bool selectableMode =
|
2014-05-04 03:55:58 -06:00
|
|
|
isInDesignationMenu() ||
|
|
|
|
ui->main.mode == Stockpiles ||
|
|
|
|
ui->main.mode == Zones;
|
|
|
|
|
|
|
|
if (selectableMode)
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
int32_t x, y, z;
|
|
|
|
return Gui::getDesignationCoords(x, y, z);
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool handleMouse(const set<df::interface_key> *input)
|
|
|
|
{
|
|
|
|
int32_t mx, my;
|
|
|
|
auto mpos = get_mouse_pos(mx, my);
|
|
|
|
if (mpos.x == -30000)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto dims = Gui::getDwarfmodeViewDims();
|
|
|
|
if (enabler->mouse_lbut)
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
bool cursor_still_here = (last_clicked_x == mpos.x && last_clicked_y == mpos.y && last_clicked_z == mpos.z);
|
|
|
|
last_clicked_x = mpos.x;
|
|
|
|
last_clicked_y = mpos.y;
|
|
|
|
last_clicked_z = mpos.z;
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
df::interface_key key = interface_key::NONE;
|
|
|
|
bool designationMode = false;
|
|
|
|
bool skipRefresh = false;
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
if (isInTrackableMode())
|
|
|
|
{
|
|
|
|
designationMode = true;
|
|
|
|
key = df::interface_key::SELECT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (ui->main.mode)
|
|
|
|
{
|
|
|
|
case QueryBuilding:
|
|
|
|
if (cursor_still_here)
|
|
|
|
key = df::interface_key::D_BUILDITEM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BuildingItems:
|
|
|
|
if (cursor_still_here)
|
|
|
|
key = df::interface_key::D_VIEWUNIT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ViewUnits:
|
|
|
|
if (cursor_still_here)
|
|
|
|
key = df::interface_key::D_LOOK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LookAround:
|
|
|
|
if (cursor_still_here)
|
|
|
|
key = df::interface_key::D_BUILDJOB;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Build:
|
2014-08-11 14:07:52 -06:00
|
|
|
if (ui_build_selector)
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2014-08-11 14:07:52 -06:00
|
|
|
if (ui_build_selector->stage < 2)
|
2014-05-04 03:55:58 -06:00
|
|
|
{
|
|
|
|
designationMode = true;
|
|
|
|
key = df::interface_key::SELECT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
designationMode = true;
|
|
|
|
skipRefresh = true;
|
|
|
|
key = df::interface_key::SELECT_ALL;
|
|
|
|
}
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
2014-05-04 03:55:58 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Default:
|
|
|
|
break;
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
default:
|
|
|
|
return false;
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
enabler->mouse_lbut = 0;
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-12-21 14:42:12 -07:00
|
|
|
// Can't check limits earlier as we must be sure we are in query or default mode
|
2014-05-04 03:55:58 -06:00
|
|
|
// (so we can clear the button down flag)
|
|
|
|
int right_bound = (dims.menu_x1 > 0) ? dims.menu_x1 - 2 : gps->dimx - 2;
|
|
|
|
if (mx < 1 || mx > right_bound || my < 1 || my > gps->dimy - 2)
|
|
|
|
return false;
|
|
|
|
|
2014-12-21 14:42:12 -07:00
|
|
|
if (ui->main.mode == df::ui_sidebar_mode::Zones ||
|
2014-05-04 03:55:58 -06:00
|
|
|
ui->main.mode == df::ui_sidebar_mode::Stockpiles)
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
int32_t x, y, z;
|
|
|
|
if (Gui::getDesignationCoords(x, y, z))
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
auto dX = abs(x - mpos.x);
|
|
|
|
if (dX > 30)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto dY = abs(y - mpos.y);
|
|
|
|
if (dY > 30)
|
|
|
|
return false;
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
|
|
|
}
|
2014-05-04 03:55:58 -06:00
|
|
|
|
|
|
|
if (!designationMode)
|
|
|
|
{
|
|
|
|
while (ui->main.mode != Default)
|
|
|
|
{
|
|
|
|
sendKey(df::interface_key::LEAVESCREEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key == interface_key::NONE)
|
|
|
|
key = get_default_query_mode(mpos);
|
|
|
|
|
|
|
|
sendKey(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!skipRefresh)
|
|
|
|
{
|
|
|
|
// Force UI refresh
|
|
|
|
moveCursor(mpos, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (designationMode)
|
|
|
|
sendKey(key);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (rbutton_enabled && enabler->mouse_rbut)
|
|
|
|
{
|
|
|
|
if (isInDesignationMenu() && !box_designation_enabled)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Escape out of query mode
|
|
|
|
enabler->mouse_rbut_down = 0;
|
|
|
|
enabler->mouse_rbut = 0;
|
|
|
|
|
|
|
|
using namespace df::enums::ui_sidebar_mode;
|
|
|
|
if ((ui->main.mode == QueryBuilding || ui->main.mode == BuildingItems ||
|
2014-12-21 14:42:12 -07:00
|
|
|
ui->main.mode == ViewUnits || ui->main.mode == LookAround) ||
|
2014-05-04 03:55:58 -06:00
|
|
|
(isInTrackableMode() && tracking_enabled))
|
|
|
|
{
|
|
|
|
sendKey(df::interface_key::LEAVESCREEN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int scroll_trigger_x = dims.menu_x1 / 3;
|
|
|
|
int scroll_trigger_y = gps->dimy / 3;
|
|
|
|
if (mx < scroll_trigger_x)
|
|
|
|
sendKey(interface_key::CURSOR_LEFT_FAST);
|
|
|
|
|
|
|
|
if (mx > ((dims.menu_x1 > 0) ? dims.menu_x1 : gps->dimx) - scroll_trigger_x)
|
|
|
|
sendKey(interface_key::CURSOR_RIGHT_FAST);
|
|
|
|
|
|
|
|
if (my < scroll_trigger_y)
|
|
|
|
sendKey(interface_key::CURSOR_UP_FAST);
|
|
|
|
|
|
|
|
if (my > gps->dimy - scroll_trigger_y)
|
|
|
|
sendKey(interface_key::CURSOR_DOWN_FAST);
|
|
|
|
}
|
|
|
|
}
|
2014-12-27 09:03:06 -07:00
|
|
|
else if (input->count(interface_key::CUSTOM_ALT_M) && isInDesignationMenu())
|
2014-05-04 03:55:58 -06:00
|
|
|
{
|
|
|
|
box_designation_enabled = !box_designation_enabled;
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
if (input->count(interface_key::CURSOR_UP) ||
|
|
|
|
input->count(interface_key::CURSOR_DOWN) ||
|
|
|
|
input->count(interface_key::CURSOR_LEFT) ||
|
|
|
|
input->count(interface_key::CURSOR_RIGHT) ||
|
|
|
|
input->count(interface_key::CURSOR_UPLEFT) ||
|
|
|
|
input->count(interface_key::CURSOR_UPRIGHT) ||
|
|
|
|
input->count(interface_key::CURSOR_DOWNLEFT) ||
|
|
|
|
input->count(interface_key::CURSOR_DOWNRIGHT) ||
|
|
|
|
input->count(interface_key::CURSOR_UP_FAST) ||
|
|
|
|
input->count(interface_key::CURSOR_DOWN_FAST) ||
|
|
|
|
input->count(interface_key::CURSOR_LEFT_FAST) ||
|
|
|
|
input->count(interface_key::CURSOR_RIGHT_FAST) ||
|
|
|
|
input->count(interface_key::CURSOR_UPLEFT_FAST) ||
|
|
|
|
input->count(interface_key::CURSOR_UPRIGHT_FAST) ||
|
|
|
|
input->count(interface_key::CURSOR_DOWNLEFT_FAST) ||
|
|
|
|
input->count(interface_key::CURSOR_DOWNRIGHT_FAST) ||
|
|
|
|
input->count(interface_key::CURSOR_UP_Z) ||
|
|
|
|
input->count(interface_key::CURSOR_DOWN_Z) ||
|
|
|
|
input->count(interface_key::CURSOR_UP_Z_AUX) ||
|
|
|
|
input->count(interface_key::CURSOR_DOWN_Z_AUX))
|
|
|
|
{
|
|
|
|
mouse_moved = false;
|
|
|
|
if (shouldTrack())
|
|
|
|
skip_tracking_once = true;
|
|
|
|
}
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
return false;
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
void moveCursor(df::coord &mpos, bool forced)
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
bool should_skip_tracking = skip_tracking_once;
|
|
|
|
skip_tracking_once = false;
|
|
|
|
if (!forced)
|
|
|
|
{
|
|
|
|
if (mpos.x == last_pos_x && mpos.y == last_pos_y && mpos.z == last_pos_z)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_pos_x = mpos.x;
|
|
|
|
last_pos_y = mpos.y;
|
|
|
|
last_pos_z = mpos.z;
|
|
|
|
|
|
|
|
if (!forced && should_skip_tracking)
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t x, y, z;
|
|
|
|
Gui::getCursorCoords(x, y, z);
|
|
|
|
if (mpos.x == x && mpos.y == y && mpos.z == z)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Gui::setCursorCoords(mpos.x, mpos.y, mpos.z);
|
2014-09-23 16:57:31 -06:00
|
|
|
if (mpos.z == 0)
|
|
|
|
{
|
|
|
|
sendKey(interface_key::CURSOR_UP_Z);
|
|
|
|
sendKey(interface_key::CURSOR_DOWN_Z);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sendKey(interface_key::CURSOR_DOWN_Z);
|
|
|
|
sendKey(interface_key::CURSOR_UP_Z);
|
|
|
|
}
|
2014-05-04 03:55:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool inBuildPlacement()
|
|
|
|
{
|
2014-08-11 14:07:52 -06:00
|
|
|
return ui_build_selector &&
|
|
|
|
ui_build_selector->building_type != -1 &&
|
|
|
|
ui_build_selector->stage == 1;
|
2014-05-04 03:55:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool shouldTrack()
|
|
|
|
{
|
|
|
|
if (!tracking_enabled)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return isInTrackableMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, feed, (set<df::interface_key> *input))
|
|
|
|
{
|
|
|
|
if (!plugin_enabled || !handleMouse(input))
|
|
|
|
INTERPOSE_NEXT(feed)(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, render, ())
|
|
|
|
{
|
|
|
|
INTERPOSE_NEXT(render)();
|
|
|
|
|
|
|
|
if (!plugin_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
static decltype(enabler->clock) last_t = 0;
|
|
|
|
|
|
|
|
auto dims = Gui::getDwarfmodeViewDims();
|
|
|
|
auto right_margin = (dims.menu_x1 > 0) ? dims.menu_x1 : gps->dimx;
|
|
|
|
|
|
|
|
int32_t mx, my;
|
|
|
|
auto mpos = get_mouse_pos(mx, my);
|
|
|
|
bool mpos_valid = mpos.x != -30000 && mpos.y != -30000 && mpos.z != -30000;
|
|
|
|
if (mx < 1 || mx > right_margin - 2 || my < 1 || my > gps->dimy - 2)
|
|
|
|
mpos_valid = false;
|
|
|
|
|
2014-06-01 04:13:36 -06:00
|
|
|
// Check if in lever binding mode
|
2014-12-21 14:42:12 -07:00
|
|
|
if (Gui::getFocusString(Core::getTopViewscreen()) ==
|
2014-06-01 04:13:36 -06:00
|
|
|
"dwarfmode/QueryBuilding/Some/Lever/AddJob")
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
if (mpos_valid)
|
|
|
|
{
|
|
|
|
if (mpos.x != last_move_pos.x || mpos.y != last_move_pos.y || mpos.z != last_move_pos.z)
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
mouse_moved = true;
|
|
|
|
last_move_pos = mpos;
|
|
|
|
}
|
|
|
|
}
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
int left_margin = dims.menu_x1 + 1;
|
|
|
|
int look_width = dims.menu_x2 - dims.menu_x1 - 1;
|
|
|
|
int disp_x = left_margin;
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
if (isInDesignationMenu())
|
|
|
|
{
|
|
|
|
int x = left_margin;
|
2014-12-27 09:03:06 -07:00
|
|
|
int y = gps->dimy - 2;
|
2016-01-04 17:31:57 -07:00
|
|
|
OutputToggleString(x, y, "Box Select", interface_key::CUSTOM_ALT_M, box_designation_enabled,
|
2014-12-27 09:03:06 -07:00
|
|
|
true, left_margin, COLOR_WHITE, COLOR_LIGHTRED);
|
2014-05-04 03:55:58 -06:00
|
|
|
}
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
//Display selection dimensions
|
|
|
|
bool showing_dimensions = false;
|
|
|
|
if (isInAreaSelectionMode())
|
|
|
|
{
|
|
|
|
showing_dimensions = true;
|
|
|
|
int32_t x, y, z;
|
|
|
|
Gui::getDesignationCoords(x, y, z);
|
|
|
|
coord32_t curr_pos;
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
if (!tracking_enabled && mouse_moved && mpos_valid &&
|
|
|
|
(!isInDesignationMenu() || box_designation_enabled))
|
|
|
|
{
|
|
|
|
curr_pos = mpos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Gui::getCursorCoords(curr_pos.x, curr_pos.y, curr_pos.z);
|
|
|
|
}
|
|
|
|
auto dX = abs(x - curr_pos.x) + 1;
|
|
|
|
auto dY = abs(y - curr_pos.y) + 1;
|
|
|
|
auto dZ = abs(z - curr_pos.z) + 1;
|
|
|
|
|
|
|
|
int disp_y = gps->dimy - 3;
|
|
|
|
stringstream label;
|
|
|
|
label << "Selection: " << dX << "x" << dY << "x" << dZ;
|
|
|
|
OutputString(COLOR_WHITE, disp_x, disp_y, label.str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mouse_moved = false;
|
|
|
|
}
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
if (!mpos_valid)
|
|
|
|
return;
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
int scroll_buffer = 6;
|
|
|
|
auto delta_t = enabler->clock - last_t;
|
|
|
|
if (active_scrolling && !isInTrackableMode() && delta_t > scroll_delay)
|
|
|
|
{
|
|
|
|
last_t = enabler->clock;
|
|
|
|
if (mx < scroll_buffer)
|
|
|
|
{
|
|
|
|
sendKey(interface_key::CURSOR_LEFT);
|
|
|
|
return;
|
|
|
|
}
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
if (mx > right_margin - scroll_buffer)
|
|
|
|
{
|
|
|
|
sendKey(interface_key::CURSOR_RIGHT);
|
|
|
|
return;
|
|
|
|
}
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
if (my < scroll_buffer)
|
|
|
|
{
|
|
|
|
sendKey(interface_key::CURSOR_UP);
|
|
|
|
return;
|
|
|
|
}
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
if (my > gps->dimy - scroll_buffer)
|
|
|
|
{
|
|
|
|
sendKey(interface_key::CURSOR_DOWN);
|
|
|
|
return;
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
2014-05-04 03:55:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!live_view && !isInTrackableMode() && !DFHack::World::ReadPauseState())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!tracking_enabled && isInTrackableMode())
|
|
|
|
{
|
|
|
|
UIColor color = COLOR_GREEN;
|
|
|
|
int32_t x, y, z;
|
|
|
|
if (Gui::getDesignationCoords(x, y, z))
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
color = COLOR_WHITE;
|
2014-12-21 14:42:12 -07:00
|
|
|
if (ui->main.mode == df::ui_sidebar_mode::Zones ||
|
2014-05-04 03:55:58 -06:00
|
|
|
ui->main.mode == df::ui_sidebar_mode::Stockpiles)
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
auto dX = abs(x - mpos.x);
|
|
|
|
if (dX > 30)
|
|
|
|
color = COLOR_RED;
|
|
|
|
|
|
|
|
auto dY = abs(y - mpos.y);
|
|
|
|
if (dY > 30)
|
|
|
|
color = COLOR_RED;
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
|
|
|
}
|
2014-05-04 03:55:58 -06:00
|
|
|
|
2015-12-22 09:42:51 -07:00
|
|
|
OutputString(color, mx, my, "X", false, 0, 0, true);
|
2014-05-04 03:55:58 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldTrack())
|
|
|
|
{
|
2014-12-21 14:42:12 -07:00
|
|
|
if (delta_t <= scroll_delay && (mx < scroll_buffer ||
|
|
|
|
mx > dims.menu_x1 - scroll_buffer ||
|
2014-05-04 03:55:58 -06:00
|
|
|
my < scroll_buffer ||
|
|
|
|
my > gps->dimy - scroll_buffer))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_t = enabler->clock;
|
|
|
|
moveCursor(mpos, false);
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
if (dims.menu_x1 <= 0)
|
|
|
|
return; // No menu displayed
|
|
|
|
|
|
|
|
if (!is_valid_pos(mpos) || isInTrackableMode())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (showing_dimensions)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Display live query
|
|
|
|
auto ulist = get_units_at(mpos, false);
|
|
|
|
auto bld = Buildings::findAtTile(mpos);
|
|
|
|
auto ilist = get_items_at(mpos, false);
|
|
|
|
|
|
|
|
int look_list = ulist.size() + ((bld) ? 1 : 0) + ilist.size() + 1;
|
|
|
|
set_to_limit(look_list, 8);
|
|
|
|
int disp_y = gps->dimy - look_list - 2;
|
|
|
|
|
|
|
|
int c = 0;
|
|
|
|
for (auto it = ulist.begin(); it != ulist.end() && c < 8; it++, c++)
|
|
|
|
{
|
|
|
|
string label;
|
|
|
|
auto name = Units::getVisibleName(*it);
|
|
|
|
if (name->has_name)
|
|
|
|
label = Translation::TranslateName(name, false);
|
|
|
|
if (label.length() > 0)
|
|
|
|
label += ", ";
|
|
|
|
|
|
|
|
label += Units::getProfessionName(*it); // Check animal type too
|
|
|
|
label = pad_string(label, look_width, false, true);
|
|
|
|
|
|
|
|
OutputString(COLOR_WHITE, disp_x, disp_y, label, true, left_margin);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto it = ilist.begin(); it != ilist.end() && c < 8; it++, c++)
|
|
|
|
{
|
|
|
|
auto label = Items::getDescription(*it, 0, false);
|
|
|
|
label = pad_string(label, look_width, false, true);
|
|
|
|
OutputString(COLOR_YELLOW, disp_x, disp_y, label, true, left_margin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c > 7)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (bld)
|
|
|
|
{
|
|
|
|
string label;
|
|
|
|
bld->getName(&label);
|
|
|
|
label = pad_string(label, look_width, false, true);
|
|
|
|
OutputString(COLOR_CYAN, disp_x, disp_y, label, true, left_margin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c > 7)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto tt = Maps::getTileType(mpos);
|
|
|
|
OutputString(COLOR_BLUE, disp_x, disp_y, tileName(*tt), true, left_margin);
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
2014-05-04 03:55:58 -06:00
|
|
|
};
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE_PRIO(mousequery_hook, feed, 100);
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE_PRIO(mousequery_hook, render, 100);
|
|
|
|
|
|
|
|
static command_result mousequery_cmd(color_ostream &out, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
bool show_help = false;
|
|
|
|
if (parameters.size() < 1)
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
show_help = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto cmd = toLower(parameters[0]);
|
|
|
|
auto state = (parameters.size() == 2) ? toLower(parameters[1]) : "-1";
|
|
|
|
if (cmd[0] == 'v')
|
|
|
|
{
|
|
|
|
out << "MouseQuery" << endl << "Version: " << PLUGIN_VERSION << endl;
|
|
|
|
}
|
|
|
|
else if (cmd[0] == 'p')
|
|
|
|
{
|
|
|
|
plugin_enabled = (state == "enable");
|
|
|
|
}
|
|
|
|
else if (cmd[0] == 'r')
|
|
|
|
{
|
|
|
|
rbutton_enabled = (state == "enable");
|
|
|
|
}
|
|
|
|
else if (cmd[0] == 't')
|
|
|
|
{
|
|
|
|
tracking_enabled = (state == "enable");
|
|
|
|
if (!tracking_enabled)
|
|
|
|
active_scrolling = false;
|
|
|
|
}
|
|
|
|
else if (cmd[0] == 'e')
|
|
|
|
{
|
|
|
|
active_scrolling = (state == "enable");
|
|
|
|
if (active_scrolling)
|
|
|
|
tracking_enabled = true;
|
|
|
|
}
|
|
|
|
else if (cmd[0] == 'l')
|
|
|
|
{
|
|
|
|
live_view = (state == "enable");
|
|
|
|
}
|
|
|
|
else if (cmd[0] == 'd')
|
|
|
|
{
|
|
|
|
auto l = atoi(state.c_str());
|
|
|
|
if (l > 0 || state == "0")
|
|
|
|
scroll_delay = l;
|
|
|
|
else
|
|
|
|
out << "Current delay: " << scroll_delay << endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
show_help = true;
|
|
|
|
}
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
if (show_help)
|
|
|
|
return CR_WRONG_USAGE;
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2013-09-30 03:19:51 -06:00
|
|
|
DFHACK_PLUGIN_IS_ENABLED(is_enabled);
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2013-09-30 03:19:51 -06:00
|
|
|
DFhackCExport command_result plugin_enable ( color_ostream &out, bool enable)
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2013-09-30 03:19:51 -06:00
|
|
|
if (is_enabled != enable)
|
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
last_clicked_x = last_clicked_y = last_clicked_z = -1;
|
|
|
|
last_pos_x = last_pos_y = last_pos_z = -1;
|
|
|
|
last_move_pos.x = last_move_pos.y = last_move_pos.z = -1;
|
2013-09-30 03:19:51 -06:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
if (!INTERPOSE_HOOK(mousequery_hook, feed).apply(enable) ||
|
|
|
|
!INTERPOSE_HOOK(mousequery_hook, render).apply(enable))
|
2013-09-30 03:19:51 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
|
|
|
|
is_enabled = enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2013-09-30 03:19:51 -06:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
2014-05-04 03:55:58 -06:00
|
|
|
commands.push_back(
|
|
|
|
PluginCommand(
|
|
|
|
"mousequery", "Add mouse functionality to Dwarf Fortress",
|
2014-12-21 14:42:12 -07:00
|
|
|
mousequery_cmd, false,
|
2014-05-04 03:55:58 -06:00
|
|
|
"mousequery [plugin|rbutton|track|edge|live] [enabled|disabled]\n"
|
|
|
|
" plugin: enable/disable the entire plugin\n"
|
|
|
|
" rbutton: enable/disable right mouse button\n"
|
|
|
|
" track: enable/disable moving cursor in build and designation mode\n"
|
|
|
|
" edge: enable/disable active edge scrolling (when on, will also enable tracking)\n"
|
|
|
|
" live: enable/disable query view when unpaused\n\n"
|
|
|
|
"mousequery delay <amount>\n"
|
|
|
|
" Set delay when edge scrolling in tracking mode. Omit amount to display current setting.\n"
|
|
|
|
));
|
2012-11-23 23:48:26 -07:00
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
|
|
|
|
{
|
|
|
|
switch (event) {
|
|
|
|
case SC_MAP_LOADED:
|
2014-05-04 03:55:58 -06:00
|
|
|
last_clicked_x = last_clicked_y = last_clicked_z = -1;
|
|
|
|
last_pos_x = last_pos_y = last_pos_z = -1;
|
|
|
|
last_move_pos.x = last_move_pos.y = last_move_pos.z = -1;
|
2012-11-23 23:48:26 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|