Skip to content

Commit

Permalink
NWN: Add back the ingame main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Mar 21, 2014
1 parent 9027256 commit 4b267c2
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 29 deletions.
6 changes: 6 additions & 0 deletions src/engines/nwn/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ noinst_HEADERS = \
gui/widgets/quadwidget.h \
gui/widgets/portrait.h \
gui/gui.h \
gui/dialogs/okcancel.h \
gui/dialogs/yesnocancel.h \
gui/main/main.h \
gui/main/moviesbase.h \
gui/main/moviescamp.h \
Expand All @@ -54,6 +56,7 @@ noinst_HEADERS = \
gui/options/videoadv.h \
gui/options/resolution.h \
gui/chargen/chargen.h \
gui/ingame/main.h \
$(EMPTY)

libnwn_la_SOURCES = \
Expand Down Expand Up @@ -88,6 +91,8 @@ libnwn_la_SOURCES = \
gui/widgets/quadwidget.cpp \
gui/widgets/portrait.cpp \
gui/gui.cpp \
gui/dialogs/okcancel.cpp \
gui/dialogs/yesnocancel.cpp \
gui/main/main.cpp \
gui/main/moviesbase.cpp \
gui/main/moviescamp.cpp \
Expand All @@ -109,4 +114,5 @@ libnwn_la_SOURCES = \
gui/options/videoadv.cpp \
gui/options/resolution.cpp \
gui/chargen/chargen.cpp \
gui/ingame/main.cpp \
$(EMPTY)
19 changes: 11 additions & 8 deletions src/engines/nwn/gui/dialogs/okcancel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ OKCancelDialog::OKCancelDialog(const Common::UString &msg,
const Common::UString &ok, const Common::UString &cancel) :
_msg(msg), _ok(ok), _cancel(cancel) {

setPosition(0.0, 0.0, -250.0);
load("okcancelpanel");
}

Expand All @@ -67,17 +68,19 @@ void OKCancelDialog::initWidget(Widget &widget) {
}
}

