Inheritance: LWF.IObject
Ejemplo n.º 1
0
        public Graphic(LWF lwf, Movie parent, int objId)
            : base(lwf, parent, Format.Object.Type.GRAPHIC, objId)
        {
            Format.Graphic data = lwf.data.graphics[objId];
            int n = data.graphicObjects;
            m_displayList = new Object[n];

            Format.GraphicObject[] graphicObjects = lwf.data.graphicObjects;
            for (int i = 0; i < n; ++i) {
            Format.GraphicObject gobj =
                graphicObjects[data.graphicObjectId + i];
            Object obj = null;
            int graphicObjectId = gobj.graphicObjectId;

            // Ignore error
            if (graphicObjectId == -1)
                continue;

            switch ((Type)gobj.graphicObjectType) {
            case Type.BITMAP:
                obj = new Bitmap(lwf, parent, graphicObjectId);
                break;

            case Type.BITMAPEX:
                obj = new BitmapEx(lwf, parent, graphicObjectId);
                break;

            case Type.TEXT:
                obj = new Text(lwf, parent, graphicObjectId);
                break;
            }

            m_displayList[i] = obj;
            }
        }
Ejemplo n.º 2
0
    // use lunaStack::push if possible.
    public static void push(Lua.lua_State L, LWF.Movie obj, bool gc, Lua.CharPtr metatable = null)
    {
        int objectId = -1;

        if (!objectIdentifiers[L].TryGetValue(obj, out objectId))
        {
            objectId = idOffset++;
            objectIdentifiers[L].Add(obj, objectId);
            objects[L].Add(objectId, obj);
        }

        if (metatable == null)
        {
            metatable = LunaTraits_LWF_Movie.className;
        }
        Lua.lua_pushstring(L, "__luna");
        Lua.lua_gettable(L, Lua.LUA_GLOBALSINDEX);
        int __luna = Lua.lua_gettop(L);

        Luna.userdataType ud = new Luna.userdataType(
            objectId: objectId,  // store object in userdata
            gc: gc,              // collect garbage
            has_env: false,      // does this userdata has a table attached to it?
            typeId: LunaTraits_LWF_Movie.uniqueID
            );

        ud.ToBytes((byte[])Lua.lua_newuserdata(L, Luna.userdataType.Size));

        Lua.lua_pushstring(L, metatable);
        Lua.lua_gettable(L, __luna);
        Lua.lua_setmetatable(L, -2);
        //Luna.printStack(L);
        Lua.lua_insert(L, -2);          // swap __luna and userdata
        Lua.lua_pop(L, 1);
    }
Ejemplo n.º 3
0
    public void AddMovieLoadHandler(
        string instanceName, MovieEventHandler handler, bool immortal = false)
    {
        AddLoadCallback((o) => {
            HandlerWrapper w    = new HandlerWrapper();
            MovieEventHandler h = (m) => {
                if (!immortal)
                {
                    lwf.RemoveMovieEventHandler(instanceName, w.id);
                }
                handler(m);
            };

            LWF.Movie movie = lwf[instanceName];
            if (movie != null)
            {
                handler(movie);
                if (immortal)
                {
                    w.id = lwf.AddMovieEventHandler(instanceName, load: h);
                }
            }
            else
            {
                w.id = lwf.AddMovieEventHandler(instanceName, load: h);
            }
        });
    }
Ejemplo n.º 4
0
    void OnGUI()
    {
        if (GUILayout.Button("Attach movie from library sprite"))
        {
            if (lwf != null)
            {
                // The linkage named "gree" is instantiated and attached to root movie.

                string    instance_name  = linkage_name + attach_count.ToString();
                LWF.Movie attached_movie =
                    lwf.rootMovie.AttachMovie(
                        linkage_name,                         // Symbol's linkage name in library
                        instance_name,                        // Attached movie name.
                        // NOTE: Atttached movie name should unique.
                        // If duplicated name is specified , new instance is not created and existing instance is returned.
                        enterFrame: enterFrameCallback                         // Callback that called every frame.
                        );


                if (attached_movie != null)
                {
                    // Randomize position
                    attached_movie.MoveTo(Random.Range(0, 500), Random.Range(0, 500));



                    // Increament count for unique attached movie name.
                    attach_count++;
                }
            }
        }


        GUILayout.Box(message);
    }
Ejemplo n.º 5
0
    public void AttachLWF(LWF.Movie movie, LWFObject lwfObject,
                          string attachName, int attachDepth   = -1, bool reorder = false,
                          LWFObjectDetachHandler detachHandler = null)
    {
        AddLoadCallback((o) => {
            lwfObject.AddLoadCallback((lo) => {
                movie.AttachLWF(lwfObject.lwf,
                                attachName, attachDepth, reorder, (attachedLWF) => {
                    if (detachHandler == null)
                    {
                        if (lwfObject.isAlive)
                        {
                            Destroy(lwfObject.gameObject);
                        }
                    }
                    else
                    {
                        if (detachHandler(lwfObject) && lwfObject.isAlive)
                        {
                            Destroy(lwfObject.gameObject);
                        }
                    }
                });

                lwfObject.callUpdate = false;

                Transform transform     = lwfObject.gameObject.transform;
                transform.parent        = lwfObject.transform;
                transform.localPosition = Vector3.zero;
                transform.localRotation = Quaternion.identity;
                transform.localScale    = Vector3.one;
            });
        });
    }
Ejemplo n.º 6
0
	public static void SyncMatrix(Movie movie)
	{
		int matrixId = movie.matrixId;
		float scaleX = 1;
		float scaleY = 1;
		float rotation = 0;
		Matrix matrix;
		if ((matrixId & (int)Constant.MATRIX_FLAG) == 0) {
			Translate translate = movie.lwf.data.translates[matrixId];
			matrix = new Matrix(scaleX, scaleY,
				0, 0, translate.translateX, translate.translateY);
		} else {
			matrixId &= ~(int)Constant.MATRIX_FLAG_MASK;
			matrix = movie.lwf.data.matrices[matrixId];
			bool md = GetMatrixDeterminant(matrix);
			scaleX = (float)Math.Sqrt(
				matrix.scaleX * matrix.scaleX + matrix.skew1 * matrix.skew1);
			if (md)
				scaleX = -scaleX;
			scaleY = (float)Math.Sqrt(
				matrix.scaleY * matrix.scaleY + matrix.skew0 * matrix.skew0);
			if (md)
				rotation = (float)Math.Atan2(matrix.skew1, -matrix.scaleX);
			else
				rotation = (float)Math.Atan2(matrix.skew1, matrix.scaleX);
			rotation = rotation / (float)Math.PI * 180.0f;
		}

		movie.SetMatrix(matrix, scaleX, scaleY, rotation);
	}
Ejemplo n.º 7
0
    }                               // hide default constructor

    // create a new T object and
    // push onto the Lua stack a userdata containing a pointer to T object
    private static int new_T(Lua.lua_State L)
    {
        Lua.lua_remove(L, 1);                               // use classname:new(), instead of classname.new()
        LWF.Movie obj = LunaTraits_LWF_Movie._bind_ctor(L); // call constructor for T objects
        push(L, obj, true);
        return(1);                                          // userdata containing pointer to T object
    }
