Exemplo n.º 1
0
        void OnGUIFadeWhiteCurtain(object sender, InstantMessageArgs args)
        {
            bool up = (bool)args.arg;

            if (up)
            {
                switch (exitMode)
                {
                case ExitMode.Gallery:
                    int galleryLevel = GlobalManager.MStorage.GalleryLevel;
                    LevelDataManager.Descriptor descriptor = GlobalManager.MLevel.GetDescriptor(galleryLevel);
                    int nextGalleryLevel = descriptor.state.NextCompleteId;
                    if (nextGalleryLevel < 0)
                    {
                        nextGalleryLevel = 0;
                    }
                    GlobalManager.MStorage.GalleryLevel = nextGalleryLevel;
                    //SceneManager.LoadScene(SceneManager.GetActiveScene().name);
                    GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.PuzzleShowWinimage, this, string.Empty);
                    GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.GUIFadeWhiteCurtain, this, false);
                    break;

                case ExitMode.World:
                    GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.GalleryClosed, this);
                    SceneManager.LoadScene(worldScene);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        void Awake()
        {
            descriptor = GlobalManager.MLevel.GetDescriptor(GlobalManager.MStorage.SelectedLevel); // load player state for current level
            fieldSize  = new Vector2(descriptor.init.width * PuzzleBuilder.TileSize, descriptor.init.height * PuzzleBuilder.TileSize);

            ControlledCamera.transform.position = new Vector3(0, 0, CameraDistance().max);
        }
Exemplo n.º 3
0
 // message handling
 void OnWorldShowLevelDescription(object sender, InstantMessageArgs args)
 {
     LevelDataManager.Descriptor descriptor = (LevelDataManager.Descriptor)args.arg;
     if (descriptor != null)
     {
         InitializeDialog(descriptor);
     }
 }
        public void Initialize()
        {
            descriptor = GlobalManager.MLevel.GetDescriptor(GlobalManager.MStorage.GalleryLevel);
            //int width = descriptor.init.width;
            //int height = descriptor.init.height;
            float finalRatioXY = descriptor.init.finalXYScale;
            float screenAspect = Camera.main.aspect;

            // load STRESS and SMOOTH textures
            string    stressImage = StressImageCreator.StressedFinalImageFile(descriptor.init.id);
            Texture2D stressTex   = new Texture2D(2, 2, TextureFormat.RGB24, false);

            stressTex.LoadImage(System.IO.File.ReadAllBytes(stressImage));
            imageParams[0].winImage.texture = stressTex;
            Texture2D smoothTex = Resources.Load <Texture2D>(LevelDataManager.SmoothImageResource(descriptor.init.id));

            imageParams[1].winImage.texture = smoothTex;

            // set up scaling and UV rectangles
            CanvasScaler canvasScaler = GetComponent <CanvasScaler>();
            // the size of the canvas excluding margins
            Rect sourceCanvasRect = new Rect(0, 0, canvasScaler.referenceResolution.x * (1 - marginRatio), canvasScaler.referenceResolution.y * (1 - marginRatio));

            sourceCanvasSize = new Vector2(sourceCanvasRect.width, sourceCanvasRect.height);
            // SourceCanvas matches screen by width, so the final height scaling should be adjusted by:
            float heightAdjustFactor = sourceCanvasRect.width / sourceCanvasRect.height / screenAspect;

            for (int i = 0; i < imageParams.Length; i++)
            {
                imageParams[i].imageTransform.localPosition = imageParams[i].originalPosition;
                Vector2 canvasToImageRatio = new Vector2(
                    sourceCanvasRect.width / imageParams[i].originalRect.width,
                    sourceCanvasRect.height * heightAdjustFactor / imageParams[i].originalRect.height
                    );
                imageParams[i].sourceScale = new Vector2(
                    finalRatioXY > screenAspect ? canvasToImageRatio.y * finalRatioXY : canvasToImageRatio.x,
                    finalRatioXY > screenAspect ? canvasToImageRatio.y : canvasToImageRatio.x / finalRatioXY
                    );
                imageParams[i].effectiveSize             = Vector2.Scale(new Vector2(imageParams[i].originalRect.width, imageParams[i].originalRect.height), imageParams[i].sourceScale);
                imageParams[i].imageTransform.localScale = imageParams[i].sourceScale;
                currentScale = new FloatRange
                {
                    min = scaleRange.min,
                    max = scaleRange.min
                };
                // UV-coordinates of the image
                imageParams[i].winImage.uvRect = new Rect(0, 0, 1, 1);
                // positions
                //imageParams[i].originalPosition = imageParams[i].imageTransform.localPosition;
                imageParams[i].movePosition = new Vector2[2]
                {
                    imageParams[i].originalPosition,
                    imageParams[i].originalPosition
                };
            }
            effectFinished = false;
            GenerateNewStep(true);
        }
