Skip to content
Permalink
Browse files

Merge pull request #1220 from MeridianOXC/mod-check

Check if OXCE is required when enabling mods
  • Loading branch information...
SupSuper committed Mar 4, 2019
2 parents 374e236 + 4f1a6e6 commit 8482ac38271221149456cad5480cee781285e553
@@ -452,6 +452,8 @@ openxcom_SOURCES = \
src/Menu/OptionsDefaultsState.h \
src/Menu/OptionsGeoscapeState.cpp \
src/Menu/OptionsGeoscapeState.h \
src/Menu/OptionsInformExtendedState.cpp \
src/Menu/OptionsInformExtendedState.h \
src/Menu/OptionsModsState.cpp \
src/Menu/OptionsModsState.h \
src/Menu/OptionsNoAudioState.cpp \
@@ -247,6 +247,7 @@ en-GB:
STR_ALIEN_RACE: "Race"
STR_ALIEN_TECH_LEVEL: "Tech Level"
STR_RANDOMIZE: "Randomize"
STR_OXCE_REQUIRED_QUESTION: "This mod requires OpenXcom Extended to run correctly. Enable this mod?"
STR_RESTORE_DEFAULTS_QUESTION: "Are you sure you want to restore the default options?"
STR_DISPLAY_OPTIONS_CONFIRM: "Do you want to keep the current display options?"
STR_DISPLAY_OPTIONS_REVERT: "Reverting in 0:{0}"
@@ -247,6 +247,7 @@ en-US:
STR_ALIEN_RACE: "Race"
STR_ALIEN_TECH_LEVEL: "Tech Level"
STR_RANDOMIZE: "Randomize"
STR_OXCE_REQUIRED_QUESTION: "This mod requires OpenXcom Extended to run correctly. Enable this mod?"
STR_RESTORE_DEFAULTS_QUESTION: "Are you sure you want to restore the default options?"
STR_DISPLAY_OPTIONS_CONFIRM: "Do you want to keep the current display options?"
STR_DISPLAY_OPTIONS_REVERT: "Reverting in 0:{0}"
@@ -221,6 +221,7 @@ set ( menu_src
Menu/OptionsControlsState.cpp
Menu/OptionsDefaultsState.cpp
Menu/OptionsGeoscapeState.cpp
Menu/OptionsInformExtendedState.cpp
Menu/OptionsModsState.cpp
Menu/OptionsNoAudioState.cpp
Menu/OptionsVideoState.cpp
@@ -43,6 +43,7 @@ void ModInfo::load(const std::string &filename)
_id = doc["id"].as<std::string>(_id);
_isMaster = doc["isMaster"].as<bool>(_isMaster);
_reservedSpace = doc["reservedSpace"].as<int>(_reservedSpace);
_requiredExtendedVersion = doc["requiredExtendedVersion"].as<std::string>(_requiredExtendedVersion);

if (_reservedSpace < 1)
{
@@ -77,6 +78,7 @@ const std::string &ModInfo::getAuthor() const { return _author; }
const std::string &ModInfo::getId() const { return _id; }
const std::string &ModInfo::getMaster() const { return _master; }
bool ModInfo::isMaster() const { return _isMaster; }
const std::string &ModInfo::getRequiredExtendedVersion() const { return _requiredExtendedVersion; }
int ModInfo::getReservedSpace() const { return _reservedSpace; }
void ModInfo::setReservedSpace(int reservedSpace)
{
@@ -33,6 +33,7 @@ class ModInfo
std::string _name, _desc, _version, _author, _url, _id, _master;
bool _isMaster;
int _reservedSpace;
std::string _requiredExtendedVersion;
std::vector<std::string> _externalResourceDirs;
public:
/// Creates default metadata for a mod at the specified path.
@@ -62,6 +63,8 @@ class ModInfo
int getReservedSpace() const;
/// Sets mod size (DO NOT use this method outside Options::updateReservedSpace()).
void setReservedSpace(int reservedSpace);
/// Gets the OXCE version required by this mod.
const std::string &getRequiredExtendedVersion() const;
/// Gets the list of external resource dirs to load for this mod.
const std::vector<std::string> &getExternalResourceDirs() const;
};
@@ -0,0 +1,111 @@
/*
* Copyright 2010-2019 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 "OptionsInformExtendedState.h"
#include "../Engine/Game.h"
#include "../Engine/LocalizedText.h"
#include "../Engine/Options.h"
#include "../Interface/Text.h"
#include "../Interface/TextButton.h"
#include "../Interface/Window.h"
#include "../Mod/Mod.h"

namespace OpenXcom
{

/**
* Initializes all the elements in the Confirm OXCE screen.
* @param state Pointer to the Options|Mod state.
* @param isMaster Are we enabling a standard mod or a master mod?
*/
OptionsInformExtendedState::OptionsInformExtendedState(OptionsModsState *state, bool isMaster) : _state(state), _isMaster(isMaster)
{
_screen = false;

// Create objects
_window = new Window(this, 256, 100, 32, 50, POPUP_BOTH);
_btnYes = new TextButton(60, 18, 60, 122);
_btnNo = new TextButton(60, 18, 200, 122);
_txtTitle = new Text(246, 50, 37, 64);

// Set palette
setInterface("optionsMenu");

add(_window, "confirmDefaults", "optionsMenu");
add(_btnYes, "confirmDefaults", "optionsMenu");
add(_btnNo, "confirmDefaults", "optionsMenu");
add(_txtTitle, "confirmDefaults", "optionsMenu");

centerAllSurfaces();

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

_btnYes->setText(tr("STR_YES"));
_btnYes->onMouseClick((ActionHandler)&OptionsInformExtendedState::btnYesClick);

_btnNo->setText(tr("STR_NO"));
_btnNo->onMouseClick((ActionHandler)&OptionsInformExtendedState::btnNoClick);

_txtTitle->setAlign(ALIGN_CENTER);
_txtTitle->setBig();
_txtTitle->setWordWrap(true);
_txtTitle->setText(tr("STR_OXCE_REQUIRED_QUESTION"));
}

/**
*
*/
OptionsInformExtendedState::~OptionsInformExtendedState()
{

}

/**
* Closes the window. Enables the mod.
* @param action Pointer to an action.
*/
void OptionsInformExtendedState::btnYesClick(Action *action)
{
_game->popState();

if (_isMaster)
{
_state->changeMasterMod();
}
else
{
_state->toggleMod();
}
}

/**
* Closes the window. Does not enable the mod.
* @param action Pointer to an action.
*/
void OptionsInformExtendedState::btnNoClick(Action *)
{
_game->popState();

if (_isMaster)
{
_state->revertMasterMod();
}
}

}
@@ -0,0 +1,53 @@
#pragma once
/*
* Copyright 2010-2019 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 "../Engine/State.h"
#include "OptionsModsState.h"

namespace OpenXcom
{

class TextButton;
class Window;
class Text;

/**
* Confirmation window when enabling
* mods that require OXCE.
*/
class OptionsInformExtendedState : public State
{
private:
OptionsModsState *_state;
bool _isMaster;
TextButton *_btnYes, *_btnNo;
Window *_window;
Text *_txtTitle;
public:
/// Creates the Confirm OXCE state.
OptionsInformExtendedState(OptionsModsState *state, bool isMaster);
/// Cleans up the Confirm OXCE state.
~OptionsInformExtendedState();
/// Handler for clicking the Yes button.
void btnYesClick(Action *action);
/// Handler for clicking the No button.
void btnNoClick(Action *action);
};

}
@@ -17,6 +17,7 @@
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "OptionsModsState.h"
#include "OptionsInformExtendedState.h"
#include <climits>
#include <algorithm>
#include "../Engine/Game.h"
@@ -37,7 +38,7 @@ namespace OpenXcom
* @param game Pointer to the core game.
* @param origin Game section that originated this state.
*/
OptionsModsState::OptionsModsState(OptionsOrigin origin) : OptionsBaseState(origin)
OptionsModsState::OptionsModsState(OptionsOrigin origin) : OptionsBaseState(origin), _curMasterIdx(0)
{
setCategory(_btnMods);

@@ -69,7 +70,6 @@ OptionsModsState::OptionsModsState(OptionsOrigin origin) : OptionsBaseState(orig

// scan for masters
const std::map<std::string, ModInfo> &modInfos(Options::getModInfos());
size_t curMasterIdx = 0;
std::vector<std::string> masterNames;
for (std::vector< std::pair<std::string, bool> >::const_iterator i = Options::mods.begin(); i != Options::mods.end(); ++i)
{
@@ -86,14 +86,14 @@ OptionsModsState::OptionsModsState(OptionsOrigin origin) : OptionsBaseState(orig
}
else if (_curMasterId.empty())
{
++curMasterIdx;
++_curMasterIdx;
}
_masters.push_back(modInfo);
masterNames.push_back(modInfo->getName());
}

_cbxMasters->setOptions(masterNames);
_cbxMasters->setSelected(curMasterIdx);
_cbxMasters->setSelected(_curMasterIdx);
_cbxMasters->onChange((ActionHandler)&OptionsModsState::cbxMasterChange);
_cbxMasters->onMouseIn((ActionHandler)&OptionsModsState::txtTooltipIn);
_cbxMasters->onMouseOut((ActionHandler)&OptionsModsState::txtTooltipOut);
@@ -134,6 +134,22 @@ void OptionsModsState::cbxMasterHover(Action *)
}

void OptionsModsState::cbxMasterChange(Action *)
{
const ModInfo *masterModInfo = _masters[_cbxMasters->getSelected()];

// when changing a master mod, check if it requires OXCE
{
if (!masterModInfo->getRequiredExtendedVersion().empty())
{
_game->pushState(new OptionsInformExtendedState(this, true));
return;
}
}

changeMasterMod();
}

void OptionsModsState::changeMasterMod()
{
std::string masterId = _masters[_cbxMasters->getSelected()]->getId();
for (std::vector< std::pair<std::string, bool> >::iterator i = Options::mods.begin(); i != Options::mods.end(); ++i)
@@ -149,10 +165,16 @@ void OptionsModsState::cbxMasterChange(Action *)
}
Options::reload = true;

_curMasterIdx = _cbxMasters->getSelected();
_curMasterId = masterId;
lstModsRefresh(0);
}

