Skip to content

Commit

Permalink
Added confirmation at mission end
Browse files Browse the repository at this point in the history
- if auto-end option is turned on
- and there is at least one soldier with fatal wounds
  • Loading branch information
MeridianOXC committed Jan 23, 2016
1 parent c00a39e commit 2f6df1d
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 25 deletions.
37 changes: 33 additions & 4 deletions src/Battlescape/BattlescapeGame.cpp
Expand Up @@ -59,6 +59,7 @@
#include "InfoboxOKState.h"
#include "UnitFallBState.h"
#include "../Engine/Logger.h"
#include "ConfirmEndMissionState.h"

namespace OpenXcom
{
Expand Down Expand Up @@ -1583,13 +1584,41 @@ void BattlescapeGame::moveUpDown(BattleUnit *unit, int dir)
/**
* Requests the end of the turn (waits for explosions etc to really end the turn).
*/
void BattlescapeGame::requestEndTurn()
void BattlescapeGame::requestEndTurn(bool askForConfirmation)
{
cancelCurrentAction();
if (!_endTurnRequested)

if (askForConfirmation)
{
_endTurnRequested = true;
statePushBack(0);
// check for fatal wounds
int soldiersWithFatalWounds = 0;
for (std::vector<BattleUnit*>::iterator it = _save->getUnits()->begin(); it != _save->getUnits()->end(); ++it)
{
if ((*it)->getOriginalFaction() == FACTION_PLAYER && (*it)->getStatus() != STATUS_DEAD && (*it)->getFatalWounds() > 0)
soldiersWithFatalWounds++;
}

if (soldiersWithFatalWounds > 0)
{
// confirm end of turn/mission
_parentState->getGame()->pushState(new ConfirmEndMissionState(_save, soldiersWithFatalWounds, this));
}
else
{
if (!_endTurnRequested)
{
_endTurnRequested = true;
statePushBack(0);
}
}
}
else
{
if (!_endTurnRequested)
{
_endTurnRequested = true;
statePushBack(0);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Battlescape/BattlescapeGame.h
Expand Up @@ -169,7 +169,7 @@ class BattlescapeGame
/// Moves a unit up or down.
void moveUpDown(BattleUnit *unit, int dir);
/// Requests the end of the turn (wait for explosions etc to really end the turn).
void requestEndTurn();
void requestEndTurn(bool askForConfirmation);
/// Sets the TU reserved type.
void setTUReserved(BattleActionType tur);
/// Sets up the cursor taking into account the action.
Expand Down
2 changes: 1 addition & 1 deletion src/Battlescape/BattlescapeState.cpp
Expand Up @@ -1078,7 +1078,7 @@ void BattlescapeState::btnEndTurnClick(Action *)
if (allowButtons())
{
_txtTooltip->setText(L"");
_battleGame->requestEndTurn();
_battleGame->requestEndTurn(false);
}
}
/**
Expand Down
123 changes: 123 additions & 0 deletions src/Battlescape/ConfirmEndMissionState.cpp
@@ -0,0 +1,123 @@
/*
* Copyright 2010-2015 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ConfirmEndMissionState.h"
#include <vector>
#include "../Engine/Game.h"
#include "../Mod/Mod.h"
#include "../Engine/LocalizedText.h"
#include "../Interface/Window.h"
#include "../Interface/Text.h"
#include "../Interface/TextButton.h"
#include "../Engine/Action.h"
#include "../Savegame/SavedBattleGame.h"
#include "BattlescapeState.h"
#include "../Engine/Options.h"
#include "../Mod/AlienDeployment.h"
#include "../Mod/Mod.h"
#include "../Mod/MapScript.h"
#include "../Savegame/Tile.h"

namespace OpenXcom
{

/**
* Initializes all the elements in the ConfirmEndMission window.
* @param battleGame Pointer to the saved game.
*/
ConfirmEndMissionState::ConfirmEndMissionState(SavedBattleGame *battleGame, int wounded, BattlescapeGame *parent) : _battleGame(battleGame), _wounded(wounded), _parent(parent)
{
// Create objects
_screen = false;
_window = new Window(this, 320, 144, 0, 0);
_txtTitle = new Text(304, 17, 16, 26);
_txtWounded = new Text(304, 17, 16, 54);
_txtConfirm = new Text(320, 17, 0, 80);
_btnOk = new TextButton(120, 16, 16, 110);
_btnCancel = new TextButton(120, 16, 184, 110);

// Set palette
_battleGame->setPaletteByDepth(this);

add(_window, "messageWindowBorder", "battlescape");
add(_txtTitle, "messageWindows", "battlescape");
add(_txtWounded, "messageWindows", "battlescape");
add(_txtConfirm, "messageWindows", "battlescape");
add(_btnOk, "messageWindowButtons", "battlescape");
add(_btnCancel, "messageWindowButtons", "battlescape");

// Set up objects
_window->setHighContrast(true);
_window->setBackground(_game->getMod()->getSurface("TAC00.SCR"));

_txtTitle->setBig();
_txtTitle->setHighContrast(true);
_txtTitle->setText(tr("STR_MISSION_OVER"));

_txtWounded->setBig();
_txtWounded->setHighContrast(true);
_txtWounded->setText(tr("STR_UNITS_WITH_FATAL_WOUNDS", _wounded));

_txtConfirm->setBig();
_txtConfirm->setAlign(ALIGN_CENTER);
_txtConfirm->setHighContrast(true);
_txtConfirm->setText(tr("STR_END_MISSION_QUESTION"));

_btnOk->setText(tr("STR_OK"));
_btnOk->setHighContrast(true);
_btnOk->onMouseClick((ActionHandler)&ConfirmEndMissionState::btnOkClick);
_btnOk->onKeyboardPress((ActionHandler)&ConfirmEndMissionState::btnOkClick, Options::keyOk);

_btnCancel->setText(tr("STR_CANCEL_UC"));
_btnCancel->setHighContrast(true);
_btnCancel->onMouseClick((ActionHandler)&ConfirmEndMissionState::btnCancelClick);
_btnCancel->onKeyboardPress((ActionHandler)&ConfirmEndMissionState::btnCancelClick, Options::keyCancel);
_btnCancel->onKeyboardPress((ActionHandler)&ConfirmEndMissionState::btnCancelClick, Options::keyBattleAbort);

centerAllSurfaces();
}

/**
*
*/
ConfirmEndMissionState::~ConfirmEndMissionState()
{

}

/**
* Confirms mission end.
* @param action Pointer to an action.
*/
void ConfirmEndMissionState::btnOkClick(Action *)
{
_game->popState();
_parent->requestEndTurn(false);
}

/**
* Returns to the previous screen.
* @param action Pointer to an action.
*/
void ConfirmEndMissionState::btnCancelClick(Action *)
{
_game->popState();
}


}
60 changes: 60 additions & 0 deletions src/Battlescape/ConfirmEndMissionState.h
@@ -0,0 +1,60 @@
/*
* Copyright 2010-2015 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPENXCOM_CONFIRMENDMISSION_H
#define OPENXCOM_CONFIRMENDMISSION_H

#include "../Engine/State.h"

namespace OpenXcom
{

class Window;
class Text;
class TextButton;
class SavedBattleGame;
class BattlescapeGame;

/**
* Screen which asks for confirmation to end the mission.
* Note: only if auto-end battle option is enabled and if there are still soldiers with fatal wounds
*/
class ConfirmEndMissionState : public State
{
private:
Window *_window;
Text *_txtTitle, *_txtWounded, *_txtConfirm;
TextButton *_btnOk, *_btnCancel;
SavedBattleGame *_battleGame;
BattlescapeGame *_parent;
int _wounded;
public:
/// Creates the ConfirmEndMission state.
ConfirmEndMissionState(SavedBattleGame *battleGame, int wounded, BattlescapeGame *parent);
/// Cleans up the ConfirmEndMission state.
~ConfirmEndMissionState();
/// Handler for clicking the OK button.
void btnOkClick(Action *action);
/// Handler for clicking the Cancel button.
void btnCancelClick(Action *action);

};

}

#endif
2 changes: 1 addition & 1 deletion src/Battlescape/TileEngine.cpp
Expand Up @@ -2723,7 +2723,7 @@ bool TileEngine::psiAttack(BattleAction *action)
{
_save->setSelectedUnit(0);
_save->getBattleGame()->cancelCurrentAction(true);
_save->getBattleGame()->requestEndTurn();
_save->getBattleGame()->requestEndTurn(true);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Battlescape/UnitDieBState.cpp
Expand Up @@ -188,7 +188,7 @@ void UnitDieBState::think()
{
_parent->getSave()->setSelectedUnit(0);
_parent->cancelCurrentAction(true);
_parent->requestEndTurn();
_parent->requestEndTurn(true);
}
}
}
Expand Down

0 comments on commit 2f6df1d

Please sign in to comment.