Reactionhooks more usefull and gm-editor minor tweaks (e.g. search in containers)

develop
Warmist 2012-10-07 20:44:18 +03:00
parent ddc83a0a72
commit 923ea3f4b0
3 changed files with 42 additions and 3 deletions

@ -472,3 +472,18 @@ namespace DFHack {namespace Lua {
name##_event.invoke(out, 5); \
} \
}
#define DEFINE_LUA_EVENT_6(name, handler, arg_type1, arg_type2, arg_type3, arg_type4, arg_type5,arg_type6) \
static DFHack::Lua::Notification name##_event(df::wrap_function(handler, true)); \
void name(color_ostream &out, arg_type1 arg1, arg_type2 arg2, arg_type3 arg3, arg_type4 arg4,arg_type5 arg5, arg_type6 arg6) { \
handler(out, arg1, arg2, arg3, arg4, arg5, arg6); \
if (auto state = name##_event.state_if_count()) { \
DFHack::Lua::Push(state, arg1); \
DFHack::Lua::Push(state, arg2); \
DFHack::Lua::Push(state, arg3); \
DFHack::Lua::Push(state, arg4); \
DFHack::Lua::Push(state, arg5); \
DFHack::Lua::Push(state, arg6); \
name##_event.invoke(out, 6); \
} \
}

@ -184,9 +184,10 @@ df::item* find_item(
return NULL;
}
static void handle_reaction_done(color_ostream &out, df::unit *unit, std::vector<df::item*> *in_items, std::vector<df::item*> *out_items,bool *call_native){};
static void handle_reaction_done(color_ostream &out,df::reaction*, df::unit *unit, std::vector<df::item*> *in_items,std::vector<df::reaction_reagent*> *in_reag
, std::vector<df::item*> *out_items,bool *call_native){};
DEFINE_LUA_EVENT_4(onReactionComplete, handle_reaction_done, df::unit *, std::vector<df::item*> *,std::vector<df::item*> *,bool *);
DEFINE_LUA_EVENT_6(onReactionComplete, handle_reaction_done,df::reaction*, df::unit *, std::vector<df::item*> *,std::vector<df::reaction_reagent*> *,std::vector<df::item*> *,bool *);
DFHACK_PLUGIN_LUA_EVENTS {
@ -207,9 +208,11 @@ struct product_hook : item_product {
) {
if (auto product = products[this])
{
df::reaction* this_reaction=product->react;
CoreSuspendClaimer suspend;
color_ostream_proxy out(Core::getInstance().getConsole());
bool call_native=true;
onReactionComplete(out,unit,in_items,out_items,&call_native);
onReactionComplete(out,this_reaction,unit,in_items,in_reag,out_items,&call_native);
if(!call_native)
return;
}

@ -45,6 +45,25 @@ function GmEditorUi:init(args)
return self
end
function GmEditorUi:find(test)
local trg=self:currentTarget()
if trg.target and trg.target._kind and trg.target._kind=="container" then
if test== nil then
dialog.showInputPrompt("Test function","Input function that tests(k,v as argument):",COLOR_WHITE,"",dfhack.curry(self.find,self))
return
end
local e,what=load("return function(k,v) return "..test.." end")
if e==nil then
dialog.showMessage("Error!","function failed to compile\n"..what,COLOR_RED)
end
for k,v in pairs(trg.target) do
if e()(k,v)==true then
self:pushTarget(v)
return
end
end
end
end
function GmEditorUi:insertNew(typename)
local tp=typename
if typename== nil then
@ -165,6 +184,8 @@ end
self:changeSelected(10)
elseif keys.SELECT then
self:editSelected()
elseif keys.CUSTOM_ALT_F then
self:find()
elseif keys.CUSTOM_ALT_E then
--self:specialEditor()
elseif keys.CUSTOM_ALT_I then --insert