Skip to content

Commit 16e5b39

Browse files
authoredApr 20, 2021
Add a key to toggle map block bounds (#11172)
It's often useful to know where the map block boundaries are for doing server admin work and the like. Adds three modes: single mapblock, range of 5, and disabled.
1 parent 0077982 commit 16e5b39

File tree

8 files changed

+100
-33
lines changed

8 files changed

+100
-33
lines changed
 

‎src/client/game.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,8 @@ void Game::processKeyInput()
19321932
toggleCinematic();
19331933
} else if (wasKeyDown(KeyType::SCREENSHOT)) {
19341934
client->makeScreenshot();
1935+
} else if (wasKeyDown(KeyType::TOGGLE_BLOCK_BOUNDS)) {
1936+
hud->toggleBlockBounds();
19351937
} else if (wasKeyDown(KeyType::TOGGLE_HUD)) {
19361938
m_game_ui->toggleHud();
19371939
} else if (wasKeyDown(KeyType::MINIMAP)) {

‎src/client/hud.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,54 @@ void Hud::drawSelectionMesh()
862862
}
863863
}
864864

865+
void Hud::toggleBlockBounds()
866+
{
867+
m_block_bounds_mode = static_cast<BlockBoundsMode>(m_block_bounds_mode + 1);
868+
869+
if (m_block_bounds_mode >= BLOCK_BOUNDS_MAX) {
870+
m_block_bounds_mode = BLOCK_BOUNDS_OFF;
871+
}
872+
}
873+
874+
void Hud::drawBlockBounds()
875+
{
876+
if (m_block_bounds_mode == BLOCK_BOUNDS_OFF) {
877+
return;
878+
}
879+
880+
video::SMaterial old_material = driver->getMaterial2D();
881+
driver->setMaterial(m_selection_material);
882+
883+
v3s16 pos = player->getStandingNodePos();
884+
885+
v3s16 blockPos(
886+
floorf((float) pos.X / MAP_BLOCKSIZE),
887+
floorf((float) pos.Y / MAP_BLOCKSIZE),
888+
floorf((float) pos.Z / MAP_BLOCKSIZE)
889+
);
890+
891+
v3f offset = intToFloat(client->getCamera()->getOffset(), BS);
892+
893+
s8 radius = m_block_bounds_mode == BLOCK_BOUNDS_ALL ? 2 : 0;
894+
895+
v3f halfNode = v3f(BS, BS, BS) / 2.0f;
896+
897+
for (s8 x = -radius; x <= radius; x++)
898+
for (s8 y = -radius; y <= radius; y++)
899+
for (s8 z = -radius; z <= radius; z++) {
900+
v3s16 blockOffset(x, y, z);
901+
902+
aabb3f box(
903+
intToFloat((blockPos + blockOffset) * MAP_BLOCKSIZE, BS) - offset - halfNode,
904+
intToFloat(((blockPos + blockOffset) * MAP_BLOCKSIZE) + (MAP_BLOCKSIZE - 1), BS) - offset + halfNode
905+
);
906+
907+
driver->draw3DBox(box, video::SColor(255, 255, 0, 0));
908+
}
909+
910+
driver->setMaterial(old_material);
911+
}
912+
865913
void Hud::updateSelectionMesh(const v3s16 &camera_offset)
866914
{
867915
m_camera_offset = camera_offset;

‎src/client/hud.h

+11
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class Hud
5959
Inventory *inventory);
6060
~Hud();
6161

62+
void toggleBlockBounds();
63+
void drawBlockBounds();
64+
6265
void drawHotbar(u16 playeritem);
6366
void resizeHotbar();
6467
void drawCrosshair();
@@ -125,6 +128,14 @@ class Hud
125128

126129
scene::SMeshBuffer m_rotation_mesh_buffer;
127130