Exemplo n.º 5
0
        protected override void AwakeInit()
        {
            descriptor = GlobalManager.MLevel.GetDescriptor(GlobalManager.MStorage.SelectedLevel);
            float puzzleRatioXY = (float)descriptor.init.width / (float)descriptor.init.height;
            float screenAspect  = Camera.main.aspect;

            // prepare STRESS texture
            string    stressImage = StressImageCreator.StressedFinalImageFile(descriptor.init.id);
            Texture2D tex         = new Texture2D(2, 2, TextureFormat.RGB24, false);

            tex.LoadImage(System.IO.File.ReadAllBytes(stressImage));
            Vector2 texFactor = new Vector2
            {
                x = descriptor.init.finalXYScale > puzzleRatioXY ? puzzleRatioXY / descriptor.init.finalXYScale : 1f,
                y = puzzleRatioXY > descriptor.init.finalXYScale ? descriptor.init.finalXYScale / puzzleRatioXY : 1f
            };

            sourceImage.texture = tex;
            CanvasScaler canvasScaler = GetComponent <CanvasScaler>();
            // the size of the canvas excluding margins
            Rect sourceCanvasRect = new Rect(0, 0, canvasScaler.referenceResolution.x * (1 - marginRatio), canvasScaler.referenceResolution.y * (1 - marginRatio));
            // SourceCanvas matches screen by width, so the final scaling should be multiplied by:
            float         heightAdjustFactor = sourceCanvasRect.width / sourceCanvasRect.height / screenAspect;
            RectTransform sourceTransform    = sourceImage.GetComponent <RectTransform>();
            // the original size of the source image (square)
            Rect    sourceRect         = sourceTransform.rect;
            Vector2 canvasToImageRatio = new Vector2(
                sourceCanvasRect.width / sourceRect.width,
                sourceCanvasRect.height * heightAdjustFactor / sourceRect.height
                );
            Vector3 sourceRectScale = new Vector3(
                puzzleRatioXY > screenAspect ? canvasToImageRatio.x : canvasToImageRatio.y * puzzleRatioXY,
                puzzleRatioXY > screenAspect ? canvasToImageRatio.x / puzzleRatioXY : canvasToImageRatio.y,
                1
                );

            //Debug.Log("Image sizes: canvas: " + sourceCanvasRect.ToString() + ", image: " + sourceRect.ToString() + ", image/canvas: " + canvasToImageRatio.ToString() + ", scale: " + sourceRectScale.ToString());
            sourceTransform.localScale = sourceRectScale;
            // UV-coordinates of the image
            Rect uvRect = new Rect(
                (1f - texFactor.x) / 2,
                (1f - texFactor.y) / 2,
                texFactor.x,
                texFactor.y
                );

            sourceImage.uvRect = uvRect;

            // button text
            sourceText.text = GlobalManager.MLanguage.Entry(GetSourceTextId());

            // message handling
            registrator.Add(new MessageRegistrationTuple {
                type = InstantMessageType.PuzzleViewSourceImage, handler = OnPuzzleViewSourceImage
            });
            sourceButton.interactable = true;
        }
 public void Init(LevelDataManager.Descriptor descriptor, SelectorPrefab prefab, bool noStatusCheck = false)
 {
     levelDescriptor = descriptor;
     meshRenderer    = GetComponent <MeshRenderer>();
     lightBeacon.SetActive(false);
     if (noStatusCheck || levelDescriptor.state.Revealed)
     {
         // set up height above the world sphere
         string     iconPath    = LevelDataManager.GraphicsResource(levelDescriptor.init.id);
         bool       glow        = false;
         float      iconOpacity = normalIconOpacity;
         Material[] materials   = meshRenderer.materials;
         if (noStatusCheck)
         {
             iconPath    += "/icon";
             materials[0] = prefab.opaqueMaterial;
         }
         else
         {
             if (levelDescriptor.state.Playable)
             {
                 Debug.Log("WorldSelectorController.Init: id=" + levelDescriptor.init.id.ToString() + ", playable=" + levelDescriptor.state.Playable.ToString());
                 iconPath += "/icon";
                 if (levelDescriptor.init.id == GlobalManager.MStorage.SelectedLevel)
                 {
                     materials[0] = prefab.glowMaterial;
                     lightBeacon.SetActive(true);
                     glow = true;
                 }
                 else
                 {
                     materials[0] = prefab.opaqueMaterial;
                 }
             }
             else
             {
                 iconPath    += "/grayicon";
                 iconOpacity  = disabledIconOpacity;
                 materials[0] = prefab.transparentMaterial;
             }
         }
         meshRenderer.materials = materials;
         iconRenderer.sprite    = Resources.Load <Sprite>(iconPath);
         Color c = iconRenderer.color;
         c.a = iconOpacity;
         iconRenderer.color = c;
         if (glow)
         {
             StartFlash();
         }
     }
     else
     {
         gameObject.SetActive(false);
     }
 }
 // Use this for initialization
 void Start()
 {
     // notify that the Puzzle scene has just started
     GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.PuzzleStarted, this);
     // update RotoChips and RotoCoins indicators
     LevelDataManager.Descriptor descriptor = GlobalManager.MLevel.GetDescriptor(GlobalManager.MStorage.SelectedLevel);
     GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.GUIRotoChipsChanged, this, (decimal)descriptor.state.EarnedPoints);
     GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.GUIRotoCoinsChanged, this, GlobalManager.MStorage.CurrentCoins);
     // hide WinCanvas
     GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.PuzzleShowWinimage, this, null);
 }
        bool startVictoryScreen;                // a flag to start the victory screen

        protected override void AwakeInit()
        {
            descriptor         = GlobalManager.MLevel.GetDescriptor(GlobalManager.MStorage.SelectedLevel);
            tileNeighbours     = new TileStatus[descriptor.init.width, descriptor.init.height];
            buttonAngles       = new int[descriptor.init.width - 1, descriptor.init.height - 1];
            builder            = GetComponent <PuzzleBuilder>();
            puzzleBusy         = false;
            buttonRotated      = false;
            puzzleComplete     = false;
            autostepUsed       = false;
            startVictoryScreen = true;
            registrator.Add(
                new MessageRegistrationTuple {
                type = InstantMessageType.PuzzleButtonPressed, handler = OnPuzzleButtonPressed
            },
                new MessageRegistrationTuple {
                type = InstantMessageType.PuzzleButtonRotated, handler = OnPuzzleButtonRotated
            },
                new MessageRegistrationTuple {
                type = InstantMessageType.PuzzleTileFlashed, handler = OnPuzzleTileFlashed
            },
                new MessageRegistrationTuple {
                type = InstantMessageType.PuzzleAutostepUsed, handler = OnPuzzleAutostepUsed
            },
                new MessageRegistrationTuple {
                type = InstantMessageType.PuzzleShuffle, handler = OnPuzzleShuffle
            },
                new MessageRegistrationTuple {
                type = InstantMessageType.PuzzleReset, handler = OnPuzzleReset
            },
                new MessageRegistrationTuple {
                type = InstantMessageType.PuzzlePrepareAutostep, handler = OnPuzzlePrepareAutostep
            },
                new MessageRegistrationTuple {
                type = InstantMessageType.PuzzleAutostep, handler = OnPuzzleAutostep
            },
                new MessageRegistrationTuple {
                type = InstantMessageType.PuzzleAutocomplete, handler = OnPuzzleAutocomplete
            },
                new MessageRegistrationTuple {
                type = InstantMessageType.PuzzleBusy, handler = OnPuzzleBusy
            },
                new MessageRegistrationTuple {
                type = InstantMessageType.RedirectFirstTileButtons, handler = OnRedirectFirstTileButtons
            },
                new MessageRegistrationTuple {
                type = InstantMessageType.RedirectSecondTileButtons, handler = OnRedirectSecondTileButtons
            }
                );
        }
