Add object crosshair, disable entity selectionboxes by default (#9523)

Adds new object crosshair base pack texture
This commit is contained in:
LoneWolfHT 2020-07-14 10:12:17 -07:00 committed by SmallJoker
parent 4fa1e03f68
commit 88ffd64124
8 changed files with 55 additions and 10 deletions

@ -741,9 +741,11 @@ selectionbox_color (Selection box color) string (0,0,0)
selectionbox_width (Selection box width) int 2 1 5 selectionbox_width (Selection box width) int 2 1 5
# Crosshair color (R,G,B). # Crosshair color (R,G,B).
# Also controls the object crosshair color
crosshair_color (Crosshair color) string (255,255,255) crosshair_color (Crosshair color) string (255,255,255)
# Crosshair alpha (opaqueness, between 0 and 255). # Crosshair alpha (opaqueness, between 0 and 255).
# Also controls the object crosshair color
crosshair_alpha (Crosshair alpha) int 255 0 255 crosshair_alpha (Crosshair alpha) int 255 0 255
# Maximum number of recent chat messages to show # 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 autoscale_mode (Autoscaling mode) enum disable disable,enable,force
# Show entity selection boxes # 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] [*Menus]

@ -72,7 +72,12 @@ by texture packs. All existing fallback textures can be found in the directory
* `crosshair.png` * `crosshair.png`
* the crosshair texture in the center of the screen. The settings * the crosshair texture in the center of the screen. The settings
`crosshair_color` and `crosshair_alpha` are used to create a cross `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 * `halo.png`: used for the node highlighting mesh

@ -955,8 +955,9 @@
# autoscale_mode = disable # autoscale_mode = disable
# Show entity selection boxes # Show entity selection boxes
# A restart is required after changing this.
# type: bool # type: bool
# show_entity_selectionbox = true # show_entity_selectionbox = false
## Menus ## Menus
@ -3374,4 +3375,3 @@
# so see a full list at https://content.minetest.net/help/content_flags/ # so see a full list at https://content.minetest.net/help/content_flags/
# type: string # type: string
# contentdb_flag_blacklist = nonfree, desktop_default # contentdb_flag_blacklist = nonfree, desktop_default

@ -3176,11 +3176,14 @@ PointedThing Game::updatePointedThing(
const NodeDefManager *nodedef = map.getNodeDefManager(); const NodeDefManager *nodedef = map.getNodeDefManager();
runData.selected_object = NULL; runData.selected_object = NULL;
hud->pointing_at_object = false;
RaycastState s(shootline, look_for_object, liquids_pointable); RaycastState s(shootline, look_for_object, liquids_pointable);
PointedThing result; PointedThing result;
env.continueRaycast(&s, &result); env.continueRaycast(&s, &result);
if (result.type == POINTEDTHING_OBJECT) { if (result.type == POINTEDTHING_OBJECT) {
hud->pointing_at_object = true;
runData.selected_object = client->getEnv().getActiveObject(result.object_id); runData.selected_object = client->getEnv().getActiveObject(result.object_id);
aabb3f selection_box; aabb3f selection_box;
if (show_entity_selectionbox && runData.selected_object->doShowSelectionBox() && if (show_entity_selectionbox && runData.selected_object->doShowSelectionBox() &&

@ -41,6 +41,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gui/touchscreengui.h" #include "gui/touchscreengui.h"
#endif #endif
#define OBJECT_CROSSHAIR_LINE_SIZE 8
#define CROSSHAIR_LINE_SIZE 10
Hud::Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player, Hud::Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
Inventory *inventory) 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); selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b);
use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png"); use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png");
use_object_crosshair_image = tsrc->isKnownSourceImage("object_crosshair.png");
m_selection_boxes.clear(); m_selection_boxes.clear();
m_halo_boxes.clear(); m_halo_boxes.clear();
@ -601,6 +605,31 @@ void Hud::drawHotbar(u16 playeritem) {
void Hud::drawCrosshair() 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<s32>(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) { if (use_crosshair_image) {
video::ITexture *crosshair = tsrc->getTexture("crosshair.png"); video::ITexture *crosshair = tsrc->getTexture("crosshair.png");
v2u32 size = crosshair->getOriginalSize(); v2u32 size = crosshair->getOriginalSize();
@ -608,12 +637,12 @@ void Hud::drawCrosshair()
m_displaycenter.Y - (size.Y / 2)); m_displaycenter.Y - (size.Y / 2));
driver->draw2DImage(crosshair, lsize, driver->draw2DImage(crosshair, lsize,
core::rect<s32>(0, 0, size.X, size.Y), core::rect<s32>(0, 0, size.X, size.Y),
0, crosshair_argb, true); nullptr, crosshair_argb, true);
} else { } else {
driver->draw2DLine(m_displaycenter - v2s32(10, 0), driver->draw2DLine(m_displaycenter - v2s32(CROSSHAIR_LINE_SIZE, 0),
m_displaycenter + v2s32(10, 0), crosshair_argb); m_displaycenter + v2s32(CROSSHAIR_LINE_SIZE, 0), crosshair_argb);
driver->draw2DLine(m_displaycenter - v2s32(0, 10), driver->draw2DLine(m_displaycenter - v2s32(0, CROSSHAIR_LINE_SIZE),
m_displaycenter + v2s32(0, 10), crosshair_argb); m_displaycenter + v2s32(0, CROSSHAIR_LINE_SIZE), crosshair_argb);
} }
} }

@ -45,12 +45,16 @@ public:
video::SColor crosshair_argb; video::SColor crosshair_argb;
video::SColor selectionbox_argb; video::SColor selectionbox_argb;
bool use_crosshair_image = false; bool use_crosshair_image = false;
bool use_object_crosshair_image = false;
std::string hotbar_image = ""; std::string hotbar_image = "";
bool use_hotbar_image = false; bool use_hotbar_image = false;
std::string hotbar_selected_image = ""; std::string hotbar_selected_image = "";
bool use_hotbar_selected_image = false; bool use_hotbar_selected_image = false;
bool pointing_at_object = false;
Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player, Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
Inventory *inventory); Inventory *inventory);
~Hud(); ~Hud();

@ -86,6 +86,7 @@ void RenderingCore::drawHUD()
if (show_hud) { if (show_hud) {
if (draw_crosshair) if (draw_crosshair)
hud->drawCrosshair(); hud->drawCrosshair();
hud->drawHotbar(client->getEnv().getLocalPlayer()->getWieldIndex()); hud->drawHotbar(client->getEnv().getLocalPlayer()->getWieldIndex());
hud->drawLuaElements(camera->getOffset()); hud->drawLuaElements(camera->getOffset());
camera->drawNametags(); camera->drawNametags();

@ -225,7 +225,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("desynchronize_mapblock_texture_animation", "true"); settings->setDefault("desynchronize_mapblock_texture_animation", "true");
settings->setDefault("hud_hotbar_max_width", "1.0"); settings->setDefault("hud_hotbar_max_width", "1.0");
settings->setDefault("enable_local_map_saving", "false"); 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_clean_transparent", "false");
settings->setDefault("texture_min_size", "64"); settings->setDefault("texture_min_size", "64");
settings->setDefault("ambient_occlusion_gamma", "2.2"); settings->setDefault("ambient_occlusion_gamma", "2.2");