예제 #1
0
        public void setPreviewBackground(string path)
        {
            var     background             = Controller.ResourceManager.getImage(path);
            Vector2 previousBackgroundSize = new Vector2(AssetsImageDimensions.BACKGROUND_MAX_WIDTH, AssetsImageDimensions.BACKGROUND_MAX_HEIGHT);
            bool    set = true;
            bool    maintainRelative = true;

            if (background)
            {
                var previousBackground = Controller.ResourceManager.getImage(getPreviewBackground());
                previousBackgroundSize = new Vector2(previousBackground.width, previousBackground.height);

                if ((previousBackground.width != background.width || previousBackground.height != background.height) &&
                    !Controller.Instance.ShowStrictConfirmDialog("Different Size", "The selected background dimensions " +
                                                                 "are not the same as the previous background, do you want the elements to maintain its relative position and scale?"))
                {
                    maintainRelative = false;
                }

                var foreground = Controller.ResourceManager.getImage(getPreviewForeground());
                if (foreground && (foreground.width != background.width || foreground.height != background.height))
                {
                    if (Controller.Instance.ShowStrictConfirmDialog("Incompatible background", "The selected background dimensions " +
                                                                    "are not the same as the foreground, if you select this background the foreground will be removed. Do you want to continue?"))
                    {
                        resourcesDataControlList[selectedResources].addAsset("foreground", "");
                    }
                    else
                    {
                        set = false;
                    }
                }
            }

            if (set)
            {
                var wasAtDefaultPosition = Controller.Instance.PlayerMode == Controller.FILE_ADVENTURE_3RDPERSON_PLAYER && isPlayerAtDefaultPosition();
                resourcesDataControlList[selectedResources].addAsset("background", path);

                if (maintainRelative && background)
                {
                    // References
                    foreach (var reference in referencesListDataControl.getRefferences())
                    {
                        var data = reference.getElementReference();
                        data.setPosition((int)(reference.getElementX() * background.width / previousBackgroundSize.x),
                                         (int)(reference.getElementY() * background.height / previousBackgroundSize.y));
                        data.Scale = reference.getElementScale() * background.height / previousBackgroundSize.y;
                    }

                    // Areas
                    var nbr = new Vector2(background.width, background.height);
                    exitsListDataControl.getExits().ForEach(e => adaptRectangle(e.getRectangle(), previousBackgroundSize, nbr));
                    activeAreasListDataControl.getActiveAreas().ForEach(e => adaptRectangle(e.getRectangle(), previousBackgroundSize, nbr));
                    barriersListDataControl.getBarriers().ForEach(e => adaptRectangle(e.getRectangle(), previousBackgroundSize, nbr));

                    // Player
                    if (Controller.Instance.PlayerMode == Controller.FILE_ADVENTURE_3RDPERSON_PLAYER && getPlayerLayer() != -2)
                    {
                        if (getTrajectory() != null && getTrajectory().hasTrajectory())
                        {
                            foreach (var node in getTrajectory().getNodes())
                            {
                                node.setNode((int)(node.getX() * background.width / previousBackgroundSize.x),
                                             (int)(node.getY() * background.height / previousBackgroundSize.y),
                                             node.getScale() * background.height / previousBackgroundSize.y);
                            }
                        }
                        else
                        {
                            setDefaultInitialPosition((int)(getDefaultInitialPositionX() * background.width / previousBackgroundSize.x),
                                                      (int)(getDefaultInitialPositionY() * background.height / previousBackgroundSize.y));
                            setPlayerScale(getPlayerScale() * background.height / previousBackgroundSize.y);
                        }
                    }
                }
                else if (wasAtDefaultPosition)
                {
                    setPlayerScale(getPlayerAppropiateScale());
                    var newDefaultPosition = getDefaultInitialPosition();
                    setDefaultInitialPosition((int)newDefaultPosition.x, (int)newDefaultPosition.y);
                }
            }
        }