Skip to content

Commit

Permalink
Image background per UFO (for missile base hit)
Browse files Browse the repository at this point in the history
  • Loading branch information
MeridianOXC committed Dec 30, 2023
1 parent 472398e commit 2af9575
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/Engine/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,17 @@ void State::setInterface(const std::string& category, bool alterPal, SavedBattle
void State::setWindowBackground(Window *window, const std::string &s)
{
auto& bgImageName = _game->getMod()->getInterface(s)->getBackgroundImage();
auto* bgImage = _game->getMod()->getSurface(bgImageName);
setWindowBackgroundImage(window, bgImageName);
}

/**
* Set window background by image name (instead of by interface name).
* @param window Window handle.
* @param s ID of the image.
*/
void State::setWindowBackgroundImage(Window* window, const std::string& bgImageName)
{
const auto* bgImage = _game->getMod()->getSurface(bgImageName);
window->setBackground(bgImage);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Engine/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class State
void setInterface(const std::string &s, bool alterPal = false, SavedBattleGame *battleGame = 0);
/// Set window background.
void setWindowBackground(Window *window, const std::string &s);
/// Set window background by image name (instead of by interface name).
void setWindowBackgroundImage(Window* window, const std::string& bgImageName);
/// Adds a child element to the state.
void add(Surface *surface);
/// Adds a child element to the state.
Expand Down
12 changes: 10 additions & 2 deletions src/Geoscape/BaseDestroyedState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
namespace OpenXcom
{

BaseDestroyedState::BaseDestroyedState(Base *base, bool missiles, bool partialDestruction) : _base(base), _missiles(missiles), _partialDestruction(partialDestruction)
BaseDestroyedState::BaseDestroyedState(Base *base, const Ufo* ufo, bool missiles, bool partialDestruction) :
_base(base), _missiles(missiles), _partialDestruction(partialDestruction)
{
_screen = false;

Expand All @@ -60,7 +61,14 @@ BaseDestroyedState::BaseDestroyedState(Base *base, bool missiles, bool partialDe
centerAllSurfaces();

// Set up objects
setWindowBackground(_window, "baseDestroyed");
if (ufo->getRules()->getHitImage().empty())
{
setWindowBackground(_window, "baseDestroyed");
}
else
{
setWindowBackgroundImage(_window, ufo->getRules()->getHitImage());
}

_btnOk->setText(tr("STR_OK"));
_btnOk->onMouseClick((ActionHandler)&BaseDestroyedState::btnOkClick);
Expand Down
3 changes: 2 additions & 1 deletion src/Geoscape/BaseDestroyedState.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Window;
class Text;
class TextButton;
class TextList;
class Ufo;

/**
* Screen that allows the player
Expand All @@ -43,7 +44,7 @@ class BaseDestroyedState : public State
bool _missiles, _partialDestruction;
public:
/// Creates the Select Destination state.
BaseDestroyedState(Base *base, bool missiles, bool partialDestruction);
BaseDestroyedState(Base *base, const Ufo* ufo, bool missiles, bool partialDestruction);
/// Cleans up the Select Destination state.
~BaseDestroyedState();
/// Handler for clicking the Cydonia mission button.
Expand Down
6 changes: 3 additions & 3 deletions src/Geoscape/GeoscapeState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3404,7 +3404,7 @@ void GeoscapeState::handleBaseDefense(Base *base, Ufo *ufo)
if (ufo->getRules()->getMissilePower() < 0)
{
// It's a nuclear warhead... Skynet knows no mercy
popup(new BaseDestroyedState(base, true, false));
popup(new BaseDestroyedState(base, ufo, true, false));
}
else
{
Expand All @@ -3418,7 +3418,7 @@ void GeoscapeState::handleBaseDefense(Base *base, Ufo *ufo)
base->cleanupDefenses(true);

// let the player know that some facilities were destroyed, but the base survived
popup(new BaseDestroyedState(base, true, true));
popup(new BaseDestroyedState(base, ufo, true, true));
}
}
else if (base->getAvailableSoldiers(true, true) > 0 || !base->getVehicles()->empty())
Expand All @@ -3441,7 +3441,7 @@ void GeoscapeState::handleBaseDefense(Base *base, Ufo *ufo)
else
{
// Please garrison your bases in future
popup(new BaseDestroyedState(base, false, false));
popup(new BaseDestroyedState(base, ufo, false, false));
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Mod/RuleUfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void RuleUfo::load(const YAML::Node &node, Mod *mod, const ModScript &parsers)
_battlescapeTerrainData = rule;
}
_modSprite = node["modSprite"].as<std::string>(_modSprite);
_hitImage = node["hitImage"].as<std::string>(_hitImage);
if (const YAML::Node &raceBonus = node["raceBonus"])
{
for (YAML::const_iterator i = raceBonus.begin(); i != raceBonus.end(); ++i)
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/RuleUfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class RuleUfo
RuleUfoStats _stats;
std::map<std::string, RuleUfoStats> _statsRaceBonus;
std::string _modSprite;
std::string _hitImage;

ModScript::UfoScripts::Container _ufoScripts;
ScriptValues<RuleUfo> _scriptValues;
Expand Down Expand Up @@ -134,6 +135,8 @@ class RuleUfo
int getHuntAlertSound() const;
/// Gets the name of the surface that represents this UFO.
const std::string &getModSprite() const;
/// Gets the name of the surface to be displayed in the BaseDestroyedState UI.
const std::string& getHitImage() const { return _hitImage; }
/// Get basic statistic of UFO.
const RuleUfoStats& getStats() const;
/// Get race bonus of statistic of UFO.
Expand Down

0 comments on commit 2af9575

Please sign in to comment.