Merge pull request #3504 from myk002/myk_widget

widget and focus string enhancements
develop
Myk 2023-07-03 11:47:49 -07:00 committed by GitHub
commit c7b24e4cb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 27 deletions

@ -46,6 +46,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Internals
## Lua
- ``dfhack.items.markForTrade``: new API for marking items for trade
## Removed

@ -1775,6 +1775,10 @@ Items module
Checks whether the item and all items it contains, if any, can be traded.
* ``dfhack.items.markForTrade(item, depot)``
Marks the given item for trade at the given depot.
* ``dfhack.items.isRouteVehicle(item)``
Checks whether the item is an assigned hauling vehicle.

@ -2014,6 +2014,7 @@ static const LuaWrapper::FunctionReg dfhack_items_module[] = {
WRAPM(Items, checkMandates),
WRAPM(Items, canTrade),
WRAPM(Items, canTradeWithContents),
WRAPM(Items, markForTrade),
WRAPM(Items, isRouteVehicle),
WRAPM(Items, isSquadEquipment),
WRAPN(moveToGround, items_moveToGround),

@ -33,6 +33,7 @@ distribution.
#include "MemAccess.h"
#include "DataDefs.h"
#include "df/building_tradedepotst.h"
#include "df/item.h"
#include "df/item_type.h"
#include "df/general_ref.h"
@ -199,6 +200,8 @@ DFHACK_EXPORT bool checkMandates(df::item *item);
DFHACK_EXPORT bool canTrade(df::item *item);
/// Checks whether the item and all items it contains, if any, can be traded
DFHACK_EXPORT bool canTradeWithContents(df::item *item);
/// marks the given item for trade at the given depot
DFHACK_EXPORT bool markForTrade(df::item *item, df::building_tradedepotst *depot);
/// Checks whether the item is an assigned hauling vehicle
DFHACK_EXPORT bool isRouteVehicle(df::item *item);

@ -1552,8 +1552,7 @@ function CycleHotkeyLabel:setOption(value_or_index, call_on_change)
end
end
if not option_idx then
error(('cannot find option with value or index: "%s"')
:format(value_or_index))
option_idx = 1
end
local old_option_idx = self.option_idx
self.option_idx = option_idx
@ -2392,9 +2391,15 @@ local function rangeslider_do_drag(self, width_per_idx)
end
end
if new_left_idx and new_left_idx ~= self.get_left_idx_fn() then
if not new_right_idx and new_left_idx > self.get_right_idx_fn() then
self.on_right_change(new_left_idx)
end
self.on_left_change(new_left_idx)
end
if new_right_idx and new_right_idx ~= self.get_right_idx_fn() then
if new_right_idx < self.get_left_idx_fn() then
self.on_left_change(new_right_idx)
end
self.on_right_change(new_right_idx)
end
end

@ -216,6 +216,11 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode)
newFocusString = baseFocus;
newFocusString += "/ViewSheets";
newFocusString += "/" + enum_item_key(game->main_interface.view_sheets.active_sheet);
if (game->main_interface.view_sheets.active_sheet == df::view_sheet_type::BUILDING) {
auto bld = df::building::find(game->main_interface.view_sheets.viewing_bldid);
if (bld)
newFocusString += '/' + enum_item_key(bld->getType());
}
focusStrings.push_back(newFocusString);
}
@ -328,6 +333,10 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode)
if (game->main_interface.trade.open) {
newFocusString = baseFocus;
newFocusString += "/Trade";
if (game->main_interface.trade.choosing_merchant)
newFocusString += "/ChoosingMerchant";
else
newFocusString += "/Default";
focusStrings.push_back(newFocusString);
}
if (game->main_interface.job_details.open) {
@ -377,6 +386,7 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode)
if (game->main_interface.unit_selector.open) {
newFocusString = baseFocus;
newFocusString += "/UnitSelector";
newFocusString += '/' + enum_item_key(game->main_interface.unit_selector.context);
focusStrings.push_back(newFocusString);
}
if (game->main_interface.announcement_alert.open) {

@ -39,6 +39,7 @@ distribution.
using namespace std;
#include "ModuleFactory.h"
#include "modules/Job.h"
#include "modules/MapCache.h"
#include "modules/Materials.h"
#include "modules/Items.h"
@ -48,6 +49,7 @@ using namespace std;
#include "df/body_part_template_flags.h"
#include "df/building.h"
#include "df/building_actual.h"
#include "df/building_tradedepotst.h"
#include "df/caste_raw.h"
#include "df/creature_raw.h"
#include "df/general_ref.h"
@ -1637,6 +1639,42 @@ bool Items::canTradeWithContents(df::item *item)
return true;
}
bool Items::markForTrade(df::item *item, df::building_tradedepotst *depot) {
CHECK_NULL_POINTER(item);
CHECK_NULL_POINTER(depot);
// validate that the depot is in a good state
if (depot->getBuildStage() < depot->getMaxBuildStage())
return false;
if (depot->jobs.size() && depot->jobs[0]->job_type == df::job_type::DestroyBuilding)
return false;
auto href = df::allocate<df::general_ref_building_holderst>();
if (!href)
return false;
auto job = new df::job();
job->job_type = df::job_type::BringItemToDepot;
job->pos = df::coord(depot->centerx, depot->centery, depot->z);
// job <-> item link
if (!Job::attachJobItem(job, item, df::job_item_ref::Hauled)) {
delete job;
delete href;
return false;
}
// job <-> building link
href->building_id = depot->id;
depot->jobs.push_back(job);
job->general_refs.push_back(href);
// add to job list
Job::linkIntoWorld(job);
return true;
}
bool Items::isRouteVehicle(df::item *item)
{
CHECK_NULL_POINTER(item);

@ -323,31 +323,7 @@ public:
bool designate(color_ostream& out, df::item* item) override {
if (!depot)
return false;
auto href = df::allocate<df::general_ref_building_holderst>();
if (!href)
return false;
auto job = new df::job();
job->job_type = df::job_type::BringItemToDepot;
job->pos = df::coord(depot->centerx, depot->centery, depot->z);
// job <-> item link
if (!Job::attachJobItem(job, item, df::job_item_ref::Hauled)) {
delete job;
delete href;
return false;
}
// job <-> building link
href->building_id = depot->id;
depot->jobs.push_back(job);
job->general_refs.push_back(href);
// add to job list
Job::linkIntoWorld(job);
return true;
return Items::markForTrade(item, depot);
}
private: