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"
|
2022-09-19 12:13:47 -06:00
|
|
|
#include "Debug.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
|
|
|
|
2022-09-19 12:13:47 -06:00
|
|
|
namespace DFHack {
|
|
|
|
DBG_DECLARE(mousequery,log,DebugCategory::LINFO);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2018-04-06 00:18:15 -06:00
|
|
|
static uint32_t scroll_delay = 100;
|
2014-05-04 03:55:58 -06:00
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
static bool awaiting_lbut_up, awaiting_rbut_up;
|
|
|
|
static enum { None, Left, Right } drag_mode;
|
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
static df::coord get_mouse_pos(int32_t &mx, int32_t &my)
|
|
|
|
{
|
2022-09-18 09:19:02 -06:00
|
|
|
df::coord pos = Gui::getMousePos();
|
|
|
|
pos.z -= Gui::getDepthAt(pos.x, pos.y);
|
2014-05-04 03:55:58 -06:00
|
|
|
|
2022-09-19 12:13:47 -06:00
|
|
|
df::coord vpos = Gui::getViewportPos();
|
|
|
|
mx = pos.x - vpos.x + 1;
|
|
|
|
my = pos.y - vpos.y + 1;
|
|
|
|
|
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;
|
2018-06-21 09:17:09 -06:00
|
|
|
bad_flags.bits.inactive = true;
|
2014-05-04 03:55:58 -06:00
|
|
|
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];
|
|
|
|
|
2018-05-24 18:43:30 -06: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 ||
|
2018-05-24 18:43:30 -06: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;
|
|
|
|
|
2018-04-06 00:18:15 -06:00
|
|
|
default:
|
|
|
|
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()
|
|
|
|
{
|
2018-05-24 18:43:30 -06: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;
|
|
|
|
}
|
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
bool handleLeft(df::coord &mpos, int32_t mx, int32_t my)
|
2014-05-04 03:55:58 -06:00
|
|
|
{
|
2018-05-24 07:34:57 -06:00
|
|
|
if (!(Core::getInstance().getModstate() & DFH_MOD_SHIFT))
|
2018-05-24 07:07:12 -06:00
|
|
|
mpos.z += Gui::getDepthAt(mx, my);
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2018-05-24 07:07:12 -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
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
df::interface_key key = interface_key::NONE;
|
|
|
|
bool designationMode = false;
|
|
|
|
bool skipRefresh = false;
|
|
|
|
|
|
|
|
if (isInTrackableMode())
|
|
|
|
{
|
|
|
|
designationMode = true;
|
|
|
|
key = df::interface_key::SELECT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (ui->main.mode)
|
2014-05-04 03:55:58 -06:00
|
|
|
{
|
2018-05-24 07:07:12 -06:00
|
|
|
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:
|
|
|
|
if (ui_build_selector)
|
2014-05-04 03:55:58 -06:00
|
|
|
{
|
2018-05-24 07:07:12 -06:00
|
|
|
if (ui_build_selector->stage < 2)
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2018-05-24 07:07:12 -06:00
|
|
|
designationMode = true;
|
|
|
|
key = df::interface_key::SELECT;
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
2018-05-24 07:07:12 -06:00
|
|
|
else
|
|
|
|
{
|
|
|
|
designationMode = true;
|
|
|
|
skipRefresh = true;
|
|
|
|
key = df::interface_key::SELECT_ALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-05-04 03:55:58 -06:00
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
case Default:
|
|
|
|
break;
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
default:
|
|
|
|
return false;
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
2018-05-24 07:07:12 -06:00
|
|
|
}
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
enabler->mouse_lbut = 0;
|
2012-11-23 23:48:26 -07:00
|
|
|
|
2018-05-24 18:43:30 -06:00
|
|
|
// Can't check limits earlier as we must be sure we are in query or default mode
|
2018-05-24 07:07:12 -06:00
|
|
|
// (so we can clear the button down flag)
|
|
|
|
auto dims = Gui::getDwarfmodeViewDims();
|
2019-05-16 21:30:03 -06:00
|
|
|
if (mx < 1 || mx > dims.map_x2 || my < 1 || my > dims.map_y2)
|
2018-05-24 07:07:12 -06:00
|
|
|
return false;
|
2014-05-04 03:55:58 -06:00
|
|
|
|
2018-05-24 18:43:30 -06:00
|
|
|
if (ui->main.mode == df::ui_sidebar_mode::Zones ||
|
2018-05-24 07:07:12 -06:00
|
|
|
ui->main.mode == df::ui_sidebar_mode::Stockpiles)
|
|
|
|
{
|
|
|
|
int32_t x, y, z;
|
|
|
|
if (Gui::getDesignationCoords(x, y, z))
|
2012-11-23 23:48:26 -07:00
|
|
|
{
|
2018-05-24 07:07:12 -06:00
|
|
|
auto dX = abs(x - mpos.x);
|
|
|
|
if (dX > 30)
|
|
|
|
return false;
|
2014-05-04 03:55:58 -06:00
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
auto dY = abs(y - mpos.y);
|
|
|
|
if (dY > 30)
|
|
|
|
return false;
|
2012-11-23 23:48:26 -07:00
|
|
|
}
|
2018-05-24 07:07:12 -06:00
|
|
|
}
|
2014-05-04 03:55:58 -06:00
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
if (!designationMode)
|
|
|
|
{
|
|
|
|
Gui::resetDwarfmodeView();
|
2014-05-04 03:55:58 -06:00
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
if (key == interface_key::NONE)
|
|
|
|
key = get_default_query_mode(mpos);
|
2014-05-04 03:55:58 -06:00
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
sendKey(key);
|
|
|
|
}
|
2014-05-04 03:55:58 -06:00
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
if (!skipRefresh)
|
|
|
|
{
|
|
|
|
// Force UI refresh
|
|
|
|
moveCursor(mpos, true);
|
|
|
|
}
|
2014-05-04 03:55:58 -06:00
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
if (designationMode)
|
|
|
|
sendKey(key);
|
2014-05-04 03:55:58 -06:00
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool handleRight(df::coord &mpos, int32_t mx, int32_t my)
|
|
|
|
{
|
|
|
|
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 ||
|
2018-05-24 18:43:30 -06:00
|
|
|
ui->main.mode == ViewUnits || ui->main.mode == LookAround) ||
|
2018-05-24 07:07:12 -06:00
|
|
|
(isInTrackableMode() && tracking_enabled))
|
|
|
|
{
|
|
|
|
sendKey(df::interface_key::LEAVESCREEN);
|
2014-05-04 03:55:58 -06:00
|
|
|
}
|
2018-05-24 07:07:12 -06:00
|
|
|
else
|
2014-05-04 03:55:58 -06:00
|
|
|
{
|
2018-05-24 07:07:12 -06:00
|
|
|
auto dims = Gui::getDwarfmodeViewDims();
|
|
|
|
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);
|
|
|
|
|
2019-05-16 21:30:03 -06:00
|
|
|
if (mx > dims.map_x2 - scroll_trigger_x)
|
2018-05-24 07:07:12 -06:00
|
|
|
sendKey(interface_key::CURSOR_RIGHT_FAST);
|
|
|
|
|
|
|
|
if (my < scroll_trigger_y)
|
|
|
|
sendKey(interface_key::CURSOR_UP_FAST);
|
|
|
|
|
2019-05-16 21:30:03 -06:00
|
|
|
if (my > dims.map_y2 - scroll_trigger_y)
|
2018-05-24 07:07:12 -06:00
|
|
|
sendKey(interface_key::CURSOR_DOWN_FAST);
|
2018-05-24 18:43:30 -06:00
|
|
|
}
|
2014-05-04 03:55:58 -06:00
|
|
|
|
2018-05-24 18:43:30 -06:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-04 03:55:58 -06:00
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
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;
|
|
|
|
|
|
|
|
if (enabler->mouse_lbut)
|
|
|
|
{
|
|
|
|
if (drag_mode == Left)
|
2014-05-04 03:55:58 -06:00
|
|
|
{
|
2018-05-24 07:07:12 -06:00
|
|
|
awaiting_lbut_up = true;
|
|
|
|
enabler->mouse_lbut = false;
|
2018-05-24 18:43:30 -06:00
|
|
|
last_move_pos = mpos;
|
2014-05-04 03:55:58 -06:00
|
|
|
}
|
|
|
|
else
|
2018-05-24 07:07:12 -06:00
|
|
|
return handleLeft(mpos, mx, my);
|
|
|
|
}
|
|
|
|
else if (enabler->mouse_rbut)
|
|
|
|
{
|
|
|
|
if (drag_mode == Right)
|
2014-05-04 03:55:58 -06:00
|
|
|
{
|
2018-05-24 07:07:12 -06:00
|
|
|
awaiting_rbut_up = true;
|
|
|
|
enabler->mouse_rbut = false;
|
2018-05-24 18:43:30 -06:00
|
|
|
last_move_pos = mpos;
|
2014-05-04 03:55:58 -06:00
|
|
|
}
|
2018-05-24 07:07:12 -06:00
|
|
|
else if (rbutton_enabled)
|
|
|
|
return handleRight(mpos, mx, my);
|
2014-05-04 03:55:58 -06:00
|
|
|
}
|
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;
|
|
|
|
|
2022-09-19 12:13:47 -06:00
|
|
|
DEBUG(log).print("moving cursor to %d, %d, %d\n", x, y, z);
|
2014-05-04 03:55:58 -06:00
|
|
|
Gui::setCursorCoords(mpos.x, mpos.y, mpos.z);
|
2017-06-22 21:56:35 -06:00
|
|
|
Gui::refreshSidebar();
|
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;
|
2018-05-24 18:43:30 -06:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
auto dims = Gui::getDwarfmodeViewDims();
|
|
|
|
|
|
|
|
int32_t mx, my;
|
|
|
|
auto mpos = get_mouse_pos(mx, my);
|
|
|
|
bool mpos_valid = mpos.x != -30000 && mpos.y != -30000 && mpos.z != -30000;
|
|
|
|
|
2014-06-01 04:13:36 -06:00
|
|
|
// Check if in lever binding mode
|
2018-05-24 18:43:30 -06:00
|
|
|
if (Gui::getFocusString(Core::getTopViewscreen()) ==
|
2014-06-01 04:13:36 -06:00
|
|
|
"dwarfmode/QueryBuilding/Some/Lever/AddJob")
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
if (awaiting_lbut_up && !enabler->mouse_lbut_down)
|
|
|
|
{
|
|
|
|
awaiting_lbut_up = false;
|
|
|
|
handleLeft(mpos, mx, my);
|
2018-05-24 18:43:30 -06:00
|
|
|
}
|
2018-05-24 07:07:12 -06:00
|
|
|
|
|
|
|
if (awaiting_rbut_up && !enabler->mouse_rbut_down)
|
|
|
|
{
|
2018-05-24 18:43:30 -06:00
|
|
|
awaiting_rbut_up = false;
|
2018-05-24 07:07:12 -06:00
|
|
|
if (rbutton_enabled)
|
|
|
|
handleRight(mpos, mx, my);
|
2018-05-24 18:43:30 -06:00
|
|
|
}
|
2018-05-24 07:07:12 -06:00
|
|
|
|
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
|
|
|
{
|
2018-05-24 07:07:12 -06:00
|
|
|
awaiting_lbut_up = false;
|
|
|
|
awaiting_rbut_up = false;
|
|
|
|
|
|
|
|
if ((enabler->mouse_lbut_down && drag_mode == Left) || (enabler->mouse_rbut_down && drag_mode == Right))
|
|
|
|
{
|
|
|
|
int newx = (*df::global::window_x) - (mpos.x - last_move_pos.x);
|
|
|
|
int newy = (*df::global::window_y) - (mpos.y - last_move_pos.y);
|
|
|
|
|
|
|
|
newx = std::max(0, std::min(newx, world->map.x_count - dims.map_x2+1));
|
|
|
|
newy = std::max(0, std::min(newy, world->map.y_count - dims.map_y2+1));
|
|
|
|
|
|
|
|
(*df::global::window_x) = newx;
|
|
|
|
(*df::global::window_y) = newy;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-05-16 21:22:11 -06:00
|
|
|
if (mx > dims.map_x2 - scroll_buffer)
|
2014-05-04 03:55:58 -06:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2019-05-16 21:22:11 -06:00
|
|
|
if (my > dims.map_y2 - scroll_buffer)
|
2014-05-04 03:55:58 -06:00
|
|
|
{
|
|
|
|
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;
|
2018-05-24 18:43:30 -06: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
|
|
|
|
2022-09-19 12:13:47 -06:00
|
|
|
Screen::paintTile(Screen::Pen('X', color), mx, my, 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 ||
|
2019-05-16 21:30:03 -06:00
|
|
|
mx > dims.map_x2 - scroll_buffer ||
|
2014-05-04 03:55:58 -06:00
|
|
|
my < scroll_buffer ||
|
2019-05-16 21:30:03 -06:00
|
|
|
my > dims.map_y2 - scroll_buffer))
|
2014-05-04 03:55:58 -06:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
// Don't change levels
|
|
|
|
if (mpos.z != *df::global::window_z)
|
|
|
|
return;
|
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
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;
|
|
|
|
|
2018-05-24 07:07:12 -06:00
|
|
|
if (mpos.z != *df::global::window_z)
|
|
|
|
{
|
|
|
|
int y = gps->dimy - 2;
|
|
|
|
char buf[6];
|
|
|
|
sprintf(buf, "@%d", mpos.z - *df::global::window_z);
|
|
|
|
OutputString(COLOR_GREY, disp_x, y, buf, true, left_margin);
|
2018-05-24 18:43:30 -06:00
|
|
|
}
|
2018-05-24 07:07:12 -06:00
|
|
|
|
2014-05-04 03:55:58 -06:00
|
|
|
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");
|
2019-05-13 17:21:57 -06:00
|
|
|
out << "mousequery: plugin " << (plugin_enabled ? "enabled" : "disabled") << endl;
|
2014-05-04 03:55:58 -06:00
|
|
|
}
|
|
|
|
else if (cmd[0] == 'r')
|
|
|
|
{
|
|
|
|
rbutton_enabled = (state == "enable");
|
2019-05-13 17:21:57 -06:00
|
|
|
out << "mousequery: rbutton " << (rbutton_enabled ? "enabled" : "disabled") << endl;
|
2014-05-04 03:55:58 -06:00
|
|
|
}
|
|
|
|
else if (cmd[0] == 't')
|
|
|
|
{
|
|
|
|
tracking_enabled = (state == "enable");
|
2019-05-13 17:21:57 -06:00
|
|
|
if (!tracking_enabled) {
|
|
|
|
out << "mousequery: edge scrolling disabled" << endl;
|
2014-05-04 03:55:58 -06:00
|
|
|
active_scrolling = false;
|
2019-05-13 17:21:57 -06:00
|
|
|
}
|
|
|
|
out << "mousequery: tracking " << (tracking_enabled ? "enabled" : "disabled") << endl;
|
2014-05-04 03:55:58 -06:00
|
|
|
}
|
|
|
|
else if (cmd[0] == 'e')
|
|
|
|
{
|
|
|
|
active_scrolling = (state == "enable");
|
2019-05-13 17:21:57 -06:00
|
|
|
if (active_scrolling) {
|
|
|
|
out << "mousequery: tracking enabled" << endl;
|
2014-05-04 03:55:58 -06:00
|
|
|
tracking_enabled = true;
|
2019-05-13 17:21:57 -06:00
|
|
|
}
|
|
|
|
out << "mousequery: edge scrolling " << (active_scrolling ? "enabled" : "disabled") << endl;
|
2014-05-04 03:55:58 -06:00
|
|
|
}
|
|
|
|
else if (cmd[0] == 'l')
|
|
|
|
{
|
|
|
|
live_view = (state == "enable");
|
2019-05-13 17:21:57 -06:00
|
|
|
out << "mousequery: live view " << (live_view ? "enabled" : "disabled") << endl;
|
2014-05-04 03:55:58 -06:00
|
|
|
}
|
2018-05-24 07:07:12 -06:00
|
|
|
else if (cmd == "drag")
|
|
|
|
{
|
|
|
|
if (state == "left")
|
|
|
|
drag_mode = Left;
|
|
|
|
else if (state == "right")
|
|
|
|
drag_mode = Right;
|
|
|
|
else if (state == "disable")
|
|
|
|
drag_mode = None;
|
2018-05-24 18:43:30 -06:00
|
|
|
}
|
2014-05-04 03:55:58 -06:00
|
|
|
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(
|
2022-07-28 04:22:32 -06:00
|
|
|
"mousequery",
|
|
|
|
"Add mouse functionality to Dwarf Fortress.",
|
|
|
|
mousequery_cmd));
|
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;
|
|
|
|
}
|