// use lunaStack::push if possible. public static void push(Lua.lua_State L, LWF.LWF 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_LWF.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_LWF.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); }
public virtual void OnDestroy() { isAlive = false; if (lwfName == null) { return; } if (lwf != null) { lwf.Destroy(); lwf = null; } if (factory != null) { factory.Destruct(); factory = null; } if (meshes != null) { meshes = null; ResourceCache.SharedInstance().DeleteRenderedMesh(lwfName); } ResourceCache.SharedInstance().UnloadLWFData(lwfName); }
public static ColorTransform CalcColorTransform(LWF lwf, ColorTransform dst, ColorTransform src0, int src1Id) { if (src1Id == 0) { dst.Set(src0); } else if ((src1Id & (int)Constant.COLORTRANSFORM_FLAG) == 0) { AlphaTransform alphaTransform = lwf.data.alphaTransforms[src1Id]; dst.multi.red = src0.multi.red; dst.multi.green = src0.multi.green; dst.multi.blue = src0.multi.blue; dst.multi.alpha = src0.multi.alpha * alphaTransform.alpha; dst.add.Set(src0.add); } else { int colorTransformId = src1Id & ~(int)Constant.COLORTRANSFORM_FLAG; ColorTransform src1 = lwf.data.colorTransforms[colorTransformId]; CalcColorTransform(dst, src0, src1); } return(dst); }
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; } ButtonEventHandlers handler = lwf.GetButtonEventHandlers(this); if (handler != null) { m_handler = new ButtonEventHandlers(); m_handler.Add(handler); m_handler.Call(EventType.LOAD, this); } }
public LWF SearchAttachedLWF(string attachName, bool recursive = true) { LWF attachedLWF = GetAttachedLWF(attachName); if (attachedLWF != null) { return(attachedLWF); } if (!recursive) { return(null); } for (IObject instance = m_instanceHead; instance != null; instance = instance.linkInstance) { if (instance.IsMovie()) { LWF i = ((Movie)instance).SearchAttachedLWF( attachName, recursive); if (i != null) { return(i); } } } return(null); }
public virtual void OnDestroy() { isAlive = false; lwfDestroyCallbacks.ForEach(c => c(this)); lwfDestroyCallbacks = null; if (lwfName == null) { return; } if (lwf != null) { lwf.Destroy(); lwf = null; } if (factory != null) { factory.Destruct(); factory = null; } ResourceCache.SharedInstance().UnloadLWFData(lwfName); }
} // 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.LWF obj = LunaTraits_LWF_LWF._bind_ctor(L); // call constructor for T objects push(L, obj, true); return(1); // userdata containing pointer to T object }
public virtual bool Load(string path, string texturePrefix = "", string fontPrefix = "", float zOffset = 0, float zRate = 1, int renderQueueOffset = 0, Camera camera = null, bool autoUpdate = true, LWFDataCallback lwfDataCallback = null, LWFLoadCallback lwfLoadCallback = null, LWFDataLoader lwfDataLoader = null, TextureLoader textureLoader = null, TextureUnloader textureUnloader = null) { lwfName = path; callUpdate = autoUpdate; if (camera == null) { camera = Camera.main; } if (lwfLoadCallback != null) { lwfLoadCallbacks.Add(lwfLoadCallback); } LWF.Data data = ResourceCache.SharedInstance().LoadLWFData(lwfName, lwfDataLoader); if (data == null || !data.Check()) { return(false); } if (lwfDataCallback != null && !lwfDataCallback(data)) { return(false); } if (rendererFactoryConstructor != null) { RendererFactoryArguments arg = new RendererFactoryArguments( data, gameObject, zOffset, zRate, renderQueueOffset, camera, texturePrefix, fontPrefix, textureLoader, textureUnloader); factory = rendererFactoryConstructor(arg); } else if (useCombinedMeshRenderer && data.textures.Length == 1) { factory = new LWF.CombinedMeshRenderer.Factory( data, gameObject, zOffset, zRate, renderQueueOffset, camera, texturePrefix, fontPrefix, textureLoader, textureUnloader); } else { factory = new LWF.DrawMeshRenderer.Factory( data, gameObject, zOffset, zRate, renderQueueOffset, camera, texturePrefix, fontPrefix, textureLoader, textureUnloader); } lwf = new LWF.LWF(data, factory); OnLoad(); return(true); }
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); } }
public static void CalcColorTransform(LWF lwf, ColorTransform dst, ColorTransform src0, int src1Id) { ColorTransform src1 = null; if (src1Id == 0) { dst.Set(src0); } else if ((src1Id & (int)Constant.COLORTRANSFORM_FLAG) == 0) { AlphaTransform alphaTransform = lwf.data.alphaTransforms[src1Id]; dst.multi.red = src0.multi.red; dst.multi.green = src0.multi.green; dst.multi.blue = src0.multi.blue; dst.multi.alpha = src0.multi.alpha * alphaTransform.alpha; #if LWF_USE_ADDITIONALCOLOR dst.add.Set(src0.add); #endif } else { int colorTransformId = src1Id & ~(int)Constant.COLORTRANSFORM_FLAG; src1 = lwf.data.colorTransforms[colorTransformId]; CalcColorTransform(dst, src0, src1); } }
public override void RenderNow() { for (int dlDepth = 0; dlDepth < m_data.depths; ++dlDepth) { Object obj = m_displayList[dlDepth]; if (obj != null) { obj.RenderNow(); } } if (m_attachedMovies != null) { foreach (Movie movie in m_attachedMovieList.Values) { if (movie != null) { movie.RenderNow(); } } } if (m_attachedLWFs != null) { foreach (LWFContainer lwfContainer in m_attachedLWFList.Values) { if (lwfContainer != null) { LWF child = lwfContainer.child; child.RenderNow(); } } } }
public virtual void OnDestroy() { isAlive = false; if (lwfName == null) return; lwfDestroyCallbacks.ForEach(c => c(this)); lwfDestroyCallbacks = null; if (lwf != null) { lwf.Destroy(); lwf = null; } if (factory != null) { factory.Destruct(); factory = null; } if (meshes != null) { meshes = null; ResourceCache.SharedInstance().DeleteRenderedMesh(lwfName); } ResourceCache.SharedInstance().UnloadLWFData(lwfName); }
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; } }
public static void CalcMatrix(LWF lwf, Matrix dst, Matrix src0, int src1Id) { if (src1Id == 0) { dst.Set(src0); } else if ((src1Id & (int)Constant.MATRIX_FLAG) == 0) { Translate translate = lwf.data.translates[src1Id]; dst.scaleX = src0.scaleX; dst.skew0 = src0.skew0; dst.translateX = src0.scaleX * translate.translateX + src0.skew0 * translate.translateY + src0.translateX; dst.skew1 = src0.skew1; dst.scaleY = src0.scaleY; dst.translateY = src0.skew1 * translate.translateX + src0.scaleY * translate.translateY + src0.translateY; } else { int matrixId = src1Id & ~(int)Constant.MATRIX_FLAG_MASK; Matrix src1 = lwf.data.matrices[matrixId]; CalcMatrix(dst, src0, src1); } }
public void DetachLWF(LWF detachLWF) { if (m_detachedLWFs != null && detachLWF != null && detachLWF.attachName != null) { m_detachedLWFs[detachLWF.attachName] = true; } }
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_property = new Property(lwf); m_matrix0 = new Matrix(); m_matrix1 = new Matrix(); m_colorTransform0 = new ColorTransform(); m_colorTransform1 = new ColorTransform(); m_displayList = new Object[m_data.depths]; PlayAnimation(ClipEvent.LOAD); m_eventHandlers = new EventHandlerDictionary(); m_handler = new MovieEventHandlers(); m_handler.Add(lwf.GetMovieEventHandlers(this)); m_handler.Add(handler); if (!m_handler.Empty()) { m_handler.Call(EventType.LOAD, this); } lwf.ExecMovieCommand(); }
public static void FitForWidth(LWF lwf, float stageWidth) { float scale = stageWidth / lwf.width; float offsetX = -lwf.width / 2 * scale; float offsetY = -lwf.height / 2 * scale; lwf.property.Scale(scale, scale); lwf.property.Move(offsetX, offsetY); }
public CharacterProgramObject( LWFObject parent, LWF.LWF lwf, int width, int height) : base(lwf) { m_parent = parent; m_cube = GameObject.CreatePrimitive(PrimitiveType.Cube); m_cube.transform.parent = m_parent.gameObject.transform; m_cube.transform.localScale = new Vector3(width / 100.0f, height / 100.0f, 1); }
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); }
public override void Render(bool v, int rOffset) { if (!m_visible || !m_active) { v = false; } if (v && !m_handler.Empty()) { m_handler.Call(EventType.RENDER, this); } if (m_property.hasRenderingOffset) { m_lwf.RenderOffset(); rOffset = m_property.renderingOffset; } if (rOffset == Int32.MinValue) { m_lwf.ClearRenderOffset(); } for (int dlDepth = 0; dlDepth < m_data.depths; ++dlDepth) { Object obj = m_displayList[dlDepth]; if (obj != null) { obj.Render(v, rOffset); } } if (m_attachedMovies != null) { foreach (Movie movie in m_attachedMovieList.Values) { if (movie != null) { movie.Render(v, rOffset); } } } if (m_attachedLWFs != null) { foreach (LWFContainer lwfContainer in m_attachedLWFList.Values) { if (lwfContainer != null) { LWF child = lwfContainer.child; child.SetAttachVisible(v); m_lwf.RenderObject(child.Render(m_lwf.renderingIndex, m_lwf.renderingCount, rOffset)); } } } }
public Movie SearchMovieInstance(string instanceName, bool recursive = true) { int stringId = m_lwf.GetStringId(instanceName); if (stringId != -1) { return(SearchMovieInstance(stringId, recursive)); } if (m_attachedMovies != null) { foreach (Movie movie in m_attachedMovieList.Values) { if (movie != null) { if (movie.attachName == instanceName) { return(movie); } else if (recursive) { Movie descendant = movie.SearchMovieInstance(instanceName, recursive); if (descendant != null) { return(descendant); } } } } } if (m_attachedLWFs != null) { foreach (LWFContainer lwfContainer in m_attachedLWFList.Values) { if (lwfContainer != null) { LWF child = lwfContainer.child; if (child.attachName == instanceName) { return(child.rootMovie); } else if (recursive) { Movie descendant = child.rootMovie.SearchMovieInstance(instanceName, recursive); if (descendant != null) { return(descendant); } } } } } return(null); }
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; }
public static void Destroy(Lua.lua_State L, LWF.LWF obj) { int objectId = -1; if (objectIdentifiers[L].TryGetValue(obj, out objectId)) { objectIdentifiers[L].Remove(obj); objects[L].Remove(objectId); } }
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; }
public static int _bind_gotoAndStopMovie_overload_1(Lua.lua_State L) { LWF.LWF self = Luna_LWF_LWF.check(L, 1); string instanceName = Lua.lua_tostring(L, 2).ToString(); int frameNo = (int)Lua.lua_tonumber(L, 3); try { self.GotoAndStopMovie(instanceName, frameNo); } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); } return(0); }
public static int _bind_gotoAndPlayMovie_overload_2(Lua.lua_State L) { LWF.LWF self = Luna_LWF_LWF.check(L, 1); string instanceName = Lua.lua_tostring(L, 2).ToString(); string label = Lua.lua_tostring(L, 3).ToString(); try { self.GotoAndPlayMovie(instanceName, label); } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); } return(0); }
public void AttachLWF(LWF attachLWF, string attachName, int attachDepth = -1, bool reorder = false, DetachHandler detachHandler = null) { if (m_attachedLWFs == null) { m_attachedLWFs = new AttachedLWFs(); m_detachedLWFs = new DetachDict(); m_attachedLWFList = new AttachedLWFList(); } LWFContainer lwfContainer; if (attachLWF.parent != null) { attachLWF.parent.m_attachedLWFs.TryGetValue( attachLWF.attachName, out lwfContainer); DeleteAttachedLWF(attachLWF.parent, lwfContainer, false); } else { if (m_attachedLWFs.TryGetValue(attachName, out lwfContainer)) { DeleteAttachedLWF(this, lwfContainer); } } if (!reorder && attachDepth >= 0 && attachDepth <= m_attachedLWFList.Count - 1) { lwfContainer = m_attachedLWFList[attachDepth]; if (lwfContainer != null) { DeleteAttachedLWF(this, lwfContainer); } } lwfContainer = new LWFContainer(this, attachLWF); if (attachLWF.interactive == true) { m_lwf.interactive = true; } attachLWF.parent = this; attachLWF.detachHandler = detachHandler; attachLWF.attachName = attachName; attachLWF.depth = attachDepth >= 0 ? attachDepth : m_attachedLWFList.Count; m_attachedLWFs[attachName] = lwfContainer; ReorderAttachedLWFList(reorder, attachLWF.depth, lwfContainer); m_lwf.isLWFAttached = true; }
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); } }
public void AttachLWF(LWF attachLWF, string attachName, int attachDepth = -1, bool reorder = false, DetachHandler detachHandler = null) { if (m_attachedLWFs == null) { m_attachedLWFs = new AttachedLWFs(); m_detachedLWFs = new DetachDict(); m_attachedLWFList = new AttachedLWFList(); m_attachedLWFDescendingList = new AttachedLWFDescendingList(new DescendingComparer <int>()); } LWFContainer lwfContainer; if (attachLWF.parent != null) { attachLWF.parent.m_attachedLWFs.TryGetValue( attachLWF.attachName, out lwfContainer); DeleteAttachedLWF(attachLWF.parent, lwfContainer, false); } else { if (m_attachedLWFs.TryGetValue(attachName, out lwfContainer)) { DeleteAttachedLWF(this, lwfContainer); } } if (!reorder && attachDepth >= 0) { if (m_attachedLWFList.TryGetValue(attachDepth, out lwfContainer)) { DeleteAttachedLWF(this, lwfContainer); } } lwfContainer = new LWFContainer(this, attachLWF); if (attachLWF.interactive == true) { m_lwf.interactive = true; } attachLWF.parent = this; attachLWF.detachHandler = detachHandler; attachLWF.attachName = attachName; attachLWF.depth = attachDepth >= 0 ? attachDepth : m_attachedLWFDescendingList.Keys.GetEnumerator().Current + 1; m_attachedLWFs[attachName] = lwfContainer; ReorderAttachedLWFList(reorder, attachLWF.depth, lwfContainer); m_lwf.isLWFAttached = true; }
public override void Inspect( Inspector inspector, int hierarchy, int inspectDepth, int rOffset) { if (m_property.hasRenderingOffset) { m_lwf.RenderOffset(); rOffset = m_property.renderingOffset; } if (rOffset == Int32.MinValue) { m_lwf.ClearRenderOffset(); } inspector(this, hierarchy, inspectDepth, rOffset); ++hierarchy; int d; for (d = 0; d < m_data.depths; ++d) { Object obj = m_displayList[d]; if (obj != null) { obj.Inspect(inspector, hierarchy, d, rOffset); } } if (m_attachedMovies != null) { foreach (Movie movie in m_attachedMovieList.Values) { if (movie != null) { movie.Inspect(inspector, hierarchy, d++, rOffset); } } } if (m_attachedLWFs != null) { foreach (LWFContainer lwfContainer in m_attachedLWFList.Values) { if (lwfContainer != null) { LWF child = lwfContainer.child; m_lwf.RenderObject( child.Inspect(inspector, hierarchy, d++, rOffset)); } } } }
public static int addButtonEventListener(Lua.lua_State L) { if (Lua.lua_gettop(L) != 3 || Luna.get_uniqueid(L, 1) != LunaTraits_LWF_LWF.uniqueID || Lua.lua_isstring(L, 2) == 0 || !Lua.lua_istable(L, 3)) { Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed: LWF.addButtonEventListener"); } LWF.LWF a = Luna_LWF_LWF.check(L, 1); return(a.AddButtonEventHandlerLua()); }
public static int _bind_get_root(Lua.lua_State L) { if (Lua.lua_gettop(L) != 1 || Luna.get_uniqueid(L, 1) != LunaTraits_LWF_LWF.uniqueID) { Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed: LWF.LWF._root"); } LWF.LWF a = Luna_LWF_LWF.check(L, 1); Luna_LWF_Movie.push(L, a._root, false); return(1); }
private static int tostring_T(Lua.lua_State L) { Luna.userdataType ud = (Luna.userdataType)Lua.lua_touserdata(L, 1); LWF.LWF 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_LWF.className, buff }); return(1); }
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); }
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; }
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); }
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); }
public void AttachLWF(LWF attachLWF, string attachName, int attachDepth = -1, bool reorder = false, DetachHandler detachHandler = null) { if (m_attachedLWFs == null) { m_attachedLWFs = new AttachedLWFs(); m_detachedLWFs = new DetachDict(); m_attachedLWFList = new AttachedLWFList(); } LWFContainer lwfContainer; if (attachLWF.parent != null) { attachLWF.parent.m_attachedLWFs.TryGetValue( attachLWF.attachName, out lwfContainer); DeleteAttachedLWF(attachLWF.parent, lwfContainer, false); } else { if (m_attachedLWFs.TryGetValue(attachName, out lwfContainer)) DeleteAttachedLWF(this, lwfContainer); } if (!reorder && attachDepth >= 0 && attachDepth <= m_attachedLWFList.Count - 1) { lwfContainer = m_attachedLWFList[attachDepth]; if (lwfContainer != null) DeleteAttachedLWF(this, lwfContainer); } lwfContainer = new LWFContainer(this, attachLWF); if (attachLWF.interactive == true) m_lwf.interactive = true; attachLWF.parent = this; attachLWF.detachHandler = detachHandler; attachLWF.attachName = attachName; attachLWF.depth = attachDepth >= 0 ? attachDepth : m_attachedLWFList.Count; m_attachedLWFs[attachName] = lwfContainer; ReorderAttachedLWFList(reorder, attachLWF.depth, lwfContainer); m_lwf.isLWFAttached = true; }
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); } }
public static ColorTransform CalcColorTransform(LWF lwf, ColorTransform dst, ColorTransform src0, int src1Id) { if (src1Id == 0) { dst.Set(src0); } else if ((src1Id & (int)Constant.COLORTRANSFORM_FLAG) == 0) { AlphaTransform alphaTransform = lwf.data.alphaTransforms[src1Id]; dst.multi.red = src0.multi.red; dst.multi.green = src0.multi.green; dst.multi.blue = src0.multi.blue; dst.multi.alpha = src0.multi.alpha * alphaTransform.alpha; #if LWF_USE_ADDITIONALCOLOR dst.add.Set(src0.add); #endif } else { int colorTransformId = src1Id & ~(int)Constant.COLORTRANSFORM_FLAG; ColorTransform src1 = lwf.data.colorTransforms[colorTransformId]; CalcColorTransform(dst, src0, src1); } return dst; }
public static void FitForWidth(LWF lwf, float stageWidth) { float scale = stageWidth / lwf.width; float offsetX = -lwf.width / 2 * scale; float offsetY = -lwf.height / 2 * scale; lwf.property.Scale(scale, scale); lwf.property.Move(offsetX, offsetY); }
public IObject(LWF lwf, Movie parent, int type, int objId, int instId) : this(lwf, parent, (Type)type, objId, instId) { }
public virtual bool Load(string path, string texturePrefix = "", string fontPrefix = "", float zOffset = 0, float zRate = 1, int renderQueueOffset = 0, int cachingFrames = 0, Camera camera = null, bool autoPlay = true, LWFDataCallback lwfDataCallback = null, LWFCallback lwfLoadCallback = null, LWFCallback lwfDestroyCallback = null, LWFDataLoader lwfDataLoader = null, TextureLoader textureLoader = null, TextureUnloader textureUnloader = null) { lwfName = path; if (camera == null) camera = Camera.main; if (lwfLoadCallback != null) lwfLoadCallbacks.Add(lwfLoadCallback); if (lwfDestroyCallback != null) lwfDestroyCallbacks.Add(lwfDestroyCallback); LWF.Data data = ResourceCache.SharedInstance().LoadLWFData(lwfName, lwfDataLoader); if (data == null || !data.Check()) return false; if (lwfDataCallback != null && !lwfDataCallback(data)) return false; factory = new LWF.CombinedMeshRenderer.Factory( data, gameObject, zOffset, zRate, renderQueueOffset, camera, texturePrefix, fontPrefix, textureLoader, textureUnloader); lwf = new LWF.LWF(data, factory); if (cachingFrames == 0) { foreach (LWF.Format.Movie m in data.movies) { if (cachingFrames < m.frames) cachingFrames = m.frames; } if (cachingFrames == 0) cachingFrames = 1; } meshes = ResourceCache.SharedInstance().AddRenderedMesh( lwfName, cachingFrames); frameNo = 0; OnLoad(); if (autoPlay) Play(); return true; }
public virtual bool Load(string path, string texturePrefix = null, string fontPrefix = "", float zOffset = 0, float zRate = 1, int renderQueueOffset = 0, Camera renderCamera = null, Camera inputCamera = null, bool autoUpdate = true, bool useAdditionalColor = false, LWFDataCallback lwfDataCallback = null, LWFCallback lwfLoadCallback = null, LWFCallback lwfDestroyCallback = null, LWFDataLoader lwfDataLoader = null, TextureLoader textureLoader = null, TextureUnloader textureUnloader = null, string shaderName = "LWF" #if LWF_USE_LUA , object luaState = null #endif ) { callUpdate = autoUpdate; if (inputCamera == null) inputCamera = Camera.main; if (texturePrefix == null) { texturePrefix = Path.GetDirectoryName(path); if (!string.IsNullOrEmpty(texturePrefix)) { texturePrefix += "/"; } } if (lwfLoadCallback != null) lwfLoadCallbacks.Add(lwfLoadCallback); if (lwfDestroyCallback != null) lwfDestroyCallbacks.Add(lwfDestroyCallback); ResourceCache cache = ResourceCache.SharedInstance(); LWF.Data data = cache.LoadLWFData(path, lwfDataLoader); if (data == null || !data.Check()) return false; if (lwfDataCallback != null && !lwfDataCallback(data)) return false; RendererType rt = rendererType; #if UNITY_EDITOR if (!Application.isPlaying && rt == RendererType.CombinedMeshRenderer) rt = RendererType.DrawMeshRenderer; #endif if (rt == RendererType.CombinedMeshRenderer) { combinedMeshRendererfactory = new LWF.CombinedMeshRenderer.Factory( data, gameObject, zOffset, zRate, renderQueueOffset, mSortingLayerName, mSortingOrder, useAdditionalColor, renderCamera, inputCamera, texturePrefix, fontPrefix, textureLoader, textureUnloader, shaderName); factory = combinedMeshRendererfactory; } else if (rt == RendererType.DrawMeshRenderer) { factory = new LWF.DrawMeshRenderer.Factory( data, gameObject, zOffset, zRate, renderQueueOffset, mSortingLayerName, mSortingOrder, useAdditionalColor, renderCamera, inputCamera, texturePrefix, fontPrefix, textureLoader, textureUnloader, shaderName); } else /*if (rt == RendererType.UIVertexRenderer)*/ { factory = new LWF.UIVertexRenderer.Factory( data, gameObject, zOffset, zRate, renderQueueOffset, mSortingLayerName, mSortingOrder, useAdditionalColor, renderCamera, inputCamera, texturePrefix, fontPrefix, textureLoader, textureUnloader, shaderName); } #if LWF_USE_LUA lwf = new LWF.LWF(data, factory, luaState); #else lwf = new LWF.LWF(data, factory); #endif lwf.lwfLoader = (childPath, childTexturePrefix) => { LWF.Data childData = cache.LoadLWFData(childPath, lwfDataLoader); if (childData == null || !childData.Check()) return null; if (lwfDataCallback != null && !lwfDataCallback(childData)) return null; if (childTexturePrefix == null) childTexturePrefix = Path.GetDirectoryName(childPath) + "/"; LWF.UnityRenderer.Factory f; if (rt == RendererType.CombinedMeshRenderer) { f = new LWF.CombinedMeshRenderer.Factory( childData, gameObject, factory.zOffset, factory.zRate, factory.renderQueueOffset, mSortingLayerName, mSortingOrder, factory.useAdditionalColor, factory.renderCamera, factory.inputCamera, childTexturePrefix, factory.fontPrefix, factory.textureLoader, factory.textureUnloader, shaderName, true); } else if (rt == RendererType.DrawMeshRenderer) { f = new LWF.DrawMeshRenderer.Factory( childData, gameObject, factory.zOffset, factory.zRate, factory.renderQueueOffset, mSortingLayerName, mSortingOrder, factory.useAdditionalColor, factory.renderCamera, factory.inputCamera, childTexturePrefix, factory.fontPrefix, factory.textureLoader, factory.textureUnloader, shaderName); } else /*if (rt == RendererType.UIVertexRenderer)*/ { f = new LWF.UIVertexRenderer.Factory( childData, gameObject, factory.zOffset, factory.zRate, factory.renderQueueOffset, mSortingLayerName, mSortingOrder, factory.useAdditionalColor, factory.renderCamera, factory.inputCamera, childTexturePrefix, factory.fontPrefix, factory.textureLoader, factory.textureUnloader, shaderName); } #if LWF_USE_LUA LWF.LWF child = new LWF.LWF(childData, f, lwf.luaState); #else LWF.LWF child = new LWF.LWF(childData, f); #endif child.lwfLoader = lwf.lwfLoader; child.lwfUnloader = () => { ResourceCache.SharedInstance().UnloadLWFData(childPath); }; return child; }; lwf.lwfUnloader = () => { ResourceCache.SharedInstance().UnloadLWFData(path); }; OnLoad(); return true; }
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(); }
public virtual void OnDestroy() { isAlive = false; foreach (var c in lwfDestroyCallbacks) c(this); lwfDestroyCallbacks = null; if (lwf != null) { lwf.Destroy(); lwf = null; } }
public virtual bool Load(string path, string texturePrefix = "", string fontPrefix = "", float zOffset = 0, float zRate = 1, int renderQueueOffset = 0, Camera camera = null, bool autoUpdate = true, bool useAdditionalColor = false, LWFDataCallback lwfDataCallback = null, LWFCallback lwfLoadCallback = null, LWFCallback lwfDestroyCallback = null, LWFDataLoader lwfDataLoader = null, TextureLoader textureLoader = null, TextureUnloader textureUnloader = null #if LWF_USE_LUA , object luaState = null #endif ) { lwfName = path; callUpdate = autoUpdate; if (camera == null) camera = Camera.main; if (lwfLoadCallback != null) lwfLoadCallbacks.Add(lwfLoadCallback); if (lwfDestroyCallback != null) lwfDestroyCallbacks.Add(lwfDestroyCallback); LWF.Data data = ResourceCache.SharedInstance().LoadLWFData(lwfName, lwfDataLoader); if (data == null || !data.Check()) return false; if (lwfDataCallback != null && !lwfDataCallback(data)) return false; if (rendererFactoryConstructor != null) { RendererFactoryArguments arg = new RendererFactoryArguments( data, gameObject, zOffset, zRate, renderQueueOffset, useAdditionalColor, camera, texturePrefix, fontPrefix, textureLoader, textureUnloader); factory = rendererFactoryConstructor(arg); } else if (useCombinedMeshRenderer && data.textures.Length == 1) { factory = new LWF.CombinedMeshRenderer.Factory( data, gameObject, zOffset, zRate, renderQueueOffset, useAdditionalColor, camera, texturePrefix, fontPrefix, textureLoader, textureUnloader); } else { factory = new LWF.DrawMeshRenderer.Factory( data, gameObject, zOffset, zRate, renderQueueOffset, useAdditionalColor, camera, texturePrefix, fontPrefix, textureLoader, textureUnloader); } #if LWF_USE_LUA lwf = new LWF.LWF(data, factory, luaState); #else lwf = new LWF.LWF(data, factory); #endif OnLoad(); return true; }
public void DetachLWF(LWF detachLWF) { if (m_detachedLWFs != null && detachLWF != null && detachLWF.attachName != null) m_detachedLWFs[detachLWF.attachName] = true; }
public static void CalcMatrix(LWF lwf, Matrix dst, Matrix src0, int src1Id) { if (src1Id == 0) { dst.Set(src0); } else if ((src1Id & (int)Constant.MATRIX_FLAG) == 0) { Translate translate = lwf.data.translates[src1Id]; dst.scaleX = src0.scaleX; dst.skew0 = src0.skew0; dst.translateX = src0.scaleX * translate.translateX + src0.skew0 * translate.translateY + src0.translateX; dst.skew1 = src0.skew1; dst.scaleY = src0.scaleY; dst.translateY = src0.skew1 * translate.translateX + src0.scaleY * translate.translateY + src0.translateY; } else { int matrixId = src1Id & ~(int)Constant.MATRIX_FLAG_MASK; Matrix src1 = lwf.data.matrices[matrixId]; CalcMatrix(dst, src0, src1); } }
public static void ScaleForWidth(LWF lwf, float stageWidth) { float scale = stageWidth / lwf.width; lwf.property.Scale(scale, scale); }
public static void ScaleForHeight(LWF lwf, float stageHeight) { float scale = stageHeight / lwf.height; lwf.property.Scale(scale, scale); }
public Movie(LWF lwf, Movie parent, int objId, int instId, int matrixId = 0, int colorTransformId = 0, bool attached = false, MovieEventHandlers handler = 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; 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_property = new Property(lwf); m_matrix0 = new Matrix(); m_matrix1 = new Matrix(); m_colorTransform0 = new ColorTransform(); m_colorTransform1 = new ColorTransform(); m_displayList = new Object[m_data.depths]; PlayAnimation(ClipEvent.LOAD); m_eventHandlers = new EventHandlerDictionary(); m_handler.Add(lwf.GetMovieEventHandlers(this)); m_handler.Add(handler); if (m_handler != null) m_handler.Call(EventType.LOAD, this); lwf.ExecMovieCommand(); }
public virtual void OnDestroy() { isAlive = false; lwfDestroyCallbacks.ForEach(c => c(this)); lwfDestroyCallbacks = null; if (lwf != null) { lwf.Destroy(); lwf = null; } }