implement make_top_priority, cache inspector data

develop
Myk Taylor 2023-02-16 18:02:15 -08:00
parent 0d3285678c
commit 3f8be2cd9e
No known key found for this signature in database
2 changed files with 68 additions and 3 deletions

@ -336,7 +336,7 @@ static bool registerPlannedBuilding(color_ostream &out, PlannedBuilding & pb) {
// as invalid
for (auto vector_id : pb.vector_ids[job_item_idx]) {
for (int item_num = 0; item_num < job_item->quantity; ++item_num) {
tasks[vector_id][bucket].push_back(std::make_pair(id, job_item_idx));
tasks[vector_id][bucket].emplace_back(id, job_item_idx);
DEBUG(status,out).print("added task: %s/%s/%d,%d; "
"%zu vector(s), %zu filter bucket(s), %zu task(s) in bucket",
ENUM_KEY_STR(job_item_vector_id, vector_id).c_str(),
@ -578,6 +578,36 @@ static int getQueuePosition(color_ostream &out, df::building *bld, int index) {
return min_pos < 0 ? 0 : min_pos;
}
static void makeTopPriority(color_ostream &out, df::building *bld) {
DEBUG(status,out).print("entering makeTopPriority\n");
if (!validate_pb(out, bld, 0))
return;
PlannedBuilding &pb = planned_buildings.at(bld->id);
auto &job_items = bld->jobs[0]->job_items;
for (int index = 0; index < job_items.size(); ++index) {
for (auto &vec_id : pb.vector_ids[index]) {
if (!tasks.count(vec_id))
continue;
auto &buckets = tasks.at(vec_id);
string bucket_id = getBucket(*job_items[index]);
if (!buckets.count(bucket_id))
continue;
auto &bucket = buckets.at(bucket_id);
for (auto taskit = bucket.begin(); taskit != bucket.end(); ++taskit) {
if (bld->id == taskit->first && index == taskit->second) {
auto task_bld_id = taskit->first;
auto task_job_item_idx = taskit->second;
bucket.erase(taskit);
bucket.emplace_front(task_bld_id, task_job_item_idx);
break;
}
}
}
}
}
DFHACK_PLUGIN_LUA_FUNCTIONS {
DFHACK_LUA_FUNCTION(printStatus),
DFHACK_LUA_FUNCTION(setSetting),
@ -589,5 +619,6 @@ DFHACK_PLUGIN_LUA_FUNCTIONS {
DFHACK_LUA_FUNCTION(countAvailableItems),
DFHACK_LUA_FUNCTION(getDescString),
DFHACK_LUA_FUNCTION(getQueuePosition),
DFHACK_LUA_FUNCTION(makeTopPriority),
DFHACK_LUA_END
};

@ -65,8 +65,10 @@ function get_job_item(btype, subtype, custom, index)
end
local reset_counts_flag = false
local reset_inspector_flag = false
function reset_counts()
reset_counts_flag = true
reset_inspector_flag = true
end
--------------------------------
@ -560,7 +562,7 @@ function InspectorLine:init()
self:addviews{
widgets.Label{
frame={t=0, l=0},
text={{text=function() return getDescString(dfhack.gui.getSelectedBuilding(), self.idx-1) end}},
text={{text=self:callback('get_desc_string')}},
},
widgets.Label{
frame={t=1, l=2},
@ -569,12 +571,24 @@ function InspectorLine:init()
}
end
function InspectorLine:get_desc_string()
if self.desc then return self.desc end
self.desc = getDescString(dfhack.gui.getSelectedBuilding(), self.idx-1)
return self.desc
end
function InspectorLine:get_status_line()
if self.status then return self.status end
local queue_pos = getQueuePosition(dfhack.gui.getSelectedBuilding(), self.idx-1)
if queue_pos <= 0 then
return 'Item attached'
end
return ('Position in line: %d'):format(queue_pos)
self.status = ('Position in line: %d'):format(queue_pos)
return self.status
end
function InspectorLine:reset()
self.status = nil
end
InspectorOverlay = defclass(InspectorOverlay, overlay.OverlayWidget)
@ -606,14 +620,31 @@ function InspectorOverlay:init()
frame={t=11, l=0},
label='make top priority',
key='CUSTOM_CTRL_T',
on_activate=self:callback('make_top_priority'),
},
}
end
function InspectorOverlay:reset()
self.subviews.item1:reset()
self.subviews.item2:reset()
self.subviews.item3:reset()
self.subviews.item4:reset()
reset_inspector_flag = false
end
function InspectorOverlay:make_top_priority()
makeTopPriority(dfhack.gui.getSelectedBuilding())
self:reset()
end
function InspectorOverlay:onInput(keys)
if not isPlannedBuilding(dfhack.gui.getSelectedBuilding()) then
return false
end
if keys._MOUSE_L_DOWN or keys._MOUSE_R_DOWN or keys.LEAVESCREEN then
self:reset()
end
return InspectorOverlay.super.onInput(self, keys)
end
@ -621,6 +652,9 @@ function InspectorOverlay:render(dc)
if not isPlannedBuilding(dfhack.gui.getSelectedBuilding()) then
return
end
if reset_inspector_flag then
self:reset()
end
InspectorOverlay.super.render(self, dc)
end