Exemplo n.º 1
0
 public void UpdateSprite()
 {
     if (File == null)
     {
         File = Images.Load16A(FileName);
     }
 }
Exemplo n.º 2
0
    public static MapCursorSettings CreateCursor(string filename, int x, int y, float delay)
    {
        MapCursorSettings mcs = new MapCursorSettings();

        mcs.Xoffs = x;
        mcs.Yoffs = y;
        Images.AllodsSprite sprite = Images.LoadSprite(filename);
        mcs.Sprite  = sprite;
        mcs.Sprites = mcs.Sprite.Sprites;
        mcs.Delay   = delay;
        return(mcs);
    }
Exemplo n.º 3
0
 public void UpdateSprite()
 {
     if (!Loaded)
     {
         File                     = Images.Load256(FileName + ".256");
         FileMaterial             = new Material(MainCamera.MainShaderPaletted);
         FileMaterial.mainTexture = File.Atlas;
         FileMaterial.SetTexture("_Palette", File.OwnPalette);
         FileB  = Images.Load256(FileName + "b.256");
         Loaded = true;
     }
 }
Exemplo n.º 4
0
 // Unity occasionally erases this.
 private void CheckTexture()
 {
     if (_CombinedTexture == null || _CombinedTexture.Atlas == null)
     {
         _CombinedTexture = Images.LoadSprite(_Filename);
     }
     if (_CombinedMaterial == null)
     {
         _CombinedMaterial             = new Material(MainCamera.MainShaderPaletted);
         _CombinedMaterial.mainTexture = _CombinedTexture.Atlas;
     }
 }
Exemplo n.º 5
0
    private Mesh UpdateMesh(Images.AllodsSprite sprite, int frame, Mesh mesh, float shadowOffs, bool first)
    {
        Texture2D sTex  = sprite.Atlas;
        float     sW    = sprite.Sprites[frame].rect.width;
        float     sH    = sprite.Sprites[frame].rect.height;
        float     tMinX = sprite.AtlasRects[frame].xMin;
        float     tMinY = sprite.AtlasRects[frame].yMin;
        float     tMaxX = sprite.AtlasRects[frame].xMax;
        float     tMaxY = sprite.AtlasRects[frame].yMax;

        float centerY = 0.9f;

        float shadowOffsReal  = shadowOffs * sH;
        float shadowOffsXLeft = -shadowOffsReal * (1f - centerY);

        Vector3[] qv = new Vector3[4];
        int       pp = 0;

        qv[pp++] = new Vector3(shadowOffsReal, 0, 0);
        qv[pp++] = new Vector3(shadowOffsReal + sW, 0, 0);
        qv[pp++] = new Vector3(shadowOffsXLeft + sW, sH, 0);
        qv[pp++] = new Vector3(shadowOffsXLeft, sH, 0);

        Vector2[] quv = new Vector2[4];
        quv[0] = new Vector2(tMinX, tMinY);
        quv[1] = new Vector2(tMaxX, tMinY);
        quv[2] = new Vector2(tMaxX, tMaxY);
        quv[3] = new Vector2(tMinX, tMaxY);

        mesh.vertices = qv;
        mesh.uv       = quv;

        if (first)
        {
            Color[] qc = new Color[4];
            qc[0]       = qc[1] = qc[2] = qc[3] = new Color(1, 1, 1, 1);
            mesh.colors = qc;

            int[] qt = new int[4];
            for (int i = 0; i < qt.Length; i++)
            {
                qt[i] = i;
            }
            mesh.SetIndices(qt, MeshTopology.Quads, 0);
        }

        Renderer.material.mainTexture       = sTex;
        ShadowRenderer.material.mainTexture = sTex;

        return(mesh);
    }
Exemplo n.º 6
0
 public void UpdateSprite()
 {
     if (File != null)
     {
         return;
     }
     if (!Is16A)
     {
         File = Images.Load256(FileName, HasPalette);
     }
     else
     {
         File = Images.Load16A(FileName, HasPalette);
     }
 }
Exemplo n.º 7
0
    public Font(string filename, int spacing, int line_height, int space_width)
    {
        Spacing    = spacing;
        LineHeight = line_height;

        string[] fns = filename.Split('.');
        string   fnn = string.Join(".", fns, 0, fns.Length - 1);

        // first, load the data file.
        MemoryStream ms = ResourceManager.OpenRead(fnn + ".dat");

        if (ms == null)
        {
            Core.Abort("Couldn't load \"{0}\" as data file for \"{1}\"", fnn + ".dat", filename);
            return;
        }

        int          count = (int)ms.Length / 4;
        BinaryReader br    = new BinaryReader(ms);

        for (int i = 0; i < 224; i++)
        {
            if (i < count)
            {
                Widths[i] = br.ReadInt32();
            }
            else
            {
                Widths[i] = 0;
            }
        }

        br.Close();
        Widths[0] = space_width;

        CombinedTexture              = Images.LoadSprite(filename);
        CombinedMaterial             = new Material(MainCamera.MainShaderPaletted);
        CombinedMaterial.mainTexture = CombinedTexture.Atlas;
    }