131+
enum BlockBoundsMode
132+
{
133+
BLOCK_BOUNDS_OFF,
134+
BLOCK_BOUNDS_CURRENT,
135+
BLOCK_BOUNDS_ALL,
136+
BLOCK_BOUNDS_MAX
137+
} m_block_bounds_mode = BLOCK_BOUNDS_OFF;
138+
128139
enum
129140
{
130141
HIGHLIGHT_BOX,

‎src/client/inputhandler.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void KeyCache::populate()
6060
key[KeyType::DEC_VOLUME] = getKeySetting("keymap_decrease_volume");
6161
key[KeyType::CINEMATIC] = getKeySetting("keymap_cinematic");
6262
key[KeyType::SCREENSHOT] = getKeySetting("keymap_screenshot");
63+
key[KeyType::TOGGLE_BLOCK_BOUNDS] = getKeySetting("keymap_toggle_block_bounds");
6364
key[KeyType::TOGGLE_HUD] = getKeySetting("keymap_toggle_hud");
6465
key[KeyType::TOGGLE_CHAT] = getKeySetting("keymap_toggle_chat");
6566
key[KeyType::TOGGLE_FOG] = getKeySetting("keymap_toggle_fog");

‎src/client/keys.h

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class KeyType
5959
DEC_VOLUME,
6060
CINEMATIC,
6161
SCREENSHOT,
62+
TOGGLE_BLOCK_BOUNDS,
6263
TOGGLE_HUD,
6364
TOGGLE_CHAT,
6465
TOGGLE_FOG,

‎src/client/render/core.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void RenderingCore::draw3D()
7676
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
7777
if (!show_hud)
7878
return;
79+
hud->drawBlockBounds();
7980
hud->drawSelectionMesh();
8081
if (draw_wield_tool)
8182
camera->drawWieldedTool();

‎src/defaultsettings.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void set_default_settings()
9797
settings->setDefault("keymap_increase_volume", "");
9898
settings->setDefault("keymap_decrease_volume", "");
9999
settings->setDefault("keymap_cinematic", "");
100+
settings->setDefault("keymap_toggle_block_bounds", "");
100101
settings->setDefault("keymap_toggle_hud", "KEY_F1");
101102
settings->setDefault("keymap_toggle_chat", "KEY_F2");
102103
settings->setDefault("keymap_toggle_fog", "KEY_F3");

‎src/gui/guiKeyChangeMenu.cpp

+35-33
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ enum
7070
GUI_ID_KEY_MINIMAP_BUTTON,
7171
GUI_ID_KEY_SCREENSHOT_BUTTON,
7272
GUI_ID_KEY_CHATLOG_BUTTON,
73+
GUI_ID_KEY_BLOCK_BOUNDS_BUTTON,
7374
GUI_ID_KEY_HUD_BUTTON,
7475
GUI_ID_KEY_FOG_BUTTON,
7576
GUI_ID_KEY_DEC_RANGE_BUTTON,
@@ -412,37 +413,38 @@ void GUIKeyChangeMenu::add_key(int id, const wchar_t *button_name, const std::st
412413

413414
void GUIKeyChangeMenu::init_keys()
414415
{
415-
this->add_key(GUI_ID_KEY_FORWARD_BUTTON, wgettext("Forward"), "keymap_forward");
416-
this->add_key(GUI_ID_KEY_BACKWARD_BUTTON, wgettext("Backward"), "keymap_backward");
417-
this->add_key(GUI_ID_KEY_LEFT_BUTTON, wgettext("Left"), "keymap_left");
418-
this->add_key(GUI_ID_KEY_RIGHT_BUTTON, wgettext("Right"), "keymap_right");
419-
this->add_key(GUI_ID_KEY_AUX1_BUTTON, wgettext("Aux1"), "keymap_aux1");
420-
this->add_key(GUI_ID_KEY_JUMP_BUTTON, wgettext("Jump"), "keymap_jump");
421-
this->add_key(GUI_ID_KEY_SNEAK_BUTTON, wgettext("Sneak"), "keymap_sneak");
422-
this->add_key(GUI_ID_KEY_DROP_BUTTON, wgettext("Drop"), "keymap_drop");
423-
this->add_key(GUI_ID_KEY_INVENTORY_BUTTON, wgettext("Inventory"), "keymap_inventory");
424-
this->add_key(GUI_ID_KEY_HOTBAR_PREV_BUTTON,wgettext("Prev. item"), "keymap_hotbar_previous");
425-
this->add_key(GUI_ID_KEY_HOTBAR_NEXT_BUTTON,wgettext("Next item"), "keymap_hotbar_next");
426-
this->add_key(GUI_ID_KEY_ZOOM_BUTTON, wgettext("Zoom"), "keymap_zoom");
427-
this->add_key(GUI_ID_KEY_CAMERA_BUTTON, wgettext("Change camera"), "keymap_camera_mode");
428-
this->add_key(GUI_ID_KEY_MINIMAP_BUTTON, wgettext("Toggle minimap"), "keymap_minimap");
429-
this->add_key(GUI_ID_KEY_FLY_BUTTON, wgettext("Toggle fly"), "keymap_freemove");
430-
this->add_key(GUI_ID_KEY_PITCH_MOVE, wgettext("Toggle pitchmove"), "keymap_pitchmove");
431-
this->add_key(GUI_ID_KEY_FAST_BUTTON, wgettext("Toggle fast"), "keymap_fastmove");
432-
this->add_key(GUI_ID_KEY_NOCLIP_BUTTON, wgettext("Toggle noclip"), "keymap_noclip");
433-
this->add_key(GUI_ID_KEY_MUTE_BUTTON, wgettext("Mute"), "keymap_mute");
434-
this->add_key(GUI_ID_KEY_DEC_VOLUME_BUTTON,wgettext("Dec. volume"), "keymap_decrease_volume");
435-
this->add_key(GUI_ID_KEY_INC_VOLUME_BUTTON,wgettext("Inc. volume"), "keymap_increase_volume");
436-
this->add_key(GUI_ID_KEY_AUTOFWD_BUTTON, wgettext("Autoforward"), "keymap_autoforward");
437-
this->add_key(GUI_ID_KEY_CHAT_BUTTON, wgettext("Chat"), "keymap_chat");
438-
this->add_key(GUI_ID_KEY_SCREENSHOT_BUTTON,wgettext("Screenshot"), "keymap_screenshot");
439-
this->add_key(GUI_ID_KEY_RANGE_BUTTON, wgettext("Range select"), "keymap_rangeselect");
440-
this->add_key(GUI_ID_KEY_DEC_RANGE_BUTTON, wgettext("Dec. range"), "keymap_decrease_viewing_range_min");
441-
this->add_key(GUI_ID_KEY_INC_RANGE_BUTTON, wgettext("Inc. range"), "keymap_increase_viewing_range_min");
442-
this->add_key(GUI_ID_KEY_CONSOLE_BUTTON, wgettext("Console"), "keymap_console");
443-
this->add_key(GUI_ID_KEY_CMD_BUTTON, wgettext("Command"), "keymap_cmd");
444-
this->add_key(GUI_ID_KEY_CMD_LOCAL_BUTTON, wgettext("Local command"), "keymap_cmd_local");
445-
this->add_key(GUI_ID_KEY_HUD_BUTTON, wgettext("Toggle HUD"), "keymap_toggle_hud");
446-
this->add_key(GUI_ID_KEY_CHATLOG_BUTTON, wgettext("Toggle chat log"), "keymap_toggle_chat");
447-
this->add_key(GUI_ID_KEY_FOG_BUTTON, wgettext("Toggle fog"), "keymap_toggle_fog");
416+
this->add_key(GUI_ID_KEY_FORWARD_BUTTON, wgettext("Forward"), "keymap_forward");
417+
this->add_key(GUI_ID_KEY_BACKWARD_BUTTON, wgettext("Backward"), "keymap_backward");
418+
this->add_key(GUI_ID_KEY_LEFT_BUTTON, wgettext("Left"), "keymap_left");
419+
this->add_key(GUI_ID_KEY_RIGHT_BUTTON, wgettext("Right"), "keymap_right");
420+
this->add_key(GUI_ID_KEY_AUX1_BUTTON, wgettext("Aux1"), "keymap_aux1");
421+
this->add_key(GUI_ID_KEY_JUMP_BUTTON, wgettext("Jump"), "keymap_jump");
422+
this->add_key(GUI_ID_KEY_SNEAK_BUTTON, wgettext("Sneak"), "keymap_sneak");
423+
this->add_key(GUI_ID_KEY_DROP_BUTTON, wgettext("Drop"), "keymap_drop");
424+
this->add_key(GUI_ID_KEY_INVENTORY_BUTTON, wgettext("Inventory"), "keymap_inventory");
425+
this->add_key(GUI_ID_KEY_HOTBAR_PREV_BUTTON, wgettext("Prev. item"), "keymap_hotbar_previous");
426+
this->add_key(GUI_ID_KEY_HOTBAR_NEXT_BUTTON, wgettext("Next item"), "keymap_hotbar_next");
427+
this->add_key(GUI_ID_KEY_ZOOM_BUTTON, wgettext("Zoom"), "keymap_zoom");
428+
this->add_key(GUI_ID_KEY_CAMERA_BUTTON, wgettext("Change camera"), "keymap_camera_mode");
429+
this->add_key(GUI_ID_KEY_MINIMAP_BUTTON, wgettext("Toggle minimap"), "keymap_minimap");
430+
this->add_key(GUI_ID_KEY_FLY_BUTTON, wgettext("Toggle fly"), "keymap_freemove");
431+
this->add_key(GUI_ID_KEY_PITCH_MOVE, wgettext("Toggle pitchmove"), "keymap_pitchmove");
432+
this->add_key(GUI_ID_KEY_FAST_BUTTON, wgettext("Toggle fast"), "keymap_fastmove");
433+
this->add_key(GUI_ID_KEY_NOCLIP_BUTTON, wgettext("Toggle noclip"), "keymap_noclip");
434+
this->add_key(GUI_ID_KEY_MUTE_BUTTON, wgettext("Mute"), "keymap_mute");
435+
this->add_key(GUI_ID_KEY_DEC_VOLUME_BUTTON, wgettext("Dec. volume"), "keymap_decrease_volume");
436+
this->add_key(GUI_ID_KEY_INC_VOLUME_BUTTON, wgettext("Inc. volume"), "keymap_increase_volume");
437+
this->add_key(GUI_ID_KEY_AUTOFWD_BUTTON, wgettext("Autoforward"), "keymap_autoforward");
438+
this->add_key(GUI_ID_KEY_CHAT_BUTTON, wgettext("Chat"), "keymap_chat");
439+
this->add_key(GUI_ID_KEY_SCREENSHOT_BUTTON, wgettext("Screenshot"), "keymap_screenshot");
440+
this->add_key(GUI_ID_KEY_RANGE_BUTTON, wgettext("Range select"), "keymap_rangeselect");
441+
this->add_key(GUI_ID_KEY_DEC_RANGE_BUTTON, wgettext("Dec. range"), "keymap_decrease_viewing_range_min");
442+
this->add_key(GUI_ID_KEY_INC_RANGE_BUTTON, wgettext("Inc. range"), "keymap_increase_viewing_range_min");
443+
this->add_key(GUI_ID_KEY_CONSOLE_BUTTON, wgettext("Console"), "keymap_console");
444+
this->add_key(GUI_ID_KEY_CMD_BUTTON, wgettext("Command"), "keymap_cmd");
445+
this->add_key(GUI_ID_KEY_CMD_LOCAL_BUTTON, wgettext("Local command"), "keymap_cmd_local");
446+
this->add_key(GUI_ID_KEY_BLOCK_BOUNDS_BUTTON, wgettext("Block bounds"), "keymap_toggle_block_bounds");
447+
this->add_key(GUI_ID_KEY_HUD_BUTTON, wgettext("Toggle HUD"), "keymap_toggle_hud");
448+
this->add_key(GUI_ID_KEY_CHATLOG_BUTTON, wgettext("Toggle chat log"), "keymap_toggle_chat");
449+
this->add_key(GUI_ID_KEY_FOG_BUTTON, wgettext("Toggle fog"), "keymap_toggle_fog");
448450
}

0 commit comments

Comments
 (0)