Skip to content
Permalink
Browse files

Move Mods to main menu

  • Loading branch information...
SupSuper committed Jul 18, 2019
1 parent d6b8c6e commit 01223c9f507af2910aff5003905802799521a0fe
@@ -164,7 +164,8 @@ en-GB:
STR_VIDEO: "VIDEO"
STR_AUDIO: "AUDIO"
STR_BATTLESCAPE_UC: "BATTLESCAPE"
STR_MODS: "MODS"
STR_MODS_UC: "MODS"
STR_MODS: "Mods"
STR_DISPLAY_RESOLUTION: "Display Resolution"
STR_DISPLAY_RESOLUTION_DESC: "Changes the resolution of the display, the game resolution will be resized to match. Arrows switch between supported resolutions. Click to input a custom resolution."
STR_ORIGINAL: "Original"
@@ -208,7 +209,7 @@ en-GB:
STR_GLOBE_FLIGHT_PATHS: "Flight Paths"
STR_GLOBE_FLIGHT_PATHS_DESC: "Shows craft flight paths on the globe."
STR_CONTROLS_DESC: "Left-click a shortcut and press a key to change it.{NEWLINE}Right-click a shortcut to disable it."
STR_GAME_TYPE: "Game type"
STR_BASE_GAME: "Base game"
STR_MODS_TOOLTIP: "Version {0} by {1}.{NEWLINE}{2}"
STR_EDGE_SCROLL: "Edge Scroll"
STR_EDGE_SCROLL_DESC: "Trigger: Scroll map when the left mouse button is held down on a screen edge.{NEWLINE}Auto: Scroll map when the cursor is over a screen edge."
@@ -164,7 +164,8 @@ en-US:
STR_VIDEO: "VIDEO"
STR_AUDIO: "AUDIO"
STR_BATTLESCAPE_UC: "BATTLESCAPE"
STR_MODS: "MODS"
STR_MODS_UC: "MODS"
STR_MODS: "Mods"
STR_DISPLAY_RESOLUTION: "Display Resolution"
STR_DISPLAY_RESOLUTION_DESC: "Changes the resolution of the display, the game resolution will be resized to match. Arrows switch between supported resolutions. Click to input a custom resolution."
STR_ORIGINAL: "Original"
@@ -208,7 +209,7 @@ en-US:
STR_GLOBE_FLIGHT_PATHS: "Flight Paths"
STR_GLOBE_FLIGHT_PATHS_DESC: "Shows craft flight paths on the globe."
STR_CONTROLS_DESC: "Left-click a shortcut and press a key to change it.{NEWLINE}Right-click a shortcut to disable it."
STR_GAME_TYPE: "Game type"
STR_BASE_GAME: "Base game"
STR_MODS_TOOLTIP: "Version {0} by {1}.{NEWLINE}{2}"
STR_EDGE_SCROLL: "Edge Scroll"
STR_EDGE_SCROLL_DESC: "Trigger: Scroll map when the left mouse button is held down on a screen edge.{NEWLINE}Auto: Scroll map when the cursor is over a screen edge."
@@ -30,6 +30,7 @@
#include "NewBattleState.h"
#include "ListLoadState.h"
#include "OptionsVideoState.h"
#include "OptionsModsState.h"
#include "../Engine/Options.h"

namespace OpenXcom
@@ -54,7 +55,8 @@ MainMenuState::MainMenuState()
_btnNewBattle = new TextButton(92, 20, 164, 90);
_btnLoad = new TextButton(92, 20, 64, 118);
_btnOptions = new TextButton(92, 20, 164, 118);
_btnQuit = new TextButton(192, 20, 64, 146);
_btnMods = new TextButton(92, 20, 64, 146);
_btnQuit = new TextButton(92, 20, 164, 146);
_txtTitle = new Text(256, 30, 32, 45);

// Set palette
@@ -65,6 +67,7 @@ MainMenuState::MainMenuState()
add(_btnNewBattle, "button", "mainMenu");
add(_btnLoad, "button", "mainMenu");
add(_btnOptions, "button", "mainMenu");
add(_btnMods, "button", "mainMenu");
add(_btnQuit, "button", "mainMenu");
add(_txtTitle, "text", "mainMenu");

@@ -85,6 +88,9 @@ MainMenuState::MainMenuState()
_btnOptions->setText(tr("STR_OPTIONS"));
_btnOptions->onMouseClick((ActionHandler)&MainMenuState::btnOptionsClick);

_btnMods->setText(tr("STR_MODS"));
_btnMods->onMouseClick((ActionHandler)&MainMenuState::btnModsClick);

_btnQuit->setText(tr("STR_QUIT"));
_btnQuit->onMouseClick((ActionHandler)&MainMenuState::btnQuitClick);

@@ -141,6 +147,15 @@ void MainMenuState::btnOptionsClick(Action *)
_game->pushState(new OptionsVideoState(OPT_MENU));
}

