Skip to content

Commit

Permalink
SHERLOCK: SS: Make load/save menu multilingual
Browse files Browse the repository at this point in the history
Also change behavior of makeButton/buttonPrint to directly
remove a hotkey-prefix, in case it was passed.
  • Loading branch information
Martin Kiewitz committed Jan 30, 2016
1 parent dc3c3a8 commit 741b868
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 121 deletions.
33 changes: 33 additions & 0 deletions engines/sherlock/scalpel/scalpel_fixed_text.cpp
Expand Up @@ -76,6 +76,17 @@ static const char *const fixedTextEN[] = {
"FFade Directly",
"KKey Pad Slow",
"KKey Pad Fast",
// Load/Save
"EExit",
"LLoad",
"SSave",
"UUp",
"DDown",
"QQuit",
// Quit Game
"Are you sure you wish to Quit ?",
"YYes",
"NNo",
// SH1: Press key text
"Press any Key for More.",
"P",
Expand Down Expand Up @@ -210,6 +221,17 @@ static const char *const fixedTextDE[] = {
"BBlende",
"CCursor langsam",
"CCursor schnell",
// Load/Save
"ZZur\201ck",
"LLaden",
"SSichern",
"HHoch",
"RRunter",
"EEnde",
// Quit Game
"Das Spiel verlassen ?",
"JJa",
"NNein",
// SH1: Press key text
"Mehr auf Tastendruck...",
"M",
Expand Down Expand Up @@ -343,6 +365,17 @@ static const char *const fixedTextES[] = {
"FFundido directo",
"eTeclado lento",
"eTeclado rapido",
// Load/Save
"aSalir", // original interpreter: "Exit"
"CCargar",
"GGrabar",
"SSubir",
"BBajar",
"AAcabar",
// Quit Game
"\250Seguro que quieres Acabar?",
"SSi",
"NNo",
// SH1: Press key text
"Tecla para ver mas",
"T",
Expand Down
11 changes: 11 additions & 0 deletions engines/sherlock/scalpel/scalpel_fixed_text.h
Expand Up @@ -78,6 +78,17 @@ enum FixedTextId {
kFixedText_Settings_FadeDirectly,
kFixedText_Settings_KeyPadSlow,
kFixedText_Settings_KeyPadFast,
// Load/Save
kFixedText_LoadSave_Exit,
kFixedText_LoadSave_Load,
kFixedText_LoadSave_Save,
kFixedText_LoadSave_Up,
kFixedText_LoadSave_Down,
kFixedText_LoadSave_Quit,
// Quit Game
kFixedText_QuitGame_Question,
kFixedText_QuitGame_Yes,
kFixedText_QuitGame_No,
// Press key text
kFixedText_PressKey_ForMore,
kFixedText_PressKey_ForMoreHotkey,
Expand Down
89 changes: 63 additions & 26 deletions engines/sherlock/scalpel/scalpel_saveload.cpp
Expand Up @@ -20,6 +20,7 @@
*
*/

#include "sherlock/scalpel/scalpel_fixed_text.h"
#include "sherlock/scalpel/scalpel_saveload.h"
#include "sherlock/scalpel/scalpel_screen.h"
#include "sherlock/scalpel/scalpel.h"
Expand All @@ -41,6 +42,42 @@ const int ENV_POINTS[6][3] = {

ScalpelSaveManager::ScalpelSaveManager(SherlockEngine *vm, const Common::String &target) :
SaveManager(vm, target), _envMode(SAVEMODE_NONE) {

_fixedTextExit = FIXED(LoadSave_Exit);
_fixedTextLoad = FIXED(LoadSave_Load);
_fixedTextSave = FIXED(LoadSave_Save);
_fixedTextUp = FIXED(LoadSave_Up);
_fixedTextDown = FIXED(LoadSave_Down);
_fixedTextQuit = FIXED(LoadSave_Quit);

_hotkeyExit = toupper(_fixedTextExit[0]);
_hotkeyLoad = toupper(_fixedTextLoad[0]);
_hotkeySave = toupper(_fixedTextSave[0]);
_hotkeyUp = toupper(_fixedTextUp[0]);
_hotkeyDown = toupper(_fixedTextDown[0]);
_hotkeyQuit = toupper(_fixedTextQuit[0]);

_hotkeysIndexed[0] = _hotkeyExit;
_hotkeysIndexed[1] = _hotkeyLoad;
_hotkeysIndexed[2] = _hotkeySave;
_hotkeysIndexed[3] = _hotkeyUp;
_hotkeysIndexed[4] = _hotkeyDown;
_hotkeysIndexed[5] = _hotkeyQuit;

_fixedTextQuitGameQuestion = FIXED(QuitGame_Question);
_fixedTextQuitGameYes = FIXED(QuitGame_Yes);
_fixedTextQuitGameNo = FIXED(QuitGame_No);

_hotkeyQuitGameYes = toupper(_fixedTextQuitGameYes[0]);
_hotkeyQuitGameNo = toupper(_fixedTextQuitGameNo[0]);
}

int ScalpelSaveManager::identifyUserButton(int key) {
for (uint16 hotkeyNr = 0; hotkeyNr < sizeof(_hotkeysIndexed); hotkeyNr++) {
if (key == _hotkeysIndexed[hotkeyNr])
return hotkeyNr;
}
return -1;
}

void ScalpelSaveManager::drawInterface() {
Expand All @@ -57,23 +94,23 @@ void ScalpelSaveManager::drawInterface() {
screen._backBuffer1.fillRect(Common::Rect(2, CONTROLS_Y + 10, SHERLOCK_SCREEN_WIDTH - 2, SHERLOCK_SCREEN_HEIGHT - 2), INV_BACKGROUND);

screen.makeButton(Common::Rect(ENV_POINTS[0][0], CONTROLS_Y, ENV_POINTS[0][1], CONTROLS_Y + 10),
ENV_POINTS[0][2], "Exit");
ENV_POINTS[0][2], _fixedTextExit, true);
screen.makeButton(Common::Rect(ENV_POINTS[1][0], CONTROLS_Y, ENV_POINTS[1][1], CONTROLS_Y + 10),
ENV_POINTS[1][2], "Load");
ENV_POINTS[1][2], _fixedTextLoad, true);
screen.makeButton(Common::Rect(ENV_POINTS[2][0], CONTROLS_Y, ENV_POINTS[2][1], CONTROLS_Y + 10),
ENV_POINTS[2][2], "Save");
ENV_POINTS[2][2], _fixedTextSave, true);
screen.makeButton(Common::Rect(ENV_POINTS[3][0], CONTROLS_Y, ENV_POINTS[3][1], CONTROLS_Y + 10),
ENV_POINTS[3][2], "Up");
ENV_POINTS[3][2], _fixedTextUp, true);
screen.makeButton(Common::Rect(ENV_POINTS[4][0], CONTROLS_Y, ENV_POINTS[4][1], CONTROLS_Y + 10),
ENV_POINTS[4][2], "Down");
ENV_POINTS[4][2], _fixedTextDown, true);
screen.makeButton(Common::Rect(ENV_POINTS[5][0], CONTROLS_Y, ENV_POINTS[5][1], CONTROLS_Y + 10),
ENV_POINTS[5][2], "Quit");
ENV_POINTS[5][2], _fixedTextQuit, true);

if (!_savegameIndex)
screen.buttonPrint(Common::Point(ENV_POINTS[3][2], CONTROLS_Y), COMMAND_NULL, 0, "Up");
screen.buttonPrint(Common::Point(ENV_POINTS[3][2], CONTROLS_Y), COMMAND_NULL, 0, _fixedTextUp, true);

if (_savegameIndex == MAX_SAVEGAME_SLOTS - ONSCREEN_FILES_COUNT)
screen.buttonPrint(Common::Point(ENV_POINTS[4][2], CONTROLS_Y), COMMAND_NULL, 0, "Down");
screen.buttonPrint(Common::Point(ENV_POINTS[4][2], CONTROLS_Y), COMMAND_NULL, 0, _fixedTextDown, true);

for (int idx = _savegameIndex; idx < _savegameIndex + ONSCREEN_FILES_COUNT; ++idx) {
screen.gPrint(Common::Point(6, CONTROLS_Y + 11 + (idx - _savegameIndex) * 10),
Expand Down Expand Up @@ -107,31 +144,31 @@ void ScalpelSaveManager::highlightButtons(int btnIndex) {
ScalpelScreen &screen = *(ScalpelScreen *)_vm->_screen;
byte color = (btnIndex == 0) ? COMMAND_HIGHLIGHTED : COMMAND_FOREGROUND;

screen.buttonPrint(Common::Point(ENV_POINTS[0][2], CONTROLS_Y), color, 1, "Exit");
screen.buttonPrint(Common::Point(ENV_POINTS[0][2], CONTROLS_Y), color, 1, _fixedTextExit, true);

if ((btnIndex == 1) || ((_envMode == SAVEMODE_LOAD) && (btnIndex != 2)))
screen.buttonPrint(Common::Point(ENV_POINTS[1][2], CONTROLS_Y), COMMAND_HIGHLIGHTED, true, "Load");
screen.buttonPrint(Common::Point(ENV_POINTS[1][2], CONTROLS_Y), COMMAND_HIGHLIGHTED, true, _fixedTextLoad, true);
else
screen.buttonPrint(Common::Point(ENV_POINTS[1][2], CONTROLS_Y), COMMAND_FOREGROUND, true, "Load");
screen.buttonPrint(Common::Point(ENV_POINTS[1][2], CONTROLS_Y), COMMAND_FOREGROUND, true, _fixedTextLoad, true);

if ((btnIndex == 2) || ((_envMode == SAVEMODE_SAVE) && (btnIndex != 1)))
screen.buttonPrint(Common::Point(ENV_POINTS[2][2], CONTROLS_Y), COMMAND_HIGHLIGHTED, true, "Save");
screen.buttonPrint(Common::Point(ENV_POINTS[2][2], CONTROLS_Y), COMMAND_HIGHLIGHTED, true, _fixedTextSave, true);
else
screen.buttonPrint(Common::Point(ENV_POINTS[2][2], CONTROLS_Y), COMMAND_FOREGROUND, true, "Save");
screen.buttonPrint(Common::Point(ENV_POINTS[2][2], CONTROLS_Y), COMMAND_FOREGROUND, true, _fixedTextSave, true);

if (btnIndex == 3 && _savegameIndex)
screen.buttonPrint(Common::Point(ENV_POINTS[3][2], CONTROLS_Y), COMMAND_HIGHLIGHTED, true, "Up");
screen.buttonPrint(Common::Point(ENV_POINTS[3][2], CONTROLS_Y), COMMAND_HIGHLIGHTED, true, _fixedTextUp, true);
else
if (_savegameIndex)
screen.buttonPrint(Common::Point(ENV_POINTS[3][2], CONTROLS_Y), COMMAND_FOREGROUND, true, "Up");
screen.buttonPrint(Common::Point(ENV_POINTS[3][2], CONTROLS_Y), COMMAND_FOREGROUND, true, _fixedTextUp, true);

if ((btnIndex == 4) && (_savegameIndex < MAX_SAVEGAME_SLOTS - 5))
screen.buttonPrint(Common::Point(ENV_POINTS[4][2], CONTROLS_Y), COMMAND_HIGHLIGHTED, true, "Down");
screen.buttonPrint(Common::Point(ENV_POINTS[4][2], CONTROLS_Y), COMMAND_HIGHLIGHTED, true, _fixedTextDown, true);
else if (_savegameIndex < (MAX_SAVEGAME_SLOTS - 5))
screen.buttonPrint(Common::Point(ENV_POINTS[4][2], CONTROLS_Y), COMMAND_FOREGROUND, true, "Down");
screen.buttonPrint(Common::Point(ENV_POINTS[4][2], CONTROLS_Y), COMMAND_FOREGROUND, true, _fixedTextDown, true);

color = (btnIndex == 5) ? COMMAND_HIGHLIGHTED : COMMAND_FOREGROUND;
screen.buttonPrint(Common::Point(ENV_POINTS[5][2], CONTROLS_Y), color, 1, "Quit");
screen.buttonPrint(Common::Point(ENV_POINTS[5][2], CONTROLS_Y), color, 1, _fixedTextQuit, true);
}

bool ScalpelSaveManager::checkGameOnScreen(int slot) {
Expand All @@ -154,10 +191,10 @@ bool ScalpelSaveManager::checkGameOnScreen(int slot) {
screen.slamRect(Common::Rect(3, CONTROLS_Y + 11, 318, SHERLOCK_SCREEN_HEIGHT));

byte color = !_savegameIndex ? COMMAND_NULL : COMMAND_FOREGROUND;
screen.buttonPrint(Common::Point(ENV_POINTS[3][2], CONTROLS_Y), color, 1, "Up");
screen.buttonPrint(Common::Point(ENV_POINTS[3][2], CONTROLS_Y), color, 1, _fixedTextUp, true);

color = (_savegameIndex == (MAX_SAVEGAME_SLOTS - 5)) ? COMMAND_NULL : COMMAND_FOREGROUND;
screen.buttonPrint(Common::Point(ENV_POINTS[4][2], CONTROLS_Y), color, 1, "Down");
screen.buttonPrint(Common::Point(ENV_POINTS[4][2], CONTROLS_Y), color, 1, _fixedTextDown, true);

return true;
}
Expand All @@ -173,12 +210,12 @@ bool ScalpelSaveManager::promptForDescription(int slot) {
int xp, yp;
bool flag = false;

screen.buttonPrint(Common::Point(ENV_POINTS[0][2], CONTROLS_Y), COMMAND_NULL, true, "Exit");
screen.buttonPrint(Common::Point(ENV_POINTS[1][2], CONTROLS_Y), COMMAND_NULL, true, "Load");
screen.buttonPrint(Common::Point(ENV_POINTS[2][2], CONTROLS_Y), COMMAND_NULL, true, "Save");
screen.buttonPrint(Common::Point(ENV_POINTS[3][2], CONTROLS_Y), COMMAND_NULL, true, "Up");
screen.buttonPrint(Common::Point(ENV_POINTS[4][2], CONTROLS_Y), COMMAND_NULL, true, "Down");
screen.buttonPrint(Common::Point(ENV_POINTS[5][2], CONTROLS_Y), COMMAND_NULL, true, "Quit");
screen.buttonPrint(Common::Point(ENV_POINTS[0][2], CONTROLS_Y), COMMAND_NULL, true, _fixedTextExit, true);
screen.buttonPrint(Common::Point(ENV_POINTS[1][2], CONTROLS_Y), COMMAND_NULL, true, _fixedTextLoad, true);
screen.buttonPrint(Common::Point(ENV_POINTS[2][2], CONTROLS_Y), COMMAND_NULL, true, _fixedTextSave, true);
screen.buttonPrint(Common::Point(ENV_POINTS[3][2], CONTROLS_Y), COMMAND_NULL, true, _fixedTextUp, true);
screen.buttonPrint(Common::Point(ENV_POINTS[4][2], CONTROLS_Y), COMMAND_NULL, true, _fixedTextDown, true);
screen.buttonPrint(Common::Point(ENV_POINTS[5][2], CONTROLS_Y), COMMAND_NULL, true, _fixedTextQuit, true);

Common::String saveName = _savegames[slot];
if (isSlotEmpty(slot)) {
Expand Down
29 changes: 29 additions & 0 deletions engines/sherlock/scalpel/scalpel_saveload.h
Expand Up @@ -34,6 +34,30 @@ extern const int ENV_POINTS[6][3];
class ScalpelSaveManager: public SaveManager {
public:
SaveMode _envMode;

Common::String _fixedTextExit;
Common::String _fixedTextLoad;
Common::String _fixedTextSave;
Common::String _fixedTextUp;
Common::String _fixedTextDown;
Common::String _fixedTextQuit;

byte _hotkeyExit;
byte _hotkeyLoad;
byte _hotkeySave;
byte _hotkeyUp;
byte _hotkeyDown;
byte _hotkeyQuit;

byte _hotkeysIndexed[6];

Common::String _fixedTextQuitGameQuestion;
Common::String _fixedTextQuitGameYes;
Common::String _fixedTextQuitGameNo;

byte _hotkeyQuitGameYes;
byte _hotkeyQuitGameNo;

public:
ScalpelSaveManager(SherlockEngine *vm, const Common::String &target);
virtual ~ScalpelSaveManager() {}
Expand Down Expand Up @@ -62,6 +86,11 @@ class ScalpelSaveManager: public SaveManager {
* Prompts the user to enter a description in a given slot
*/
bool promptForDescription(int slot);

/**
* Identifies a button number according to the key, that the user pressed
*/
int identifyUserButton(int key);
};

} // End of namespace Scalpel
Expand Down
43 changes: 26 additions & 17 deletions engines/sherlock/scalpel/scalpel_screen.cpp
Expand Up @@ -31,7 +31,7 @@ ScalpelScreen::ScalpelScreen(SherlockEngine *vm) : Screen(vm) {
}

void ScalpelScreen::makeButton(const Common::Rect &bounds, int textX,
const Common::String &str, const byte hotkey) {
const Common::String &str, bool textContainsHotkey) {

Surface &bb = *_backBuffer;
bb.fillRect(Common::Rect(bounds.left, bounds.top, bounds.right, bounds.top + 1), BUTTON_TOP);
Expand All @@ -40,24 +40,33 @@ void ScalpelScreen::makeButton(const Common::Rect &bounds, int textX,
bb.fillRect(Common::Rect(bounds.left + 1, bounds.bottom - 1, bounds.right, bounds.bottom), BUTTON_BOTTOM);
bb.fillRect(Common::Rect(bounds.left + 1, bounds.top + 1, bounds.right - 1, bounds.bottom - 1), BUTTON_MIDDLE);

buttonPrint(Common::Point(textX, bounds.top), COMMAND_FOREGROUND, false, str, hotkey);
buttonPrint(Common::Point(textX, bounds.top), COMMAND_FOREGROUND, false, str, textContainsHotkey);
}

void ScalpelScreen::buttonPrint(const Common::Point &pt, uint color, bool slamIt,
const Common::String &str, byte hotkey) {
int xStart = pt.x - stringWidth(str) / 2;
const Common::String &str, bool textContainsHotkey) {
int xStart = pt.x;
int skipTextOffset = textContainsHotkey ? +1 : 0; // skip first char in case text contains hotkey

// Center text around given x-coordinate
if (textContainsHotkey) {
xStart -= (stringWidth(Common::String(str.c_str() + 1)) / 2);
} else {
xStart -= (stringWidth(str) / 2);
}

if (color == COMMAND_FOREGROUND) {
Common::String prefixText = str;
uint16 prefixOffsetX = 0;
byte hotkey = str[0];

// Hotkey needs to be highlighted
if (hotkey) {
// Hotkey was passed, we search for the hotkey inside the button text and
// remove it from there. We then draw the whole text as highlighted and afterward
// the processed text again as regular text (without the hotkey)
if (textContainsHotkey) {
Common::String prefixText = Common::String(str.c_str() + 1);
uint16 prefixTextPos = 0;

// Hotkey was passed additionally, we search for the hotkey inside the button text and
// remove it from there. We then draw the whole text as highlighted and afterward
// the processed text again as regular text (without the hotkey)
while (prefixTextPos < prefixText.size()) {
if (prefixText[prefixTextPos] == hotkey) {
// Hotkey found, remove remaining text
Expand All @@ -69,25 +78,25 @@ void ScalpelScreen::buttonPrint(const Common::Point &pt, uint color, bool slamIt
prefixTextPos++;
}

prefixOffsetX = stringWidth(prefixText);
} else {
// no hotkey passed, used first character of text
hotkey = str[0];
if (prefixTextPos < prefixText.size()) {
// only adjust in case hotkey character was actually found
prefixOffsetX = stringWidth(prefixText);
}
}

if (slamIt) {
print(Common::Point(xStart, pt.y + 1),
COMMAND_FOREGROUND, "%s", str.c_str());
COMMAND_FOREGROUND, "%s", str.c_str() + skipTextOffset);
print(Common::Point(xStart + prefixOffsetX, pt.y + 1), COMMAND_HIGHLIGHTED, "%c", hotkey);
} else {
gPrint(Common::Point(xStart, pt.y),
COMMAND_FOREGROUND, "%s", str.c_str());
COMMAND_FOREGROUND, "%s", str.c_str() + skipTextOffset);
gPrint(Common::Point(xStart + prefixOffsetX, pt.y), COMMAND_HIGHLIGHTED, "%c", hotkey);
}
} else if (slamIt) {
print(Common::Point(xStart, pt.y + 1), color, "%s", str.c_str());
print(Common::Point(xStart, pt.y + 1), color, "%s", str.c_str() + skipTextOffset);
} else {
gPrint(Common::Point(xStart, pt.y), color, "%s", str.c_str());
gPrint(Common::Point(xStart, pt.y), color, "%s", str.c_str() + skipTextOffset);
}
}

Expand Down
4 changes: 2 additions & 2 deletions engines/sherlock/scalpel/scalpel_screen.h
Expand Up @@ -39,13 +39,13 @@ class ScalpelScreen : public Screen {
/**
* Draws a button for use in the inventory, talk, and examine dialogs.
*/
void makeButton(const Common::Rect &bounds, int textX, const Common::String &str, const byte hotkey = 0);
void makeButton(const Common::Rect &bounds, int textX, const Common::String &str, bool textContainsHotkey = false);

/**
* Prints an interface command with the first letter highlighted to indicate
* what keyboard shortcut is associated with it
*/
void buttonPrint(const Common::Point &pt, uint color, bool slamIt, const Common::String &str, byte hotkey = 0);
void buttonPrint(const Common::Point &pt, uint color, bool slamIt, const Common::String &str, bool textContainsHotkey = false);

/**
* Draw a panel in the back buffer with a raised area effect around the edges
Expand Down

0 comments on commit 741b868

Please sign in to comment.