Beispiel #1
0
        public override void DrawPreview(Rect rect)
        {
            // We first fix the ratio of the rect
            var viewport = rect.AdjustToRatio(800f / 600f);

            GUI.DrawTexture(viewport, backgroundPreview, ScaleMode.ScaleToFit);

            bool selected;

            if (Event.current.type == EventType.MouseDown)
            {
                SelectedArrow = -1;
            }

            // Draw the left arrow
            if (leftNormalArrow)
            {
                EditorGUI.BeginChangeCheck();
                var leftArrowPos = DoArrow(workingBook.getPreviousPagePosition(), leftNormalArrow, leftOverArrow, viewport, false, out selected, "Arrow left".GetHashCode());
                if (EditorGUI.EndChangeCheck())
                {
                    workingBook.setPreviousPagePosition(leftArrowPos);
                }
                if (selected)
                {
                    SelectedArrow = BookDataControl.ARROW_LEFT;
                }
            }

            if (rightNormalArrow)
            {
                EditorGUI.BeginChangeCheck();
                var isDefault     = workingBook.getArrowImagePath(BookDataControl.ARROW_RIGHT, BookDataControl.ARROW_NORMAL) == SpecialAssetPaths.ASSET_DEFAULT_ARROW_NORMAL_RIGHT;
                var rightArrowPos = DoArrow(workingBook.getNextPagePosition(), rightNormalArrow, rightOverArrow, viewport, isDefault, out selected, "Arrow right".GetHashCode());
                if (EditorGUI.EndChangeCheck())
                {
                    workingBook.setNextPagePosition(rightArrowPos);
                }
                if (selected)
                {
                    SelectedArrow = BookDataControl.ARROW_RIGHT;
                }
            }
        }
Beispiel #2
0
        public void Init(DialogReceiverInterface e, BookDataControl book)
        {
            bookRef = book;

            string backgroundPath = book.getPreviewImage();

            backgroundPreviewTex =
                (Texture2D)Resources.Load(backgroundPath.Substring(0, backgroundPath.LastIndexOf(".")), typeof(Texture2D));

            string leftNormalArrowPath = book.getArrowImagePath_WithDefault(BookDataControl.ARROW_LEFT,
                                                                            BookDataControl.ARROW_NORMAL);

            leftArrowTex =
                (Texture2D)
                Resources.Load(leftNormalArrowPath.Substring(0, leftNormalArrowPath.LastIndexOf(".")),
                               typeof(Texture2D));

            string rightNormalArrowPath = book.getArrowImagePath_WithDefault(BookDataControl.ARROW_RIGHT,
                                                                             BookDataControl.ARROW_NORMAL);

            rightArrowTex =
                (Texture2D)
                Resources.Load(rightNormalArrowPath.Substring(0, rightNormalArrowPath.LastIndexOf(".")),
                               typeof(Texture2D));

            imageBackgroundRect = new Rect(0f, 0f, backgroundPreviewTex.width, backgroundPreviewTex.height);

            defaultPreviousPageArrowPosition = new Vector2(MARGIN,
                                                           backgroundPreviewTex.height - leftArrowTex.height - MARGIN);
            defaultNextPageArrowPosition = new Vector2(backgroundPreviewTex.width - rightArrowTex.width - MARGIN,
                                                       backgroundPreviewTex.height - rightArrowTex.height - MARGIN);

            if (bookRef.getPreviousPagePosition() == Vector2.zero && bookRef.getNextPagePosition() == Vector2.zero)
            {
                SetDefaultArrowsPosition();
            }

            CalculateArrowsPosition();

            base.Init(e, backgroundPreviewTex.width, backgroundPreviewTex.height);
        }
Beispiel #3
0
        void OnGUI()
        {
            // Dragging events
            if (Event.current.type == EventType.mouseDrag)
            {
                if (leftArrowRect.Contains(Event.current.mousePosition) ||
                    rightArrowRect.Contains(Event.current.mousePosition))
                {
                    if (!dragging)
                    {
                        dragging = true;
                        startPos = currentPos;
                        if (leftArrowRect.Contains(Event.current.mousePosition))
                        {
                            arrowDragged = ArrowType.Left;
                        }
                        else
                        {
                            arrowDragged = ArrowType.Right;
                        }
                    }
                }
                currentPos = Event.current.mousePosition;
            }

            if (Event.current.type == EventType.mouseUp)
            {
                dragging     = false;
                arrowDragged = ArrowType.None;
            }

            if (dragging)
            {
                OnBeingDragged();
            }
            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

            GUI.DrawTexture(imageBackgroundRect, backgroundPreviewTex);

            GUI.DrawTexture(leftArrowRect, leftArrowTex);
            GUI.DrawTexture(rightArrowRect, rightArrowTex);

            GUILayout.EndScrollView();

            // Default arrow positions
            if (GUILayout.Button(TC.get("Behaviour.Normal")))
            {
                OnDefaultClicked();
            }



            GUILayout.BeginHorizontal();
            GUILayout.Box(TC.get("Book.Previous"), GUILayout.Width(0.5f * backgroundPreviewTex.width));
            GUILayout.Box(TC.get("Book.Next"), GUILayout.Width(0.5f * backgroundPreviewTex.width));
            GUILayout.EndHorizontal();



            GUILayout.BeginHorizontal();

            GUILayout.Box("X", GUILayout.Width(0.15f * backgroundPreviewTex.width));
            x_prev = EditorGUILayout.IntField((int)bookRef.getPreviousPagePosition().x,
                                              GUILayout.Width(0.35f * backgroundPreviewTex.width));

            GUILayout.Box("X", GUILayout.Width(0.15f * backgroundPreviewTex.width));
            x_next = EditorGUILayout.IntField((int)bookRef.getNextPagePosition().x,
                                              GUILayout.Width(0.35f * backgroundPreviewTex.width));

            GUILayout.EndHorizontal();



            GUILayout.BeginHorizontal();

            GUILayout.Box("Y", GUILayout.Width(0.15f * backgroundPreviewTex.width));
            y_prev = EditorGUILayout.IntField((int)bookRef.getPreviousPagePosition().y,
                                              GUILayout.Width(0.35f * backgroundPreviewTex.width));
            GUILayout.Box("Y", GUILayout.Width(0.15f * backgroundPreviewTex.width));
            y_next = EditorGUILayout.IntField((int)bookRef.getNextPagePosition().y,
                                              GUILayout.Width(0.35f * backgroundPreviewTex.width));

            GUILayout.EndHorizontal();

            bookRef.setPreviousPagePosition(new Vector2(x_prev, y_prev));
            bookRef.setNextPagePosition(new Vector2(x_next, y_next));
            CalculateArrowsPosition();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("End"))
            {
                reference.OnDialogOk("Applied");
                this.Close();
            }
            GUILayout.EndHorizontal();
        }