Exemplo n.º 8
0
    public void Start()
    {
        UiManager.Instance.Subscribe(this);

        if (imgRadiob == null)
        {
            imgRadiob = Images.Load256("graphics/interface/radiob.256");
        }

        Renderer                      = gameObject.AddComponent <MeshRenderer>();
        Renderer.material             = new Material(MainCamera.MainShaderPaletted);
        Renderer.material.mainTexture = imgRadiob.Atlas;
        Renderer.material.SetTexture("_Palette", imgRadiob.OwnPalette);
        Filter = gameObject.AddComponent <MeshFilter>();

        LabelRendererA      = new AllodsTextRenderer(Fonts.Font1, Font.Align.Left, Width);
        LabelRendererA.Text = _Text;
        LabelObject         = LabelRendererA.GetNewGameObject(0.01f, transform, 100, 1);
        LabelObject.transform.localPosition = new Vector3(32, 0, 0);
        LabelSubObject = LabelObject.transform.GetChild(0).gameObject;
        LabelRenderer  = LabelObject.GetComponent <MeshRenderer>();

        UpdateMesh();
    }
Exemplo n.º 9
0
 public static void SetCursor(Images.AllodsSprite sprite)
 {
     CurItem.Sprite  = sprite;
     CurItem.Sprites = CurItem.Sprite.Sprites;
     SetCursor(CurItem);
 }
Exemplo n.º 10
0
    public void OnUpdate()
    {
        if (Renderer == null)
        {
            return;
        }

        if (LogicSack.GetVisibility() < 2)
        {
            oldVisibility          = false;
            Renderer.enabled       = false;
            ShadowRenderer.enabled = false;
            return;
        }
        else if (!oldVisibility)
        {
            Renderer.enabled       = true;
            ShadowRenderer.enabled = true;
            oldVisibility          = true;
            return;
        }

        if (LogicSack.DoUpdateView)
        {
            Renderer.enabled       = true;
            ShadowRenderer.enabled = true;

            if (_SackSprite == null)
            {
                _SackSprite = Images.Load256("graphics/backpack/sprites.256");
            }

            Images.AllodsSprite sprites = _SackSprite;

            if (!spriteSet)
            {
                Renderer.material = new Material(MainCamera.MainShaderPaletted);
                Renderer.material.SetTexture("_Palette", sprites.OwnPalette); // no palette swap for this one
                ShadowRenderer.material       = Renderer.material;
                ShadowRenderer.material.color = new Color(0, 0, 0, 0.5f);
                spriteSet = true;
            }

            // http://archive.allods2.eu/homeunix/article_sacks.php.htm
            int actualFrame = 0;
            if (LogicSack.Pack.Price >= 100000)
            {
                actualFrame = 5;
            }
            else if (LogicSack.Pack.Price >= 10000)
            {
                actualFrame = 4;
            }
            else if (LogicSack.Pack.Price >= 1000)
            {
                actualFrame = 3;
            }
            else if (LogicSack.Pack.Price >= 100)
            {
                actualFrame = 2;
            }
            else if (LogicSack.Pack.Price >= 10)
            {
                actualFrame = 1;
            }
            // always centered
            Vector2 xP = MapView.Instance.MapToScreenCoords(LogicObject.X + 0.5f, LogicObject.Y + 0.5f, 1, 1);
            transform.localPosition = new Vector3(xP.x - (float)sprites.Sprites[actualFrame].rect.width * 0.5f,
                                                  xP.y - (float)sprites.Sprites[actualFrame].rect.height * 0.5f,
                                                  MakeZFromY(xP.y) + 32);   // order sprites by y coordinate basically
            //Debug.Log(string.Format("{0} {1} {2}", xP.x, sprites.Sprites[0].rect.width, LogicObstacle.Class.CenterX));
            //Renderer.sprite = sprites.Sprites[actualFrame];
            SackMesh   = UpdateMesh(sprites, actualFrame, Filter.mesh, 0, (SackMesh == null));
            ShadowMesh = UpdateMesh(sprites, actualFrame, ShadowFilter.mesh, 0.3f, (ShadowMesh == null)); // 0.3 of sprite height

            LogicSack.DoUpdateView = false;
        }
    }