void OKCancelDialog::show() {
// Center the message
WidgetLabel &msg = *getLabel("MessageLabel", true);
WidgetPanel &pnl = *getPanel("PNL_OK" , true);
void OKCancelDialog::setVisible(bool visible) {
if (visible) {
// Center the message
WidgetLabel &msg = *getLabel("MessageLabel", true);
WidgetPanel &pnl = *getPanel("PNL_OK" , true);

float pX, pY, pZ;
pnl.getPosition(pX, pY, pZ);
float pX, pY, pZ;
pnl.getPosition(pX, pY, pZ);

msg.setPosition(pX - msg.getWidth() / 2.0, pY - msg.getHeight() / 2.0, pZ - 1.0);
msg.setPosition(floor(pX - msg.getWidth() / 2.0f), floor(pY + msg.getHeight() / 2.0f), pZ + 1.0f);
}

GUI::show();
GUI::setVisible(visible);
}

void OKCancelDialog::callbackActive(Widget &widget) {
Expand Down
2 changes: 1 addition & 1 deletion src/engines/nwn/gui/dialogs/okcancel.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class OKCancelDialog : public GUI {
const Common::UString &ok = "", const Common::UString &cancel = "");
~OKCancelDialog();

void show();
void setVisible(bool visible);

protected:
void initWidget(Widget &widget);
Expand Down
19 changes: 11 additions & 8 deletions src/engines/nwn/gui/dialogs/yesnocancel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ YesNoCancelDialog::YesNoCancelDialog(const Common::UString &msg, const Common::U
const Common::UString &no, const Common::UString &cancel) :
_msg(msg), _yes(yes), _no(no), _cancel(cancel) {

setPosition(0.0, 0.0, -250.0);
load("yesnocancelpanel");
}

Expand Down Expand Up @@ -72,17 +73,19 @@ void YesNoCancelDialog::initWidget(Widget &widget) {
}
}

void YesNoCancelDialog::show() {
// Center the message
WidgetLabel &msg = *getLabel("MessageLabel", true);
WidgetPanel &pnl = *getPanel("PNL_OK" , true);
void YesNoCancelDialog::setVisible(bool visible) {
if (visible) {
// Center the message
WidgetLabel &msg = *getLabel("MessageLabel", true);
WidgetPanel &pnl = *getPanel("PNL_OK" , true);

float pX, pY, pZ;
pnl.getPosition(pX, pY, pZ);
float pX, pY, pZ;
pnl.getPosition(pX, pY, pZ);

msg.setPosition(pX - msg.getWidth() / 2.0, pY - msg.getHeight() / 2.0, pZ);
msg.setPosition(floor(pX - msg.getWidth() / 2.0f), floor(pY + msg.getHeight() / 2.0f), pZ + 1.0f);
}

GUI::show();
GUI::setVisible(visible);
}

void YesNoCancelDialog::callbackActive(Widget &widget) {
Expand Down
2 changes: 1 addition & 1 deletion src/engines/nwn/gui/dialogs/yesnocancel.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class YesNoCancelDialog : public GUI {
const Common::UString &no = "", const Common::UString &cancel = "");
~YesNoCancelDialog();

void show();
void setVisible(bool visible);

protected:
void initWidget(Widget &widget);
Expand Down
30 changes: 20 additions & 10 deletions src/engines/nwn/gui/ingame/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ namespace Engines {

namespace NWN {

IngameMainMenu::IngameMainMenu() {
IngameMainMenu::IngameMainMenu() : _game(0), _video(0), _sound(0), _controls(0), _quitPrompt(0) {
setPosition(0.0, 0.0, -300.0);
load("options_main");

// TODO: Load game
Expand All @@ -58,14 +59,6 @@ IngameMainMenu::IngameMainMenu() {

// TODO: Save character
getWidget("SaveCharButton", true)->setDisabled(true);

_game = new OptionsGameMenu(false);
_video = new OptionsVideoMenu(false);
_sound = new OptionsSoundMenu(false);
_controls = new OptionsControlsMenu(false);

_quitPrompt = new OKCancelDialog(TalkMan.getString(10308),
TalkMan.getString(8274), TalkMan.getString(8275));
}

IngameMainMenu::~IngameMainMenu() {
Expand Down Expand Up @@ -98,31 +91,48 @@ void IngameMainMenu::callbackActive(Widget &widget) {
}

if (widget.getTag() == "ExitButton") {
if (!_quitPrompt)
_quitPrompt = new OKCancelDialog(TalkMan.getString(10308),
TalkMan.getString(8274), TalkMan.getString(8275));

if (sub(*_quitPrompt, 0, false) == 1) {
_returnCode = 2;
return;
}

show();
setVisible(true);
return;
}


if (widget.getTag() == "GameButton") {
if (!_game)
_game = new OptionsGameMenu(false);

sub(*_game);
return;
}

if (widget.getTag() == "VideoOptionsButton") {
if (!_video)
_video = new OptionsVideoMenu(false);

sub(*_video);
return;
}

if (widget.getTag() == "SoundOptionsButton") {
if (!_sound)
_sound = new OptionsSoundMenu(false);

sub(*_sound);
return;
}

if (widget.getTag() == "ControlsButton") {
if (!_controls)
_controls = new OptionsControlsMenu(false);

sub(*_controls);
return;
}
Expand Down
22 changes: 21 additions & 1 deletion src/engines/nwn/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,20 @@
#include "engines/nwn/area.h"
#include "engines/nwn/object.h"

#include "engines/nwn/gui/ingame/main.h"

namespace Engines {

namespace NWN {

Module::Module() : _hasModule(false), _currentTexturePack(-1), _exit(false),
Module::Module() : _hasModule(false), _menu(0), _currentTexturePack(-1), _exit(false),
_currentArea(0), _currentObject(0) {

}

Module::~Module() {
delete _menu;

clear();
}

Expand Down Expand Up @@ -339,6 +343,8 @@ bool Module::handleKeys(const Events::Event &e) {
_currentArea->setHighlightAll(true);
else if (e.key.keysym.scancode == SDL_SCANCODE_F)
warning("FPS: %lf", GfxMan.getFPS());
else if (e.key.keysym.sym == SDLK_ESCAPE)
showMenu();
else
return false;
}
Expand All @@ -354,6 +360,20 @@ bool Module::handleKeys(const Events::Event &e) {
return true;
}

void Module::showMenu() {
if (!_menu)
_menu = new IngameMainMenu;

_menu->setVisible(true);

int code = _menu->run();

_menu->setVisible(false);

if (code == 2)
_exit = true;
}

void Module::checkCurrentObject() {
int x, y;
CursorMan.getPosition(x, y);
Expand Down
6 changes: 6 additions & 0 deletions src/engines/nwn/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace NWN {
class Area;
class Object;

class GUI;

class Module : public Aurora::NWScript::Object, public Aurora::NWScript::ObjectContainer {
public:
Module();
Expand Down Expand Up @@ -87,6 +89,8 @@ class Module : public Aurora::NWScript::Object, public Aurora::NWScript::ObjectC

IFOFile _ifo; ///< The module's IFO.

GUI *_menu; ///< The ingame main menu.

// Texture pack
int _currentTexturePack;
Aurora::ResourceManager::ChangeID _resTP[4];
Expand Down Expand Up @@ -127,6 +131,8 @@ class Module : public Aurora::NWScript::Object, public Aurora::NWScript::ObjectC
bool handlePicker(const Events::Event &e);
bool handleKeys(const Events::Event &e);

void showMenu();

void checkCurrentObject();
};

Expand Down

0 comments on commit 4b267c2

Please sign in to comment.