Exemplo n.º 9
0
        void OnWorldSelectorPressed(object sender, InstantMessageArgs args)
        {
            GameObject targetObject = ((Component)sender).gameObject;

            if (cameraController.Zoom != WorldCameraController.ZoomStatus.ZoomAtMin)
            {
                RotateWorldToZero(targetObject);
            }
            else
            {
                LevelDataManager.Descriptor descriptor = (LevelDataManager.Descriptor)args.arg;
                if (descriptor.state.Playable)
                {
                    if (descriptor.state.Complete)
                    {
                        // show a description of the complete level
                        GlobalManager.MAudio.PlaySFX(levelDescriptionSFX);
                        GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.WorldRotationEnable, this, false);
                        GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.WorldShowLevelDescription, this, descriptor);
                    }
                    else
                    {
                        // start level
                        GlobalManager.MAudio.PlaySFX(startLevelSFX);
                        GlobalManager.MStorage.SelectedLevel = descriptor.init.id;
                        //GlobalManager.MStorage.GalleryLevel = descriptor.init.id;
                        StartCoroutine(YieldToScene(targetObject, puzzleScene));
                    }
                }
                else
                {
                    // show hint message
                    GlobalManager.MAudio.PlaySFX(noLevelSFX);
                    GlobalManager.MInstantMessage.DeliverMessage(
                        InstantMessageType.GUIShowHint,
                        this,
                        new HintRequest
                    {
                        type   = HintType.LevelNotYetPlayable,
                        target = null
                    }
                        );
                }
            }
        }
