MM: MM1: Creating base class for views that allow switching character

This commit is contained in:
Paul Gilbert 2023-02-19 22:07:41 -08:00
parent 70b65410e4
commit 3792c23854
9 changed files with 158 additions and 37 deletions

View File

@ -176,6 +176,11 @@ public:
int getRandomNumber(int minNumber, int maxNumber);
int getRandomNumber(int maxNumber);
/**
* Gets the element's name
*/
Common::String getName() const { return _name; }
/**
* Sets the element's bounds
*/

View File

@ -71,21 +71,6 @@ bool Game::msgAction(const ActionMessage &msg) {
case KEYBIND_SPELL:
addView("CastSpell");
return true;
case KEYBIND_VIEW_PARTY1:
case KEYBIND_VIEW_PARTY2:
case KEYBIND_VIEW_PARTY3:
case KEYBIND_VIEW_PARTY4:
case KEYBIND_VIEW_PARTY5:
case KEYBIND_VIEW_PARTY6:
{
uint charNum = msg._action - KEYBIND_VIEW_PARTY1;
if (charNum < g_globals->_party.size()) {
g_globals->_currCharacter = &g_globals->_party[charNum];
addView("CharacterInfo");
}
return true;
}
default:
break;
}

View File

@ -19,7 +19,7 @@
*
*/
#include "mm/mm1/views_enh/game_party.h"
#include "mm/mm1/views_enh/game.h"
#include "mm/mm1/events.h"
#include "mm/mm1/globals.h"
@ -31,13 +31,13 @@ static const byte CONDITION_COLORS[17] = {
9, 9, 9, 9, 9, 9, 9, 9, 32, 32, 32, 32, 6, 6, 6, 6, 15
};
const byte FACE_CONDITION_FRAMES[17] = {
static const byte FACE_CONDITION_FRAMES[17] = {
2, 2, 2, 1, 1, 4, 4, 4, 3, 2, 4, 3, 3, 5, 6, 7, 0
};
const byte CHAR_FACES_X[6] = { 10, 45, 81, 117, 153, 189 };
static const byte CHAR_FACES_X[6] = { 10, 45, 81, 117, 153, 189 };
const byte HP_BARS_X[6] = { 13, 50, 86, 122, 158, 194 };
static const byte HP_BARS_X[6] = { 13, 50, 86, 122, 158, 194 };
GameParty::GameParty(UIElement *owner) : TextView("GameParty", owner),
_restoreSprites("restorex.icn"),
@ -106,6 +106,43 @@ bool GameParty::msgGame(const GameMessage &msg) {
return false;
}
bool GameParty::msgMouseDown(const MouseDownMessage &msg) {
for (uint i = 0; i < g_globals->_party.size(); ++i) {
const Common::Rect r(CHAR_FACES_X[i], 150, CHAR_FACES_X[i] + 30, 180);
if (r.contains(msg._pos)) {
msgAction(ActionMessage((KeybindingAction)(KEYBIND_VIEW_PARTY1 + i)));
return true;
}
}
return false;
}
bool GameParty::msgAction(const ActionMessage &msg) {
if (msg._action >= KEYBIND_VIEW_PARTY1 &&
msg._action <= KEYBIND_VIEW_PARTY6) {
uint charNum = msg._action - KEYBIND_VIEW_PARTY1;
if (charNum < g_globals->_party.size()) {
// Change the selected character
g_globals->_currCharacter = &g_globals->_party[charNum];
_highlightOn = true;
draw();
if (dynamic_cast<ViewsEnh::Game *>(g_events->focusedView()) != nullptr) {
// Open character info dialog
addView("CharacterInfo");
} else {
// Another view is focused, so simply call it to update
send(g_events->focusedView()->getName(), GameMessage("UPDATE"));
}
return true;
}
}
return false;
}
} // namespace ViewsEnh
} // namespace MM1

View File

@ -52,6 +52,10 @@ public:
* Handle game messages
*/
bool msgGame(const GameMessage &msg) override;
bool msgMouseDown(const MouseDownMessage &msg) override;
bool msgAction(const ActionMessage &msg) override;
};
} // namespace ViewsEnh

View File