Ejemplo n.º 8
0
    void OnGUI()
    {
        if (GUILayout.Button("Attach movie from movie"))
        {
            if (lwf != null)
            {
                // The linkage named "gree" is instantiated and attached to root movie.
                LWF.Movie attached_movie =
                    lwf.rootMovie.AttachMovie(
                        "gree",                                   // Symbol's linkage name in library
                        "attached_gree" + attach_count.ToString() // Attached movie name.
                        // NOTE: Atttached movie name should unique.
                        // If duplicated name is specified , new instance is not created and existing instance is returned.
                        );

                if (attached_movie != null)
                {
                    // Randomize position
                    attached_movie.MoveTo(Random.Range(0, 500), Random.Range(0, 500));

                    // Increament count for unique attached movie name.
                    attach_count++;
                }
            }
        }
    }
Ejemplo n.º 9
0
 void enterFrameCallback(LWF.Movie movie)
 {
     if (movie.currentFrame == movie.totalFrames ||
         !movie.playing)
     {
         message += movie.GetFullName() + " is done \n";
         lwf.rootMovie.DetachMovie(movie);
     }
 }
Ejemplo n.º 10
0
    public void DetachLWF(LWF.Movie movie, string attachName)
    {
        if (movie == null)
        {
            return;
        }

        movie.DetachLWF(attachName);
    }
Ejemplo n.º 11
0
    public void DetachAllLWFs(LWF.Movie movie)
    {
        if (movie == null)
        {
            return;
        }

        movie.DetachAllLWFs();
    }
Ejemplo n.º 12
0
    public void DetachLWF(LWF.Movie movie, LWFObject lwfObject)
    {
        if (movie == null)
        {
            return;
        }

        movie.DetachLWF(lwfObject.lwf);
    }
Ejemplo n.º 13
0
	public ProgramObject(LWF lwf, Movie parent, int objId)
		: base(lwf, parent, Format.Object.Type.PROGRAMOBJECT, objId)
	{
		Format.ProgramObject data = lwf.data.programObjects[objId];
		m_dataMatrixId = data.matrixId;
		ProgramObjectConstructor ctor = lwf.GetProgramObjectConstructor(objId);
		if (ctor != null)
			m_renderer = ctor(this, objId, data.width, data.height);
	}
