From c985cd6f1d65a07e809beb3cde5358a6b361dcca Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 22 May 2016 18:04:56 +0300 Subject: [PATCH] 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. --- scripts/gui/advfort.lua | 61 +++++++++++++++++++++++++---------- scripts/gui/advfort_items.lua | 21 +++++++++++- 2 files changed, 64 insertions(+), 18 deletions(-) diff --git a/scripts/gui/advfort.lua b/scripts/gui/advfort.lua index 0733e88a2..4f18d071b 100644 --- a/scripts/gui/advfort.lua +++ b/scripts/gui/advfort.lua @@ -28,9 +28,10 @@ An example of player digging in adventure mode: version: 0.05 changelog: *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 tallow making to accept fat + - display filters *0.044 - added output to clear_jobs of number of cleared jobs - another failed attempt at gather plants fix @@ -1401,7 +1402,37 @@ function usetool:onWorkShopButtonClicked(building,index,choice) self:openShopWindowButtoned(building,true) 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) self:setupFields() 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}) names_already_in[label]=true end - --add fallback list if for some reason df does not make the buttons - 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 and not no_reset then - 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") + if #list==0 then + --we couldn't use the df hack so let's fill the list from fallback + self:openShopWindowFallback(building,list) + else + --the hack worked. Though we are not sure how well so let's add a button for fallback + table.insert(list,{text='[fallback]'}) end + if #list==0 then qerror("no jobs for this shop") end + dialog.showListPrompt("Workshop job choice", "Choose what to make", COLOR_WHITE,list, function (index,choice) + if choice.text=="[fallback]" then + self:openShopWindowFallback(building) + return + end if choice.is_button then self:onWorkShopButtonClicked(building,index,choice) else diff --git a/scripts/gui/advfort_items.lua b/scripts/gui/advfort_items.lua index befb12ef5..4cc05da72 100644 --- a/scripts/gui/advfort_items.lua +++ b/scripts/gui/advfort_items.lua @@ -100,6 +100,25 @@ function jobitemEditor:can_remove() local slot=self:get_slot() return #slot.items>0 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() local cur_slot=self:get_slot() local choices={} @@ -110,7 +129,7 @@ function jobitemEditor:add_item() end end 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 self:add_item_to_slot(cur_slot,choice.item) end