mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-13 07:14:59 +00:00
AGS: small refactor of key code variables (stricter names, types)
From upstream e04c8ff1fe77e4462babd21d2a103a12e68b4b84
This commit is contained in:
parent
e2497cff42
commit
0927821afd
@ -820,12 +820,12 @@ bool DialogOptions::Run() {
|
||||
|
||||
KeyInput ki;
|
||||
if (run_service_key_controls(ki) && !_GP(play).IsIgnoringInput()) {
|
||||
eAGSKeyCode gkey = ki.Key;
|
||||
const eAGSKeyCode agskey = ki.Key;
|
||||
if (parserInput) {
|
||||
wantRefresh = true;
|
||||
// type into the parser
|
||||
// TODO: find out what are these key commands, and are these documented?
|
||||
if ((gkey == eAGSKeyCodeF3) || ((gkey == eAGSKeyCodeSpace) && (parserInput->Text.GetLength() == 0))) {
|
||||
if ((agskey == eAGSKeyCodeF3) || ((agskey == eAGSKeyCodeSpace) && (parserInput->Text.GetLength() == 0))) {
|
||||
// write previous contents into textbox (F3 or Space when box is empty)
|
||||
size_t last_len = ustrlen(_GP(play).lastParserEntry);
|
||||
size_t cur_len = ustrlen(parserInput->Text.GetCStr());
|
||||
@ -841,7 +841,7 @@ bool DialogOptions::Run() {
|
||||
//ags_domouse(DOMOUSE_DISABLE);
|
||||
Redraw();
|
||||
return true; // continue running loop
|
||||
} else if ((gkey >= eAGSKeyCodeSpace) || (gkey == eAGSKeyCodeReturn) || (gkey == eAGSKeyCodeBackspace)) {
|
||||
} else if ((agskey >= eAGSKeyCodeSpace) || (agskey == eAGSKeyCodeReturn) || (agskey == eAGSKeyCodeBackspace)) {
|
||||
parserInput->OnKeyPress(ki);
|
||||
if (!parserInput->IsActivated) {
|
||||
//ags_domouse(DOMOUSE_DISABLE);
|
||||
@ -853,7 +853,7 @@ bool DialogOptions::Run() {
|
||||
if (old_keyhandle || (ki.UChar == 0)) {
|
||||
// "dialog_options_key_press"
|
||||
_GP(runDialogOptionKeyPressHandlerFunc).params[0].SetDynamicObject(&_GP(ccDialogOptionsRendering), &_GP(ccDialogOptionsRendering));
|
||||
_GP(runDialogOptionKeyPressHandlerFunc).params[1].SetInt32(AGSKeyToScriptKey(gkey));
|
||||
_GP(runDialogOptionKeyPressHandlerFunc).params[1].SetInt32(AGSKeyToScriptKey(ki.Key));
|
||||
_GP(runDialogOptionKeyPressHandlerFunc).params[2].SetInt32(ki.Mod);
|
||||
run_function_on_non_blocking_thread(&_GP(runDialogOptionKeyPressHandlerFunc));
|
||||
}
|
||||
@ -866,8 +866,8 @@ bool DialogOptions::Run() {
|
||||
}
|
||||
// Allow selection of options by keyboard shortcuts
|
||||
else if (_GP(game).options[OPT_DIALOGNUMBERED] >= kDlgOptKeysOnly &&
|
||||
gkey >= '1' && gkey <= '9') {
|
||||
int numkey = gkey - '1';
|
||||
agskey >= '1' && agskey <= '9') {
|
||||
int numkey = agskey - '1';
|
||||
if (numkey < numdisp) {
|
||||
chose = disporder[numkey];
|
||||
return false; // end dialog options running loop
|
||||
|
@ -346,8 +346,8 @@ bool InventoryScreen::Run() {
|
||||
// Run() can be called in a loop, so keep events going.
|
||||
sys_evt_process_pending();
|
||||
|
||||
KeyInput kgn;
|
||||
if (run_service_key_controls(kgn) && !_GP(play).IsIgnoringInput()) {
|
||||
KeyInput ki;
|
||||
if (run_service_key_controls(ki) && !_GP(play).IsIgnoringInput()) {
|
||||
return false; // end inventory screen loop
|
||||
}
|
||||
|
||||
|
@ -323,7 +323,7 @@ bool run_service_key_controls(KeyInput &out_key) {
|
||||
}
|
||||
|
||||
// Alt+X, abort (but only once game is loaded)
|
||||
if ((_G(displayed_room) >= 0) && (_GP(play).abort_key > 0 && agskey == _GP(play).abort_key)) {
|
||||
if ((_G(displayed_room) >= 0) && (agskey == _GP(play).abort_key)) {
|
||||
Debug::Printf("Abort key pressed");
|
||||
_G(check_dynamic_sprites_at_exit) = 0;
|
||||
quit("!|");
|
||||
@ -417,9 +417,9 @@ static void check_keyboard_controls() {
|
||||
if (!run_service_key_controls(ki)) {
|
||||
return;
|
||||
}
|
||||
eAGSKeyCode kgn = ki.Key;
|
||||
const eAGSKeyCode agskey = ki.Key;
|
||||
// Then, check cutscene skip
|
||||
check_skip_cutscene_keypress(kgn);
|
||||
check_skip_cutscene_keypress(agskey);
|
||||
if (_GP(play).fast_forward) {
|
||||
return;
|
||||
}
|
||||
@ -427,9 +427,9 @@ static void check_keyboard_controls() {
|
||||
return;
|
||||
}
|
||||
// Now check for in-game controls
|
||||
if (pl_run_plugin_hooks(AGSE_KEYPRESS, kgn)) {
|
||||
if (pl_run_plugin_hooks(AGSE_KEYPRESS, agskey)) {
|
||||
// plugin took the keypress
|
||||
debug_script_log("Keypress code %d taken by plugin", kgn);
|
||||
debug_script_log("Keypress code %d taken by plugin", agskey);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -438,9 +438,8 @@ static void check_keyboard_controls() {
|
||||
// only allow a key to remove the overlay if the icon bar isn't up
|
||||
if (IsGamePaused() == 0) {
|
||||
// check if it requires a specific keypress
|
||||
if ((_GP(play).skip_speech_specific_key > 0) &&
|
||||
(kgn != _GP(play).skip_speech_specific_key)) {
|
||||
} else {
|
||||
if ((_GP(play).skip_speech_specific_key == 0) ||
|
||||
(agskey == _GP(play).skip_speech_specific_key)) {
|
||||
remove_screen_overlay(_GP(play).text_overlay_on);
|
||||
_GP(play).SetWaitKeySkip(ki);
|
||||
}
|
||||
@ -456,7 +455,7 @@ static void check_keyboard_controls() {
|
||||
|
||||
if (_G(inside_script)) {
|
||||
// Don't queue up another keypress if it can't be run instantly
|
||||
debug_script_log("Keypress %d ignored (game blocked)", kgn);
|
||||
debug_script_log("Keypress %d ignored (game blocked)", agskey);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -466,8 +465,9 @@ static void check_keyboard_controls() {
|
||||
// it should do if a displayable character (32-255) is
|
||||
// pressed, but exclude control characters (<32) and
|
||||
// extended keys (eg. up/down arrow; 256+)
|
||||
if ((((kgn >= 32) && (kgn <= 255) && (kgn != '[')) || (kgn == eAGSKeyCodeReturn) || (kgn == eAGSKeyCodeBackspace))
|
||||
&& (_G(all_buttons_disabled) < 0)) {
|
||||
if ( (((agskey >= 32) && (agskey <= 255) && (agskey != '[')) ||
|
||||
(agskey == eAGSKeyCodeReturn) || (agskey == eAGSKeyCodeBackspace))
|
||||
&& (_G(all_buttons_disabled) < 0)) {
|
||||
for (int guiIndex = 0; guiIndex < _GP(game).numgui; guiIndex++) {
|
||||
auto &gui = _GP(guis)[guiIndex];
|
||||
|
||||
@ -505,17 +505,17 @@ static void check_keyboard_controls() {
|
||||
}
|
||||
|
||||
// Built-in key-presses
|
||||
if (kgn == _GP(usetup).key_save_game) {
|
||||
if (agskey == _GP(usetup).key_save_game) {
|
||||
do_save_game_dialog();
|
||||
return;
|
||||
} else if (kgn == _GP(usetup).key_restore_game) {
|
||||
} else if (agskey == _GP(usetup).key_restore_game) {
|
||||
do_restore_game_dialog();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!keywasprocessed) {
|
||||
int sckey = AGSKeyToScriptKey(kgn);
|
||||
int sckeymod = ki.Mod;
|
||||
const int sckey = AGSKeyToScriptKey(ki.Key);
|
||||
const int sckeymod = ki.Mod;
|
||||
if (old_keyhandle || (ki.UChar == 0)) {
|
||||
debug_script_log("Running on_key_press keycode %d, mod %d", sckey, sckeymod);
|
||||
setevent(EV_TEXTSCRIPT, TS_KEYPRESS, sckey, sckeymod);
|
||||
|
@ -23,12 +23,13 @@
|
||||
|
||||
namespace AGS3 {
|
||||
|
||||
int AGSKeyToScriptKey(int keycode) {
|
||||
eAGSKeyCode AGSKeyToScriptKey(eAGSKeyCode keycode) {
|
||||
// Script API requires strictly capital letters, if this is a small letter - capitalize it
|
||||
return (keycode >= 'a' && keycode <= 'z') ? keycode - 'a' + 'A' : keycode;
|
||||
return (keycode >= 'a' && keycode <= 'z') ?
|
||||
static_cast<eAGSKeyCode>(keycode - 'a' + 'A') : keycode;
|
||||
}
|
||||
|
||||
char AGSKeyToText(int keycode) {
|
||||
char AGSKeyToText(eAGSKeyCode keycode) {
|
||||
// support only printable characters (128-255 are chars from extended fonts)
|
||||
if (keycode >= 32 && keycode < 256)
|
||||
return static_cast<char>(keycode);
|
||||
|
@ -297,10 +297,10 @@ enum eAGSMouseButton
|
||||
};
|
||||
|
||||
// Converts eAGSKeyCode to script API code, for "on_key_press" and similar callbacks
|
||||
int AGSKeyToScriptKey(int keycode);
|
||||
eAGSKeyCode AGSKeyToScriptKey(eAGSKeyCode keycode);
|
||||
// Converts eAGSKeyCode to ASCII text representation with the range check; returns 0 on failure
|
||||
// Not unicode compatible.
|
||||
char AGSKeyToText(int keycode);
|
||||
char AGSKeyToText(eAGSKeyCode keycode);
|
||||
|
||||
} // namespace AGS3
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user