void OptionsModsState::revertMasterMod()
{
_cbxMasters->setSelected(_curMasterIdx);
}

void OptionsModsState::lstModsRefresh(size_t scrollLoc)
{
_lstMods->clearList();
@@ -195,6 +217,26 @@ void OptionsModsState::lstModsClick(Action *action)
}

std::pair<std::string, bool> &mod(_mods.at(_lstMods->getSelectedRow()));

// when activating a mod, check if it requires OXCE
if (!mod.second)
{
const ModInfo *modInfo = &Options::getModInfos().at(mod.first);
if (!modInfo->getRequiredExtendedVersion().empty())
{
_game->pushState(new OptionsInformExtendedState(this, false));
return;
}
}

// if deactivating, or if not OXCE mod
toggleMod();
}

void OptionsModsState::toggleMod()
{
std::pair<std::string, bool> &mod(_mods.at(_lstMods->getSelectedRow()));

for (std::vector< std::pair<std::string, bool> >::iterator i = Options::mods.begin(); i != Options::mods.end(); ++i)
{
if (mod.first != i->first)
@@ -42,6 +42,7 @@ class OptionsModsState : public OptionsBaseState
std::vector<const ModInfo *> _masters;
std::string _curMasterId;
std::vector< std::pair<std::string, bool> > _mods;
size_t _curMasterIdx;
public:
/// Creates the Advanced state.
OptionsModsState(OptionsOrigin origin);
@@ -50,10 +51,13 @@ class OptionsModsState : public OptionsBaseState
std::string makeTooltip(const ModInfo &modInfo);
void cbxMasterHover(Action *action);
void cbxMasterChange(Action *action);
void changeMasterMod();
void revertMasterMod();
void lstModsRefresh(size_t scrollLoc);
void lstModsHover(Action *action);
/// Handler for clicking an item on the menu.
void lstModsClick(Action *action);
void toggleMod();
/// Handler for clicking the left reordering button.
void lstModsLeftArrowClick(Action *action);
/// Moves a mod up.
@@ -426,6 +426,7 @@
<ClCompile Include="Menu\OptionsBaseState.cpp" />
<ClCompile Include="Menu\OptionsBattlescapeState.cpp" />
<ClCompile Include="Menu\OptionsControlsState.cpp" />
<ClCompile Include="Menu\OptionsInformExtendedState.cpp" />
<ClCompile Include="Menu\OptionsModsState.cpp" />
<ClCompile Include="Menu\OptionsNoAudioState.cpp" />
<ClCompile Include="Menu\OptionsVideoState.cpp" />
@@ -758,6 +759,7 @@
<ClInclude Include="Menu\OptionsBaseState.h" />
<ClInclude Include="Menu\OptionsBattlescapeState.h" />
<ClInclude Include="Menu\OptionsControlsState.h" />
<ClInclude Include="Menu\OptionsInformExtendedState.h" />
<ClInclude Include="Menu\OptionsModsState.h" />
<ClInclude Include="Menu\OptionsNoAudioState.h" />
<ClInclude Include="Menu\OptionsVideoState.h" />
@@ -943,6 +943,9 @@
<ClCompile Include="Engine\Unicode.cpp">
<Filter>Engine</Filter>
</ClCompile>
<ClCompile Include="Menu\OptionsInformExtendedState.cpp">
<Filter>Menu</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h" />
@@ -1926,6 +1929,9 @@
<ClInclude Include="Engine\Unicode.h">
<Filter>Engine</Filter>
</ClInclude>
<ClInclude Include="Menu\OptionsInformExtendedState.h">
<Filter>Menu</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Geoscape">

0 comments on commit 8482ac3

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.