Skip to content

Commit

Permalink
Add object crosshair and disable entity selectionboxes by default (#9523
Browse files Browse the repository at this point in the history
)

* The PR is born

* Add missing entry in texture_packs.txt

* Remove minetest.conf.example changes

* Remove image offset for the selectionindicator

* Remove if checks

* Make selectionindicator texture replace crosshair

* Make requested changes

* Change selectionindicator to an X

* The PR is born

* Change size of selectionindicator lines to 8

* Rename to 'object crosshair'

* Fix what I somehow broke

* Remove something I missed

* Disappear usage of magic numbers

* Apply ClobberXD's code style fix

Co-authored-by: ANAND <ClobberXD@gmail.com>

* Fix indenting in texture_packs.txt

* Improve texture_packs.txt doc

* Apply SmallJoker's suggestion

Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com>

* Make requested changes

Co-authored-by: ANAND <ClobberXD@gmail.com>
Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 14, 2020
1 parent 4fa1e03 commit 94619d8
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 10 deletions.
5 changes: 4 additions & 1 deletion builtin/settingtypes.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand Down
7 changes: 6 additions & 1 deletion doc/texture_packs.txt
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions minetest.conf.example
Expand Up @@ -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

Expand Down Expand Up @@ -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

3 changes: 3 additions & 0 deletions src/client/game.cpp
Expand Up @@ -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() &&
Expand Down
39 changes: 34 additions & 5 deletions src/client/hud.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -601,19 +605,44 @@ 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<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) {
video::ITexture *crosshair = tsrc->getTexture("crosshair.png");
v2u32 size = crosshair->getOriginalSize();
v2s32 lsize = v2s32(m_displaycenter.X - (size.X / 2),
m_displaycenter.Y - (size.Y / 2));
driver->draw2DImage(crosshair, lsize,
core::rect<s32>(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);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/client/hud.h
Expand Up @@ -45,12 +45,16 @@ class Hud

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();
Expand Down
1 change: 1 addition & 0 deletions src/client/render/core.cpp
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/defaultsettings.cpp
Expand Up @@ -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");
Expand Down

0 comments on commit 94619d8

Please sign in to comment.