Various changes to advfort.lua

Add explicit [fallback] option to the workshop jobs when sometimes the hacky way fails.
Fix brewing accepting too many items instead of barrel.
Fix tallow making reaction.
Add a limited display of item filters when adding items in a job slot.
develop
Warmist 2016-05-22 18:04:56 +03:00
parent 6c64b3441d
commit c985cd6f1d
2 changed files with 64 additions and 18 deletions

@ -28,9 +28,10 @@ An example of player digging in adventure mode:
version: 0.05 version: 0.05
changelog: changelog:
*0.05 *0.05
- fixed some reactions not showing. Now there are duplicated reactions :/ - fixed some reactions not showing. Now there is a '[fallback]' choice to choose from other way of getting reactions.
- fixed brewing accepting too many items instead of barrel - fixed brewing accepting too many items instead of barrel
- fixed tallow making to accept fat - fixed tallow making to accept fat
- display filters
*0.044 *0.044
- added output to clear_jobs of number of cleared jobs - added output to clear_jobs of number of cleared jobs
- another failed attempt at gather plants fix - another failed attempt at gather plants fix
@ -1401,7 +1402,37 @@ function usetool:onWorkShopButtonClicked(building,index,choice)
self:openShopWindowButtoned(building,true) self:openShopWindowButtoned(building,true)
end end
end end
function usetool:openShopWindowFallback( building,list)
local open_window=false
if not list then --if list is not passed we are responsible for showing the menu
list={}
open_window=true
end
local filter_pile=workshopJobs.getJobs(building:getType(),building:getSubtype(),building:getCustomType())
local adv=df.global.world.units.active[0]
local state={unit=adv,from_pos={x=adv.pos.x,y=adv.pos.y, z=adv.pos.z},building=building
,screen=self,bld=building}
if filter_pile then
local count=0
state.common=filter_pile.common
for i,v in ipairs(filter_pile) do
local label=v.name:lower()
table.insert(list,{job_id=0,text=label,filter=v})
count=count+1
end
end
if open_window then
dialog.showListPrompt("Workshop job choice", "Choose what to make",
COLOR_WHITE,list,
function (index,choice)
onWorkShopJobChosen(state,index,choice)
end
,nil, nil,true)
end
end
--no reset here means that the button opens submenu
function usetool:openShopWindowButtoned(building,no_reset) function usetool:openShopWindowButtoned(building,no_reset)
self:setupFields() self:setupFields()
local wui=df.global.ui_sidebar_menus.workshop_job local wui=df.global.ui_sidebar_menus.workshop_job
@ -1421,29 +1452,25 @@ function usetool:openShopWindowButtoned(building,no_reset)
table.insert(list,{text=label,button=choice,is_button=true}) table.insert(list,{text=label,button=choice,is_button=true})
names_already_in[label]=true names_already_in[label]=true
end end
--add fallback list if for some reason df does not make the buttons if #list==0 then
local filter_pile=workshopJobs.getJobs(building:getType(),building:getSubtype(),building:getCustomType()) --we couldn't use the df hack so let's fill the list from fallback
local adv=df.global.world.units.active[0] self:openShopWindowFallback(building,list)
local state={unit=adv,from_pos={x=adv.pos.x,y=adv.pos.y, z=adv.pos.z},building=building else
,screen=self,bld=building} --the hack worked. Though we are not sure how well so let's add a button for fallback
if filter_pile and not no_reset then table.insert(list,{text='[fallback]'})
local count=0
state.common=filter_pile.common
for i,v in ipairs(filter_pile) do
local label=v.name:lower()
if not names_already_in[label] then
table.insert(list,{job_id=0,text=label,filter=v})
count=count+1
end
end
print("Added:",count," non-button jobs")
end end
if #list==0 then if #list==0 then
qerror("no jobs for this shop") qerror("no jobs for this shop")
end end
dialog.showListPrompt("Workshop job choice", "Choose what to make", dialog.showListPrompt("Workshop job choice", "Choose what to make",
COLOR_WHITE,list, COLOR_WHITE,list,
function (index,choice) function (index,choice)
if choice.text=="[fallback]" then
self:openShopWindowFallback(building)
return
end
if choice.is_button then if choice.is_button then
self:onWorkShopButtonClicked(building,index,choice) self:onWorkShopButtonClicked(building,index,choice)
else else

@ -100,6 +100,25 @@ function jobitemEditor:can_remove()
local slot=self:get_slot() local slot=self:get_slot()
return #slot.items>0 return #slot.items>0
end end
function jobitemEditor:get_item_filters( job_item )
local true_flags={}
for k,v in pairs(job_item.flags1) do
if v then
table.insert(true_flags,k)
end
end
for k,v in pairs(job_item.flags2) do
if v then
table.insert(true_flags,k)
end
end
for k,v in pairs(job_item.flags3) do
if v then
table.insert(true_flags,k)
end
end
return table.concat(true_flags,"\n")
end
function jobitemEditor:add_item() function jobitemEditor:add_item()
local cur_slot=self:get_slot() local cur_slot=self:get_slot()
local choices={} local choices={}
@ -110,7 +129,7 @@ function jobitemEditor:add_item()
end end
end end
gscript.start(function () gscript.start(function ()
local _,_2,choice=gscript.showListPrompt("which item?", "Select item", COLOR_WHITE, choices) local _,_2,choice=gscript.showListPrompt("which item?", "Select item\nItem filters:\n"..self:get_item_filters(cur_slot.job_item), COLOR_WHITE, choices)
if choice ~= nil and choice.item~=nil then if choice ~= nil and choice.item~=nil then
self:add_item_to_slot(cur_slot,choice.item) self:add_item_to_slot(cur_slot,choice.item)
end end