Ejemplo n.º 1
0
    void AccionComprarPowerup(PowerUpDescriptor _powerUpDescriptor)
    {
        int cantidad = PowerupService.ownInventory.GetCantidadPowerUp(_powerUpDescriptor.idWs);

        ifcDialogBox.instance.ShowOneButtonDialog(
            ifcDialogBox.OneButtonType.COINS,
            string.Format(LocalizacionManager.instance.GetTexto(80), _powerUpDescriptor.nombre).ToUpper(),
            string.Format(_powerUpDescriptor._descripcion + "\n" + LocalizacionManager.instance.GetTexto(81), "<color=#ddf108> " + cantidad.ToString() + "</color>", "<color=#ddf108>" + _powerUpDescriptor.nombre + "</color>", cantidad == 1 ? LocalizacionManager.instance.GetTexto(138) : LocalizacionManager.instance.GetTexto(17)),
            _powerUpDescriptor.precioSoft.ToString(),
            // callback al comprar el powerup
            (_name) => {
            // para que el usuario no se pase comprando
            if (PowerupService.ownInventory.GetCantidadPowerUp(_powerUpDescriptor.idWs) >= PowerUpDescriptor.LIMITE_UNIDADES)
            {
                ifcDialogBox.instance.ShowOneButtonDialog(
                    ifcDialogBox.OneButtonType.POSITIVE,
                    LocalizacionManager.instance.GetTexto(84).ToUpper(),
                    string.Format(LocalizacionManager.instance.GetTexto(85), "<color=#ddf108> " + _powerUpDescriptor.nombre + "</color>"),
                    LocalizacionManager.instance.GetTexto(45).ToUpper());
                return;
            }

            // comprobar que el usuario tenga suficiente dinero para la compra
            if (Interfaz.MonedasSoft < _powerUpDescriptor.precioSoft)
            {
                ifcDialogBox.instance.ShowOneButtonDialog(
                    ifcDialogBox.OneButtonType.POSITIVE,
                    LocalizacionManager.instance.GetTexto(84).ToUpper(),
                    string.Format(LocalizacionManager.instance.GetTexto(86), "<color=#ddf108> " + LocalizacionManager.instance.GetTexto(46) + "</color>"),
                    LocalizacionManager.instance.GetTexto(45).ToUpper());
                return;
            }

            // pagar el powerup y actualizar el dinero mostrado
            Interfaz.MonedasSoft -= _powerUpDescriptor.precioSoft;
            cntBarraSuperior.instance.ActualizarDinero();

            // incrementar la cantidad de powerup y repintar la tienda
            PowerupService.ownInventory.IncrementarCantidadPowerUp(_powerUpDescriptor.idWs, 1);

            GeneralSounds_menu.instance.playOneShot(GeneralSounds_menu.instance.compraClip);

            if (ifcVestuario.instance != null)
            {
                ifcVestuario.instance.RefreshInfo();
            }

            // persistir la cantidad de powerups
            PersistenciaManager.instance.SavePowerUps();

            // volver a mostrar este dialogo
            AccionComprarPowerup(_powerUpDescriptor);
        },
            true,
            null, true);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Inicializa los valores de este control para mostrar un power up
    /// </summary>
    /// <param name="_powerUpDescriptor"></param>
    public void ShowAsPowerUp(PowerUpDescriptor _powerUpDescriptor)
    {
        ObtenerReferencias();

        if (_powerUpDescriptor == null)
        {
            // ocultar este control
            SetVisible(false);

            // mostrar en el boton la textura por defecto
            m_btnCompra.GetComponent <GUITexture>().texture = AvataresManager.instance.m_texturaCompraPowerUp;
            m_btnCompra.m_current = AvataresManager.instance.m_texturaCompraPowerUp;
        }
        else
        {
            // mostrar este control
            SetVisible(true);

            // actualizar la cantidad de items
            if (PowerupService.ownInventory == null)
            {
                m_txtCantidad.text = "0";
            }
            else
            {
                m_txtCantidad.text = PowerupService.ownInventory.GetCantidadPowerUp(_powerUpDescriptor.idWs).ToString();
            }
            m_txtCantidadSombra.text = m_txtCantidad.text;

            //m_icono.texture = AvataresManager.instance.GetTexturaPowerUp((int) PowerupInventory.IdWsToPowerup(_powerUpDescriptor.idWs));
            //m_icono.gameObject.SetActive(true);

            // actualizar el resto de textos
            m_txtPrecio.text       = "¤ " + _powerUpDescriptor.precioSoft.ToString();
            m_txtPrecioSombra.text = m_txtPrecio.text;
            m_txtBoost.gameObject.SetActive(false);

            // boton compra
            Texture textura = AvataresManager.instance.GetTexturaPowerUp((int)PowerupInventory.IdWsToPowerup(_powerUpDescriptor.idWs));
            m_btnCompra.GetComponent <GUITexture>().texture = textura;
            m_btnCompra.m_current = textura;

            m_btnCompra.action = (_name) => {
                Interfaz.ClickFX();
                AccionComprarPowerup(_powerUpDescriptor);
            };
        }
    }