/**
 * Pop the current state. Handle errors and mouse cursor appearing again.
 * States pop themselves when they are finished.
 */
void BattlescapeState::popState()
{
	if (_states.empty()) return;

	if (_states.front()->getResult().length() > 0)
	{
		showWarningMessage(_states.front()->getResult());
	}
	_states.pop_front();

	if (_states.empty() && _selectedAction == BA_AUTOSHOT)
	{
		_autoShot++;
		if (_autoShot <= 3)
		{
			// shoot another try
			statePushBack(new ProjectileFlyBState(this));
		}
		else
		{
			_autoShot = 1;
		}
	}

	// if all states are empty - give the mouse back to the player
	if (_states.empty())
	{
		_game->getCursor()->setVisible(true);
		if (_selectedAction == BA_NONE)
		{
			_map->setCursorType(CT_NORMAL);
		}
		else
		{
			_map->setCursorType(CT_AIM);
		}
	}
	else
	{
		// init the next state in queue
		_states.front()->init();
	}
	if (_battleGame->getSelectedUnit() == 0 || _battleGame->getSelectedUnit()->isOut())
	{
		_targeting = false;
		_selectedAction = BA_NONE;
		_map->setCursorType(CT_NORMAL);
		_game->getCursor()->setVisible(true);
		_battleGame->setSelectedUnit(0);
	}
	updateSoldierInfo(_battleGame->getSelectedUnit());
}
Exemple #2
0
Window::Window(QWidget *parent)
    : KMainWindow(parent)
{
    QWidget* widget = new QWidget;
    setCentralWidget(widget);
    resize(500, 400);

    m_actions
            << new QAction(KIcon("document-save"), i18n("Save"), this)
            << new QAction(i18n("Discard"), this)
            ;

    QVBoxLayout* mainLayout = new QVBoxLayout(widget);

    // KMessageWidget
    m_messageWidget = new KMessageWidget(this);
    m_messageWidget->hide();
    mainLayout->addWidget(m_messageWidget);

    // Message buttons
    {
        QGroupBox* groupBox = new QGroupBox();
        groupBox->setTitle(i18n("Show/hide message widget"));
        mainLayout->addWidget(groupBox);
        QVBoxLayout* layout = new QVBoxLayout(groupBox);

        createMessageButton(layout, i18n("Error"), SLOT(showErrorMessage()));
        createMessageButton(layout, i18n("Warning"), SLOT(showWarningMessage()));
        createMessageButton(layout, i18n("Information"), SLOT(showInformationMessage()));
        createMessageButton(layout, i18n("Positive"), SLOT(showPositiveMessage()));
    }

    // Text
    {
        QGroupBox* groupBox = new QGroupBox();
        groupBox->setTitle(i18n("Text"));
        mainLayout->addWidget(groupBox);
        QVBoxLayout* layout = new QVBoxLayout(groupBox);

        m_edit = new KTextEdit;
        m_edit->setClickMessage(i18n("Use default text"));
        layout->addWidget(m_edit);
    }

    // Options
    {
        QGroupBox* groupBox = new QGroupBox();
        groupBox->setTitle(i18n("Options"));
        mainLayout->addWidget(groupBox);
        QVBoxLayout* layout = new QVBoxLayout(groupBox);

        QCheckBox* wordwrapCheckBox = new QCheckBox(i18n("Word wrap"));
        layout->addWidget(wordwrapCheckBox);
        connect(wordwrapCheckBox, SIGNAL(toggled(bool)), m_messageWidget, SLOT(setWordWrap(bool)));

        QCheckBox* showActionsCheckBox = new QCheckBox(i18n("Show action buttons"));
        layout->addWidget(showActionsCheckBox);
        connect(showActionsCheckBox, SIGNAL(toggled(bool)), SLOT(showActions(bool)));

        QCheckBox* showCloseButtonCheckBox = new QCheckBox(i18n("Show close button"));
        showCloseButtonCheckBox->setChecked(true);
        layout->addWidget(showCloseButtonCheckBox);
        connect(showCloseButtonCheckBox, SIGNAL(toggled(bool)),m_messageWidget, SLOT(setCloseButtonVisible(bool)));

        m_animatedShowCheckBox = new QCheckBox(i18n("Animated"));
        m_animatedShowCheckBox->setChecked(true);
        layout->addWidget(m_animatedShowCheckBox);

        QLabel* iconLabel = new QLabel("Icon:");
        layout->addWidget(iconLabel);

        m_iconComboBox = new QComboBox;
        iconLabel->setBuddy(m_iconComboBox);
        QStringList names = QStringList() << QString() << "preferences-system-network" << "document-save" << "system-users";
        Q_FOREACH(const QString &name, names) {
            QIcon icon = QIcon::fromTheme(name);
            m_iconComboBox->addItem(icon, name.isEmpty() ? "none" : name);
        }
        connect(m_iconComboBox, SIGNAL(activated(int)), SLOT(setIconFromComboBox(int)));
        layout->addWidget(m_iconComboBox);
    }