Exemplo n.º 10
0
        void InitializeDialog(LevelDataManager.Descriptor descriptor)
        {
            // calculate dialog size
            int   adjustmentIndex    = -1;
            float currentScreenRatio = (float)Screen.width / (float)Screen.height;

            for (int i = 0; i < dialogAdjustments.Length; i++)
            {
                if (currentScreenRatio >= dialogAdjustments[i].screenAspect)
                {
                    adjustmentIndex = i;
                    break;
                }
            }
            if (adjustmentIndex < 0)
            {
                return;
            }
            // get level data
            string levelStr = descriptor.init.id.ToString("D3");

            titleText.GetComponent <Text>().text = GlobalManager.MLanguage.Entry(titlePrefix + levelStr);
            GameObject activeImage, inactiveImage;
            GameObject activeText, inactiveText;

            // adjust dialog height
            descriptionDialog.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dialogAdjustments[adjustmentIndex].dialogHeight);

            bool horizontal = descriptor.init.finalXYScale >= 1f;
            // set up image dimensions and the dialog layout depending on "horizontal" or "vertical" image orientation

            float finalImageWidth;
            float finalImageHeight;

            if (horizontal)
            {
                // the maximum height of the image is fixed
                finalImageHeight = dialogAdjustments[adjustmentIndex].maxHorizontalImageSize.y;
                finalImageWidth  = finalImageHeight * descriptor.init.finalXYScale;
                if (finalImageWidth > dialogAdjustments[adjustmentIndex].maxHorizontalImageSize.x)
                {
                    finalImageWidth  = dialogAdjustments[adjustmentIndex].maxHorizontalImageSize.x;
                    finalImageHeight = finalImageWidth / descriptor.init.finalXYScale;
                }
                activeImage   = hDescriptionImage;
                inactiveImage = vDescriptionImage;
                activeText    = hDescriptionText;
                inactiveText  = vDescriptionText;
                // adjust horizontal description text Y-shift
                RectTransform activeTextRectTransform = activeText.GetComponent <RectTransform>();
                Vector2       activeTextPosition      = activeTextRectTransform.localPosition;
                activeTextPosition.y = dialogAdjustments[adjustmentIndex].descriptionYShift;
                activeTextRectTransform.localPosition = activeTextPosition;
            }
            else
            {
                // the maximum width of the image is fixed
                finalImageWidth  = dialogAdjustments[adjustmentIndex].maxVerticalImageSize.x;
                finalImageHeight = finalImageWidth / descriptor.init.finalXYScale;
                if (finalImageHeight > dialogAdjustments[adjustmentIndex].maxVerticalImageSize.y)
                {
                    finalImageHeight = dialogAdjustments[adjustmentIndex].maxVerticalImageSize.y;
                    finalImageWidth  = finalImageHeight * descriptor.init.finalXYScale;
                }
                activeImage   = vDescriptionImage;
                inactiveImage = hDescriptionImage;
                activeText    = vDescriptionText;
                inactiveText  = hDescriptionText;
            }

            activeTextScript          = activeText.GetComponent <Text>();
            activeTextScript.fontSize = dialogAdjustments[adjustmentIndex].descriptionFontSize;
            // activate active objects
            activeImage.SetActive(true);
            activeText.SetActive(true);
            // load "smooth" image
            activeImage.GetComponent <RawImage>().texture = Resources.Load <Texture>(LevelDataManager.SmoothImageResource(descriptor.init.id));
            // and set up its size
            activeImage.GetComponent <RectTransform>().localScale = new Vector3(finalImageWidth, finalImageHeight, 1.0f);
            // set text objects
            activeText.GetComponent <Text>().text = GlobalManager.MLanguage.Entry(descriptionPrefix + levelStr);
            // deactivate inactive objects
            inactiveImage.SetActive(false);
            inactiveText.SetActive(false);
            okButton.GetComponent <Button>().interactable = true;
            Visualize(flashRange.min);
            // now activate the dialog
            gameObject.SetActive(true);
            StartFlash(true);
        }
