Exemplo n.º 1
0
    private IEnumerator ImageViewWithFrame(
        CardData card,
        ImageViewWithFrame frame,
        int imageSize,
        string resourcePath,
        float leftMargin = 0,
        float topMargin = 0,
        float rightMargin = 0,
        float bottomMargin = 0)
    {
        Texture texture;

        if (!string.IsNullOrEmpty(resourcePath))
        {
            texture = Resources.Load<Texture>(resourcePath);
        }
        else
        {
            string path = WebCache.GetCachedPath(card);
            WWW www = new WWW(path);
            yield return www;

            texture = www.texture;
        }

        frame.BigSize = imageSize;
        frame.FrameTexture = FrameObject;
        frame.ImageTexture = texture;
        frame.LeftMargin = leftMargin;
        frame.TopMargin = topMargin;
        frame.RightMargin = rightMargin;
        frame.BottomMargin = bottomMargin;

        frame.MeasureSize();
    }
Exemplo n.º 2
0
        private void AddToSet(ImageViewWithFrame imageView)
        {
            Vector3 p = new Vector3(Scale(10), Scale(10));

            var startPosition = Camera.main.WorldToScreenPoint(SpawnMyDeckStartLocation.transform.position);
            startPosition.y = Screen.height - startPosition.y;

            var endPosition = Camera.main.WorldToScreenPoint(SpawnMyDeckEndLocation.transform.position);
            endPosition.y = Screen.height - endPosition.y;

            float controlWidth = endPosition.x - startPosition.x;
            float fullSize = controlWidth / 3.6f;

            GroupControl item = new GroupControl();

            var framedImage = new ImageViewWithFrame();
            framedImage.BigSize = (int)(fullSize * 0.9f);
            framedImage.ImageTexture = imageView.ImageTexture;
            framedImage.FrameTexture = imageView.FrameTexture;
            framedImage.LeftMargin = 0;
            framedImage.RightMargin = (int)(fullSize * 0.05f);
            framedImage.TopMargin = 0;
            framedImage.MeasureSize();

            item.Items.Add(framedImage);

            Rect rect = new Rect();
            rect.x = (int)(p.x + (int)(fullSize * 0.05f) + (fullSize * (x % breakIn)));
            rect.y = (int)(p.y + (((p.y * 2) + framedImage.BigSize) * (int)(x / breakIn)));
            rect.width = framedImage.Rect.width;
            rect.height = framedImage.Rect.height;
            item.Rect = rect;

            var cancelImage = new ImageView();
            cancelImage.Width = cancelImage.Height = (int)(fullSize * 0.22);
            cancelImage.ImageScaleMode = ScaleMode.ScaleToFit;
            cancelImage.Offset.x = (int)(fullSize * 0.74);
            cancelImage.Offset.y = (int)(fullSize * 0.11);
            cancelImage.ImageTexture = MiniCancelTexture;
            cancelImage.MeasureSize();

            // Revert auto scalling stuff in measure size.
            rect = cancelImage.ImageRect;
            rect.x = cancelImage.Offset.x;
            rect.y = cancelImage.Offset.y;
            rect.width = rect.height = cancelImage.Width;
            cancelImage.ImageRect = rect;

            item.Tag = imageView.Tag;
            item.Items.Add(cancelImage);
            selectedCardsImages.Add(item);

            item.MeasureSize();

            selectedCardsScrollContentHeight = item.Rect.y + item.Rect.height;
            ++x;
        }
Exemplo n.º 3
0
        private ImageViewWithFrame AddToSearchResults(
            Texture texture,
            int imageSize,
            float leftRightMargin,
            float topBottomMargin)
        {
            var image = new ImageViewWithFrame();
            image.BigSize = imageSize;
            image.ImageTexture = texture;
            image.FrameTexture = FrameTexture;
            image.LeftMargin = leftRightMargin / 2.0f;
            image.RightMargin = leftRightMargin / 2.0f;
            image.TopMargin = topBottomMargin / 2.0f;
            image.BottomMargin = topBottomMargin / 2.0f;

            image.MeasureSize();

            return image;
        }