Exemplo n.º 11
0
    public void OnUpdate()
    {
        if (Renderer == null)
        {
            return;
        }

        if (LogicProjectile.Class == null)
        {
            oldVisibility          = false;
            Renderer.enabled       = false;
            ShadowRenderer.enabled = false;
            return;
        }

        if (LogicProjectile.GetVisibility() < 2)
        {
            oldVisibility          = false;
            Renderer.enabled       = false;
            ShadowRenderer.enabled = false;
            return;
        }
        else if (!oldVisibility)
        {
            Renderer.enabled       = true;
            ShadowRenderer.enabled = HasShadow;
            oldVisibility          = true;
            return;
        }

        if (LogicProjectile.DoUpdateView)
        {
            Renderer.enabled       = true;
            ShadowRenderer.enabled = HasShadow;

            /*if (_ProjectileSprite == null)
             *  _ProjectileSprite = Images.Load256("graphics/backpack/sprites.256");*/
            LogicProjectile.Class.UpdateSprite();

            Images.AllodsSprite sprites = LogicProjectile.Class.File;

            if (sprites == null || !spriteSet)
            {
                if (LogicProjectile.Class.ID == 7) // bat_sonic attack, apparently hardcoded
                {
                    Renderer.material = new Material(MainCamera.BatShader);
                }
                else
                {
                    Renderer.material = new Material(MainCamera.MainShaderPaletted);
                    if (LogicProjectile.Class.HasPalette)
                    {
                        Renderer.material.SetTexture("_Palette", sprites.OwnPalette); // no palette swap for this one
                    }
                    else
                    {
                        if (_BasePalette == null)
                        {
                            _BasePalette = Images.LoadPalette("graphics/projectiles/projectiles.pal");
                        }
                        Renderer.material.SetTexture("_Palette", _BasePalette);
                    }
                    ShadowRenderer.material       = Renderer.material;
                    ShadowRenderer.material.color = new Color(0, 0, 0, 0.5f);
                }
                spriteSet = true;
            }

            // This is a hack for prismatic spray support. Maybe something else in the future
            Renderer.material.color = new Color(LogicProjectile.Color.r,
                                                LogicProjectile.Color.g,
                                                LogicProjectile.Color.b,
                                                LogicProjectile.Color.a * LogicProjectile.Alpha);

            int actualFrame = 0;
            // now, projectile frame is RotationPhases * angle + CurrentFrame
            // thus, max count of frames is Count / RotationPhases
            int actualRotationPhases;
            if (LogicProjectile.Class.RotationPhases > 0)
            {
                actualRotationPhases = LogicProjectile.Class.RotationPhases;
            }
            else
            {
                actualRotationPhases = 16;
            }
            int actualAngle = 0;


            int lPA = (int)(Mathf.Round((float)LogicProjectile.Angle / 45) * 45) % 360;
            // calculate nearest angle

            bool doFlip = false;
            if (actualRotationPhases < 1)
            {
                actualAngle = 0;
            }
            else if (LogicProjectile.Class.Flip)
            {
                actualRotationPhases = actualRotationPhases / 2;
                if (LogicProjectile.Angle < 180)
                {
                    actualAngle = lPA * actualRotationPhases / 180;
                }
                else
                {
                    actualAngle = (180 - (lPA - 180)) * actualRotationPhases / 180;
                    doFlip      = true;
                }
            }
            else
            {
                actualAngle = lPA * actualRotationPhases / 360;
            }

            actualAngle %= 16;

            actualFrame = LogicProjectile.Class.Phases * actualAngle + LogicProjectile.CurrentFrame;
            //Debug.LogFormat("actualFrame = {0}, actualAngle = {1}", actualFrame, actualAngle);

            Vector2 xP;
            if (LogicProjectile.ZAbsolute)
            {
                xP    = new Vector2(LogicProjectile.ProjectileX * 32, LogicProjectile.ProjectileY * 32);
                xP.y -= LogicProjectile.ProjectileZ * 32;
            }
            else if (LogicProjectile.Class.ID != (int)AllodsProjectile.Lightning)
            {
                xP    = MapView.Instance.MapToScreenCoords(LogicProjectile.ProjectileX, LogicProjectile.ProjectileY, 1, 1);
                xP.y -= LogicProjectile.ProjectileZ * 32;
            }
            else
            {
                xP = MapView.Instance.MapToScreenCoords(LogicProjectile.ProjectileX, LogicProjectile.ProjectileY - LogicProjectile.ProjectileZ, 1, 1);
            }

            // always centered
            transform.localPosition = new Vector3(xP.x - LogicProjectile.Class.Width * 0.5f * LogicProjectile.Scale,
                                                  xP.y - LogicProjectile.Class.Height * 0.5f * LogicProjectile.Scale,
                                                  MakeZFromY(xP.y) - LogicProjectile.ZOffset - LogicProjectile.ProjectileZ * 32);   // order sprites by y coordinate basically

            transform.localScale = new Vector3(LogicProjectile.Scale, LogicProjectile.Scale, LogicProjectile.Scale);
            ShadowObject.transform.localScale = new Vector3(LogicProjectile.Scale, LogicProjectile.Scale, LogicProjectile.Scale);

            ProjectileMesh = UpdateMesh(sprites, actualFrame, Filter.mesh, 0, (ProjectileMesh == null), doFlip);
            ShadowMesh     = UpdateMesh(sprites, actualFrame, ShadowFilter.mesh, 0.3f, (ShadowMesh == null), doFlip); // 0.3 of sprite height

            LogicProjectile.DoUpdateView = false;
        }
    }
