Exemplo n.º 1
0
        private bool initScreen(int i)
        {
            MaterialPtr      overlayMaterial = null;
            TextureUnitState unit            = null;

            animation           = null;
            currentMaterialName = null;
            if (isScreenAnAd[i - 1]) // poczatkowo i = 1
            {
                // pobierz i ustaw na bie¿ac¹
                AdManager.AdStatus status = AdManager.Singleton.GetAd(C_AD_ZONE, 1.0f, out currentAd);

                if (status == AdManager.AdStatus.OK)
                {
                    // pobieranie OK.
                    currentMaterialName = C_AD_MATERIAL;
                    string path = AdManager.Singleton.LoadAdTexture(currentAd);
                    if (path == null)
                    {
                        return(false);
                    }
                    showAdText(viewport);


                    overlayMaterial = MaterialManager.Singleton.GetByName(currentMaterialName);
                    overlayMaterial.Load();
                    unit = overlayMaterial.GetBestTechnique().GetPass(0).GetTextureUnitState(0);

                    unit.SetTextureName(path);
                    AdManager.Singleton.RegisterImpression(currentAd);

                    //   int count;
                    //   count = adAction.Get_Ad_Impression_Counter(currentAd.id);
                    //    Console.WriteLine("Pobrañ: " + count);
                }
                else
                {
                    hideAdText();
                    return(false);
                }
            }
            else
            {
                currentMaterialName = C_TEXTURE_NAME + currentScreen;
                overlayMaterial     = MaterialManager.Singleton.GetByName(currentMaterialName);
                overlayMaterial.Load();
                unit = overlayMaterial.GetBestTechnique().GetPass(0).GetTextureUnitState(0);
                hideAdText();
            }



            textureDimensions = unit.GetTextureDimensions();
            PointD scale = new PointD(1, 1);
            // skaluj overlay tak aby tekstury nie zmienia³y swoich proporcji
            float prop = 1.0f;

            if (isScreenAnAd[currentScreen - 1])
            {
                // reklamy maja zachowac oryginalna rozdzielczosc
                scale = AdSizeUtils.ScaleAdToDisplay(textureDimensions, new PointD(Viewport.ActualWidth, Viewport.ActualHeight), true);
                scale = 0.65f * scale;
            }
            else
            {
                prop = 1.0f / ((1.0f * textureDimensions.first / textureDimensions.second) / (1.0f * Viewport.ActualWidth / Viewport.ActualHeight));
                // wychodzimy poza ekran
                if (scale.Y * prop > 1.0f)
                {
                    float scalingFactor = 1.0f / (scale.Y * prop);
                    scale.X *= scalingFactor; scale.Y *= scalingFactor;
                }

                if (scale.X * prop > 1.0f)
                {
                    float scalingFactor = 1.0f / (scale.X * prop);
                    scale.X *= scalingFactor; scale.Y *= scalingFactor;
                }
            }
            overlay.SetScale(scale.X, scale.Y * prop);



            animation =
                new EffectTextureAnimation(null, unit, screenTimes[i - 1], "QuitAnimation",
                                           VisibilityNodeAnimation.VisibilityType.VISIBLE,
                                           VisibilityNodeAnimation.VisibilityType.VISIBLE);

            animation.Enabled = true;
            animation.Looped  = true;
            OverlayContainer container = overlay.GetChild("Wof/QuitScreen");

            container.MaterialName = currentMaterialName;

            EffectsManager.Singleton.AddCustomEffect(animation);
            lastChange = DateTime.Now;
            return(true);
        }