Exemplo n.º 4
0
    private void OnGUI()
    {
        Vector3 p = Camera.main.WorldToScreenPoint(SpawnObject.transform.position);
        Vector3 e = Camera.main.WorldToScreenPoint(SpawnEndObject.transform.position);
        p.y = Screen.height - p.y;
        e.y = Screen.height - e.y;

        if (state == ShowDeckState)
        {
            int fullItemWidth = BigSize + Spacing;

            float scaledBigFrameOffsetX = Scale(14) * BigScale;
            float scaledBigFrameOffsetY = Scale(13) * BigScale;
            float scaledBigFrameWidth = BigSize + (Scale(30) * BigScale);
            float scaledBigFrameHeight = BigSize + (Scale(27) * BigScale);

            float scaledSmallFrameOffsetX = Scale(5) * SmallScale;
            float scaledSmallFrameOffsetY = Scale(5) * SmallScale;
            float scaledSmallFrameWidth = SmallSize + (Scale(10) * SmallScale);
            float scaledSmallFrameHeight = SmallSize + (Scale(9) * SmallScale);

            float width = (fullItemWidth * size) + p.x + (Screen.width - e.x - Spacing);
            scrollViewVector = GUI.BeginScrollView(new Rect(0, p.y - 20, Screen.width, scaledBigFrameHeight + Scale(25)), scrollViewVector, new Rect(0, 0, width, scaledBigFrameHeight));

            p.y = 10;

            float firstImageOffsetY = p.y + (Scale(7) * BigScale);
            float secondImageOffsetY = p.y + SmallSize + (Scale(13 + 7) * BigScale);

            p.x -= scaledBigFrameOffsetX - scaledSmallFrameOffsetX;

            int imageIndex = 0;
            for (int i = 0; i < size; ++i)
            {
                ScaleMode scaleMode = ScaleMode.ScaleAndCrop;

                Rect imageRect = CalculatePosition(p, p.y, scaledBigFrameWidth + 200);

                GUI.BeginGroup(imageRect);

                GUI.DrawTexture(new Rect(scaledBigFrameOffsetX, scaledBigFrameOffsetY, BigSize, BigSize), textures[imageIndex], scaleMode);
                GUI.DrawTexture(new Rect(0, 0, scaledBigFrameWidth, scaledBigFrameHeight), FrameObject, ScaleMode.StretchToFill);

                ++imageIndex;
                float x = scaledBigFrameOffsetX - Scale(9);
                GUI.DrawTexture(new Rect(x, firstImageOffsetY, SmallSize, SmallSize), textures[imageIndex], scaleMode);
                GUI.DrawTexture(new Rect(x - scaledSmallFrameOffsetX, firstImageOffsetY - scaledSmallFrameOffsetY, scaledSmallFrameWidth, scaledSmallFrameHeight), FrameObject, ScaleMode.StretchToFill);

                ++imageIndex;
                GUI.DrawTexture(new Rect(x, secondImageOffsetY, SmallSize, SmallSize), textures[imageIndex], scaleMode);
                GUI.DrawTexture(new Rect(x - scaledSmallFrameOffsetX, secondImageOffsetY - scaledSmallFrameOffsetY, scaledSmallFrameWidth, scaledSmallFrameHeight), FrameObject, ScaleMode.StretchToFill);
                ++imageIndex;

                GroupControl groupControl = new GroupControl();
                ImageViewWithFrame frame = new ImageViewWithFrame();
                frame.BigSize = BigSize;
                frame.FrameTexture = FrameObject;
                frame.ImageTexture = textures[imageIndex];
                frame.RightMargin = 30;

                frame.MeasureSize();
                //frame.Render();
                groupControl.Items.Add(frame);

                frame = new ImageViewWithFrame();
                frame.BigSize = SmallSize;
                frame.FrameTexture = FrameObject;
                frame.ImageTexture = textures[imageIndex];
                frame.LeftMargin = x - scaledSmallFrameOffsetX;
                frame.TopMargin = firstImageOffsetY - scaledSmallFrameOffsetY;

                frame.MeasureSize();
                //frame.Render();
                groupControl.Items.Add(frame);

                frame = new ImageViewWithFrame();
                frame.BigSize = SmallSize;
                frame.FrameTexture = FrameObject;
                frame.ImageTexture = textures[imageIndex];
                frame.LeftMargin = x - scaledSmallFrameOffsetX;
                frame.TopMargin = secondImageOffsetY - scaledSmallFrameOffsetY;

                frame.MeasureSize();
                //frame.Render();
                groupControl.Items.Add(frame);

                groupControl.Render();

                GUI.EndGroup();

                p.x += fullItemWidth;
            }

            GUI.EndScrollView(true);
        }

        if (Input.GetMouseButtonDown(0) && !isMousePressed && mouseTimeout <= 0)
        {
            mouseTimeout = 30;

            isMousePressed = true;

            MouseDown();
        }
        else
        {
            isMousePressed = false;

            if (mouseTimeout > 0)
            {
                --mouseTimeout;
            }
        }
    }