Ejemplo n.º 14
0
    public static int _bind_gotoAndPlay_overload_2(Lua.lua_State L)
    {
        LWF.Movie self    = Luna_LWF_Movie.check(L, 1);
        int       frameNo = (int)Lua.lua_tonumber(L, 2);

        try {
            self.GotoAndPlay(frameNo);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
Ejemplo n.º 15
0
    public static int _bind_gotoAndPlay_overload_1(Lua.lua_State L)
    {
        LWF.Movie self  = Luna_LWF_Movie.check(L, 1);
        string    label = Lua.lua_tostring(L, 2).ToString();

        try {
            self.GotoAndPlay(label);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
Ejemplo n.º 16
0
    public static void Destroy(Lua.lua_State L, LWF.Movie obj)
    {
        int objectId = -1;

        if (objectIdentifiers[L].TryGetValue(obj, out objectId))
        {
            objectIdentifiers[L].Remove(obj);
            objects[L].Remove(objectId);
        }
    }
Ejemplo n.º 17
0
 public Object(LWF lwf, Movie parent, Type type, int objId)
 {
     m_lwf = lwf;
     m_parent = parent;
     m_type = type;
     m_objectId = objId;
     m_matrix = new Matrix();
     m_colorTransform = new ColorTransform();
     m_execCount = 0;
 }
Ejemplo n.º 18
0
	public static float GetY(Movie movie)
	{
		int matrixId = movie.matrixId;
		if ((matrixId & (int)Constant.MATRIX_FLAG) == 0) {
			Translate translate = movie.lwf.data.translates[matrixId];
			return translate.translateY;
		} else {
			matrixId &= ~(int)Constant.MATRIX_FLAG_MASK;
			Matrix matrix = movie.lwf.data.matrices[matrixId];
			return matrix.translateY;
		}
	}
Ejemplo n.º 19
0
	public int SearchFrame(Movie movie, int stringId)
	{
		if (stringId < 0 || stringId >= m_data.strings.Length)
			return -1;

		int frameNo;
		Dictionary<int, int> labelMap = m_data.labelMap[movie.objectId];
		if (labelMap.TryGetValue(stringId, out frameNo))
			return frameNo + 1;
		else
			return -1;
	}
Ejemplo n.º 20
0
 public void AddMovieLoadHandler(
     string instanceName, MovieEventHandler handler)
 {
     AddLoadCallback((o) => {
         lwf.AddMovieEventHandler(instanceName, load: handler);
         LWF.Movie movie = lwf[instanceName];
         if (movie != null)
         {
             handler(movie);
         }
     });
 }
Ejemplo n.º 21
0
 public static int _bind_getParent(Lua.lua_State L)
 {
     if (Lua.lua_gettop(L) != 1 || Luna.get_uniqueid(L, 1) !=
         LunaTraits_LWF_Movie.uniqueID)
     {
         Luna.printStack(L);
         Lua.luaL_error(L, "luna typecheck failed: LWF.Movie.parent");
     }
     LWF.Movie a =
         Luna_LWF_Movie.check(L, 1);
     Luna_LWF_Movie.push(L, a.parent, false);
     return(1);
 }
Ejemplo n.º 22
0
    private static int tostring_T(Lua.lua_State L)
    {
        Luna.userdataType ud  = (Luna.userdataType)Lua.lua_touserdata(L, 1);
        LWF.Movie         obj = null;
        if (!objects[L].TryGetValue(ud.ObjectId, out obj))
        {
            return(0);
        }

        char[] buff = obj.ToString().ToCharArray(0, 32);
        Lua.lua_pushfstring(L, "%s (%s)", new object[] { LunaTraits_LWF_Movie.className, buff });
        return(1);
    }
Ejemplo n.º 23
0
 public static int _bind_getBlue(Lua.lua_State L)
 {
     if (Lua.lua_gettop(L) != 1 ||
         Luna.get_uniqueid(L, 1) != 29625181)
     {
         Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:getBlue(LWF.Movie self ...)");
     }
     LWF.Movie o = Luna_LWF_Movie.check(L, 1);
     try {
         float ret = getBlue(o);
         Lua.lua_pushnumber(L, ret);
     } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
     return(1);
 }
Ejemplo n.º 24
0
    public static int _bind_prevFrame(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 1 ||
            Luna.get_uniqueid(L, 1) != 29625181)
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:prevFrame(LWF.Movie self)");
        }

        LWF.Movie self = Luna_LWF_Movie.check(L, 1);
        try {
            self.PrevFrame();
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
Ejemplo n.º 25
0
	public Object(LWF lwf, Movie parent, Type type, int objId)
	{
		m_lwf = lwf;
		m_parent = parent;
		m_type = type;
		m_objectId = objId;
		m_matrixId = -1;
		m_colorTransformId = -1;
		m_matrixIdChanged = true;
		m_colorTransformIdChanged = true;
		m_matrix = new Matrix(0, 0, 0, 0, 0, 0);
		m_colorTransform = new ColorTransform(0, 0, 0, 0);
		m_execCount = 0;
		m_updated = false;
	}
Ejemplo n.º 26
0
    public static int __index(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) == 2 && Luna.get_uniqueid(L, 1) ==
            LunaTraits_LWF_Movie.uniqueID)
        {
            LWF.Movie o =
                Luna_LWF_Movie.check(L, 1);
            string name = Lua.lua_tostring(L, 2).ToString();
            if (o.lwf.GetFieldLua(o, name))
            {
                return(1);
            }
            LWF.Movie movie = o.SearchMovieInstance(name, false);
            if (movie != null)
            {
                Lua.lua_pop(L, 1);
                Luna_LWF_Movie.push(L, movie, false);
                return(1);
            }
            LWF.Button button = o.SearchButtonInstance(name, false);
            if (button != null)
            {
                Lua.lua_pop(L, 1);
                Luna_LWF_Button.push(L, button, false);
                return(1);
            }
        }


        {
            Lua.lua_CFunction fnc = null;
            if (LunaTraits_LWF_Movie.properties.TryGetValue(Lua.lua_tostring(L, 2).ToString(), out fnc))
            {
                Lua.lua_pop(L, 1);                // remove self
                return(fnc(L));
            }
        }

        int mt = Lua.lua_getmetatable(L, 1);

        if (mt == 0)
        {
            Lua.luaL_error(L, "__index");             //end
        }
        Lua.lua_pushstring(L, Lua.lua_tostring(L, 2));
        Lua.lua_rawget(L, -2);
        return(1);
    }
Ejemplo n.º 27
0
        public Button(LWF lwf, Movie parent, int objId, int instId)
            : base(lwf, parent, Format.Object.Type.BUTTON, objId, instId)
        {
            m_invert = new Matrix();
            m_hitX = Int32.MinValue;
            m_hitY = Int32.MinValue;

            if (objId >= 0) {
            m_data = lwf.data.buttons[objId];
            m_dataMatrixId = m_data.matrixId;
            }

            m_handler = lwf.GetButtonEventHandlers(this);
            if (m_handler != null && m_handler.load != null)
            m_handler.load(this);
        }
Ejemplo n.º 28
0
    public static int _bind_setVisible(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 2 ||
            Luna.get_uniqueid(L, 1) != 29625181 ||
            Lua.lua_isboolean(L, 2))
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:setVisible(LWF.Movie self ...)");
        }
        LWF.Movie o = Luna_LWF_Movie.check(L, 1);
        bool      v = Lua.lua_toboolean(L, 2) != 0;

        try {
            setVisible(o, v);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
Ejemplo n.º 29
0
    public static int _bind_setBlue(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 2 ||
            Luna.get_uniqueid(L, 1) != 29625181 ||
            Lua.lua_isnumber(L, 2) == 0)
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:setBlue(LWF.Movie self ...)");
        }
        LWF.Movie o = Luna_LWF_Movie.check(L, 1);
        float     v = (float)Lua.lua_tonumber(L, 2);

        try {
            setBlue(o, v);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
Ejemplo n.º 30
0
    void OnGUI()
    {
        if (GUILayout.Button("Attach movie from library sprite"))
        {
            if (lwf != null)
            {
                // The linkage named "gree" is instantiated and attached to root movie.
                LWF.Movie attached_movie =
                    lwf.rootMovie.AttachMovie(
                        linkage_name,                                   // Symbol's linkage name in library
                        linkage_name + attached_movies.Count.ToString() // Attached movie name.
                        // NOTE: Atttached movie name should unique.
                        // If duplicated name is specified , new instance is not created and existing instance is returned.
                        );

                if (attached_movie != null)
                {
                    attached_movies.Add(attached_movie);

                    // Randomize position
                    attached_movie.MoveTo(
                        UnityEngine.Random.Range(0, 500),
                        UnityEngine.Random.Range(0, 500));
                }
            }
        }

        // Go to "action"
        if (GUILayout.Button("action"))
        {
            foreach (Movie attached_movie in attached_movies)
            {
                attached_movie.GotoLabel("action");
                attached_movie.Play();
            }
        }

        // Go back to "start"
        if (GUILayout.Button("start"))
        {
            foreach (Movie attached_movie in attached_movies)
            {
                attached_movie.GotoLabel("start");
                attached_movie.Play();
            }
        }
    }
Ejemplo n.º 31
0
    public static int _bind_localToGlobal(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 2 ||
            Luna.get_uniqueid(L, 1) != 29625181 ||
            Luna.get_uniqueid(L, 2) != LunaTraits_LWF_Point.uniqueID)
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:localToGlobal(LWF.Movie self)");
        }

        LWF.Movie self  = Luna_LWF_Movie.check(L, 1);
        LWF.Point point = Luna_LWF_Point.check(L, 2);
        try {
            LWF.Point ret = self.LocalToGlobal(point);
            Luna_LWF_Point.push(L, ret, true, "LWF_Point");
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(1);
    }
Ejemplo n.º 32
0
    public static int _bind_gotoFrame(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 2 ||
            Luna.get_uniqueid(L, 1) != 29625181 ||
            Lua.lua_isnumber(L, 2) == 0)
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:gotoFrame(LWF.Movie self)");
        }

        LWF.Movie self    = Luna_LWF_Movie.check(L, 1);
        int       frameNo = (int)Lua.lua_tonumber(L, 2);

        try {
            self.GotoFrame(frameNo);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
Ejemplo n.º 33
0
    // garbage collection metamethod
    private static int gc_T(Lua.lua_State L)
    {
        Luna.userdataType ud = (Luna.userdataType)Lua.lua_touserdata(L, 1);

        LWF.Movie obj = null;
        if (!objects[L].TryGetValue(ud.ObjectId, out obj))
        {
            return(0);
        }

        if (ud.Gc)
        {
            LunaTraits_LWF_Movie._bind_dtor(obj);              // call constructor for T objects
        }
        Destroy(L, obj);
        return(0);
    }
Ejemplo n.º 34
0
    public static int _bind_scaleTo(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 3 ||
            Luna.get_uniqueid(L, 1) != 29625181 ||
            Lua.lua_isnumber(L, 2) == 0 ||
            Lua.lua_isnumber(L, 3) == 0)
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:scaleTo(LWF.Movie self)");
        }

        LWF.Movie self = Luna_LWF_Movie.check(L, 1);
        float     vx   = (float)Lua.lua_tonumber(L, 2);
        float     vy   = (float)Lua.lua_tonumber(L, 3);

        try {
            self.ScaleTo(vx, vy);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
Ejemplo n.º 35
0
 static public LWF.Movie check(Lua.lua_State L, int narg)
 {
     byte[] d = (byte[])Lua.lua_touserdata(L, narg);
     if (d == null)
     {
         Luna.print("checkRaw: ud==nil\n"); Lua.luaL_typerror(L, narg, LunaTraits_LWF_Movie.className);
     }
     Luna.userdataType ud = new Luna.userdataType(d);
     if (ud.TypeId != LunaTraits_LWF_Movie.uniqueID)       // type checking with almost no overhead
     {
         Luna.print(String.Format("ud.uid: {0} != interface::uid : {1}\n", ud.TypeId, LunaTraits_LWF_Movie.uniqueID));
         Lua.luaL_typerror(L, narg, LunaTraits_LWF_Movie.className);
     }
     LWF.Movie obj = null;
     if (!objects[L].TryGetValue(ud.ObjectId, out obj))
     {
         return(null);
     }
     return(obj);
 }
Ejemplo n.º 36
0
        public Button(LWF lwf, Movie parent, int objId, int instId,
			int matrixId = -1, int colorTransformId = -1)
            : base(lwf, parent, Format.Object.Type.BUTTON, objId, instId)
        {
            m_matrixId = matrixId;
            m_colorTransformId = colorTransformId;

            m_invert = new Matrix();
            m_hitX = Int32.MinValue;
            m_hitY = Int32.MinValue;

            if (objId >= 0) {
            m_data = lwf.data.buttons[objId];
            m_dataMatrixId = m_data.matrixId;
            }

            m_handler = lwf.GetButtonEventHandlers(this);
            if (m_handler != null)
            m_handler.Call(EventType.LOAD, this);
        }
Ejemplo n.º 37
0
        public IObject(LWF lwf,
			Movie parent, Type type, int objId, int instId)
            : base(lwf, parent, type, objId)
        {
            m_prevInstance = null;
            m_nextInstance = null;
            m_linkInstance = null;

            m_instanceId =
            (instId >= lwf.data.instanceNames.Length) ? -1 : (int)instId;

            if (m_instanceId >= 0) {
            int stringId = lwf.GetInstanceNameStringId(m_instanceId);
            m_name = stringId == -1 ? null : lwf.data.strings[stringId];

            IObject head = m_lwf.GetInstance(m_instanceId);
            if (head != null)
                head.m_prevInstance = this;
            m_nextInstance = head;
            m_lwf.SetInstance(m_instanceId, this);
            }
        }
Ejemplo n.º 38
0
    public static int __newindex(Lua.lua_State L)
    {
        Lua.lua_CFunction fnc = null;
        if (LunaTraits_LWF_Movie.write_properties.TryGetValue(Lua.lua_tostring(L, 2).ToString(), out fnc))
        {
            Lua.lua_insert(L, 2);            // swap key and value
            Lua.lua_settop(L, 2);            // delete key
            return(fnc(L));
        }
        if (Lua.lua_gettop(L) == 3 && Luna.get_uniqueid(L, 1) ==
            LunaTraits_LWF_Movie.uniqueID)
        {
            LWF.Movie o =
                Luna_LWF_Movie.check(L, 1);
            string name = Lua.lua_tostring(L, 2).ToString();
            if (o.lwf.SetFieldLua(o, name))
            {
                return(0);
            }
        }

        Lua.luaL_error(L, "__newindex doesn't allow defining non-property member");
        return(0);
    }
Ejemplo n.º 39
0
	public string GetTextLua(Movie movie, string textName)
	{
		if (luaState==null)
			return "";

		Lua.lua_State l = (Lua.lua_State)luaState;
		if (!GetFieldLua(movie, textName) || Lua.lua_isstring(l, -1)==0) {
			/* -1: nil or not text */
			Lua.lua_pop(l, 1);
			return "";
		}
		/* -1: text */
		string text = Lua.lua_tostring(l, -1).ToString();
		Lua.lua_pop(l, 1);
		/* 0 */
		return text;
	}
Ejemplo n.º 40
0
	public bool SetFieldLua(Movie movie, string key)
	{
		if (luaState==null)
			return false;

		Lua.lua_State l = (Lua.lua_State)luaState;
		/* 1: LWF_Movie instance */
		/* 2: key */
		/* 3: value */

		if (Lua.lua_isstring(l, 3)!=0 && movie.SearchText(key)) {
			movie.lwf.SetText(
				movie.GetFullName() + "." + key, Lua.lua_tostring(l, 3).ToString());
		}

		Lua.lua_getglobal(l, "LWF");
		/* -1: LWF.Instances */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return false;
		}
		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 */
			return false;
		}
		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 */
			return false;
		}
		Lua.lua_getfield(l, -1, "Movies");
		/* -2: LWF.Instances.<instanceId> */
		/* -1: LWF.Instances.<instanceId>.Movies */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Instances.<instanceId>.Movies */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			return false;
		}
		string s = movie.iObjectId.ToString();
		Lua.lua_getfield(l, -1, s);
		/* -2: LWF.Instances.<instanceId>.Movies */
		/* -1: LWF.Instances.<instanceId>.Movies.<iObjectId> */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* -1: LWF.Instances.<instanceId>.Movies */
			Lua.lua_newtable(l);
			/* -2: LWF.Instances.<instanceId>.Movies */
			/* -1: table */
			Lua.lua_pushvalue(l, -1);
			/* -3: LWF.Instances.<instanceId>.Movies */
			/* -2: table */
			/* -1: table */
			Lua.lua_setfield(l, -3, s);
			/* -2: LWF.Instances.<instanceId>.Movies */
			/* -1: table LWF.Instances.<instanceId>.Movies.<iObjectId> */
		}
		Lua.lua_pushvalue(l, 3);
		/* -2: LWF.Instances.<instanceId>.Movies.<iObjectId> */
		/* -1: value */
		Lua.lua_setfield(l, -2, key);
		/* -1: LWF.Instances.<instanceId>.Movies.<iObjectId> */
		Lua.lua_pop(l, 1);
		/* 0 */
		return true;
	}