@ -0,0 +1,56 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "mm/mm1/views_enh/party_view.h"
#include "mm/mm1/views_enh/game_party.h"
#include "mm/mm1/events.h"
#include "mm/mm1/globals.h"
#include "mm/mm1/mm1.h"
namespace MM {
namespace MM1 {
namespace ViewsEnh {
bool PartyView::msgFocus(const FocusMessage &msg) {
// Turn on highlight for selected character
if (!g_globals->_currCharacter)
g_globals->_currCharacter = &g_globals->_party[0];
g_events->send(GameMessage("CHAR_HIGHLIGHT", (int)true));
MetaEngine::setKeybindingMode(KeybindingMode::KBMODE_PARTY_MENUS);
return true;
}
bool PartyView::msgUnfocus(const UnfocusMessage &msg) {
// Turn off highlight for selected character
g_events->send(GameMessage("CHAR_HIGHLIGHT", (int)false));
MetaEngine::setKeybindingMode(KeybindingMode::KBMODE_MENUS);
return true;
}
bool PartyView::msgMouseDown(const MouseDownMessage &msg) {
return send("GameParty", msg);
}
} // namespace ViewsEnh
} // namespace MM1
} // namespace MM

View File

@ -0,0 +1,47 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef MM1_VIEWS_ENH_PARTY_VIEW_H
#define MM1_VIEWS_ENH_PARTY_VIEW_H
#include "mm/mm1/views_enh/scroll_view.h"
namespace MM {
namespace MM1 {
namespace ViewsEnh {
class PartyView : public ScrollView {
public:
PartyView(const Common::String &name) : ScrollView(name) {}
PartyView(const Common::String &name, UIElement *owner) :
ScrollView(name, owner) {}
virtual ~PartyView() {}
bool msgFocus(const FocusMessage &msg) override;
bool msgUnfocus(const UnfocusMessage &msg) override;
bool msgMouseDown(const MouseDownMessage &msg) override;
};
} // namespace ViewsEnh
} // namespace MM1
} // namespace MM
#endif

View File

@ -27,7 +27,7 @@ namespace MM1 {
namespace ViewsEnh {
namespace Spells {
CastSpell::CastSpell() : ScrollView("CastSpell") {
CastSpell::CastSpell() : PartyView("CastSpell") {
_bounds = Common::Rect(225, 0, 320, 146);
_icons.load("cast.icn");
@ -39,21 +39,8 @@ CastSpell::CastSpell() : ScrollView("CastSpell") {
}
bool CastSpell::msgFocus(const FocusMessage &msg) {
// Turn on highlight for selected character
if (!g_globals->_currCharacter)
g_globals->_currCharacter = &g_globals->_party[0];
(void)PartyView::msgFocus(msg);
updateSelectedSpell();
g_events->send(GameMessage("CHAR_HIGHLIGHT", (int)true));
MetaEngine::setKeybindingMode(KeybindingMode::KBMODE_PARTY_MENUS);
return true;
}
bool CastSpell::msgUnfocus(const UnfocusMessage &msg) {
// Turn off highlight for selected character
g_events->send(GameMessage("CHAR_HIGHLIGHT", (int)false));
MetaEngine::setKeybindingMode(KeybindingMode::KBMODE_MENUS);
return true;
}

View File

@ -24,7 +24,7 @@
#include "mm/mm1/messages.h"
#include "mm/mm1/game/spell_casting.h"
#include "mm/mm1/views_enh/scroll_view.h"
#include "mm/mm1/views_enh/party_view.h"
namespace MM {
namespace MM1 {
@ -34,7 +34,7 @@ namespace Spells {
/**
* Dialog for casting a spell
*/
class CastSpell : public ScrollView, public MM1::Game::SpellCasting {
class CastSpell : public PartyView, public MM1::Game::SpellCasting {
private:
Shared::Xeen::SpriteResource _icons;
@ -49,7 +49,6 @@ public:
void draw() override;
bool msgFocus(const FocusMessage &msg) override;
bool msgUnfocus(const UnfocusMessage &msg) override;
bool msgKeypress(const KeypressMessage &msg) override;
bool msgAction(const ActionMessage &msg) override;
bool msgGame(const GameMessage &msg) override;

View File

@ -131,6 +131,7 @@ MODULE_OBJS += \
mm1/views_enh/main_menu.o \
mm1/views_enh/map.o \
mm1/views_enh/map_popup.o \
mm1/views_enh/party_view.o \
mm1/views_enh/quick_ref.o \
mm1/views_enh/scroll_popup.o \
mm1/views_enh/scroll_text.o \