Exemplo n.º 12
0
    public void OnUpdate()
    {
        if (Renderer == null)
        {
            return;
        }

        if (LogicStructure.GetVisibility() == 0)
        {
            oldVisibility           = false;
            Renderer.enabled        = false;
            OverlayRenderer.enabled = false;
            if (ShadowRenderer != null)
            {
                ShadowRenderer.enabled = false;
            }
            return;
        }
        else if (!oldVisibility && !LogicStructure.DoUpdateView)
        {
            Renderer.enabled        = true;
            OverlayRenderer.enabled = true;
            if (ShadowRenderer != null)
            {
                ShadowRenderer.enabled = true;
            }
            oldVisibility = true;
            return;
        }

        if (LogicStructure.DoUpdateView)
        {
            Renderer.enabled        = true;
            OverlayRenderer.enabled = true;
            if (ShadowRenderer != null)
            {
                ShadowRenderer.enabled = true;
            }

            StructureClass      cls      = LogicStructure.Class;
            Images.AllodsSprite sprites  = LogicStructure.Class.File.File;
            Images.AllodsSprite spritesB = LogicStructure.Class.File.FileB;

            if (sprites == null)
            {
                LogicStructure.Class.File.UpdateSprite();
                sprites  = LogicStructure.Class.File.File;
                spritesB = LogicStructure.Class.File.FileB;
            }

            if (!MapView.Instance.SpritesBEnabled)
            {
                spritesB = null;
            }

            int newMaterialCount = (spritesB != null) ? 2 : 1;

            if (!spriteSet || Renderer.materials.Length != newMaterialCount)
            {
                List <Material> newMats        = new List <Material>();
                List <Material> newMatsShadow  = new List <Material>();
                List <Material> newMatsOverlay = new List <Material>();
                for (int i = 0; i < newMaterialCount; i++)
                {
                    newMats.Add(new Material(MainCamera.MainShaderPaletted));
                    newMatsOverlay.Add(new Material(MainCamera.MainShaderPaletted));
                    if (ShadowRenderer != null)
                    {
                        newMatsShadow.Add(new Material(MainCamera.MainShaderPaletted));
                    }
                }
                Renderer.materials        = newMats.ToArray();
                OverlayRenderer.materials = newMatsOverlay.ToArray();
                if (ShadowRenderer != null)
                {
                    ShadowRenderer.materials = newMats.ToArray();
                }

                for (int i = 0; i < newMaterialCount; i++)
                {
                    Renderer.materials[i].SetTexture("_Palette", sprites.OwnPalette);
                    Renderer.materials[i].SetFloat("_Lightness", 1f);
                    OverlayRenderer.materials[i].SetTexture("_Palette", sprites.OwnPalette);
                    OverlayRenderer.materials[i].SetFloat("_Lightness", 1f);
                    if (ShadowRenderer != null)
                    {
                        ShadowRenderer.materials[i].SetTexture("_Palette", sprites.OwnPalette);
                        ShadowRenderer.materials[i].color = new Color(0, 0, 0, 0.5f);
                    }
                }
                spriteSet = true;
            }

            int     actualFrame = cls.Frames[LogicStructure.CurrentFrame].Frame;
            Vector2 xP          = MapView.Instance.MapToScreenCoords(LogicObject.X + 0.5f, LogicObject.Y + 0.5f, LogicStructure.Width, LogicStructure.Height);
            transform.localPosition = new Vector3(xP.x - 16,
                                                  xP.y - 16 - (cls.FullHeight - cls.TileHeight) * 32,
                                                  MakeZFromY(xP.y) + 4);

            if (LogicStructure.Class.VariableSize)
            {
                StructureMesh = UpdateMesh(sprites, spritesB, 0, Filter.mesh, 0, 0, LogicStructure.Width, LogicStructure.Height, 0, (StructureMesh == null), false);
            }
            else
            {
                StructureMesh = UpdateMesh(sprites, spritesB, actualFrame, Filter.mesh, 0, cls.FullHeight - cls.TileHeight, cls.TileWidth, cls.TileHeight, 0, (StructureMesh == null), false);
                OverlayMesh   = UpdateMesh(sprites, spritesB, actualFrame, OverlayFilter.mesh, 0, 0, cls.TileWidth, cls.FullHeight - cls.TileHeight, 0, (OverlayMesh == null), false);
                if (ShadowFilter != null)
                {
                    ShadowMesh = UpdateMesh(sprites, spritesB, actualFrame, ShadowFilter.mesh, 0, 0, cls.TileWidth, cls.FullHeight, 0.3f, (ShadowMesh == null), false);
                }
            }

            LogicStructure.DoUpdateView = false;
        }
    }