Ejemplo n.º 41
0
	public bool GetFieldLua(Movie movie, string key)
	{
		if (luaState==null)
			return false;

		Lua.lua_State l = (Lua.lua_State)luaState;
		/* 1: LWF_Movie instance */
		/* 2: key */

		Lua.lua_getglobal(l, "LWF");
		/* -1: LWF.Instances */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return false;
		}
		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 */
			return false;
		}
		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 */
			return false;
		}
		Lua.lua_getfield(l, -1, "Movies");
		/* -2: LWF.Instances.<instanceId> */
		/* -1: LWF.Instances.<instanceId>.Movies */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Instances.<instanceId>.Movies */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return false;
		}
		Lua.lua_getfield(l, -1, movie.iObjectId.ToString());
		/* -2: LWF.Instances.<instanceId>.Movies */
		/* -1: LWF.Instances.<instanceId>.Movies.<iObjectId> */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Instances.<instanceId>.Movies.<iObjectId> */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return false;
		}
		/* -1: LWF.Instances.<instanceId>.Movies.<iObjectId> */
		Lua.lua_getfield(l, -1, key);
		/* -2: LWF.Instances.<instanceId>.Movies.<iObjectId> */
		/* -1: value */
		Lua.lua_remove(l, -2);
		/* -1: value */
		if (Lua.lua_isnil(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return false;
		}
		return true;
	}
