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>
|
2023-09-17 22:38:48 -06:00
|
|
|
using namespace std;
|
2011-04-10 02:19:15 -06:00
|
|
|
|
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"
|
2022-05-16 19:41:47 -06:00
|
|
|
#include "Debug.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"
|
2022-04-24 23:45:26 -06:00
|
|
|
#include "modules/Units.h"
|
2023-01-18 14:38:23 -07:00
|
|
|
#include "modules/World.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"
|
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"
|
2023-02-06 01:58:57 -07:00
|
|
|
#include "df/cri_unitst.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"
|
2022-12-28 17:00:10 -07:00
|
|
|
#include "df/graphic_viewportst.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"
|
2023-08-07 03:50:37 -06:00
|
|
|
#include "df/legend_pagest.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/occupation.h"
|
|
|
|
#include "df/plant.h"
|
|
|
|
#include "df/popup_message.h"
|
|
|
|
#include "df/report.h"
|
2022-04-24 23:45:26 -06:00
|
|
|
#include "df/report_zoom_type.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/route_stockpile_link.h"
|
|
|
|
#include "df/stop_depart_condition.h"
|
2023-01-05 18:11:01 -07:00
|
|
|
#include "df/adventurest.h"
|
|
|
|
#include "df/buildreq.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/ui_look_list.h"
|
2023-01-05 18:11:01 -07:00
|
|
|
#include "df/gamest.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/ui_unit_view_mode.h"
|
|
|
|
#include "df/unit.h"
|
|
|
|
#include "df/unit_inventory_item.h"
|
|
|
|
#include "df/viewscreen_dwarfmodest.h"
|
2023-08-07 03:50:37 -06:00
|
|
|
#include "df/viewscreen_legendsst.h"
|
2023-05-03 16:52:01 -06:00
|
|
|
#include "df/viewscreen_new_regionst.h"
|
2023-09-26 04:45:15 -06:00
|
|
|
#include "df/viewscreen_setupdwarfgamest.h"
|
2023-04-24 09:03:11 -06:00
|
|
|
#include "df/viewscreen_titlest.h"
|
2017-06-07 18:51:40 -06:00
|
|
|
#include "df/world.h"
|
2012-01-07 08:21:07 -07:00
|
|
|
|
2022-06-06 02:56:11 -06:00
|
|
|
const size_t MAX_REPORTS_SIZE = 3000; // DF clears old reports to maintain this vector size
|
|
|
|
const int32_t RECENT_REPORT_TICKS = 500; // used by UNIT_COMBAT_REPORT_ALL_ACTIVE
|
2023-02-04 20:56:37 -07:00
|
|
|
const int32_t ANNOUNCE_LINE_DURATION = 100; // time to display each line in announcement bar; 2 sec at 50 GFPS
|
|
|
|
const int16_t ANNOUNCE_DISPLAY_TIME = 2000; // DF uses this value for most announcements; 40 sec at 50 GFPS
|
2022-06-04 16:23:57 -06:00
|
|
|
|
2022-05-16 19:41:47 -06:00
|
|
|
namespace DFHack
|
|
|
|
{
|
|
|
|
DBG_DECLARE(core, gui, DebugCategory::LINFO);
|
|
|
|
}
|
|
|
|
|
2012-01-07 08:21:07 -07:00
|
|
|
using namespace df::enums;
|
2018-05-09 08:23:05 -06:00
|
|
|
|
2023-02-13 16:21:43 -07:00
|
|
|
using df::building_civzonest;
|
|
|
|
using df::global::game;
|
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;
|
2023-01-05 18:11:01 -07:00
|
|
|
using df::global::plotinfo;
|
2023-02-13 16:21:43 -07:00
|
|
|
using df::global::selection_rect;
|
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::world;
|
2011-12-31 02:25:46 -07:00
|
|
|
|
2022-12-16 13:02:36 -07:00
|
|
|
/* TODO: understand how this changes for v50
|
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));
|
|
|
|
}
|
2022-12-16 13:02:36 -07:00
|
|
|
*/
|
2012-04-26 01:05:35 -06:00
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2023-01-27 11:22:52 -07:00
|
|
|
typedef void (*getFocusStringsHandler)(std::string &str, std::vector<std::string> &strList, df::viewscreen *screen);
|
|
|
|
static std::map<virtual_identity*, getFocusStringsHandler> getFocusStringsHandlers;
|
2012-05-19 09:50:36 -06:00
|
|
|
|
|
|
|
#define VIEWSCREEN(name) df::viewscreen_##name##st
|
|
|
|
#define DEFINE_GET_FOCUS_STRING_HANDLER(screen_type) \
|
2023-01-27 11:22:52 -07:00
|
|
|
static void getFocusStrings_##screen_type(std::string &baseFocus, std::vector<std::string> &focusStrings, VIEWSCREEN(screen_type) *screen);\
|
2012-05-19 09:50:36 -06:00
|
|
|
DFHACK_STATIC_ADD_TO_MAP(\
|
2023-01-27 11:22:52 -07:00
|
|
|
&getFocusStringsHandlers, &VIEWSCREEN(screen_type)::_identity, \
|
|
|
|
(getFocusStringsHandler)getFocusStrings_##screen_type \
|
2012-05-19 09:50:36 -06:00
|
|
|
); \
|
2023-01-27 11:22:52 -07:00
|
|
|
static void getFocusStrings_##screen_type(std::string &baseFocus, std::vector<std::string> &focusStrings, VIEWSCREEN(screen_type) *screen)
|
2012-05-19 09:50:36 -06:00
|
|
|
|
2023-04-24 09:03:11 -06:00
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(title)
|
|
|
|
{
|
|
|
|
if (screen->managing_mods)
|
|
|
|
focusStrings.push_back(baseFocus + "/Mods");
|
|
|
|
else if (game->main_interface.settings.open)
|
|
|
|
focusStrings.push_back(baseFocus + "/Settings");
|
|
|
|
|
|
|
|
if (focusStrings.empty())
|
|
|
|
focusStrings.push_back(baseFocus + "/Default");
|
|
|
|
}
|
|
|
|
|
2023-05-03 16:52:01 -06:00
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(new_region)
|
|
|
|
{
|
2023-09-10 17:32:52 -06:00
|
|
|
if (screen->raw_load)
|
|
|
|
focusStrings.push_back(baseFocus + "/Loading");
|
|
|
|
else if (screen->doing_mods)
|
2023-05-03 16:52:01 -06:00
|
|
|
focusStrings.push_back(baseFocus + "/Mods");
|
|
|
|
else if (screen->doing_simple_params)
|
|
|
|
focusStrings.push_back(baseFocus + "/Basic");
|
|
|
|
else if (screen->doing_params)
|
|
|
|
focusStrings.push_back(baseFocus + "/Advanced");
|
|
|
|
|
|
|
|
if (focusStrings.empty())
|
|
|
|
focusStrings.push_back(baseFocus);
|
|
|
|
}
|
|
|
|
|
2023-09-26 04:45:15 -06:00
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(setupdwarfgame)
|
|
|
|
{
|
|
|
|
if (screen->doing_custom_settings)
|
|
|
|
focusStrings.push_back(baseFocus + "/CustomSettings");
|
|
|
|
else if (game->main_interface.options.open)
|
|
|
|
focusStrings.push_back(baseFocus + "/Abort");
|
|
|
|
else if (screen->initial_selection == 1)
|
|
|
|
focusStrings.push_back(baseFocus + "/Default");
|
|
|
|
else if (game->main_interface.name_creator.open) {
|
|
|
|
switch (game->main_interface.name_creator.context) {
|
|
|
|
case df::name_creator_context_type::EMBARK_FORT_NAME:
|
|
|
|
focusStrings.push_back(baseFocus + "/FortName");
|
|
|
|
break;
|
|
|
|
case df::name_creator_context_type::EMBARK_GROUP_NAME:
|
|
|
|
focusStrings.push_back(baseFocus + "/GroupName");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (game->main_interface.image_creator.open) {
|
|
|
|
focusStrings.push_back(baseFocus + "/GroupSymbol");
|
|
|
|
}
|
|
|
|
else if (screen->viewing_objections != 0)
|
|
|
|
focusStrings.push_back(baseFocus + "/Objections");
|
|
|
|
else {
|
|
|
|
switch (screen->mode) {
|
|
|
|
case 0: focusStrings.push_back(baseFocus + "/Dwarves"); break;
|
|
|
|
case 1: focusStrings.push_back(baseFocus + "/Items"); break;
|
|
|
|
case 2: focusStrings.push_back(baseFocus + "/Animals"); break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (focusStrings.empty())
|
|
|
|
focusStrings.push_back(baseFocus + "/Default");
|
|
|
|
}
|
|
|
|
|
2023-08-07 03:50:37 -06:00
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(legends)
|
|
|
|
{
|
|
|
|
if (screen->init_stage != -1)
|
|
|
|
focusStrings.push_back(baseFocus + "/Loading");
|
|
|
|
else if (screen->page.size() <= 1)
|
|
|
|
focusStrings.push_back(baseFocus + "/Default");
|
|
|
|
else
|
|
|
|
focusStrings.push_back(baseFocus + '/' + screen->page[screen->active_page_index]->header);
|
|
|
|
}
|
|
|
|
|
2012-05-19 09:50:36 -06:00
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode)
|
|
|
|
{
|
2023-01-27 11:22:52 -07:00
|
|
|
std::string newFocusString;
|
2012-05-19 09:50:36 -06:00
|
|
|
|
2023-02-02 11:21:38 -07:00
|
|
|
if(game->main_interface.main_designation_selected != -1) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/Designate/" + enum_item_key(game->main_interface.main_designation_selected);
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
2023-01-27 11:22:52 -07:00
|
|
|
if (game->main_interface.info.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/Info";
|
2023-06-25 18:53:16 -06:00
|
|
|
newFocusString += '/' + enum_item_key(game->main_interface.info.current_mode);
|
2023-02-02 11:21:38 -07:00
|
|
|
|
|
|
|
switch(game->main_interface.info.current_mode) {
|
|
|
|
case df::enums::info_interface_mode_type::CREATURES:
|
2023-10-07 13:10:52 -06:00
|
|
|
if (game->main_interface.info.creatures.showing_overall_training)
|
|
|
|
newFocusString += "/OverallTraining";
|
|
|
|
else if (game->main_interface.info.creatures.showing_activity_details)
|
|
|
|
newFocusString += "/ActivityDetails";
|
|
|
|
else if (game->main_interface.info.creatures.adding_trainer)
|
|
|
|
newFocusString += "/AddingTrainer";
|
|
|
|
else
|
|
|
|
newFocusString += '/' + enum_item_key(game->main_interface.info.creatures.current_mode);
|
2023-02-02 11:21:38 -07:00
|
|
|
break;
|
|
|
|
case df::enums::info_interface_mode_type::BUILDINGS:
|
2023-06-25 18:53:16 -06:00
|
|
|
newFocusString += '/' + enum_item_key(game->main_interface.info.buildings.mode);
|
2023-02-02 11:21:38 -07:00
|
|
|
break;
|
|
|
|
case df::enums::info_interface_mode_type::LABOR:
|
2023-06-25 18:53:16 -06:00
|
|
|
newFocusString += '/' + enum_item_key(game->main_interface.info.labor.mode);
|
2023-02-02 11:21:38 -07:00
|
|
|
break;
|
|
|
|
case df::enums::info_interface_mode_type::ARTIFACTS:
|
2023-06-25 18:53:16 -06:00
|
|
|
newFocusString += '/' + enum_item_key(game->main_interface.info.artifacts.mode);
|
2023-02-02 11:21:38 -07:00
|
|
|
break;
|
|
|
|
case df::enums::info_interface_mode_type::JUSTICE:
|
2023-06-25 18:53:16 -06:00
|
|
|
newFocusString += '/' + enum_item_key(game->main_interface.info.justice.current_mode);
|
2023-02-02 11:21:38 -07:00
|
|
|
break;
|
2023-06-19 17:48:07 -06:00
|
|
|
case df::enums::info_interface_mode_type::WORK_ORDERS:
|
|
|
|
if (game->main_interface.info.work_orders.conditions.open)
|
|
|
|
newFocusString += "/Conditions";
|
2023-08-12 23:02:17 -06:00
|
|
|
else if (game->main_interface.create_work_order.open)
|
|
|
|
newFocusString += "/Create";
|
2023-06-19 17:48:07 -06:00
|
|
|
else
|
|
|
|
newFocusString += "/Default";
|
|
|
|
break;
|
2023-02-02 22:24:13 -07:00
|
|
|
default:
|
|
|
|
break;
|
2023-02-02 11:21:38 -07:00
|
|
|
}
|
|
|
|
|
2023-01-27 11:22:52 -07:00
|
|
|
focusStrings.push_back(newFocusString);
|
2012-05-19 09:50:36 -06:00
|
|
|
}
|
2023-01-27 11:22:52 -07:00
|
|
|
if (game->main_interface.view_sheets.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/ViewSheets";
|
2023-06-25 18:53:16 -06:00
|
|
|
newFocusString += '/' + enum_item_key(game->main_interface.view_sheets.active_sheet);
|
2023-08-14 00:54:18 -06:00
|
|
|
switch (game->main_interface.view_sheets.active_sheet) {
|
|
|
|
case df::view_sheet_type::UNIT:
|
|
|
|
switch (game->main_interface.view_sheets.active_sub_tab) {
|
|
|
|
case 0: newFocusString += "/Overview"; break;
|
|
|
|
case 1: newFocusString += "/Items"; break;
|
|
|
|
case 2:
|
|
|
|
newFocusString += "/Health";
|
|
|
|
switch (game->main_interface.view_sheets.unit_health_active_tab) {
|
|
|
|
case 0: newFocusString += "/Status"; break;
|
|
|
|
case 1: newFocusString += "/Wounds"; break;
|
|
|
|
case 2: newFocusString += "/Treatment"; break;
|
|
|
|
case 3: newFocusString += "/History"; break;
|
|
|
|
case 4: newFocusString += "/Description"; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
newFocusString += "/Skills";
|
|
|
|
switch (game->main_interface.view_sheets.unit_skill_active_tab) {
|
|
|
|
case 0: newFocusString += "/Labor"; break;
|
|
|
|
case 1: newFocusString += "/Combat"; break;
|
|
|
|
case 2: newFocusString += "/Social"; break;
|
|
|
|
case 3: newFocusString += "/Other"; break;
|
|
|
|
case 4:
|
|
|
|
newFocusString += "/Knowledge";
|
|
|
|
if (game->main_interface.view_sheets.skill_description_raw_str.size())
|
|
|
|
newFocusString += "/Details";
|
|
|
|
else
|
|
|
|
newFocusString += "/Default";
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4: newFocusString += "/Rooms"; break;
|
|
|
|
case 5:
|
|
|
|
newFocusString += "/Labor";
|
|
|
|
switch (game->main_interface.view_sheets.unit_labor_active_tab) {
|
|
|
|
case 0: newFocusString += "/WorkDetails"; break;
|
|
|
|
case 1: newFocusString += "/Workshops"; break;
|
|
|
|
case 2: newFocusString += "/Locations"; break;
|
|
|
|
case 3: newFocusString += "/WorkAnimals"; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6: newFocusString += "/Relations"; break;
|
|
|
|
case 7: newFocusString += "/Groups"; break;
|
|
|
|
case 8:
|
|
|
|
newFocusString += "/Military";
|
|
|
|
switch (game->main_interface.view_sheets.unit_military_active_tab) {
|
|
|
|
case 0: newFocusString += "/Squad"; break;
|
|
|
|
case 1: newFocusString += "/Uniform"; break;
|
|
|
|
case 2: newFocusString += "/Kills"; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
newFocusString += "/Thoughts";
|
|
|
|
switch (game->main_interface.view_sheets.thoughts_active_tab) {
|
|
|
|
case 0: newFocusString += "/Recent"; break;
|
|
|
|
case 1: newFocusString += "/Memories"; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
newFocusString += "/Personality";
|
|
|
|
switch (game->main_interface.view_sheets.personality_active_tab) {
|
|
|
|
case 0: newFocusString += "/Traits"; break;
|
|
|
|
case 1: newFocusString += "/Values"; break;
|
|
|
|
case 2: newFocusString += "/Preferences"; break;
|
|
|
|
case 3: newFocusString += "/Needs"; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case df::view_sheet_type::BUILDING:
|
|
|
|
if (auto bld = df::building::find(game->main_interface.view_sheets.viewing_bldid))
|
2023-06-29 19:14:15 -06:00
|
|
|
newFocusString += '/' + enum_item_key(bld->getType());
|
2023-08-14 00:54:18 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2023-06-29 19:14:15 -06:00
|
|
|
}
|
2023-01-27 11:22:52 -07:00
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
2023-02-02 11:21:38 -07:00
|
|
|
|
|
|
|
if(game->main_interface.bottom_mode_selected != -1) {
|
2023-02-01 15:22:56 -07:00
|
|
|
newFocusString = baseFocus;
|
2023-02-02 11:21:38 -07:00
|
|
|
|
|
|
|
switch(game->main_interface.bottom_mode_selected) {
|
|
|
|
case df::enums::main_bottom_mode_type::STOCKPILE:
|
|
|
|
if (game->main_interface.stockpile.cur_bld) {
|
|
|
|
newFocusString += "/Some";
|
|
|
|
}
|
|
|
|
newFocusString += "/Stockpile";
|
|
|
|
break;
|
|
|
|
case df::enums::main_bottom_mode_type::STOCKPILE_PAINT:
|
|
|
|
newFocusString += "/Stockpile/Paint";
|
|
|
|
break;
|
|
|
|
case df::enums::main_bottom_mode_type::HAULING:
|
|
|
|
newFocusString += "/Hauling";
|
|
|
|
break;
|
|
|
|
case df::enums::main_bottom_mode_type::ZONE:
|
|
|
|
newFocusString += "/Zone";
|
|
|
|
if (game->main_interface.civzone.cur_bld) {
|
|
|
|
newFocusString += "/Some";
|
2023-06-25 18:53:16 -06:00
|
|
|
newFocusString += '/' + enum_item_key(game->main_interface.civzone.cur_bld->type);
|
2023-02-02 11:21:38 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case df::enums::main_bottom_mode_type::ZONE_PAINT:
|
|
|
|
newFocusString += "/Zone/Paint";
|
|
|
|
|
|
|
|
// TODO: figure out why enum_item_key doesn't work on this?
|
|
|
|
switch(game->main_interface.civzone.adding_new_type) {
|
|
|
|
case df::enums::civzone_type::MeetingHall:
|
|
|
|
newFocusString += "/MeetingHall";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::Bedroom:
|
|
|
|
newFocusString += "/Bedroom";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::DiningHall:
|
|
|
|
newFocusString += "/DiningHall";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::Pen:
|
|
|
|
newFocusString += "/Pen";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::Pond:
|
|
|
|
newFocusString += "/Pond";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::WaterSource:
|
|
|
|
newFocusString += "/WaterSource";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::Dungeon:
|
|
|
|
newFocusString += "/Dungeon";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::FishingArea:
|
|
|
|
newFocusString += "/FishingArea";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::SandCollection:
|
|
|
|
newFocusString += "/SandCollection";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::Office:
|
|
|
|
newFocusString += "/Office";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::Dormitory:
|
|
|
|
newFocusString += "/Dormitory";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::Barracks:
|
|
|
|
newFocusString += "/Barracks";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::ArcheryRange:
|
|
|
|
newFocusString += "/ArcheryRange";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::Dump:
|
|
|
|
newFocusString += "/Dump";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::AnimalTraining:
|
|
|
|
newFocusString += "/AnimalTraining";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::Tomb:
|
|
|
|
newFocusString += "/Tomb";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::PlantGathering:
|
|
|
|
newFocusString += "/PlantGathering";
|
|
|
|
break;
|
|
|
|
case df::enums::civzone_type::ClayCollection:
|
|
|
|
newFocusString += "/ClayCollection";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case df::enums::main_bottom_mode_type::BURROW:
|
|
|
|
newFocusString += "/Burrow";
|
|
|
|
break;
|
|
|
|
case df::enums::main_bottom_mode_type::BURROW_PAINT:
|
|
|
|
newFocusString += "/Burrow/Paint";
|
|
|
|
break;
|
|
|
|
case df::enums::main_bottom_mode_type::BUILDING:
|
|
|
|
newFocusString += "/Building";
|
|
|
|
break;
|
|
|
|
case df::enums::main_bottom_mode_type::BUILDING_PLACEMENT:
|
|
|
|
newFocusString += "/Building/Placement";
|
|
|
|
break;
|
|
|
|
case df::enums::main_bottom_mode_type::BUILDING_PICK_MATERIALS:
|
|
|
|
newFocusString += "/Building/PickMaterials";
|
|
|
|
break;
|
2023-02-02 22:24:13 -07:00
|
|
|
default:
|
|
|
|
break;
|
2023-02-01 15:22:56 -07:00
|
|
|
}
|
2023-02-02 11:21:38 -07:00
|
|
|
|
2023-02-01 15:22:56 -07:00
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
2023-02-02 11:21:38 -07:00
|
|
|
|
2023-01-27 11:22:52 -07:00
|
|
|
if (game->main_interface.trade.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/Trade";
|
2023-07-02 20:09:15 -06:00
|
|
|
if (game->main_interface.trade.choosing_merchant)
|
|
|
|
newFocusString += "/ChoosingMerchant";
|
|
|
|
else
|
|
|
|
newFocusString += "/Default";
|
2023-01-27 11:22:52 -07:00
|
|
|
focusStrings.push_back(newFocusString);
|
2012-05-19 09:50:36 -06:00
|
|
|
}
|
2023-01-27 11:22:52 -07:00
|
|
|
if (game->main_interface.job_details.open) {
|
|
|
|
newFocusString = baseFocus;
|
2023-09-03 13:50:12 -06:00
|
|
|
newFocusString += "/JobDetails/" + enum_item_key(game->main_interface.job_details.context);
|
2023-01-27 11:22:52 -07:00
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.assign_trade.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/AssignTrade";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.diplomacy.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/Diplomacy";
|
2023-06-26 03:29:36 -06:00
|
|
|
if (game->main_interface.diplomacy.taking_requests)
|
|
|
|
newFocusString += "/Requests";
|
|
|
|
else
|
|
|
|
newFocusString += "/Default";
|
2023-01-27 11:22:52 -07:00
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.petitions.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/Petitions";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.stocks.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/Stocks";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.assign_display_item.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/AssignDisplayItem";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.name_creator.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/NameCreator";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.image_creator.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/ImageCreator";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.unit_selector.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/UnitSelector";
|
2023-06-29 19:14:15 -06:00
|
|
|
newFocusString += '/' + enum_item_key(game->main_interface.unit_selector.context);
|
2023-01-27 11:22:52 -07:00
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.announcement_alert.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/AnnouncementAlert";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.custom_symbol.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/CustomSymbol";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.patrol_routes.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/PatrolRoutes";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.squad_schedule.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/SquadSchedule";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.squad_selector.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/SquadSelector";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.burrow_selector.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/BurrowSelector";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.location_selector.open) {
|
|
|
|
newFocusString = baseFocus;
|
2023-10-07 20:04:19 -06:00
|
|
|
newFocusString += "/LocationSelector/";
|
|
|
|
if (game->main_interface.location_selector.choosing_temple_religious_practice)
|
|
|
|
newFocusString += "Temple";
|
|
|
|
else if (game->main_interface.location_selector.choosing_craft_guild)
|
|
|
|
newFocusString += "Guildhall";
|
|
|
|
else
|
|
|
|
newFocusString += "Default";
|
2023-01-27 11:22:52 -07:00
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.location_details.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/LocationDetails";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.hauling_stop_conditions.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/HaulingStopConditions";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.assign_vehicle.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/AssignVehicle";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.stockpile_link.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/StockpileLink";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.stockpile_tools.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/StockpileTools";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.custom_stockpile.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/CustomStockpile";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.create_squad.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/CreateSquad";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.squad_supplies.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/SquadSupplies";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.assign_uniform.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/AssignUniform";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.hotkey.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/Hotkey";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.options.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/Options";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.help.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/Help";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.settings.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/Settings";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
if (game->main_interface.squad_equipment.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/SquadEquipment";
|
|
|
|
focusStrings.push_back(newFocusString);
|
|
|
|
}
|
|
|
|
// squads should be last because it's the only one not exclusive with the others? or something?
|
|
|
|
if (game->main_interface.squads.open) {
|
|
|
|
newFocusString = baseFocus;
|
|
|
|
newFocusString += "/Squads";
|
|
|
|
focusStrings.push_back(newFocusString);
|
2012-06-06 08:54:06 -06:00
|
|
|
}
|
|
|
|
|
2023-01-27 11:22:52 -07:00
|
|
|
if (!newFocusString.size()) {
|
2023-02-06 01:58:57 -07:00
|
|
|
focusStrings.push_back(baseFocus + "/Default");
|
2012-06-06 08:54:06 -06:00
|
|
|
}
|
|
|
|
}
|
2012-05-21 11:30:53 -06:00
|
|
|
|
2023-02-01 15:29:33 -07:00
|
|
|
/* TODO: understand how this changes for v50
|
|
|
|
DEFINE_GET_FOCUS_STRING_HANDLER(dungeonmode)
|
|
|
|
{
|
|
|
|
using df::global::adventure;
|
|
|
|
|
|
|
|
if (!adventure)
|
|
|
|
return;
|
|
|
|
|
2023-06-25 18:53:16 -06:00
|
|
|
focus += '/' + enum_item_key(adventure->menu);
|
2023-02-01 15:29:33 -07:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2023-02-06 01:58:57 -07:00
|
|
|
bool Gui::matchFocusString(std::string focus_string, df::viewscreen *top) {
|
|
|
|
focus_string = toLower(focus_string);
|
|
|
|
if (!top)
|
|
|
|
top = getCurViewscreen(true);
|
|
|
|
std::vector<std::string> currentFocusStrings = getFocusStrings(top);
|
2015-12-25 09:09:05 -07:00
|
|
|
|
2023-02-06 01:58:57 -07:00
|
|
|
return std::find_if(currentFocusStrings.begin(), currentFocusStrings.end(), [&focus_string](std::string item) {
|
|
|
|
return prefix_matches(focus_string, toLower(item));
|
2023-02-02 18:53:58 -07:00
|
|
|
}) != currentFocusStrings.end();
|
2017-05-26 22:56:40 -06:00
|
|
|
}
|
|
|
|
|
2023-02-05 19:01:46 -07:00
|
|
|
static void push_dfhack_focus_string(dfhack_viewscreen *vs, std::vector<std::string> &focusStrings)
|
|
|
|
{
|
|
|
|
auto name = vs->getFocusString();
|
2023-02-20 00:27:16 -07:00
|
|
|
if (name.empty())
|
|
|
|
name = "dfhack";
|
|
|
|
else if (string::npos == name.find("dfhack/"))
|
|
|
|
name = "dfhack/" + name;
|
|
|
|
|
|
|
|
focusStrings.push_back(name);
|
2023-02-05 19:01:46 -07:00
|
|
|
}
|
|
|
|
|
2023-01-27 11:22:52 -07:00
|
|
|
std::vector<std::string> Gui::getFocusStrings(df::viewscreen* top)
|
2017-05-26 22:56:40 -06:00
|
|
|
{
|
2023-01-27 11:22:52 -07:00
|
|
|
std::vector<std::string> focusStrings;
|
2017-05-26 22:56:40 -06:00
|
|
|
|
2012-05-19 11:31:42 -06:00
|
|
|
if (!top)
|
2023-01-27 11:22:52 -07:00
|
|
|
return focusStrings;
|
2012-05-19 09:50:36 -06:00
|
|
|
|
2020-02-07 15:00:14 -07:00
|
|
|
if (dfhack_viewscreen::is_instance(top))
|
|
|
|
{
|
2023-02-05 19:01:46 -07:00
|
|
|
dfhack_viewscreen *vs = static_cast<dfhack_viewscreen*>(top);
|
|
|
|
if (vs->isFocused())
|
|
|
|
{
|
|
|
|
push_dfhack_focus_string(vs, focusStrings);
|
|
|
|
return focusStrings;
|
|
|
|
}
|
|
|
|
top = Gui::getDFViewscreen(top);
|
|
|
|
if (dfhack_viewscreen::is_instance(top))
|
|
|
|
{
|
|
|
|
push_dfhack_focus_string(static_cast<dfhack_viewscreen*>(top), focusStrings);
|
|
|
|
return focusStrings;
|
|
|
|
}
|
2020-02-07 15:00:14 -07:00
|
|
|
}
|
2023-02-05 19:01:46 -07:00
|
|
|
|
|
|
|
if (virtual_identity *id = virtual_identity::get(top))
|
2012-05-19 11:31:42 -06:00
|
|
|
{
|
|
|
|
std::string name = getNameChunk(id, 11, 2);
|
|
|
|
|
2023-01-27 11:22:52 -07:00
|
|
|
auto handler = map_find(getFocusStringsHandlers, id);
|
2012-05-19 11:31:42 -06:00
|
|
|
if (handler)
|
2023-01-27 11:22:52 -07:00
|
|
|
handler(name, focusStrings, top);
|
2012-05-19 11:31:42 -06:00
|
|
|
}
|
2023-02-05 19:01:46 -07:00
|
|
|
|
|
|
|
if (!focusStrings.size())
|
2012-05-19 11:31:42 -06:00
|
|
|
{
|
|
|
|
Core &core = Core::getInstance();
|
|
|
|
std::string name = core.p->readClassName(*(void**)top);
|
2023-01-27 11:22:52 -07:00
|
|
|
focusStrings.push_back(name.substr(11, name.size()-11-2));
|
2012-05-19 11:31:42 -06:00
|
|
|
}
|
2023-01-27 11:22:52 -07:00
|
|
|
return focusStrings;
|
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
|
|
|
{
|
2023-02-06 01:58:57 -07:00
|
|
|
return World::isFortressMode() || World::isAdventureMode();
|
2011-12-31 02:25:46 -07:00
|
|
|
}
|
|
|
|
|
2022-11-09 15:32:09 -07:00
|
|
|
bool Gui::anywhere_hotkey(df::viewscreen *) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-01-18 14:38:23 -07:00
|
|
|
bool Gui::dwarfmode_hotkey(df::viewscreen *top) {
|
2023-02-06 01:58:57 -07:00
|
|
|
return matchFocusString("dwarfmode", top);
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
|
|
|
|
2021-05-15 13:05:00 -06:00
|
|
|
static bool has_cursor()
|
|
|
|
{
|
2023-01-18 14:57:42 -07:00
|
|
|
return Gui::getCursorPos().isValid();
|
2021-05-15 13:05:00 -06:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2023-01-01 02:03:42 -07:00
|
|
|
if (!dwarfmode_hotkey(top))
|
|
|
|
return false;
|
|
|
|
|
2023-02-06 01:58:57 -07:00
|
|
|
df::building *selected = getAnyBuilding(top);
|
|
|
|
if (!virtual_cast<df::building_workshopst>(selected) &&
|
|
|
|
!virtual_cast<df::building_furnacest>(selected))
|
|
|
|
return false;
|
2012-01-07 08:21:07 -07:00
|
|
|
|
2023-02-06 01:58:57 -07:00
|
|
|
if (selected->jobs.empty() ||
|
|
|
|
selected->jobs[0]->job_type == job_type::DestroyBuilding)
|
2012-01-07 08:21:07 -07:00
|
|
|
return false;
|
2023-02-06 01:58:57 -07:00
|
|
|
|
|
|
|
return true;
|
2012-01-07 08:21:07 -07:00
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
bool Gui::build_selector_hotkey(df::viewscreen *top)
|
2012-01-07 08:21:07 -07:00
|
|
|
{
|
2023-02-06 01:58:57 -07:00
|
|
|
using df::global::buildreq;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
if (!dwarfmode_hotkey(top))
|
2012-01-07 08:21:07 -07:00
|
|
|
return false;
|
|
|
|
|
2023-02-06 01:58:57 -07:00
|
|
|
if (buildreq->building_type < 0 ||
|
|
|
|
buildreq->stage != 2 ||
|
|
|
|
buildreq->choices.empty())
|
2012-01-07 08:21:07 -07:00
|
|
|
return false;
|
2023-02-06 01:58:57 -07:00
|
|
|
|
|
|
|
return true;
|
2012-01-07 08:21:07 -07:00
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
bool Gui::view_unit_hotkey(df::viewscreen *top)
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
if (!dwarfmode_hotkey(top))
|
2012-01-14 08:31:43 -07:00
|
|
|
return false;
|
|
|
|
|
2023-02-06 01:58:57 -07:00
|
|
|
return !!getAnyUnit(top);
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
|
|
|
|
2023-02-06 01:58:57 -07:00
|
|
|
bool Gui::any_job_hotkey(df::viewscreen *top)
|
2012-01-14 08:31:43 -07:00
|
|
|
{
|
2023-02-06 01:58:57 -07:00
|
|
|
return matchFocusString("dwarfmode/Info/JOBS", top)
|
|
|
|
|| matchFocusString("dwarfmode/Info/CREATURES/CITIZEN", top)
|
|
|
|
|| workshop_job_hotkey(top);
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2023-02-06 01:58:57 -07:00
|
|
|
auto bld = getSelectedBuilding(out, true);
|
|
|
|
if (!bld)
|
2012-01-07 08:21:07 -07:00
|
|
|
return NULL;
|
2012-02-20 06:53:39 -07:00
|
|
|
|
2023-02-06 01:58:57 -07:00
|
|
|
// no way to select a specific job; just get the first one
|
|
|
|
return bld->jobs.size() ? bld->jobs[0] : NULL;
|
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
|
|
|
{
|
2023-02-06 01:58:57 -07:00
|
|
|
using df::global::game;
|
2012-01-14 08:31:43 -07:00
|
|
|
|
2023-02-06 01:58:57 -07:00
|
|
|
auto top = Core::getTopViewscreen();
|
|
|
|
if (auto dfscreen = dfhack_viewscreen::try_cast(top))
|
|
|
|
return dfscreen->getSelectedJob();
|
2012-01-14 08:31:43 -07:00
|
|
|
|
2023-02-06 01:58:57 -07:00
|
|
|
if (matchFocusString("dwarfmode/Info/JOBS")) {
|
|
|
|
auto &cri_job = game->main_interface.info.jobs.cri_job;
|
|
|
|
// no way to select specific jobs; just get the first one
|
|
|
|
return cri_job.size() ? cri_job[0]->jb : NULL;
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
2023-02-06 01:58:57 -07:00
|
|
|
|
|
|
|
if (auto unit = getAnyUnit(top)) {
|
|
|
|
df::job *job = unit->job.current_job;
|
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;
|
|
|
|
}
|
2023-02-06 01:58:57 -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
|
|
|
{
|
2023-01-09 02:39:48 -07:00
|
|
|
using df::global::game;
|
|
|
|
|
|
|
|
if (auto dfscreen = dfhack_viewscreen::try_cast(top))
|
|
|
|
return dfscreen->getSelectedUnit();
|
|
|
|
|
|
|
|
if (game->main_interface.view_sheets.open
|
|
|
|
&& game->main_interface.view_sheets.active_sheet == view_sheet_type::UNIT)
|
|
|
|
return df::unit::find(game->main_interface.view_sheets.active_id);
|
|
|
|
|
2023-01-01 02:03:42 -07:00
|
|
|
/* TODO: understand how this changes for v50
|
2023-02-06 01:58:57 -07:00
|
|
|
using namespace ui_sidebar_mode;
|
2012-01-14 08:31:43 -07:00
|
|
|
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;
|
|
|
|
|
2023-01-05 18:11:01 -07:00
|
|
|
if (!plotinfo)
|
2018-01-31 12:01:49 -07:00
|
|
|
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
|
2023-01-05 18:11:01 -07:00
|
|
|
&& plotinfo->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);
|
|
|
|
|
2023-01-05 18:11:01 -07:00
|
|
|
if (plotinfo->follow_unit != -1)
|
|
|
|
return df::unit::find(plotinfo->follow_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
|
|
|
|
2023-01-05 18:11:01 -07:00
|
|
|
switch (plotinfo->main.mode) {
|
2012-01-14 08:31:43 -07:00
|
|
|
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:
|
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
if (plotinfo->burrows.in_add_units_mode)
|
|
|
|
return vector_get(plotinfo->burrows.list_units, plotinfo->burrows.unit_cursor_pos);
|
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;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2022-12-16 13:02:36 -07:00
|
|
|
*/ return NULL;
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2023-01-09 02:39:48 -07:00
|
|
|
using df::global::game;
|
|
|
|
|
|
|
|
if (auto dfscreen = dfhack_viewscreen::try_cast(top))
|
|
|
|
return dfscreen->getSelectedItem();
|
|
|
|
|
|
|
|
if (game->main_interface.view_sheets.open
|
|
|
|
&& game->main_interface.view_sheets.active_sheet == view_sheet_type::ITEM)
|
|
|
|
return df::item::find(game->main_interface.view_sheets.active_id);
|
|
|
|
|
2023-01-01 02:03:42 -07:00
|
|
|
/* TODO: understand how this changes for v50
|
2012-01-14 08:31:43 -07:00
|
|
|
using namespace ui_sidebar_mode;
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-07-12 09:25:16 -06:00
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_treasurelistst, top))
|
|
|
|
{
|
|
|
|
if (world)
|
|
|
|
return vector_get(world->items.other[df::items_other_id::ANY_ARTIFACT], screen->sel_idx);
|
|
|
|
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;
|
|
|
|
|
2023-01-05 18:11:01 -07:00
|
|
|
switch (plotinfo->main.mode) {
|
2012-01-14 08:31:43 -07:00
|
|
|
case ViewUnits:
|
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
if (!ui_unit_view_mode || !ui_look_cursor || !game)
|
2012-01-14 08:31:43 -07:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (ui_unit_view_mode->value != df::ui_unit_view_mode::Inventory)
|
|
|
|
return NULL;
|
|
|
|
|
2023-01-05 18:11:01 -07:00
|
|
|
auto inv_item = vector_get(game->unit.inv_items, *ui_look_cursor);
|
2012-01-14 08:31:43 -07:00
|
|
|
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;
|
|
|
|
}
|
2022-12-16 13:02:36 -07:00
|
|
|
*/ return NULL;
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-01-27 11:22:52 -07:00
|
|
|
bool Gui::any_stockpile_hotkey(df::viewscreen* top)
|
|
|
|
{
|
|
|
|
return getAnyStockpile(top) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::building_stockpilest* Gui::getAnyStockpile(df::viewscreen* top) {
|
2023-08-28 14:27:46 -06:00
|
|
|
if (auto dfscreen = dfhack_viewscreen::try_cast(top))
|
|
|
|
return dfscreen->getSelectedStockpile();
|
|
|
|
|
|
|
|
if (game->main_interface.bottom_mode_selected == main_bottom_mode_type::STOCKPILE)
|
2023-01-27 11:22:52 -07:00
|
|
|
return game->main_interface.stockpile.cur_bld;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::building_stockpilest* Gui::getSelectedStockpile(color_ostream& out, bool quiet) {
|
|
|
|
df::building_stockpilest* stockpile = getAnyStockpile(Core::getTopViewscreen());
|
|
|
|
|
|
|
|
if (!stockpile && !quiet)
|
|
|
|
out.printerr("No stockpile is selected in the UI.\n");
|
|
|
|
|
|
|
|
return stockpile;
|
|
|
|
}
|
|
|
|
|
2023-02-13 16:21:43 -07:00
|
|
|
bool Gui::any_civzone_hotkey(df::viewscreen* top) {
|
|
|
|
return getAnyCivZone(top) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::building_civzonest *Gui::getAnyCivZone(df::viewscreen* top) {
|
2023-08-28 14:27:46 -06:00
|
|
|
if (auto dfscreen = dfhack_viewscreen::try_cast(top))
|
|
|
|
return dfscreen->getSelectedCivZone();
|
|
|
|
|
|
|
|
if (game->main_interface.bottom_mode_selected == main_bottom_mode_type::ZONE)
|
2023-02-13 16:21:43 -07:00
|
|
|
return game->main_interface.civzone.cur_bld;
|
2023-08-28 14:27:46 -06:00
|
|
|
|
2023-02-13 16:21:43 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::building_civzonest *Gui::getSelectedCivZone(color_ostream &out, bool quiet) {
|
|
|
|
df::building_civzonest *civzone = getAnyCivZone(Core::getTopViewscreen());
|
|
|
|
|
|
|
|
if (!civzone && !quiet)
|
|
|
|
out.printerr("No zone is selected in the UI");
|
|
|
|
|
|
|
|
return civzone;
|
|
|
|
}
|
|
|
|
|
2014-11-25 18:22:26 -07:00
|
|
|
df::building *Gui::getAnyBuilding(df::viewscreen *top)
|
2012-09-20 00:41:03 -06:00
|
|
|
{
|
2023-01-09 02:39:48 -07:00
|
|
|
if (auto dfscreen = dfhack_viewscreen::try_cast(top))
|
|
|
|
return dfscreen->getSelectedBuilding();
|
|
|
|
|
|
|
|
if (game->main_interface.view_sheets.open
|
|
|
|
&& game->main_interface.view_sheets.active_sheet == view_sheet_type::BUILDING)
|
|
|
|
return df::building::find(game->main_interface.view_sheets.active_id);
|
|
|
|
|
2023-01-01 02:03:42 -07:00
|
|
|
/* TODO: understand how this changes for v50
|
2012-09-20 00:41:03 -06:00
|
|
|
using namespace ui_sidebar_mode;
|
|
|
|
using df::global::ui_look_list;
|
|
|
|
using df::global::ui_look_cursor;
|
|
|
|
|
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;
|
|
|
|
|
2023-01-05 18:11:01 -07:00
|
|
|
switch (plotinfo->main.mode) {
|
2012-09-20 00:41:03 -06:00
|
|
|
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:
|
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
if (game)
|
|
|
|
return game->zone.selected;
|
2012-09-20 00:41:03 -06:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2022-12-16 13:02:36 -07:00
|
|
|
*/ return NULL;
|
2012-09-20 00:41:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (auto dfscreen = dfhack_viewscreen::try_cast(top))
|
|
|
|
return dfscreen->getSelectedPlant();
|
|
|
|
|
|
|
|
if (Gui::dwarfmode_hotkey(top))
|
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
if (!cursor || !plotinfo || !world)
|
2017-05-05 12:45:46 -06:00
|
|
|
return nullptr;
|
|
|
|
|
2023-01-01 02:03:42 -07:00
|
|
|
/* TODO: understand how this changes for v50
|
2023-01-05 18:11:01 -07:00
|
|
|
if (plotinfo->main.mode == ui_sidebar_mode::LookAround)
|
2017-05-05 12:45:46 -06:00
|
|
|
{
|
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
|
|
|
}
|
2023-01-01 02:03:42 -07:00
|
|
|
*/
|
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);
|
2023-09-17 22:38:48 -06:00
|
|
|
if(fseed.is_open())
|
|
|
|
fseed << message << std::endl;
|
2014-04-14 09:41:01 -06:00
|
|
|
fseed.close();
|
|
|
|
}
|
|
|
|
|
2022-05-30 14:51:24 -06:00
|
|
|
// Utility functions for reports
|
|
|
|
static bool parseReportString(std::vector<std::string> *out, const std::string &str, size_t line_length = 73)
|
|
|
|
{ // parse a string into output strings like DF does for reports
|
|
|
|
if (str.empty() || line_length == 0)
|
|
|
|
return false;
|
2022-04-24 23:45:26 -06:00
|
|
|
|
2022-05-30 14:51:24 -06:00
|
|
|
string parsed;
|
|
|
|
size_t i = 0;
|
2022-04-24 23:45:26 -06:00
|
|
|
|
2022-05-30 14:51:24 -06:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (str[i] == '&') // escape character
|
2022-05-24 04:52:33 -06:00
|
|
|
{
|
2022-05-30 14:51:24 -06:00
|
|
|
i++; // ignore the '&' itself
|
|
|
|
if (i >= str.length())
|
|
|
|
break;
|
2022-05-24 04:52:33 -06:00
|
|
|
|
2022-05-30 14:51:24 -06:00
|
|
|
if (str[i] == 'r') // "&r" adds a blank line
|
|
|
|
{
|
2022-06-04 12:59:04 -06:00
|
|
|
word_wrap(out, parsed, line_length, WSMODE_TRIM_LEADING);
|
2022-05-30 14:51:24 -06:00
|
|
|
out->push_back(" "); // DF adds a line with a space for some reason
|
|
|
|
parsed.clear();
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
2022-05-30 14:51:24 -06:00
|
|
|
else if (str[i] == '&') // "&&" is '&'
|
|
|
|
parsed.push_back('&');
|
|
|
|
// else next char is ignored
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
2022-05-30 14:51:24 -06:00
|
|
|
else
|
|
|
|
parsed.push_back(str[i]);
|
|
|
|
}
|
|
|
|
while (++i < str.length());
|
2022-04-24 23:45:26 -06:00
|
|
|
|
2022-05-30 14:51:24 -06:00
|
|
|
if (parsed.length())
|
2022-06-04 12:59:04 -06:00
|
|
|
word_wrap(out, parsed, line_length, WSMODE_TRIM_LEADING);
|
2022-05-24 04:52:33 -06:00
|
|
|
|
2022-05-30 14:51:24 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool recent_report(df::unit *unit, df::unit_report_type slot)
|
|
|
|
{
|
|
|
|
return unit && !unit->reports.log[slot].empty() &&
|
|
|
|
*df::global::cur_year == unit->reports.last_year[slot] &&
|
2022-06-04 16:23:57 -06:00
|
|
|
(*df::global::cur_year_tick - unit->reports.last_year_tick[slot]) <= RECENT_REPORT_TICKS;
|
2022-05-30 14:51:24 -06:00
|
|
|
}
|
2022-04-24 23:45:26 -06:00
|
|
|
|
2022-05-30 14:51:24 -06:00
|
|
|
static bool recent_report_any(df::unit *unit)
|
|
|
|
{
|
|
|
|
FOR_ENUM_ITEMS(unit_report_type, slot)
|
2022-04-24 23:45:26 -06:00
|
|
|
{
|
2022-05-30 14:51:24 -06:00
|
|
|
if (recent_report(unit, slot))
|
2022-04-24 23:45:26 -06:00
|
|
|
return true;
|
|
|
|
}
|
2022-05-30 14:51:24 -06:00
|
|
|
return false;
|
|
|
|
}
|
2022-04-24 23:45:26 -06:00
|
|
|
|
2022-05-30 14:51:24 -06:00
|
|
|
static void delete_old_reports()
|
|
|
|
{
|
|
|
|
auto &reports = world->status.reports;
|
2022-06-07 05:21:48 -06:00
|
|
|
if (reports.size() > MAX_REPORTS_SIZE)
|
2022-04-24 23:45:26 -06:00
|
|
|
{
|
2022-06-07 05:21:48 -06:00
|
|
|
size_t excess = reports.size() - MAX_REPORTS_SIZE;
|
|
|
|
for (size_t i = 0; i < excess; i++)
|
2022-04-24 23:45:26 -06:00
|
|
|
{
|
2022-06-07 05:21:48 -06:00
|
|
|
if (reports[i] != NULL)
|
|
|
|
{ // report destructor
|
|
|
|
if (reports[i]->flags.bits.announcement)
|
|
|
|
erase_from_vector(world->status.announcements, &df::report::id, reports[i]->id);
|
|
|
|
delete reports[i];
|
|
|
|
}
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
2022-06-07 05:21:48 -06:00
|
|
|
reports.erase(reports.begin(), reports.begin() + excess);
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
2022-05-30 14:51:24 -06:00
|
|
|
}
|
2022-04-24 23:45:26 -06:00
|
|
|
|
2022-05-30 14:51:24 -06:00
|
|
|
static int32_t check_repeat_report(vector<string> &results)
|
|
|
|
{ // returns the new repeat count, else 0
|
|
|
|
if (*gamemode == game_mode::DWARF && !results.empty() && world->status.reports.size() >= results.size())
|
2022-04-24 23:45:26 -06:00
|
|
|
{
|
|
|
|
auto &reports = world->status.reports;
|
2022-05-30 14:51:24 -06:00
|
|
|
size_t base = reports.size() - results.size(); // index where a repeat would start
|
|
|
|
size_t offset = 0;
|
|
|
|
while (reports[base + offset]->text == results[offset] && ++offset < results.size()); // match each report
|
2022-04-24 23:45:26 -06:00
|
|
|
|
2022-05-30 14:51:24 -06:00
|
|
|
if (offset == results.size()) // all lines matched
|
2022-04-24 23:45:26 -06:00
|
|
|
{
|
2022-06-06 02:56:11 -06:00
|
|
|
reports[base]->duration = ANNOUNCE_LINE_DURATION; // display the last line again
|
2022-05-30 14:51:24 -06:00
|
|
|
return ++(reports[base]->repeat_count);
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
|
|
|
}
|
2022-05-30 14:51:24 -06:00
|
|
|
return 0;
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
2022-05-30 16:04:43 -06:00
|
|
|
|
|
|
|
static bool add_proper_report(df::unit *unit, bool is_sparring, int report_index)
|
2022-06-04 16:23:57 -06:00
|
|
|
{ // add report to proper category based on is_sparring and unit current job
|
2022-05-30 16:04:43 -06:00
|
|
|
if (is_sparring)
|
|
|
|
return Gui::addCombatReport(unit, unit_report_type::Sparring, report_index);
|
|
|
|
else if (unit->job.current_job != NULL && unit->job.current_job->job_type == job_type::Hunt)
|
|
|
|
return Gui::addCombatReport(unit, unit_report_type::Hunting, report_index);
|
|
|
|
else
|
|
|
|
return Gui::addCombatReport(unit, unit_report_type::Combat, report_index);
|
|
|
|
}
|
2022-05-30 14:51:24 -06:00
|
|
|
// End of utility functions for reports
|
2022-04-24 23:45:26 -06:00
|
|
|
|
2014-04-14 09:41:01 -06:00
|
|
|
DFHACK_EXPORT int Gui::makeAnnouncement(df::announcement_type type, df::announcement_flags flags, df::coord pos, std::string message, int color, bool bright)
|
|
|
|
{
|
2022-06-04 16:36:50 -06:00
|
|
|
using df::global::cur_year;
|
|
|
|
using df::global::cur_year_tick;
|
|
|
|
|
2022-06-04 16:23:57 -06:00
|
|
|
if (gamemode == NULL || cur_year == NULL || cur_year_tick == NULL)
|
2012-01-15 04:19:20 -07:00
|
|
|
{
|
2022-06-04 16:23:57 -06:00
|
|
|
return -1;
|
2012-01-15 04:19:20 -07:00
|
|
|
}
|
2022-06-04 16:23:57 -06:00
|
|
|
else if (message.empty())
|
2012-01-15 04:19:20 -07:00
|
|
|
{
|
2022-06-04 16:46:02 -06:00
|
|
|
Core::printerr("Empty announcement %u\n", type); // DF would print this to errorlog.txt
|
2022-06-04 16:23:57 -06:00
|
|
|
return -1;
|
2012-01-15 04:19:20 -07:00
|
|
|
}
|
|
|
|
|
2014-04-14 09:41:01 -06:00
|
|
|
// Apply the requested effects
|
|
|
|
|
2022-06-04 16:23:57 -06:00
|
|
|
if (flags.bits.PAUSE || flags.bits.RECENTER)
|
|
|
|
pauseRecenter((flags.bits.RECENTER ? pos : df::coord()), flags.bits.PAUSE);
|
2014-04-14 09:41:01 -06:00
|
|
|
|
2022-06-04 16:23:57 -06:00
|
|
|
bool adv_unconscious = (*gamemode == game_mode::ADVENTURE && !world->units.active.empty() && world->units.active[0]->counters.unconscious > 0);
|
2014-04-14 09:41:01 -06:00
|
|
|
|
2022-06-04 16:23:57 -06:00
|
|
|
if (flags.bits.DO_MEGA && !adv_unconscious)
|
|
|
|
showPopupAnnouncement(message, color, bright);
|
2014-04-14 09:41:01 -06:00
|
|
|
|
2022-06-04 16:23:57 -06:00
|
|
|
vector<string> results;
|
|
|
|
word_wrap(&results, message, init->display.grid_x - 7);
|
2014-04-14 09:41:01 -06:00
|
|
|
|
2022-06-04 16:23:57 -06:00
|
|
|
// Check for repeat report
|
|
|
|
int32_t repeat_count = check_repeat_report(results); // Does nothing outside dwarf mode
|
|
|
|
if (repeat_count > 0)
|
|
|
|
{
|
|
|
|
if (flags.bits.D_DISPLAY)
|
|
|
|
{
|
2022-06-06 02:56:11 -06:00
|
|
|
world->status.display_timer = ANNOUNCE_DISPLAY_TIME;
|
2023-09-17 22:38:48 -06:00
|
|
|
Gui::writeToGamelog('x' + to_string(repeat_count + 1));
|
2022-06-04 16:23:57 -06:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not a repeat, write the message to gamelog.txt
|
|
|
|
writeToGamelog(message);
|
2014-04-14 09:41:01 -06:00
|
|
|
|
|
|
|
// Generate the report objects
|
|
|
|
int report_idx = world->status.reports.size();
|
2012-01-15 04:19:20 -07:00
|
|
|
bool continued = false;
|
2022-06-04 16:46:02 -06:00
|
|
|
bool display = ((*gamemode == game_mode::ADVENTURE && flags.bits.A_DISPLAY) || (*gamemode == game_mode::DWARF && flags.bits.D_DISPLAY));
|
2012-01-15 04:19:20 -07:00
|
|
|
|
2022-06-04 16:23:57 -06:00
|
|
|
for (size_t i = 0; i < results.size(); i++)
|
2012-01-15 04:19:20 -07:00
|
|
|
{
|
2022-06-04 16:23:57 -06:00
|
|
|
auto 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;
|
2022-06-04 16:36:50 -06:00
|
|
|
new_rep->year = *cur_year;
|
|
|
|
new_rep->time = *cur_year_tick;
|
2012-01-15 04:19:20 -07:00
|
|
|
|
|
|
|
new_rep->flags.bits.continuation = continued;
|
|
|
|
continued = true;
|
|
|
|
|
2022-06-04 16:23:57 -06:00
|
|
|
new_rep->text = results[i];
|
2012-01-15 04:19:20 -07:00
|
|
|
new_rep->id = world->status.next_report_id++;
|
|
|
|
world->status.reports.push_back(new_rep);
|
2014-04-14 09:41:01 -06:00
|
|
|
|
2022-06-04 16:23:57 -06:00
|
|
|
if (adv_unconscious)
|
|
|
|
new_rep->flags.bits.unconscious = true;
|
|
|
|
|
2014-04-14 09:41:01 -06:00
|
|
|
if (display)
|
|
|
|
{
|
2022-06-04 16:23:57 -06:00
|
|
|
insert_into_vector(world->status.announcements, &df::report::id, new_rep);
|
2014-04-14 09:41:01 -06:00
|
|
|
new_rep->flags.bits.announcement = true;
|
2022-06-06 02:56:11 -06:00
|
|
|
world->status.display_timer = ANNOUNCE_DISPLAY_TIME;
|
2014-04-14 09:41:01 -06:00
|
|
|
}
|
2012-01-15 04:19:20 -07:00
|
|
|
}
|
2014-04-14 09:41:01 -06:00
|
|
|
|
2022-06-04 16:23:57 -06:00
|
|
|
delete_old_reports();
|
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)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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)
|
2022-05-28 13:35:49 -06:00
|
|
|
ok |= add_proper_report(unit, unit->flags2.bits.sparring, report_index);
|
2014-04-14 09:41:01 -06:00
|
|
|
|
|
|
|
if (mode.bits.UNIT_COMBAT_REPORT_ALL_ACTIVE)
|
|
|
|
{
|
|
|
|
FOR_ENUM_ITEMS(unit_report_type, slot)
|
|
|
|
{
|
2022-06-04 16:23:57 -06:00
|
|
|
if (recent_report(unit, slot))
|
2014-04-14 09:41:01 -06:00
|
|
|
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
|
|
|
{
|
|
|
|
df::popup_message *popup = new df::popup_message();
|
|
|
|
popup->text = message;
|
|
|
|
popup->color = color;
|
|
|
|
popup->bright = bright;
|
2022-06-04 16:23:57 -06:00
|
|
|
|
|
|
|
auto &popups = world->status.popups;
|
|
|
|
popups.push_back(popup);
|
|
|
|
|
|
|
|
while (popups.size() > MAX_REPORTS_SIZE)
|
|
|
|
{ // Delete old popups
|
|
|
|
if (popups[0] != NULL)
|
|
|
|
delete popups[0];
|
|
|
|
popups.erase(popups.begin());
|
|
|
|
}
|
2012-01-15 04:19:20 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-05-16 19:41:47 -06:00
|
|
|
bool Gui::autoDFAnnouncement(df::report_init r, string message)
|
2022-04-24 23:45:26 -06:00
|
|
|
{ // Reverse-engineered from DF announcement code
|
2022-05-16 19:41:47 -06:00
|
|
|
if (!world->allow_announcements)
|
|
|
|
{
|
|
|
|
DEBUG(gui).print("Skipped announcement because world->allow_announcements is false:\n%s\n", message.c_str());
|
|
|
|
return false;
|
2022-05-28 13:39:49 -06:00
|
|
|
}
|
2022-05-28 13:35:49 -06:00
|
|
|
else if (!is_valid_enum_item(r.type))
|
2022-05-16 19:41:47 -06:00
|
|
|
{
|
|
|
|
WARN(gui).print("Invalid announcement type:\n%s\n", message.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2022-05-28 13:35:49 -06:00
|
|
|
else if (message.empty())
|
2022-04-24 23:45:26 -06:00
|
|
|
{
|
|
|
|
Core::printerr("Empty announcement %u\n", r.type); // DF would print this to errorlog.txt
|
2022-05-16 19:41:47 -06:00
|
|
|
return false;
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
|
|
|
|
2022-05-28 13:35:49 -06:00
|
|
|
df::announcement_flags a_flags = df::global::d_init->announcements.flags[r.type];
|
|
|
|
|
2022-04-24 23:45:26 -06:00
|
|
|
// Check if the announcement will actually be announced
|
|
|
|
if (*gamemode == game_mode::ADVENTURE)
|
|
|
|
{
|
2023-01-18 14:57:42 -07:00
|
|
|
if (r.pos.x >= 0 &&
|
2022-04-24 23:45:26 -06:00
|
|
|
r.type != announcement_type::CREATURE_SOUND &&
|
|
|
|
r.type != announcement_type::REGULAR_CONVERSATION &&
|
|
|
|
r.type != announcement_type::CONFLICT_CONVERSATION &&
|
|
|
|
r.type != announcement_type::MECHANISM_SOUND)
|
|
|
|
{ // If not sound, make sure we can see pos
|
2022-05-28 13:35:49 -06:00
|
|
|
if (world->units.active.empty() || (r.unit1 != world->units.active[0] && r.unit2 != world->units.active[0]))
|
|
|
|
{ // Adventure mode reuses a dwarf mode digging designation bit to determine current visibility
|
|
|
|
if (!Maps::isValidTilePos(r.pos) || (Maps::getTileDesignation(r.pos)->whole & 0x10) == 0x0)
|
|
|
|
{
|
|
|
|
DEBUG(gui).print("Adventure mode announcement not detected:\n%s\n", message.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2022-05-24 04:52:33 -06:00
|
|
|
{ // Dwarf mode
|
2022-04-24 23:45:26 -06:00
|
|
|
if ((r.unit1 != NULL || r.unit2 != NULL) && (r.unit1 == NULL || Units::isHidden(r.unit1)) && (r.unit2 == NULL || Units::isHidden(r.unit2)))
|
2022-05-16 19:41:47 -06:00
|
|
|
{
|
2022-05-28 13:35:49 -06:00
|
|
|
DEBUG(gui).print("Dwarf mode announcement not detected:\n%s\n", message.c_str());
|
2022-05-16 19:41:47 -06:00
|
|
|
return false;
|
|
|
|
}
|
2022-04-24 23:45:26 -06:00
|
|
|
|
|
|
|
if (!a_flags.bits.D_DISPLAY)
|
|
|
|
{
|
|
|
|
if (a_flags.bits.UNIT_COMBAT_REPORT)
|
|
|
|
{
|
|
|
|
if (r.unit1 == NULL && r.unit2 == NULL)
|
2022-05-16 19:41:47 -06:00
|
|
|
{
|
|
|
|
DEBUG(gui).print("Skipped UNIT_COMBAT_REPORT because it has no units:\n%s\n", message.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!a_flags.bits.UNIT_COMBAT_REPORT_ALL_ACTIVE)
|
2022-05-16 19:41:47 -06:00
|
|
|
{
|
|
|
|
DEBUG(gui).print("Skipped announcement not enabled for this game mode:\n%s\n", message.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (!recent_report_any(r.unit1) && !recent_report_any(r.unit2))
|
|
|
|
{
|
|
|
|
DEBUG(gui).print("Skipped UNIT_COMBAT_REPORT_ALL_ACTIVE because there's no active report:\n%s\n", message.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a_flags.bits.PAUSE || a_flags.bits.RECENTER)
|
|
|
|
pauseRecenter((a_flags.bits.RECENTER ? r.pos : df::coord()), a_flags.bits.PAUSE); // Does nothing outside dwarf mode
|
|
|
|
|
2022-06-04 16:23:57 -06:00
|
|
|
bool adv_unconscious = (*gamemode == game_mode::ADVENTURE && !world->units.active.empty() && world->units.active[0]->counters.unconscious > 0);
|
|
|
|
|
|
|
|
if (a_flags.bits.DO_MEGA && !adv_unconscious)
|
2022-04-24 23:45:26 -06:00
|
|
|
showPopupAnnouncement(message, r.color, r.bright);
|
|
|
|
|
|
|
|
vector<string> results;
|
|
|
|
size_t line_length = (r.speaker_id == -1) ? (init->display.grid_x - 7) : (init->display.grid_x - 10);
|
2022-05-24 04:52:33 -06:00
|
|
|
parseReportString(&results, message, line_length);
|
2022-04-24 23:45:26 -06:00
|
|
|
|
2022-05-24 04:52:33 -06:00
|
|
|
if (results.empty()) // DF doesn't do this check
|
2022-05-16 19:41:47 -06:00
|
|
|
{
|
|
|
|
DEBUG(gui).print("Skipped announcement because it was empty after parsing:\n%s\n", message.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2022-04-24 23:45:26 -06:00
|
|
|
|
|
|
|
// Check for repeat report
|
2022-06-06 02:56:11 -06:00
|
|
|
int32_t repeat_count = check_repeat_report(results); // always returns 0 outside dwarf mode
|
2022-04-24 23:45:26 -06:00
|
|
|
if (repeat_count > 0)
|
|
|
|
{
|
|
|
|
if (a_flags.bits.D_DISPLAY)
|
|
|
|
{
|
|
|
|
world->status.display_timer = r.display_timer;
|
2023-09-17 22:38:48 -06:00
|
|
|
Gui::writeToGamelog('x' + to_string(repeat_count + 1));
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
2022-05-16 19:41:47 -06:00
|
|
|
DEBUG(gui).print("Announcement succeeded as repeat:\n%s\n", message.c_str());
|
|
|
|
return true;
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
|
|
|
|
2022-05-24 04:52:33 -06:00
|
|
|
size_t new_report_index = world->status.reports.size(); // we need this for addCombatReport
|
2022-06-04 16:23:57 -06:00
|
|
|
bool success = false; // only print to gamelog if report was used
|
|
|
|
bool display = ((*gamemode == game_mode::ADVENTURE && a_flags.bits.A_DISPLAY) || (*gamemode == game_mode::DWARF && a_flags.bits.D_DISPLAY));
|
|
|
|
|
2022-04-24 23:45:26 -06:00
|
|
|
for (size_t i = 0; i < results.size(); i++)
|
|
|
|
{ // Generate report entries for each line
|
|
|
|
auto new_report = new df::report();
|
|
|
|
new_report->type = r.type;
|
|
|
|
new_report->text = results[i];
|
|
|
|
new_report->color = r.color;
|
|
|
|
new_report->bright = r.bright;
|
|
|
|
new_report->flags.whole = 0x0;
|
|
|
|
new_report->zoom_type = r.zoom_type;
|
|
|
|
new_report->pos = r.pos;
|
|
|
|
new_report->zoom_type2 = r.zoom_type2;
|
|
|
|
new_report->pos2 = r.pos2;
|
|
|
|
new_report->id = world->status.next_report_id++;
|
|
|
|
new_report->year = *df::global::cur_year;
|
|
|
|
new_report->time = *df::global::cur_year_tick;
|
|
|
|
new_report->unk_v40_1 = r.unk_v40_1;
|
|
|
|
new_report->unk_v40_2 = r.unk_v40_2;
|
|
|
|
new_report->speaker_id = r.speaker_id;
|
|
|
|
world->status.reports.push_back(new_report);
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
new_report->flags.bits.continuation = true;
|
|
|
|
|
2022-06-04 16:23:57 -06:00
|
|
|
if (adv_unconscious)
|
2022-04-24 23:45:26 -06:00
|
|
|
new_report->flags.bits.unconscious = true;
|
|
|
|
|
2022-06-04 16:23:57 -06:00
|
|
|
if (display)
|
2022-04-24 23:45:26 -06:00
|
|
|
{
|
|
|
|
insert_into_vector(world->status.announcements, &df::report::id, new_report);
|
|
|
|
new_report->flags.bits.announcement = true;
|
|
|
|
world->status.display_timer = r.display_timer;
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-24 04:52:33 -06:00
|
|
|
if (*gamemode == game_mode::DWARF) // DF does this inside the previous loop, but we're using addCombatReport instead
|
2022-04-24 23:45:26 -06:00
|
|
|
{
|
|
|
|
if (a_flags.bits.UNIT_COMBAT_REPORT)
|
|
|
|
{
|
|
|
|
if (r.unit1 != NULL)
|
2022-05-28 13:35:49 -06:00
|
|
|
success |= add_proper_report(r.unit1, !r.flags.bits.hostile_combat, new_report_index);
|
2022-04-24 23:45:26 -06:00
|
|
|
|
|
|
|
if (r.unit2 != NULL)
|
2022-05-28 13:35:49 -06:00
|
|
|
success |= add_proper_report(r.unit2, !r.flags.bits.hostile_combat, new_report_index);
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (a_flags.bits.UNIT_COMBAT_REPORT_ALL_ACTIVE)
|
|
|
|
{
|
|
|
|
FOR_ENUM_ITEMS(unit_report_type, slot)
|
|
|
|
{
|
|
|
|
if (recent_report(r.unit1, slot))
|
|
|
|
success |= addCombatReport(r.unit1, slot, new_report_index);
|
2022-05-28 13:35:49 -06:00
|
|
|
|
2022-04-24 23:45:26 -06:00
|
|
|
if (recent_report(r.unit2, slot))
|
|
|
|
success |= addCombatReport(r.unit2, slot, new_report_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete_old_reports();
|
|
|
|
|
2022-05-16 19:41:47 -06:00
|
|
|
if (/*debug_gamelog &&*/ success) // TODO: Add debug_gamelog to globals?
|
|
|
|
{
|
|
|
|
DEBUG(gui).print("Announcement succeeded and printed to gamelog.txt:\n%s\n", message.c_str());
|
2022-04-24 23:45:26 -06:00
|
|
|
Gui::writeToGamelog(message);
|
2022-05-16 19:41:47 -06:00
|
|
|
}
|
|
|
|
/*else if (success)
|
|
|
|
{
|
|
|
|
DEBUG(gui).print("Announcement succeeded but skipped printing to gamelog.txt because debug_gamelog is false:\n%s\n", message.c_str());
|
|
|
|
}*/
|
2022-05-24 04:52:33 -06:00
|
|
|
else // not sure if this can actually happen; our results.empty() check handles the one edge case I can think of that would get this far
|
2022-04-24 23:45:26 -06:00
|
|
|
{
|
2022-05-16 19:41:47 -06:00
|
|
|
DEBUG(gui).print("Announcement succeeded internally but didn't qualify to be displayed anywhere:\n%s\n", message.c_str());
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
2022-05-16 19:41:47 -06:00
|
|
|
|
|
|
|
return true;
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
|
|
|
|
2022-05-16 19:41:47 -06:00
|
|
|
bool Gui::autoDFAnnouncement(df::announcement_type type, df::coord pos, std::string message, int color,
|
2022-05-24 04:52:33 -06:00
|
|
|
bool bright, df::unit *unit1, df::unit *unit2, bool is_sparring)
|
2022-04-24 23:45:26 -06:00
|
|
|
{
|
|
|
|
auto r = df::report_init();
|
|
|
|
r.type = type;
|
|
|
|
r.color = color;
|
|
|
|
r.bright = bright;
|
|
|
|
r.pos = pos;
|
2022-06-06 02:56:11 -06:00
|
|
|
r.display_timer = ANNOUNCE_DISPLAY_TIME;
|
2022-04-24 23:45:26 -06:00
|
|
|
r.unit1 = unit1;
|
|
|
|
r.unit2 = unit2;
|
2022-05-01 23:53:53 -06:00
|
|
|
r.flags.bits.hostile_combat = !is_sparring;
|
2022-04-24 23:45:26 -06:00
|
|
|
|
2022-05-16 19:41:47 -06:00
|
|
|
return autoDFAnnouncement(r, message);
|
2022-04-24 23:45:26 -06:00
|
|
|
}
|
|
|
|
|
2023-01-06 13:17:36 -07:00
|
|
|
static df::viewscreen * do_skip_dismissed(df::viewscreen * ws) {
|
|
|
|
while (ws && Screen::isDismissed(ws) && ws->parent)
|
|
|
|
ws = ws->parent;
|
|
|
|
return ws;
|
|
|
|
}
|
|
|
|
|
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)
|
2023-01-06 13:17:36 -07:00
|
|
|
ws = do_skip_dismissed(ws);
|
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;
|
|
|
|
}
|
|
|
|
|
2023-02-05 19:01:46 -07:00
|
|
|
df::viewscreen *Gui::getDFViewscreen(bool skip_dismissed, df::viewscreen *screen) {
|
|
|
|
if (!screen)
|
|
|
|
screen = Gui::getCurViewscreen(skip_dismissed);
|
2023-01-06 13:17:36 -07:00
|
|
|
while (screen && dfhack_viewscreen::is_instance(screen)) {
|
|
|
|
screen = screen->parent;
|
|
|
|
if (skip_dismissed)
|
|
|
|
screen = do_skip_dismissed(screen);
|
|
|
|
}
|
|
|
|
return screen;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2022-12-31 23:49:30 -07:00
|
|
|
bool use_graphics = Screen::inGraphicsMode();
|
|
|
|
auto dimx = use_graphics ? gps->main_viewport->dim_x : gps->dimx;
|
|
|
|
auto dimy = use_graphics ? gps->main_viewport->dim_y : gps->dimy;
|
2016-10-07 21:51:58 -06:00
|
|
|
|
2022-12-31 23:49:30 -07:00
|
|
|
dims.map_x1 = 0;
|
|
|
|
dims.map_x2 = dimx - 1;
|
|
|
|
dims.map_y1 = 0;
|
|
|
|
dims.map_y2 = dimy - 1;
|
2012-09-02 04:10:58 -06:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2023-01-05 18:11:01 -07:00
|
|
|
if (plotinfo)
|
2012-09-02 04:10:58 -06:00
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
plotinfo->follow_unit = -1;
|
|
|
|
plotinfo->follow_item = -1;
|
|
|
|
plotinfo->main.mode = ui_sidebar_mode::Default;
|
2012-09-02 04:10:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (selection_rect)
|
|
|
|
{
|
|
|
|
selection_rect->start_x = -30000;
|
2023-02-04 20:56:37 -07:00
|
|
|
selection_rect->start_y = -30000;
|
|
|
|
selection_rect->start_z = -30000;
|
2012-09-02 04:10:58 -06:00
|
|
|
selection_rect->end_x = -30000;
|
2023-02-04 20:56:37 -07:00
|
|
|
selection_rect->end_y = -30000;
|
|
|
|
selection_rect->end_z = -30000;
|
2012-09-02 04:10:58 -06:00
|
|
|
}
|
2023-02-04 20:56:37 -07:00
|
|
|
// NOTE: There's an unidentified global coord after selection_rect that is reset to -30000 here.
|
|
|
|
// This coord goes into game->main_interface.keyboard_last_track_s if the x value is not -30000. Probably okay to ignore?
|
2012-09-02 04:10:58 -06:00
|
|
|
|
|
|
|
if (cursor)
|
|
|
|
cursor->x = cursor->y = cursor->z = -30000;
|
|
|
|
|
|
|
|
if (pause && df::global::pause_state)
|
|
|
|
*df::global::pause_state = true;
|
|
|
|
}
|
|
|
|
|
2022-06-04 12:59:04 -06:00
|
|
|
bool Gui::revealInDwarfmodeMap(int32_t x, int32_t y, int32_t z, bool center)
|
|
|
|
{ // Reverse-engineered from DF announcement and scrolling code
|
2012-09-02 04:10:58 -06:00
|
|
|
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;
|
|
|
|
|
|
|
|
auto dims = getDwarfmodeViewDims();
|
2022-06-04 12:59:04 -06:00
|
|
|
int32_t w = dims.map_x2 - dims.map_x1 + 1;
|
|
|
|
int32_t h = dims.map_y2 - dims.map_y1 + 1;
|
|
|
|
int32_t new_win_x, new_win_y, new_win_z;
|
|
|
|
getViewCoords(new_win_x, new_win_y, new_win_z);
|
2012-09-02 04:10:58 -06:00
|
|
|
|
2022-06-04 12:59:04 -06:00
|
|
|
if (Maps::isValidTilePos(x, y, z))
|
2012-09-02 04:10:58 -06:00
|
|
|
{
|
2022-06-04 12:59:04 -06:00
|
|
|
if (center)
|
|
|
|
{
|
|
|
|
new_win_x = x - w / 2;
|
|
|
|
new_win_y = y - h / 2;
|
|
|
|
}
|
|
|
|
else // just bring it on screen
|
|
|
|
{
|
|
|
|
if (new_win_x > (x - 5)) // equivalent to: "while (new_win_x > x - 5) new_win_x -= 10;"
|
|
|
|
new_win_x -= (new_win_x - (x - 5) - 1) / 10 * 10 + 10;
|
|
|
|
if (new_win_y > (y - 5))
|
|
|
|
new_win_y -= (new_win_y - (y - 5) - 1) / 10 * 10 + 10;
|
|
|
|
if (new_win_x < (x + 5 - w))
|
|
|
|
new_win_x += ((x + 5 - w) - new_win_x - 1) / 10 * 10 + 10;
|
|
|
|
if (new_win_y < (y + 5 - h))
|
|
|
|
new_win_y += ((y + 5 - h) - new_win_y - 1) / 10 * 10 + 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_win_z = z;
|
2012-09-02 04:10:58 -06:00
|
|
|
}
|
2022-06-04 12:59:04 -06:00
|
|
|
|
|
|
|
*window_x = clip_range(new_win_x, 0, (world->map.x_count - w));
|
|
|
|
*window_y = clip_range(new_win_y, 0, (world->map.y_count - h));
|
|
|
|
*window_z = clip_range(new_win_z, 0, (world->map.z_count - 1));
|
2023-01-08 12:33:14 -07:00
|
|
|
game->minimap.update = true;
|
|
|
|
game->minimap.mustmake = true;
|
2022-06-04 12:59:04 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gui::pauseRecenter(int32_t x, int32_t y, int32_t z, bool pause)
|
|
|
|
{ // Reverse-engineered from DF announcement code
|
|
|
|
if (*gamemode != game_mode::DWARF)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
resetDwarfmodeView(pause);
|
|
|
|
|
|
|
|
if (Maps::isValidTilePos(x, y, z))
|
|
|
|
revealInDwarfmodeMap(x, y, z, false);
|
|
|
|
|
|
|
|
if (init->input.pause_zoom_no_interface_ms > 0)
|
2012-09-02 04:10:58 -06:00
|
|
|
{
|
2022-06-04 12:59:04 -06:00
|
|
|
gview->shutdown_interface_tickcount = Core::getInstance().p->getTickCount();
|
|
|
|
gview->shutdown_interface_for_ms = init->input.pause_zoom_no_interface_ms;
|
2012-09-02 04:10:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
if (!game)
|
2018-05-09 08:23:05 -06:00
|
|
|
return false;
|
2022-12-17 12:07:37 -07:00
|
|
|
/* TODO: understand how this changes for v50
|
2023-01-05 18:11:01 -07:00
|
|
|
return game->barracks.in_rename;
|
2022-12-17 12:07:37 -07:00
|
|
|
*/
|
|
|
|
return false;
|
2018-05-09 08:23:05 -06:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2022-06-06 02:56:11 -06:00
|
|
|
x = selection_rect->start_x;
|
|
|
|
y = selection_rect->start_y;
|
|
|
|
z = selection_rect->start_z;
|
2023-01-18 14:57:42 -07:00
|
|
|
return (x >= 0) ? 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)
|
|
|
|
{
|
2022-06-06 02:56:11 -06:00
|
|
|
selection_rect->start_x = x;
|
|
|
|
selection_rect->start_y = y;
|
|
|
|
selection_rect->start_z = z;
|
2011-09-25 19:39:27 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-09-18 09:19:02 -06:00
|
|
|
// returns the map coordinates that the mouse cursor is over
|
|
|
|
df::coord Gui::getMousePos()
|
2011-09-25 19:39:27 -06:00
|
|
|
{
|
2022-09-18 09:19:02 -06:00
|
|
|
df::coord pos;
|
2022-12-21 15:07:36 -07:00
|
|
|
if (gps && gps->precise_mouse_x > -1) {
|
2022-09-18 09:19:02 -06:00
|
|
|
pos = getViewportPos();
|
2022-12-29 01:01:40 -07:00
|
|
|
if (Screen::inGraphicsMode()) {
|
2022-12-29 23:18:35 -07:00
|
|
|
int32_t map_tile_pixels = gps->viewport_zoom_factor / 4;
|
2022-12-29 01:01:40 -07:00
|
|
|
pos.x += gps->precise_mouse_x / map_tile_pixels;
|
|
|
|
pos.y += gps->precise_mouse_y / map_tile_pixels;
|
|
|
|
} else {
|
|
|
|
pos.x += gps->mouse_x;
|
|
|
|
pos.y += gps->mouse_y;
|
|
|
|
}
|
2022-12-20 12:00:49 -07:00
|
|
|
}
|
2022-12-29 01:01:40 -07:00
|
|
|
if (!Maps::isValidTilePos(pos.x, pos.y, pos.z))
|
|
|
|
return df::coord();
|
2022-09-18 09:19:02 -06:00
|
|
|
return pos;
|
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)
|
|
|
|
{
|
2022-12-28 17:00:10 -07:00
|
|
|
auto &main_vp = gps->main_viewport;
|
|
|
|
if (x < 0 || x >= main_vp->dim_x || y < 0 || y >= main_vp->dim_y)
|
|
|
|
return 0;
|
|
|
|
const size_t num_viewports = gps->viewport.size();
|
|
|
|
const size_t index = (x * main_vp->dim_y) + y;
|
2022-12-29 00:31:06 -07:00
|
|
|
for (size_t depth = 0; depth < num_viewports; ++depth) {
|
2022-12-28 17:00:10 -07:00
|
|
|
if (gps->viewport[depth]->screentexpos_background[index])
|
|
|
|
return depth;
|
|
|
|
}
|
2015-11-14 12:14:32 -07:00
|
|
|
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
|
|
|
}
|