public void Call(Type type, Button target) { ButtonEventHandlerDictionary dict = null; switch (type) { case Type.LOAD: dict = load; break; case Type.UNLOAD: dict = unload; break; case Type.ENTERFRAME: dict = enterFrame; break; case Type.UPDATE: dict = update; break; case Type.RENDER: dict = render; break; case Type.PRESS: dict = press; break; case Type.RELEASE: dict = release; break; case Type.ROLLOVER: dict = rollOver; break; case Type.ROLLOUT: dict = rollOut; break; } if (dict != null) { dict = new ButtonEventHandlerDictionary(dict); foreach (var h in dict) { h.Value(target); } } }
public ButtonEventHandlers() { load = new ButtonEventHandlerDictionary(); unload = new ButtonEventHandlerDictionary(); enterFrame = new ButtonEventHandlerDictionary(); update = new ButtonEventHandlerDictionary(); render = new ButtonEventHandlerDictionary(); press = new ButtonEventHandlerDictionary(); release = new ButtonEventHandlerDictionary(); rollOver = new ButtonEventHandlerDictionary(); rollOut = new ButtonEventHandlerDictionary(); keyPress = new ButtonKeyPressHandlerDictionary(); }
public int AddButtonEventHandlerLua() { if (luaState == null) return 0; Lua.lua_State l = (Lua.lua_State)luaState; string instanceName; ButtonEventHandlerDictionary handlers = new ButtonEventHandlerDictionary() { {"load", null}, {"unload", null}, {"enterFrame", null}, {"update", null}, {"render", null}, {"press", null}, {"release", null}, {"rollOver", null}, {"rollOut", null}, {"keyPress", null} }; int handlerId; /* 1: LWF_LWF instance */ /* 2: instanceName:string */ /* 3: table {key:string, handler:function} */ instanceName = Lua.lua_tostring(l, 2).ToString(); Lua.lua_getglobal(l, "LWF"); /* -1: LWF */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, "Instances"); /* -2: LWF */ /* -1: LWF.Instances */ Lua.lua_remove(l, -2); /* -1: LWF.Instances */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, instanceIdString); /* -2: LWF.Instances */ /* -1: LWF.Instances.<instanceId> */ Lua.lua_remove(l, -2); /* -1: LWF.Instances.<instanceId> */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, "Handlers"); /* -2: LWF.Instances.<instanceId> */ /* -1: LWF.Instances.<instanceId>.Handlers */ Lua.lua_remove(l, -2); /* -1: LWF.Instances.<instanceId>.Handlers */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_pushnil(l); /* -2: LWF.Instances.<instanceId>.Handlers */ /* -1: nil */ while (Lua.lua_next(l, 3)!=0) { /* -3: LWF.Instances.<instanceId>.Handlers */ /* -2: key: eventName string */ /* -1: value: handler function */ string key = Lua.lua_tostring(l, -2).ToString(); if (key != null && Lua.lua_isfunction(l, -1)) { int luaHandlerId = GetEventOffset(); handlers[key] = (Button a) => { if (!a.lwf.PushHandlerLua(luaHandlerId)) return; /* -1: function */ Lua.lua_State ls = (Lua.lua_State)a.lwf.luaState; Luna_LWF_Button.push(ls, a, false); /* -2: function */ /* -1: Movie or Button */ if (Lua.lua_pcall(ls, 1, 0, 0)!=0) Lua.lua_pop(ls, 1); /* 0 */ }; Lua.lua_setfield(l, -3, luaHandlerId.ToString()); /* LWF.Instances.<instanceId>.Handlers.<luaHandlerId> = function */ /* -2: LWF.Instances.<instanceId>.Handlers */ /* -1: key */ } else { Lua.lua_pop(l, 2); /* 0 */ goto error; } } /* -1: LWF.Instances.<instanceId>.Handlers */ Lua.lua_pop(l, 1); /* 0 */ handlerId = AddButtonEventHandler(instanceName, handlers["load"], handlers["unload"], handlers["enterFrame"], handlers["update"], handlers["render"], handlers["press"], handlers["release"], handlers["rollOver"], handlers["rollOut"]); Lua.lua_pushnumber(l, handlerId); /* handlerId */ return 1; error: Lua.lua_pushnumber(l, -1); /* -1: -1 */ return 1; }
public int AddButtonEventHandlerLua() { if (luaState == null) { return(0); } Lua.lua_State l = (Lua.lua_State)luaState; string instanceName; ButtonEventHandlerDictionary handlers = new ButtonEventHandlerDictionary() { { "load", null }, { "unload", null }, { "enterFrame", null }, { "update", null }, { "render", null }, { "press", null }, { "release", null }, { "rollOver", null }, { "rollOut", null }, { "keyPress", null } }; int handlerId; /* 1: LWF_LWF instance */ /* 2: instanceName:string */ /* 3: table {key:string, handler:function} */ instanceName = Lua.lua_tostring(l, 2).ToString(); Lua.lua_getglobal(l, "LWF"); /* -1: LWF */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, "Instances"); /* -2: LWF */ /* -1: LWF.Instances */ Lua.lua_remove(l, -2); /* -1: LWF.Instances */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, instanceIdString); /* -2: LWF.Instances */ /* -1: LWF.Instances.<instanceId> */ Lua.lua_remove(l, -2); /* -1: LWF.Instances.<instanceId> */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, "Handlers"); /* -2: LWF.Instances.<instanceId> */ /* -1: LWF.Instances.<instanceId>.Handlers */ Lua.lua_remove(l, -2); /* -1: LWF.Instances.<instanceId>.Handlers */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_pushnil(l); /* -2: LWF.Instances.<instanceId>.Handlers */ /* -1: nil */ while (Lua.lua_next(l, 3) != 0) { /* -3: LWF.Instances.<instanceId>.Handlers */ /* -2: key: eventName string */ /* -1: value: handler function */ string key = Lua.lua_tostring(l, -2).ToString(); if (key != null && Lua.lua_isfunction(l, -1)) { int luaHandlerId = GetEventOffset(); handlers[key] = (Button a) => { if (!a.lwf.PushHandlerLua(luaHandlerId)) { return; } /* -1: function */ Lua.lua_State ls = (Lua.lua_State)a.lwf.luaState; Luna_LWF_Button.push(ls, a, false); /* -2: function */ /* -1: Movie or Button */ if (Lua.lua_pcall(ls, 1, 0, 0) != 0) { Lua.lua_pop(ls, 1); } /* 0 */ }; Lua.lua_setfield(l, -3, luaHandlerId.ToString()); /* LWF.Instances.<instanceId>.Handlers.<luaHandlerId> = function */ /* -2: LWF.Instances.<instanceId>.Handlers */ /* -1: key */ } else { Lua.lua_pop(l, 2); /* 0 */ goto error; } } /* -1: LWF.Instances.<instanceId>.Handlers */ Lua.lua_pop(l, 1); /* 0 */ handlerId = AddButtonEventHandler(instanceName, handlers["load"], handlers["unload"], handlers["enterFrame"], handlers["update"], handlers["render"], handlers["press"], handlers["release"], handlers["rollOver"], handlers["rollOut"]); Lua.lua_pushnumber(l, handlerId); /* handlerId */ return(1); error: Lua.lua_pushnumber(l, -1); /* -1: -1 */ return(1); }
public void Call(Type type, Button target) { ButtonEventHandlerDictionary dict = null; switch (type) { case Type.LOAD: dict = load; break; case Type.UNLOAD: dict = unload; break; case Type.ENTERFRAME: dict = enterFrame; break; case Type.UPDATE: dict = update; break; case Type.RENDER: dict = render; break; case Type.PRESS: dict = press; break; case Type.RELEASE: dict = release; break; case Type.ROLLOVER: dict = rollOver; break; case Type.ROLLOUT: dict = rollOut; break; } if (dict != null) { dict = new ButtonEventHandlerDictionary(dict); foreach (var h in dict) h.Value(target); } }