local _ENV = mkmodule('hack.scripts.gui.advfort_items') local gui=require('gui') local wid=require('gui.widgets') local gscript=require('gui.script') jobitemEditor=defclass(jobitemEditor,gui.FramedScreen) jobitemEditor.ATTRS{ frame_style = gui.GREY_LINE_FRAME, frame_inset = 1, allow_add=false, allow_remove=false, allow_any_item=false, job=DEFAULT_NIL, job_items=DEFAULT_NIL, items=DEFAULT_NIL, on_okay=DEFAULT_NIL, autofill=true, } function update_slot_text(slot) local items="" for i,v in ipairs(slot.items) do items=items.." "..dfhack.items.getDescription(v,0) if i~=#slot.items then items=items.."," end end slot.text=string.format("%02d. Filled(%d/%d):%s",slot.id+1,slot.filled_amount,slot.job_item.quantity,items) end --items-> table => key-> id of job.job_items, value-> table => key (num), value => item(ref) function jobitemEditor:init(args) --self.job=args.job if self.job==nil and self.job_items==nil then qerror("This screen must have job target or job_items list") end if self.items==nil then qerror("This screen must have item list") end self:addviews{ wid.Label{ view_id = 'label', text = args.prompt, text_pen = args.text_pen, frame = { l = 0, t = 0 }, }, wid.List{ view_id = 'itemList', frame = { l = 0, t = 2 ,b=2}, }, wid.Label{ frame = { b=1,l=1}, text ={{text= ": cancel", key = "LEAVESCREEN", on_activate= self:callback("dismiss") }, { gap=3, text= ": accept", key = "SEC_SELECT", on_activate= self:callback("commit"), enabled=self:callback("jobValid") }, { gap=3, text= ": add", key = "CUSTOM_A", enabled=self:callback("can_add"), on_activate= self:callback("add_item") }, { gap=3, text= ": remove", key = "CUSTOM_R", enabled=self:callback("can_remove"), on_activate= self:callback("remove_item") },} }, } self.assigned={} self:fill() if self.autofill then self:fill_slots() end end function jobitemEditor:get_slot() local idx,choice=self.subviews.itemList:getSelected() return choice end function jobitemEditor:can_add() local slot=self:get_slot() return slot.filled_amount0 end function jobitemEditor:add_item() local cur_slot=self:get_slot() local choices={} table.insert(choices,{text=""}) for k,v in pairs(cur_slot.choices) do if not self.assigned[v.id] then table.insert(choices,{text=dfhack.items.getDescription(v,0),item=v}) end end gscript.start(function () local _,_2,choice=gscript.showListPrompt("which item?", "Select item", COLOR_WHITE, choices) if choice ~= nil and choice.item~=nil then self:add_item_to_slot(cur_slot,choice.item) end end ) end function jobitemEditor:fill_slots() for i,v in ipairs(self.slots) do while v.filled_amount