MM: MM1: Adding a Select keybinding action

This commit is contained in:
Paul Gilbert 2023-02-07 22:33:23 -08:00
parent dd0f31ada1
commit 03895d242e
7 changed files with 74 additions and 27 deletions

View File

@ -38,6 +38,7 @@ struct KeybindingRecord {
static const KeybindingRecord MENU_KEYS[] = {
{ KEYBIND_ESCAPE, "ESCAPE", "Escape", "ESCAPE", nullptr },
{ KEYBIND_SELECT, "SELECT", "Select", "RETURN", nullptr },
{ KEYBIND_NONE, nullptr, nullptr, nullptr, nullptr }
};

View File

@ -29,6 +29,7 @@ namespace MM1 {
enum KeybindingAction {
KEYBIND_ESCAPE,
KEYBIND_SELECT,
KEYBIND_FORWARDS,
KEYBIND_BACKWARDS,

View File

@ -32,8 +32,8 @@ void AreYouReady::draw() {
writeString(11, 13, STRING["dialogs.ready.2"]);
}
bool AreYouReady::msgKeypress(const KeypressMessage &msg) {
if (msg.keycode == Common::KEYCODE_RETURN) {
bool AreYouReady::msgAction(const ActionMessage &msg) {
if (msg._action == KEYBIND_SELECT) {
replaceView("MainMenu");
return true;
}

View File

@ -34,7 +34,7 @@ public:
virtual ~AreYouReady() {}
void draw() override;
bool msgKeypress(const KeypressMessage &msg) override;
bool msgAction(const ActionMessage &msg) override;
};
} // namespace Views

View File

@ -345,11 +345,7 @@ void CreateCharacters::printSummary(bool promptToSave) {
bool CreateCharacters::msgKeypress(const KeypressMessage &msg) {
switch (_state) {
case SELECT_CLASS:
if (msg.keycode == Common::KEYCODE_RETURN) {
// Re-roll attributes
_newChar.reroll();
redraw();
} else if (msg.keycode >= Common::KEYCODE_1 &&
if (msg.keycode >= Common::KEYCODE_1 &&
msg.keycode <= Common::KEYCODE_6) {
if (_newChar._classesAllowed[msg.keycode - Common::KEYCODE_0] &&
!g_globals->_roster.full()) {
@ -426,7 +422,7 @@ bool CreateCharacters::msgKeypress(const KeypressMessage &msg) {
_newChar._name += toupper(msg.ascii);
redraw();
}
if (msg.keycode == Common::KEYCODE_RETURN || _newChar._name.size() == 15) {
if (_newChar._name.size() == 15) {
_state = SAVE_PROMPT;
redraw();
} else if (msg.keycode == Common::KEYCODE_BACKSPACE &&
@ -450,7 +446,8 @@ bool CreateCharacters::msgKeypress(const KeypressMessage &msg) {
}
bool CreateCharacters::msgAction(const ActionMessage &msg) {
if (msg._action == KEYBIND_ESCAPE) {
switch (msg._action) {
case KEYBIND_ESCAPE:
if (_state == SELECT_CLASS) {
close();
} else {
@ -459,6 +456,32 @@ bool CreateCharacters::msgAction(const ActionMessage &msg) {
redraw();
}
return true;
case KEYBIND_SELECT:
switch (_state) {
case SELECT_CLASS:
// Re-roll attributes
_newChar.reroll();
redraw();
break;
case SELECT_NAME:
_state = SAVE_PROMPT;
redraw();
break;
case SAVE_PROMPT:
_newChar.save();
_state = SELECT_CLASS;
_newChar.reroll();
redraw();
break;
default:
break;
}
return true;
default:
break;
}
return false;

View File

@ -121,30 +121,46 @@ bool Inn::msgKeypress(const KeypressMessage &msg) {
g_globals->_currCharacter = &g_globals->_roster[charNum];
_characterView.addView();
}
return true;
} else if (msg.keycode == Common::KEYCODE_x) {
// Load party from selected characters
g_globals->_party.clear();
for (uint i = 0; i < _partyChars.size(); ++i)
g_globals->_party.push_back(
g_globals->_roster[_partyChars[i]]);
g_globals->_currCharacter = &g_globals->_party.front();
// Load the given town
g_globals->_maps.loadTown(g_globals->_startingTown);
}
return false;
}
bool Inn::msgAction(const ActionMessage &msg) {
if (msg._action == KEYBIND_ESCAPE) {
replaceView("MainMenu");
exitInn();
return true;
}
return false;
}
bool Inn::msgAction(const ActionMessage &msg) {
switch (msg._action) {
case KEYBIND_ESCAPE:
replaceView("MainMenu");
return true;
case KEYBIND_SELECT:
exitInn();
return true;
default:
break;
}
return false;
}
void Inn::exitInn() {
if (_partyChars.empty())
return;
// Load party from selected characters
g_globals->_party.clear();
for (uint i = 0; i < _partyChars.size(); ++i)
g_globals->_party.push_back(
g_globals->_roster[_partyChars[i]]);
g_globals->_currCharacter = &g_globals->_party.front();
// Load the given town
g_globals->_maps.loadTown(g_globals->_startingTown);
}
} // namespace Locations
} // namespace Views
} // namespace MM1

View File

@ -36,6 +36,12 @@ private:
CharacterView _characterView;
Common::Array<uint> _charNums;
IntArray _partyChars;
/**
* Exit the Inn
*/
void exitInn();
public:
Inn() : TextView("Inn") {
}