From 88ffd641243ead70d82623d54822421c72893240 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Tue, 14 Jul 2020 10:12:17 -0700 Subject: [PATCH] Add object crosshair, disable entity selectionboxes by default (#9523) Adds new object crosshair base pack texture --- builtin/settingtypes.txt | 5 ++++- doc/texture_packs.txt | 7 ++++++- minetest.conf.example | 4 ++-- src/client/game.cpp | 3 +++ src/client/hud.cpp | 39 +++++++++++++++++++++++++++++++++----- src/client/hud.h | 4 ++++ src/client/render/core.cpp | 1 + src/defaultsettings.cpp | 2 +- 8 files changed, 55 insertions(+), 10 deletions(-) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index c787aea2c..c0620542d 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -741,9 +741,11 @@ selectionbox_color (Selection box color) string (0,0,0) selectionbox_width (Selection box width) int 2 1 5 # Crosshair color (R,G,B). +# Also controls the object crosshair color crosshair_color (Crosshair color) string (255,255,255) # Crosshair alpha (opaqueness, between 0 and 255). +# Also controls the object crosshair color crosshair_alpha (Crosshair alpha) int 255 0 255 # Maximum number of recent chat messages to show @@ -817,7 +819,8 @@ world_aligned_mode (World-aligned textures mode) enum enable disable,enable,forc autoscale_mode (Autoscaling mode) enum disable disable,enable,force # Show entity selection boxes -show_entity_selectionbox (Show entity selection boxes) bool true +# A restart is required after changing this. +show_entity_selectionbox (Show entity selection boxes) bool false [*Menus] diff --git a/doc/texture_packs.txt b/doc/texture_packs.txt index 94151f1a4..e7a7dfd3c 100644 --- a/doc/texture_packs.txt +++ b/doc/texture_packs.txt @@ -72,7 +72,12 @@ by texture packs. All existing fallback textures can be found in the directory * `crosshair.png` * the crosshair texture in the center of the screen. The settings `crosshair_color` and `crosshair_alpha` are used to create a cross - when no texture was found + when no texture is found. + +* `object_crosshair.png` + * the crosshair seen when pointing at an object. The settings + `crosshair_color` and `crosshair_alpha` are used to create a cross + when no texture is found. * `halo.png`: used for the node highlighting mesh diff --git a/minetest.conf.example b/minetest.conf.example index a5f98ee5e..520125713 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -955,8 +955,9 @@ # autoscale_mode = disable # Show entity selection boxes +# A restart is required after changing this. # type: bool -# show_entity_selectionbox = true +# show_entity_selectionbox = false ## Menus @@ -3374,4 +3375,3 @@ # so see a full list at https://content.minetest.net/help/content_flags/ # type: string # contentdb_flag_blacklist = nonfree, desktop_default - diff --git a/src/client/game.cpp b/src/client/game.cpp index 5f3ff5649..42d60b21c 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -3176,11 +3176,14 @@ PointedThing Game::updatePointedThing( const NodeDefManager *nodedef = map.getNodeDefManager(); runData.selected_object = NULL; + hud->pointing_at_object = false; RaycastState s(shootline, look_for_object, liquids_pointable); PointedThing result; env.continueRaycast(&s, &result); if (result.type == POINTEDTHING_OBJECT) { + hud->pointing_at_object = true; + runData.selected_object = client->getEnv().getActiveObject(result.object_id); aabb3f selection_box; if (show_entity_selectionbox && runData.selected_object->doShowSelectionBox() && diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 31e633bc2..2b347c1e0 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -41,6 +41,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "gui/touchscreengui.h" #endif +#define OBJECT_CROSSHAIR_LINE_SIZE 8 +#define CROSSHAIR_LINE_SIZE 10 + Hud::Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player, Inventory *inventory) { @@ -76,6 +79,7 @@ Hud::Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player, selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b); use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png"); + use_object_crosshair_image = tsrc->isKnownSourceImage("object_crosshair.png"); m_selection_boxes.clear(); m_halo_boxes.clear(); @@ -601,6 +605,31 @@ void Hud::drawHotbar(u16 playeritem) { void Hud::drawCrosshair() { + if (pointing_at_object) { + if (use_object_crosshair_image) { + video::ITexture *object_crosshair = tsrc->getTexture("object_crosshair.png"); + v2u32 size = object_crosshair->getOriginalSize(); + v2s32 lsize = v2s32(m_displaycenter.X - (size.X / 2), + m_displaycenter.Y - (size.Y / 2)); + driver->draw2DImage(object_crosshair, lsize, + core::rect(0, 0, size.X, size.Y), + nullptr, crosshair_argb, true); + } else { + driver->draw2DLine( + m_displaycenter - v2s32(OBJECT_CROSSHAIR_LINE_SIZE, + OBJECT_CROSSHAIR_LINE_SIZE), + m_displaycenter + v2s32(OBJECT_CROSSHAIR_LINE_SIZE, + OBJECT_CROSSHAIR_LINE_SIZE), crosshair_argb); + driver->draw2DLine( + m_displaycenter + v2s32(OBJECT_CROSSHAIR_LINE_SIZE, + -OBJECT_CROSSHAIR_LINE_SIZE), + m_displaycenter + v2s32(-OBJECT_CROSSHAIR_LINE_SIZE, + OBJECT_CROSSHAIR_LINE_SIZE), crosshair_argb); + } + + return; + } + if (use_crosshair_image) { video::ITexture *crosshair = tsrc->getTexture("crosshair.png"); v2u32 size = crosshair->getOriginalSize(); @@ -608,12 +637,12 @@ void Hud::drawCrosshair() m_displaycenter.Y - (size.Y / 2)); driver->draw2DImage(crosshair, lsize, core::rect(0, 0, size.X, size.Y), - 0, crosshair_argb, true); + nullptr, crosshair_argb, true); } else { - driver->draw2DLine(m_displaycenter - v2s32(10, 0), - m_displaycenter + v2s32(10, 0), crosshair_argb); - driver->draw2DLine(m_displaycenter - v2s32(0, 10), - m_displaycenter + v2s32(0, 10), crosshair_argb); + driver->draw2DLine(m_displaycenter - v2s32(CROSSHAIR_LINE_SIZE, 0), + m_displaycenter + v2s32(CROSSHAIR_LINE_SIZE, 0), crosshair_argb); + driver->draw2DLine(m_displaycenter - v2s32(0, CROSSHAIR_LINE_SIZE), + m_displaycenter + v2s32(0, CROSSHAIR_LINE_SIZE), crosshair_argb); } } diff --git a/src/client/hud.h b/src/client/hud.h index 6f4c54626..ba34d479d 100644 --- a/src/client/hud.h +++ b/src/client/hud.h @@ -45,12 +45,16 @@ public: video::SColor crosshair_argb; video::SColor selectionbox_argb; + bool use_crosshair_image = false; + bool use_object_crosshair_image = false; std::string hotbar_image = ""; bool use_hotbar_image = false; std::string hotbar_selected_image = ""; bool use_hotbar_selected_image = false; + bool pointing_at_object = false; + Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player, Inventory *inventory); ~Hud(); diff --git a/src/client/render/core.cpp b/src/client/render/core.cpp index bf5aa6c2c..92a7137ea 100644 --- a/src/client/render/core.cpp +++ b/src/client/render/core.cpp @@ -86,6 +86,7 @@ void RenderingCore::drawHUD() if (show_hud) { if (draw_crosshair) hud->drawCrosshair(); + hud->drawHotbar(client->getEnv().getLocalPlayer()->getWieldIndex()); hud->drawLuaElements(camera->getOffset()); camera->drawNametags(); diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index abb6593b7..07bf0ebb8 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -225,7 +225,7 @@ void set_default_settings(Settings *settings) settings->setDefault("desynchronize_mapblock_texture_animation", "true"); settings->setDefault("hud_hotbar_max_width", "1.0"); settings->setDefault("enable_local_map_saving", "false"); - settings->setDefault("show_entity_selectionbox", "true"); + settings->setDefault("show_entity_selectionbox", "false"); settings->setDefault("texture_clean_transparent", "false"); settings->setDefault("texture_min_size", "64"); settings->setDefault("ambient_occlusion_gamma", "2.2");