/**
* Opens the Mods screen.
* @param action Pointer to an action.
*/
void MainMenuState::btnModsClick(Action *)
{
_game->pushState(new OptionsModsState);
}

/**
* Quits the game.
* @param action Pointer to an action.
@@ -40,7 +40,7 @@ class GoToMainMenuState : public State
class MainMenuState : public State
{
private:
TextButton *_btnNewGame, *_btnNewBattle, *_btnLoad, *_btnOptions, *_btnQuit;
TextButton *_btnNewGame, *_btnNewBattle, *_btnLoad, *_btnOptions, *_btnMods, *_btnQuit;
Window *_window;
Text *_txtTitle;
public:
@@ -56,6 +56,8 @@ class MainMenuState : public State
void btnLoadClick(Action *action);
/// Handler for clicking the Options button.
void btnOptionsClick(Action *action);
/// Handler for clicking the Mods button.
void btnModsClick(Action *action);
/// Handler for clicking the Quit button.
void btnQuitClick(Action *action);
/// Update the resolution settings, we just resized the window.
@@ -63,7 +63,6 @@ OptionsBaseState::OptionsBaseState(OptionsOrigin origin) : _origin(origin)
_btnGeoscape = new TextButton(80, 16, 8, 68);
_btnBattlescape = new TextButton(80, 16, 8, 88);
_btnAdvanced = new TextButton(80, 16, 8, 108);
_btnMods = new TextButton(80, 16, 8, 128);

_btnOk = new TextButton(100, 16, 8, 176);
_btnCancel = new TextButton(100, 16, 110, 176);
@@ -82,7 +81,6 @@ OptionsBaseState::OptionsBaseState(OptionsOrigin origin) : _origin(origin)
add(_btnGeoscape, "button", "optionsMenu");
add(_btnBattlescape, "button", "optionsMenu");
add(_btnAdvanced, "button", "optionsMenu");
add(_btnMods, "button", "optionsMenu");

add(_btnOk, "button", "optionsMenu");
add(_btnCancel, "button", "optionsMenu");
@@ -111,10 +109,6 @@ OptionsBaseState::OptionsBaseState(OptionsOrigin origin) : _origin(origin)
_btnAdvanced->setText(tr("STR_ADVANCED"));
_btnAdvanced->onMousePress((ActionHandler)&OptionsBaseState::btnGroupPress, SDL_BUTTON_LEFT);

_btnMods->setText(tr("STR_MODS"));
_btnMods->onMousePress((ActionHandler)&OptionsBaseState::btnGroupPress, SDL_BUTTON_LEFT);
_btnMods->setVisible(_origin == OPT_MENU); // Mods require a restart, don't enable them in-game

_btnOk->setText(tr("STR_OK"));
_btnOk->onMouseClick((ActionHandler)&OptionsBaseState::btnOkClick);
_btnOk->onKeyboardPress((ActionHandler)&OptionsBaseState::btnOkClick, Options::keyOk);
@@ -181,7 +175,6 @@ void OptionsBaseState::setCategory(TextButton *button)
_btnGeoscape->setGroup(&_group);
_btnBattlescape->setGroup(&_group);
_btnAdvanced->setGroup(&_group);
_btnMods->setGroup(&_group);
}

/**
@@ -291,10 +284,6 @@ void OptionsBaseState::btnGroupPress(Action *action)
{
_game->pushState(new OptionsAdvancedState(_origin));
}
else if (sender == _btnMods)
{
_game->pushState(new OptionsModsState(_origin));
}
}
}

@@ -43,7 +43,7 @@ class OptionsBaseState : public State
protected:
OptionsOrigin _origin;
Window *_window;
TextButton *_btnVideo, *_btnAudio, *_btnControls, *_btnGeoscape, *_btnBattlescape, *_btnAdvanced, *_btnMods;
TextButton *_btnVideo, *_btnAudio, *_btnControls, *_btnGeoscape, *_btnBattlescape, *_btnAdvanced;
TextButton *_btnOk, *_btnCancel, *_btnDefault;
Text *_txtTooltip;
std::string _currentTooltip;
@@ -26,29 +26,44 @@
#include "../Interface/Window.h"
#include "../Interface/TextList.h"
#include "../Interface/Text.h"
#include "../Interface/TextButton.h"
#include "../Interface/ComboBox.h"
#include "../Engine/Options.h"
#include "../Engine/Action.h"
#include "StartState.h"

namespace OpenXcom
{

/**
* Initializes all the elements in the Mod Options window.
* @param game Pointer to the core game.
* @param origin Game section that originated this state.
*/
OptionsModsState::OptionsModsState(OptionsOrigin origin) : OptionsBaseState(origin), _curMasterIdx(0)
OptionsModsState::OptionsModsState() : _curMasterIdx(0)
{
setCategory(_btnMods);

// Create objects
_txtMaster = new Text(114, 9, 94, 8);
_cbxMasters = new ComboBox(this, 218, 16, 94, 18);
_lstMods = new TextList(200, 104, 94, 40);
_window = new Window(this, 320, 200, 0, 0);

_txtMaster = new Text(305, 9, 8, 8);
_cbxMasters = new ComboBox(this, 305, 16, 8, 18);
_lstMods = new TextList(288, 104, 8, 40);

_btnOk = new TextButton(100, 16, 8, 176);
_btnCancel = new TextButton(100, 16, 212, 176);

_txtTooltip = new Text(305, 25, 8, 148);

// Set palette
setInterface("optionsMenu");

add(_window, "window", "optionsMenu");

add(_txtMaster, "text", "modsMenu");
add(_lstMods, "optionLists", "modsMenu");
add(_btnOk, "button", "optionsMenu");
add(_btnCancel, "button", "optionsMenu");
add(_txtTooltip, "tooltip", "optionsMenu");

add(_cbxMasters, "button", "modsMenu");

centerAllSurfaces();
@@ -66,7 +81,9 @@ OptionsModsState::OptionsModsState(OptionsOrigin origin) : OptionsBaseState(orig
int leftcol = _lstMods->getWidth() - (rightcol + arrowCol);

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

_txtMaster->setText(tr("STR_BASE_GAME"));

// scan for masters
const std::map<std::string, ModInfo> &modInfos(Options::getModInfos());
@@ -116,6 +133,16 @@ OptionsModsState::OptionsModsState(OptionsOrigin origin) : OptionsBaseState(orig
_lstMods->onMouseOut((ActionHandler)&OptionsModsState::txtTooltipOut);
_lstMods->onMouseOver((ActionHandler)&OptionsModsState::lstModsHover);
lstModsRefresh(0);

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

_btnCancel->setText(tr("STR_CANCEL"));
_btnCancel->onMouseClick((ActionHandler)&OptionsModsState::btnCancelClick);
_btnCancel->onKeyboardPress((ActionHandler)&OptionsModsState::btnCancelClick, Options::keyCancel);

_txtTooltip->setWordWrap(true);
}

OptionsModsState::~OptionsModsState()
@@ -441,4 +468,56 @@ void OptionsModsState::lstModsMousePress(Action *action)
}
}

