Пример #1
0
    // the most epic perversion so far
    private void UpdateItemPic()
    {
        for (int i = 0; i < 16; i++)
        {
            HumanSprites[i] = null;
            HumanItems[i]   = null;
        }

        HumanSprites[1] = UpdateHumanPic();
        for (int i = 0; i < (int)MapUnit.BodySlot.TopSlot; i++)
        {
            Item item = LogicHuman.GetItemFromBody((MapUnit.BodySlot)i);
            if (item == null)
            {
                continue;
            }

            int slot = item.Class.Option.Slot;
            if (slot == 0 || slot == 3 || slot == 11 || (slot >= 13 && slot <= 15))
            {
                continue;
            }

            ItemFile file1 = null;
            ItemFile file2 = null;

            int idx1 = -1;
            int idx2 = -1;

            if ((LogicHuman.Gender & MapHuman.GenderFlags.Fighter) != 0) // fighter
            {
                // order of fighter equipment:
                // cloak* -> FACE -> ring1 -> ring2 -> amulet -> boots -> mail -> bracers2 -> gauntlets2 -> cuirass
                //        -> bracers1 -> gauntlets1 -> helm -> weapon -> shield

                if ((LogicHuman.Gender & MapHuman.GenderFlags.Male) != 0)
                {
                    file1 = item.Class.File_BodyMF1;
                    file2 = item.Class.File_BodyMF2;
                }
                else
                {
                    file1 = item.Class.File_BodyFF1;
                    file2 = item.Class.File_BodyFF2;
                }

                file1.UpdateSprite();

                if (LogicHuman.IsHero)
                {
                    int fighter_cloak_num = ((LogicHuman.Gender & MapHuman.GenderFlags.Male) != 0) ? 0 : 1;
                    if (HumanCloak[fighter_cloak_num] == null)
                    {
                        HumanCloak[fighter_cloak_num] = Images.Load256AsTexture((fighter_cloak_num == 0) ? "graphics/interface/heroback/backm.256" : "graphics/interface/heroback/backf.256");
                    }
                    HumanSprites[0] = HumanCloak[fighter_cloak_num];
                }

                switch (slot)
                {
                case 9:     // bracers
                    file2.UpdateSprite();
                    idx1 = 7;
                    idx2 = 10;
                    break;

                case 10:     // gauntlets
                    file2.UpdateSprite();
                    idx1 = 8;
                    idx2 = 11;
                    break;

                case 4:     // ring
                    file2.UpdateSprite();
                    idx1 = 2;
                    idx2 = 3;
                    break;

                case 5:     // amulet
                    idx1 = 6;
                    break;

                case 6:     // helm
                    idx1 = 12;
                    break;

                case 7:     // mail
                    idx1 = 4;
                    break;

                case 8:     // cuirass
                    idx1 = 9;
                    break;

                case 12:     // boots
                    idx1 = 5;
                    break;

                case 1:     // weapon
                    idx1 = 13;
                    break;

                case 2:     // shield
                    idx1 = 14;
                    break;
                }
            }
            else if ((LogicHuman.Gender & MapHuman.GenderFlags.Mage) != 0)
            {
                // order of mage equipment:
                // cloak1 -> face -> ring1 -> ring2 -> boots ->
                //   gloves1 -> robe -> amulet -> cloak2 -> gloves2 -> hat -> staff

                if ((LogicHuman.Gender & MapHuman.GenderFlags.Male) != 0)
                {
                    file1 = item.Class.File_BodyMM1;
                    file2 = item.Class.File_BodyMM2;
                }
                else
                {
                    file1 = item.Class.File_BodyFM1;
                    file2 = item.Class.File_BodyFM2;
                }

                file1.UpdateSprite();

                switch (slot)
                {
                case 4:     // ring
                    file2.UpdateSprite();
                    idx1 = 2;
                    idx2 = 3;
                    break;

                case 10:     // gloves
                    file2.UpdateSprite();
                    idx1 = 5;
                    idx2 = 9;
                    break;

                case 8:     // cloak
                    file2.UpdateSprite();
                    idx1 = 0;
                    idx2 = 8;
                    break;

                case 5:     // amulet
                    idx1 = 7;
                    break;

                case 6:     // hat
                    idx1 = 10;
                    break;

                case 7:     // robe
                    idx1 = 6;
                    break;

                case 12:     // shoes
                    idx1 = 4;
                    break;

                case 1:     // staff
                    idx1 = 11;
                    break;
                }
            }

            if (idx1 >= 0)
            {
                HumanSprites[idx1] = file1.File;
                HumanItems[idx1]   = item;
            }

            if (idx2 >= 0)
            {
                HumanSprites[idx2] = file2.File;
                HumanItems[idx2]   = item;
            }
        }

        // generate supermesh of 16 materials
        if (HumanTexMaterials == null)
        {
            HumanTexMaterials = new Material[16];
            for (int i = 0; i < 16; i++)
            {
                HumanTexMaterials[i] = new Material(MainCamera.MainShader);
            }
        }

        for (int i = 0; i < 16; i++)
        {
            HumanTexMaterials[i].mainTexture = HumanSprites[i];
        }

        // materials done. make mesh itself
        if (HumanTexObject == null)
        {
            HumanTexObject      = Utils.CreateObject();
            HumanTexObject.name = "MapViewHuman$InfoPic";
            HumanTexRenderer    = HumanTexObject.AddComponent <MeshRenderer>();
            HumanTexFilter      = HumanTexObject.AddComponent <MeshFilter>();
            Mesh mesh = new Mesh();
            int  pp = 0, ppc = 0, ppt = 0;

            Vector3[] qv  = new Vector3[4 * 16];
            Vector2[] quv = new Vector2[4 * 16];

            for (int i = 0; i < 16; i++)
            {
                Utils.PutQuadInMesh(qv, quv, null, ref pp, ref ppt, ref ppc, 0, 0, 160, 240, new Rect(0, 0, 1, 1), new Color());
            }

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

            mesh.subMeshCount = 16;
            for (int i = 0; i < 16; i++)
            {
                int[] qt = { i * 4, i * 4 + 1, i * 4 + 2, i * 4 + 3 };
                mesh.SetIndices(qt, MeshTopology.Quads, i);
            }

            HumanTexFilter.mesh        = mesh;
            HumanTexRenderer.materials = HumanTexMaterials;
        }

        // update colors every time
        Color[] qc = new Color[4 * 16];
        for (int i = 0; i < 16; i++)
        {
            //Debug.LogFormat("up: {0} item {1}, dragitem = {2}", i, HumanItems[i], UiManager.Instance.DragItem);
            Color c = (HumanSprites[i] == null) ? new Color(0, 0, 0, 0) : new Color(1, 1, 1, (HumanItems[i] != null && HumanItems[i] == UiManager.Instance.DragItem) ? 0.5f : 1);
            for (int j = 0; j < 4; j++)
            {
                qc[i * 4 + j] = c;
            }
        }

        HumanTexFilter.mesh.colors = qc;
    }