Ejemplo n.º 42
0
	public void DestroyMovieLua(Movie movie)
	{
		if (luaState==null)
			return;

		Lua.lua_State l = (Lua.lua_State)luaState;
		Lua.lua_getglobal(l, "LWF");
		/* -1: LWF */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return;
		}
		Lua.lua_getfield(l, -1, "Script");
		/* -2: LWF */
		/* -1: LWF.Script */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Script */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return;
		}
		Lua.lua_getfield(l, -1, name);
		/* -2: LWF.Script */
		/* -1: LWF.Script.<name> */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Script.<name> */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return;
		}
		Lua.lua_getfield(l, -1, "Destroy");
		/* -2: LWF.Script.<name> */
		/* -1: LWF.Script.<name>.Destroy */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Script.<name>.Destroy */
		if (Lua.lua_isfunction(l, -1)) {
			Luna_LWF_LWF.push(l, this, false);
			/* -2: LWF.Script.<name>.Destroy */
			/* -1: LWF instance */
			if (Lua.lua_pcall(l, 1, 0, 0) != 0)
				Lua.lua_pop(l, 1);
			/* 0 */
		}
		Lua.lua_getglobal(l, "LWF");
		/* -1: LWF */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return;
		}
		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 */
			return;
		}
		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 */
			return;
		}
		Lua.lua_getfield(l, -1, "Movies");
		/* -2: LWF.Instances.<instanceId> */
		/* -1: LWF.Instances.<instanceId>.Movies */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Instances.<instanceId>.Movies */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return;
		}
		Lua.lua_pushnil(l);
		/* -2: LWF.Instances.<instanceId>.Movies */
		/* -1: nil */
		Lua.lua_setfield(l, -2, movie.iObjectId.ToString());
		/* LWF.Instances.<instanceId>.Movies.<iObjectId> = nil */
		/* -1: LWF.Instances.<instanceId>.Movies */
		Lua.lua_pop(l, 1);
		/* 0 */
		Luna_LWF_Movie.Destroy(l, movie);
		return;
	}
Ejemplo n.º 43
0
 public Dictionary<int, int> GetMovieLabels(Movie movie)
 {
     if (movie == null)
     return null;
     return m_data.labelMap[movie.objectId];
 }
Ejemplo n.º 44
0
 public IObject(LWF lwf, Movie parent, int type, int objId, int instId)
     : this(lwf, parent, (Type)type, objId, instId)
 {
 }
Ejemplo n.º 45
0
 public void Call(Type type, Movie target)
 {
     switch (type) {
     case Type.LOAD: load.ForEach(h => h(target)); break;
     case Type.POSTLOAD: postLoad.ForEach(h => h(target)); break;
     case Type.UNLOAD: unload.ForEach(h => h(target)); break;
     case Type.ENTERFRAME: enterFrame.ForEach(h => h(target)); break;
     case Type.UPDATE: update.ForEach(h => h(target)); break;
     case Type.RENDER: render.ForEach(h => h(target)); break;
     }
 }
Ejemplo n.º 46
0
 private void ReorderAttachedMovieList(bool reorder, int index, Movie movie)
 {
     if (!reorder || index >= m_attachedMovieList.Count) {
     for (int i = m_attachedMovieList.Count; i < index; ++i)
         m_attachedMovieList.Add(null);
     m_attachedMovieList.Add(movie);
     } else {
     m_attachedMovieList.Insert(index, movie);
     if (reorder) {
         m_attachedMovieList.Remove(null);
         for (int i = 0; i < m_attachedMovieList.Count; ++i)
             m_attachedMovieList[i].depth = i;
     }
     }
 }
Ejemplo n.º 47
0
        public void Init()
        {
            m_time = 0;
            m_progress = 0;

            Array.Clear(m_instances, 0, m_instances.Length);
            m_focus = null;

            m_movieCommands.Clear();

            m_rootMovieStringId = GetStringId("_root");
            if (m_rootMovie != null)
            m_rootMovie.Destroy();
            m_rootMovie = new Movie(this, null,
            m_data.header.rootMovieId, SearchInstanceId(m_rootMovieStringId));
        }
Ejemplo n.º 48
0
        public Movie(LWF lwf, Movie parent, int objId, int instId, int matrixId = 0,
			int colorTransformId = 0, bool attached = false,
			MovieEventHandlers handler = null, string n = null)
            : base(lwf, parent,
			attached ? Type.ATTACHEDMOVIE : Type.MOVIE, objId, instId)
        {
            m_data = lwf.data.movies[objId];
            m_matrixId = matrixId;
            m_colorTransformId = colorTransformId;
            m_totalFrames = m_data.frames;

            if (!String.IsNullOrEmpty(n))
            m_name = n;
            m_instanceHead = null;
            m_instanceTail = null;
            m_currentFrameInternal = -1;
            m_execedFrame = -1;
            m_animationPlayedFrame = -1;
            m_lastControlOffset = -1;
            m_lastControls = -1;
            m_lastHasButton = false;
            m_lastControlAnimationOffset = -1;
            m_skipped = false;
            m_postLoaded = false;
            m_active = true;
            m_visible = true;
            m_playing = true;
            m_jumped = false;
            m_overriding = false;
            m_attachMovieExeced = false;
            m_attachMoviePostExeced = false;
            m_movieExecCount = -1;
            m_postExecCount = -1;
            m_blendMode = (int)Constant.BLEND_MODE_NORMAL;
            m_requestedCalculateBounds = false;
            m_calculateBoundsCallback = null;

            m_property = new Property(lwf);

            m_matrix0 = new Matrix();
            m_matrix1 = new Matrix();
            m_matrixForAttachedLWFs = new Matrix();
            m_colorTransform0 = new ColorTransform();
            m_colorTransform1 = new ColorTransform();
            m_colorTransformForAttachedLWFs = new ColorTransform();

            m_displayList = new Object[m_data.depths];

            m_eventHandlers = new EventHandlers();
            m_handler = new MovieEventHandlers();
            m_handler.Add(lwf.GetMovieEventHandlers(this));
            m_handler.Add(handler);

            #if LWF_USE_LUA
            m_isRoot = objId == lwf.data.header.rootMovieId;
            if (m_isRoot) {
            if (parent == null)
                lwf.CallFunctionLua("Init", this);
            lwf.GetFunctionsLua(objId, out m_rootLoadFunc,
                out m_rootPostLoadFunc, out m_rootUnloadFunc,
                    out m_rootEnterFrameFunc, true);
            }
            lwf.GetFunctionsLua(objId, out m_loadFunc, out m_postLoadFunc,
            out m_unloadFunc, out m_enterFrameFunc, false);

            if (m_isRoot && !String.IsNullOrEmpty(m_rootLoadFunc))
            lwf.CallFunctionLua(m_rootLoadFunc, this);
            if (m_loadFunc != String.Empty)
            lwf.CallFunctionLua(m_loadFunc, this);
            #endif

            PlayAnimation(ClipEvent.LOAD);
            if (!m_handler.Empty())
            m_handler.Call(EventType.LOAD, this);

            lwf.ExecMovieCommand();
        }