Exemplo n.º 11
0
        private void Awake()
        {
            descriptor = GlobalManager.MLevel.GetDescriptor(GlobalManager.MStorage.SelectedLevel);
            int   width         = descriptor.init.width;
            int   height        = descriptor.init.height;
            float puzzleRatioXY = (float)width / (float)height;

            // prepare one STRESS texture for all tiles
            string    stressImage = StressImageCreator.StressedFinalImageFile(descriptor.init.id);
            Texture2D tex         = new Texture2D(2, 2, TextureFormat.RGB24, false);

            tex.LoadImage(System.IO.File.ReadAllBytes(stressImage));
            // a special factor used in later calculations
            Vector2 texFactor = new Vector2
            {
                x = descriptor.init.finalXYScale > puzzleRatioXY ? puzzleRatioXY / descriptor.init.finalXYScale : 1f,
                y = puzzleRatioXY > descriptor.init.finalXYScale ? descriptor.init.finalXYScale / puzzleRatioXY : 1f
            };
            Vector2 texScale = new Vector2
            {
                x = texFactor.x / (float)width,
                y = texFactor.y / (float)height
            };
            Vector2 texOffsetStart = new Vector2
            {
                x = (1f - texFactor.x) / 2,
                y = (1f - texFactor.y) / 2 + texFactor.y * (float)(height - 1) / (float)height
            };
            Vector2 texOffsetStep = new Vector2
            {
                x = texFactor.x / (float)width,
                y = -texFactor.y / (float)height
            };

            // create buttons
            buttons = new ButtonCluster[width - 1, height - 1];
            float   buttonStartX   = -(width - 2) * TileSize / 2;
            Vector3 buttonPosition = new Vector3(buttonStartX, (height - 2) * TileSize / 2, neutralButtonZ);

            for (int y = 0; y < height - 1; y++)
            {
                for (int x = 0; x < width - 1; x++)
                {
                    GameObject button = (GameObject)Instantiate(buttonPrefab);
                    initialButtonRotation     = button.transform.localRotation;
                    button.transform.position = buttonPosition;
                    button.GetComponent <PuzzleButtonController>().Init(new Vector2Int(x, y), neutralButtonZ, pressedButtonZ, releasedButtonZ);
                    buttons[x, y] = new ButtonCluster
                    {
                        button = button,
                        tiles  = new GameObject[4]
                    };
                    buttonPosition.x += TileSize;
                }
                buttonPosition.x  = buttonStartX;
                buttonPosition.y -= TileSize;
            }

            // create tiles
            tiles = new GameObject[width, height];
            Vector2 texOffset = texOffsetStart;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    GameObject tile = (GameObject)Instantiate(tilePrefab);
                    initialTileRotation = tile.transform.localRotation;
                    // downscale the tile a bit
                    Vector3 tileScale = tile.transform.localScale;
                    tileScale *= 1 - tileGap / 2;
                    tile.transform.localScale = tileScale;
                    // set up tile's texture and its parameters
                    MeshRenderer meshRenderer = tile.GetComponent <MeshRenderer>();
                    Material[]   materials    = meshRenderer.materials;
                    materials[0].SetTexture("_MainTex", tex);
                    materials[0].SetTextureScale("_MainTex", texScale);
                    materials[0].SetTextureOffset("_MainTex", texOffset);
                    meshRenderer.materials = materials;
                    tile.GetComponent <TileFlasher>().Init(new Vector2Int(x, y));
                    tiles[x, y]  = tile;
                    texOffset.x += texOffsetStep.x;
                }
                texOffset.x  = texOffsetStart.x;
                texOffset.y += texOffsetStep.y;
            }
        }
Exemplo n.º 12
0
 private void Start()
 {
     LevelDataManager.Descriptor descriptor = GlobalManager.MLevel.GetDescriptor(0);
     gameObject.SetActive(descriptor.state.Complete);
 }