2010-04-02 19:52:46 -06:00
|
|
|
/*
|
2011-06-16 15:53:39 -06:00
|
|
|
https://github.com/peterix/dfhack
|
2012-09-29 20:03:37 -06:00
|
|
|
Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com)
|
2010-04-02 19:52:46 -06:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
*/
|
|
|
|
|
2011-06-16 15:53:39 -06:00
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
#include "Internal.h"
|
2011-04-10 02:19:15 -06:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
using namespace std;
|
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "modules/Gui.h"
|
|
|
|
#include "MemAccess.h"
|
|
|
|
#include "VersionInfo.h"
|
|
|
|
#include "Types.h"
|
|
|
|
#include "Error.h"
|
2011-03-18 01:53:59 -06:00
|
|
|
#include "ModuleFactory.h"
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
2011-12-31 05:09:12 -07:00
|
|
|
#include "PluginManager.h"
|
2012-01-14 08:31:43 -07:00
|
|
|
#include "MiscUtils.h"
|
2010-04-02 19:52:46 -06:00
|
|
|
using namespace DFHack;
|
|
|
|
|
2012-05-21 12:29:03 -06:00
|
|
|
#include "modules/Job.h"
|
2012-08-18 23:31:09 -06:00
|
|
|
#include "modules/Screen.h"
|
2012-09-02 04:10:58 -06:00
|
|
|
#include "modules/Maps.h"
|
2012-05-21 12:29:03 -06:00
|
|
|
|
2011-12-31 05:09:12 -07:00
|
|
|
#include "DataDefs.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
|
|
|
|
#include "df/announcement_flags.h"
|
|
|
|
#include "df/assign_trade_status.h"
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
#include "df/building_cagest.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/building_civzonest.h"
|
|
|
|
#include "df/building_furnacest.h"
|
|
|
|
#include "df/building_trapst.h"
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
#include "df/building_type.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/building_workshopst.h"
|
2017-12-03 19:05:08 -07:00
|
|
|
#include "df/d_init.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/game_mode.h"
|
|
|
|
#include "df/general_ref.h"
|
2012-02-20 03:42:40 -07:00
|
|
|
#include "df/global_objects.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/graphic.h"
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
#include "df/historical_figure.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/interfacest.h"
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
#include "df/item_corpsepiecest.h"
|
|
|
|
#include "df/item_corpsest.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/job.h"
|
|
|
|
#include "df/layer_object_listst.h"
|
|
|
|
#include "df/occupation.h"
|
|
|
|
#include "df/plant.h"
|
|
|
|
#include "df/popup_message.h"
|
|
|
|
#include "df/report.h"
|
|
|
|
#include "df/route_stockpile_link.h"
|
|
|
|
#include "df/stop_depart_condition.h"
|
|
|
|
#include "df/ui_advmode.h"
|
|
|
|
#include "df/ui_build_selector.h"
|
|
|
|
#include "df/ui_look_list.h"
|
|
|
|
#include "df/ui_sidebar_menus.h"
|
|
|
|
#include "df/ui_unit_view_mode.h"
|
|
|
|
#include "df/unit.h"
|
|
|
|
#include "df/unit_inventory_item.h"
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
#include "df/viewscreen_announcelistst.h"
|
2017-12-28 14:19:45 -07:00
|
|
|
#include "df/viewscreen_assign_display_itemst.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/viewscreen_buildinglistst.h"
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
#include "df/viewscreen_customize_unitst.h"
|
2012-04-07 09:08:30 -06:00
|
|
|
#include "df/viewscreen_dungeon_monsterstatusst.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/viewscreen_dungeonmodest.h"
|
|
|
|
#include "df/viewscreen_dwarfmodest.h"
|
|
|
|
#include "df/viewscreen_itemst.h"
|
2012-02-19 12:27:44 -07:00
|
|
|
#include "df/viewscreen_joblistst.h"
|
2017-05-26 22:56:40 -06:00
|
|
|
#include "df/viewscreen_jobmanagementst.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/viewscreen_jobst.h"
|
2012-09-17 02:47:18 -06:00
|
|
|
#include "df/viewscreen_layer.h"
|
2012-05-18 07:54:05 -06:00
|
|
|
#include "df/viewscreen_layer_assigntradest.h"
|
2012-05-19 09:50:36 -06:00
|
|
|
#include "df/viewscreen_layer_militaryst.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/viewscreen_layer_noblelistst.h"
|
|
|
|
#include "df/viewscreen_layer_overall_healthst.h"
|
2012-06-06 08:54:06 -06:00
|
|
|
#include "df/viewscreen_layer_stockpilest.h"
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
#include "df/viewscreen_layer_unit_healthst.h"
|
2017-06-10 17:06:43 -06:00
|
|
|
#include "df/viewscreen_layer_unit_relationshipst.h"
|
2015-12-25 09:09:05 -07:00
|
|
|
#include "df/viewscreen_locationsst.h"
|
2012-04-26 01:05:35 -06:00
|
|
|
#include "df/viewscreen_petst.h"
|
2012-05-21 12:29:03 -06:00
|
|
|
#include "df/viewscreen_storesst.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/viewscreen_textviewerst.h"
|
|
|
|
#include "df/viewscreen_tradegoodsst.h"
|
|
|
|
#include "df/viewscreen_unitlistst.h"
|
|
|
|
#include "df/viewscreen_unitst.h"
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
#include "df/viewscreen_reportlistst.h"
|
2017-05-26 22:56:40 -06:00
|
|
|
#include "df/viewscreen_workquota_conditionst.h"
|
2016-05-11 15:52:56 -06:00
|
|
|
#include "df/viewscreen_workshop_profilest.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/world.h"
|
2012-01-07 08:21:07 -07:00
|
|
|
|
|
|
|
using namespace df::enums;
|
2018-05-09 08:23:05 -06:00
|
|
|
|
|
|
|
using df::global::gamemode;
|
|
|
|
using df::global::gps;
|
2012-01-24 21:18:21 -07:00
|
|
|
using df::global::gview;
|
|
|
|
using df::global::init;
|
2012-09-02 04:10:58 -06:00
|
|
|
using df::global::selection_rect;
|
2018-05-09 08:23:05 -06:00
|
|
|
using df::global::ui;
|
2012-09-02 04:10:58 -06:00
|
|
|
using df::global::ui_menu_width;
|
2018-05-09 08:23:05 -06:00
|
|
|
using df::global::ui_sidebar_menus;
|
|
|
|
using df::global::world;
|
2011-12-31 02:25:46 -07:00
|
|
|
|
2012-09-17 02:47:18 -06:00
|
|
|
static df::layer_object_listst *getLayerList(df::viewscreen_layer *layer, int idx)
|
2012-04-26 01:05:35 -06:00
|
|
|
{
|
|
|
|
return virtual_cast<df::layer_object_listst>(vector_get(layer->layer_objects,idx));
|
|
|
|
}
|
|
|
|
|
2012-05-19 09:50:36 -06:00
|
|
|
static std::string getNameChunk(virtual_identity *id, int start, int end)
|
|
|
|
{
|
|
|
|
if (!id)
|
|
|
|
return "UNKNOWN";
|
|
|
|
const char *name = id->getName();
|
|
|
|
int len = strlen(name);
|
|
|
|
if (len > start + end)
|
|
|
|
return std::string(name+start, len-start-end);
|
|
|
|
else
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Classifying focus context by means of a string path.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef void (*getFocusStringHandler)(std::string &str, df::viewscreen *screen);
|
|
|
|
static std::map<virtual_identity*, getFocusStringHandler> getFocusStringHandlers;
|
|
|
|
|
|
|
|
#define VIEWSCREEN(name) df::viewscreen_##name##st
|
|
|
|
#define DEFINE_GET_FOCUS_STRING_HANDLER(screen_type) \
|
|
|
|
static void getFocusString_##screen_type(std::string &focus, VIEWSCREEN(screen_type) *screen);\
|
|
|
|
DFHACK_STATIC_ADD_TO_MAP(\
|
|
|
|
&getFocusStringHandlers, &VIEWSCREEN(screen_type)::_identity, \
|
|
|
|
(getFocusStringHandler)getFocusString_##screen_type \
|
|
|
|
); \
|
|
|
|
static void getFocusString_##screen_type(std::string &focus, VIEWSCREEN(screen_type) *screen)
|
|
|
|
|
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode)
|
|
|
|
{
|
|
|
|
using namespace df::enums::ui_sidebar_mode;
|
|
|
|
|
|
|
|
using df::global::ui_workshop_in_add;
|
|
|
|
using df::global::ui_build_selector;
|
|
|
|
using df::global::ui_selected_unit;
|
|
|
|
using df::global::ui_look_list;
|
|
|
|
using df::global::ui_look_cursor;
|
|
|
|
using df::global::ui_building_item_cursor;
|
|
|
|
using df::global::ui_building_assign_type;
|
|
|
|
using df::global::ui_building_assign_is_marked;
|
|
|
|
using df::global::ui_building_assign_units;
|
|
|
|
using df::global::ui_building_assign_items;
|
|
|
|
using df::global::ui_building_in_assign;
|
|
|
|
|
|
|
|
focus += "/" + enum_item_key(ui->main.mode);
|
|
|
|
|
|
|
|
switch (ui->main.mode)
|
|
|
|
{
|
|
|
|
case QueryBuilding:
|
|
|
|
if (df::building *selected = world->selected_building)
|
|
|
|
{
|
|
|
|
if (!selected->jobs.empty() &&
|
|
|
|
selected->jobs[0]->job_type == job_type::DestroyBuilding)
|
|
|
|
{
|
|
|
|
focus += "/Destroying";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
focus += "/Some";
|
|
|
|
|
|
|
|
virtual_identity *id = virtual_identity::get(selected);
|
|
|
|
|
|
|
|
bool jobs = false;
|
|
|
|
|
|
|
|
if (id == &df::building_workshopst::_identity ||
|
|
|
|
id == &df::building_furnacest::_identity)
|
|
|
|
{
|
|
|
|
focus += "/Workshop";
|
|
|
|
jobs = true;
|
|
|
|
}
|
|
|
|
else if (id == &df::building_trapst::_identity)
|
|
|
|
{
|
|
|
|
auto trap = (df::building_trapst*)selected;
|
2012-09-08 03:46:02 -06:00
|
|
|
focus += "/" + enum_item_key(trap->trap_type);
|
|
|
|
if (trap->trap_type == trap_type::Lever)
|
2012-05-19 09:50:36 -06:00
|
|
|
jobs = true;
|
|
|
|
}
|
|
|
|
else if (ui_building_in_assign && *ui_building_in_assign &&
|
|
|
|
ui_building_assign_type && ui_building_assign_units &&
|
|
|
|
ui_building_assign_type->size() == ui_building_assign_units->size())
|
|
|
|
{
|
|
|
|
focus += "/Assign";
|
|
|
|
if (ui_building_item_cursor)
|
|
|
|
{
|
|
|
|
auto unit = vector_get(*ui_building_assign_units, *ui_building_item_cursor);
|
|
|
|
focus += unit ? "/Unit" : "/None";
|
|
|
|
}
|
|
|
|
}
|
2012-09-08 03:46:02 -06:00
|
|
|
else
|
|
|
|
focus += "/" + enum_item_key(selected->getType());
|
2012-05-19 09:50:36 -06:00
|
|
|
|
|
|
|
if (jobs)
|
|
|
|
{
|
|
|
|
if (ui_workshop_in_add && *ui_workshop_in_add)
|
|
|
|
focus += "/AddJob";
|
|
|
|
else if (!selected->jobs.empty())
|
|
|
|
focus += "/Job";
|
|
|
|
else
|
|
|
|
focus += "/Empty";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
focus += "/None";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Build:
|
|
|
|
if (ui_build_selector)
|
|
|
|
{
|
|
|
|
// Not selecting, or no choices?
|
|
|
|
if (ui_build_selector->building_type < 0)
|
|
|
|
focus += "/Type";
|
|
|
|
else if (ui_build_selector->stage != 2)
|
2012-09-06 02:37:29 -06:00
|
|
|
{
|
|
|
|
if (ui_build_selector->stage != 1)
|
|
|
|
focus += "/NoMaterials";
|
|
|
|
else
|
|
|
|
focus += "/Position";
|
|
|
|
|
|
|
|
focus += "/" + enum_item_key(ui_build_selector->building_type);
|
|
|
|
}
|
2012-05-19 09:50:36 -06:00
|
|
|
else
|
|
|
|
{
|
|
|
|
focus += "/Material";
|
|
|
|
if (ui_build_selector->is_grouped)
|
|
|
|
focus += "/Groups";
|
|
|
|
else
|
|
|
|
focus += "/Items";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ViewUnits:
|
|
|
|
if (ui_selected_unit)
|
|
|
|
{
|
|
|
|
if (auto unit = vector_get(world->units.active, *ui_selected_unit))
|
|
|
|
{
|
|
|
|
focus += "/Some";
|
|
|
|
|
|
|
|
using df::global::ui_unit_view_mode;
|
|
|
|
|
|
|
|
if (ui_unit_view_mode)
|
|
|
|
focus += "/" + enum_item_key(ui_unit_view_mode->value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
focus += "/None";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LookAround:
|
|
|
|
if (ui_look_list && ui_look_cursor)
|
|
|
|
{
|
|
|
|
auto item = vector_get(ui_look_list->items, *ui_look_cursor);
|
|
|
|
if (item)
|
|
|
|
focus += "/" + enum_item_key(item->type);
|
|
|
|
else
|
|
|
|
focus += "/None";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BuildingItems:
|
|
|
|
if (VIRTUAL_CAST_VAR(selected, df::building_actual, world->selected_building))
|
|
|
|
{
|
|
|
|
if (selected->contained_items.empty())
|
|
|
|
focus += "/Some/Empty";
|
|
|
|
else
|
|
|
|
focus += "/Some/Item";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
focus += "/None";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZonesPenInfo:
|
|
|
|
if (ui_building_assign_type && ui_building_assign_units &&
|
|
|
|
ui_building_assign_is_marked && ui_building_assign_items &&
|
|
|
|
ui_building_assign_type->size() == ui_building_assign_units->size())
|
|
|
|
{
|
|
|
|
focus += "/Assign";
|
|
|
|
if (ui_building_item_cursor)
|
|
|
|
{
|
|
|
|
if (vector_get(*ui_building_assign_units, *ui_building_item_cursor))
|
|
|
|
focus += "/Unit";
|
|
|
|
else if (vector_get(*ui_building_assign_items, *ui_building_item_cursor))
|
|
|
|
focus += "/Vermin";
|
|
|
|
else
|
|
|
|
focus += "/None";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Burrows:
|
2012-06-06 08:54:06 -06:00
|
|
|
if (ui->burrows.in_confirm_delete)
|
|
|
|
focus += "/ConfirmDelete";
|
|
|
|
else if (ui->burrows.in_add_units_mode)
|
2012-05-19 09:50:36 -06:00
|
|
|
focus += "/AddUnits";
|
|
|
|
else if (ui->burrows.in_edit_name_mode)
|
|
|
|
focus += "/EditName";
|
|
|
|
else if (ui->burrows.in_define_mode)
|
|
|
|
focus += "/Define";
|
|
|
|
else
|
|
|
|
focus += "/List";
|
|
|
|
break;
|
|
|
|
|
2012-10-11 02:36:17 -06:00
|
|
|
case Hauling:
|
|
|
|
if (ui->hauling.in_assign_vehicle)
|
|
|
|
{
|
|
|
|
auto vehicle = vector_get(ui->hauling.vehicles, ui->hauling.cursor_vehicle);
|
|
|
|
focus += "/AssignVehicle/" + std::string(vehicle ? "Some" : "None");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int idx = ui->hauling.cursor_top;
|
|
|
|
auto route = vector_get(ui->hauling.view_routes, idx);
|
|
|
|
auto stop = vector_get(ui->hauling.view_stops, idx);
|
|
|
|
std::string tag = stop ? "Stop" : (route ? "Route" : "None");
|
|
|
|
|
|
|
|
if (ui->hauling.in_name)
|
|
|
|
focus += "/Rename/" + tag;
|
|
|
|
else if (ui->hauling.in_stop)
|
|
|
|
{
|
|
|
|
int sidx = ui->hauling.cursor_stop;
|
|
|
|
auto cond = vector_get(ui->hauling.stop_conditions, sidx);
|
|
|
|
auto link = vector_get(ui->hauling.stop_links, sidx);
|
|
|
|
|
|
|
|
focus += "/DefineStop";
|
|
|
|
|
|
|
|
if (cond)
|
|
|
|
focus += "/Cond/" + enum_item_key(cond->mode);
|
|
|
|
else if (link)
|
|
|
|
{
|
|
|
|
focus += "/Link/";
|
|
|
|
if (link->mode.bits.give) focus += "Give";
|
|
|
|
if (link->mode.bits.take) focus += "Take";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
focus += "/None";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
focus += "/Select/" + tag;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-05-19 09:50:36 -06:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-06 08:54:06 -06:00
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(dungeonmode)
|
|
|
|
{
|
|
|
|
using df::global::ui_advmode;
|
|
|
|
|
|
|
|
if (!ui_advmode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
focus += "/" + enum_item_key(ui_advmode->menu);
|
|
|
|
}
|
|
|
|
|
2012-05-19 09:50:36 -06:00
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(unitlist)
|
|
|
|
{
|
|
|
|
focus += "/" + enum_item_key(screen->page);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(layer_military)
|
|
|
|
{
|
|
|
|
auto list1 = getLayerList(screen, 0);
|
|
|
|
auto list2 = getLayerList(screen, 1);
|
|
|
|
auto list3 = getLayerList(screen, 2);
|
|
|
|
if (!list1 || !list2 || !list3) return;
|
|
|
|
|
|
|
|
focus += "/" + enum_item_key(screen->page);
|
|
|
|
|
|
|
|
int cur_list;
|
2012-09-18 03:11:11 -06:00
|
|
|
if (list1->active) cur_list = 0;
|
|
|
|
else if (list2->active) cur_list = 1;
|
|
|
|
else if (list3->active) cur_list = 2;
|
2012-05-19 09:50:36 -06:00
|
|
|
else return;
|
|
|
|
|
|
|
|
switch (screen->page)
|
|
|
|
{
|
|
|
|
case df::viewscreen_layer_militaryst::Positions:
|
|
|
|
{
|
|
|
|
static const char *lists[] = { "/Squads", "/Positions", "/Candidates" };
|
|
|
|
focus += lists[cur_list];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-09-29 07:21:49 -06:00
|
|
|
case df::viewscreen_layer_militaryst::Equip:
|
|
|
|
{
|
|
|
|
focus += "/" + enum_item_key(screen->equip.mode);
|
|
|
|
|
|
|
|
switch (screen->equip.mode)
|
|
|
|
{
|
|
|
|
case df::viewscreen_layer_militaryst::T_equip::Customize:
|
|
|
|
{
|
|
|
|
if (screen->equip.edit_mode < 0)
|
|
|
|
focus += "/View";
|
|
|
|
else
|
|
|
|
focus += "/" + enum_item_key(screen->equip.edit_mode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case df::viewscreen_layer_militaryst::T_equip::Uniform:
|
|
|
|
break;
|
|
|
|
case df::viewscreen_layer_militaryst::T_equip::Priority:
|
|
|
|
{
|
|
|
|
if (screen->equip.prio_in_move >= 0)
|
|
|
|
focus += "/Move";
|
|
|
|
else
|
|
|
|
focus += "/View";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *lists[] = { "/Squads", "/Positions", "/Choices" };
|
|
|
|
focus += lists[cur_list];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-05-19 09:50:36 -06:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-14 09:43:37 -06:00
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(workshop_profile)
|
|
|
|
{
|
|
|
|
typedef df::viewscreen_workshop_profilest::T_tab T_tab;
|
|
|
|
switch(screen->tab)
|
|
|
|
{
|
|
|
|
case T_tab::Workers:
|
|
|
|
focus += "/Unit";
|
|
|
|
break;
|
|
|
|
case T_tab::Orders:
|
|
|
|
focus += "/Orders";
|
|
|
|
break;
|
|
|
|
case T_tab::Restrictions:
|
|
|
|
focus += "/Restrictions";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-05-19 09:50:36 -06:00
|
|
|
|
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(layer_noblelist)
|
|
|
|
{
|
|
|
|
auto list1 = getLayerList(screen, 0);
|
|
|
|
auto list2 = getLayerList(screen, 1);
|
|
|
|
if (!list1 || !list2) return;
|
|
|
|
|
|
|
|
focus += "/" + enum_item_key(screen->mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(pet)
|
|
|
|
{
|
|
|
|
focus += "/" + enum_item_key(screen->mode);
|
|
|
|
|
|
|
|
switch (screen->mode)
|
|
|
|
{
|
|
|
|
case df::viewscreen_petst::List:
|
|
|
|
focus += vector_get(screen->is_vermin, screen->cursor) ? "/Vermin" : "/Unit";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case df::viewscreen_petst::SelectTrainer:
|
|
|
|
if (vector_get(screen->trainer_unit, screen->trainer_cursor))
|
|
|
|
focus += "/Unit";
|
|
|
|
break;
|
2012-05-21 12:29:03 -06:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2012-05-19 09:50:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(layer_overall_health)
|
|
|
|
{
|
|
|
|
auto list1 = getLayerList(screen, 0);
|
|
|
|
if (!list1) return;
|
|
|
|
|
|
|
|
focus += "/Units";
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(tradegoods)
|
|
|
|
{
|
|
|
|
if (!screen->has_traders || screen->is_unloading)
|
|
|
|
focus += "/NoTraders";
|
|
|
|
else if (screen->in_edit_count)
|
|
|
|
focus += "/EditCount";
|
|
|
|
else
|
|
|
|
focus += (screen->in_right_pane ? "/Items/Broker" : "/Items/Trader");
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(layer_assigntrade)
|
|
|
|
{
|
|
|
|
auto list1 = getLayerList(screen, 0);
|
|
|
|
auto list2 = getLayerList(screen, 1);
|
|
|
|
if (!list1 || !list2) return;
|
|
|
|
|
|
|
|
int list_idx = vector_get(screen->visible_lists, list1->cursor, (int16_t)-1);
|
|
|
|
unsigned num_lists = sizeof(screen->lists)/sizeof(screen->lists[0]);
|
|
|
|
if (unsigned(list_idx) >= num_lists)
|
|
|
|
return;
|
|
|
|
|
2012-09-18 03:11:11 -06:00
|
|
|
if (list1->active)
|
2012-05-19 09:50:36 -06:00
|
|
|
focus += "/Groups";
|
|
|
|
else
|
|
|
|
focus += "/Items";
|
|
|
|
}
|
|
|
|
|
2012-05-21 11:30:53 -06:00
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(stores)
|
|
|
|
{
|
|
|
|
if (!screen->in_right_list)
|
|
|
|
focus += "/Categories";
|
|
|
|
else if (screen->in_group_mode)
|
|
|
|
focus += "/Groups";
|
|
|
|
else
|
|
|
|
focus += "/Items";
|
|
|
|
}
|
|
|
|
|
2012-06-06 08:54:06 -06:00
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(layer_stockpile)
|
|
|
|
{
|
|
|
|
auto list1 = getLayerList(screen, 0);
|
|
|
|
auto list2 = getLayerList(screen, 1);
|
|
|
|
auto list3 = getLayerList(screen, 2);
|
|
|
|
if (!list1 || !list2 || !list3 || !screen->settings) return;
|
|
|
|
|
|
|
|
auto group = screen->cur_group;
|
|
|
|
if (group != vector_get(screen->group_ids, list1->cursor))
|
|
|
|
return;
|
|
|
|
|
|
|
|
focus += "/" + enum_item_key(group);
|
|
|
|
|
|
|
|
auto bits = vector_get(screen->group_bits, list1->cursor);
|
|
|
|
if (bits.whole && !(bits.whole & screen->settings->flags.whole))
|
|
|
|
{
|
|
|
|
focus += "/Off";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
focus += "/On";
|
|
|
|
|
2012-09-18 03:11:11 -06:00
|
|
|
if (list2->active || list3->active || screen->list_ids.empty()) {
|
2012-06-06 08:54:06 -06:00
|
|
|
focus += "/" + enum_item_key(screen->cur_list);
|
|
|
|
|
2012-09-18 03:11:11 -06:00
|
|
|
if (list3->active)
|
2012-06-06 08:54:06 -06:00
|
|
|
focus += (screen->item_names.empty() ? "/None" : "/Item");
|
|
|
|
}
|
|
|
|
}
|
2012-05-21 11:30:53 -06:00
|
|
|
|
2015-12-25 09:09:05 -07:00
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(locations)
|
|
|
|
{
|
|
|
|
focus += "/" + enum_item_key(screen->menu);
|
|
|
|
}
|
|
|
|
|
2017-05-26 22:56:40 -06:00
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(jobmanagement)
|
|
|
|
{
|
|
|
|
focus += (screen->in_max_workshops ? "/MaxWorkshops" : "/Main");
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(workquota_condition)
|
|
|
|
{
|
|
|
|
focus += "/" + enum_item_key(screen->mode);
|
|
|
|
if (screen->item_count_edit)
|
|
|
|
focus += "/EditCount";
|
|
|
|
}
|
|
|
|
|
2012-05-19 09:50:36 -06:00
|
|
|
std::string Gui::getFocusString(df::viewscreen *top)
|
|
|
|
{
|
2012-05-19 11:31:42 -06:00
|
|
|
if (!top)
|
|
|
|
return "";
|
2012-05-19 09:50:36 -06:00
|
|
|
|
2020-02-07 15:00:14 -07:00
|
|
|
if (dfhack_viewscreen::is_instance(top))
|
|
|
|
{
|
|
|
|
auto name = static_cast<dfhack_viewscreen*>(top)->getFocusString();
|
|
|
|
return name.empty() ? "dfhack" : "dfhack/"+name;
|
|
|
|
}
|
|
|
|
else if (virtual_identity *id = virtual_identity::get(top))
|
2012-05-19 11:31:42 -06:00
|
|
|
{
|
|
|
|
std::string name = getNameChunk(id, 11, 2);
|
|
|
|
|
|
|
|
auto handler = map_find(getFocusStringHandlers, id);
|
|
|
|
if (handler)
|
|
|
|
handler(name, top);
|
2012-05-19 09:50:36 -06:00
|
|
|
|
2012-05-19 11:31:42 -06:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Core &core = Core::getInstance();
|
|
|
|
std::string name = core.p->readClassName(*(void**)top);
|
|
|
|
return name.substr(11, name.size()-11-2);
|
|
|
|
}
|
2012-05-19 09:50:36 -06:00
|
|
|
}
|
|
|
|
|
2011-12-31 02:25:46 -07:00
|
|
|
// Predefined common guard functions
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
bool Gui::default_hotkey(df::viewscreen *top)
|
2011-12-31 02:25:46 -07:00
|
|
|
{
|
|
|
|
// Default hotkey guard function
|
|
|
|
for (;top ;top = top->parent)
|
2012-03-10 04:55:42 -07:00
|
|
|
{
|
2011-12-31 02:25:46 -07:00
|
|
|
if (strict_virtual_cast<df::viewscreen_dwarfmodest>(top))
|
|
|
|
return true;
|
2012-03-10 04:55:42 -07:00
|
|
|
if (strict_virtual_cast<df::viewscreen_dungeonmodest>(top))
|
|
|
|
return true;
|
|
|
|
}
|
2011-12-31 02:25:46 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
bool Gui::dwarfmode_hotkey(df::viewscreen *top)
|
2011-12-31 02:25:46 -07:00
|
|
|
{
|
|
|
|
// Require the main dwarf mode screen
|
|
|
|
return !!strict_virtual_cast<df::viewscreen_dwarfmodest>(top);
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
bool Gui::unitjobs_hotkey(df::viewscreen *top)
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
2012-02-20 06:53:39 -07:00
|
|
|
// Require the unit or jobs list
|
|
|
|
return !!strict_virtual_cast<df::viewscreen_joblistst>(top) ||
|
|
|
|
!!strict_virtual_cast<df::viewscreen_unitlistst>(top);
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
bool Gui::item_details_hotkey(df::viewscreen *top)
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
|
|
|
// Require the main dwarf mode screen
|
|
|
|
return !!strict_virtual_cast<df::viewscreen_itemst>(top);
|
|
|
|
}
|
|
|
|
|
2021-05-15 13:05:00 -06:00
|
|
|
static bool has_cursor()
|
|
|
|
{
|
|
|
|
return df::global::cursor && df::global::cursor->x != -30000;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
bool Gui::cursor_hotkey(df::viewscreen *top)
|
2011-12-31 02:25:46 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
if (!dwarfmode_hotkey(top))
|
2011-12-31 02:25:46 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Also require the cursor.
|
2021-05-15 13:05:00 -06:00
|
|
|
if (!has_cursor())
|
2011-12-31 02:25:46 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
bool Gui::workshop_job_hotkey(df::viewscreen *top)
|
2012-01-07 08:21:07 -07:00
|
|
|
{
|
|
|
|
using namespace ui_sidebar_mode;
|
|
|
|
using df::global::ui;
|
|
|
|
using df::global::world;
|
|
|
|
using df::global::ui_workshop_in_add;
|
|
|
|
using df::global::ui_workshop_job_cursor;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
if (!dwarfmode_hotkey(top))
|
2012-01-07 08:21:07 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (ui->main.mode) {
|
|
|
|
case QueryBuilding:
|
|
|
|
{
|
|
|
|
if (!ui_workshop_job_cursor) // allow missing
|
|
|
|
return false;
|
|
|
|
|
|
|
|
df::building *selected = world->selected_building;
|
|
|
|
if (!virtual_cast<df::building_workshopst>(selected) &&
|
|
|
|
!virtual_cast<df::building_furnacest>(selected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// No jobs?
|
|
|
|
if (selected->jobs.empty() ||
|
|
|
|
selected->jobs[0]->job_type == job_type::DestroyBuilding)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Add job gui activated?
|
|
|
|
if (ui_workshop_in_add && *ui_workshop_in_add)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
bool Gui::build_selector_hotkey(df::viewscreen *top)
|
2012-01-07 08:21:07 -07:00
|
|
|
{
|
|
|
|
using namespace ui_sidebar_mode;
|
|
|
|
using df::global::ui;
|
|
|
|
using df::global::ui_build_selector;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
if (!dwarfmode_hotkey(top))
|
2012-01-07 08:21:07 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (ui->main.mode) {
|
|
|
|
case Build:
|
|
|
|
{
|
|
|
|
if (!ui_build_selector) // allow missing
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Not selecting, or no choices?
|
|
|
|
if (ui_build_selector->building_type < 0 ||
|
|
|
|
ui_build_selector->stage != 2 ||
|
|
|
|
ui_build_selector->choices.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
bool Gui::view_unit_hotkey(df::viewscreen *top)
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
|
|
|
using df::global::ui;
|
|
|
|
using df::global::world;
|
|
|
|
using df::global::ui_selected_unit;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
if (!dwarfmode_hotkey(top))
|
2012-01-14 08:31:43 -07:00
|
|
|
return false;
|
|
|
|
if (ui->main.mode != ui_sidebar_mode::ViewUnits)
|
|
|
|
return false;
|
|
|
|
if (!ui_selected_unit) // allow missing
|
|
|
|
return false;
|
|
|
|
|
2012-04-21 02:46:55 -06:00
|
|
|
return vector_get(world->units.active, *ui_selected_unit) != NULL;
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
bool Gui::unit_inventory_hotkey(df::viewscreen *top)
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
|
|
|
using df::global::ui_unit_view_mode;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
if (!view_unit_hotkey(top))
|
2012-01-14 08:31:43 -07:00
|
|
|
return false;
|
|
|
|
if (!ui_unit_view_mode)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return ui_unit_view_mode->value == df::ui_unit_view_mode::Inventory;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
df::job *Gui::getSelectedWorkshopJob(color_ostream &out, bool quiet)
|
2012-01-07 08:21:07 -07:00
|
|
|
{
|
|
|
|
using df::global::world;
|
|
|
|
using df::global::ui_workshop_job_cursor;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
if (!workshop_job_hotkey(Core::getTopViewscreen())) {
|
2012-01-07 08:21:07 -07:00
|
|
|
if (!quiet)
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Not in a workshop, or no job is highlighted.\n");
|
2012-01-07 08:21:07 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::building *selected = world->selected_building;
|
|
|
|
int idx = *ui_workshop_job_cursor;
|
|
|
|
|
2012-04-20 03:30:37 -06:00
|
|
|
if (size_t(idx) >= selected->jobs.size())
|
2012-01-07 08:21:07 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Invalid job cursor index: %d\n", idx);
|
2012-01-07 08:21:07 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return selected->jobs[idx];
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
bool Gui::any_job_hotkey(df::viewscreen *top)
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
2012-02-19 12:27:44 -07:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_joblistst, top))
|
2012-01-14 08:31:43 -07:00
|
|
|
return vector_get(screen->jobs, screen->cursor_pos) != NULL;
|
|
|
|
|
2012-02-20 06:53:39 -07:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_unitlistst, top))
|
|
|
|
return vector_get(screen->jobs[screen->page], screen->cursor_pos[screen->page]) != NULL;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
return workshop_job_hotkey(top);
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
df::job *Gui::getSelectedJob(color_ostream &out, bool quiet)
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
df::viewscreen *top = Core::getTopViewscreen();
|
2012-01-14 08:31:43 -07:00
|
|
|
|
2016-05-14 14:07:27 -06:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_jobst, top))
|
|
|
|
{
|
|
|
|
return screen->job;
|
|
|
|
}
|
2012-02-29 17:29:55 -07:00
|
|
|
if (VIRTUAL_CAST_VAR(joblist, df::viewscreen_joblistst, top))
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
2012-02-29 17:29:55 -07:00
|
|
|
df::job *job = vector_get(joblist->jobs, joblist->cursor_pos);
|
2012-01-14 08:31:43 -07:00
|
|
|
|
|
|
|
if (!job && !quiet)
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Selected unit has no job\n");
|
2012-01-14 08:31:43 -07:00
|
|
|
|
|
|
|
return job;
|
|
|
|
}
|
2012-02-29 17:29:55 -07:00
|
|
|
else if (VIRTUAL_CAST_VAR(unitlist, df::viewscreen_unitlistst, top))
|
2012-02-20 06:53:39 -07:00
|
|
|
{
|
2012-02-29 17:29:55 -07:00
|
|
|
int page = unitlist->page;
|
|
|
|
df::job *job = vector_get(unitlist->jobs[page], unitlist->cursor_pos[page]);
|
2012-02-20 06:53:39 -07:00
|
|
|
|
|
|
|
if (!job && !quiet)
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Selected unit has no job\n");
|
2012-02-20 06:53:39 -07:00
|
|
|
|
|
|
|
return job;
|
|
|
|
}
|
2012-09-20 01:11:20 -06:00
|
|
|
else if (auto dfscreen = dfhack_viewscreen::try_cast(top))
|
|
|
|
return dfscreen->getSelectedJob();
|
2012-01-14 08:31:43 -07:00
|
|
|
else
|
2012-03-10 04:55:42 -07:00
|
|
|
return getSelectedWorkshopJob(out, quiet);
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
|
|
|
|
2014-11-25 18:22:26 -07:00
|
|
|
df::unit *Gui::getAnyUnit(df::viewscreen *top)
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
|
|
|
using namespace ui_sidebar_mode;
|
|
|
|
using df::global::ui;
|
|
|
|
using df::global::world;
|
|
|
|
using df::global::ui_look_cursor;
|
|
|
|
using df::global::ui_look_list;
|
|
|
|
using df::global::ui_selected_unit;
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
using df::global::ui_building_in_assign;
|
|
|
|
using df::global::ui_building_assign_units;
|
|
|
|
using df::global::ui_building_item_cursor;
|
2012-01-14 08:31:43 -07:00
|
|
|
|
2017-06-07 18:51:40 -06:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_unitst, top))
|
|
|
|
{
|
|
|
|
return screen->unit;
|
|
|
|
}
|
|
|
|
|
2012-02-19 12:27:44 -07:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_joblistst, top))
|
2012-05-21 12:29:03 -06:00
|
|
|
{
|
|
|
|
if (auto unit = vector_get(screen->units, screen->cursor_pos))
|
|
|
|
return unit;
|
|
|
|
if (auto job = vector_get(screen->jobs, screen->cursor_pos))
|
|
|
|
return Job::getWorker(job);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-14 08:31:43 -07:00
|
|
|
|
2012-02-20 06:53:39 -07:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_unitlistst, top))
|
|
|
|
return vector_get(screen->units[screen->page], screen->cursor_pos[screen->page]);
|
|
|
|
|
2012-04-07 09:08:30 -06:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_dungeon_monsterstatusst, top))
|
|
|
|
return screen->unit;
|
|
|
|
|
2017-06-10 17:06:43 -06:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_layer_unit_relationshipst, top))
|
|
|
|
{
|
|
|
|
if (VIRTUAL_CAST_VAR(list, df::layer_object_listst, vector_get(screen->layer_objects, 0)))
|
|
|
|
return vector_get(screen->relation_unit, list->cursor);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-14 08:31:43 -07:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_itemst, top))
|
|
|
|
{
|
|
|
|
df::general_ref *ref = vector_get(screen->entry_ref, screen->cursor_pos);
|
|
|
|
return ref ? ref->getUnit() : NULL;
|
|
|
|
}
|
|
|
|
|
2016-05-14 09:43:37 -06:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_workshop_profilest, top))
|
|
|
|
{
|
|
|
|
if (screen->tab == df::viewscreen_workshop_profilest::Workers)
|
|
|
|
return vector_get(screen->workers, screen->worker_idx);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-26 01:05:35 -06:00
|
|
|
|
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_layer_noblelistst, top))
|
|
|
|
{
|
|
|
|
switch (screen->mode)
|
|
|
|
{
|
|
|
|
case df::viewscreen_layer_noblelistst::List:
|
|
|
|
if (auto list1 = getLayerList(screen, 0))
|
|
|
|
{
|
|
|
|
if (auto info = vector_get(screen->info, list1->cursor))
|
|
|
|
return info->unit;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case df::viewscreen_layer_noblelistst::Appoint:
|
|
|
|
if (auto list2 = getLayerList(screen, 1))
|
|
|
|
{
|
|
|
|
if (auto info = vector_get(screen->candidates, list2->cursor))
|
|
|
|
return info->unit;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-25 09:09:05 -07:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_locationsst, top))
|
|
|
|
{
|
|
|
|
switch (screen->menu)
|
|
|
|
{
|
|
|
|
case df::viewscreen_locationsst::AssignOccupation:
|
|
|
|
return vector_get(screen->units, screen->unit_idx);
|
|
|
|
case df::viewscreen_locationsst::Occupations:
|
|
|
|
{
|
|
|
|
auto occ = vector_get(screen->occupations, screen->occupation_idx);
|
|
|
|
if (occ)
|
|
|
|
return df::unit::find(occ->unit_id);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-26 01:05:35 -06:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_petst, top))
|
|
|
|
{
|
2018-04-05 15:49:30 -06:00
|
|
|
df::viewscreen_petst::T_animal animal_default;
|
|
|
|
animal_default.unit = NULL;
|
2012-04-26 01:05:35 -06:00
|
|
|
switch (screen->mode)
|
|
|
|
{
|
|
|
|
case df::viewscreen_petst::List:
|
|
|
|
if (!vector_get(screen->is_vermin, screen->cursor))
|
2018-04-05 15:49:30 -06:00
|
|
|
return vector_get(screen->animal, screen->cursor, animal_default).unit;
|
2012-04-26 01:05:35 -06:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case df::viewscreen_petst::SelectTrainer:
|
|
|
|
return vector_get(screen->trainer_unit, screen->trainer_cursor);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_layer_overall_healthst, top))
|
|
|
|
{
|
|
|
|
if (auto list1 = getLayerList(screen, 0))
|
|
|
|
return vector_get(screen->unit, list1->cursor);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-06-07 18:51:40 -06:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_textviewerst, top))
|
|
|
|
{
|
|
|
|
if (screen->parent)
|
|
|
|
return getAnyUnit(screen->parent);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_reportlistst, top))
|
|
|
|
return vector_get(screen->units, screen->cursor);
|
|
|
|
|
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_announcelistst, top))
|
|
|
|
{
|
2018-05-11 09:48:19 -06:00
|
|
|
if (world && screen->unit) {
|
2018-01-31 12:01:49 -07:00
|
|
|
// in (r)eports -> enter
|
|
|
|
auto *report = vector_get(screen->reports, screen->sel_idx);
|
|
|
|
if (report)
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
{
|
2018-01-31 12:01:49 -07:00
|
|
|
for (df::unit *unit : world->units.all)
|
|
|
|
{
|
|
|
|
if (unit && screen->report_type >= 0 && screen->report_type < 3
|
|
|
|
&& unit != screen->unit) // find 'other' unit related to this report
|
|
|
|
{
|
|
|
|
for (int32_t report_id : unit->reports.log[screen->report_type])
|
|
|
|
{
|
|
|
|
if (report_id == report->id)
|
|
|
|
return unit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
}
|
2018-01-31 12:01:49 -07:00
|
|
|
} else {
|
|
|
|
// in (a)nnouncements
|
|
|
|
return NULL; // cannot determine unit from reports
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_layer_militaryst, top))
|
|
|
|
{
|
|
|
|
if (screen->page == df::viewscreen_layer_militaryst::T_page::Positions) {
|
|
|
|
auto positions = getLayerList(screen, 1);
|
2018-01-31 12:01:49 -07:00
|
|
|
if (positions && positions->enabled && positions->active)
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
return vector_get(screen->positions.assigned, positions->cursor);
|
|
|
|
|
|
|
|
auto candidates = getLayerList(screen, 2);
|
2018-01-31 12:01:49 -07:00
|
|
|
if (candidates && candidates->enabled && candidates->active)
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
return vector_get(screen->positions.candidates, candidates->cursor);
|
|
|
|
}
|
|
|
|
if (screen->page == df::viewscreen_layer_militaryst::T_page::Equip) {
|
|
|
|
auto positions = getLayerList(screen, 1);
|
2018-01-31 12:01:49 -07:00
|
|
|
if (positions && positions->enabled && positions->active)
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
return vector_get(screen->equip.units, positions->cursor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_layer_unit_healthst, top))
|
|
|
|
return screen->unit;
|
|
|
|
|
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_customize_unitst, top))
|
|
|
|
return screen->unit;
|
|
|
|
|
2012-09-20 01:11:20 -06:00
|
|
|
if (auto dfscreen = dfhack_viewscreen::try_cast(top))
|
|
|
|
return dfscreen->getSelectedUnit();
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
if (!Gui::dwarfmode_hotkey(top))
|
2012-01-14 08:31:43 -07:00
|
|
|
return NULL;
|
|
|
|
|
2018-01-31 12:01:49 -07:00
|
|
|
if (!ui)
|
|
|
|
return NULL;
|
|
|
|
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
// general assigning units in building, i.e. (q)uery cage -> (a)ssign
|
|
|
|
if (ui_building_in_assign && *ui_building_in_assign
|
2018-01-31 12:01:49 -07:00
|
|
|
&& ui_building_assign_units && ui_building_item_cursor
|
|
|
|
&& ui->main.mode != Zones) // dont show for (i) zone
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
return vector_get(*ui_building_assign_units, *ui_building_item_cursor);
|
|
|
|
|
|
|
|
if (ui->follow_unit != -1)
|
|
|
|
return df::unit::find(ui->follow_unit);
|
|
|
|
|
2012-01-14 08:31:43 -07:00
|
|
|
switch (ui->main.mode) {
|
|
|
|
case ViewUnits:
|
|
|
|
{
|
2018-05-11 07:58:40 -06:00
|
|
|
if (!ui_selected_unit || !world)
|
2012-01-14 08:31:43 -07:00
|
|
|
return NULL;
|
|
|
|
|
2012-04-21 02:46:55 -06:00
|
|
|
return vector_get(world->units.active, *ui_selected_unit);
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
case ZonesPitInfo: // (i) zone -> (P)it
|
|
|
|
case ZonesPenInfo: // (i) zone -> pe(N)
|
|
|
|
{
|
2018-05-11 08:04:10 -06:00
|
|
|
if (!ui_building_assign_units || !ui_building_item_cursor)
|
|
|
|
return NULL;
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
|
2018-05-11 08:04:10 -06:00
|
|
|
return vector_get(*ui_building_assign_units, *ui_building_item_cursor);
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
}
|
|
|
|
case Burrows:
|
|
|
|
{
|
|
|
|
if (ui->burrows.in_add_units_mode)
|
|
|
|
return vector_get(ui->burrows.list_units, ui->burrows.unit_cursor_pos);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
case QueryBuilding:
|
|
|
|
{
|
2018-01-31 12:01:49 -07:00
|
|
|
if (df::building *building = getAnyBuilding(top))
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
{
|
2018-01-31 12:01:49 -07:00
|
|
|
if (VIRTUAL_CAST_VAR(cage, df::building_cagest, building))
|
|
|
|
{
|
|
|
|
if (ui_building_item_cursor)
|
|
|
|
return df::unit::find(vector_get(cage->assigned_units, *ui_building_item_cursor));
|
|
|
|
}
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-14 08:31:43 -07:00
|
|
|
case LookAround:
|
|
|
|
{
|
|
|
|
if (!ui_look_list || !ui_look_cursor)
|
|
|
|
return NULL;
|
|
|
|
|
2018-01-31 12:01:49 -07:00
|
|
|
if (auto item = vector_get(ui_look_list->items, *ui_look_cursor))
|
|
|
|
{
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
if (item->type == df::ui_look_list::T_items::Unit)
|
2020-03-06 15:06:27 -07:00
|
|
|
return item->data.Unit;
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
else if (item->type == df::ui_look_list::T_items::Item)
|
|
|
|
{
|
2020-03-06 15:06:27 -07:00
|
|
|
if (VIRTUAL_CAST_VAR(corpse, df::item_corpsest, item->data.Item))
|
2018-01-31 12:01:49 -07:00
|
|
|
return df::unit::find(corpse->unit_id); // loo(k) at corpse
|
2020-03-06 15:06:27 -07:00
|
|
|
else if (VIRTUAL_CAST_VAR(corpsepiece, df::item_corpsepiecest, item->data.Item))
|
2018-01-31 12:01:49 -07:00
|
|
|
return df::unit::find(corpsepiece->unit_id); // loo(k) at corpse piece
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
}
|
|
|
|
else if (item->type == df::ui_look_list::T_items::Spatter)
|
|
|
|
{
|
|
|
|
// loo(k) at blood/ichor/.. spatter with a name
|
|
|
|
MaterialInfo mat;
|
2018-01-28 05:37:27 -07:00
|
|
|
if (mat.decode(item->spatter_mat_type, item->spatter_mat_index) && mat.figure)
|
add many new cases for Gui::getSelectedUnit: report list, combat log list, military screen, unit health, unit custumize, assigning to cage, viewing cage, pitting, penning, burrows, look at corpse, look at corpse piece, look at named spatter
2018-01-28 05:04:52 -07:00
|
|
|
return df::unit::find(mat.figure->unit_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
bool Gui::any_unit_hotkey(df::viewscreen *top)
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
return getAnyUnit(top) != NULL;
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
df::unit *Gui::getSelectedUnit(color_ostream &out, bool quiet)
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
df::unit *unit = getAnyUnit(Core::getTopViewscreen());
|
2012-01-14 08:31:43 -07:00
|
|
|
|
|
|
|
if (!unit && !quiet)
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("No unit is selected in the UI.\n");
|
2012-01-14 08:31:43 -07:00
|
|
|
|
|
|
|
return unit;
|
|
|
|
}
|
|
|
|
|
2014-11-25 18:22:26 -07:00
|
|
|
df::item *Gui::getAnyItem(df::viewscreen *top)
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
|
|
|
using namespace ui_sidebar_mode;
|
|
|
|
using df::global::ui;
|
|
|
|
using df::global::world;
|
|
|
|
using df::global::ui_look_cursor;
|
|
|
|
using df::global::ui_look_list;
|
|
|
|
using df::global::ui_unit_view_mode;
|
|
|
|
using df::global::ui_building_item_cursor;
|
|
|
|
using df::global::ui_sidebar_menus;
|
|
|
|
|
2017-08-05 19:38:18 -06:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_textviewerst, top))
|
|
|
|
{
|
|
|
|
// return the main item if the parent screen is a viewscreen_itemst
|
|
|
|
if (VIRTUAL_CAST_VAR(parent_screen, df::viewscreen_itemst, screen->parent))
|
|
|
|
return parent_screen->item;
|
|
|
|
|
|
|
|
if (screen->parent)
|
|
|
|
return getAnyItem(screen->parent);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-14 08:31:43 -07:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_itemst, top))
|
|
|
|
{
|
|
|
|
df::general_ref *ref = vector_get(screen->entry_ref, screen->cursor_pos);
|
|
|
|
return ref ? ref->getItem() : NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-18 07:54:05 -06:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_layer_assigntradest, top))
|
|
|
|
{
|
|
|
|
auto list1 = getLayerList(screen, 0);
|
|
|
|
auto list2 = getLayerList(screen, 1);
|
2012-09-18 03:11:11 -06:00
|
|
|
if (!list1 || !list2 || !list2->active)
|
2012-05-18 07:54:05 -06:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
int list_idx = vector_get(screen->visible_lists, list1->cursor, (int16_t)-1);
|
|
|
|
unsigned num_lists = sizeof(screen->lists)/sizeof(std::vector<int32_t>);
|
|
|
|
if (unsigned(list_idx) >= num_lists)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
int idx = vector_get(screen->lists[list_idx], list2->cursor, -1);
|
|
|
|
if (auto info = vector_get(screen->info, idx))
|
|
|
|
return info->item;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_tradegoodsst, top))
|
|
|
|
{
|
|
|
|
if (screen->in_right_pane)
|
|
|
|
return vector_get(screen->broker_items, screen->broker_cursor);
|
|
|
|
else
|
|
|
|
return vector_get(screen->trader_items, screen->trader_cursor);
|
|
|
|
}
|
|
|
|
|
2012-05-21 12:29:03 -06:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_storesst, top))
|
|
|
|
{
|
|
|
|
if (screen->in_right_list && !screen->in_group_mode)
|
|
|
|
return vector_get(screen->items, screen->item_cursor);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-12-28 14:19:45 -07:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_assign_display_itemst, top))
|
|
|
|
{
|
|
|
|
if (screen->sel_column == df::viewscreen_assign_display_itemst::T_sel_column::Items)
|
|
|
|
return vector_get(screen->items[screen->item_type[screen->sel_type]],
|
|
|
|
screen->sel_item);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-20 01:11:20 -06:00
|
|
|
if (auto dfscreen = dfhack_viewscreen::try_cast(top))
|
|
|
|
return dfscreen->getSelectedItem();
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
if (!Gui::dwarfmode_hotkey(top))
|
2012-01-14 08:31:43 -07:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (ui->main.mode) {
|
|
|
|
case ViewUnits:
|
|
|
|
{
|
|
|
|
if (!ui_unit_view_mode || !ui_look_cursor || !ui_sidebar_menus)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (ui_unit_view_mode->value != df::ui_unit_view_mode::Inventory)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
auto inv_item = vector_get(ui_sidebar_menus->unit.inv_items, *ui_look_cursor);
|
|
|
|
return inv_item ? inv_item->item : NULL;
|
|
|
|
}
|
|
|
|
case LookAround:
|
|
|
|
{
|
|
|
|
if (!ui_look_list || !ui_look_cursor)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
auto item = vector_get(ui_look_list->items, *ui_look_cursor);
|
|
|
|
if (item && item->type == df::ui_look_list::T_items::Item)
|
2020-03-06 15:06:27 -07:00
|
|
|
return item->data.Item;
|
2012-01-14 08:31:43 -07:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
case BuildingItems:
|
|
|
|
{
|
|
|
|
if (!ui_building_item_cursor)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
VIRTUAL_CAST_VAR(selected, df::building_actual, world->selected_building);
|
|
|
|
if (!selected)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
auto inv_item = vector_get(selected->contained_items, *ui_building_item_cursor);
|
|
|
|
return inv_item ? inv_item->item : NULL;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
bool Gui::any_item_hotkey(df::viewscreen *top)
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
return getAnyItem(top) != NULL;
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
df::item *Gui::getSelectedItem(color_ostream &out, bool quiet)
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
df::item *item = getAnyItem(Core::getTopViewscreen());
|
2012-01-14 08:31:43 -07:00
|
|
|
|
|
|
|
if (!item && !quiet)
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("No item is selected in the UI.\n");
|
2012-01-14 08:31:43 -07:00
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2014-11-25 18:22:26 -07:00
|
|
|
df::building *Gui::getAnyBuilding(df::viewscreen *top)
|
2012-09-20 00:41:03 -06:00
|
|
|
{
|
|
|
|
using namespace ui_sidebar_mode;
|
|
|
|
using df::global::ui;
|
|
|
|
using df::global::ui_look_list;
|
|
|
|
using df::global::ui_look_cursor;
|
|
|
|
using df::global::world;
|
|
|
|
using df::global::ui_sidebar_menus;
|
|
|
|
|
2016-05-14 14:07:27 -06:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_buildinglistst, top))
|
2012-09-20 01:55:53 -06:00
|
|
|
return vector_get(screen->buildings, screen->cursor);
|
|
|
|
|
2016-05-14 14:07:27 -06:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_workshop_profilest, top))
|
|
|
|
return df::building::find(screen->building_id);
|
|
|
|
|
2012-09-20 01:11:20 -06:00
|
|
|
if (auto dfscreen = dfhack_viewscreen::try_cast(top))
|
|
|
|
return dfscreen->getSelectedBuilding();
|
|
|
|
|
2012-09-20 00:41:03 -06:00
|
|
|
if (!Gui::dwarfmode_hotkey(top))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (ui->main.mode) {
|
|
|
|
case LookAround:
|
|
|
|
{
|
|
|
|
if (!ui_look_list || !ui_look_cursor)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
auto item = vector_get(ui_look_list->items, *ui_look_cursor);
|
|
|
|
if (item && item->type == df::ui_look_list::T_items::Building)
|
2020-03-06 15:06:27 -07:00
|
|
|
return item->data.Building;
|
2012-09-20 00:41:03 -06:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
case QueryBuilding:
|
|
|
|
case BuildingItems:
|
|
|
|
{
|
|
|
|
return world->selected_building;
|
|
|
|
}
|
|
|
|
case Zones:
|
|
|
|
case ZonesPenInfo:
|
|
|
|
case ZonesPitInfo:
|
|
|
|
case ZonesHospitalInfo:
|
|
|
|
{
|
|
|
|
if (ui_sidebar_menus)
|
|
|
|
return ui_sidebar_menus->zone.selected;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gui::any_building_hotkey(df::viewscreen *top)
|
|
|
|
{
|
|
|
|
return getAnyBuilding(top) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::building *Gui::getSelectedBuilding(color_ostream &out, bool quiet)
|
|
|
|
{
|
|
|
|
df::building *building = getAnyBuilding(Core::getTopViewscreen());
|
|
|
|
|
|
|
|
if (!building && !quiet)
|
|
|
|
out.printerr("No building is selected in the UI.\n");
|
|
|
|
|
|
|
|
return building;
|
|
|
|
}
|
|
|
|
|
2017-05-05 12:45:46 -06:00
|
|
|
df::plant *Gui::getAnyPlant(df::viewscreen *top)
|
|
|
|
{
|
|
|
|
using df::global::cursor;
|
|
|
|
using df::global::ui;
|
|
|
|
using df::global::world;
|
|
|
|
|
|
|
|
if (auto dfscreen = dfhack_viewscreen::try_cast(top))
|
|
|
|
return dfscreen->getSelectedPlant();
|
|
|
|
|
|
|
|
if (Gui::dwarfmode_hotkey(top))
|
|
|
|
{
|
|
|
|
if (!cursor || !ui || !world)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if (ui->main.mode == ui_sidebar_mode::LookAround)
|
|
|
|
{
|
2021-06-24 23:08:58 -06:00
|
|
|
return Maps::getPlantAtTile(cursor->x, cursor->y, cursor->z);
|
2017-05-05 12:45:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gui::any_plant_hotkey(df::viewscreen *top)
|
|
|
|
{
|
|
|
|
return getAnyPlant(top) != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::plant *Gui::getSelectedPlant(color_ostream &out, bool quiet)
|
|
|
|
{
|
|
|
|
df::plant *plant = getAnyPlant(Core::getTopViewscreen());
|
|
|
|
|
|
|
|
if (!plant && !quiet)
|
|
|
|
out.printerr("No plant is selected in the UI.\n");
|
|
|
|
|
|
|
|
return plant;
|
|
|
|
}
|
|
|
|
|
2011-12-31 02:25:46 -07:00
|
|
|
//
|
|
|
|
|
2014-04-14 09:41:01 -06:00
|
|
|
DFHACK_EXPORT void Gui::writeToGamelog(std::string message)
|
|
|
|
{
|
|
|
|
if (message.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::ofstream fseed("gamelog.txt", std::ios::out | std::ios::app);
|
|
|
|
if(fseed.is_open())
|
|
|
|
fseed << message << std::endl;
|
|
|
|
fseed.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
DFHACK_EXPORT int Gui::makeAnnouncement(df::announcement_type type, df::announcement_flags flags, df::coord pos, std::string message, int color, bool bright)
|
|
|
|
{
|
2012-01-15 04:19:20 -07:00
|
|
|
using df::global::world;
|
|
|
|
using df::global::cur_year;
|
|
|
|
using df::global::cur_year_tick;
|
|
|
|
|
2014-04-14 09:41:01 -06:00
|
|
|
if (message.empty())
|
|
|
|
return -1;
|
|
|
|
|
2012-01-15 04:19:20 -07:00
|
|
|
int year = 0, year_time = 0;
|
|
|
|
|
|
|
|
if (cur_year && cur_year_tick)
|
|
|
|
{
|
|
|
|
year = *cur_year;
|
|
|
|
year_time = *cur_year_tick;
|
|
|
|
}
|
|
|
|
else if (!world->status.reports.empty())
|
|
|
|
{
|
|
|
|
// Fallback: copy from the last report
|
|
|
|
df::report *last = world->status.reports.back();
|
|
|
|
year = last->year;
|
|
|
|
year_time = last->time;
|
|
|
|
}
|
|
|
|
|
2014-04-14 09:41:01 -06:00
|
|
|
// Apply the requested effects
|
|
|
|
writeToGamelog(message);
|
|
|
|
|
|
|
|
if (flags.bits.DO_MEGA || flags.bits.PAUSE || flags.bits.RECENTER)
|
|
|
|
{
|
|
|
|
resetDwarfmodeView(flags.bits.DO_MEGA || flags.bits.PAUSE);
|
|
|
|
|
|
|
|
if (flags.bits.RECENTER && pos.isValid())
|
|
|
|
revealInDwarfmodeMap(pos, true);
|
|
|
|
|
|
|
|
if (flags.bits.DO_MEGA)
|
|
|
|
showPopupAnnouncement(message, color, bright);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool display = false;
|
|
|
|
|
|
|
|
if (gamemode == NULL)
|
|
|
|
display = flags.bits.A_DISPLAY || flags.bits.D_DISPLAY;
|
|
|
|
else if (*gamemode == game_mode::ADVENTURE)
|
|
|
|
display = flags.bits.A_DISPLAY;
|
|
|
|
else
|
|
|
|
display = flags.bits.D_DISPLAY;
|
|
|
|
|
|
|
|
// Generate the report objects
|
|
|
|
int report_idx = world->status.reports.size();
|
2012-01-15 04:19:20 -07:00
|
|
|
bool continued = false;
|
|
|
|
|
|
|
|
while (!message.empty())
|
|
|
|
{
|
|
|
|
df::report *new_rep = new df::report();
|
|
|
|
|
2012-09-02 04:10:58 -06:00
|
|
|
new_rep->type = type;
|
|
|
|
new_rep->pos = pos;
|
|
|
|
|
2012-01-15 04:19:20 -07:00
|
|
|
new_rep->color = color;
|
|
|
|
new_rep->bright = bright;
|
|
|
|
new_rep->year = year;
|
|
|
|
new_rep->time = year_time;
|
|
|
|
|
|
|
|
new_rep->flags.bits.continuation = continued;
|
|
|
|
|
2012-05-24 09:31:20 -06:00
|
|
|
int size = std::min(message.size(), (size_t)73);
|
2012-01-15 04:19:20 -07:00
|
|
|
new_rep->text = message.substr(0, size);
|
|
|
|
message = message.substr(size);
|
|
|
|
|
|
|
|
continued = true;
|
|
|
|
|
|
|
|
// Add the object to the lists
|
|
|
|
new_rep->id = world->status.next_report_id++;
|
|
|
|
|
|
|
|
world->status.reports.push_back(new_rep);
|
2014-04-14 09:41:01 -06:00
|
|
|
|
|
|
|
if (display)
|
|
|
|
{
|
|
|
|
new_rep->flags.bits.announcement = true;
|
|
|
|
world->status.announcements.push_back(new_rep);
|
|
|
|
world->status.display_timer = 2000;
|
|
|
|
}
|
2012-01-15 04:19:20 -07:00
|
|
|
}
|
2014-04-14 09:41:01 -06:00
|
|
|
|
|
|
|
return report_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Gui::addCombatReport(df::unit *unit, df::unit_report_type slot, int report_index)
|
|
|
|
{
|
|
|
|
using df::global::world;
|
|
|
|
|
|
|
|
CHECK_INVALID_ARGUMENT(is_valid_enum_item(slot));
|
|
|
|
|
|
|
|
auto &vec = world->status.reports;
|
|
|
|
auto report = vector_get(vec, report_index);
|
|
|
|
|
|
|
|
if (!unit || !report)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check that it is a new report
|
|
|
|
auto &rvec = unit->reports.log[slot];
|
|
|
|
if (!rvec.empty() && rvec.back() >= report->id)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Add the report
|
|
|
|
rvec.push_back(report->id);
|
|
|
|
|
|
|
|
unit->reports.last_year[slot] = report->year;
|
|
|
|
unit->reports.last_year_tick[slot] = report->time;
|
|
|
|
|
|
|
|
switch (slot) {
|
|
|
|
case unit_report_type::Combat:
|
|
|
|
world->status.flags.bits.combat = true;
|
|
|
|
break;
|
|
|
|
case unit_report_type::Hunting:
|
|
|
|
world->status.flags.bits.hunting = true;
|
|
|
|
break;
|
|
|
|
case unit_report_type::Sparring:
|
|
|
|
world->status.flags.bits.sparring = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// And all the continuation lines
|
|
|
|
for (size_t i = report_index+1; i < vec.size() && vec[i]->flags.bits.continuation; i++)
|
|
|
|
rvec.push_back(vec[i]->id);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gui::addCombatReportAuto(df::unit *unit, df::announcement_flags mode, int report_index)
|
|
|
|
{
|
|
|
|
using df::global::world;
|
|
|
|
|
|
|
|
auto &vec = world->status.reports;
|
|
|
|
auto report = vector_get(vec, report_index);
|
|
|
|
|
|
|
|
if (!unit || !report)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
if (mode.bits.UNIT_COMBAT_REPORT)
|
|
|
|
{
|
|
|
|
if (unit->flags2.bits.sparring)
|
|
|
|
ok |= addCombatReport(unit, unit_report_type::Sparring, report_index);
|
|
|
|
else if (unit->job.current_job && unit->job.current_job->job_type == job_type::Hunt)
|
|
|
|
ok |= addCombatReport(unit, unit_report_type::Hunting, report_index);
|
|
|
|
else
|
|
|
|
ok |= addCombatReport(unit, unit_report_type::Combat, report_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode.bits.UNIT_COMBAT_REPORT_ALL_ACTIVE)
|
|
|
|
{
|
|
|
|
FOR_ENUM_ITEMS(unit_report_type, slot)
|
|
|
|
{
|
|
|
|
if (!unit->reports.log[slot].empty() &&
|
|
|
|
unit->reports.last_year[slot] == report->year &&
|
|
|
|
(report->time - unit->reports.last_year_tick[slot]) <= 500)
|
|
|
|
{
|
|
|
|
ok |= addCombatReport(unit, slot, report_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
2012-09-02 04:10:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::showAnnouncement(std::string message, int color, bool bright)
|
|
|
|
{
|
2016-12-09 11:41:14 -07:00
|
|
|
df::announcement_flags mode;
|
2014-04-14 09:41:01 -06:00
|
|
|
mode.bits.D_DISPLAY = mode.bits.A_DISPLAY = true;
|
|
|
|
|
2016-12-09 11:41:14 -07:00
|
|
|
makeAnnouncement(df::announcement_type(), mode, df::coord(), message, color, bright);
|
2012-09-02 04:10:58 -06:00
|
|
|
}
|
2012-01-15 04:19:20 -07:00
|
|
|
|
2012-09-02 04:10:58 -06:00
|
|
|
void Gui::showZoomAnnouncement(
|
|
|
|
df::announcement_type type, df::coord pos, std::string message, int color, bool bright
|
|
|
|
) {
|
2016-12-09 11:41:14 -07:00
|
|
|
df::announcement_flags mode;
|
2014-04-14 09:41:01 -06:00
|
|
|
mode.bits.D_DISPLAY = mode.bits.A_DISPLAY = true;
|
|
|
|
|
|
|
|
makeAnnouncement(type, mode, pos, message, color, bright);
|
2012-01-15 04:19:20 -07:00
|
|
|
}
|
|
|
|
|
2012-03-03 06:38:24 -07:00
|
|
|
void Gui::showPopupAnnouncement(std::string message, int color, bool bright)
|
2012-01-15 04:19:20 -07:00
|
|
|
{
|
|
|
|
using df::global::world;
|
|
|
|
|
|
|
|
df::popup_message *popup = new df::popup_message();
|
|
|
|
popup->text = message;
|
|
|
|
popup->color = color;
|
|
|
|
popup->bright = bright;
|
|
|
|
world->status.popups.push_back(popup);
|
|
|
|
}
|
|
|
|
|
2012-09-02 04:10:58 -06:00
|
|
|
void Gui::showAutoAnnouncement(
|
2014-04-14 09:41:01 -06:00
|
|
|
df::announcement_type type, df::coord pos, std::string message, int color, bool bright,
|
|
|
|
df::unit *unit1, df::unit *unit2
|
2012-09-02 04:10:58 -06:00
|
|
|
) {
|
2017-12-03 19:05:08 -07:00
|
|
|
using df::global::d_init;
|
2012-09-02 04:10:58 -06:00
|
|
|
|
2016-12-09 11:41:14 -07:00
|
|
|
df::announcement_flags flags;
|
2014-04-14 09:41:01 -06:00
|
|
|
flags.bits.D_DISPLAY = flags.bits.A_DISPLAY = true;
|
|
|
|
|
2017-12-03 19:05:08 -07:00
|
|
|
if (is_valid_enum_item(type) && d_init)
|
|
|
|
flags = d_init->announcements.flags[type];
|
2012-09-02 04:10:58 -06:00
|
|
|
|
2014-04-14 09:41:01 -06:00
|
|
|
int id = makeAnnouncement(type, flags, pos, message, color, bright);
|
2012-09-02 04:10:58 -06:00
|
|
|
|
2014-04-14 09:41:01 -06:00
|
|
|
addCombatReportAuto(unit1, flags, id);
|
|
|
|
addCombatReportAuto(unit2, flags, id);
|
2012-09-02 04:10:58 -06:00
|
|
|
}
|
|
|
|
|
2012-08-24 03:20:08 -06:00
|
|
|
df::viewscreen *Gui::getCurViewscreen(bool skip_dismissed)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2014-07-24 13:10:37 -06:00
|
|
|
if (!gview)
|
|
|
|
return NULL;
|
|
|
|
|
2012-01-24 21:18:21 -07:00
|
|
|
df::viewscreen * ws = &gview->view;
|
2012-08-24 03:20:08 -06:00
|
|
|
while (ws && ws->child)
|
|
|
|
ws = ws->child;
|
|
|
|
|
|
|
|
if (skip_dismissed)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-08-24 03:20:08 -06:00
|
|
|
while (ws && Screen::isDismissed(ws) && ws->parent)
|
|
|
|
ws = ws->parent;
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
2012-08-24 03:20:08 -06:00
|
|
|
|
|
|
|
return ws;
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
2011-03-18 04:09:26 -06:00
|
|
|
|
2015-10-03 07:27:24 -06:00
|
|
|
df::viewscreen *Gui::getViewscreenByIdentity (virtual_identity &id, int n)
|
2015-10-02 19:50:55 -06:00
|
|
|
{
|
|
|
|
bool limit = (n > 0);
|
|
|
|
df::viewscreen *screen = Gui::getCurViewscreen();
|
|
|
|
while (screen)
|
|
|
|
{
|
|
|
|
if (limit && n-- <= 0)
|
|
|
|
break;
|
|
|
|
if (id.is_instance(screen))
|
|
|
|
return screen;
|
|
|
|
screen = screen->parent;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-08-25 00:37:03 -06:00
|
|
|
df::coord Gui::getViewportPos()
|
|
|
|
{
|
|
|
|
if (!df::global::window_x || !df::global::window_y || !df::global::window_z)
|
|
|
|
return df::coord(0,0,0);
|
|
|
|
|
|
|
|
return df::coord(*df::global::window_x, *df::global::window_y, *df::global::window_z);
|
|
|
|
}
|
|
|
|
|
|
|
|
df::coord Gui::getCursorPos()
|
|
|
|
{
|
|
|
|
using df::global::cursor;
|
|
|
|
if (!cursor)
|
|
|
|
return df::coord();
|
|
|
|
|
|
|
|
return df::coord(cursor->x, cursor->y, cursor->z);
|
|
|
|
}
|
|
|
|
|
2015-11-14 12:14:32 -07:00
|
|
|
Gui::DwarfmodeDims getDwarfmodeViewDims_default()
|
2012-09-02 04:10:58 -06:00
|
|
|
{
|
2015-11-14 12:14:32 -07:00
|
|
|
Gui::DwarfmodeDims dims;
|
2012-09-02 04:10:58 -06:00
|
|
|
|
|
|
|
auto ws = Screen::getWindowSize();
|
|
|
|
dims.y1 = 1;
|
|
|
|
dims.y2 = ws.y-2;
|
2016-10-07 21:51:58 -06:00
|
|
|
|
2012-09-02 04:10:58 -06:00
|
|
|
dims.map_x1 = 1;
|
|
|
|
dims.map_x2 = ws.x-2;
|
2016-10-07 21:51:58 -06:00
|
|
|
dims.map_y1 = dims.y1;
|
|
|
|
dims.map_y2 = dims.y2;
|
|
|
|
|
2012-09-02 04:10:58 -06:00
|
|
|
dims.area_x1 = dims.area_x2 = dims.menu_x1 = dims.menu_x2 = -1;
|
|
|
|
dims.menu_forced = false;
|
|
|
|
|
2017-12-03 19:34:59 -07:00
|
|
|
int menu_pos = (ui_menu_width ? (*ui_menu_width)[0] : 2);
|
|
|
|
int area_pos = (ui_menu_width ? (*ui_menu_width)[1] : 3);
|
2012-09-02 04:10:58 -06:00
|
|
|
|
|
|
|
if (ui && ui->main.mode && menu_pos >= area_pos)
|
|
|
|
{
|
|
|
|
dims.menu_forced = true;
|
|
|
|
menu_pos = area_pos-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dims.area_on = (area_pos < 3);
|
|
|
|
dims.menu_on = (menu_pos < area_pos);
|
|
|
|
|
|
|
|
if (dims.menu_on)
|
|
|
|
{
|
|
|
|
dims.menu_x2 = ws.x - 2;
|
|
|
|
dims.menu_x1 = dims.menu_x2 - Gui::MENU_WIDTH + 1;
|
|
|
|
if (menu_pos == 1)
|
|
|
|
dims.menu_x1 -= Gui::AREA_MAP_WIDTH + 1;
|
|
|
|
dims.map_x2 = dims.menu_x1 - 2;
|
|
|
|
}
|
|
|
|
if (dims.area_on)
|
|
|
|
{
|
|
|
|
dims.area_x2 = ws.x-2;
|
|
|
|
dims.area_x1 = dims.area_x2 - Gui::AREA_MAP_WIDTH + 1;
|
|
|
|
if (dims.menu_on)
|
|
|
|
dims.menu_x2 = dims.area_x1 - 2;
|
|
|
|
else
|
|
|
|
dims.map_x2 = dims.area_x1 - 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dims;
|
|
|
|
}
|
|
|
|
|
2015-11-14 12:14:32 -07:00
|
|
|
GUI_HOOK_DEFINE(Gui::Hooks::dwarfmode_view_dims, getDwarfmodeViewDims_default);
|
|
|
|
Gui::DwarfmodeDims Gui::getDwarfmodeViewDims()
|
|
|
|
{
|
|
|
|
return GUI_HOOK_TOP(Gui::Hooks::dwarfmode_view_dims)();
|
|
|
|
}
|
|
|
|
|
2012-09-02 04:10:58 -06:00
|
|
|
void Gui::resetDwarfmodeView(bool pause)
|
|
|
|
{
|
|
|
|
using df::global::cursor;
|
|
|
|
|
|
|
|
if (ui)
|
|
|
|
{
|
|
|
|
ui->follow_unit = -1;
|
|
|
|
ui->follow_item = -1;
|
|
|
|
ui->main.mode = ui_sidebar_mode::Default;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selection_rect)
|
|
|
|
{
|
|
|
|
selection_rect->start_x = -30000;
|
|
|
|
selection_rect->end_x = -30000;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cursor)
|
|
|
|
cursor->x = cursor->y = cursor->z = -30000;
|
|
|
|
|
|
|
|
if (pause && df::global::pause_state)
|
|
|
|
*df::global::pause_state = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gui::revealInDwarfmodeMap(df::coord pos, bool center)
|
|
|
|
{
|
|
|
|
using df::global::window_x;
|
|
|
|
using df::global::window_y;
|
|
|
|
using df::global::window_z;
|
|
|
|
|
|
|
|
if (!window_x || !window_y || !window_z || !world)
|
|
|
|
return false;
|
|
|
|
if (!Maps::isValidTilePos(pos))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto dims = getDwarfmodeViewDims();
|
|
|
|
int w = dims.map_x2 - dims.map_x1 + 1;
|
2017-06-01 22:40:59 -06:00
|
|
|
int h = dims.map_y2 - dims.map_y1 + 1;
|
2012-09-02 04:10:58 -06:00
|
|
|
|
|
|
|
*window_z = pos.z;
|
|
|
|
|
|
|
|
if (center)
|
|
|
|
{
|
|
|
|
*window_x = pos.x - w/2;
|
|
|
|
*window_y = pos.y - h/2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (*window_x + w < pos.x+5) *window_x += 10;
|
|
|
|
while (*window_y + h < pos.y+5) *window_y += 10;
|
|
|
|
while (*window_x + 5 > pos.x) *window_x -= 10;
|
|
|
|
while (*window_y + 5 > pos.y) *window_y -= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
*window_x = std::max(0, std::min(*window_x, world->map.x_count-w));
|
|
|
|
*window_y = std::max(0, std::min(*window_y, world->map.y_count-h));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-22 21:56:35 -06:00
|
|
|
bool Gui::refreshSidebar()
|
|
|
|
{
|
|
|
|
auto scr = getViewscreenByType<df::viewscreen_dwarfmodest>(0);
|
|
|
|
if (scr)
|
|
|
|
{
|
|
|
|
if (df::global::window_z && *df::global::window_z == 0)
|
|
|
|
{
|
|
|
|
scr->feed_key(interface_key::CURSOR_UP_Z);
|
|
|
|
scr->feed_key(interface_key::CURSOR_DOWN_Z);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scr->feed_key(interface_key::CURSOR_DOWN_Z);
|
2017-06-23 08:30:16 -06:00
|
|
|
scr->feed_key(interface_key::CURSOR_UP_Z);
|
2017-06-22 21:56:35 -06:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-09 08:23:05 -06:00
|
|
|
bool Gui::inRenameBuilding()
|
|
|
|
{
|
|
|
|
if (!ui_sidebar_menus)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return ui_sidebar_menus->barracks.in_rename;
|
|
|
|
}
|
|
|
|
|
2011-03-18 04:09:26 -06:00
|
|
|
bool Gui::getViewCoords (int32_t &x, int32_t &y, int32_t &z)
|
|
|
|
{
|
2012-03-03 06:38:24 -07:00
|
|
|
x = *df::global::window_x;
|
|
|
|
y = *df::global::window_y;
|
|
|
|
z = *df::global::window_z;
|
2011-03-18 04:09:26 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gui::setViewCoords (const int32_t x, const int32_t y, const int32_t z)
|
|
|
|
{
|
2012-03-03 06:38:24 -07:00
|
|
|
(*df::global::window_x) = x;
|
|
|
|
(*df::global::window_y) = y;
|
|
|
|
(*df::global::window_z) = z;
|
2011-03-18 04:09:26 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gui::getCursorCoords (int32_t &x, int32_t &y, int32_t &z)
|
|
|
|
{
|
2012-01-24 21:18:21 -07:00
|
|
|
x = df::global::cursor->x;
|
|
|
|
y = df::global::cursor->y;
|
|
|
|
z = df::global::cursor->z;
|
2021-05-15 13:05:00 -06:00
|
|
|
return has_cursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gui::getCursorCoords (df::coord &pos)
|
|
|
|
{
|
|
|
|
pos.x = df::global::cursor->x;
|
|
|
|
pos.y = df::global::cursor->y;
|
|
|
|
pos.z = df::global::cursor->z;
|
|
|
|
return has_cursor();
|
2011-03-18 04:09:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//FIXME: confine writing of coords to map bounds?
|
|
|
|
bool Gui::setCursorCoords (const int32_t x, const int32_t y, const int32_t z)
|
|
|
|
{
|
2012-01-24 21:18:21 -07:00
|
|
|
df::global::cursor->x = x;
|
|
|
|
df::global::cursor->y = y;
|
|
|
|
df::global::cursor->z = z;
|
2011-03-18 04:09:26 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-25 19:39:27 -06:00
|
|
|
bool Gui::getDesignationCoords (int32_t &x, int32_t &y, int32_t &z)
|
|
|
|
{
|
2012-01-24 21:18:21 -07:00
|
|
|
x = df::global::selection_rect->start_x;
|
|
|
|
y = df::global::selection_rect->start_y;
|
|
|
|
z = df::global::selection_rect->start_z;
|
2012-03-03 06:38:24 -07:00
|
|
|
return (x == -30000) ? false : true;
|
2011-09-25 19:39:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Gui::setDesignationCoords (const int32_t x, const int32_t y, const int32_t z)
|
|
|
|
{
|
2012-01-24 21:18:21 -07:00
|
|
|
df::global::selection_rect->start_x = x;
|
|
|
|
df::global::selection_rect->start_y = y;
|
|
|
|
df::global::selection_rect->start_z = z;
|
2011-09-25 19:39:27 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gui::getMousePos (int32_t & x, int32_t & y)
|
|
|
|
{
|
2012-05-23 12:38:01 -06:00
|
|
|
if (gps) {
|
|
|
|
x = gps->mouse_x;
|
|
|
|
y = gps->mouse_y;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
x = -1;
|
|
|
|
y = -1;
|
|
|
|
}
|
2012-03-03 06:38:24 -07:00
|
|
|
return (x == -1) ? false : true;
|
2011-09-25 19:39:27 -06:00
|
|
|
}
|
|
|
|
|
2015-11-14 12:14:32 -07:00
|
|
|
int getDepthAt_default (int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GUI_HOOK_DEFINE(Gui::Hooks::depth_at, getDepthAt_default);
|
|
|
|
int Gui::getDepthAt (int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
return GUI_HOOK_TOP(Gui::Hooks::depth_at)(x, y);
|
|
|
|
}
|
|
|
|
|
2011-03-18 04:09:26 -06:00
|
|
|
bool Gui::getWindowSize (int32_t &width, int32_t &height)
|
|
|
|
{
|
2012-05-23 12:38:01 -06:00
|
|
|
if (gps) {
|
|
|
|
width = gps->dimx;
|
|
|
|
height = gps->dimy;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
width = 80;
|
|
|
|
height = 25;
|
|
|
|
return false;
|
|
|
|
}
|
2012-02-22 00:30:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Gui::getMenuWidth(uint8_t &menu_width, uint8_t &area_map_width)
|
|
|
|
{
|
2017-12-03 19:34:59 -07:00
|
|
|
menu_width = (*df::global::ui_menu_width)[0];
|
|
|
|
area_map_width = (*df::global::ui_menu_width)[1];
|
2012-02-22 00:30:44 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gui::setMenuWidth(const uint8_t menu_width, const uint8_t area_map_width)
|
|
|
|
{
|
2017-12-03 19:34:59 -07:00
|
|
|
(*df::global::ui_menu_width)[0] = menu_width;
|
|
|
|
(*df::global::ui_menu_width)[1] = area_map_width;
|
2012-02-22 00:30:44 -07:00
|
|
|
return true;
|
2011-03-18 04:09:26 -06:00
|
|
|
}
|