Exemplo n.º 13
0
    public void Start()
    {
        if (wnd_LM == null)
        {
            wnd_LM                = Images.Load256("graphics/interface/lm.256");
            wnd_LMMat             = new Material(MainCamera.MainShaderPaletted);
            wnd_LMMat.mainTexture = wnd_LM.Atlas;
            wnd_LMMat.SetTexture("_Palette", wnd_LM.OwnPalette);
        }

        // init base mesh
        // make screenshot of background.
        // this should be done before everything, otherwise the previous window can't be screenshotted
        BgTexture = new RenderTexture(Screen.width, Screen.height, 24);
        Camera mc = MainCamera.Instance.GetComponent <Camera>();

        mc.targetTexture = BgTexture;
        bool cvis = MouseCursor.Instance.Visible;

        MouseCursor.Instance.Visible = false;
        mc.Render();
        MouseCursor.Instance.Visible = cvis;
        mc.targetTexture             = null;
        BgObject = Utils.CreatePrimitive(PrimitiveType.Quad);
        BgObject.transform.parent        = transform;
        BgObject.transform.localPosition = new Vector3(Screen.width / 2, Screen.height / 2, 0.025f);
        BgObject.transform.localScale    = new Vector3(Screen.width, -Screen.height, 1);
        MeshRenderer bgRenderer = BgObject.GetComponent <MeshRenderer>();

        bgRenderer.material             = new Material(MainCamera.WindowBgShader);
        bgRenderer.material.mainTexture = BgTexture;
        bgRenderer.material.color       = new Color(0.15f, 0.15f, 0.15f, 1);

        // init transform
        transform.parent     = UiManager.Instance.transform;
        transform.localScale = new Vector3(1, 1, 1);
        transform.position   = new Vector3(0, 0, UiManager.Instance.RegisterWindow(this));
        UiManager.Instance.Subscribe(this);

        MeshRenderer wRenderer = gameObject.AddComponent <MeshRenderer>();
        MeshFilter   wFilter   = gameObject.AddComponent <MeshFilter>();
        Mesh         wMesh     = new Mesh();

        wFilter.mesh       = wMesh;
        wRenderer.material = wnd_LMMat;

        int vcnt = (8 * Height + 8 * Width + 4 * Width * Height + 4 * 4) // main part
                   + (4 * Width + 4 * Height + 4 * 3)
                   + 4;                                                  // shadow border
        Color fullColor   = new Color(1, 1, 1, 1);
        Color shadowColor = new Color(0, 0, 0, 0.25f);

        Vector3[] qv  = new Vector3[vcnt];
        Vector2[] quv = new Vector2[vcnt];
        Color[]   qc  = new Color[vcnt];
        int[]     qt  = new int[vcnt];
        for (int i = 0; i < qt.Length; i++)
        {
            qt[i] = i;
        }
        int pp  = 0;
        int ppt = 0;
        int ppc = 0;

        int oScreenX = Screen.width / 2 - Width * 96 / 2;
        int oScreenY = Screen.height / 2 - Height * 64 / 2;

        WorkingArea = Utils.CreateObject();
        WorkingArea.transform.parent = transform;
        //WorkingArea.transform.localPosition = new Vector3(oScreenX, oScreenY, -0.025f);
        WorkingArea.transform.localPosition = new Vector3(oScreenX, oScreenY, -1.025f);

        int shadowOffs = 8;

        // main shadow
        //Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, 0, 0, Screen.width, Screen.height, wnd_LM.AtlasRects[0], shadowColor);


        // add shadow corners
        Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, shadowOffs + oScreenX + Width * 96, shadowOffs + oScreenY - 48, 48, 48, wnd_LM.AtlasRects[3], shadowColor);
        Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, shadowOffs + oScreenX + Width * 96, shadowOffs + oScreenY + Height * 64, 48, 48, wnd_LM.AtlasRects[8], shadowColor);
        Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, shadowOffs + oScreenX - 48, shadowOffs + oScreenY + Height * 64, 48, 48, wnd_LM.AtlasRects[6], shadowColor);

        for (int y = 0; y < Height; y++)
        {
            // left = 4
            // right = 5
            Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, shadowOffs + oScreenX + Width * 96, shadowOffs + oScreenY + y * 64, 48, 64, wnd_LM.AtlasRects[5], shadowColor);

            Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, oScreenX - 48, oScreenY + y * 64, 48, 64, wnd_LM.AtlasRects[4], fullColor);
            Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, oScreenX + Width * 96, oScreenY + y * 64, 48, 64, wnd_LM.AtlasRects[5], fullColor);

            for (int x = 0; x < Width; x++)
            {
                if (y == 0) // do only once.
                {
                    Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, shadowOffs + oScreenX + x * 96, shadowOffs + oScreenY + Height * 64, 96, 48, wnd_LM.AtlasRects[7], shadowColor);

                    Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, oScreenX + x * 96, oScreenY - 48, 96, 48, wnd_LM.AtlasRects[2], fullColor);
                    Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, oScreenX + x * 96, oScreenY + Height * 64, 96, 48, wnd_LM.AtlasRects[7], fullColor);
                }

                Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, oScreenX + x * 96, oScreenY + y * 64, 96, 64, wnd_LM.AtlasRects[0], fullColor);
            }
        }

        // add corners
        Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, oScreenX - 48, oScreenY - 48, 48, 48, wnd_LM.AtlasRects[1], fullColor);
        Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, oScreenX + Width * 96, oScreenY - 48, 48, 48, wnd_LM.AtlasRects[3], fullColor);
        Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, oScreenX + Width * 96, oScreenY + Height * 64, 48, 48, wnd_LM.AtlasRects[8], fullColor);
        Utils.PutQuadInMesh(qv, quv, qc, ref pp, ref ppt, ref ppc, oScreenX - 48, oScreenY + Height * 64, 48, 48, wnd_LM.AtlasRects[6], fullColor);

        wMesh.vertices = qv;
        wMesh.uv       = quv;
        wMesh.colors   = qc;
        wMesh.SetIndices(qt, MeshTopology.Quads, 0);

        OnStart();
    }