Ejemplo n.º 49
0
        private void ExecObject(int dlDepth, int objId,
		int matrixId, int colorTransformId, int instId,
		int dlBlendMode, bool updateBlendMode = false)
        {
            // Ignore error
            if (objId == -1)
            return;
            Data data = m_lwf.data;
            Format.Object dataObject = data.objects[objId];
            int dataObjectId = dataObject.objectId;
            Object obj = m_displayList[dlDepth];

            if (obj != null && (obj.type != (Type)dataObject.objectType ||
                obj.objectId != dataObjectId || (obj.IsMovie() &&
                ((IObject)obj).instanceId != instId))) {
            if (m_texts != null && obj.IsText())
                EraseText(obj.objectId);
            obj.Destroy();
            obj = null;
            }

            if (obj == null) {
            switch ((Type)dataObject.objectType) {
            case Type.BUTTON:
                obj = new Button(m_lwf,
                    this, dataObjectId, instId, matrixId, colorTransformId);
                break;

            case Type.GRAPHIC:
                obj = new Graphic(m_lwf, this, dataObjectId);
                break;

            case Type.MOVIE:
                obj = new Movie(m_lwf, this,
                    dataObjectId, instId, matrixId, colorTransformId);
                ((Movie)obj).blendMode = dlBlendMode;
                break;

            case Type.BITMAP:
                obj = new Bitmap(m_lwf, this, dataObjectId);
                break;

            case Type.BITMAPEX:
                obj = new BitmapEx(m_lwf, this, dataObjectId);
                break;

            case Type.TEXT:
                obj = new Text(m_lwf, this, dataObjectId, instId);
                break;

            case Type.PARTICLE:
                obj = new Particle(m_lwf, this, dataObjectId);
                break;

            case Type.PROGRAMOBJECT:
                obj = new ProgramObject(m_lwf, this, dataObjectId);
                break;
            }
            }

            if (obj.IsMovie() && updateBlendMode)
            ((Movie)obj).blendMode = dlBlendMode;

            if (obj.IsMovie() || obj.IsButton()) {
            IObject instance = (IObject)obj;
            instance.linkInstance = null;
            if (m_instanceHead == null)
                m_instanceHead = instance;
            else
                m_instanceTail.linkInstance = instance;
            m_instanceTail = instance;
            if (obj.IsButton())
                m_hasButton = true;
            }

            if (m_texts != null && obj.IsText())
            InsertText(obj.objectId);

            m_displayList[dlDepth] = obj;
            obj.execCount = m_movieExecCount;
            obj.Exec(matrixId, colorTransformId);
        }
Ejemplo n.º 50
0
    void DrawInspector(ObjectContainer container)
    {
        EditorGUI.indentLevel = container.hierarchy + 1;

        LWF.Object obj = container.obj;
        LWF.LWF    lwf = obj.lwf;
        if (obj.type == Type.MOVIE)
        {
            LWF.Movie movie = (LWF.Movie)obj;

            string movieName = "Movie: " +
                               (movie.name == null ? "(null)" : movie.name);
            if (!visibilities.ContainsKey(movie))
            {
                visibilities[movie] = true;
            }
            visibilities[movie] =
                EditorGUILayout.Foldout(visibilities[movie], movieName);

            if (!visibilities[movie])
            {
                return;
            }

            EditorGUI.indentLevel = container.hierarchy + 2;
            string fullName = movie.GetFullName();
            if (fullName == null)
            {
                fullName = "(null)";
            }
            EditorGUILayout.LabelField("Fullname:", fullName);
            EditorGUILayout.LabelField("Visible:", movie.visible.ToString());
            EditorGUILayout.LabelField("Playing:", movie.playing.ToString());
            EditorGUILayout.LabelField("Frame:", movie.currentFrame.ToString());
            DrawInfo(container, movie);

            // TODO
            EditorGUILayout.Space();

            foreach (KeyValuePair <int, ObjectContainer>
                     kvp in container.objects)
            {
                DrawInspector(kvp.Value);
            }
        }
        else
        {
            EditorGUILayout.LabelField("Depth:", container.depth.ToString());
            EditorGUI.indentLevel = container.hierarchy + 2;

            switch (obj.type)
            {
            case Type.BUTTON:
                LWF.Button button     = (LWF.Button)obj;
                string     buttonName =
                    (button.name == null ? "(null)" : button.name);
                string buttonFullName = button.GetFullName();
                if (buttonFullName == null)
                {
                    buttonFullName = "(null)";
                }
                EditorGUILayout.LabelField("Button:", buttonName);

                EditorGUI.indentLevel = container.hierarchy + 3;
                EditorGUILayout.LabelField("Fullname:", buttonFullName);
                DrawInfo(container, obj);
                // TODO
                break;

            case Type.GRAPHIC:
                EditorGUILayout.LabelField("Graphic:", "");
                EditorGUI.indentLevel = container.hierarchy + 3;
                DrawInfo(container, obj);
                // TODO
                break;

            case Type.BITMAP:
                LWF.Bitmap bitmap      = (LWF.Bitmap)obj;
                int        tFId        = lwf.data.bitmaps[bitmap.objectId].textureFragmentId;
                string     textureName = (tFId == -1 ? "(null)" :
                                          lwf.data.textureFragments[tFId].filename);
                EditorGUILayout.LabelField("Bitmap:", textureName);
                EditorGUI.indentLevel = container.hierarchy + 3;
                DrawInfo(container, obj);
                // TODO
                break;

            case Type.BITMAPEX:
                LWF.BitmapEx bitmapEx = (LWF.BitmapEx)obj;
                int          tFIdEx   =
                    lwf.data.bitmapExs[bitmapEx.objectId].textureFragmentId;
                string textureNameEx = (tFIdEx == -1 ? "(null)" :
                                        lwf.data.textureFragments[tFIdEx].filename);
                EditorGUILayout.LabelField("BitmapEx:", textureNameEx);
                EditorGUI.indentLevel = container.hierarchy + 3;
                DrawInfo(container, obj);
                // TODO
                break;

            case Type.TEXT:
                LWF.Text text     = (LWF.Text)obj;
                string   textName = lwf.data.strings[
                    lwf.data.texts[text.objectId].nameStringId];
                EditorGUILayout.LabelField("Text:", textName);
                EditorGUI.indentLevel = container.hierarchy + 3;
                DrawInfo(container, obj);
                // TODO
                break;

            case Type.PARTICLE:
                EditorGUILayout.LabelField("Particle:", "");
                EditorGUI.indentLevel = container.hierarchy + 3;
                DrawInfo(container, obj);
                // TODO
                break;

            case Type.PROGRAMOBJECT:
                LWF.ProgramObject pObject     = (LWF.ProgramObject)obj;
                string            pObjectName = lwf.data.strings[
                    lwf.data.programObjects[pObject.objectId].stringId];
                EditorGUILayout.LabelField("ProgramObject:", pObjectName);
                EditorGUI.indentLevel = container.hierarchy + 3;
                DrawInfo(container, obj);
                // TODO
                break;
            }
        }
    }
Ejemplo n.º 51
0
        public static void GetColorTransform(Movie movie)
        {
            int colorTransformId = movie.colorTransformId;
            ColorTransform colorTransform;
            if ((colorTransformId & (int)Constant.COLORTRANSFORM_FLAG) == 0) {
            AlphaTransform alphaTransform =
                movie.lwf.data.alphaTransforms[colorTransformId];
            colorTransform = new ColorTransform(1, 1, 1, alphaTransform.alpha);
            } else {
            colorTransformId &= ~(int)Constant.COLORTRANSFORM_FLAG;
            colorTransform = movie.lwf.data.colorTransforms[colorTransformId];
            }

            movie.SetColorTransform(colorTransform);
        }