Exemplo n.º 5
0
        private void AddToSet2(ImageViewWithFrame imageView)
        {
            Vector3 p = new Vector3(Scale(10), Scale(10));

            var startPosition = Camera.main.WorldToScreenPoint(SpawnMyDeckStartLocation.transform.position);
            startPosition.y = Screen.height - startPosition.y;

            var endPosition = Camera.main.WorldToScreenPoint(SpawnMyDeckEndLocation.transform.position);
            endPosition.y = Screen.height - endPosition.y;

            float controlWidth = endPosition.x - startPosition.x;
            float fullSize = controlWidth / 3.6f;

            var framedImage = new ImageViewWithFrame();
            framedImage.BigSize = (int)(fullSize * 0.9f);
            framedImage.ImageTexture = imageView.ImageTexture;
            framedImage.FrameTexture = imageView.FrameTexture;
            framedImage.LeftMargin = p.x + (int)(fullSize * 0.05f) + (fullSize * (x % breakIn));
            framedImage.RightMargin = (int)(fullSize * 0.05f);
            framedImage.TopMargin = p.y + (((p.y * 2) + framedImage.BigSize) * (int)(x / breakIn));
            framedImage.MeasureSize();

            var cancelImage = new ImageView();
            cancelImage.Width = cancelImage.Height = (int)(framedImage.BigSize * 0.12);
            cancelImage.ImageScaleMode = ScaleMode.ScaleToFit;
            cancelImage.LeftMargin = (int)framedImage.LeftMargin + (int)(framedImage.BigSize * 0.85);
            cancelImage.TopMargin = (int)framedImage.TopMargin + Scale(5);
            cancelImage.ImageTexture = MiniCancelTexture;
            cancelImage.MeasureSize();

            selectedCardsImages.Add(framedImage);

            selectedCardsScrollContentHeight = framedImage.TopMargin + framedImage.Rect.height;
            ++x;
        }