Exemplo n.º 14
0
    public void OnUpdate()
    {
        if (Renderer == null)
        {
            return;
        }

        if (LogicProjectile.GetVisibility() < 2)
        {
            oldVisibility          = false;
            Renderer.enabled       = false;
            ShadowRenderer.enabled = false;
            return;
        }
        else if (!oldVisibility)
        {
            Renderer.enabled       = true;
            ShadowRenderer.enabled = HasShadow;
            oldVisibility          = true;
            return;
        }

        if (LogicProjectile.DoUpdateView)
        {
            Renderer.enabled       = true;
            ShadowRenderer.enabled = HasShadow;

            /*if (_ProjectileSprite == null)
             *  _ProjectileSprite = Images.Load256("graphics/backpack/sprites.256");*/
            LogicProjectile.Class.UpdateSprite();

            Images.AllodsSprite sprites = LogicProjectile.Class.File;

            if (sprites == null || !spriteSet)
            {
                if (LogicProjectile.Class.ID == 7) // bat_sonic attack, apparently hardcoded
                {
                    Renderer.material = new Material(MainCamera.BatShader);
                }
                else
                {
                    Renderer.material = new Material(MainCamera.MainShaderPaletted);
                    if (LogicProjectile.Class.HasPalette)
                    {
                        Renderer.material.SetTexture("_Palette", sprites.OwnPalette); // no palette swap for this one
                    }
                    else
                    {
                        if (_BasePalette == null)
                        {
                            _BasePalette = Images.LoadPalette("graphics/projectiles/projectiles.pal");
                        }
                        Renderer.material.SetTexture("_Palette", _BasePalette);
                    }
                    ShadowRenderer.material       = Renderer.material;
                    ShadowRenderer.material.color = new Color(0, 0, 0, 0.5f);
                }
                spriteSet = true;
            }

            int actualFrame = 0;
            // now, projectile frame is RotationPhases * angle + CurrentFrame
            // thus, max count of frames is Count / RotationPhases
            int actualRotationPhases;
            if (LogicProjectile.Class.RotationPhases > 0)
            {
                actualRotationPhases = LogicProjectile.Class.RotationPhases;
            }
            else
            {
                actualRotationPhases = 16;
            }
            int actualAngle = 0;


            int lPA = (int)(Mathf.Round((float)LogicProjectile.Angle / 45) * 45) % 360;
            // calculate nearest angle

            bool doFlip = false;
            if (actualRotationPhases < 1)
            {
                actualAngle = 0;
            }
            else if (LogicProjectile.Class.Flip)
            {
                actualRotationPhases = actualRotationPhases / 2;
                if (LogicProjectile.Angle < 180)
                {
                    actualAngle = lPA * actualRotationPhases / 180;
                }
                else
                {
                    actualAngle = (180 - (lPA - 180)) * actualRotationPhases / 180;
                    doFlip      = true;
                }
            }
            else
            {
                actualAngle = lPA * actualRotationPhases / 360;
            }

            actualAngle %= 16;

            actualFrame = LogicProjectile.Class.Phases * actualAngle + LogicProjectile.CurrentFrame;
            //Debug.LogFormat("actualFrame = {0}, actualAngle = {1}", actualFrame, actualAngle);

            // always centered
            Vector2 xP = MapView.Instance.MapToScreenCoords(LogicProjectile.ProjectileX, LogicProjectile.ProjectileY - LogicProjectile.ProjectileZ, 1, 1);
            if (LogicProjectile.Class.ID == 7)
            {
                transform.localPosition = new Vector3(xP.x - 16,
                                                      xP.y - 16,
                                                      MakeZFromY(xP.y) - 128); // order sprites by y coordinate basically
            }
            else
            {
                transform.localPosition = new Vector3(xP.x - sprites.Sprites[actualFrame].rect.width * 0.5f,
                                                      xP.y - sprites.Sprites[actualFrame].rect.height * 0.5f,
                                                      MakeZFromY(xP.y) - 128); // order sprites by y coordinate basically
            }

            //Debug.Log(string.Format("{0} {1} {2}", xP.x, sprites.Sprites[0].rect.width, LogicObstacle.Class.CenterX));
            //Renderer.sprite = sprites.Sprites[actualFrame];
            ProjectileMesh = UpdateMesh(sprites, actualFrame, Filter.mesh, 0, (ProjectileMesh == null), doFlip);
            ShadowMesh     = UpdateMesh(sprites, actualFrame, ShadowFilter.mesh, 0.3f, (ShadowMesh == null), doFlip); // 0.3 of sprite height

            LogicProjectile.DoUpdateView = false;
        }
    }
Exemplo n.º 15
0
 public ItemPackFile(string fname)
 {
     FileName = fname;
     File     = null;
 }
