This commit is contained in:
Xeno333 2025-01-01 21:26:43 -06:00 committed by GitHub
commit 2731f84ca9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 34 additions and 2 deletions

View File

@ -2357,6 +2357,9 @@ keymap_jump (Jump key) key KEY_SPACE
# Also used for climbing down and descending in water if aux1_descends is disabled.
keymap_sneak (Sneak key) key KEY_LSHIFT
# Key for locking sneak.
keymap_sneak_lock (Sneak lock key) key
# Key for digging, punching or using something.
# (Note: The actual meaning might vary on a per-game basis.)
keymap_dig (Dig/punch/use key) key KEY_LBUTTON

View File

@ -545,6 +545,7 @@ protected:
void toggleCinematic();
void toggleBlockBounds();
void toggleAutoforward();
void toggleSneakLock();
void toggleMinimap(bool shift_pressed);
void toggleFog();
@ -1832,6 +1833,8 @@ void Game::processKeyInput()
} else if (wasKeyDown(KeyType::BACKWARD)) {
if (g_settings->getBool("continuous_forward"))
toggleAutoforward();
} else if (wasKeyDown(KeyType::SNEAK_LOCK)) {
toggleSneakLock();
} else if (wasKeyDown(KeyType::INVENTORY)) {
m_game_formspec.showPlayerInventory();
} else if (input->cancelPressed()) {
@ -2172,6 +2175,17 @@ void Game::toggleAutoforward()
m_game_ui->showTranslatedStatusText("Automatic forward disabled");
}
void Game::toggleSneakLock()
{
bool sneak_lock = !g_settings->getBool("sneak_lock");
g_settings->set("sneak_lock", bool_to_cstr(sneak_lock));
if (sneak_lock)
m_game_ui->showTranslatedStatusText("Sneak locked");
else
m_game_ui->showTranslatedStatusText("Sneak unlocked");
}
void Game::toggleMinimap(bool shift_pressed)
{
if (!mapper || !m_game_ui->m_flags.show_hud || !g_settings->getBool("enable_minimap"))
@ -2450,6 +2464,15 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
input->getJoystickSpeed(),
input->getJoystickDirection()
);
// Enable sneak lock
if (g_settings->getBool("sneak_lock")) {
if (control.sneak)
toggleSneakLock();
else
control.sneak = true;
}
control.setMovementFromKeys();
// autoforward if set: move at maximum speed
@ -3356,7 +3379,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
// formspec in meta
if (meta && !meta->getString("formspec").empty() && !input->isRandom()
&& !isKeyDown(KeyType::SNEAK)) {
&& !(isKeyDown(KeyType::SNEAK) || g_settings->getBool("sneak_lock"))) {
// on_rightclick callbacks are called anyway
if (nodedef_manager->get(map.getNode(nodepos)).rightclickable)
client->interact(INTERACT_PLACE, pointed);
@ -3367,7 +3390,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
// on_rightclick callback
if (prediction.empty() || (nodedef->get(node).rightclickable &&
!isKeyDown(KeyType::SNEAK))) {
!(isKeyDown(KeyType::SNEAK) || g_settings->getBool("sneak_lock")))) {
// Report to server
client->interact(INTERACT_PLACE, pointed);
return false;

View File

@ -26,6 +26,7 @@ void KeyCache::populate()
key[KeyType::JUMP] = getKeySetting("keymap_jump");
key[KeyType::AUX1] = getKeySetting("keymap_aux1");
key[KeyType::SNEAK] = getKeySetting("keymap_sneak");
key[KeyType::SNEAK_LOCK] = getKeySetting("keymap_sneak_lock");
key[KeyType::DIG] = getKeySetting("keymap_dig");
key[KeyType::PLACE] = getKeySetting("keymap_place");

View File

@ -19,6 +19,7 @@ public:
JUMP,
AUX1,
SNEAK,
SNEAK_LOCK,
AUTOFORWARD,
DIG,
PLACE,

View File

@ -137,6 +137,7 @@ void set_default_settings()
settings->setDefault("keymap_right", "KEY_KEY_D");
settings->setDefault("keymap_jump", "KEY_SPACE");
settings->setDefault("keymap_sneak", "KEY_LSHIFT");
settings->setDefault("keymap_sneak_lock", "");
settings->setDefault("keymap_dig", "KEY_LBUTTON");
settings->setDefault("keymap_place", "KEY_RBUTTON");
settings->setDefault("keymap_drop", "KEY_KEY_Q");
@ -232,6 +233,7 @@ void set_default_settings()
settings->setDefault("show_debug", "true");
settings->setDefault("opengl_debug", "true");
#endif
settings->setDefault("sneak_lock", "false");
settings->setDefault("fsaa", "2");
settings->setDefault("undersampling", "1");
settings->setDefault("world_aligned_mode", "enable");

View File

@ -43,6 +43,7 @@ enum
GUI_ID_KEY_CMD_LOCAL_BUTTON,
GUI_ID_KEY_CONSOLE_BUTTON,
GUI_ID_KEY_SNEAK_BUTTON,
GUI_ID_KEY_SNEAK_LOCK_BUTTON,
GUI_ID_KEY_DROP_BUTTON,
GUI_ID_KEY_INVENTORY_BUTTON,
GUI_ID_KEY_HOTBAR_PREV_BUTTON,
@ -373,6 +374,7 @@ void GUIKeyChangeMenu::init_keys()
this->add_key(GUI_ID_KEY_AUX1_BUTTON, wstrgettext("Aux1"), "keymap_aux1");
this->add_key(GUI_ID_KEY_JUMP_BUTTON, wstrgettext("Jump"), "keymap_jump");
this->add_key(GUI_ID_KEY_SNEAK_BUTTON, wstrgettext("Sneak"), "keymap_sneak");
this->add_key(GUI_ID_KEY_SNEAK_LOCK_BUTTON, wstrgettext("Sneak lock"), "keymap_sneak_lock");
this->add_key(GUI_ID_KEY_DROP_BUTTON, wstrgettext("Drop"), "keymap_drop");
this->add_key(GUI_ID_KEY_INVENTORY_BUTTON, wstrgettext("Inventory"), "keymap_inventory");
this->add_key(GUI_ID_KEY_HOTBAR_PREV_BUTTON, wstrgettext("Prev. item"), "keymap_hotbar_previous");