Exemplo n.º 6
0
    private IEnumerator LoadDecks()
    {
        deckControls.Clear();
        scrollViewVector = Vector2.zero;

        Vector3 p = Camera.main.WorldToScreenPoint(SpawnObject.transform.position);
        p.y = Screen.height - p.y;

        Vector3 e = Camera.main.WorldToScreenPoint(SpawnEndObject.transform.position);
        e.y = Screen.height - e.y;

        BigSize = (int)(((e.y - p.y) * 0.8f) - Scale(14));
        BigScale = BigSize / (float)Scale(120);

        //Debug.Log(e.y + "-" + p.y + "-" + Scale(14) + "=" + BigSize + "  =>  BigScale = " + BigScale);

        SmallSize = BigSize / 3;
        SmallScale = SmallSize / (float)Scale(40);

        p.y = 10;

        float scaledBigFrameOffsetX = Scale(14) * BigScale;

        float scaledSmallFrameOffsetX = Scale(5) * SmallScale;
        float scaledSmallFrameOffsetY = Scale(5) * SmallScale;

        float firstImageOffsetY = p.y + (Scale(7) * BigScale);
        float secondImageOffsetY = p.y + SmallSize + (Scale(13 + 7) * BigScale);

        p.x -= scaledBigFrameOffsetX - scaledSmallFrameOffsetX;

        if (size > 0)
        {
            DataMessenger.SelectedDeck = decks[0];
        }

        size = decks.Count;
        for (int i = 0; i < size; ++i)
        {
            bool isInResources = decks[i].ImageLocation == "Resources";
            List<CardData> cards = new List<CardData>(decks[i].Cards).OrderBy(o => Guid.NewGuid()).ToList();

            string path = isInResources
                              ? "Decks/" + decks[i].ResourceName + "/" + Path.GetFileNameWithoutExtension(cards[0].Image)
                              : string.Empty;

            var groupControl = new GroupControl();
            var frame = new ImageViewWithFrame();

            yield return StartCoroutine(ImageViewWithFrame(cards[0], frame, BigSize, path, rightMargin: 30));
            groupControl.Items.Add(frame);

            path = isInResources
                       ? "Decks/" + decks[i].ResourceName + "/" + Path.GetFileNameWithoutExtension(cards[1].Image)
                       : string.Empty;
            float leftMargin = scaledBigFrameOffsetX - Scale(9) - scaledSmallFrameOffsetX;
            float topMargin = firstImageOffsetY - scaledSmallFrameOffsetY;

            frame = new ImageViewWithFrame();
            yield return StartCoroutine(ImageViewWithFrame(cards[1], frame, SmallSize, path, leftMargin, topMargin));
            groupControl.Items.Add(frame);

            path = isInResources
                       ? "Decks/" + decks[i].ResourceName + "/" + Path.GetFileNameWithoutExtension(cards[2].Image)
                       : string.Empty;
            topMargin = secondImageOffsetY - scaledSmallFrameOffsetY;

            frame = new ImageViewWithFrame();
            yield return StartCoroutine(ImageViewWithFrame(cards[2], frame, SmallSize, path, leftMargin, topMargin));
            groupControl.Items.Add(frame);

            leftMargin = scaledBigFrameOffsetX + Scale(8);
            topMargin = BigSize - Scale(10);

            GUIStyle style = new GUIStyle
                                 {
                                     fontSize = (int)(24 * Initialize.Scale),
                                     font = DefaultFont,
                                     clipping = TextClipping.Clip,
                                 };

            int textWidth = 200;

            TextView textView = new TextView();
            textView.Content = new GUIContent(FontColorUtils.Shadow(decks[i].Title));
            textView.Style = style;
            textView.Rect = new Rect(leftMargin + 2, topMargin + 2, Scale(textWidth), 100);
            groupControl.Items.Add(textView);

            textView = new TextView();
            textView.Content = new GUIContent(FontColorUtils.DeckTitle(decks[i].Title));
            textView.Style = style;
            textView.Rect = new Rect(leftMargin, topMargin, Scale(textWidth), 100);
            groupControl.Items.Add(textView);

            ImageView imageView = new ImageView();
            imageView.LeftMargin = BigSize - Scale(25);
            imageView.TopMargin = (int)scaledSmallFrameOffsetY + Scale(15);
            imageView.ImageTexture = SelectedTexture;
            imageView.ImageRect = new Rect(0, 0, SelectedTexture.width, SelectedTexture.height);
            imageView.Scale = i == 0 ? 0.3f : 0;
            imageView.Tag = "selected";
            imageView.MeasureSize();
            groupControl.Items.Add(imageView);

            groupControl.Tag = decks[i];
            deckControls.Add(groupControl);

            if (i == 0)
            {
                UpdateDifficultyAvailability();
            }
        }

        p = Camera.main.WorldToScreenPoint(SpawnObject.transform.position);
        p.y = Screen.height - p.y;

        int fullItemWidth = BigSize + Spacing;
        float scaledBigFrameHeight = BigSize + (Scale(27) * BigScale);
        float width = (fullItemWidth * size) + p.x + (Screen.width - e.x - Spacing);

        scrollViewRect = new Rect(0, p.y - 20, Screen.width, scaledBigFrameHeight + Scale(25));
        scrollViewContentRect = new Rect(0, 0, width, scaledBigFrameHeight);

        NextState();
    }