コード例 #1
0
/**
 * The craft info can change
 * after going into other screens.
 */
void CraftInfoState::init()
{
    // Set palette
    _game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(3)), Palette::backPos, 16);

    Craft *c = _base->getCrafts()->at(_craft);

    _edtCraft->setText(c->getName(_game->getLanguage()));

    SurfaceSet *texture = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK");
    texture->getFrame(c->getRules()->getSprite() + 33)->setX(0);
    texture->getFrame(c->getRules()->getSprite() + 33)->setY(0);
    texture->getFrame(c->getRules()->getSprite() + 33)->blit(_sprite);

    std::wstringstream ss;
    ss << tr("STR_DAMAGE_UC_").arg(Text::formatPercentage(c->getDamagePercentage()));
    if (c->getStatus() == "STR_REPAIRS")
    {
        int damageDays = (int)ceil((float)c->getDamage() / c->getRules()->getRepairRate() / 24.0f);
        ss << L"\n(" << tr("STR_DAY", damageDays) << ")";
    }
    _txtDamage->setText(ss.str());

    std::wstringstream ss2;
    ss2 << tr("STR_FUEL").arg(Text::formatPercentage(c->getFuelPercentage()));
    if (c->getStatus() == "STR_REFUELLING")
    {
        int fuelDays = (int) ceil((float)(c->getRules()->getMaxFuel() - c->getFuel()) / c->getRules()->getRefuelRate() / 48.0f);
        ss2 << L"\n(" << tr("STR_DAY", fuelDays) << ")";
    }
    _txtFuel->setText(ss2.str());

    if (c->getRules()->getSoldiers() > 0)
    {
        _crew->clear();
        _equip->clear();

        Surface *frame1 = texture->getFrame(38);
        frame1->setY(0);
        for (int i = 0, x = 0; i < c->getNumSoldiers(); ++i, x += 10)
        {
            frame1->setX(x);
            frame1->blit(_crew);
        }

        Surface *frame2 = texture->getFrame(40);
        frame2->setY(0);
        int x = 0;
        for (int i = 0; i < c->getNumVehicles(); ++i, x += 10)
        {
            frame2->setX(x);
            frame2->blit(_equip);
        }
        Surface *frame3 = texture->getFrame(39);
        for (int i = 0; i < c->getNumEquipment(); i += 4, x += 10)
        {
            frame3->setX(x);
            frame3->blit(_equip);
        }
    }
    else
    {
        _crew->setVisible(false);
        _equip->setVisible(false);
        _btnCrew->setVisible(false);
        _btnEquip->setVisible(false);
        _btnArmor->setVisible(false);
    }

    if (c->getRules()->getWeapons() > 0)
    {
        CraftWeapon *w1 = c->getWeapons()->at(0);

        if (w1 != 0)
        {
            Surface *frame = texture->getFrame(w1->getRules()->getSprite() + 48);
            frame->setX(0);
            frame->setY(0);
            frame->blit(_weapon1);

            _txtW1Name->setText(tr(w1->getRules()->getType()));
            _txtW1Ammo->setText(tr("STR_AMMO_").arg(w1->getAmmo()));
            _txtW1Max->setText(tr("STR_MAX").arg(w1->getRules()->getAmmoMax()));
        }
        else
        {
            _weapon1->clear();
            _txtW1Name->setText(L"");
            _txtW1Ammo->setText(L"");
            _txtW1Max->setText(L"");
        }
    }
    else
    {
        _weapon1->setVisible(false);
        _btnW1->setVisible(false);
        _txtW1Name->setVisible(false);
        _txtW1Ammo->setVisible(false);
        _txtW1Max->setVisible(false);
    }

    if (c->getRules()->getWeapons() > 1)
    {
        CraftWeapon *w2 = c->getWeapons()->at(1);

        if (w2 != 0)
        {
            Surface *frame = texture->getFrame(w2->getRules()->getSprite() + 48);
            frame->setX(0);
            frame->setY(0);
            frame->blit(_weapon2);

            _txtW2Name->setText(tr(w2->getRules()->getType()));
            _txtW2Ammo->setText(tr("STR_AMMO_").arg(w2->getAmmo()));
            _txtW2Max->setText(tr("STR_MAX").arg(w2->getRules()->getAmmoMax()));
        }
        else
        {
            _weapon2->clear();
            _txtW2Name->setText(L"");
            _txtW2Ammo->setText(L"");
            _txtW2Max->setText(L"");
        }
    }
    else
    {
        _weapon2->setVisible(false);
        _btnW2->setVisible(false);
        _txtW2Name->setVisible(false);
        _txtW2Ammo->setVisible(false);
        _txtW2Max->setVisible(false);
    }
}
コード例 #2
0
/**
 * The craft info can change
 * after going into other screens.
 */
