eventful: added support for custom workshops and a convenience function to interpose side panel generation

develop
Warmist 2014-01-07 18:15:49 +02:00
parent 834350012f
commit a52451a97a
2 changed files with 21 additions and 4 deletions

@ -25,13 +25,13 @@ local function getShopName(btype,bsubtype,bcustom)
if typenames_shop[bsubtype]~=nil then
return typenames_shop[bsubtype]
else
return nil --todo add custom (not very useful)
return df.building_def_workshopst.find(bcustom).code
end
elseif btype==df.building_type.Furnace then
if typenames_furnace[bsubtype]~=nil then
return typenames_furnace[bsubtype]
else
return nil --todo add custom (not very useful)
return df.building_def_furnacest.find(bcustom).code
end
end
end
@ -77,9 +77,19 @@ local function onPostSidebar(workshop)
wjob.choices_visible:insert("#",new_button)
end
end
if _registeredStuff.customSidebar and _registeredStuff.customSidebar[shop_id] then
_registeredStuff.customSidebar[shop_id](workshop)
end
end
end
local function customSidebarsCallback(workshop)
local shop_id=getShopName(workshop:getType(),workshop:getSubtype(),workshop:getCustomType())
if shop_id then
if _registeredStuff.customSidebar and _registeredStuff.customSidebar[shop_id] then
_registeredStuff.customSidebar[shop_id](workshop)
end
end
end
function registerReaction(reaction_name,callback)
_registeredStuff.reactionCallbacks=_registeredStuff.reactionCallbacks or {}
_registeredStuff.reactionCallbacks[reaction_name]=callback
@ -87,6 +97,13 @@ function registerReaction(reaction_name,callback)
dfhack.onStateChange.eventful=unregall
end
function registerSidebar(shop_name,callback)
_registeredStuff.customSidebar=_registeredStuff.customSidebar or {}
_registeredStuff.customSidebar[shop_name]=callback
onWorkshopFillSidebarMenu._library=customSidebarsCallback
dfhack.onStateChange.eventful=unregall
end
function removeNative(shop_name,name)
_registeredStuff.shopNonNative=_registeredStuff.shopNonNative or {}
local shops=_registeredStuff.shopNonNative

@ -880,7 +880,7 @@ function usetool:init(args)
wid.Label{
view_id="mainLabel",
frame = {xalign=0,yalign=0},
text={{key=keybinds.prevJob.key},{gap=1,text=dfhack.curry(usetool.getModeName,self)},{gap=1,key=keybinds.nextJob.key},
text={{key=keybinds.prevJob.key},{gap=1,text=self:callback("getModeName")},{gap=1,key=keybinds.nextJob.key},
}
},