/**
* Restarts game with new mods.
* @param action Pointer to an action.
*/
void OptionsModsState::btnOkClick(Action *)
{
Options::save();
if (Options::reload)
{
Options::mapResources();
_game->loadLanguages();
_game->setState(new StartState);
}
else
{
_game->popState();
}
}

/**
* Ignores mod changes and returns to the previous screen.
* @param action Pointer to an action.
*/
void OptionsModsState::btnCancelClick(Action *)
{
Options::reload = false;
Options::load();
_game->popState();
}

/**
* Shows a tooltip for the appropriate button.
* @param action Pointer to an action.
*/
void OptionsModsState::txtTooltipIn(Action *action)
{
_currentTooltip = action->getSender()->getTooltip();
_txtTooltip->setText(tr(_currentTooltip));
}

/**
* Clears the tooltip text.
* @param action Pointer to an action.
*/
void OptionsModsState::txtTooltipOut(Action *action)
{
if (_currentTooltip == action->getSender()->getTooltip())
{
_txtTooltip->setText("");
}
}

}
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "OptionsBaseState.h"
#include "../Engine/State.h"
#include "../Engine/ModInfo.h"
#include <vector>
#include <string>
@@ -26,27 +26,34 @@
namespace OpenXcom
{

class Window;
class Text;
class TextList;
class TextButton;
class ComboBox;

/**
* Options window that displays the
* available mods.
*/
class OptionsModsState : public OptionsBaseState
class OptionsModsState : public State
{
private:
Text *_txtMaster;
Window *_window;
Text *_txtMaster;
ComboBox *_cbxMasters;
TextList *_lstMods;
TextButton *_btnOk, *_btnCancel;
Text *_txtTooltip;
std::string _currentTooltip;
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);
/// Cleans up the Advanced state.
/// Creates the Mods state.
OptionsModsState();
/// Cleans up the Mods state.
~OptionsModsState();
std::string makeTooltip(const ModInfo &modInfo);
void cbxMasterHover(Action *action);
@@ -68,6 +75,14 @@ class OptionsModsState : public OptionsBaseState
void moveModDown(Action *action, unsigned int row, bool max = false);
/// Handler for pressing-down a mouse-button in the list.
void lstModsMousePress(Action *action);
/// Handler for showing tooltip.
void txtTooltipIn(Action *action);
/// Handler for hiding tooltip.
void txtTooltipOut(Action *action);
/// Handler for clicking the OK button.
void btnOkClick(Action *action);
/// Handler for clicking the Cancel button.
void btnCancelClick(Action *action);
};

}

0 comments on commit 01223c9

Please sign in to comment.
You can’t perform that action at this time.