void CraftInfoState::init()
{
	// Set palette
	_game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(3)), Palette::backPos, 16);

	Craft *c = _base->getCrafts()->at(_craft);

	_edtCraft->setText(c->getName(_game->getLanguage()));

	SurfaceSet *texture = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK");
	texture->getFrame(c->getRules()->getSprite() + 33)->setX(0);
	texture->getFrame(c->getRules()->getSprite() + 33)->setY(0);
	texture->getFrame(c->getRules()->getSprite() + 33)->blit(_sprite);

	std::wstringstream ss;
	ss << _game->getLanguage()->getString("STR_DAMAGE_UC_") << L'\x01' << c->getDamagePercentage() << "%";
	_txtDamage->setText(ss.str());

	std::wstringstream ss2;
	ss2 << _game->getLanguage()->getString("STR_FUEL") << L'\x01' << c->getFuelPercentage() << "%";
	_txtFuel->setText(ss2.str());

	if (c->getRules()->getSoldiers() > 0)
	{
		_crew->clear();
		_equip->clear();

		Surface *frame1 = texture->getFrame(38);
		frame1->setY(0);
		for (int i = 0, x = 0; i < c->getNumSoldiers(); ++i, x += 10)
		{
			frame1->setX(x);
			frame1->blit(_crew);
		}

		Surface *frame2 = texture->getFrame(39);
		frame2->setY(0);
		int x = 0;
		for (int i = 0; i < c->getNumEquipment(); i += 4, x += 10)
		{
			frame2->setX(x);
			frame2->blit(_equip);
		}
		Surface *frame3 = texture->getFrame(40);
		for (int i = 0; i < c->getNumVehicles(); ++i, x += 10)
		{
			frame3->setX(x);
			frame3->blit(_equip);
		}
	}
	else
	{
		_crew->setVisible(false);
		_equip->setVisible(false);
		_btnCrew->setVisible(false);
		_btnEquip->setVisible(false);
		_btnArmor->setVisible(false);
	}

	if (c->getRules()->getWeapons() > 0)
	{
		CraftWeapon *w1 = c->getWeapons()->at(0);

		if (w1 != 0)
		{
			Surface *frame = texture->getFrame(w1->getRules()->getSprite() + 48);
			frame->setX(0);
			frame->setY(0);
			frame->blit(_weapon1);

			_txtW1Name->setText(_game->getLanguage()->getString(w1->getRules()->getType()));

			std::wstringstream ss3;
			ss3 << _game->getLanguage()->getString("STR_AMMO_") << L'\x01' << w1->getAmmo();
			_txtW1Ammo->setText(ss3.str());

			std::wstringstream ss4;
			ss4 << _game->getLanguage()->getString("STR_MAX") << L'\x01' << w1->getRules()->getAmmoMax();
			_txtW1Max->setText(ss4.str());
		}
		else
		{
			_weapon1->clear();
			_txtW1Name->setText(L"");
			_txtW1Ammo->setText(L"");
			_txtW1Max->setText(L"");
		}
	}
	else
	{
		_weapon1->setVisible(false);
		_btnW1->setVisible(false);
		_txtW1Name->setVisible(false);
		_txtW1Ammo->setVisible(false);
		_txtW1Max->setVisible(false);
	}

	if (c->getRules()->getWeapons() > 1)
	{
		CraftWeapon *w2 = c->getWeapons()->at(1);

		if (w2 != 0)
		{
			Surface *frame = texture->getFrame(w2->getRules()->getSprite() + 48);
			frame->setX(0);
			frame->setY(0);
			frame->blit(_weapon2);

			_txtW2Name->setText(_game->getLanguage()->getString(w2->getRules()->getType()));

			std::wstringstream ss5;
			ss5 << _game->getLanguage()->getString("STR_AMMO_") << L'\x01' << w2->getAmmo();
			_txtW2Ammo->setText(ss5.str());

			std::wstringstream ss6;
			ss6 << _game->getLanguage()->getString("STR_MAX") << L'\x01' << w2->getRules()->getAmmoMax();
			_txtW2Max->setText(ss6.str());
		}
		else
		{
			_weapon2->clear();
			_txtW2Name->setText(L"");
			_txtW2Ammo->setText(L"");
			_txtW2Max->setText(L"");
		}
	}
	else
	{
		_weapon2->setVisible(false);
		_btnW2->setVisible(false);
		_txtW2Name->setVisible(false);
		_txtW2Ammo->setVisible(false);
		_txtW2Max->setVisible(false);
	}
}