Exemplo n.º 16
0
    private Mesh UpdateMesh(Images.AllodsSprite sprite, Images.AllodsSprite spriteB, int frame, Mesh mesh, int x, int y, int w, int h, float shadowOffs, bool first, bool onlyColors)
    {
        Texture2D sTex  = sprite.Atlas;
        Texture2D sTexB = (spriteB != null) ? spriteB.Atlas : null;

        bool isBridge       = LogicStructure.Class.VariableSize;
        int  totalAnimCount = 0;

        foreach (char ch in LogicStructure.Class.AnimMask)
        {
            if (ch == '+')
            {
                totalAnimCount++;
            }
        }
        float shadowOffsPerY    = shadowOffs * 32;
        float shadowOffsFromReg = -((float)LogicStructure.Class.ShadowY / LogicStructure.Class.FullHeight * shadowOffs);
        int   fw = isBridge ? LogicStructure.Width : LogicStructure.Class.TileWidth;
        int   fh = isBridge ? LogicStructure.Height : LogicStructure.Class.FullHeight;

        if (isBridge)
        {
            w = fw;
            h = fh;
            x = 0;
            y = 0;
        }

        bool dead = (!LogicStructure.Class.Indestructible && LogicStructure.Health <= 0);

        int vertexCount = (spriteB != null) ? 8 : 4;

        int subMeshCount = (spriteB != null) ? 2 : 1;

        if (!onlyColors || first || (mesh.subMeshCount != subMeshCount))
        {
            mesh.subMeshCount = subMeshCount;

            Vector3[] qv  = new Vector3[w * h * vertexCount];
            Vector2[] quv = new Vector2[w * h * vertexCount];

            // populate vertices
            int pp  = 0;
            int ppt = 0;
            for (int j = 0; j < vertexCount / 4; j++)
            {
                for (int ly = y; ly < y + h; ly++)
                {
                    float actualOffsetX = shadowOffsFromReg + shadowOffsPerY * (fh - ly - 1);
                    for (int lx = x; lx < x + w; lx++)
                    {
                        qv[pp++] = new Vector3(lx * 32 + shadowOffsPerY + actualOffsetX, ly * 32, 0);
                        qv[pp++] = new Vector3(lx * 32 + 32 + shadowOffsPerY + actualOffsetX, ly * 32, 0);
                        qv[pp++] = new Vector3(lx * 32 + 32 + actualOffsetX, ly * 32 + 32, 0);
                        qv[pp++] = new Vector3(lx * 32 + actualOffsetX, ly * 32 + 32, 0);

                        int realFrame;
                        if (!isBridge)
                        {
                            // handle odd structure animation method
                            realFrame = ly * fw + lx;
                            if (dead)
                            {
                                realFrame = sprite.Sprites.Length - (fw * fh) + realFrame; // last frame is always full flat frame
                            }
                            else if (frame > 0 && LogicStructure.Class.AnimMask[realFrame] == '+')
                            {
                                if (fw == 1 && fh == 1)
                                {
                                    realFrame = frame;
                                }
                                else
                                {
                                    int preAnimCount = 0;
                                    for (int i = realFrame - 1; i >= 0; i--)
                                    {
                                        if (LogicStructure.Class.AnimMask[i] == '+')
                                        {
                                            preAnimCount++;
                                        }
                                    }
                                    realFrame = fw * fh + totalAnimCount * (frame - 1) + preAnimCount;
                                }
                            }
                        }
                        else
                        {
                            // handle resizable things (normally bridges)
                            int bx = 1;
                            int by = 1;

                            if (lx == 0)
                            {
                                bx = 0;
                            }
                            else if (lx == fw - 1)
                            {
                                bx = 2;
                            }

                            if (ly == 0)
                            {
                                by = 0;
                            }
                            else if (ly == fh - 1)
                            {
                                by = 2;
                            }

                            realFrame = by * 3 + bx;
                        }

                        Rect texRect = (j == 0) ? sprite.AtlasRects[realFrame] : spriteB.AtlasRects[realFrame];

                        quv[ppt++] = new Vector2(texRect.xMin, texRect.yMin);
                        quv[ppt++] = new Vector2(texRect.xMax, texRect.yMin);
                        quv[ppt++] = new Vector2(texRect.xMax, texRect.yMax);
                        quv[ppt++] = new Vector2(texRect.xMin, texRect.yMax);
                    }
                }
            }

            mesh.vertices = qv;
            mesh.uv       = quv;
        }

        Color[] qc          = new Color[w * h * vertexCount];
        int     ownDynLight = LogicStructure.GetLightValue();
        int     ppc         = 0;

        for (int i = 0; i < vertexCount / 4; i++)
        {
            for (int ly = y; ly < y + h; ly++)
            {
                int lTy = ly - (LogicStructure.Class.FullHeight - LogicStructure.Class.TileHeight);
                for (int lx = x; lx < x + w; lx++)
                {
                    float cellLight = 0.5f;
                    // check if terrain has dynlights. if so, add to current lightness.
                    int currentLightAtNode = Mathf.Max(MapLogic.Instance.Nodes[LogicStructure.X + lx, LogicStructure.Y + lTy].DynLight, ownDynLight);
                    if (currentLightAtNode > 0)
                    {
                        cellLight += (float)currentLightAtNode / 255;
                    }
                    if (cellLight > 1f)
                    {
                        cellLight = 1f;
                    }

                    if (i == 0)
                    {
                        qc[ppc++] = new Color(cellLight, cellLight, cellLight, 1f);
                        qc[ppc++] = new Color(cellLight, cellLight, cellLight, 1f);
                        qc[ppc++] = new Color(cellLight, cellLight, cellLight, 1f);
                        qc[ppc++] = new Color(cellLight, cellLight, cellLight, 1f);
                    }
                    else
                    {
                        qc[ppc++] = new Color(cellLight, cellLight, cellLight, 0.5f);
                        qc[ppc++] = new Color(cellLight, cellLight, cellLight, 0.5f);
                        qc[ppc++] = new Color(cellLight, cellLight, cellLight, 0.5f);
                        qc[ppc++] = new Color(cellLight, cellLight, cellLight, 0.5f);
                    }
                }
            }
        }

        mesh.colors = qc;

        int[] qt = new int[w * h * 4];
        for (int i = 0; i < qt.Length; i++)
        {
            qt[i] = i;
        }
        mesh.SetIndices(qt, MeshTopology.Quads, 0);

        if (spriteB != null)
        {
            int[] qtB = new int[w * h * 4];
            for (int i = 0; i < qtB.Length; i++)
            {
                qtB[i] = qt.Length + i;
            }
            mesh.SetIndices(qtB, MeshTopology.Quads, 1);
        }

        Renderer.materials[0].mainTexture        = sTex;
        OverlayRenderer.materials[0].mainTexture = sTex;
        if (ShadowRenderer != null)
        {
            ShadowRenderer.materials[0].mainTexture = sTex;
        }

        if (spriteB != null)
        {
            Renderer.materials[1].mainTexture        = sTexB;
            OverlayRenderer.materials[1].mainTexture = sTexB;
            if (ShadowRenderer != null)
            {
                ShadowRenderer.materials[1].mainTexture = sTexB;
            }
        }

        return(mesh);
    }
