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.
This commit is contained in:
Seth Traverse 2021-04-20 10:23:31 -07:00 committed by GitHub
parent 0077982fb7
commit 16e5b39e1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 100 additions and 33 deletions

@ -1932,6 +1932,8 @@ void Game::processKeyInput()
toggleCinematic(); toggleCinematic();
} else if (wasKeyDown(KeyType::SCREENSHOT)) { } else if (wasKeyDown(KeyType::SCREENSHOT)) {
client->makeScreenshot(); client->makeScreenshot();
} else if (wasKeyDown(KeyType::TOGGLE_BLOCK_BOUNDS)) {
hud->toggleBlockBounds();
} else if (wasKeyDown(KeyType::TOGGLE_HUD)) { } else if (wasKeyDown(KeyType::TOGGLE_HUD)) {
m_game_ui->toggleHud(); m_game_ui->toggleHud();
} else if (wasKeyDown(KeyType::MINIMAP)) { } else if (wasKeyDown(KeyType::MINIMAP)) {

@ -862,6 +862,54 @@ void Hud::drawSelectionMesh()
} }
} }
void Hud::toggleBlockBounds()
{
m_block_bounds_mode = static_cast<BlockBoundsMode>(m_block_bounds_mode + 1);
if (m_block_bounds_mode >= BLOCK_BOUNDS_MAX) {
m_block_bounds_mode = BLOCK_BOUNDS_OFF;
}
}
void Hud::drawBlockBounds()
{
if (m_block_bounds_mode == BLOCK_BOUNDS_OFF) {
return;
}
video::SMaterial old_material = driver->getMaterial2D();
driver->setMaterial(m_selection_material);
v3s16 pos = player->getStandingNodePos();
v3s16 blockPos(
floorf((float) pos.X / MAP_BLOCKSIZE),
floorf((float) pos.Y / MAP_BLOCKSIZE),
floorf((float) pos.Z / MAP_BLOCKSIZE)
);
v3f offset = intToFloat(client->getCamera()->getOffset(), BS);
s8 radius = m_block_bounds_mode == BLOCK_BOUNDS_ALL ? 2 : 0;
v3f halfNode = v3f(BS, BS, BS) / 2.0f;
for (s8 x = -radius; x <= radius; x++)
for (s8 y = -radius; y <= radius; y++)
for (s8 z = -radius; z <= radius; z++) {
v3s16 blockOffset(x, y, z);
aabb3f box(
intToFloat((blockPos + blockOffset) * MAP_BLOCKSIZE, BS) - offset - halfNode,
intToFloat(((blockPos + blockOffset) * MAP_BLOCKSIZE) + (MAP_BLOCKSIZE - 1), BS) - offset + halfNode
);
driver->draw3DBox(box, video::SColor(255, 255, 0, 0));
}
driver->setMaterial(old_material);
}
void Hud::updateSelectionMesh(const v3s16 &camera_offset) void Hud::updateSelectionMesh(const v3s16 &camera_offset)
{ {
m_camera_offset = camera_offset; m_camera_offset = camera_offset;

@ -59,6 +59,9 @@ public:
Inventory *inventory); Inventory *inventory);
~Hud(); ~Hud();
void toggleBlockBounds();
void drawBlockBounds();
void drawHotbar(u16 playeritem); void drawHotbar(u16 playeritem);
void resizeHotbar(); void resizeHotbar();
void drawCrosshair(); void drawCrosshair();
@ -125,6 +128,14 @@ private:
scene::SMeshBuffer m_rotation_mesh_buffer; scene::SMeshBuffer m_rotation_mesh_buffer;
enum BlockBoundsMode
{
BLOCK_BOUNDS_OFF,
BLOCK_BOUNDS_CURRENT,
BLOCK_BOUNDS_ALL,
BLOCK_BOUNDS_MAX
} m_block_bounds_mode = BLOCK_BOUNDS_OFF;
enum enum
{ {
HIGHLIGHT_BOX, HIGHLIGHT_BOX,

@ -60,6 +60,7 @@ void KeyCache::populate()
key[KeyType::DEC_VOLUME] = getKeySetting("keymap_decrease_volume"); key[KeyType::DEC_VOLUME] = getKeySetting("keymap_decrease_volume");
key[KeyType::CINEMATIC] = getKeySetting("keymap_cinematic"); key[KeyType::CINEMATIC] = getKeySetting("keymap_cinematic");
key[KeyType::SCREENSHOT] = getKeySetting("keymap_screenshot"); key[KeyType::SCREENSHOT] = getKeySetting("keymap_screenshot");
key[KeyType::TOGGLE_BLOCK_BOUNDS] = getKeySetting("keymap_toggle_block_bounds");
key[KeyType::TOGGLE_HUD] = getKeySetting("keymap_toggle_hud"); key[KeyType::TOGGLE_HUD] = getKeySetting("keymap_toggle_hud");
key[KeyType::TOGGLE_CHAT] = getKeySetting("keymap_toggle_chat"); key[KeyType::TOGGLE_CHAT] = getKeySetting("keymap_toggle_chat");
key[KeyType::TOGGLE_FOG] = getKeySetting("keymap_toggle_fog"); key[KeyType::TOGGLE_FOG] = getKeySetting("keymap_toggle_fog");

@ -59,6 +59,7 @@ public:
DEC_VOLUME, DEC_VOLUME,
CINEMATIC, CINEMATIC,
SCREENSHOT, SCREENSHOT,
TOGGLE_BLOCK_BOUNDS,
TOGGLE_HUD, TOGGLE_HUD,
TOGGLE_CHAT, TOGGLE_CHAT,
TOGGLE_FOG, TOGGLE_FOG,

@ -76,6 +76,7 @@ void RenderingCore::draw3D()
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix); driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
if (!show_hud) if (!show_hud)
return; return;
hud->drawBlockBounds();
hud->drawSelectionMesh(); hud->drawSelectionMesh();
if (draw_wield_tool) if (draw_wield_tool)
camera->drawWieldedTool(); camera->drawWieldedTool();

@ -97,6 +97,7 @@ void set_default_settings()
settings->setDefault("keymap_increase_volume", ""); settings->setDefault("keymap_increase_volume", "");
settings->setDefault("keymap_decrease_volume", ""); settings->setDefault("keymap_decrease_volume", "");
settings->setDefault("keymap_cinematic", ""); settings->setDefault("keymap_cinematic", "");
settings->setDefault("keymap_toggle_block_bounds", "");
settings->setDefault("keymap_toggle_hud", "KEY_F1"); settings->setDefault("keymap_toggle_hud", "KEY_F1");
settings->setDefault("keymap_toggle_chat", "KEY_F2"); settings->setDefault("keymap_toggle_chat", "KEY_F2");
settings->setDefault("keymap_toggle_fog", "KEY_F3"); settings->setDefault("keymap_toggle_fog", "KEY_F3");

@ -70,6 +70,7 @@ enum
GUI_ID_KEY_MINIMAP_BUTTON, GUI_ID_KEY_MINIMAP_BUTTON,
GUI_ID_KEY_SCREENSHOT_BUTTON, GUI_ID_KEY_SCREENSHOT_BUTTON,
GUI_ID_KEY_CHATLOG_BUTTON, GUI_ID_KEY_CHATLOG_BUTTON,
GUI_ID_KEY_BLOCK_BOUNDS_BUTTON,
GUI_ID_KEY_HUD_BUTTON, GUI_ID_KEY_HUD_BUTTON,
GUI_ID_KEY_FOG_BUTTON, GUI_ID_KEY_FOG_BUTTON,
GUI_ID_KEY_DEC_RANGE_BUTTON, GUI_ID_KEY_DEC_RANGE_BUTTON,
@ -442,6 +443,7 @@ void GUIKeyChangeMenu::init_keys()
this->add_key(GUI_ID_KEY_CONSOLE_BUTTON, wgettext("Console"), "keymap_console"); this->add_key(GUI_ID_KEY_CONSOLE_BUTTON, wgettext("Console"), "keymap_console");
this->add_key(GUI_ID_KEY_CMD_BUTTON, wgettext("Command"), "keymap_cmd"); this->add_key(GUI_ID_KEY_CMD_BUTTON, wgettext("Command"), "keymap_cmd");
this->add_key(GUI_ID_KEY_CMD_LOCAL_BUTTON, wgettext("Local command"), "keymap_cmd_local"); this->add_key(GUI_ID_KEY_CMD_LOCAL_BUTTON, wgettext("Local command"), "keymap_cmd_local");
this->add_key(GUI_ID_KEY_BLOCK_BOUNDS_BUTTON, wgettext("Block bounds"), "keymap_toggle_block_bounds");
this->add_key(GUI_ID_KEY_HUD_BUTTON, wgettext("Toggle HUD"), "keymap_toggle_hud"); this->add_key(GUI_ID_KEY_HUD_BUTTON, wgettext("Toggle HUD"), "keymap_toggle_hud");
this->add_key(GUI_ID_KEY_CHATLOG_BUTTON, wgettext("Toggle chat log"), "keymap_toggle_chat"); this->add_key(GUI_ID_KEY_CHATLOG_BUTTON, wgettext("Toggle chat log"), "keymap_toggle_chat");
this->add_key(GUI_ID_KEY_FOG_BUTTON, wgettext("Toggle fog"), "keymap_toggle_fog"); this->add_key(GUI_ID_KEY_FOG_BUTTON, wgettext("Toggle fog"), "keymap_toggle_fog");