Ejemplo n.º 52
0
	public int AddEventHandlerLua(Movie movie = null, Button button = null)
	{
		if (luaState==null)
			return 0;

		Lua.lua_State l = (Lua.lua_State)luaState;
		string ev;
		int luaHandlerId;
		int handlerId;

		/* 1: LWF_LWF instance */
		/* 2: string */
		/* 3: function */
		ev = 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_pushvalue(l, 3);
		/* -2: LWF.Instances.<instanceId>.Handlers */
		/* -1: function */
		luaHandlerId = GetEventOffset();
		Lua.lua_setfield(l, -2, luaHandlerId.ToString());
		/* LWF.Instances.<instanceId>.Handlers.<luaHandlerId> = function */
		/* -1: LWF.Instances.<instanceId>.Handlers */
		Lua.lua_pop(l, 1);
		/* 0 */

		if (movie != null) {
			if (string.IsNullOrEmpty(ev) || MovieEvents.ContainsKey(ev)) {
				/* Movie event */
				handlerId = movie.AddEventHandler(ev, (Movie m) => {
					Lua.lua_State _l = (Lua.lua_State)m.lwf.luaState;
					if (!m.lwf.PushHandlerLua(luaHandlerId))
						return;
					/* -1: function */

					Luna_LWF_Movie.push(_l, m, false);
					/* -2: function */
					/* -1: Movie */
					if (Lua.lua_pcall(_l, 1, 0, 0)!=0)
						Lua.lua_pop(_l, 1);
				});
			} else {
				handlerId = movie.AddEventHandler(ev, () => {
					Lua.lua_State _l = (Lua.lua_State)movie.lwf.luaState;
					if (!movie.lwf.PushHandlerLua(luaHandlerId))
						return;
					/* -1: function */

					/* User defined event */
					Lua.lua_createtable(_l, 0, 2);
					/* -2: function */
					/* -1: table */
					Lua.lua_pushstring(_l, ev);
					/* -3: function */
					/* -2: table */
					/* -1: string(type) */
					Lua.lua_setfield(_l, -2, "type");
					/* -2: function */
					/* -1: table */
					if (Lua.lua_istable(_l, 2)) {
						Lua.lua_getfield(_l, 2, "param");
						/* -3: function */
						/* -2: table */
						/* -1: param */
					} else {
						Lua.lua_pushnil(_l);
						/* -3: function */
						/* -2: table */
						/* -1: nil */
					}
					Lua.lua_setfield(_l, -2, "param");
					/* -2: function */
					/* -1: table */
					if (Lua.lua_pcall(_l, 1, 0, 0)!=0)
						Lua.lua_pop(_l, 1);
					/* 0 */
				});
			}
		} else if (button != null) {
			if (string.Compare(ev, "keyPress") == 0) {
				handlerId = button.AddEventHandler(ev, (Button b, int k) => {
					if (!b.lwf.PushHandlerLua(luaHandlerId))
						return;

					/* -1: function */
					Lua.lua_State _l = (Lua.lua_State)b.lwf.luaState;
					Luna_LWF_Button.push(_l, b, false);
					Lua.lua_pushnumber(_l, k);
					/* -3: function */
					/* -2: Button */
					/* -1: int */
					if (Lua.lua_pcall(l, 2, 0, 0)!=0)
						Lua.lua_pop(l, 1);
					/* 0 */
				});
			} else {
				handlerId = button.AddEventHandler(ev, (Button b) => {
					if (!b.lwf.PushHandlerLua(luaHandlerId))
						return;

					/* -1: function */
					Lua.lua_State _l = (Lua.lua_State)b.lwf.luaState;
					Luna_LWF_Button.push(_l, b, false);
					/* -2: function */
					/* -1: Button */
					if (Lua.lua_pcall(l, 1, 0, 0)!=0)
						Lua.lua_pop(l, 1);
					/* 0 */
				});
			}
		} else {
			handlerId = AddEventHandler(ev, (Movie m, Button b) => {
				if (!m.lwf.PushHandlerLua(luaHandlerId))
					return;

				/* -1: function */
				Lua.lua_State _l = (Lua.lua_State)m.lwf.luaState;
				Luna_LWF_Movie.push(_l, m, false);
				Luna_LWF_Button.push(_l, b, false);
				/* -3: function */
				/* -2: Movie */
				/* -1: Button */
				if (Lua.lua_pcall(l, 2, 0, 0)!=0)
					Lua.lua_pop(l, 1);
				/* 0 */
			});
		}

		Lua.lua_pushnumber(l, handlerId);
		/* -1: handlerId */
		return 1;

	error:
		Lua.lua_pushnumber(l, -1);
		/* -1: -1 */
		return 1;
	}
Ejemplo n.º 53
0
	public int AttachMovieLua(Movie movie, bool empty)
	{
		if (luaState==null)
			return 0;

		Lua.lua_State l = (Lua.lua_State)luaState;
		int args = Lua.lua_gettop(l);
		string linkageName;
		string attachName;
		int attachDepth = -1;
		bool reorder = false;
		int offset = empty ? 2 : 3;
		MovieEventHandlerDictionary handlers =
				new MovieEventHandlerDictionary() {
			{"load",null},
			{"postLoad",null},
			{"unload",null},
			{"enterFrame",null},
			{"update",null},
			{"render",null}
		};

		Movie child;

		/* 1: LWF_Movie instance */
		/* 2: linkageName:string */
		/* 3: attachName:string */
		/* 4: table {key:string, handler:function} */
		/* 5: attachDepth:number (option) */
		/* 6: reorder:boolean (option) */
		/* or */
		/* 1: LWF_Movie instance */
		/* 2: attachName:string */
		/* 3: table {key:string, handler:function} */
		/* 4: attachDepth:number (option) */
		/* 5: reorder:boolean (option) */
		linkageName = empty ? "_empty" : Lua.lua_tostring(l, 2).ToString();
		attachName = Lua.lua_tostring(l, offset).ToString();
		if (args >= offset + 1) {
			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, 4) != 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] = (Movie a) => {
						if (!a.lwf.PushHandlerLua(luaHandlerId))
							return;

						/* -1: function */
						Lua.lua_State ls = (Lua.lua_State)a.lwf.luaState;
						Luna_LWF_Movie.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, 1);
					/* -2: LWF.Instances.<instanceId>.Handlers */
					/* -1: key: eventName string */
				}
			}
			/* -1: LWF.Instances.<instanceId>.Handlers */
			Lua.lua_pop(l, 1);
			/* 0 */
		}
		if (args >= offset + 2)
			attachDepth = (int)Lua.lua_tonumber(l, offset + 2);
		if (args >= offset + 3)
			reorder = Lua.lua_toboolean(l, offset + 3)!=0;

		child = movie.AttachMovie(
			linkageName,
			attachName,
			attachDepth,
			reorder,
			handlers["load"],
			handlers["postLoad"],
			handlers["unload"],
			handlers["enterFrame"],
			handlers["update"],
			handlers["render"]);
		Luna_LWF_Movie.push(l, child, false);
		/* -1: LWF_Movie child */
		return 1;

	error:
		Lua.lua_pushnil(l);
		/* -1: nil */
		return 1;
	}