Exemplo n.º 17
0
    public void OnUpdate()
    {
        if (Renderer == null)
        {
            return;
        }

        if (LogicStructure.GetVisibility() == 0)
        {
            oldVisibility           = false;
            Renderer.enabled        = false;
            OverlayRenderer.enabled = false;
            if (ShadowRenderer != null)
            {
                ShadowRenderer.enabled = false;
            }
            return;
        }
        else if (!oldVisibility && !LogicStructure.DoUpdateView)
        {
            Renderer.enabled        = true;
            OverlayRenderer.enabled = true;
            if (ShadowRenderer != null)
            {
                ShadowRenderer.enabled = true;
            }
            oldVisibility = true;
            return;
        }

        if (LogicStructure.DoUpdateView)
        {
            Renderer.enabled        = true;
            OverlayRenderer.enabled = true;
            if (ShadowRenderer != null)
            {
                ShadowRenderer.enabled = true;
            }

            StructureClass      cls     = LogicStructure.Class;
            Images.AllodsSprite sprites = LogicStructure.Class.File.File;

            if (!spriteSet)
            {
                LogicStructure.Class.File.UpdateSprite();
                sprites           = LogicStructure.Class.File.File;
                Renderer.material = LogicStructure.Class.File.FileMaterial;
                Renderer.material.SetTexture("_Palette", sprites.OwnPalette);
                Renderer.material.SetFloat("_Lightness", 1f);
                OverlayRenderer.material = LogicStructure.Class.File.FileMaterial;
                OverlayRenderer.material.SetTexture("_Palette", sprites.OwnPalette);
                OverlayRenderer.material.SetFloat("_Lightness", 1f);
                if (ShadowRenderer != null)
                {
                    ShadowRenderer.material = LogicStructure.Class.File.FileMaterial;
                    ShadowRenderer.material.SetTexture("_Palette", sprites.OwnPalette);
                    ShadowRenderer.material.color = new Color(0, 0, 0, 0.5f);
                }
                spriteSet = true;
            }

            int     actualFrame = cls.Frames[LogicStructure.CurrentFrame].Frame;
            Vector2 xP          = MapView.Instance.MapToScreenCoords(LogicObject.X + 0.5f, LogicObject.Y + 0.5f, LogicStructure.Width, LogicStructure.Height);
            transform.localPosition = new Vector3(xP.x - 16,
                                                  xP.y - 16 - (cls.FullHeight - cls.TileHeight) * 32,
                                                  MakeZFromY(xP.y) + 4);

            if (LogicStructure.Class.VariableSize)
            {
                StructureMesh = UpdateMesh(sprites, 0, Filter.mesh, 0, 0, LogicStructure.Width, LogicStructure.Height, 0, (StructureMesh == null), false);
            }
            else
            {
                StructureMesh = UpdateMesh(sprites, actualFrame, Filter.mesh, 0, cls.FullHeight - cls.TileHeight, cls.TileWidth, cls.TileHeight, 0, (StructureMesh == null), false);
                OverlayMesh   = UpdateMesh(sprites, actualFrame, OverlayFilter.mesh, 0, 0, cls.TileWidth, cls.FullHeight - cls.TileHeight, 0, (OverlayMesh == null), false);
                if (ShadowFilter != null)
                {
                    ShadowMesh = UpdateMesh(sprites, actualFrame, ShadowFilter.mesh, 0, 0, cls.TileWidth, cls.FullHeight, 0.3f, (ShadowMesh == null), false);
                }
            }

            LogicStructure.DoUpdateView = false;
        }
        else if (Renderer != null)
        {
            StructureClass      cls     = LogicStructure.Class;
            Images.AllodsSprite sprites = LogicStructure.Class.File.File;
            int actualFrame             = LogicStructure.Class.Frames[LogicStructure.CurrentFrame].Frame;

            StructureMesh = UpdateMesh(sprites, actualFrame, Filter.mesh, 0, cls.FullHeight - cls.TileHeight, cls.TileWidth, cls.TileHeight, 0, (StructureMesh == null), false);
            OverlayMesh   = UpdateMesh(sprites, actualFrame, OverlayFilter.mesh, 0, 0, cls.TileWidth, cls.FullHeight - cls.TileHeight, 0, (OverlayMesh == null), false);
        }
    }