Ejemplo n.º 54
0
	public int AttachLWFLua(Movie movie)
	{
		if (luaState == null)
			return 0;

		Lua.lua_State l = (Lua.lua_State)luaState;
		int args = Lua.lua_gettop(l);
		string attachName;
		string path;
		int attachDepth = -1;
		bool reorder = false;
		string texturePrefix = null;

		/* 1: LWF_Movie instance */
		/* 2: path:string */
		/* 3: attachName:string */
		/* 4: attachDepth:number (option) */
		/* 5: reorder:boolean (option) */
		/* 6: texturePrefix:string (option) */
		path = Lua.lua_tostring(l, 2).ToString();
		attachName = Lua.lua_tostring(l, 3).ToString();
		if (args >= 4)
			attachDepth = (int)Lua.lua_tonumber(l, 4);
		if (args >= 5)
			reorder = Lua.lua_toboolean(l, 5) != 0;
		if (args >= 6)
			texturePrefix = Lua.lua_tostring(l, 6).ToString();

		LWF child = movie.AttachLWF(
			path, attachName, attachDepth, reorder, texturePrefix);

		if (child != null) {
			Luna_LWF_LWF.push(l, child, false);
			/* -1: LWF_LWF child */
		} else {
			Lua.lua_pushnil(l);
			/* -1: nil */
		}
		return 1;
	}
Ejemplo n.º 55
0
	public void CallFunctionLua(string function, Movie movie)
	{
		if (luaState==null)
			return;

		Lua.lua_State l = (Lua.lua_State)luaState;
		Lua.lua_getglobal(l, "LWF");
		/* -1: LWF */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return;
		}
		Lua.lua_getfield(l, -1, "Script");
		/* -2: LWF */
		/* -1: LWF.Script */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Script */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return;
		}
		Lua.lua_getfield(l, -1, name);
		/* -2: LWF.Script */
		/* -1: LWF.Script.<name> */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Script.<name> */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return;
		}
		Lua.lua_getfield(l, -1, function);
		/* -2: LWF.Script.<name> */
		/* -1: LWF.Script.<name>.<function> */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Script.<name>.<function> */
		if (!Lua.lua_isfunction(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return;
		}
		Luna_LWF_Movie.push(l, movie, false);
		/* -2: LWF.Script.<name>.<function> */
		/* -1: LWF_Movie instance */
		if (Lua.lua_pcall(l, 1, 0, 0)!=0)
			Lua.lua_pop(l, 1);
		/* 0 */
	}
Ejemplo n.º 56
0
	public void CallEventFunctionLua(int eventId, Movie movie, Button button)
	{
		if (luaState==null)
			return;

		if (!m_eventFunctions.ContainsKey(eventId))
			return;

		Lua.lua_State l = (Lua.lua_State)luaState;
		Lua.lua_getglobal(l, "LWF");
		/* -1: LWF */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return;
		}
		Lua.lua_getfield(l, -1, "Script");
		/* -2: LWF */
		/* -1: LWF.Script */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Script */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return;
		}
		Lua.lua_getfield(l, -1, name);
		/* -2: LWF.Script */
		/* -1: LWF.Script.<name> */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Script.<name> */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return;
		}
		string ev = "Event_";
		Lua.lua_getfield(l, -1,
			(ev + data.strings[data.events[eventId].stringId]));
		/* -2: LWF.Script.<name> */
		/* -1: LWF.Script.<name>.Event_<eventName> */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Script.<name>.Event_<eventName>*/

		if (!Lua.lua_isfunction(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			return;
		}
		Luna_LWF_Movie.push(l, movie, false);
		/* -2: LWF.Script.<name>.Event_<eventName> */
		/* -1: LWF_Movie instance */
		Luna_LWF_Button.push(l, button, false);
		/* -3: LWF.Script.<name>.Event_<eventName> */
		/* -2: LWF_Movie instance */
		/* -1: LWF_Button instance */
		if (Lua.lua_pcall(l, 2, 0, 0)!=0)
			Lua.lua_pop(l, 1);
		/* 0 */
	}
Ejemplo n.º 57
0
        public Movie AttachMovie(string linkageName, string attachName,
		int attachDepth = -1, bool reorder = false,
		MovieEventHandler load = null, MovieEventHandler postLoad = null,
		MovieEventHandler unload = null, MovieEventHandler enterFrame = null,
		MovieEventHandler update = null, MovieEventHandler render = null)
        {
            int movieId = m_lwf.SearchMovieLinkage(m_lwf.GetStringId(linkageName));
            if (movieId == -1)
            return null;

            MovieEventHandlers handlers = new MovieEventHandlers();
            handlers.Add(load, postLoad, unload, enterFrame, update, render);
            Movie movie = new Movie(m_lwf, this, movieId, -1, 0, 0, true, handlers);
            if (m_attachMovieExeced)
            movie.Exec();
            if (m_attachMoviePostExeced)
            movie.PostExec(true);

            return AttachMovieInternal(movie, attachName, attachDepth, reorder);
        }
Ejemplo n.º 58
0
 public int SearchFrame(Movie movie, string label)
 {
     return SearchFrame(movie, GetStringId(label));
 }
Ejemplo n.º 59
0
    void OnGUI()
    {
        LWFObject[] lwfObjects =
            FindObjectsOfType(typeof(LWFObject)) as LWFObject[];
        if (lwfObjects == null)
        {
            return;
        }

        if (!texture)
        {
            texture = new Texture2D(1, 1);
            texture.SetPixel(0, 0, Color.white);
            texture.Apply();
        }

        Matrix4x4 savedMatrix = GUI.matrix;
        Color     savedColor  = GUI.color;

        foreach (LWFObject lwfObject in lwfObjects)
        {
            bool visibility;
            if (visibilities.TryGetValue(
                    lwfObject, out visibility) && !visibility)
            {
                continue;
            }

            LWF.LWF lwf = lwfObject.lwf;
            if (lwf == null)
            {
                continue;
            }

            lwf.Inspect((obj, hierarchy, depth, rOffset) => {
                if (obj.type != Type.BUTTON)
                {
                    return;
                }

                for (LWF.Object o = obj.parent; o != null; o = o.parent)
                {
                    LWF.Movie m = o as LWF.Movie;
                    if (m != null && !m.visible)
                    {
                        return;
                    }
                    if (visibilities.TryGetValue(
                            o, out visibility) && !visibility)
                    {
                        return;
                    }
                }

                Factory factory = lwf.rendererFactory as Factory;
                if (factory == null)
                {
                    return;
                }

                LWF.Button button = (LWF.Button)obj;
                DrawButton(button, factory);
            });
        }

        GUI.matrix = savedMatrix;
        GUI.color  = savedColor;
    }
Ejemplo n.º 60
0
        public MovieEventHandlers GetMovieEventHandlers(Movie m)
        {
            if (m_movieEventHandlersByFullName != null) {
            string fullName = m.GetFullName();
            if (fullName != null) {
                MovieEventHandlers handlers;
                if (m_movieEventHandlersByFullName.TryGetValue(
                        fullName, out handlers)) {
                    return handlers;
                }
            }
            }

            int instId = m.instanceId;
            if (instId < 0 || instId >= m_instances.Length)
            return null;
            return m_movieEventHandlers[instId];
        }